@bmsuisse/ui 0.15.0 → 0.16.0

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> {
@@ -741,6 +741,8 @@ interface KpiCardProps {
741
741
  segments?: DonutSegment[];
742
742
  /** Donut variant only: big label centered in the ring. Defaults to the sum of `segments`' values. */
743
743
  centerValue?: string;
744
+ /** Any CSS color/gradient, overriding the variant's default surface (`--color-primary` for `hero`, `bg-card` for the rest). */
745
+ background?: string;
744
746
  /** For E2E tests to target a specific tile unambiguously when `label` also appears elsewhere on the page (e.g. a chart legend). */
745
747
  testId?: string;
746
748
  }
@@ -918,6 +920,207 @@ declare function SidebarNav({ children, className, ...rest }: SidebarNavProps):
918
920
  */
919
921
  declare function useSidebarCollapsed(): boolean;
920
922
 
923
+ /** The three `buttonVariants` entries that carry the violet AI accent. */
924
+ type AiButtonVariant = "ai" | "ai-subtle" | "ai-ghost";
925
+ interface AiButtonProps extends Omit<ButtonProps, "variant"> {
926
+ /** `ai` = solid CTA, `ai-subtle` = tinted chip, `ai-ghost` = inline text action. @default "ai-subtle" */
927
+ variant?: AiButtonVariant;
928
+ /** Swaps the leading icon for a spinner and disables the button while an AI call is in flight. */
929
+ loading?: boolean;
930
+ /** Leading icon. @default Sparkles */
931
+ icon?: ElementType<NavIconProps>;
932
+ }
933
+ /**
934
+ * The "do something with AI" button: sparkle icon plus a built-in in-flight
935
+ * state on top of `Button`'s `ai*` variants. Forwards its ref like `Button`
936
+ * so it works as a Radix `asChild` trigger — `AiExplainButton` mounts one
937
+ * inside `PopoverTrigger`, which needs the DOM node to anchor the popover.
938
+ */
939
+ declare const AiButton: react.ForwardRefExoticComponent<AiButtonProps & react.RefAttributes<HTMLButtonElement>>;
940
+
941
+ interface AiExplainButtonProps extends Omit<AiButtonProps, "children" | "onClick" | "loading" | "title" | "aria-busy"> {
942
+ /**
943
+ * Produces the explanation, called the first time the popover opens (and on
944
+ * "Try again" after a failure) — not on mount, so nothing is spent on a
945
+ * button nobody clicks.
946
+ */
947
+ onExplain: () => Promise<ReactNode> | ReactNode;
948
+ /** Button text. @default "Explain" */
949
+ label?: string;
950
+ /** Heading inside the popover. @default the label */
951
+ title?: string;
952
+ /** Popover alignment relative to the button. @default "start" */
953
+ align?: "start" | "center" | "end";
954
+ /** Class names for the popover panel, e.g. to widen it. @default "w-80" */
955
+ contentClassName?: string;
956
+ }
957
+ /**
958
+ * "What am I looking at?" button: a sparkle affordance next to a chart, a KPI
959
+ * or a form field that opens a popover and lazily asks the caller's model to
960
+ * explain it. The caller returns any node, so an explanation can be prose,
961
+ * a list, or a small rendered breakdown. Every other prop (`variant`, `size`,
962
+ * `icon`, `data-testid`, ...) goes to the underlying `AiButton`.
963
+ */
964
+ declare function AiExplainButton({ onExplain, label, title, align, contentClassName, size, ...props }: AiExplainButtonProps): ReactElement;
965
+
966
+ interface SpeechRecognitionAlternative {
967
+ transcript: string;
968
+ }
969
+ interface SpeechRecognitionResult {
970
+ isFinal: boolean;
971
+ 0: SpeechRecognitionAlternative;
972
+ }
973
+ interface SpeechRecognitionEventLike {
974
+ resultIndex: number;
975
+ results: {
976
+ length: number;
977
+ [index: number]: SpeechRecognitionResult;
978
+ };
979
+ }
980
+ /**
981
+ * The recognizer contract `useSpeechRecognition` drives — matches the shape
982
+ * of the browser's built-in `SpeechRecognition`/`webkitSpeechRecognition`,
983
+ * which is also what the default engine (below) wraps. Implement this to
984
+ * swap in something other than the browser's on-device recognizer — for
985
+ * example a server-side transcription API — via the `engine` option.
986
+ * Whatever backs it, finalized chunks and interim words must arrive through
987
+ * `onresult` the same way the Web Speech API delivers them.
988
+ */
989
+ interface SpeechRecognitionEngine {
990
+ lang: string;
991
+ continuous: boolean;
992
+ interimResults: boolean;
993
+ start(): void;
994
+ stop(): void;
995
+ abort(): void;
996
+ onresult: ((event: SpeechRecognitionEventLike) => void) | null;
997
+ onerror: ((event: {
998
+ error: string;
999
+ }) => void) | null;
1000
+ onend: (() => void) | null;
1001
+ }
1002
+ /** Builds one `SpeechRecognitionEngine` per dictation session (`start()` calls it fresh each time). */
1003
+ type SpeechRecognitionEngineFactory = () => SpeechRecognitionEngine;
1004
+ /**
1005
+ * Turns a recognizer error code into a sentence a user can act on, or `null`
1006
+ * for codes that aren't the user's problem (`aborted` fires on every
1007
+ * programmatic stop/unmount and would otherwise flash an alert on each one).
1008
+ * `onError` still receives the raw code, for callers who want to branch.
1009
+ */
1010
+ declare function describeSpeechError(code: string): string | null;
1011
+ interface UseSpeechRecognitionOptions {
1012
+ /** BCP-47 tag passed to the recognizer, e.g. `"de-CH"`. @default the document language, else "en-US" */
1013
+ lang?: string;
1014
+ /** Called with each finalized chunk of speech. */
1015
+ onResult?: (text: string) => void;
1016
+ /** Called when the recognizer reports an error (`"not-allowed"`, `"no-speech"`, ...). */
1017
+ onError?: (error: string) => void;
1018
+ /**
1019
+ * Overrides what backs dictation — e.g. to stream audio to a server-side
1020
+ * transcription API instead of the browser's on-device `SpeechRecognition`.
1021
+ * Called once per `start()` to build that session's engine; must satisfy
1022
+ * `SpeechRecognitionEngine`. Omit to use the browser's Web Speech API
1023
+ * (`supported` then reflects whether that API exists); passing `engine`
1024
+ * makes `supported` unconditionally `true`, since the caller's factory is
1025
+ * assumed to work wherever the app decides to render the button.
1026
+ */
1027
+ engine?: SpeechRecognitionEngineFactory;
1028
+ }
1029
+ interface SpeechRecognitionState {
1030
+ /** False when neither a custom `engine` nor the browser's Web Speech API is available (Firefox, most of mobile, SSR). */
1031
+ supported: boolean;
1032
+ listening: boolean;
1033
+ /** The not-yet-finalized words the recognizer is still revising. */
1034
+ interim: string;
1035
+ error: string | null;
1036
+ start: () => void;
1037
+ stop: () => void;
1038
+ toggle: () => void;
1039
+ }
1040
+ /**
1041
+ * Thin hook over a `SpeechRecognitionEngine` — by default the browser's
1042
+ * built-in `SpeechRecognition`, so no dependency and no server round-trip;
1043
+ * pass `engine` to back it with something else (e.g. a server-side
1044
+ * transcription API) instead. Finalized chunks are pushed to `onResult`;
1045
+ * the caller owns the accumulated transcript (so it stays editable), this
1046
+ * only reports what's currently being heard.
1047
+ */
1048
+ declare function useSpeechRecognition({ lang, onResult, onError, engine, }?: UseSpeechRecognitionOptions): SpeechRecognitionState;
1049
+
1050
+ interface VoiceInputButtonProps extends Omit<ButtonProps, "onError" | "variant" | "children"> {
1051
+ /** Called with each finalized chunk of speech, ready to append to whatever the caller is filling in. */
1052
+ onTranscript: (text: string) => void;
1053
+ /** Called with the recognizer's raw error code (`"not-allowed"`, `"no-speech"`, ...) — see `describeSpeechError` for user-facing text. */
1054
+ onError?: (error: string) => void;
1055
+ /** BCP-47 tag, e.g. `"de-CH"`. Defaults to the document language. */
1056
+ lang?: string;
1057
+ /**
1058
+ * Overrides what backs dictation — e.g. to stream audio to a server-side
1059
+ * transcription API instead of the browser's on-device `SpeechRecognition`.
1060
+ * See `useSpeechRecognition`'s `engine` option. Passing this makes the
1061
+ * button render enabled unconditionally, since browser support no longer
1062
+ * applies.
1063
+ */
1064
+ engine?: SpeechRecognitionEngineFactory;
1065
+ /** Rendered next to the icon. Icon-only (the default) when omitted. */
1066
+ label?: string;
1067
+ /** Accessible name while idle (icon-only buttons only). @default "Start dictation" */
1068
+ startLabel?: string;
1069
+ /** Accessible name while listening (icon-only buttons only). @default "Stop dictation" */
1070
+ stopLabel?: string;
1071
+ /** Renders the interim (not yet finalized) words next to the button. @default false */
1072
+ showInterim?: boolean;
1073
+ }
1074
+ /**
1075
+ * Push-to-dictate microphone button, backed by the browser's built-in
1076
+ * `SpeechRecognition` by default — no API key, no upload, no extra
1077
+ * dependency. Pass `engine` to back it with something else instead, such as
1078
+ * a server-side transcription API (see `useSpeechRecognition`'s `engine`
1079
+ * option). While listening it takes the `destructive` tint (the same one
1080
+ * AlertBox's `error` uses) and only the mic icon pulses, so the "recording"
1081
+ * signal reads at a glance without the whole control throbbing. Where
1082
+ * neither `engine` nor the browser API is available (Firefox, most mobile)
1083
+ * the button renders disabled with a crossed-out mic rather than vanishing,
1084
+ * so the layout doesn't shift between browsers.
1085
+ */
1086
+ declare const VoiceInputButton: react.ForwardRefExoticComponent<VoiceInputButtonProps & react.RefAttributes<HTMLButtonElement>>;
1087
+
1088
+ interface VoiceTranscriptProps extends Omit<HTMLAttributes<HTMLDivElement>, "onChange"> {
1089
+ /** The transcript. Controlled, like `SearchBar` — the caller owns the text. */
1090
+ value: string;
1091
+ onChange: (value: string) => void;
1092
+ /**
1093
+ * Rewrites the transcript with AI (clean up, translate, summarize —
1094
+ * whatever the caller's model does) and resolves with the new text.
1095
+ * Omitted hides the transform button, leaving plain dictation.
1096
+ */
1097
+ onTransform?: (text: string) => Promise<string> | string;
1098
+ /** @default "Transform with AI" */
1099
+ transformLabel?: string;
1100
+ /** @default "Speak or type…" */
1101
+ placeholder?: string;
1102
+ /** BCP-47 tag for dictation, e.g. `"de-CH"`. Defaults to the document language. */
1103
+ lang?: string;
1104
+ /**
1105
+ * Overrides what backs dictation — e.g. to stream audio to a server-side
1106
+ * transcription API instead of the browser's on-device `SpeechRecognition`.
1107
+ * Forwarded to `VoiceInputButton`; see `useSpeechRecognition`'s `engine`
1108
+ * option.
1109
+ */
1110
+ engine?: SpeechRecognitionEngineFactory;
1111
+ /** @default 4 */
1112
+ rows?: number;
1113
+ disabled?: boolean;
1114
+ className?: string;
1115
+ }
1116
+ /**
1117
+ * Dictate → edit → rewrite-with-AI, in one box: a mic button feeding an
1118
+ * editable transcript, plus a "Transform with AI" action that hands the text
1119
+ * to the caller's model and swaps in the result (with one-click undo, since
1120
+ * a model rewriting your own words is exactly where you want an escape hatch).
1121
+ */
1122
+ declare function VoiceTranscript({ value, onChange, onTransform, transformLabel, placeholder, lang, engine, rows, disabled, className, ...props }: VoiceTranscriptProps): ReactElement;
1123
+
921
1124
  /** The minimal shape this component needs to render one chip in the stepper. */
922
1125
  interface StepperStep {
923
1126
  /** 1-based step number, also used as the React key and navigation target. */
@@ -991,4 +1194,4 @@ type ConfirmButtonPlacement = "leading" | "trailing";
991
1194
  */
992
1195
  declare function getConfirmButtonPlacement(): ConfirmButtonPlacement;
993
1196
 
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 };
1197
+ 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, 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, 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 };