enes

Exported components

  • TeachingTip
  • TeachingTipPreview
  • TeachingTipHeader
  • TeachingTipFooter

TeachingTip AI

A teaching tip is a flyout that points at an element to inform, remind and teach users about a feature, with an optional preview, a header, content and actions.

A teaching tip is built out of the following components:

  • TeachingTip: The root component. It holds the open state, provides context to its parts and floats against its target.
  • TeachingTipPreview: The media shown at the top or the bottom edge, spanning the whole width.
  • TeachingTipHeader: The title, with an optional icon, description, step counter and close button.
  • TeachingTipFooter: The actions shown at the bottom, each one taking half of the width.

Usage

<script>
  import { TeachingTip, TeachingTipPreview, TeachingTipHeader, TeachingTipFooter, Button } from 'fluentui-svelte';
  let open = $state(false);
  let target = $state(null);
</script>

{#snippet action()}
  <Button appearance="standard" onclick={() => (open = false)}>Got it</Button>
{/snippet}

<Button bind:ref={target} onclick={() => (open = !open)}>Save</Button>
<TeachingTip bind:open {target} withArrow>
  <TeachingTipPreview><img src="https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=640&h=320&fit=crop&q=60" alt="" /></TeachingTipPreview>
  <TeachingTipHeader title="Save automatically" />
  <p>Your changes are saved to the cloud as you work.</p>
  <TeachingTipFooter {action} />
</TeachingTip>

Target

Pass an element to target to float the teaching tip against it, on the side placement picks. Without a target, it stays in the normal flow. bind:open shows and hides it. The close button and Escape close it, and lightDismiss closes it on a click outside.

Arrow

withArrow adds an arrow that points at the target, on the side the teaching tip sits on. It follows the target when the teaching tip flips or shifts, and only shows when there is a target.

placement="bottom"
placement="top"

Preview

TeachingTipPreview spans the whole width and follows the corners of the edge it sits against: put it first for a preview at the top, or last for one at the bottom.

Preview at the top
Preview at the bottom

Header

The header takes a title, and optionally an icon and a description. A string title renders inside a heading that names the teaching tip. hideCloseButton removes the close button, and closeLabel gives it another accessible name.

icon, description
hideCloseButton

Step counter

Outside the Fluent spec. Set step and totalSteps on the header to show the progress of a tour next to the close button. formatStep changes its text, for example to translate it.

Headless tours with driver.js

TeachingTip has no tour logic of its own. A headless tour library such as driver.js/headless finds each element, listens for advanceOn and calls your hooks, and the teaching tip renders the step: onHighlighted gives it the target and the content, onDestroyed closes it, and the close button ends the tour through onOpenChange. Install it with npm install driver.js.

Keyboard and accessibility

The teaching tip is a non-modal dialog, named by the title of its header. It does not move the focus when it opens. Escape closes it while it is open.

Component Props (TeachingTip)

NameTypeDefaultDescription
ref bindableHTMLElement | nullThe DOM reference of the teaching tip element.
idstringThe id of the teaching tip element. Falls back to a generated one.
open bindablebooleanfalseControls the open state of the teaching tip.
onOpenChange(open: boolean) => voidCalled whenever the teaching tip opens or closes from within.
targetHTMLElement | nullThe element the teaching tip points at. Without it, the teaching tip stays in the normal flow.
placementPlacement'top'Where the teaching tip is placed relative to its target.
positionConfigComputePositionConfigThe position configuration handed over to floating-ui.
lightDismissbooleanfalseCloses the teaching tip on a click outside of it and its target.
withArrowbooleanfalseWhether the teaching tip has an arrow pointing at its target.
childrenSnippetThe parts of the teaching tip: a preview, a header, the content and a footer.
HTMLAttributes<HTMLDivElement> without children

Component Props (TeachingTipPreview)

NameTypeDefaultDescription
ref bindableHTMLDivElement | nullThe DOM reference of the preview element.
childrenSnippetThe media to preview, usually an image.
HTMLAttributes<HTMLDivElement> without children

Component Props (TeachingTipHeader)

NameTypeDefaultDescription
ref bindableHTMLDivElement | nullThe DOM reference of the header element.
titleSnippet | Component | stringThe title of the teaching tip. A snippet or a component receives the id the teaching tip is labelled by.
headingLevel1 | 2 | 3 | 4 | 5 | 63The level of the heading that holds a string title, to fit the headings of the page around it.
iconSnippet | ComponentThe icon rendered before the title.
descriptionSnippet | Component | stringA second line of text below the title.
stepnumberThe current step of a tour. The step counter shows when totalSteps is set too.
totalStepsnumberThe number of steps of a tour. The step counter shows when step is set too.
formatStep(step: number, totalSteps: number) => stringFormats the text of the step counter, which reads "1 of 3" by default.
hideCloseButtonbooleanRemoves the button that closes the teaching tip.
closeLabelstring'Close'The accessible name of the close button.
HTMLAttributes<HTMLDivElement> without children, title

Component Props (TeachingTipFooter)

NameTypeDefaultDescription
ref bindableHTMLDivElement | nullThe DOM reference of the footer element.
actionSnippet | ComponentThe actions rendered inside the footer.
HTMLAttributes<HTMLDivElement> without children

Support Fluent UI Svelte

The library is built by one person in their free time. If it helps your work, consider sponsoring it.