@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,59 @@
1
+ import { createContext, type Dispatch, type ReactNode } from 'react';
2
+
3
+ type SelectState = {
4
+ isActive: boolean;
5
+ selected?: string;
6
+ defaultValue?: string;
7
+ items: Map<string, ReactNode>;
8
+ containerRef: React.RefObject<HTMLDivElement | null>;
9
+ };
10
+
11
+ type SelectAction =
12
+ | { type: 'ADD'; payload: { value: string; children: ReactNode } }
13
+ | { type: 'REMOVE'; payload: { value: string } }
14
+ | { type: 'SELECT'; payload: { value: string } }
15
+ | { type: 'TOGGLE' };
16
+
17
+ export const SelectContext = createContext<
18
+ { state: SelectState; dispatch: Dispatch<SelectAction> } | undefined
19
+ >(undefined);
20
+
21
+ export const selectReducer = (
22
+ state: SelectState,
23
+ action: SelectAction,
24
+ ): SelectState => {
25
+ switch (action.type) {
26
+ case 'ADD': {
27
+ // 현재 selected가 없고, defaultValue === payload.value일 경우 select함.
28
+ if (
29
+ state.selected === undefined &&
30
+ state.defaultValue === action.payload.value
31
+ ) {
32
+ return {
33
+ ...state,
34
+ selected: action.payload.value,
35
+ items: new Map(state.items).set(
36
+ action.payload.value,
37
+ action.payload.children,
38
+ ),
39
+ };
40
+ }
41
+ return {
42
+ ...state,
43
+ items: new Map(state.items).set(
44
+ action.payload.value,
45
+ action.payload.children,
46
+ ),
47
+ };
48
+ }
49
+ case 'REMOVE': {
50
+ const newMap = new Map(state.items);
51
+ newMap.delete(action.payload.value);
52
+ return { ...state, items: newMap };
53
+ }
54
+ case 'SELECT':
55
+ return { ...state, isActive: false, selected: action.payload.value };
56
+ case 'TOGGLE':
57
+ return { ...state, isActive: !state.isActive };
58
+ }
59
+ };
@@ -0,0 +1,14 @@
1
+ import { styleWithLayer } from '#styleUtils';
2
+ import { theme } from '#themes';
3
+
4
+ export const selectOption = styleWithLayer({
5
+ padding: '0.75em 0.5em',
6
+
7
+ transition: 'background-color 0.2s ease',
8
+
9
+ cursor: 'default',
10
+
11
+ ':hover': {
12
+ backgroundColor: `rgb(${theme.color.accent})`,
13
+ },
14
+ });
@@ -0,0 +1,40 @@
1
+ 'use client';
2
+
3
+ import { useContext, useEffect, type ReactNode } from 'react';
4
+
5
+ import { SelectContext } from './SelectContext';
6
+ import * as s from './SelectOption.css';
7
+
8
+ interface SelectOptionProps {
9
+ children: ReactNode;
10
+ value: string;
11
+ }
12
+
13
+ export const SelectOption = ({ children, value }: SelectOptionProps) => {
14
+ const selectContext = useContext(SelectContext);
15
+
16
+ if (!selectContext) {
17
+ throw new Error('SelectOption must be rendered within a Select.');
18
+ }
19
+
20
+ const { dispatch } = selectContext;
21
+
22
+ useEffect(() => {
23
+ dispatch({ type: 'ADD', payload: { value, children } });
24
+
25
+ return () => {
26
+ dispatch({ type: 'REMOVE', payload: { value } });
27
+ };
28
+ // eslint-disable-next-line
29
+ }, [dispatch, value]);
30
+
31
+ const handleClick = () => {
32
+ dispatch({ type: 'SELECT', payload: { value } });
33
+ };
34
+
35
+ return (
36
+ <div className={s.selectOption} onClick={handleClick}>
37
+ {children}
38
+ </div>
39
+ );
40
+ };
@@ -0,0 +1,68 @@
1
+ import { keyframes } from '@vanilla-extract/css';
2
+
3
+ import { recipeWithLayer } from '#styleUtils';
4
+ import { theme } from '#themes';
5
+
6
+ const fadeIn = keyframes({
7
+ '0%': {
8
+ transform: 'scale(0.95)',
9
+ opacity: 0,
10
+ },
11
+
12
+ '100%': {
13
+ transform: 'scale(1)',
14
+ opacity: 1,
15
+ },
16
+ });
17
+
18
+ export const container = recipeWithLayer({
19
+ base: {
20
+ overflowY: 'auto',
21
+ position: 'absolute',
22
+ zIndex: '10',
23
+
24
+ width: '100%',
25
+ minWidth: 'max-content',
26
+ border: `1px solid rgb(${theme.color.border})`,
27
+ borderRadius: theme.borderRadius,
28
+ margin: '0.5rem 0',
29
+
30
+ backgroundColor: `rgb(${theme.color.background})`,
31
+
32
+ animation: `${fadeIn} 0.3s ease 1`,
33
+ transformOrigin: '0 0',
34
+
35
+ userSelect: 'none',
36
+
37
+ '::-webkit-scrollbar': {
38
+ width: '0.25rem',
39
+ height: '0.25rem',
40
+ },
41
+
42
+ '::-webkit-scrollbar-thumb': {
43
+ borderRadius: '0.5rem',
44
+
45
+ backgroundColor: `rgb(${theme.color['muted-foreground']})`,
46
+ },
47
+ },
48
+
49
+ variants: {
50
+ isVisible: {
51
+ true: {
52
+ display: 'block',
53
+ },
54
+ false: {
55
+ display: 'none',
56
+ },
57
+ },
58
+
59
+ isAbove: {
60
+ true: {
61
+ top: '100%',
62
+ },
63
+ false: {
64
+ bottom: '100%',
65
+ },
66
+ },
67
+ },
68
+ });
@@ -0,0 +1,59 @@
1
+ import { useContext, useMemo, useRef, type ReactNode } from 'react';
2
+
3
+ import clsx from 'clsx';
4
+
5
+ import { sprinkles } from '#styles';
6
+
7
+ import { SelectContext } from './SelectContext';
8
+ import * as s from './SelectOptionList.css';
9
+
10
+ interface SelectOptionListProps {
11
+ children: ReactNode;
12
+ }
13
+
14
+ const SelectOptionList = ({ children }: SelectOptionListProps) => {
15
+ const selectContext = useContext(SelectContext);
16
+ const containerRef = useRef<HTMLDivElement>(null);
17
+
18
+ if (!selectContext) {
19
+ throw new Error('SelectOption must be rendered within a Select.');
20
+ }
21
+
22
+ const { state } = selectContext;
23
+
24
+ const isAbove = useMemo(() => {
25
+ const container = containerRef.current;
26
+ const parent = state.containerRef.current;
27
+
28
+ if (!state.isActive || !container || !parent) {
29
+ return;
30
+ }
31
+
32
+ const parentRect = parent.getBoundingClientRect();
33
+ container.style.display = 'block';
34
+ const containerRect = container.getBoundingClientRect();
35
+ container.style.display = '';
36
+
37
+ // 하단에 리스트를 모두 보여줄 공간이 충분한 경우
38
+ if (containerRect.top + containerRect.height < window.innerHeight) {
39
+ return true;
40
+ }
41
+
42
+ // 그렇지 않으면 parent의 상단/하단 중 공간이 더 넓은 쪽으로 리스트를 보여줌
43
+ return parentRect.top + parentRect.height / 2 < window.innerHeight / 2;
44
+ }, [state.isActive, state.containerRef]);
45
+
46
+ return (
47
+ <div
48
+ ref={containerRef}
49
+ className={clsx(
50
+ s.container({ isVisible: state.isActive, isAbove }),
51
+ sprinkles({ boxShadow: 'accent-sm' }),
52
+ )}
53
+ >
54
+ {children}
55
+ </div>
56
+ );
57
+ };
58
+
59
+ export default SelectOptionList;
@@ -0,0 +1,73 @@
1
+ import { style } from '@vanilla-extract/css';
2
+ import { recipe } from '@vanilla-extract/recipes';
3
+
4
+ import { theme } from '#themes';
5
+
6
+ export const children = style({
7
+ overflow: 'hidden',
8
+ textOverflow: 'ellipsis',
9
+ whiteSpace: 'nowrap',
10
+ });
11
+
12
+ export const icon = recipe({
13
+ base: {
14
+ flexShrink: '0',
15
+
16
+ lineHeight: '0',
17
+
18
+ transition: 'color 0.2s ease, transform 0.2s ease',
19
+ },
20
+
21
+ variants: {
22
+ isActive: {
23
+ false: {
24
+ transform: 'rotate(0)',
25
+ },
26
+ true: {
27
+ color: `rgb(${theme.color.primary})`,
28
+
29
+ transform: 'rotate(-180deg)',
30
+ },
31
+ },
32
+ },
33
+ });
34
+
35
+ export const selectTrigger = recipe({
36
+ base: {
37
+ display: 'flex',
38
+ alignItems: 'center',
39
+ gap: '0.5em',
40
+ justifyContent: 'space-between',
41
+
42
+ width: '100%',
43
+
44
+ transition: 'border-color 0.2s ease',
45
+
46
+ cursor: 'pointer',
47
+ userSelect: 'none',
48
+ },
49
+
50
+ variants: {
51
+ isActive: {
52
+ true: {
53
+ borderColor: `rgb(${theme.color.primary})`,
54
+ },
55
+ },
56
+ variant: {
57
+ contained: {
58
+ padding: '0.75em 0.75em',
59
+ borderRadius: theme.borderRadius,
60
+
61
+ backgroundColor: `rgb(${theme.color.secondary})`,
62
+ },
63
+ outlined: {
64
+ padding: '0.75em 0.5em',
65
+ border: '1px solid',
66
+ borderColor: `rgb(${theme.color.border})`,
67
+ borderRadius: theme.borderRadius,
68
+
69
+ backgroundColor: `rgb(${theme.color.background})`,
70
+ },
71
+ },
72
+ },
73
+ });
@@ -0,0 +1,49 @@
1
+ import { useContext } from 'react';
2
+
3
+ import clsx from 'clsx';
4
+ import { ChevronDownIcon } from 'lucide-react';
5
+
6
+ import { sx } from '#styles';
7
+ import type { UIComponent } from '#types';
8
+
9
+ import { SelectContext } from './SelectContext';
10
+ import * as s from './SelectTrigger.css';
11
+
12
+ type SelectTriggerProps = UIComponent<'div', typeof s.selectTrigger>;
13
+
14
+ const SelectTrigger = ({
15
+ children,
16
+ className,
17
+ variant,
18
+ sx: propSx,
19
+ }: SelectTriggerProps) => {
20
+ const selectContext = useContext(SelectContext);
21
+
22
+ if (!selectContext) {
23
+ throw new Error('SelectTrigger must be rendered within a Select.');
24
+ }
25
+
26
+ const { state, dispatch } = selectContext;
27
+
28
+ const handleClick = () => {
29
+ dispatch({ type: 'TOGGLE' });
30
+ };
31
+
32
+ return (
33
+ <div
34
+ className={clsx(
35
+ s.selectTrigger({ isActive: state.isActive, variant }),
36
+ className,
37
+ sx(propSx),
38
+ )}
39
+ onClick={handleClick}
40
+ >
41
+ <span className={s.children}>{children}</span>
42
+ <span className={s.icon({ isActive: state.isActive })}>
43
+ <ChevronDownIcon size="1em" strokeWidth="2px" />
44
+ </span>
45
+ </div>
46
+ );
47
+ };
48
+
49
+ export default SelectTrigger;
@@ -0,0 +1,2 @@
1
+ export * from './Select';
2
+ export * from './SelectOption';
@@ -0,0 +1,26 @@
1
+ import { keyframes } from '@vanilla-extract/css';
2
+
3
+ import { styleWithLayer } from '#styleUtils';
4
+ import { theme } from '#themes';
5
+
6
+ const shimmer = keyframes({
7
+ '0%': {
8
+ backgroundPosition: '-300% 0',
9
+ },
10
+
11
+ '100%': {
12
+ backgroundPosition: '300% 0',
13
+ },
14
+ });
15
+
16
+ export const skeleton = styleWithLayer({
17
+ display: 'block',
18
+
19
+ maxWidth: '100%',
20
+ borderRadius: theme.borderRadius,
21
+
22
+ background: `linear-gradient(90deg, rgba(${theme.color.accent}, 0.4) 30%, rgba(${theme.color.accent}, 0.2) 65%, rgba(${theme.color.accent}, 0.4))`,
23
+ backgroundSize: '300% 100%',
24
+
25
+ animation: `${shimmer} 5s linear 0s infinite`,
26
+ });
@@ -0,0 +1,6 @@
1
+ import { Skeleton } from '.';
2
+ import { uiTest } from '../../tests/uiTest';
3
+
4
+ describe('Skeleton 컴포넌트', () => {
5
+ uiTest(Skeleton, 'Skeleton');
6
+ });
@@ -0,0 +1,27 @@
1
+ import { forwardRef, type CSSProperties } 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 './Skeleton.css';
9
+
10
+ interface SkeletonProps extends UIComponent<'div'> {
11
+ width?: CSSProperties['width'];
12
+ height?: CSSProperties['height'];
13
+ }
14
+
15
+ export const Skeleton = forwardRef<HTMLDivElement, SkeletonProps>(
16
+ ({ className, width, height, style, sx: propSx, ...props }, ref) => {
17
+ return (
18
+ <div
19
+ ref={ref}
20
+ className={clsx(s.skeleton, className, sx(propSx))}
21
+ style={{ ...style, width, height }}
22
+ {...props}
23
+ />
24
+ );
25
+ },
26
+ );
27
+ Skeleton.displayName = 'Skeleton';
@@ -0,0 +1,10 @@
1
+ import { styleWithLayer } from '#styleUtils';
2
+
3
+ export const table = styleWithLayer({
4
+ width: '100%',
5
+
6
+ tableLayout: 'fixed',
7
+ borderSpacing: '0',
8
+ });
9
+
10
+ export const striped = styleWithLayer({});
@@ -0,0 +1,12 @@
1
+ import { Table } from '#components';
2
+
3
+ import { uiTest } from '../../tests/uiTest';
4
+
5
+ describe('Table 컴포넌트', () => {
6
+ uiTest(Table, 'Table');
7
+ // uiTest(TableBody, 'TableBody');
8
+ // uiTest(TableCell, 'TableCell');
9
+ // uiTest(TableHead, 'TableHead');
10
+ // uiTest(TableHeader, 'TableHeader');
11
+ // uiTest(TableRow, 'TableRow');
12
+ });
@@ -0,0 +1,27 @@
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 './Table.css';
9
+
10
+ interface TableProps extends UIComponent<'table'> {
11
+ isStriped?: boolean;
12
+ }
13
+
14
+ export const Table = forwardRef<HTMLTableElement, TableProps>(
15
+ ({ isStriped, className, sx: propSx, ...props }, ref) => {
16
+ return (
17
+ <table
18
+ ref={ref}
19
+ className={clsx(s.table, isStriped && s.striped, sx(propSx), className)}
20
+ {...props}
21
+ />
22
+ );
23
+ },
24
+ );
25
+ Table.displayName = 'Table';
26
+
27
+ export { s as tableCss };
@@ -0,0 +1,14 @@
1
+ import clsx from 'clsx';
2
+
3
+ import { sx } from '#styles';
4
+ import type { UIComponent } from '#types';
5
+
6
+ type TableBodyProps = UIComponent<'tbody'>;
7
+
8
+ export const TableBody = ({
9
+ className,
10
+ sx: propSx,
11
+ ...props
12
+ }: TableBodyProps) => {
13
+ return <tbody className={clsx(className, sx(propSx))} {...props} />;
14
+ };
@@ -0,0 +1,43 @@
1
+ import { styleWithLayer } from '#styleUtils';
2
+ import { theme } from '#themes';
3
+
4
+ import { striped } from './Table.css';
5
+ import { interactive } from './TableRow.css';
6
+
7
+ export const tableCell = styleWithLayer({
8
+ padding: '0.5em',
9
+
10
+ transition: 'background-color 0.1s ease, color 0.1s ease',
11
+
12
+ selectors: {
13
+ [`${interactive} > &`]: {
14
+ cursor: 'pointer',
15
+ },
16
+
17
+ 'tr > &:first-child': {
18
+ borderTopLeftRadius: theme.borderRadius,
19
+ borderBottomLeftRadius: theme.borderRadius,
20
+ },
21
+
22
+ 'tr > &:last-child': {
23
+ borderTopRightRadius: theme.borderRadius,
24
+ borderBottomRightRadius: theme.borderRadius,
25
+ },
26
+
27
+ 'tbody > tr:hover > &': {
28
+ backgroundColor: `rgb(${theme.color.accent})`,
29
+
30
+ color: `rgb(${theme.color['accent-foreground']})`,
31
+ },
32
+
33
+ [`${striped} > tbody > tr:nth-of-type(odd) > &`]: {
34
+ backgroundColor: `rgb(${theme.color.card})`,
35
+
36
+ color: `rgb(${theme.color['accent-foreground']})`,
37
+ },
38
+
39
+ [`${striped} > tbody > tr:nth-of-type(odd):hover > &`]: {
40
+ backgroundColor: `rgb(${theme.color.accent})`,
41
+ },
42
+ },
43
+ });
@@ -0,0 +1,30 @@
1
+ import { type CSSProperties } 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 './TableCell.css';
9
+
10
+ interface TableCellProps extends UIComponent<'td'> {
11
+ width?: CSSProperties['width'];
12
+ textAlign?: CSSProperties['textAlign'];
13
+ }
14
+
15
+ export const TableCell = ({
16
+ width,
17
+ textAlign,
18
+ style,
19
+ className,
20
+ sx: propSx,
21
+ ...props
22
+ }: TableCellProps) => {
23
+ return (
24
+ <td
25
+ style={{ ...style, width, textAlign }}
26
+ className={clsx(s.tableCell, className, sx(propSx))}
27
+ {...props}
28
+ />
29
+ );
30
+ };
@@ -0,0 +1,10 @@
1
+ import { styleWithLayer } from '#styleUtils';
2
+ import { theme } from '#themes';
3
+
4
+ export const tableHead = styleWithLayer({
5
+ padding: '0.5em 0.625em',
6
+
7
+ color: `rgb(${theme.color['accent-foreground']})`,
8
+ fontSize: '0.9375em',
9
+ fontWeight: '500',
10
+ });
@@ -0,0 +1,30 @@
1
+ import { type CSSProperties } 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 './TableHead.css';
9
+
10
+ interface TableHeadProps extends UIComponent<'th'> {
11
+ width?: CSSProperties['width'];
12
+ textAlign?: CSSProperties['textAlign'];
13
+ }
14
+
15
+ export const TableHead = ({
16
+ width,
17
+ textAlign,
18
+ style,
19
+ className,
20
+ sx: propSx,
21
+ ...props
22
+ }: TableHeadProps) => {
23
+ return (
24
+ <th
25
+ style={{ ...style, width, textAlign }}
26
+ className={clsx(s.tableHead, className, sx(propSx))}
27
+ {...props}
28
+ />
29
+ );
30
+ };
@@ -0,0 +1,14 @@
1
+ import clsx from 'clsx';
2
+
3
+ import { sx } from '#styles';
4
+ import type { UIComponent } from '#types';
5
+
6
+ type TableHeaderProps = UIComponent<'thead'>;
7
+
8
+ export const TableHeader = ({
9
+ className,
10
+ sx: propSx,
11
+ ...props
12
+ }: TableHeaderProps) => {
13
+ return <thead className={clsx(className, sx(propSx))} {...props} />;
14
+ };
@@ -0,0 +1,3 @@
1
+ import { styleWithLayer } from '#styleUtils';
2
+
3
+ export const interactive = styleWithLayer({});
@@ -0,0 +1,24 @@
1
+ import clsx from 'clsx';
2
+
3
+ import { sx } from '#styles';
4
+ import type { UIComponent } from '#types';
5
+
6
+ import * as s from './TableRow.css';
7
+
8
+ interface TableRowProps extends UIComponent<'tr'> {
9
+ isInteractive?: boolean;
10
+ }
11
+
12
+ export const TableRow = ({
13
+ isInteractive = false,
14
+ className,
15
+ sx: propSx,
16
+ ...props
17
+ }: TableRowProps) => {
18
+ return (
19
+ <tr
20
+ className={clsx(isInteractive && s.interactive, className, sx(propSx))}
21
+ {...props}
22
+ />
23
+ );
24
+ };
@@ -0,0 +1,6 @@
1
+ export * from './Table';
2
+ export * from './TableBody';
3
+ export * from './TableCell';
4
+ export * from './TableHead';
5
+ export * from './TableHeader';
6
+ export * from './TableRow';