@sereno-ds/ui 0.41.4 → 0.42.1
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/README.md +20 -1
- package/dist/core/Button.d.ts +1 -1
- package/dist/core/Button.js +15 -19
- package/dist/core/Button.js.map +1 -1
- package/dist/core/Card.d.ts +1 -1
- package/dist/core/Card.js +14 -11
- package/dist/core/Card.js.map +1 -1
- package/dist/core/IconButton.d.ts +1 -1
- package/dist/core/IconButton.js +13 -18
- package/dist/core/IconButton.js.map +1 -1
- package/dist/forms/SearchInput.d.ts +4 -0
- package/dist/forms/SearchInput.js +11 -8
- package/dist/forms/SearchInput.js.map +1 -1
- package/dist/styles.css +54 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,11 +18,30 @@ npm i @sereno-ds/ui @sereno-ds/tokens lucide-react
|
|
|
18
18
|
|
|
19
19
|
```ts
|
|
20
20
|
import '@sereno-ds/tokens/tokens.css'; // the token layer (colors, spacing, dark overrides…)
|
|
21
|
-
import '@sereno-ds/ui/styles.css'; //
|
|
21
|
+
import '@sereno-ds/ui/styles.css'; // keyframes, structural rules, and the hover / press / focus of Button, IconButton and Card
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
`tokens.css` **must** come first. Both are side-effect CSS: import them once (a root layout, `_app`, or `main.tsx`), not per-component.
|
|
25
25
|
|
|
26
|
+
**`styles.css` is required**, not decorative: `Button`, `IconButton` and `Card` take their colours, border and hover / press / focus states from it (their values are on the element, the rules that switch between them are in the stylesheet), so without it those three render unstyled.
|
|
27
|
+
|
|
28
|
+
#### Restyling a state with plain CSS
|
|
29
|
+
|
|
30
|
+
`Button`, `IconButton` and `Card` carry the class `sereno-btn` (the first two) or `sereno-card` and, on a `Card`, `data-interactive` and `data-clickable`. The state rules have the specificity of `.sereno-btn:hover` (one class and one pseudo-class), so a rule of yours with the same specificity **that comes later** wins, with no `!important`:
|
|
31
|
+
|
|
32
|
+
```css
|
|
33
|
+
/* a ghost button on a brand-coloured band: its hover fill vanishes on that colour */
|
|
34
|
+
.on-band:hover { background: rgb(255 255 255 / 0.2); }
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Or change what the DS reads, on the element itself (the component reads `--interactive-ghost-hover` from its own style, so only that element changes):
|
|
38
|
+
|
|
39
|
+
```css
|
|
40
|
+
.on-band { --interactive-ghost-hover: rgb(255 255 255 / 0.2); }
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The class names and the `data-` attributes are the styling hooks. The `--sd-*` custom properties are how the component hands its values to the stylesheet and are **not** a public API: restyle with the rules above, not by setting them.
|
|
44
|
+
|
|
26
45
|
### 2. Provide the fonts
|
|
27
46
|
|
|
28
47
|
Components reference three font CSS variables. Define them however you host fonts; the tokens already carry a system fallback, so text renders without them, just off-brand.
|
package/dist/core/Button.d.ts
CHANGED
|
@@ -26,6 +26,6 @@ interface InteractState {
|
|
|
26
26
|
}
|
|
27
27
|
/** Shared hover / press / focus-visible tracking used by Button, IconButton and Card. */
|
|
28
28
|
declare function useInteract(disabled: boolean): InteractState;
|
|
29
|
-
declare function Button({ variant, size, fullWidth, disabled, loading, iconLeft, iconRight, children, style, ...rest }: ButtonProps): React.JSX.Element;
|
|
29
|
+
declare function Button({ variant, size, fullWidth, disabled, loading, iconLeft, iconRight, children, className, style, ...rest }: ButtonProps): React.JSX.Element;
|
|
30
30
|
|
|
31
31
|
export { Button, type ButtonProps, type InteractState, useInteract };
|
package/dist/core/Button.js
CHANGED
|
@@ -27,39 +27,39 @@ const SIZES = {
|
|
|
27
27
|
lg: { h: "var(--control-height-lg)", px: "var(--space-5)", fs: "var(--text-md)", gap: "10px" },
|
|
28
28
|
xl: { h: "var(--control-height-xl)", px: "var(--space-6)", fs: "var(--text-lg)", gap: "10px" }
|
|
29
29
|
};
|
|
30
|
-
function
|
|
30
|
+
function stateVars(variant) {
|
|
31
31
|
switch (variant) {
|
|
32
32
|
case "accent":
|
|
33
|
-
return { bg:
|
|
33
|
+
return { "--sd-bg": "var(--interactive-accent)", "--sd-bg-hover": "var(--interactive-accent-hover)", "--sd-bg-active": "var(--interactive-accent-active)", "--sd-fg": "var(--interactive-accent-fg)", "--sd-bd": "transparent", "--sd-sh": "var(--shadow-xs)", "--sd-sh-hover": "var(--shadow-accent)", "--sd-ring": "var(--focus-ring-accent)" };
|
|
34
34
|
case "secondary":
|
|
35
|
-
return { bg:
|
|
35
|
+
return { "--sd-bg": "var(--interactive-secondary)", "--sd-bg-hover": "var(--interactive-secondary-hover)", "--sd-bg-active": "var(--interactive-secondary-active)", "--sd-fg": "var(--interactive-secondary-fg)", "--sd-bd": "var(--border-default)", "--sd-sh": "var(--shadow-xs)" };
|
|
36
36
|
case "ghost":
|
|
37
|
-
return { bg:
|
|
37
|
+
return { "--sd-bg": "transparent", "--sd-bg-hover": "var(--interactive-ghost-hover)", "--sd-fg": "var(--text-secondary)", "--sd-bd": "transparent", "--sd-sh": "none" };
|
|
38
38
|
case "success":
|
|
39
|
-
return { bg:
|
|
39
|
+
return { "--sd-bg": "var(--interactive-success)", "--sd-bg-hover": "var(--interactive-success-hover)", "--sd-fg": "var(--interactive-success-fg)", "--sd-bd": "transparent", "--sd-sh": "var(--shadow-xs)" };
|
|
40
40
|
case "warning":
|
|
41
|
-
return { bg:
|
|
41
|
+
return { "--sd-bg": "var(--interactive-warning)", "--sd-bg-hover": "var(--interactive-warning-hover)", "--sd-fg": "var(--interactive-warning-fg)", "--sd-bd": "transparent", "--sd-sh": "var(--shadow-xs)" };
|
|
42
42
|
case "error":
|
|
43
|
-
return { bg:
|
|
43
|
+
return { "--sd-bg": "var(--interactive-error)", "--sd-bg-hover": "var(--interactive-error-hover)", "--sd-fg": "var(--interactive-error-fg)", "--sd-bd": "transparent", "--sd-sh": "var(--shadow-xs)" };
|
|
44
44
|
case "link":
|
|
45
|
-
return { bg: "transparent", fg:
|
|
45
|
+
return { "--sd-bg": "transparent", "--sd-fg": "var(--text-link)", "--sd-fg-hover": "var(--text-link-hover)", "--sd-bd": "transparent", "--sd-sh": "none", "--sd-deco-hover": "underline" };
|
|
46
46
|
default:
|
|
47
|
-
return { bg:
|
|
47
|
+
return { "--sd-bg": "var(--interactive-primary)", "--sd-bg-hover": "var(--interactive-primary-hover)", "--sd-bg-active": "var(--interactive-primary-active)", "--sd-fg": "var(--interactive-primary-fg)", "--sd-bd": "transparent", "--sd-sh": "var(--shadow-xs)", "--sd-sh-hover": "var(--shadow-brand)" };
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
const DISABLED_VARS = { "--sd-bg": "var(--interactive-disabled-bg)", "--sd-fg": "var(--interactive-disabled-fg)", "--sd-bd": "transparent", "--sd-sh": "none" };
|
|
51
|
+
function Button({ variant = "primary", size = "md", fullWidth = false, disabled = false, loading = false, iconLeft, iconRight, children, className, style, ...rest }) {
|
|
52
52
|
const sz = SIZES[size] || SIZES.md;
|
|
53
|
-
const p = palette(variant, st);
|
|
54
53
|
const isLink = variant === "link";
|
|
55
54
|
return /* @__PURE__ */ jsxs(
|
|
56
55
|
"button",
|
|
57
56
|
{
|
|
58
57
|
type: "button",
|
|
59
58
|
disabled: disabled || loading,
|
|
60
|
-
...st.handlers,
|
|
61
59
|
...rest,
|
|
60
|
+
className: ["sereno-btn", className].filter(Boolean).join(" "),
|
|
62
61
|
style: sx({
|
|
62
|
+
...disabled ? DISABLED_VARS : stateVars(variant),
|
|
63
63
|
display: "inline-flex",
|
|
64
64
|
alignItems: "center",
|
|
65
65
|
justifyContent: "center",
|
|
@@ -72,16 +72,12 @@ function Button({ variant = "primary", size = "md", fullWidth = false, disabled
|
|
|
72
72
|
fontWeight: "var(--weight-semibold)",
|
|
73
73
|
letterSpacing: "var(--tracking-snug)",
|
|
74
74
|
borderRadius: isLink ? "var(--radius-xs)" : "var(--radius-control)",
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
color: disabled ? "var(--interactive-disabled-fg)" : p.fg,
|
|
78
|
-
boxShadow: disabled ? "none" : st.focus ? p.ring : p.sh,
|
|
79
|
-
transform: st.press && !disabled ? "scale(var(--press-scale))" : "none",
|
|
75
|
+
borderWidth: "var(--border-width-hairline)",
|
|
76
|
+
borderStyle: "solid",
|
|
80
77
|
cursor: disabled ? "not-allowed" : "pointer",
|
|
81
78
|
opacity: loading ? 0.75 : 1,
|
|
82
79
|
transition: "var(--transition-control)",
|
|
83
80
|
outline: "none",
|
|
84
|
-
textDecoration: isLink && st.hover ? "underline" : "none",
|
|
85
81
|
textUnderlineOffset: "2px",
|
|
86
82
|
...style
|
|
87
83
|
}),
|
package/dist/core/Button.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/Button.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { sx } from '../_internal/style';\n\n/**\n * Primary action control. `primary` for navigation-level commitment, `accent` for the single\n * conversion action on a view. `success` / `warning` / `error` are the semantic fills, using the\n * same words as Badge / Alert / Toast. (No `info` - in Sereno that is the brand indigo = `primary`.)\n */\nexport interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n /** Visual role. Only one `accent` button per screen. */\n variant?: 'primary' | 'accent' | 'secondary' | 'ghost' | 'link' | 'success' | 'warning' | 'error';\n /** Control height. `lg`/`xl` are the mobile defaults (≥44px tap target). */\n size?: 'sm' | 'md' | 'lg' | 'xl';\n fullWidth?: boolean;\n disabled?: boolean;\n /** Shows a spinner and blocks interaction. */\n loading?: boolean;\n iconLeft?: React.ReactNode;\n iconRight?: React.ReactNode;\n children?: React.ReactNode;\n}\n\nexport interface InteractState {\n hover: boolean;\n press: boolean;\n focus: boolean;\n handlers: React.HTMLAttributes<HTMLElement>;\n}\n\n/** Shared hover / press / focus-visible tracking used by Button, IconButton and Card. */\nexport function useInteract(disabled: boolean): InteractState {\n const [hover, setHover] = React.useState(false);\n const [press, setPress] = React.useState(false);\n const [focus, setFocus] = React.useState(false);\n const handlers: React.HTMLAttributes<HTMLElement> = disabled\n ? {}\n : {\n onMouseEnter: () => setHover(true),\n onMouseLeave: () => {\n setHover(false);\n setPress(false);\n },\n onMouseDown: () => setPress(true),\n onMouseUp: () => setPress(false),\n onFocus: (e) => {\n if ((e.target as HTMLElement).matches(':focus-visible')) setFocus(true);\n },\n onBlur: () => setFocus(false),\n };\n return { hover, press, focus, handlers };\n}\n\nconst SIZES = {\n sm: { h: 'var(--control-height-sm)', px: 'var(--space-3)', fs: 'var(--text-sm)', gap: '6px' },\n md: { h: 'var(--control-height-md)', px: 'var(--space-4)', fs: 'var(--text-base)', gap: '8px' },\n lg: { h: 'var(--control-height-lg)', px: 'var(--space-5)', fs: 'var(--text-md)', gap: '10px' },\n xl: { h: 'var(--control-height-xl)', px: 'var(--space-6)', fs: 'var(--text-lg)', gap: '10px' },\n} as const;\n\nfunction
|
|
1
|
+
{"version":3,"sources":["../../src/core/Button.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { sx } from '../_internal/style';\n\n/**\n * Primary action control. `primary` for navigation-level commitment, `accent` for the single\n * conversion action on a view. `success` / `warning` / `error` are the semantic fills, using the\n * same words as Badge / Alert / Toast. (No `info` - in Sereno that is the brand indigo = `primary`.)\n */\nexport interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n /** Visual role. Only one `accent` button per screen. */\n variant?: 'primary' | 'accent' | 'secondary' | 'ghost' | 'link' | 'success' | 'warning' | 'error';\n /** Control height. `lg`/`xl` are the mobile defaults (≥44px tap target). */\n size?: 'sm' | 'md' | 'lg' | 'xl';\n fullWidth?: boolean;\n disabled?: boolean;\n /** Shows a spinner and blocks interaction. */\n loading?: boolean;\n iconLeft?: React.ReactNode;\n iconRight?: React.ReactNode;\n children?: React.ReactNode;\n}\n\nexport interface InteractState {\n hover: boolean;\n press: boolean;\n focus: boolean;\n handlers: React.HTMLAttributes<HTMLElement>;\n}\n\n/** Shared hover / press / focus-visible tracking used by Button, IconButton and Card. */\nexport function useInteract(disabled: boolean): InteractState {\n const [hover, setHover] = React.useState(false);\n const [press, setPress] = React.useState(false);\n const [focus, setFocus] = React.useState(false);\n const handlers: React.HTMLAttributes<HTMLElement> = disabled\n ? {}\n : {\n onMouseEnter: () => setHover(true),\n onMouseLeave: () => {\n setHover(false);\n setPress(false);\n },\n onMouseDown: () => setPress(true),\n onMouseUp: () => setPress(false),\n onFocus: (e) => {\n if ((e.target as HTMLElement).matches(':focus-visible')) setFocus(true);\n },\n onBlur: () => setFocus(false),\n };\n return { hover, press, focus, handlers };\n}\n\nconst SIZES = {\n sm: { h: 'var(--control-height-sm)', px: 'var(--space-3)', fs: 'var(--text-sm)', gap: '6px' },\n md: { h: 'var(--control-height-md)', px: 'var(--space-4)', fs: 'var(--text-base)', gap: '8px' },\n lg: { h: 'var(--control-height-lg)', px: 'var(--space-5)', fs: 'var(--text-md)', gap: '10px' },\n xl: { h: 'var(--control-height-xl)', px: 'var(--space-6)', fs: 'var(--text-lg)', gap: '10px' },\n} as const;\n\n/**\n * What a variant looks like in each state, as the custom properties `.sereno-btn` (styles.css) reads:\n * the base, then only what differs on `:hover`, `:active` (pressed) and `:focus-visible` (SS-577). The\n * browser switches between them, so a button holds no hover / press / focus state and does not re-render when\n * the pointer crosses it. A property left out falls back to the one before it in the CSS.\n */\nfunction stateVars(variant: NonNullable<ButtonProps['variant']>): Record<string, string> {\n switch (variant) {\n case 'accent':\n return { '--sd-bg': 'var(--interactive-accent)', '--sd-bg-hover': 'var(--interactive-accent-hover)', '--sd-bg-active': 'var(--interactive-accent-active)', '--sd-fg': 'var(--interactive-accent-fg)', '--sd-bd': 'transparent', '--sd-sh': 'var(--shadow-xs)', '--sd-sh-hover': 'var(--shadow-accent)', '--sd-ring': 'var(--focus-ring-accent)' };\n case 'secondary':\n return { '--sd-bg': 'var(--interactive-secondary)', '--sd-bg-hover': 'var(--interactive-secondary-hover)', '--sd-bg-active': 'var(--interactive-secondary-active)', '--sd-fg': 'var(--interactive-secondary-fg)', '--sd-bd': 'var(--border-default)', '--sd-sh': 'var(--shadow-xs)' };\n case 'ghost':\n return { '--sd-bg': 'transparent', '--sd-bg-hover': 'var(--interactive-ghost-hover)', '--sd-fg': 'var(--text-secondary)', '--sd-bd': 'transparent', '--sd-sh': 'none' };\n case 'success':\n return { '--sd-bg': 'var(--interactive-success)', '--sd-bg-hover': 'var(--interactive-success-hover)', '--sd-fg': 'var(--interactive-success-fg)', '--sd-bd': 'transparent', '--sd-sh': 'var(--shadow-xs)' };\n case 'warning':\n return { '--sd-bg': 'var(--interactive-warning)', '--sd-bg-hover': 'var(--interactive-warning-hover)', '--sd-fg': 'var(--interactive-warning-fg)', '--sd-bd': 'transparent', '--sd-sh': 'var(--shadow-xs)' };\n case 'error':\n return { '--sd-bg': 'var(--interactive-error)', '--sd-bg-hover': 'var(--interactive-error-hover)', '--sd-fg': 'var(--interactive-error-fg)', '--sd-bd': 'transparent', '--sd-sh': 'var(--shadow-xs)' };\n case 'link':\n return { '--sd-bg': 'transparent', '--sd-fg': 'var(--text-link)', '--sd-fg-hover': 'var(--text-link-hover)', '--sd-bd': 'transparent', '--sd-sh': 'none', '--sd-deco-hover': 'underline' };\n default:\n return { '--sd-bg': 'var(--interactive-primary)', '--sd-bg-hover': 'var(--interactive-primary-hover)', '--sd-bg-active': 'var(--interactive-primary-active)', '--sd-fg': 'var(--interactive-primary-fg)', '--sd-bd': 'transparent', '--sd-sh': 'var(--shadow-xs)', '--sd-sh-hover': 'var(--shadow-brand)' };\n }\n}\n\n/** A disabled control: one look, no hover, no press, no ring (the CSS rules exclude `:disabled`). */\nconst DISABLED_VARS = { '--sd-bg': 'var(--interactive-disabled-bg)', '--sd-fg': 'var(--interactive-disabled-fg)', '--sd-bd': 'transparent', '--sd-sh': 'none' };\n\nexport function Button({ variant = 'primary', size = 'md', fullWidth = false, disabled = false, loading = false, iconLeft, iconRight, children, className, style, ...rest }: ButtonProps) {\n const sz = SIZES[size] || SIZES.md;\n const isLink = variant === 'link';\n return (\n <button\n type=\"button\"\n disabled={disabled || loading}\n {...rest}\n className={['sereno-btn', className].filter(Boolean).join(' ')}\n style={sx({\n ...(disabled ? DISABLED_VARS : stateVars(variant)),\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n gap: sz.gap,\n height: isLink ? 'auto' : sz.h,\n padding: isLink ? 0 : '0 ' + sz.px,\n width: fullWidth ? '100%' : undefined,\n fontFamily: 'var(--font-body)',\n fontSize: sz.fs,\n fontWeight: 'var(--weight-semibold)',\n letterSpacing: 'var(--tracking-snug)',\n borderRadius: isLink ? 'var(--radius-xs)' : 'var(--radius-control)',\n borderWidth: 'var(--border-width-hairline)',\n borderStyle: 'solid',\n cursor: disabled ? 'not-allowed' : 'pointer',\n opacity: loading ? 0.75 : 1,\n transition: 'var(--transition-control)',\n outline: 'none',\n textUnderlineOffset: '2px',\n ...style,\n })}\n >\n {loading ? (\n <span style={sx({ width: '1em', height: '1em', borderRadius: '999px', border: '2px solid currentColor', borderTopColor: 'transparent', display: 'inline-block', animation: 'sereno-spin .7s linear infinite' })} />\n ) : (\n iconLeft\n )}\n {children}\n {iconRight}\n </button>\n );\n}"],"mappings":";AA+FI,SA8BI,KA9BJ;AA7FJ,YAAY,WAAW;AACvB,SAAS,UAAU;AA6BZ,SAAS,YAAY,UAAkC;AAC5D,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAS,KAAK;AAC9C,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAS,KAAK;AAC9C,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAS,KAAK;AAC9C,QAAM,WAA8C,WAChD,CAAC,IACD;AAAA,IACE,cAAc,MAAM,SAAS,IAAI;AAAA,IACjC,cAAc,MAAM;AAClB,eAAS,KAAK;AACd,eAAS,KAAK;AAAA,IAChB;AAAA,IACA,aAAa,MAAM,SAAS,IAAI;AAAA,IAChC,WAAW,MAAM,SAAS,KAAK;AAAA,IAC/B,SAAS,CAAC,MAAM;AACd,UAAK,EAAE,OA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AAA,QACT,qBAAqB;AAAA,QACrB,GAAG;AAAA,MACL,CAAC;AAAA,MAEA;AAAA,kBACC,oBAAC,UAAK,OAAO,GAAG,EAAE,OAAO,OAAO,QAAQ,OAAO,cAAc,SAAS,QAAQ,0BAA0B,gBAAgB,eAAe,SAAS,gBAAgB,WAAW,kCAAkC,CAAC,GAAG,IAEjN;AAAA,QAED;AAAA,QACA;AAAA;AAAA;AAAA,EACH;AAEJ;","names":[]}
|
package/dist/core/Card.d.ts
CHANGED
|
@@ -10,6 +10,6 @@ interface CardProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
10
10
|
selected?: boolean;
|
|
11
11
|
children?: React.ReactNode;
|
|
12
12
|
}
|
|
13
|
-
declare function Card({ padding, elevation, interactive, selected, children, style, onClick, onKeyDown, ...rest }: CardProps): React.JSX.Element;
|
|
13
|
+
declare function Card({ padding, elevation, interactive, selected, children, style, className, onClick, onKeyDown, ...rest }: CardProps): React.JSX.Element;
|
|
14
14
|
|
|
15
15
|
export { Card, type CardProps };
|
package/dist/core/Card.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { sx } from "../_internal/style.js";
|
|
4
|
-
import { useInteract } from "./Button.js";
|
|
5
4
|
const PADS = { none: 0, sm: "var(--space-3)", md: "var(--space-4)", lg: "var(--space-5)" };
|
|
6
5
|
const DROP = { none: "", sm: "var(--shadow-xs)", md: "var(--shadow-md)", lg: "var(--shadow-lg)" };
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const lifted = interactive && st.hover;
|
|
6
|
+
const NO_SHADOW = "0 0 0 0 transparent";
|
|
7
|
+
function Card({ padding = "md", elevation = "sm", interactive = false, selected = false, children, style, className, onClick, onKeyDown, ...rest }) {
|
|
10
8
|
const clickable = interactive && !!onClick;
|
|
11
|
-
const ring = selected ? "0 0 0 1.5px var(--border-brand)" : "0 0 0 1px
|
|
12
|
-
const
|
|
9
|
+
const ring = selected ? "0 0 0 1.5px var(--border-brand)" : "0 0 0 1px var(--border-default)";
|
|
10
|
+
const ringHover = selected ? ring : "0 0 0 1px var(--border-strong)";
|
|
11
|
+
const drop = (selected ? "var(--shadow-md)" : DROP[elevation]) || NO_SHADOW;
|
|
12
|
+
const dropHover = selected ? "var(--shadow-md)" : elevation === "lg" ? "var(--shadow-lg)" : "var(--shadow-md)";
|
|
13
13
|
return /* @__PURE__ */ jsx(
|
|
14
14
|
"div",
|
|
15
15
|
{
|
|
16
|
-
...interactive ? st.handlers : {},
|
|
17
16
|
role: clickable ? "button" : void 0,
|
|
18
17
|
tabIndex: clickable ? 0 : void 0,
|
|
19
18
|
onClick,
|
|
@@ -25,17 +24,21 @@ function Card({ padding = "md", elevation = "sm", interactive = false, selected
|
|
|
25
24
|
onKeyDown?.(e);
|
|
26
25
|
} : onKeyDown,
|
|
27
26
|
...rest,
|
|
27
|
+
className: ["sereno-card", className].filter(Boolean).join(" "),
|
|
28
|
+
"data-interactive": interactive || void 0,
|
|
29
|
+
"data-clickable": clickable || void 0,
|
|
28
30
|
style: sx({
|
|
31
|
+
"--sd-ring": ring,
|
|
32
|
+
"--sd-ring-h": ringHover,
|
|
33
|
+
"--sd-drop": drop,
|
|
34
|
+
"--sd-drop-h": dropHover,
|
|
29
35
|
background: "var(--bg-surface)",
|
|
30
36
|
borderRadius: "var(--radius-card)",
|
|
31
37
|
padding: PADS[padding],
|
|
32
|
-
boxShadow: [ring, drop, clickable && st.focus ? "var(--focus-ring)" : null].filter(Boolean).join(", "),
|
|
33
|
-
transform: lifted && !st.press ? "translateY(var(--hover-lift))" : interactive && st.press ? "scale(var(--press-scale))" : "none",
|
|
34
38
|
transition: "var(--transition-control)",
|
|
35
39
|
cursor: interactive ? "pointer" : "default",
|
|
36
40
|
// outline:none is safe here (unlike the CSS-class pattern elsewhere in
|
|
37
|
-
// this package)
|
|
38
|
-
// the same useInteract-based substitute Button/IconButton already use.
|
|
41
|
+
// this package): the focus ring is the box-shadow `.sereno-card[data-clickable]:focus-visible` draws.
|
|
39
42
|
outline: clickable ? "none" : void 0,
|
|
40
43
|
...style
|
|
41
44
|
}),
|
package/dist/core/Card.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/Card.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { sx } from '../_internal/style';\
|
|
1
|
+
{"version":3,"sources":["../../src/core/Card.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { sx } from '../_internal/style';\n\n/** Neutral surface container: a crisp 1px ring + optional soft lift + 14px radius. The base of every list row and panel. */\nexport interface CardProps extends React.HTMLAttributes<HTMLDivElement> {\n padding?: 'none' | 'sm' | 'md' | 'lg';\n elevation?: 'none' | 'sm' | 'md' | 'lg';\n /** Adds hover lift, press scale and pointer cursor. */\n interactive?: boolean;\n /** Brand-coloured ring for a chosen option. */\n selected?: boolean;\n children?: React.ReactNode;\n}\n\nconst PADS = { none: 0, sm: 'var(--space-3)', md: 'var(--space-4)', lg: 'var(--space-5)' } as const;\n// The edge is a box-shadow ring (pixel-crisp at any radius), with the elevation\n// drop-shadow layered beneath it - never a real `border` fighting the shadow.\nconst DROP = { none: '', sm: 'var(--shadow-xs)', md: 'var(--shadow-md)', lg: 'var(--shadow-lg)' } as const;\n/** A shadow that draws nothing: lets `box-shadow: ring, drop` stay valid when there is no drop (`elevation=\"none\"`). */\nconst NO_SHADOW = '0 0 0 0 transparent';\n\nexport function Card({ padding = 'md', elevation = 'sm', interactive = false, selected = false, children, style, className, onClick, onKeyDown, ...rest }: CardProps) {\n // A Card only needs real button semantics (SS-228) when it owns its own\n // onClick - `interactive` alone (no onClick) means it's just borrowing the\n // hover/press visual inside an already-interactive wrapper (e.g. the\n // landing page's Cards inside a <Link>), and giving it a tabIndex there\n // would nest one focusable control inside another.\n const clickable = interactive && !!onClick;\n\n // The edge is a ring and the lift a drop shadow, each with its hover value. `.sereno-card` (styles.css)\n // switches between them on :hover / :active / :focus-visible (SS-577), so the card keeps no state.\n const ring = selected ? '0 0 0 1.5px var(--border-brand)' : '0 0 0 1px var(--border-default)';\n const ringHover = selected ? ring : '0 0 0 1px var(--border-strong)';\n const drop = (selected ? 'var(--shadow-md)' : DROP[elevation]) || NO_SHADOW;\n const dropHover = selected ? 'var(--shadow-md)' : elevation === 'lg' ? 'var(--shadow-lg)' : 'var(--shadow-md)';\n\n return (\n <div\n role={clickable ? 'button' : undefined}\n tabIndex={clickable ? 0 : undefined}\n onClick={onClick}\n onKeyDown={\n clickable\n ? (e) => {\n if (e.key === 'Enter' || e.key === ' ') {\n e.preventDefault();\n // Not a real MouseEvent - every onClick in this codebase ignores\n // the event argument, so the cast is safe in practice.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- see above\n onClick(e as any);\n }\n onKeyDown?.(e);\n }\n : onKeyDown\n }\n {...rest}\n className={['sereno-card', className].filter(Boolean).join(' ')}\n data-interactive={interactive || undefined}\n data-clickable={clickable || undefined}\n style={sx({\n '--sd-ring': ring,\n '--sd-ring-h': ringHover,\n '--sd-drop': drop,\n '--sd-drop-h': dropHover,\n background: 'var(--bg-surface)',\n borderRadius: 'var(--radius-card)',\n padding: PADS[padding],\n transition: 'var(--transition-control)',\n cursor: interactive ? 'pointer' : 'default',\n // outline:none is safe here (unlike the CSS-class pattern elsewhere in\n // this package): the focus ring is the box-shadow `.sereno-card[data-clickable]:focus-visible` draws.\n outline: clickable ? 'none' : undefined,\n ...style,\n })}\n >\n {children}\n </div>\n );\n}\n"],"mappings":";AAuCI;AApCJ,SAAS,UAAU;AAanB,MAAM,OAAO,EAAE,MAAM,GAAG,IAAI,kBAAkB,IAAI,kBAAkB,IAAI,iBAAiB;AAGzF,MAAM,OAAO,EAAE,MAAM,IAAI,IAAI,oBAAoB,IAAI,oBAAoB,IAAI,mBAAmB;AAEhG,MAAM,YAAY;AAEX,SAAS,KAAK,EAAE,UAAU,MAAM,YAAY,MAAM,cAAc,OAAO,WAAW,OAAO,UAAU,OAAO,WAAW,SAAS,WAAW,GAAG,KAAK,GAAc;AAMpK,QAAM,YAAY,eAAe,CAAC,CAAC;AAInC,QAAM,OAAO,WAAW,oCAAoC;AAC5D,QAAM,YAAY,WAAW,OAAO;AACpC,QAAM,QAAQ,WAAW,qBAAqB,KAAK,SAAS,MAAM;AAClE,QAAM,YAAY,WAAW,qBAAqB,cAAc,OAAO,qBAAqB;AAE5F,SACE;AAAA,IAAC;AAAA;AAAA,MACC,MAAM,YAAY,WAAW;AAAA,MAC7B,UAAU,YAAY,IAAI;AAAA,MAC1B;AAAA,MACA,WACE,YACI,CAAC,MAAM;AACL,YAAI,EAAE,QAAQ,WAAW,EAAE,QAAQ,KAAK;AACtC,YAAE,eAAe;AAIjB,kBAAQ,CAAQ;AAAA,QAClB;AACA,oBAAY,CAAC;AAAA,MACf,IACA;AAAA,MAEL,GAAG;AAAA,MACJ,WAAW,CAAC,eAAe,SAAS,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG;AAAA,MAC9D,oBAAkB,eAAe;AAAA,MACjC,kBAAgB,aAAa;AAAA,MAC7B,OAAO,GAAG;AAAA,QACR,aAAa;AAAA,QACb,eAAe;AAAA,QACf,aAAa;AAAA,QACb,eAAe;AAAA,QACf,YAAY;AAAA,QACZ,cAAc;AAAA,QACd,SAAS,KAAK,OAAO;AAAA,QACrB,YAAY;AAAA,QACZ,QAAQ,cAAc,YAAY;AAAA;AAAA;AAAA,QAGlC,SAAS,YAAY,SAAS;AAAA,QAC9B,GAAG;AAAA,MACL,CAAC;AAAA,MAEA;AAAA;AAAA,EACH;AAEJ;","names":[]}
|
|
@@ -13,6 +13,6 @@ interface IconButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>
|
|
|
13
13
|
/** The icon element (Lucide 20px stroke 1.75). */
|
|
14
14
|
children?: React.ReactNode;
|
|
15
15
|
}
|
|
16
|
-
declare function IconButton({ variant, size, label, disabled, children, style, ...rest }: IconButtonProps): React.JSX.Element;
|
|
16
|
+
declare function IconButton({ variant, size, label, disabled, children, className, style, ...rest }: IconButtonProps): React.JSX.Element;
|
|
17
17
|
|
|
18
18
|
export { IconButton, type IconButtonProps };
|
package/dist/core/IconButton.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { sx } from "../_internal/style.js";
|
|
4
|
-
import { useInteract } from "./Button.js";
|
|
5
4
|
const S = { sm: 32, md: 40, lg: 48 };
|
|
6
5
|
const SOLID = {
|
|
7
6
|
primary: ["--interactive-primary", "--interactive-primary-hover", "--interactive-primary-fg"],
|
|
@@ -9,24 +8,22 @@ const SOLID = {
|
|
|
9
8
|
warning: ["--interactive-warning", "--interactive-warning-hover", "--interactive-warning-fg"],
|
|
10
9
|
error: ["--interactive-error", "--interactive-error-hover", "--interactive-error-fg"]
|
|
11
10
|
};
|
|
12
|
-
function IconButton({ variant = "ghost", size = "md", label, disabled = false, children, style, ...rest }) {
|
|
13
|
-
const st = useInteract(disabled);
|
|
11
|
+
function IconButton({ variant = "ghost", size = "md", label, disabled = false, children, className, style, ...rest }) {
|
|
14
12
|
const d = S[size] || S.md;
|
|
15
13
|
const solid = SOLID[variant];
|
|
16
14
|
const outline = variant === "secondary";
|
|
17
|
-
let
|
|
18
|
-
let color = "var(--text-secondary)";
|
|
15
|
+
let vars;
|
|
19
16
|
if (disabled) {
|
|
20
|
-
|
|
21
|
-
color = "var(--interactive-disabled-fg)";
|
|
17
|
+
vars = { "--sd-bg": "var(--interactive-disabled-bg)", "--sd-fg": "var(--interactive-disabled-fg)" };
|
|
22
18
|
} else if (solid) {
|
|
23
|
-
|
|
24
|
-
color = `var(${solid[2]})`;
|
|
19
|
+
vars = { "--sd-bg": `var(${solid[0]})`, "--sd-bg-hover": `var(${solid[1]})`, "--sd-fg": `var(${solid[2]})` };
|
|
25
20
|
} else if (outline) {
|
|
26
|
-
|
|
27
|
-
} else
|
|
28
|
-
|
|
21
|
+
vars = { "--sd-bg": "var(--interactive-secondary)", "--sd-bg-hover": "var(--interactive-secondary-hover)", "--sd-fg": "var(--text-secondary)" };
|
|
22
|
+
} else {
|
|
23
|
+
vars = { "--sd-bg": "transparent", "--sd-bg-hover": "var(--interactive-ghost-hover)", "--sd-fg": "var(--text-secondary)" };
|
|
29
24
|
}
|
|
25
|
+
vars["--sd-bd"] = outline ? "var(--border-default)" : "transparent";
|
|
26
|
+
vars["--sd-sh"] = "none";
|
|
30
27
|
return /* @__PURE__ */ jsx(
|
|
31
28
|
"button",
|
|
32
29
|
{
|
|
@@ -34,9 +31,10 @@ function IconButton({ variant = "ghost", size = "md", label, disabled = false, c
|
|
|
34
31
|
"aria-label": label,
|
|
35
32
|
title: label,
|
|
36
33
|
disabled,
|
|
37
|
-
...st.handlers,
|
|
38
34
|
...rest,
|
|
35
|
+
className: ["sereno-btn", className].filter(Boolean).join(" "),
|
|
39
36
|
style: sx({
|
|
37
|
+
...vars,
|
|
40
38
|
display: "inline-flex",
|
|
41
39
|
alignItems: "center",
|
|
42
40
|
justifyContent: "center",
|
|
@@ -44,11 +42,8 @@ function IconButton({ variant = "ghost", size = "md", label, disabled = false, c
|
|
|
44
42
|
height: d,
|
|
45
43
|
flex: "0 0 auto",
|
|
46
44
|
borderRadius: "var(--radius-control)",
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
color,
|
|
50
|
-
boxShadow: st.focus ? "var(--focus-ring)" : "none",
|
|
51
|
-
transform: st.press && !disabled ? "scale(var(--press-scale))" : "none",
|
|
45
|
+
borderWidth: "var(--border-width-hairline)",
|
|
46
|
+
borderStyle: "solid",
|
|
52
47
|
cursor: disabled ? "not-allowed" : "pointer",
|
|
53
48
|
transition: "var(--transition-control)",
|
|
54
49
|
outline: "none",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/IconButton.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { sx } from '../_internal/style';\
|
|
1
|
+
{"version":3,"sources":["../../src/core/IconButton.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { sx } from '../_internal/style';\n\n/**\n * Square icon-only control for toolbars, card corners and top bars. Always pass `label`.\n * `success` / `warning` / `error` are solid semantic fills - same words as Button / Badge.\n */\nexport interface IconButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n variant?: 'ghost' | 'secondary' | 'primary' | 'success' | 'warning' | 'error';\n size?: 'sm' | 'md' | 'lg';\n /** Accessible name - becomes aria-label and title. Required. */\n label: string;\n disabled?: boolean;\n /** The icon element (Lucide 20px stroke 1.75). */\n children?: React.ReactNode;\n}\n\nconst S = { sm: 32, md: 40, lg: 48 } as const;\n\n/** Solid-fill variants: [base, hover, fg]. */\nconst SOLID: Partial<Record<NonNullable<IconButtonProps['variant']>, [string, string, string]>> = {\n primary: ['--interactive-primary', '--interactive-primary-hover', '--interactive-primary-fg'],\n success: ['--interactive-success', '--interactive-success-hover', '--interactive-success-fg'],\n warning: ['--interactive-warning', '--interactive-warning-hover', '--interactive-warning-fg'],\n error: ['--interactive-error', '--interactive-error-hover', '--interactive-error-fg'],\n};\n\nexport function IconButton({ variant = 'ghost', size = 'md', label, disabled = false, children, className, style, ...rest }: IconButtonProps) {\n const d = S[size] || S.md;\n const solid = SOLID[variant];\n const outline = variant === 'secondary';\n\n // The values of each state, for `.sereno-btn` (styles.css) to switch between on :hover / :active / :focus-visible\n // (SS-577). Only a press scale and a focus ring are common to all; the rest is per variant.\n let vars: Record<string, string>;\n if (disabled) {\n vars = { '--sd-bg': 'var(--interactive-disabled-bg)', '--sd-fg': 'var(--interactive-disabled-fg)' };\n } else if (solid) {\n vars = { '--sd-bg': `var(${solid[0]})`, '--sd-bg-hover': `var(${solid[1]})`, '--sd-fg': `var(${solid[2]})` };\n } else if (outline) {\n vars = { '--sd-bg': 'var(--interactive-secondary)', '--sd-bg-hover': 'var(--interactive-secondary-hover)', '--sd-fg': 'var(--text-secondary)' };\n } else {\n vars = { '--sd-bg': 'transparent', '--sd-bg-hover': 'var(--interactive-ghost-hover)', '--sd-fg': 'var(--text-secondary)' };\n }\n vars['--sd-bd'] = outline ? 'var(--border-default)' : 'transparent';\n vars['--sd-sh'] = 'none';\n\n return (\n <button\n type=\"button\"\n aria-label={label}\n title={label}\n disabled={disabled}\n {...rest}\n className={['sereno-btn', className].filter(Boolean).join(' ')}\n style={sx({\n ...vars,\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n width: d,\n height: d,\n flex: '0 0 auto',\n borderRadius: 'var(--radius-control)',\n borderWidth: 'var(--border-width-hairline)',\n borderStyle: 'solid',\n cursor: disabled ? 'not-allowed' : 'pointer',\n transition: 'var(--transition-control)',\n outline: 'none',\n ...style,\n })}\n >\n {children}\n </button>\n );\n}\n"],"mappings":";AAkDI;AA/CJ,SAAS,UAAU;AAgBnB,MAAM,IAAI,EAAE,IAAI,IAAI,IAAI,IAAI,IAAI,GAAG;AAGnC,MAAM,QAA4F;AAAA,EAChG,SAAS,CAAC,yBAAyB,+BAA+B,0BAA0B;AAAA,EAC5F,SAAS,CAAC,yBAAyB,+BAA+B,0BAA0B;AAAA,EAC5F,SAAS,CAAC,yBAAyB,+BAA+B,0BAA0B;AAAA,EAC5F,OAAO,CAAC,uBAAuB,6BAA6B,wBAAwB;AACtF;AAEO,SAAS,WAAW,EAAE,UAAU,SAAS,OAAO,MAAM,OAAO,WAAW,OAAO,UAAU,WAAW,OAAO,GAAG,KAAK,GAAoB;AAC5I,QAAM,IAAI,EAAE,IAAI,KAAK,EAAE;AACvB,QAAM,QAAQ,MAAM,OAAO;AAC3B,QAAM,UAAU,YAAY;AAI5B,MAAI;AACJ,MAAI,UAAU;AACZ,WAAO,EAAE,WAAW,kCAAkC,WAAW,iCAAiC;AAAA,EACpG,WAAW,OAAO;AAChB,WAAO,EAAE,WAAW,OAAO,MAAM,CAAC,CAAC,KAAK,iBAAiB,OAAO,MAAM,CAAC,CAAC,KAAK,WAAW,OAAO,MAAM,CAAC,CAAC,IAAI;AAAA,EAC7G,WAAW,SAAS;AAClB,WAAO,EAAE,WAAW,gCAAgC,iBAAiB,sCAAsC,WAAW,wBAAwB;AAAA,EAChJ,OAAO;AACL,WAAO,EAAE,WAAW,eAAe,iBAAiB,kCAAkC,WAAW,wBAAwB;AAAA,EAC3H;AACA,OAAK,SAAS,IAAI,UAAU,0BAA0B;AACtD,OAAK,SAAS,IAAI;AAElB,SACE;AAAA,IAAC;AAAA;AAAA,MACC,MAAK;AAAA,MACL,cAAY;AAAA,MACZ,OAAO;AAAA,MACP;AAAA,MACC,GAAG;AAAA,MACJ,WAAW,CAAC,cAAc,SAAS,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG;AAAA,MAC7D,OAAO,GAAG;AAAA,QACR,GAAG;AAAA,QACH,SAAS;AAAA,QACT,YAAY;AAAA,QACZ,gBAAgB;AAAA,QAChB,OAAO;AAAA,QACP,QAAQ;AAAA,QACR,MAAM;AAAA,QACN,cAAc;AAAA,QACd,aAAa;AAAA,QACb,aAAa;AAAA,QACb,QAAQ,WAAW,gBAAgB;AAAA,QACnC,YAAY;AAAA,QACZ,SAAS;AAAA,QACT,GAAG;AAAA,MACL,CAAC;AAAA,MAEA;AAAA;AAAA,EACH;AAEJ;","names":[]}
|
|
@@ -5,6 +5,10 @@ import '../_internal/mask.js';
|
|
|
5
5
|
/**
|
|
6
6
|
* A search field: `Input` with a leading magnifier, a clear (×) button, and a
|
|
7
7
|
* **debounced** `onSearch`. `Enter` searches immediately; `Esc` clears.
|
|
8
|
+
*
|
|
9
|
+
* A caller's `onKeyDown` runs first, on every key. Calling `preventDefault()` on
|
|
10
|
+
* the event there says it was handled, and the built-in `Enter` / `Esc` are skipped
|
|
11
|
+
* (the same "handled" rule a popup's `Esc` follows inside a `Dialog`).
|
|
8
12
|
*/
|
|
9
13
|
interface SearchInputProps extends Omit<InputProps, 'iconLeft' | 'suffix' | 'prefix' | 'type' | 'mask' | 'showCount' | 'value' | 'defaultValue' | 'onChange'> {
|
|
10
14
|
value?: string;
|
|
@@ -4,7 +4,7 @@ import * as React from "react";
|
|
|
4
4
|
import { Search, X } from "lucide-react";
|
|
5
5
|
import { sx } from "../_internal/style.js";
|
|
6
6
|
import { Input } from "./Input.js";
|
|
7
|
-
const SearchInput = React.forwardRef(function SearchInput2({ value, defaultValue, onValueChange, onSearch, debounce = 250, clearLabel = "Clear search", placeholder = "Search\u2026", disabled, ...rest }, ref) {
|
|
7
|
+
const SearchInput = React.forwardRef(function SearchInput2({ value, defaultValue, onValueChange, onSearch, onKeyDown, debounce = 250, clearLabel = "Clear search", placeholder = "Search\u2026", disabled, ...rest }, ref) {
|
|
8
8
|
const [internal, setInternal] = React.useState(defaultValue ?? "");
|
|
9
9
|
const text = value !== void 0 ? value : internal;
|
|
10
10
|
const timer = React.useRef(void 0);
|
|
@@ -20,6 +20,15 @@ const SearchInput = React.forwardRef(function SearchInput2({ value, defaultValue
|
|
|
20
20
|
runSearch(v, immediate);
|
|
21
21
|
};
|
|
22
22
|
const clear = () => update("", true);
|
|
23
|
+
const handleKeyDown = (e) => {
|
|
24
|
+
onKeyDown?.(e);
|
|
25
|
+
if (e.defaultPrevented) return;
|
|
26
|
+
if (e.key === "Enter") runSearch(e.currentTarget.value, true);
|
|
27
|
+
else if (e.key === "Escape" && text) {
|
|
28
|
+
e.preventDefault();
|
|
29
|
+
clear();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
23
32
|
return /* @__PURE__ */ jsx(
|
|
24
33
|
Input,
|
|
25
34
|
{
|
|
@@ -33,13 +42,7 @@ const SearchInput = React.forwardRef(function SearchInput2({ value, defaultValue
|
|
|
33
42
|
disabled,
|
|
34
43
|
value: text,
|
|
35
44
|
onChange: (e) => update(e.currentTarget.value),
|
|
36
|
-
onKeyDown:
|
|
37
|
-
if (e.key === "Enter") runSearch(e.currentTarget.value, true);
|
|
38
|
-
else if (e.key === "Escape" && text) {
|
|
39
|
-
e.preventDefault();
|
|
40
|
-
clear();
|
|
41
|
-
}
|
|
42
|
-
},
|
|
45
|
+
onKeyDown: handleKeyDown,
|
|
43
46
|
iconLeft: /* @__PURE__ */ jsx(Search, { size: 16, strokeWidth: 1.75 }),
|
|
44
47
|
suffix: text && !disabled ? /* @__PURE__ */ jsx(
|
|
45
48
|
"button",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/forms/SearchInput.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { Search, X } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { Input, type InputProps } from './Input';\n\n/**\n * A search field: `Input` with a leading magnifier, a clear (×) button, and a\n * **debounced** `onSearch`. `Enter` searches immediately; `Esc` clears.\n */\nexport interface SearchInputProps\n extends Omit<InputProps, 'iconLeft' | 'suffix' | 'prefix' | 'type' | 'mask' | 'showCount' | 'value' | 'defaultValue' | 'onChange'> {\n value?: string;\n defaultValue?: string;\n /** Every keystroke and on clear - the plain string. */\n onValueChange?: (value: string) => void;\n /** Debounced (and on `Enter` / clear) - run the actual query here. */\n onSearch?: (value: string) => void;\n /** Debounce for `onSearch`, in ms. */\n debounce?: number;\n /** aria-label for the clear button. */\n clearLabel?: string;\n}\n\nexport const SearchInput = React.forwardRef<HTMLInputElement, SearchInputProps>(function SearchInput(\n { value, defaultValue, onValueChange, onSearch, debounce = 250, clearLabel = 'Clear search', placeholder = 'Search…', disabled, ...rest },\n ref,\n) {\n const [internal, setInternal] = React.useState(defaultValue ?? '');\n const text = value !== undefined ? value : internal;\n\n const timer = React.useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n React.useEffect(() => () => clearTimeout(timer.current), []);\n\n const runSearch = (v: string, immediate: boolean) => {\n clearTimeout(timer.current);\n if (immediate) onSearch?.(v);\n else timer.current = setTimeout(() => onSearch?.(v), debounce);\n };\n\n const update = (v: string, immediate = false) => {\n if (value === undefined) setInternal(v);\n onValueChange?.(v);\n runSearch(v, immediate);\n };\n\n const clear = () => update('', true);\n\n return (\n <Input\n ref={ref}\n {...rest}\n role=\"searchbox\"\n enterKeyHint=\"search\"\n autoComplete=\"off\"\n spellCheck={false}\n placeholder={placeholder}\n disabled={disabled}\n value={text}\n onChange={(e) => update(e.currentTarget.value)}\n onKeyDown={
|
|
1
|
+
{"version":3,"sources":["../../src/forms/SearchInput.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { Search, X } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { Input, type InputProps } from './Input';\n\n/**\n * A search field: `Input` with a leading magnifier, a clear (×) button, and a\n * **debounced** `onSearch`. `Enter` searches immediately; `Esc` clears.\n *\n * A caller's `onKeyDown` runs first, on every key. Calling `preventDefault()` on\n * the event there says it was handled, and the built-in `Enter` / `Esc` are skipped\n * (the same \"handled\" rule a popup's `Esc` follows inside a `Dialog`).\n */\nexport interface SearchInputProps\n extends Omit<InputProps, 'iconLeft' | 'suffix' | 'prefix' | 'type' | 'mask' | 'showCount' | 'value' | 'defaultValue' | 'onChange'> {\n value?: string;\n defaultValue?: string;\n /** Every keystroke and on clear - the plain string. */\n onValueChange?: (value: string) => void;\n /** Debounced (and on `Enter` / clear) - run the actual query here. */\n onSearch?: (value: string) => void;\n /** Debounce for `onSearch`, in ms. */\n debounce?: number;\n /** aria-label for the clear button. */\n clearLabel?: string;\n}\n\nexport const SearchInput = React.forwardRef<HTMLInputElement, SearchInputProps>(function SearchInput(\n { value, defaultValue, onValueChange, onSearch, onKeyDown, debounce = 250, clearLabel = 'Clear search', placeholder = 'Search…', disabled, ...rest },\n ref,\n) {\n const [internal, setInternal] = React.useState(defaultValue ?? '');\n const text = value !== undefined ? value : internal;\n\n const timer = React.useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n React.useEffect(() => () => clearTimeout(timer.current), []);\n\n const runSearch = (v: string, immediate: boolean) => {\n clearTimeout(timer.current);\n if (immediate) onSearch?.(v);\n else timer.current = setTimeout(() => onSearch?.(v), debounce);\n };\n\n const update = (v: string, immediate = false) => {\n if (value === undefined) setInternal(v);\n onValueChange?.(v);\n runSearch(v, immediate);\n };\n\n const clear = () => update('', true);\n\n // Composed, not replaced: a plain `{...rest}` spread followed by our own `onKeyDown` used to drop the caller's\n // silently (the same class of bug `Input` and `Textarea` already guard against for onFocus / onBlur / onChange).\n // The caller's runs first and can opt out of the built-in keys with `preventDefault()`.\n const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n onKeyDown?.(e);\n if (e.defaultPrevented) return;\n if (e.key === 'Enter') runSearch(e.currentTarget.value, true);\n else if (e.key === 'Escape' && text) {\n e.preventDefault();\n clear();\n }\n };\n\n return (\n <Input\n ref={ref}\n {...rest}\n role=\"searchbox\"\n enterKeyHint=\"search\"\n autoComplete=\"off\"\n spellCheck={false}\n placeholder={placeholder}\n disabled={disabled}\n value={text}\n onChange={(e) => update(e.currentTarget.value)}\n onKeyDown={handleKeyDown}\n iconLeft={<Search size={16} strokeWidth={1.75} />}\n suffix={\n text && !disabled ? (\n <button\n type=\"button\"\n className=\"ds-affix-btn\"\n aria-label={clearLabel}\n onClick={clear}\n style={sx({ display: 'inline-flex', alignItems: 'center', border: 'none', background: 'transparent', color: 'var(--text-muted)', cursor: 'pointer', padding: 0 })}\n >\n <X size={16} strokeWidth={2} />\n </button>\n ) : undefined\n }\n />\n );\n});\n\nSearchInput.displayName = 'SearchInput';\n"],"mappings":";AA+EgB;AA7EhB,YAAY,WAAW;AACvB,SAAS,QAAQ,SAAS;AAC1B,SAAS,UAAU;AACnB,SAAS,aAA8B;AAwBhC,MAAM,cAAc,MAAM,WAA+C,SAASA,aACvF,EAAE,OAAO,cAAc,eAAe,UAAU,WAAW,WAAW,KAAK,aAAa,gBAAgB,cAAc,gBAAW,UAAU,GAAG,KAAK,GACnJ,KACA;AACA,QAAM,CAAC,UAAU,WAAW,IAAI,MAAM,SAAS,gBAAgB,EAAE;AACjE,QAAM,OAAO,UAAU,SAAY,QAAQ;AAE3C,QAAM,QAAQ,MAAM,OAAkD,MAA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GAAG;AAAA;AAAA,MAC/B,IACE;AAAA;AAAA,EAER;AAEJ,CAAC;AAED,YAAY,cAAc;","names":["SearchInput"]}
|
package/dist/styles.css
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
The Sereno components are token-driven inline styles, but a handful of things
|
|
5
5
|
can't live in an inline `style`: @keyframes, pseudo-classes (:checked,
|
|
6
|
-
:focus-visible
|
|
6
|
+
:focus-visible, and the :hover / :active / :focus-visible of Button, IconButton
|
|
7
|
+
and Card, SS-577), pseudo-elements (::-webkit-scrollbar) and one narrow
|
|
7
8
|
responsive reflow. Those rules live here and MUST be loaded once, at the app
|
|
8
9
|
root, for the components to render correctly:
|
|
9
10
|
|
|
@@ -33,6 +34,58 @@
|
|
|
33
34
|
@keyframes sereno-toast-out { to { opacity: 0; transform: scale(0.96); } }
|
|
34
35
|
@keyframes sereno-toast-bar { from { transform: scaleX(1); } to { transform: scaleX(0); } }
|
|
35
36
|
|
|
37
|
+
/* ── Button / IconButton / Card: hover, press and keyboard focus (SS-577) ──────────────
|
|
38
|
+
The component declares what each state looks like as custom properties on the element
|
|
39
|
+
(`--sd-bg`, `--sd-bg-hover`, ...) and these rules switch between them, so the browser does
|
|
40
|
+
the work and a button holds no hover / press / focus state (before: three useState and five
|
|
41
|
+
handlers per instance, re-rendering on every hover). It also means an app can restyle a
|
|
42
|
+
state with plain CSS (`.sereno-btn:hover { ... }`) with no `!important`.
|
|
43
|
+
|
|
44
|
+
Order matters: hover, then active (a press while hovering), then focus-visible (the ring wins).
|
|
45
|
+
A property a variant does not set falls back to the one before it. `:disabled` is excluded:
|
|
46
|
+
a disabled control, and a `loading` one, has no states. The `:where()` keeps each state rule at the
|
|
47
|
+
specificity of `.sereno-btn:hover` (0,2,0), so an app's own `.my-button:hover` overrides it by being
|
|
48
|
+
later in the cascade; the base `.sereno-btn` stays (0,1,0) so it still beats a global `button {}` reset. */
|
|
49
|
+
.sereno-btn {
|
|
50
|
+
background: var(--sd-bg);
|
|
51
|
+
color: var(--sd-fg);
|
|
52
|
+
border-color: var(--sd-bd);
|
|
53
|
+
box-shadow: var(--sd-sh, none);
|
|
54
|
+
}
|
|
55
|
+
.sereno-btn:hover:where(:not(:disabled)) {
|
|
56
|
+
background: var(--sd-bg-hover, var(--sd-bg));
|
|
57
|
+
color: var(--sd-fg-hover, var(--sd-fg));
|
|
58
|
+
box-shadow: var(--sd-sh-hover, var(--sd-sh, none));
|
|
59
|
+
text-decoration: var(--sd-deco-hover, none);
|
|
60
|
+
}
|
|
61
|
+
.sereno-btn:active:where(:not(:disabled)) {
|
|
62
|
+
background: var(--sd-bg-active, var(--sd-bg-hover, var(--sd-bg)));
|
|
63
|
+
box-shadow: var(--sd-sh, none);
|
|
64
|
+
transform: scale(var(--press-scale));
|
|
65
|
+
}
|
|
66
|
+
.sereno-btn:focus-visible:where(:not(:disabled)) {
|
|
67
|
+
box-shadow: var(--sd-ring, var(--focus-ring));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* Card: a ring and a drop shadow, each with its hover value; `data-interactive` lifts on hover and
|
|
71
|
+
scales on press, `data-clickable` (a card with its own onClick) also gets the focus ring. */
|
|
72
|
+
.sereno-card {
|
|
73
|
+
box-shadow: var(--sd-ring), var(--sd-drop);
|
|
74
|
+
}
|
|
75
|
+
.sereno-card[data-interactive]:hover {
|
|
76
|
+
box-shadow: var(--sd-ring-h), var(--sd-drop-h);
|
|
77
|
+
transform: translateY(var(--hover-lift));
|
|
78
|
+
}
|
|
79
|
+
.sereno-card[data-interactive]:active {
|
|
80
|
+
transform: scale(var(--press-scale));
|
|
81
|
+
}
|
|
82
|
+
.sereno-card[data-clickable]:focus-visible {
|
|
83
|
+
box-shadow: var(--sd-ring), var(--sd-drop), var(--focus-ring);
|
|
84
|
+
}
|
|
85
|
+
.sereno-card[data-clickable]:hover:focus-visible {
|
|
86
|
+
box-shadow: var(--sd-ring-h), var(--sd-drop-h), var(--focus-ring);
|
|
87
|
+
}
|
|
88
|
+
|
|
36
89
|
/* ── Checkbox / Radio / Switch ───────────────────────────────────────────────
|
|
37
90
|
Checkbox and Radio render bare <input>s; Switch is a role="switch" <span>.
|
|
38
91
|
All three need these host rules for their checked / focus states. */
|