Skip to content

Commit 2f12b93

Browse files
authored
New documentation (#673)
1 parent 74030a8 commit 2f12b93

22 files changed

+1113
-17
lines changed

.changeset/proud-pugs-design.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cube-dev/ui-kit": minor
3+
---
4+
5+
Add `scrollbar` style deprecating `styledScrollbar` style.

.changeset/quiet-coats-lick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cube-dev/ui-kit": patch
3+
---
4+
5+
Add support for the `offset` value in the `outline` style.

.changeset/thin-penguins-exist.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cube-dev/ui-kit": patch
3+
---
4+
5+
Add support for default container props in `useDialogContainer`.

.size-limit.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = [
2727
path: './dist/es/index.js',
2828
webpack: true,
2929
import: '{ Button }',
30-
limit: '22 kB',
30+
limit: '23 kB',
3131
},
3232
{
3333
name: 'Tree shaking (just an Icon)',

src/components/overlays/Dialog/DialogTrigger.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ function PopoverTrigger(allProps) {
297297

298298
function DialogTriggerBase(props) {
299299
const ref = useCombinedRefs(props.ref);
300-
const isFirstRender = useIsFirstRender();
300+
const wasOpenRef = useRef(false);
301301

302302
let {
303303
type,
@@ -320,10 +320,13 @@ function DialogTriggerBase(props) {
320320

321321
// Restore focus manually when the dialog closes
322322
useEffect(() => {
323-
if (!state.isOpen && !isFirstRender) {
323+
if (!state.isOpen && wasOpenRef.current) {
324+
wasOpenRef.current = false;
324325
ref.current?.focus();
326+
} else if (state.isOpen) {
327+
wasOpenRef.current = true;
325328
}
326-
}, [state.isOpen, ref.current]);
329+
}, [state.isOpen]);
327330

328331
return (
329332
<Fragment>

src/components/overlays/Dialog/dialog-container.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from 'react';
88

99
import { useEvent } from '../../../_internal/index';
10+
import { mergeProps } from '../../../utils/react/index';
1011

1112
import { DialogContainer } from './DialogContainer';
1213

@@ -19,7 +20,10 @@ import { DialogContainer } from './DialogContainer';
1920
export function useDialogContainer<
2021
P,
2122
E = ComponentProps<typeof DialogContainer>,
22-
>(Component: ComponentType<P>) {
23+
>(
24+
Component: ComponentType<P>,
25+
defaultContainerProps?: ComponentProps<typeof DialogContainer>,
26+
) {
2327
const [isOpen, setIsOpen] = useState(false);
2428
const [componentProps, setComponentProps] = useState<P | null>(null);
2529
const [containerProps, setContainerProps] = useState<E | null>(null);
@@ -63,7 +67,7 @@ export function useDialogContainer<
6367
onDismiss={close}
6468
{...(containerProps ?? {})}
6569
>
66-
<Component {...componentProps} />
70+
<Component {...mergeProps(defaultContainerProps, componentProps)} />
6771
</DialogContainer>
6872
);
6973
}, [componentProps, containerProps, isOpen]);

src/tasty/styles.test.ts

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
import { borderStyle } from './styles/border';
2+
import { flowStyle } from './styles/flow';
3+
import { gapStyle } from './styles/gap';
4+
import { insetStyle } from './styles/inset';
5+
import { marginStyle } from './styles/margin';
6+
import { outlineStyle } from './styles/outline';
7+
import { paddingStyle } from './styles/padding';
8+
import { presetStyle } from './styles/preset';
9+
import { radiusStyle } from './styles/radius';
10+
import { scrollbarStyle } from './styles/scrollbar';
11+
12+
describe('Tasty style tests', () => {
13+
it('should handle border styles', () => {
14+
expect(borderStyle({ border: '1px solid #000' })).toEqual({
15+
border: '1px solid var(--000-color, rgb(0 0 0))',
16+
});
17+
});
18+
19+
it('should handle outline styles', () => {
20+
expect(outlineStyle({ outline: '2px dashed #f00' })).toEqual({
21+
outline: '2px dashed var(--f00-color, rgb(255 0 0))',
22+
});
23+
});
24+
25+
it('should handle padding styles', () => {
26+
expect(
27+
paddingStyle({
28+
padding: '10px',
29+
}),
30+
).toEqual({
31+
'padding-top': '10px',
32+
'padding-right': '10px',
33+
'padding-bottom': '10px',
34+
'padding-left': '10px',
35+
});
36+
});
37+
38+
it('should handle margin styles', () => {
39+
expect(
40+
marginStyle({
41+
margin: '5px',
42+
}),
43+
).toEqual({
44+
'margin-top': '5px',
45+
'margin-right': '5px',
46+
'margin-bottom': '5px',
47+
'margin-left': '5px',
48+
});
49+
});
50+
51+
it('should handle inset styles', () => {
52+
expect(insetStyle({ inset: '0 10px 20px 30px' })).toEqual({
53+
top: '0',
54+
right: '10px',
55+
bottom: '20px',
56+
left: '30px',
57+
});
58+
});
59+
60+
it('should handle radius styles', () => {
61+
expect(radiusStyle({ radius: '50%' })).toEqual([
62+
{ '--local-radius': '50%', 'border-radius': 'var(--local-radius)' },
63+
{ $: '>*', '--context-radius': '50%' },
64+
]);
65+
});
66+
67+
it('should handle preset styles', () => {
68+
expect(
69+
presetStyle({
70+
preset: 't3',
71+
}),
72+
).toEqual({
73+
'--font-size': 'var(--t3-font-size, var(--default-font-size, inherit))',
74+
'--font-style':
75+
'var(--t3-font-style, var(--default-font-style, inherit))',
76+
'--font-weight':
77+
'var(--t3-font-weight, var(--default-font-weight, inherit))',
78+
'--letter-spacing':
79+
'var(--t3-letter-spacing, var(--default-letter-spacing, inherit))',
80+
'--line-height':
81+
'var(--t3-line-height, var(--default-line-height, inherit))',
82+
'--bold-font-weight':
83+
'var(--t3-bold-font-weight, var(--default-bold-font-weight, inherit))',
84+
'--font-family':
85+
'var(--t3-font-family, var(--default-font-family, var(--font, NonexistentFontName))), var(--font, sans-serif)',
86+
'--icon-size': 'var(--t3-icon-size, var(--default-icon-size, inherit))',
87+
'--text-transform':
88+
'var(--t3-text-transform, var(--default-text-transform, inherit))',
89+
'font-size': 'var(--t3-font-size, var(--default-font-size, inherit))',
90+
'font-style': 'var(--t3-font-style, var(--default-font-style, inherit))',
91+
'font-weight':
92+
'var(--t3-font-weight, var(--default-font-weight, inherit))',
93+
'letter-spacing':
94+
'var(--t3-letter-spacing, var(--default-letter-spacing, inherit))',
95+
'line-height':
96+
'var(--t3-line-height, var(--default-line-height, inherit))',
97+
'font-family':
98+
'var(--t3-font-family, var(--default-font-family, var(--font, NonexistentFontName))), var(--font, sans-serif)',
99+
'text-transform':
100+
'var(--t3-text-transform, var(--default-text-transform, inherit))',
101+
});
102+
});
103+
104+
it('should handle flow styles', () => {
105+
expect(flowStyle({ flow: 'row nowrap' })).toEqual(null);
106+
});
107+
108+
it('should handle gap styles', () => {
109+
expect(
110+
gapStyle({
111+
gap: '1rem',
112+
}),
113+
).toEqual({
114+
$: '& > *:not(:last-child)',
115+
'margin-bottom': '1rem',
116+
});
117+
});
118+
119+
it('should return undefined for undefined scrollbar', () => {
120+
expect(scrollbarStyle({})).toBeUndefined();
121+
});
122+
123+
it('should return correct styles for two colors', () => {
124+
expect(scrollbarStyle({ scrollbar: '#dark #clear' })).toEqual({
125+
'scrollbar-color': 'var(--dark-color) var(--clear-color)',
126+
'&::-webkit-scrollbar-corner': {
127+
background: 'var(--clear-color)',
128+
},
129+
});
130+
});
131+
132+
it('should return correct styles for `thin` scrollbar', () => {
133+
expect(scrollbarStyle({ scrollbar: 'thin' })).toEqual({
134+
'scrollbar-width': 'thin',
135+
'scrollbar-color': 'var(--scrollbar-thumb-color) transparent',
136+
});
137+
});
138+
139+
it('should return correct styles for `none` scrollbar', () => {
140+
expect(scrollbarStyle({ scrollbar: 'none' })).toEqual({
141+
'scrollbar-color': 'var(--scrollbar-thumb-color) transparent',
142+
'&::-webkit-scrollbar': {
143+
width: 'none',
144+
height: 'none',
145+
},
146+
});
147+
});
148+
149+
it('should handle custom overflow with scrollbar', () => {
150+
expect(scrollbarStyle({ scrollbar: 'always', overflow: 'scroll' })).toEqual(
151+
{
152+
overflow: 'scroll',
153+
'scrollbar-gutter': 'always',
154+
'scrollbar-color': 'var(--scrollbar-thumb-color) transparent',
155+
},
156+
);
157+
});
158+
159+
it('should handle styled scrollbar', () => {
160+
expect(scrollbarStyle({ scrollbar: 'styled' })).toEqual({
161+
'scrollbar-width': 'thin',
162+
'scrollbar-color': 'var(--scrollbar-thumb-color) transparent',
163+
'&::-webkit-scrollbar': {
164+
width: '8px',
165+
height: '8px',
166+
background: 'var(--scrollbar-track-color)',
167+
transition:
168+
'background var(--transition), border-radius var(--transition), box-shadow var(--transition), width var(--transition), height var(--transition), border var(--transition)',
169+
},
170+
'&::-webkit-scrollbar-thumb': {
171+
background: 'var(--scrollbar-thumb-color)',
172+
borderRadius: '8px',
173+
minHeight: '24px',
174+
transition:
175+
'background var(--transition), border-radius var(--transition), box-shadow var(--transition), width var(--transition), height var(--transition), border var(--transition)',
176+
},
177+
'&::-webkit-scrollbar-corner': {
178+
background: 'var(--scrollbar-track-color)',
179+
transition:
180+
'background var(--transition), border-radius var(--transition), box-shadow var(--transition), width var(--transition), height var(--transition), border var(--transition)',
181+
},
182+
});
183+
});
184+
});

src/tasty/styles/border.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ export function borderStyle({ border }) {
2323

2424
if (border === true) border = '1bw';
2525

26-
const { values, mods, color } = parseStyle(String(border));
26+
const { values, mods, colors } = parseStyle(String(border));
2727

2828
const directions = filterMods(mods, DIRECTIONS);
2929
const typeMods = filterMods(mods, BORDER_STYLES);
3030

3131
const value = values[0] || 'var(--border-width)';
3232
const type = typeMods[0] || 'solid';
33-
const borderColor = color || 'var(--border-color)';
33+
const borderColor = (colors && colors[0]) || 'var(--border-color)';
3434

3535
const styleValue = [value, type, borderColor].join(' ');
3636

src/tasty/styles/color.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export function colorStyle({ color }) {
55

66
if (color === true) color = 'currentColor';
77

8-
if (color.startsWith('#')) {
8+
if (typeof color === 'string' && color.startsWith('#')) {
99
color = parseColor(color).color || color;
1010
}
1111

src/tasty/styles/fill.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export function fillStyle({ fill }) {
44
if (!fill) return '';
55

66
if (fill.startsWith('#')) {
7-
fill = parseStyle(fill).color || fill;
7+
fill = parseStyle(fill).colors[0] || fill;
88
}
99

1010
const match = fill.match(/var\(--(.+?)-color/);

src/tasty/styles/gap.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { parseStyle } from '../utils/styles';
22

3-
export function gapStyle({ display = 'block', flow, gap }) {
3+
export function gapStyle({
4+
display = 'block',
5+
flow,
6+
gap,
7+
}: {
8+
display?: string;
9+
flow?: string;
10+
gap?: string | number | boolean;
11+
}) {
412
if (typeof gap === 'number') {
513
gap = `${gap}px`;
614
}
@@ -31,7 +39,7 @@ export function gapStyle({ display = 'block', flow, gap }) {
3139
return { gap };
3240
}
3341

34-
const gapDir = flow.includes('row') ? 'right' : 'bottom';
42+
const gapDir = flow?.includes('row') ? 'right' : 'bottom';
3543

3644
return isWrap
3745
? [

src/tasty/styles/margin.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ export function marginStyle({
88
marginRight,
99
marginBottom,
1010
marginLeft,
11+
}: {
12+
margin?: string | number | boolean;
13+
marginBlock?: string;
14+
marginInline?: string;
15+
marginTop?: string;
16+
marginRight?: string;
17+
marginBottom?: string;
18+
marginLeft?: string;
1119
}) {
1220
if (typeof margin === 'number') {
1321
margin = `${margin}px`;

src/tasty/styles/outline.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,23 @@ export function outlineStyle({ outline }) {
2323

2424
if (outline === true) outline = '1ow';
2525

26-
const { values, mods, color } = parseStyle(String(outline));
26+
const { values, mods, colors } = parseStyle(String(outline));
2727

2828
const typeMods = filterMods(mods, BORDER_STYLES);
2929

3030
const value = values[0] || 'var(--outline-width)';
3131
const type = typeMods[0] || 'solid';
32-
const outlineColor = color || 'var(--outline-color)';
32+
const outlineColor = colors?.[0] || 'var(--outline-color)';
3333

3434
const styleValue = [value, type, outlineColor].join(' ');
3535

36+
if (values.length > 1) {
37+
return {
38+
outline: styleValue,
39+
'outline-offset': values[1],
40+
};
41+
}
42+
3643
return { outline: styleValue };
3744
}
3845

src/tasty/styles/padding.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,24 @@ export function paddingStyle({
88
paddingRight,
99
paddingBottom,
1010
paddingLeft,
11+
}: {
12+
padding?: string | number | boolean | string[];
13+
paddingBlock?: string;
14+
paddingInline?: string;
15+
paddingTop?: string;
16+
paddingRight?: string;
17+
paddingBottom?: string;
18+
paddingLeft?: string;
1119
}) {
20+
if (Array.isArray(padding)) {
21+
return {
22+
'padding-top': padding[0],
23+
'padding-right': padding[1] || padding[0],
24+
'padding-bottom': padding[2] || padding[0],
25+
'padding-left': padding[3] || padding[1] || padding[0],
26+
};
27+
}
28+
1229
if (typeof padding === 'number') {
1330
padding = `${padding}px`;
1431
}

0 commit comments

Comments
 (0)