@kolkrabbi/kol-component 0.12.3 → 0.12.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kolkrabbi/kol-component",
3
- "version": "0.12.3",
3
+ "version": "0.12.5",
4
4
  "description": "KOL design-system components — atoms through organisms, emitting canonical kol-* classes. Pairs with @kolkrabbi/kol-theme for styling.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -23,16 +23,17 @@
23
23
  "dependencies": {
24
24
  "@floating-ui/react": "^0.27.19",
25
25
  "embla-carousel-react": "^8.6.0",
26
- "@kolkrabbi/kol-icons": "0.8.0"
26
+ "react-syntax-highlighter": "^16.1.1",
27
+ "@kolkrabbi/kol-icons": "0.8.4"
27
28
  },
28
29
  "peerDependencies": {
29
- "react": "^18.3.0 || ^19.0.0",
30
- "react-dom": "^18.3.0 || ^19.0.0",
31
- "react-router-dom": "^6.0.0 || ^7.0.0",
32
30
  "framer-motion": "^12.0.0",
33
31
  "gsap": "^3.13.0",
34
32
  "hls.js": "^1.6.0",
35
- "opentype.js": "^1.3.4"
33
+ "opentype.js": "^1.3.4",
34
+ "react": "^18.3.0 || ^19.0.0",
35
+ "react-dom": "^18.3.0 || ^19.0.0",
36
+ "react-router-dom": "^6.0.0 || ^7.0.0"
36
37
  },
37
38
  "peerDependenciesMeta": {
38
39
  "react-router-dom": {
@@ -1,27 +1,122 @@
1
- import CopyButton from '../atoms/CopyButton.jsx'
1
+ import { useState } from 'react'
2
+ import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
3
+ import { oneDark } from 'react-syntax-highlighter/dist/esm/styles/prism'
4
+ import { Icon } from '@kolkrabbi/kol-icons'
2
5
 
3
6
  /**
4
- * CodeBlock — a chrome'd code block with language chip, filename chip, and copy.
7
+ * CodeBlock — REPLICATED from the elder reference
8
+ * (kol-website/packages/ui/src/molecules/CodeBlock.jsx, 2026-07-28 user
9
+ * mandate): react-syntax-highlighter (Prism) with the oneDark theme flattened
10
+ * onto KOL chrome — transparent bg, 14px/1.6 mono, no text-shadow — a single
11
+ * filename-or-language chip, and a 32×32 icon copy button (`copy` glyph →
12
+ * check on copied). Chrome lives in kol-theme (kol-components-molecules.css).
5
13
  *
6
- * Accepts three input shapes (first match wins per field):
7
- * • Portable Text: `value={{ code, language, filename }}` — the Sanity code-block
8
- * object can be passed straight through from a portable-text map.
9
- * • Direct props: `code` / `language` / `filename`.
10
- * • Children: `<CodeBlock language="js">{'…'}</CodeBlock>` (the original API).
11
- *
12
- * DOM order is copy → filename → lang → pre so the `.kol-codeblock-*` + pre
13
- * adjacency rules in the chrome CSS can pad the pre when chips are present.
14
+ * Input shapes (first match wins per field):
15
+ * • Portable Text: `value={{ code, language, filename }}`
16
+ * Direct props: `code` / `language` / `filename`
17
+ * • Children: `<CodeBlock language="js">{'…'}</CodeBlock>`
14
18
  */
15
- export default function CodeBlock({ children, code, language, filename, value }) {
16
- const src = code ?? value?.code ?? children
17
- const lang = language ?? value?.language
18
- const file = filename ?? value?.filename
19
+
20
+ const CheckMarkIcon = () => (
21
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
22
+ <path d="M19.4697 6.41987C19.7626 6.12697 20.2373 6.12697 20.5302 6.41987C20.8231 6.71276 20.8231 7.18752 20.5302 7.48041L10.9443 17.0663C9.87038 18.1401 8.12951 18.1401 7.05561 17.0663L3.46967 13.4804C3.17678 13.1875 3.17678 12.7128 3.46967 12.4199C3.76256 12.127 4.23732 12.127 4.53022 12.4199L8.11615 16.0058C8.60427 16.4938 9.39561 16.4938 9.88373 16.0058L19.4697 6.41987Z" fill="currentColor"/>
23
+ </svg>
24
+ )
25
+
26
+ const syntaxTheme = (foregroundToken = 80) => ({
27
+ ...oneDark,
28
+ 'pre[class*="language-"]': {
29
+ ...oneDark['pre[class*="language-"]'],
30
+ background: 'transparent',
31
+ margin: 0,
32
+ padding: 0,
33
+ fontSize: '14px',
34
+ lineHeight: '1.6',
35
+ textShadow: 'none',
36
+ letterSpacing: '0',
37
+ overflow: 'visible',
38
+ border: 'none',
39
+ borderRadius: 0,
40
+ color: `color-mix(in srgb, var(--kol-surface-on-primary) ${foregroundToken}%, transparent)`
41
+ },
42
+ 'code[class*="language-"]': {
43
+ ...oneDark['code[class*="language-"]'],
44
+ background: 'transparent',
45
+ fontFamily: 'var(--kol-font-family-mono)',
46
+ fontSize: '14px',
47
+ textShadow: 'none',
48
+ letterSpacing: '0',
49
+ textDecoration: 'none',
50
+ display: 'block',
51
+ borderRadius: 0,
52
+ border: 'none',
53
+ color: `color-mix(in srgb, var(--kol-surface-on-primary) ${foregroundToken}%, transparent)`
54
+ },
55
+ comment: {
56
+ ...oneDark['comment'],
57
+ fontStyle: 'normal'
58
+ }
59
+ })
60
+
61
+ export default function CodeBlock({ children, code: codeProp, language: languageProp, filename: filenameProp, value }) {
62
+ const [copied, setCopied] = useState(false)
63
+
64
+ const code = String(value?.code ?? codeProp ?? children ?? '')
65
+ const language = value?.language ?? languageProp ?? 'text'
66
+ const filename = value?.filename ?? filenameProp
67
+
68
+ const handleCopy = async () => {
69
+ try {
70
+ await navigator.clipboard.writeText(code)
71
+ setCopied(true)
72
+ setTimeout(() => setCopied(false), 2000)
73
+ } catch {
74
+ /* clipboard blocked — silent */
75
+ }
76
+ }
77
+
19
78
  return (
20
- <div className="kol-codeblock">
21
- <CopyButton text={String(src ?? '')} className="kol-codeblock-copy" />
22
- {file && <span className="kol-codeblock-filename">{file}</span>}
23
- {lang && <span className="kol-codeblock-lang">{lang}</span>}
24
- <pre><code>{src}</code></pre>
79
+ <div className="kol-codeblock-wrapper">
80
+ <div className="kol-codeblock">
81
+ {(filename || (language && language !== 'text')) && (
82
+ <div className="kol-codeblock-filename">{filename || language}</div>
83
+ )}
84
+ <SyntaxHighlighter
85
+ language={language}
86
+ style={syntaxTheme(80)}
87
+ customStyle={{
88
+ margin: 0,
89
+ padding: 0,
90
+ background: 'transparent',
91
+ whiteSpace: 'pre-wrap',
92
+ wordBreak: 'break-word',
93
+ overflow: 'visible',
94
+ height: 'auto',
95
+ maxHeight: 'none',
96
+ }}
97
+ wrapLines={true}
98
+ wrapLongLines={true}
99
+ PreTag="div"
100
+ lineProps={{
101
+ style: {
102
+ border: 'none',
103
+ background: 'transparent',
104
+ display: 'block',
105
+ }
106
+ }}
107
+ >
108
+ {code}
109
+ </SyntaxHighlighter>
110
+ <button
111
+ type="button"
112
+ className="kol-codeblock-copy"
113
+ onClick={handleCopy}
114
+ aria-label={copied ? 'Code copied!' : 'Copy code'}
115
+ title={copied ? 'Code copied!' : 'Copy code'}
116
+ >
117
+ {copied ? <CheckMarkIcon /> : <Icon name="copy" size={16} />}
118
+ </button>
119
+ </div>
25
120
  </div>
26
121
  )
27
122
  }