@cdx-ui/components 0.0.1-beta.79 → 0.0.1-beta.80
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/lib/commonjs/animation/hooks/index.js +17 -0
- package/lib/commonjs/animation/hooks/index.js.map +1 -0
- package/lib/commonjs/animation/hooks/useCombinedAnimationDisabledState.js +50 -0
- package/lib/commonjs/animation/hooks/useCombinedAnimationDisabledState.js.map +1 -0
- package/lib/commonjs/animation/index.js +39 -0
- package/lib/commonjs/animation/index.js.map +1 -0
- package/lib/commonjs/animation/types.js +6 -0
- package/lib/commonjs/animation/types.js.map +1 -0
- package/lib/commonjs/animation/utils.js +223 -0
- package/lib/commonjs/animation/utils.js.map +1 -0
- package/lib/commonjs/components/CLAUDE.md +1 -1
- package/lib/commonjs/components/Card/index.js +45 -17
- package/lib/commonjs/components/Card/index.js.map +1 -1
- package/lib/commonjs/components/Toast/animation.js +329 -0
- package/lib/commonjs/components/Toast/animation.js.map +1 -0
- package/lib/commonjs/components/Toast/hooks.js +66 -0
- package/lib/commonjs/components/Toast/hooks.js.map +1 -0
- package/lib/commonjs/components/Toast/index.js +493 -0
- package/lib/commonjs/components/Toast/index.js.map +1 -0
- package/lib/commonjs/components/Toast/styles.js +141 -0
- package/lib/commonjs/components/Toast/styles.js.map +1 -0
- package/lib/commonjs/components/Toast/types.js +6 -0
- package/lib/commonjs/components/Toast/types.js.map +1 -0
- package/lib/commonjs/components/index.js +12 -0
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/index.js +15 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/providers/animation-settings/index.js +31 -0
- package/lib/commonjs/providers/animation-settings/index.js.map +1 -0
- package/lib/commonjs/providers/animation-settings/provider.js +59 -0
- package/lib/commonjs/providers/animation-settings/provider.js.map +1 -0
- package/lib/commonjs/providers/animation-settings/types.js +6 -0
- package/lib/commonjs/providers/animation-settings/types.js.map +1 -0
- package/lib/commonjs/providers/forge-design/index.js +29 -0
- package/lib/commonjs/providers/forge-design/index.js.map +1 -0
- package/lib/commonjs/providers/forge-design/provider.js +71 -0
- package/lib/commonjs/providers/forge-design/provider.js.map +1 -0
- package/lib/commonjs/providers/forge-design/types.js +6 -0
- package/lib/commonjs/providers/forge-design/types.js.map +1 -0
- package/lib/commonjs/providers/text-component/index.js +28 -0
- package/lib/commonjs/providers/text-component/index.js.map +1 -0
- package/lib/commonjs/providers/text-component/provider.js +11 -0
- package/lib/commonjs/providers/text-component/provider.js.map +1 -0
- package/lib/commonjs/providers/text-component/types.js +6 -0
- package/lib/commonjs/providers/text-component/types.js.map +1 -0
- package/lib/commonjs/providers/toast/index.js +33 -0
- package/lib/commonjs/providers/toast/index.js.map +1 -0
- package/lib/commonjs/providers/toast/insets-container.js +160 -0
- package/lib/commonjs/providers/toast/insets-container.js.map +1 -0
- package/lib/commonjs/providers/toast/lifecycle.context.js +36 -0
- package/lib/commonjs/providers/toast/lifecycle.context.js.map +1 -0
- package/lib/commonjs/providers/toast/provider.js +508 -0
- package/lib/commonjs/providers/toast/provider.js.map +1 -0
- package/lib/commonjs/providers/toast/reducer.js +46 -0
- package/lib/commonjs/providers/toast/reducer.js.map +1 -0
- package/lib/commonjs/providers/toast/toast-config.context.js +29 -0
- package/lib/commonjs/providers/toast/toast-config.context.js.map +1 -0
- package/lib/commonjs/providers/toast/toast-item-renderer.js +43 -0
- package/lib/commonjs/providers/toast/toast-item-renderer.js.map +1 -0
- package/lib/commonjs/providers/toast/types.js +6 -0
- package/lib/commonjs/providers/toast/types.js.map +1 -0
- package/lib/module/animation/hooks/index.js +4 -0
- package/lib/module/animation/hooks/index.js.map +1 -0
- package/lib/module/animation/hooks/useCombinedAnimationDisabledState.js +47 -0
- package/lib/module/animation/hooks/useCombinedAnimationDisabledState.js.map +1 -0
- package/lib/module/animation/index.js +6 -0
- package/lib/module/animation/index.js.map +1 -0
- package/lib/module/animation/types.js +4 -0
- package/lib/module/animation/types.js.map +1 -0
- package/lib/module/animation/utils.js +212 -0
- package/lib/module/animation/utils.js.map +1 -0
- package/lib/module/components/CLAUDE.md +1 -1
- package/lib/module/components/Card/index.js +47 -19
- package/lib/module/components/Card/index.js.map +1 -1
- package/lib/module/components/Toast/animation.js +324 -0
- package/lib/module/components/Toast/animation.js.map +1 -0
- package/lib/module/components/Toast/hooks.js +61 -0
- package/lib/module/components/Toast/hooks.js.map +1 -0
- package/lib/module/components/Toast/index.js +487 -0
- package/lib/module/components/Toast/index.js.map +1 -0
- package/lib/module/components/Toast/styles.js +138 -0
- package/lib/module/components/Toast/styles.js.map +1 -0
- package/lib/module/components/Toast/types.js +4 -0
- package/lib/module/components/Toast/types.js.map +1 -0
- package/lib/module/components/index.js +1 -0
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/providers/animation-settings/index.js +4 -0
- package/lib/module/providers/animation-settings/index.js.map +1 -0
- package/lib/module/providers/animation-settings/provider.js +52 -0
- package/lib/module/providers/animation-settings/provider.js.map +1 -0
- package/lib/module/providers/animation-settings/types.js +4 -0
- package/lib/module/providers/animation-settings/types.js.map +1 -0
- package/lib/module/providers/forge-design/index.js +5 -0
- package/lib/module/providers/forge-design/index.js.map +1 -0
- package/lib/module/providers/forge-design/provider.js +66 -0
- package/lib/module/providers/forge-design/provider.js.map +1 -0
- package/lib/module/providers/forge-design/types.js +4 -0
- package/lib/module/providers/forge-design/types.js.map +1 -0
- package/lib/module/providers/text-component/index.js +5 -0
- package/lib/module/providers/text-component/index.js.map +1 -0
- package/lib/module/providers/text-component/provider.js +6 -0
- package/lib/module/providers/text-component/provider.js.map +1 -0
- package/lib/module/providers/text-component/types.js +4 -0
- package/lib/module/providers/text-component/types.js.map +1 -0
- package/lib/module/providers/toast/index.js +6 -0
- package/lib/module/providers/toast/index.js.map +1 -0
- package/lib/module/providers/toast/insets-container.js +156 -0
- package/lib/module/providers/toast/insets-container.js.map +1 -0
- package/lib/module/providers/toast/lifecycle.context.js +32 -0
- package/lib/module/providers/toast/lifecycle.context.js.map +1 -0
- package/lib/module/providers/toast/provider.js +503 -0
- package/lib/module/providers/toast/provider.js.map +1 -0
- package/lib/module/providers/toast/reducer.js +42 -0
- package/lib/module/providers/toast/reducer.js.map +1 -0
- package/lib/module/providers/toast/toast-config.context.js +25 -0
- package/lib/module/providers/toast/toast-config.context.js.map +1 -0
- package/lib/module/providers/toast/toast-item-renderer.js +39 -0
- package/lib/module/providers/toast/toast-item-renderer.js.map +1 -0
- package/lib/module/providers/toast/types.js +4 -0
- package/lib/module/providers/toast/types.js.map +1 -0
- package/lib/typescript/animation/hooks/index.d.ts +2 -0
- package/lib/typescript/animation/hooks/index.d.ts.map +1 -0
- package/lib/typescript/animation/hooks/useCombinedAnimationDisabledState.d.ts +22 -0
- package/lib/typescript/animation/hooks/useCombinedAnimationDisabledState.d.ts.map +1 -0
- package/lib/typescript/animation/index.d.ts +4 -0
- package/lib/typescript/animation/index.d.ts.map +1 -0
- package/lib/typescript/animation/types.d.ts +105 -0
- package/lib/typescript/animation/types.d.ts.map +1 -0
- package/lib/typescript/animation/utils.d.ts +120 -0
- package/lib/typescript/animation/utils.d.ts.map +1 -0
- package/lib/typescript/components/Card/index.d.ts +4 -0
- package/lib/typescript/components/Card/index.d.ts.map +1 -1
- package/lib/typescript/components/Toast/animation.d.ts +21 -0
- package/lib/typescript/components/Toast/animation.d.ts.map +1 -0
- package/lib/typescript/components/Toast/hooks.d.ts +17 -0
- package/lib/typescript/components/Toast/hooks.d.ts.map +1 -0
- package/lib/typescript/components/Toast/index.d.ts +28 -0
- package/lib/typescript/components/Toast/index.d.ts.map +1 -0
- package/lib/typescript/components/Toast/styles.d.ts +73 -0
- package/lib/typescript/components/Toast/styles.d.ts.map +1 -0
- package/lib/typescript/components/Toast/types.d.ts +303 -0
- package/lib/typescript/components/Toast/types.d.ts.map +1 -0
- package/lib/typescript/components/index.d.ts +1 -0
- package/lib/typescript/components/index.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +2 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/providers/animation-settings/index.d.ts +3 -0
- package/lib/typescript/providers/animation-settings/index.d.ts.map +1 -0
- package/lib/typescript/providers/animation-settings/provider.d.ts +28 -0
- package/lib/typescript/providers/animation-settings/provider.d.ts.map +1 -0
- package/lib/typescript/providers/animation-settings/types.d.ts +35 -0
- package/lib/typescript/providers/animation-settings/types.d.ts.map +1 -0
- package/lib/typescript/providers/forge-design/index.d.ts +3 -0
- package/lib/typescript/providers/forge-design/index.d.ts.map +1 -0
- package/lib/typescript/providers/forge-design/provider.d.ts +24 -0
- package/lib/typescript/providers/forge-design/provider.d.ts.map +1 -0
- package/lib/typescript/providers/forge-design/types.d.ts +82 -0
- package/lib/typescript/providers/forge-design/types.d.ts.map +1 -0
- package/lib/typescript/providers/text-component/index.d.ts +3 -0
- package/lib/typescript/providers/text-component/index.d.ts.map +1 -0
- package/lib/typescript/providers/text-component/provider.d.ts +7 -0
- package/lib/typescript/providers/text-component/provider.d.ts.map +1 -0
- package/lib/typescript/providers/text-component/types.d.ts +51 -0
- package/lib/typescript/providers/text-component/types.d.ts.map +1 -0
- package/lib/typescript/providers/toast/index.d.ts +5 -0
- package/lib/typescript/providers/toast/index.d.ts.map +1 -0
- package/lib/typescript/providers/toast/insets-container.d.ts +72 -0
- package/lib/typescript/providers/toast/insets-container.d.ts.map +1 -0
- package/lib/typescript/providers/toast/lifecycle.context.d.ts +32 -0
- package/lib/typescript/providers/toast/lifecycle.context.d.ts.map +1 -0
- package/lib/typescript/providers/toast/provider.d.ts +32 -0
- package/lib/typescript/providers/toast/provider.d.ts.map +1 -0
- package/lib/typescript/providers/toast/reducer.d.ts +14 -0
- package/lib/typescript/providers/toast/reducer.d.ts.map +1 -0
- package/lib/typescript/providers/toast/toast-config.context.d.ts +20 -0
- package/lib/typescript/providers/toast/toast-config.context.d.ts.map +1 -0
- package/lib/typescript/providers/toast/toast-item-renderer.d.ts +7 -0
- package/lib/typescript/providers/toast/toast-item-renderer.d.ts.map +1 -0
- package/lib/typescript/providers/toast/types.d.ts +422 -0
- package/lib/typescript/providers/toast/types.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/animation/hooks/index.ts +1 -0
- package/src/animation/hooks/useCombinedAnimationDisabledState.ts +46 -0
- package/src/animation/index.ts +3 -0
- package/src/animation/types.ts +128 -0
- package/src/animation/utils.ts +249 -0
- package/src/components/CLAUDE.md +1 -1
- package/src/components/Card/index.tsx +58 -28
- package/src/components/Toast/animation.ts +387 -0
- package/src/components/Toast/hooks.ts +92 -0
- package/src/components/Toast/index.tsx +520 -0
- package/src/components/Toast/styles.ts +186 -0
- package/src/components/Toast/types.ts +332 -0
- package/src/components/index.ts +1 -0
- package/src/index.ts +2 -0
- package/src/providers/animation-settings/index.ts +11 -0
- package/src/providers/animation-settings/provider.tsx +54 -0
- package/src/providers/animation-settings/types.ts +37 -0
- package/src/providers/forge-design/index.ts +2 -0
- package/src/providers/forge-design/provider.tsx +61 -0
- package/src/providers/forge-design/types.ts +84 -0
- package/src/providers/text-component/index.ts +2 -0
- package/src/providers/text-component/provider.tsx +7 -0
- package/src/providers/text-component/types.ts +52 -0
- package/src/providers/toast/index.ts +4 -0
- package/src/providers/toast/insets-container.tsx +230 -0
- package/src/providers/toast/lifecycle.context.tsx +37 -0
- package/src/providers/toast/provider.tsx +567 -0
- package/src/providers/toast/reducer.ts +40 -0
- package/src/providers/toast/toast-config.context.ts +25 -0
- package/src/providers/toast/toast-item-renderer.tsx +40 -0
- package/src/providers/toast/types.ts +431 -0
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { View } from 'react-native';
|
|
2
|
+
import type { EntryOrExitLayoutType, WithTimingConfig } from 'react-native-reanimated';
|
|
3
|
+
import type { ToastRootProps } from '@cdx-ui/primitives';
|
|
4
|
+
import { ForgeIcon } from '@cdx-ui/icons';
|
|
5
|
+
import type { AnimationRoot, AnimationValue } from '../../animation';
|
|
6
|
+
import type { ToastComponentProps, ToastShowOptions } from '../../providers/toast';
|
|
7
|
+
import type { ButtonProps } from '../Button';
|
|
8
|
+
import type { IconButtonProps } from '../IconButton';
|
|
9
|
+
import type { IconProps } from '../Icon';
|
|
10
|
+
import { ToastColorProps } from './styles';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Toast color types
|
|
14
|
+
*/
|
|
15
|
+
export type ToastColor = ToastColorProps['color'];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Toast placement types.
|
|
19
|
+
*
|
|
20
|
+
* On web, `-start` and `-end` variants position the toast at the
|
|
21
|
+
* corresponding horizontal edge with a `max-width` of 460 px.
|
|
22
|
+
* The plain `top` / `bottom` values centre the toast horizontally.
|
|
23
|
+
*
|
|
24
|
+
* On native (iOS / Android), `-start` and `-end` degrade gracefully
|
|
25
|
+
* to edge-to-edge layout identical to their base `top` / `bottom`
|
|
26
|
+
* counterpart — the toast still spans the full width.
|
|
27
|
+
*/
|
|
28
|
+
export type ToastPlacement =
|
|
29
|
+
| 'top-start'
|
|
30
|
+
| 'top'
|
|
31
|
+
| 'top-end'
|
|
32
|
+
| 'bottom-start'
|
|
33
|
+
| 'bottom'
|
|
34
|
+
| 'bottom-end';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Animation configuration for toast root component
|
|
38
|
+
*/
|
|
39
|
+
export type ToastRootAnimation = AnimationRoot<{
|
|
40
|
+
opacity?: AnimationValue<{
|
|
41
|
+
/**
|
|
42
|
+
* Opacity interpolation values [start, end]
|
|
43
|
+
* Controls how fast toast items fade out as they move beyond the visible stack limits.
|
|
44
|
+
* When toasts are pushed out of view (beyond the last few visible items), their opacity
|
|
45
|
+
* gradually decreases to create a smooth disappearing effect.
|
|
46
|
+
* - First value: fully visible opacity (1) for items within visible stack
|
|
47
|
+
* - Second value: hidden opacity (0) for items pushed out of view
|
|
48
|
+
* @default [1, 0]
|
|
49
|
+
*/
|
|
50
|
+
value?: [number, number];
|
|
51
|
+
/**
|
|
52
|
+
* Animation timing configuration
|
|
53
|
+
* @default { duration: 300 }
|
|
54
|
+
*/
|
|
55
|
+
timingConfig?: WithTimingConfig;
|
|
56
|
+
}>;
|
|
57
|
+
translateY?: AnimationValue<{
|
|
58
|
+
/**
|
|
59
|
+
* Translate Y interpolation values [start, end]
|
|
60
|
+
* Controls how much of a toast item is visible when it's positioned behind the last visible toast.
|
|
61
|
+
* This creates a "peek" effect where stacked toasts are slightly offset vertically,
|
|
62
|
+
* allowing users to see a portion of the toast behind the current one.
|
|
63
|
+
* - First value: no offset (0) for the last/active toast
|
|
64
|
+
* - Second value: vertical offset in pixels (10) for toasts behind the last one
|
|
65
|
+
* Note: The offset direction is automatically adjusted based on placement (top/bottom)
|
|
66
|
+
* @default [0, 10] (multiplied by placement sign)
|
|
67
|
+
*/
|
|
68
|
+
value?: [number, number];
|
|
69
|
+
/**
|
|
70
|
+
* Animation timing configuration
|
|
71
|
+
* @default { duration: 300 }
|
|
72
|
+
*/
|
|
73
|
+
timingConfig?: WithTimingConfig;
|
|
74
|
+
}>;
|
|
75
|
+
scale?: AnimationValue<{
|
|
76
|
+
/**
|
|
77
|
+
* Scale interpolation values [start, end]
|
|
78
|
+
* Controls the size scaling of toast items in the stack.
|
|
79
|
+
* Toasts behind the active one are slightly scaled down to create depth and visual hierarchy.
|
|
80
|
+
* - First value: normal scale (1) for the active/last toast
|
|
81
|
+
* - Second value: scaled down value (0.97) for toasts positioned behind
|
|
82
|
+
* @default [1, 0.97]
|
|
83
|
+
*/
|
|
84
|
+
value?: [number, number];
|
|
85
|
+
/**
|
|
86
|
+
* Animation timing configuration
|
|
87
|
+
* @default { duration: 300 }
|
|
88
|
+
*/
|
|
89
|
+
timingConfig?: WithTimingConfig;
|
|
90
|
+
}>;
|
|
91
|
+
entering?: AnimationValue<{
|
|
92
|
+
/**
|
|
93
|
+
* Custom entering animation for top placement
|
|
94
|
+
* @default FadeInUp.springify().withInitialValues({ opacity: 1, transform: [{ translateY: -100 }] }).mass(3)
|
|
95
|
+
*/
|
|
96
|
+
top?: EntryOrExitLayoutType;
|
|
97
|
+
/**
|
|
98
|
+
* Custom entering animation for bottom placement
|
|
99
|
+
* @default FadeInDown.springify().withInitialValues({ opacity: 1, transform: [{ translateY: 100 }] }).mass(3)
|
|
100
|
+
*/
|
|
101
|
+
bottom?: EntryOrExitLayoutType;
|
|
102
|
+
}>;
|
|
103
|
+
exiting?: AnimationValue<{
|
|
104
|
+
/**
|
|
105
|
+
* Custom exiting animation for top placement
|
|
106
|
+
* @default Keyframe animation with translateY: -100, scale: 0.97, opacity: 0.5
|
|
107
|
+
*/
|
|
108
|
+
top?: EntryOrExitLayoutType;
|
|
109
|
+
/**
|
|
110
|
+
* Custom exiting animation for bottom placement
|
|
111
|
+
* @default Keyframe animation with translateY: 100, scale: 0.97, opacity: 0.5
|
|
112
|
+
*/
|
|
113
|
+
bottom?: EntryOrExitLayoutType;
|
|
114
|
+
}>;
|
|
115
|
+
}>;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Props for the Toast.Root component
|
|
119
|
+
*/
|
|
120
|
+
export interface ToastProps extends ToastRootProps, Omit<ToastComponentProps, 'id'> {
|
|
121
|
+
/**
|
|
122
|
+
* Color of the toast
|
|
123
|
+
* @default 'default'
|
|
124
|
+
*/
|
|
125
|
+
color?: ToastColor;
|
|
126
|
+
/**
|
|
127
|
+
* Placement of the toast
|
|
128
|
+
* @default 'bottom'
|
|
129
|
+
*/
|
|
130
|
+
placement?: ToastPlacement;
|
|
131
|
+
/**
|
|
132
|
+
* Additional CSS class for the toast container
|
|
133
|
+
*
|
|
134
|
+
* @note The following style properties are occupied by animations and cannot be set via className:
|
|
135
|
+
* - `opacity` - Animated for visibility transitions when toasts are pushed beyond visible stack limits
|
|
136
|
+
* - `transform` (translateY) - Animated for vertical position transitions when toasts are stacked, and for swipe-to-dismiss gestures
|
|
137
|
+
* - `transform` (scale) - Animated for size scaling transitions when toasts are stacked (toasts behind active one are scaled down)
|
|
138
|
+
* - `height` - Animated for height transitions when toast content changes
|
|
139
|
+
*
|
|
140
|
+
* To customize these properties, use the `animation` prop:
|
|
141
|
+
* ```tsx
|
|
142
|
+
* <Toast.Root
|
|
143
|
+
* animation={{
|
|
144
|
+
* opacity: {
|
|
145
|
+
* value: [1, 0],
|
|
146
|
+
* timingConfig: { duration: 300 }
|
|
147
|
+
* },
|
|
148
|
+
* translateY: {
|
|
149
|
+
* value: [0, 10],
|
|
150
|
+
* timingConfig: { duration: 300 }
|
|
151
|
+
* },
|
|
152
|
+
* scale: {
|
|
153
|
+
* value: [1, 0.97],
|
|
154
|
+
* timingConfig: { duration: 300 }
|
|
155
|
+
* }
|
|
156
|
+
* }}
|
|
157
|
+
* />
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* To completely disable animated styles and use your own via className or style prop, set `isAnimatedStyleActive={false}`.
|
|
161
|
+
*/
|
|
162
|
+
className?: string;
|
|
163
|
+
/**
|
|
164
|
+
* Animation configuration for toast
|
|
165
|
+
* - `false` or `"disabled"`: Disable only root animations
|
|
166
|
+
* - `"disable-all"`: Disable all animations including children
|
|
167
|
+
* - `true` or `undefined`: Use default animations
|
|
168
|
+
* - `object`: Custom animation configuration
|
|
169
|
+
*/
|
|
170
|
+
animation?: ToastRootAnimation;
|
|
171
|
+
/**
|
|
172
|
+
* Whether the toast can be swiped to dismiss and dragged with rubber effect
|
|
173
|
+
* @default true
|
|
174
|
+
*/
|
|
175
|
+
isSwipeable?: boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Whether animated styles (react-native-reanimated) are active
|
|
178
|
+
* When `false`, the animated style is removed and you can implement custom logic
|
|
179
|
+
* This prop should only be used when you want to write custom styling logic instead of the default animated styles
|
|
180
|
+
* @default true
|
|
181
|
+
*/
|
|
182
|
+
isAnimatedStyleActive?: boolean;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Props for the Toast.Title component
|
|
187
|
+
*/
|
|
188
|
+
export interface ToastTitleProps {
|
|
189
|
+
/**
|
|
190
|
+
* Content to be rendered as title
|
|
191
|
+
*/
|
|
192
|
+
children?: React.ReactNode;
|
|
193
|
+
/**
|
|
194
|
+
* Additional CSS class for the title
|
|
195
|
+
*/
|
|
196
|
+
className?: string;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Props for the Toast.Description component
|
|
201
|
+
*/
|
|
202
|
+
export interface ToastDescriptionProps {
|
|
203
|
+
/**
|
|
204
|
+
* Content to be rendered as description
|
|
205
|
+
*/
|
|
206
|
+
children?: React.ReactNode;
|
|
207
|
+
/**
|
|
208
|
+
* Additional CSS class for the description
|
|
209
|
+
*/
|
|
210
|
+
className?: string;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Props for the Toast.Icon component
|
|
215
|
+
*/
|
|
216
|
+
export interface ToastIconProps extends Omit<IconProps, 'children' | 'as'> {
|
|
217
|
+
asChild?: boolean;
|
|
218
|
+
/**
|
|
219
|
+
* Forge icon component to render. Required unless `asChild` is set.
|
|
220
|
+
*/
|
|
221
|
+
as?: IconProps['as'];
|
|
222
|
+
/**
|
|
223
|
+
* Child element to render when `asChild` is set.
|
|
224
|
+
*/
|
|
225
|
+
children?: React.ReactNode;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Props for the Toast.Action component
|
|
230
|
+
*/
|
|
231
|
+
export type ToastActionProps = ButtonProps;
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Props for the Toast.Close component
|
|
235
|
+
*/
|
|
236
|
+
export type ToastCloseProps = Omit<IconButtonProps, 'as'> & {
|
|
237
|
+
/**
|
|
238
|
+
* Forge icon component to render (icon-only control).
|
|
239
|
+
* @default CloseIcon
|
|
240
|
+
*/
|
|
241
|
+
as?: ForgeIcon;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Context values shared between Toast components
|
|
246
|
+
*/
|
|
247
|
+
export interface ToastContextValue {
|
|
248
|
+
/**
|
|
249
|
+
* Color of the toast
|
|
250
|
+
*/
|
|
251
|
+
color?: ToastColor;
|
|
252
|
+
/**
|
|
253
|
+
* Function to hide the toast
|
|
254
|
+
*/
|
|
255
|
+
hide?: (ids?: (string & {}) | string[] | 'all') => void;
|
|
256
|
+
/**
|
|
257
|
+
* ID of the toast
|
|
258
|
+
*/
|
|
259
|
+
id?: string;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Ref type for the Toast.Root component
|
|
264
|
+
*/
|
|
265
|
+
export type ToastRootRef = React.ComponentRef<typeof View>;
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Props for useToastRootAnimation hook
|
|
269
|
+
* Picks required properties from ToastRootProps and adds id from ToastComponentProps
|
|
270
|
+
*/
|
|
271
|
+
export type UseToastRootAnimationOptions = Pick<
|
|
272
|
+
ToastProps,
|
|
273
|
+
| 'animation'
|
|
274
|
+
| 'index'
|
|
275
|
+
| 'total'
|
|
276
|
+
| 'heights'
|
|
277
|
+
| 'placement'
|
|
278
|
+
| 'hide'
|
|
279
|
+
| 'isSwipeable'
|
|
280
|
+
| 'maxVisibleToasts'
|
|
281
|
+
> &
|
|
282
|
+
Pick<ToastComponentProps, 'id'>;
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Props for the DefaultToast component
|
|
286
|
+
* Used internally when showing toasts with string or config object (without component)
|
|
287
|
+
*/
|
|
288
|
+
export interface DefaultToastProps extends ToastComponentProps {
|
|
289
|
+
/**
|
|
290
|
+
* Color of the toast
|
|
291
|
+
* @default 'default'
|
|
292
|
+
*/
|
|
293
|
+
color?: ToastProps['color'];
|
|
294
|
+
/**
|
|
295
|
+
* Placement of the toast
|
|
296
|
+
* @default 'bottom'
|
|
297
|
+
*/
|
|
298
|
+
placement?: ToastProps['placement'];
|
|
299
|
+
/**
|
|
300
|
+
* Animation configuration for toast
|
|
301
|
+
*/
|
|
302
|
+
animation?: ToastProps['animation'];
|
|
303
|
+
/**
|
|
304
|
+
* Whether the toast can be swiped to dismiss and dragged with rubber effect
|
|
305
|
+
*/
|
|
306
|
+
isSwipeable?: ToastProps['isSwipeable'];
|
|
307
|
+
/**
|
|
308
|
+
* Label text for the toast
|
|
309
|
+
*/
|
|
310
|
+
label?: string;
|
|
311
|
+
/**
|
|
312
|
+
* Description text for the toast
|
|
313
|
+
*/
|
|
314
|
+
description?: string;
|
|
315
|
+
/**
|
|
316
|
+
* Action button label text
|
|
317
|
+
*/
|
|
318
|
+
actionLabel?: string;
|
|
319
|
+
/**
|
|
320
|
+
* Callback function called when the action button is pressed
|
|
321
|
+
* Receives show and hide functions for programmatic toast control
|
|
322
|
+
*/
|
|
323
|
+
onActionPress?: (helpers: {
|
|
324
|
+
show: (options: string | ToastShowOptions) => string;
|
|
325
|
+
hide: (ids?: (string & {}) | string[] | 'all') => void;
|
|
326
|
+
}) => void;
|
|
327
|
+
/**
|
|
328
|
+
* Forge icon component to display in the toast.
|
|
329
|
+
* Rendered via `Toast.Icon` internally — inherits color-aware coloring automatically.
|
|
330
|
+
*/
|
|
331
|
+
icon?: ForgeIcon;
|
|
332
|
+
}
|
package/src/components/index.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -2,5 +2,7 @@
|
|
|
2
2
|
export * from './components';
|
|
3
3
|
export * from './hooks';
|
|
4
4
|
export * from './navigation';
|
|
5
|
+
export { ToastProvider, useToast } from './providers/toast';
|
|
6
|
+
export type * from './providers/toast';
|
|
5
7
|
export { View, ScrollView, KeyboardAvoidingView } from 'react-native';
|
|
6
8
|
export { SafeAreaView, useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export {
|
|
2
|
+
GlobalAnimationSettingsProvider,
|
|
3
|
+
AnimationSettingsProvider,
|
|
4
|
+
useGlobalAnimationSettings,
|
|
5
|
+
useAnimationSettings,
|
|
6
|
+
} from './provider';
|
|
7
|
+
export type {
|
|
8
|
+
GlobalAnimationSettingsContextValue,
|
|
9
|
+
GlobalAnimationSettingsProviderProps,
|
|
10
|
+
AnimationSettingsContextValue,
|
|
11
|
+
} from './types';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useReducedMotion } from 'react-native-reanimated';
|
|
3
|
+
import { createContext } from '@cdx-ui/utils';
|
|
4
|
+
import type {
|
|
5
|
+
GlobalAnimationSettingsContextValue,
|
|
6
|
+
GlobalAnimationSettingsProviderProps,
|
|
7
|
+
AnimationSettingsContextValue,
|
|
8
|
+
} from './types';
|
|
9
|
+
|
|
10
|
+
const [GlobalAnimationSettingsProviderComponent, useGlobalAnimationSettings] =
|
|
11
|
+
createContext<GlobalAnimationSettingsContextValue>('GlobalAnimationSettingsContext', {
|
|
12
|
+
strict: false,
|
|
13
|
+
defaultValue: { globalIsAllAnimationsDisabled: false },
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export { useGlobalAnimationSettings };
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* GlobalAnimationSettingsProvider Component
|
|
20
|
+
*
|
|
21
|
+
* @description
|
|
22
|
+
* Provider component that controls global animation settings across the application.
|
|
23
|
+
* When animation is set to 'disable-all', all animations will be disabled globally.
|
|
24
|
+
* Additionally, if the user has enabled reduce motion in accessibility settings,
|
|
25
|
+
* all animations will be disabled automatically.
|
|
26
|
+
*
|
|
27
|
+
* The global setting is read directly via `useGlobalAnimationSettings`; the
|
|
28
|
+
* separate `AnimationSettingsProvider` handles per-subtree cascading. Both
|
|
29
|
+
* contexts are non-strict, so components can read them without a provider
|
|
30
|
+
* mounted (falling back to "animations enabled").
|
|
31
|
+
*
|
|
32
|
+
* @param {GlobalAnimationSettingsProviderProps} props - Provider props
|
|
33
|
+
* @param {AnimationRootDisableAll} [props.animation] - Global animation setting
|
|
34
|
+
* @param {ReactNode} props.children - Child components to wrap
|
|
35
|
+
*/
|
|
36
|
+
export const GlobalAnimationSettingsProvider: React.FC<GlobalAnimationSettingsProviderProps> = ({
|
|
37
|
+
animation,
|
|
38
|
+
children,
|
|
39
|
+
}) => {
|
|
40
|
+
const reducedMotion = useReducedMotion();
|
|
41
|
+
const globalIsAllAnimationsDisabled = animation === 'disable-all' || reducedMotion;
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<GlobalAnimationSettingsProviderComponent value={{ globalIsAllAnimationsDisabled }}>
|
|
45
|
+
{children}
|
|
46
|
+
</GlobalAnimationSettingsProviderComponent>
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const [AnimationSettingsProvider, useAnimationSettings] =
|
|
51
|
+
createContext<AnimationSettingsContextValue>('AnimationSettingsContext', {
|
|
52
|
+
strict: false,
|
|
53
|
+
defaultValue: { isAllAnimationsDisabled: false },
|
|
54
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { AnimationRootDisableAll } from '../../animation';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Props for GlobalAnimationSettingsProvider component
|
|
6
|
+
*/
|
|
7
|
+
export interface GlobalAnimationSettingsProviderProps {
|
|
8
|
+
/**
|
|
9
|
+
* Global animation setting
|
|
10
|
+
* When set to 'disable-all', all animations across the app will be disabled
|
|
11
|
+
*/
|
|
12
|
+
animation?: AnimationRootDisableAll;
|
|
13
|
+
/**
|
|
14
|
+
* Child components to render within the provider
|
|
15
|
+
*/
|
|
16
|
+
children: ReactNode;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Context value for global animation settings
|
|
21
|
+
*/
|
|
22
|
+
export interface GlobalAnimationSettingsContextValue {
|
|
23
|
+
/**
|
|
24
|
+
* Whether all animations should be disabled globally
|
|
25
|
+
*/
|
|
26
|
+
globalIsAllAnimationsDisabled: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Context value for global animation settings
|
|
31
|
+
*/
|
|
32
|
+
export interface AnimationSettingsContextValue {
|
|
33
|
+
/**
|
|
34
|
+
* Whether all animations should be disabled (cascading from parent)
|
|
35
|
+
*/
|
|
36
|
+
isAllAnimationsDisabled: boolean;
|
|
37
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SafeAreaListener } from 'react-native-safe-area-context';
|
|
3
|
+
import { Uniwind } from 'uniwind';
|
|
4
|
+
import { PortalHost } from '@cdx-ui/primitives';
|
|
5
|
+
import { GlobalAnimationSettingsProvider } from '../animation-settings';
|
|
6
|
+
import { TextComponentProvider } from '../text-component/provider';
|
|
7
|
+
import { ToastProvider } from '../toast/provider';
|
|
8
|
+
import type { ForgeDesignProviderProps } from './types';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* ForgeDesignProvider Component
|
|
12
|
+
*
|
|
13
|
+
* @description
|
|
14
|
+
* Main provider component for HeroUI Native that configures the application
|
|
15
|
+
* with global settings. This component should wrap your entire application
|
|
16
|
+
* or the section where you want to use HeroUI Native components.
|
|
17
|
+
*
|
|
18
|
+
* Currently provides:
|
|
19
|
+
* - Global animation settings
|
|
20
|
+
* - Global text component configuration
|
|
21
|
+
* - Toast notification system
|
|
22
|
+
* - Portal management for overlays
|
|
23
|
+
*
|
|
24
|
+
* @param {ForgeDesignProviderProps} props - Provider configuration props
|
|
25
|
+
* @param {ReactNode} props.children - Child components to wrap
|
|
26
|
+
* @param {ForgeDesignConfig} [props.config] - Configuration object
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
29
|
+
const ForgeDesignProvider: React.FC<ForgeDesignProviderProps> = ({ children, config = {} }) => {
|
|
30
|
+
const { textProps, toast, animation } = config;
|
|
31
|
+
|
|
32
|
+
// Determine if toast should be enabled and get props
|
|
33
|
+
const isToastEnabled = toast !== false && toast !== 'disabled';
|
|
34
|
+
const toastProps = typeof toast === 'object' ? toast : {};
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<SafeAreaListener
|
|
38
|
+
onChange={({ insets }) => {
|
|
39
|
+
Uniwind.updateInsets(insets);
|
|
40
|
+
}}
|
|
41
|
+
>
|
|
42
|
+
<GlobalAnimationSettingsProvider animation={animation}>
|
|
43
|
+
<TextComponentProvider value={{ textProps }}>
|
|
44
|
+
{isToastEnabled ? (
|
|
45
|
+
<ToastProvider {...toastProps}>
|
|
46
|
+
{children}
|
|
47
|
+
<PortalHost />
|
|
48
|
+
</ToastProvider>
|
|
49
|
+
) : (
|
|
50
|
+
<>
|
|
51
|
+
{children}
|
|
52
|
+
<PortalHost />
|
|
53
|
+
</>
|
|
54
|
+
)}
|
|
55
|
+
</TextComponentProvider>
|
|
56
|
+
</GlobalAnimationSettingsProvider>
|
|
57
|
+
</SafeAreaListener>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export default ForgeDesignProvider;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { AnimationRootDisableAll } from '../../animation';
|
|
3
|
+
import type { TextComponentContextValue } from '../text-component/types';
|
|
4
|
+
import type { ToastProviderProps } from '../toast/types';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Configuration object for ForgeDesignProvider
|
|
8
|
+
*
|
|
9
|
+
* @interface ForgeDesignConfig
|
|
10
|
+
* @extends TextComponentContextValue
|
|
11
|
+
*
|
|
12
|
+
* @description
|
|
13
|
+
* Contains configuration options for the HeroUI Native provider.
|
|
14
|
+
* Additional configuration options can be added in future versions.
|
|
15
|
+
*/
|
|
16
|
+
export interface ForgeDesignConfig extends TextComponentContextValue {
|
|
17
|
+
/**
|
|
18
|
+
* Global animation configuration
|
|
19
|
+
*
|
|
20
|
+
* @description
|
|
21
|
+
* When set to 'disable-all', all animations across the application will be disabled.
|
|
22
|
+
*/
|
|
23
|
+
animation?: AnimationRootDisableAll;
|
|
24
|
+
/**
|
|
25
|
+
* Toast configuration
|
|
26
|
+
*
|
|
27
|
+
* @description
|
|
28
|
+
* Configure the global toast system including insets and wrapper components.
|
|
29
|
+
* Set to `false` or `'disabled'` to disable the toast provider entirely.
|
|
30
|
+
* Provide a `ToastProviderProps` object for custom configuration.
|
|
31
|
+
*/
|
|
32
|
+
toast?: boolean | 'disabled' | ToastProviderProps;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Props for ForgeDesignProvider component
|
|
37
|
+
*
|
|
38
|
+
* @interface ForgeDesignProviderProps
|
|
39
|
+
*
|
|
40
|
+
* @description
|
|
41
|
+
* Main provider component props that wraps the entire application
|
|
42
|
+
* or a section of it to provide HeroUI Native functionality.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```tsx
|
|
46
|
+
* <ForgeDesignProvider config={{
|
|
47
|
+
* textProps: {
|
|
48
|
+
* allowFontScaling: false,
|
|
49
|
+
* maxFontSizeMultiplier: 1.5
|
|
50
|
+
* }
|
|
51
|
+
* }}>
|
|
52
|
+
* <App />
|
|
53
|
+
* </ForgeDesignProvider>
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export interface ForgeDesignProviderProps {
|
|
57
|
+
/**
|
|
58
|
+
* Child components to render within the provider
|
|
59
|
+
*
|
|
60
|
+
* @description
|
|
61
|
+
* All children will have access to HeroUI Native theme
|
|
62
|
+
* and configuration through the provider.
|
|
63
|
+
*/
|
|
64
|
+
children: ReactNode;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Configuration object for the provider
|
|
68
|
+
*
|
|
69
|
+
* @description
|
|
70
|
+
* Contains all configuration options including global text component configuration.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```tsx
|
|
74
|
+
* const config: ForgeDesignConfig = {
|
|
75
|
+
* textProps: {
|
|
76
|
+
* allowFontScaling: false,
|
|
77
|
+
* adjustsFontSizeToFit: false,
|
|
78
|
+
* maxFontSizeMultiplier: 1.5
|
|
79
|
+
* }
|
|
80
|
+
* };
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
config?: ForgeDesignConfig;
|
|
84
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createContext } from '@cdx-ui/utils';
|
|
2
|
+
import type { TextComponentContextValue } from './types';
|
|
3
|
+
|
|
4
|
+
const [TextComponentProvider, useTextComponent] =
|
|
5
|
+
createContext<TextComponentContextValue>('TextComponentContext');
|
|
6
|
+
|
|
7
|
+
export { TextComponentProvider, useTextComponent };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { TextProps } from 'react-native';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Global text component configuration props.
|
|
5
|
+
* These props are carefully selected to include only those that make sense
|
|
6
|
+
* to configure globally across all Text components in the application.
|
|
7
|
+
*
|
|
8
|
+
* @description
|
|
9
|
+
* Includes accessibility and font scaling settings that typically
|
|
10
|
+
* should be consistent throughout the app for better UX.
|
|
11
|
+
*/
|
|
12
|
+
export interface TextComponentProps {
|
|
13
|
+
/**
|
|
14
|
+
* Specifies whether fonts should be scaled down automatically to fit given style constraints.
|
|
15
|
+
*
|
|
16
|
+
* @default false
|
|
17
|
+
*/
|
|
18
|
+
adjustsFontSizeToFit?: TextProps['adjustsFontSizeToFit'];
|
|
19
|
+
/**
|
|
20
|
+
* Specifies whether fonts should scale to respect Text Size accessibility settings.
|
|
21
|
+
*
|
|
22
|
+
* @default true
|
|
23
|
+
*/
|
|
24
|
+
allowFontScaling?: TextProps['allowFontScaling'];
|
|
25
|
+
/**
|
|
26
|
+
* Specifies the largest possible scale a font can reach when `allowFontScaling` is enabled.
|
|
27
|
+
*
|
|
28
|
+
* Possible values:
|
|
29
|
+
*
|
|
30
|
+
* - `null` or `undefined`: inherit from the parent node or the global default (0)
|
|
31
|
+
* - `0`: no max, ignore parent/global default
|
|
32
|
+
* - `>= 1`: sets the `maxFontSizeMultiplier` of this node to this value
|
|
33
|
+
*
|
|
34
|
+
* @default `undefined`
|
|
35
|
+
*/
|
|
36
|
+
maxFontSizeMultiplier?: TextProps['maxFontSizeMultiplier'];
|
|
37
|
+
/**
|
|
38
|
+
* Specifies the smallest possible scale a font can reach when adjustsFontSizeToFit is enabled. (values 0.01-1.0).
|
|
39
|
+
*
|
|
40
|
+
* iOS only
|
|
41
|
+
*
|
|
42
|
+
* @default `undefined`
|
|
43
|
+
*/
|
|
44
|
+
minimumFontScale?: TextProps['minimumFontScale'];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Context value for text component configuration
|
|
49
|
+
*/
|
|
50
|
+
export interface TextComponentContextValue {
|
|
51
|
+
textProps?: TextComponentProps;
|
|
52
|
+
}
|