@ufoui/core 0.0.5 → 0.0.12
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/assets/icons.d.ts +3 -0
- package/components/accordion/accordion.d.ts +31 -3
- package/components/accordion/accordionItem.d.ts +31 -3
- package/components/base/boxBase.d.ts +15 -37
- package/components/base/buttonBase.d.ts +1 -1
- package/components/base/dialogBase.d.ts +9 -7
- package/components/base/fieldBase.d.ts +2 -3
- package/components/base/textBase.d.ts +1 -2
- package/components/breadcrumbs/breadcrumbs.d.ts +48 -0
- package/components/calendar/calendar.d.ts +23 -0
- package/components/calendar/calendarUtils.d.ts +18 -0
- package/components/collapse/collapse.d.ts +15 -20
- package/components/dialogs/dialog.d.ts +1 -1
- package/components/dialogs/dialogTitle.d.ts +1 -1
- package/components/dialogs/drawer.d.ts +1 -1
- package/components/fieldset/fieldset.d.ts +1 -1
- package/components/link/link.d.ts +58 -0
- package/components/list/list.d.ts +1 -1
- package/components/rating/rating.d.ts +68 -0
- package/components/slider/slider.d.ts +11 -0
- package/components/switch/switch.d.ts +1 -9
- package/components/toast/toast.d.ts +18 -4
- package/components/toast/toastViewport.d.ts +4 -3
- package/components/toolbar/toolbar.d.ts +1 -1
- package/context/selectionContext.d.ts +18 -17
- package/hooks/index.d.ts +3 -1
- package/hooks/useAnimate.d.ts +36 -16
- package/hooks/useFocusTrap.d.ts +32 -0
- package/hooks/useFocusVisible.d.ts +16 -14
- package/hooks/useResizeObserver.d.ts +7 -3
- package/hooks/useRovingFocus.d.ts +30 -0
- package/hooks/useSelection.d.ts +10 -7
- package/hooks/useSelectionState.d.ts +29 -0
- package/hooks/useSliderKeys.d.ts +41 -0
- package/index.css +1 -1
- package/index.d.ts +4 -8
- package/index.js +4881 -0
- package/internal/controlGrid/controlGrid.d.ts +32 -0
- package/internal/controlLabel/controlLabel.d.ts +31 -0
- package/internal/description/description.d.ts +18 -0
- package/internal/index.d.ts +6 -0
- package/internal/inlineTooltip/index.d.ts +1 -0
- package/internal/inlineTooltip/inlineTooltipManager.d.ts +1 -1
- package/internal/slots/slot.d.ts +44 -0
- package/internal/stateLayer/stateLayer.d.ts +33 -0
- package/package.json +12 -3
- package/utils/color.d.ts +0 -102
- package/utils/getWrapperStyle.d.ts +53 -0
- package/utils/index.d.ts +1 -0
- package/utils/toasts/ensureViewport.d.ts +6 -1
- package/utils/toasts/toast.d.ts +66 -10
- package/utils/toasts/toastStore.d.ts +55 -1
- package/utils/utils.d.ts +65 -53
- package/hooks/useFocusState.d.ts +0 -16
- package/index.mjs +0 -4649
- package/internal/inlineTooltip/inlineTooltip.d.ts +0 -11
- package/internal/inlineTooltip/inlineTooltip2.d.ts +0 -10
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { ElementTextPlacement } from '../../utils';
|
|
3
|
+
/**
|
|
4
|
+
* Props for the ControlGrid component.
|
|
5
|
+
*
|
|
6
|
+
* Layout container for form control, label and description.
|
|
7
|
+
*
|
|
8
|
+
* @category Slot
|
|
9
|
+
*/
|
|
10
|
+
export interface ControlGridProps {
|
|
11
|
+
/** Main control element such as checkbox, switch or slider. */
|
|
12
|
+
control?: ReactNode;
|
|
13
|
+
/** Label displayed next to the control. */
|
|
14
|
+
label?: ReactNode;
|
|
15
|
+
/** Supporting text such as description or error message. */
|
|
16
|
+
description?: ReactNode;
|
|
17
|
+
/** Placement of label relative to the control. */
|
|
18
|
+
textPlacement: ElementTextPlacement;
|
|
19
|
+
/** Additional root class name. */
|
|
20
|
+
className?: string;
|
|
21
|
+
/** Spans description across all grid columns. */
|
|
22
|
+
spanDesc?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Layout helper that arranges control, label and description.
|
|
26
|
+
*
|
|
27
|
+
* @function
|
|
28
|
+
* @param props Component properties.
|
|
29
|
+
*
|
|
30
|
+
* @category Slot
|
|
31
|
+
*/
|
|
32
|
+
export declare const ControlGrid: import('react').ForwardRefExoticComponent<ControlGridProps & import('react').RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ElementType, ReactNode, RefObject } from 'react';
|
|
2
|
+
import { ElementFont } from '../../utils';
|
|
3
|
+
export interface ControlLabelProps {
|
|
4
|
+
/** Label content. */
|
|
5
|
+
label?: ReactNode;
|
|
6
|
+
/** ID of the associated control element. Used when tag is 'label'. */
|
|
7
|
+
htmlFor?: string;
|
|
8
|
+
/** DOM id applied to the label element. */
|
|
9
|
+
id?: string;
|
|
10
|
+
/** Reference to a control element that should receive focus when the label is clicked. */
|
|
11
|
+
focusRef?: RefObject<HTMLElement>;
|
|
12
|
+
/** Displays a required indicator next to the label. */
|
|
13
|
+
required?: boolean;
|
|
14
|
+
/** Font applied to the label text. */
|
|
15
|
+
font?: ElementFont;
|
|
16
|
+
/** HTML tag used to render the label element. Default: 'label'. */
|
|
17
|
+
tag?: ElementType;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Renders a label for form controls.
|
|
21
|
+
*
|
|
22
|
+
* Supports both native label behaviour and ARIA labeling for custom controls.
|
|
23
|
+
* When tag is 'label', htmlFor associates the label with a form element.
|
|
24
|
+
* When focusRef is provided, clicking the label focuses the referenced control.
|
|
25
|
+
*
|
|
26
|
+
* @function
|
|
27
|
+
* @param props Component properties.
|
|
28
|
+
*
|
|
29
|
+
* @category Slot
|
|
30
|
+
*/
|
|
31
|
+
export declare const ControlLabel: ({ label, htmlFor, id, required, font, focusRef, tag: Tag, }: ControlLabelProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
export interface DescriptionProps extends HTMLAttributes<HTMLElement> {
|
|
3
|
+
/** Supporting description text. */
|
|
4
|
+
description?: ReactNode;
|
|
5
|
+
/** Error message text. Overrides description when present. */
|
|
6
|
+
error?: ReactNode;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Renders supporting text such as description or error message.
|
|
10
|
+
*
|
|
11
|
+
* Error message takes precedence over description.
|
|
12
|
+
*
|
|
13
|
+
* @function
|
|
14
|
+
* @param props Component properties.
|
|
15
|
+
*
|
|
16
|
+
* @category Slot
|
|
17
|
+
*/
|
|
18
|
+
export declare const Description: ({ description, error, ...rest }: DescriptionProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './inlineTooltipManager';
|
|
@@ -6,7 +6,7 @@ interface InlineTooltipManagerProps extends HTMLProps<HTMLSpanElement> {
|
|
|
6
6
|
align: ElementAlign;
|
|
7
7
|
}
|
|
8
8
|
export declare const InlineTooltipManager: {
|
|
9
|
-
({ tooltip, align, triggerRef
|
|
9
|
+
({ tooltip, align, triggerRef }: InlineTooltipManagerProps): React.ReactPortal;
|
|
10
10
|
displayName: string;
|
|
11
11
|
};
|
|
12
12
|
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Props for the Slot component.
|
|
4
|
+
*
|
|
5
|
+
* @category Slot
|
|
6
|
+
*/
|
|
7
|
+
interface SlotProps {
|
|
8
|
+
/** Element rendered before the content. */
|
|
9
|
+
start?: ReactNode;
|
|
10
|
+
/** Element rendered after the content. */
|
|
11
|
+
end?: ReactNode;
|
|
12
|
+
/** Main slot content. */
|
|
13
|
+
content: ReactNode;
|
|
14
|
+
/** Root class name. */
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Layout helper that renders start, content, and end regions.
|
|
19
|
+
*
|
|
20
|
+
* @function
|
|
21
|
+
* @param props Component properties.
|
|
22
|
+
*
|
|
23
|
+
* @category Slot
|
|
24
|
+
*/
|
|
25
|
+
export declare const Slot: ({ start, end, content, className }: SlotProps) => import("react/jsx-runtime").JSX.Element;
|
|
26
|
+
/**
|
|
27
|
+
* Slot wrapper for leading content.
|
|
28
|
+
*
|
|
29
|
+
* @function
|
|
30
|
+
* @param props Component properties.
|
|
31
|
+
*
|
|
32
|
+
* @category Slot
|
|
33
|
+
*/
|
|
34
|
+
export declare const Leading: (props: SlotProps) => import("react/jsx-runtime").JSX.Element;
|
|
35
|
+
/**
|
|
36
|
+
* Slot wrapper for trailing content.
|
|
37
|
+
*
|
|
38
|
+
* @function
|
|
39
|
+
* @param props Component properties.
|
|
40
|
+
*
|
|
41
|
+
* @category Slot
|
|
42
|
+
*/
|
|
43
|
+
export declare const Trailing: (props: SlotProps) => import("react/jsx-runtime").JSX.Element;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { SurfaceColor } from '../../utils';
|
|
2
|
+
/**
|
|
3
|
+
* Props for StateLayer component.
|
|
4
|
+
*
|
|
5
|
+
* @category Internal components
|
|
6
|
+
*/
|
|
7
|
+
export interface StateLayerProps {
|
|
8
|
+
/** Background color token. */
|
|
9
|
+
color?: SurfaceColor;
|
|
10
|
+
/** Additional class name. */
|
|
11
|
+
className?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* StateLayer component.
|
|
15
|
+
*
|
|
16
|
+
* Renders a visual state layer used for hover, focus, pressed and selected effects.
|
|
17
|
+
*
|
|
18
|
+
* @param color Background color token.
|
|
19
|
+
* @param className Additional class name.
|
|
20
|
+
*
|
|
21
|
+
* @function
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* <Component>
|
|
25
|
+
* <StateLayer />
|
|
26
|
+
* </Component>
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* <StateLayer color="primary" />
|
|
30
|
+
*
|
|
31
|
+
* @category Internal components
|
|
32
|
+
*/
|
|
33
|
+
export declare const StateLayer: ({ color, className }: StateLayerProps) => import("react/jsx-runtime").JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ufoui/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "Lightweight Material Design 3 UI components for React",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.mjs",
|
|
@@ -14,10 +14,19 @@
|
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
16
16
|
"react",
|
|
17
|
+
"react-components",
|
|
17
18
|
"components",
|
|
19
|
+
"material-design",
|
|
20
|
+
"material-design-3",
|
|
21
|
+
"md3",
|
|
22
|
+
"material-you",
|
|
18
23
|
"ui",
|
|
24
|
+
"ui-kit",
|
|
25
|
+
"component-library",
|
|
26
|
+
"typescript",
|
|
27
|
+
"esm",
|
|
19
28
|
"ufoui",
|
|
20
|
-
"
|
|
29
|
+
"ufo-ui"
|
|
21
30
|
],
|
|
22
31
|
"peerDependencies": {
|
|
23
32
|
"react": "^18.0.0",
|
|
@@ -35,4 +44,4 @@
|
|
|
35
44
|
"./style.css": "./index.css",
|
|
36
45
|
"./style": "./index.css"
|
|
37
46
|
}
|
|
38
|
-
}
|
|
47
|
+
}
|
package/utils/color.d.ts
CHANGED
|
@@ -80,7 +80,6 @@ export declare const getSemanticColorClasses: (color: SemanticColor) => {
|
|
|
80
80
|
* for all semantic, extended, and surface tokens defined in {@link ThemeColor}.
|
|
81
81
|
* Enables consistent inverse lookups for text/background pairings.
|
|
82
82
|
*
|
|
83
|
-
* Commonly used by {@link getSurfaceColorClasses}.
|
|
84
83
|
*
|
|
85
84
|
* @category Color
|
|
86
85
|
*/
|
|
@@ -148,104 +147,12 @@ export declare const inverseColorMap: {
|
|
|
148
147
|
readonly onSuccessContainer: "successContainer";
|
|
149
148
|
readonly onErrorContainer: "errorContainer";
|
|
150
149
|
};
|
|
151
|
-
/**
|
|
152
|
-
* Returns utility class names (`uui-*`) for a given surface color and its mapped “on” color.
|
|
153
|
-
*
|
|
154
|
-
* @remarks
|
|
155
|
-
* Uses the {@link inverseColorMap} to find the related “on” color
|
|
156
|
-
* (e.g. `'surfaceContainer'` → `'onSurface'`).
|
|
157
|
-
* Produces `text`, `border`, and `background` variants for both.
|
|
158
|
-
* All names are kebab-cased (e.g. `'surfaceContainerHigh'` → `'surface-container-high'`).
|
|
159
|
-
*
|
|
160
|
-
* @param color - Surface color key (e.g. `'surfaceContainerHigh'`).
|
|
161
|
-
* @returns Object with `uui-text-*`, `uui-border-*`, and `uui-bg-*` class names for base and on-color.
|
|
162
|
-
*
|
|
163
|
-
* @example
|
|
164
|
-
* ```ts
|
|
165
|
-
* getSurfaceColorClasses('surfaceContainer');
|
|
166
|
-
* // → { textColor: 'uui-text-surface-container', textOnColor: 'uui-text-on-surface', ... }
|
|
167
|
-
* ```
|
|
168
|
-
* @category Color
|
|
169
|
-
*/
|
|
170
|
-
export declare const getSurfaceColorClasses: (color: SurfaceColor) => {
|
|
171
|
-
readonly textColor: `uui-text-${string}`;
|
|
172
|
-
readonly textOnColor: `uui-text-${string}`;
|
|
173
|
-
readonly borderColor: `uui-border-${string}`;
|
|
174
|
-
readonly borderOnColor: `uui-border-${string}`;
|
|
175
|
-
readonly bgColor: `uui-bg-${string}`;
|
|
176
|
-
readonly bgOnColor: `uui-bg-${string}`;
|
|
177
|
-
};
|
|
178
|
-
/**
|
|
179
|
-
* Returns utility class names (`uui-*`) for any theme color token.
|
|
180
|
-
*
|
|
181
|
-
* @remarks
|
|
182
|
-
* Generates `text`, `border`, and `background` class names based on the provided
|
|
183
|
-
* {@link ThemeColor}. If the color key is invalid, `'primary'` is used as fallback.
|
|
184
|
-
*
|
|
185
|
-
* @param color - Theme color token (e.g. `'primary'`, `'surfaceContainerHigh'`, `'error'`).
|
|
186
|
-
* @returns An object with `uui-text-*`, `uui-border-*`, and `uui-bg-*` class names.
|
|
187
|
-
*
|
|
188
|
-
* @example
|
|
189
|
-
* ```ts
|
|
190
|
-
* getColorClasses('error');
|
|
191
|
-
* // → { textColor: 'uui-text-error', borderColor: 'uui-border-error', bgColor: 'uui-bg-error' }
|
|
192
|
-
* ```
|
|
193
|
-
* @category Color
|
|
194
|
-
*/
|
|
195
|
-
export declare const getColorClasses: (color: ThemeColor) => {
|
|
196
|
-
readonly textColor: `uui-text-${string}`;
|
|
197
|
-
readonly borderColor: `uui-border-${string}`;
|
|
198
|
-
readonly bgColor: `uui-bg-${string}`;
|
|
199
|
-
};
|
|
200
150
|
/**
|
|
201
151
|
* Represents the available border color options.
|
|
202
152
|
*
|
|
203
153
|
* @category Color
|
|
204
154
|
*/
|
|
205
155
|
export type BorderColor = SurfaceColor;
|
|
206
|
-
/**
|
|
207
|
-
* Returns the appropriate border color class for a given configuration.
|
|
208
|
-
*
|
|
209
|
-
* @remarks
|
|
210
|
-
* Typical border colors are `'outline'` and `'outlineVariant'`, matching MD3 tokens.
|
|
211
|
-
* @param borderColor - Border color keyword or surface color token.
|
|
212
|
-
* @returns The resolved border color class (e.g. `'uui-border-surface-container-high'`).
|
|
213
|
-
*
|
|
214
|
-
* @example
|
|
215
|
-
* ```ts
|
|
216
|
-
* getBorderColorClass('surfaceContainer'); // → 'uui-border-surface-container'
|
|
217
|
-
* ```
|
|
218
|
-
* @category Color
|
|
219
|
-
*/
|
|
220
|
-
export declare function getBorderColorClass(borderColor: BorderColor): `uui-border-${string}`;
|
|
221
|
-
/**
|
|
222
|
-
* Returns all CSS variable references for a **semantic color**.
|
|
223
|
-
*
|
|
224
|
-
* @remarks
|
|
225
|
-
* Generates `var(--uui-color-*)` tokens only for semantic colors
|
|
226
|
-
* defined in {@link SemanticColor} (e.g. `primary`, `error`, `success`).
|
|
227
|
-
* Useful for dynamic component theming and inline styles.
|
|
228
|
-
*
|
|
229
|
-
* @param color - Semantic color key (e.g. `'primary'`, `'error'`, `'info'`).
|
|
230
|
-
* @returns Object containing `var(--uui-color-...)` references for all variants.
|
|
231
|
-
*
|
|
232
|
-
* @example
|
|
233
|
-
* ```ts
|
|
234
|
-
* const vars = getSemanticColorVar('primary');
|
|
235
|
-
* // → "var(--uui-color-primary)", "var(--uui-color-on-primary)"
|
|
236
|
-
* ```
|
|
237
|
-
* @category Color
|
|
238
|
-
*/
|
|
239
|
-
export declare const getSemanticColorVar: (color: SemanticColor) => {
|
|
240
|
-
color: string;
|
|
241
|
-
onColor: string;
|
|
242
|
-
container: string;
|
|
243
|
-
onContainer: string;
|
|
244
|
-
fixed: string;
|
|
245
|
-
fixedDim: string;
|
|
246
|
-
onFixed: string;
|
|
247
|
-
onFixedVariant: string;
|
|
248
|
-
};
|
|
249
156
|
/**
|
|
250
157
|
* Returns basic CSS variable references for a **surface color**.
|
|
251
158
|
*
|
|
@@ -312,14 +219,5 @@ export declare const hexToRgb: (colorValue: string) => string;
|
|
|
312
219
|
* @category Color
|
|
313
220
|
*/
|
|
314
221
|
export declare function getTintOverlayColor(elevation: number, tintColor: string): string;
|
|
315
|
-
/**
|
|
316
|
-
* Returns a set of predefined utility class names for fixed theme colors.
|
|
317
|
-
*
|
|
318
|
-
* Each entry maps text, border, outline, and background variants like:
|
|
319
|
-
* `textSurface`, `bgOnSurface`, `borderOutlineVariant`, etc.
|
|
320
|
-
*
|
|
321
|
-
* @returns Object with fixed color class mappings.
|
|
322
|
-
*/
|
|
323
|
-
export declare const getFixedColorClasses: () => Record<string, string>;
|
|
324
222
|
export declare function capitalize(s: string): string;
|
|
325
223
|
export declare function getBorderColor(borderColor?: BorderColor): BorderColor;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Props for wrapper-level behavior.
|
|
4
|
+
*
|
|
5
|
+
* Applies outer layout such as margin, positioning and stacking.
|
|
6
|
+
* Does not affect internal layout or content.
|
|
7
|
+
*
|
|
8
|
+
* @category Utils
|
|
9
|
+
*/
|
|
10
|
+
export type WrapperProps = {
|
|
11
|
+
/** Margin on all sides. */
|
|
12
|
+
m?: number | string;
|
|
13
|
+
/** Horizontal margin (left + right). */
|
|
14
|
+
mx?: number | string;
|
|
15
|
+
/** Vertical margin (top + bottom). */
|
|
16
|
+
my?: number | string;
|
|
17
|
+
/** Margin top. */
|
|
18
|
+
mt?: number | string;
|
|
19
|
+
/** Margin bottom. */
|
|
20
|
+
mb?: number | string;
|
|
21
|
+
/** Margin left. */
|
|
22
|
+
ml?: number | string;
|
|
23
|
+
/** Margin right. */
|
|
24
|
+
mr?: number | string;
|
|
25
|
+
/** Top offset. */
|
|
26
|
+
top?: number | string;
|
|
27
|
+
/** Right offset. */
|
|
28
|
+
right?: number | string;
|
|
29
|
+
/** Bottom offset. */
|
|
30
|
+
bottom?: number | string;
|
|
31
|
+
/** Left offset. */
|
|
32
|
+
left?: number | string;
|
|
33
|
+
/** Stacking order. */
|
|
34
|
+
zIndex?: number;
|
|
35
|
+
/** CSS position value. */
|
|
36
|
+
position?: CSSProperties['position'];
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Resolves wrapper props into style and remaining props.
|
|
40
|
+
*
|
|
41
|
+
* Margin shorthands priority:
|
|
42
|
+
* mt/ml/... overrides mx/my, which overrides m.
|
|
43
|
+
*
|
|
44
|
+
* @function
|
|
45
|
+
* @param props Wrapper configuration.
|
|
46
|
+
* @returns Object containing wrapperStyle and otherProps.
|
|
47
|
+
*
|
|
48
|
+
* @category Utils
|
|
49
|
+
*/
|
|
50
|
+
export declare function getWrapperStyle(props: WrapperProps): {
|
|
51
|
+
wrapperStyle: CSSProperties;
|
|
52
|
+
otherProps: {};
|
|
53
|
+
};
|
package/utils/index.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Ensures that a global toast viewport exists.
|
|
3
|
+
*
|
|
4
|
+
* If the user already rendered ToastViewport manually,
|
|
5
|
+
* no additional viewport is created.
|
|
6
|
+
*/
|
|
2
7
|
export declare function ensureViewport(): void;
|
package/utils/toasts/toast.d.ts
CHANGED
|
@@ -1,29 +1,85 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { SurfaceColor } from '../index';
|
|
3
|
+
/**
|
|
4
|
+
* Status variant applied to a toast.
|
|
5
|
+
*
|
|
6
|
+
* @category Toast
|
|
7
|
+
*/
|
|
3
8
|
export type ToastStatus = 'success' | 'error' | 'warning' | 'info';
|
|
9
|
+
/**
|
|
10
|
+
* Options used to create or update a toast.
|
|
11
|
+
*
|
|
12
|
+
* @category Toast
|
|
13
|
+
*/
|
|
4
14
|
export interface ToastOptions {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
15
|
+
/** Action element rendered inside the toast. */
|
|
16
|
+
action?: ReactNode | ((id: string) => ReactNode);
|
|
17
|
+
/** Surface color token overriding background and text colors. */
|
|
8
18
|
color?: SurfaceColor;
|
|
9
|
-
|
|
19
|
+
/** Full custom content replacing default layout. */
|
|
20
|
+
content?: ReactNode;
|
|
21
|
+
/** Supporting message text. */
|
|
22
|
+
description?: string;
|
|
23
|
+
/** Leading visual element such as an icon. */
|
|
10
24
|
icon?: ReactNode;
|
|
11
|
-
|
|
12
|
-
|
|
25
|
+
/** Optional identifier. Generated automatically if not provided. */
|
|
26
|
+
id?: string;
|
|
27
|
+
/** Priority toasts appear before normal queued toasts. */
|
|
28
|
+
priority?: boolean;
|
|
29
|
+
/** Status variant applied as CSS modifier class. */
|
|
30
|
+
status?: ToastStatus;
|
|
31
|
+
/** Time in milliseconds before the toast is automatically dismissed. */
|
|
32
|
+
timeout?: number;
|
|
33
|
+
/** Primary heading text. */
|
|
34
|
+
title?: string;
|
|
13
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Message descriptor used by promise helper.
|
|
38
|
+
*
|
|
39
|
+
* @category Toast
|
|
40
|
+
*/
|
|
41
|
+
type ToastPromiseMessage<T> = string | ToastOptions | ((v: T) => string | ToastOptions);
|
|
42
|
+
/**
|
|
43
|
+
* Creates and displays a toast.
|
|
44
|
+
*
|
|
45
|
+
* Accepts either a message string or a ToastOptions object.
|
|
46
|
+
*
|
|
47
|
+
* @function
|
|
48
|
+
*/
|
|
14
49
|
declare function show(input: string | ToastOptions): string;
|
|
50
|
+
/**
|
|
51
|
+
* Toast API used to create, update and manage notifications.
|
|
52
|
+
*
|
|
53
|
+
* @category Toast
|
|
54
|
+
*/
|
|
15
55
|
export declare const toast: typeof show & {
|
|
16
|
-
|
|
56
|
+
/** Updates an existing toast. */
|
|
57
|
+
update: (id: string, partial: import('./toastStore').ToastUpdate) => void;
|
|
58
|
+
/** Removes a toast by id. */
|
|
17
59
|
dismiss: (id: string) => void;
|
|
60
|
+
/** Removes all toasts. */
|
|
18
61
|
clear: () => void;
|
|
62
|
+
/** Creates a success toast. */
|
|
19
63
|
success: (description: string, o?: ToastOptions) => string;
|
|
64
|
+
/** Creates an error toast. */
|
|
20
65
|
error: (description: string, o?: ToastOptions) => string;
|
|
66
|
+
/** Creates an informational toast. */
|
|
21
67
|
info: (description: string, o?: ToastOptions) => string;
|
|
68
|
+
/** Creates a warning toast. */
|
|
22
69
|
warning: (description: string, o?: ToastOptions) => string;
|
|
70
|
+
/**
|
|
71
|
+
* Displays toast lifecycle bound to a promise.
|
|
72
|
+
*
|
|
73
|
+
* Promise toasts use priority so the user immediately
|
|
74
|
+
* sees feedback for the triggered action.
|
|
75
|
+
*
|
|
76
|
+
* @category Toast
|
|
77
|
+
* @function
|
|
78
|
+
*/
|
|
23
79
|
promise<T>(p: Promise<T>, m: {
|
|
24
|
-
loading:
|
|
25
|
-
success:
|
|
26
|
-
error:
|
|
80
|
+
loading: ToastPromiseMessage<void>;
|
|
81
|
+
success: ToastPromiseMessage<T>;
|
|
82
|
+
error: ToastPromiseMessage<unknown>;
|
|
27
83
|
}): Promise<T>;
|
|
28
84
|
};
|
|
29
85
|
export {};
|
|
@@ -1,11 +1,65 @@
|
|
|
1
1
|
import { ToastOptions } from './toast';
|
|
2
|
+
/**
|
|
3
|
+
* Internal toast state stored in the toast store.
|
|
4
|
+
*
|
|
5
|
+
* @category Toast
|
|
6
|
+
*/
|
|
2
7
|
export type ToastState = Required<Pick<ToastOptions, 'id'>> & Omit<ToastOptions, 'id'>;
|
|
8
|
+
/**
|
|
9
|
+
* Partial update object used when modifying a toast.
|
|
10
|
+
*
|
|
11
|
+
* @category Toast
|
|
12
|
+
*/
|
|
13
|
+
export type ToastUpdate = Partial<Omit<ToastOptions, 'id'>>;
|
|
14
|
+
/**
|
|
15
|
+
* Subscriber function receiving current toast list.
|
|
16
|
+
*
|
|
17
|
+
* @category Toast
|
|
18
|
+
*/
|
|
3
19
|
export type ToastStoreSubscriber = (toasts: ToastState[]) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Internal store managing toast lifecycle and subscriptions.
|
|
22
|
+
*
|
|
23
|
+
* @category Toast
|
|
24
|
+
*/
|
|
4
25
|
export declare const toastStore: {
|
|
26
|
+
/**
|
|
27
|
+
* Subscribes to toast state updates.
|
|
28
|
+
*
|
|
29
|
+
* @function
|
|
30
|
+
*/
|
|
5
31
|
subscribe(subscriber: ToastStoreSubscriber): () => void;
|
|
32
|
+
/**
|
|
33
|
+
* Adds a new toast to the store.
|
|
34
|
+
*
|
|
35
|
+
* Priority toasts are inserted at the beginning
|
|
36
|
+
* so they appear before normal queued toasts.
|
|
37
|
+
*
|
|
38
|
+
* @function
|
|
39
|
+
*/
|
|
6
40
|
add(toast: ToastState): void;
|
|
7
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Updates an existing toast.
|
|
43
|
+
*
|
|
44
|
+
* @function
|
|
45
|
+
*/
|
|
46
|
+
update(id: string, partial: ToastUpdate): void;
|
|
47
|
+
/**
|
|
48
|
+
* Removes a toast from the store.
|
|
49
|
+
*
|
|
50
|
+
* @function
|
|
51
|
+
*/
|
|
8
52
|
remove(id: string): void;
|
|
53
|
+
/**
|
|
54
|
+
* Removes all toasts.
|
|
55
|
+
*
|
|
56
|
+
* @function
|
|
57
|
+
*/
|
|
9
58
|
clear(): void;
|
|
59
|
+
/**
|
|
60
|
+
* Returns current toast list snapshot.
|
|
61
|
+
*
|
|
62
|
+
* @function
|
|
63
|
+
*/
|
|
10
64
|
getState(): ToastState[];
|
|
11
65
|
};
|