@dust-tt/sparkle 0.2.612 → 0.2.614

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.
@@ -0,0 +1,361 @@
1
+ import type { Meta, StoryObj } from "@storybook/react";
2
+ import React from "react";
3
+
4
+ import { CodeBlock } from "../index_with_tw_base";
5
+
6
+ const meta: Meta<typeof CodeBlock> = {
7
+ title: "Components/CodeBlock",
8
+ component: CodeBlock,
9
+ argTypes: {
10
+ children: {
11
+ description: "The code content to display",
12
+ control: { type: "text" },
13
+ },
14
+ className: {
15
+ description:
16
+ "CSS class name, can include language specification (e.g., 'language-javascript')",
17
+ control: { type: "text" },
18
+ },
19
+ inline: {
20
+ description:
21
+ "Whether to render as inline code (single line) or block code",
22
+ control: { type: "boolean" },
23
+ defaultValue: false,
24
+ },
25
+ variant: {
26
+ description: "Visual variant of the code block",
27
+ options: ["surface"],
28
+ control: { type: "select" },
29
+ defaultValue: "surface",
30
+ },
31
+ wrapLongLines: {
32
+ description: "Whether to wrap long lines in block code",
33
+ control: { type: "boolean" },
34
+ defaultValue: false,
35
+ },
36
+ showLineNumber: {
37
+ description: "Whether to show line numbers on the left side of the code",
38
+ control: { type: "boolean" },
39
+ defaultValue: false,
40
+ },
41
+ },
42
+ decorators: [
43
+ (Story) => (
44
+ <div className="s-bg-background s-p-4 dark:s-bg-background-night">
45
+ <Story />
46
+ </div>
47
+ ),
48
+ ],
49
+ };
50
+
51
+ export default meta;
52
+ type Story = StoryObj<typeof meta>;
53
+
54
+ // Inline code examples
55
+ export const InlineCode: Story = {
56
+ args: {
57
+ children: "const greeting = 'Hello, World!';",
58
+ inline: true,
59
+ },
60
+ };
61
+
62
+ export const InlineCodeWithVariant: Story = {
63
+ args: {
64
+ children: "npm install @dust-tt/sparkle",
65
+ inline: true,
66
+ variant: "surface",
67
+ },
68
+ };
69
+
70
+ export const TypescriptBlock: Story = {
71
+ args: {
72
+ children: `interface User {
73
+ id: number;
74
+ name: string;
75
+ email: string;
76
+ isActive: boolean;
77
+ }
78
+
79
+ const createUser = (userData: Partial<User>): User => {
80
+ return {
81
+ id: Math.random(),
82
+ name: userData.name || "Anonymous",
83
+ email: userData.email || "",
84
+ isActive: userData.isActive ?? true,
85
+ };
86
+ };
87
+
88
+ const newUser = createUser({ name: "John Doe", email: "john@example.com" });`,
89
+ className: "language-typescript",
90
+ inline: false,
91
+ },
92
+ };
93
+
94
+ export const ReactTSXBlock: Story = {
95
+ args: {
96
+ children: `import React, { useState, useEffect } from 'react';
97
+ import { Button } from '@dust-tt/sparkle';
98
+
99
+ interface CounterProps {
100
+ initialValue?: number;
101
+ step?: number;
102
+ onCountChange?: (count: number) => void;
103
+ }
104
+
105
+ const Counter: React.FC<CounterProps> = ({
106
+ initialValue = 0,
107
+ step = 1,
108
+ onCountChange
109
+ }) => {
110
+ const [count, setCount] = useState<number>(initialValue);
111
+
112
+ useEffect(() => {
113
+ document.title = \`Count: \${count}\`;
114
+ onCountChange?.(count);
115
+ }, [count, onCountChange]);
116
+
117
+ const increment = (): void => setCount(prev => prev + step);
118
+ const decrement = (): void => setCount(prev => prev - step);
119
+ const reset = (): void => setCount(initialValue);
120
+
121
+ return (
122
+ <div className="flex items-center gap-4">
123
+ <Button onClick={decrement} variant="outline">
124
+ -
125
+ </Button>
126
+ <span className="text-2xl font-bold">{count}</span>
127
+ <Button onClick={increment} variant="primary">
128
+ +
129
+ </Button>
130
+ <Button onClick={reset} variant="ghost">
131
+ Reset
132
+ </Button>
133
+ </div>
134
+ );
135
+ };
136
+
137
+ export default Counter;`,
138
+ className: "language-tsx",
139
+ inline: false,
140
+ },
141
+ };
142
+
143
+ export const CSSBlock: Story = {
144
+ args: {
145
+ children: `.code-block {
146
+ background-color: var(--s-muted);
147
+ border: 1px solid var(--s-border);
148
+ border-radius: 0.5rem;
149
+ padding: 1rem;
150
+ font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
151
+ font-size: 0.875rem;
152
+ line-height: 1.5;
153
+ overflow-x: auto;
154
+ }
155
+
156
+ .code-block .keyword {
157
+ color: #8b5cf6; /* violet-500 */
158
+ }
159
+
160
+ .code-block .string {
161
+ color: #10b981; /* emerald-500 */
162
+ }
163
+
164
+ .code-block .comment {
165
+ color: #6b7280; /* gray-500 */
166
+ font-style: italic;
167
+ }
168
+
169
+ @media (prefers-color-scheme: dark) {
170
+ .code-block {
171
+ background-color: var(--s-muted-night);
172
+ border-color: var(--s-border-night);
173
+ }
174
+ }`,
175
+ className: "language-css",
176
+ inline: false,
177
+ },
178
+ };
179
+
180
+ export const JSONBlock: Story = {
181
+ args: {
182
+ children: `{
183
+ "name": "@dust-tt/sparkle",
184
+ "version": "1.0.0",
185
+ "description": "A beautiful component library for React applications",
186
+ "main": "dist/index.js",
187
+ "types": "dist/index.d.ts",
188
+ "scripts": {
189
+ "build": "rollup -c",
190
+ "dev": "rollup -c -w",
191
+ "test": "jest",
192
+ "lint": "eslint src/**/*.{ts,tsx}"
193
+ },
194
+ "dependencies": {
195
+ "react": "^18.0.0",
196
+ "react-dom": "^18.0.0",
197
+ "class-variance-authority": "^0.7.0"
198
+ },
199
+ "devDependencies": {
200
+ "@types/react": "^18.0.0",
201
+ "@types/react-dom": "^18.0.0",
202
+ "typescript": "^5.0.0"
203
+ },
204
+ "keywords": ["react", "components", "ui", "typescript"],
205
+ "author": "Dust Team",
206
+ "license": "MIT"
207
+ }`,
208
+ className: "language-json",
209
+ inline: false,
210
+ },
211
+ };
212
+
213
+ export const BashBlock: Story = {
214
+ args: {
215
+ children: `#!/bin/bash
216
+
217
+ # Install dependencies
218
+ npm install
219
+
220
+ # Build the project
221
+ npm run build
222
+
223
+ # Run tests
224
+ npm test
225
+
226
+ # Deploy to production
227
+ if [ "$ENVIRONMENT" = "production" ]; then
228
+ echo "Deploying to production..."
229
+ npm run deploy:prod
230
+ else
231
+ echo "Deploying to staging..."
232
+ npm run deploy:staging
233
+ fi
234
+
235
+ # Clean up
236
+ npm run clean`,
237
+ className: "language-bash",
238
+ inline: false,
239
+ },
240
+ };
241
+
242
+ export const SQLBlock: Story = {
243
+ args: {
244
+ children: `-- Create users table
245
+ CREATE TABLE users (
246
+ id SERIAL PRIMARY KEY,
247
+ username VARCHAR(50) UNIQUE NOT NULL,
248
+ email VARCHAR(100) UNIQUE NOT NULL,
249
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
250
+ updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
251
+ );
252
+
253
+ -- Insert sample data
254
+ INSERT INTO users (username, email) VALUES
255
+ ('alice', 'alice@example.com'),
256
+ ('bob', 'bob@example.com'),
257
+ ('charlie', 'charlie@example.com');
258
+
259
+ -- Query with joins
260
+ SELECT
261
+ u.username,
262
+ u.email,
263
+ p.title as post_title,
264
+ p.created_at as post_date
265
+ FROM users u
266
+ LEFT JOIN posts p ON u.id = p.user_id
267
+ WHERE u.created_at > '2024-01-01'
268
+ ORDER BY p.created_at DESC
269
+ LIMIT 10;`,
270
+ className: "language-sql",
271
+ inline: false,
272
+ },
273
+ };
274
+
275
+ // Long code example with line wrapping
276
+ export const LongCodeWithWrapping: Story = {
277
+ args: {
278
+ children: `// This is a very long line of code that demonstrates how the wrapLongLines prop works when set to true. It contains a lot of text and would normally overflow the container, but with wrapLongLines enabled, it will wrap to the next line instead of creating a horizontal scrollbar. This is particularly useful for mobile devices or narrow containers where horizontal scrolling is not desirable.
279
+
280
+ function processVeryLongFunctionNameWithManyParameters(
281
+ parameterOne: string,
282
+ parameterTwo: number,
283
+ parameterThree: boolean,
284
+ parameterFour: object,
285
+ parameterFive: array,
286
+ parameterSix: function,
287
+ parameterSeven: string,
288
+ parameterEight: number
289
+ ): Promise<ComplexReturnType> {
290
+ // Implementation here
291
+ return new Promise((resolve, reject) => {
292
+ // More implementation
293
+ });
294
+ }`,
295
+ className: "language-typescript",
296
+ inline: false,
297
+ wrapLongLines: true,
298
+ },
299
+ };
300
+
301
+ // Long code example without line wrapping (default)
302
+ export const LongCodeWithoutWrapping: Story = {
303
+ args: {
304
+ children: `// This is a very long line of code that demonstrates how the wrapLongLines prop works when set to false (default). It contains a lot of text and will create a horizontal scrollbar when it overflows the container. This is the default behavior and is useful when you want to preserve the exact formatting of the code.
305
+
306
+ function processVeryLongFunctionNameWithManyParameters(parameterOne: string, parameterTwo: number, parameterThree: boolean, parameterFour: object, parameterFive: array, parameterSix: function, parameterSeven: string, parameterEight: number): Promise<ComplexReturnType> {
307
+ // Implementation here
308
+ return new Promise((resolve, reject) => {
309
+ // More implementation
310
+ });
311
+ }`,
312
+ className: "language-typescript",
313
+ inline: false,
314
+ wrapLongLines: false,
315
+ },
316
+ };
317
+
318
+ export const TypescriptWithLineNumbers: Story = {
319
+ args: {
320
+ children: `interface User {
321
+ id: number;
322
+ name: string;
323
+ email: string;
324
+ isActive: boolean;
325
+ }
326
+
327
+ class UserService {
328
+ private users: User[] = [];
329
+
330
+ addUser(user: Omit<User, 'id'>): User {
331
+ const newUser: User = {
332
+ id: this.users.length + 1,
333
+ ...user
334
+ };
335
+
336
+ this.users.push(newUser);
337
+ return newUser;
338
+ }
339
+
340
+ getUserById(id: number): User | undefined {
341
+ return this.users.find(user => user.id === id);
342
+ }
343
+
344
+ getAllUsers(): User[] {
345
+ return [...this.users];
346
+ }
347
+ }
348
+
349
+ const userService = new UserService();
350
+ const newUser = userService.addUser({
351
+ name: "John Doe",
352
+ email: "john@example.com",
353
+ isActive: true
354
+ });
355
+
356
+ console.log("Created user:", newUser);`,
357
+ className: "language-typescript",
358
+ inline: false,
359
+ showLineNumber: true,
360
+ },
361
+ };