@tangible/ui 0.2.44 → 0.2.46

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 (36) hide show
  1. package/components/ColorPicker/ColorPicker.js +1 -1
  2. package/components/GradientPicker/GradientPicker.js +1 -1
  3. package/components/PasswordInput/PasswordInput.d.ts +7 -0
  4. package/components/PasswordInput/PasswordInput.js +64 -0
  5. package/components/PasswordInput/index.d.ts +3 -0
  6. package/components/PasswordInput/index.js +2 -0
  7. package/components/PasswordInput/types.d.ts +45 -0
  8. package/components/PasswordInput/types.js +6 -0
  9. package/components/SecretInput/SecretInput.js +10 -33
  10. package/components/Tooltip/Tooltip.d.ts +1 -1
  11. package/components/Tooltip/Tooltip.js +302 -19
  12. package/components/Tooltip/types.d.ts +30 -0
  13. package/components/index.d.ts +2 -0
  14. package/components/index.js +1 -0
  15. package/figma-tokens.json +1 -1
  16. package/icons/icons.svg +1 -1
  17. package/icons/sprite-version.js +1 -1
  18. package/icons/sprite.php +1 -1
  19. package/package.json +5 -1
  20. package/skills/building-with-tui/SKILL.md +9 -3
  21. package/styles/all.css +1 -1
  22. package/styles/all.expanded.css +51 -0
  23. package/styles/all.expanded.unlayered.css +51 -0
  24. package/styles/all.unlayered.css +1 -1
  25. package/styles/components/_bundle.scss +5 -1
  26. package/styles/components/password-input.scss +24 -0
  27. package/styles/components/secret-input.scss +1 -65
  28. package/styles/system/_reveal.scss +82 -0
  29. package/styles/system/index.scss +1 -0
  30. package/tui-manifest.json +93 -2
  31. package/utils/reveal/RevealToggle.d.ts +32 -0
  32. package/utils/reveal/RevealToggle.js +57 -0
  33. package/utils/reveal/index.d.ts +3 -0
  34. package/utils/reveal/index.js +4 -0
  35. package/utils/reveal/useReveal.d.ts +26 -0
  36. package/utils/reveal/useReveal.js +55 -0
@@ -212,5 +212,5 @@ export function ColorPicker({ value: controlledValue, defaultValue = '#000000',
212
212
  return (_jsxs("div", { ref: rootRef, className: cx('tui-color-picker', disabled && 'is-disabled', className), role: "group", "aria-label": ariaLabel ?? L.group, ...rest, children: [_jsx(ColorArea, { hsva: hsva, onValueChange: ({ s, v }) => patch({ s, v }), disabled: disabled, "aria-label": L.area, valueText: L.areaValueText(Math.round(hsva.s * 100), Math.round(hsva.v * 100)) }), _jsx(ColorSlider, { "aria-label": L.hue, value: hsva.h, min: 0, max: 360, track: HUE_TRACK, valueText: L.hueValueText(Math.round(hsva.h)), onValueChange: (h) => patch({ h }), disabled: disabled }), alpha && (_jsx(ColorSlider, { "aria-label": L.alpha, value: hsva.a * 100, min: 0, max: 100, checkerboard: true, track: alphaTrack(opaqueHex), valueText: L.alphaValueText(Math.round(hsva.a * 100)), onValueChange: (a) => patch({ a: a / 100 }), disabled: disabled })), _jsxs("div", { className: "tui-color-picker__value", children: [offeredFormats.length > 1 && (_jsxs(Select, { value: format, onValueChange: (v) => setFormat(v), disabled: disabled, "aria-label": L.format, children: [_jsx(Select.Trigger, { className: "tui-color-picker__format" }), _jsx(Select.Content, { children: offeredFormats.map((f) => (_jsx(Select.Option, { value: f, children: L.formats[f] }, f))) })] })), _jsx("div", { className: "tui-color-picker__field-group", children: useChannels ? (_jsx(Channels, { format: format, hsva: hsva, alpha: alpha, disabled: disabled, onChange: commitHsva, channelLabels: L.channels, groupLabel: L.channelGroup(L.formats[format] ?? format) })) : (_jsx("input", { className: "tui-color-picker__field-input", type: "text", autoComplete: "off", spellCheck: false, value: fieldText, onChange: (e) => setDraft(e.target.value), onBlur: commitText, onKeyDown: (e) => {
213
213
  if (e.key === 'Enter')
214
214
  commitText();
215
- }, "aria-label": L.value, disabled: disabled })) }), _jsxs(Tooltip, { type: "label", children: [_jsx(Tooltip.Trigger, { asChild: true, children: _jsx(IconButton, { className: "tui-color-picker__copy", icon: CopyIcon, label: L.copy, variant: "ghost", size: "sm", disabled: disabled, onClick: handleCopy }) }), _jsx(Tooltip.Content, { children: copied ? L.copied : L.copy })] })] }), _jsx("span", { className: "tui-visually-hidden", role: "status", "aria-live": "polite", children: copied ? L.copied : '' }), _jsx("p", { className: cx('tui-color-picker__var', !isVar && 'is-empty'), "aria-live": "polite", children: isVar && (_jsxs(_Fragment, { children: [L.variable, " ", _jsx("code", { children: parsed.name })] })) })] }));
215
+ }, "aria-label": L.value, disabled: disabled })) }), _jsxs(Tooltip, { type: "label", closeOnPress: false, children: [_jsx(Tooltip.Trigger, { asChild: true, children: _jsx(IconButton, { className: "tui-color-picker__copy", icon: CopyIcon, label: L.copy, variant: "ghost", size: "sm", disabled: disabled, onClick: handleCopy }) }), _jsx(Tooltip.Content, { children: copied ? L.copied : L.copy })] })] }), _jsx("span", { className: "tui-visually-hidden", role: "status", "aria-live": "polite", children: copied ? L.copied : '' }), _jsx("p", { className: cx('tui-color-picker__var', !isVar && 'is-empty'), "aria-live": "polite", children: isVar && (_jsxs(_Fragment, { children: [L.variable, " ", _jsx("code", { children: parsed.name })] })) })] }));
216
216
  }
@@ -182,7 +182,7 @@ export function GradientPicker({ value: controlledValue, defaultValue = formatGr
182
182
  // stop after the reorder — close it instead.
183
183
  setOpenStop(null);
184
184
  patch({ stops: reverseStops(stops) });
185
- } }) }), _jsx(Tooltip.Content, { children: L.reverse })] }), _jsxs(Tooltip, { type: "label", children: [_jsx(Tooltip.Trigger, { asChild: true, children: _jsx(IconButton, { icon: CopyIcon, label: L.copy, variant: "ghost", size: "sm", disabled: disabled, onClick: handleCopy }) }), _jsx(Tooltip.Content, { children: copied ? L.copied : L.copy })] })] }), _jsxs("div", { className: "tui-gradient-picker__stops", children: [_jsx("span", { className: "tui-gradient-picker__label tui-text-style-overline", children: L.stopsHeading }), stops.map((stop, i) => (_jsxs("div", { className: "tui-gradient-picker__stop", children: [_jsxs(Popover, { open: openStop === i, onOpenChange: (open) => setOpenStop(open ? i : null), children: [_jsx(Popover.Trigger, { asChild: true, children: _jsx("button", { type: "button", className: "tui-gradient-picker__swatch", "aria-label": L.editStop(i + 1), disabled: disabled, children: _jsx("span", { className: "tui-gradient-picker__swatch-fill", "aria-hidden": "true", style: { '--_swatch': stop.color } }) }) }), _jsx(Popover.Content, { side: "bottom", align: "start", modal: true, "aria-label": L.editStop(i + 1), className: "tui-gradient-picker__stop-popover", children: _jsx(ColorPicker, { value: stop.color, onValueChange: (color) => updateStop(i, { color }), alpha: alpha, formats: formats }) })] }), _jsx(NumberField, { label: L.stopPosition(i + 1), hideLabel: true, value: stop.position, min: stops[i - 1]?.position ?? 0, max: stops[i + 1]?.position ?? 100, suffix: "%", disabled: disabled, onCommit: (position) => updateStop(i, { position: round1(position) }), className: "tui-gradient-picker__stop-position" }), _jsx(IconButton, { ref: (el) => {
185
+ } }) }), _jsx(Tooltip.Content, { children: L.reverse })] }), _jsxs(Tooltip, { type: "label", closeOnPress: false, children: [_jsx(Tooltip.Trigger, { asChild: true, children: _jsx(IconButton, { icon: CopyIcon, label: L.copy, variant: "ghost", size: "sm", disabled: disabled, onClick: handleCopy }) }), _jsx(Tooltip.Content, { children: copied ? L.copied : L.copy })] })] }), _jsxs("div", { className: "tui-gradient-picker__stops", children: [_jsx("span", { className: "tui-gradient-picker__label tui-text-style-overline", children: L.stopsHeading }), stops.map((stop, i) => (_jsxs("div", { className: "tui-gradient-picker__stop", children: [_jsxs(Popover, { open: openStop === i, onOpenChange: (open) => setOpenStop(open ? i : null), children: [_jsx(Popover.Trigger, { asChild: true, children: _jsx("button", { type: "button", className: "tui-gradient-picker__swatch", "aria-label": L.editStop(i + 1), disabled: disabled, children: _jsx("span", { className: "tui-gradient-picker__swatch-fill", "aria-hidden": "true", style: { '--_swatch': stop.color } }) }) }), _jsx(Popover.Content, { side: "bottom", align: "start", modal: true, "aria-label": L.editStop(i + 1), className: "tui-gradient-picker__stop-popover", children: _jsx(ColorPicker, { value: stop.color, onValueChange: (color) => updateStop(i, { color }), alpha: alpha, formats: formats }) })] }), _jsx(NumberField, { label: L.stopPosition(i + 1), hideLabel: true, value: stop.position, min: stops[i - 1]?.position ?? 0, max: stops[i + 1]?.position ?? 100, suffix: "%", disabled: disabled, onCommit: (position) => updateStop(i, { position: round1(position) }), className: "tui-gradient-picker__stop-position" }), _jsx(IconButton, { ref: (el) => {
186
186
  removeRefs.current[i] = el;
187
187
  }, icon: TrashIcon, label: L.removeStop(i + 1), variant: "ghost", theme: "danger", size: "sm", disabled: disabled || stops.length <= 2, onClick: () => removeStop(i, true) })] }, i))), _jsx(Button, { ref: (el) => {
188
188
  addRef.current = el;
@@ -0,0 +1,7 @@
1
+ export declare const PasswordInput: import("react").ForwardRefExoticComponent<Omit<import("..").TextInputProps, "type" | "autoCapitalize" | "spellCheck" | "prefix" | "autoCorrect" | "autoComplete" | "suffix"> & {
2
+ purpose: import("./types").PasswordInputPurpose;
3
+ revealed?: boolean;
4
+ defaultRevealed?: boolean;
5
+ onRevealChange?: (revealed: boolean) => void;
6
+ labels?: import("./types").PasswordInputLabels;
7
+ } & import("react").RefAttributes<HTMLInputElement>>;
@@ -0,0 +1,64 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef, useEffect, useRef } from 'react';
3
+ import { cx } from '../../utils/cx.js';
4
+ import { composeRefs } from '../../utils/compose-refs.js';
5
+ import { TextInput } from '../TextInput/index.js';
6
+ import { RevealToggle, useReveal } from '../../utils/reveal/index.js';
7
+ import { defaultPasswordInputLabels } from './types.js';
8
+ // =============================================================================
9
+ // PasswordInput Component
10
+ // =============================================================================
11
+ //
12
+ // TextInput variant for a password someone signs in with or chooses: masked,
13
+ // with a show/hide toggle. Its sibling SecretInput is for stored secrets (API
14
+ // keys) and does the opposite with password managers, keeping them out; this
15
+ // one is built to let them in.
16
+ //
17
+ // - `purpose` sets autocomplete (current-password / new-password), so managers
18
+ // fill a saved password or offer to generate one.
19
+ // - Shown as text, it must not be autocorrected, capitalised or spellchecked:
20
+ // those would change what's typed, and a cloud spellchecker would send it
21
+ // off the page. So those three are set after the consumer's props.
22
+ // - A native submit masks it again, quietly, so a password left showing isn't
23
+ // saved as plain text in a browser's form history. A submit the app cancels
24
+ // (preventDefault) leaves it as it is.
25
+ // - The reveal toggle is shared with SecretInput (src/utils/reveal and the
26
+ // system reveal-button mixin), so the two can't drift.
27
+ //
28
+ // =============================================================================
29
+ export const PasswordInput = forwardRef(function PasswordInput({ purpose, revealed: revealedProp, defaultRevealed, onRevealChange, labels, className, inputClassName, disabled, ...rest }, forwardedRef) {
30
+ const text = { ...defaultPasswordInputLabels, ...labels };
31
+ const inputRef = useRef(null);
32
+ const { revealed, setRevealed, announcement } = useReveal({
33
+ revealed: revealedProp,
34
+ defaultRevealed,
35
+ onRevealChange,
36
+ shown: text.shown,
37
+ hidden: text.hidden,
38
+ });
39
+ // Re-mask when the form really submits. Listened for on the document in
40
+ // the bubble phase, so it runs after React's own handlers and can see
41
+ // whether one cancelled the submit: an app that handles sign-in itself
42
+ // (preventDefault) keeps the password showing, so a failed attempt can be
43
+ // checked for a typo. A native submit masks it first, so the browser never
44
+ // stores it as plain text in form history. Matched to the field's form at
45
+ // the time, so it holds if the field mounts before its form. The ref keeps
46
+ // the latest setter without re-adding the listener on every toggle.
47
+ const remask = useRef(() => { });
48
+ remask.current = () => setRevealed(false, { announce: false });
49
+ useEffect(() => {
50
+ const doc = inputRef.current?.ownerDocument;
51
+ if (!doc)
52
+ return;
53
+ const onSubmit = (event) => {
54
+ if (!event.defaultPrevented && event.target === inputRef.current?.form)
55
+ remask.current();
56
+ };
57
+ doc.addEventListener('submit', onSubmit);
58
+ return () => doc.removeEventListener('submit', onSubmit);
59
+ }, []);
60
+ return (_jsx(TextInput, { ...rest, ref: composeRefs(forwardedRef, inputRef), type: revealed ? 'text' : 'password', autoComplete: purpose === 'new' ? 'new-password' : 'current-password', spellCheck: false, autoCapitalize: "off", autoCorrect: "off", disabled: disabled, className: cx('tui-password-input', className),
61
+ // tui-input-reset strips Edge's own ::-ms-reveal eye, which would sit
62
+ // beside our toggle and unmask the field without changing `type`.
63
+ inputClassName: cx('tui-input-reset', 'tui-password-input__input', inputClassName), suffix: _jsx(RevealToggle, { revealed: revealed, onToggle: () => setRevealed(!revealed), revealLabel: text.reveal, hideLabel: text.hide, announcement: announcement, disabled: disabled, className: "tui-password-input__reveal", inputRef: inputRef, rootClassName: "tui-password-input" }) }));
64
+ });
@@ -0,0 +1,3 @@
1
+ export { PasswordInput } from './PasswordInput';
2
+ export { defaultPasswordInputLabels } from './types';
3
+ export type { PasswordInputProps, PasswordInputLabels, PasswordInputPurpose } from './types';
@@ -0,0 +1,2 @@
1
+ export { PasswordInput } from './PasswordInput.js';
2
+ export { defaultPasswordInputLabels } from './types.js';
@@ -0,0 +1,45 @@
1
+ import type { TextInputProps } from '../TextInput/types';
2
+ /**
3
+ * What the password is for. It sets `autocomplete`, which is how browsers and
4
+ * password managers know to fill a saved password (`current`) or offer to
5
+ * generate and save a new one (`new`). A wrong value fails silently, so it's
6
+ * a required prop rather than a default.
7
+ */
8
+ export type PasswordInputPurpose = 'current' | 'new';
9
+ /** Overridable strings, for i18n and for naming a second field on a page. */
10
+ export type PasswordInputLabels = {
11
+ /**
12
+ * The reveal toggle's name while the password is masked. Two password
13
+ * fields on one page need different names ("Show new password"): override
14
+ * all four strings together, so the announcements name the field too.
15
+ * @default "Show password"
16
+ */
17
+ reveal?: string;
18
+ /** @default "Hide password" */
19
+ hide?: string;
20
+ /** Announced when the password is shown. @default "Password shown." */
21
+ shown?: string;
22
+ /** Announced when it's masked again. @default "Password hidden." */
23
+ hidden?: string;
24
+ };
25
+ export declare const defaultPasswordInputLabels: Required<PasswordInputLabels>;
26
+ /**
27
+ * `autoComplete` comes from `purpose`; `spellCheck`, `autoCapitalize` and
28
+ * `autoCorrect` are always off (shown as text, they'd change or send the
29
+ * password), so none of the four is a prop.
30
+ */
31
+ export type PasswordInputProps = Omit<TextInputProps, 'type' | 'prefix' | 'suffix' | 'autoComplete' | 'spellCheck' | 'autoCapitalize' | 'autoCorrect'> & {
32
+ /**
33
+ * `current` to sign in or confirm who you are; `new` to choose a password
34
+ * (sign up, reset, change). Sets `autocomplete` to `current-password` or
35
+ * `new-password`.
36
+ */
37
+ purpose: PasswordInputPurpose;
38
+ /** Controlled: whether the password shows as text */
39
+ revealed?: boolean;
40
+ /** Uncontrolled: start shown. @default false */
41
+ defaultRevealed?: boolean;
42
+ /** Fires on the toggle, and with `false` when a native submit re-masks the field */
43
+ onRevealChange?: (revealed: boolean) => void;
44
+ labels?: PasswordInputLabels;
45
+ };
@@ -0,0 +1,6 @@
1
+ export const defaultPasswordInputLabels = {
2
+ reveal: 'Show password',
3
+ hide: 'Hide password',
4
+ shown: 'Password shown.',
5
+ hidden: 'Password hidden.',
6
+ };
@@ -6,7 +6,8 @@ import { isDev } from '../../utils/is-dev.js';
6
6
  import { Icon } from '../Icon/index.js';
7
7
  import { TextInput } from '../TextInput/index.js';
8
8
  import { defaultSecretInputLabels } from './types.js';
9
- import { LockSmall as LockSmallIcon, View as ViewIcon, ViewOff as ViewOffIcon } from '../../icons/system/index.js';
9
+ import { RevealToggle, useReveal } from '../../utils/reveal/index.js';
10
+ import { LockSmall as LockSmallIcon } from '../../icons/system/index.js';
10
11
  // =============================================================================
11
12
  // SecretInput Component
12
13
  // =============================================================================
@@ -29,11 +30,13 @@ export const SecretInput = forwardRef(function SecretInput({ isSet = false, reve
29
30
  // none of them is assembled from fragments.
30
31
  const text = { ...defaultSecretInputLabels, ...labels };
31
32
  const inputRef = useRef(null);
32
- const [revealedState, setRevealedState] = useState(defaultRevealed);
33
- // Locked in at mount, like the rest of the family: a component that flips
34
- // between controlled and uncontrolled mid-life pollutes its own state.
35
- const [isRevealControlled] = useState(revealedProp !== undefined);
36
- const revealed = isRevealControlled ? !!revealedProp : revealedState;
33
+ const { revealed, setRevealed, announcement } = useReveal({
34
+ revealed: revealedProp,
35
+ defaultRevealed,
36
+ onRevealChange,
37
+ shown: text.shown,
38
+ hidden: text.hidden,
39
+ });
37
40
  const [isValueControlled] = useState(value !== undefined);
38
41
  // Emptiness decides the set-state, which drives an ARIA description as well
39
42
  // as the placeholder — so a wrong answer here tells a screen-reader user
@@ -82,30 +85,6 @@ export const SecretInput = forwardRef(function SecretInput({ isSet = false, reve
82
85
  setDomHasValue(e.target.value.length > 0);
83
86
  onChange?.(e);
84
87
  };
85
- // Announced state, for the screen-reader-plus-mouse case: pointerdown is
86
- // prevented so focus stays in the field, which means the toggle is never
87
- // focused on a mouse click and neither its name nor its state is ever read.
88
- // Without this, a user flips their key into the clear in total silence.
89
- // Empty until the first toggle so nothing is announced on mount.
90
- const [announcement, setAnnouncement] = useState('');
91
- const toggleReveal = () => {
92
- const next = !revealed;
93
- if (!isRevealControlled)
94
- setRevealedState(next);
95
- setAnnouncement(next ? text.shown : text.hidden);
96
- onRevealChange?.(next);
97
- };
98
- const handleToggleClick = () => {
99
- toggleReveal();
100
- // Pointer activation leaves focus wherever it was — including on <body>
101
- // if nothing was focused, which strands the user at the top of the
102
- // document. Recover only in that case: on keyboard activation focus is
103
- // already on the button, and stealing it would break the toggle.
104
- const input = inputRef.current;
105
- const active = input?.ownerDocument.activeElement;
106
- if (input && !active?.closest('.tui-secret-input'))
107
- input.focus();
108
- };
109
88
  // The set-state treatment only makes sense while there is nothing typed —
110
89
  // once there is, the field shows what the user is entering.
111
90
  const showSetState = isSet && isEmpty;
@@ -142,7 +121,5 @@ export const SecretInput = forwardRef(function SecretInput({ isSet = false, reve
142
121
  // tui-input-reset strips native in-field chrome — here Edge's own
143
122
  // ::-ms-reveal eye, which would sit beside our toggle AND unmask the
144
123
  // field without changing `type`, so the toggle's state would be wrong.
145
- inputClassName: cx('tui-input-reset', 'tui-secret-input__input', inputClassName), suffix: _jsxs(_Fragment, { children: [describeSetState && (_jsx("span", { id: setDescId, className: "tui-visually-hidden", children: text.valueSetDescription })), locked ? (_jsxs(_Fragment, { children: [_jsx("span", { id: lockedDescId, className: "tui-visually-hidden", children: lockedMessage ?? text.locked }), _jsx(Icon, { name: LockSmallIcon, className: "tui-secret-input__lock" })] })) : (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "tui-secret-input__reveal", "aria-label": revealed ? text.hide : text.reveal, "data-revealed": revealed ? 'true' : undefined, disabled: disabled, onClick: handleToggleClick,
146
- // Keep pointerdown from stealing focus before the click fires.
147
- onPointerDown: (e) => e.preventDefault(), children: _jsx(Icon, { name: revealed ? ViewOffIcon : ViewIcon }) }), _jsx("span", { role: "status", "aria-live": "polite", className: "tui-visually-hidden", children: announcement })] }))] }) }));
124
+ inputClassName: cx('tui-input-reset', 'tui-secret-input__input', inputClassName), suffix: _jsxs(_Fragment, { children: [describeSetState && (_jsx("span", { id: setDescId, className: "tui-visually-hidden", children: text.valueSetDescription })), locked ? (_jsxs(_Fragment, { children: [_jsx("span", { id: lockedDescId, className: "tui-visually-hidden", children: lockedMessage ?? text.locked }), _jsx(Icon, { name: LockSmallIcon, className: "tui-secret-input__lock" })] })) : (_jsx(RevealToggle, { revealed: revealed, onToggle: () => setRevealed(!revealed), revealLabel: text.reveal, hideLabel: text.hide, announcement: announcement, disabled: disabled, className: "tui-secret-input__reveal", inputRef: inputRef, rootClassName: "tui-secret-input" }))] }) }));
148
125
  });
@@ -1,6 +1,6 @@
1
1
  import type { TooltipProviderProps, TooltipProps, TooltipTriggerProps, TooltipContentProps } from './types';
2
2
  declare function TooltipProviderComponent({ delayDuration, closeDelayDuration, skipDelayDuration, children, }: TooltipProviderProps): import("react/jsx-runtime").JSX.Element;
3
- declare function TooltipRoot({ open: controlledOpen, onOpenChange, defaultOpen, delayDuration: localDelay, type, children, }: TooltipProps): import("react/jsx-runtime").JSX.Element;
3
+ declare function TooltipRoot({ open: controlledOpen, onOpenChange, defaultOpen, delayDuration: localDelay, type, closeOnPress, children, }: TooltipProps): import("react/jsx-runtime").JSX.Element;
4
4
  declare function TooltipTriggerComponent({ asChild, 'aria-label': ariaLabel, children, }: TooltipTriggerProps): import("react/jsx-runtime").JSX.Element;
5
5
  declare function TooltipContentComponent(props: TooltipContentProps): import("react/jsx-runtime").JSX.Element | null;
6
6
  type TooltipCompound = typeof TooltipRoot & {