@techsio/ui-kit 0.58.0 → 0.59.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 +53 -16
- package/dist/atoms/button.js +40 -4
- package/dist/atoms/image.js +12 -2
- package/dist/atoms/link-button.js +2 -1
- package/dist/atoms/numeric-input.js +70 -9
- package/dist/molecules/chart.js +154 -43
- package/dist/molecules/combobox.js +3 -1
- package/dist/molecules/date-picker.js +66 -8
- package/dist/molecules/dialog.js +11 -4
- package/dist/molecules/drawer.js +10 -2
- package/dist/molecules/product-card.js +65 -8
- package/dist/molecules/switch.js +3 -2
- package/dist/molecules/toast.js +12 -5
- package/dist/organisms/data-table.fields.js +1 -0
- package/dist/organisms/data-table.js +7 -3
- package/dist/src/atoms/badge.d.ts +1 -1
- package/dist/src/atoms/button.d.ts +23 -11
- package/dist/src/atoms/button.d.ts.map +1 -1
- package/dist/src/atoms/image.d.ts +25 -2
- package/dist/src/atoms/image.d.ts.map +1 -1
- package/dist/src/atoms/input.d.ts +1 -1
- package/dist/src/atoms/link-button.d.ts +38 -14
- package/dist/src/atoms/link-button.d.ts.map +1 -1
- package/dist/src/atoms/numeric-input.d.ts +3 -2
- package/dist/src/atoms/numeric-input.d.ts.map +1 -1
- package/dist/src/atoms/textarea.d.ts +1 -1
- package/dist/src/molecules/chart.d.ts +12 -1
- package/dist/src/molecules/chart.d.ts.map +1 -1
- package/dist/src/molecules/combobox.d.ts +6 -2
- package/dist/src/molecules/combobox.d.ts.map +1 -1
- package/dist/src/molecules/date-picker.d.ts +24 -2
- package/dist/src/molecules/date-picker.d.ts.map +1 -1
- package/dist/src/molecules/dialog.d.ts +11 -2
- package/dist/src/molecules/dialog.d.ts.map +1 -1
- package/dist/src/molecules/drawer.d.ts.map +1 -1
- package/dist/src/molecules/product-card.d.ts +109 -4
- package/dist/src/molecules/product-card.d.ts.map +1 -1
- package/dist/src/molecules/switch.d.ts.map +1 -1
- package/dist/src/molecules/toast.d.ts +14 -2
- package/dist/src/molecules/toast.d.ts.map +1 -1
- package/dist/src/organisms/data-table.d.ts +5 -1
- package/dist/src/organisms/data-table.d.ts.map +1 -1
- package/dist/src/organisms/data-table.fields.d.ts.map +1 -1
- package/dist/src/templates/numeric-input.d.ts +1 -1
- package/dist/src/templates/product-card.d.ts +1 -1
- package/package.json +3 -1
- package/src/tokens/_business-atoms.css +0 -7
- package/src/tokens/_scheme-scopes.css +73 -23
- package/src/tokens/components/atoms/_button.css +10 -0
- package/src/tokens/components/atoms/_input.css +1 -1
- package/src/tokens/components/atoms/_numeric-input.css +10 -0
- package/src/tokens/components/molecules/_chart.css +24 -6
- package/src/tokens/components/molecules/_product-card.css +21 -0
- package/src/tokens/figma/akros/variables.css +10 -1
- package/src/tokens/figma/brand-overrides.css +9 -0
- package/src/tokens/figma/business/variables.css +10 -1
- package/src/tokens/figma/dark/variables.css +10 -1
- package/src/tokens/figma/light/variables.css +20 -10
- package/src/tokens/figma/n1/variables.css +10 -1
- package/src/tokens/figma/variables.css +19 -9
package/README.md
CHANGED
|
@@ -167,7 +167,18 @@ and remove the duplicate bridge declarations. Do not edit generated
|
|
|
167
167
|
|
|
168
168
|
## Visual regression tests (Playwright + Docker)
|
|
169
169
|
|
|
170
|
-
|
|
170
|
+
Pick the smallest run that answers your question:
|
|
171
|
+
|
|
172
|
+
| Question | Command | Typical time |
|
|
173
|
+
| --- | --- | --- |
|
|
174
|
+
| Did my change move any pixels? | `pnpm -C libs/ui test:visual:local` (no Docker) | seconds to a few minutes |
|
|
175
|
+
| Do the stories my change can affect still match the committed baselines? | `VISUAL_CHANGED_SINCE=origin/master pnpm -C libs/ui test:components` | seconds to minutes |
|
|
176
|
+
| Does everything match? | `pnpm -C libs/ui test:components` | about 15 minutes of screenshots plus about 10 of behavior specs on an Apple Silicon Mac |
|
|
177
|
+
| The change is intended and I need new baselines | let CI fail, then `pnpm -C libs/ui baselines:pull --pr <number>` | one CI run |
|
|
178
|
+
|
|
179
|
+
CI renders the committed Linux baselines on `linux/amd64` and is the authority for them.
|
|
180
|
+
|
|
181
|
+
To keep screenshots stable across machines, comparisons against the committed baselines run inside Docker.
|
|
171
182
|
|
|
172
183
|
1. Run Playwright tests in a consistent Linux environment (builds Storybook static output by default):
|
|
173
184
|
|
|
@@ -182,7 +193,7 @@ pnpm -C libs/ui test:components:update
|
|
|
182
193
|
```
|
|
183
194
|
|
|
184
195
|
Docker image is defined in `docker/development/playwright/Dockerfile`.
|
|
185
|
-
|
|
196
|
+
Comparisons against the committed baselines are Docker-only; running them directly on the host is blocked to keep snapshots reproducible. The local check below runs on the host with its own baselines.
|
|
186
197
|
Make sure Storybook is served at `TEST_BASE_URL` (default `http://127.0.0.1:6006` inside the container).
|
|
187
198
|
You can run `pnpm -C libs/ui storybook` on the host and set `TEST_BASE_URL=http://host.docker.internal:6006`,
|
|
188
199
|
or let Playwright start its own static server inside Docker from `storybook-static`.
|
|
@@ -195,34 +206,60 @@ Run the focused replay contracts with `pnpm -C libs/ui test:visual-assets` after
|
|
|
195
206
|
|
|
196
207
|
Optional environment overrides:
|
|
197
208
|
- `TEST_BASE_URL` (default: `http://127.0.0.1:6006` inside the container)
|
|
198
|
-
- `PLAYWRIGHT_STORYBOOK_REBUILD` (
|
|
209
|
+
- `PLAYWRIGHT_STORYBOOK_REBUILD` (unset: rebuilds `storybook-static` only when its inputs changed; `1`: always rebuild; `0`: never rebuild)
|
|
199
210
|
- `VISUAL_STORYBOOK_STATIC_DIR` (absolute path to another Storybook build, e.g. one built from `master`, to test against the committed baselines; skips the rebuild)
|
|
200
211
|
- `VISUAL_BRANDS` (default: `business,akros,n1`; focused development only)
|
|
201
212
|
- `TEST_STORIES` (comma-separated Storybook story ids to run, e.g. `atoms-button--states,molecules-productcard--layout-variants`)
|
|
202
213
|
- `PLAYWRIGHT_WORKERS` (override worker count for parallel runs)
|
|
203
214
|
- `VISUAL_ASSET_HAR_PATH` (absolute path to an alternative HAR; its directory and attachments mount read-only)
|
|
204
|
-
- `PLAYWRIGHT_DOCKER_IMAGE` (default: `new-engine-ui-playwright:<Playwright version>-<Dockerfile hash
|
|
215
|
+
- `PLAYWRIGHT_DOCKER_IMAGE` (default: `new-engine-ui-playwright:<Playwright version>-<Dockerfile hash>`, with an `-arm64` suffix on `linux/arm64`)
|
|
216
|
+
- `PLAYWRIGHT_DOCKER_PLATFORM` (`linux/amd64` or `linux/arm64`; default: host architecture, or `linux/amd64` for snapshot updates and release runs)
|
|
205
217
|
- `PLAYWRIGHT_DOCKER_SHM_SIZE` (default: `2g`, improves Playwright stability in Docker)
|
|
206
218
|
- `PLAYWRIGHT_DOCKER_IPC` (default: `host`, improves Playwright stability in Docker)
|
|
207
219
|
- `PLAYWRIGHT_DOCKER_SEQUENTIAL` (default: `0`, runs projects in parallel; set to `1` to run one project at a time and reduce memory spikes)
|
|
220
|
+
- `VISUAL_CHANGED_SINCE` (git ref, e.g. `origin/master`; screenshots only the stories affected since the merge-base, or a full run when everything could be affected)
|
|
221
|
+
- `VISUAL_CHANGED_FILES` (comma-separated repo-relative paths; used instead of git, and wins over `VISUAL_CHANGED_SINCE` when both are set)
|
|
222
|
+
- `VISUAL_CHANGED_FILES_FROM` (path to a file with one repo-relative path per line, or NUL-separated as `git diff -z` writes it so names with newlines survive; the same as `VISUAL_CHANGED_FILES` for long lists, and it wins over both other changed-mode variables)
|
|
223
|
+
- `VISUAL_CHANGED_DRY_RUN` (set to `1` with a changed-mode variable to print the selection as JSON; needs an existing Storybook build and never builds or starts Docker)
|
|
224
|
+
- `PLAYWRIGHT_SHARD` (`index/total`, e.g. `2/8`; runs one shard of a non-release run, and a shard with no matching tests passes; cannot be combined with `PLAYWRIGHT_RELEASE_SHARD` or `VISUAL_RELEASE_READINESS=1`)
|
|
225
|
+
- `VISUAL_CHANGED_BEHAVIOR` (set to `1` to also run the component behavior specs in a changed subset; by default only screenshot specs run)
|
|
226
|
+
|
|
227
|
+
Example: `VISUAL_CHANGED_SINCE=origin/master pnpm -C libs/ui test:components`
|
|
208
228
|
|
|
209
229
|
Extra arguments are passed to `playwright test`, e.g. `pnpm -C libs/ui test:components -- --project=n1-mobile-light`.
|
|
210
|
-
|
|
230
|
+
Comparison runs use the host architecture (native arm64 on Apple Silicon); snapshot updates and release runs always use `linux/amd64`, matching the committed baselines. `PLAYWRIGHT_DOCKER_PLATFORM` overrides both. A full run must cover every story in every visual project; component behavior specs (`test/*.spec.ts`) run once in the `desktop` and `mobile` projects.
|
|
211
231
|
|
|
212
|
-
###
|
|
232
|
+
### Known differences on `linux/arm64`
|
|
213
233
|
|
|
214
|
-
|
|
215
|
-
browser memory. Override it depending on your machine or CI runner size.
|
|
216
|
-
- The test suite enables `fullyParallel` in Playwright config, so tests can run
|
|
217
|
-
concurrently across files and workers — ensure tests are isolated and use
|
|
218
|
-
unique snapshot names (the visual tests already include `story.id` in the
|
|
219
|
-
screenshot filename, which is good).
|
|
234
|
+
Comparison runs on Apple Silicon use `linux/arm64`. One result differs there from `linux/amd64` in every run and is not a regression: screenshot `molecules-colorselect--keyboard-navigation` on `akros-mobile-light` and `n1-mobile-light`, where 17 pixels differ against an allowance of 16.
|
|
220
235
|
|
|
221
|
-
|
|
236
|
+
Behavior specs can be timing-sensitive on a fast machine. `date-picker.behavior.spec.ts` ("portals the popup, moves through the grid, and restores trigger focus", `desktop`) failed in a full run under load and passed 6 of 6 on its own.
|
|
222
237
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
238
|
+
A failing native run prints the commands that confirm failed screenshot stories and behavior specs on `linux/amd64`.
|
|
239
|
+
|
|
240
|
+
### Workers
|
|
241
|
+
|
|
242
|
+
The Docker runner uses 4 workers unless `PLAYWRIGHT_WORKERS` is set. On a 6-CPU Docker VM 4 workers already use every core: 6 workers finished a 372-test sample in 153 seconds against 158. Raise the number only when the VM has more CPUs. The local check without Docker picks its own count from the host's cores.
|
|
243
|
+
|
|
244
|
+
### Local visual check without Docker
|
|
245
|
+
|
|
246
|
+
`pnpm -C libs/ui test:visual:local` answers one question: did your working tree change any pixels compared with the commit you branched from?
|
|
247
|
+
|
|
248
|
+
- It runs on your machine and needs no Docker.
|
|
249
|
+
- It renders the base commit (`--base`, default `origin/master`, compared at `git merge-base HEAD <ref>`) and compares your changes against it.
|
|
250
|
+
- The first run per base commit builds that commit in a temporary worktree (about 2 minutes) and needs 3 GiB free in the temporary directory.
|
|
251
|
+
- Base screenshots are captured with the test harness of the branch you run from. They are cached per machine, per base commit and per harness: the build is shared, the baselines are not. The harness is `libs/ui/test/visual.spec.ts`, `libs/ui/test/visual-*.mjs` (not `*.test.mjs`), `libs/ui/playwright.config.mts` and `libs/ui/test/fixtures/visual-assets`. When any of them changes, the baselines are re-captured automatically on the next run.
|
|
252
|
+
- Cache layout: `<root>/builds/<base>/storybook-static` and `<root>/<platform>-<arch>-pw<version>-h<harness>/<base>/snapshots`. The `<root>` is `VISUAL_LOCAL_CACHE` when set, otherwise `~/Library/Caches/techsio-ui-visual` on macOS and `~/.cache/techsio-ui-visual` elsewhere. Caches from the older single-key layout are ignored and can be deleted.
|
|
253
|
+
- Each cache level keeps the 5 most recently used base commits. `VISUAL_LOCAL_CACHE_KEEP=<n>` changes that number. Directories used by the current run and directories locked by a live run are never removed.
|
|
254
|
+
- Runs for the same base commit wait for each other, so a commit is never built or captured twice at once. A failed or killed capture leaves no baselines behind.
|
|
255
|
+
- Nothing is written to the committed Linux baselines. CI stays the authority for those.
|
|
256
|
+
- Flags: `--base <ref>`, `--all` (every visual story), `--stories <id,id>` (skips change detection), `--workers <n>`, `--rebuild-base` (rebuilds the base build and clears the baselines for the current harness), `--dry-run` (prints the plan as JSON and builds nothing).
|
|
257
|
+
- Install the browsers once: `pnpm -C libs/ui exec playwright install chromium webkit`. If a run reports missing browsers, it says so in the summary.
|
|
258
|
+
- The HTML report goes to `libs/ui/.visual-local/report`. Open it with `pnpm -C libs/ui exec playwright show-report .visual-local/report`.
|
|
259
|
+
|
|
260
|
+
### Baselines from CI
|
|
261
|
+
|
|
262
|
+
When a PR's screenshot check fails because the visual change is intended, run `pnpm -C libs/ui baselines:pull --pr <number>` to copy the screenshots that CI rendered into the committed Linux baselines. Use a run id or `--branch <name>` instead of `--pr` to pick another run, and `--out <dir>` or `--dry-run` to write elsewhere or only list the files. Review the images and `git status`, then commit.
|
|
226
263
|
|
|
227
264
|
### Release coverage versus focused development
|
|
228
265
|
|
package/dist/atoms/button.js
CHANGED
|
@@ -22,6 +22,10 @@ const buttonVariants = tv({
|
|
|
22
22
|
"motion-safe:not-disabled:not-data-disabled:not-data-loading:active:scale-97"
|
|
23
23
|
]
|
|
24
24
|
},
|
|
25
|
+
density: {
|
|
26
|
+
default: "",
|
|
27
|
+
compact: ""
|
|
28
|
+
},
|
|
25
29
|
variant: {
|
|
26
30
|
primary: "",
|
|
27
31
|
secondary: "",
|
|
@@ -40,9 +44,9 @@ const buttonVariants = tv({
|
|
|
40
44
|
true: "uppercase"
|
|
41
45
|
},
|
|
42
46
|
size: {
|
|
43
|
-
sm: "
|
|
44
|
-
md: "
|
|
45
|
-
lg: "
|
|
47
|
+
sm: "min-w-0 gap-button-sm rounded-button-sm text-button-sm",
|
|
48
|
+
md: "min-w-0 gap-button-md rounded-button-md text-button-md",
|
|
49
|
+
lg: "min-w-0 gap-button-lg rounded-button-lg text-button-lg",
|
|
46
50
|
current: "button-current-size gap-button-md"
|
|
47
51
|
},
|
|
48
52
|
block: {
|
|
@@ -50,6 +54,36 @@ const buttonVariants = tv({
|
|
|
50
54
|
}
|
|
51
55
|
},
|
|
52
56
|
compoundVariants: [
|
|
57
|
+
{
|
|
58
|
+
density: "default",
|
|
59
|
+
size: "sm",
|
|
60
|
+
className: "button-size-sm p-button-sm"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
density: "default",
|
|
64
|
+
size: "md",
|
|
65
|
+
className: "button-size-md p-button-md"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
density: "default",
|
|
69
|
+
size: "lg",
|
|
70
|
+
className: "button-size-lg p-button-lg"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
density: "compact",
|
|
74
|
+
size: "sm",
|
|
75
|
+
className: "h-button-compact-sm p-button-compact-sm"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
density: "compact",
|
|
79
|
+
size: "md",
|
|
80
|
+
className: "h-button-compact-md p-button-compact-md"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
density: "compact",
|
|
84
|
+
size: "lg",
|
|
85
|
+
className: "h-button-compact-lg p-button-compact-lg"
|
|
86
|
+
},
|
|
53
87
|
{
|
|
54
88
|
variant: "primary",
|
|
55
89
|
theme: "solid",
|
|
@@ -253,6 +287,7 @@ const buttonVariants = tv({
|
|
|
253
287
|
],
|
|
254
288
|
defaultVariants: {
|
|
255
289
|
composition: false,
|
|
290
|
+
density: "default",
|
|
256
291
|
variant: "primary",
|
|
257
292
|
theme: "solid",
|
|
258
293
|
size: "md",
|
|
@@ -272,7 +307,7 @@ const buttonIconVariants = tv({
|
|
|
272
307
|
size: "md"
|
|
273
308
|
}
|
|
274
309
|
});
|
|
275
|
-
function Button({ variant, theme, size, block, isLoading, loadingText, icon, iconPosition = "left", iconSize, uppercase = false, children, className, disabled, composition, ref, onClick, type = "button", ...props }) {
|
|
310
|
+
function Button({ density, variant, theme, size, block, isLoading, loadingText, icon, iconPosition = "left", iconSize, uppercase = false, children, className, disabled, composition, ref, onClick, type = "button", ...props }) {
|
|
276
311
|
const buttonRef = useRef(null);
|
|
277
312
|
useImperativeHandle(ref, ()=>buttonRef.current, []);
|
|
278
313
|
useEffect(()=>{
|
|
@@ -300,6 +335,7 @@ function Button({ variant, theme, size, block, isLoading, loadingText, icon, ico
|
|
|
300
335
|
"aria-busy": isLoading || void 0,
|
|
301
336
|
"aria-disabled": disabled || isLoading || props["aria-disabled"] || void 0,
|
|
302
337
|
className: buttonVariants({
|
|
338
|
+
density,
|
|
303
339
|
variant,
|
|
304
340
|
theme,
|
|
305
341
|
size,
|
package/dist/atoms/image.js
CHANGED
|
@@ -6,6 +6,13 @@ import { Icon } from "./icon.js";
|
|
|
6
6
|
const imageVariants = tv({
|
|
7
7
|
base: "block max-w-full object-cover",
|
|
8
8
|
variants: {
|
|
9
|
+
objectFit: {
|
|
10
|
+
contain: "object-contain",
|
|
11
|
+
cover: "object-cover",
|
|
12
|
+
fill: "object-fill",
|
|
13
|
+
none: "object-none",
|
|
14
|
+
scaleDown: "object-scale-down"
|
|
15
|
+
},
|
|
9
16
|
size: {
|
|
10
17
|
sm: "size-image-sm",
|
|
11
18
|
md: "size-image-md",
|
|
@@ -18,12 +25,13 @@ const imageVariants = tv({
|
|
|
18
25
|
size: "full"
|
|
19
26
|
}
|
|
20
27
|
});
|
|
21
|
-
function Image({ as, src, alt, size, className, ...props }) {
|
|
28
|
+
function Image({ as, src, alt, size, objectFit, className, ...props }) {
|
|
22
29
|
const Component = as || "img";
|
|
23
30
|
return /*#__PURE__*/ jsx(Component, {
|
|
24
31
|
alt: alt,
|
|
25
32
|
className: imageVariants({
|
|
26
33
|
size,
|
|
34
|
+
objectFit,
|
|
27
35
|
className
|
|
28
36
|
}),
|
|
29
37
|
src: src,
|
|
@@ -57,7 +65,7 @@ function ImageWithFallback(props) {
|
|
|
57
65
|
...props
|
|
58
66
|
}, sourceKey);
|
|
59
67
|
}
|
|
60
|
-
function ImageFallbackContent({ as, src, alt, size, className, fallbackLabel, ...props }) {
|
|
68
|
+
function ImageFallbackContent({ as, src, alt, size, objectFit, className, fallbackLabel, ...props }) {
|
|
61
69
|
const [failed, setFailed] = useState(!src);
|
|
62
70
|
const [loaded, setLoaded] = useState(false);
|
|
63
71
|
const pending = !(failed || loaded);
|
|
@@ -81,6 +89,7 @@ function ImageFallbackContent({ as, src, alt, size, className, fallbackLabel, ..
|
|
|
81
89
|
className: styles.root({
|
|
82
90
|
className: imageVariants({
|
|
83
91
|
size,
|
|
92
|
+
objectFit,
|
|
84
93
|
className
|
|
85
94
|
})
|
|
86
95
|
}),
|
|
@@ -102,6 +111,7 @@ function ImageFallbackContent({ as, src, alt, size, className, fallbackLabel, ..
|
|
|
102
111
|
className: styles.image({
|
|
103
112
|
className: imageVariants({
|
|
104
113
|
size,
|
|
114
|
+
objectFit,
|
|
105
115
|
className
|
|
106
116
|
})
|
|
107
117
|
}),
|
|
@@ -10,13 +10,14 @@ const linkButton = tv({
|
|
|
10
10
|
size: "md"
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
|
-
function LinkButton({ href, icon, as, iconPosition = "left", iconSize, children, variant, theme, size, block, uppercase, className, disabled, composition, ref, onClick, tabIndex, ...props }) {
|
|
13
|
+
function LinkButton({ density, href, icon, as, iconPosition = "left", iconSize, children, variant, theme, size, block, uppercase, className, disabled, composition, ref, onClick, tabIndex, ...props }) {
|
|
14
14
|
const handleClick = onClick;
|
|
15
15
|
const Component = disabled ? "span" : as || "a";
|
|
16
16
|
return /*#__PURE__*/ jsxs(Component, {
|
|
17
17
|
...props,
|
|
18
18
|
"aria-disabled": true === disabled ? true : props["aria-disabled"],
|
|
19
19
|
className: linkButton({
|
|
20
|
+
density,
|
|
20
21
|
variant,
|
|
21
22
|
theme,
|
|
22
23
|
size,
|
|
@@ -65,7 +65,6 @@ const numericInputVariants = tv({
|
|
|
65
65
|
],
|
|
66
66
|
container: [
|
|
67
67
|
"group numeric-input-focus-owner form-control-base numeric-input-validation numeric-input-readonly relative flex",
|
|
68
|
-
"border-numeric-input-border",
|
|
69
68
|
"min-w-0 items-center overflow-clip",
|
|
70
69
|
"hover:border-numeric-input-border-hover",
|
|
71
70
|
"focus-within:border-numeric-input-border-focus",
|
|
@@ -97,7 +96,7 @@ const numericInputVariants = tv({
|
|
|
97
96
|
trigger: [
|
|
98
97
|
"flex min-h-numeric-input-trigger-min min-w-numeric-input-trigger-min flex-1 place-items-center",
|
|
99
98
|
"pointer-coarse:min-w-numeric-input-trigger-touch-min",
|
|
100
|
-
"
|
|
99
|
+
"py-numeric-input-trigger-y",
|
|
101
100
|
"bg-transparent hover:bg-numeric-input-trigger-bg-hover active:bg-numeric-input-trigger-bg-active",
|
|
102
101
|
"text-numeric-input-trigger-fg",
|
|
103
102
|
"cursor-pointer",
|
|
@@ -108,31 +107,92 @@ const numericInputVariants = tv({
|
|
|
108
107
|
scrubber: "absolute inset-0 cursor-ew-resize"
|
|
109
108
|
},
|
|
110
109
|
variants: {
|
|
110
|
+
density: {
|
|
111
|
+
default: {
|
|
112
|
+
container: "border-numeric-input-border",
|
|
113
|
+
trigger: "px-numeric-input-trigger-x"
|
|
114
|
+
},
|
|
115
|
+
compact: {
|
|
116
|
+
container: "border-numeric-input-compact-border",
|
|
117
|
+
trigger: "px-numeric-input-compact-trigger"
|
|
118
|
+
}
|
|
119
|
+
},
|
|
111
120
|
size: {
|
|
112
121
|
sm: {
|
|
113
122
|
root: "gap-numeric-input-sm text-numeric-input-sm",
|
|
114
|
-
container: "
|
|
123
|
+
container: "rounded-numeric-input-sm",
|
|
115
124
|
trigger: "text-numeric-input-sm",
|
|
116
125
|
triggerIcon: "numeric-input-trigger-icon-sm",
|
|
117
|
-
input: "
|
|
126
|
+
input: "text-numeric-input-sm"
|
|
118
127
|
},
|
|
119
128
|
md: {
|
|
120
129
|
root: "gap-numeric-input-md text-numeric-input-md",
|
|
121
|
-
container: "
|
|
130
|
+
container: "rounded-numeric-input-md",
|
|
122
131
|
trigger: "text-numeric-input-md",
|
|
123
132
|
triggerIcon: "numeric-input-trigger-icon-md",
|
|
124
|
-
input: "
|
|
133
|
+
input: "text-numeric-input-md"
|
|
125
134
|
},
|
|
126
135
|
lg: {
|
|
127
136
|
root: "gap-numeric-input-lg text-numeric-input-lg",
|
|
128
|
-
container: "
|
|
137
|
+
container: "rounded-numeric-input-lg",
|
|
129
138
|
trigger: "text-numeric-input-lg",
|
|
130
139
|
triggerIcon: "numeric-input-trigger-icon-lg",
|
|
131
|
-
input: "
|
|
140
|
+
input: "text-numeric-input-lg"
|
|
132
141
|
}
|
|
133
142
|
}
|
|
134
143
|
},
|
|
144
|
+
compoundVariants: [
|
|
145
|
+
{
|
|
146
|
+
density: "default",
|
|
147
|
+
size: "sm",
|
|
148
|
+
className: {
|
|
149
|
+
container: "h-form-control-sm",
|
|
150
|
+
input: "ps-numeric-input-input-sm"
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
density: "default",
|
|
155
|
+
size: "md",
|
|
156
|
+
className: {
|
|
157
|
+
container: "h-form-control-md",
|
|
158
|
+
input: "ps-numeric-input-input-md"
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
density: "default",
|
|
163
|
+
size: "lg",
|
|
164
|
+
className: {
|
|
165
|
+
container: "h-form-control-lg",
|
|
166
|
+
input: "ps-numeric-input-input-lg"
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
density: "compact",
|
|
171
|
+
size: "sm",
|
|
172
|
+
className: {
|
|
173
|
+
container: "h-numeric-input-compact-sm",
|
|
174
|
+
input: "ps-numeric-input-compact-sm"
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
density: "compact",
|
|
179
|
+
size: "md",
|
|
180
|
+
className: {
|
|
181
|
+
container: "h-numeric-input-compact-md",
|
|
182
|
+
input: "ps-numeric-input-compact-md"
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
density: "compact",
|
|
187
|
+
size: "lg",
|
|
188
|
+
className: {
|
|
189
|
+
container: "h-numeric-input-compact-lg",
|
|
190
|
+
input: "ps-numeric-input-compact-lg"
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
],
|
|
135
194
|
defaultVariants: {
|
|
195
|
+
density: "default",
|
|
136
196
|
size: "md"
|
|
137
197
|
}
|
|
138
198
|
});
|
|
@@ -143,7 +203,7 @@ function useNumericInputContext() {
|
|
|
143
203
|
if (!context) throw new Error("NumericInput components must be used within NumericInput.Root");
|
|
144
204
|
return context;
|
|
145
205
|
}
|
|
146
|
-
function NumericInput({ id, size, value, defaultValue, onChange, validateStatus = "default", dir = "ltr", describedBy, "aria-describedby": ariaDescribedBy, "aria-errormessage": ariaErrorMessage, "aria-invalid": ariaInvalid, precision, children, ref, className, locale = "cs-CZ", ...props }) {
|
|
206
|
+
function NumericInput({ density, id, size, value, defaultValue, onChange, validateStatus = "default", dir = "ltr", describedBy, "aria-describedby": ariaDescribedBy, "aria-errormessage": ariaErrorMessage, "aria-invalid": ariaInvalid, precision, children, ref, className, locale = "cs-CZ", ...props }) {
|
|
147
207
|
const generatedId = useId();
|
|
148
208
|
const [inputId, setInputId] = useState();
|
|
149
209
|
const description = useDescribedBy();
|
|
@@ -297,6 +357,7 @@ function NumericInput({ id, size, value, defaultValue, onChange, validateStatus
|
|
|
297
357
|
service
|
|
298
358
|
]);
|
|
299
359
|
const styles = numericInputVariants({
|
|
360
|
+
density,
|
|
300
361
|
size
|
|
301
362
|
});
|
|
302
363
|
const inputDisabled = api.getInputProps().disabled;
|
package/dist/molecules/chart.js
CHANGED
|
@@ -19,10 +19,10 @@ const chartVariants = tv({
|
|
|
19
19
|
tooltip: "chart-tooltip popup-layer!",
|
|
20
20
|
alternative: "overflow-auto text-chart-data text-chart-fg",
|
|
21
21
|
summary: "cursor-pointer rounded-chart-tooltip focus-visible:outline-chart-fg",
|
|
22
|
-
cell: "border-chart-tooltip-border border-b p-chart-
|
|
22
|
+
cell: "border-chart-tooltip-border border-b p-chart-cell text-start",
|
|
23
23
|
legend: "flex flex-wrap gap-chart-legend text-chart-data text-chart-fg",
|
|
24
24
|
legendItem: "inline-flex items-center gap-chart-item",
|
|
25
|
-
fallback: "p-chart-
|
|
25
|
+
fallback: "p-chart-fallback text-chart-data text-chart-fg"
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
28
|
const SERIES_1_PAINT = "var(--color-chart-series-1)";
|
|
@@ -46,6 +46,78 @@ const LINE_DASHES = [
|
|
|
46
46
|
"12 4",
|
|
47
47
|
"4 4"
|
|
48
48
|
];
|
|
49
|
+
const TOOLTIP_GAP = 12;
|
|
50
|
+
const TOOLTIP_EDGE = 8;
|
|
51
|
+
let tooltipMeasureContext;
|
|
52
|
+
function validLocale(locale) {
|
|
53
|
+
if (null == locale) return;
|
|
54
|
+
try {
|
|
55
|
+
Intl.getCanonicalLocales(locale);
|
|
56
|
+
return locale;
|
|
57
|
+
} catch {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function tooltipTextWidth(text, weight) {
|
|
62
|
+
if (null == tooltipMeasureContext && "u" > typeof document) tooltipMeasureContext = document.createElement("canvas").getContext?.("2d") ?? false;
|
|
63
|
+
if (!tooltipMeasureContext) return 8.5 * text.length;
|
|
64
|
+
tooltipMeasureContext.font = `${weight} 15px system-ui, sans-serif`;
|
|
65
|
+
return 1.08 * tooltipMeasureContext.measureText(text).width;
|
|
66
|
+
}
|
|
67
|
+
function estimateTooltipSize(content) {
|
|
68
|
+
const titleWidth = content.title ? tooltipTextWidth(content.title, 650) : 0;
|
|
69
|
+
const rowWidth = Math.max(0, ...content.rows.map((row)=>40 + tooltipTextWidth(row.label, 500) + tooltipTextWidth(row.value, 600)));
|
|
70
|
+
return {
|
|
71
|
+
width: Math.ceil(Math.max(titleWidth, rowWidth) + 34),
|
|
72
|
+
height: Math.ceil(30 + (content.title ? 26 : 0) + 24 * content.rows.length)
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function chartTooltipCorner(content, points, context, horizontal) {
|
|
76
|
+
const first = points[0];
|
|
77
|
+
if (!first) return null;
|
|
78
|
+
const { width, height } = estimateTooltipSize(content);
|
|
79
|
+
const { surface } = context;
|
|
80
|
+
const xs = points.map((point)=>point.x);
|
|
81
|
+
const ys = points.map((point)=>point.y);
|
|
82
|
+
const categoryScale = context.scales[horizontal ? "y" : "x"];
|
|
83
|
+
const band = categoryScale?.bandwidth ?? 0;
|
|
84
|
+
const bandStart = categoryScale && band > 0 ? categoryScale.map(horizontal ? first.yValue : first.xValue) : 0 / 0;
|
|
85
|
+
const hasBand = Number.isFinite(bandStart);
|
|
86
|
+
if (horizontal) {
|
|
87
|
+
const top = hasBand ? bandStart : Math.min(...ys);
|
|
88
|
+
const bottom = hasBand ? bandStart + band : Math.max(...ys);
|
|
89
|
+
const end = Math.max(...xs);
|
|
90
|
+
if (end + TOOLTIP_GAP + width + TOOLTIP_EDGE <= surface.width) return {
|
|
91
|
+
x: end + TOOLTIP_GAP,
|
|
92
|
+
y: (top + bottom - height) / 2
|
|
93
|
+
};
|
|
94
|
+
if (top - TOOLTIP_GAP - height >= TOOLTIP_EDGE) return {
|
|
95
|
+
x: end - width,
|
|
96
|
+
y: top - TOOLTIP_GAP - height
|
|
97
|
+
};
|
|
98
|
+
return {
|
|
99
|
+
x: end - width,
|
|
100
|
+
y: bottom + TOOLTIP_GAP
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const left = hasBand ? bandStart : Math.min(...xs);
|
|
104
|
+
const right = hasBand ? bandStart + band : Math.max(...xs);
|
|
105
|
+
const top = Math.min(...ys);
|
|
106
|
+
const center = (left + right) / 2;
|
|
107
|
+
if (top - TOOLTIP_GAP - height >= TOOLTIP_EDGE) return {
|
|
108
|
+
x: center - width / 2,
|
|
109
|
+
y: top - TOOLTIP_GAP - height
|
|
110
|
+
};
|
|
111
|
+
const y = Math.max(TOOLTIP_EDGE, top);
|
|
112
|
+
if (right + TOOLTIP_GAP + width + TOOLTIP_EDGE <= surface.width) return {
|
|
113
|
+
x: right + TOOLTIP_GAP,
|
|
114
|
+
y
|
|
115
|
+
};
|
|
116
|
+
return {
|
|
117
|
+
x: left - TOOLTIP_GAP - width,
|
|
118
|
+
y
|
|
119
|
+
};
|
|
120
|
+
}
|
|
49
121
|
function resolveXAxis(data, getX, xLabel) {
|
|
50
122
|
const values = data.map(getX);
|
|
51
123
|
if (values.length > 0 && values.every((value)=>value instanceof Date)) return {
|
|
@@ -87,57 +159,85 @@ function resolveBuild(config) {
|
|
|
87
159
|
use: tooltip_tooltip,
|
|
88
160
|
className: config.tooltipClassName
|
|
89
161
|
};
|
|
90
|
-
const
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
162
|
+
const locale = validLocale(config.locale);
|
|
163
|
+
const numberFormat = locale ? new Intl.NumberFormat(locale) : void 0;
|
|
164
|
+
const dateFormat = new Intl.DateTimeFormat(locale ?? "en-US", {
|
|
165
|
+
dateStyle: "medium",
|
|
166
|
+
timeZone: "UTC"
|
|
167
|
+
});
|
|
168
|
+
const formatCategory = (value)=>{
|
|
169
|
+
if (config.formatCategory) return config.formatCategory(value);
|
|
170
|
+
if (value instanceof Date) return dateFormat.format(value);
|
|
171
|
+
if ("number" == typeof value) return numberFormat ? numberFormat.format(value) : String(value);
|
|
172
|
+
return String(value);
|
|
97
173
|
};
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
label: valueName,
|
|
106
|
-
|
|
174
|
+
const formatTooltipValue = (value)=>{
|
|
175
|
+
const format = config.formatTooltipValue ?? formatValue;
|
|
176
|
+
if (format) return format(value);
|
|
177
|
+
return numberFormat ? numberFormat.format(value) : String(value);
|
|
178
|
+
};
|
|
179
|
+
const valueName = config.valueLabel ?? config.yLabel ?? "";
|
|
180
|
+
const rowFor = (row, point, active)=>({
|
|
181
|
+
label: getSeries ? String(getSeries(row)) : valueName,
|
|
182
|
+
value: formatTooltipValue(getY(row)),
|
|
183
|
+
color: point.color || SERIES_1_PAINT,
|
|
184
|
+
active
|
|
185
|
+
});
|
|
186
|
+
const cartesianContent = (points, primaryPoint)=>{
|
|
187
|
+
const first = points[0];
|
|
188
|
+
if (!first) return {
|
|
189
|
+
rows: []
|
|
107
190
|
};
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
label: categoryName
|
|
191
|
+
return {
|
|
192
|
+
title: formatCategory(getX(first.datum)),
|
|
193
|
+
rows: points.map((point)=>rowFor(point.datum, point, points.length > 1 && point === primaryPoint))
|
|
112
194
|
};
|
|
195
|
+
};
|
|
196
|
+
const polarContent = (points)=>{
|
|
197
|
+
const first = points[0];
|
|
198
|
+
if (!first) return {
|
|
199
|
+
rows: []
|
|
200
|
+
};
|
|
201
|
+
const row = first.datum.data;
|
|
113
202
|
return {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
203
|
+
title: formatCategory(getX(row)),
|
|
204
|
+
rows: [
|
|
205
|
+
{
|
|
206
|
+
label: valueName,
|
|
207
|
+
value: formatTooltipValue(getY(row)),
|
|
208
|
+
color: first.color || SERIES_1_PAINT
|
|
209
|
+
}
|
|
121
210
|
]
|
|
122
211
|
};
|
|
123
212
|
};
|
|
213
|
+
const tooltipFor = (valueChannel)=>{
|
|
214
|
+
if (!config.showTooltip) return false;
|
|
215
|
+
const horizontal = "x" === valueChannel;
|
|
216
|
+
return {
|
|
217
|
+
...tooltipBase,
|
|
218
|
+
content: (points, context)=>cartesianContent(points, context.primaryPoint),
|
|
219
|
+
anchor: (points, context)=>chartTooltipCorner(cartesianContent(points, context.focus.primary), points, context, horizontal),
|
|
220
|
+
placement: "bottom-right",
|
|
221
|
+
offset: 0
|
|
222
|
+
};
|
|
223
|
+
};
|
|
124
224
|
const polarTooltip = ()=>{
|
|
125
225
|
if (!config.showTooltip) return false;
|
|
126
226
|
return {
|
|
127
227
|
...tooltipBase,
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
]
|
|
228
|
+
content: polarContent,
|
|
229
|
+
anchor: "pointer",
|
|
230
|
+
placement: [
|
|
231
|
+
"right",
|
|
232
|
+
"left",
|
|
233
|
+
"bottom",
|
|
234
|
+
"top"
|
|
235
|
+
],
|
|
236
|
+
offset: 16
|
|
139
237
|
};
|
|
140
238
|
};
|
|
239
|
+
let focus;
|
|
240
|
+
if (null != getSeries && !isPolar) focus = "bar-horizontal" === config.type ? "group-y" : "group-x";
|
|
141
241
|
const valueAxis = {
|
|
142
242
|
scale: scaleLinear,
|
|
143
243
|
nice: true,
|
|
@@ -186,7 +286,10 @@ function resolveBuild(config) {
|
|
|
186
286
|
})
|
|
187
287
|
}) : void 0
|
|
188
288
|
},
|
|
189
|
-
svgAnimation: config.animate
|
|
289
|
+
svgAnimation: config.animate,
|
|
290
|
+
...focus ? {
|
|
291
|
+
focus
|
|
292
|
+
} : {}
|
|
190
293
|
}
|
|
191
294
|
};
|
|
192
295
|
}
|
|
@@ -294,7 +397,7 @@ function buildBars(build, horizontal) {
|
|
|
294
397
|
y: build.bandAxis
|
|
295
398
|
},
|
|
296
399
|
...build.shared,
|
|
297
|
-
tooltip: build.tooltipFor("x"
|
|
400
|
+
tooltip: build.tooltipFor("x")
|
|
298
401
|
};
|
|
299
402
|
return {
|
|
300
403
|
marks: [
|
|
@@ -571,7 +674,7 @@ function ChartLineLegend({ identities, domain, label }) {
|
|
|
571
674
|
})
|
|
572
675
|
});
|
|
573
676
|
}
|
|
574
|
-
function chart_Chart({ type = "line", data, x, y, series, seriesDomain, stacked, points = false, smooth = false, grid = true, legend, legendLabel, xLabel, yLabel, formatValue, height, aspectRatio, initialWidth = 640, animate, tooltip = true, ariaLabel, ariaDescription, className, dataTableLabel = "View chart data", emptyLabel = "No data to display.", invalidLabel = "Pie and donut values must be finite, non-negative numbers with a positive total.", onSelect }) {
|
|
677
|
+
function chart_Chart({ type = "line", data, x, y, series, seriesDomain, stacked, points = false, smooth = false, grid = true, legend, legendLabel, xLabel, yLabel, formatValue, valueLabel, formatCategory, formatTooltipValue, locale, height, aspectRatio, initialWidth = 640, animate, tooltip = true, ariaLabel, ariaDescription, className, dataTableLabel = "View chart data", emptyLabel = "No data to display.", invalidLabel = "Pie and donut values must be finite, non-negative numbers with a positive total.", onSelect }) {
|
|
575
678
|
const { root, tooltip: tooltipSlot, fallback } = chartVariants();
|
|
576
679
|
const tooltipClassName = tooltipSlot();
|
|
577
680
|
const prefersReducedMotion = usePrefersReducedMotion();
|
|
@@ -605,6 +708,10 @@ function chart_Chart({ type = "line", data, x, y, series, seriesDomain, stacked,
|
|
|
605
708
|
xLabel,
|
|
606
709
|
yLabel,
|
|
607
710
|
formatValue,
|
|
711
|
+
valueLabel,
|
|
712
|
+
formatCategory,
|
|
713
|
+
formatTooltipValue,
|
|
714
|
+
locale,
|
|
608
715
|
animate: shouldAnimate,
|
|
609
716
|
showTooltip: tooltip && !dismissed,
|
|
610
717
|
tooltipClassName
|
|
@@ -626,6 +733,10 @@ function chart_Chart({ type = "line", data, x, y, series, seriesDomain, stacked,
|
|
|
626
733
|
xLabel,
|
|
627
734
|
yLabel,
|
|
628
735
|
formatValue,
|
|
736
|
+
valueLabel,
|
|
737
|
+
formatCategory,
|
|
738
|
+
formatTooltipValue,
|
|
739
|
+
locale,
|
|
629
740
|
shouldAnimate,
|
|
630
741
|
tooltip,
|
|
631
742
|
tooltipClassName
|