@cladd-ui/react 0.0.1 → 0.0.2
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/LICENSE +21 -0
- package/README.md +1 -1
- package/components/Backdrop.d.ts +8 -0
- package/components/Backdrop.d.ts.map +1 -0
- package/components/Backdrop.js +7 -0
- package/components/Backdrop.js.map +1 -0
- package/components/BlockTitle.d.ts +10 -0
- package/components/BlockTitle.d.ts.map +1 -0
- package/components/BlockTitle.js +7 -0
- package/components/BlockTitle.js.map +1 -0
- package/components/Button.d.ts +61 -0
- package/components/Button.d.ts.map +1 -0
- package/components/Button.js +83 -0
- package/components/Button.js.map +1 -0
- package/components/Checkbox.d.ts +57 -0
- package/components/Checkbox.d.ts.map +1 -0
- package/components/Checkbox.js +48 -0
- package/components/Checkbox.js.map +1 -0
- package/components/Chip.d.ts +47 -0
- package/components/Chip.d.ts.map +1 -0
- package/components/Chip.js +55 -0
- package/components/Chip.js.map +1 -0
- package/components/Dialog.d.ts +118 -0
- package/components/Dialog.d.ts.map +1 -0
- package/components/Dialog.js +178 -0
- package/components/Dialog.js.map +1 -0
- package/components/DialogsPortal.d.ts +2 -0
- package/components/DialogsPortal.d.ts.map +1 -0
- package/components/DialogsPortal.js +17 -0
- package/components/DialogsPortal.js.map +1 -0
- package/components/DialogsPortalContext.d.ts +49 -0
- package/components/DialogsPortalContext.d.ts.map +1 -0
- package/components/DialogsPortalContext.js +17 -0
- package/components/DialogsPortalContext.js.map +1 -0
- package/components/FocusableLayer.d.ts +25 -0
- package/components/FocusableLayer.d.ts.map +1 -0
- package/components/FocusableLayer.js +18 -0
- package/components/FocusableLayer.js.map +1 -0
- package/components/Input.d.ts +87 -0
- package/components/Input.d.ts.map +1 -0
- package/components/Input.js +93 -0
- package/components/Input.js.map +1 -0
- package/components/Link.d.ts +28 -0
- package/components/Link.d.ts.map +1 -0
- package/components/Link.js +21 -0
- package/components/Link.js.map +1 -0
- package/components/List.d.ts +8 -0
- package/components/List.d.ts.map +1 -0
- package/components/List.js +7 -0
- package/components/List.js.map +1 -0
- package/components/ListButton.d.ts +61 -0
- package/components/ListButton.d.ts.map +1 -0
- package/components/ListButton.js +9 -0
- package/components/ListButton.js.map +1 -0
- package/components/ListItem.d.ts +8 -0
- package/components/ListItem.d.ts.map +1 -0
- package/components/ListItem.js +7 -0
- package/components/ListItem.js.map +1 -0
- package/components/ListSeparator.d.ts +8 -0
- package/components/ListSeparator.d.ts.map +1 -0
- package/components/ListSeparator.js +7 -0
- package/components/ListSeparator.js.map +1 -0
- package/components/ModalController.d.ts +26 -0
- package/components/ModalController.d.ts.map +1 -0
- package/components/ModalController.js +52 -0
- package/components/ModalController.js.map +1 -0
- package/components/NumberField.d.ts +49 -0
- package/components/NumberField.d.ts.map +1 -0
- package/components/NumberField.js +34 -0
- package/components/NumberField.js.map +1 -0
- package/components/Popover.d.ts +137 -0
- package/components/Popover.d.ts.map +1 -0
- package/components/Popover.js +366 -0
- package/components/Popover.js.map +1 -0
- package/components/Popup.d.ts +120 -0
- package/components/Popup.d.ts.map +1 -0
- package/components/Popup.js +235 -0
- package/components/Popup.js.map +1 -0
- package/components/PopupContent.d.ts +19 -0
- package/components/PopupContent.d.ts.map +1 -0
- package/components/PopupContent.js +8 -0
- package/components/PopupContent.js.map +1 -0
- package/components/Preloader.d.ts +12 -0
- package/components/Preloader.d.ts.map +1 -0
- package/components/Preloader.js +30 -0
- package/components/Preloader.js.map +1 -0
- package/components/Radio.d.ts +53 -0
- package/components/Radio.d.ts.map +1 -0
- package/components/Radio.js +46 -0
- package/components/Radio.js.map +1 -0
- package/components/Range.d.ts +35 -0
- package/components/Range.d.ts.map +1 -0
- package/components/Range.js +76 -0
- package/components/Range.js.map +1 -0
- package/components/Searchbar.d.ts +29 -0
- package/components/Searchbar.d.ts.map +1 -0
- package/components/Searchbar.js +10 -0
- package/components/Searchbar.js.map +1 -0
- package/components/Segmented.d.ts +39 -0
- package/components/Segmented.d.ts.map +1 -0
- package/components/Segmented.js +26 -0
- package/components/Segmented.js.map +1 -0
- package/components/SegmentedButton.d.ts +13 -0
- package/components/SegmentedButton.d.ts.map +1 -0
- package/components/SegmentedButton.js +10 -0
- package/components/SegmentedButton.js.map +1 -0
- package/components/SegmentedContext.d.ts +36 -0
- package/components/SegmentedContext.d.ts.map +1 -0
- package/components/SegmentedContext.js +10 -0
- package/components/SegmentedContext.js.map +1 -0
- package/components/Select.d.ts +145 -0
- package/components/Select.d.ts.map +1 -0
- package/components/Select.js +316 -0
- package/components/Select.js.map +1 -0
- package/components/Surface.d.ts +67 -0
- package/components/Surface.d.ts.map +1 -0
- package/components/Surface.js +36 -0
- package/components/Surface.js.map +1 -0
- package/components/SurfaceContent.d.ts +8 -0
- package/components/SurfaceContent.d.ts.map +1 -0
- package/components/SurfaceContent.js +7 -0
- package/components/SurfaceContent.js.map +1 -0
- package/components/SurfaceContext.d.ts +19 -0
- package/components/SurfaceContext.d.ts.map +1 -0
- package/components/SurfaceContext.js +9 -0
- package/components/SurfaceContext.js.map +1 -0
- package/components/SurfaceCut.d.ts +33 -0
- package/components/SurfaceCut.d.ts.map +1 -0
- package/components/SurfaceCut.js +17 -0
- package/components/SurfaceCut.js.map +1 -0
- package/components/SurfaceCutContent.d.ts +16 -0
- package/components/SurfaceCutContent.d.ts.map +1 -0
- package/components/SurfaceCutContent.js +8 -0
- package/components/SurfaceCutContent.js.map +1 -0
- package/components/TextArea.d.ts +61 -0
- package/components/TextArea.d.ts.map +1 -0
- package/components/TextArea.js +102 -0
- package/components/TextArea.js.map +1 -0
- package/components/ThemeContext.d.ts +23 -0
- package/components/ThemeContext.d.ts.map +1 -0
- package/components/ThemeContext.js +18 -0
- package/components/ThemeContext.js.map +1 -0
- package/components/Toast.d.ts +89 -0
- package/components/Toast.d.ts.map +1 -0
- package/components/Toast.js +129 -0
- package/components/Toast.js.map +1 -0
- package/components/ToastsPortal.d.ts +2 -0
- package/components/ToastsPortal.d.ts.map +1 -0
- package/components/ToastsPortal.js +17 -0
- package/components/ToastsPortal.js.map +1 -0
- package/components/ToastsPortalContext.d.ts +45 -0
- package/components/ToastsPortalContext.d.ts.map +1 -0
- package/components/ToastsPortalContext.js +17 -0
- package/components/ToastsPortalContext.js.map +1 -0
- package/components/Toggle.d.ts +69 -0
- package/components/Toggle.d.ts.map +1 -0
- package/components/Toggle.js +48 -0
- package/components/Toggle.js.map +1 -0
- package/components/Tooltip.d.ts +48 -0
- package/components/Tooltip.d.ts.map +1 -0
- package/components/Tooltip.js +90 -0
- package/components/Tooltip.js.map +1 -0
- package/components/UIProvider.d.ts +16 -0
- package/components/UIProvider.d.ts.map +1 -0
- package/components/UIProvider.js +11 -0
- package/components/UIProvider.js.map +1 -0
- package/components/WithTooltip.d.ts +36 -0
- package/components/WithTooltip.d.ts.map +1 -0
- package/components/WithTooltip.js +138 -0
- package/components/WithTooltip.js.map +1 -0
- package/components/icons/CheckIcon.d.ts +2 -0
- package/components/icons/CheckIcon.d.ts.map +1 -0
- package/components/icons/CheckIcon.js +5 -0
- package/components/icons/CheckIcon.js.map +1 -0
- package/components/icons/CloseIcon.d.ts +2 -0
- package/components/icons/CloseIcon.d.ts.map +1 -0
- package/components/icons/CloseIcon.js +3 -0
- package/components/icons/CloseIcon.js.map +1 -0
- package/components/icons/DropdownIcon.d.ts +2 -0
- package/components/icons/DropdownIcon.d.ts.map +1 -0
- package/components/icons/DropdownIcon.js +3 -0
- package/components/icons/DropdownIcon.js.map +1 -0
- package/components/icons/SearchIcon.d.ts +2 -0
- package/components/icons/SearchIcon.d.ts.map +1 -0
- package/components/icons/SearchIcon.js +5 -0
- package/components/icons/SearchIcon.js.map +1 -0
- package/hooks/use-accent-color.d.ts +2 -0
- package/hooks/use-accent-color.d.ts.map +1 -0
- package/hooks/use-accent-color.js +6 -0
- package/hooks/use-accent-color.js.map +1 -0
- package/hooks/use-device.d.ts +14 -0
- package/hooks/use-device.d.ts.map +1 -0
- package/hooks/use-device.js +68 -0
- package/hooks/use-device.js.map +1 -0
- package/hooks/use-dialog.d.ts +8 -0
- package/hooks/use-dialog.d.ts.map +1 -0
- package/hooks/use-dialog.js +38 -0
- package/hooks/use-dialog.js.map +1 -0
- package/hooks/use-focus-trap.d.ts +9 -0
- package/hooks/use-focus-trap.d.ts.map +1 -0
- package/hooks/use-focus-trap.js +106 -0
- package/hooks/use-focus-trap.js.map +1 -0
- package/hooks/use-modal-utils.d.ts +17 -0
- package/hooks/use-modal-utils.d.ts.map +1 -0
- package/hooks/use-modal-utils.js +110 -0
- package/hooks/use-modal-utils.js.map +1 -0
- package/hooks/use-surface.d.ts +2 -0
- package/hooks/use-surface.d.ts.map +1 -0
- package/hooks/use-surface.js +6 -0
- package/hooks/use-surface.js.map +1 -0
- package/hooks/use-theme.d.ts +2 -0
- package/hooks/use-theme.d.ts.map +1 -0
- package/hooks/use-theme.js +6 -0
- package/hooks/use-theme.js.map +1 -0
- package/hooks/use-toast.d.ts +3 -0
- package/hooks/use-toast.d.ts.map +1 -0
- package/hooks/use-toast.js +21 -0
- package/hooks/use-toast.js.map +1 -0
- package/index.d.ts +42 -0
- package/index.d.ts.map +1 -0
- package/index.js +42 -0
- package/index.js.map +1 -0
- package/package.json +27 -9
- package/shared/cn.d.ts +3 -0
- package/shared/cn.d.ts.map +1 -0
- package/shared/cn.js +6 -0
- package/shared/cn.js.map +1 -0
- package/shared/next-tick.d.ts +2 -0
- package/shared/next-tick.d.ts.map +1 -0
- package/shared/next-tick.js +6 -0
- package/shared/next-tick.js.map +1 -0
- package/styles/colors.css +403 -0
- package/styles/popup.css +14 -0
- package/styles/preloader.css +71 -0
- package/styles/range.css +17 -0
- package/styles/safe-areas.css +192 -0
- package/types.d.ts +2 -0
- package/types.d.ts.map +1 -0
- package/types.js +2 -0
- package/types.js.map +1 -0
- package/ui.css +10 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from '../shared/cn';
|
|
3
|
+
export const SurfaceCutContent = (props) => {
|
|
4
|
+
const { children, fullHeight = true, component = 'div', className = '', ref, ...rest } = props;
|
|
5
|
+
const Component = component;
|
|
6
|
+
return (_jsx(Component, { ref: ref, className: cn(`relative`, fullHeight && 'h-full', className), ...rest, children: children }));
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=SurfaceCutContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SurfaceCutContent.js","sourceRoot":"","sources":["../../../src/components/SurfaceCutContent.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;AAkBlC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,KAAgC,EAChC,EAAE;IACF,MAAM,EACJ,QAAQ,EACR,UAAU,GAAG,IAAI,EACjB,SAAS,GAAG,KAAK,EACjB,SAAS,GAAG,EAAE,EACd,GAAG,EACH,GAAG,IAAI,EACR,GAAG,KAAK,CAAC;IACV,MAAM,SAAS,GAAG,SAAwB,CAAC;IAC3C,OAAO,CACL,KAAC,SAAS,IACR,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,CAAC,UAAU,EAAE,UAAU,IAAI,QAAQ,EAAE,SAAS,CAAC,KACxD,IAAI,YAEP,QAAQ,GACC,CACb,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ElementType, ReactNode, Ref, FocusEvent, KeyboardEvent, FormEvent, ComponentPropsWithoutRef } from 'react';
|
|
2
|
+
import { Color } from '../types';
|
|
3
|
+
export type TextAreaSize = 'sm' | 'md' | 'lg' | 'xl' | '2xl';
|
|
4
|
+
interface TextAreaOwnProps<C extends ElementType = 'div'> {
|
|
5
|
+
/** Polymorphic wrapper element. Defaults to `'div'`. The editable area itself is always a `contenteditable` `<div>`. */
|
|
6
|
+
component?: C;
|
|
7
|
+
/** Forwarded to the wrapper element. */
|
|
8
|
+
ref?: Ref<HTMLElement>;
|
|
9
|
+
/** Controlled value. Synced into the editable `innerText` on change (see `updateContentOnChange`). */
|
|
10
|
+
value?: string;
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
/** Visually dim the textarea and remove `contenteditable`. */
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
/** Make the textarea non-editable but still selectable. */
|
|
15
|
+
readOnly?: boolean;
|
|
16
|
+
/** Apply pill-style corners. Default `false` - uses size-specific radii. */
|
|
17
|
+
rounded?: boolean;
|
|
18
|
+
size?: TextAreaSize;
|
|
19
|
+
/** Fires on every input event. First arg is the new text, second is the raw event. */
|
|
20
|
+
onChange?: (value: string, event?: FormEvent<HTMLDivElement>) => void;
|
|
21
|
+
onKeyDown?: (e: KeyboardEvent<HTMLDivElement>) => void;
|
|
22
|
+
onFocus?: (e: FocusEvent<HTMLDivElement>) => void;
|
|
23
|
+
onBlur?: (e: FocusEvent<HTMLDivElement>) => void;
|
|
24
|
+
/** Accent color token. Drives the focus ring and `infoMessage` colors. Default: theme accent. */
|
|
25
|
+
color?: Color;
|
|
26
|
+
/** Slot rendered before the editable area. */
|
|
27
|
+
prefix?: ReactNode;
|
|
28
|
+
/** Slot rendered after the editable area. */
|
|
29
|
+
suffix?: ReactNode;
|
|
30
|
+
/**
|
|
31
|
+
* When `true` (default), syncs the editable `innerText` whenever `value` changes from
|
|
32
|
+
* the outside. Set to `false` for performance-sensitive editors that manage their own
|
|
33
|
+
* DOM (e.g. rich-text editors) - otherwise external `value` updates would stomp on
|
|
34
|
+
* caret position and selection.
|
|
35
|
+
*/
|
|
36
|
+
updateContentOnChange?: boolean;
|
|
37
|
+
/** Extra classes for the outer wrapper. */
|
|
38
|
+
className?: string;
|
|
39
|
+
/** Extra classes for the inner content row (where prefix/editor/suffix live). */
|
|
40
|
+
contentClassName?: string;
|
|
41
|
+
/** Extra classes for the editable `[contenteditable]` `<div>`. */
|
|
42
|
+
inputClassName?: string;
|
|
43
|
+
/** Extra classes for the placeholder layer. */
|
|
44
|
+
placeholderClassName?: string;
|
|
45
|
+
/** Validity state. Default `true`. When `false`, switches the focus ring to red and shows `errorMessage`. */
|
|
46
|
+
valid?: boolean;
|
|
47
|
+
/** Floating label shown above the editor on focus. Hidden when `valid === false` or `readOnly`. */
|
|
48
|
+
infoMessage?: ReactNode;
|
|
49
|
+
/** Floating error label. Always visible when `valid === false`. */
|
|
50
|
+
errorMessage?: ReactNode;
|
|
51
|
+
/** Icon node rendered absolutely positioned on the left. */
|
|
52
|
+
icon?: ReactNode;
|
|
53
|
+
/** Extra classes applied to the inner `SurfaceCut`. */
|
|
54
|
+
surfaceClassName?: string;
|
|
55
|
+
/** Reserved - currently not applied in the rendered output. */
|
|
56
|
+
inputPadding?: string;
|
|
57
|
+
}
|
|
58
|
+
export type TextAreaProps<C extends ElementType = 'div'> = TextAreaOwnProps<C> & Omit<ComponentPropsWithoutRef<C>, keyof TextAreaOwnProps<C>>;
|
|
59
|
+
export declare const TextArea: <C extends ElementType = "div">(props: TextAreaProps<C>) => import("react/jsx-runtime").JSX.Element;
|
|
60
|
+
export {};
|
|
61
|
+
//# sourceMappingURL=TextArea.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextArea.d.ts","sourceRoot":"","sources":["../../../src/components/TextArea.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,WAAW,EACX,SAAS,EACT,GAAG,EACH,UAAU,EACV,aAAa,EACb,SAAS,EAGT,wBAAwB,EACzB,MAAM,OAAO,CAAC;AAIf,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAKjC,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC;AAE7D,UAAU,gBAAgB,CAAC,CAAC,SAAS,WAAW,GAAG,KAAK;IACtD,wHAAwH;IACxH,SAAS,CAAC,EAAE,CAAC,CAAC;IACd,wCAAwC;IACxC,GAAG,CAAC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;IACv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zB,4DAA4D;IAC5D,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,uDAAuD;IACvD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,+DAA+D;IAC/D,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,WAAW,GAAG,KAAK,IAAI,gBAAgB,CAAC,CAAC,CAAC,GAC5E,IAAI,CAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE,MAAM,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;AAE/D,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,WAAW,GAAG,KAAK,EACpD,OAAO,aAAa,CAAC,CAAC,CAAC,4CA2OxB,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState, } from 'react';
|
|
3
|
+
import { useAccentColor } from '../hooks/use-accent-color';
|
|
4
|
+
import { cn } from '../shared/cn';
|
|
5
|
+
import { FocusableLayer } from './FocusableLayer';
|
|
6
|
+
import { SurfaceCut } from './SurfaceCut';
|
|
7
|
+
import { SurfaceCutContent } from './SurfaceCutContent';
|
|
8
|
+
export const TextArea = (props) => {
|
|
9
|
+
const accentColor = useAccentColor();
|
|
10
|
+
const { component = 'div', ref: externalRef, value, placeholder, disabled = false, readOnly, rounded = false, size = 'lg', onChange = () => { }, onKeyDown = () => { }, onFocus = () => { }, onBlur = () => { }, color = accentColor, prefix, suffix, updateContentOnChange = true, className, contentClassName, inputClassName, placeholderClassName = '', valid = true, infoMessage, errorMessage, icon, surfaceClassName, } = props;
|
|
11
|
+
const fontSizes = {
|
|
12
|
+
sm: 'text-xs',
|
|
13
|
+
md: 'text-xs',
|
|
14
|
+
lg: 'text-xs',
|
|
15
|
+
xl: 'text-xs',
|
|
16
|
+
'2xl': 'text-xs',
|
|
17
|
+
};
|
|
18
|
+
const iconWrapClasses = {
|
|
19
|
+
sm: 'left-2.5 [&>svg]:size-4 top-1',
|
|
20
|
+
md: 'left-2.5 [&>svg]:size-4 top-1.5',
|
|
21
|
+
lg: 'left-2.5 [&>svg]:size-4 top-2.5',
|
|
22
|
+
xl: 'left-2.5 [&>svg]:size-4 top-3',
|
|
23
|
+
'2xl': 'left-3.5 [&>svg]:size-4 top-4',
|
|
24
|
+
};
|
|
25
|
+
const inputPaddingNoIcon = {
|
|
26
|
+
sm: 'px-2.5',
|
|
27
|
+
md: 'px-2.5',
|
|
28
|
+
lg: 'px-2.5',
|
|
29
|
+
xl: 'px-2.5',
|
|
30
|
+
'2xl': 'px-3.5',
|
|
31
|
+
};
|
|
32
|
+
const inputPaddingVertical = {
|
|
33
|
+
sm: 'py-1',
|
|
34
|
+
md: 'py-1.5',
|
|
35
|
+
lg: 'py-2.5',
|
|
36
|
+
xl: 'py-3',
|
|
37
|
+
'2xl': 'py-4',
|
|
38
|
+
};
|
|
39
|
+
const inputPaddingWithIcon = {
|
|
40
|
+
sm: 'pl-8.5 pr-2',
|
|
41
|
+
md: 'pl-8.5 pr-2',
|
|
42
|
+
lg: 'pl-8.5 pr-3',
|
|
43
|
+
xl: 'pl-8.5 pr-3',
|
|
44
|
+
'2xl': 'pl-9.5 pr-4',
|
|
45
|
+
};
|
|
46
|
+
const roundedFullSizes = {
|
|
47
|
+
sm: 'rounded-[12px]',
|
|
48
|
+
md: 'rounded-[14px]',
|
|
49
|
+
lg: 'rounded-[18px]',
|
|
50
|
+
xl: 'rounded-[20px]',
|
|
51
|
+
'2xl': 'rounded-[24px]',
|
|
52
|
+
};
|
|
53
|
+
const roundedSizes = {
|
|
54
|
+
sm: 'rounded-md',
|
|
55
|
+
md: 'rounded-lg',
|
|
56
|
+
lg: 'rounded-[10px]',
|
|
57
|
+
xl: 'rounded-xl',
|
|
58
|
+
'2xl': 'rounded-xl',
|
|
59
|
+
};
|
|
60
|
+
const heights = {
|
|
61
|
+
sm: 'min-h-6',
|
|
62
|
+
md: 'min-h-7',
|
|
63
|
+
lg: 'min-h-9',
|
|
64
|
+
xl: 'min-h-10',
|
|
65
|
+
'2xl': 'min-h-12',
|
|
66
|
+
};
|
|
67
|
+
const inputPadding = cn(inputPaddingVertical[size], icon ? inputPaddingWithIcon[size] : inputPaddingNoIcon[size]);
|
|
68
|
+
const elRef = useRef(null);
|
|
69
|
+
const inputElRef = useRef(null);
|
|
70
|
+
const [text, setText] = useState();
|
|
71
|
+
const onPaste = (e) => {
|
|
72
|
+
if (e.clipboardData && e.clipboardData.getData) {
|
|
73
|
+
const text = e.clipboardData.getData('text/plain');
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
document.execCommand('insertText', false, text);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const onInput = (e) => {
|
|
79
|
+
const target = e.target;
|
|
80
|
+
setText(target.innerText);
|
|
81
|
+
onChange(target.innerText, e);
|
|
82
|
+
};
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (text !== value) {
|
|
85
|
+
setText(value);
|
|
86
|
+
if (updateContentOnChange && inputElRef.current) {
|
|
87
|
+
inputElRef.current.innerText = value || '';
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}, [value]);
|
|
91
|
+
const Component = component;
|
|
92
|
+
return (_jsxs(Component, { className: cn('input group/textarea relative', disabled && 'opacity-50', className), children: [!readOnly && !disabled && (_jsx(FocusableLayer, { className: cn(rounded ? roundedFullSizes[size] : roundedSizes[size], valid === false && 'color-red'), force: valid === false, color: valid === false ? 'red' : color, group: "textarea" })), _jsx(SurfaceCut, { className: cn(rounded ? roundedFullSizes[size] : roundedSizes[size], surfaceClassName), hoverable: !disabled && !readOnly, onContextMenuCapture: (e) => e.preventDefault(), ref: (el) => {
|
|
93
|
+
elRef.current = el;
|
|
94
|
+
if (externalRef) {
|
|
95
|
+
if (typeof externalRef === 'function')
|
|
96
|
+
externalRef(el);
|
|
97
|
+
else
|
|
98
|
+
externalRef.current = el;
|
|
99
|
+
}
|
|
100
|
+
}, children: _jsxs(SurfaceCutContent, { className: cn('flex items-center', contentClassName), children: [prefix, icon && (_jsx("div", { className: cn('pointer-events-none absolute', iconWrapClasses[size]), children: icon })), _jsxs("div", { className: "relative w-full", children: [_jsx("div", { contentEditable: !disabled && !readOnly, ref: inputElRef, className: cn(inputPadding, heights[size], roundedSizes, fontSizes[size], 'w-full appearance-none border-none bg-transparent font-medium shadow-none outline-none', disabled && 'text-on-surface-darker', inputClassName), onPaste: onPaste, onFocus: onFocus, onBlur: onBlur, onKeyDown: onKeyDown, onInput: onInput }), !text && placeholder && (_jsx("div", { className: cn('pointer-events-none absolute top-0 left-0 h-full w-full text-on-surface-darker select-none', fontSizes[size], inputPadding, placeholderClassName), children: placeholder }))] }), suffix] }) }), infoMessage && valid !== false && !readOnly && (_jsx("div", { className: cn('pointer-events-none absolute -top-1.5 left-2 z-10 translate-y-1 rounded-lg bg-primary px-2 py-1.5 text-[10px] leading-none font-semibold text-on-primary opacity-0 duration-200 group-has-[[contenteditable]:focus]/textarea:-translate-y-1/2 group-has-[[contenteditable]:focus]/textarea:opacity-100', `color-${color}`), children: infoMessage })), errorMessage && valid === false && (_jsx("div", { className: cn('pointer-events-none absolute -top-1.5 left-2 z-10 -translate-y-1/2 rounded-sm bg-primary px-1 py-0.5 text-[10px] leading-none font-semibold text-on-primary opacity-100 duration-200', `color-red`), children: errorMessage }))] }));
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=TextArea.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextArea.js","sourceRoot":"","sources":["../../../src/components/TextArea.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,SAAS,EACT,MAAM,EACN,QAAQ,GAUT,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;AAElC,OAAO,EAAE,cAAc,EAAE,MAAM,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,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,OAAO,GAChB,EACD,CAAC,IAAI,IAAI,WAAW,IAAI,CACvB,cACE,SAAS,EAAE,EAAE,CACX,4FAA4F,EAC5F,SAAS,CAAC,IAAI,CAAC,EACf,YAAY,EACZ,oBAAoB,CACrB,YAEA,WAAW,GACR,CACP,IACG,EAEL,MAAM,IACW,GACT,EAEZ,WAAW,IAAI,KAAK,KAAK,KAAK,IAAI,CAAC,QAAQ,IAAI,CAC9C,cACE,SAAS,EAAE,EAAE,CACX,wSAAwS,EACxS,SAAS,KAAK,EAAE,CACjB,YAEA,WAAW,GACR,CACP,EACA,YAAY,IAAI,KAAK,KAAK,KAAK,IAAI,CAClC,cACE,SAAS,EAAE,EAAE,CACX,sLAAsL,EACtL,WAAW,CACZ,YAEA,YAAY,GACT,CACP,IACS,CACb,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Color } from '../types';
|
|
2
|
+
type ThemeContextValue = {
|
|
3
|
+
theme: 'dark' | 'light';
|
|
4
|
+
accentColor: Color;
|
|
5
|
+
};
|
|
6
|
+
export declare const ThemeContext: import("react").Context<ThemeContextValue>;
|
|
7
|
+
/**
|
|
8
|
+
* Provides `{ theme, accentColor }` to the rest of the tree via `ThemeContext`.
|
|
9
|
+
* Most apps use `UIProvider` instead, which wraps this together with the dialog/toast portals.
|
|
10
|
+
*
|
|
11
|
+
* Components read these values via `useTheme()` and `useAccentColor()` to pick:
|
|
12
|
+
* - per-theme defaults (Dialog/Popover/Tooltip variant, outline, surfaceLevel),
|
|
13
|
+
* - the default `color` for interactive components (Button/Toggle/Checkbox/Radio default to `accentColor`).
|
|
14
|
+
*/
|
|
15
|
+
export declare const ThemeProvider: ({ children, theme, accentColor, }: {
|
|
16
|
+
children: React.ReactNode;
|
|
17
|
+
/** Color scheme to expose to descendants. */
|
|
18
|
+
theme: "dark" | "light";
|
|
19
|
+
/** App-wide accent color token used as the default for interactive components. */
|
|
20
|
+
accentColor: string;
|
|
21
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=ThemeContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThemeContext.d.ts","sourceRoot":"","sources":["../../../src/components/ThemeContext.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,KAAK,iBAAiB,GAAG;IACvB,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IACxB,WAAW,EAAE,KAAK,CAAC;CACpB,CAAC;AACF,eAAO,MAAM,YAAY,4CAGvB,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,GAAI,mCAI3B;IACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,6CAA6C;IAC7C,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IACxB,kFAAkF;IAClF,WAAW,EAAE,MAAM,CAAC;CACrB,4CAMA,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext } from 'react';
|
|
3
|
+
export const ThemeContext = createContext({
|
|
4
|
+
theme: 'dark',
|
|
5
|
+
accentColor: 'brand',
|
|
6
|
+
});
|
|
7
|
+
/**
|
|
8
|
+
* Provides `{ theme, accentColor }` to the rest of the tree via `ThemeContext`.
|
|
9
|
+
* Most apps use `UIProvider` instead, which wraps this together with the dialog/toast portals.
|
|
10
|
+
*
|
|
11
|
+
* Components read these values via `useTheme()` and `useAccentColor()` to pick:
|
|
12
|
+
* - per-theme defaults (Dialog/Popover/Tooltip variant, outline, surfaceLevel),
|
|
13
|
+
* - the default `color` for interactive components (Button/Toggle/Checkbox/Radio default to `accentColor`).
|
|
14
|
+
*/
|
|
15
|
+
export const ThemeProvider = ({ children, theme, accentColor, }) => {
|
|
16
|
+
return (_jsx(ThemeContext.Provider, { value: { theme, accentColor }, children: children }));
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=ThemeContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThemeContext.js","sourceRoot":"","sources":["../../../src/components/ThemeContext.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAQtC,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAoB;IAC3D,KAAK,EAAE,MAAM;IACb,WAAW,EAAE,OAAO;CACrB,CAAC,CAAC;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAC5B,QAAQ,EACR,KAAK,EACL,WAAW,GAOZ,EAAE,EAAE;IACH,OAAO,CACL,KAAC,YAAY,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,YACjD,QAAQ,GACa,CACzB,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { ElementType, ReactNode, Ref } from 'react';
|
|
2
|
+
import { Color } from '../types';
|
|
3
|
+
import { SurfaceVariant } from './Surface';
|
|
4
|
+
/**
|
|
5
|
+
* State container for the `Toast` + `ToastTrigger` + `Toast` compound. Less commonly used than
|
|
6
|
+
* the imperative `useToasts()` portal API - prefer the portal for app-wide notifications and
|
|
7
|
+
* use this only when you need a toast tied to a specific trigger element in JSX.
|
|
8
|
+
*/
|
|
9
|
+
export declare const ToastRoot: ({ children, defaultOpen, open: openProp, onOpenChange, }: {
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
/** Initial open state (uncontrolled). Default `false`. Ignored when `open` is provided. */
|
|
12
|
+
defaultOpen?: boolean;
|
|
13
|
+
/** Controlled open state. When provided, internal state is bypassed. */
|
|
14
|
+
open?: boolean;
|
|
15
|
+
/** Fires whenever the open state should change (trigger click, close button, auto-timeout). */
|
|
16
|
+
onOpenChange?: (open: boolean) => void;
|
|
17
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
/**
|
|
19
|
+
* Wraps a single child element to act as the toast trigger. **Clones** the child to attach
|
|
20
|
+
* an `onClick` handler that toggles the surrounding `ToastRoot`'s open state (composed with
|
|
21
|
+
* any existing `onClick` on the child).
|
|
22
|
+
*
|
|
23
|
+
* No-ops (renders the child as-is) when used outside a `ToastRoot`.
|
|
24
|
+
*/
|
|
25
|
+
export declare const ToastTrigger: ({ children }: {
|
|
26
|
+
children: ReactNode;
|
|
27
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
28
|
+
/**
|
|
29
|
+
* Wraps a single child element to close the surrounding toast when clicked. **Clones** the
|
|
30
|
+
* child to attach an `onClick` handler that flips the surrounding `ToastRoot`'s open state
|
|
31
|
+
* to `false` (composed with any existing `onClick` on the child).
|
|
32
|
+
*
|
|
33
|
+
* ```tsx
|
|
34
|
+
* <ToastRoot>
|
|
35
|
+
* <ToastTrigger><Button>Notify</Button></ToastTrigger>
|
|
36
|
+
* <Toast title="...">
|
|
37
|
+
* <ToastClose><Button>Dismiss</Button></ToastClose>
|
|
38
|
+
* </Toast>
|
|
39
|
+
* </ToastRoot>
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* No-ops (renders the child as-is) when used outside a `ToastRoot`.
|
|
43
|
+
*/
|
|
44
|
+
export declare const ToastClose: ({ children }: {
|
|
45
|
+
children: ReactNode;
|
|
46
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
47
|
+
export interface ToastProps {
|
|
48
|
+
/** Controlled open state. When omitted, falls back to the surrounding `ToastRoot` state, then `false`. */
|
|
49
|
+
open?: boolean;
|
|
50
|
+
/** Fires whenever the open state should change (close button, auto-timeout, etc.). */
|
|
51
|
+
onOpenChange?: (open: boolean) => void;
|
|
52
|
+
/** Portal target selector. Default `'#app, #__next, #root'`. */
|
|
53
|
+
root?: string;
|
|
54
|
+
/** Fires after the close transition completes - use for unmount or post-dismiss cleanup. */
|
|
55
|
+
onClosed?: () => void;
|
|
56
|
+
/** Extra classes applied to the toast root `Surface`. */
|
|
57
|
+
className?: string;
|
|
58
|
+
/** Title slot. Rendered as a bold line above `text`. */
|
|
59
|
+
title?: ReactNode;
|
|
60
|
+
/** Body text slot. Rendered as a smaller line under `title`. */
|
|
61
|
+
text?: ReactNode;
|
|
62
|
+
/** Icon node rendered before the text content. Pre-rendered. */
|
|
63
|
+
icon?: ReactNode;
|
|
64
|
+
/** Icon component rendered before the text content. Instantiated as `<IconComponent />` (no props). */
|
|
65
|
+
iconComponent?: ElementType<any>;
|
|
66
|
+
/** Stop click propagation on the toast surface. Use when the toast renders inside a clickable parent. */
|
|
67
|
+
stopPropagationOnClick?: boolean;
|
|
68
|
+
/** Render the auto close button on the right. Default `true`. */
|
|
69
|
+
closeButton?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Forwarded to the underlying `Surface` as `level`. Default depends on theme:
|
|
72
|
+
* `3` for dark theme, `1` for light theme - keeps the toast visually elevated above page content.
|
|
73
|
+
*/
|
|
74
|
+
surfaceLevel?: string | number;
|
|
75
|
+
/** Default `'neutral'`. */
|
|
76
|
+
color?: Color;
|
|
77
|
+
/** Surface variant. Default `'gradient'`. */
|
|
78
|
+
variant?: SurfaceVariant;
|
|
79
|
+
/** Outline ring on the toast surface. Default `true`. */
|
|
80
|
+
outline?: boolean;
|
|
81
|
+
/** Auto-close after this many ms. Pass `0` to disable auto-close. Default `5000`. */
|
|
82
|
+
timeout?: number;
|
|
83
|
+
/** Forwarded to the toast surface root. */
|
|
84
|
+
ref?: Ref<HTMLDivElement>;
|
|
85
|
+
/** Custom content rendered after the title/text block, before the close button. */
|
|
86
|
+
children?: ReactNode;
|
|
87
|
+
}
|
|
88
|
+
export declare const Toast: ({ open, onOpenChange, ...rest }: ToastProps) => import("react/jsx-runtime").JSX.Element;
|
|
89
|
+
//# sourceMappingURL=Toast.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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IACvG,aAAa,CAAC,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC;IACjC,yGAAyG;IACzG,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,iEAAiE;IACjE,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,2BAA2B;IAC3B,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,6CAA6C;IAC7C,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,yDAAyD;IACzD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,qFAAqF;IACrF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;IAC1B,mFAAmF;IACnF,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AA0HD,eAAO,MAAM,KAAK,GAAI,iCAAiC,UAAU,4CAShE,CAAC"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cloneElement, createContext, useContext, useState, useEffect, useRef, } from 'react';
|
|
3
|
+
import { createPortal } from 'react-dom';
|
|
4
|
+
import { useModalUtils } from '../hooks/use-modal-utils';
|
|
5
|
+
import { useTheme } from '../hooks/use-theme';
|
|
6
|
+
import { cn } from '../shared/cn';
|
|
7
|
+
import { Button } from './Button';
|
|
8
|
+
import { CloseIcon } from './icons/CloseIcon';
|
|
9
|
+
import { ModalController } from './ModalController';
|
|
10
|
+
import { Surface } from './Surface';
|
|
11
|
+
const ToastRootContext = createContext(null);
|
|
12
|
+
/**
|
|
13
|
+
* State container for the `Toast` + `ToastTrigger` + `Toast` compound. Less commonly used than
|
|
14
|
+
* the imperative `useToasts()` portal API - prefer the portal for app-wide notifications and
|
|
15
|
+
* use this only when you need a toast tied to a specific trigger element in JSX.
|
|
16
|
+
*/
|
|
17
|
+
export const ToastRoot = ({ children, defaultOpen = false, open: openProp, onOpenChange, }) => {
|
|
18
|
+
const [internalOpen, setInternalOpen] = useState(defaultOpen);
|
|
19
|
+
const isControlled = openProp !== undefined;
|
|
20
|
+
const open = isControlled ? openProp : internalOpen;
|
|
21
|
+
const setOpen = (newOpen) => {
|
|
22
|
+
if (!isControlled)
|
|
23
|
+
setInternalOpen(newOpen);
|
|
24
|
+
onOpenChange?.(newOpen);
|
|
25
|
+
};
|
|
26
|
+
return (_jsx(ToastRootContext.Provider, { value: { open, setOpen }, children: children }));
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Wraps a single child element to act as the toast trigger. **Clones** the child to attach
|
|
30
|
+
* an `onClick` handler that toggles the surrounding `ToastRoot`'s open state (composed with
|
|
31
|
+
* any existing `onClick` on the child).
|
|
32
|
+
*
|
|
33
|
+
* No-ops (renders the child as-is) when used outside a `ToastRoot`.
|
|
34
|
+
*/
|
|
35
|
+
export const ToastTrigger = ({ children }) => {
|
|
36
|
+
const ctx = useContext(ToastRootContext);
|
|
37
|
+
if (!ctx)
|
|
38
|
+
return _jsx(_Fragment, { children: children });
|
|
39
|
+
const child = children;
|
|
40
|
+
const originalOnClick = child?.props?.onClick;
|
|
41
|
+
const onClick = (e) => {
|
|
42
|
+
if (originalOnClick)
|
|
43
|
+
originalOnClick(e);
|
|
44
|
+
ctx.setOpen(!ctx.open);
|
|
45
|
+
};
|
|
46
|
+
return cloneElement(child, { onClick });
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Wraps a single child element to close the surrounding toast when clicked. **Clones** the
|
|
50
|
+
* child to attach an `onClick` handler that flips the surrounding `ToastRoot`'s open state
|
|
51
|
+
* to `false` (composed with any existing `onClick` on the child).
|
|
52
|
+
*
|
|
53
|
+
* ```tsx
|
|
54
|
+
* <ToastRoot>
|
|
55
|
+
* <ToastTrigger><Button>Notify</Button></ToastTrigger>
|
|
56
|
+
* <Toast title="...">
|
|
57
|
+
* <ToastClose><Button>Dismiss</Button></ToastClose>
|
|
58
|
+
* </Toast>
|
|
59
|
+
* </ToastRoot>
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* No-ops (renders the child as-is) when used outside a `ToastRoot`.
|
|
63
|
+
*/
|
|
64
|
+
export const ToastClose = ({ children }) => {
|
|
65
|
+
const ctx = useContext(ToastRootContext);
|
|
66
|
+
if (!ctx)
|
|
67
|
+
return _jsx(_Fragment, { children: children });
|
|
68
|
+
const child = children;
|
|
69
|
+
const originalOnClick = child?.props?.onClick;
|
|
70
|
+
const onClick = (e) => {
|
|
71
|
+
if (originalOnClick)
|
|
72
|
+
originalOnClick(e);
|
|
73
|
+
ctx.setOpen(false);
|
|
74
|
+
};
|
|
75
|
+
return cloneElement(child, { onClick });
|
|
76
|
+
};
|
|
77
|
+
const ToastInner = (props) => {
|
|
78
|
+
const theme = useTheme();
|
|
79
|
+
const { root = '#app, #__next, #root', phase = 'closed', onPhaseChange = () => { }, onClosed = () => { }, className = '', title, text, stopPropagationOnClick, closeButton = true, color = 'neutral', icon, iconComponent, surfaceLevel = theme === 'dark' ? 3 : 1, variant = 'gradient', outline = true, timeout = 5000, ref, children, } = props;
|
|
80
|
+
const elRef = useRef(null);
|
|
81
|
+
const timeoutRef = useRef(null);
|
|
82
|
+
const { opened, open, close } = useModalUtils({
|
|
83
|
+
phase,
|
|
84
|
+
onPhaseChange,
|
|
85
|
+
onClosed,
|
|
86
|
+
closeOnEscape: false,
|
|
87
|
+
transitionEndElRef: elRef,
|
|
88
|
+
});
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
open();
|
|
91
|
+
if (timeout && timeout > 0) {
|
|
92
|
+
timeoutRef.current = setTimeout(() => {
|
|
93
|
+
close();
|
|
94
|
+
}, timeout);
|
|
95
|
+
}
|
|
96
|
+
return () => {
|
|
97
|
+
if (timeoutRef.current) {
|
|
98
|
+
clearTimeout(timeoutRef.current);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}, []);
|
|
102
|
+
const IconComponent = iconComponent;
|
|
103
|
+
const content = (_jsxs(Surface, { className: cn(`toast fixed right-safe-4 bottom-safe-4 z-50 max-w-full origin-bottom rounded-3xl`, !opened &&
|
|
104
|
+
cn('translate-y-4 scale-75 opacity-0 duration-200 ease-out!'), opened &&
|
|
105
|
+
'scale-100 opacity-100 duration-500 ease-[cubic-bezier(0,1,0.2,1.1)] has-[+.toast+.toast+.toast:not(.toast-closing)]:opacity-0 has-[+.toast+.toast:not(.toast-closing)]:-translate-y-8 has-[+.toast+.toast:not(.toast-closing)]:scale-80 has-[+.toast:not(.toast-closing)]:origin-top has-[+.toast:not(.toast-closing)]:-translate-y-4 has-[+.toast:not(.toast-closing)]:scale-90', phase === 'closing' && 'toast-closing', className), ref: (el) => {
|
|
106
|
+
elRef.current = el;
|
|
107
|
+
if (typeof ref === 'function') {
|
|
108
|
+
ref(el);
|
|
109
|
+
}
|
|
110
|
+
else if (ref) {
|
|
111
|
+
ref.current = el;
|
|
112
|
+
}
|
|
113
|
+
}, level: surfaceLevel, variant: variant, outline: outline, color: color, contentClassName: "flex items-center gap-4 pl-4 pr-2 py-2", onClick: (e) => {
|
|
114
|
+
if (stopPropagationOnClick) {
|
|
115
|
+
e.stopPropagation();
|
|
116
|
+
}
|
|
117
|
+
}, children: [icon ||
|
|
118
|
+
(iconComponent && (_jsxs("div", { className: "flex shrink-0 items-center [&>svg]:size-4 [&>svg]:shrink-0", children: [icon, iconComponent && _jsx(IconComponent, {})] }))), (title || text) && (_jsxs("div", { className: "flex flex-col gap-1", children: [title && _jsx("div", { className: "text-sm font-semibold", children: title }), text && _jsx("div", { className: "text-xs leading-relaxed", children: text })] })), children, closeButton && (_jsx("div", { className: "ml-auto", children: _jsx(Button, { rounded: true, outline: false, variant: "transparent", onClick: () => {
|
|
119
|
+
close();
|
|
120
|
+
}, children: _jsx(CloseIcon, {}) }) }))] }));
|
|
121
|
+
return root ? createPortal(content, document.querySelector(root)) : content;
|
|
122
|
+
};
|
|
123
|
+
export const Toast = ({ open, onOpenChange, ...rest }) => {
|
|
124
|
+
const ctx = useContext(ToastRootContext);
|
|
125
|
+
const effectiveOpen = open ?? ctx?.open ?? false;
|
|
126
|
+
const effectiveOnOpenChange = onOpenChange ?? ctx?.setOpen ?? (() => { });
|
|
127
|
+
return (_jsx(ModalController, { open: effectiveOpen, onOpenChange: effectiveOnOpenChange, children: _jsx(ToastInner, { ...rest }) }));
|
|
128
|
+
};
|
|
129
|
+
//# sourceMappingURL=Toast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Toast.js","sourceRoot":"","sources":["../../../src/components/Toast.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,YAAY,EACZ,aAAa,EACb,UAAU,EACV,QAAQ,EAKR,SAAS,EACT,MAAM,GACP,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;AAElC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAc,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,OAAO,EAAkB,MAAM,WAAW,CAAC;AAOpD,MAAM,gBAAgB,GAAG,aAAa,CAA+B,IAAI,CAAC,CAAC;AAE3E;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,EACxB,QAAQ,EACR,WAAW,GAAG,KAAK,EACnB,IAAI,EAAE,QAAQ,EACd,YAAY,GASb,EAAE,EAAE;IACH,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC;IAE9D,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
|
|
1
|
+
{"version":3,"file":"ToastsPortal.d.ts","sourceRoot":"","sources":["../../../src/components/ToastsPortal.tsx"],"names":[],"mappings":"AAGA,wBAAgB,YAAY,mDA+B3B"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Toast } from './Toast';
|
|
3
|
+
import { useToastsPortalContext } from './ToastsPortalContext';
|
|
4
|
+
export function ToastsPortal() {
|
|
5
|
+
const { data, state, setState, setData } = useToastsPortalContext();
|
|
6
|
+
if (!data)
|
|
7
|
+
return null;
|
|
8
|
+
return (_jsx(_Fragment, { children: data.map((toast) => (_jsx(Toast, { open: state[toast.id], onOpenChange: (newState) => setState({ ...state, [toast.id]: newState }), title: toast.title, text: toast.text, closeButton: toast.closeButton, icon: toast.icon, iconComponent: toast.iconComponent, color: toast.color, timeout: toast.timeout, className: toast.className, onClosed: () => {
|
|
9
|
+
if (toast.removed)
|
|
10
|
+
return;
|
|
11
|
+
toast.removed = true;
|
|
12
|
+
data.splice(data.indexOf(toast), 1);
|
|
13
|
+
setData([...data]);
|
|
14
|
+
toast.onClosed?.(false);
|
|
15
|
+
} }, toast.id))) }));
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=ToastsPortal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToastsPortal.js","sourceRoot":"","sources":["../../../src/components/ToastsPortal.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,MAAM,UAAU,YAAY;IAC1B,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,sBAAsB,EAAE,CAAC;IACpE,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IACvB,OAAO,CACL,4BACG,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CACnB,KAAC,KAAK,IACJ,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,EACrB,YAAY,EAAE,CAAC,QAAQ,EAAE,EAAE,CACzB,QAAQ,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAG9C,KAAK,EAAE,KAAK,CAAC,KAAK,EAClB,IAAI,EAAE,KAAK,CAAC,IAAI,EAChB,WAAW,EAAE,KAAK,CAAC,WAAW,EAC9B,IAAI,EAAE,KAAK,CAAC,IAAI,EAChB,aAAa,EAAE,KAAK,CAAC,aAAa,EAClC,KAAK,EAAE,KAAK,CAAC,KAAK,EAClB,OAAO,EAAE,KAAK,CAAC,OAAO,EACtB,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,QAAQ,EAAE,GAAG,EAAE;gBACb,IAAI,KAAK,CAAC,OAAO;oBAAE,OAAO;gBAC1B,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;gBACrB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;gBACpC,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;gBACnB,KAAK,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAC;YAC1B,CAAC,IAfI,KAAK,CAAC,EAAE,CAgBb,CACH,CAAC,GACD,CACJ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Color } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Shape of a queued toast in the imperative toast portal. Mirrors `ToastProps` but adds an
|
|
4
|
+
* `id` (used as React key + lifecycle handle) and an internal `removed` flag.
|
|
5
|
+
*/
|
|
6
|
+
export type ToastsPortalData = {
|
|
7
|
+
/** Stable identifier - also used as the React key when rendering the toast list. */
|
|
8
|
+
id: string;
|
|
9
|
+
/** Toast title (bold line). */
|
|
10
|
+
title: string;
|
|
11
|
+
/** Toast body text. */
|
|
12
|
+
text: string | React.ReactNode;
|
|
13
|
+
/** Render the auto close button. Default `true` (in `Toast`). */
|
|
14
|
+
closeButton?: boolean;
|
|
15
|
+
/** Icon node rendered before the text content. */
|
|
16
|
+
icon?: React.ReactNode;
|
|
17
|
+
/** Icon component instantiated as `<IconComponent />` (no props). */
|
|
18
|
+
iconComponent?: React.ElementType<any>;
|
|
19
|
+
/** Accent color token. */
|
|
20
|
+
color?: Color;
|
|
21
|
+
/** Internal flag set after `onClosed` fires once - prevents double-removal from the queue. */
|
|
22
|
+
removed?: boolean;
|
|
23
|
+
/** Auto-close timeout in ms (`0` disables). */
|
|
24
|
+
timeout?: number;
|
|
25
|
+
/** Extra classes for the toast surface. */
|
|
26
|
+
className?: string;
|
|
27
|
+
/** Fires after the close transition completes. */
|
|
28
|
+
onClosed?: (closed: boolean) => void;
|
|
29
|
+
};
|
|
30
|
+
export declare const ToastsPortalContext: import("react").Context<{
|
|
31
|
+
data: ToastsPortalData[];
|
|
32
|
+
setData: React.Dispatch<React.SetStateAction<ToastsPortalData[]>>;
|
|
33
|
+
state: Record<string, boolean>;
|
|
34
|
+
setState: React.Dispatch<React.SetStateAction<Record<string, boolean>>>;
|
|
35
|
+
}>;
|
|
36
|
+
export declare const ToastsPortalProvider: ({ children, }: {
|
|
37
|
+
children: React.ReactNode;
|
|
38
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
39
|
+
export declare const useToastsPortalContext: () => {
|
|
40
|
+
data: ToastsPortalData[];
|
|
41
|
+
setData: React.Dispatch<React.SetStateAction<ToastsPortalData[]>>;
|
|
42
|
+
state: Record<string, boolean>;
|
|
43
|
+
setState: React.Dispatch<React.SetStateAction<Record<string, boolean>>>;
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=ToastsPortalContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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sB;UAzB3B,gBAAgB,EAAE;aACf,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,gBAAgB,EAAE,CAAC,CAAC;WAC1D,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;cACpB,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAwBxE,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useState } from 'react';
|
|
3
|
+
export const ToastsPortalContext = createContext({
|
|
4
|
+
data: [],
|
|
5
|
+
setData: () => { },
|
|
6
|
+
state: {},
|
|
7
|
+
setState: () => { },
|
|
8
|
+
});
|
|
9
|
+
export const ToastsPortalProvider = ({ children, }) => {
|
|
10
|
+
const [data, setData] = useState([]);
|
|
11
|
+
const [state, setState] = useState({});
|
|
12
|
+
return (_jsx(ToastsPortalContext.Provider, { value: { data, setData, state, setState }, children: children }));
|
|
13
|
+
};
|
|
14
|
+
export const useToastsPortalContext = () => {
|
|
15
|
+
return useContext(ToastsPortalContext);
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=ToastsPortalContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToastsPortalContext.js","sourceRoot":"","sources":["../../../src/components/ToastsPortalContext.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAiC5D,MAAM,CAAC,MAAM,mBAAmB,GAAG,aAAa,CAK7C;IACD,IAAI,EAAE,EAAE;IACR,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;IACjB,KAAK,EAAE,EAAE;IACT,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC;CACnB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,EACnC,QAAQ,GAGT,EAAE,EAAE;IACH,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAqB,EAAE,CAAC,CAAC;IACzD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAA0B,EAAE,CAAC,CAAC;IAChE,OAAO,CACL,KAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,YACpE,QAAQ,GACoB,CAChC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,OAAO,UAAU,CAAC,mBAAmB,CAAC,CAAC;AACzC,CAAC,CAAC"}
|