@efolusi/meridian 1.15.0 → 1.16.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.
package/components.css CHANGED
@@ -1019,6 +1019,12 @@ button.ef-listitem:focus-visible{outline:none;box-shadow:var(--focus-ring)}
1019
1019
  .ef-input--icon.ef-input--md .ef-input__el{padding-left:36px}
1020
1020
  .ef-input--icon.ef-input--lg .ef-input__el{padding-left:40px}
1021
1021
  .ef-input__icon{position:absolute;left:11px;color:var(--text-muted);display:inline-flex;pointer-events:none}
1022
+ .ef-input__reveal{position:absolute;right:6px;display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;padding:0;border:none;border-radius:var(--radius-sm);background:none;color:var(--text-muted);cursor:pointer}
1023
+ .ef-input__reveal:hover{color:var(--text-primary)}
1024
+ .ef-input__reveal:focus-visible{outline:none;box-shadow:var(--focus-ring)}
1025
+ .ef-input--reveal.ef-input--sm .ef-input__el{padding-right:34px}
1026
+ .ef-input--reveal.ef-input--md .ef-input__el{padding-right:38px}
1027
+ .ef-input--reveal.ef-input--lg .ef-input__el{padding-right:42px}
1022
1028
  .ef-input--invalid .ef-input__el{border-color:var(--danger-600)}
1023
1029
  .ef-input--invalid .ef-input__el:focus{box-shadow:var(--focus-ring-danger)}
1024
1030
  /* components/forms/InputGroup.jsx */
package/forms/Input.d.ts CHANGED
@@ -10,5 +10,11 @@ export interface InputProps extends Omit<React.InputHTMLAttributes<HTMLInputElem
10
10
  /** @default 'md' */
11
11
  size?: 'sm' | 'md' | 'lg';
12
12
  invalid?: boolean;
13
+ /** Adds a show/hide button to a `type="password"` field */
14
+ revealable?: boolean;
15
+ /** @default 'Show password' */
16
+ revealLabel?: string;
17
+ /** @default 'Hide password' */
18
+ hideLabel?: string;
13
19
  }
14
20
  export declare function Input(props: InputProps): React.JSX.Element;
package/forms/Input.js CHANGED
@@ -10,10 +10,18 @@ export function Input({
10
10
  iconLeft,
11
11
  size = 'md',
12
12
  invalid,
13
+ revealable,
14
+ revealLabel = 'Show password',
15
+ hideLabel = 'Hide password',
13
16
  style,
14
17
  className,
15
18
  ...rest
16
19
  }) {
20
+ // A password field people cannot read back is a password field people mistype.
21
+ // The toggle is a real button so it is reachable by keyboard, and it is left
22
+ // out of the tab order only when there is nothing to reveal.
23
+ const [revealed, setRevealed] = React.useState(false);
24
+ const showToggle = revealable && rest.type === 'password';
17
25
  // Picks up id / aria wiring when nested in a FormField; standalone this is a no-op.
18
26
  const field = useFieldProps({
19
27
  invalid,
@@ -23,7 +31,7 @@ export function Input({
23
31
  });
24
32
  const bad = field.invalid;
25
33
  const control = /*#__PURE__*/React.createElement("span", {
26
- className: `ef-input ef-input--${size}${iconLeft ? ' ef-input--icon' : ''}${bad ? ' ef-input--invalid' : ''}`
34
+ className: `ef-input ef-input--${size}${iconLeft ? ' ef-input--icon' : ''}${showToggle ? ' ef-input--reveal' : ''}${bad ? ' ef-input--invalid' : ''}`
27
35
  }, iconLeft ? /*#__PURE__*/React.createElement("span", {
28
36
  className: "ef-input__icon"
29
37
  }, /*#__PURE__*/React.createElement(Icon, {
@@ -32,7 +40,18 @@ export function Input({
32
40
  })) : null, /*#__PURE__*/React.createElement("input", _extends({
33
41
  className: "ef-input__el",
34
42
  "aria-invalid": bad || undefined
35
- }, rest, field.controlProps)));
43
+ }, rest, field.controlProps, {
44
+ type: showToggle && revealed ? 'text' : rest.type
45
+ })), showToggle ? /*#__PURE__*/React.createElement("button", {
46
+ type: "button",
47
+ className: "ef-input__reveal",
48
+ "aria-label": revealed ? hideLabel : revealLabel,
49
+ "aria-pressed": revealed,
50
+ onClick: () => setRevealed(v => !v)
51
+ }, /*#__PURE__*/React.createElement(Icon, {
52
+ name: revealed ? 'eye-off' : 'eye',
53
+ size: 16
54
+ })) : null);
36
55
  if (!label && !hint && !error) return /*#__PURE__*/React.cloneElement(control, {
37
56
  style,
38
57
  className: control.props.className + (className ? ' ' + className : '')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@efolusi/meridian",
3
- "version": "1.15.0",
3
+ "version": "1.16.0",
4
4
  "description": "A general-purpose open-source design system by Efolusi: accessible React components, design tokens, blocks and example apps.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://meridian.efolusi.com",