Synertech Web/ui v0.57.5 Site Storybook

Documentation / Feedback & overlays

HelpButton

Client@synertech/uiOpen in Storybook

A small round “?” button that opens a contextual help bubble next to a field or a heading. The content is a text, interpreted as HTML reduced to its formatting (headings, lists, links, code, tables: no style, no form, no image), Markdown with markdown (GFM: lists, tables, code…, no image either) or any React node. The bubble closes on an outside click and on Escape. WithHelpButton places the button right after its children.

With editable, a pencil in the header lets the help be rewritten in place: onSave(content) receives the text and returns true (or a promise of true) if the save succeeded; passing the new text back into content is up to you. onReset adds a reset button. To edit Markdown, pass MarkdownEditor (separate entry @synertech/ui/markdown-editor) to the markdownEditor prop. "use client" component.

Examples

Basic usage

A short plain-text help, opened below the button by default.

Open in a tab
import { HelpButton } from "@synertech/ui";

export function Basic() {
  return <HelpButton content="Le SIRET comporte 14 chiffres, sans espace." />;
}

Next to a label

WithHelpButton lines the button up after its children; title adds a header to the bubble.

Open in a tab
import { WithHelpButton } from "@synertech/ui";

export function NextToLabel() {
  return (
    <WithHelpButton
      title="Taux de conversion"
      content="Part des visiteurs ayant passé au moins une commande sur la période."
      position="right"
    >
      <span className="text-sm font-medium text-gray-700 dark:text-gray-300">
        Taux de conversion
      </span>
    </WithHelpButton>
  );
}

Markdown content

markdown interprets the text (headings, lists, code, links); width widens the bubble.

Open in a tab
import { HelpButton } from "@synertech/ui";

export function Markdown() {
  return (
    <HelpButton
      markdown
      width="lg"
      title="Format d’import"
      content={`Le fichier CSV doit contenir :

- une colonne \`email\` **obligatoire** ;
- une colonne \`nom\` facultative.

Séparateur accepté : \`;\` ou \`,\`.`}
    />
  );
}

React content, sizes and positions

content accepts JSX; size sets the button, position the side of the bubble.

Open in a tab
import { HelpButton } from "@synertech/ui";

export function RichContent() {
  return (
    <div className="flex items-center gap-6 p-8">
      <HelpButton size="xs" position="top" content="Petit bouton, bulle au-dessus." />
      <HelpButton
        size="lg"
        position="right"
        width="sm"
        content={
          <ul className="list-disc pl-4">
            <li>8 caractères minimum</li>
            <li>une majuscule et un chiffre</li>
          </ul>
        }
      />
    </div>
  );
}

Editable help

editable opens a text area; onSave persists the text and passes it back up into content.

Open in a tab
import { useState } from "react";
import { HelpButton } from "@synertech/ui";

export function Editable() {
  const [help, setHelp] = useState("Indiquez le numéro de commande figurant sur votre facture.");
  const initial = "Indiquez le numéro de commande figurant sur votre facture.";

  const save = async (content: string) => {
    await new Promise((resolve) => setTimeout(resolve, 500));
    setHelp(content);
    return true;
  };

  return (
    <HelpButton
      editable
      title="Numéro de commande"
      content={help}
      onSave={save}
      onReset={() => {
        setHelp(initial);
        return true;
      }}
    />
  );
}

API reference

Components

HelpButton

ComponentClient
import { HelpButton } from "@synertech/ui";

Props — HelpButtonProps

PropTypeDefaultDescription
content• string | ReactNode —

What the bubble shows: a node as it is, a string as Markdown under markdown, and as HTML otherwise. That HTML keeps the formatting Markdown produces — headings, paragraphs, lists, links, code, quotes, tables — and nothing else: <style>, forms and their fields, images and frames are dropped, and so are class, style, id and name. A link keeps an http:, https:, mailto:, tel: or relative address. Neither mode shows an image: a help that needs one is given as a node.

className string ""
editable boolean false
labels UILabelsOf<"helpButton" | "markdownEditor"> —

The strings the button writes itself, for this instance: any helpButton… key of UILabels, and markdownEditorPlaceholder. Wins over UILabelsProvider.

markdown boolean false
markdownEditor MarkdownEditorComponent —

Editor rendered when both markdown and editable are set: pass MarkdownEditor from @synertech/ui/markdown-editor. It lives in its own entry point so apps that never edit Markdown don't have to install or bundle its dependency.

markdownEditorUnavailableLabel string —

Shown in place of the editor when markdownEditor is missing. Defaults to the UILabels value.

onReset () => Promise<boolean> | boolean —
onSave (content: string) => Promise<boolean> | boolean —
position "top" | "bottom" | "left" | "right" "bottom"
size "xs" | "sm" | "md" | "lg" "sm"
title string —
visible boolean true
width "sm" | "md" | "lg" | "xl" "md"

WithHelpButton

ComponentClient
import { WithHelpButton } from "@synertech/ui";

Props — WithHelpButtonProps

PropTypeDefaultDescription
children• ReactNode —
content• string | ReactNode —

What the bubble shows: a node as it is, a string as Markdown under markdown, and as HTML otherwise. That HTML keeps the formatting Markdown produces — headings, paragraphs, lists, links, code, quotes, tables — and nothing else: <style>, forms and their fields, images and frames are dropped, and so are class, style, id and name. A link keeps an http:, https:, mailto:, tel: or relative address. Neither mode shows an image: a help that needs one is given as a node.

className string —
editable boolean false
labels UILabelsOf<"helpButton" | "markdownEditor"> —

The strings the button writes itself, for this instance: any helpButton… key of UILabels, and markdownEditorPlaceholder. Wins over UILabelsProvider.

markdown boolean false
markdownEditor MarkdownEditorComponent —

Editor rendered when both markdown and editable are set: pass MarkdownEditor from @synertech/ui/markdown-editor. It lives in its own entry point so apps that never edit Markdown don't have to install or bundle its dependency.

markdownEditorUnavailableLabel string —

Shown in place of the editor when markdownEditor is missing. Defaults to the UILabels value.

onReset () => Promise<boolean> | boolean —
onSave (content: string) => Promise<boolean> | boolean —
position "top" | "bottom" | "left" | "right" "bottom"
size "xs" | "sm" | "md" | "lg" "sm"
title string —
visible boolean true
width "sm" | "md" | "lg" | "xl" "md"

Types

Any component accepting MarkdownEditorProps. The stock one is MarkdownEditor from @synertech/ui/markdown-editor.

type MarkdownEditorComponent = ComponentType<MarkdownEditorProps>