@carbonid1/design-system 5.19.0 → 6.0.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.
Files changed (48) hide show
  1. package/README.md +26 -7
  2. package/dist/Button/Button.js +2 -1
  3. package/dist/ContextMenu/ContextMenu.js +9 -8
  4. package/dist/Dialog/Dialog.js +4 -3
  5. package/dist/Field/Field.d.ts +10 -0
  6. package/dist/Field/Field.js +19 -0
  7. package/dist/Field/Field.types.d.ts +24 -0
  8. package/dist/Field/Field.types.js +1 -0
  9. package/dist/Input/Input.js +2 -1
  10. package/dist/InputGroup/InputGroup.js +4 -3
  11. package/dist/Menu/Menu.js +9 -8
  12. package/dist/MeterRing/MeterRing.d.ts +2 -0
  13. package/dist/MeterRing/MeterRing.js +9 -0
  14. package/dist/MeterRing/MeterRing.types.d.ts +9 -0
  15. package/dist/MeterRing/MeterRing.types.js +1 -0
  16. package/dist/ProgressRing/ProgressRing.d.ts +2 -10
  17. package/dist/ProgressRing/ProgressRing.js +8 -11
  18. package/dist/ProgressRing/ProgressRing.types.d.ts +13 -0
  19. package/dist/ProgressRing/ProgressRing.types.js +1 -0
  20. package/dist/RingVisual/RingVisual.d.ts +11 -0
  21. package/dist/RingVisual/RingVisual.js +20 -0
  22. package/dist/RingVisual/RingVisual.types.d.ts +1 -0
  23. package/dist/RingVisual/RingVisual.types.js +1 -0
  24. package/dist/ScrollArea/ScrollArea.js +7 -6
  25. package/dist/Select/Select.d.ts +48 -1
  26. package/dist/Select/Select.js +51 -91
  27. package/dist/Select/Select.types.d.ts +7 -0
  28. package/dist/Slider/Slider.d.ts +12 -12
  29. package/dist/Slider/Slider.js +25 -3
  30. package/dist/Slider/Slider.types.d.ts +34 -0
  31. package/dist/Slider/Slider.types.js +1 -0
  32. package/dist/ThemeCycler/ThemeCycler.js +1 -1
  33. package/dist/Toaster/Toaster.d.ts +4 -2
  34. package/dist/Toaster/Toaster.js +58 -3
  35. package/dist/Toaster/Toaster.types.d.ts +26 -0
  36. package/dist/Toaster/Toaster.types.js +1 -0
  37. package/dist/Tooltip/Tooltip.d.ts +25 -2
  38. package/dist/Tooltip/Tooltip.js +30 -114
  39. package/dist/helpers/mergeStatefulClassName/mergeStatefulClassName.d.ts +3 -0
  40. package/dist/helpers/mergeStatefulClassName/mergeStatefulClassName.js +4 -0
  41. package/dist/index.d.ts +11 -4
  42. package/dist/index.js +3 -2
  43. package/package.json +3 -5
  44. package/skills/design-system/SKILL.md +5 -1
  45. package/dist/helpers/tooltipPlacement/tooltipPlacement.d.ts +0 -38
  46. package/dist/helpers/tooltipPlacement/tooltipPlacement.js +0 -26
  47. /package/dist/{ProgressRing/ProgressRing.consts.d.ts → RingVisual/RingVisual.consts.d.ts} +0 -0
  48. /package/dist/{ProgressRing/ProgressRing.consts.js → RingVisual/RingVisual.consts.js} +0 -0
@@ -1,96 +1,56 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Select as BaseSelect } from '@base-ui/react/select';
3
4
  import { ChevronDown } from 'lucide-react';
4
- import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
5
- export const Select = ({ value, onChange, options, groups, placeholder, id, className, menuClassName, renderOption, onOpenChange, 'aria-label': ariaLabel, }) => {
6
- const [open, setOpen] = useState(false);
7
- const [highlightedIndex, setHighlightedIndex] = useState(-1);
8
- const containerRef = useRef(null);
9
- const changeOpen = useCallback((next) => {
10
- setOpen(next);
11
- onOpenChange?.(next);
12
- }, [onOpenChange]);
13
- // Build flat items list with group metadata
14
- const { items, groupStartIndices } = useMemo(() => {
15
- const flat = [...(options ?? [])];
16
- const starts = [];
17
- for (const group of groups ?? []) {
18
- starts.push({ index: flat.length, label: group.label });
19
- flat.push(...group.options);
20
- }
21
- return { items: flat, groupStartIndices: starts };
22
- }, [options, groups]);
23
- const selectedOption = items.find(o => o.value === value);
24
- const selectedIndex = items.findIndex(o => o.value === value);
25
- const displayText = selectedOption?.label ?? placeholder ?? value;
26
- const initialHighlightedIndex = selectedIndex >= 0 ? selectedIndex : 0;
27
- // Click outside to close
28
- useEffect(() => {
29
- const handleClickOutside = (e) => {
30
- if (containerRef.current && !containerRef.current.contains(e.target)) {
31
- changeOpen(false);
5
+ import { mergeStatefulClassName } from '../helpers/mergeStatefulClassName/mergeStatefulClassName';
6
+ const triggerClasses = 'border-border bg-background text-foreground focus-visible:ring-ring/50 group flex items-center justify-between gap-2 rounded-lg border px-3 py-2 text-sm outline-hidden focus-visible:ring-3 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 aria-invalid:ring-3 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40';
7
+ const popupClasses = 'bg-popover text-popover-foreground border-border shadow-popover z-50 min-w-[var(--anchor-width)] max-w-[var(--available-width)] overflow-hidden rounded-lg border outline-hidden';
8
+ const listClasses = 'max-h-[min(15rem,var(--available-height))] overflow-y-auto p-1';
9
+ const itemClasses = 'relative flex min-h-9 cursor-default items-center rounded-[calc(var(--radius)-0.25rem)] px-2.5 py-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground data-[selected]:font-medium';
10
+ const Trigger = ({ className, ...props }) => (_jsx(BaseSelect.Trigger, { className: mergeStatefulClassName(triggerClasses, className), ...props }));
11
+ const Positioner = ({ className, alignItemWithTrigger = false, sideOffset = 4, collisionPadding = 8, positionMethod = 'fixed', ...props }) => (_jsx(BaseSelect.Positioner, { alignItemWithTrigger: alignItemWithTrigger, sideOffset: sideOffset, collisionPadding: collisionPadding, positionMethod: positionMethod, className: mergeStatefulClassName('z-50 outline-hidden', className), ...props }));
12
+ const Popup = ({ className, ...props }) => (_jsx(BaseSelect.Popup, { className: mergeStatefulClassName(popupClasses, className), ...props }));
13
+ const List = ({ className, ...props }) => (_jsx(BaseSelect.List, { className: mergeStatefulClassName(listClasses, className), ...props }));
14
+ const Item = ({ className, ...props }) => (_jsx(BaseSelect.Item, { className: mergeStatefulClassName(itemClasses, className), ...props }));
15
+ const ItemText = ({ className, ...props }) => (_jsx(BaseSelect.ItemText, { className: mergeStatefulClassName('min-w-0 flex-1', className), ...props }));
16
+ const GroupLabel = ({ className, ...props }) => (_jsx(BaseSelect.GroupLabel, { className: mergeStatefulClassName('text-muted-foreground px-2.5 pt-2 pb-1 text-xs font-medium uppercase', className), ...props }));
17
+ const OptionItem = ({ option, renderOption }) => (_jsx(Item, { value: option.value, label: option.label, render: (props, state) => (_jsx("div", { ...props, children: _jsx(ItemText, { children: renderOption
18
+ ? renderOption(option, {
19
+ highlighted: state.highlighted,
20
+ selected: state.selected,
21
+ })
22
+ : option.label }) })) }));
23
+ const SelectComponent = ({ value, onChange, options, groups, placeholder, id, className, menuClassName, menuAlign = 'start', renderOption, onOpenChange, name, form, autoComplete, required, disabled, readOnly, 'aria-label': ariaLabel, }) => {
24
+ const items = [...(options ?? []), ...(groups ?? []).flatMap(group => group.options)];
25
+ const selectedOption = items.find(option => option.value === value);
26
+ const selectedValue = selectedOption ? value : null;
27
+ const displayPlaceholder = selectedOption ? undefined : (placeholder ?? value);
28
+ const accessibleLabel = ariaLabel ?? (id ? undefined : (selectedOption?.label ?? displayPlaceholder));
29
+ return (_jsxs(BaseSelect.Root, { value: selectedValue, onValueChange: nextValue => {
30
+ if (nextValue !== null) {
31
+ onChange(nextValue);
32
32
  }
33
- };
34
- document.addEventListener('mousedown', handleClickOutside);
35
- return () => document.removeEventListener('mousedown', handleClickOutside);
36
- }, [changeOpen]);
37
- const selectItem = (itemValue) => {
38
- onChange(itemValue);
39
- changeOpen(false);
40
- setHighlightedIndex(-1);
41
- };
42
- const handleKeyDown = (e) => {
43
- if (e.key === 'Escape') {
44
- changeOpen(false);
45
- setHighlightedIndex(-1);
46
- return;
47
- }
48
- if (!open) {
49
- if (e.key === 'ArrowDown' || e.key === 'ArrowUp' || e.key === 'Enter' || e.key === ' ') {
50
- e.preventDefault();
51
- changeOpen(true);
52
- setHighlightedIndex(initialHighlightedIndex);
53
- }
54
- return;
55
- }
56
- if (items.length === 0) {
57
- return;
58
- }
59
- if (e.key === 'ArrowDown') {
60
- e.preventDefault();
61
- setHighlightedIndex(prev => (prev + 1) % items.length);
62
- }
63
- else if (e.key === 'ArrowUp') {
64
- e.preventDefault();
65
- setHighlightedIndex(prev => (prev - 1 + items.length) % items.length);
66
- }
67
- else if (e.key === 'Enter') {
68
- e.preventDefault();
69
- const highlighted = items[highlightedIndex];
70
- if (highlighted) {
71
- selectItem(highlighted.value);
72
- }
73
- }
74
- };
75
- const itemClassName = (index, itemValue) => {
76
- const base = 'px-3 py-2.5 cursor-pointer';
77
- const highlight = index === highlightedIndex ? 'bg-primary-muted' : 'hover:bg-primary-muted';
78
- const selected = itemValue === value ? 'font-medium' : '';
79
- return `${base} ${highlight} ${selected}`;
80
- };
81
- return (_jsxs("div", { className: "relative", ref: containerRef, onKeyDown: handleKeyDown, children: [_jsxs("button", { type: "button", id: id, className: `flex items-center justify-between gap-2 ${className ?? ''}`, "aria-expanded": open, "aria-haspopup": "listbox", "aria-label": ariaLabel, onClick: () => {
82
- const nextOpen = !open;
83
- changeOpen(nextOpen);
84
- if (nextOpen) {
85
- setHighlightedIndex(initialHighlightedIndex);
86
- }
87
- }, children: [_jsx("span", { className: "truncate", children: displayText }), _jsx(ChevronDown, { className: `size-4 shrink-0 transition-transform ${open ? 'rotate-180' : ''}` })] }), open && (_jsx("ul", { role: "listbox", className: `border-border bg-background absolute z-50 mt-1 max-h-60 w-max min-w-full overflow-y-auto rounded-lg border shadow-lg ${menuClassName ?? ''}`, children: items.map((item, index) => {
88
- const groupHeader = groupStartIndices.find(g => g.index === index);
89
- return (_jsxs("li", { role: "presentation", children: [groupHeader && (_jsx("div", { className: "text-muted-foreground px-3 pt-2 pb-1 text-xs font-medium uppercase", children: groupHeader.label })), _jsx("div", { role: "option", "aria-selected": value === item.value, className: itemClassName(index, item.value), onClick: () => selectItem(item.value), onMouseEnter: () => setHighlightedIndex(index), children: renderOption
90
- ? renderOption(item, {
91
- highlighted: index === highlightedIndex,
92
- selected: value === item.value,
93
- })
94
- : item.label })] }, item.value));
95
- }) }))] }));
33
+ }, items: items, onOpenChange: open => onOpenChange?.(open), name: name, form: form, autoComplete: autoComplete, required: required, disabled: disabled, readOnly: readOnly, modal: false, children: [_jsxs(Trigger, { id: id, "aria-label": accessibleLabel, className: className, children: [_jsx(BaseSelect.Value, { className: "truncate", placeholder: displayPlaceholder }), _jsx(BaseSelect.Icon, { children: _jsx(ChevronDown, { "aria-hidden": true, className: "size-4 shrink-0 transition-transform duration-150 group-data-[popup-open]:rotate-180 motion-reduce:transition-none" }) })] }), _jsx(BaseSelect.Portal, { children: _jsx(Positioner, { align: menuAlign, children: _jsx(Popup, { children: _jsxs(List, { className: menuClassName, children: [(options ?? []).map(option => (_jsx(OptionItem, { option: option, renderOption: renderOption }, option.value))), (groups ?? []).map(group => (_jsxs(BaseSelect.Group, { children: [_jsx(GroupLabel, { children: group.label }), group.options.map(option => (_jsx(OptionItem, { option: option, renderOption: renderOption }, option.value)))] }, group.label)))] }) }) }) })] }));
96
34
  };
35
+ SelectComponent.displayName = 'Select';
36
+ export const Select = Object.assign(SelectComponent, {
37
+ Root: BaseSelect.Root,
38
+ Label: BaseSelect.Label,
39
+ Trigger,
40
+ Value: BaseSelect.Value,
41
+ Icon: BaseSelect.Icon,
42
+ Portal: BaseSelect.Portal,
43
+ Backdrop: BaseSelect.Backdrop,
44
+ Positioner,
45
+ Popup,
46
+ List,
47
+ Item,
48
+ ItemIndicator: BaseSelect.ItemIndicator,
49
+ ItemText,
50
+ Arrow: BaseSelect.Arrow,
51
+ ScrollDownArrow: BaseSelect.ScrollDownArrow,
52
+ ScrollUpArrow: BaseSelect.ScrollUpArrow,
53
+ Group: BaseSelect.Group,
54
+ GroupLabel,
55
+ Separator: BaseSelect.Separator,
56
+ });
@@ -20,7 +20,14 @@ export type SelectProps = {
20
20
  id?: string;
21
21
  className?: string;
22
22
  menuClassName?: string;
23
+ menuAlign?: 'start' | 'center' | 'end';
23
24
  renderOption?: (option: SelectOption, state: SelectOptionState) => ReactNode;
24
25
  onOpenChange?: (open: boolean) => void;
26
+ name?: string;
27
+ form?: string;
28
+ autoComplete?: string;
29
+ required?: boolean;
30
+ disabled?: boolean;
31
+ readOnly?: boolean;
25
32
  'aria-label'?: string;
26
33
  };
@@ -1,13 +1,13 @@
1
- type SliderProps = {
2
- value: number;
3
- onChange: (value: number) => void;
4
- onCommit?: (value: number) => void;
5
- min: number;
6
- max: number;
7
- step?: number;
8
- disabled?: boolean;
9
- 'aria-label'?: string;
10
- className?: string;
1
+ import type { SliderControlProps, SliderIndicatorProps, SliderLabelProps, SliderProps, SliderRootProps, SliderThumbProps, SliderTrackProps, SliderValueProps } from './Slider.types';
2
+ export declare const Slider: {
3
+ ({ value, onChange, onCommit, min, max, step, disabled, "aria-label": ariaLabel, className, }: SliderProps): import("react/jsx-runtime").JSX.Element;
4
+ displayName: string;
5
+ } & {
6
+ Root: <Value extends number | readonly number[] = number | readonly number[]>({ className, ...props }: SliderRootProps<Value>) => import("react/jsx-runtime").JSX.Element;
7
+ Label: ({ className, ...props }: SliderLabelProps) => import("react/jsx-runtime").JSX.Element;
8
+ Value: ({ className, ...props }: SliderValueProps) => import("react/jsx-runtime").JSX.Element;
9
+ Control: ({ className, ...props }: SliderControlProps) => import("react/jsx-runtime").JSX.Element;
10
+ Track: ({ className, ...props }: SliderTrackProps) => import("react/jsx-runtime").JSX.Element;
11
+ Indicator: ({ className, ...props }: SliderIndicatorProps) => import("react/jsx-runtime").JSX.Element;
12
+ Thumb: ({ className, ...props }: SliderThumbProps) => import("react/jsx-runtime").JSX.Element;
11
13
  };
12
- export declare const Slider: ({ value, onChange, onCommit, min, max, step, disabled, "aria-label": ariaLabel, className, }: SliderProps) => import("react/jsx-runtime").JSX.Element;
13
- export {};
@@ -1,5 +1,27 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { cn } from '../helpers/cn/cn';
4
- import { Slider as SliderPrimitive } from '@base-ui/react/slider';
5
- export const Slider = ({ value, onChange, onCommit, min, max, step = 1, disabled, 'aria-label': ariaLabel, className, }) => (_jsx(SliderPrimitive.Root, { value: value, onValueChange: v => onChange(v), onValueCommitted: v => onCommit?.(v), min: min, max: max, step: step, disabled: disabled, "aria-label": ariaLabel, className: cn('relative flex w-full touch-none items-center py-2', className), children: _jsxs(SliderPrimitive.Control, { className: "relative flex h-1.5 w-full items-center", children: [_jsx(SliderPrimitive.Track, { className: "bg-input h-full w-full overflow-hidden rounded-full", children: _jsx(SliderPrimitive.Indicator, { className: "bg-primary h-full rounded-full" }) }), _jsx(SliderPrimitive.Thumb, { className: cn('bg-primary border-background block size-4 rounded-full border-2 shadow-sm', 'focus-visible:ring-ring/50 focus-visible:ring-3 focus-visible:outline-hidden', disabled && 'pointer-events-none opacity-50') })] }) }));
3
+ import { Slider as BaseSlider } from '@base-ui/react/slider';
4
+ import { mergeStatefulClassName } from '../helpers/mergeStatefulClassName/mergeStatefulClassName';
5
+ const rootClasses = 'relative flex touch-none flex-col gap-2 data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-48 data-[orientation=vertical]:w-fit';
6
+ const controlClasses = 'relative flex data-[orientation=horizontal]:w-full data-[orientation=horizontal]:items-center data-[orientation=horizontal]:py-2 data-[orientation=vertical]:h-full data-[orientation=vertical]:justify-center data-[orientation=vertical]:px-2';
7
+ const trackClasses = 'bg-input relative rounded-full data-[orientation=horizontal]:h-1.5 data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1.5';
8
+ const indicatorClasses = 'bg-primary rounded-full data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full';
9
+ const thumbClasses = 'bg-primary border-background block size-4 rounded-full border-2 shadow-sm has-[input:focus-visible]:ring-ring/50 has-[input:focus-visible]:ring-3 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 forced-colors:has-[input:focus-visible]:ring-0 forced-colors:has-[input:focus-visible]:outline-2 forced-colors:has-[input:focus-visible]:outline-offset-2 forced-colors:has-[input:focus-visible]:outline-[Highlight]';
10
+ const Root = ({ className, ...props }) => (_jsx(BaseSlider.Root, { className: mergeStatefulClassName(rootClasses, className), ...props }));
11
+ const Label = ({ className, ...props }) => (_jsx(BaseSlider.Label, { className: mergeStatefulClassName('text-foreground text-sm font-medium', className), ...props }));
12
+ const Value = ({ className, ...props }) => (_jsx(BaseSlider.Value, { className: mergeStatefulClassName('text-muted-foreground text-sm tabular-nums', className), ...props }));
13
+ const Control = ({ className, ...props }) => (_jsx(BaseSlider.Control, { className: mergeStatefulClassName(controlClasses, className), ...props }));
14
+ const Track = ({ className, ...props }) => (_jsx(BaseSlider.Track, { className: mergeStatefulClassName(trackClasses, className), ...props }));
15
+ const Indicator = ({ className, ...props }) => (_jsx(BaseSlider.Indicator, { className: mergeStatefulClassName(indicatorClasses, className), ...props }));
16
+ const Thumb = ({ className, ...props }) => (_jsx(BaseSlider.Thumb, { className: mergeStatefulClassName(thumbClasses, className), ...props }));
17
+ const SliderComponent = ({ value, onChange, onCommit, min, max, step = 1, disabled, 'aria-label': ariaLabel, className, }) => (_jsx(Root, { value: value, onValueChange: nextValue => onChange(nextValue), onValueCommitted: nextValue => onCommit?.(nextValue), min: min, max: max, step: step, disabled: disabled, className: className, children: _jsx(Control, { children: _jsxs(Track, { children: [_jsx(Indicator, {}), _jsx(Thumb, { "aria-label": ariaLabel })] }) }) }));
18
+ SliderComponent.displayName = 'Slider';
19
+ export const Slider = Object.assign(SliderComponent, {
20
+ Root,
21
+ Label,
22
+ Value,
23
+ Control,
24
+ Track,
25
+ Indicator,
26
+ Thumb,
27
+ });
@@ -0,0 +1,34 @@
1
+ import type { Slider as BaseSlider } from '@base-ui/react/slider';
2
+ import type { Ref } from 'react';
3
+ export type SliderProps = {
4
+ value: number;
5
+ onChange: (value: number) => void;
6
+ onCommit?: (value: number) => void;
7
+ min: number;
8
+ max: number;
9
+ step?: number;
10
+ disabled?: boolean;
11
+ 'aria-label'?: string;
12
+ className?: string;
13
+ };
14
+ export type SliderRootProps<Value extends number | readonly number[] = number | readonly number[]> = BaseSlider.Root.Props<Value> & {
15
+ ref?: Ref<HTMLDivElement>;
16
+ };
17
+ export type SliderLabelProps = BaseSlider.Label.Props & {
18
+ ref?: Ref<HTMLDivElement>;
19
+ };
20
+ export type SliderValueProps = BaseSlider.Value.Props & {
21
+ ref?: Ref<HTMLOutputElement>;
22
+ };
23
+ export type SliderControlProps = BaseSlider.Control.Props & {
24
+ ref?: Ref<HTMLDivElement>;
25
+ };
26
+ export type SliderTrackProps = BaseSlider.Track.Props & {
27
+ ref?: Ref<HTMLDivElement>;
28
+ };
29
+ export type SliderIndicatorProps = BaseSlider.Indicator.Props & {
30
+ ref?: Ref<HTMLDivElement>;
31
+ };
32
+ export type SliderThumbProps = BaseSlider.Thumb.Props & {
33
+ ref?: Ref<HTMLDivElement>;
34
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -2,7 +2,7 @@
2
2
  import { useTheme } from 'next-themes';
3
3
  import { useCallback, useSyncExternalStore } from 'react';
4
4
  import { useHotkeys } from 'react-hotkeys-hook';
5
- import { toast } from 'sonner';
5
+ import { toast } from '../Toaster/Toaster';
6
6
  const THEME_CYCLE = ['system', 'light', 'dark'];
7
7
  const THEME_LABELS = {
8
8
  system: 'System',
@@ -1,2 +1,4 @@
1
- import { type ToasterProps } from 'sonner';
2
- export declare const Toaster: (props: ToasterProps) => import("react/jsx-runtime").JSX.Element;
1
+ import type { ToastFunction, ToasterProps } from './Toaster.types';
2
+ declare const toast: ToastFunction;
3
+ declare const Toaster: ({ className, duration, richColors, visibleToasts, }: ToasterProps) => import("react/jsx-runtime").JSX.Element;
4
+ export { Toaster, toast };
@@ -1,4 +1,59 @@
1
1
  'use client';
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import { Toaster as Sonner } from 'sonner';
4
- export const Toaster = (props) => (_jsx(Sonner, { theme: "system", position: "bottom-right", ...props }));
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Toast as BaseToast } from '@base-ui/react/toast';
4
+ import { CircleAlert, CircleCheck, X } from 'lucide-react';
5
+ import { cn } from '../helpers/cn/cn';
6
+ import { buttonVariants } from '../Button/Button';
7
+ const DEFAULT_DURATION = 4000;
8
+ const DEFAULT_VISIBLE_TOASTS = 3;
9
+ const toastManager = BaseToast.createToastManager();
10
+ let generatedToastId = 0;
11
+ const resolveMessage = (message) => typeof message === 'function' ? message() : message;
12
+ const normalizeToastId = (id) => `${typeof id}:${id}`;
13
+ const resolveTimeout = (duration) => {
14
+ if (duration === Infinity)
15
+ return 0;
16
+ if (duration === 0)
17
+ return undefined;
18
+ return duration;
19
+ };
20
+ const createToast = (type, message, options = {}) => {
21
+ const externalId = options.id ?? `toast-${++generatedToastId}`;
22
+ const internalId = normalizeToastId(externalId);
23
+ const actionProps = options.action
24
+ ? {
25
+ children: options.action.label,
26
+ onClick: (event) => {
27
+ options.action?.onClick(event);
28
+ if (!event.defaultPrevented)
29
+ toastManager.close(internalId);
30
+ },
31
+ }
32
+ : undefined;
33
+ toastManager.add({
34
+ id: internalId,
35
+ title: resolveMessage(message),
36
+ description: options.description === undefined ? undefined : resolveMessage(options.description),
37
+ type,
38
+ priority: type === 'error' ? 'high' : 'low',
39
+ timeout: resolveTimeout(options.duration),
40
+ actionProps,
41
+ data: { closeButton: options.closeButton ?? false },
42
+ });
43
+ return externalId;
44
+ };
45
+ const toast = ((message, options) => createToast('default', message, options));
46
+ toast.success = (message, options) => createToast('success', message, options);
47
+ toast.error = (message, options) => createToast('error', message, options);
48
+ toast.dismiss = id => toastManager.close(id === undefined ? undefined : normalizeToastId(id));
49
+ const toastRootClasses = '[--gap:0.75rem] [--height:var(--toast-frontmost-height,var(--toast-height))] [--offset-y:calc(var(--toast-offset-y)*-1+calc(var(--toast-index)*var(--gap)*-1)+var(--toast-swipe-movement-y))] [--peek:0.5rem] [--scale:calc(max(0,1-(var(--toast-index)*0.04)))] [--shrink:calc(1-var(--scale))] border-border bg-popover text-popover-foreground shadow-popover absolute right-0 bottom-0 z-[calc(1000-var(--toast-index))] h-[var(--height)] w-full origin-bottom rounded-lg border outline-hidden select-none [transform:translateX(var(--toast-swipe-movement-x))_translateY(calc(var(--toast-swipe-movement-y)-(var(--toast-index)*var(--peek))-(var(--shrink)*var(--height))))_scale(var(--scale))] [transition:transform_220ms_cubic-bezier(0.23,1,0.32,1),opacity_180ms_ease-out,height_150ms_ease-out] after:absolute after:top-full after:left-0 after:h-[calc(var(--gap)+1px)] after:w-full after:content-[""] data-ending-style:opacity-0 data-ending-style:[transition-duration:150ms] data-expanded:h-[var(--toast-height)] data-expanded:[transform:translateX(var(--toast-swipe-movement-x))_translateY(var(--offset-y))] data-limited:pointer-events-none data-limited:opacity-0 data-starting-style:[transform:translateY(150%)] focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 [&[data-ending-style]:not([data-limited]):not([data-swipe-direction])]:[transform:translateY(150%)] data-ending-style:data-[swipe-direction=down]:[transform:translateY(calc(var(--toast-swipe-movement-y)+150%))] data-ending-style:data-[swipe-direction=left]:[transform:translateX(calc(var(--toast-swipe-movement-x)-150%))_translateY(var(--offset-y))] data-ending-style:data-[swipe-direction=right]:[transform:translateX(calc(var(--toast-swipe-movement-x)+150%))_translateY(var(--offset-y))] data-ending-style:data-[swipe-direction=up]:[transform:translateY(calc(var(--toast-swipe-movement-y)-150%))] motion-reduce:transition-none motion-reduce:data-starting-style:opacity-100 motion-reduce:data-starting-style:[transform:none]';
50
+ const ToastList = ({ richColors }) => {
51
+ const { toasts } = BaseToast.useToastManager();
52
+ return toasts.map(item => (_jsx(BaseToast.Root, { toast: item, className: cn(toastRootClasses, richColors &&
53
+ item.type === 'success' &&
54
+ 'border-success/40 dark:border-success/50 bg-[color-mix(in_oklab,var(--popover)_90%,var(--success))]', richColors &&
55
+ item.type === 'error' &&
56
+ 'border-destructive/40 dark:border-destructive/50 bg-[color-mix(in_oklab,var(--popover)_90%,var(--destructive))]'), children: _jsxs(BaseToast.Content, { className: "flex h-full items-start gap-3 overflow-hidden p-3 transition-opacity duration-180 ease-[cubic-bezier(0.23,1,0.32,1)] data-behind:opacity-0 data-expanded:opacity-100 motion-reduce:transition-none", children: [item.type === 'success' && (_jsx(CircleCheck, { className: "text-success-foreground mt-0.5 size-4 shrink-0", "aria-hidden": "true" })), item.type === 'error' && (_jsx(CircleAlert, { className: "text-destructive mt-0.5 size-4 shrink-0", "aria-hidden": "true" })), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx(BaseToast.Title, { className: "m-0 text-sm leading-5 font-medium break-words" }), item.description !== undefined && (_jsx(BaseToast.Description, { className: "text-muted-foreground mt-0.5 mb-0 text-sm leading-5 break-words" }))] }), (item.actionProps || item.data?.closeButton) && (_jsxs("div", { className: "flex shrink-0 items-center gap-1", children: [_jsx(BaseToast.Action, { className: buttonVariants({ variant: 'outline', size: 'default' }) }), item.data?.closeButton && (_jsx(BaseToast.Close, { "aria-label": "Close toast", className: buttonVariants({ variant: 'subtle', size: 'icon' }), children: _jsx(X, { "aria-hidden": "true" }) }))] }))] }) }, item.id)));
57
+ };
58
+ const Toaster = ({ className, duration = DEFAULT_DURATION, richColors = false, visibleToasts = DEFAULT_VISIBLE_TOASTS, }) => (_jsx(BaseToast.Provider, { limit: visibleToasts, timeout: duration, toastManager: toastManager, children: _jsx(BaseToast.Portal, { children: _jsx(BaseToast.Viewport, { className: cn('fixed right-[max(1rem,env(safe-area-inset-right))] bottom-[max(1rem,env(safe-area-inset-bottom))] z-50 w-[calc(100vw-2rem)] outline-hidden sm:right-6 sm:bottom-6 sm:w-[22.5rem]', className), children: _jsx(ToastList, { richColors: richColors }) }) }) }));
59
+ export { Toaster, toast };
@@ -0,0 +1,26 @@
1
+ import type { MouseEventHandler, ReactNode } from 'react';
2
+ export type ToastId = string | number;
3
+ export type ToastMessage = ReactNode | (() => ReactNode);
4
+ export type ToastAction = {
5
+ label: ReactNode;
6
+ onClick: MouseEventHandler<HTMLButtonElement>;
7
+ };
8
+ export type ToastOptions = {
9
+ action?: ToastAction;
10
+ closeButton?: boolean;
11
+ description?: ToastMessage;
12
+ duration?: number;
13
+ id?: ToastId;
14
+ };
15
+ export type ToastFunction = {
16
+ (message: ToastMessage, options?: ToastOptions): ToastId;
17
+ success: (message: ToastMessage, options?: ToastOptions) => ToastId;
18
+ error: (message: ToastMessage, options?: ToastOptions) => ToastId;
19
+ dismiss: (id?: ToastId) => void;
20
+ };
21
+ export type ToasterProps = {
22
+ className?: string;
23
+ duration?: number;
24
+ richColors?: boolean;
25
+ visibleToasts?: number;
26
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,13 @@
1
- import { type ReactElement } from 'react';
1
+ import { Tooltip as BaseTooltip } from '@base-ui/react/tooltip';
2
+ import { type ComponentPropsWithoutRef, type ReactElement, type Ref } from 'react';
3
+ type BasePositionerProps = ComponentPropsWithoutRef<typeof BaseTooltip.Positioner>;
4
+ type BasePopupProps = ComponentPropsWithoutRef<typeof BaseTooltip.Popup>;
5
+ type PositionerProps = BasePositionerProps & {
6
+ ref?: Ref<HTMLDivElement>;
7
+ };
8
+ type PopupProps = BasePopupProps & {
9
+ ref?: Ref<HTMLDivElement>;
10
+ };
2
11
  type TooltipProps = {
3
12
  label: string;
4
13
  shortcut?: string | string[];
@@ -12,5 +21,19 @@ type TooltipProps = {
12
21
  }>;
13
22
  };
14
23
  export declare const VIEWPORT_MARGIN = 8;
15
- export declare const Tooltip: ({ label, shortcut, position, delay, maxWidth, disabled, className, children, }: TooltipProps) => import("react/jsx-runtime").JSX.Element;
24
+ export declare const Tooltip: {
25
+ ({ label, shortcut, position, delay, maxWidth, disabled, className, children, }: TooltipProps): import("react/jsx-runtime").JSX.Element;
26
+ displayName: string;
27
+ } & {
28
+ Provider: import("react").FC<import("@base-ui/react").TooltipProviderProps>;
29
+ Root: <Payload>(props: BaseTooltip.Root.Props<Payload>) => import("react/jsx-runtime").JSX.Element;
30
+ Trigger: BaseTooltip.Trigger;
31
+ Portal: import("react").ForwardRefExoticComponent<Omit<import("@base-ui/react").TooltipPortalProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
32
+ Positioner: ({ className, sideOffset, collisionPadding, collisionAvoidance, positionMethod, ...props }: PositionerProps) => import("react/jsx-runtime").JSX.Element;
33
+ Popup: ({ className, role, ...props }: PopupProps) => import("react/jsx-runtime").JSX.Element;
34
+ Arrow: import("react").ForwardRefExoticComponent<Omit<import("@base-ui/react").TooltipArrowProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
35
+ Viewport: import("react").ForwardRefExoticComponent<Omit<import("@base-ui/react").TooltipViewportProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
36
+ createHandle: typeof BaseTooltip.createHandle;
37
+ Handle: typeof BaseTooltip.Handle;
38
+ };
16
39
  export {};
@@ -1,121 +1,37 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { computeTooltipPlacement, } from '../helpers/tooltipPlacement/tooltipPlacement';
3
+ import { Tooltip as BaseTooltip } from '@base-ui/react/tooltip';
4
+ import { cloneElement } from 'react';
5
+ import { cn } from '../helpers/cn/cn';
6
+ import { mergeStatefulClassName } from '../helpers/mergeStatefulClassName/mergeStatefulClassName';
4
7
  import { Kbd } from '../Kbd/Kbd';
5
- import { cloneElement, useCallback, useEffect, useLayoutEffect, useRef, useState, } from 'react';
6
- import { createPortal } from 'react-dom';
7
8
  const DEFAULT_DELAY = 400;
8
9
  export const VIEWPORT_MARGIN = 8;
9
- // Gap in px between the trigger and the tooltip box, baked into the fixed `top`
10
- // offset below; the flip math subtracts it when deciding whether a side fits.
11
10
  const TRIGGER_GAP = 8;
12
- // Position before paint so an edge tooltip never flashes centered-then-shifted.
13
- // useLayoutEffect warns and no-ops during SSR, so fall back to useEffect there.
14
- const useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
15
- export const Tooltip = ({ label, shortcut, position = 'top', delay = DEFAULT_DELAY, maxWidth, disabled, className, children, }) => {
16
- const [visible, setVisible] = useState(false);
17
- const [box, setBox] = useState(null);
18
- const timeoutRef = useRef(null);
19
- const wrapperRef = useRef(null);
20
- const tooltipRef = useRef(null);
21
- const show = useCallback(() => {
22
- if (disabled)
23
- return;
24
- timeoutRef.current = setTimeout(() => setVisible(true), delay);
25
- }, [disabled, delay]);
26
- const hide = useCallback(() => {
27
- if (timeoutRef.current) {
28
- clearTimeout(timeoutRef.current);
29
- timeoutRef.current = null;
30
- }
31
- setVisible(false);
32
- }, []);
33
- useEffect(() => {
34
- if (disabled && timeoutRef.current) {
35
- clearTimeout(timeoutRef.current);
36
- timeoutRef.current = null;
37
- }
38
- }, [disabled]);
39
- useEffect(() => {
40
- return () => {
41
- if (timeoutRef.current)
42
- clearTimeout(timeoutRef.current);
43
- };
44
- }, []);
45
- useEffect(() => {
46
- if (!visible)
47
- return;
48
- let lastCheck = 0;
49
- const handlePointerMove = (e) => {
50
- if (e.timeStamp - lastCheck < 100)
51
- return;
52
- lastCheck = e.timeStamp;
53
- const rect = wrapperRef.current?.getBoundingClientRect();
54
- if (!rect)
55
- return;
56
- const inside = e.clientX >= rect.left &&
57
- e.clientX <= rect.right &&
58
- e.clientY >= rect.top &&
59
- e.clientY <= rect.bottom;
60
- if (!inside)
61
- hide();
62
- };
63
- document.addEventListener('pointermove', handlePointerMove, { passive: true });
64
- return () => document.removeEventListener('pointermove', handlePointerMove);
65
- }, [visible, hide]);
66
- useIsomorphicLayoutEffect(() => {
67
- if (!visible)
68
- return;
69
- const measure = () => {
70
- const wrapper = wrapperRef.current;
71
- const tooltip = tooltipRef.current;
72
- if (!wrapper || !tooltip)
73
- return;
74
- const trigger = wrapper.getBoundingClientRect();
75
- const tip = tooltip.getBoundingClientRect();
76
- const placement = computeTooltipPlacement({
77
- trigger,
78
- tooltip: { width: tip.width, height: tip.height },
79
- viewport: { width: window.innerWidth, height: window.innerHeight },
80
- preferredSide: position,
81
- margin: VIEWPORT_MARGIN,
82
- gap: TRIGGER_GAP,
83
- });
84
- const left = trigger.left + trigger.width / 2;
85
- const top = placement.side === 'top' ? trigger.top - TRIGGER_GAP : trigger.bottom + TRIGGER_GAP;
86
- // Keep the same object when nothing moved so a no-op resize/scroll doesn't
87
- // trigger a redundant re-render (the common centered, still case is a no-op).
88
- setBox(prev => prev &&
89
- prev.side === placement.side &&
90
- prev.offsetX === placement.offsetX &&
91
- prev.left === left &&
92
- prev.top === top
93
- ? prev
94
- : { ...placement, left, top });
95
- };
96
- measure();
97
- // Portaled and fixed, the box no longer rides the trigger's scroll container,
98
- // so re-anchor on scroll (capture, to catch any scrolling ancestor) and resize.
99
- window.addEventListener('resize', measure, { passive: true });
100
- window.addEventListener('scroll', measure, { capture: true, passive: true });
101
- return () => {
102
- window.removeEventListener('resize', measure);
103
- window.removeEventListener('scroll', measure, { capture: true });
104
- };
105
- }, [visible, position]);
106
- const boxStyle = {
107
- position: 'fixed',
108
- left: box?.left ?? 0,
109
- top: box?.top ?? 0,
110
- transform: `translate(calc(-50% + ${box?.offsetX ?? 0}px), ${box?.side === 'top' ? '-100%' : '0'})`,
111
- // Hidden until measured so the first frame never paints at the un-anchored origin.
112
- visibility: box ? 'visible' : 'hidden',
113
- ...(maxWidth ? { maxWidth } : {}),
114
- };
115
- return (_jsxs("div", { ref: wrapperRef, className: `inline-flex${className ? ` ${className}` : ''}`, onMouseEnter: show, onMouseLeave: hide, onPointerDown: hide, onFocus: show, onBlur: hide, children: [cloneElement(children, {
116
- 'aria-label': children.props['aria-label'] ?? label,
117
- }), visible &&
118
- !disabled &&
119
- typeof document !== 'undefined' &&
120
- createPortal(_jsxs("div", { ref: tooltipRef, role: "tooltip", style: boxStyle, className: `bg-foreground text-background pointer-events-none z-50 flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-xs shadow-lg ${maxWidth ? 'w-max whitespace-normal' : 'whitespace-nowrap'}`, children: [label, shortcut && (_jsx(Kbd, { keys: shortcut, size: "sm", className: "bg-background/15 border-transparent" }))] }), document.body)] }));
11
+ const TOOLTIP_COLLISION_AVOIDANCE = {
12
+ side: 'flip',
13
+ align: 'shift',
14
+ fallbackAxisSide: 'none',
121
15
  };
16
+ const popupClasses = 'bg-foreground text-background shadow-popover pointer-events-none flex origin-[var(--transform-origin)] items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-xs transition-[transform,opacity] duration-150 ease-[cubic-bezier(0.23,1,0.32,1)] data-[ending-style]:scale-[0.97] data-[ending-style]:opacity-0 data-[instant]:transition-none data-[starting-style]:scale-[0.97] data-[starting-style]:opacity-0 motion-reduce:transform-none motion-reduce:transition-none';
17
+ const Positioner = ({ className, sideOffset = TRIGGER_GAP, collisionPadding = VIEWPORT_MARGIN, collisionAvoidance = TOOLTIP_COLLISION_AVOIDANCE, positionMethod = 'fixed', ...props }) => (_jsx(BaseTooltip.Positioner, { sideOffset: sideOffset, collisionPadding: collisionPadding, collisionAvoidance: collisionAvoidance, positionMethod: positionMethod, className: mergeStatefulClassName('z-50 outline-hidden', className), ...props }));
18
+ const Popup = ({ className, role = 'tooltip', ...props }) => (_jsx(BaseTooltip.Popup, { role: role, className: mergeStatefulClassName(popupClasses, className), ...props }));
19
+ const TooltipComponent = ({ label, shortcut, position = 'top', delay = DEFAULT_DELAY, maxWidth, disabled, className, children, }) => {
20
+ const trigger = cloneElement(children, {
21
+ 'aria-label': children.props['aria-label'] ?? label,
22
+ });
23
+ return (_jsxs(BaseTooltip.Root, { disabled: disabled, disableHoverablePopup: true, children: [_jsx(BaseTooltip.Trigger, { className: cn('inline-flex', className), delay: delay, render: _jsx("div", {}), children: trigger }), _jsx(BaseTooltip.Portal, { children: _jsx(Positioner, { side: position, children: _jsxs(Popup, { style: maxWidth ? { maxWidth } : undefined, className: maxWidth ? 'w-max whitespace-normal' : 'whitespace-nowrap', children: [label, shortcut && (_jsx(Kbd, { keys: shortcut, size: "sm", className: "bg-background/15 border-transparent" }))] }) }) })] }));
24
+ };
25
+ TooltipComponent.displayName = 'Tooltip';
26
+ export const Tooltip = Object.assign(TooltipComponent, {
27
+ Provider: BaseTooltip.Provider,
28
+ Root: BaseTooltip.Root,
29
+ Trigger: BaseTooltip.Trigger,
30
+ Portal: BaseTooltip.Portal,
31
+ Positioner,
32
+ Popup,
33
+ Arrow: BaseTooltip.Arrow,
34
+ Viewport: BaseTooltip.Viewport,
35
+ createHandle: BaseTooltip.createHandle,
36
+ Handle: BaseTooltip.Handle,
37
+ });
@@ -0,0 +1,3 @@
1
+ type StatefulClassName<State> = string | ((state: State) => string | undefined) | undefined;
2
+ export declare const mergeStatefulClassName: <State>(baseClassName: string, className: StatefulClassName<State>) => StatefulClassName<State>;
3
+ export {};
@@ -0,0 +1,4 @@
1
+ import { cn } from '../cn/cn';
2
+ export const mergeStatefulClassName = (baseClassName, className) => typeof className === 'function'
3
+ ? state => cn(baseClassName, className(state))
4
+ : cn(baseClassName, className);