@synerise/ds-code-snippet 1.2.1 → 1.2.2

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/CLAUDE.md +128 -0
  3. package/package.json +9 -8
package/CHANGELOG.md CHANGED
@@ -3,6 +3,10 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.2.2](https://github.com/Synerise/synerise-design/compare/@synerise/ds-code-snippet@1.2.1...@synerise/ds-code-snippet@1.2.2) (2026-07-23)
7
+
8
+ **Note:** Version bump only for package @synerise/ds-code-snippet
9
+
6
10
  ## [1.2.1](https://github.com/Synerise/synerise-design/compare/@synerise/ds-code-snippet@1.2.0...@synerise/ds-code-snippet@1.2.1) (2026-07-16)
7
11
 
8
12
  **Note:** Version bump only for package @synerise/ds-code-snippet
package/CLAUDE.md ADDED
@@ -0,0 +1,128 @@
1
+ # CodeSnippet (`@synerise/ds-code-snippet`)
2
+
3
+ > Displays code in three variants — inline, single-line, and expandable multi-line — with optional syntax highlighting, copy-to-clipboard, and animated expand/collapse.
4
+
5
+ ## Package structure
6
+
7
+ ```
8
+ src/
9
+ CodeSnippet.tsx — main component, switches between three variants
10
+ CodeSnippet.types.ts — CodeSnippetType enum, FontSize enum, CodeSnippetProps
11
+ CodeSnippet.figma.tsx — Figma Code Connect mappings
12
+ index.ts — public exports
13
+ style/
14
+ index.less — IBM Plex Mono font-face declarations
15
+ CodeTypes/
16
+ InlineCode/ — <code> element with pink background; no copy button
17
+ SingleCode/ — single-line block with copy icon
18
+ MultiCode/ — multi-line block with expand/collapse + syntax highlight
19
+ Highlight/
20
+ Highlight.tsx — wraps children with highlight.js, async language loading
21
+ Highlight.types.ts — HighlightProps, LanguageHighlight (190+ language union)
22
+ Highlight.styles.ts — design token-mapped hljs colour classes
23
+ ```
24
+
25
+ ## Public exports
26
+
27
+ ### `CodeSnippet` (default export)
28
+
29
+ No `forwardRef`. Routes to `InlineCode`, `SingleCode`, or `MultiCode` based on `type`.
30
+
31
+ | Prop | Type | Default | Description |
32
+ |------|------|---------|-------------|
33
+ | `type` | `CodeSnippetType` | `CodeSnippetType.INLINE` | Which variant to render. |
34
+ | `children` | `string` | `''` | The code content. Must be a string, not JSX. |
35
+ | `className` | `string` | `undefined` | Applied to the root wrapper. |
36
+ | `style` | `React.CSSProperties` | `undefined` | Inline styles on the root. _(only forwarded to SingleCode — not all variants)_ |
37
+ | `fontSize` | `FontSize` | `FontSize.SMALL` (12) | `FontSize.SMALL = 12` or `FontSize.MEDIUM = 14`. |
38
+ | `colorSyntax` | `boolean` | `false` | Enables highlight.js syntax colouring. Multi-line only. |
39
+ | `languages` | `LanguageHighlight[]` | `['javascript', 'typescript', 'json']` | Languages to register with highlight.js. |
40
+ | `rows` | `number` | `6` | Visible line count before expand button appears. Multi-line only. |
41
+ | `expanded` | `boolean` | `false` | Initial expanded state. Multi-line only. |
42
+ | `wrap` | `boolean` | `false` | Enables `white-space: pre-wrap`. Multi-line only. |
43
+ | `overscrollBehavior` | `OverscrollBehavior` | `'contain'` | `'contain' \| 'auto' \| 'none'`, re-exported from `@synerise/ds-scrollbar`. Forwarded to the scroll container; controls scroll chaining to the parent. Multi-line only. |
44
+ | `tooltipTitleHover` | `string` | `'Copy'` | Tooltip text before copy. Single-line and multi-line. |
45
+ | `tooltipTitleClick` | `string` | `'Copied!'` | Tooltip text after copy. |
46
+ | `labelBeforeExpanded` | `string` | `'Show more'` | Expand button label. |
47
+ | `labelAfterExpanded` | `string` | `'Show less'` | Collapse button label. |
48
+ | `hideExpandButton` | `boolean` | `false` | Hides the expand/collapse button. Multi-line only. |
49
+ | `hideCopyButton` | `boolean` | `false` | Hides the copy icon. Multi-line only. |
50
+ | `customTriggerComponent` | `ReactNode` | `undefined` | Replaces the default `DuplicateS` copy icon. Single-line and multi-line. |
51
+ | `onExpand` | `() => void` | `undefined` | Extra callback on expand/collapse click. |
52
+ | `onCopy` | `() => void` | `undefined` | Extra callback on copy. |
53
+
54
+ ### `CodeSnippetType` (enum)
55
+
56
+ ```ts
57
+ enum CodeSnippetType {
58
+ INLINE = 'inline',
59
+ SINGLE_LINE = 'single-line',
60
+ MULTI_LINE = 'multi-line',
61
+ }
62
+ ```
63
+
64
+ ### `FontSize` (enum)
65
+
66
+ ```ts
67
+ enum FontSize {
68
+ SMALL = 12,
69
+ MEDIUM = 14,
70
+ }
71
+ ```
72
+
73
+ ### `CodeSnippetProps` (type)
74
+
75
+ Re-exported props interface.
76
+
77
+ ## Usage patterns
78
+
79
+ ```tsx
80
+ import CodeSnippet, { CodeSnippetType } from '@synerise/ds-code-snippet';
81
+ import { FontSize } from '@synerise/ds-code-snippet';
82
+
83
+ // Inline (default)
84
+ <CodeSnippet>some_variable</CodeSnippet>
85
+
86
+ // Single-line with copy
87
+ <CodeSnippet type={CodeSnippetType.SINGLE_LINE} fontSize={FontSize.SMALL}>
88
+ npm install @synerise/ds-button
89
+ </CodeSnippet>
90
+
91
+ // Multi-line with syntax highlighting and expand
92
+ <CodeSnippet
93
+ type={CodeSnippetType.MULTI_LINE}
94
+ colorSyntax
95
+ languages={['javascript']}
96
+ rows={4}
97
+ labelBeforeExpanded="Show more"
98
+ labelAfterExpanded="Show less"
99
+ >
100
+ {codeString}
101
+ </CodeSnippet>
102
+ ```
103
+
104
+ ## Styling
105
+
106
+ - Styles split across `InlineCode.styles.ts`, `SingleCode.styles.ts`, `MultiCode.styles.ts`, `Highlight.styles.ts`.
107
+ - Uses `@synerise/ds-core` theme palette tokens (e.g. `props.theme.palette['grey-100']`).
108
+ - Font loaded via `src/style/index.less` — imports IBM Plex Mono WOFF files. The Less file is compiled separately (`build:css` script) and must be imported as a side effect: `import './style/index.less'` (already done in `CodeSnippet.tsx`).
109
+ - Inline variant uses a hardcoded `#e31a5d` for the code text colour (not a token).
110
+
111
+ ## Key dependencies
112
+
113
+ - `highlight.js` — syntax colouring; languages are loaded **asynchronously** via dynamic `import()` in `Highlight.tsx`
114
+ - `react-animate-height` — smooth expand/collapse animation in `MultiCode` (300ms duration)
115
+ - `@synerise/ds-copy-icon` — copy-to-clipboard button with tooltip state management
116
+ - `@synerise/ds-scrollbar` — custom scrollbar for multi-line code content
117
+
118
+ ## Implementation notes
119
+
120
+ - **`children` must be a plain string**, not JSX. All three code type components type `children` as `string`.
121
+ - **Syntax highlighting is async** — `Highlight` dynamically imports each language module on mount/update. There may be a brief flash of unstyled code before highlighting applies.
122
+ - **`rows` controls both the expand threshold and the initial height** — the expand button only appears when the actual line count exceeds `rows + 1`. Height is calculated as `(rows + 1) * 17px` (LINE_HEIGHT_DEFAULT).
123
+ - **`expanded` prop** sets the initial state but the component controls its own expand/collapse state after mount (`useState(expanded)`). It is not a fully controlled prop.
124
+ - **`style` prop** is declared in `CodeSnippetProps` but only forwarded to the `SingleCode` path — not `InlineCode` or `MultiCode`.
125
+ - **`colorSyntax` and `languages`** are only meaningful for `CodeSnippetType.MULTI_LINE`; they are silently ignored for other types.
126
+ - **`hideExpandButton` and `hideCopyButton`** are only forwarded to `MultiCode`; they have no effect on `INLINE` or `SINGLE_LINE`.
127
+ - **Font-face declarations** are in a `.less` file compiled as a CSS side effect. If the Less build step is skipped, IBM Plex Mono will not load.
128
+ - **`tooltipHint` prop** appears in the README but does **not exist** in `CodeSnippetProps` — it was removed. The correct props are `tooltipTitleHover` and `tooltipTitleClick`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-code-snippet",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "CodeSnippet UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "Synerise/synerise-design",
@@ -18,6 +18,7 @@
18
18
  "/dist",
19
19
  "/fonts",
20
20
  "CHANGELOG.md",
21
+ "CLAUDE.md",
21
22
  "README.md",
22
23
  "package.json",
23
24
  "LICENSE.md"
@@ -42,12 +43,12 @@
42
43
  ],
43
44
  "types": "dist/index.d.ts",
44
45
  "dependencies": {
45
- "@synerise/ds-button": "^1.5.34",
46
- "@synerise/ds-copy-icon": "^1.2.15",
47
- "@synerise/ds-icon": "^1.18.4",
48
- "@synerise/ds-scrollbar": "^1.5.1",
49
- "@synerise/ds-tooltip": "^1.5.3",
50
- "@synerise/ds-utils": "^1.10.1",
46
+ "@synerise/ds-button": "^1.5.35",
47
+ "@synerise/ds-copy-icon": "^1.2.16",
48
+ "@synerise/ds-icon": "^1.18.5",
49
+ "@synerise/ds-scrollbar": "^1.5.2",
50
+ "@synerise/ds-tooltip": "^1.5.4",
51
+ "@synerise/ds-utils": "^1.10.2",
51
52
  "highlight.js": "^10.7.2",
52
53
  "react-animate-height": "^2.0.23"
53
54
  },
@@ -60,5 +61,5 @@
60
61
  "react": ">=16.9.0 <= 18.3.1",
61
62
  "styled-components": "^5.3.3"
62
63
  },
63
- "gitHead": "a81ab6519d49a3dea9c0cfebcdc9104cbb4f4226"
64
+ "gitHead": "d0a43cc43d8528a36f105aceea52ab470edb71d9"
64
65
  }