Skip to content

Commit 381c3bd

Browse files
authored
fix(CopySnippet): various improvements (#562)
1 parent c40aae4 commit 381c3bd

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

.changeset/few-seahorses-agree.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+
Change PrismCode default font and add selection styles.

.changeset/sharp-bulldogs-press.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+
Improve CopySnippet formatting to clear CR symbols and remove spaces at the end of each line.

src/components/GlobalStyles.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ const GlobalStylesElement = createGlobalStyle<GlobalStylesElementProps>`
243243
pre[class*="language-"] {
244244
color: var(--dark-color);
245245
background: none;
246-
font-family: "Source Code Pro", Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
246+
font-family: var(--monospace-font);
247247
text-align: left;
248248
font-weight: normal;
249249
font-size: 14px;
@@ -268,13 +268,13 @@ const GlobalStylesElement = createGlobalStyle<GlobalStylesElementProps>`
268268
pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection,
269269
code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection {
270270
text-shadow: none;
271-
/*background: #b3d4fc;*/
271+
background: rgba(var(--purple-color-rgb), .2);
272272
}
273273
274274
pre[class*="language-"]::selection, pre[class*="language-"] ::selection,
275275
code[class*="language-"]::selection, code[class*="language-"] ::selection {
276276
text-shadow: none;
277-
/*background: #b3d4fc;*/
277+
background: rgba(var(--purple-color-rgb), .2);
278278
}
279279
280280
@media print {

src/components/content/CopySnippet/CopySnippet.stories.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ JavascriptSyntax.args = {
116116
});`,
117117
};
118118

119+
export const DAX = Template.bind({});
120+
DAX.args = {
121+
language: 'javascript',
122+
height: 'max 30x',
123+
code: 'DEFINE\r\n\tVAR __DS0FilterTable = \r\n\t\tTREATAS({"Computers",\r\n\t\t\t"Electronics",\r\n\t\t\t"Home"}, \'orders\'[product_category])\r\n\r\n\tVAR __DS0Core = \r\n\t\tSUMMARIZECOLUMNS(\r\n\t\t\tROLLUPADDISSUBTOTAL(\'orders\'[product_category], "IsGrandTotalRowTotal"),\r\n\t\t\t__DS0FilterTable,\r\n\t\t\t"revenue", \'orders\'[revenue],\r\n\t\t\t"count", \'orders\'[count],\r\n\t\t\t"completed_count", \'orders\'[completed_count],\r\n\t\t\t"completed_percentage", \'orders\'[completed_percentage]\r\n\t\t)\r\n\r\n\tVAR __DS0PrimaryWindowed = \r\n\t\tTOPN(502, __DS0Core, [IsGrandTotalRowTotal], 0, [revenue], 0, \'orders\'[product_category], 1)\r\n\r\nEVALUATE\r\n\t__DS0PrimaryWindowed\r\n\r\nORDER BY\r\n\t[IsGrandTotalRowTotal] DESC, [revenue] DESC, \'orders\'[product_category]',
124+
};
125+
119126
export const Complex = Template.bind({});
120127
Complex.args = {
121128
language: 'javascript',

src/components/content/CopySnippet/CopySnippet.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,9 @@ function CopySnippet(allProps: CubeCopySnippetProps) {
186186

187187
const multiline = pristineCode.includes('\n') && !nowrap;
188188
let formattedCode = pristineCode
189+
.replace(/\r/g, '')
189190
.split(/\n/g)
190-
.map((line) => `${prefix}${line} `)
191+
.map((line) => `${prefix}${line}`)
191192
.join('\n')
192193
.trim();
193194

0 commit comments

Comments
 (0)