@galaxy-io/dls 2.13.6 → 2.14.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.
@@ -11,6 +11,10 @@
11
11
  * Field's context (each gets the description, error and disabled state explicitly). It never
12
12
  * validates: duplicate or empty keys are the app's `error`. No 1.x equivalent.
13
13
  *
14
+ * `isMasked` draws every value field as a `PasswordInput` (dots, with a reveal toggle per row) for
15
+ * secrets such as `Authorization` headers or API keys. Masking is visual only: the values are still
16
+ * in state and in the DOM, so an app should never load a saved secret back into the field.
17
+ *
14
18
  * SSR: ids come from `useId`; focus moves run in an effect; nothing touches `window` or
15
19
  * `document` at module scope.
16
20
  */
@@ -72,6 +76,12 @@ export interface KeyValueInputProps extends AriaAttributes {
72
76
  * @default false
73
77
  */
74
78
  isGhost?: boolean;
79
+ /**
80
+ * Mask every value field (`PasswordInput`, with a reveal toggle per row) for secrets. Visual only:
81
+ * never load a saved secret back into the field. Keys stay plain text.
82
+ * @default false
83
+ */
84
+ isMasked?: boolean;
75
85
  /** Label above the rows, rendered through `Field`. For a horizontal layout or `actions`, wrap it in `Field`. */
76
86
  label?: string;
77
87
  /** Hint behind an info icon beside the label, shown in a `Tooltip` (through `Field`). */
@@ -9,6 +9,7 @@ import Field, { FieldSize } from "./Field.js";
9
9
  import { rootStyle, useOwnField } from "./internal/ownField.js";
10
10
  import { InputSize, InputVariant } from "./Input.js";
11
11
  import TextInput from "./TextInput.js";
12
+ import PasswordInput from "./PasswordInput.js";
12
13
  /* empty css */
13
14
  import { styled } from "@linaria/react";
14
15
  import { forwardRef, useEffect, useRef, useState } from "react";
@@ -29,6 +30,10 @@ import { PlusIcon, TrashIcon } from "@phosphor-icons/react";
29
30
  * Field's context (each gets the description, error and disabled state explicitly). It never
30
31
  * validates: duplicate or empty keys are the app's `error`. No 1.x equivalent.
31
32
  *
33
+ * `isMasked` draws every value field as a `PasswordInput` (dots, with a reveal toggle per row) for
34
+ * secrets such as `Authorization` headers or API keys. Masking is visual only: the values are still
35
+ * in state and in the DOM, so an app should never load a saved secret back into the field.
36
+ *
32
37
  * SSR: ids come from `useId`; focus moves run in an effect; nothing touches `window` or
33
38
  * `document` at module scope.
34
39
  */
@@ -168,7 +173,7 @@ function parseLines(text) {
168
173
  }
169
174
  /** The group, its rows and the add button, wired to the nearest Field (the input's own or the app's). */
170
175
  function KeyValueGroup({ keyValueProps, forwardedRef, isRoot }) {
171
- const { value, defaultValue = [], onChange, size = "MEDIUM", variant = "PRIMARY", isGhost = false, label: _label, labelTooltip: _labelTooltip, description: _description, error, isError = false, isDisabled = false, isReadOnly = false, isRequired = false, fillWidth = false, ariaLabel, id, "aria-describedby": ariaDescribedBy, className, style, ...rest } = keyValueProps;
176
+ const { value, defaultValue = [], onChange, size = "MEDIUM", variant = "PRIMARY", isGhost = false, isMasked = false, label: _label, labelTooltip: _labelTooltip, description: _description, error, isError = false, isDisabled = false, isReadOnly = false, isRequired = false, fillWidth = false, ariaLabel, id, "aria-describedby": ariaDescribedBy, className, style, ...rest } = keyValueProps;
172
177
  const { field, controlId: groupId, describedBy: fieldDescribedBy, isInvalid, hasName } = useFieldWiring({
173
178
  id,
174
179
  ariaLabel,
@@ -187,6 +192,7 @@ function KeyValueGroup({ keyValueProps, forwardedRef, isRoot }) {
187
192
  const pairsRef = useRef(pairs);
188
193
  pairsRef.current = pairs;
189
194
  const [announcement, setAnnouncement] = useState("");
195
+ const [revealedRows, setRevealedRows] = useState(() => /* @__PURE__ */ new Set());
190
196
  const keyRefs = useRef([]);
191
197
  const valueRefs = useRef([]);
192
198
  const addRef = useRef(null);
@@ -199,6 +205,23 @@ function KeyValueGroup({ keyValueProps, forwardedRef, isRoot }) {
199
205
  const announce = (message) => {
200
206
  setAnnouncement((previous) => previous === message ? `${message} ` : message);
201
207
  };
208
+ const setRowRevealed = (index, isRevealed) => {
209
+ setRevealedRows((previous) => {
210
+ const next = new Set(previous);
211
+ if (isRevealed) next.add(index);
212
+ else next.delete(index);
213
+ return next;
214
+ });
215
+ };
216
+ /** Re-indexes the revealed rows after rows `[start, start + removed)` become `added` new (masked) rows. */
217
+ const shiftRevealedRows = (start, removed, added) => {
218
+ setRevealedRows((previous) => {
219
+ const next = /* @__PURE__ */ new Set();
220
+ for (const index of previous) if (index < start) next.add(index);
221
+ else if (index >= start + removed) next.add(index - removed + added);
222
+ return next;
223
+ });
224
+ };
202
225
  const commit = (next) => {
203
226
  pairsRef.current = next;
204
227
  setPairs(next);
@@ -235,6 +258,7 @@ function KeyValueGroup({ keyValueProps, forwardedRef, isRoot }) {
235
258
  kind: "key",
236
259
  index: index - 1
237
260
  } : { kind: "add" };
261
+ shiftRevealedRows(index, 1, 0);
238
262
  commit(next);
239
263
  announce("Row removed");
240
264
  };
@@ -247,6 +271,7 @@ function KeyValueGroup({ keyValueProps, forwardedRef, isRoot }) {
247
271
  const parsed = parseLines(text);
248
272
  if (parsed.length === 0) return;
249
273
  const current = pairsRef.current;
274
+ shiftRevealedRows(index, 1, parsed.length);
250
275
  commit([
251
276
  ...current.slice(0, index),
252
277
  ...parsed,
@@ -265,6 +290,13 @@ function KeyValueGroup({ keyValueProps, forwardedRef, isRoot }) {
265
290
  (target.kind === "add" ? addRef.current : target.kind === "key" ? keyRefs.current[target.index] : valueRefs.current[target.index])?.focus();
266
291
  });
267
292
  useDevWarning(!hasName, "[@galaxy-io/dls] KeyValueInput has no accessible name. Pass `label`, wrap it in a labelled `Field`, or set `ariaLabel`.");
293
+ const ValueInput = isMasked ? PasswordInput : TextInput;
294
+ const maskedValueProps = (index) => isMasked ? {
295
+ autoComplete: "new-password",
296
+ isRevealed: revealedRows.has(index),
297
+ onRevealedChange: (isRevealed) => setRowRevealed(index, isRevealed),
298
+ revealAriaLabel: `Show value ${index + 1}`
299
+ } : {};
268
300
  const rows = pairs.map((pair, index) => ({
269
301
  pair,
270
302
  index
@@ -306,7 +338,7 @@ function KeyValueGroup({ keyValueProps, forwardedRef, isRoot }) {
306
338
  ...fieldDescribedBy === void 0 ? {} : { "aria-describedby": fieldDescribedBy }
307
339
  })
308
340
  }),
309
- /* @__PURE__ */ jsx(TextInput, {
341
+ /* @__PURE__ */ jsx(ValueInput, {
310
342
  ref: (element) => {
311
343
  valueRefs.current[index] = element;
312
344
  },
@@ -318,6 +350,7 @@ function KeyValueGroup({ keyValueProps, forwardedRef, isRoot }) {
318
350
  family: FontFamily.MONO,
319
351
  placeholder: "Value",
320
352
  ariaLabel: `Value ${rowNumber}`,
353
+ ...maskedValueProps(index),
321
354
  isError: isInvalid,
322
355
  isDisabled,
323
356
  isReadOnly,
@@ -6,6 +6,20 @@ export type PasswordInputProps = Omit<InputProps, "type" | "trailing" | "isClear
6
6
  * @default "current-password"
7
7
  */
8
8
  autoComplete?: InputProps["autoComplete"];
9
+ /** Controlled reveal state: `true` shows the value as text. Pass it with `onRevealedChange`. */
10
+ isRevealed?: boolean;
11
+ /**
12
+ * Initial reveal state while uncontrolled.
13
+ * @default false
14
+ */
15
+ defaultIsRevealed?: boolean;
16
+ /** Called with the next reveal state when the toggle is pressed. */
17
+ onRevealedChange?: (isRevealed: boolean) => void;
18
+ /**
19
+ * Accessible name of the reveal toggle. Name the field when several share a view ("Show value 2").
20
+ * @default "Show password"
21
+ */
22
+ revealAriaLabel?: string;
9
23
  };
10
24
  /** A masked single-line field with a "Show password" toggle: `Input` with `type="password"`. */
11
25
  declare const PasswordInput: import("react").ForwardRefExoticComponent<Omit<InputProps, "type" | "trailing" | "spellCheck" | "prefix" | "inputMode" | "suffix" | "autoComplete" | "isClearable"> & {
@@ -14,5 +28,19 @@ declare const PasswordInput: import("react").ForwardRefExoticComponent<Omit<Inpu
14
28
  * @default "current-password"
15
29
  */
16
30
  autoComplete?: InputProps["autoComplete"];
31
+ /** Controlled reveal state: `true` shows the value as text. Pass it with `onRevealedChange`. */
32
+ isRevealed?: boolean;
33
+ /**
34
+ * Initial reveal state while uncontrolled.
35
+ * @default false
36
+ */
37
+ defaultIsRevealed?: boolean;
38
+ /** Called with the next reveal state when the toggle is pressed. */
39
+ onRevealedChange?: (isRevealed: boolean) => void;
40
+ /**
41
+ * Accessible name of the reveal toggle. Name the field when several share a view ("Show value 2").
42
+ * @default "Show password"
43
+ */
44
+ revealAriaLabel?: string;
17
45
  } & import("react").RefAttributes<HTMLInputElement>>;
18
46
  export default PasswordInput;
@@ -1,7 +1,8 @@
1
+ import { useControlledState } from "../hooks/useControlledState.js";
1
2
  import Button, { ButtonVariant } from "../buttons/Button.js";
2
3
  import "./internal/innerButton.js";
3
4
  import Input, { INPUT_SIZE_TO_BUTTON_SIZE_MAP, InputSize } from "./Input.js";
4
- import { forwardRef, useState } from "react";
5
+ import { forwardRef } from "react";
5
6
  import { jsx } from "react/jsx-runtime";
6
7
  import { cx } from "@linaria/core";
7
8
  import { EyeIcon, EyeSlashIcon } from "@phosphor-icons/react";
@@ -21,13 +22,17 @@ import { EyeIcon, EyeSlashIcon } from "@phosphor-icons/react";
21
22
  */
22
23
  /** A masked single-line field with a "Show password" toggle: `Input` with `type="password"`. */
23
24
  var PasswordInput = forwardRef(function PasswordInput(props, ref) {
24
- const { autoComplete = "current-password", size = InputSize.MEDIUM, isDisabled = false, ...rest } = props;
25
- const [isRevealed, setIsRevealed] = useState(false);
25
+ const { autoComplete = "current-password", size = InputSize.MEDIUM, isDisabled = false, isRevealed: isRevealedProp, defaultIsRevealed = false, onRevealedChange, revealAriaLabel = "Show password", ...rest } = props;
26
+ const [isRevealed, setIsRevealed] = useControlledState({
27
+ value: isRevealedProp,
28
+ defaultValue: defaultIsRevealed,
29
+ onChange: onRevealedChange
30
+ });
26
31
  const toggle = /* @__PURE__ */ jsx(Button, {
27
32
  variant: ButtonVariant.TERTIARY,
28
33
  size: INPUT_SIZE_TO_BUTTON_SIZE_MAP[size],
29
34
  icon: isRevealed ? EyeSlashIcon : EyeIcon,
30
- ariaLabel: "Show password",
35
+ ariaLabel: revealAriaLabel,
31
36
  "aria-pressed": isRevealed,
32
37
  isDisabled,
33
38
  onClick: () => setIsRevealed(!isRevealed),
@@ -10,6 +10,16 @@ export declare const INTERACTIVE_RESET = "appearance: none; background: none; bo
10
10
  * draws one edge or subtracts its border in `calc()`.
11
11
  */
12
12
  export declare const HAIRLINE_WIDTH = "1px";
13
+ /**
14
+ * The DLS text underline, shared by every line drawn under text (`Link`, `isUnderlined`,
15
+ * `hasTooltip`, `EditableText`): `HAIRLINE_WIDTH` thick, so it never thickens with the font's own
16
+ * underline metric on large steps, and `0.25em` below the baseline, so it drops with the type step
17
+ * (2.5px at caption, 3px at body_sm, 3.5px at body_lg, 4px at heading_sm) and clears descenders.
18
+ * `em`, not a space token: a `Span` inherits its step and cannot pick a px value per size.
19
+ * Interpolate it first, then set `text-decoration-style` (solid link and emphasis, dashed
20
+ * editable, dotted tooltip trigger) and `text-decoration-color`.
21
+ */
22
+ export declare const UNDERLINE = "text-decoration-line: underline; text-decoration-thickness: 1px; text-underline-offset: 0.25em;";
13
23
  /** The DLS hairline: a `HAIRLINE_WIDTH` `border.primary` border on every side. */
14
24
  export declare const HAIRLINE_BORDER: string;
15
25
  /**
@@ -30,6 +30,16 @@ var INTERACTIVE_RESET = `appearance: none; background: none; border: 0; padding:
30
30
  * draws one edge or subtracts its border in `calc()`.
31
31
  */
32
32
  var HAIRLINE_WIDTH = "1px";
33
+ /**
34
+ * The DLS text underline, shared by every line drawn under text (`Link`, `isUnderlined`,
35
+ * `hasTooltip`, `EditableText`): `HAIRLINE_WIDTH` thick, so it never thickens with the font's own
36
+ * underline metric on large steps, and `0.25em` below the baseline, so it drops with the type step
37
+ * (2.5px at caption, 3px at body_sm, 3.5px at body_lg, 4px at heading_sm) and clears descenders.
38
+ * `em`, not a space token: a `Span` inherits its step and cannot pick a px value per size.
39
+ * Interpolate it first, then set `text-decoration-style` (solid link and emphasis, dashed
40
+ * editable, dotted tooltip trigger) and `text-decoration-color`.
41
+ */
42
+ var UNDERLINE = `text-decoration-line: underline; text-decoration-thickness: 1px; text-underline-offset: 0.25em;`;
33
43
  /** The DLS hairline: a `HAIRLINE_WIDTH` `border.primary` border on every side. */
34
44
  var HAIRLINE_BORDER = `border: 1px solid ${t.color.border.primary};`;
35
45
  /**
@@ -64,4 +74,4 @@ var VISUALLY_HIDDEN = `position: absolute; width: 1px; height: 1px; padding: 0;
64
74
  */
65
75
  var REDUCED_MOTION = `@media (prefers-reduced-motion: reduce) { transition: none !important; animation: none !important; }`;
66
76
  //#endregion
67
- export { FIELD_FOCUS, FOCUS_RING, HAIRLINE_BORDER, HAIRLINE_WIDTH, INTERACTIVE_RESET, REDUCED_MOTION, TRUNCATE, VISUALLY_HIDDEN };
77
+ export { FIELD_FOCUS, FOCUS_RING, HAIRLINE_BORDER, HAIRLINE_WIDTH, INTERACTIVE_RESET, REDUCED_MOTION, TRUNCATE, UNDERLINE, VISUALLY_HIDDEN };