@epilot/spark-ui 0.16.1 → 0.18.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/dist/components/alert-dialog.cjs +2 -0
- package/dist/components/alert-dialog.cjs.map +1 -1
- package/dist/components/alert-dialog.js +2 -0
- package/dist/components/alert-dialog.js.map +1 -1
- package/dist/components/attachment.d.cts +1 -1
- package/dist/components/attachment.d.ts +1 -1
- package/dist/components/autocomplete.cjs +160 -0
- package/dist/components/autocomplete.cjs.map +1 -0
- package/dist/components/autocomplete.d.cts +73 -0
- package/dist/components/autocomplete.d.ts +73 -0
- package/dist/components/autocomplete.js +142 -0
- package/dist/components/autocomplete.js.map +1 -0
- package/dist/components/bubble.d.cts +1 -1
- package/dist/components/bubble.d.ts +1 -1
- package/dist/components/button.d.cts +1 -1
- package/dist/components/button.d.ts +1 -1
- package/dist/components/callout.d.cts +1 -1
- package/dist/components/callout.d.ts +1 -1
- package/dist/components/info-block.d.cts +1 -1
- package/dist/components/info-block.d.ts +1 -1
- package/dist/components/input-date.cjs +141 -0
- package/dist/components/input-date.cjs.map +1 -0
- package/dist/components/input-date.d.cts +22 -0
- package/dist/components/input-date.d.ts +22 -0
- package/dist/components/input-date.js +138 -0
- package/dist/components/input-date.js.map +1 -0
- package/dist/components/marker.d.cts +1 -1
- package/dist/components/marker.d.ts +1 -1
- package/dist/components/page-header.d.cts +1 -1
- package/dist/components/page-header.d.ts +1 -1
- package/dist/components/pill.cjs +2 -2
- package/dist/components/pill.cjs.map +1 -1
- package/dist/components/pill.js +2 -2
- package/dist/components/pill.js.map +1 -1
- package/dist/components/power-network.cjs +1 -1
- package/dist/components/power-network.js +1 -1
- package/dist/styles/spark-default.css +4 -0
- package/package.json +3 -2
- package/dist/utils/date-mask.cjs +0 -45
- package/dist/utils/date-mask.cjs.map +0 -1
- package/dist/utils/date-mask.d.cts +0 -17
- package/dist/utils/date-mask.d.ts +0 -17
- package/dist/utils/date-mask.js +0 -41
- package/dist/utils/date-mask.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autocomplete.js","names":["AutocompletePrimitive","React"],"sources":["../../src/components/autocomplete.tsx"],"sourcesContent":["'use client'\n\nimport { Autocomplete as AutocompletePrimitive } from '@base-ui/react/autocomplete'\nimport { Close, KeyboardArrowDown } from '@epilot/spark-icons'\nimport * as React from 'react'\nimport { cn } from '../utils/cn'\nimport { useFieldControl } from './field'\nimport { Input, type InputVariant } from './input'\nimport { InputGroup } from './input-group'\n\nconst Autocomplete = AutocompletePrimitive.Root\nconst AutocompleteCollection = AutocompletePrimitive.Collection\nconst useAutocompleteFilter = AutocompletePrimitive.useFilter\nconst useAutocompleteFilteredItems = AutocompletePrimitive.useFilteredItems\n\nconst AutocompleteInputGroupContext = React.createContext(false)\n\nconst OUTSET_FOCUS_RING =\n 'focus-visible:ring-2 focus-visible:ring-(--color-focus-root)! focus-visible:ring-offset-2 focus-visible:outline-hidden'\n\nfunction AutocompleteInput({\n variant,\n id: idProp,\n className,\n 'aria-describedby': ariaDescribedByProp,\n ...props\n}: React.ComponentProps<typeof AutocompletePrimitive.Input> & {\n variant?: InputVariant\n}) {\n const inGroup = React.useContext(AutocompleteInputGroupContext)\n const resolvedVariant = variant ?? (inGroup ? 'none' : undefined)\n const { field, id, ariaDescribedBy, ariaInvalid } = useFieldControl({\n id: typeof idProp === 'string' ? idProp : undefined,\n ariaDescribedBy:\n typeof ariaDescribedByProp === 'string' ? ariaDescribedByProp : undefined,\n variant: resolvedVariant !== 'none' ? resolvedVariant : undefined,\n })\n const outsetBox = !inGroup && field?.labelPosition === 'outset'\n return (\n <AutocompletePrimitive.Input\n render={<Input id={id} variant={resolvedVariant} />}\n id={id}\n aria-invalid={ariaInvalid}\n className={cn(\n outsetBox && OUTSET_FOCUS_RING,\n inGroup && 'flex-1',\n className,\n )}\n {...props}\n aria-describedby={ariaDescribedBy}\n />\n )\n}\n\nfunction AutocompleteInputGroup(\n props: React.ComponentProps<typeof AutocompletePrimitive.InputGroup>,\n) {\n return (\n <AutocompleteInputGroupContext.Provider value={true}>\n <AutocompletePrimitive.InputGroup\n data-slot=\"autocomplete-input-group\"\n render={<InputGroup />}\n {...props}\n />\n </AutocompleteInputGroupContext.Provider>\n )\n}\n\nconst ICON_BUTTON =\n \"relative inline-flex size-6 shrink-0 items-center justify-center rounded-sm p-0 text-gray-light outline-hidden transition-colors hover:text-gray focus-visible:ring-2 focus-visible:ring-(--color-focus-root)! focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50 motion-reduce:transition-none [&_svg]:pointer-events-none [&_svg]:shrink-0 before:absolute before:top-1/2 before:left-1/2 before:size-10 before:-translate-x-1/2 before:-translate-y-1/2 before:content-['']\"\n\nfunction AutocompleteClear({\n className,\n children,\n ...props\n}: React.ComponentProps<typeof AutocompletePrimitive.Clear>) {\n return (\n <AutocompletePrimitive.Clear\n data-slot=\"autocomplete-clear\"\n className={cn(ICON_BUTTON, className)}\n {...props}\n >\n {children ?? <Close aria-hidden className=\"[--spark-icon-size:14px]\" />}\n </AutocompletePrimitive.Clear>\n )\n}\n\nfunction AutocompleteTrigger({\n className,\n children,\n ...props\n}: React.ComponentProps<typeof AutocompletePrimitive.Trigger>) {\n return (\n <AutocompletePrimitive.Trigger\n data-slot=\"autocomplete-trigger\"\n className={cn(\n ICON_BUTTON,\n '[&_svg]:transition-transform data-popup-open:[&_svg]:rotate-180 motion-reduce:[&_svg]:transition-none',\n className,\n )}\n {...props}\n >\n {children ?? (\n <KeyboardArrowDown aria-hidden className=\"[--spark-icon-size:14px]\" />\n )}\n </AutocompletePrimitive.Trigger>\n )\n}\n\ntype AutocompleteContentProps = React.ComponentProps<\n typeof AutocompletePrimitive.Popup\n> &\n Pick<\n AutocompletePrimitive.Positioner.Props,\n 'align' | 'alignOffset' | 'side' | 'sideOffset'\n > &\n Pick<AutocompletePrimitive.Portal.Props, 'container'>\n\nfunction AutocompleteContent({\n className,\n children,\n align = 'start',\n alignOffset,\n side,\n sideOffset = 4,\n container,\n ...props\n}: AutocompleteContentProps) {\n return (\n <AutocompletePrimitive.Portal container={container}>\n <AutocompletePrimitive.Positioner\n align={align}\n alignOffset={alignOffset}\n side={side}\n sideOffset={sideOffset}\n >\n <AutocompletePrimitive.Popup\n data-slot=\"autocomplete-content\"\n className={cn(\n 'relative isolate z-50 max-h-(--available-height) w-(--anchor-width) max-w-(--available-width) origin-(--transform-origin) overflow-x-hidden overflow-y-auto overscroll-contain rounded-lg border border-gray-a1 bg-gray-1 p-1 text-gray-a12 shadow-lg',\n 'transition-[opacity,scale,translate] duration-100 data-ending-style:scale-95 data-ending-style:opacity-0 data-starting-style:scale-95 data-starting-style:opacity-0 motion-reduce:transition-none',\n 'data-[side=bottom]:data-starting-style:-translate-y-2 data-[side=left]:data-starting-style:translate-x-2 data-[side=right]:data-starting-style:-translate-x-2 data-[side=top]:data-starting-style:translate-y-2',\n className,\n )}\n {...props}\n >\n {children}\n </AutocompletePrimitive.Popup>\n </AutocompletePrimitive.Positioner>\n </AutocompletePrimitive.Portal>\n )\n}\n\nfunction AutocompleteList({\n className,\n ...props\n}: React.ComponentProps<typeof AutocompletePrimitive.List>) {\n return (\n <AutocompletePrimitive.List\n data-slot=\"autocomplete-list\"\n className={cn('outline-hidden data-empty:p-0', className)}\n {...props}\n />\n )\n}\n\nfunction AutocompleteItem({\n className,\n ...props\n}: React.ComponentProps<typeof AutocompletePrimitive.Item>) {\n return (\n <AutocompletePrimitive.Item\n data-slot=\"autocomplete-item\"\n className={cn(\n 'relative flex w-full cursor-default items-center gap-1.5 rounded-sm px-1.5 py-1.5 text-sm text-gray outline-hidden transition-colors select-none data-disabled:pointer-events-none data-disabled:opacity-50 data-highlighted:bg-gray-a3 motion-reduce:transition-none',\n className,\n )}\n {...props}\n />\n )\n}\n\nfunction AutocompleteEmpty({\n className,\n ...props\n}: React.ComponentProps<typeof AutocompletePrimitive.Empty>) {\n return (\n <AutocompletePrimitive.Empty\n data-slot=\"autocomplete-empty\"\n className={cn(\n 'px-1.5 py-1.5 text-sm text-gray-light empty:p-0',\n className,\n )}\n {...props}\n />\n )\n}\n\nfunction AutocompleteStatus({\n className,\n ...props\n}: React.ComponentProps<typeof AutocompletePrimitive.Status>) {\n return (\n <AutocompletePrimitive.Status\n data-slot=\"autocomplete-status\"\n className={cn(\n 'px-1.5 py-1.5 text-sm text-gray-light empty:p-0',\n className,\n )}\n {...props}\n />\n )\n}\n\nfunction AutocompleteGroup({\n className,\n ...props\n}: React.ComponentProps<typeof AutocompletePrimitive.Group>) {\n return (\n <AutocompletePrimitive.Group\n data-slot=\"autocomplete-group\"\n className={cn('scroll-my-1', className)}\n {...props}\n />\n )\n}\n\nfunction AutocompleteGroupLabel({\n className,\n ...props\n}: React.ComponentProps<typeof AutocompletePrimitive.GroupLabel>) {\n return (\n <AutocompletePrimitive.GroupLabel\n data-slot=\"autocomplete-group-label\"\n className={cn('px-1.5 py-1 text-xs text-gray-light', className)}\n {...props}\n />\n )\n}\n\nfunction AutocompleteSeparator({\n className,\n ...props\n}: React.ComponentProps<'div'>) {\n return (\n <div\n aria-hidden=\"true\"\n data-slot=\"autocomplete-separator\"\n className={cn(\n 'pointer-events-none -mx-1 my-1 h-px bg-gray-a3',\n className,\n )}\n {...props}\n />\n )\n}\n\nexport {\n Autocomplete,\n AutocompleteClear,\n AutocompleteCollection,\n AutocompleteContent,\n AutocompleteEmpty,\n AutocompleteGroup,\n AutocompleteGroupLabel,\n AutocompleteInput,\n AutocompleteInputGroup,\n AutocompleteItem,\n AutocompleteList,\n AutocompleteSeparator,\n AutocompleteStatus,\n AutocompleteTrigger,\n useAutocompleteFilter,\n useAutocompleteFilteredItems,\n}\n"],"mappings":";;;;;;;;;;;AAUA,MAAM,eAAeA,eAAsB;AAC3C,MAAM,yBAAyBA,eAAsB;AACrD,MAAM,wBAAwBA,eAAsB;AACpD,MAAM,+BAA+BA,eAAsB;AAE3D,MAAM,gCAAgCC,Q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EA,SAAS,sBAAsB,EAC7B,WACA,GAAG,SAC2B;CAC9B,OACE,oBAAC,OAAD;EACE,eAAY;EACZ,aAAU;EACV,WAAW,GACT,kDACA,SACF;EACA,GAAI;CACL,CAAA;AAEL"}
|
|
@@ -10,7 +10,7 @@ declare function BubbleGroup({
|
|
|
10
10
|
...props
|
|
11
11
|
}: React$1.ComponentProps<'div'>): import("react/jsx-runtime").JSX.Element;
|
|
12
12
|
declare const bubbleVariants: (props?: ({
|
|
13
|
-
variant?: "
|
|
13
|
+
variant?: "ghost" | "outline" | "default" | "secondary" | "destructive" | "muted" | "tinted" | null | undefined;
|
|
14
14
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
15
15
|
declare function Bubble({
|
|
16
16
|
variant,
|
|
@@ -10,7 +10,7 @@ declare function BubbleGroup({
|
|
|
10
10
|
...props
|
|
11
11
|
}: React$1.ComponentProps<'div'>): import("react/jsx-runtime").JSX.Element;
|
|
12
12
|
declare const bubbleVariants: (props?: ({
|
|
13
|
-
variant?: "
|
|
13
|
+
variant?: "ghost" | "outline" | "default" | "secondary" | "destructive" | "muted" | "tinted" | null | undefined;
|
|
14
14
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
15
15
|
declare function Bubble({
|
|
16
16
|
variant,
|
|
@@ -9,7 +9,7 @@ import { VariantProps } from "class-variance-authority";
|
|
|
9
9
|
declare const buttonVariants: (props?: ({
|
|
10
10
|
variant?: "primary" | "secondary" | "tertiary" | "bare" | "destructive" | null | undefined;
|
|
11
11
|
color?: "neutral" | "accent" | "danger" | null | undefined;
|
|
12
|
-
size?: "small" | "default" | "
|
|
12
|
+
size?: "small" | "default" | "icon" | "medium" | "icon-small" | "icon-medium" | null | undefined;
|
|
13
13
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
14
14
|
type SparkButtonColor = 'accent' | 'neutral' | 'danger';
|
|
15
15
|
interface ButtonProps extends Omit<React$1.ComponentProps<typeof Button$1>, 'ref'>, Omit<VariantProps<typeof buttonVariants>, 'variant' | 'color'> {
|
|
@@ -9,7 +9,7 @@ import { VariantProps } from "class-variance-authority";
|
|
|
9
9
|
declare const buttonVariants: (props?: ({
|
|
10
10
|
variant?: "primary" | "secondary" | "tertiary" | "bare" | "destructive" | null | undefined;
|
|
11
11
|
color?: "neutral" | "accent" | "danger" | null | undefined;
|
|
12
|
-
size?: "small" | "default" | "
|
|
12
|
+
size?: "small" | "default" | "icon" | "medium" | "icon-small" | "icon-medium" | null | undefined;
|
|
13
13
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
14
14
|
type SparkButtonColor = 'accent' | 'neutral' | 'danger';
|
|
15
15
|
interface ButtonProps extends Omit<React$1.ComponentProps<typeof Button$1>, 'ref'>, Omit<VariantProps<typeof buttonVariants>, 'variant' | 'color'> {
|
|
@@ -8,7 +8,7 @@ import { SparkIcon } from "@epilot/spark-icons";
|
|
|
8
8
|
//#region src/components/callout.d.ts
|
|
9
9
|
type CalloutVariant = 'error' | 'info' | 'neutral' | 'success' | 'warning';
|
|
10
10
|
declare const calloutVariants: (props?: ({
|
|
11
|
-
variant?: "
|
|
11
|
+
variant?: "neutral" | "success" | "warning" | "error" | "info" | null | undefined;
|
|
12
12
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
13
13
|
interface CalloutProps extends React$1.HTMLAttributes<HTMLDivElement>, VariantProps<typeof calloutVariants> {
|
|
14
14
|
/** Overrides the variant's default icon; the variant's color is kept. `false` renders no icon. */
|
|
@@ -8,7 +8,7 @@ import { VariantProps } from "class-variance-authority";
|
|
|
8
8
|
//#region src/components/callout.d.ts
|
|
9
9
|
type CalloutVariant = 'error' | 'info' | 'neutral' | 'success' | 'warning';
|
|
10
10
|
declare const calloutVariants: (props?: ({
|
|
11
|
-
variant?: "
|
|
11
|
+
variant?: "neutral" | "success" | "warning" | "error" | "info" | null | undefined;
|
|
12
12
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
13
13
|
interface CalloutProps extends React$1.HTMLAttributes<HTMLDivElement>, VariantProps<typeof calloutVariants> {
|
|
14
14
|
/** Overrides the variant's default icon; the variant's color is kept. `false` renders no icon. */
|
|
@@ -5,7 +5,7 @@ import { VariantProps } from "class-variance-authority";
|
|
|
5
5
|
|
|
6
6
|
//#region src/components/info-block.d.ts
|
|
7
7
|
declare const InfoBlock: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLDivElement> & VariantProps<(props?: ({
|
|
8
|
-
variant?: "
|
|
8
|
+
variant?: "default" | "bare" | null | undefined;
|
|
9
9
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string> & React$1.RefAttributes<HTMLDivElement>>;
|
|
10
10
|
declare const InfoBlockIcon: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLDivElement> & React$1.RefAttributes<HTMLDivElement>>;
|
|
11
11
|
declare const InfoBlockContent: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLDivElement> & React$1.RefAttributes<HTMLDivElement>>;
|
|
@@ -5,7 +5,7 @@ import { VariantProps } from "class-variance-authority";
|
|
|
5
5
|
|
|
6
6
|
//#region src/components/info-block.d.ts
|
|
7
7
|
declare const InfoBlock: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLDivElement> & VariantProps<(props?: ({
|
|
8
|
-
variant?: "
|
|
8
|
+
variant?: "default" | "bare" | null | undefined;
|
|
9
9
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string> & React$1.RefAttributes<HTMLDivElement>>;
|
|
10
10
|
declare const InfoBlockIcon: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLDivElement> & React$1.RefAttributes<HTMLDivElement>>;
|
|
11
11
|
declare const InfoBlockContent: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLDivElement> & React$1.RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use client";
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
+
const require_chunk = require("../chunk-DY84GLCh.cjs");
|
|
5
|
+
const require_components_button = require("./button.cjs");
|
|
6
|
+
const require_components_input_group = require("./input-group.cjs");
|
|
7
|
+
const require_components_calendar = require("./calendar.cjs");
|
|
8
|
+
const require_components_popover = require("./popover.cjs");
|
|
9
|
+
let react = require("react");
|
|
10
|
+
react = require_chunk.__toESM(react);
|
|
11
|
+
let _epilot_spark_icons = require("@epilot/spark-icons");
|
|
12
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
13
|
+
let ictus = require("ictus");
|
|
14
|
+
let cnfast = require("cnfast");
|
|
15
|
+
//#region src/components/input-date.tsx
|
|
16
|
+
function useControllableState({ defaultProp, onChange, prop }) {
|
|
17
|
+
const [uncontrolled, setUncontrolled] = react.useState(defaultProp);
|
|
18
|
+
const isControlled = prop !== void 0;
|
|
19
|
+
return [isControlled ? prop : uncontrolled, react.useCallback((next) => {
|
|
20
|
+
if (!isControlled) setUncontrolled(next);
|
|
21
|
+
onChange?.(next);
|
|
22
|
+
}, [isControlled, onChange])];
|
|
23
|
+
}
|
|
24
|
+
const InputDate = react.forwardRef(function InputDate({ calendarLabel, calendarProps, className, defaultOpen = false, defaultValue = "", disabled, id, onDateChange, onKeyDown, onOpenChange, onValueChange, open: openProp, placeholder, readOnly, separator = ".", value: valueProp, ...props }, ref) {
|
|
25
|
+
const inputRef = react.useRef(null);
|
|
26
|
+
const [text, setText] = useControllableState({
|
|
27
|
+
defaultProp: defaultValue,
|
|
28
|
+
onChange: onValueChange,
|
|
29
|
+
prop: valueProp
|
|
30
|
+
});
|
|
31
|
+
const [open, setOpenState] = useControllableState({
|
|
32
|
+
defaultProp: defaultOpen,
|
|
33
|
+
onChange: onOpenChange,
|
|
34
|
+
prop: openProp
|
|
35
|
+
});
|
|
36
|
+
const selected = (0, ictus.parseDate)(text);
|
|
37
|
+
const [month, setMonth] = react.useState(() => selected ?? calendarProps?.month);
|
|
38
|
+
const setOpen = react.useCallback((next) => {
|
|
39
|
+
if (next && calendarProps?.month === void 0) setMonth((0, ictus.parseDate)(text) ?? /* @__PURE__ */ new Date());
|
|
40
|
+
setOpenState(next);
|
|
41
|
+
}, [
|
|
42
|
+
calendarProps?.month,
|
|
43
|
+
setOpenState,
|
|
44
|
+
text
|
|
45
|
+
]);
|
|
46
|
+
const commit = react.useCallback((next) => {
|
|
47
|
+
if (next === text) return;
|
|
48
|
+
setText(next);
|
|
49
|
+
onDateChange?.((0, ictus.parseDate)(next));
|
|
50
|
+
}, [
|
|
51
|
+
onDateChange,
|
|
52
|
+
setText,
|
|
53
|
+
text
|
|
54
|
+
]);
|
|
55
|
+
const setInputRef = react.useCallback((node) => {
|
|
56
|
+
inputRef.current = node;
|
|
57
|
+
if (typeof ref === "function") ref(node);
|
|
58
|
+
else if (ref) ref.current = node;
|
|
59
|
+
}, [ref]);
|
|
60
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_components_popover.Popover, {
|
|
61
|
+
onOpenChange: setOpen,
|
|
62
|
+
open,
|
|
63
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_components_popover.PopoverAnchor, {
|
|
64
|
+
render: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_input_group.InputGroup, { className }),
|
|
65
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_input_group.InputGroupInput, {
|
|
66
|
+
autoComplete: "off",
|
|
67
|
+
...props,
|
|
68
|
+
className: (0, cnfast.cn)(readOnly && "cursor-pointer"),
|
|
69
|
+
disabled,
|
|
70
|
+
id,
|
|
71
|
+
inputMode: readOnly ? void 0 : "numeric",
|
|
72
|
+
onChange: () => {},
|
|
73
|
+
onClick: readOnly && !disabled ? (event) => {
|
|
74
|
+
props.onClick?.(event);
|
|
75
|
+
if (!event.defaultPrevented) setOpen(true);
|
|
76
|
+
} : props.onClick,
|
|
77
|
+
onKeyDown: (event) => {
|
|
78
|
+
onKeyDown?.(event);
|
|
79
|
+
if (event.defaultPrevented) return;
|
|
80
|
+
if (event.key === "ArrowDown") {
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
setOpen(true);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (readOnly || !(0, ictus.isDateMaskKey)(event.key)) return;
|
|
86
|
+
event.preventDefault();
|
|
87
|
+
const next = (0, ictus.apply)({
|
|
88
|
+
caret: event.currentTarget.selectionStart ?? 0,
|
|
89
|
+
key: event.key,
|
|
90
|
+
selectionEnd: event.currentTarget.selectionEnd ?? void 0,
|
|
91
|
+
separator,
|
|
92
|
+
value: event.currentTarget.value
|
|
93
|
+
});
|
|
94
|
+
commit(next.value);
|
|
95
|
+
const caret = next.caret;
|
|
96
|
+
const input = inputRef.current;
|
|
97
|
+
requestAnimationFrame(() => {
|
|
98
|
+
input?.setSelectionRange(caret, caret);
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
placeholder: placeholder ?? `DD${separator}MM${separator}YYYY`,
|
|
102
|
+
readOnly,
|
|
103
|
+
ref: setInputRef,
|
|
104
|
+
spellCheck: false,
|
|
105
|
+
value: text
|
|
106
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_input_group.InputGroupAddon, {
|
|
107
|
+
align: "inline-end",
|
|
108
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_popover.PopoverTrigger, { render: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_button.Button, {
|
|
109
|
+
"aria-label": calendarLabel,
|
|
110
|
+
color: "neutral",
|
|
111
|
+
disabled,
|
|
112
|
+
size: "icon-small",
|
|
113
|
+
styleVariant: "ghost",
|
|
114
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_epilot_spark_icons.CalendarMonth, {})
|
|
115
|
+
}) })
|
|
116
|
+
})]
|
|
117
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_popover.PopoverContent, {
|
|
118
|
+
align: "start",
|
|
119
|
+
"aria-label": calendarLabel,
|
|
120
|
+
className: "w-auto p-0",
|
|
121
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_calendar.Calendar, {
|
|
122
|
+
...calendarProps,
|
|
123
|
+
mode: "single",
|
|
124
|
+
month: calendarProps?.month ?? month,
|
|
125
|
+
onMonthChange: (next) => {
|
|
126
|
+
calendarProps?.onMonthChange?.(next);
|
|
127
|
+
if (calendarProps?.month === void 0) setMonth(next);
|
|
128
|
+
},
|
|
129
|
+
onSelect: (next) => {
|
|
130
|
+
commit(next ? (0, ictus.formatDate)(next, separator) : "");
|
|
131
|
+
setOpen(false);
|
|
132
|
+
},
|
|
133
|
+
selected
|
|
134
|
+
})
|
|
135
|
+
})]
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
//#endregion
|
|
139
|
+
exports.InputDate = InputDate;
|
|
140
|
+
|
|
141
|
+
//# sourceMappingURL=input-date.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-date.cjs","names":["React","Popover","PopoverAnchor","InputGroup","InputGroupInput","InputGroupAddon","PopoverTrigger","Button","CalendarMonth","PopoverContent","Calendar"],"sources":["../../src/components/input-date.tsx"],"sourcesContent":["'use client'\n\nimport { CalendarMonth } from '@epilot/spark-icons'\nimport { apply, formatDate, isDateMaskKey, parseDate } from 'ictus'\nimport * as React from 'react'\nimport { cn } from '../utils/cn'\nimport { Button } from './button'\nimport { Calendar, type CalendarProps } from './calendar'\nimport { InputGroup, InputGroupAddon, InputGroupInput } from './input-group'\nimport {\n Popover,\n PopoverAnchor,\n PopoverContent,\n PopoverTrigger,\n} from './popover'\n\nfunction useControllableState<T>({\n defaultProp,\n onChange,\n prop,\n}: {\n defaultProp: T\n onChange?: (value: T) => void\n prop?: T\n}) {\n const [uncontrolled, setUncontrolled] = React.useState(defaultProp)\n const isControlled = prop !== undefined\n const value = isControlled ? prop : uncontrolled\n\n const setValue = React.useCallback(\n (next: T) => {\n if (!isControlled) setUncontrolled(next)\n onChange?.(next)\n },\n [isControlled, onChange],\n )\n\n return [value, setValue] as const\n}\n\nexport type InputDateProps = Omit<\n React.ComponentProps<'input'>,\n 'children' | 'defaultValue' | 'onChange' | 'type' | 'value'\n> & {\n calendarLabel: string\n calendarProps?: Omit<CalendarProps, 'mode' | 'onSelect' | 'selected'>\n defaultOpen?: boolean\n defaultValue?: string\n onDateChange?: (date: Date | undefined) => void\n onOpenChange?: (open: boolean) => void\n onValueChange?: (value: string) => void\n open?: boolean\n separator?: string\n value?: string\n}\n\nconst InputDate = React.forwardRef<HTMLInputElement, InputDateProps>(\n function InputDate(\n {\n calendarLabel,\n calendarProps,\n className,\n defaultOpen = false,\n defaultValue = '',\n disabled,\n id,\n onDateChange,\n onKeyDown,\n onOpenChange,\n onValueChange,\n open: openProp,\n placeholder,\n readOnly,\n separator = '.',\n value: valueProp,\n ...props\n },\n ref,\n ) {\n const inputRef = React.useRef<HTMLInputElement>(null)\n const [text, setText] = useControllableState({\n defaultProp: defaultValue,\n onChange: onValueChange,\n prop: valueProp,\n })\n const [open, setOpenState] = useControllableState({\n defaultProp: defaultOpen,\n onChange: onOpenChange,\n prop: openProp,\n })\n const selected = parseDate(text)\n const [month, setMonth] = React.useState<Date | undefined>(\n () => selected ?? calendarProps?.month,\n )\n const setOpen = React.useCallback(\n (next: boolean) => {\n if (next && calendarProps?.month === undefined) {\n setMonth(parseDate(text) ?? new Date())\n }\n setOpenState(next)\n },\n [calendarProps?.month, setOpenState, text],\n )\n\n const commit = React.useCallback(\n (next: string) => {\n if (next === text) return\n setText(next)\n onDateChange?.(parseDate(next))\n },\n [onDateChange, setText, text],\n )\n\n const setInputRef = React.useCallback(\n (node: HTMLInputElement | null) => {\n inputRef.current = node\n if (typeof ref === 'function') ref(node)\n else if (ref) ref.current = node\n },\n [ref],\n )\n\n return (\n <Popover onOpenChange={setOpen} open={open}>\n <PopoverAnchor render={<InputGroup className={className} />}>\n <InputGroupInput\n autoComplete=\"off\"\n {...props}\n className={cn(readOnly && 'cursor-pointer')}\n disabled={disabled}\n id={id}\n inputMode={readOnly ? undefined : 'numeric'}\n onChange={() => {}}\n onClick={\n readOnly && !disabled\n ? (event) => {\n props.onClick?.(event)\n if (!event.defaultPrevented) setOpen(true)\n }\n : props.onClick\n }\n onKeyDown={(event) => {\n onKeyDown?.(event)\n if (event.defaultPrevented) return\n if (event.key === 'ArrowDown') {\n event.preventDefault()\n setOpen(true)\n return\n }\n if (readOnly || !isDateMaskKey(event.key)) return\n event.preventDefault()\n const next = apply({\n caret: event.currentTarget.selectionStart ?? 0,\n key: event.key,\n selectionEnd: event.currentTarget.selectionEnd ?? undefined,\n separator,\n value: event.currentTarget.value,\n })\n commit(next.value)\n const caret = next.caret\n const input = inputRef.current\n requestAnimationFrame(() => {\n input?.setSelectionRange(caret, caret)\n })\n }}\n placeholder={placeholder ?? `DD${separator}MM${separator}YYYY`}\n readOnly={readOnly}\n ref={setInputRef}\n spellCheck={false}\n value={text}\n />\n <InputGroupAddon align=\"inline-end\">\n <PopoverTrigger\n render={\n <Button\n aria-label={calendarLabel}\n color=\"neutral\"\n disabled={disabled}\n size=\"icon-small\"\n styleVariant=\"ghost\"\n >\n <CalendarMonth />\n </Button>\n }\n />\n </InputGroupAddon>\n </PopoverAnchor>\n <PopoverContent\n align=\"start\"\n aria-label={calendarLabel}\n className=\"w-auto p-0\"\n >\n <Calendar\n {...calendarProps}\n mode=\"single\"\n month={calendarProps?.month ?? month}\n onMonthChange={(next) => {\n calendarProps?.onMonthChange?.(next)\n if (calendarProps?.month === undefined) setMonth(next)\n }}\n onSelect={(next) => {\n commit(next ? formatDate(next, separator) : '')\n setOpen(false)\n }}\n selected={selected}\n />\n </PopoverContent>\n </Popover>\n )\n },\n)\n\nexport { InputDate }\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,SAAS,qBAAwB,EAC/B,aACA,UACA,QAKC;CACD,MAAM,CAAC,cAAc,mBAAmBA,MAAM,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AA,kBAAA,KAACC,0BAAAA,QAAD;KACE,cAAY;KACZ,OAAM;KACI;KACV,MAAK;KACL,cAAa;eAEb,iBAAA,GAAA,kBAAA,KAACC,oBAAAA,eAAD,CAAgB,CAAA;IACV,CAAA,EAEX,CAAA;GACc,CAAA,CACJ;MACf,iBAAA,GAAA,kBAAA,KAACC,2BAAAA,gBAAD;GACE,OAAM;GACN,cAAY;GACZ,WAAU;aAEV,iBAAA,GAAA,kBAAA,KAACC,4BAAAA,UAAD;IACE,GAAI;IACJ,MAAK;IACL,OAAO,eAAe,SAAS;IAC/B,gBAAgB,SAAS;KACvB,eAAe,gBAAgB,IAAI;KACnC,IAAI,eAAe,UAAU,KAAA,GAAW,SAAS,IAAI;IACvD;IACA,WAAW,SAAS;KAClB,OAAO,QAAA,GAAA,MAAA,YAAkB,MAAM,SAAS,IAAI,EAAE;KAC9C,QAAQ,KAAK;IACf;IACU;GACX,CAAA;EACa,CAAA,CACT;;AAEb,CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { CalendarProps } from "./calendar.cjs";
|
|
4
|
+
import * as React$1 from "react";
|
|
5
|
+
|
|
6
|
+
//#region src/components/input-date.d.ts
|
|
7
|
+
type InputDateProps = Omit<React$1.ComponentProps<'input'>, 'children' | 'defaultValue' | 'onChange' | 'type' | 'value'> & {
|
|
8
|
+
calendarLabel: string;
|
|
9
|
+
calendarProps?: Omit<CalendarProps, 'mode' | 'onSelect' | 'selected'>;
|
|
10
|
+
defaultOpen?: boolean;
|
|
11
|
+
defaultValue?: string;
|
|
12
|
+
onDateChange?: (date: Date | undefined) => void;
|
|
13
|
+
onOpenChange?: (open: boolean) => void;
|
|
14
|
+
onValueChange?: (value: string) => void;
|
|
15
|
+
open?: boolean;
|
|
16
|
+
separator?: string;
|
|
17
|
+
value?: string;
|
|
18
|
+
};
|
|
19
|
+
declare const InputDate: React$1.ForwardRefExoticComponent<Omit<InputDateProps, "ref"> & React$1.RefAttributes<HTMLInputElement>>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { InputDate, InputDateProps };
|
|
22
|
+
//# sourceMappingURL=input-date.d.cts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { CalendarProps } from "./calendar.js";
|
|
4
|
+
import * as React$1 from "react";
|
|
5
|
+
|
|
6
|
+
//#region src/components/input-date.d.ts
|
|
7
|
+
type InputDateProps = Omit<React$1.ComponentProps<'input'>, 'children' | 'defaultValue' | 'onChange' | 'type' | 'value'> & {
|
|
8
|
+
calendarLabel: string;
|
|
9
|
+
calendarProps?: Omit<CalendarProps, 'mode' | 'onSelect' | 'selected'>;
|
|
10
|
+
defaultOpen?: boolean;
|
|
11
|
+
defaultValue?: string;
|
|
12
|
+
onDateChange?: (date: Date | undefined) => void;
|
|
13
|
+
onOpenChange?: (open: boolean) => void;
|
|
14
|
+
onValueChange?: (value: string) => void;
|
|
15
|
+
open?: boolean;
|
|
16
|
+
separator?: string;
|
|
17
|
+
value?: string;
|
|
18
|
+
};
|
|
19
|
+
declare const InputDate: React$1.ForwardRefExoticComponent<Omit<InputDateProps, "ref"> & React$1.RefAttributes<HTMLInputElement>>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { InputDate, InputDateProps };
|
|
22
|
+
//# sourceMappingURL=input-date.d.ts.map
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use client";
|
|
3
|
+
import { cn } from "../utils/cn.js";
|
|
4
|
+
import { Button } from "./button.js";
|
|
5
|
+
import { InputGroup, InputGroupAddon, InputGroupInput } from "./input-group.js";
|
|
6
|
+
import { Calendar } from "./calendar.js";
|
|
7
|
+
import { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from "./popover.js";
|
|
8
|
+
import * as React$1 from "react";
|
|
9
|
+
import { CalendarMonth } from "@epilot/spark-icons";
|
|
10
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { apply, formatDate, isDateMaskKey, parseDate } from "ictus";
|
|
12
|
+
//#region src/components/input-date.tsx
|
|
13
|
+
function useControllableState({ defaultProp, onChange, prop }) {
|
|
14
|
+
const [uncontrolled, setUncontrolled] = React$1.useState(defaultProp);
|
|
15
|
+
const isControlled = prop !== void 0;
|
|
16
|
+
return [isControlled ? prop : uncontrolled, React$1.useCallback((next) => {
|
|
17
|
+
if (!isControlled) setUncontrolled(next);
|
|
18
|
+
onChange?.(next);
|
|
19
|
+
}, [isControlled, onChange])];
|
|
20
|
+
}
|
|
21
|
+
const InputDate = React$1.forwardRef(function InputDate({ calendarLabel, calendarProps, className, defaultOpen = false, defaultValue = "", disabled, id, onDateChange, onKeyDown, onOpenChange, onValueChange, open: openProp, placeholder, readOnly, separator = ".", value: valueProp, ...props }, ref) {
|
|
22
|
+
const inputRef = React$1.useRef(null);
|
|
23
|
+
const [text, setText] = useControllableState({
|
|
24
|
+
defaultProp: defaultValue,
|
|
25
|
+
onChange: onValueChange,
|
|
26
|
+
prop: valueProp
|
|
27
|
+
});
|
|
28
|
+
const [open, setOpenState] = useControllableState({
|
|
29
|
+
defaultProp: defaultOpen,
|
|
30
|
+
onChange: onOpenChange,
|
|
31
|
+
prop: openProp
|
|
32
|
+
});
|
|
33
|
+
const selected = parseDate(text);
|
|
34
|
+
const [month, setMonth] = React$1.useState(() => selected ?? calendarProps?.month);
|
|
35
|
+
const setOpen = React$1.useCallback((next) => {
|
|
36
|
+
if (next && calendarProps?.month === void 0) setMonth(parseDate(text) ?? /* @__PURE__ */ new Date());
|
|
37
|
+
setOpenState(next);
|
|
38
|
+
}, [
|
|
39
|
+
calendarProps?.month,
|
|
40
|
+
setOpenState,
|
|
41
|
+
text
|
|
42
|
+
]);
|
|
43
|
+
const commit = React$1.useCallback((next) => {
|
|
44
|
+
if (next === text) return;
|
|
45
|
+
setText(next);
|
|
46
|
+
onDateChange?.(parseDate(next));
|
|
47
|
+
}, [
|
|
48
|
+
onDateChange,
|
|
49
|
+
setText,
|
|
50
|
+
text
|
|
51
|
+
]);
|
|
52
|
+
const setInputRef = React$1.useCallback((node) => {
|
|
53
|
+
inputRef.current = node;
|
|
54
|
+
if (typeof ref === "function") ref(node);
|
|
55
|
+
else if (ref) ref.current = node;
|
|
56
|
+
}, [ref]);
|
|
57
|
+
return /* @__PURE__ */ jsxs(Popover, {
|
|
58
|
+
onOpenChange: setOpen,
|
|
59
|
+
open,
|
|
60
|
+
children: [/* @__PURE__ */ jsxs(PopoverAnchor, {
|
|
61
|
+
render: /* @__PURE__ */ jsx(InputGroup, { className }),
|
|
62
|
+
children: [/* @__PURE__ */ jsx(InputGroupInput, {
|
|
63
|
+
autoComplete: "off",
|
|
64
|
+
...props,
|
|
65
|
+
className: cn(readOnly && "cursor-pointer"),
|
|
66
|
+
disabled,
|
|
67
|
+
id,
|
|
68
|
+
inputMode: readOnly ? void 0 : "numeric",
|
|
69
|
+
onChange: () => {},
|
|
70
|
+
onClick: readOnly && !disabled ? (event) => {
|
|
71
|
+
props.onClick?.(event);
|
|
72
|
+
if (!event.defaultPrevented) setOpen(true);
|
|
73
|
+
} : props.onClick,
|
|
74
|
+
onKeyDown: (event) => {
|
|
75
|
+
onKeyDown?.(event);
|
|
76
|
+
if (event.defaultPrevented) return;
|
|
77
|
+
if (event.key === "ArrowDown") {
|
|
78
|
+
event.preventDefault();
|
|
79
|
+
setOpen(true);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (readOnly || !isDateMaskKey(event.key)) return;
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
const next = apply({
|
|
85
|
+
caret: event.currentTarget.selectionStart ?? 0,
|
|
86
|
+
key: event.key,
|
|
87
|
+
selectionEnd: event.currentTarget.selectionEnd ?? void 0,
|
|
88
|
+
separator,
|
|
89
|
+
value: event.currentTarget.value
|
|
90
|
+
});
|
|
91
|
+
commit(next.value);
|
|
92
|
+
const caret = next.caret;
|
|
93
|
+
const input = inputRef.current;
|
|
94
|
+
requestAnimationFrame(() => {
|
|
95
|
+
input?.setSelectionRange(caret, caret);
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
placeholder: placeholder ?? `DD${separator}MM${separator}YYYY`,
|
|
99
|
+
readOnly,
|
|
100
|
+
ref: setInputRef,
|
|
101
|
+
spellCheck: false,
|
|
102
|
+
value: text
|
|
103
|
+
}), /* @__PURE__ */ jsx(InputGroupAddon, {
|
|
104
|
+
align: "inline-end",
|
|
105
|
+
children: /* @__PURE__ */ jsx(PopoverTrigger, { render: /* @__PURE__ */ jsx(Button, {
|
|
106
|
+
"aria-label": calendarLabel,
|
|
107
|
+
color: "neutral",
|
|
108
|
+
disabled,
|
|
109
|
+
size: "icon-small",
|
|
110
|
+
styleVariant: "ghost",
|
|
111
|
+
children: /* @__PURE__ */ jsx(CalendarMonth, {})
|
|
112
|
+
}) })
|
|
113
|
+
})]
|
|
114
|
+
}), /* @__PURE__ */ jsx(PopoverContent, {
|
|
115
|
+
align: "start",
|
|
116
|
+
"aria-label": calendarLabel,
|
|
117
|
+
className: "w-auto p-0",
|
|
118
|
+
children: /* @__PURE__ */ jsx(Calendar, {
|
|
119
|
+
...calendarProps,
|
|
120
|
+
mode: "single",
|
|
121
|
+
month: calendarProps?.month ?? month,
|
|
122
|
+
onMonthChange: (next) => {
|
|
123
|
+
calendarProps?.onMonthChange?.(next);
|
|
124
|
+
if (calendarProps?.month === void 0) setMonth(next);
|
|
125
|
+
},
|
|
126
|
+
onSelect: (next) => {
|
|
127
|
+
commit(next ? formatDate(next, separator) : "");
|
|
128
|
+
setOpen(false);
|
|
129
|
+
},
|
|
130
|
+
selected
|
|
131
|
+
})
|
|
132
|
+
})]
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
//#endregion
|
|
136
|
+
export { InputDate };
|
|
137
|
+
|
|
138
|
+
//# sourceMappingURL=input-date.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-date.js","names":["React"],"sources":["../../src/components/input-date.tsx"],"sourcesContent":["'use client'\n\nimport { CalendarMonth } from '@epilot/spark-icons'\nimport { apply, formatDate, isDateMaskKey, parseDate } from 'ictus'\nimport * as React from 'react'\nimport { cn } from '../utils/cn'\nimport { Button } from './button'\nimport { Calendar, type CalendarProps } from './calendar'\nimport { InputGroup, InputGroupAddon, InputGroupInput } from './input-group'\nimport {\n Popover,\n PopoverAnchor,\n PopoverContent,\n PopoverTrigger,\n} from './popover'\n\nfunction useControllableState<T>({\n defaultProp,\n onChange,\n prop,\n}: {\n defaultProp: T\n onChange?: (value: T) => void\n prop?: T\n}) {\n const [uncontrolled, setUncontrolled] = React.useState(defaultProp)\n const isControlled = prop !== undefined\n const value = isControlled ? prop : uncontrolled\n\n const setValue = React.useCallback(\n (next: T) => {\n if (!isControlled) setUncontrolled(next)\n onChange?.(next)\n },\n [isControlled, onChange],\n )\n\n return [value, setValue] as const\n}\n\nexport type InputDateProps = Omit<\n React.ComponentProps<'input'>,\n 'children' | 'defaultValue' | 'onChange' | 'type' | 'value'\n> & {\n calendarLabel: string\n calendarProps?: Omit<CalendarProps, 'mode' | 'onSelect' | 'selected'>\n defaultOpen?: boolean\n defaultValue?: string\n onDateChange?: (date: Date | undefined) => void\n onOpenChange?: (open: boolean) => void\n onValueChange?: (value: string) => void\n open?: boolean\n separator?: string\n value?: string\n}\n\nconst InputDate = React.forwardRef<HTMLInputElement, InputDateProps>(\n function InputDate(\n {\n calendarLabel,\n calendarProps,\n className,\n defaultOpen = false,\n defaultValue = '',\n disabled,\n id,\n onDateChange,\n onKeyDown,\n onOpenChange,\n onValueChange,\n open: openProp,\n placeholder,\n readOnly,\n separator = '.',\n value: valueProp,\n ...props\n },\n ref,\n ) {\n const inputRef = React.useRef<HTMLInputElement>(null)\n const [text, setText] = useControllableState({\n defaultProp: defaultValue,\n onChange: onValueChange,\n prop: valueProp,\n })\n const [open, setOpenState] = useControllableState({\n defaultProp: defaultOpen,\n onChange: onOpenChange,\n prop: openProp,\n })\n const selected = parseDate(text)\n const [month, setMonth] = React.useState<Date | undefined>(\n () => selected ?? calendarProps?.month,\n )\n const setOpen = React.useCallback(\n (next: boolean) => {\n if (next && calendarProps?.month === undefined) {\n setMonth(parseDate(text) ?? new Date())\n }\n setOpenState(next)\n },\n [calendarProps?.month, setOpenState, text],\n )\n\n const commit = React.useCallback(\n (next: string) => {\n if (next === text) return\n setText(next)\n onDateChange?.(parseDate(next))\n },\n [onDateChange, setText, text],\n )\n\n const setInputRef = React.useCallback(\n (node: HTMLInputElement | null) => {\n inputRef.current = node\n if (typeof ref === 'function') ref(node)\n else if (ref) ref.current = node\n },\n [ref],\n )\n\n return (\n <Popover onOpenChange={setOpen} open={open}>\n <PopoverAnchor render={<InputGroup className={className} />}>\n <InputGroupInput\n autoComplete=\"off\"\n {...props}\n className={cn(readOnly && 'cursor-pointer')}\n disabled={disabled}\n id={id}\n inputMode={readOnly ? undefined : 'numeric'}\n onChange={() => {}}\n onClick={\n readOnly && !disabled\n ? (event) => {\n props.onClick?.(event)\n if (!event.defaultPrevented) setOpen(true)\n }\n : props.onClick\n }\n onKeyDown={(event) => {\n onKeyDown?.(event)\n if (event.defaultPrevented) return\n if (event.key === 'ArrowDown') {\n event.preventDefault()\n setOpen(true)\n return\n }\n if (readOnly || !isDateMaskKey(event.key)) return\n event.preventDefault()\n const next = apply({\n caret: event.currentTarget.selectionStart ?? 0,\n key: event.key,\n selectionEnd: event.currentTarget.selectionEnd ?? undefined,\n separator,\n value: event.currentTarget.value,\n })\n commit(next.value)\n const caret = next.caret\n const input = inputRef.current\n requestAnimationFrame(() => {\n input?.setSelectionRange(caret, caret)\n })\n }}\n placeholder={placeholder ?? `DD${separator}MM${separator}YYYY`}\n readOnly={readOnly}\n ref={setInputRef}\n spellCheck={false}\n value={text}\n />\n <InputGroupAddon align=\"inline-end\">\n <PopoverTrigger\n render={\n <Button\n aria-label={calendarLabel}\n color=\"neutral\"\n disabled={disabled}\n size=\"icon-small\"\n styleVariant=\"ghost\"\n >\n <CalendarMonth />\n </Button>\n }\n />\n </InputGroupAddon>\n </PopoverAnchor>\n <PopoverContent\n align=\"start\"\n aria-label={calendarLabel}\n className=\"w-auto p-0\"\n >\n <Calendar\n {...calendarProps}\n mode=\"single\"\n month={calendarProps?.month ?? month}\n onMonthChange={(next) => {\n calendarProps?.onMonthChange?.(next)\n if (calendarProps?.month === undefined) setMonth(next)\n }}\n onSelect={(next) => {\n commit(next ? formatDate(next, separator) : '')\n setOpen(false)\n }}\n selected={selected}\n />\n </PopoverContent>\n </Popover>\n )\n },\n)\n\nexport { InputDate }\n"],"mappings":";;;;;;;;;;;;AAgBA,SAAS,qBAAwB,EAC/B,aACA,UACA,QAKC;CACD,MAAM,CAAC,cAAc,mBAAmBA,QAAM,SAAS,WAAW;CAClE,MAAM,eAAe,SAAS,KAAA;CAW9B,OAAO,CAVO,eAAe,OAAO,cAEnBA,QAAM,aACpB,SAAY;EACX,IAAI,CAAC,cAAc,gBAAgB,IAAI;EACvC,WAAW,IAAI;CACjB,GACA,CAAC,cAAc,QAAQ,CAGH,CAAC;AACzB;AAkBA,MAAM,YAAYA,QAAM,WACtB,SAAS,UACP,EACE,eACA,eACA,WACA,cAAc,OACd,eAAe,IACf,UACA,IACA,cACA,WACA,cACA,eACA,MAAM,UACN,aACA,UACA,YAAY,KACZ,OAAO,WACP,GAAG,SAEL,KACA;CACA,MAAM,WAAWA,QAAM,OAAyB,IAAI;CACpD,MAAM,CAAC,MAAM,WAAW,qBAAqB;EAC3C,aAAa;EACb,UAAU;EACV,MAAM;CACR,CAAC;CACD,MAAM,CAAC,MAAM,gBAAgB,qBAAqB;EAChD,aAAa;EACb,UAAU;EACV,MAAM;CACR,CAAC;CACD,MAAM,WAAW,UAAU,IAAI;CAC/B,MAAM,CAAC,OAAO,YAAYA,QAAM,eACxB,YAAY,eAAe,KACnC;CACA,MAAM,UAAUA,QAAM,aACnB,SAAkB;EACjB,IAAI,QAAQ,eAAe,UAAU,KAAA,GACnC,SA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S;KACvB,4BAA4B;MAC1B,OAAO,kBAAkB,OAAO,KAAK;KACvC,CAAC;IACH;IACA,aAAa,eAAe,KAAK,UAAU,IAAI,UAAU;IAC/C;IACV,KAAK;IACL,YAAY;IACZ,OAAO;GACR,CAAA,GACD,oBAAC,iBAAD;IAAiB,OAAM;cACrB,oBAAC,gBAAD,EACE,QACE,oBAAC,QAAD;KACE,cAAY;KACZ,OAAM;KACI;KACV,MAAK;KACL,cAAa;eAEb,oBAAC,eAAD,CAAgB,CAAA;IACV,CAAA,EAEX,CAAA;GACc,CAAA,CACJ;MACf,oBAAC,gBAAD;GACE,OAAM;GACN,cAAY;GACZ,WAAU;aAEV,oBAAC,UAAD;IACE,GAAI;IACJ,MAAK;IACL,OAAO,eAAe,SAAS;IAC/B,gBAAgB,SAAS;KACvB,eAAe,gBAAgB,IAAI;KACnC,IAAI,eAAe,UAAU,KAAA,GAAW,SAAS,IAAI;IACvD;IACA,WAAW,SAAS;KAClB,OAAO,OAAO,WAAW,MAAM,SAAS,IAAI,EAAE;KAC9C,QAAQ,KAAK;IACf;IACU;GACX,CAAA;EACa,CAAA,CACT;;AAEb,CACF"}
|
|
@@ -6,7 +6,7 @@ import { useRender } from "@base-ui/react/use-render";
|
|
|
6
6
|
|
|
7
7
|
//#region src/components/marker.d.ts
|
|
8
8
|
declare const markerVariants: (props?: ({
|
|
9
|
-
variant?: "
|
|
9
|
+
variant?: "separator" | "border" | "default" | null | undefined;
|
|
10
10
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
11
11
|
declare function Marker({
|
|
12
12
|
className,
|
|
@@ -6,7 +6,7 @@ import { useRender } from "@base-ui/react/use-render";
|
|
|
6
6
|
|
|
7
7
|
//#region src/components/marker.d.ts
|
|
8
8
|
declare const markerVariants: (props?: ({
|
|
9
|
-
variant?: "
|
|
9
|
+
variant?: "separator" | "border" | "default" | null | undefined;
|
|
10
10
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
11
11
|
declare function Marker({
|
|
12
12
|
className,
|
|
@@ -6,7 +6,7 @@ import { useRender } from "@base-ui/react/use-render";
|
|
|
6
6
|
|
|
7
7
|
//#region src/components/page-header.d.ts
|
|
8
8
|
declare const PageHeader: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLElement> & React$1.RefAttributes<HTMLElement>>;
|
|
9
|
-
declare const PageHeaderBackButton: React$1.ForwardRefExoticComponent<Omit<ButtonProps, "color" | "
|
|
9
|
+
declare const PageHeaderBackButton: React$1.ForwardRefExoticComponent<Omit<ButtonProps, "color" | "size" | "styleVariant"> & React$1.RefAttributes<HTMLButtonElement>>;
|
|
10
10
|
declare const PageHeaderTitle: ({
|
|
11
11
|
className,
|
|
12
12
|
...props
|
|
@@ -6,7 +6,7 @@ import { useRender } from "@base-ui/react/use-render";
|
|
|
6
6
|
|
|
7
7
|
//#region src/components/page-header.d.ts
|
|
8
8
|
declare const PageHeader: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLElement> & React$1.RefAttributes<HTMLElement>>;
|
|
9
|
-
declare const PageHeaderBackButton: React$1.ForwardRefExoticComponent<Omit<ButtonProps, "color" | "
|
|
9
|
+
declare const PageHeaderBackButton: React$1.ForwardRefExoticComponent<Omit<ButtonProps, "color" | "size" | "styleVariant"> & React$1.RefAttributes<HTMLButtonElement>>;
|
|
10
10
|
declare const PageHeaderTitle: ({
|
|
11
11
|
className,
|
|
12
12
|
...props
|
package/dist/components/pill.cjs
CHANGED
|
@@ -42,7 +42,7 @@ const Pill = react.forwardRef(function Pill({ className, children, styleVariant,
|
|
|
42
42
|
"data-accent-color": color ? require_lib_accent_colors.accentByColor[color] : void 0,
|
|
43
43
|
...interaction,
|
|
44
44
|
ref,
|
|
45
|
-
className: (0, cnfast.cn)("inline-flex h-7 items-center gap-1 rounded-full px-2.5 text-xs font-medium select-none", "bg-(--spark-style-bg,var(--neutral-a3)) text-(--spark-style-fg,var(--neutral-a11))", focusable && "transition-colors focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-hidden motion-reduce:transition-none", clickable && "cursor-pointer hover:bg-(--spark-style-bg-hover)", disabled && "pointer-events-none opacity-50", className),
|
|
45
|
+
className: (0, cnfast.cn)("inline-flex h-7 items-center gap-1 rounded-full px-2.5 text-xs font-medium select-none", "bg-(--spark-style-bg,var(--neutral-a3)) text-(--spark-style-fg,var(--spark-badge-fg,var(--neutral-a11)))", "shadow-[inset_0_0_0_var(--spark-style-border-width,1px)_var(--spark-style-border,transparent)]", focusable && "transition-colors focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-hidden motion-reduce:transition-none", clickable && "cursor-pointer hover:bg-(--spark-style-bg-hover,var(--neutral-a4))", disabled && "pointer-events-none opacity-50", className),
|
|
46
46
|
...props,
|
|
47
47
|
children: [children, removable ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
48
48
|
className: "sr-only",
|
|
@@ -54,7 +54,7 @@ const Pill = react.forwardRef(function Pill({ className, children, styleVariant,
|
|
|
54
54
|
event.stopPropagation();
|
|
55
55
|
onRemove?.(event);
|
|
56
56
|
},
|
|
57
|
-
className: "-mr-1 inline-flex size-4 shrink-0 items-center justify-center rounded-full transition-colors hover:bg-(--spark-style-bg-hover) motion-reduce:transition-none",
|
|
57
|
+
className: "-mr-1 inline-flex size-4 shrink-0 items-center justify-center rounded-full transition-colors hover:bg-(--spark-style-bg-hover,var(--neutral-a4)) motion-reduce:transition-none",
|
|
58
58
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_epilot_spark_icons.Close, { className: "[--spark-icon-size:14px]" })
|
|
59
59
|
})] }) : null]
|
|
60
60
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pill.cjs","names":["React","accentByColor","Close"],"sources":["../../src/components/pill.tsx"],"sourcesContent":["import { Close } from '@epilot/spark-icons'\nimport * as React from 'react'\nimport { accentByColor } from '../lib/accent-colors'\nimport type { SparkAccentColor } from '../lib/accent-colors'\nimport type { SparkStyle } from '../lib/theme-types'\nimport { cn } from '../utils/cn'\n\ntype PillRemoveProps =\n | { onRemove?: undefined; removeLabel?: string }\n | {\n /** Fires on a pointer click of the (decorative) glyph, or Delete/Backspace while the pill has focus. */\n onRemove: (event: React.SyntheticEvent) => void\n /** Visually-hidden text folded into the pill's accessible name -- the glyph itself is `aria-hidden`. */\n removeLabel: string\n }\n\ntype PillProps = Omit<React.HTMLAttributes<HTMLSpanElement>, 'onClick'> &\n PillRemoveProps & {\n styleVariant?: SparkStyle\n color?: SparkAccentColor\n disabled?: boolean\n onClick?: (event: React.SyntheticEvent<HTMLSpanElement>) => void\n }\n\n/**\n * Like Badge, but interactive: `onClick` makes the whole pill a button\n * (Enter/Space), `onRemove` adds a Delete/Backspace-and-click affordance.\n * Both are optional -- with neither, it's a static label.\n */\nconst Pill = React.forwardRef<HTMLSpanElement, PillProps>(function Pill(\n {\n className,\n children,\n styleVariant,\n color,\n disabled = false,\n onClick,\n onRemove,\n removeLabel,\n onKeyDown,\n ...props\n },\n ref,\n) {\n const clickable = !disabled && onClick !== undefined\n const removable = !disabled && onRemove !== undefined\n const focusable = clickable || removable\n const hasLook = styleVariant !== undefined || color !== undefined\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLSpanElement>) => {\n onKeyDown?.(event)\n if (clickable && (event.key === 'Enter' || event.key === ' ')) {\n if (event.key === ' ') event.preventDefault()\n onClick?.(event)\n }\n if (removable && (event.key === 'Delete' || event.key === 'Backspace')) {\n onRemove?.(event)\n }\n }\n\n // button role and click handler travel together, so a clickable pill always\n // answers Enter/Space; a removable-only pill stays generic and answers Delete\n const interaction = {\n onKeyDown: handleKeyDown,\n ...(clickable && { role: 'button' as const, onClick }),\n ...(focusable && { tabIndex: 0 }),\n }\n\n return (\n <span\n aria-disabled={disabled || undefined}\n aria-keyshortcuts={removable ? 'Delete' : undefined}\n data-slot=\"pill\"\n data-style={hasLook ? (styleVariant ?? 'soft') : undefined}\n data-accent-color={color ? accentByColor[color] : undefined}\n {...interaction}\n ref={ref}\n className={cn(\n 'inline-flex h-7 items-center gap-1 rounded-full px-2.5 text-xs font-medium select-none',\n 'bg-(--spark-style-bg,var(--neutral-a3)) text-(--spark-style-fg,var(--neutral-a11))',\n focusable &&\n 'transition-colors focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-hidden motion-reduce:transition-none',\n clickable
|
|
1
|
+
{"version":3,"file":"pill.cjs","names":["React","accentByColor","Close"],"sources":["../../src/components/pill.tsx"],"sourcesContent":["import { Close } from '@epilot/spark-icons'\nimport * as React from 'react'\nimport { accentByColor } from '../lib/accent-colors'\nimport type { SparkAccentColor } from '../lib/accent-colors'\nimport type { SparkStyle } from '../lib/theme-types'\nimport { cn } from '../utils/cn'\n\ntype PillRemoveProps =\n | { onRemove?: undefined; removeLabel?: string }\n | {\n /** Fires on a pointer click of the (decorative) glyph, or Delete/Backspace while the pill has focus. */\n onRemove: (event: React.SyntheticEvent) => void\n /** Visually-hidden text folded into the pill's accessible name -- the glyph itself is `aria-hidden`. */\n removeLabel: string\n }\n\ntype PillProps = Omit<React.HTMLAttributes<HTMLSpanElement>, 'onClick'> &\n PillRemoveProps & {\n styleVariant?: SparkStyle\n color?: SparkAccentColor\n disabled?: boolean\n onClick?: (event: React.SyntheticEvent<HTMLSpanElement>) => void\n }\n\n/**\n * Like Badge, but interactive: `onClick` makes the whole pill a button\n * (Enter/Space), `onRemove` adds a Delete/Backspace-and-click affordance.\n * Both are optional -- with neither, it's a static label.\n */\nconst Pill = React.forwardRef<HTMLSpanElement, PillProps>(function Pill(\n {\n className,\n children,\n styleVariant,\n color,\n disabled = false,\n onClick,\n onRemove,\n removeLabel,\n onKeyDown,\n ...props\n },\n ref,\n) {\n const clickable = !disabled && onClick !== undefined\n const removable = !disabled && onRemove !== undefined\n const focusable = clickable || removable\n const hasLook = styleVariant !== undefined || color !== undefined\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLSpanElement>) => {\n onKeyDown?.(event)\n if (clickable && (event.key === 'Enter' || event.key === ' ')) {\n if (event.key === ' ') event.preventDefault()\n onClick?.(event)\n }\n if (removable && (event.key === 'Delete' || event.key === 'Backspace')) {\n onRemove?.(event)\n }\n }\n\n // button role and click handler travel together, so a clickable pill always\n // answers Enter/Space; a removable-only pill stays generic and answers Delete\n const interaction = {\n onKeyDown: handleKeyDown,\n ...(clickable && { role: 'button' as const, onClick }),\n ...(focusable && { tabIndex: 0 }),\n }\n\n return (\n <span\n aria-disabled={disabled || undefined}\n aria-keyshortcuts={removable ? 'Delete' : undefined}\n data-slot=\"pill\"\n data-style={hasLook ? (styleVariant ?? 'soft') : undefined}\n data-accent-color={color ? accentByColor[color] : undefined}\n {...interaction}\n ref={ref}\n className={cn(\n 'inline-flex h-7 items-center gap-1 rounded-full px-2.5 text-xs font-medium select-none',\n // shared chip ink with Badge: solid leaves --spark-style-fg unset, so without the\n // --spark-badge-fg link solid text falls through to a11 on the step-9 fill (fails AA)\n 'bg-(--spark-style-bg,var(--neutral-a3)) text-(--spark-style-fg,var(--spark-badge-fg,var(--neutral-a11)))',\n // surface/outline are defined by their edge; painted inset like Button's so it\n // costs no layout, unlike Badge's real border\n 'shadow-[inset_0_0_0_var(--spark-style-border-width,1px)_var(--spark-style-border,transparent)]',\n focusable &&\n 'transition-colors focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-hidden motion-reduce:transition-none',\n clickable &&\n 'cursor-pointer hover:bg-(--spark-style-bg-hover,var(--neutral-a4))',\n disabled && 'pointer-events-none opacity-50',\n className,\n )}\n {...props}\n >\n {children}\n {removable ? (\n <>\n {/* aria-hidden hides the glyph itself; this carries removeLabel into the pill's own accessible name */}\n <span className=\"sr-only\">{removeLabel}</span>\n <span\n aria-hidden=\"true\"\n data-slot=\"pill-remove\"\n onClick={(event) => {\n event.stopPropagation()\n onRemove?.(event)\n }}\n className=\"-mr-1 inline-flex size-4 shrink-0 items-center justify-center rounded-full transition-colors hover:bg-(--spark-style-bg-hover,var(--neutral-a4)) motion-reduce:transition-none\"\n >\n <Close className=\"[--spark-icon-size:14px]\" />\n </span>\n </>\n ) : null}\n </span>\n )\n})\n\nPill.displayName = 'Pill'\n\nexport { Pill }\nexport type { PillProps }\n"],"mappings":";;;;;;;;;;;;;;;AA6BA,MAAM,OAAOA,MAAM,WAAuC,SAAS,KACjE,EACE,WACA,UACA,cACA,OACA,WAAW,OACX,SACA,UACA,aACA,WACA,GAAG,SAEL,KACA;CACA,MAAM,YAAY,CAAC,YAAY,YAAY,KAAA;CAC3C,MAAM,YAAY,CAAC,YAAY,aAAa,KAAA;CAC5C,MAAM,YAAY,aAAa;CAC/B,MAAM,UAAU,iBAAiB,KAAA,KAAa,UAAU,KAAA;CAExD,MAAM,iBAAiB,UAAgD;EACrE,YAAY,KAAK;EACjB,IAAI,cAAc,MAAM,QAAQ,WAAW,MAAM,QAAQ,MAAM;GAC7D,IAAI,MAAM,QAAQ,KAAK,MAAM,eAAe;GAC5C,UAAU,KAAK;EACjB;EACA,IAAI,cAAc,MAAM,QAAQ,YAAY,MAAM,QAAQ,cACxD,WAAW,KAAK;CAEpB;CAIA,MAAM,cAAc;EAClB,WAAW;EACX,GAAI,aAAa;GAAE,MAAM;GAAmB;EAAQ;EACpD,GAAI,aAAa,EAAE,UAAU,EAAE;CACjC;CAEA,OACE,iBAAA,GAAA,kBAAA,MAAC,QAAD;EACE,iBAAe,YAAY,KAAA;EAC3B,qBAAmB,YAAY,WAAW,KAAA;EAC1C,aAAU;EACV,cAAY,UAAW,gBAAgB,SAAU,KAAA;EACjD,qBAAmB,QAAQC,0BAAAA,cAAc,SAAS,KAAA;EAClD,GAAI;EACC;EACL,YAAA,GAAA,OAAA,IACE,0FAGA,4GAGA,kGACA,aACE,iIACF,aACE,sEACF,YAAY,kCACZ,SACF;EACA,GAAI;YAvBN,CAyBG,UACA,YACC,iBAAA,GAAA,kBAAA,MAAA,kBAAA,UAAA,EAAA,UAAA,CAEE,iBAAA,GAAA,kBAAA,KAAC,QAAD;GAAM,WAAU;aAAW;EAAkB,CAAA,GAC7C,iBAAA,GAAA,kBAAA,KAAC,QAAD;GACE,eAAY;GACZ,aAAU;GACV,UAAU,UAAU;IAClB,MAAM,gBAAgB;IACtB,WAAW,KAAK;GAClB;GACA,WAAU;aAEV,iBAAA,GAAA,kBAAA,KAACC,oBAAAA,OAAD,EAAO,WAAU,2BAA4B,CAAA;EACzC,CAAA,CACN,EAAA,CAAA,IACA,IACA;;AAEV,CAAC;AAED,KAAK,cAAc"}
|
package/dist/components/pill.js
CHANGED
|
@@ -39,7 +39,7 @@ const Pill = React$1.forwardRef(function Pill({ className, children, styleVarian
|
|
|
39
39
|
"data-accent-color": color ? accentByColor[color] : void 0,
|
|
40
40
|
...interaction,
|
|
41
41
|
ref,
|
|
42
|
-
className: cn("inline-flex h-7 items-center gap-1 rounded-full px-2.5 text-xs font-medium select-none", "bg-(--spark-style-bg,var(--neutral-a3)) text-(--spark-style-fg,var(--neutral-a11))", focusable && "transition-colors focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-hidden motion-reduce:transition-none", clickable && "cursor-pointer hover:bg-(--spark-style-bg-hover)", disabled && "pointer-events-none opacity-50", className),
|
|
42
|
+
className: cn("inline-flex h-7 items-center gap-1 rounded-full px-2.5 text-xs font-medium select-none", "bg-(--spark-style-bg,var(--neutral-a3)) text-(--spark-style-fg,var(--spark-badge-fg,var(--neutral-a11)))", "shadow-[inset_0_0_0_var(--spark-style-border-width,1px)_var(--spark-style-border,transparent)]", focusable && "transition-colors focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-hidden motion-reduce:transition-none", clickable && "cursor-pointer hover:bg-(--spark-style-bg-hover,var(--neutral-a4))", disabled && "pointer-events-none opacity-50", className),
|
|
43
43
|
...props,
|
|
44
44
|
children: [children, removable ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
45
45
|
className: "sr-only",
|
|
@@ -51,7 +51,7 @@ const Pill = React$1.forwardRef(function Pill({ className, children, styleVarian
|
|
|
51
51
|
event.stopPropagation();
|
|
52
52
|
onRemove?.(event);
|
|
53
53
|
},
|
|
54
|
-
className: "-mr-1 inline-flex size-4 shrink-0 items-center justify-center rounded-full transition-colors hover:bg-(--spark-style-bg-hover) motion-reduce:transition-none",
|
|
54
|
+
className: "-mr-1 inline-flex size-4 shrink-0 items-center justify-center rounded-full transition-colors hover:bg-(--spark-style-bg-hover,var(--neutral-a4)) motion-reduce:transition-none",
|
|
55
55
|
children: /* @__PURE__ */ jsx(Close, { className: "[--spark-icon-size:14px]" })
|
|
56
56
|
})] }) : null]
|
|
57
57
|
});
|