@kimdw-rtk/ui 0.0.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 (158) hide show
  1. package/.babelrc +12 -0
  2. package/.turbo/turbo-check-types.log +2 -0
  3. package/.turbo/turbo-lint.log +12 -0
  4. package/.turbo/turbo-test.log +4084 -0
  5. package/.vscode/settings.json +4 -0
  6. package/eslint.config.mjs +4 -0
  7. package/jest.config.json +10 -0
  8. package/jest.setup.js +2 -0
  9. package/package.json +53 -0
  10. package/src/components/Accordion/Accordion.css.ts +29 -0
  11. package/src/components/Accordion/Accordion.spec.tsx +6 -0
  12. package/src/components/Accordion/Accordion.tsx +44 -0
  13. package/src/components/Accordion/AccordionContent.css.ts +29 -0
  14. package/src/components/Accordion/AccordionContent.tsx +87 -0
  15. package/src/components/Accordion/AccordionContext.ts +9 -0
  16. package/src/components/Accordion/AccordionTrigger.css.ts +46 -0
  17. package/src/components/Accordion/AccordionTrigger.tsx +41 -0
  18. package/src/components/Accordion/index.ts +3 -0
  19. package/src/components/Alert/index.tsx +25 -0
  20. package/src/components/Box/Box.css.ts +18 -0
  21. package/src/components/Box/Box.spec.tsx +6 -0
  22. package/src/components/Box/index.tsx +41 -0
  23. package/src/components/Button/Button.css.ts +241 -0
  24. package/src/components/Button/Button.spec.tsx +30 -0
  25. package/src/components/Button/index.tsx +60 -0
  26. package/src/components/Card/Card.css.ts +93 -0
  27. package/src/components/Card/Card.spec.tsx +24 -0
  28. package/src/components/Card/Card.tsx +41 -0
  29. package/src/components/Card/CardContent.css.ts +8 -0
  30. package/src/components/Card/CardContent.tsx +23 -0
  31. package/src/components/Card/CardInteraction.css.ts +11 -0
  32. package/src/components/Card/CardInteraction.tsx +36 -0
  33. package/src/components/Card/CardThumbnail.css.ts +6 -0
  34. package/src/components/Card/CardThumbnail.tsx +23 -0
  35. package/src/components/Card/index.ts +4 -0
  36. package/src/components/Chip/Chip.css.ts +75 -0
  37. package/src/components/Chip/Chip.spec.tsx +6 -0
  38. package/src/components/Chip/Chip.tsx +37 -0
  39. package/src/components/Chip/index.ts +1 -0
  40. package/src/components/Confirm/index.tsx +44 -0
  41. package/src/components/Dialog/Dialog.css.ts +25 -0
  42. package/src/components/Dialog/Dialog.spec.tsx +26 -0
  43. package/src/components/Dialog/Dialog.tsx +30 -0
  44. package/src/components/Dialog/DialogContent.css.ts +16 -0
  45. package/src/components/Dialog/DialogContent.tsx +26 -0
  46. package/src/components/Dialog/DialogFooter.css.ts +20 -0
  47. package/src/components/Dialog/DialogFooter.tsx +26 -0
  48. package/src/components/Dialog/DialogHeader.css.ts +31 -0
  49. package/src/components/Dialog/DialogHeader.tsx +37 -0
  50. package/src/components/Dialog/index.ts +4 -0
  51. package/src/components/Navigation/Navigation.spec.tsx +19 -0
  52. package/src/components/Navigation/NavigationAside.css.ts +7 -0
  53. package/src/components/Navigation/NavigationAside.tsx +23 -0
  54. package/src/components/Navigation/NavigationBar.css.ts +42 -0
  55. package/src/components/Navigation/NavigationBar.tsx +25 -0
  56. package/src/components/Navigation/NavigationContainer.css.ts +11 -0
  57. package/src/components/Navigation/NavigationContainer.tsx +26 -0
  58. package/src/components/Navigation/NavigationDrawer.css.ts +61 -0
  59. package/src/components/Navigation/NavigationDrawer.tsx +67 -0
  60. package/src/components/Navigation/NavigationItem.css.ts +43 -0
  61. package/src/components/Navigation/NavigationItem.tsx +24 -0
  62. package/src/components/Navigation/NavigationLogo.css.ts +5 -0
  63. package/src/components/Navigation/NavigationLogo.tsx +28 -0
  64. package/src/components/Navigation/NavigationMenu.css.ts +23 -0
  65. package/src/components/Navigation/NavigationMenu.tsx +25 -0
  66. package/src/components/Navigation/index.ts +7 -0
  67. package/src/components/Range/Range.css.ts +132 -0
  68. package/src/components/Range/Range.spec.tsx +6 -0
  69. package/src/components/Range/Range.tsx +90 -0
  70. package/src/components/Range/index.ts +1 -0
  71. package/src/components/ScrollArea/ScrollArea.css.ts +40 -0
  72. package/src/components/ScrollArea/ScrollArea.spec.tsx +6 -0
  73. package/src/components/ScrollArea/ScrollArea.tsx +68 -0
  74. package/src/components/ScrollArea/index.ts +1 -0
  75. package/src/components/Select/Select.css.ts +22 -0
  76. package/src/components/Select/Select.spec.tsx +65 -0
  77. package/src/components/Select/Select.tsx +111 -0
  78. package/src/components/Select/SelectContext.ts +59 -0
  79. package/src/components/Select/SelectOption.css.ts +14 -0
  80. package/src/components/Select/SelectOption.tsx +40 -0
  81. package/src/components/Select/SelectOptionList.css.ts +68 -0
  82. package/src/components/Select/SelectOptionList.tsx +59 -0
  83. package/src/components/Select/SelectTrigger.css.ts +73 -0
  84. package/src/components/Select/SelectTrigger.tsx +49 -0
  85. package/src/components/Select/index.tsx +2 -0
  86. package/src/components/Skeleton/Skeleton.css.ts +26 -0
  87. package/src/components/Skeleton/Skeleton.spec.tsx +6 -0
  88. package/src/components/Skeleton/index.tsx +27 -0
  89. package/src/components/Table/Table.css.ts +10 -0
  90. package/src/components/Table/Table.spec.tsx +12 -0
  91. package/src/components/Table/Table.tsx +27 -0
  92. package/src/components/Table/TableBody.tsx +14 -0
  93. package/src/components/Table/TableCell.css.ts +43 -0
  94. package/src/components/Table/TableCell.tsx +30 -0
  95. package/src/components/Table/TableHead.css.ts +10 -0
  96. package/src/components/Table/TableHead.tsx +30 -0
  97. package/src/components/Table/TableHeader.tsx +14 -0
  98. package/src/components/Table/TableRow.css.ts +3 -0
  99. package/src/components/Table/TableRow.tsx +24 -0
  100. package/src/components/Table/index.ts +6 -0
  101. package/src/components/Tabs/Tabs.spec.tsx +46 -0
  102. package/src/components/Tabs/Tabs.tsx +34 -0
  103. package/src/components/Tabs/TabsContent.tsx +32 -0
  104. package/src/components/Tabs/TabsList.css.ts +11 -0
  105. package/src/components/Tabs/TabsList.tsx +25 -0
  106. package/src/components/Tabs/TabsProvider.tsx +17 -0
  107. package/src/components/Tabs/TabsTrigger.css.ts +38 -0
  108. package/src/components/Tabs/TabsTrigger.tsx +43 -0
  109. package/src/components/Tabs/index.ts +4 -0
  110. package/src/components/TextField/TextField.css.ts +81 -0
  111. package/src/components/TextField/TextField.spec.tsx +6 -0
  112. package/src/components/TextField/index.tsx +38 -0
  113. package/src/components/Toast/Toast.css.ts +79 -0
  114. package/src/components/Toast/Toast.spec.tsx +6 -0
  115. package/src/components/Toast/index.tsx +48 -0
  116. package/src/components/Typography/Typography.css.ts +17 -0
  117. package/src/components/Typography/Typography.spec.tsx +35 -0
  118. package/src/components/Typography/index.tsx +57 -0
  119. package/src/components/index.ts +18 -0
  120. package/src/contexts/UIProvider.tsx +30 -0
  121. package/src/contexts/index.ts +1 -0
  122. package/src/hooks/index.ts +5 -0
  123. package/src/hooks/useDialog/index.tsx +51 -0
  124. package/src/hooks/useDialog/useDialog.spec.tsx +80 -0
  125. package/src/hooks/useMouseScroll/index.ts +63 -0
  126. package/src/hooks/usePointerSlider/index.ts +79 -0
  127. package/src/hooks/useRipple/index.tsx +152 -0
  128. package/src/hooks/useRipple/ripple.css.ts +40 -0
  129. package/src/hooks/useToast/ToastContainer.css.ts +12 -0
  130. package/src/hooks/useToast/ToastContainer.tsx +11 -0
  131. package/src/hooks/useToast/ToastProvider.tsx +131 -0
  132. package/src/hooks/useToast/index.ts +15 -0
  133. package/src/index.ts +8 -0
  134. package/src/styles/globalStyle.css.ts +36 -0
  135. package/src/styles/index.ts +4 -0
  136. package/src/styles/layers.css.ts +4 -0
  137. package/src/styles/overlay.css.ts +40 -0
  138. package/src/styles/sprinkles.css.ts +149 -0
  139. package/src/styles/sx.ts +13 -0
  140. package/src/tests/uiTest.tsx +54 -0
  141. package/src/themes/darkTheme.css.ts +30 -0
  142. package/src/themes/index.ts +3 -0
  143. package/src/themes/lightTheme.css.ts +30 -0
  144. package/src/themes/theme.css.ts +32 -0
  145. package/src/tokens/index.ts +5 -0
  146. package/src/tokens/scale/color.ts +604 -0
  147. package/src/tokens/semantic/breakpoint.ts +6 -0
  148. package/src/tokens/semantic/color.ts +10 -0
  149. package/src/tokens/semantic/spacing.ts +9 -0
  150. package/src/tokens/semantic/typography.ts +32 -0
  151. package/src/types/index.ts +1 -0
  152. package/src/types/ui.types.ts +26 -0
  153. package/src/utils/index.ts +1 -0
  154. package/src/utils/sprinklesUtils.ts +28 -0
  155. package/src/utils/styleUtils.css.ts +109 -0
  156. package/tsconfig.json +11 -0
  157. package/turbo/generators/config.ts +30 -0
  158. package/turbo/generators/templates/component.hbs +8 -0
@@ -0,0 +1,24 @@
1
+ import { forwardRef } from 'react';
2
+
3
+ import clsx from 'clsx';
4
+
5
+ import { sx } from '#styles';
6
+ import type { UIComponent } from '#types';
7
+
8
+ import * as s from './NavigationItem.css';
9
+
10
+ type NavigationItemProps = UIComponent<'div', typeof s.container>;
11
+
12
+ export const NavigationItem = forwardRef<HTMLDivElement, NavigationItemProps>(
13
+ ({ style, className, sx: propSx, isSelected = false, ...props }, ref) => {
14
+ return (
15
+ <div
16
+ ref={ref}
17
+ style={{ ...style }}
18
+ className={clsx(s.container({ isSelected }), className, sx(propSx))}
19
+ {...props}
20
+ />
21
+ );
22
+ },
23
+ );
24
+ NavigationItem.displayName = 'NavigationItem';
@@ -0,0 +1,5 @@
1
+ import { styleWithLayer } from '#styleUtils';
2
+
3
+ export const navigationLogo = styleWithLayer({
4
+ marginRight: '0.5em',
5
+ });
@@ -0,0 +1,28 @@
1
+ import { forwardRef } from 'react';
2
+
3
+ import clsx from 'clsx';
4
+
5
+ import { sx } from '#styles';
6
+ import type { UIComponent } from '#types';
7
+
8
+ import * as s from './NavigationLogo.css';
9
+
10
+ type NavigationLogoProps = UIComponent<'div'>;
11
+
12
+ export const NavigationLogo = forwardRef<HTMLDivElement, NavigationLogoProps>(
13
+ ({ className, sx: propSx, ...props }, ref) => {
14
+ return (
15
+ <div
16
+ ref={ref}
17
+ className={clsx(
18
+ s.navigationLogo,
19
+ className,
20
+ sx({ marginRight: { mobile: 'lg', desktop: '3xl' } }),
21
+ sx(propSx),
22
+ )}
23
+ {...props}
24
+ />
25
+ );
26
+ },
27
+ );
28
+ NavigationLogo.displayName = 'NavigationLogo';
@@ -0,0 +1,23 @@
1
+ import { styleWithLayer } from '#styleUtils';
2
+ import { theme } from '#themes';
3
+ import { spacing } from '#tokens';
4
+
5
+ import { narrow } from './NavigationDrawer.css';
6
+
7
+ export const navigationMenu = styleWithLayer({
8
+ display: 'flex',
9
+ alignItems: 'center',
10
+ gap: '0.5em',
11
+
12
+ selectors: {
13
+ [`${narrow} &`]: {
14
+ flexDirection: 'column',
15
+ alignItems: 'stretch',
16
+ gap: '0',
17
+
18
+ width: '100%',
19
+ borderTop: `1px solid rgb(${theme.color['border.weak']})`,
20
+ paddingTop: spacing['md'],
21
+ },
22
+ },
23
+ });
@@ -0,0 +1,25 @@
1
+ import { forwardRef } from 'react';
2
+
3
+ import clsx from 'clsx';
4
+
5
+ import { sx } from '#styles';
6
+ import type { UIComponent } from '#types';
7
+
8
+ import * as s from './NavigationMenu.css';
9
+
10
+ type NavigationMenuProps = UIComponent<'div'>;
11
+
12
+ export const NavigationMenu = forwardRef<HTMLDivElement, NavigationMenuProps>(
13
+ ({ className, sx: propSx, ...props }, ref) => {
14
+ return (
15
+ <div
16
+ ref={ref}
17
+ className={clsx(s.navigationMenu, className, sx(propSx))}
18
+ {...props}
19
+ />
20
+ );
21
+ },
22
+ );
23
+ NavigationMenu.displayName = 'NavigationMenu';
24
+
25
+ export { s as navigationMenuCss };
@@ -0,0 +1,7 @@
1
+ export * from './NavigationAside';
2
+ export * from './NavigationBar';
3
+ export * from './NavigationContainer';
4
+ export * from './NavigationDrawer';
5
+ export * from './NavigationItem';
6
+ export * from './NavigationLogo';
7
+ export * from './NavigationMenu';
@@ -0,0 +1,132 @@
1
+ import { createVar } from '@vanilla-extract/css';
2
+
3
+ import { recipeWithLayer, styleWithLayer } from '#styleUtils';
4
+ import { theme } from '#themes';
5
+ import { semanticColor } from '#tokens';
6
+
7
+ import { SCALE_COLOR, type ScaleColor } from '../../tokens/scale/color';
8
+
9
+ const backgroundVar = createVar();
10
+
11
+ const semanticColors = semanticColor.reduce(
12
+ (prev, color) => ({
13
+ ...prev,
14
+ [color]: styleWithLayer({
15
+ vars: {
16
+ [backgroundVar]: theme.color[color],
17
+ },
18
+ }),
19
+ }),
20
+ {} as Record<(typeof semanticColor)[number], string>,
21
+ );
22
+
23
+ const scaleColors = SCALE_COLOR.reduce(
24
+ (prev, value) => ({
25
+ ...prev,
26
+ [value]: styleWithLayer({
27
+ vars: {
28
+ [backgroundVar]: theme.color[value][100],
29
+ },
30
+ }),
31
+ }),
32
+ {} as Record<ScaleColor, string>,
33
+ );
34
+
35
+ export const range = recipeWithLayer({
36
+ base: {
37
+ position: 'relative',
38
+
39
+ width: '100%',
40
+ height: '2em',
41
+
42
+ userSelect: 'none',
43
+ },
44
+
45
+ variants: {
46
+ color: {
47
+ ...semanticColors,
48
+ ...scaleColors,
49
+ },
50
+
51
+ size: {
52
+ sm: {
53
+ fontSize: '0.75em',
54
+ },
55
+
56
+ md: {
57
+ fontSize: '1em',
58
+ },
59
+
60
+ lg: {
61
+ fontSize: '1.25em',
62
+ },
63
+ },
64
+ },
65
+ });
66
+
67
+ export const thumb = styleWithLayer({
68
+ display: 'inline-block',
69
+ position: 'absolute',
70
+ top: '50%',
71
+
72
+ width: '1.25em',
73
+ height: '1.25em',
74
+
75
+ borderRadius: '50%',
76
+
77
+ boxShadow: `0 0 0.375em 0.125em rgba(${backgroundVar}, 0.33)`,
78
+ backgroundColor: `rgb(${backgroundVar})`,
79
+
80
+ transform: 'translate(-50%, -50%)',
81
+
82
+ cursor: 'pointer',
83
+
84
+ '::before': {
85
+ position: 'absolute',
86
+ inset: '-0.75em',
87
+
88
+ content: '',
89
+ },
90
+
91
+ '::after': {
92
+ position: 'absolute',
93
+ inset: '0',
94
+
95
+ borderRadius: '50%',
96
+
97
+ boxShadow: `0 0 0.5em 0.125em rgba(${backgroundVar}, 0.5)`,
98
+
99
+ opacity: '0',
100
+ transition: 'opacity 0.2s ease',
101
+
102
+ content: '',
103
+ },
104
+
105
+ selectors: {
106
+ '&:hover::after': {
107
+ opacity: '1',
108
+ },
109
+ },
110
+ });
111
+
112
+ export const fill = styleWithLayer({
113
+ position: 'absolute',
114
+ top: '0',
115
+
116
+ height: '100%',
117
+
118
+ backgroundColor: `rgb(${backgroundVar})`,
119
+ });
120
+
121
+ export const bar = styleWithLayer({
122
+ position: 'absolute',
123
+ top: '50%',
124
+
125
+ width: '100%',
126
+ height: '0.5em',
127
+ borderRadius: theme.borderRadius,
128
+
129
+ backgroundColor: `rgb(${theme.color.muted})`,
130
+
131
+ transform: 'translateY(-50%)',
132
+ });
@@ -0,0 +1,6 @@
1
+ import { uiTest } from '../../tests/uiTest';
2
+ import { Range } from './Range';
3
+
4
+ describe('Range 컴포넌트', () => {
5
+ uiTest(Range, 'Range');
6
+ });
@@ -0,0 +1,90 @@
1
+ 'use client';
2
+
3
+ import { forwardRef, useEffect, useRef } from 'react';
4
+
5
+ import clsx from 'clsx';
6
+
7
+ import { sx } from '#styles';
8
+ import type { UIComponent } from '#types';
9
+
10
+ import { usePointerSlider } from '../../hooks/usePointerSlider';
11
+ import * as s from './Range.css';
12
+
13
+ interface RangeProps
14
+ extends Omit<UIComponent<'div', typeof s.range>, 'children' | 'onChange'> {
15
+ min: number;
16
+ max: number;
17
+ defaultMinValue: number;
18
+ defaultMaxValue: number;
19
+ onChange: (min: number, max: number) => void;
20
+ }
21
+
22
+ export const Range = forwardRef<HTMLDivElement, RangeProps>(
23
+ (
24
+ {
25
+ min,
26
+ max,
27
+ defaultMinValue,
28
+ defaultMaxValue,
29
+ onChange,
30
+ className,
31
+ color = 'primary',
32
+ size = 'md',
33
+ sx: propSx,
34
+ ...props
35
+ },
36
+ ref,
37
+ ) => {
38
+ const barRef = useRef<HTMLDivElement>(null);
39
+ const leftThumbRef = useRef<HTMLSpanElement>(null);
40
+ const rightThumbRef = useRef<HTMLSpanElement>(null);
41
+ const leftValue = usePointerSlider(leftThumbRef, {
42
+ min,
43
+ max,
44
+ defaultValue: defaultMinValue,
45
+ }),
46
+ rightValue = usePointerSlider(rightThumbRef, {
47
+ min,
48
+ max,
49
+ defaultValue: defaultMaxValue,
50
+ });
51
+ const initRef = useRef<boolean>(false);
52
+
53
+ const minValue = Math.min(leftValue, rightValue),
54
+ maxValue = Math.max(leftValue, rightValue);
55
+
56
+ useEffect(() => {
57
+ if (!initRef.current) {
58
+ initRef.current = true;
59
+ return;
60
+ }
61
+
62
+ onChange(minValue, maxValue);
63
+ // eslint-disable-next-line
64
+ }, [minValue, maxValue]);
65
+
66
+ return (
67
+ <div
68
+ ref={ref}
69
+ className={clsx(s.range({ color, size }), className, sx(propSx))}
70
+ {...props}
71
+ >
72
+ <div className={s.bar}>
73
+ <div
74
+ ref={barRef}
75
+ className={s.fill}
76
+ style={{
77
+ left: `${((minValue - min) / (max - min)) * 100}%`,
78
+ right: `${(1 - (maxValue - min) / (max - min)) * 100}%`,
79
+ }}
80
+ />
81
+ </div>
82
+ <span ref={leftThumbRef} className={s.thumb} />
83
+ <span ref={rightThumbRef} className={s.thumb} />
84
+ </div>
85
+ );
86
+ },
87
+ );
88
+ Range.displayName = 'Range';
89
+
90
+ export { s as rangeCss };
@@ -0,0 +1 @@
1
+ export * from './Range';
@@ -0,0 +1,40 @@
1
+ import { style } from '@vanilla-extract/css';
2
+
3
+ import { styleWithLayer } from '#styleUtils';
4
+
5
+ const MASK_SIZE = '3rem';
6
+
7
+ export const scrollArea = styleWithLayer({
8
+ width: '100%',
9
+ overflowX: 'scroll',
10
+
11
+ '::-webkit-scrollbar': {
12
+ display: 'none',
13
+ },
14
+ });
15
+
16
+ export const maskLeft = style({
17
+ maskImage: `linear-gradient(to left,
18
+ black 0%,
19
+ black calc(100% - ${MASK_SIZE}),
20
+ transparent 100%)`,
21
+ });
22
+
23
+ export const maskRight = style({
24
+ maskImage: `linear-gradient(to right,
25
+ black 0%,
26
+ black calc(100% - ${MASK_SIZE}),
27
+ transparent 100%)`,
28
+ });
29
+
30
+ export const maskBoth = style({
31
+ maskImage: `linear-gradient(to right,
32
+ transparent 0%,
33
+ black ${MASK_SIZE},
34
+ black calc(100% - ${MASK_SIZE}),
35
+ transparent 100%)`,
36
+ });
37
+
38
+ export const wrapper = style({
39
+ width: 'max-content',
40
+ });
@@ -0,0 +1,6 @@
1
+ import { uiTest } from '../../tests/uiTest';
2
+ import { ScrollArea } from './ScrollArea';
3
+
4
+ describe('ScrollArea 컴포넌트', () => {
5
+ uiTest(ScrollArea, 'ScrollArea');
6
+ });
@@ -0,0 +1,68 @@
1
+ 'use client';
2
+
3
+ import { forwardRef, useEffect, useRef, useState } from 'react';
4
+
5
+ import { useCombinedRefs } from '@kimdw-rtk/utils';
6
+ import clsx from 'clsx';
7
+
8
+ import { useMouseScroll } from '#hooks/useMouseScroll';
9
+ import { sx } from '#styles';
10
+ import type { UIComponent } from '#types';
11
+
12
+ import * as s from './ScrollArea.css';
13
+
14
+ type ScrollAreaProps = UIComponent<'div'>;
15
+
16
+ export const ScrollArea = forwardRef<HTMLDivElement, ScrollAreaProps>(
17
+ ({ children, className, sx: propSx, ...props }, ref) => {
18
+ const scrollAreaRef = useRef<HTMLDivElement>(null);
19
+ const targetRef = useCombinedRefs(ref, scrollAreaRef);
20
+ const [hasLeftSpace, setHasLeftSpace] = useState<boolean>(false);
21
+ const [hasRightSpace, setHasRightSpace] = useState<boolean>(true);
22
+ useMouseScroll(scrollAreaRef);
23
+
24
+ useEffect(() => {
25
+ const element = scrollAreaRef.current;
26
+
27
+ if (element === null) {
28
+ return;
29
+ }
30
+
31
+ const handleScroll = () => {
32
+ setHasLeftSpace(element.scrollLeft !== 0);
33
+ setHasRightSpace(
34
+ Math.round(element.scrollLeft + element.clientWidth) <
35
+ element.scrollWidth,
36
+ );
37
+ };
38
+
39
+ handleScroll();
40
+
41
+ element.addEventListener('scroll', handleScroll);
42
+
43
+ return () => {
44
+ element.removeEventListener('scroll', handleScroll);
45
+ };
46
+ }, []);
47
+
48
+ return (
49
+ <div
50
+ ref={targetRef}
51
+ className={clsx(
52
+ s.scrollArea,
53
+ className,
54
+ sx(propSx),
55
+ hasLeftSpace && hasRightSpace && s.maskBoth,
56
+ hasLeftSpace && s.maskLeft,
57
+ hasRightSpace && s.maskRight,
58
+ )}
59
+ {...props}
60
+ >
61
+ <div className={s.wrapper}>{children}</div>
62
+ </div>
63
+ );
64
+ },
65
+ );
66
+ ScrollArea.displayName = 'ScrollArea';
67
+
68
+ export { s as scrollAreaCss };
@@ -0,0 +1 @@
1
+ export * from './ScrollArea';
@@ -0,0 +1,22 @@
1
+ import { recipeWithLayer } from '#styleUtils';
2
+ import { typography } from '#tokens';
3
+
4
+ export const select = recipeWithLayer({
5
+ base: {
6
+ position: 'relative',
7
+ },
8
+
9
+ variants: {
10
+ size: {
11
+ sm: {
12
+ fontSize: typography.size.sm,
13
+ },
14
+ md: {
15
+ fontSize: typography.size.md,
16
+ },
17
+ lg: {
18
+ fontSize: typography.size.lg,
19
+ },
20
+ },
21
+ },
22
+ });
@@ -0,0 +1,65 @@
1
+ import { fireEvent, render, screen } from '@testing-library/react';
2
+
3
+ import { Select, SelectOption } from '.';
4
+ import { uiTest } from '../../tests/uiTest';
5
+
6
+ describe('Select 컴포넌트', () => {
7
+ uiTest(Select, 'Select');
8
+
9
+ it('클릭한 option의 내용이 Select에 보인다.', () => {
10
+ render(
11
+ <Select data-testid="select">
12
+ <SelectOption value="1">1번</SelectOption>
13
+ <SelectOption value="2">2번</SelectOption>
14
+ </Select>,
15
+ );
16
+
17
+ const select = screen.getByTestId('select');
18
+
19
+ fireEvent.click(screen.getByText('2번'));
20
+ expect(select).toHaveTextContent('2번');
21
+ });
22
+
23
+ it('새로운 option을 클릭하면 onChange 이벤트가 발생하고, form value, ref.value의 값이 바뀐다.', () => {
24
+ const handleChange = jest.fn();
25
+
26
+ render(
27
+ <form data-testid="form">
28
+ <Select data-testid="select" name="select" onChange={handleChange}>
29
+ <SelectOption value="1">1번</SelectOption>
30
+ <SelectOption value="2">2번</SelectOption>
31
+ </Select>
32
+ </form>,
33
+ );
34
+
35
+ const option2 = screen.getByText('2번');
36
+ const form = screen.getByTestId('form') as HTMLFormElement;
37
+
38
+ fireEvent.click(option2);
39
+ expect(handleChange).toHaveBeenCalledTimes(1);
40
+ expect(handleChange.mock.calls[0][0]).toBe('2');
41
+ expect(new FormData(form).get('select')).toBe('2');
42
+
43
+ fireEvent.click(option2);
44
+ expect(handleChange).toHaveBeenCalledTimes(1);
45
+ expect(new FormData(form).get('select')).toBe('2');
46
+
47
+ fireEvent.click(screen.getByText('1번'));
48
+ expect(handleChange).toHaveBeenCalledTimes(2);
49
+ expect(handleChange.mock.calls[1][0]).toBe('1');
50
+ expect(new FormData(form).get('select')).toBe('1');
51
+ });
52
+
53
+ it('defaultValue의 값이 기본으로 보인다.', () => {
54
+ render(
55
+ <Select data-testid="select" defaultValue="2">
56
+ <SelectOption value="1">1번</SelectOption>
57
+ <SelectOption value="2">2번</SelectOption>
58
+ </Select>,
59
+ );
60
+
61
+ const select = screen.getByTestId('select');
62
+
63
+ expect(select).toHaveTextContent('2번');
64
+ });
65
+ });
@@ -0,0 +1,111 @@
1
+ 'use client';
2
+
3
+ import {
4
+ forwardRef,
5
+ useEffect,
6
+ useReducer,
7
+ useRef,
8
+ type ComponentProps,
9
+ type CSSProperties,
10
+ type RefObject,
11
+ } from 'react';
12
+
13
+ import { useCombinedRefs } from '@kimdw-rtk/utils';
14
+ import clsx from 'clsx';
15
+
16
+ import { sx } from '#styles';
17
+ import type { UIComponent } from '#types';
18
+
19
+ import * as s from './Select.css';
20
+ import { SelectContext, selectReducer } from './SelectContext';
21
+ import SelectOptionList from './SelectOptionList';
22
+ import SelectTrigger from './SelectTrigger';
23
+
24
+ interface SelectProps
25
+ extends Omit<UIComponent<'div', typeof s.select>, 'ref' | 'onChange'> {
26
+ ref?: RefObject<{ value?: string } | null>;
27
+ name?: string;
28
+ width?: CSSProperties['width'];
29
+ defaultValue?: string;
30
+ variant?: ComponentProps<typeof SelectTrigger>['variant'];
31
+ onChange?: (value: string | undefined) => void;
32
+ }
33
+
34
+ export const Select = forwardRef<HTMLDivElement, SelectProps>(
35
+ (
36
+ {
37
+ children,
38
+ className,
39
+ style,
40
+ name,
41
+ defaultValue,
42
+ width = '100%',
43
+ size = 'md',
44
+ sx: propSx,
45
+ variant = 'outlined',
46
+ onChange,
47
+ ...props
48
+ },
49
+ ref,
50
+ ) => {
51
+ const containerRef = useRef<HTMLDivElement>(null);
52
+ const targetRef = useCombinedRefs(ref, containerRef);
53
+ const [state, dispatch] = useReducer(selectReducer, {
54
+ isActive: false,
55
+ containerRef,
56
+ defaultValue,
57
+ items: new Map(),
58
+ });
59
+
60
+ useEffect(() => {
61
+ const container = containerRef.current;
62
+
63
+ if (!container) {
64
+ return;
65
+ }
66
+
67
+ const handleOutsideClick = (e: MouseEvent) => {
68
+ if (container.contains(e.target as Node) || !state.isActive) {
69
+ return;
70
+ }
71
+
72
+ dispatch({ type: 'TOGGLE' });
73
+ };
74
+
75
+ window.addEventListener('mousedown', handleOutsideClick);
76
+
77
+ return () => {
78
+ window.removeEventListener('mousedown', handleOutsideClick);
79
+ };
80
+ }, [state.isActive, dispatch]);
81
+
82
+ useEffect(() => {
83
+ if (!onChange || !state.items.size) {
84
+ return;
85
+ }
86
+
87
+ onChange(state.selected);
88
+ //eslint-disable-next-line
89
+ }, [state.selected]);
90
+
91
+ return (
92
+ <SelectContext.Provider value={{ state, dispatch }}>
93
+ <div
94
+ ref={targetRef}
95
+ style={{ ...style, width }}
96
+ className={clsx(s.select({ size }), className, sx(propSx))}
97
+ {...props}
98
+ >
99
+ <SelectTrigger variant={variant}>
100
+ {state.selected !== null && state.items.get(state.selected || '')}
101
+ </SelectTrigger>
102
+ <SelectOptionList>{children}</SelectOptionList>
103
+ <input type="hidden" name={name} value={state.selected || ''} />
104
+ </div>
105
+ </SelectContext.Provider>
106
+ );
107
+ },
108
+ );
109
+ Select.displayName = 'Select';
110
+
111
+ export { s as selectCss };