cpk-ui 0.0.1

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 (69) hide show
  1. package/README.md +27 -0
  2. package/components/modals/AlertDialog/AlertDialog.js +80 -0
  3. package/components/modals/AlertDialog/AlertDialog.stories.tsx +80 -0
  4. package/components/modals/AlertDialog/AlertDialog.tsx +194 -0
  5. package/components/modals/Snackbar/Snackbar.js +94 -0
  6. package/components/modals/Snackbar/Snackbar.stories.tsx +98 -0
  7. package/components/modals/Snackbar/Snackbar.tsx +174 -0
  8. package/components/modals/Snackbar/const.js +5 -0
  9. package/components/modals/Snackbar/const.ts +4 -0
  10. package/components/uis/Accordion/Accordion.js +11 -0
  11. package/components/uis/Accordion/Accordion.stories.tsx +38 -0
  12. package/components/uis/Accordion/Accordion.test.tsx +128 -0
  13. package/components/uis/Accordion/Accordion.tsx +58 -0
  14. package/components/uis/Accordion/AccordionItem.js +102 -0
  15. package/components/uis/Accordion/AccordionItem.tsx +213 -0
  16. package/components/uis/Button/Button.js +161 -0
  17. package/components/uis/Button/Button.stories.tsx +81 -0
  18. package/components/uis/Button/Button.test.tsx +560 -0
  19. package/components/uis/Button/Button.tsx +335 -0
  20. package/components/uis/Checkbox/Checkbox.js +70 -0
  21. package/components/uis/Checkbox/Checkbox.stories.tsx +46 -0
  22. package/components/uis/Checkbox/Checkbox.test.tsx +139 -0
  23. package/components/uis/Checkbox/Checkbox.tsx +150 -0
  24. package/components/uis/Icon/Icon.js +3780 -0
  25. package/components/uis/Icon/Icon.stories.tsx +45 -0
  26. package/components/uis/Icon/Icon.test.tsx +19 -0
  27. package/components/uis/Icon/Icon.tsx +3800 -0
  28. package/components/uis/Icon/Pretendard-Bold.otf +0 -0
  29. package/components/uis/Icon/Pretendard-Regular.otf +0 -0
  30. package/components/uis/Icon/Pretendard-Thin.otf +0 -0
  31. package/components/uis/Icon/cpk.ttf +0 -0
  32. package/components/uis/Icon/selection.json +1 -0
  33. package/components/uis/IconButton/IconButton.js +120 -0
  34. package/components/uis/IconButton/IconButton.test.tsx +165 -0
  35. package/components/uis/IconButton/IconButton.tsx +252 -0
  36. package/components/uis/LoadingIndicator/LoadingIndicator.js +24 -0
  37. package/components/uis/LoadingIndicator/LoadingIndicator.tsx +79 -0
  38. package/components/uis/Rating/Rating.js +53 -0
  39. package/components/uis/Rating/Rating.test.tsx +72 -0
  40. package/components/uis/Rating/Rating.tsx +155 -0
  41. package/components/uis/StatusbarBrightness/StatusBarBrightness.js +13 -0
  42. package/components/uis/StatusbarBrightness/StatusBarBrightness.test.tsx +41 -0
  43. package/components/uis/StatusbarBrightness/StatusBarBrightness.tsx +17 -0
  44. package/components/uis/Styled/StyledComponents.js +130 -0
  45. package/components/uis/Styled/StyledComponents.tsx +200 -0
  46. package/components/uis/SwitchToggle/SwitchToggle.js +126 -0
  47. package/components/uis/SwitchToggle/SwitchToggle.test.tsx +70 -0
  48. package/components/uis/SwitchToggle/SwitchToggle.tsx +224 -0
  49. package/components/uis/Typography/Typography.js +90 -0
  50. package/components/uis/Typography/Typography.test.tsx +58 -0
  51. package/components/uis/Typography/Typography.tsx +132 -0
  52. package/hooks/useDebouncedColorScheme.js +21 -0
  53. package/hooks/useDebouncedColorScheme.tsx +30 -0
  54. package/index.js +16 -0
  55. package/index.tsx +18 -0
  56. package/package.json +35 -0
  57. package/providers/ThemeProvider.js +106 -0
  58. package/providers/ThemeProvider.tsx +180 -0
  59. package/providers/index.js +62 -0
  60. package/providers/index.tsx +125 -0
  61. package/react-native.config.cjs +5 -0
  62. package/utils/colors.js +124 -0
  63. package/utils/colors.ts +127 -0
  64. package/utils/createCtx.js +15 -0
  65. package/utils/createCtx.tsx +26 -0
  66. package/utils/guards.js +44 -0
  67. package/utils/guards.ts +93 -0
  68. package/utils/theme.js +5 -0
  69. package/utils/theme.ts +33 -0
@@ -0,0 +1,560 @@
1
+ import '@testing-library/jest-native/extend-expect';
2
+
3
+ import React from 'react';
4
+ import {Text} from 'react-native';
5
+ import {css} from '@emotion/native';
6
+ import type {RenderAPI} from '@testing-library/react-native';
7
+ import {fireEvent, render} from '@testing-library/react-native';
8
+
9
+ import {createComponent} from '../../../../test/testUtils';
10
+ import {Button} from './Button';
11
+ import {LoadingIndicator} from '../LoadingIndicator/LoadingIndicator';
12
+ import type {Props as ButtonProps} from './Button';
13
+ import {ThemeType} from '../../../providers/ThemeProvider';
14
+ import {dark, light} from '../../../utils/colors';
15
+
16
+ let testingLib: RenderAPI;
17
+
18
+ jest.mock('react-native-web-hooks', () => ({
19
+ useHover: () => true,
20
+ }));
21
+
22
+ const Component = ({
23
+ props,
24
+ themeType,
25
+ }: {
26
+ props?: ButtonProps;
27
+ themeType?: ThemeType;
28
+ }): JSX.Element =>
29
+ createComponent(<Button onPress={jest.fn} {...props} />, themeType);
30
+
31
+ describe('[Button]', () => {
32
+ it('should render without crashing', () => {
33
+ testingLib = render(Component({}));
34
+
35
+ const json = testingLib.toJSON();
36
+ expect(json).toBeTruthy();
37
+ });
38
+
39
+ describe('Index', () => {
40
+ it('should render loading status', () => {
41
+ testingLib = render(Component({props: {loading: true}}));
42
+
43
+ expect(LoadingIndicator).toBeDefined();
44
+ expect(testingLib.getByTestId('loading-view')).toBeTruthy();
45
+ });
46
+
47
+ it('should render default disabled style when disabled', () => {
48
+ testingLib = render(Component({props: {disabled: true}}));
49
+
50
+ const loadingView = testingLib.getByTestId('button-container');
51
+ expect(loadingView).toHaveStyle({borderTopColor: light.text.disabled});
52
+ });
53
+ });
54
+
55
+ describe('Disabled', () => {
56
+ it('should render disabled status', () => {
57
+ testingLib = render(Component({props: {disabled: true}}));
58
+
59
+ const json = testingLib.toJSON();
60
+ expect(json).toBeTruthy();
61
+ });
62
+
63
+ it('should render disabled status with disabled style', () => {
64
+ testingLib = render(
65
+ Component({
66
+ props: {
67
+ disabled: true,
68
+ styles: {
69
+ disabled: css`
70
+ background-color: yellow;
71
+ `,
72
+ },
73
+ },
74
+ }),
75
+ );
76
+
77
+ const button = testingLib.getByTestId('button-container');
78
+ expect(button).toHaveStyle({backgroundColor: 'yellow'});
79
+ });
80
+
81
+ it('should render container', () => {
82
+ testingLib = render(
83
+ Component({
84
+ props: {
85
+ styles: {
86
+ container: css`
87
+ background-color: blue;
88
+ `,
89
+ },
90
+ },
91
+ }),
92
+ );
93
+
94
+ const button = testingLib.getByTestId('button-container');
95
+ expect(button).toHaveStyle({backgroundColor: 'blue'});
96
+ });
97
+ });
98
+
99
+ describe('TextButton', () => {
100
+ it('renders text button', () => {
101
+ testingLib = render(
102
+ Component({
103
+ props: {
104
+ testID: 'text-button',
105
+ type: 'text',
106
+ },
107
+ }),
108
+ );
109
+
110
+ const json = testingLib.toJSON();
111
+ expect(json).toBeTruthy();
112
+ });
113
+ });
114
+
115
+ it('should render start and end elements', () => {
116
+ testingLib = render(
117
+ Component({props: {startElement: <Text />, endElement: <Text />}}),
118
+ );
119
+
120
+ const button = testingLib.getByTestId('button-container');
121
+
122
+ // @ts-ignore
123
+ expect(button.findAllByType(Text)).toHaveLength(3);
124
+ });
125
+
126
+ describe('[Button] Interaction', () => {
127
+ let cnt = 1;
128
+
129
+ it('should simulate onPress', () => {
130
+ testingLib = render(
131
+ Component({
132
+ props: {
133
+ onPress: () => cnt++,
134
+ },
135
+ }),
136
+ );
137
+
138
+ const button = testingLib.getByTestId('button-container');
139
+
140
+ fireEvent.press(button);
141
+
142
+ expect(cnt).toBe(2);
143
+ });
144
+ });
145
+
146
+ describe('[Button] color', () => {
147
+ it('should renders primary color', () => {
148
+ testingLib = render(Component({props: {color: 'primary'}}));
149
+
150
+ const button = testingLib.getByTestId('button-container');
151
+ expect(button).toHaveStyle({backgroundColor: light.button.primary.bg});
152
+ });
153
+
154
+ it('should renders secondary color', () => {
155
+ testingLib = render(Component({props: {color: 'secondary'}}));
156
+
157
+ const button = testingLib.getByTestId('button-container');
158
+ expect(button).toHaveStyle({
159
+ backgroundColor: light.button.secondary.bg,
160
+ });
161
+ });
162
+
163
+ it('should renders success color', () => {
164
+ testingLib = render(Component({props: {color: 'success'}}));
165
+
166
+ const button = testingLib.getByTestId('button-container');
167
+ expect(button).toHaveStyle({backgroundColor: light.button.success.bg});
168
+ });
169
+
170
+ it('should renders warning color', () => {
171
+ testingLib = render(Component({props: {color: 'warning'}}));
172
+
173
+ const button = testingLib.getByTestId('button-container');
174
+ expect(button).toHaveStyle({backgroundColor: light.button.warning.bg});
175
+ });
176
+
177
+ it('renders danger color', () => {
178
+ testingLib = render(Component({props: {color: 'danger'}}));
179
+
180
+ const button = testingLib.getByTestId('button-container');
181
+ expect(button).toHaveStyle({backgroundColor: light.button.danger.bg});
182
+ });
183
+
184
+ it('should renders info color', () => {
185
+ testingLib = render(Component({props: {color: 'info'}}));
186
+
187
+ const button = testingLib.getByTestId('button-container');
188
+ expect(button).toHaveStyle({backgroundColor: light.button.info.bg});
189
+ });
190
+
191
+ it('should renders light color', () => {
192
+ testingLib = render(Component({props: {color: 'light'}}));
193
+
194
+ const button = testingLib.getByTestId('button-container');
195
+ expect(button).toHaveStyle({backgroundColor: light.button.light.bg});
196
+ });
197
+ });
198
+
199
+ describe('[Button] - dark mode', () => {
200
+ it('should render button', () => {
201
+ testingLib = render(Component({themeType: 'dark'}));
202
+
203
+ const button = testingLib.getByTestId('button-container');
204
+ expect(button).toHaveStyle({backgroundColor: dark.button.primary.bg});
205
+ });
206
+
207
+ it('should renders danger color', () => {
208
+ testingLib = render(
209
+ Component({
210
+ props: {
211
+ text: 'my-button',
212
+ color: 'danger',
213
+ },
214
+ themeType: 'dark',
215
+ }),
216
+ );
217
+
218
+ const button = testingLib.getByTestId('button-container');
219
+ expect(button).toHaveStyle({backgroundColor: dark.button.danger.bg});
220
+ });
221
+ });
222
+
223
+ describe('[Button] outlined', () => {
224
+ it('should render [type=outlined] button', () => {
225
+ testingLib = render(
226
+ Component({
227
+ props: {type: 'outlined'},
228
+ }),
229
+ );
230
+
231
+ const button = testingLib.getByTestId('button-container');
232
+ expect(button).toHaveStyle({backgroundColor: light.bg.basic});
233
+ });
234
+
235
+ it('should render [type=outlined] button with [color=primary]', () => {
236
+ testingLib = render(
237
+ Component({
238
+ props: {
239
+ type: 'outlined',
240
+ color: 'primary',
241
+ },
242
+ }),
243
+ );
244
+
245
+ const button = testingLib.getByTestId('button-container');
246
+ expect(button).toHaveStyle({
247
+ backgroundColor: light.bg.basic,
248
+ borderBottomColor: light.button.primary.bg,
249
+ });
250
+ });
251
+
252
+ it('should render [type=outlined] button with [color=secondary]', () => {
253
+ testingLib = render(
254
+ Component({
255
+ props: {
256
+ type: 'outlined',
257
+ color: 'secondary',
258
+ },
259
+ }),
260
+ );
261
+
262
+ const button = testingLib.getByTestId('button-container');
263
+ expect(button).toHaveStyle({
264
+ backgroundColor: light.bg.basic,
265
+ borderBottomColor: light.button.secondary.bg,
266
+ });
267
+ });
268
+
269
+ it('should render [type=outlined] button with [color=success]', () => {
270
+ testingLib = render(
271
+ Component({
272
+ props: {
273
+ type: 'outlined',
274
+ color: 'success',
275
+ },
276
+ }),
277
+ );
278
+
279
+ const button = testingLib.getByTestId('button-container');
280
+ expect(button.props.type).toEqual('outlined');
281
+
282
+ expect(button).toHaveStyle({
283
+ backgroundColor: light.bg.basic,
284
+ borderBottomColor: light.button.success.bg,
285
+ });
286
+ });
287
+
288
+ it('should render [type=outlined] button with [color=warning]', () => {
289
+ testingLib = render(
290
+ Component({
291
+ props: {
292
+ type: 'outlined',
293
+ color: 'warning',
294
+ },
295
+ }),
296
+ );
297
+
298
+ const button = testingLib.getByTestId('button-container');
299
+
300
+ expect(button.props.type).toEqual('outlined');
301
+
302
+ expect(button).toHaveStyle({
303
+ backgroundColor: light.bg.basic,
304
+ borderBottomColor: light.button.warning.bg,
305
+ });
306
+ });
307
+
308
+ it('should render [type=outlined] button with [color=danger]', () => {
309
+ testingLib = render(
310
+ Component({
311
+ props: {
312
+ type: 'outlined',
313
+ color: 'danger',
314
+ },
315
+ }),
316
+ );
317
+
318
+ const button = testingLib.getByTestId('button-container');
319
+ expect(button.props.type).toEqual('outlined');
320
+
321
+ expect(button).toHaveStyle({
322
+ backgroundColor: light.bg.basic,
323
+ borderBottomColor: light.button.danger.bg,
324
+ });
325
+ });
326
+
327
+ it('should render [type=outlined] button with [color=info]', () => {
328
+ testingLib = render(
329
+ Component({
330
+ props: {
331
+ type: 'outlined',
332
+ color: 'info',
333
+ },
334
+ }),
335
+ );
336
+
337
+ const button = testingLib.getByTestId('button-container');
338
+ expect(button.props.type).toEqual('outlined');
339
+
340
+ expect(button).toHaveStyle({
341
+ backgroundColor: light.bg.basic,
342
+ borderBottomColor: light.button.info.bg,
343
+ });
344
+ });
345
+
346
+ it('should render [type=outlined] button with [color=light]', () => {
347
+ testingLib = render(
348
+ Component({
349
+ props: {
350
+ type: 'outlined',
351
+ color: 'light',
352
+ },
353
+ }),
354
+ );
355
+
356
+ const button = testingLib.getByTestId('button-container');
357
+ expect(button.props.type).toEqual('outlined');
358
+
359
+ expect(button).toHaveStyle({
360
+ backgroundColor: light.bg.basic,
361
+ borderBottomColor: light.button.light.bg,
362
+ });
363
+ });
364
+
365
+ it('should render [type=outlined] `disabled` button', () => {
366
+ testingLib = render(
367
+ Component({
368
+ props: {
369
+ type: 'outlined',
370
+ disabled: true,
371
+ text: 'my-button',
372
+ },
373
+ }),
374
+ );
375
+
376
+ const button = testingLib.getByTestId('button-container');
377
+ expect(button.props.type).toEqual('outlined');
378
+
379
+ const text = testingLib.getByText('my-button');
380
+ expect(text).toHaveStyle({color: light.button.disabled.text});
381
+ });
382
+ });
383
+
384
+ describe('Outlined - dark mode', () => {
385
+ it('should render [type=outlined] [color=primary] button', () => {
386
+ testingLib = render(
387
+ Component({
388
+ props: {
389
+ type: 'outlined',
390
+ color: 'primary',
391
+ },
392
+ themeType: 'dark',
393
+ }),
394
+ );
395
+
396
+ const button = testingLib.getByTestId('button-container');
397
+ expect(button).toHaveStyle({borderBottomColor: dark.button.primary.bg});
398
+ });
399
+
400
+ it('should render [type=outlined] [color=secondary] button', () => {
401
+ testingLib = render(
402
+ Component({
403
+ props: {
404
+ type: 'outlined',
405
+ color: 'secondary',
406
+ },
407
+ themeType: 'dark',
408
+ }),
409
+ );
410
+
411
+ const button = testingLib.getByTestId('button-container');
412
+ expect(button).toHaveStyle({
413
+ borderBottomColor: dark.button.secondary.bg,
414
+ });
415
+ });
416
+
417
+ it('should render [type=outlined] [color=success] button', () => {
418
+ testingLib = render(
419
+ Component({
420
+ props: {
421
+ type: 'outlined',
422
+ color: 'success',
423
+ },
424
+ themeType: 'dark',
425
+ }),
426
+ );
427
+
428
+ const button = testingLib.getByTestId('button-container');
429
+ expect(button).toHaveStyle({borderBottomColor: dark.button.success.bg});
430
+ });
431
+
432
+ it('should render [type=outlined] [color=warning] button', () => {
433
+ testingLib = render(
434
+ Component({
435
+ props: {
436
+ type: 'outlined',
437
+ color: 'warning',
438
+ },
439
+ themeType: 'dark',
440
+ }),
441
+ );
442
+
443
+ const button = testingLib.getByTestId('button-container');
444
+ expect(button).toHaveStyle({borderBottomColor: dark.button.warning.bg});
445
+ });
446
+
447
+ it('should render [type=outlined] [color=danger] button', () => {
448
+ testingLib = render(
449
+ Component({
450
+ props: {
451
+ type: 'outlined',
452
+ color: 'danger',
453
+ },
454
+ themeType: 'dark',
455
+ }),
456
+ );
457
+
458
+ const button = testingLib.getByTestId('button-container');
459
+ expect(button).toHaveStyle({borderBottomColor: dark.button.danger.bg});
460
+ });
461
+
462
+ it('should [type=outlined] [color=light] button', () => {
463
+ testingLib = render(
464
+ Component({
465
+ props: {
466
+ type: 'outlined',
467
+ color: 'light',
468
+ },
469
+ themeType: 'dark',
470
+ }),
471
+ );
472
+
473
+ const button = testingLib.getByTestId('button-container');
474
+ expect(button).toHaveStyle({borderBottomColor: dark.button.light.bg});
475
+ });
476
+
477
+ it('should render [type=outlined] [color=info] button', () => {
478
+ testingLib = render(
479
+ Component({
480
+ props: {
481
+ type: 'outlined',
482
+ color: 'info',
483
+ },
484
+ themeType: 'dark',
485
+ }),
486
+ );
487
+
488
+ const button = testingLib.getByTestId('button-container');
489
+ expect(button).toHaveStyle({borderBottomColor: dark.button.info.bg});
490
+ });
491
+
492
+ it('should render [type=outlined] `disabled` button', () => {
493
+ testingLib = render(
494
+ Component({
495
+ props: {
496
+ type: 'outlined',
497
+ disabled: true,
498
+ text: 'my-button',
499
+ },
500
+ themeType: 'dark',
501
+ }),
502
+ );
503
+
504
+ const button = testingLib.getByTestId('button-container');
505
+ expect(button.props.type).toEqual('outlined');
506
+
507
+ const text = testingLib.getByText('my-button');
508
+ expect(text).toHaveStyle({color: dark.button.disabled.text});
509
+ });
510
+ });
511
+
512
+ describe('[Button] sizes', () => {
513
+ it('should render [large] button', () => {
514
+ testingLib = render(
515
+ Component({
516
+ props: {size: 'large'},
517
+ }),
518
+ );
519
+
520
+ const button = testingLib.getByTestId('button-container');
521
+ expect(button.props.size).toEqual('large');
522
+ });
523
+
524
+ it('should render [small] button', () => {
525
+ testingLib = render(
526
+ Component({
527
+ props: {
528
+ size: 'small',
529
+ color: 'danger',
530
+ },
531
+ themeType: 'dark',
532
+ }),
533
+ );
534
+
535
+ const button = testingLib.getByTestId('button-container');
536
+ expect(button.props.size).toEqual('small');
537
+ });
538
+ });
539
+
540
+ describe('[Button] borderRadius', () => {
541
+ it('should render with given borderRadius', () => {
542
+ const borderRadius = 10;
543
+
544
+ testingLib = render(
545
+ Component({
546
+ props: {
547
+ styles: {
548
+ container: {
549
+ borderTopRightRadius: borderRadius,
550
+ },
551
+ },
552
+ },
553
+ }),
554
+ );
555
+
556
+ const button = testingLib.getByTestId('button-container');
557
+ expect(button).toHaveStyle({borderTopRightRadius: borderRadius});
558
+ });
559
+ });
560
+ });