@bmsuisse/ui 0.15.0 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -15,7 +15,7 @@ import * as TooltipPrimitive from '@radix-ui/react-tooltip';
15
15
  import { ClassValue } from 'clsx';
16
16
 
17
17
  declare const buttonVariants: (props?: ({
18
- variant?: "default" | "outline" | "ghost" | "destructive" | "secondary" | "link" | "swiss-primary" | "swiss-secondary" | null | undefined;
18
+ variant?: "default" | "outline" | "ghost" | "destructive" | "secondary" | "link" | "swiss-primary" | "swiss-secondary" | "ai" | "ai-subtle" | "ai-ghost" | null | undefined;
19
19
  size?: "default" | "xs" | "sm" | "lg" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" | null | undefined;
20
20
  } & class_variance_authority_types.ClassProp) | undefined) => string;
21
21
  interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
@@ -55,6 +55,7 @@ declare const DialogContent: react.ForwardRefExoticComponent<Omit<DialogPrimitiv
55
55
  declare const DialogHeader: ({ className, ...props }: HTMLAttributes<HTMLDivElement>) => ReactElement;
56
56
  declare const DialogTitle: react.ForwardRefExoticComponent<Omit<DialogPrimitive.DialogTitleProps & react.RefAttributes<HTMLHeadingElement>, "ref"> & react.RefAttributes<HTMLHeadingElement>>;
57
57
  declare const DialogDescription: react.ForwardRefExoticComponent<Omit<DialogPrimitive.DialogDescriptionProps & react.RefAttributes<HTMLParagraphElement>, "ref"> & react.RefAttributes<HTMLParagraphElement>>;
58
+ declare const DialogBody: ({ className, ...props }: HTMLAttributes<HTMLDivElement>) => ReactElement;
58
59
  declare const DialogFooter: ({ className, ...props }: HTMLAttributes<HTMLDivElement>) => ReactElement;
59
60
 
60
61
  declare const Popover: react.FC<PopoverPrimitive.PopoverProps>;
@@ -144,6 +145,7 @@ interface SheetContentProps extends ComponentPropsWithoutRef<typeof DialogPrimit
144
145
  }
145
146
  declare const SheetContent: react.ForwardRefExoticComponent<SheetContentProps & react.RefAttributes<HTMLDivElement>>;
146
147
  declare const SheetHeader: ({ className, ...props }: HTMLAttributes<HTMLDivElement>) => ReactElement;
148
+ declare const SheetBody: ({ className, ...props }: HTMLAttributes<HTMLDivElement>) => ReactElement;
147
149
  declare const SheetFooter: ({ className, ...props }: HTMLAttributes<HTMLDivElement>) => ReactElement;
148
150
  declare const SheetTitle: react.ForwardRefExoticComponent<Omit<DialogPrimitive.DialogTitleProps & react.RefAttributes<HTMLHeadingElement>, "ref"> & react.RefAttributes<HTMLHeadingElement>>;
149
151
  declare const SheetDescription: react.ForwardRefExoticComponent<Omit<DialogPrimitive.DialogDescriptionProps & react.RefAttributes<HTMLParagraphElement>, "ref"> & react.RefAttributes<HTMLParagraphElement>>;
@@ -741,6 +743,8 @@ interface KpiCardProps {
741
743
  segments?: DonutSegment[];
742
744
  /** Donut variant only: big label centered in the ring. Defaults to the sum of `segments`' values. */
743
745
  centerValue?: string;
746
+ /** Any CSS color/gradient, overriding the variant's default surface (`--color-primary` for `hero`, `bg-card` for the rest). */
747
+ background?: string;
744
748
  /** For E2E tests to target a specific tile unambiguously when `label` also appears elsewhere on the page (e.g. a chart legend). */
745
749
  testId?: string;
746
750
  }
@@ -918,6 +922,207 @@ declare function SidebarNav({ children, className, ...rest }: SidebarNavProps):
918
922
  */
919
923
  declare function useSidebarCollapsed(): boolean;
920
924
 
925
+ /** The three `buttonVariants` entries that carry the violet AI accent. */
926
+ type AiButtonVariant = "ai" | "ai-subtle" | "ai-ghost";
927
+ interface AiButtonProps extends Omit<ButtonProps, "variant"> {
928
+ /** `ai` = solid CTA, `ai-subtle` = tinted chip, `ai-ghost` = inline text action. @default "ai-subtle" */
929
+ variant?: AiButtonVariant;
930
+ /** Swaps the leading icon for a spinner and disables the button while an AI call is in flight. */
931
+ loading?: boolean;
932
+ /** Leading icon. @default Sparkles */
933
+ icon?: ElementType<NavIconProps>;
934
+ }
935
+ /**
936
+ * The "do something with AI" button: sparkle icon plus a built-in in-flight
937
+ * state on top of `Button`'s `ai*` variants. Forwards its ref like `Button`
938
+ * so it works as a Radix `asChild` trigger — `AiExplainButton` mounts one
939
+ * inside `PopoverTrigger`, which needs the DOM node to anchor the popover.
940
+ */
941
+ declare const AiButton: react.ForwardRefExoticComponent<AiButtonProps & react.RefAttributes<HTMLButtonElement>>;
942
+
943
+ interface AiExplainButtonProps extends Omit<AiButtonProps, "children" | "onClick" | "loading" | "title" | "aria-busy"> {
944
+ /**
945
+ * Produces the explanation, called the first time the popover opens (and on
946
+ * "Try again" after a failure) — not on mount, so nothing is spent on a
947
+ * button nobody clicks.
948
+ */
949
+ onExplain: () => Promise<ReactNode> | ReactNode;
950
+ /** Button text. @default "Explain" */
951
+ label?: string;
952
+ /** Heading inside the popover. @default the label */
953
+ title?: string;
954
+ /** Popover alignment relative to the button. @default "start" */
955
+ align?: "start" | "center" | "end";
956
+ /** Class names for the popover panel, e.g. to widen it. @default "w-80" */
957
+ contentClassName?: string;
958
+ }
959
+ /**
960
+ * "What am I looking at?" button: a sparkle affordance next to a chart, a KPI
961
+ * or a form field that opens a popover and lazily asks the caller's model to
962
+ * explain it. The caller returns any node, so an explanation can be prose,
963
+ * a list, or a small rendered breakdown. Every other prop (`variant`, `size`,
964
+ * `icon`, `data-testid`, ...) goes to the underlying `AiButton`.
965
+ */
966
+ declare function AiExplainButton({ onExplain, label, title, align, contentClassName, size, ...props }: AiExplainButtonProps): ReactElement;
967
+
968
+ interface SpeechRecognitionAlternative {
969
+ transcript: string;
970
+ }
971
+ interface SpeechRecognitionResult {
972
+ isFinal: boolean;
973
+ 0: SpeechRecognitionAlternative;
974
+ }
975
+ interface SpeechRecognitionEventLike {
976
+ resultIndex: number;
977
+ results: {
978
+ length: number;
979
+ [index: number]: SpeechRecognitionResult;
980
+ };
981
+ }
982
+ /**
983
+ * The recognizer contract `useSpeechRecognition` drives — matches the shape
984
+ * of the browser's built-in `SpeechRecognition`/`webkitSpeechRecognition`,
985
+ * which is also what the default engine (below) wraps. Implement this to
986
+ * swap in something other than the browser's on-device recognizer — for
987
+ * example a server-side transcription API — via the `engine` option.
988
+ * Whatever backs it, finalized chunks and interim words must arrive through
989
+ * `onresult` the same way the Web Speech API delivers them.
990
+ */
991
+ interface SpeechRecognitionEngine {
992
+ lang: string;
993
+ continuous: boolean;
994
+ interimResults: boolean;
995
+ start(): void;
996
+ stop(): void;
997
+ abort(): void;
998
+ onresult: ((event: SpeechRecognitionEventLike) => void) | null;
999
+ onerror: ((event: {
1000
+ error: string;
1001
+ }) => void) | null;
1002
+ onend: (() => void) | null;
1003
+ }
1004
+ /** Builds one `SpeechRecognitionEngine` per dictation session (`start()` calls it fresh each time). */
1005
+ type SpeechRecognitionEngineFactory = () => SpeechRecognitionEngine;
1006
+ /**
1007
+ * Turns a recognizer error code into a sentence a user can act on, or `null`
1008
+ * for codes that aren't the user's problem (`aborted` fires on every
1009
+ * programmatic stop/unmount and would otherwise flash an alert on each one).
1010
+ * `onError` still receives the raw code, for callers who want to branch.
1011
+ */
1012
+ declare function describeSpeechError(code: string): string | null;
1013
+ interface UseSpeechRecognitionOptions {
1014
+ /** BCP-47 tag passed to the recognizer, e.g. `"de-CH"`. @default the document language, else "en-US" */
1015
+ lang?: string;
1016
+ /** Called with each finalized chunk of speech. */
1017
+ onResult?: (text: string) => void;
1018
+ /** Called when the recognizer reports an error (`"not-allowed"`, `"no-speech"`, ...). */
1019
+ onError?: (error: string) => void;
1020
+ /**
1021
+ * Overrides what backs dictation — e.g. to stream audio to a server-side
1022
+ * transcription API instead of the browser's on-device `SpeechRecognition`.
1023
+ * Called once per `start()` to build that session's engine; must satisfy
1024
+ * `SpeechRecognitionEngine`. Omit to use the browser's Web Speech API
1025
+ * (`supported` then reflects whether that API exists); passing `engine`
1026
+ * makes `supported` unconditionally `true`, since the caller's factory is
1027
+ * assumed to work wherever the app decides to render the button.
1028
+ */
1029
+ engine?: SpeechRecognitionEngineFactory;
1030
+ }
1031
+ interface SpeechRecognitionState {
1032
+ /** False when neither a custom `engine` nor the browser's Web Speech API is available (Firefox, most of mobile, SSR). */
1033
+ supported: boolean;
1034
+ listening: boolean;
1035
+ /** The not-yet-finalized words the recognizer is still revising. */
1036
+ interim: string;
1037
+ error: string | null;
1038
+ start: () => void;
1039
+ stop: () => void;
1040
+ toggle: () => void;
1041
+ }
1042
+ /**
1043
+ * Thin hook over a `SpeechRecognitionEngine` — by default the browser's
1044
+ * built-in `SpeechRecognition`, so no dependency and no server round-trip;
1045
+ * pass `engine` to back it with something else (e.g. a server-side
1046
+ * transcription API) instead. Finalized chunks are pushed to `onResult`;
1047
+ * the caller owns the accumulated transcript (so it stays editable), this
1048
+ * only reports what's currently being heard.
1049
+ */
1050
+ declare function useSpeechRecognition({ lang, onResult, onError, engine, }?: UseSpeechRecognitionOptions): SpeechRecognitionState;
1051
+
1052
+ interface VoiceInputButtonProps extends Omit<ButtonProps, "onError" | "variant" | "children"> {
1053
+ /** Called with each finalized chunk of speech, ready to append to whatever the caller is filling in. */
1054
+ onTranscript: (text: string) => void;
1055
+ /** Called with the recognizer's raw error code (`"not-allowed"`, `"no-speech"`, ...) — see `describeSpeechError` for user-facing text. */
1056
+ onError?: (error: string) => void;
1057
+ /** BCP-47 tag, e.g. `"de-CH"`. Defaults to the document language. */
1058
+ lang?: string;
1059
+ /**
1060
+ * Overrides what backs dictation — e.g. to stream audio to a server-side
1061
+ * transcription API instead of the browser's on-device `SpeechRecognition`.
1062
+ * See `useSpeechRecognition`'s `engine` option. Passing this makes the
1063
+ * button render enabled unconditionally, since browser support no longer
1064
+ * applies.
1065
+ */
1066
+ engine?: SpeechRecognitionEngineFactory;
1067
+ /** Rendered next to the icon. Icon-only (the default) when omitted. */
1068
+ label?: string;
1069
+ /** Accessible name while idle (icon-only buttons only). @default "Start dictation" */
1070
+ startLabel?: string;
1071
+ /** Accessible name while listening (icon-only buttons only). @default "Stop dictation" */
1072
+ stopLabel?: string;
1073
+ /** Renders the interim (not yet finalized) words next to the button. @default false */
1074
+ showInterim?: boolean;
1075
+ }
1076
+ /**
1077
+ * Push-to-dictate microphone button, backed by the browser's built-in
1078
+ * `SpeechRecognition` by default — no API key, no upload, no extra
1079
+ * dependency. Pass `engine` to back it with something else instead, such as
1080
+ * a server-side transcription API (see `useSpeechRecognition`'s `engine`
1081
+ * option). While listening it takes the `destructive` tint (the same one
1082
+ * AlertBox's `error` uses) and only the mic icon pulses, so the "recording"
1083
+ * signal reads at a glance without the whole control throbbing. Where
1084
+ * neither `engine` nor the browser API is available (Firefox, most mobile)
1085
+ * the button renders disabled with a crossed-out mic rather than vanishing,
1086
+ * so the layout doesn't shift between browsers.
1087
+ */
1088
+ declare const VoiceInputButton: react.ForwardRefExoticComponent<VoiceInputButtonProps & react.RefAttributes<HTMLButtonElement>>;
1089
+
1090
+ interface VoiceTranscriptProps extends Omit<HTMLAttributes<HTMLDivElement>, "onChange"> {
1091
+ /** The transcript. Controlled, like `SearchBar` — the caller owns the text. */
1092
+ value: string;
1093
+ onChange: (value: string) => void;
1094
+ /**
1095
+ * Rewrites the transcript with AI (clean up, translate, summarize —
1096
+ * whatever the caller's model does) and resolves with the new text.
1097
+ * Omitted hides the transform button, leaving plain dictation.
1098
+ */
1099
+ onTransform?: (text: string) => Promise<string> | string;
1100
+ /** @default "Transform with AI" */
1101
+ transformLabel?: string;
1102
+ /** @default "Speak or type…" */
1103
+ placeholder?: string;
1104
+ /** BCP-47 tag for dictation, e.g. `"de-CH"`. Defaults to the document language. */
1105
+ lang?: string;
1106
+ /**
1107
+ * Overrides what backs dictation — e.g. to stream audio to a server-side
1108
+ * transcription API instead of the browser's on-device `SpeechRecognition`.
1109
+ * Forwarded to `VoiceInputButton`; see `useSpeechRecognition`'s `engine`
1110
+ * option.
1111
+ */
1112
+ engine?: SpeechRecognitionEngineFactory;
1113
+ /** @default 4 */
1114
+ rows?: number;
1115
+ disabled?: boolean;
1116
+ className?: string;
1117
+ }
1118
+ /**
1119
+ * Dictate → edit → rewrite-with-AI, in one box: a mic button feeding an
1120
+ * editable transcript, plus a "Transform with AI" action that hands the text
1121
+ * to the caller's model and swaps in the result (with one-click undo, since
1122
+ * a model rewriting your own words is exactly where you want an escape hatch).
1123
+ */
1124
+ declare function VoiceTranscript({ value, onChange, onTransform, transformLabel, placeholder, lang, engine, rows, disabled, className, ...props }: VoiceTranscriptProps): ReactElement;
1125
+
921
1126
  /** The minimal shape this component needs to render one chip in the stepper. */
922
1127
  interface StepperStep {
923
1128
  /** 1-based step number, also used as the React key and navigation target. */
@@ -991,4 +1196,4 @@ type ConfirmButtonPlacement = "leading" | "trailing";
991
1196
  */
992
1197
  declare function getConfirmButtonPlacement(): ConfirmButtonPlacement;
993
1198
 
994
- export { AlertBox, type AlertBoxProps, type AlertBoxVariant, Badge, type BadgeProps, Button, ButtonGroup, type ButtonGroupOption, type ButtonGroupProps, type ButtonProps, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, Combobox, type GridColumn as ComboboxColumn, type ComboboxMultiProps, type ComboboxOption, type ComboboxProps, type ComboboxSingleProps, type ConfirmButtonPlacement, ConfirmDialog, type ConfirmDialogProps, Dialog, DialogActions, type DialogActionsProps, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, DonutChart, type DonutSegment, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, FormField, type FormFieldProps, FormModal, type FormModalProps, Input, type InputProps, KpiCard, type KpiCardProps, Label, LoadingOverlay, type LoadingOverlayProps, LoadingSpinner, type LoadingSpinnerProps, Modal, type ModalProps, NavGroup, type NavGroupProps, type NavIconProps, NavItem, type NavItemProps, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, QuestionDialog, type QuestionDialogAction, type QuestionDialogProps, ResponsivePanel, type ResponsivePanelProps, type ResponsivePanelSize, ScrollArea, ScrollBar, SearchBar, type SearchBarProps, SearchPanel, type SearchPanelMode, type SearchPanelProps, SearchTrigger, type SearchTriggerProps, Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, type SelectTriggerProps, SelectValue, Separator, Sheet, SheetClose, SheetContent, type SheetContentProps, SheetDescription, SheetFooter, SheetHeader, SheetPortal, SheetTitle, SheetTrigger, Sidebar, SidebarNav, type SidebarNavProps, type SidebarProps, Skeleton, Sparkline, StatusBadge, type StatusBadgeProps, type StatusTone, Stepper, type StepperProps, type StepperStep, Switch, type SwitchProps, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, TagCombobox, type TagComboboxOption, type TagComboboxProps, Textarea, type TextareaProps, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, badgeVariants, buttonVariants, cn, getConfirmButtonPlacement, isWindowsPlatform, loadingSpinnerIconVariants, sheetVariants, useMediaQuery, useSidebarCollapsed };
1199
+ export { AiButton, type AiButtonProps, type AiButtonVariant, AiExplainButton, type AiExplainButtonProps, AlertBox, type AlertBoxProps, type AlertBoxVariant, Badge, type BadgeProps, Button, ButtonGroup, type ButtonGroupOption, type ButtonGroupProps, type ButtonProps, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, Combobox, type GridColumn as ComboboxColumn, type ComboboxMultiProps, type ComboboxOption, type ComboboxProps, type ComboboxSingleProps, type ConfirmButtonPlacement, ConfirmDialog, type ConfirmDialogProps, Dialog, DialogActions, type DialogActionsProps, DialogBody, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, DonutChart, type DonutSegment, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, FormField, type FormFieldProps, FormModal, type FormModalProps, Input, type InputProps, KpiCard, type KpiCardProps, Label, LoadingOverlay, type LoadingOverlayProps, LoadingSpinner, type LoadingSpinnerProps, Modal, type ModalProps, NavGroup, type NavGroupProps, type NavIconProps, NavItem, type NavItemProps, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, QuestionDialog, type QuestionDialogAction, type QuestionDialogProps, ResponsivePanel, type ResponsivePanelProps, type ResponsivePanelSize, ScrollArea, ScrollBar, SearchBar, type SearchBarProps, SearchPanel, type SearchPanelMode, type SearchPanelProps, SearchTrigger, type SearchTriggerProps, Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, type SelectTriggerProps, SelectValue, Separator, Sheet, SheetBody, SheetClose, SheetContent, type SheetContentProps, SheetDescription, SheetFooter, SheetHeader, SheetPortal, SheetTitle, SheetTrigger, Sidebar, SidebarNav, type SidebarNavProps, type SidebarProps, Skeleton, Sparkline, type SpeechRecognitionEngine, type SpeechRecognitionEngineFactory, type SpeechRecognitionState, StatusBadge, type StatusBadgeProps, type StatusTone, Stepper, type StepperProps, type StepperStep, Switch, type SwitchProps, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, TagCombobox, type TagComboboxOption, type TagComboboxProps, Textarea, type TextareaProps, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, type UseSpeechRecognitionOptions, VoiceInputButton, type VoiceInputButtonProps, VoiceTranscript, type VoiceTranscriptProps, badgeVariants, buttonVariants, cn, describeSpeechError, getConfirmButtonPlacement, isWindowsPlatform, loadingSpinnerIconVariants, sheetVariants, useMediaQuery, useSidebarCollapsed, useSpeechRecognition };