Skip to content

Commit b76deb1

Browse files
authored
chore: update tasty playground (#1073)
1 parent f8d6059 commit b76deb1

File tree

11 files changed

+507
-20
lines changed

11 files changed

+507
-20
lines changed

.changeset/nine-plants-shop.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+
Update tasty to 0.8.1

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"@react-types/shared": "^3.32.1",
7474
"@tabler/icons-react": "^3.31.0",
7575
"@tanstack/react-virtual": "^3.13.12",
76-
"@tenphi/tasty": "0.8.0",
76+
"@tenphi/tasty": "0.9.0",
7777
"clipboard-copy": "^4.0.1",
7878
"clsx": "^1.1.1",
7979
"diff": "^8.0.3",

pnpm-lock.yaml

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/content/Layout/LayoutContent.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ const ContentElement = tasty({
5757
},
5858
placeSelf: 'stretch',
5959
scrollbar: {
60-
'': 'thin',
60+
'': 'auto',
61+
'scrollbar=thin': 'thin',
6162
'scrollbar=tiny | scrollbar=none': 'none',
6263
},
6364

src/stories/playground/Playground.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function PlaygroundComponent() {
135135
<PlaygroundPreview component={component} styles={styles} />
136136
) : undefined
137137
}
138-
output={<PlaygroundOutput styles={styles} />}
138+
output={<PlaygroundOutput styles={styles} resetKey={exampleIndex} />}
139139
/>
140140
);
141141
}

src/stories/playground/PlaygroundOutput.tsx

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { renderStyles, tasty } from '@tenphi/tasty';
22
import copy from 'clipboard-copy';
3-
import { useCallback, useMemo } from 'react';
3+
import { useCallback, useEffect, useMemo, useRef } from 'react';
44

55
import { Button } from '../../components/actions/Button';
66
import { Layout } from '../../components/content/Layout';
77
import { PrismCode } from '../../components/content/PrismCode/PrismCode';
88
import { useToast } from '../../components/overlays/Toast';
99
import { CopyIcon } from '../../icons';
1010

11-
import type { StyleResult, Styles } from '@tenphi/tasty';
11+
import type { KeyframesSteps, StyleResult, Styles } from '@tenphi/tasty';
1212

1313
const OutputContent = tasty({
1414
styles: {
@@ -23,6 +23,31 @@ const OutputContent = tasty({
2323

2424
export interface PlaygroundOutputProps {
2525
styles: Styles;
26+
resetKey?: number | string;
27+
}
28+
29+
function formatKeyframes(keyframes: Record<string, KeyframesSteps>): string {
30+
const blocks: string[] = [];
31+
32+
for (const [name, steps] of Object.entries(keyframes)) {
33+
const stepLines: string[] = [];
34+
35+
for (const [step, value] of Object.entries(steps)) {
36+
if (typeof value === 'string') {
37+
stepLines.push(` ${step} {\n ${value};\n }`);
38+
} else {
39+
const decls = Object.entries(value)
40+
.map(([prop, val]) => `${prop}: ${val}`)
41+
.join(';\n ');
42+
43+
stepLines.push(` ${step} {\n ${decls};\n }`);
44+
}
45+
}
46+
47+
blocks.push(`@keyframes ${name} {\n${stepLines.join('\n')}\n}`);
48+
}
49+
50+
return blocks.join('\n\n');
2651
}
2752

2853
function formatStyleResults(results: StyleResult[]): string {
@@ -76,18 +101,34 @@ function formatStyleResults(results: StyleResult[]): string {
76101
return lines.join('\n\n');
77102
}
78103

79-
export function PlaygroundOutput({ styles }: PlaygroundOutputProps) {
104+
export function PlaygroundOutput({ styles, resetKey }: PlaygroundOutputProps) {
80105
const toast = useToast();
106+
const scrollRef = useRef<HTMLDivElement>(null);
107+
108+
useEffect(() => {
109+
scrollRef.current?.scrollTo(0, 0);
110+
}, [resetKey]);
81111

82112
const cssOutput = useMemo(() => {
83113
if (!styles || Object.keys(styles).length === 0) {
84114
return '/* Enter styles in the editor to see generated CSS */';
85115
}
86116

87117
try {
88-
// Use a demo selector for display purposes
118+
const parts: string[] = [];
119+
120+
const keyframesDef = styles['@keyframes'] as
121+
| Record<string, KeyframesSteps>
122+
| undefined;
123+
124+
if (keyframesDef && typeof keyframesDef === 'object') {
125+
parts.push(formatKeyframes(keyframesDef));
126+
}
127+
89128
const results = renderStyles(styles, '.demo');
90-
return formatStyleResults(results as StyleResult[]);
129+
parts.push(formatStyleResults(results as StyleResult[]));
130+
131+
return parts.filter(Boolean).join('\n\n');
91132
} catch (e) {
92133
return `/* Error generating CSS: ${(e as Error).message} */`;
93134
}
@@ -111,7 +152,7 @@ export function PlaygroundOutput({ styles }: PlaygroundOutputProps) {
111152
/>
112153
</Layout.Toolbar>
113154
<Layout.Content padding={0}>
114-
<OutputContent>
155+
<OutputContent ref={scrollRef}>
115156
<PrismCode code={cssOutput} language="css" />
116157
</OutputContent>
117158
</Layout.Content>

src/stories/playground/PlaygroundPreview.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import { Layout } from '../../components/content/Layout';
44

55
import { Button } from './components/Button';
66
import { Card } from './components/Card';
7+
import { ListCard } from './components/ListCard';
78
import { ScrollProgress } from './components/ScrollProgress';
9+
import { StructuredCard } from './components/StructuredCard';
810

911
import type { Styles } from '@tenphi/tasty';
1012

@@ -54,7 +56,12 @@ const ButtonColumn = tasty({
5456
});
5557

5658
export interface PlaygroundPreviewProps {
57-
component: 'card' | 'button' | 'scroll-progress';
59+
component:
60+
| 'card'
61+
| 'button'
62+
| 'scroll-progress'
63+
| 'structured-card'
64+
| 'list-card';
5865
styles: Styles;
5966
}
6067

@@ -97,6 +104,10 @@ export function PlaygroundPreview({
97104
<Layout.Content padding={0}>
98105
<PreviewContent>
99106
{component === 'card' && <Card styles={styles} />}
107+
{component === 'structured-card' && (
108+
<StructuredCard styles={styles} />
109+
)}
110+
{component === 'list-card' && <ListCard styles={styles} />}
100111
{component === 'scroll-progress' && (
101112
<ScrollProgress styles={styles} />
102113
)}

src/stories/playground/components/Card.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,21 @@ export function Card({ styles, children }: CardProps) {
2222
<>
2323
<div style={{ fontWeight: 600, marginBottom: '8px' }}>Card Title</div>
2424
<div style={{ opacity: 0.7 }}>
25-
This is a simple card component for demonstrating tasty styles.
25+
<p style={{ margin: '0 0 8px' }}>
26+
This is a simple card component for demonstrating tasty styles.
27+
</p>
28+
<p style={{ margin: '0 0 8px' }}>
29+
Cards are one of the most common UI patterns. They group related
30+
content and actions, providing a clear visual boundary.
31+
</p>
32+
<p style={{ margin: '0 0 8px' }}>
33+
Try adjusting padding, radius, fill, border, and shadow properties
34+
in the editor to see how the card changes.
35+
</p>
36+
<p style={{ margin: 0 }}>
37+
You can also experiment with overflow-related features like
38+
scrollbar styling and fade edges using this content.
39+
</p>
2640
</div>
2741
</>
2842
)}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { tasty } from '@tenphi/tasty';
2+
3+
import type { Styles } from '@tenphi/tasty';
4+
5+
const ListCardElement = tasty({
6+
qa: 'PlaygroundListCard',
7+
styles: {
8+
display: 'block',
9+
},
10+
});
11+
12+
export interface ListCardProps {
13+
styles?: Styles;
14+
}
15+
16+
export function ListCard({ styles }: ListCardProps) {
17+
return (
18+
<ListCardElement styles={styles}>
19+
<div data-element="Title">Tasks</div>
20+
<div data-element="Item">
21+
<div data-element="Icon">&#9679;</div>
22+
<span>Review pull request</span>
23+
</div>
24+
<div data-element="Item">
25+
<span>Write documentation</span>
26+
</div>
27+
<div data-element="Item">
28+
<div data-element="Icon">&#9679;</div>
29+
<span>Deploy to staging</span>
30+
</div>
31+
<div data-element="Item">
32+
<span>Send weekly update</span>
33+
</div>
34+
</ListCardElement>
35+
);
36+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { tasty } from '@tenphi/tasty';
2+
3+
import type { Styles } from '@tenphi/tasty';
4+
5+
const StructuredCardElement = tasty({
6+
qa: 'PlaygroundStructuredCard',
7+
styles: {
8+
display: 'block',
9+
},
10+
});
11+
12+
export interface StructuredCardProps {
13+
styles?: Styles;
14+
}
15+
16+
export function StructuredCard({ styles }: StructuredCardProps) {
17+
return (
18+
<StructuredCardElement styles={styles}>
19+
<div data-element="Header">
20+
<div data-element="Title">Card Title</div>
21+
<div data-element="Subtitle">Updated 2 hours ago</div>
22+
</div>
23+
<div data-element="Body">
24+
This card demonstrates sub-element styling. Each section is targeted via
25+
capitalized keys in the styles object and matched by data-element
26+
attributes in the DOM.
27+
</div>
28+
<div data-element="Footer">
29+
<span>Footer action area</span>
30+
</div>
31+
</StructuredCardElement>
32+
);
33+
}

0 commit comments

Comments
 (0)