@redis-ui/components 51.27.0 → 51.29.0
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.
- package/dist/CodeBlock/CodeBlock.cjs +32 -15
- package/dist/CodeBlock/CodeBlock.js +32 -15
- package/dist/CodeBlock/CodeBlock.style.d.ts +4 -3
- package/dist/CodeBlock/CodeBlock.types.cjs +7 -0
- package/dist/CodeBlock/CodeBlock.types.d.ts +9 -1
- package/dist/CodeBlock/CodeBlock.types.js +7 -1
- package/dist/CodeBlock/components/HighlightedCode/HighlightedCode.cjs +29 -0
- package/dist/CodeBlock/components/HighlightedCode/HighlightedCode.constants.cjs +34 -0
- package/dist/CodeBlock/components/HighlightedCode/HighlightedCode.constants.d.ts +25 -0
- package/dist/CodeBlock/components/HighlightedCode/HighlightedCode.constants.js +32 -0
- package/dist/CodeBlock/components/HighlightedCode/HighlightedCode.d.ts +6 -0
- package/dist/CodeBlock/components/HighlightedCode/HighlightedCode.js +29 -0
- package/dist/CodeBlock/components/HighlightedCode/HighlightedCode.types.d.ts +10 -0
- package/dist/CodeBlock/components/HighlightedCode/HighlightedCode.types.js +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.js +2 -2
- package/dist/node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.cjs +8 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.js +8 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.cjs +7 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js +7 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/defineProperty.cjs +12 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/defineProperty.js +12 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/extends.cjs +17 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/extends.js +12 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/iterableToArray.cjs +6 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/iterableToArray.js +6 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/nonIterableSpread.cjs +6 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/nonIterableSpread.js +6 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/objectWithoutProperties.cjs +13 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/objectWithoutProperties.js +13 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.cjs +12 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.js +12 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/toConsumableArray.cjs +10 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/toConsumableArray.js +10 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/toPrimitive.cjs +14 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/toPrimitive.js +14 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/toPropertyKey.cjs +9 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/toPropertyKey.js +9 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/typeof.cjs +16 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/typeof.js +11 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.cjs +11 -0
- package/dist/node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js +11 -0
- package/dist/node_modules/character-entities-legacy/index.cjs +116 -0
- package/dist/node_modules/character-entities-legacy/index.js +116 -0
- package/dist/node_modules/character-reference-invalid/index.cjs +38 -0
- package/dist/node_modules/character-reference-invalid/index.js +38 -0
- package/dist/node_modules/comma-separated-tokens/index.cjs +43 -0
- package/dist/node_modules/comma-separated-tokens/index.js +43 -0
- package/dist/node_modules/decode-named-character-reference/index.dom.cjs +15 -0
- package/dist/node_modules/decode-named-character-reference/index.dom.js +15 -0
- package/dist/node_modules/hast-util-parse-selector/lib/index.cjs +76 -0
- package/dist/node_modules/hast-util-parse-selector/lib/index.js +76 -0
- package/dist/node_modules/hastscript/lib/create-h.cjs +262 -0
- package/dist/node_modules/hastscript/lib/create-h.js +262 -0
- package/dist/node_modules/hastscript/lib/index.cjs +21 -0
- package/dist/node_modules/hastscript/lib/index.js +21 -0
- package/dist/node_modules/hastscript/lib/svg-case-sensitive-tag-names.cjs +49 -0
- package/dist/node_modules/hastscript/lib/svg-case-sensitive-tag-names.js +49 -0
- package/dist/node_modules/is-alphabetical/index.cjs +14 -0
- package/dist/node_modules/is-alphabetical/index.js +14 -0
- package/dist/node_modules/is-alphanumerical/index.cjs +15 -0
- package/dist/node_modules/is-alphanumerical/index.js +15 -0
- package/dist/node_modules/is-decimal/index.cjs +14 -0
- package/dist/node_modules/is-decimal/index.js +14 -0
- package/dist/node_modules/is-hexadecimal/index.cjs +14 -0
- package/dist/node_modules/is-hexadecimal/index.js +14 -0
- package/dist/node_modules/parse-entities/lib/index.cjs +232 -0
- package/dist/node_modules/parse-entities/lib/index.js +232 -0
- package/dist/node_modules/property-information/index.cjs +27 -0
- package/dist/node_modules/property-information/index.js +26 -0
- package/dist/node_modules/property-information/lib/aria.cjs +60 -0
- package/dist/node_modules/property-information/lib/aria.js +61 -0
- package/dist/node_modules/property-information/lib/find.cjs +81 -0
- package/dist/node_modules/property-information/lib/find.js +81 -0
- package/dist/node_modules/property-information/lib/html.cjs +326 -0
- package/dist/node_modules/property-information/lib/html.js +326 -0
- package/dist/node_modules/property-information/lib/normalize.cjs +15 -0
- package/dist/node_modules/property-information/lib/normalize.js +15 -0
- package/dist/node_modules/property-information/lib/svg.cjs +564 -0
- package/dist/node_modules/property-information/lib/svg.js +564 -0
- package/dist/node_modules/property-information/lib/util/case-insensitive-transform.cjs +15 -0
- package/dist/node_modules/property-information/lib/util/case-insensitive-transform.js +15 -0
- package/dist/node_modules/property-information/lib/util/case-sensitive-transform.cjs +14 -0
- package/dist/node_modules/property-information/lib/util/case-sensitive-transform.js +14 -0
- package/dist/node_modules/property-information/lib/util/create.cjs +53 -0
- package/dist/node_modules/property-information/lib/util/create.js +53 -0
- package/dist/node_modules/property-information/lib/util/defined-info.cjs +49 -0
- package/dist/node_modules/property-information/lib/util/defined-info.js +49 -0
- package/dist/node_modules/property-information/lib/util/info.cjs +33 -0
- package/dist/node_modules/property-information/lib/util/info.js +33 -0
- package/dist/node_modules/property-information/lib/util/merge.cjs +26 -0
- package/dist/node_modules/property-information/lib/util/merge.js +26 -0
- package/dist/node_modules/property-information/lib/util/schema.cjs +27 -0
- package/dist/node_modules/property-information/lib/util/schema.js +27 -0
- package/dist/node_modules/property-information/lib/util/types.cjs +35 -0
- package/dist/node_modules/property-information/lib/util/types.js +24 -0
- package/dist/node_modules/property-information/lib/xlink.cjs +18 -0
- package/dist/node_modules/property-information/lib/xlink.js +19 -0
- package/dist/node_modules/property-information/lib/xml.cjs +14 -0
- package/dist/node_modules/property-information/lib/xml.js +15 -0
- package/dist/node_modules/property-information/lib/xmlns.cjs +14 -0
- package/dist/node_modules/property-information/lib/xmlns.js +14 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/checkForListedLanguage.cjs +6 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/checkForListedLanguage.js +6 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/create-element.cjs +183 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/create-element.js +181 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/highlight.cjs +308 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/highlight.js +306 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/languages/prism/bash.cjs +4 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/languages/prism/bash.js +5 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/languages/prism/json.cjs +4 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/languages/prism/json.js +5 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/languages/prism/python.cjs +4 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/languages/prism/python.js +5 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/languages/prism/typescript.cjs +4 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/languages/prism/typescript.js +5 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/prism-light.cjs +12 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/prism-light.js +12 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/styles/prism/vs.cjs +121 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/styles/prism/vs.js +121 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/styles/prism/vsc-dark-plus.cjs +147 -0
- package/dist/node_modules/react-syntax-highlighter/dist/esm/styles/prism/vsc-dark-plus.js +147 -0
- package/dist/node_modules/refractor/lang/bash.cjs +190 -0
- package/dist/node_modules/refractor/lang/bash.js +190 -0
- package/dist/node_modules/refractor/lang/clike.cjs +37 -0
- package/dist/node_modules/refractor/lang/clike.js +37 -0
- package/dist/node_modules/refractor/lang/javascript.cjs +122 -0
- package/dist/node_modules/refractor/lang/javascript.js +122 -0
- package/dist/node_modules/refractor/lang/json.cjs +36 -0
- package/dist/node_modules/refractor/lang/json.js +36 -0
- package/dist/node_modules/refractor/lang/python.cjs +71 -0
- package/dist/node_modules/refractor/lang/python.js +71 -0
- package/dist/node_modules/refractor/lang/typescript.cjs +55 -0
- package/dist/node_modules/refractor/lang/typescript.js +55 -0
- package/dist/node_modules/refractor/lib/core.cjs +214 -0
- package/dist/node_modules/refractor/lib/core.js +214 -0
- package/dist/node_modules/refractor/lib/prism-core.cjs +595 -0
- package/dist/node_modules/refractor/lib/prism-core.js +595 -0
- package/dist/node_modules/space-separated-tokens/index.cjs +15 -0
- package/dist/node_modules/space-separated-tokens/index.js +15 -0
- package/package.json +3 -1
- package/skills/redis-ui-components/references/CodeBlock.md +27 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# CodeBlock
|
|
2
2
|
|
|
3
|
-
A multi-line code block for snippets, commands and JSON, with
|
|
3
|
+
A multi-line code block for snippets, commands and JSON, with optional syntax highlighting and a copy button. Use `Typography.Code` for inline code.
|
|
4
4
|
|
|
5
5
|
## Import
|
|
6
6
|
```tsx
|
|
@@ -11,23 +11,26 @@ import { CodeBlock } from '@redis-ui/components';
|
|
|
11
11
|
| Prop | Type | Default | Description |
|
|
12
12
|
|------|------|---------|-------------|
|
|
13
13
|
| code | `string` | *required* | Text rendered in the block and copied by the copy button |
|
|
14
|
+
| language | `'bash' \| 'json' \| 'python' \| 'typescript'` | - | Highlights the code's syntax. Without it, the code is plain text |
|
|
14
15
|
| copyLabel | `string` | - | Shows a copy button and is used as its accessible name |
|
|
16
|
+
| onCopy | `(text: string) => void` | - | Called with the code after the copy button writes it to the clipboard, e.g. to show a toast |
|
|
17
|
+
| onCopyError | `(error: unknown) => void` | - | Called when the clipboard write fails |
|
|
15
18
|
| overflow | `'scroll' \| 'wrap' \| 'ellipsis'` | `'scroll'` | How long lines behave: scroll horizontally, wrap (use for commands and prompts), or truncate with an ellipsis |
|
|
16
19
|
| maxHeight | `string` | - | Scrolls vertically past this height (any CSS length, e.g. `'19rem'`) |
|
|
17
20
|
| size | `'M' \| 'S'` | `'M'` | Text size. `S` is the compact size |
|
|
18
|
-
| native div props | `Omit<HTMLAttributes<HTMLDivElement>, 'children'>` | - | Passed to the root element. `aria-label` names the block when it scrolls (defaults to `Code`) |
|
|
21
|
+
| native div props | `Omit<HTMLAttributes<HTMLDivElement>, 'children' \| 'onCopy'>` | - | Passed to the root element. `aria-label` names the block when it scrolls (defaults to `Code`) |
|
|
19
22
|
|
|
20
23
|
## Examples
|
|
21
24
|
|
|
22
25
|
### Playground
|
|
23
26
|
|
|
24
27
|
```tsx
|
|
25
|
-
import { CodeBlock
|
|
28
|
+
import { CodeBlock } from '@redis-ui/components';
|
|
26
29
|
|
|
27
|
-
<CodeBlock code={lensSnippet} copyLabel="Copy code" overflow="scroll" size="M" />
|
|
30
|
+
<CodeBlock code={lensSnippet} language="typescript" copyLabel="Copy code" overflow="scroll" size="M" />
|
|
28
31
|
```
|
|
29
32
|
|
|
30
|
-
`codeBlockOverflows` and `codeBlockSizes` list the allowed `overflow` and `size` values, e.g. for controls.
|
|
33
|
+
`codeBlockLanguages`, `codeBlockOverflows` and `codeBlockSizes` list the allowed `language`, `overflow` and `size` values, e.g. for controls.
|
|
31
34
|
|
|
32
35
|
### Default
|
|
33
36
|
|
|
@@ -40,6 +43,7 @@ import { CodeBlock, codeBlockOverflows, codeBlockSizes } from '@redis-ui/compone
|
|
|
40
43
|
```tsx
|
|
41
44
|
<CodeBlock code={installCommand} copyLabel="Copy install command" />
|
|
42
45
|
<CodeBlock code={lensSnippet} copyLabel="Copy code" />
|
|
46
|
+
<CodeBlock code={lensSnippet} copyLabel="Copy code" onCopy={() => showToast('Code copied')} />
|
|
43
47
|
```
|
|
44
48
|
|
|
45
49
|
### WrappedCommand
|
|
@@ -86,8 +90,25 @@ import { CodeBlock, codeBlockSizes } from '@redis-ui/components';
|
|
|
86
90
|
))}
|
|
87
91
|
```
|
|
88
92
|
|
|
93
|
+
### Languages
|
|
94
|
+
|
|
95
|
+
> `language` highlights the syntax of bash, JSON, Python or TypeScript code.
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
import { CodeBlock, codeBlockLanguages } from '@redis-ui/components';
|
|
99
|
+
|
|
100
|
+
{codeBlockLanguages.map((language) => (
|
|
101
|
+
<CodeBlock
|
|
102
|
+
key={language}
|
|
103
|
+
code={languageSnippets[language]}
|
|
104
|
+
language={language}
|
|
105
|
+
copyLabel="Copy code"
|
|
106
|
+
/>
|
|
107
|
+
))}
|
|
108
|
+
```
|
|
109
|
+
|
|
89
110
|
## Notes
|
|
90
111
|
- The component forwards refs to the root element.
|
|
91
112
|
- When the content scrolls, the block becomes keyboard-focusable so it can be scrolled with the keyboard. Truncated lines (`overflow="ellipsis"`) don't count.
|
|
92
113
|
- The copy button is `CopyToClipboardButton`, centered on the first code line in the top-right corner.
|
|
93
|
-
-
|
|
114
|
+
- Without `language`, `code` is rendered as plain text. With it, the syntax is highlighted with the VS palette in light themes and VS Code Dark+ in dark themes, and bash commands, including `npx` and `pip`, are colored as keywords.
|