@dbcdk/react-components 0.0.192 → 0.0.194

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.
@@ -23,6 +23,7 @@ function JsonViewer({
23
23
  value,
24
24
  defaultExpandedDepth = 2,
25
25
  expandAll = false,
26
+ defaultViewMode = "tree",
26
27
  searchDebounceMs = 800,
27
28
  helperText,
28
29
  searchPlaceholder = "S\xF8g i n\xF8gler, stier og v\xE6rdier",
@@ -30,6 +31,7 @@ function JsonViewer({
30
31
  className,
31
32
  maxHeight,
32
33
  appearance = "dark",
34
+ deleted = false,
33
35
  storageKey,
34
36
  borderless = false
35
37
  }) {
@@ -44,7 +46,7 @@ function JsonViewer({
44
46
  validate: (stored) => stored === "dark" || stored === "light"
45
47
  });
46
48
  const { value: viewMode, setValue: setViewMode } = usePersistentState.usePersistentState({
47
- initialValue: "tree",
49
+ initialValue: defaultViewMode,
48
50
  storageKey: storageKey ? `${storageKey}:viewMode` : void 0,
49
51
  validate: (stored) => stored === "tree" || stored === "raw"
50
52
  });
@@ -76,6 +78,10 @@ function JsonViewer({
76
78
  );
77
79
  const hasResults = normalizedQuery ? matches.size > 0 : true;
78
80
  const rawJson = react.useMemo(() => JSON.stringify(safeValue, null, 2), [safeValue]);
81
+ const contentClassName = [
82
+ viewMode === "raw" ? styles__default.default.rawPane : styles__default.default.treePane,
83
+ deleted ? styles__default.default.deleted : ""
84
+ ].filter(Boolean).join(" ");
79
85
  const handleCopy = async (nodeId, rawValue) => {
80
86
  try {
81
87
  await navigator.clipboard.writeText(rawValue);
@@ -242,14 +248,14 @@ function JsonViewer({
242
248
  viewMode === "raw" ? /* @__PURE__ */ jsxRuntime.jsx(
243
249
  "pre",
244
250
  {
245
- className: styles__default.default.rawPane,
251
+ className: contentClassName,
246
252
  style: maxHeight !== void 0 ? { maxHeight: typeof maxHeight === "number" ? `${maxHeight}px` : maxHeight } : void 0,
247
253
  children: rawJson
248
254
  }
249
255
  ) : /* @__PURE__ */ jsxRuntime.jsx(
250
256
  "div",
251
257
  {
252
- className: styles__default.default.treePane,
258
+ className: contentClassName,
253
259
  role: "tree",
254
260
  "aria-label": "JSON-visning",
255
261
  style: maxHeight !== void 0 ? { maxHeight: typeof maxHeight === "number" ? `${maxHeight}px` : maxHeight } : void 0,
@@ -1,4 +1,4 @@
1
1
  import type { JSX } from 'react';
2
2
  import type { JsonViewerProps } from './types';
3
- export type { JsonViewerProps } from './types';
4
- export declare function JsonViewer({ value, defaultExpandedDepth, expandAll, searchDebounceMs, helperText, searchPlaceholder, emptySearchText, className, maxHeight, appearance, storageKey, borderless, }: JsonViewerProps): JSX.Element;
3
+ export type { JsonViewerProps, JsonViewerViewMode } from './types';
4
+ export declare function JsonViewer({ value, defaultExpandedDepth, expandAll, defaultViewMode, searchDebounceMs, helperText, searchPlaceholder, emptySearchText, className, maxHeight, appearance, deleted, storageKey, borderless, }: JsonViewerProps): JSX.Element;
@@ -17,6 +17,7 @@ function JsonViewer({
17
17
  value,
18
18
  defaultExpandedDepth = 2,
19
19
  expandAll = false,
20
+ defaultViewMode = "tree",
20
21
  searchDebounceMs = 800,
21
22
  helperText,
22
23
  searchPlaceholder = "S\xF8g i n\xF8gler, stier og v\xE6rdier",
@@ -24,6 +25,7 @@ function JsonViewer({
24
25
  className,
25
26
  maxHeight,
26
27
  appearance = "dark",
28
+ deleted = false,
27
29
  storageKey,
28
30
  borderless = false
29
31
  }) {
@@ -38,7 +40,7 @@ function JsonViewer({
38
40
  validate: (stored) => stored === "dark" || stored === "light"
39
41
  });
40
42
  const { value: viewMode, setValue: setViewMode } = usePersistentState({
41
- initialValue: "tree",
43
+ initialValue: defaultViewMode,
42
44
  storageKey: storageKey ? `${storageKey}:viewMode` : void 0,
43
45
  validate: (stored) => stored === "tree" || stored === "raw"
44
46
  });
@@ -70,6 +72,10 @@ function JsonViewer({
70
72
  );
71
73
  const hasResults = normalizedQuery ? matches.size > 0 : true;
72
74
  const rawJson = useMemo(() => JSON.stringify(safeValue, null, 2), [safeValue]);
75
+ const contentClassName = [
76
+ viewMode === "raw" ? styles.rawPane : styles.treePane,
77
+ deleted ? styles.deleted : ""
78
+ ].filter(Boolean).join(" ");
73
79
  const handleCopy = async (nodeId, rawValue) => {
74
80
  try {
75
81
  await navigator.clipboard.writeText(rawValue);
@@ -236,14 +242,14 @@ function JsonViewer({
236
242
  viewMode === "raw" ? /* @__PURE__ */ jsx(
237
243
  "pre",
238
244
  {
239
- className: styles.rawPane,
245
+ className: contentClassName,
240
246
  style: maxHeight !== void 0 ? { maxHeight: typeof maxHeight === "number" ? `${maxHeight}px` : maxHeight } : void 0,
241
247
  children: rawJson
242
248
  }
243
249
  ) : /* @__PURE__ */ jsx(
244
250
  "div",
245
251
  {
246
- className: styles.treePane,
252
+ className: contentClassName,
247
253
  role: "tree",
248
254
  "aria-label": "JSON-visning",
249
255
  style: maxHeight !== void 0 ? { maxHeight: typeof maxHeight === "number" ? `${maxHeight}px` : maxHeight } : void 0,
@@ -165,6 +165,11 @@
165
165
  font-size: inherit;
166
166
  }
167
167
 
168
+ .deleted,
169
+ .deleted * {
170
+ color: var(--color-status-error);
171
+ }
172
+
168
173
  .node {
169
174
  display: flex;
170
175
  flex-direction: column;
@@ -8,10 +8,12 @@ export type SearchMatch = {
8
8
  descendant: boolean;
9
9
  };
10
10
  export type JsonViewerAppearance = 'dark' | 'light';
11
+ export type JsonViewerViewMode = 'tree' | 'raw';
11
12
  export interface JsonViewerProps {
12
13
  value: unknown;
13
14
  defaultExpandedDepth?: number;
14
15
  expandAll?: boolean;
16
+ defaultViewMode?: JsonViewerViewMode;
15
17
  searchDebounceMs?: number;
16
18
  helperText?: string;
17
19
  searchPlaceholder?: string;
@@ -20,6 +22,8 @@ export interface JsonViewerProps {
20
22
  maxHeight?: number | string;
21
23
  /** Initial appearance. The user can toggle it via the kebab menu; defaults to 'dark'. */
22
24
  appearance?: JsonViewerAppearance;
25
+ /** Displays all JSON content in the theme's error color, for deleted or invalid content. */
26
+ deleted?: boolean;
23
27
  /**
24
28
  * When set, the user's appearance choice is persisted to localStorage
25
29
  * under `${storageKey}:appearance`.
@@ -30,6 +30,8 @@ function LineViewer({
30
30
  lines,
31
31
  size = "md",
32
32
  appearance = "dark",
33
+ defaultViewMode = "highlighted",
34
+ deleted = false,
33
35
  storageKey,
34
36
  borderless = false
35
37
  }) {
@@ -41,7 +43,7 @@ function LineViewer({
41
43
  validate: (stored) => stored === "dark" || stored === "light"
42
44
  });
43
45
  const { value: viewMode, setValue: setViewMode } = usePersistentState.usePersistentState({
44
- initialValue: "highlighted",
46
+ initialValue: defaultViewMode,
45
47
  storageKey: storageKey ? `${storageKey}:viewMode` : void 0,
46
48
  validate: (stored) => stored === "highlighted" || stored === "raw"
47
49
  });
@@ -158,7 +160,12 @@ function LineViewer({
158
160
  /* @__PURE__ */ jsxRuntime.jsx(
159
161
  "pre",
160
162
  {
161
- className: [styles__default.default.codePane, styles__default.default[size], wrap ? styles__default.default.wrap : styles__default.default.noWrap].join(" "),
163
+ className: [
164
+ styles__default.default.codePane,
165
+ styles__default.default[size],
166
+ wrap ? styles__default.default.wrap : styles__default.default.noWrap,
167
+ deleted ? styles__default.default.deleted : ""
168
+ ].filter(Boolean).join(" "),
162
169
  tabIndex: 0,
163
170
  onDoubleClick: handleDoubleClick,
164
171
  children: /* @__PURE__ */ jsxRuntime.jsx("code", { ref: codeRef, children: viewMode === "raw" ? lines : tokens.map((token, index) => {
@@ -1,10 +1,15 @@
1
1
  import type { JSX } from 'react';
2
2
  export type LineViewerAppearance = 'dark' | 'light';
3
+ export type LineViewerViewMode = 'highlighted' | 'raw';
3
4
  export interface LineViewerProps {
4
5
  lines: string;
5
6
  size?: 'xs' | 'sm' | 'md' | 'lg';
6
7
  /** Initial appearance. The user can toggle it via the kebab menu; defaults to 'dark'. */
7
8
  appearance?: LineViewerAppearance;
9
+ /** Initial view mode. The user can toggle it via the kebab menu; defaults to 'highlighted'. */
10
+ defaultViewMode?: LineViewerViewMode;
11
+ /** Displays all line text in the theme's error color, for deleted or invalid content. */
12
+ deleted?: boolean;
8
13
  /**
9
14
  * When set, the user's appearance/view-mode/wrap choices are persisted to
10
15
  * localStorage under `${storageKey}:appearance` etc.
@@ -17,4 +22,4 @@ export interface LineViewerProps {
17
22
  */
18
23
  borderless?: boolean;
19
24
  }
20
- export declare function LineViewer({ lines, size, appearance, storageKey, borderless, }: LineViewerProps): JSX.Element;
25
+ export declare function LineViewer({ lines, size, appearance, defaultViewMode, deleted, storageKey, borderless, }: LineViewerProps): JSX.Element;
@@ -24,6 +24,8 @@ function LineViewer({
24
24
  lines,
25
25
  size = "md",
26
26
  appearance = "dark",
27
+ defaultViewMode = "highlighted",
28
+ deleted = false,
27
29
  storageKey,
28
30
  borderless = false
29
31
  }) {
@@ -35,7 +37,7 @@ function LineViewer({
35
37
  validate: (stored) => stored === "dark" || stored === "light"
36
38
  });
37
39
  const { value: viewMode, setValue: setViewMode } = usePersistentState({
38
- initialValue: "highlighted",
40
+ initialValue: defaultViewMode,
39
41
  storageKey: storageKey ? `${storageKey}:viewMode` : void 0,
40
42
  validate: (stored) => stored === "highlighted" || stored === "raw"
41
43
  });
@@ -152,7 +154,12 @@ function LineViewer({
152
154
  /* @__PURE__ */ jsx(
153
155
  "pre",
154
156
  {
155
- className: [styles.codePane, styles[size], wrap ? styles.wrap : styles.noWrap].join(" "),
157
+ className: [
158
+ styles.codePane,
159
+ styles[size],
160
+ wrap ? styles.wrap : styles.noWrap,
161
+ deleted ? styles.deleted : ""
162
+ ].filter(Boolean).join(" "),
156
163
  tabIndex: 0,
157
164
  onDoubleClick: handleDoubleClick,
158
165
  children: /* @__PURE__ */ jsx("code", { ref: codeRef, children: viewMode === "raw" ? lines : tokens.map((token, index) => {
@@ -5,9 +5,17 @@
5
5
 
6
6
  --line-tag: color-mix(in oklab, var(--color-fg-inverse) 66%, var(--color-syntax-accent) 34%);
7
7
  --line-indicator: color-mix(in oklab, var(--color-fg-inverse) 46%, transparent);
8
- --line-subfield-code: color-mix(in oklab, var(--color-fg-inverse) 30%, var(--color-syntax-number) 70%);
8
+ --line-subfield-code: color-mix(
9
+ in oklab,
10
+ var(--color-fg-inverse) 30%,
11
+ var(--color-syntax-number) 70%
12
+ );
9
13
  --line-value: color-mix(in oklab, var(--color-fg-inverse) 20%, var(--color-syntax-string) 80%);
10
- --line-terminator: color-mix(in oklab, var(--color-fg-inverse) 30%, var(--color-syntax-boolean) 70%);
14
+ --line-terminator: color-mix(
15
+ in oklab,
16
+ var(--color-fg-inverse) 30%,
17
+ var(--color-syntax-boolean) 70%
18
+ );
11
19
  --line-punctuation: color-mix(in oklab, var(--color-fg-inverse) 60%, transparent);
12
20
  --line-continuation: color-mix(in oklab, var(--color-fg-inverse) 46%, transparent);
13
21
 
@@ -57,6 +65,11 @@
57
65
  line-height: 1.35;
58
66
  }
59
67
 
68
+ .deleted code,
69
+ .deleted code * {
70
+ color: var(--color-status-error);
71
+ }
72
+
60
73
  .wrap {
61
74
  white-space: pre-wrap;
62
75
  overflow-wrap: break-word;
@@ -31,6 +31,8 @@ function XmlViewer({
31
31
  xml,
32
32
  size = "md",
33
33
  appearance = "dark",
34
+ defaultViewMode = "highlighted",
35
+ deleted = false,
34
36
  storageKey,
35
37
  borderless = false
36
38
  }) {
@@ -42,7 +44,7 @@ function XmlViewer({
42
44
  validate: (stored) => stored === "dark" || stored === "light"
43
45
  });
44
46
  const { value: viewMode, setValue: setViewMode } = usePersistentState.usePersistentState({
45
- initialValue: "highlighted",
47
+ initialValue: defaultViewMode,
46
48
  storageKey: storageKey ? `${storageKey}:viewMode` : void 0,
47
49
  validate: (stored) => stored === "highlighted" || stored === "raw"
48
50
  });
@@ -159,7 +161,12 @@ function XmlViewer({
159
161
  /* @__PURE__ */ jsxRuntime.jsx(
160
162
  "pre",
161
163
  {
162
- className: [styles__default.default.codePane, styles__default.default[size], wrap ? styles__default.default.wrap : styles__default.default.noWrap].join(" "),
164
+ className: [
165
+ styles__default.default.codePane,
166
+ styles__default.default[size],
167
+ wrap ? styles__default.default.wrap : styles__default.default.noWrap,
168
+ deleted ? styles__default.default.deleted : ""
169
+ ].filter(Boolean).join(" "),
163
170
  tabIndex: 0,
164
171
  onDoubleClick: handleDoubleClick,
165
172
  children: /* @__PURE__ */ jsxRuntime.jsx("code", { ref: codeRef, children: viewMode === "raw" ? xml : tokens.map((token, index) => {
@@ -1,10 +1,15 @@
1
1
  import type { JSX } from 'react';
2
2
  export type XmlViewerAppearance = 'dark' | 'light';
3
+ type ViewMode = 'highlighted' | 'raw';
3
4
  export interface XmlViewerProps {
4
5
  xml: string;
5
6
  size?: 'xs' | 'sm' | 'md' | 'lg';
6
7
  /** Initial appearance. The user can toggle it via the kebab menu; defaults to 'dark'. */
7
8
  appearance?: XmlViewerAppearance;
9
+ /** Initial view mode. The user can toggle it via the kebab menu; defaults to 'highlighted'. */
10
+ defaultViewMode?: ViewMode;
11
+ /** Displays all XML text in the theme's error color, for deleted or invalid content. */
12
+ deleted?: boolean;
8
13
  /**
9
14
  * When set, the user's appearance/view-mode/wrap choices are persisted to
10
15
  * localStorage under `${storageKey}:appearance` etc.
@@ -17,4 +22,5 @@ export interface XmlViewerProps {
17
22
  */
18
23
  borderless?: boolean;
19
24
  }
20
- export declare function XmlViewer({ xml, size, appearance, storageKey, borderless, }: XmlViewerProps): JSX.Element;
25
+ export declare function XmlViewer({ xml, size, appearance, defaultViewMode, deleted, storageKey, borderless, }: XmlViewerProps): JSX.Element;
26
+ export {};
@@ -25,6 +25,8 @@ function XmlViewer({
25
25
  xml,
26
26
  size = "md",
27
27
  appearance = "dark",
28
+ defaultViewMode = "highlighted",
29
+ deleted = false,
28
30
  storageKey,
29
31
  borderless = false
30
32
  }) {
@@ -36,7 +38,7 @@ function XmlViewer({
36
38
  validate: (stored) => stored === "dark" || stored === "light"
37
39
  });
38
40
  const { value: viewMode, setValue: setViewMode } = usePersistentState({
39
- initialValue: "highlighted",
41
+ initialValue: defaultViewMode,
40
42
  storageKey: storageKey ? `${storageKey}:viewMode` : void 0,
41
43
  validate: (stored) => stored === "highlighted" || stored === "raw"
42
44
  });
@@ -153,7 +155,12 @@ function XmlViewer({
153
155
  /* @__PURE__ */ jsx(
154
156
  "pre",
155
157
  {
156
- className: [styles.codePane, styles[size], wrap ? styles.wrap : styles.noWrap].join(" "),
158
+ className: [
159
+ styles.codePane,
160
+ styles[size],
161
+ wrap ? styles.wrap : styles.noWrap,
162
+ deleted ? styles.deleted : ""
163
+ ].filter(Boolean).join(" "),
157
164
  tabIndex: 0,
158
165
  onDoubleClick: handleDoubleClick,
159
166
  children: /* @__PURE__ */ jsx("code", { ref: codeRef, children: viewMode === "raw" ? xml : tokens.map((token, index) => {
@@ -5,7 +5,11 @@
5
5
 
6
6
  --xml-tag: color-mix(in oklab, var(--color-fg-inverse) 66%, var(--color-syntax-accent) 34%);
7
7
  --xml-attr-name: color-mix(in oklab, var(--color-fg-inverse) 50%, var(--color-syntax-accent) 50%);
8
- --xml-attr-value: color-mix(in oklab, var(--color-fg-inverse) 20%, var(--color-syntax-string) 80%);
8
+ --xml-attr-value: color-mix(
9
+ in oklab,
10
+ var(--color-fg-inverse) 20%,
11
+ var(--color-syntax-string) 80%
12
+ );
9
13
  --xml-comment: color-mix(in oklab, var(--color-fg-inverse) 46%, transparent);
10
14
  --xml-punctuation: color-mix(in oklab, var(--color-fg-inverse) 60%, transparent);
11
15
 
@@ -53,6 +57,11 @@
53
57
  line-height: 1.35;
54
58
  }
55
59
 
60
+ .deleted code,
61
+ .deleted code * {
62
+ color: var(--color-status-error);
63
+ }
64
+
56
65
  .wrap {
57
66
  white-space: pre-wrap;
58
67
  overflow-wrap: break-word;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbcdk/react-components",
3
- "version": "0.0.192",
3
+ "version": "0.0.194",
4
4
  "description": "Reusable React components for DBC projects",
5
5
  "license": "ISC",
6
6
  "author": "",