Skip to content

Commit c7abb00

Browse files
authored
fix(react): refine component behavior and themed demos (#99)
* fix: update select component * chore: update docs * chore: update docs * chore: docs * chore: add changeset for react component fixes
1 parent 3e7997b commit c7abb00

28 files changed

Lines changed: 405 additions & 97 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tiny-design/react": patch
3+
---
4+
5+
Fix React component behavior and update demos to follow theme tokens.

apps/docs/src/containers/theme-studio/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ const ThemeStudioPage = (): React.ReactElement => {
156156
<Select
157157
className="theme-studio__select"
158158
value={draft.presetId}
159+
showSearch
160+
filterOption={(inputValue, option) => {
161+
const query = inputValue.toLowerCase();
162+
const label = typeof option.label === 'string' ? option.label : '';
163+
return label.toLowerCase().includes(query) || option.value.toLowerCase().includes(query);
164+
}}
159165
onChange={(value) => handlePresetChange(value)}
160166
>
161167
{THEME_EDITOR_PRESETS.map((preset) => (

apps/docs/src/containers/theme-studio/preview-components.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ const subscriptionsChartConfig: ChartConfig = {
130130
},
131131
};
132132

133+
const currYear = new Date().getFullYear()
134+
const currMonth = new Date().getMonth()
135+
133136
function MetricsStrip({
134137
items = [
135138
['Total Revenue', '$15,231.89', '+20.1% from last month'],
@@ -386,7 +389,7 @@ function CardsPreview(): React.ReactElement {
386389
<div className="theme-studio__cards-bottom-pair">
387390
<Card className="theme-studio__cards-panel theme-studio__cards-panel_calendar">
388391
<Card.Content>
389-
<Calendar value={new Date(2025, 5, 6)} fullscreen={false} />
392+
<Calendar selectionMode="range" defaultRangeValue={[new Date(currYear, currMonth, 5), new Date(currYear, currMonth, 15)]} fullscreen={false} />
390393
</Card.Content>
391394
</Card>
392395

apps/docs/src/containers/theme-studio/runtime-presets.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ function buildPresetDescription(source: TweakcnRuntimePresetSource): string {
1818
: 'Imported from tweakcn runtime preset.';
1919
}
2020

21-
function mapRuntimeStylesToFields(styles: RuntimeStyles): Partial<ThemeEditorFields> {
21+
function readRuntimeStyle(styles: RuntimeStyles, key: string, fallbackStyles?: RuntimeStyles): string | undefined {
22+
return styles[key] ?? fallbackStyles?.[key];
23+
}
24+
25+
function mapRuntimeStylesToFields(
26+
styles: RuntimeStyles,
27+
typographyFallbackStyles?: RuntimeStyles,
28+
): Partial<ThemeEditorFields> {
2229
const radius = styles.radius ?? DEFAULT_FIELDS.radius;
2330
const ring = styles.ring ?? styles.primary ?? DEFAULT_FIELDS.ring;
2431
const statusPalette = deriveStatusPalette(styles);
@@ -62,9 +69,9 @@ function mapRuntimeStylesToFields(styles: RuntimeStyles): Partial<ThemeEditorFie
6269
sidebarAccentForeground: styles['sidebar-accent-foreground'] ?? DEFAULT_FIELDS.sidebarAccentForeground,
6370
sidebarBorder: styles['sidebar-border'] ?? DEFAULT_FIELDS.sidebarBorder,
6471
sidebarRing: styles['sidebar-ring'] ?? DEFAULT_FIELDS.sidebarRing,
65-
fontSans: styles['font-sans'] ?? DEFAULT_FIELDS.fontSans,
66-
fontMono: styles['font-mono'] ?? DEFAULT_FIELDS.fontMono,
67-
letterSpacing: styles['letter-spacing'] ?? DEFAULT_FIELDS.letterSpacing,
72+
fontSans: readRuntimeStyle(styles, 'font-sans', typographyFallbackStyles) ?? DEFAULT_FIELDS.fontSans,
73+
fontMono: readRuntimeStyle(styles, 'font-mono', typographyFallbackStyles) ?? DEFAULT_FIELDS.fontMono,
74+
letterSpacing: readRuntimeStyle(styles, 'letter-spacing', typographyFallbackStyles) ?? DEFAULT_FIELDS.letterSpacing,
6875
radius,
6976
shadowCard: buildShadow(styles),
7077
shadowFocus: `0 0 0 3px ${toRgba(ring, 0.24)}`,
@@ -78,7 +85,7 @@ function buildPresetFromRuntimeSource(source: TweakcnRuntimePresetSource): Theme
7885
const lightStyles = source.styles.light;
7986
const darkStyles = source.styles.dark;
8087
const lightFields = mapRuntimeStylesToFields(lightStyles);
81-
const darkFields = mapRuntimeStylesToFields(darkStyles);
88+
const darkFields = mapRuntimeStylesToFields(darkStyles, lightStyles);
8289

8390
return {
8491
id: source.id,

apps/docs/src/containers/theme-studio/theme-studio.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
}
9393

9494
.theme-studio__topbar-actions .theme-studio__select {
95-
min-width: 180px;
95+
width: 220px;
9696
}
9797

9898
.theme-studio__eyebrow {

packages/react/src/flex/demo/Align.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default function AlignDemo() {
1212
width: '100%',
1313
height: 120,
1414
borderRadius: 6,
15-
border: '1px solid #6e41bf',
15+
border: '1px solid var(--ty-color-primary)',
1616
};
1717

1818
return (
@@ -29,4 +29,4 @@ export default function AlignDemo() {
2929
</Flex>
3030
</Flex>
3131
);
32-
}
32+
}

packages/react/src/flex/demo/Basic.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,17 @@ export default function BasicDemo() {
1818
</Radio.Group>
1919
<Flex vertical={vertical}>
2020
{Array.from({ length: 4 }).map((_, i) => (
21-
<div key={i} style={{ ...baseStyle, backgroundColor: i % 2 ? '#6e41bf' : 'rgba(110, 65, 191, 0.75)' }} />
21+
<div
22+
key={i}
23+
style={{
24+
...baseStyle,
25+
backgroundColor: i % 2
26+
? 'var(--ty-color-primary)'
27+
: 'color-mix(in srgb, var(--ty-color-primary) 75%, transparent)',
28+
}}
29+
/>
2230
))}
2331
</Flex>
2432
</Flex>
2533
);
26-
}
34+
}

packages/react/src/grid/demo/Alignment.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ export default function AlignmentDemo() {
3434
};
3535

3636
const lighterBox = {
37-
backgroundColor: '#6E41BFD6',
37+
backgroundColor: 'color-mix(in srgb, var(--ty-color-primary) 84%, transparent)',
3838
};
3939

4040
const darkerBox = {
41-
backgroundColor: '#6E41BFFA',
41+
backgroundColor: 'color-mix(in srgb, var(--ty-color-primary) 98%, transparent)',
4242
};
4343

4444
return (
@@ -68,4 +68,4 @@ export default function AlignmentDemo() {
6868
</Row>
6969
</>
7070
);
71-
}
71+
}

packages/react/src/grid/demo/AlignmentGrid.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default function AlignmentGridDemo() {
1313
padding: 16,
1414
border: '1px dashed var(--ty-color-border)',
1515
borderRadius: 12,
16-
background: 'linear-gradient(180deg, rgba(110,65,191,0.06), rgba(110,65,191,0.01))',
16+
background: 'linear-gradient(180deg, color-mix(in srgb, var(--ty-color-primary) 6%, transparent), color-mix(in srgb, var(--ty-color-primary-bg) 45%, transparent))',
1717
}}
1818
>
1919
<Button btnType="primary">Primary</Button>

packages/react/src/grid/demo/Basic.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ export default function BasicDemo() {
1313
};
1414

1515
const lighterBox = {
16-
backgroundColor: '#6E41BFD6',
16+
backgroundColor: 'color-mix(in srgb, var(--ty-color-primary) 84%, transparent)',
1717
};
1818

1919
const darkerBox = {
20-
backgroundColor: '#6E41BFFA',
20+
backgroundColor: 'color-mix(in srgb, var(--ty-color-primary) 98%, transparent)',
2121
};
2222

2323
return (
@@ -42,4 +42,4 @@ export default function BasicDemo() {
4242
</Row>
4343
</>
4444
);
45-
}
45+
}

0 commit comments

Comments
 (0)