Theming & RTL
Every value in the default look is a CSS custom property under .bit-bonboarding-root (the tour layer)
and .bit-bonboarding-themed (the beacons, checklists and tour lists on the page). Restyling the library
is a matter of overriding variables in your own stylesheet, with no selector fights and no framework to install.
Try it
Pick a theme, a direction, a progress style, an animation speed and a skin, then run the tour over the product below. With the theme left to the site, its last step points at the header's light/dark switch - press it while the card is up.
- Theme:
LightandDarkforce a palette;Systemfollows the operating system, or your stylesheet. - Direction:
Autofollows the page'sdir;RightToLeftmirrors the card, its alignment and the arrow keys. - Progress:
Dots(the default),Bar(aprogressbara screen reader reads as "2 of 4"),Text, orNone. - Animation:
AnimationDurationtimes the fades and the spotlight's move between steps; under reduced motion it is zero whatever you set, unlessRespectReducedMotion = false. - Skin: a
PopoverClassthat re-points the variables for one tour.
System - the tour leaves its colours to your stylesheet, and this site's
stylesheet follows its own light/dark switch. Light and Dark win over the switch.
Localisation
Every string the default card renders comes from a BonboardingLabels instance - set globally, per tour
(replacing the global set wholesale; Clone() one to change a few strings), or per step with
NextLabel, PreviousLabel, SkipLabel and DoneLabel. Each button
below runs the tour with a translated label set; the Arabic one is also right-to-left.
Translate the labels a screen reader hears, too: DialogLabel, StepAnnouncementFormat,
WaitingAnnouncement and ProgressLabel are never shown, and they are all a screen reader user
gets. For resource files or a translation service, register your own IBonboardingLocalizer: it supplies
the labels, and its Localize lets step titles and descriptions be resource keys. Progress numbers are
formatted in the current culture; the CSS the library writes always uses the invariant one.
// Globally:
builder.Services.AddBitBonboardingServices(options =>
{
options.Labels.Next = "Weiter";
options.Labels.Done = "Fertig";
});
// Per tour - a whole set; Clone() the default to change a few strings:
var labels = BonboardingLabels.Default.Clone();
labels.Next = "Weiter";
labels.StepAnnouncementFormat = "Schritt {0} von {1}. {2}"; // read by screen readers
new BonboardingTourDefinition { Id = "welcome", Labels = labels, Direction = BonboardingDirection.Auto };
// Per step:
new BonboardingStepDefinition { NextLabel = "Show me", DoneLabel = "Finish setup" };
// From resource files:
builder.Services.AddBitBonboardingLocalizer<ResourceOnboardingLocalizer>();Right-to-left
Direction = Auto (the default) follows the document: set dir="rtl" on <html>
as you already would, and tours follow. Set LeftToRight or RightToLeft on a tour for a page
of one direction with a tour of the other. Direction changes more than text alignment:
StartandEndalignments mirror:BottomStartaligns to the target's right edge.InlineStartandInlineEndare logical sides:InlineEndis on the right in English and on the left in Arabic, so one placement serves both.LeftandRightstay physical.- The arrow keys swap: Left advances and Right goes back, in reading order.
- Padding, margins and the footer's button order flip, and the root carries
dir, so a template inherits it.
The variables
This site does exactly what the snippet below shows: every tour card on it is the library's default markup
with Fluent 2 values poured into these variables, light and dark, in the demo's wwwroot/demo.css.
Apart from shielding the card from the site's own global element styles, none of the library's rules is
overridden.
| Group | Variables |
|---|---|
| Colour | --bit-bonboarding-surface, -surface-subtle, -text, -text-muted,
-border, -border-strong, -accent (with -hover, -active,
-text, -soft), -danger, -overlay (an R, G, B triple),
-spotlight-ring, -spotlight-glow |
| Shape and depth | --bit-bonboarding-radius, -radius-sm, -radius-pill, -shadow, -focus-ring |
| Typography | --bit-bonboarding-font, -font-size, -font-size-sm, -title-size, -title-weight, -line-height |
| Metrics and motion | --bit-bonboarding-popover-width, -popover-max-height, -space, -ease |
| Beacons | --bit-bonboarding-beacon-size, -beacon-dot, -beacon-color |
| Set by the engine | --bit-bonboarding-z, -duration, -overlay-opacity and -arrow are written
inline from ZIndex, AnimationDuration, OverlayOpacity and ArrowSize,
so a stylesheet cannot override them: change the option instead.
|
Every variable with its light and dark default is one request away: GetBonboardingThemeVariables.
/* Your stylesheet, loaded after the library's. The second selector reaches the beacons,
checklists and tour lists, which render on the page rather than in the tour layer. */
.bit-bonboarding-root,
.bit-bonboarding-themed {
--bit-bonboarding-accent: #f59e0b;
--bit-bonboarding-accent-text: #1f1300;
--bit-bonboarding-surface: #101828;
--bit-bonboarding-text: #f9fafb;
--bit-bonboarding-radius: 6px;
--bit-bonboarding-overlay: 15, 23, 42; /* dim with a brand colour rather than black */
}
/* Scope it to one tour with PopoverClass - it lands on the card. To restyle the overlay and
the spotlight as well, put the class on the host: <BonboardingRoot Class="checkout-theme" />. */
.checkout-tour { --bit-bonboarding-accent: #16a34a; }
/* A wider card for a step with a form: PopoverClass = "wide-step" on that step. */
.wide-step { --bit-bonboarding-popover-width: 32rem; }
// Motion, stacking and dimming are options, not variables:
new BonboardingTourDefinition { AnimationDuration = TimeSpan.FromMilliseconds(160), ZIndex = 9000, OverlayOpacity = 0.4 }Following your own theme switch
A tour that leaves its theme unset is drawn with data-bonboarding-theme="system". Out of the box the
library's stylesheet gives that the dark palette while the operating system asks for a dark scheme, and the light
one otherwise, following a change of the system setting at once. An application with a theme switch of its own maps
system to that switch in CSS, as this site does - or binds the switch to the host, whose
Theme overrides the tour's and the global one alike.
An explicit Light or Dark also sets color-scheme on the card, so native controls
in a custom step body match it; System inherits the page's.
/* This site: a tour with no theme of its own goes dark with the page's own switch. */
:root[bit-theme="dark"] .bit-bonboarding-root[data-bonboarding-theme="system"],
:root[bit-theme="dark"] .bit-bonboarding-themed[data-bonboarding-theme="system"] {
--bit-bonboarding-surface: #15191E;
--bit-bonboarding-text: #E6ECF2;
--bit-bonboarding-accent: #4FA3F4;
/* ... */
}
@* Or from C#: the host's Theme overrides the tour's and the global one. *@
<BonboardingRoot Theme="@(_dark ? BonboardingTheme.Dark : BonboardingTheme.Light)" />