@expressive-ui/native 0.2.0 → 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.
Files changed (48) hide show
  1. package/README.md +10 -0
  2. package/dist/Feedback.d.ts +3 -3
  3. package/dist/Feedback.d.ts.map +1 -1
  4. package/dist/Feedback.js +73 -14
  5. package/dist/Feedback.js.map +1 -1
  6. package/dist/Fields.d.ts +10 -6
  7. package/dist/Fields.d.ts.map +1 -1
  8. package/dist/Fields.js +125 -29
  9. package/dist/Fields.js.map +1 -1
  10. package/dist/FileUpload.d.ts.map +1 -1
  11. package/dist/FileUpload.js +61 -19
  12. package/dist/FileUpload.js.map +1 -1
  13. package/dist/NumberField.d.ts +6 -2
  14. package/dist/NumberField.d.ts.map +1 -1
  15. package/dist/NumberField.js +71 -11
  16. package/dist/NumberField.js.map +1 -1
  17. package/dist/Pickers.d.ts.map +1 -1
  18. package/dist/Pickers.js +227 -36
  19. package/dist/Pickers.js.map +1 -1
  20. package/dist/RenderUI.d.ts +3 -0
  21. package/dist/RenderUI.d.ts.map +1 -0
  22. package/dist/RenderUI.js +45 -0
  23. package/dist/RenderUI.js.map +1 -0
  24. package/dist/Search.js +1 -1
  25. package/dist/Search.js.map +1 -1
  26. package/dist/Select.d.ts +5 -1
  27. package/dist/Select.d.ts.map +1 -1
  28. package/dist/Select.js +52 -10
  29. package/dist/Select.js.map +1 -1
  30. package/dist/index.d.ts +1 -0
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +1 -0
  33. package/dist/index.js.map +1 -1
  34. package/dist/theme.d.ts +3 -1
  35. package/dist/theme.d.ts.map +1 -1
  36. package/dist/theme.js +36 -11
  37. package/dist/theme.js.map +1 -1
  38. package/package.json +4 -4
  39. package/src/Feedback.tsx +211 -16
  40. package/src/Fields.tsx +341 -58
  41. package/src/FileUpload.tsx +169 -7
  42. package/src/NumberField.tsx +187 -9
  43. package/src/Pickers.tsx +783 -86
  44. package/src/RenderUI.tsx +47 -0
  45. package/src/Search.tsx +1 -1
  46. package/src/Select.tsx +209 -27
  47. package/src/index.ts +2 -0
  48. 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 { AccessibilityInfo, Animated, Pressable, View, type DimensionValue, type StyleProp, type ViewStyle } from 'react-native';
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={variant?:'text'|'rectangular'|'circular';width?:DimensionValue;height?:number;lines?:number;animation?:boolean;label?:string;style?:StyleProp<ViewStyle>};
8
- export function Skeleton({variant='text',width='100%',height,lines=1,animation=true,label,style}:SkeletonProps){
9
- const {colors}=useExpressiveTheme(),opacity=useRef(new Animated.Value(1)).current,[reduced,setReduced]=useState(true);
10
- useEffect(()=>{let active=true;AccessibilityInfo.isReduceMotionEnabled().then(value=>{if(active)setReduced(value);});const listener=AccessibilityInfo.addEventListener('reduceMotionChanged',setReduced);return()=>{active=false;listener.remove();};},[]);
11
- useEffect(()=>{if(!animation||reduced){opacity.setValue(1);return;}const loop=Animated.loop(Animated.sequence([Animated.timing(opacity,{toValue:.45,duration:750,useNativeDriver:true}),Animated.timing(opacity,{toValue:1,duration:750,useNativeDriver:true})]));loop.start();return()=>loop.stop();},[animation,reduced,opacity]);
12
- return <View accessible={!!label} accessibilityLabel={label} accessibilityLiveRegion={label?'polite':undefined} accessibilityElementsHidden={!label} importantForAccessibility={label?'yes':'no-hide-descendants'} style={[{width,gap:10},style]}>{Array.from({length:Math.max(1,Math.floor(lines))},(_,index)=><Animated.View key={index} style={{height:height??(variant==='text'?16:48),width:variant==='circular'?height??48:index===Math.floor(lines)-1&&lines>1?'72%':'100%',borderRadius:variant==='circular'?999:8,backgroundColor:colors.surfaceContainerHighest,opacity}}/>)}</View>;
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={severity?:AlertSeverity;title?:string;children:ReactNode;icon?:string|false;action?:{label:string;onPress:()=>void};onClose?:()=>void;live?:boolean;style?:StyleProp<ViewStyle>};
15
- export function Alert({severity='info',title,children,icon,action,onClose,live=true,style}:AlertProps){
16
- const {colors,labels}=useExpressiveTheme();
17
- const background=severity==='error'?colors.errorContainer:severity==='success'?colors.tertiaryContainer:severity==='warning'?colors.primaryContainer:colors.secondaryContainer;
18
- const content=severity==='error'?'onErrorContainer':severity==='success'?'onTertiaryContainer':severity==='warning'?'onPrimaryContainer':'onSecondaryContainer';
19
- return <View accessibilityLiveRegion={live?severity==='error'?'assertive':'polite':'none'} style={[{flexDirection:'row',gap:14,padding:18,borderRadius:16,backgroundColor:background},style]}>{icon!==false?<Icon name={icon??alertIcons[severity]} color={content}/>:null}<View style={{flex:1,gap:6}}>{title?<T variant="titleSmall" color={content}>{title}</T>:null}{typeof children==='string'?<T color={content}>{children}</T>:children}{action?<Button variant="text" action={{id:'alert.action',label:action.label}} onPress={action.onPress}/>:null}</View>{onClose?<Pressable accessibilityRole="button" accessibilityLabel={labels.close} onPress={onClose} style={{minWidth:40,minHeight:40,alignItems:'center',justifyContent:'center'}}><Icon name="close" color={content}/></Pressable>:null}</View>;
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>;}