@nswds/ui 8.4.0 → 8.5.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.
@@ -1,6 +1,7 @@
1
1
  "use client"
2
2
  import { jsx } from 'react/jsx-runtime';
3
3
  import { Switch as Switch$1 } from '@base-ui/react/switch';
4
+ import { IconCheck } from '../icons/check.js';
4
5
  import { cn } from '../lib/utils.js';
5
6
 
6
7
  function Switch({
@@ -14,7 +15,25 @@ function Switch({
14
15
  "data-slot": "switch",
15
16
  "data-size": size,
16
17
  className: cn(
17
- "peer group/switch relative inline-flex shrink-0 items-center rounded-full border border-transparent transition-all outline-none group-has-[:focus-visible]/field-label:border-transparent group-has-[:focus-visible]/field-label:ring-0 after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 aria-invalid:border-destructive aria-invalid:ring-2 aria-invalid:ring-destructive/20 data-[size=default]:h-[16.6px] data-[size=default]:w-[28px] data-[size=sm]:h-[14px] data-[size=sm]:w-[24px] dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:bg-primary data-unchecked:bg-input dark:data-unchecked:bg-input/80 data-disabled:cursor-not-allowed data-disabled:opacity-50",
18
+ "peer group/switch relative inline-flex shrink-0 items-center rounded-full border border-(--text-default) bg-(--input-surface) motion-safe:transition-colors",
19
+ // Checkbox's theme bridge, so brand overrides reach both modes. The
20
+ // thumb reads these too: ink for the fill and tick, mark for the thumb
21
+ // on a selected track, off for the ring on an unselected one.
22
+ "[--switch-ink:var(--color-primary-800)] [--switch-mark:var(--surface-default)] [--switch-off:var(--text-default)] dark:not-data-disabled:not-aria-invalid:[--switch-ink:var(--color-primary-200)]",
23
+ // The padding puts the thumb 5px (sm: 4px) inside the outer edge,
24
+ // Checkbox's inset, and fixes its travel at the track minus both insets.
25
+ "data-[size=default]:h-8 data-[size=default]:w-14 data-[size=default]:px-1 data-[size=sm]:h-6 data-[size=sm]:w-10 data-[size=sm]:px-0.75",
26
+ // A 44px hit area without making the visible control larger. The
27
+ // pseudo-element sizes from the padding box, so add the border back.
28
+ "after:absolute after:top-1/2 after:left-1/2 after:h-11 after:w-[calc(100%+2px)] after:min-w-11 after:-translate-1/2",
29
+ "data-checked:border-(--switch-ink) data-checked:bg-(--switch-ink)",
30
+ "not-data-disabled:data-checked:hover:bg-[color-mix(in_srgb,var(--switch-ink)_88%,var(--input-surface))] not-data-disabled:data-unchecked:hover:bg-[color-mix(in_srgb,var(--switch-ink)_10%,var(--input-surface))]",
31
+ "focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-3 focus-visible:outline-(--switch-ink)",
32
+ // Input's invalid roles. The second pixel of the off border is an inset
33
+ // ring rather than border-2, so the thumb does not shift by a pixel.
34
+ "aria-invalid:not-data-disabled:[--switch-ink:var(--danger-solid)] aria-invalid:not-data-disabled:[--switch-mark:var(--white)] aria-invalid:focus-visible:outline-offset-2 aria-invalid:focus-visible:outline-(--input-invalid-ring) aria-invalid:not-data-disabled:data-unchecked:border-(--input-invalid-border) aria-invalid:not-data-disabled:data-unchecked:inset-ring aria-invalid:not-data-disabled:data-unchecked:inset-ring-(--input-invalid-border) aria-invalid:not-data-disabled:data-unchecked:hover:bg-(--input-invalid-surface-hover)",
35
+ // Base UI renders a span: data-disabled covers both the prop and Field.
36
+ "data-disabled:cursor-not-allowed data-disabled:border-(--text-subtle) data-disabled:[--switch-ink:var(--text-subtle)] data-disabled:[--switch-off:var(--text-subtle)]",
18
37
  className
19
38
  ),
20
39
  ...props,
@@ -22,7 +41,14 @@ function Switch({
22
41
  Switch$1.Thumb,
23
42
  {
24
43
  "data-slot": "switch-thumb",
25
- className: "pointer-events-none block rounded-full bg-background ring-0 transition-transform group-data-[size=default]/switch:size-3.5 group-data-[size=sm]/switch:size-3 group-data-[size=default]/switch:data-checked:translate-x-[calc(100%-2px)] group-data-[size=sm]/switch:data-checked:translate-x-[calc(100%-2px)] rtl:group-data-[size=default]/switch:data-checked:-translate-x-[calc(100%-2px)] rtl:group-data-[size=sm]/switch:data-checked:-translate-x-[calc(100%-2px)] dark:data-checked:bg-primary-foreground group-data-[size=default]/switch:data-unchecked:translate-x-0 group-data-[size=sm]/switch:data-unchecked:translate-x-0 rtl:group-data-[size=default]/switch:data-unchecked:-translate-x-0 rtl:group-data-[size=sm]/switch:data-unchecked:-translate-x-0 dark:data-unchecked:bg-foreground"
44
+ className: cn(
45
+ "pointer-events-none grid shrink-0 place-items-center rounded-full bg-(--input-surface) text-(--switch-ink) inset-ring-2 inset-ring-(--switch-off) motion-safe:transition-[translate,background-color,box-shadow]",
46
+ "group-data-[size=default]/switch:size-5.5 group-data-[size=sm]/switch:size-4 group-data-[size=default]/switch:[&>svg]:size-4.5 group-data-[size=sm]/switch:[&>svg]:size-3",
47
+ "not-data-disabled:data-unchecked:group-hover/switch:bg-[color-mix(in_srgb,var(--switch-ink)_10%,var(--input-surface))] group-aria-invalid/switch:not-data-disabled:data-unchecked:group-hover/switch:bg-(--input-invalid-surface-hover)",
48
+ "data-checked:bg-(--switch-mark) data-checked:inset-ring-0",
49
+ "group-data-[size=default]/switch:data-checked:translate-x-6 group-data-[size=sm]/switch:data-checked:translate-x-4 rtl:group-data-[size=default]/switch:data-checked:-translate-x-6 rtl:group-data-[size=sm]/switch:data-checked:-translate-x-4"
50
+ ),
51
+ render: (thumbProps, state) => /* @__PURE__ */ jsx("span", { ...thumbProps, children: state.checked ? /* @__PURE__ */ jsx(IconCheck, { "aria-hidden": true }) : null })
26
52
  }
27
53
  )
28
54
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/switch.tsx"],"names":["SwitchPrimitive"],"mappings":";;;;AAMA,SAAS,MAAA,CAAO;AAAA,EACd,SAAA;AAAA,EACA,IAAA,GAAO,SAAA;AAAA,EACP,GAAG;AACL,CAAA,EAEG;AACD,EAAA,uBACE,GAAA;AAAA,IAACA,QAAA,CAAgB,IAAA;AAAA,IAAhB;AAAA,MACC,WAAA,EAAU,QAAA;AAAA,MACV,WAAA,EAAW,IAAA;AAAA,MACX,SAAA,EAAW,EAAA;AAAA,QACT,6vBAAA;AAAA,QACA;AAAA,OACF;AAAA,MACC,GAAG,KAAA;AAAA,MAEJ,QAAA,kBAAA,GAAA;AAAA,QAACA,QAAA,CAAgB,KAAA;AAAA,QAAhB;AAAA,UACC,WAAA,EAAU,cAAA;AAAA,UACV,SAAA,EAAU;AAAA;AAAA;AACZ;AAAA,GACF;AAEJ","file":"switch.js","sourcesContent":["'use client'\n\nimport { Switch as SwitchPrimitive } from '@base-ui/react/switch'\n\nimport { cn } from '../lib/utils.js'\n\nfunction Switch({\n className,\n size = 'default',\n ...props\n}: SwitchPrimitive.Root.Props & {\n size?: 'sm' | 'default'\n}) {\n return (\n <SwitchPrimitive.Root\n data-slot='switch'\n data-size={size}\n className={cn(\n 'peer group/switch relative inline-flex shrink-0 items-center rounded-full border border-transparent transition-all outline-none group-has-[:focus-visible]/field-label:border-transparent group-has-[:focus-visible]/field-label:ring-0 after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 aria-invalid:border-destructive aria-invalid:ring-2 aria-invalid:ring-destructive/20 data-[size=default]:h-[16.6px] data-[size=default]:w-[28px] data-[size=sm]:h-[14px] data-[size=sm]:w-[24px] dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:bg-primary data-unchecked:bg-input dark:data-unchecked:bg-input/80 data-disabled:cursor-not-allowed data-disabled:opacity-50',\n className,\n )}\n {...props}\n >\n <SwitchPrimitive.Thumb\n data-slot='switch-thumb'\n className='pointer-events-none block rounded-full bg-background ring-0 transition-transform group-data-[size=default]/switch:size-3.5 group-data-[size=sm]/switch:size-3 group-data-[size=default]/switch:data-checked:translate-x-[calc(100%-2px)] group-data-[size=sm]/switch:data-checked:translate-x-[calc(100%-2px)] rtl:group-data-[size=default]/switch:data-checked:-translate-x-[calc(100%-2px)] rtl:group-data-[size=sm]/switch:data-checked:-translate-x-[calc(100%-2px)] dark:data-checked:bg-primary-foreground group-data-[size=default]/switch:data-unchecked:translate-x-0 group-data-[size=sm]/switch:data-unchecked:translate-x-0 rtl:group-data-[size=default]/switch:data-unchecked:-translate-x-0 rtl:group-data-[size=sm]/switch:data-unchecked:-translate-x-0 dark:data-unchecked:bg-foreground'\n />\n </SwitchPrimitive.Root>\n )\n}\n\nexport { Switch }\n"]}
1
+ {"version":3,"sources":["../../src/components/switch.tsx"],"names":["SwitchPrimitive"],"mappings":";;;;;AAOA,SAAS,MAAA,CAAO;AAAA,EACd,SAAA;AAAA,EACA,IAAA,GAAO,SAAA;AAAA,EACP,GAAG;AACL,CAAA,EAEG;AACD,EAAA,uBACE,GAAA;AAAA,IAACA,QAAA,CAAgB,IAAA;AAAA,IAAhB;AAAA,MACC,WAAA,EAAU,QAAA;AAAA,MACV,WAAA,EAAW,IAAA;AAAA,MACX,SAAA,EAAW,EAAA;AAAA,QACT,6JAAA;AAAA;AAAA;AAAA;AAAA,QAIA,mMAAA;AAAA;AAAA;AAAA,QAGA,yIAAA;AAAA;AAAA;AAAA,QAGA,qHAAA;AAAA,QACA,mEAAA;AAAA,QACA,mNAAA;AAAA,QACA,mHAAA;AAAA;AAAA;AAAA,QAGA,qhBAAA;AAAA;AAAA,QAEA,uKAAA;AAAA,QACA;AAAA,OACF;AAAA,MACC,GAAG,KAAA;AAAA,MAIJ,QAAA,kBAAA,GAAA;AAAA,QAACA,QAAA,CAAgB,KAAA;AAAA,QAAhB;AAAA,UACC,WAAA,EAAU,cAAA;AAAA,UACV,SAAA,EAAW,EAAA;AAAA,YACT,kNAAA;AAAA,YACA,2KAAA;AAAA,YACA,yOAAA;AAAA,YACA,2DAAA;AAAA,YACA;AAAA,WACF;AAAA,UACA,MAAA,EAAQ,CAAC,UAAA,EAAY,KAAA,yBAClB,MAAA,EAAA,EAAM,GAAG,UAAA,EAAa,QAAA,EAAA,KAAA,CAAM,0BAAU,GAAA,CAAC,SAAA,EAAA,EAAU,aAAA,EAAW,IAAA,EAAC,IAAK,IAAA,EAAK;AAAA;AAAA;AAE5E;AAAA,GACF;AAEJ","file":"switch.js","sourcesContent":["'use client'\n\nimport { Switch as SwitchPrimitive } from '@base-ui/react/switch'\n\nimport { IconCheck } from '../icons/check.js'\nimport { cn } from '../lib/utils.js'\n\nfunction Switch({\n className,\n size = 'default',\n ...props\n}: SwitchPrimitive.Root.Props & {\n size?: 'sm' | 'default'\n}) {\n return (\n <SwitchPrimitive.Root\n data-slot='switch'\n data-size={size}\n className={cn(\n 'peer group/switch relative inline-flex shrink-0 items-center rounded-full border border-(--text-default) bg-(--input-surface) motion-safe:transition-colors',\n // Checkbox's theme bridge, so brand overrides reach both modes. The\n // thumb reads these too: ink for the fill and tick, mark for the thumb\n // on a selected track, off for the ring on an unselected one.\n '[--switch-ink:var(--color-primary-800)] [--switch-mark:var(--surface-default)] [--switch-off:var(--text-default)] dark:not-data-disabled:not-aria-invalid:[--switch-ink:var(--color-primary-200)]',\n // The padding puts the thumb 5px (sm: 4px) inside the outer edge,\n // Checkbox's inset, and fixes its travel at the track minus both insets.\n 'data-[size=default]:h-8 data-[size=default]:w-14 data-[size=default]:px-1 data-[size=sm]:h-6 data-[size=sm]:w-10 data-[size=sm]:px-0.75',\n // A 44px hit area without making the visible control larger. The\n // pseudo-element sizes from the padding box, so add the border back.\n 'after:absolute after:top-1/2 after:left-1/2 after:h-11 after:w-[calc(100%+2px)] after:min-w-11 after:-translate-1/2',\n 'data-checked:border-(--switch-ink) data-checked:bg-(--switch-ink)',\n 'not-data-disabled:data-checked:hover:bg-[color-mix(in_srgb,var(--switch-ink)_88%,var(--input-surface))] not-data-disabled:data-unchecked:hover:bg-[color-mix(in_srgb,var(--switch-ink)_10%,var(--input-surface))]',\n 'focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-3 focus-visible:outline-(--switch-ink)',\n // Input's invalid roles. The second pixel of the off border is an inset\n // ring rather than border-2, so the thumb does not shift by a pixel.\n 'aria-invalid:not-data-disabled:[--switch-ink:var(--danger-solid)] aria-invalid:not-data-disabled:[--switch-mark:var(--white)] aria-invalid:focus-visible:outline-offset-2 aria-invalid:focus-visible:outline-(--input-invalid-ring) aria-invalid:not-data-disabled:data-unchecked:border-(--input-invalid-border) aria-invalid:not-data-disabled:data-unchecked:inset-ring aria-invalid:not-data-disabled:data-unchecked:inset-ring-(--input-invalid-border) aria-invalid:not-data-disabled:data-unchecked:hover:bg-(--input-invalid-surface-hover)',\n // Base UI renders a span: data-disabled covers both the prop and Field.\n 'data-disabled:cursor-not-allowed data-disabled:border-(--text-subtle) data-disabled:[--switch-ink:var(--text-subtle)] data-disabled:[--switch-off:var(--text-subtle)]',\n className,\n )}\n {...props}\n >\n {/* Off is a hollow ring, on is a solid thumb with a tick, so the state\n reads by shape as well as by colour and side. */}\n <SwitchPrimitive.Thumb\n data-slot='switch-thumb'\n className={cn(\n 'pointer-events-none grid shrink-0 place-items-center rounded-full bg-(--input-surface) text-(--switch-ink) inset-ring-2 inset-ring-(--switch-off) motion-safe:transition-[translate,background-color,box-shadow]',\n 'group-data-[size=default]/switch:size-5.5 group-data-[size=sm]/switch:size-4 group-data-[size=default]/switch:[&>svg]:size-4.5 group-data-[size=sm]/switch:[&>svg]:size-3',\n 'not-data-disabled:data-unchecked:group-hover/switch:bg-[color-mix(in_srgb,var(--switch-ink)_10%,var(--input-surface))] group-aria-invalid/switch:not-data-disabled:data-unchecked:group-hover/switch:bg-(--input-invalid-surface-hover)',\n 'data-checked:bg-(--switch-mark) data-checked:inset-ring-0',\n 'group-data-[size=default]/switch:data-checked:translate-x-6 group-data-[size=sm]/switch:data-checked:translate-x-4 rtl:group-data-[size=default]/switch:data-checked:-translate-x-6 rtl:group-data-[size=sm]/switch:data-checked:-translate-x-4',\n )}\n render={(thumbProps, state) => (\n <span {...thumbProps}>{state.checked ? <IconCheck aria-hidden /> : null}</span>\n )}\n />\n </SwitchPrimitive.Root>\n )\n}\n\nexport { Switch }\n"]}