@expressive-ui/native 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/dist/Feedback.d.ts +3 -3
- package/dist/Feedback.d.ts.map +1 -1
- package/dist/Feedback.js +73 -14
- package/dist/Feedback.js.map +1 -1
- package/dist/Fields.d.ts +10 -6
- package/dist/Fields.d.ts.map +1 -1
- package/dist/Fields.js +125 -29
- package/dist/Fields.js.map +1 -1
- package/dist/FileUpload.d.ts.map +1 -1
- package/dist/FileUpload.js +61 -19
- package/dist/FileUpload.js.map +1 -1
- package/dist/NumberField.d.ts +6 -2
- package/dist/NumberField.d.ts.map +1 -1
- package/dist/NumberField.js +71 -11
- package/dist/NumberField.js.map +1 -1
- package/dist/Pickers.d.ts.map +1 -1
- package/dist/Pickers.js +227 -36
- package/dist/Pickers.js.map +1 -1
- package/dist/RenderUI.d.ts +3 -0
- package/dist/RenderUI.d.ts.map +1 -0
- package/dist/RenderUI.js +45 -0
- package/dist/RenderUI.js.map +1 -0
- package/dist/Search.js +1 -1
- package/dist/Search.js.map +1 -1
- package/dist/Select.d.ts +5 -1
- package/dist/Select.d.ts.map +1 -1
- package/dist/Select.js +52 -10
- package/dist/Select.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/theme.d.ts +3 -1
- package/dist/theme.d.ts.map +1 -1
- package/dist/theme.js +36 -11
- package/dist/theme.js.map +1 -1
- package/package.json +4 -4
- package/src/Feedback.tsx +211 -16
- package/src/Fields.tsx +341 -58
- package/src/FileUpload.tsx +169 -7
- package/src/NumberField.tsx +187 -9
- package/src/Pickers.tsx +783 -86
- package/src/RenderUI.tsx +47 -0
- package/src/Search.tsx +1 -1
- package/src/Select.tsx +209 -27
- package/src/index.ts +2 -0
- package/src/theme.tsx +77 -14
package/src/Feedback.tsx
CHANGED
|
@@ -1,23 +1,218 @@
|
|
|
1
1
|
import { useEffect, useRef, useState, type ReactNode } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
AccessibilityInfo,
|
|
4
|
+
Animated,
|
|
5
|
+
Pressable,
|
|
6
|
+
View,
|
|
7
|
+
type DimensionValue,
|
|
8
|
+
type StyleProp,
|
|
9
|
+
type ViewStyle,
|
|
10
|
+
} from 'react-native';
|
|
3
11
|
import { alertIcons, type AlertSeverity } from '@expressive-ui/core';
|
|
4
12
|
import { Button } from './Button.js';
|
|
5
13
|
import { Icon, T } from './primitives.js';
|
|
6
14
|
import { useExpressiveTheme } from './theme.js';
|
|
7
|
-
export type SkeletonProps={
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
export type SkeletonProps = {
|
|
16
|
+
variant?: 'text' | 'rectangular' | 'circular';
|
|
17
|
+
width?: DimensionValue;
|
|
18
|
+
height?: number;
|
|
19
|
+
lines?: number;
|
|
20
|
+
animation?: boolean;
|
|
21
|
+
label?: string;
|
|
22
|
+
style?: StyleProp<ViewStyle>;
|
|
23
|
+
};
|
|
24
|
+
export function Skeleton({
|
|
25
|
+
variant = 'text',
|
|
26
|
+
width = '100%',
|
|
27
|
+
height,
|
|
28
|
+
lines = 1,
|
|
29
|
+
animation = true,
|
|
30
|
+
label,
|
|
31
|
+
style,
|
|
32
|
+
}: SkeletonProps) {
|
|
33
|
+
const { colors } = useExpressiveTheme(),
|
|
34
|
+
opacity = useRef(new Animated.Value(1)).current,
|
|
35
|
+
[reduced, setReduced] = useState(true);
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
let active = true;
|
|
38
|
+
AccessibilityInfo.isReduceMotionEnabled().then((value) => {
|
|
39
|
+
if (active) setReduced(value);
|
|
40
|
+
});
|
|
41
|
+
const listener = AccessibilityInfo.addEventListener('reduceMotionChanged', setReduced);
|
|
42
|
+
return () => {
|
|
43
|
+
active = false;
|
|
44
|
+
listener.remove();
|
|
45
|
+
};
|
|
46
|
+
}, []);
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (!animation || reduced) {
|
|
49
|
+
opacity.setValue(1);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const loop = Animated.loop(
|
|
53
|
+
Animated.sequence([
|
|
54
|
+
Animated.timing(opacity, { toValue: 0.45, duration: 750, useNativeDriver: true }),
|
|
55
|
+
Animated.timing(opacity, { toValue: 1, duration: 750, useNativeDriver: true }),
|
|
56
|
+
]),
|
|
57
|
+
);
|
|
58
|
+
loop.start();
|
|
59
|
+
return () => loop.stop();
|
|
60
|
+
}, [animation, reduced, opacity]);
|
|
61
|
+
return (
|
|
62
|
+
<View
|
|
63
|
+
accessible={!!label}
|
|
64
|
+
accessibilityLabel={label}
|
|
65
|
+
accessibilityLiveRegion={label ? 'polite' : undefined}
|
|
66
|
+
accessibilityElementsHidden={!label}
|
|
67
|
+
importantForAccessibility={label ? 'yes' : 'no-hide-descendants'}
|
|
68
|
+
style={[{ width, gap: 10 }, style]}
|
|
69
|
+
>
|
|
70
|
+
{Array.from({ length: Math.max(1, Math.floor(lines)) }, (_, index) => (
|
|
71
|
+
<Animated.View
|
|
72
|
+
key={index}
|
|
73
|
+
style={{
|
|
74
|
+
height: height ?? (variant === 'text' ? 16 : 48),
|
|
75
|
+
width:
|
|
76
|
+
variant === 'circular'
|
|
77
|
+
? height ?? 48
|
|
78
|
+
: index === Math.floor(lines) - 1 && lines > 1
|
|
79
|
+
? '72%'
|
|
80
|
+
: '100%',
|
|
81
|
+
borderRadius: variant === 'circular' ? 999 : 8,
|
|
82
|
+
backgroundColor: colors.surfaceContainerHighest,
|
|
83
|
+
opacity,
|
|
84
|
+
}}
|
|
85
|
+
/>
|
|
86
|
+
))}
|
|
87
|
+
</View>
|
|
88
|
+
);
|
|
13
89
|
}
|
|
14
|
-
export type AlertProps={
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
90
|
+
export type AlertProps = {
|
|
91
|
+
severity?: AlertSeverity;
|
|
92
|
+
title?: string;
|
|
93
|
+
children: ReactNode;
|
|
94
|
+
icon?: string | false;
|
|
95
|
+
action?: { label: string; onPress: () => void };
|
|
96
|
+
onClose?: () => void;
|
|
97
|
+
live?: boolean;
|
|
98
|
+
style?: StyleProp<ViewStyle>;
|
|
99
|
+
};
|
|
100
|
+
export function Alert({
|
|
101
|
+
severity = 'info',
|
|
102
|
+
title,
|
|
103
|
+
children,
|
|
104
|
+
icon,
|
|
105
|
+
action,
|
|
106
|
+
onClose,
|
|
107
|
+
live = true,
|
|
108
|
+
style,
|
|
109
|
+
}: AlertProps) {
|
|
110
|
+
const { colors, labels } = useExpressiveTheme();
|
|
111
|
+
const background =
|
|
112
|
+
severity === 'error'
|
|
113
|
+
? colors.errorContainer
|
|
114
|
+
: severity === 'success'
|
|
115
|
+
? colors.tertiaryContainer
|
|
116
|
+
: severity === 'warning'
|
|
117
|
+
? colors.primaryContainer
|
|
118
|
+
: colors.secondaryContainer;
|
|
119
|
+
const content =
|
|
120
|
+
severity === 'error'
|
|
121
|
+
? 'onErrorContainer'
|
|
122
|
+
: severity === 'success'
|
|
123
|
+
? 'onTertiaryContainer'
|
|
124
|
+
: severity === 'warning'
|
|
125
|
+
? 'onPrimaryContainer'
|
|
126
|
+
: 'onSecondaryContainer';
|
|
127
|
+
return (
|
|
128
|
+
<View
|
|
129
|
+
accessibilityLiveRegion={live ? (severity === 'error' ? 'assertive' : 'polite') : 'none'}
|
|
130
|
+
style={[
|
|
131
|
+
{
|
|
132
|
+
flexDirection: 'row',
|
|
133
|
+
gap: 14,
|
|
134
|
+
padding: 18,
|
|
135
|
+
borderRadius: 16,
|
|
136
|
+
backgroundColor: background,
|
|
137
|
+
},
|
|
138
|
+
style,
|
|
139
|
+
]}
|
|
140
|
+
>
|
|
141
|
+
{icon !== false ? <Icon name={icon ?? alertIcons[severity]} color={content} /> : null}
|
|
142
|
+
<View style={{ flex: 1, gap: 6 }}>
|
|
143
|
+
{title ? (
|
|
144
|
+
<T variant="titleSmall" color={content}>
|
|
145
|
+
{title}
|
|
146
|
+
</T>
|
|
147
|
+
) : null}
|
|
148
|
+
{typeof children === 'string' ? <T color={content}>{children}</T> : children}
|
|
149
|
+
{action ? (
|
|
150
|
+
<Button
|
|
151
|
+
variant="text"
|
|
152
|
+
action={{ id: 'alert.action', label: action.label }}
|
|
153
|
+
onPress={action.onPress}
|
|
154
|
+
/>
|
|
155
|
+
) : null}
|
|
156
|
+
</View>
|
|
157
|
+
{onClose ? (
|
|
158
|
+
<Pressable
|
|
159
|
+
accessibilityRole="button"
|
|
160
|
+
accessibilityLabel={labels.close}
|
|
161
|
+
onPress={onClose}
|
|
162
|
+
style={{ minWidth: 40, minHeight: 40, alignItems: 'center', justifyContent: 'center' }}
|
|
163
|
+
>
|
|
164
|
+
<Icon name="close" color={content} />
|
|
165
|
+
</Pressable>
|
|
166
|
+
) : null}
|
|
167
|
+
</View>
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
export const InlineMessage = Alert;
|
|
171
|
+
export type EmptyStateProps = {
|
|
172
|
+
title: string;
|
|
173
|
+
description?: string;
|
|
174
|
+
icon?: string;
|
|
175
|
+
illustration?: ReactNode;
|
|
176
|
+
action?: { label: string; onPress: () => void };
|
|
177
|
+
children?: ReactNode;
|
|
178
|
+
style?: StyleProp<ViewStyle>;
|
|
179
|
+
};
|
|
180
|
+
export function EmptyState({
|
|
181
|
+
title,
|
|
182
|
+
description,
|
|
183
|
+
icon = 'inbox',
|
|
184
|
+
illustration,
|
|
185
|
+
action,
|
|
186
|
+
children,
|
|
187
|
+
style,
|
|
188
|
+
}: EmptyStateProps) {
|
|
189
|
+
const { colors } = useExpressiveTheme();
|
|
190
|
+
return (
|
|
191
|
+
<View style={[{ alignItems: 'center', gap: 16, padding: 24 }, style]}>
|
|
192
|
+
<View
|
|
193
|
+
style={{
|
|
194
|
+
width: 96,
|
|
195
|
+
height: 96,
|
|
196
|
+
borderRadius: 32,
|
|
197
|
+
backgroundColor: colors.secondaryContainer,
|
|
198
|
+
alignItems: 'center',
|
|
199
|
+
justifyContent: 'center',
|
|
200
|
+
}}
|
|
201
|
+
>
|
|
202
|
+
{illustration ?? <Icon name={icon} size={48} color="onSecondaryContainer" />}
|
|
203
|
+
</View>
|
|
204
|
+
<T variant="titleLarge" accessibilityRole="header" style={{ textAlign: 'center' }}>
|
|
205
|
+
{title}
|
|
206
|
+
</T>
|
|
207
|
+
{description ? (
|
|
208
|
+
<T color="onSurfaceVariant" style={{ textAlign: 'center' }}>
|
|
209
|
+
{description}
|
|
210
|
+
</T>
|
|
211
|
+
) : null}
|
|
212
|
+
{action ? (
|
|
213
|
+
<Button action={{ id: 'empty.action', label: action.label }} onPress={action.onPress} />
|
|
214
|
+
) : null}
|
|
215
|
+
{children}
|
|
216
|
+
</View>
|
|
217
|
+
);
|
|
20
218
|
}
|
|
21
|
-
export const InlineMessage=Alert;
|
|
22
|
-
export type EmptyStateProps={title:string;description?:string;icon?:string;illustration?:ReactNode;action?:{label:string;onPress:()=>void};children?:ReactNode;style?:StyleProp<ViewStyle>};
|
|
23
|
-
export function EmptyState({title,description,icon='inbox',illustration,action,children,style}:EmptyStateProps){const {colors}=useExpressiveTheme();return <View style={[{alignItems:'center',gap:16,padding:24},style]}><View style={{width:96,height:96,borderRadius:32,backgroundColor:colors.secondaryContainer,alignItems:'center',justifyContent:'center'}}>{illustration??<Icon name={icon} size={48} color="onSecondaryContainer"/>}</View><T variant="titleLarge" accessibilityRole="header" style={{textAlign:'center'}}>{title}</T>{description?<T color="onSurfaceVariant" style={{textAlign:'center'}}>{description}</T>:null}{action?<Button action={{id:'empty.action',label:action.label}} onPress={action.onPress}/>:null}{children}</View>;}
|