@ezpg/app-ui 0.20.0 → 0.21.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 (51) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/lib/module/blocks/choice-art/choice-art.js +589 -0
  3. package/lib/module/blocks/choice-art/choice-art.js.map +1 -0
  4. package/lib/module/blocks/choice-art/index.js +4 -0
  5. package/lib/module/blocks/choice-art/index.js.map +1 -0
  6. package/lib/module/blocks/index.js +1 -0
  7. package/lib/module/blocks/index.js.map +1 -1
  8. package/lib/module/components/page-header/page-header.js +25 -1
  9. package/lib/module/components/page-header/page-header.js.map +1 -1
  10. package/lib/module/components/toast/index.js.map +1 -1
  11. package/lib/module/components/toast/toast.js +8 -4
  12. package/lib/module/components/toast/toast.js.map +1 -1
  13. package/lib/module/index.js +1 -1
  14. package/lib/module/index.js.map +1 -1
  15. package/lib/module/internal/glyphs.js +457 -0
  16. package/lib/module/internal/glyphs.js.map +1 -1
  17. package/lib/module/templates/index.js +1 -0
  18. package/lib/module/templates/index.js.map +1 -1
  19. package/lib/module/templates/preview-edit-template.js +422 -0
  20. package/lib/module/templates/preview-edit-template.js.map +1 -0
  21. package/lib/typescript/src/blocks/choice-art/choice-art.d.ts +73 -0
  22. package/lib/typescript/src/blocks/choice-art/choice-art.d.ts.map +1 -0
  23. package/lib/typescript/src/blocks/choice-art/index.d.ts +2 -0
  24. package/lib/typescript/src/blocks/choice-art/index.d.ts.map +1 -0
  25. package/lib/typescript/src/blocks/index.d.ts +1 -0
  26. package/lib/typescript/src/blocks/index.d.ts.map +1 -1
  27. package/lib/typescript/src/components/page-header/page-header.d.ts +1 -0
  28. package/lib/typescript/src/components/page-header/page-header.d.ts.map +1 -1
  29. package/lib/typescript/src/components/toast/index.d.ts +1 -1
  30. package/lib/typescript/src/components/toast/index.d.ts.map +1 -1
  31. package/lib/typescript/src/components/toast/toast.d.ts +4 -1
  32. package/lib/typescript/src/components/toast/toast.d.ts.map +1 -1
  33. package/lib/typescript/src/index.d.ts +1 -1
  34. package/lib/typescript/src/index.d.ts.map +1 -1
  35. package/lib/typescript/src/internal/glyphs.d.ts +12 -0
  36. package/lib/typescript/src/internal/glyphs.d.ts.map +1 -1
  37. package/lib/typescript/src/templates/index.d.ts +2 -0
  38. package/lib/typescript/src/templates/index.d.ts.map +1 -1
  39. package/lib/typescript/src/templates/preview-edit-template.d.ts +39 -0
  40. package/lib/typescript/src/templates/preview-edit-template.d.ts.map +1 -0
  41. package/package.json +1 -1
  42. package/src/blocks/choice-art/choice-art.tsx +500 -0
  43. package/src/blocks/choice-art/index.ts +29 -0
  44. package/src/blocks/index.tsx +1 -0
  45. package/src/components/page-header/page-header.tsx +28 -1
  46. package/src/components/toast/index.ts +1 -0
  47. package/src/components/toast/toast.tsx +12 -4
  48. package/src/index.tsx +12 -0
  49. package/src/internal/glyphs.tsx +409 -0
  50. package/src/templates/index.ts +7 -0
  51. package/src/templates/preview-edit-template.tsx +467 -0
@@ -0,0 +1,467 @@
1
+ import { useState, type ReactNode } from 'react';
2
+ import { Text as RNText, View, type LayoutChangeEvent } from 'react-native';
3
+ import Animated, {
4
+ interpolateColor,
5
+ useAnimatedStyle,
6
+ } from 'react-native-reanimated';
7
+ import { HeaderButton } from '../components/page-header/page-header';
8
+ import { Text } from '../components/text/text';
9
+ import { ToastHost } from '../components/toast/toast';
10
+ import { ChevronGlyph, MobileGlyph, MonitorGlyph } from '../internal/glyphs';
11
+ import { haptic } from '../internal/haptics';
12
+ import { renderIcon, type IconSlot } from '../internal/icon';
13
+ import { useSwitch } from '../internal/motion';
14
+ import { PressableBase } from '../internal/pressable-base';
15
+ import { SteadyText } from '../internal/steady-text';
16
+ import { useSlide } from '../internal/use-slide';
17
+ import { useTheme } from '../theme/theme-provider';
18
+ import { makeStyles } from '../utils/styles';
19
+ import { HeaderIconButton, type TemplateAction } from './parts';
20
+
21
+ export type PreviewDevice = 'web' | 'mobile';
22
+
23
+ export type PreviewEditChoice = {
24
+ key: string;
25
+ label: string;
26
+ art?: IconSlot;
27
+ selected: boolean;
28
+ disabled?: boolean;
29
+ onPress: () => void;
30
+ };
31
+
32
+ export type PreviewEditTool = {
33
+ key: string;
34
+ label: string;
35
+ icon: IconSlot;
36
+ disabled?: boolean;
37
+ };
38
+
39
+ export type PreviewEditTemplateProps = {
40
+ title: string;
41
+ saveAction: TemplateAction;
42
+ onBack?: () => void;
43
+ backLabel?: string;
44
+ device: PreviewDevice;
45
+ onDeviceChange: (device: PreviewDevice) => void;
46
+ deviceNotes?: Partial<Record<PreviewDevice, string>>;
47
+ compareLabel?: string;
48
+ onCompareChange?: (comparing: boolean) => void;
49
+ children: ReactNode;
50
+ choices?: readonly PreviewEditChoice[];
51
+ tray?: ReactNode;
52
+ tools: readonly PreviewEditTool[];
53
+ tool: string;
54
+ onToolChange: (key: string) => void;
55
+ topInset?: number;
56
+ bottomInset?: number;
57
+ };
58
+
59
+ const DEVICES: readonly {
60
+ value: PreviewDevice;
61
+ label: string;
62
+ icon: IconSlot;
63
+ }[] = [
64
+ { value: 'web', label: '웹', icon: MonitorGlyph },
65
+ { value: 'mobile', label: '모바일', icon: MobileGlyph },
66
+ ];
67
+
68
+ const EDGE = 1.5;
69
+
70
+ const useStyles = makeStyles((t) => ({
71
+ root: { flex: 1, backgroundColor: t.colors.background },
72
+ head: {
73
+ height: t.headerHeight,
74
+ flexDirection: 'row',
75
+ alignItems: 'center',
76
+ paddingLeft: t.space[1],
77
+ paddingRight: t.space[2],
78
+ },
79
+ title: { flex: 1 },
80
+ titleAlone: { paddingLeft: t.space[4] },
81
+ row: {
82
+ flexDirection: 'row',
83
+ alignItems: 'center',
84
+ justifyContent: 'space-between',
85
+ paddingHorizontal: t.layout.groupGap,
86
+ paddingBottom: t.space[2],
87
+ },
88
+ segment: {
89
+ height: t.space[10],
90
+ flexDirection: 'row',
91
+ padding: t.space[1],
92
+ borderRadius: t.radius.full,
93
+ backgroundColor: t.colors.border,
94
+ },
95
+ option: {
96
+ flexDirection: 'row',
97
+ alignItems: 'center',
98
+ justifyContent: 'center',
99
+ gap: t.space[1],
100
+ minWidth: t.space[16],
101
+ paddingHorizontal: t.space[3],
102
+ borderRadius: t.radius.full,
103
+ },
104
+ thumb: {
105
+ position: 'absolute',
106
+ left: 0,
107
+ top: 0,
108
+ borderRadius: t.radius.full,
109
+ backgroundColor: t.colors.surface,
110
+ boxShadow: t.shadow.sm,
111
+ },
112
+ optionLabel: {
113
+ fontFamily: t.fontFamily,
114
+ fontSize: t.typography.eyebrow.fontSize,
115
+ lineHeight: t.typography.eyebrow.lineHeight,
116
+ fontWeight: '500',
117
+ color: t.colors.mutedForeground,
118
+ },
119
+ strong: { fontWeight: '600' },
120
+ note: {
121
+ fontFamily: t.fontFamily,
122
+ fontSize: t.typography.eyebrow.fontSize,
123
+ lineHeight: t.typography.eyebrow.lineHeight,
124
+ fontWeight: '500',
125
+ color: t.colors.faint,
126
+ },
127
+ noteOn: { color: t.colors.primary },
128
+ compare: {
129
+ height: t.space[8],
130
+ justifyContent: 'center',
131
+ paddingHorizontal: t.space[3],
132
+ borderRadius: t.radius.full,
133
+ borderWidth: EDGE,
134
+ borderColor: t.colors.surface,
135
+ backgroundColor: t.colors.surface,
136
+ boxShadow: t.shadow.sm,
137
+ },
138
+ compareOn: {
139
+ borderColor: t.colors.primaryEdge,
140
+ backgroundColor: t.colors.selectSurface,
141
+ },
142
+ compareLabelOn: { color: t.colors.selectForeground },
143
+ card: {
144
+ flex: 1,
145
+ minHeight: 0,
146
+ marginHorizontal: t.layout.groupGap,
147
+ borderRadius: t.radius.lg,
148
+ backgroundColor: t.colors.surface,
149
+ boxShadow: t.shadow.lift,
150
+ },
151
+ stage: { flex: 1, borderRadius: t.radius.lg, overflow: 'hidden' },
152
+ bar: {
153
+ marginTop: t.space[3],
154
+ marginHorizontal: t.layout.groupGap,
155
+ paddingTop: t.space[3],
156
+ paddingHorizontal: t.space[3],
157
+ borderRadius: t.radius.xl,
158
+ backgroundColor: t.colors.surface,
159
+ boxShadow: t.shadow.md,
160
+ },
161
+ choices: {
162
+ height: t.space[16] + t.space[5],
163
+ flexDirection: 'row',
164
+ gap: t.space[2],
165
+ },
166
+ tile: {
167
+ flex: 1,
168
+ alignItems: 'center',
169
+ justifyContent: 'center',
170
+ gap: t.space[2],
171
+ borderRadius: t.radius.lg,
172
+ borderWidth: EDGE,
173
+ borderColor: t.colors.background,
174
+ backgroundColor: t.colors.background,
175
+ },
176
+ tileOn: {
177
+ borderColor: t.colors.primaryEdge,
178
+ backgroundColor: t.colors.selectSurface,
179
+ },
180
+ tileLabel: {
181
+ fontFamily: t.fontFamily,
182
+ fontSize: t.typography.eyebrow.fontSize,
183
+ lineHeight: t.typography.eyebrow.lineHeight,
184
+ fontWeight: '400',
185
+ color: t.colors.title,
186
+ },
187
+ tileLabelOn: { fontWeight: '600', color: t.colors.selectForeground },
188
+ tabs: {
189
+ flexDirection: 'row',
190
+ marginTop: t.space[2],
191
+ borderTopWidth: 1,
192
+ borderTopColor: t.colors.line,
193
+ },
194
+ tabOff: { opacity: 1 },
195
+ tab: {
196
+ flex: 1,
197
+ minHeight: t.space[16],
198
+ alignItems: 'center',
199
+ justifyContent: 'center',
200
+ gap: t.space[1],
201
+ },
202
+ }));
203
+
204
+ function DeviceOption({
205
+ label,
206
+ icon,
207
+ note,
208
+ selected,
209
+ onPress,
210
+ onLayout,
211
+ }: {
212
+ label: string;
213
+ icon: IconSlot;
214
+ note?: string;
215
+ selected: boolean;
216
+ onPress: () => void;
217
+ onLayout: (event: LayoutChangeEvent) => void;
218
+ }) {
219
+ const t = useTheme();
220
+ const s = useStyles();
221
+ const on = useSwitch(selected, 'base');
222
+ const idle = t.colors.mutedForeground;
223
+ const ink = t.colors.title;
224
+ const tone = useAnimatedStyle(() => ({
225
+ color: interpolateColor(on.value, [0, 1], [idle, ink]),
226
+ }));
227
+ return (
228
+ <PressableBase
229
+ accessibilityRole="tab"
230
+ accessibilityState={{ selected }}
231
+ accessibilityLabel={note ? `${label} ${note}` : label}
232
+ feedback="none"
233
+ onPress={onPress}
234
+ onLayout={onLayout}
235
+ style={s.option}
236
+ >
237
+ {renderIcon(icon, {
238
+ color: selected ? ink : idle,
239
+ size: t.iconSize.sm,
240
+ })}
241
+ <SteadyText
242
+ selected={selected}
243
+ style={s.optionLabel}
244
+ strongStyle={s.strong}
245
+ animatedStyle={tone}
246
+ >
247
+ {label}
248
+ </SteadyText>
249
+ {note ? (
250
+ <RNText
251
+ numberOfLines={1}
252
+ maxFontSizeMultiplier={t.maxFontScale}
253
+ style={[s.note, selected && s.noteOn]}
254
+ >
255
+ {note}
256
+ </RNText>
257
+ ) : null}
258
+ </PressableBase>
259
+ );
260
+ }
261
+
262
+ function ChoiceTile({ choice }: { choice: PreviewEditChoice }) {
263
+ const t = useTheme();
264
+ const s = useStyles();
265
+ const { selected } = choice;
266
+ return (
267
+ <PressableBase
268
+ accessibilityRole="button"
269
+ accessibilityLabel={choice.label}
270
+ accessibilityState={{ selected, disabled: choice.disabled }}
271
+ feedback="small"
272
+ disabled={choice.disabled}
273
+ onPress={() => {
274
+ haptic('select');
275
+ choice.onPress();
276
+ }}
277
+ style={[s.tile, selected && s.tileOn]}
278
+ >
279
+ {choice.art
280
+ ? renderIcon(choice.art, {
281
+ color: selected ? t.colors.primaryEdge : t.colors.input,
282
+ size: t.space[6],
283
+ })
284
+ : null}
285
+ <RNText
286
+ numberOfLines={1}
287
+ maxFontSizeMultiplier={t.maxFontScale}
288
+ style={[s.tileLabel, selected && s.tileLabelOn]}
289
+ >
290
+ {choice.label}
291
+ </RNText>
292
+ </PressableBase>
293
+ );
294
+ }
295
+
296
+ function ToolTab({
297
+ tool,
298
+ selected,
299
+ onPress,
300
+ }: {
301
+ tool: PreviewEditTool;
302
+ selected: boolean;
303
+ onPress: () => void;
304
+ }) {
305
+ const t = useTheme();
306
+ const s = useStyles();
307
+ const off = !!tool.disabled;
308
+ const color = off
309
+ ? t.colors.disabledForeground
310
+ : selected
311
+ ? t.colors.primary
312
+ : t.colors.mutedForeground;
313
+ return (
314
+ <PressableBase
315
+ accessibilityRole="tab"
316
+ accessibilityLabel={tool.label}
317
+ accessibilityState={{ selected, disabled: off }}
318
+ feedback="small"
319
+ disabled={off}
320
+ disabledStyle={s.tabOff}
321
+ onPress={onPress}
322
+ style={s.tab}
323
+ >
324
+ {renderIcon(tool.icon, { color, size: t.iconSize.md })}
325
+ <Text
326
+ variant="caption"
327
+ weight={selected ? 'semibold' : 'regular'}
328
+ numberOfLines={1}
329
+ style={{ color }}
330
+ >
331
+ {tool.label}
332
+ </Text>
333
+ </PressableBase>
334
+ );
335
+ }
336
+
337
+ export function PreviewEditTemplate({
338
+ title,
339
+ saveAction,
340
+ onBack,
341
+ backLabel = '뒤로',
342
+ device,
343
+ onDeviceChange,
344
+ deviceNotes,
345
+ compareLabel = '원래와 비교',
346
+ onCompareChange,
347
+ children,
348
+ choices,
349
+ tray,
350
+ tools,
351
+ tool,
352
+ onToolChange,
353
+ topInset = 0,
354
+ bottomInset = 0,
355
+ }: PreviewEditTemplateProps) {
356
+ const t = useTheme();
357
+ const s = useStyles();
358
+ const slide = useSlide(device);
359
+ const [comparing, setComparing] = useState(false);
360
+ const [barHeight, setBarHeight] = useState(0);
361
+ const barBottom = bottomInset + t.space[4];
362
+ const hold = (next: boolean) => {
363
+ setComparing(next);
364
+ onCompareChange?.(next);
365
+ };
366
+ return (
367
+ <View style={[s.root, { paddingTop: topInset }]}>
368
+ <View style={s.head}>
369
+ {onBack ? (
370
+ <HeaderIconButton
371
+ icon={ChevronGlyph}
372
+ label={backLabel}
373
+ onPress={onBack}
374
+ size={24}
375
+ mirror
376
+ />
377
+ ) : null}
378
+ <Text
379
+ variant="title"
380
+ accessibilityRole="header"
381
+ numberOfLines={1}
382
+ style={[s.title, !onBack && s.titleAlone]}
383
+ >
384
+ {title}
385
+ </Text>
386
+ <HeaderButton
387
+ label={saveAction.label}
388
+ primary
389
+ disabled={saveAction.disabled || saveAction.loading}
390
+ onPress={saveAction.onPress}
391
+ />
392
+ </View>
393
+ <View style={s.row}>
394
+ <View accessibilityRole="tablist" style={s.segment}>
395
+ <Animated.View pointerEvents="none" style={[s.thumb, slide.box]} />
396
+ {DEVICES.map((option) => {
397
+ const selected = option.value === device;
398
+ return (
399
+ <DeviceOption
400
+ key={option.value}
401
+ label={option.label}
402
+ icon={option.icon}
403
+ note={deviceNotes?.[option.value]}
404
+ selected={selected}
405
+ onPress={() => {
406
+ if (selected) return;
407
+ haptic('select');
408
+ onDeviceChange(option.value);
409
+ }}
410
+ onLayout={slide.measure(option.value)}
411
+ />
412
+ );
413
+ })}
414
+ </View>
415
+ {onCompareChange ? (
416
+ <PressableBase
417
+ onPress={() => {}}
418
+ onPressIn={() => hold(true)}
419
+ onPressOut={() => hold(false)}
420
+ accessibilityRole="button"
421
+ accessibilityLabel={compareLabel}
422
+ accessibilityState={{ selected: comparing }}
423
+ feedback="small"
424
+ style={[s.compare, comparing && s.compareOn]}
425
+ >
426
+ <Text
427
+ variant="caption"
428
+ weight={comparing ? 'semibold' : 'medium'}
429
+ style={comparing ? s.compareLabelOn : undefined}
430
+ >
431
+ {compareLabel}
432
+ </Text>
433
+ </PressableBase>
434
+ ) : null}
435
+ </View>
436
+ <View style={s.card}>
437
+ <View style={s.stage}>{children}</View>
438
+ </View>
439
+ <View
440
+ onLayout={(event) => setBarHeight(event.nativeEvent.layout.height)}
441
+ style={[s.bar, { marginBottom: barBottom }]}
442
+ >
443
+ {tray ??
444
+ (choices?.length ? (
445
+ <View style={s.choices}>
446
+ {choices.map((choice) => (
447
+ <ChoiceTile key={choice.key} choice={choice} />
448
+ ))}
449
+ </View>
450
+ ) : null)}
451
+ <View accessibilityRole="tablist" style={s.tabs}>
452
+ {tools.map((item) => (
453
+ <ToolTab
454
+ key={item.key}
455
+ tool={item}
456
+ selected={item.key === tool}
457
+ onPress={() => {
458
+ if (item.key !== tool) onToolChange(item.key);
459
+ }}
460
+ />
461
+ ))}
462
+ </View>
463
+ </View>
464
+ <ToastHost bottom={barBottom + barHeight + t.space[3]} />
465
+ </View>
466
+ );
467
+ }