@nswds/ui 8.4.1 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/components/badge.d.ts +16 -25
- package/dist/components/badge.js +50 -393
- package/dist/components/badge.js.map +1 -1
- package/dist/components/button.d.ts +3 -3
- package/dist/components/callout.d.ts +2 -2
- package/dist/components/header.d.ts +3 -1
- package/dist/components/input-group.d.ts +1 -1
- package/dist/components/link.js +1 -1
- package/dist/components/link.js.map +1 -1
- package/dist/components/masthead.d.ts +1 -1
- package/dist/components/skip-link.d.ts +1 -1
- package/dist/components/switch.js +28 -2
- package/dist/components/switch.js.map +1 -1
- package/dist/components/tag.d.ts +47 -0
- package/dist/components/tag.js +196 -0
- package/dist/components/tag.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +1 -0
- package/dist/lib/label-colors.d.ts +11 -0
- package/dist/lib/label-colors.js +10 -0
- package/dist/lib/label-colors.js.map +1 -0
- package/dist/styles.css +1 -1
- package/package.json +1 -1
|
@@ -25,7 +25,7 @@ type CalloutStatus = 'info' | 'success' | 'warning' | 'danger';
|
|
|
25
25
|
* drift out of step with the token library.
|
|
26
26
|
*/
|
|
27
27
|
declare const calloutVariants: (props?: ({
|
|
28
|
-
status?: "
|
|
28
|
+
status?: "danger" | "success" | "warning" | "info" | null | undefined;
|
|
29
29
|
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
30
30
|
type CalloutProps = Omit<React.ComponentPropsWithoutRef<'div'>, 'title'> & VariantProps<typeof calloutVariants> & {
|
|
31
31
|
/** Optional bold lead line above the body copy. */
|
|
@@ -66,7 +66,7 @@ declare function Callout({ className, status, title, icon, children, ref, ...pro
|
|
|
66
66
|
*/
|
|
67
67
|
declare const Alert: typeof Callout;
|
|
68
68
|
declare const alertVariants: (props?: ({
|
|
69
|
-
status?: "
|
|
69
|
+
status?: "danger" | "success" | "warning" | "info" | null | undefined;
|
|
70
70
|
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
71
71
|
type AlertProps = CalloutProps;
|
|
72
72
|
type AlertStatus = CalloutStatus;
|
|
@@ -3,6 +3,8 @@ import { VariantProps } from 'class-variance-authority';
|
|
|
3
3
|
import React__default from 'react';
|
|
4
4
|
import { BadgeProps } from './badge.js';
|
|
5
5
|
import { Link } from './link.js';
|
|
6
|
+
import '../lib/label-colors.js';
|
|
7
|
+
import './button.js';
|
|
6
8
|
import '@base-ui/react/button';
|
|
7
9
|
|
|
8
10
|
/**
|
|
@@ -30,7 +32,7 @@ declare const headerColors: {
|
|
|
30
32
|
};
|
|
31
33
|
type HeaderColor = keyof typeof headerColors;
|
|
32
34
|
declare const headerVariants: (props?: ({
|
|
33
|
-
color?: "
|
|
35
|
+
color?: "white" | "grey" | "light" | "dark" | null | undefined;
|
|
34
36
|
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
35
37
|
declare const headerContainerVariants: (props?: ({
|
|
36
38
|
container?: "fluid" | "contained" | null | undefined;
|
|
@@ -35,7 +35,7 @@ declare function InputGroupButton({ className, type, variant, size, ...props }:
|
|
|
35
35
|
type?: 'button' | 'submit' | 'reset';
|
|
36
36
|
}): React.JSX.Element;
|
|
37
37
|
declare const inputGroupActionVariants: (props?: ({
|
|
38
|
-
variant?: "
|
|
38
|
+
variant?: "open" | "solid" | "subtle" | null | undefined;
|
|
39
39
|
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
40
40
|
declare function InputGroupAction({ className, type, variant, ...props }: Omit<React.ComponentProps<typeof Button>, 'size' | 'type' | 'variant'> & VariantProps<typeof inputGroupActionVariants> & {
|
|
41
41
|
type?: 'button' | 'submit' | 'reset';
|
package/dist/components/link.js
CHANGED
|
@@ -55,7 +55,7 @@ const linkVariants = cva("", {
|
|
|
55
55
|
...styledBase,
|
|
56
56
|
"[--link-color:var(--color-white)] dark:[--link-color:var(--color-grey-800)]"
|
|
57
57
|
],
|
|
58
|
-
// Zero classes — the consumer (typically Button /
|
|
58
|
+
// Zero classes — the consumer (typically Button / TagLink) is
|
|
59
59
|
// supplying its own complete visual treatment and doesn't want any
|
|
60
60
|
// Link styling to compose on top. Intentionally omits the icon defaults
|
|
61
61
|
// too, so the wrapping component has full control of icon sizing.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/link.tsx"],"names":[],"mappings":";;;;;AASA,MAAM,UAAA,GAAa;AAAA;AAAA,EAEjB,2FAAA;AAAA;AAAA;AAAA;AAAA,EAIA,qBAAA;AAAA,EACA,qEAAA;AAAA,EACA,4EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA,2CAAA;AAAA,EACA,mEAAA;AAAA;AAAA,EAEA,mEAAA;AAAA,EACA,mHAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA;AACF,CAAA;AAEA,MAAM,YAAA,GAAe,IAAI,EAAA,EAAI;AAAA,EAC3B,QAAA,EAAU;AAAA,IACR,OAAA,EAAS;AAAA,MACP,OAAA,EAAS;AAAA,QACP,GAAG,UAAA;AAAA;AAAA,QAEH,sFAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAMA,wDAAA;AAAA;AAAA,QAEA,oDAAA;AAAA,QACA;AAAA,OACF;AAAA,MACA,SAAA,EAAW;AAAA,QACT,GAAG,UAAA;AAAA,QACH;AAAA,OACF;AAAA,MACA,KAAA,EAAO;AAAA,QACL,GAAG,UAAA;AAAA,QACH;AAAA,OACF;AAAA;AAAA;AAAA;AAAA;AAAA,MAKA,UAAU;AAAC;AACb,GACF;AAAA,EACA,eAAA,EAAiB;AAAA,IACf,OAAA,EAAS;AAAA;AAEb,CAAC;AAkCD,MAAM,oBAAA,GAAuB,cAAoC,IAAI,CAAA;AAErE,SAAS,YAAA,CAAa;AAAA,EACpB,QAAA;AAAA,EACA;AACF,CAAA,EAGG;AACD,EAAA,2BAAQ,oBAAA,CAAqB,QAAA,EAArB,EAA8B,KAAA,EAAO,WA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AA,EACA,WAAA,GAAc,sBAAA;AAAA,EACd,MAAA,GAAS,QAAA;AAAA,EACT,GAAA,GAAM,qBAAA;AAAA,EACN,GAAA;AAAA,EACA,GAAG;AACL,CAAA,EAAsB;AACpB,EAAA,MAAM,YAAA,GAAe,SAAS,IAAA,GAAO,IAAA,GAAQ,wBAAQ,GAAA,CAAC,aAAA,EAAA,EAAc,WAAU,QAAA,EAAS,CAAA;AAEvF,EAAA,4BACG,IAAA,EAAA,EAAM,GAAG,KAAA,EAAO,MAAA,EAAgB,KAAU,GAAA,EACxC,QAAA,EAAA;AAAA,IAAA,QAAA;AAAA,IACA,YAAA;AAAA,IACA,WAAA,mBAAc,IAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,SAAA,EAAU,QAAA,EAAA;AAAA,MAAA,GAAA;AAAA,MAAE;AAAA,KAAA,EAAY,CAAA,GAAU;AAAA,GAAA,EACnE,CAAA;AAEJ","file":"link.js","sourcesContent":["'use client'\n\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport React, { createContext, useContext } from 'react'\n\nimport { cn } from '../lib/utils.js'\n\n// Shared visual base for all *styled* variants. Pulled out so the `unstyled`\n// variant can omit it entirely (otherwise it wouldn't actually be unstyled).\nconst styledBase = [\n // Typography + transition\n 'font-medium underline decoration-current underline-offset-4 motion-safe:transition-colors',\n // Text colour derives from --link-color; --link-halo and --link-halo-active\n // derive from --link-color via color-mix so each variant only sets the one\n // token and the hover/active halos follow automatically.\n 'text-(--link-color)',\n '[--link-halo:color-mix(in_oklch,var(--link-color)_10%,transparent)]',\n '[--link-halo-active:color-mix(in_oklch,var(--link-color)_18%,transparent)]',\n // Hover / active halos use box-shadow + background-color rather than\n // padding, so inline links sit flush against surrounding text. The\n // shadows extend the halo 2px above and 4px below the line box, matching\n // the GOV.UK Design System focus pattern.\n 'hover:bg-(--link-halo) hover:decoration-2',\n 'hover:shadow-[0_-2px_0_var(--link-halo),0_4px_0_var(--link-halo)]',\n // Wrapped lines each get their own halo\n '[box-decoration-break:clone] [-webkit-box-decoration-break:clone]',\n 'focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--link-color)',\n // Default sizing for icon children — without this, an unsized SVG inside\n // a Link collapses to 0×0 in flex layouts. `vertical-align: -0.15em`\n // aligns the icon's box to the text's x-height for inline-flow usage;\n // flex contexts ignore vertical-align and should set `items-baseline` (or\n // similar) on the Link itself. Consumers can override per-icon by passing\n // a `size-*` or `align-*` class on the icon itself.\n '*:data-[slot=icon]:inline-block *:data-[slot=icon]:size-[1em] *:data-[slot=icon]:shrink-0 *:data-[slot=icon]:align-[-0.15em]',\n]\n\nconst linkVariants = cva('', {\n variants: {\n variant: {\n primary: [\n ...styledBase,\n // Link\n '[--link-color:var(--color-primary-800)] dark:[--link-color:var(--color-primary-200)]',\n // Visited — set the text colour directly. `:visited` is restricted by\n // browsers to a small set of paint-only properties (color, *-color,\n // fill, stroke) and ignores custom properties, so we can't shift\n // --link-color here. Setting `text-*` works, and the underline follows\n // because the base uses `decoration-current` (currentColor).\n 'visited:text-primary-600 dark:visited:text-primary-300',\n // Active — deeper halo via --link-halo-active\n 'active:bg-(--link-halo-active) active:decoration-2',\n 'active:shadow-[0_-2px_0_var(--link-halo-active),0_4px_0_var(--link-halo-active)]',\n ],\n secondary: [\n ...styledBase,\n '[--link-color:var(--color-primary-200)] dark:[--link-color:var(--color-primary-800)]',\n ],\n white: [\n ...styledBase,\n '[--link-color:var(--color-white)] dark:[--link-color:var(--color-grey-800)]',\n ],\n // Zero classes — the consumer (typically Button / BadgeButton) is\n // supplying its own complete visual treatment and doesn't want any\n // Link styling to compose on top. Intentionally omits the icon defaults\n // too, so the wrapping component has full control of icon sizing.\n unstyled: [],\n },\n },\n defaultVariants: {\n variant: 'primary',\n },\n})\n\ntype LinkComponent = React.ElementType\n\n/**\n * Object form of a link target, mirroring the `UrlObject` accepted by framework\n * link components such as next/link. Used for `Link`'s `href` when a custom\n * element/component is supplied via `as` / `LinkProvider`; a plain anchor still\n * takes a string.\n *\n * Fields are optional, matching next/link. Typing the *shape* — rather than the\n * previous bare `object` — rejects unrelated values like arrays and functions\n * (both carry a numeric `length`, which is incompatible with `length?: never`).\n */\ntype LinkUrlObject = {\n pathname?: string | null\n query?: string | Record<string, unknown> | null\n hash?: string | null\n search?: string | null\n host?: string | null\n hostname?: string | null\n port?: string | number | null\n protocol?: string | null\n /** Brand that excludes arrays/functions (which have a numeric `length`). */\n length?: never\n}\n\ntype LinkProps = Omit<React.ComponentPropsWithoutRef<'a'>, 'href'> &\n VariantProps<typeof linkVariants> & {\n as?: LinkComponent\n href: React.ComponentPropsWithoutRef<'a'>['href'] | LinkUrlObject\n ref?: React.Ref<HTMLAnchorElement>\n }\n\nconst LinkComponentContext = createContext<LinkComponent | null>(null)\n\nfunction LinkProvider({\n children,\n component,\n}: {\n children: React.ReactNode\n component: LinkComponent\n}) {\n return <LinkComponentContext.Provider value={component}>{children}</LinkComponentContext.Provider>\n}\n\n/**\n * Polymorphic anchor wrapper. Renders an `<a>` by default, or any element\n * provided via the `as` prop, or via a `<LinkProvider component={…}>` context\n * (use the context to inject a framework Link like Next.js `next/link`).\n *\n * Hover / active / focus styling on consumers should use the native CSS\n * pseudo-class utilities (`hover:`, `active:`, `focus-visible:`, and their\n * `group-…` variants) — Tailwind v4 maps them to real CSS, no JS state\n * tracking required.\n */\n/**\n * Anchor-only HTML attributes. When `Link` is rendered as a non-anchor\n * intrinsic element (e.g. `as=\"button\"`), forwarding these produces invalid\n * markup like `<button href=\"…\">` and React DOM warnings, so they are\n * stripped. Custom components passed via `as` / `LinkProvider` are assumed to\n * be anchor-like (e.g. `next/link`) and receive the full prop set.\n */\nconst ANCHOR_ONLY_PROPS = [\n 'href',\n 'target',\n 'rel',\n 'download',\n 'ping',\n 'referrerPolicy',\n 'hrefLang',\n] as const\n\nfunction Link({ as, variant, className, ref, ...props }: LinkProps) {\n const ContextLink = useContext(LinkComponentContext)\n const component = as ?? ContextLink ?? 'a'\n\n // Drop anchor-only props when the resolved element is a non-anchor\n // intrinsic tag (e.g. `as=\"button\"`). String components other than 'a'\n // are real DOM tags that can't accept `href`/`target`/etc; non-string\n // components (framework links) keep the full set.\n const isNonAnchorIntrinsic = typeof component === 'string' && component !== 'a'\n\n const elementProps = { ...props } as Record<string, unknown>\n if (isNonAnchorIntrinsic) {\n for (const prop of ANCHOR_ONLY_PROPS) {\n delete elementProps[prop]\n }\n }\n\n return React.createElement(component, {\n ...elementProps,\n className: cn(linkVariants({ variant }), className),\n ref,\n })\n}\n\n/**\n * Open-in-new-tab glyph used by `ExternalLink`. Defined inline (rather than\n * imported from `Icons`) so that consumers of `Link` / `ExternalLink` don't\n * tree-pull the full icon set. Sized and aligned through the `[data-slot=icon]`\n * rules in `linkVariants`.\n */\nfunction OpenInNewIcon(props: React.SVGProps<SVGSVGElement>) {\n return (\n <svg\n data-slot='icon'\n fill='currentColor'\n viewBox='0 -960 960 960'\n aria-hidden='true'\n {...props}\n >\n <path d='M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h240q17 0 28.5 11.5T480-800q0 17-11.5 28.5T440-760H200v560h560v-240q0-17 11.5-28.5T800-480q17 0 28.5 11.5T840-440v240q0 33-23.5 56.5T760-120H200Zm560-584L416-360q-11 11-28 11t-28-11q-11-11-11-28t11-28l344-344H600q-17 0-28.5-11.5T560-800q0-17 11.5-28.5T600-840h200q17 0 28.5 11.5T840-800v200q0 17-11.5 28.5T800-560q-17 0-28.5-11.5T760-600v-104Z' />\n </svg>\n )\n}\n\ntype ExternalLinkProps = LinkProps & {\n /**\n * Screen-reader suffix announced after the link text. Defaults to\n * `\"(opens in a new tab)\"`. Pass an empty string to suppress.\n */\n newTabLabel?: string\n /**\n * Custom trailing icon. Pass `null` to hide the icon entirely. If omitted,\n * the default open-in-new glyph is rendered.\n */\n icon?: React.ReactNode | null\n}\n\n/**\n * Anchor preconfigured for cross-origin / new-tab navigation. Sets\n * `target=\"_blank\"` and `rel=\"noopener noreferrer\"` by default, renders a\n * trailing open-in-new icon, and appends a visually-hidden suffix so screen\n * readers announce that the link opens a new tab.\n *\n * All `Link` props are forwarded — `variant`, `as`, `className`, etc. —\n * and any of `target`, `rel`, `icon`, or `newTabLabel` can be overridden.\n */\nfunction ExternalLink({\n children,\n icon,\n newTabLabel = '(opens in a new tab)',\n target = '_blank',\n rel = 'noopener noreferrer',\n ref,\n ...props\n}: ExternalLinkProps) {\n const trailingIcon = icon === null ? null : (icon ?? <OpenInNewIcon className='ml-0.5' />)\n\n return (\n <Link {...props} target={target} rel={rel} ref={ref}>\n {children}\n {trailingIcon}\n {newTabLabel ? <span className='sr-only'> {newTabLabel}</span> : null}\n </Link>\n )\n}\n\nexport { ExternalLink, Link, LinkProvider, linkVariants }\nexport type { ExternalLinkProps, LinkComponent, LinkProps, LinkUrlObject }\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/link.tsx"],"names":[],"mappings":";;;;;AASA,MAAM,UAAA,GAAa;AAAA;AAAA,EAEjB,2FAAA;AAAA;AAAA;AAAA;AAAA,EAIA,qBAAA;AAAA,EACA,qEAAA;AAAA,EACA,4EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA,2CAAA;AAAA,EACA,mEAAA;AAAA;AAAA,EAEA,mEAAA;AAAA,EACA,mHAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA;AACF,CAAA;AAEA,MAAM,YAAA,GAAe,IAAI,EAAA,EAAI;AAAA,EAC3B,QAAA,EAAU;AAAA,IACR,OAAA,EAAS;AAAA,MACP,OAAA,EAAS;AAAA,QACP,GAAG,UAAA;AAAA;AAAA,QAEH,sFAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAMA,wDAAA;AAAA;AAAA,QAEA,oDAAA;AAAA,QACA;AAAA,OACF;AAAA,MACA,SAAA,EAAW;AAAA,QACT,GAAG,UAAA;AAAA,QACH;AAAA,OACF;AAAA,MACA,KAAA,EAAO;AAAA,QACL,G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AA,IAAC,KAAA;AAAA,IAAA;AAAA,MACC,WAAA,EAAU,MAAA;AAAA,MACV,IAAA,EAAK,cAAA;AAAA,MACL,OAAA,EAAQ,gBAAA;AAAA,MACR,aAAA,EAAY,MAAA;AAAA,MACX,GAAG,KAAA;AAAA,MAEJ,QAAA,kBAAA,GAAA,CAAC,MAAA,EAAA,EAAK,CAAA,EAAE,qZAAA,EAAsZ;AAAA;AAAA,GACha;AAEJ;AAwBA,SAAS,YAAA,CAAa;AAAA,EACpB,QAAA;AAAA,EACA,IAAA;AAAA,EACA,WAAA,GAAc,sBAAA;AAAA,EACd,MAAA,GAAS,QAAA;AAAA,EACT,GAAA,GAAM,qBAAA;AAAA,EACN,GAAA;AAAA,EACA,GAAG;AACL,CAAA,EAAsB;AACpB,EAAA,MAAM,YAAA,GAAe,SAAS,IAAA,GAAO,IAAA,GAAQ,wBAAQ,GAAA,CAAC,aAAA,EAAA,EAAc,WAAU,QAAA,EAAS,CAAA;AAEvF,EAAA,4BACG,IAAA,EAAA,EAAM,GAAG,KAAA,EAAO,MAAA,EAAgB,KAAU,GAAA,EACxC,QAAA,EAAA;AAAA,IAAA,QAAA;AAAA,IACA,YAAA;AAAA,IACA,WAAA,mBAAc,IAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,SAAA,EAAU,QAAA,EAAA;AAAA,MAAA,GAAA;AAAA,MAAE;AAAA,KAAA,EAAY,CAAA,GAAU;AAAA,GAAA,EACnE,CAAA;AAEJ","file":"link.js","sourcesContent":["'use client'\n\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport React, { createContext, useContext } from 'react'\n\nimport { cn } from '../lib/utils.js'\n\n// Shared visual base for all *styled* variants. Pulled out so the `unstyled`\n// variant can omit it entirely (otherwise it wouldn't actually be unstyled).\nconst styledBase = [\n // Typography + transition\n 'font-medium underline decoration-current underline-offset-4 motion-safe:transition-colors',\n // Text colour derives from --link-color; --link-halo and --link-halo-active\n // derive from --link-color via color-mix so each variant only sets the one\n // token and the hover/active halos follow automatically.\n 'text-(--link-color)',\n '[--link-halo:color-mix(in_oklch,var(--link-color)_10%,transparent)]',\n '[--link-halo-active:color-mix(in_oklch,var(--link-color)_18%,transparent)]',\n // Hover / active halos use box-shadow + background-color rather than\n // padding, so inline links sit flush against surrounding text. The\n // shadows extend the halo 2px above and 4px below the line box, matching\n // the GOV.UK Design System focus pattern.\n 'hover:bg-(--link-halo) hover:decoration-2',\n 'hover:shadow-[0_-2px_0_var(--link-halo),0_4px_0_var(--link-halo)]',\n // Wrapped lines each get their own halo\n '[box-decoration-break:clone] [-webkit-box-decoration-break:clone]',\n 'focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--link-color)',\n // Default sizing for icon children — without this, an unsized SVG inside\n // a Link collapses to 0×0 in flex layouts. `vertical-align: -0.15em`\n // aligns the icon's box to the text's x-height for inline-flow usage;\n // flex contexts ignore vertical-align and should set `items-baseline` (or\n // similar) on the Link itself. Consumers can override per-icon by passing\n // a `size-*` or `align-*` class on the icon itself.\n '*:data-[slot=icon]:inline-block *:data-[slot=icon]:size-[1em] *:data-[slot=icon]:shrink-0 *:data-[slot=icon]:align-[-0.15em]',\n]\n\nconst linkVariants = cva('', {\n variants: {\n variant: {\n primary: [\n ...styledBase,\n // Link\n '[--link-color:var(--color-primary-800)] dark:[--link-color:var(--color-primary-200)]',\n // Visited — set the text colour directly. `:visited` is restricted by\n // browsers to a small set of paint-only properties (color, *-color,\n // fill, stroke) and ignores custom properties, so we can't shift\n // --link-color here. Setting `text-*` works, and the underline follows\n // because the base uses `decoration-current` (currentColor).\n 'visited:text-primary-600 dark:visited:text-primary-300',\n // Active — deeper halo via --link-halo-active\n 'active:bg-(--link-halo-active) active:decoration-2',\n 'active:shadow-[0_-2px_0_var(--link-halo-active),0_4px_0_var(--link-halo-active)]',\n ],\n secondary: [\n ...styledBase,\n '[--link-color:var(--color-primary-200)] dark:[--link-color:var(--color-primary-800)]',\n ],\n white: [\n ...styledBase,\n '[--link-color:var(--color-white)] dark:[--link-color:var(--color-grey-800)]',\n ],\n // Zero classes — the consumer (typically Button / TagLink) is\n // supplying its own complete visual treatment and doesn't want any\n // Link styling to compose on top. Intentionally omits the icon defaults\n // too, so the wrapping component has full control of icon sizing.\n unstyled: [],\n },\n },\n defaultVariants: {\n variant: 'primary',\n },\n})\n\ntype LinkComponent = React.ElementType\n\n/**\n * Object form of a link target, mirroring the `UrlObject` accepted by framework\n * link components such as next/link. Used for `Link`'s `href` when a custom\n * element/component is supplied via `as` / `LinkProvider`; a plain anchor still\n * takes a string.\n *\n * Fields are optional, matching next/link. Typing the *shape* — rather than the\n * previous bare `object` — rejects unrelated values like arrays and functions\n * (both carry a numeric `length`, which is incompatible with `length?: never`).\n */\ntype LinkUrlObject = {\n pathname?: string | null\n query?: string | Record<string, unknown> | null\n hash?: string | null\n search?: string | null\n host?: string | null\n hostname?: string | null\n port?: string | number | null\n protocol?: string | null\n /** Brand that excludes arrays/functions (which have a numeric `length`). */\n length?: never\n}\n\ntype LinkProps = Omit<React.ComponentPropsWithoutRef<'a'>, 'href'> &\n VariantProps<typeof linkVariants> & {\n as?: LinkComponent\n href: React.ComponentPropsWithoutRef<'a'>['href'] | LinkUrlObject\n ref?: React.Ref<HTMLAnchorElement>\n }\n\nconst LinkComponentContext = createContext<LinkComponent | null>(null)\n\nfunction LinkProvider({\n children,\n component,\n}: {\n children: React.ReactNode\n component: LinkComponent\n}) {\n return <LinkComponentContext.Provider value={component}>{children}</LinkComponentContext.Provider>\n}\n\n/**\n * Polymorphic anchor wrapper. Renders an `<a>` by default, or any element\n * provided via the `as` prop, or via a `<LinkProvider component={…}>` context\n * (use the context to inject a framework Link like Next.js `next/link`).\n *\n * Hover / active / focus styling on consumers should use the native CSS\n * pseudo-class utilities (`hover:`, `active:`, `focus-visible:`, and their\n * `group-…` variants) — Tailwind v4 maps them to real CSS, no JS state\n * tracking required.\n */\n/**\n * Anchor-only HTML attributes. When `Link` is rendered as a non-anchor\n * intrinsic element (e.g. `as=\"button\"`), forwarding these produces invalid\n * markup like `<button href=\"…\">` and React DOM warnings, so they are\n * stripped. Custom components passed via `as` / `LinkProvider` are assumed to\n * be anchor-like (e.g. `next/link`) and receive the full prop set.\n */\nconst ANCHOR_ONLY_PROPS = [\n 'href',\n 'target',\n 'rel',\n 'download',\n 'ping',\n 'referrerPolicy',\n 'hrefLang',\n] as const\n\nfunction Link({ as, variant, className, ref, ...props }: LinkProps) {\n const ContextLink = useContext(LinkComponentContext)\n const component = as ?? ContextLink ?? 'a'\n\n // Drop anchor-only props when the resolved element is a non-anchor\n // intrinsic tag (e.g. `as=\"button\"`). String components other than 'a'\n // are real DOM tags that can't accept `href`/`target`/etc; non-string\n // components (framework links) keep the full set.\n const isNonAnchorIntrinsic = typeof component === 'string' && component !== 'a'\n\n const elementProps = { ...props } as Record<string, unknown>\n if (isNonAnchorIntrinsic) {\n for (const prop of ANCHOR_ONLY_PROPS) {\n delete elementProps[prop]\n }\n }\n\n return React.createElement(component, {\n ...elementProps,\n className: cn(linkVariants({ variant }), className),\n ref,\n })\n}\n\n/**\n * Open-in-new-tab glyph used by `ExternalLink`. Defined inline (rather than\n * imported from `Icons`) so that consumers of `Link` / `ExternalLink` don't\n * tree-pull the full icon set. Sized and aligned through the `[data-slot=icon]`\n * rules in `linkVariants`.\n */\nfunction OpenInNewIcon(props: React.SVGProps<SVGSVGElement>) {\n return (\n <svg\n data-slot='icon'\n fill='currentColor'\n viewBox='0 -960 960 960'\n aria-hidden='true'\n {...props}\n >\n <path d='M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h240q17 0 28.5 11.5T480-800q0 17-11.5 28.5T440-760H200v560h560v-240q0-17 11.5-28.5T800-480q17 0 28.5 11.5T840-440v240q0 33-23.5 56.5T760-120H200Zm560-584L416-360q-11 11-28 11t-28-11q-11-11-11-28t11-28l344-344H600q-17 0-28.5-11.5T560-800q0-17 11.5-28.5T600-840h200q17 0 28.5 11.5T840-800v200q0 17-11.5 28.5T800-560q-17 0-28.5-11.5T760-600v-104Z' />\n </svg>\n )\n}\n\ntype ExternalLinkProps = LinkProps & {\n /**\n * Screen-reader suffix announced after the link text. Defaults to\n * `\"(opens in a new tab)\"`. Pass an empty string to suppress.\n */\n newTabLabel?: string\n /**\n * Custom trailing icon. Pass `null` to hide the icon entirely. If omitted,\n * the default open-in-new glyph is rendered.\n */\n icon?: React.ReactNode | null\n}\n\n/**\n * Anchor preconfigured for cross-origin / new-tab navigation. Sets\n * `target=\"_blank\"` and `rel=\"noopener noreferrer\"` by default, renders a\n * trailing open-in-new icon, and appends a visually-hidden suffix so screen\n * readers announce that the link opens a new tab.\n *\n * All `Link` props are forwarded — `variant`, `as`, `className`, etc. —\n * and any of `target`, `rel`, `icon`, or `newTabLabel` can be overridden.\n */\nfunction ExternalLink({\n children,\n icon,\n newTabLabel = '(opens in a new tab)',\n target = '_blank',\n rel = 'noopener noreferrer',\n ref,\n ...props\n}: ExternalLinkProps) {\n const trailingIcon = icon === null ? null : (icon ?? <OpenInNewIcon className='ml-0.5' />)\n\n return (\n <Link {...props} target={target} rel={rel} ref={ref}>\n {children}\n {trailingIcon}\n {newTabLabel ? <span className='sr-only'> {newTabLabel}</span> : null}\n </Link>\n )\n}\n\nexport { ExternalLink, Link, LinkProvider, linkVariants }\nexport type { ExternalLinkProps, LinkComponent, LinkProps, LinkUrlObject }\n"]}
|
|
@@ -10,7 +10,7 @@ declare const mastheadColors: {
|
|
|
10
10
|
};
|
|
11
11
|
type MastheadColor = keyof typeof mastheadColors;
|
|
12
12
|
declare const mastheadVariants: (props?: ({
|
|
13
|
-
color?: "
|
|
13
|
+
color?: "white" | "grey" | "light" | "dark" | null | undefined;
|
|
14
14
|
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
15
15
|
declare const mastheadContainerVariants: (props?: ({
|
|
16
16
|
container?: "fluid" | "contained" | null | undefined;
|
|
@@ -3,7 +3,7 @@ import { VariantProps } from 'class-variance-authority';
|
|
|
3
3
|
import React__default from 'react';
|
|
4
4
|
|
|
5
5
|
declare const skipLinkVariants: (props?: ({
|
|
6
|
-
color?: "
|
|
6
|
+
color?: "white" | "grey" | "light" | "dark" | null | undefined;
|
|
7
7
|
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
8
8
|
type SkipLinkProps = React__default.ComponentPropsWithoutRef<'a'> & VariantProps<typeof skipLinkVariants> & {
|
|
9
9
|
/** Same-page fragment target, e.g. `"#content"`. */
|
|
@@ -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-
|
|
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:
|
|
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":"
|
|
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"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
2
|
+
import { Button } from '@base-ui/react/button';
|
|
3
|
+
import { Checkbox } from '@base-ui/react/checkbox';
|
|
4
|
+
import { VariantProps } from 'class-variance-authority';
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
import { LabelColor } from '../lib/label-colors.js';
|
|
7
|
+
import { Link } from './link.js';
|
|
8
|
+
import './button.js';
|
|
9
|
+
|
|
10
|
+
declare const tagCva: (props?: ({
|
|
11
|
+
variant?: "solid" | "soft" | "surface" | "outline" | null | undefined;
|
|
12
|
+
size?: "default" | "sm" | "lg" | null | undefined;
|
|
13
|
+
interactive?: boolean | null | undefined;
|
|
14
|
+
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
15
|
+
type TagVariantProps = NonNullable<Parameters<typeof tagCva>[0]> & {
|
|
16
|
+
color?: LabelColor | null;
|
|
17
|
+
};
|
|
18
|
+
declare function tagVariants({ color, variant, class: classValue, className, ...props }?: TagVariantProps): string;
|
|
19
|
+
type TagAppearance = Omit<VariantProps<typeof tagVariants>, 'interactive'>;
|
|
20
|
+
type TagProps = TagAppearance & React.ComponentPropsWithoutRef<'span'> & {
|
|
21
|
+
ref?: React.Ref<HTMLSpanElement>;
|
|
22
|
+
};
|
|
23
|
+
/** A non-interactive category or topic. Use Badge for status and counts. */
|
|
24
|
+
declare function Tag({ variant, color, size, className, children, ...props }: TagProps): React.JSX.Element;
|
|
25
|
+
type TagButtonProps = TagAppearance & Omit<Button.Props, 'className'> & {
|
|
26
|
+
className?: string;
|
|
27
|
+
};
|
|
28
|
+
type TagLinkProps = TagAppearance & Omit<React.ComponentProps<typeof Link>, 'variant' | 'color'>;
|
|
29
|
+
/** A tag-shaped button. Prefer TagCheckbox for selectable filters. */
|
|
30
|
+
declare function TagButton({ variant, color, size, className, children, ...props }: TagButtonProps): React.JSX.Element;
|
|
31
|
+
/** Category navigation, including through LinkProvider. Never underlined. */
|
|
32
|
+
declare function TagLink({ variant, color, size, className, children, ...props }: TagLinkProps): React.JSX.Element;
|
|
33
|
+
type TagCheckboxProps = Omit<TagAppearance, 'variant'> & Omit<Checkbox.Root.Props, 'className'> & {
|
|
34
|
+
className?: string;
|
|
35
|
+
};
|
|
36
|
+
/** Base UI owns selection, keyboard handling, form submission and disabled state. */
|
|
37
|
+
declare function TagCheckbox({ color, size, className, children, ...props }: TagCheckboxProps): React.JSX.Element;
|
|
38
|
+
type TagRemovableProps = TagProps & {
|
|
39
|
+
/** Accessible action name, for example "Remove Education filter". */
|
|
40
|
+
removeLabel: string;
|
|
41
|
+
onRemove: NonNullable<Button.Props['onClick']>;
|
|
42
|
+
disabled?: boolean;
|
|
43
|
+
};
|
|
44
|
+
/** The label stays static; only its separately named remove button is interactive. */
|
|
45
|
+
declare function TagRemovable({ variant, color, size, className, children, removeLabel, onRemove, disabled, ...props }: TagRemovableProps): React.JSX.Element;
|
|
46
|
+
|
|
47
|
+
export { Tag, TagButton, type TagButtonProps, TagCheckbox, type TagCheckboxProps, TagLink, type TagLinkProps, type TagProps, TagRemovable, type TagRemovableProps, tagVariants };
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import { Button } from '@base-ui/react/button';
|
|
4
|
+
import { Checkbox } from '@base-ui/react/checkbox';
|
|
5
|
+
import { cva } from 'class-variance-authority';
|
|
6
|
+
import { IconCheck } from '../icons/check.js';
|
|
7
|
+
import { IconClose } from '../icons/close.js';
|
|
8
|
+
import { IconRemove } from '../icons/remove.js';
|
|
9
|
+
import { labelColorVariants } from '../lib/label-colors.js';
|
|
10
|
+
import { cn } from '../lib/utils.js';
|
|
11
|
+
import { Link } from './link.js';
|
|
12
|
+
|
|
13
|
+
const tagCva = cva(
|
|
14
|
+
[
|
|
15
|
+
"relative isolate inline-flex max-w-full items-center justify-center gap-2 rounded-sm border text-start align-middle font-normal",
|
|
16
|
+
// A variable rather than a fixed size: this descendant rule outranks a
|
|
17
|
+
// class on the icon itself, so a nested control resizes by resetting it.
|
|
18
|
+
"[--tag-icon-size:--spacing(4)] [&_[data-slot=icon]]:inline-block [&_[data-slot=icon]]:size-(--tag-icon-size) [&_[data-slot=icon]]:shrink-0 [&_[data-slot=icon]]:align-middle",
|
|
19
|
+
"[--btn-hover-overlay:color-mix(in_oklab,var(--btn-bg)_10%,transparent)]",
|
|
20
|
+
"[--btn-active-overlay:color-mix(in_oklab,var(--btn-bg)_20%,transparent)]"
|
|
21
|
+
],
|
|
22
|
+
{
|
|
23
|
+
variants: {
|
|
24
|
+
variant: {
|
|
25
|
+
solid: "border-transparent bg-(--btn-fill) text-(--btn-text)",
|
|
26
|
+
soft: "border-transparent bg-(--btn-bg)/10 text-(--btn-bg) dark:bg-(--btn-bg)/20",
|
|
27
|
+
surface: "border-(--btn-bg)/50 bg-(--btn-bg)/5 text-(--btn-bg) dark:bg-(--btn-bg)/20",
|
|
28
|
+
outline: "border-(--btn-bg)/40 bg-transparent text-(--btn-bg)"
|
|
29
|
+
},
|
|
30
|
+
size: {
|
|
31
|
+
sm: "px-2 py-0.5 text-sm/5",
|
|
32
|
+
default: "px-3 py-1 text-base/6",
|
|
33
|
+
lg: "px-4 py-2 text-base/6"
|
|
34
|
+
},
|
|
35
|
+
interactive: {
|
|
36
|
+
true: [
|
|
37
|
+
// Actual layout space, so wrapping tags never have overlapping hit areas.
|
|
38
|
+
"min-h-12 min-w-12 cursor-pointer border-(--btn-bg) no-underline hover:no-underline focus:no-underline active:no-underline",
|
|
39
|
+
"motion-safe:transition-[color,background-color,border-color,opacity]",
|
|
40
|
+
"after:pointer-events-none after:absolute after:inset-0 after:-z-10 after:rounded-[inherit]",
|
|
41
|
+
"not-data-disabled:hover:after:bg-(--btn-hover-overlay) not-data-disabled:active:after:bg-(--btn-active-overlay)",
|
|
42
|
+
"focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--btn-bg)",
|
|
43
|
+
"data-disabled:cursor-not-allowed data-disabled:opacity-50",
|
|
44
|
+
"forced-colors:border-[ButtonText] forced-colors:focus-visible:outline-[Highlight]"
|
|
45
|
+
],
|
|
46
|
+
false: ""
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
compoundVariants: [{ interactive: true, variant: "solid", className: "border-transparent" }],
|
|
50
|
+
defaultVariants: { variant: "outline", size: "default", interactive: false }
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
function tagVariants({
|
|
54
|
+
color = "primary",
|
|
55
|
+
variant = "outline",
|
|
56
|
+
class: classValue,
|
|
57
|
+
className,
|
|
58
|
+
...props
|
|
59
|
+
} = {}) {
|
|
60
|
+
return cn(
|
|
61
|
+
tagCva({ ...props, variant }),
|
|
62
|
+
labelColorVariants(color, variant),
|
|
63
|
+
classValue,
|
|
64
|
+
className
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
function Tag({ variant = "outline", color, size, className, children, ...props }) {
|
|
68
|
+
return /* @__PURE__ */ jsx(
|
|
69
|
+
"span",
|
|
70
|
+
{
|
|
71
|
+
"data-slot": "tag",
|
|
72
|
+
...props,
|
|
73
|
+
"data-variant": variant,
|
|
74
|
+
className: tagVariants({ variant, color, size, className }),
|
|
75
|
+
children: /* @__PURE__ */ jsx("span", { className: "min-w-0 [overflow-wrap:anywhere]", children })
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
function TagButton({
|
|
80
|
+
variant = "outline",
|
|
81
|
+
color,
|
|
82
|
+
size,
|
|
83
|
+
className,
|
|
84
|
+
children,
|
|
85
|
+
...props
|
|
86
|
+
}) {
|
|
87
|
+
return /* @__PURE__ */ jsx(
|
|
88
|
+
Button,
|
|
89
|
+
{
|
|
90
|
+
"data-slot": "tag-button",
|
|
91
|
+
...props,
|
|
92
|
+
"data-variant": variant,
|
|
93
|
+
className: tagVariants({ variant, color, size, interactive: true, className }),
|
|
94
|
+
children: /* @__PURE__ */ jsx("span", { className: "min-w-0 [overflow-wrap:anywhere]", children })
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
function TagLink({
|
|
99
|
+
variant = "outline",
|
|
100
|
+
color,
|
|
101
|
+
size,
|
|
102
|
+
className,
|
|
103
|
+
children,
|
|
104
|
+
...props
|
|
105
|
+
}) {
|
|
106
|
+
return /* @__PURE__ */ jsx(
|
|
107
|
+
Link,
|
|
108
|
+
{
|
|
109
|
+
"data-slot": "tag-link",
|
|
110
|
+
...props,
|
|
111
|
+
variant: "unstyled",
|
|
112
|
+
"data-variant": variant,
|
|
113
|
+
className: tagVariants({ variant, color, size, interactive: true, className }),
|
|
114
|
+
children: /* @__PURE__ */ jsx("span", { className: "min-w-0 [overflow-wrap:anywhere]", children })
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
function TagCheckbox({ color, size, className, children, ...props }) {
|
|
119
|
+
return /* @__PURE__ */ jsxs(
|
|
120
|
+
Checkbox.Root,
|
|
121
|
+
{
|
|
122
|
+
"data-slot": "tag-checkbox",
|
|
123
|
+
...props,
|
|
124
|
+
"data-variant": "outline",
|
|
125
|
+
className: cn(
|
|
126
|
+
tagVariants({ color, size, interactive: true }),
|
|
127
|
+
// Selected labels sit on a tint, so use the same contrast adjustment as Button.
|
|
128
|
+
labelColorVariants(color, "surface"),
|
|
129
|
+
color === "white" || color === "secondary" ? "[--tag-check-mark:var(--btn-text)]" : "[--tag-check-mark:var(--surface-default)]",
|
|
130
|
+
"group/tag data-indeterminate:bg-(--btn-bg)/10 dark:data-indeterminate:bg-(--btn-bg)/20 data-checked:bg-(--btn-bg)/10 dark:data-checked:bg-(--btn-bg)/20",
|
|
131
|
+
"aria-invalid:border-(--danger-solid) aria-invalid:focus-visible:outline-(--danger-solid)",
|
|
132
|
+
className
|
|
133
|
+
),
|
|
134
|
+
children: [
|
|
135
|
+
/* @__PURE__ */ jsx(
|
|
136
|
+
"span",
|
|
137
|
+
{
|
|
138
|
+
"aria-hidden": true,
|
|
139
|
+
className: "flex size-4 shrink-0 items-center justify-center rounded-sm border border-current group-data-indeterminate/tag:bg-(--btn-bg) group-data-checked/tag:bg-(--btn-bg)",
|
|
140
|
+
children: /* @__PURE__ */ jsx(
|
|
141
|
+
Checkbox.Indicator,
|
|
142
|
+
{
|
|
143
|
+
className: "flex size-full items-center justify-center text-(--tag-check-mark) forced-colors:bg-[Highlight] forced-colors:text-[HighlightText]",
|
|
144
|
+
render: (indicatorProps, state) => /* @__PURE__ */ jsx("span", { ...indicatorProps, children: state.indeterminate ? /* @__PURE__ */ jsx(IconRemove, { className: "size-4" }) : /* @__PURE__ */ jsx(IconCheck, { className: "size-4" }) })
|
|
145
|
+
}
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
),
|
|
149
|
+
/* @__PURE__ */ jsx("span", { className: "min-w-0 [overflow-wrap:anywhere]", children })
|
|
150
|
+
]
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
function TagRemovable({
|
|
155
|
+
variant = "surface",
|
|
156
|
+
color,
|
|
157
|
+
size,
|
|
158
|
+
className,
|
|
159
|
+
children,
|
|
160
|
+
removeLabel,
|
|
161
|
+
onRemove,
|
|
162
|
+
disabled,
|
|
163
|
+
...props
|
|
164
|
+
}) {
|
|
165
|
+
return /* @__PURE__ */ jsxs(
|
|
166
|
+
"span",
|
|
167
|
+
{
|
|
168
|
+
"data-slot": "tag-removable",
|
|
169
|
+
...props,
|
|
170
|
+
"data-variant": variant,
|
|
171
|
+
"data-disabled": disabled ? "" : void 0,
|
|
172
|
+
className: cn(
|
|
173
|
+
tagVariants({ variant, color, size }),
|
|
174
|
+
"group/tag-removable min-h-12 py-0 pe-0",
|
|
175
|
+
className
|
|
176
|
+
),
|
|
177
|
+
children: [
|
|
178
|
+
/* @__PURE__ */ jsx("span", { className: "min-w-0 [overflow-wrap:anywhere]", children }),
|
|
179
|
+
/* @__PURE__ */ jsx(
|
|
180
|
+
Button,
|
|
181
|
+
{
|
|
182
|
+
"aria-label": removeLabel,
|
|
183
|
+
disabled,
|
|
184
|
+
onClick: onRemove,
|
|
185
|
+
className: "flex size-12 shrink-0 items-center justify-center rounded-sm [--tag-icon-size:--spacing(5)] not-data-disabled:hover:bg-(--btn-hover-overlay) focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--btn-bg) group-data-[variant=solid]/tag-removable:focus-visible:-outline-offset-2 group-data-[variant=solid]/tag-removable:focus-visible:outline-(--btn-text) not-data-disabled:active:bg-(--btn-active-overlay) forced-colors:focus-visible:outline-[Highlight] data-disabled:cursor-not-allowed data-disabled:opacity-50",
|
|
186
|
+
children: /* @__PURE__ */ jsx(IconClose, { "aria-hidden": true })
|
|
187
|
+
}
|
|
188
|
+
)
|
|
189
|
+
]
|
|
190
|
+
}
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export { Tag, TagButton, TagCheckbox, TagLink, TagRemovable, tagVariants };
|
|
195
|
+
//# sourceMappingURL=tag.js.map
|
|
196
|
+
//# sourceMappingURL=tag.js.map
|
|
@@ -0,0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ent":["'use client'\n\nimport { Button as ButtonPrimitive } from '@base-ui/react/button'\nimport { Checkbox as CheckboxPrimitive } from '@base-ui/react/checkbox'\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport type * as React from 'react'\n\nimport { IconCheck } from '../icons/check.js'\nimport { IconClose } from '../icons/close.js'\nimport { IconRemove } from '../icons/remove.js'\nimport { labelColorVariants, type LabelColor } from '../lib/label-colors.js'\nimport { cn } from '../lib/utils.js'\nimport { Link } from './link.js'\n\nconst tagCva = cva(\n [\n 'relative isolate inline-flex max-w-full items-center justify-center gap-2 rounded-sm border text-start align-middle font-normal',\n // A variable rather than a fixed size: this descendant rule outranks a\n // class on the icon itself, so a nested control resizes by resetting it.\n '[--tag-icon-size:--spacing(4)] [&_[data-slot=icon]]:inline-block [&_[data-slot=icon]]:size-(--tag-icon-size) [&_[data-slot=icon]]:shrink-0 [&_[data-slot=icon]]:align-middle',\n '[--btn-hover-overlay:color-mix(in_oklab,var(--btn-bg)_10%,transparent)]',\n '[--btn-active-overlay:color-mix(in_oklab,var(--btn-bg)_20%,transparent)]',\n ],\n {\n variants: {\n variant: {\n solid: 'border-transparent bg-(--btn-fill) text-(--btn-text)',\n soft: 'border-transparent bg-(--btn-bg)/10 text-(--btn-bg) dark:bg-(--btn-bg)/20',\n surface: 'border-(--btn-bg)/50 bg-(--btn-bg)/5 text-(--btn-bg) dark:bg-(--btn-bg)/20',\n outline: 'border-(--btn-bg)/40 bg-transparent text-(--btn-bg)',\n },\n size: {\n sm: 'px-2 py-0.5 text-sm/5',\n default: 'px-3 py-1 text-base/6',\n lg: 'px-4 py-2 text-base/6',\n },\n interactive: {\n true: [\n // Actual layout space, so wrapping tags never have overlapping hit areas.\n 'min-h-12 min-w-12 cursor-pointer border-(--btn-bg) no-underline hover:no-underline focus:no-underline active:no-underline',\n 'motion-safe:transition-[color,background-color,border-color,opacity]',\n 'after:pointer-events-none after:absolute after:inset-0 after:-z-10 after:rounded-[inherit]',\n 'not-data-disabled:hover:after:bg-(--btn-hover-overlay) not-data-disabled:active:after:bg-(--btn-active-overlay)',\n 'focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--btn-bg)',\n 'data-disabled:cursor-not-allowed data-disabled:opacity-50',\n 'forced-colors:border-[ButtonText] forced-colors:focus-visible:outline-[Highlight]',\n ],\n false: '',\n },\n },\n compoundVariants: [{ interactive: true, variant: 'solid', className: 'border-transparent' }],\n defaultVariants: { variant: 'outline', size: 'default', interactive: false },\n },\n)\n\ntype TagVariantProps = NonNullable<Parameters<typeof tagCva>[0]> & { color?: LabelColor | null }\n\nfunction tagVariants({\n color = 'primary',\n variant = 'outline',\n class: classValue,\n className,\n ...props\n}: TagVariantProps = {}) {\n return cn(\n tagCva({ ...props, variant }),\n labelColorVariants(color, variant),\n classValue,\n className,\n )\n}\n\ntype TagAppearance = Omit<VariantProps<typeof tagVariants>, 'interactive'>\ntype TagProps = TagAppearance &\n React.ComponentPropsWithoutRef<'span'> & {\n ref?: React.Ref<HTMLSpanElement>\n }\n\n/** A non-interactive category or topic. Use Badge for status and counts. */\nfunction Tag({ variant = 'outline', color, size, className, children, ...props }: TagProps) {\n return (\n <span\n data-slot='tag'\n {...props}\n data-variant={variant}\n className={tagVariants({ variant, color, size, className })}\n >\n <span className='min-w-0 [overflow-wrap:anywhere]'>{children}</span>\n </span>\n )\n}\n\ntype TagButtonProps = TagAppearance &\n Omit<ButtonPrimitive.Props, 'className'> & { className?: string }\ntype TagLinkProps = TagAppearance & Omit<React.ComponentProps<typeof Link>, 'variant' | 'color'>\n\n/** A tag-shaped button. Prefer TagCheckbox for selectable filters. */\nfunction TagButton({\n variant = 'outline',\n color,\n size,\n className,\n children,\n ...props\n}: TagButtonProps) {\n return (\n <ButtonPrimitive\n data-slot='tag-button'\n {...props}\n data-variant={variant}\n className={tagVariants({ variant, color, size, interactive: true, className })}\n >\n <span className='min-w-0 [overflow-wrap:anywhere]'>{children}</span>\n </ButtonPrimitive>\n )\n}\n\n/** Category navigation, including through LinkProvider. Never underlined. */\nfunction TagLink({\n variant = 'outline',\n color,\n size,\n className,\n children,\n ...props\n}: TagLinkProps) {\n return (\n <Link\n data-slot='tag-link'\n {...props}\n variant='unstyled'\n data-variant={variant}\n className={tagVariants({ variant, color, size, interactive: true, className })}\n >\n <span className='min-w-0 [overflow-wrap:anywhere]'>{children}</span>\n </Link>\n )\n}\n\ntype TagCheckboxProps = Omit<TagAppearance, 'variant'> &\n Omit<CheckboxPrimitive.Root.Props, 'className'> & { className?: string }\n\n/** Base UI owns selection, keyboard handling, form submission and disabled state. */\nfunction TagCheckbox({ color, size, className, children, ...props }: TagCheckboxProps) {\n return (\n <CheckboxPrimitive.Root\n data-slot='tag-checkbox'\n {...props}\n data-variant='outline'\n className={cn(\n tagVariants({ color, size, interactive: true }),\n // Selected labels sit on a tint, so use the same contrast adjustment as Button.\n labelColorVariants(color, 'surface'),\n color === 'white' || color === 'secondary'\n ? '[--tag-check-mark:var(--btn-text)]'\n : '[--tag-check-mark:var(--surface-default)]',\n 'group/tag data-indeterminate:bg-(--btn-bg)/10 dark:data-indeterminate:bg-(--btn-bg)/20 data-checked:bg-(--btn-bg)/10 dark:data-checked:bg-(--btn-bg)/20',\n 'aria-invalid:border-(--danger-solid) aria-invalid:focus-visible:outline-(--danger-solid)',\n className,\n )}\n >\n <span\n aria-hidden\n className='flex size-4 shrink-0 items-center justify-center rounded-sm border border-current group-data-indeterminate/tag:bg-(--btn-bg) group-data-checked/tag:bg-(--btn-bg)'\n >\n <CheckboxPrimitive.Indicator\n // Centre the glyph independently of the label's inherited line height.\n className='flex size-full items-center justify-center text-(--tag-check-mark) forced-colors:bg-[Highlight] forced-colors:text-[HighlightText]'\n render={(indicatorProps, state) => (\n <span {...indicatorProps}>\n {state.indeterminate ? (\n <IconRemove className='size-4' />\n ) : (\n <IconCheck className='size-4' />\n )}\n </span>\n )}\n />\n </span>\n <span className='min-w-0 [overflow-wrap:anywhere]'>{children}</span>\n </CheckboxPrimitive.Root>\n )\n}\n\ntype TagRemovableProps = TagProps & {\n /** Accessible action name, for example \"Remove Education filter\". */\n removeLabel: string\n onRemove: NonNullable<ButtonPrimitive.Props['onClick']>\n disabled?: boolean\n}\n\n/** The label stays static; only its separately named remove button is interactive. */\nfunction TagRemovable({\n variant = 'surface',\n color,\n size,\n className,\n children,\n removeLabel,\n onRemove,\n disabled,\n ...props\n}: TagRemovableProps) {\n return (\n <span\n data-slot='tag-removable'\n {...props}\n data-variant={variant}\n data-disabled={disabled ? '' : undefined}\n className={cn(\n tagVariants({ variant, color, size }),\n 'group/tag-removable min-h-12 py-0 pe-0',\n className,\n )}\n >\n <span className='min-w-0 [overflow-wrap:anywhere]'>{children}</span>\n <ButtonPrimitive\n aria-label={removeLabel}\n disabled={disabled}\n onClick={onRemove}\n className='flex size-12 shrink-0 items-center justify-center rounded-sm [--tag-icon-size:--spacing(5)] not-data-disabled:hover:bg-(--btn-hover-overlay) focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--btn-bg) group-data-[variant=solid]/tag-removable:focus-visible:-outline-offset-2 group-data-[variant=solid]/tag-removable:focus-visible:outline-(--btn-text) not-data-disabled:active:bg-(--btn-active-overlay) forced-colors:focus-visible:outline-[Highlight] data-disabled:cursor-not-allowed data-disabled:opacity-50'\n >\n <IconClose aria-hidden />\n </ButtonPrimitive>\n </span>\n )\n}\n\nexport { Tag, TagButton, TagCheckbox, TagLink, TagRemovable, tagVariants }\nexport type { TagButtonProps, TagCheckboxProps, TagLinkProps, TagProps, TagRemovableProps }\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Accordion
|
|
|
2
2
|
export { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogMedia, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger, AlertDialogVariant, alertDialogContentVariants } from './components/alert-dialog.js';
|
|
3
3
|
export { AspectRatio } from './components/aspect-ratio.js';
|
|
4
4
|
export { Avatar, AvatarBadge, AvatarFallback, AvatarGroup, AvatarGroupCount, AvatarImage } from './components/avatar.js';
|
|
5
|
-
export { Badge,
|
|
5
|
+
export { Badge, BadgeProps, badgeVariants } from './components/badge.js';
|
|
6
6
|
export { Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator } from './components/breadcrumb.js';
|
|
7
7
|
export { ButtonGroup, ButtonGroupProps, ButtonGroupSeparator, ButtonGroupText, ButtonGroupVariant, buttonGroupVariants } from './components/button-group.js';
|
|
8
8
|
export { Button, ButtonLink, ButtonLinkProps, ButtonProps, IconSlot, TouchTarget, buttonColorVariants, buttonVariants } from './components/button.js';
|
|
@@ -60,6 +60,7 @@ export { Switch } from './components/switch.js';
|
|
|
60
60
|
export { TabNav, TabNavLink, TabNavLinkProps, TabNavProps, tabNavLinkVariants, tabNavListVariants } from './components/tab-nav.js';
|
|
61
61
|
export { Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow } from './components/table.js';
|
|
62
62
|
export { Tabs, TabsContent, TabsList, TabsTrigger, tabsListVariants, tabsTriggerVariants } from './components/tabs.js';
|
|
63
|
+
export { Tag, TagButton, TagButtonProps, TagCheckbox, TagCheckboxProps, TagLink, TagLinkProps, TagProps, TagRemovable, TagRemovableProps, tagVariants } from './components/tag.js';
|
|
63
64
|
export { Textarea, TextareaProps } from './components/textarea.js';
|
|
64
65
|
export { ThemeSwitcher, ThemeSwitcherProps, ThemeSwitcherTheme } from './components/theme-switcher.js';
|
|
65
66
|
export { ToggleGroup, ToggleGroupItem } from './components/toggle-group.js';
|
|
@@ -73,9 +74,10 @@ import '@base-ui/react/accordion';
|
|
|
73
74
|
import 'class-variance-authority/types';
|
|
74
75
|
import '@base-ui/react/alert-dialog';
|
|
75
76
|
import '@base-ui/react/avatar';
|
|
76
|
-
import '@base-ui/react/button';
|
|
77
77
|
import 'class-variance-authority';
|
|
78
|
+
import './lib/label-colors.js';
|
|
78
79
|
import '@base-ui/react/use-render';
|
|
80
|
+
import '@base-ui/react/button';
|
|
79
81
|
import 'embla-carousel-react';
|
|
80
82
|
import '@base-ui/react/checkbox';
|
|
81
83
|
import '@base-ui/react/collapsible';
|
package/dist/index.js
CHANGED
|
@@ -60,6 +60,7 @@ export * from './components/switch.js';
|
|
|
60
60
|
export * from './components/tab-nav.js';
|
|
61
61
|
export * from './components/table.js';
|
|
62
62
|
export * from './components/tabs.js';
|
|
63
|
+
export * from './components/tag.js';
|
|
63
64
|
export * from './components/textarea.js';
|
|
64
65
|
export * from './components/theme-switcher.js';
|
|
65
66
|
export * from './components/toggle-group.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { VariantProps } from 'class-variance-authority';
|
|
2
|
+
import { buttonColorVariants } from '../components/button.js';
|
|
3
|
+
import 'class-variance-authority/types';
|
|
4
|
+
import '@base-ui/react/button';
|
|
5
|
+
import 'react';
|
|
6
|
+
import '../components/link.js';
|
|
7
|
+
|
|
8
|
+
type LabelColor = NonNullable<VariantProps<typeof buttonColorVariants>['color']>;
|
|
9
|
+
declare function labelColorVariants(color?: LabelColor | 'light' | null, variant?: 'solid' | 'soft' | 'surface' | 'outline' | null): string;
|
|
10
|
+
|
|
11
|
+
export { type LabelColor, labelColorVariants };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { buttonColorVariants } from '../components/button.js';
|
|
2
|
+
|
|
3
|
+
function labelColorVariants(color = "primary", variant = "soft") {
|
|
4
|
+
const resolvedColor = color === "light" ? variant === "solid" ? "white" : "grey" : color;
|
|
5
|
+
return buttonColorVariants({ color: resolvedColor, variant });
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export { labelColorVariants };
|
|
9
|
+
//# sourceMappingURL=label-colors.js.map
|
|
10
|
+
//# sourceMappingURL=label-colors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/label-colors.ts"],"names":[],"mappings":";;AAMO,SAAS,kBAAA,CACd,KAAA,GAAqC,SAAA,EACrC,OAAA,GAA2D,MAAA,EAC3D;AAEA,EAAA,MAAM,gBAAgB,KAAA,KAAU,OAAA,GAAW,OAAA,KAAY,OAAA,GAAU,UAAU,MAAA,GAAU,KAAA;AACrF,EAAA,OAAO,mBAAA,CAAoB,EAAE,KAAA,EAAO,aAAA,EAAe,SAAS,CAAA;AAC9D","file":"label-colors.js","sourcesContent":["import type { VariantProps } from 'class-variance-authority'\n\nimport { buttonColorVariants } from '../components/button.js'\n\nexport type LabelColor = NonNullable<VariantProps<typeof buttonColorVariants>['color']>\n\nexport function labelColorVariants(\n color: LabelColor | 'light' | null = 'primary',\n variant: 'solid' | 'soft' | 'surface' | 'outline' | null = 'soft',\n) {\n // Keep the light solid fill, but use neutral ink for labels on the page surface.\n const resolvedColor = color === 'light' ? (variant === 'solid' ? 'white' : 'grey') : color\n return buttonColorVariants({ color: resolvedColor, variant })\n}\n"]}
|