Skip to content

Commit d6820d0

Browse files
feat(PrismCode): react renderer (#687)
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 4c704ca commit d6820d0

File tree

19 files changed

+893
-107
lines changed

19 files changed

+893
-107
lines changed

.changeset/fair-turtles-switch.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+
Use react renderer for PrismCode.

.size-limit.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = [
2020
}),
2121
);
2222
},
23-
limit: '247kB',
23+
limit: '260kB',
2424
},
2525
{
2626
name: 'Tree shaking (just a Button)',

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"diff": "^7.0.0",
8080
"email-validator": "^2.0.4",
8181
"globals": "^16.0.0",
82+
"prism-react-renderer": "^2.4.1",
8283
"prismjs": "^1.30.0",
8384
"react-aria": "^3.37.0",
8485
"react-focus-lock": "^2.13.5",

pnpm-lock.yaml

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

src/_internal/hooks/use-event.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/no-explicit-any */
21
import { useCallback } from 'react';
32

43
import { useSyncRef } from './use-sync-ref';

src/_internal/hooks/use-update-effect.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ export function useUpdateEffect(effect: EffectCallback, deps?: DependencyList) {
99
if (!isFirst) {
1010
return effect();
1111
}
12-
// eslint-disable-next-line react-hooks/exhaustive-deps
1312
}, deps);
1413
}

src/components/GlobalStyles.tsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,24 @@ const GlobalStylesElement = createGlobalStyle<GlobalStylesElementProps>`
249249
white-space: normal;
250250
}
251251
252+
.token.inserted-sign {
253+
background-color: #e6ffed;
254+
color: #30A666;
255+
}
256+
257+
.token.inserted {
258+
color: #30A666;
259+
}
260+
261+
.token.deleted-sign {
262+
background-color: #ffeef0;
263+
color: (--danger-color);
264+
}
265+
266+
.token.deleted {
267+
color: var(--pink-color);
268+
}
269+
252270
.token.comment,
253271
.token.prolog,
254272
.token.doctype,
@@ -271,8 +289,7 @@ const GlobalStylesElement = createGlobalStyle<GlobalStylesElementProps>`
271289
.token.constant,
272290
.token.symbol,
273291
.token.key,
274-
.token.keyword,
275-
.token.deleted {
292+
.token.keyword {
276293
color: var(--pink-color);
277294
}
278295
@@ -285,8 +302,7 @@ const GlobalStylesElement = createGlobalStyle<GlobalStylesElementProps>`
285302
.token.attr-name,
286303
.token.string,
287304
.token.char,
288-
.token.builtin,
289-
.token.inserted {
305+
.token.builtin {
290306
color: var(--purple-text-color);
291307
}
292308
@@ -328,16 +344,6 @@ const GlobalStylesElement = createGlobalStyle<GlobalStylesElementProps>`
328344
.token.entity {
329345
cursor: help;
330346
}
331-
332-
.token.inserted-sign {
333-
background-color: #e6ffed;
334-
color: #30A666;
335-
}
336-
337-
.token.deleted-sign {
338-
background-color: #ffeef0;
339-
color: (--danger-color);
340-
}
341347
`;
342348

343349
export const GlobalStyles = (props: GlobalStylesProps) => {

src/components/content/PrismCode/PrismCode.stories.tsx

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,29 @@ export default {
1212
},
1313
};
1414

15-
const Template = ({ ...args }) => <PrismCode {...args} />;
15+
const Template = (args: any) => <PrismCode {...args} />;
1616

17-
export const OneLine = Template.bind({});
18-
OneLine.args = {
19-
code: '$ npm install -g cubejs-cli',
17+
export const OneLine = {
18+
render: Template,
19+
args: {
20+
language: 'bash',
21+
code: '$ npm install -g cubejs-cli',
22+
},
2023
};
2124

22-
export const MultiLine = Template.bind({});
23-
MultiLine.args = {
24-
code: '$ npm install -g cubejs-cli\n$ cubejs deploy',
25+
export const MultiLine = {
26+
render: Template,
27+
args: {
28+
language: 'bash',
29+
code: '$ npm install -g cubejs-cli\n$ cubejs deploy',
30+
},
2531
};
2632

27-
export const JavascriptSyntax = Template.bind({});
28-
JavascriptSyntax.args = {
29-
language: 'javascript',
30-
code: `cube('LineItems', {
33+
export const JavascriptSyntax = {
34+
render: Template,
35+
args: {
36+
language: 'javascript',
37+
code: `cube('LineItems', {
3138
sql: \`SELECT * FROM public.line_items\`,
3239
3340
@@ -73,12 +80,14 @@ JavascriptSyntax.args = {
7380
}
7481
}
7582
});`,
83+
},
7684
};
7785

78-
export const YamlSyntax = Template.bind({});
79-
YamlSyntax.args = {
80-
language: 'yaml',
81-
code: `cubes:
86+
export const YamlSyntax = {
87+
render: Template,
88+
args: {
89+
language: 'yaml',
90+
code: `cubes:
8291
# Define the Orders cube
8392
- name: Orders
8493
sql: SELECT * FROM public.orders
@@ -136,12 +145,14 @@ YamlSyntax.args = {
136145
- cube: Orders
137146
sql: \${Customers.id} = \${Orders.customer_id}
138147
relationship: one_to_many # One customer can have many orders`,
148+
},
139149
};
140150

141-
export const SqlSyntax = Template.bind({});
142-
SqlSyntax.args = {
143-
language: 'sql',
144-
code: `WITH RecursiveCTE AS (
151+
export const SqlSyntax = {
152+
render: Template,
153+
args: {
154+
language: 'sql',
155+
code: `WITH RecursiveCTE AS (
145156
-- Recursive CTE to generate a sequence of numbers
146157
SELECT 1 AS Level, CAST('2025-01-01' AS DATE) AS GeneratedDate
147158
UNION ALL
@@ -184,7 +195,7 @@ FinalOutput AS (
184195
CROSS JOIN RecursiveCTE r
185196
WHERE r.GeneratedDate <= GETDATE()
186197
)
187-
-- Final query to output the results
198+
-- Final query to output the results
188199
SELECT
189200
fo.UserID,
190201
fo.UserName,
@@ -194,13 +205,16 @@ SELECT
194205
fo.GeneratedDate
195206
FROM FinalOutput fo
196207
ORDER BY fo.GeneratedDate, fo.UserID;`,
208+
},
197209
};
198210

199-
export const DiffSyntax = Template.bind({});
200-
DiffSyntax.args = {
201-
language: 'javascript',
202-
code: ` console.log('Hello, world!');
211+
export const DiffSyntax = {
212+
render: Template,
213+
args: {
214+
language: 'javascript',
215+
code: ` console.log('Hello, world!');
203216
+ console.log('This line was added!');
204217
console.log('Another unchanged line');
205218
- console.log('This line was removed.');`,
219+
},
206220
};

0 commit comments

Comments
 (0)