@dbcdk/react-components 0.0.193 → 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.
@@ -31,6 +31,7 @@ function JsonViewer({
31
31
  className,
32
32
  maxHeight,
33
33
  appearance = "dark",
34
+ deleted = false,
34
35
  storageKey,
35
36
  borderless = false
36
37
  }) {
@@ -77,6 +78,10 @@ function JsonViewer({
77
78
  );
78
79
  const hasResults = normalizedQuery ? matches.size > 0 : true;
79
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(" ");
80
85
  const handleCopy = async (nodeId, rawValue) => {
81
86
  try {
82
87
  await navigator.clipboard.writeText(rawValue);
@@ -243,14 +248,14 @@ function JsonViewer({
243
248
  viewMode === "raw" ? /* @__PURE__ */ jsxRuntime.jsx(
244
249
  "pre",
245
250
  {
246
- className: styles__default.default.rawPane,
251
+ className: contentClassName,
247
252
  style: maxHeight !== void 0 ? { maxHeight: typeof maxHeight === "number" ? `${maxHeight}px` : maxHeight } : void 0,
248
253
  children: rawJson
249
254
  }
250
255
  ) : /* @__PURE__ */ jsxRuntime.jsx(
251
256
  "div",
252
257
  {
253
- className: styles__default.default.treePane,
258
+ className: contentClassName,
254
259
  role: "tree",
255
260
  "aria-label": "JSON-visning",
256
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
3
  export type { JsonViewerProps, JsonViewerViewMode } from './types';
4
- export declare function JsonViewer({ value, defaultExpandedDepth, expandAll, defaultViewMode, searchDebounceMs, helperText, searchPlaceholder, emptySearchText, className, maxHeight, appearance, storageKey, borderless, }: JsonViewerProps): JSX.Element;
4
+ export declare function JsonViewer({ value, defaultExpandedDepth, expandAll, defaultViewMode, searchDebounceMs, helperText, searchPlaceholder, emptySearchText, className, maxHeight, appearance, deleted, storageKey, borderless, }: JsonViewerProps): JSX.Element;
@@ -25,6 +25,7 @@ function JsonViewer({
25
25
  className,
26
26
  maxHeight,
27
27
  appearance = "dark",
28
+ deleted = false,
28
29
  storageKey,
29
30
  borderless = false
30
31
  }) {
@@ -71,6 +72,10 @@ function JsonViewer({
71
72
  );
72
73
  const hasResults = normalizedQuery ? matches.size > 0 : true;
73
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(" ");
74
79
  const handleCopy = async (nodeId, rawValue) => {
75
80
  try {
76
81
  await navigator.clipboard.writeText(rawValue);
@@ -237,14 +242,14 @@ function JsonViewer({
237
242
  viewMode === "raw" ? /* @__PURE__ */ jsx(
238
243
  "pre",
239
244
  {
240
- className: styles.rawPane,
245
+ className: contentClassName,
241
246
  style: maxHeight !== void 0 ? { maxHeight: typeof maxHeight === "number" ? `${maxHeight}px` : maxHeight } : void 0,
242
247
  children: rawJson
243
248
  }
244
249
  ) : /* @__PURE__ */ jsx(
245
250
  "div",
246
251
  {
247
- className: styles.treePane,
252
+ className: contentClassName,
248
253
  role: "tree",
249
254
  "aria-label": "JSON-visning",
250
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;
@@ -22,6 +22,8 @@ export interface JsonViewerProps {
22
22
  maxHeight?: number | string;
23
23
  /** Initial appearance. The user can toggle it via the kebab menu; defaults to 'dark'. */
24
24
  appearance?: JsonViewerAppearance;
25
+ /** Displays all JSON content in the theme's error color, for deleted or invalid content. */
26
+ deleted?: boolean;
25
27
  /**
26
28
  * When set, the user's appearance choice is persisted to localStorage
27
29
  * under `${storageKey}:appearance`.
@@ -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.193",
3
+ "version": "0.0.194",
4
4
  "description": "Reusable React components for DBC projects",
5
5
  "license": "ISC",
6
6
  "author": "",