@epilot/spark-ui 0.28.1 → 0.29.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/attachment.d.cts +1 -1
- package/dist/components/attachment.d.ts +1 -1
- package/dist/components/avatar.d.cts +1 -1
- package/dist/components/avatar.d.ts +1 -1
- package/dist/components/avatar.js +1 -1
- package/dist/components/badge.d.cts +1 -1
- package/dist/components/badge.d.ts +1 -1
- package/dist/components/badge.js +1 -1
- package/dist/components/box.d.cts +1 -1
- package/dist/components/box.d.ts +1 -1
- package/dist/components/box.js +1 -1
- package/dist/components/bubble.d.cts +1 -1
- package/dist/components/bubble.d.ts +1 -1
- package/dist/components/button-group.d.cts +1 -1
- package/dist/components/button-group.d.ts +1 -1
- package/dist/components/button-group.js +1 -1
- package/dist/components/button.cjs +16 -16
- package/dist/components/button.cjs.map +1 -1
- package/dist/components/button.d.cts +1 -1
- package/dist/components/button.d.ts +1 -1
- package/dist/components/button.js +17 -17
- package/dist/components/button.js.map +1 -1
- package/dist/components/card.d.cts +1 -1
- package/dist/components/card.d.ts +1 -1
- package/dist/components/card.js +1 -1
- package/dist/components/checkbox-group.cjs +1 -1
- package/dist/components/checkbox-group.d.cts +1 -1
- package/dist/components/checkbox-group.d.ts +1 -1
- package/dist/components/checkbox-group.js +2 -2
- package/dist/components/checkbox.d.cts +1 -1
- package/dist/components/checkbox.d.ts +1 -1
- package/dist/components/checkbox.js +1 -1
- package/dist/components/combobox.cjs +1 -1
- package/dist/components/combobox.d.cts +1 -1
- package/dist/components/combobox.d.ts +1 -1
- package/dist/components/combobox.js +1 -1
- package/dist/components/field.cjs +57 -16
- package/dist/components/field.cjs.map +1 -1
- package/dist/components/field.d.cts +8 -4
- package/dist/components/field.d.ts +8 -4
- package/dist/components/field.js +57 -16
- package/dist/components/field.js.map +1 -1
- package/dist/components/icon.js +1 -1
- package/dist/components/info-block.d.cts +1 -1
- package/dist/components/info-block.d.ts +1 -1
- package/dist/components/input-group.cjs +71 -3
- package/dist/components/input-group.cjs.map +1 -1
- package/dist/components/input-group.d.cts +6 -1
- package/dist/components/input-group.d.ts +6 -1
- package/dist/components/input-group.js +72 -5
- package/dist/components/input-group.js.map +1 -1
- package/dist/components/input-otp.cjs +1 -1
- package/dist/components/input-otp.js +1 -1
- package/dist/components/input.cjs +7 -4
- package/dist/components/input.cjs.map +1 -1
- package/dist/components/input.d.cts +1 -1
- package/dist/components/input.d.ts +1 -1
- package/dist/components/input.js +7 -4
- package/dist/components/input.js.map +1 -1
- package/dist/components/list.d.cts +1 -1
- package/dist/components/list.d.ts +1 -1
- package/dist/components/marker.d.cts +1 -1
- package/dist/components/marker.d.ts +1 -1
- package/dist/components/message-scroller.cjs +1 -1
- package/dist/components/message-scroller.js +1 -1
- package/dist/components/pill.d.cts +1 -1
- package/dist/components/pill.d.ts +1 -1
- package/dist/components/pill.js +1 -1
- package/dist/components/radio.cjs +1 -1
- package/dist/components/radio.d.cts +1 -1
- package/dist/components/radio.d.ts +1 -1
- package/dist/components/radio.js +2 -2
- package/dist/components/rating.cjs +17 -2
- package/dist/components/rating.cjs.map +1 -1
- package/dist/components/rating.d.cts +12 -2
- package/dist/components/rating.d.ts +12 -2
- package/dist/components/rating.js +17 -2
- package/dist/components/rating.js.map +1 -1
- package/dist/components/segmented-control.d.cts +1 -1
- package/dist/components/segmented-control.d.ts +1 -1
- package/dist/components/select.cjs +3 -2
- package/dist/components/select.cjs.map +1 -1
- package/dist/components/select.d.cts +1 -1
- package/dist/components/select.d.ts +1 -1
- package/dist/components/select.js +3 -2
- package/dist/components/select.js.map +1 -1
- package/dist/components/separator.cjs +15 -18
- package/dist/components/separator.cjs.map +1 -1
- package/dist/components/separator.d.cts +3 -0
- package/dist/components/separator.d.ts +3 -0
- package/dist/components/separator.js +16 -19
- package/dist/components/separator.js.map +1 -1
- package/dist/components/skeleton.cjs +20 -5
- package/dist/components/skeleton.cjs.map +1 -1
- package/dist/components/skeleton.d.cts +9 -5
- package/dist/components/skeleton.d.ts +9 -5
- package/dist/components/skeleton.js +19 -6
- package/dist/components/skeleton.js.map +1 -1
- package/dist/components/spinner.cjs +8 -81
- package/dist/components/spinner.cjs.map +1 -1
- package/dist/components/spinner.js +8 -81
- package/dist/components/spinner.js.map +1 -1
- package/dist/components/switch-group.cjs +1 -1
- package/dist/components/switch-group.d.cts +1 -1
- package/dist/components/switch-group.d.ts +1 -1
- package/dist/components/switch-group.js +2 -2
- package/dist/components/switch.d.cts +1 -1
- package/dist/components/switch.d.ts +1 -1
- package/dist/components/switch.js +1 -1
- package/dist/components/textarea.cjs +7 -4
- package/dist/components/textarea.cjs.map +1 -1
- package/dist/components/textarea.d.cts +1 -1
- package/dist/components/textarea.d.ts +1 -1
- package/dist/components/textarea.js +7 -4
- package/dist/components/textarea.js.map +1 -1
- package/dist/components/theme.d.cts +1 -1
- package/dist/components/theme.d.ts +1 -1
- package/dist/components/theme.js +1 -1
- package/dist/components/toggle-group.d.cts +1 -1
- package/dist/components/toggle-group.d.ts +1 -1
- package/dist/components/toggle-group.js +1 -1
- package/dist/components/toggle.cjs +1 -1
- package/dist/components/toggle.d.cts +1 -1
- package/dist/components/toggle.d.ts +1 -1
- package/dist/components/toggle.js +2 -2
- package/dist/components/tooltip.cjs +29 -25
- package/dist/components/tooltip.cjs.map +1 -1
- package/dist/components/tooltip.d.cts +4 -2
- package/dist/components/tooltip.d.ts +4 -2
- package/dist/components/tooltip.js +29 -25
- package/dist/components/tooltip.js.map +1 -1
- package/dist/lib/accent-theme.d.cts +1 -1
- package/dist/lib/accent-theme.d.ts +1 -1
- package/dist/lib/container-chrome.d.cts +1 -1
- package/dist/lib/container-chrome.d.ts +1 -1
- package/dist/lib/input-box-variants.cjs +11 -0
- package/dist/lib/input-box-variants.cjs.map +1 -1
- package/dist/lib/input-box-variants.d.cts +6 -2
- package/dist/lib/input-box-variants.d.ts +6 -2
- package/dist/lib/input-box-variants.js +8 -1
- package/dist/lib/input-box-variants.js.map +1 -1
- package/dist/lib/selection-list.d.cts +1 -1
- package/dist/lib/selection-list.d.ts +1 -1
- package/dist/lib/theme-types.cjs.map +1 -1
- package/dist/lib/theme-types.d.cts +1 -1
- package/dist/lib/theme-types.d.ts +1 -1
- package/dist/lib/theme-types.js.map +1 -1
- package/dist/lib/toggle-group-context.d.cts +1 -1
- package/dist/lib/toggle-group-context.d.ts +1 -1
- package/dist/styles/spark-default.css +3 -1
- package/dist/styles/theme.css +18 -98
- package/dist/{theme-types-Dlge0s3s.d.ts → theme-types-CHl-L2F-.d.cts} +2 -2
- package/dist/{theme-types-Dlge0s3s.d.cts → theme-types-CHl-L2F-.d.ts} +2 -2
- package/package.json +3 -2
|
@@ -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?: "border" | "default" | "separator" | 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?: "border" | "default" | "separator" | null | undefined;
|
|
10
10
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
11
11
|
declare function Marker({
|
|
12
12
|
className,
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const require_chunk = require("../chunk-DY84GLCh.cjs");
|
|
4
4
|
const require_hooks_use_reduced_motion = require("../hooks/use-reduced-motion.cjs");
|
|
5
|
-
const require_components_button = require("./button.cjs");
|
|
6
5
|
const require_lib_message_animations = require("../lib/message-animations.cjs");
|
|
6
|
+
const require_components_button = require("./button.cjs");
|
|
7
7
|
let react = require("react");
|
|
8
8
|
react = require_chunk.__toESM(react);
|
|
9
9
|
let _epilot_spark_icons = require("@epilot/spark-icons");
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useReducedMotion } from "../hooks/use-reduced-motion.js";
|
|
3
3
|
import { cn } from "../utils/cn.js";
|
|
4
|
-
import { Button } from "./button.js";
|
|
5
4
|
import { MESSAGE_ANIMATIONS } from "../lib/message-animations.js";
|
|
5
|
+
import { Button } from "./button.js";
|
|
6
6
|
import * as React$1 from "react";
|
|
7
7
|
import { ArrowDownward, ArrowUpward } from "@epilot/spark-icons";
|
|
8
8
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
package/dist/components/pill.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { cn } from "../utils/cn.js";
|
|
3
2
|
import { accentByColor } from "../lib/accent-colors.js";
|
|
3
|
+
import { cn } from "../utils/cn.js";
|
|
4
4
|
import * as React$1 from "react";
|
|
5
5
|
import { Close } from "@epilot/spark-icons";
|
|
6
6
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const require_chunk = require("../chunk-DY84GLCh.cjs");
|
|
4
4
|
const require_lib_accent_colors = require("../lib/accent-colors.cjs");
|
|
5
|
-
const require_components_field = require("./field.cjs");
|
|
6
5
|
const require_lib_selection_list = require("../lib/selection-list.cjs");
|
|
6
|
+
const require_components_field = require("./field.cjs");
|
|
7
7
|
let react = require("react");
|
|
8
8
|
react = require_chunk.__toESM(react);
|
|
9
9
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { d as SparkInputStyle, v as SparkStyle } from "../theme-types-
|
|
3
|
+
import { d as SparkInputStyle, v as SparkStyle } from "../theme-types-CHl-L2F-.cjs";
|
|
4
4
|
import * as React$1 from "react";
|
|
5
5
|
import { Radio as Radio$1 } from "@base-ui/react/radio";
|
|
6
6
|
import { RadioGroup as RadioGroup$1 } from "@base-ui/react/radio-group";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { d as SparkInputStyle, v as SparkStyle } from "../theme-types-
|
|
3
|
+
import { d as SparkInputStyle, v as SparkStyle } from "../theme-types-CHl-L2F-.js";
|
|
4
4
|
import * as React$1 from "react";
|
|
5
5
|
import { Radio as Radio$1 } from "@base-ui/react/radio";
|
|
6
6
|
import { RadioGroup as RadioGroup$1 } from "@base-ui/react/radio-group";
|
package/dist/components/radio.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { cn } from "../utils/cn.js";
|
|
3
2
|
import { accentByColor } from "../lib/accent-colors.js";
|
|
4
|
-
import {
|
|
3
|
+
import { cn } from "../utils/cn.js";
|
|
5
4
|
import { selectionListClasses } from "../lib/selection-list.js";
|
|
5
|
+
import { useFieldSetInvalid } from "./field.js";
|
|
6
6
|
import "react";
|
|
7
7
|
import { jsx } from "react/jsx-runtime";
|
|
8
8
|
import { Radio as Radio$1 } from "@base-ui/react/radio";
|
|
@@ -78,6 +78,12 @@ function starTone(fill, disabled) {
|
|
|
78
78
|
if (fill === "preview") return "fill-spark-a4 stroke-spark-9";
|
|
79
79
|
return "fill-none stroke-gray-a9";
|
|
80
80
|
}
|
|
81
|
+
function iconTone(fill, disabled) {
|
|
82
|
+
if (disabled) return fill === "off" ? "text-gray-a6" : "text-gray-a8";
|
|
83
|
+
if (fill === "on") return "text-spark-9";
|
|
84
|
+
if (fill === "preview") return "text-spark-a9";
|
|
85
|
+
return "text-gray-a8";
|
|
86
|
+
}
|
|
81
87
|
function captionTone(hasLabel, hovered, disabled) {
|
|
82
88
|
if (disabled) return "text-gray-a9";
|
|
83
89
|
if (!hasLabel) return "text-gray-11";
|
|
@@ -94,7 +100,7 @@ function Star({ className }) {
|
|
|
94
100
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M12.60 3.17 L14.72 8.03 Q15.00 8.67 15.69 8.74 L20.97 9.26 Q22.46 9.40 21.34 10.40 L17.37 13.91 Q16.85 14.38 17.00 15.06 L18.14 20.23 Q18.47 21.70 17.17 20.94 L12.60 18.25 Q12.00 17.90 11.40 18.25 L6.83 20.94 Q5.53 21.70 5.86 20.23 L7.00 15.06 Q7.15 14.38 6.63 13.91 L2.66 10.40 Q1.54 9.40 3.03 9.26 L8.31 8.74 Q9.00 8.67 9.28 8.03 L11.40 3.17 Q12.00 1.80 12.60 3.17Z" })
|
|
95
101
|
});
|
|
96
102
|
}
|
|
97
|
-
function RatingStars({ className, onPointerLeave, onKeyDown, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedByProp, ...props }) {
|
|
103
|
+
function RatingStars({ className, onPointerLeave, onKeyDown, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedByProp, renderIcon, ...props }) {
|
|
98
104
|
const rating = useRating();
|
|
99
105
|
const { field, ariaDescribedBy, ariaInvalid } = require_components_field.useFieldControl({ ariaDescribedBy: ariaDescribedByProp });
|
|
100
106
|
const invalid = require_components_field.useFieldSetInvalid();
|
|
@@ -136,7 +142,16 @@ function RatingStars({ className, onPointerLeave, onKeyDown, "aria-labelledby":
|
|
|
136
142
|
render: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {}),
|
|
137
143
|
onPointerEnter: interactive ? () => rating.setHovered(star) : void 0,
|
|
138
144
|
className: (0, cn.cn)("inline-flex min-h-[24px] min-w-[24px] shrink-0 cursor-pointer items-center justify-center rounded-sm border-0 bg-transparent p-0 touch-target-row any-pointer-coarse:min-w-11", "data-disabled:cursor-not-allowed data-readonly:cursor-default", buttonSize),
|
|
139
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
145
|
+
children: renderIcon ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
146
|
+
"aria-hidden": "true",
|
|
147
|
+
"data-slot": "rating-icon",
|
|
148
|
+
className: (0, cn.cn)("inline-flex items-center justify-center transition-colors motion-reduce:transition-none [&_svg]:size-full", starSize, iconTone(fill, rating.disabled)),
|
|
149
|
+
children: renderIcon({
|
|
150
|
+
star,
|
|
151
|
+
fill,
|
|
152
|
+
disabled: rating.disabled
|
|
153
|
+
})
|
|
154
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Star, { className: (0, cn.cn)(starSize, starTone(fill, rating.disabled)) })
|
|
140
155
|
}, star);
|
|
141
156
|
})
|
|
142
157
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rating.cjs","names":["React","useFieldControl","useFieldSetInvalid","RadioGroupPrimitive","RadioPrimitive"],"sources":["../../src/components/rating.tsx"],"sourcesContent":["import { Radio as RadioPrimitive } from '@base-ui/react/radio'\nimport { RadioGroup as RadioGroupPrimitive } from '@base-ui/react/radio-group'\nimport * as React from 'react'\nimport { cn } from '../utils/cn'\nimport { useFieldControl, useFieldSetInvalid } from './field'\n\ntype RatingSize = 'small' | 'medium' | 'large'\n\ntype RatingContextValue = {\n value: number | null\n setValue: (value: number) => void\n hovered: number | null\n setHovered: (value: number | null) => void\n max: number\n labels?: string[]\n size: RatingSize\n readOnly: boolean\n disabled: boolean\n name?: string\n}\n\nconst RatingContext = React.createContext<RatingContextValue | null>(null)\n\nfunction useRating() {\n const context = React.useContext(RatingContext)\n if (!context) throw new Error('RatingStars and RatingCaption need a Rating')\n return context\n}\n\ninterface RatingProps extends Omit<\n React.HTMLAttributes<HTMLDivElement>,\n 'defaultValue' | 'onChange'\n> {\n /** The chosen star, 1-based. `null` means nothing is chosen yet. */\n value?: number | null\n defaultValue?: number | null\n onValueChange?: (value: number) => void\n max?: number\n /** One label per star: the star's accessible name and the caption text. */\n labels?: string[]\n size?: RatingSize\n readOnly?: boolean\n disabled?: boolean\n name?: string\n}\n\nfunction Rating({\n value: valueProp,\n defaultValue = null,\n onValueChange,\n max = 5,\n labels,\n size = 'medium',\n readOnly = false,\n disabled = false,\n name,\n className,\n children,\n ...props\n}: RatingProps) {\n const [uncontrolled, setUncontrolled] = React.useState(defaultValue)\n const [hovered, setHovered] = React.useState<number | null>(null)\n const value = valueProp === undefined ? uncontrolled : valueProp\n\n const setValue = React.useCallback(\n (next: number) => {\n setUncontrolled(next)\n onValueChange?.(next)\n },\n [onValueChange],\n )\n\n return (\n <RatingContext.Provider\n value={{\n value,\n setValue,\n hovered: readOnly || disabled ? null : hovered,\n setHovered,\n max,\n labels,\n size,\n readOnly,\n disabled,\n name,\n }}\n >\n <div\n data-slot=\"rating\"\n className={cn(\n 'flex flex-col items-start gap-[calc(var(--spark-layout-gap)*1)]',\n className,\n )}\n {...props}\n >\n {children}\n </div>\n </RatingContext.Provider>\n )\n}\n\ntype SizeClasses = { star: string; button: string }\n\nconst sizeClasses: Record<RatingSize, SizeClasses> = {\n small: { star: 'size-4', button: 'size-6' },\n medium: { star: 'size-6', button: 'size-8' },\n large: { star: 'size-8', button: 'size-11' },\n}\n\n// above five stars the row would outgrow narrow panels\nconst compactSizeClasses: Record<RatingSize, SizeClasses> = {\n small: { star: 'size-3.5', button: 'size-6' },\n medium: { star: 'size-4.5', button: 'size-6' },\n large: { star: 'size-5', button: 'size-6' },\n}\n\ntype StarFill = 'on' | 'preview' | 'off'\n\nfunction starTone(fill: StarFill, disabled: boolean) {\n if (disabled) {\n return fill === 'off'\n ? 'fill-none stroke-gray-a6'\n : 'fill-gray-a7 stroke-gray-a7'\n }\n if (fill === 'on') return 'fill-spark-9 stroke-spark-9'\n if (fill === 'preview') return 'fill-spark-a4 stroke-spark-9'\n return 'fill-none stroke-gray-a9'\n}\n\nfunction captionTone(hasLabel: boolean, hovered: boolean, disabled: boolean) {\n if (disabled) return 'text-gray-a9'\n if (!hasLabel) return 'text-gray-11'\n return hovered ? 'text-spark-11' : 'text-gray-12'\n}\n\nfunction Star({ className }: { className: string }) {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n strokeWidth={1.5}\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n className={cn(\n 'transition-colors motion-reduce:transition-none',\n className,\n )}\n >\n <path d=\"M12.60 3.17 L14.72 8.03 Q15.00 8.67 15.69 8.74 L20.97 9.26 Q22.46 9.40 21.34 10.40 L17.37 13.91 Q16.85 14.38 17.00 15.06 L18.14 20.23 Q18.47 21.70 17.17 20.94 L12.60 18.25 Q12.00 17.90 11.40 18.25 L6.83 20.94 Q5.53 21.70 5.86 20.23 L7.00 15.06 Q7.15 14.38 6.63 13.91 L2.66 10.40 Q1.54 9.40 3.03 9.26 L8.31 8.74 Q9.00 8.67 9.28 8.03 L11.40 3.17 Q12.00 1.80 12.60 3.17Z\" />\n </svg>\n )\n}\n\ntype RatingStarsProps = Omit<\n React.HTMLAttributes<HTMLDivElement>,\n 'defaultValue' | 'onChange'\n>\n\nfunction RatingStars({\n className,\n onPointerLeave,\n onKeyDown,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedByProp,\n ...props\n}: RatingStarsProps) {\n const rating = useRating()\n const { field, ariaDescribedBy, ariaInvalid } = useFieldControl({\n ariaDescribedBy: ariaDescribedByProp,\n })\n const invalid = useFieldSetInvalid()\n const { star: starSize, button: buttonSize } = (\n rating.max > 5 ? compactSizeClasses : sizeClasses\n )[rating.size]\n const interactive = !rating.readOnly && !rating.disabled\n const low = Math.min(rating.value ?? 0, rating.hovered ?? rating.value ?? 0)\n const high = Math.max(rating.value ?? 0, rating.hovered ?? 0)\n\n return (\n <RadioGroupPrimitive<number | null>\n data-slot=\"rating-stars\"\n data-invalid={invalid}\n // a read-only FieldLabel renders the Field's labelId and drops a caller id\n aria-labelledby={\n ariaLabelledBy ?? (field?.readOnly ? field.labelId : undefined)\n }\n aria-describedby={ariaDescribedBy}\n aria-invalid={ariaInvalid}\n value={rating.value}\n onValueChange={(next) => next !== null && rating.setValue(next)}\n readOnly={rating.readOnly}\n disabled={rating.disabled}\n name={rating.name}\n className={cn('flex', className)}\n onPointerLeave={(event) => {\n rating.setHovered(null)\n onPointerLeave?.(event)\n }}\n onKeyDown={(event) => {\n rating.setHovered(null)\n onKeyDown?.(event)\n }}\n {...props}\n >\n {Array.from({ length: rating.max }, (_, index) => {\n const star = index + 1\n const fill: StarFill =\n star <= low ? 'on' : star <= high ? 'preview' : 'off'\n return (\n <RadioPrimitive.Root\n key={star}\n value={star}\n aria-label={rating.labels?.[index] ?? String(star)}\n data-slot=\"rating-star\"\n data-fill={fill}\n // ARIA allows aria-readonly on the radiogroup, which Base UI also sets, not on a radio\n aria-readonly={undefined}\n nativeButton\n render={<button />}\n onPointerEnter={\n interactive ? () => rating.setHovered(star) : undefined\n }\n className={cn(\n // p-0 keeps the box against the UA button padding without preflight;\n // the px floor keeps axe's 24px target size when [data-scaling] shrinks rems\n 'inline-flex min-h-[24px] min-w-[24px] shrink-0 cursor-pointer items-center justify-center rounded-sm border-0 bg-transparent p-0 touch-target-row any-pointer-coarse:min-w-11',\n 'data-disabled:cursor-not-allowed data-readonly:cursor-default',\n buttonSize,\n )}\n >\n <Star className={cn(starSize, starTone(fill, rating.disabled))} />\n </RadioPrimitive.Root>\n )\n })}\n </RadioGroupPrimitive>\n )\n}\n\nconst captionTextSize: Record<RatingSize, string> = {\n small: 'text-[0.8125rem]',\n medium: 'text-sm',\n large: 'text-base',\n}\n\nfunction RatingCaption({\n className,\n children,\n ...props\n}: React.HTMLAttributes<HTMLParagraphElement>) {\n const rating = useRating()\n const shown = rating.hovered ?? rating.value\n const label = shown ? rating.labels?.[shown - 1] : undefined\n\n return (\n <p\n data-slot=\"rating-caption\"\n // the stars already carry each label as their accessible name\n aria-hidden=\"true\"\n // axe skips contrast on inactive text, and the dim tone is the disabled cue\n aria-disabled={rating.disabled || undefined}\n className={cn(\n 'leading-5',\n captionTextSize[rating.size],\n label !== undefined && 'font-medium',\n captionTone(label !== undefined, !!rating.hovered, rating.disabled),\n className,\n )}\n {...props}\n >\n {label ?? children}\n </p>\n )\n}\n\nexport { Rating, RatingCaption, RatingStars }\nexport type { RatingProps, RatingStarsProps }\n"],"mappings":";;;;;;;;;;;AAqBA,MAAM,gBAAgBA,MAAM,cAAyC,IAAI;AAEzE,SAAS,YAAY;CACnB,MAAM,UAAUA,MAAM,WAAW,aAAa;CAC9C,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,6CAA6C;CAC3E,OAAO;AACT;AAmBA,SAAS,OAAO,EACd,OAAO,WACP,eAAe,MACf,eACA,MAAM,GACN,QACA,OAAO,UACP,WAAW,OACX,WAAW,OACX,MACA,WACA,UACA,GAAG,SACW;CACd,MAAM,CAAC,cAAc,mBAAmBA,MAAM,SAAS,YAAY;CACnE,MAAM,CAAC,SAAS,cAAcA,MAAM,SAAwB,IAAI;CAChE,MAAM,QAAQ,cAAc,KAAA,IAAY,eAAe;CAEvD,MAAM,WAAWA,MAAM,aACpB,SAAiB;EAChB,gBAAgB,IAAI;EACpB,gBAAgB,IAAI;CACtB,GACA,CAAC,aAAa,CAChB;CAEA,OACE,iBAAA,GAAA,kBAAA,KAAC,cAAc,UAAf;EACE,OAAO;GACL;GACA;GACA,SAAS,YAAY,WAAW,OAAO;GACvC;GACA;GACA;GACA;GACA;GACA;GACA;EACF;YAEA,iBAAA,GAAA,kBAAA,KAAC,OAAD;GACE,aAAU;GACV,YAAA,GAAA,GAAA,IACE,mEACA,SACF;GACA,GAAI;GAEH;EACE,CAAA;CACiB,CAAA;AAE5B;AAIA,MAAM,cAA+C;CACnD,OAAO;EAAE,MAAM;EAAU,QAAQ;CAAS;CAC1C,QAAQ;EAAE,MAAM;EAAU,QAAQ;CAAS;CAC3C,OAAO;EAAE,MAAM;EAAU,QAAQ;CAAU;AAC7C;AAGA,MAAM,qBAAsD;CAC1D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,QAAQ,OAAO,SAAS,QAAQ,KAAK,KAAA;CAEnD,OACE,iBAAA,GAAA,kBAAA,KAAC,KAAD;EACE,aAAU;EAEV,eAAY;EAEZ,iBAAe,OAAO,YAAY,KAAA;EAClC,YAAA,GAAA,GAAA,IACE,aACA,gBAAgB,OAAO,OACvB,UAAU,KAAA,KAAa,eACvB,YAAY,UAAU,KAAA,GAAW,CAAC,CAAC,OAAO,SAAS,OAAO,QAAQ,GAClE,SACF;EACA,GAAI;YAEH,SAAS;CACT,CAAA;AAEP"}
|
|
1
|
+
{"version":3,"file":"rating.cjs","names":["React","useFieldControl","useFieldSetInvalid","RadioGroupPrimitive","RadioPrimitive"],"sources":["../../src/components/rating.tsx"],"sourcesContent":["import { Radio as RadioPrimitive } from '@base-ui/react/radio'\nimport { RadioGroup as RadioGroupPrimitive } from '@base-ui/react/radio-group'\nimport * as React from 'react'\nimport { cn } from '../utils/cn'\nimport { useFieldControl, useFieldSetInvalid } from './field'\n\ntype RatingSize = 'small' | 'medium' | 'large'\n\ntype RatingContextValue = {\n value: number | null\n setValue: (value: number) => void\n hovered: number | null\n setHovered: (value: number | null) => void\n max: number\n labels?: string[]\n size: RatingSize\n readOnly: boolean\n disabled: boolean\n name?: string\n}\n\nconst RatingContext = React.createContext<RatingContextValue | null>(null)\n\nfunction useRating() {\n const context = React.useContext(RatingContext)\n if (!context) throw new Error('RatingStars and RatingCaption need a Rating')\n return context\n}\n\ninterface RatingProps extends Omit<\n React.HTMLAttributes<HTMLDivElement>,\n 'defaultValue' | 'onChange'\n> {\n /** The chosen star, 1-based. `null` means nothing is chosen yet. */\n value?: number | null\n defaultValue?: number | null\n onValueChange?: (value: number) => void\n max?: number\n /** One label per star: the star's accessible name and the caption text. */\n labels?: string[]\n size?: RatingSize\n readOnly?: boolean\n disabled?: boolean\n name?: string\n}\n\nfunction Rating({\n value: valueProp,\n defaultValue = null,\n onValueChange,\n max = 5,\n labels,\n size = 'medium',\n readOnly = false,\n disabled = false,\n name,\n className,\n children,\n ...props\n}: RatingProps) {\n const [uncontrolled, setUncontrolled] = React.useState(defaultValue)\n const [hovered, setHovered] = React.useState<number | null>(null)\n const value = valueProp === undefined ? uncontrolled : valueProp\n\n const setValue = React.useCallback(\n (next: number) => {\n setUncontrolled(next)\n onValueChange?.(next)\n },\n [onValueChange],\n )\n\n return (\n <RatingContext.Provider\n value={{\n value,\n setValue,\n hovered: readOnly || disabled ? null : hovered,\n setHovered,\n max,\n labels,\n size,\n readOnly,\n disabled,\n name,\n }}\n >\n <div\n data-slot=\"rating\"\n className={cn(\n 'flex flex-col items-start gap-[calc(var(--spark-layout-gap)*1)]',\n className,\n )}\n {...props}\n >\n {children}\n </div>\n </RatingContext.Provider>\n )\n}\n\ntype SizeClasses = { star: string; button: string }\n\nconst sizeClasses: Record<RatingSize, SizeClasses> = {\n small: { star: 'size-4', button: 'size-6' },\n medium: { star: 'size-6', button: 'size-8' },\n large: { star: 'size-8', button: 'size-11' },\n}\n\n// above five stars the row would outgrow narrow panels\nconst compactSizeClasses: Record<RatingSize, SizeClasses> = {\n small: { star: 'size-3.5', button: 'size-6' },\n medium: { star: 'size-4.5', button: 'size-6' },\n large: { star: 'size-5', button: 'size-6' },\n}\n\ntype StarFill = 'on' | 'preview' | 'off'\n\n/** What a custom star icon needs: its 1-based number, whether it is filled, previewed or empty, and the disabled state. */\ntype RatingIconState = { star: number; fill: StarFill; disabled: boolean }\n\nfunction starTone(fill: StarFill, disabled: boolean) {\n if (disabled) {\n return fill === 'off'\n ? 'fill-none stroke-gray-a6'\n : 'fill-gray-a7 stroke-gray-a7'\n }\n if (fill === 'on') return 'fill-spark-9 stroke-spark-9'\n if (fill === 'preview') return 'fill-spark-a4 stroke-spark-9'\n return 'fill-none stroke-gray-a9'\n}\n\n// a custom icon paints with currentColor, in the same steps as the star's fill\nfunction iconTone(fill: StarFill, disabled: boolean) {\n if (disabled) return fill === 'off' ? 'text-gray-a6' : 'text-gray-a8'\n if (fill === 'on') return 'text-spark-9'\n if (fill === 'preview') return 'text-spark-a9'\n return 'text-gray-a8'\n}\n\nfunction captionTone(hasLabel: boolean, hovered: boolean, disabled: boolean) {\n if (disabled) return 'text-gray-a9'\n if (!hasLabel) return 'text-gray-11'\n return hovered ? 'text-spark-11' : 'text-gray-12'\n}\n\nfunction Star({ className }: { className: string }) {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n strokeWidth={1.5}\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n className={cn(\n 'transition-colors motion-reduce:transition-none',\n className,\n )}\n >\n <path d=\"M12.60 3.17 L14.72 8.03 Q15.00 8.67 15.69 8.74 L20.97 9.26 Q22.46 9.40 21.34 10.40 L17.37 13.91 Q16.85 14.38 17.00 15.06 L18.14 20.23 Q18.47 21.70 17.17 20.94 L12.60 18.25 Q12.00 17.90 11.40 18.25 L6.83 20.94 Q5.53 21.70 5.86 20.23 L7.00 15.06 Q7.15 14.38 6.63 13.91 L2.66 10.40 Q1.54 9.40 3.03 9.26 L8.31 8.74 Q9.00 8.67 9.28 8.03 L11.40 3.17 Q12.00 1.80 12.60 3.17Z\" />\n </svg>\n )\n}\n\ntype RatingStarsProps = Omit<\n React.HTMLAttributes<HTMLDivElement>,\n 'defaultValue' | 'onChange'\n> & {\n /** Draws each star's icon in place of the star. The icon paints with `currentColor`, which carries the star's tone. */\n renderIcon?: (state: RatingIconState) => React.ReactNode\n}\n\nfunction RatingStars({\n className,\n onPointerLeave,\n onKeyDown,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedByProp,\n renderIcon,\n ...props\n}: RatingStarsProps) {\n const rating = useRating()\n const { field, ariaDescribedBy, ariaInvalid } = useFieldControl({\n ariaDescribedBy: ariaDescribedByProp,\n })\n const invalid = useFieldSetInvalid()\n const { star: starSize, button: buttonSize } = (\n rating.max > 5 ? compactSizeClasses : sizeClasses\n )[rating.size]\n const interactive = !rating.readOnly && !rating.disabled\n const low = Math.min(rating.value ?? 0, rating.hovered ?? rating.value ?? 0)\n const high = Math.max(rating.value ?? 0, rating.hovered ?? 0)\n\n return (\n <RadioGroupPrimitive<number | null>\n data-slot=\"rating-stars\"\n data-invalid={invalid}\n // a read-only FieldLabel renders the Field's labelId and drops a caller id\n aria-labelledby={\n ariaLabelledBy ?? (field?.readOnly ? field.labelId : undefined)\n }\n aria-describedby={ariaDescribedBy}\n aria-invalid={ariaInvalid}\n value={rating.value}\n onValueChange={(next) => next !== null && rating.setValue(next)}\n readOnly={rating.readOnly}\n disabled={rating.disabled}\n name={rating.name}\n className={cn('flex', className)}\n onPointerLeave={(event) => {\n rating.setHovered(null)\n onPointerLeave?.(event)\n }}\n onKeyDown={(event) => {\n rating.setHovered(null)\n onKeyDown?.(event)\n }}\n {...props}\n >\n {Array.from({ length: rating.max }, (_, index) => {\n const star = index + 1\n const fill: StarFill =\n star <= low ? 'on' : star <= high ? 'preview' : 'off'\n return (\n <RadioPrimitive.Root\n key={star}\n value={star}\n aria-label={rating.labels?.[index] ?? String(star)}\n data-slot=\"rating-star\"\n data-fill={fill}\n // ARIA allows aria-readonly on the radiogroup, which Base UI also sets, not on a radio\n aria-readonly={undefined}\n nativeButton\n render={<button />}\n onPointerEnter={\n interactive ? () => rating.setHovered(star) : undefined\n }\n className={cn(\n // p-0 keeps the box against the UA button padding without preflight;\n // the px floor keeps axe's 24px target size when [data-scaling] shrinks rems\n 'inline-flex min-h-[24px] min-w-[24px] shrink-0 cursor-pointer items-center justify-center rounded-sm border-0 bg-transparent p-0 touch-target-row any-pointer-coarse:min-w-11',\n 'data-disabled:cursor-not-allowed data-readonly:cursor-default',\n buttonSize,\n )}\n >\n {renderIcon ? (\n <span\n aria-hidden=\"true\"\n data-slot=\"rating-icon\"\n className={cn(\n 'inline-flex items-center justify-center transition-colors motion-reduce:transition-none [&_svg]:size-full',\n starSize,\n iconTone(fill, rating.disabled),\n )}\n >\n {renderIcon({ star, fill, disabled: rating.disabled })}\n </span>\n ) : (\n <Star className={cn(starSize, starTone(fill, rating.disabled))} />\n )}\n </RadioPrimitive.Root>\n )\n })}\n </RadioGroupPrimitive>\n )\n}\n\nconst captionTextSize: Record<RatingSize, string> = {\n small: 'text-[0.8125rem]',\n medium: 'text-sm',\n large: 'text-base',\n}\n\nfunction RatingCaption({\n className,\n children,\n ...props\n}: React.HTMLAttributes<HTMLParagraphElement>) {\n const rating = useRating()\n const shown = rating.hovered ?? rating.value\n const label = shown ? rating.labels?.[shown - 1] : undefined\n\n return (\n <p\n data-slot=\"rating-caption\"\n // the stars already carry each label as their accessible name\n aria-hidden=\"true\"\n // axe skips contrast on inactive text, and the dim tone is the disabled cue\n aria-disabled={rating.disabled || undefined}\n className={cn(\n 'leading-5',\n captionTextSize[rating.size],\n label !== undefined && 'font-medium',\n captionTone(label !== undefined, !!rating.hovered, rating.disabled),\n className,\n )}\n {...props}\n >\n {label ?? children}\n </p>\n )\n}\n\nexport { Rating, RatingCaption, RatingStars }\nexport type { RatingIconState, RatingProps, RatingStarsProps }\n"],"mappings":";;;;;;;;;;;AAqBA,MAAM,gBAAgBA,MAAM,cAAyC,IAAI;AAEzE,SAAS,YAAY;CACnB,MAAM,UAAUA,MAAM,WAAW,aAAa;CAC9C,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,6CAA6C;CAC3E,OAAO;AACT;AAmBA,SAAS,OAAO,EACd,OAAO,WACP,eAAe,MACf,eACA,MAAM,GACN,QACA,OAAO,UACP,WAAW,OACX,WAAW,OACX,MACA,WACA,UACA,GAAG,SACW;CACd,MAAM,CAAC,cAAc,mBAAmBA,MAAM,SAAS,YAAY;CACnE,MAAM,CAAC,SAAS,cAAcA,MAAM,SAAwB,IAAI;CAChE,MAAM,QAAQ,cAAc,KAAA,IAAY,eAAe;CAEvD,MAAM,WAAWA,MAAM,aACpB,SAAiB;EAChB,gBAAgB,IAAI;EACpB,gBAAgB,IAAI;CACtB,GACA,CAAC,aAAa,CAChB;CAEA,OACE,iBAAA,GAAA,kBAAA,K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X.Element;
|
|
34
|
-
type
|
|
34
|
+
type StarFill = 'on' | 'preview' | 'off';
|
|
35
|
+
/** What a custom star icon needs: its 1-based number, whether it is filled, previewed or empty, and the disabled state. */
|
|
36
|
+
type RatingIconState = {
|
|
37
|
+
star: number;
|
|
38
|
+
fill: StarFill;
|
|
39
|
+
disabled: boolean;
|
|
40
|
+
};
|
|
41
|
+
type RatingStarsProps = Omit<React$1.HTMLAttributes<HTMLDivElement>, 'defaultValue' | 'onChange'> & {
|
|
42
|
+
/** Draws each star's icon in place of the star. The icon paints with `currentColor`, which carries the star's tone. */renderIcon?: (state: RatingIconState) => React$1.ReactNode;
|
|
43
|
+
};
|
|
35
44
|
declare function RatingStars({
|
|
36
45
|
className,
|
|
37
46
|
onPointerLeave,
|
|
38
47
|
onKeyDown,
|
|
39
48
|
'aria-labelledby': ariaLabelledBy,
|
|
40
49
|
'aria-describedby': ariaDescribedByProp,
|
|
50
|
+
renderIcon,
|
|
41
51
|
...props
|
|
42
52
|
}: RatingStarsProps): import("react/jsx-runtime").JSX.Element;
|
|
43
53
|
declare function RatingCaption({
|
|
@@ -46,5 +56,5 @@ declare function RatingCaption({
|
|
|
46
56
|
...props
|
|
47
57
|
}: React$1.HTMLAttributes<HTMLParagraphElement>): import("react/jsx-runtime").JSX.Element;
|
|
48
58
|
//#endregion
|
|
49
|
-
export { Rating, RatingCaption, type RatingProps, RatingStars, type RatingStarsProps };
|
|
59
|
+
export { Rating, RatingCaption, type RatingIconState, type RatingProps, RatingStars, type RatingStarsProps };
|
|
50
60
|
//# sourceMappingURL=rating.d.cts.map
|
|
@@ -31,13 +31,23 @@ declare function Rating({
|
|
|
31
31
|
children,
|
|
32
32
|
...props
|
|
33
33
|
}: RatingProps): import("react/jsx-runtime").JSX.Element;
|
|
34
|
-
type
|
|
34
|
+
type StarFill = 'on' | 'preview' | 'off';
|
|
35
|
+
/** What a custom star icon needs: its 1-based number, whether it is filled, previewed or empty, and the disabled state. */
|
|
36
|
+
type RatingIconState = {
|
|
37
|
+
star: number;
|
|
38
|
+
fill: StarFill;
|
|
39
|
+
disabled: boolean;
|
|
40
|
+
};
|
|
41
|
+
type RatingStarsProps = Omit<React$1.HTMLAttributes<HTMLDivElement>, 'defaultValue' | 'onChange'> & {
|
|
42
|
+
/** Draws each star's icon in place of the star. The icon paints with `currentColor`, which carries the star's tone. */renderIcon?: (state: RatingIconState) => React$1.ReactNode;
|
|
43
|
+
};
|
|
35
44
|
declare function RatingStars({
|
|
36
45
|
className,
|
|
37
46
|
onPointerLeave,
|
|
38
47
|
onKeyDown,
|
|
39
48
|
'aria-labelledby': ariaLabelledBy,
|
|
40
49
|
'aria-describedby': ariaDescribedByProp,
|
|
50
|
+
renderIcon,
|
|
41
51
|
...props
|
|
42
52
|
}: RatingStarsProps): import("react/jsx-runtime").JSX.Element;
|
|
43
53
|
declare function RatingCaption({
|
|
@@ -46,5 +56,5 @@ declare function RatingCaption({
|
|
|
46
56
|
...props
|
|
47
57
|
}: React$1.HTMLAttributes<HTMLParagraphElement>): import("react/jsx-runtime").JSX.Element;
|
|
48
58
|
//#endregion
|
|
49
|
-
export { Rating, RatingCaption, type RatingProps, RatingStars, type RatingStarsProps };
|
|
59
|
+
export { Rating, RatingCaption, type RatingIconState, type RatingProps, RatingStars, type RatingStarsProps };
|
|
50
60
|
//# sourceMappingURL=rating.d.ts.map
|
|
@@ -75,6 +75,12 @@ function starTone(fill, disabled) {
|
|
|
75
75
|
if (fill === "preview") return "fill-spark-a4 stroke-spark-9";
|
|
76
76
|
return "fill-none stroke-gray-a9";
|
|
77
77
|
}
|
|
78
|
+
function iconTone(fill, disabled) {
|
|
79
|
+
if (disabled) return fill === "off" ? "text-gray-a6" : "text-gray-a8";
|
|
80
|
+
if (fill === "on") return "text-spark-9";
|
|
81
|
+
if (fill === "preview") return "text-spark-a9";
|
|
82
|
+
return "text-gray-a8";
|
|
83
|
+
}
|
|
78
84
|
function captionTone(hasLabel, hovered, disabled) {
|
|
79
85
|
if (disabled) return "text-gray-a9";
|
|
80
86
|
if (!hasLabel) return "text-gray-11";
|
|
@@ -91,7 +97,7 @@ function Star({ className }) {
|
|
|
91
97
|
children: /* @__PURE__ */ jsx("path", { d: "M12.60 3.17 L14.72 8.03 Q15.00 8.67 15.69 8.74 L20.97 9.26 Q22.46 9.40 21.34 10.40 L17.37 13.91 Q16.85 14.38 17.00 15.06 L18.14 20.23 Q18.47 21.70 17.17 20.94 L12.60 18.25 Q12.00 17.90 11.40 18.25 L6.83 20.94 Q5.53 21.70 5.86 20.23 L7.00 15.06 Q7.15 14.38 6.63 13.91 L2.66 10.40 Q1.54 9.40 3.03 9.26 L8.31 8.74 Q9.00 8.67 9.28 8.03 L11.40 3.17 Q12.00 1.80 12.60 3.17Z" })
|
|
92
98
|
});
|
|
93
99
|
}
|
|
94
|
-
function RatingStars({ className, onPointerLeave, onKeyDown, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedByProp, ...props }) {
|
|
100
|
+
function RatingStars({ className, onPointerLeave, onKeyDown, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedByProp, renderIcon, ...props }) {
|
|
95
101
|
const rating = useRating();
|
|
96
102
|
const { field, ariaDescribedBy, ariaInvalid } = useFieldControl({ ariaDescribedBy: ariaDescribedByProp });
|
|
97
103
|
const invalid = useFieldSetInvalid();
|
|
@@ -133,7 +139,16 @@ function RatingStars({ className, onPointerLeave, onKeyDown, "aria-labelledby":
|
|
|
133
139
|
render: /* @__PURE__ */ jsx("button", {}),
|
|
134
140
|
onPointerEnter: interactive ? () => rating.setHovered(star) : void 0,
|
|
135
141
|
className: cn("inline-flex min-h-[24px] min-w-[24px] shrink-0 cursor-pointer items-center justify-center rounded-sm border-0 bg-transparent p-0 touch-target-row any-pointer-coarse:min-w-11", "data-disabled:cursor-not-allowed data-readonly:cursor-default", buttonSize),
|
|
136
|
-
children: /* @__PURE__ */ jsx(
|
|
142
|
+
children: renderIcon ? /* @__PURE__ */ jsx("span", {
|
|
143
|
+
"aria-hidden": "true",
|
|
144
|
+
"data-slot": "rating-icon",
|
|
145
|
+
className: cn("inline-flex items-center justify-center transition-colors motion-reduce:transition-none [&_svg]:size-full", starSize, iconTone(fill, rating.disabled)),
|
|
146
|
+
children: renderIcon({
|
|
147
|
+
star,
|
|
148
|
+
fill,
|
|
149
|
+
disabled: rating.disabled
|
|
150
|
+
})
|
|
151
|
+
}) : /* @__PURE__ */ jsx(Star, { className: cn(starSize, starTone(fill, rating.disabled)) })
|
|
137
152
|
}, star);
|
|
138
153
|
})
|
|
139
154
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rating.js","names":["React","RadioGroupPrimitive","RadioPrimitive"],"sources":["../../src/components/rating.tsx"],"sourcesContent":["import { Radio as RadioPrimitive } from '@base-ui/react/radio'\nimport { RadioGroup as RadioGroupPrimitive } from '@base-ui/react/radio-group'\nimport * as React from 'react'\nimport { cn } from '../utils/cn'\nimport { useFieldControl, useFieldSetInvalid } from './field'\n\ntype RatingSize = 'small' | 'medium' | 'large'\n\ntype RatingContextValue = {\n value: number | null\n setValue: (value: number) => void\n hovered: number | null\n setHovered: (value: number | null) => void\n max: number\n labels?: string[]\n size: RatingSize\n readOnly: boolean\n disabled: boolean\n name?: string\n}\n\nconst RatingContext = React.createContext<RatingContextValue | null>(null)\n\nfunction useRating() {\n const context = React.useContext(RatingContext)\n if (!context) throw new Error('RatingStars and RatingCaption need a Rating')\n return context\n}\n\ninterface RatingProps extends Omit<\n React.HTMLAttributes<HTMLDivElement>,\n 'defaultValue' | 'onChange'\n> {\n /** The chosen star, 1-based. `null` means nothing is chosen yet. */\n value?: number | null\n defaultValue?: number | null\n onValueChange?: (value: number) => void\n max?: number\n /** One label per star: the star's accessible name and the caption text. */\n labels?: string[]\n size?: RatingSize\n readOnly?: boolean\n disabled?: boolean\n name?: string\n}\n\nfunction Rating({\n value: valueProp,\n defaultValue = null,\n onValueChange,\n max = 5,\n labels,\n size = 'medium',\n readOnly = false,\n disabled = false,\n name,\n className,\n children,\n ...props\n}: RatingProps) {\n const [uncontrolled, setUncontrolled] = React.useState(defaultValue)\n const [hovered, setHovered] = React.useState<number | null>(null)\n const value = valueProp === undefined ? uncontrolled : valueProp\n\n const setValue = React.useCallback(\n (next: number) => {\n setUncontrolled(next)\n onValueChange?.(next)\n },\n [onValueChange],\n )\n\n return (\n <RatingContext.Provider\n value={{\n value,\n setValue,\n hovered: readOnly || disabled ? null : hovered,\n setHovered,\n max,\n labels,\n size,\n readOnly,\n disabled,\n name,\n }}\n >\n <div\n data-slot=\"rating\"\n className={cn(\n 'flex flex-col items-start gap-[calc(var(--spark-layout-gap)*1)]',\n className,\n )}\n {...props}\n >\n {children}\n </div>\n </RatingContext.Provider>\n )\n}\n\ntype SizeClasses = { star: string; button: string }\n\nconst sizeClasses: Record<RatingSize, SizeClasses> = {\n small: { star: 'size-4', button: 'size-6' },\n medium: { star: 'size-6', button: 'size-8' },\n large: { star: 'size-8', button: 'size-11' },\n}\n\n// above five stars the row would outgrow narrow panels\nconst compactSizeClasses: Record<RatingSize, SizeClasses> = {\n small: { star: 'size-3.5', button: 'size-6' },\n medium: { star: 'size-4.5', button: 'size-6' },\n large: { star: 'size-5', button: 'size-6' },\n}\n\ntype StarFill = 'on' | 'preview' | 'off'\n\nfunction starTone(fill: StarFill, disabled: boolean) {\n if (disabled) {\n return fill === 'off'\n ? 'fill-none stroke-gray-a6'\n : 'fill-gray-a7 stroke-gray-a7'\n }\n if (fill === 'on') return 'fill-spark-9 stroke-spark-9'\n if (fill === 'preview') return 'fill-spark-a4 stroke-spark-9'\n return 'fill-none stroke-gray-a9'\n}\n\nfunction captionTone(hasLabel: boolean, hovered: boolean, disabled: boolean) {\n if (disabled) return 'text-gray-a9'\n if (!hasLabel) return 'text-gray-11'\n return hovered ? 'text-spark-11' : 'text-gray-12'\n}\n\nfunction Star({ className }: { className: string }) {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n strokeWidth={1.5}\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n className={cn(\n 'transition-colors motion-reduce:transition-none',\n className,\n )}\n >\n <path d=\"M12.60 3.17 L14.72 8.03 Q15.00 8.67 15.69 8.74 L20.97 9.26 Q22.46 9.40 21.34 10.40 L17.37 13.91 Q16.85 14.38 17.00 15.06 L18.14 20.23 Q18.47 21.70 17.17 20.94 L12.60 18.25 Q12.00 17.90 11.40 18.25 L6.83 20.94 Q5.53 21.70 5.86 20.23 L7.00 15.06 Q7.15 14.38 6.63 13.91 L2.66 10.40 Q1.54 9.40 3.03 9.26 L8.31 8.74 Q9.00 8.67 9.28 8.03 L11.40 3.17 Q12.00 1.80 12.60 3.17Z\" />\n </svg>\n )\n}\n\ntype RatingStarsProps = Omit<\n React.HTMLAttributes<HTMLDivElement>,\n 'defaultValue' | 'onChange'\n>\n\nfunction RatingStars({\n className,\n onPointerLeave,\n onKeyDown,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedByProp,\n ...props\n}: RatingStarsProps) {\n const rating = useRating()\n const { field, ariaDescribedBy, ariaInvalid } = useFieldControl({\n ariaDescribedBy: ariaDescribedByProp,\n })\n const invalid = useFieldSetInvalid()\n const { star: starSize, button: buttonSize } = (\n rating.max > 5 ? compactSizeClasses : sizeClasses\n )[rating.size]\n const interactive = !rating.readOnly && !rating.disabled\n const low = Math.min(rating.value ?? 0, rating.hovered ?? rating.value ?? 0)\n const high = Math.max(rating.value ?? 0, rating.hovered ?? 0)\n\n return (\n <RadioGroupPrimitive<number | null>\n data-slot=\"rating-stars\"\n data-invalid={invalid}\n // a read-only FieldLabel renders the Field's labelId and drops a caller id\n aria-labelledby={\n ariaLabelledBy ?? (field?.readOnly ? field.labelId : undefined)\n }\n aria-describedby={ariaDescribedBy}\n aria-invalid={ariaInvalid}\n value={rating.value}\n onValueChange={(next) => next !== null && rating.setValue(next)}\n readOnly={rating.readOnly}\n disabled={rating.disabled}\n name={rating.name}\n className={cn('flex', className)}\n onPointerLeave={(event) => {\n rating.setHovered(null)\n onPointerLeave?.(event)\n }}\n onKeyDown={(event) => {\n rating.setHovered(null)\n onKeyDown?.(event)\n }}\n {...props}\n >\n {Array.from({ length: rating.max }, (_, index) => {\n const star = index + 1\n const fill: StarFill =\n star <= low ? 'on' : star <= high ? 'preview' : 'off'\n return (\n <RadioPrimitive.Root\n key={star}\n value={star}\n aria-label={rating.labels?.[index] ?? String(star)}\n data-slot=\"rating-star\"\n data-fill={fill}\n // ARIA allows aria-readonly on the radiogroup, which Base UI also sets, not on a radio\n aria-readonly={undefined}\n nativeButton\n render={<button />}\n onPointerEnter={\n interactive ? () => rating.setHovered(star) : undefined\n }\n className={cn(\n // p-0 keeps the box against the UA button padding without preflight;\n // the px floor keeps axe's 24px target size when [data-scaling] shrinks rems\n 'inline-flex min-h-[24px] min-w-[24px] shrink-0 cursor-pointer items-center justify-center rounded-sm border-0 bg-transparent p-0 touch-target-row any-pointer-coarse:min-w-11',\n 'data-disabled:cursor-not-allowed data-readonly:cursor-default',\n buttonSize,\n )}\n >\n <Star className={cn(starSize, starTone(fill, rating.disabled))} />\n </RadioPrimitive.Root>\n )\n })}\n </RadioGroupPrimitive>\n )\n}\n\nconst captionTextSize: Record<RatingSize, string> = {\n small: 'text-[0.8125rem]',\n medium: 'text-sm',\n large: 'text-base',\n}\n\nfunction RatingCaption({\n className,\n children,\n ...props\n}: React.HTMLAttributes<HTMLParagraphElement>) {\n const rating = useRating()\n const shown = rating.hovered ?? rating.value\n const label = shown ? rating.labels?.[shown - 1] : undefined\n\n return (\n <p\n data-slot=\"rating-caption\"\n // the stars already carry each label as their accessible name\n aria-hidden=\"true\"\n // axe skips contrast on inactive text, and the dim tone is the disabled cue\n aria-disabled={rating.disabled || undefined}\n className={cn(\n 'leading-5',\n captionTextSize[rating.size],\n label !== undefined && 'font-medium',\n captionTone(label !== undefined, !!rating.hovered, rating.disabled),\n className,\n )}\n {...props}\n >\n {label ?? children}\n </p>\n )\n}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tB,iBAAiB,KAAK;EACxB;EACA,YAAY,UAAU;GACpB,OAAO,WAAW,IAAI;GACtB,YAAY,KAAK;EACnB;EACA,GAAI;YAEH,MAAM,KAAK,EAAE,QAAQ,OAAO,IAAI,IAAI,GAAG,UAAU;GAChD,MAAM,OAAO,QAAQ;GACrB,MAAM,OACJ,QAAQ,MAAM,OAAO,QAAQ,OAAO,YAAY;GAClD,OACE,oBAACC,MAAe,MAAhB;IAEE,OAAO;IACP,cAAY,OAAO,SAAS,UAAU,OAAO,IAAI;IACjD,aAAU;IACV,aAAW;IAEX,iBAAe,KAAA;IACf,cAAA;IACA,QAAQ,oBAAC,UAAD,CAAS,CAAA;IACjB,gBACE,oBAAoB,OAAO,WAAW,IAAI,IAAI,KAAA;IAEhD,WAAW,GAGT,iLACA,iEACA,UACF;cAEA,oBAAC,MAAD,EAAM,WAAW,GAAG,UAAU,SAAS,MAAM,OAAO,QAAQ,CAAC,EAAI,CAAA;GAC9C,GArBd,IAqBc;EAEzB,CAAC;CACkB,CAAA;AAEzB;AAEA,MAAM,kBAA8C;CAClD,OAAO;CACP,QAAQ;CACR,OAAO;AACT;AAEA,SAAS,cAAc,EACrB,WACA,UACA,GAAG,SAC0C;CAC7C,MAAM,SAAS,UAAU;CACzB,MAAM,QAAQ,OAAO,WAAW,OAAO;CACvC,MAAM,QAAQ,QAAQ,OAAO,SAAS,QAAQ,KAAK,KAAA;CAEnD,OACE,oBAAC,KAAD;EACE,aAAU;EAEV,eAAY;EAEZ,iBAAe,OAAO,YAAY,KAAA;EAClC,WAAW,GACT,aACA,gBAAgB,OAAO,OACvB,UAAU,KAAA,KAAa,eACvB,YAAY,UAAU,KAAA,GAAW,CAAC,CAAC,OAAO,SAAS,OAAO,QAAQ,GAClE,SACF;EACA,GAAI;YAEH,SAAS;CACT,CAAA;AAEP"}
|
|
1
|
+
{"version":3,"file":"rating.js","names":["React","RadioGroupPrimitive","RadioPrimitive"],"sources":["../../src/components/rating.tsx"],"sourcesContent":["import { Radio as RadioPrimitive } from '@base-ui/react/radio'\nimport { RadioGroup as RadioGroupPrimitive } from '@base-ui/react/radio-group'\nimport * as React from 'react'\nimport { cn } from '../utils/cn'\nimport { useFieldControl, useFieldSetInvalid } from './field'\n\ntype RatingSize = 'small' | 'medium' | 'large'\n\ntype RatingContextValue = {\n value: number | null\n setValue: (value: number) => void\n hovered: number | null\n setHovered: (value: number | null) => void\n max: number\n labels?: string[]\n size: RatingSize\n readOnly: boolean\n disabled: boolean\n name?: string\n}\n\nconst RatingContext = React.createContext<RatingContextValue | null>(null)\n\nfunction useRating() {\n const context = React.useContext(RatingContext)\n if (!context) throw new Error('RatingStars and RatingCaption need a Rating')\n return context\n}\n\ninterface RatingProps extends Omit<\n React.HTMLAttributes<HTMLDivElement>,\n 'defaultValue' | 'onChange'\n> {\n /** The chosen star, 1-based. `null` means nothing is chosen yet. */\n value?: number | null\n defaultValue?: number | null\n onValueChange?: (value: number) => void\n max?: number\n /** One label per star: the star's accessible name and the caption text. */\n labels?: string[]\n size?: RatingSize\n readOnly?: boolean\n disabled?: boolean\n name?: string\n}\n\nfunction Rating({\n value: valueProp,\n defaultValue = null,\n onValueChange,\n max = 5,\n labels,\n size = 'medium',\n readOnly = false,\n disabled = false,\n name,\n className,\n children,\n ...props\n}: RatingProps) {\n const [uncontrolled, setUncontrolled] = React.useState(defaultValue)\n const [hovered, setHovered] = React.useState<number | null>(null)\n const value = valueProp === undefined ? uncontrolled : valueProp\n\n const setValue = React.useCallback(\n (next: number) => {\n setUncontrolled(next)\n onValueChange?.(next)\n },\n [onValueChange],\n )\n\n return (\n <RatingContext.Provider\n value={{\n value,\n setValue,\n hovered: readOnly || disabled ? null : hovered,\n setHovered,\n max,\n labels,\n size,\n readOnly,\n disabled,\n name,\n }}\n >\n <div\n data-slot=\"rating\"\n className={cn(\n 'flex flex-col items-start gap-[calc(var(--spark-layout-gap)*1)]',\n className,\n )}\n {...props}\n >\n {children}\n </div>\n </RatingContext.Provider>\n )\n}\n\ntype SizeClasses = { star: string; button: string }\n\nconst sizeClasses: Record<RatingSize, SizeClasses> = {\n small: { star: 'size-4', button: 'size-6' },\n medium: { star: 'size-6', button: 'size-8' },\n large: { star: 'size-8', button: 'size-11' },\n}\n\n// above five stars the row would outgrow narrow panels\nconst compactSizeClasses: Record<RatingSize, SizeClasses> = {\n small: { star: 'size-3.5', button: 'size-6' },\n medium: { star: 'size-4.5', button: 'size-6' },\n large: { star: 'size-5', button: 'size-6' },\n}\n\ntype StarFill = 'on' | 'preview' | 'off'\n\n/** What a custom star icon needs: its 1-based number, whether it is filled, previewed or empty, and the disabled state. */\ntype RatingIconState = { star: number; fill: StarFill; disabled: boolean }\n\nfunction starTone(fill: StarFill, disabled: boolean) {\n if (disabled) {\n return fill === 'off'\n ? 'fill-none stroke-gray-a6'\n : 'fill-gray-a7 stroke-gray-a7'\n }\n if (fill === 'on') return 'fill-spark-9 stroke-spark-9'\n if (fill === 'preview') return 'fill-spark-a4 stroke-spark-9'\n return 'fill-none stroke-gray-a9'\n}\n\n// a custom icon paints with currentColor, in the same steps as the star's fill\nfunction iconTone(fill: StarFill, disabled: boolean) {\n if (disabled) return fill === 'off' ? 'text-gray-a6' : 'text-gray-a8'\n if (fill === 'on') return 'text-spark-9'\n if (fill === 'preview') return 'text-spark-a9'\n return 'text-gray-a8'\n}\n\nfunction captionTone(hasLabel: boolean, hovered: boolean, disabled: boolean) {\n if (disabled) return 'text-gray-a9'\n if (!hasLabel) return 'text-gray-11'\n return hovered ? 'text-spark-11' : 'text-gray-12'\n}\n\nfunction Star({ className }: { className: string }) {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n strokeWidth={1.5}\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n className={cn(\n 'transition-colors motion-reduce:transition-none',\n className,\n )}\n >\n <path d=\"M12.60 3.17 L14.72 8.03 Q15.00 8.67 15.69 8.74 L20.97 9.26 Q22.46 9.40 21.34 10.40 L17.37 13.91 Q16.85 14.38 17.00 15.06 L18.14 20.23 Q18.47 21.70 17.17 20.94 L12.60 18.25 Q12.00 17.90 11.40 18.25 L6.83 20.94 Q5.53 21.70 5.86 20.23 L7.00 15.06 Q7.15 14.38 6.63 13.91 L2.66 10.40 Q1.54 9.40 3.03 9.26 L8.31 8.74 Q9.00 8.67 9.28 8.03 L11.40 3.17 Q12.00 1.80 12.60 3.17Z\" />\n </svg>\n )\n}\n\ntype RatingStarsProps = Omit<\n React.HTMLAttributes<HTMLDivElement>,\n 'defaultValue' | 'onChange'\n> & {\n /** Draws each star's icon in place of the star. The icon paints with `currentColor`, which carries the star's tone. */\n renderIcon?: (state: RatingIconState) => React.ReactNode\n}\n\nfunction RatingStars({\n className,\n onPointerLeave,\n onKeyDown,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedByProp,\n renderIcon,\n ...props\n}: RatingStarsProps) {\n const rating = useRating()\n const { field, ariaDescribedBy, ariaInvalid } = useFieldControl({\n ariaDescribedBy: ariaDescribedByProp,\n })\n const invalid = useFieldSetInvalid()\n const { star: starSize, button: buttonSize } = (\n rating.max > 5 ? compactSizeClasses : sizeClasses\n )[rating.size]\n const interactive = !rating.readOnly && !rating.disabled\n const low = Math.min(rating.value ?? 0, rating.hovered ?? rating.value ?? 0)\n const high = Math.max(rating.value ?? 0, rating.hovered ?? 0)\n\n return (\n <RadioGroupPrimitive<number | null>\n data-slot=\"rating-stars\"\n data-invalid={invalid}\n // a read-only FieldLabel renders the Field's labelId and drops a caller id\n aria-labelledby={\n ariaLabelledBy ?? (field?.readOnly ? field.labelId : undefined)\n }\n aria-describedby={ariaDescribedBy}\n aria-invalid={ariaInvalid}\n value={rating.value}\n onValueChange={(next) => next !== null && rating.setValue(next)}\n readOnly={rating.readOnly}\n disabled={rating.disabled}\n name={rating.name}\n className={cn('flex', className)}\n onPointerLeave={(event) => {\n rating.setHovered(null)\n onPointerLeave?.(event)\n }}\n onKeyDown={(event) => {\n rating.setHovered(null)\n onKeyDown?.(event)\n }}\n {...props}\n >\n {Array.from({ length: rating.max }, (_, index) => {\n const star = index + 1\n const fill: StarFill =\n star <= low ? 'on' : star <= high ? 'preview' : 'off'\n return (\n <RadioPrimitive.Root\n key={star}\n value={star}\n aria-label={rating.labels?.[index] ?? String(star)}\n data-slot=\"rating-star\"\n data-fill={fill}\n // ARIA allows aria-readonly on the radiogroup, which Base UI also sets, not on a radio\n aria-readonly={undefined}\n nativeButton\n render={<button />}\n onPointerEnter={\n interactive ? () => rating.setHovered(star) : undefined\n }\n className={cn(\n // p-0 keeps the box against the UA button padding without preflight;\n // the px floor keeps axe's 24px target size when [data-scaling] shrinks rems\n 'inline-flex min-h-[24px] min-w-[24px] shrink-0 cursor-pointer items-center justify-center rounded-sm border-0 bg-transparent p-0 touch-target-row any-pointer-coarse:min-w-11',\n 'data-disabled:cursor-not-allowed data-readonly:cursor-default',\n buttonSize,\n )}\n >\n {renderIcon ? (\n <span\n aria-hidden=\"true\"\n data-slot=\"rating-icon\"\n className={cn(\n 'inline-flex items-center justify-center transition-colors motion-reduce:transition-none [&_svg]:size-full',\n starSize,\n iconTone(fill, rating.disabled),\n )}\n >\n {renderIcon({ star, fill, disabled: rating.disabled })}\n </span>\n ) : (\n <Star className={cn(starSize, starTone(fill, rating.disabled))} />\n )}\n </RadioPrimitive.Root>\n )\n })}\n </RadioGroupPrimitive>\n )\n}\n\nconst captionTextSize: Record<RatingSize, string> = {\n small: 'text-[0.8125rem]',\n medium: 'text-sm',\n large: 'text-base',\n}\n\nfunction RatingCaption({\n className,\n children,\n ...props\n}: React.HTMLAttributes<HTMLParagraphElement>) {\n const rating = useRating()\n const shown = rating.hovered ?? rating.value\n const label = shown ? rating.labels?.[shown - 1] : undefined\n\n return (\n <p\n data-slot=\"rating-caption\"\n // the stars already carry each label as their accessible name\n aria-hidden=\"true\"\n // axe skips contrast on inactive text, and the dim tone is the disabled cue\n aria-disabled={rating.disabled || undefined}\n className={cn(\n 'leading-5',\n captionTextSize[rating.size],\n label !== undefined && 'font-medium',\n captionTone(label !== undefined, !!rating.hovered, rating.disabled),\n className,\n )}\n {...props}\n >\n {label ?? children}\n </p>\n )\n}\n\nexport { Rating, RatingCaption, RatingStars }\nexport type { RatingIconState, RatingProps, RatingStarsProps }\n"],"mappings":";;;;;;;;AAqBA,MAAM,gBAAgBA,QAAM,cAAyC,IAAI;AAEzE,SAAS,YAAY;CACnB,MAAM,UAAUA,QAAM,WAAW,aAAa;CAC9C,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,6CAA6C;CAC3E,OAAO;AACT;AAmBA,SAAS,OAAO,EACd,OAAO,WACP,eAAe,MACf,eACA,MAAM,GACN,QACA,OAAO,UACP,WAAW,OACX,WAAW,OACX,MACA,WACA,UACA,GAAG,SACW;CACd,MAAM,CAAC,cAAc,mBAAmBA,QAAM,SAAS,YAAY;CACnE,MAAM,CAAC,SAAS,cAAcA,QAAM,SAAwB,IAAI;CAChE,MAAM,QAAQ,cAAc,KAAA,IAAY,eAAe;CAEvD,MAAM,WAAWA,QAAM,aACpB,SAAiB;EAChB,gBAAgB,IAAI;EACpB,gBAAgB,IAAI;CACtB,GACA,CAAC,aAAa,CAChB;CAEA,OACE,oBAAC,cAAc,UAAf;EACE,OAAO;GACL;GACA;GACA,SAAS,YAAY,WAAW,OAAO;GACvC;GACA;GACA;GACA;GACA;GACA;GACA;EACF;YAEA,oBAAC,OAAD;GACE,aAAU;GACV,WAAW,GACT,mEACA,SACF;GACA,GAAI;GAEH;EACE,CAAA;CACiB,CAAA;AAE5B;AAIA,MAAM,cAA+C;CACnD,OAAO;EAAE,MAAM;EAAU,QAAQ;CAAS;CAC1C,QAAQ;EAAE,MAAM;EAAU,QAAQ;CAAS;CAC3C,OAAO;EAAE,MAAM;EAAU,QAAQ;CAAU;AAC7C;AAGA,MAAM,qBAAsD;CAC1D,OAAO;EAAE,MAAM;EAAY,QAAQ;CAAS;CAC5C,QAAQ;EAAE,MAAM;EAAY,QAAQ;CAAS;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B,MAAM,QAAQ,OAAO,WAAW,OAAO;CACvC,MAAM,QAAQ,QAAQ,OAAO,SAAS,QAAQ,KAAK,KAAA;CAEnD,OACE,oBAAC,KAAD;EACE,aAAU;EAEV,eAAY;EAEZ,iBAAe,OAAO,YAAY,KAAA;EAClC,WAAW,GACT,aACA,gBAAgB,OAAO,OACvB,UAAU,KAAA,KAAa,eACvB,YAAY,UAAU,KAAA,GAAW,CAAC,CAAC,OAAO,SAAS,OAAO,QAAQ,GAClE,SACF;EACA,GAAI;YAEH,SAAS;CACT,CAAA;AAEP"}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"use client";
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
4
|
const require_chunk = require("../chunk-DY84GLCh.cjs");
|
|
5
|
+
const require_lib_input_box_variants = require("../lib/input-box-variants.cjs");
|
|
5
6
|
const require_components_theme = require("./theme.cjs");
|
|
6
7
|
const require_components_field = require("./field.cjs");
|
|
7
|
-
const require_lib_input_box_variants = require("../lib/input-box-variants.cjs");
|
|
8
8
|
let react = require("react");
|
|
9
9
|
react = require_chunk.__toESM(react);
|
|
10
10
|
let _epilot_spark_icons = require("@epilot/spark-icons");
|
|
@@ -39,11 +39,12 @@ function SelectTrigger({ className, size = "default", variant, id: idProp, child
|
|
|
39
39
|
});
|
|
40
40
|
const inset = !variant && field?.labelPosition === "inset";
|
|
41
41
|
const isGhost = inputStyle === "ghost" || inset;
|
|
42
|
+
const floating = !variant && field?.labelPosition === "floating";
|
|
42
43
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_base_ui_react_select.Select.Trigger, {
|
|
43
44
|
"data-slot": "select-trigger",
|
|
44
45
|
"data-size": size,
|
|
45
46
|
id,
|
|
46
|
-
className: (0, cn.cn)(TRIGGER_BASE, field ? "w-full" : "w-fit", !isGhost && TRIGGER_SIZE[size], require_lib_input_box_variants.boxChrome[isGhost ? "ghost" : inputStyle][inputColor], inset && "focus-visible:outline-hidden", className),
|
|
47
|
+
className: (0, cn.cn)(TRIGGER_BASE, field ? "w-full" : "w-fit", !isGhost && TRIGGER_SIZE[size], require_lib_input_box_variants.boxChrome[isGhost ? "ghost" : inputStyle][inputColor], inset && "focus-visible:outline-hidden", floating && (0, cn.cn)(require_lib_input_box_variants.floatingChrome(inputStyle), inputStyle !== "outlined" && "[&_[data-slot=select-chevron]]:-translate-y-2", "data-placeholder:text-transparent data-placeholder:focus-visible:text-gray-placeholder data-popup-open:text-gray-placeholder"), className),
|
|
47
48
|
"aria-invalid": ariaInvalid,
|
|
48
49
|
...props,
|
|
49
50
|
"aria-describedby": ariaDescribedBy,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select.cjs","names":["SelectPrimitive","useFieldControl","boxChrome","KeyboardArrowDown","Close","PortalTheme","Check"],"sources":["../../src/components/select.tsx"],"sourcesContent":["'use client'\n\nimport { Select as SelectPrimitive } from '@base-ui/react/select'\nimport { Check, Close, KeyboardArrowDown } from '@epilot/spark-icons'\nimport * as React from 'react'\nimport { boxChrome } from '../lib/input-box-variants'\nimport type { SparkInputStyle } from '../lib/theme-types'\nimport { cn } from '../utils/cn'\nimport { useFieldControl } from './field'\nimport { PortalTheme } from './theme'\n\n// bare re-export: Root renders no element and its props are generic over Value\nconst Select = SelectPrimitive.Root\n\nfunction SelectGroup({\n className,\n ...props\n}: React.ComponentProps<typeof SelectPrimitive.Group>) {\n return (\n <SelectPrimitive.Group\n data-slot=\"select-group\"\n className={cn('scroll-my-1 p-1', className)}\n {...props}\n />\n )\n}\n\nfunction SelectValue({\n ...props\n}: React.ComponentProps<typeof SelectPrimitive.Value>) {\n return <SelectPrimitive.Value data-slot=\"select-value\" {...props} />\n}\n\nconst TRIGGER_BASE =\n 'relative flex items-center justify-between gap-1.5 rounded-md px-3 text-base whitespace-nowrap text-gray transition-colors select-none data-placeholder:text-gray-placeholder disabled:cursor-not-allowed disabled:text-gray-disabled disabled:data-placeholder:text-gray-disabled *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5 motion-reduce:transition-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*=size-])]:size-4'\n\n// box-chrome sizing only — a ghost/inset trigger sizes via boxChrome.ghost's\n// GHOST_UNDERLINE (h-10), matching Input's underline row exactly (no competing\n// height utility). `min-h-[2.75rem]` is a literal, non-knob-scaled WCAG 2.5.5\n// floor; `sm` stays visually compact but restores the floor via an invisible\n// `before:` hit overlay rather than growing the box, with `my-1` to keep that\n// overlay out of an ancestor scroller's overflow.\nconst TRIGGER_SIZE = {\n default: 'h-11 min-h-[2.75rem]',\n sm: \"my-1 h-9 before:absolute before:inset-x-0 before:top-1/2 before:min-h-[2.75rem] before:-translate-y-1/2 before:content-['']\",\n} as const\n\nfunction SelectTrigger({\n className,\n size = 'default',\n variant,\n id: idProp,\n children,\n 'aria-describedby': ariaDescribedByProp,\n ...props\n}: React.ComponentProps<typeof SelectPrimitive.Trigger> & {\n size?: 'sm' | 'default'\n // input-style override; falls back to Field / <Theme>, then soft (like Input)\n variant?: SparkInputStyle\n}) {\n const { field, id, ariaDescribedBy, ariaInvalid, inputStyle, inputColor } =\n useFieldControl({\n id: idProp,\n ariaDescribedBy: ariaDescribedByProp,\n variant,\n })\n // inside an inset field the shell is the box, so the trigger goes bare\n // (underline row), matching Input's inset chrome; an explicit variant keeps\n // the box even inside an inset field (mirrors Input)\n const inset = !variant && field?.labelPosition === 'inset'\n const isGhost = inputStyle === 'ghost' || inset\n\n return (\n <SelectPrimitive.Trigger\n data-slot=\"select-trigger\"\n data-size={size}\n id={id}\n className={cn(\n TRIGGER_BASE,\n // fills the field shell like an Input; sizes to content when standalone\n field ? 'w-full' : 'w-fit',\n !isGhost && TRIGGER_SIZE[size],\n boxChrome[isGhost ? 'ghost' : inputStyle][inputColor],\n inset && 'focus-visible:outline-hidden',\n className,\n )}\n aria-invalid={ariaInvalid}\n {...props}\n aria-describedby={ariaDescribedBy}\n >\n {children}\n <SelectPrimitive.Icon\n className=\"pointer-events-none flex text-gray-light\"\n data-slot=\"select-chevron\"\n >\n <KeyboardArrowDown className=\"[--spark-icon-size:14px]\" />\n </SelectPrimitive.Icon>\n </SelectPrimitive.Trigger>\n )\n}\n\n// px floor: axe target-size flags it below 24px at small scalings because it overlays\n// the trigger; autocomplete.tsx ICON_BUTTON sits in flow and does not need one\nconst CLEAR_BUTTON =\n \"relative inline-flex size-6 min-h-[24px] min-w-[24px] shrink-0 items-center justify-center rounded-sm p-0 text-gray-light transition-colors hover:text-gray 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\n// wraps SelectTrigger since Base UI ships no Select.Clear and the trigger is a\n// native <button> — the clear sits beside it, not nested inside it\nfunction SelectTriggerGroup({\n className,\n ...props\n}: React.ComponentProps<'div'>) {\n return (\n <div\n data-slot=\"select-trigger-group\"\n className={cn(\n 'relative inline-flex w-fit items-center [&_[data-slot=select-chevron]]:absolute [&_[data-slot=select-chevron]]:right-3 has-[[data-slot=select-trigger][data-disabled]]:[&_[data-slot=select-clear]]:hidden has-[[data-slot=select-trigger][data-placeholder]]:[&_[data-slot=select-clear]]:hidden has-[[data-slot=select-trigger][data-readonly]]:[&_[data-slot=select-clear]]:hidden [&_[data-slot=select-trigger]]:pr-[calc(--spacing(8)+max(--spacing(6),24px))]',\n className,\n )}\n {...props}\n />\n )\n}\n\nfunction SelectClear({\n className,\n children,\n onClick,\n ...props\n}: React.ComponentProps<'button'>) {\n return (\n <button\n data-slot=\"select-clear\"\n type=\"button\"\n className={cn(CLEAR_BUTTON, 'absolute right-8', className)}\n onClick={(event) => {\n onClick?.(event)\n // clearing hides this button (data-placeholder returns), so keyboard\n // focus would otherwise drop to <body> — return it to the trigger\n event.currentTarget\n .closest('[data-slot=\"select-trigger-group\"]')\n ?.querySelector<HTMLElement>('[data-slot=\"select-trigger\"]')\n ?.focus()\n }}\n {...props}\n >\n {children ?? <Close aria-hidden className=\"[--spark-icon-size:14px]\" />}\n </button>\n )\n}\n\ntype SelectContentProps = React.ComponentProps<typeof SelectPrimitive.Popup> &\n Pick<\n SelectPrimitive.Positioner.Props,\n 'align' | 'alignOffset' | 'side' | 'sideOffset' | 'alignItemWithTrigger'\n > &\n Pick<SelectPrimitive.Portal.Props, 'container'>\n\nfunction SelectContent({\n className,\n children,\n align = 'start',\n alignOffset,\n side,\n sideOffset = 4,\n // drop the menu below the trigger (left-aligned) like a conventional form\n // dropdown; the native-<select>-style overlay (Base UI's inherited default)\n // shifts the popup to align item text with trigger text, exposing a sliver of\n // the trigger's fill at the edge. Opt back in per instance if you want it.\n alignItemWithTrigger = false,\n container,\n ...props\n}: SelectContentProps) {\n return (\n <SelectPrimitive.Portal container={container}>\n <PortalTheme>\n <SelectPrimitive.Positioner\n align={align}\n alignItemWithTrigger={alignItemWithTrigger}\n alignOffset={alignOffset}\n side={side}\n sideOffset={sideOffset}\n >\n <SelectPrimitive.Popup\n data-slot=\"select-content\"\n data-align-trigger={alignItemWithTrigger}\n className={cn(\n // match the trigger's width (never narrower) so the drop-below menu\n // lines up under it; --anchor-width is the trigger width, floored at\n // 9rem for very narrow triggers\n 'relative isolate z-50 max-h-(--available-height) min-w-[max(9rem,var(--anchor-width))] origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-lg border border-gray-a1 bg-gray-1 text-gray-a12 shadow-lg dark:bg-gray-3 [[data-high-contrast]_&]:border-gray-a11',\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 'data-[align-trigger=true]:transition-none',\n className,\n )}\n {...props}\n >\n <SelectScrollUpButton />\n <SelectPrimitive.List>{children}</SelectPrimitive.List>\n <SelectScrollDownButton />\n </SelectPrimitive.Popup>\n </SelectPrimitive.Positioner>\n </PortalTheme>\n </SelectPrimitive.Portal>\n )\n}\n\nfunction SelectLabel({\n className,\n ...props\n}: React.ComponentProps<typeof SelectPrimitive.GroupLabel>) {\n return (\n <SelectPrimitive.GroupLabel\n data-slot=\"select-label\"\n className={cn(\n 'px-1.5 py-1 text-xs text-gray-light [[data-high-contrast]_&]:text-gray-a12',\n className,\n )}\n {...props}\n />\n )\n}\n\nfunction SelectItem({\n className,\n children,\n ...props\n}: React.ComponentProps<typeof SelectPrimitive.Item>) {\n return (\n <SelectPrimitive.Item\n data-slot=\"select-item\"\n className={cn(\n 'relative flex w-full cursor-default items-center gap-1.5 rounded-sm py-1.5 pr-8 pl-1.5 text-sm text-gray outline-hidden transition-colors select-none touch-target-row data-disabled:pointer-events-none data-disabled:opacity-50 data-highlighted:bg-gray-a3 motion-reduce:transition-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*=size-])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2',\n className,\n )}\n {...props}\n >\n <span className=\"pointer-events-none absolute right-2 flex size-4 items-center justify-center\">\n <SelectPrimitive.ItemIndicator>\n <Check className=\"[--spark-icon-size:11px]\" />\n </SelectPrimitive.ItemIndicator>\n </span>\n <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>\n </SelectPrimitive.Item>\n )\n}\n\n// plain div, not Select.Separator: role=\"separator\" isn't a permitted child of a\n// listbox (aria-required-children), and the divider is decorative — the groups\n// carry the semantics. Hidden from assistive tech.\nfunction SelectSeparator({ className, ...props }: React.ComponentProps<'div'>) {\n return (\n <div\n aria-hidden=\"true\"\n data-slot=\"select-separator\"\n className={cn(\n 'pointer-events-none -mx-1 my-1 h-px bg-gray-a3 [[data-high-contrast]_&]:bg-gray-a6',\n className,\n )}\n {...props}\n />\n )\n}\n\nfunction SelectScrollUpButton({\n className,\n ...props\n}: React.ComponentProps<typeof SelectPrimitive.ScrollUpArrow>) {\n return (\n <SelectPrimitive.ScrollUpArrow\n data-slot=\"select-scroll-up-button\"\n className={cn(\n 'top-0 z-10 flex w-full cursor-default items-center justify-center bg-gray-1 py-1 dark:bg-gray-3 [&_svg:not([class*=size-])]:size-4',\n className,\n )}\n {...props}\n >\n <KeyboardArrowDown className=\"rotate-180 [--spark-icon-size:14px]\" />\n </SelectPrimitive.ScrollUpArrow>\n )\n}\n\nfunction SelectScrollDownButton({\n className,\n ...props\n}: React.ComponentProps<typeof SelectPrimitive.ScrollDownArrow>) {\n return (\n <SelectPrimitive.ScrollDownArrow\n data-slot=\"select-scroll-down-button\"\n className={cn(\n 'bottom-0 z-10 flex w-full cursor-default items-center justify-center bg-gray-1 py-1 dark:bg-gray-3 [&_svg:not([class*=size-])]:size-4',\n className,\n )}\n {...props}\n >\n <KeyboardArrowDown className=\"[--spark-icon-size:14px]\" />\n </SelectPrimitive.ScrollDownArrow>\n )\n}\n\nexport {\n Select,\n SelectClear,\n SelectContent,\n SelectGroup,\n SelectItem,\n SelectLabel,\n SelectScrollDownButton,\n SelectScrollUpButton,\n SelectSeparator,\n SelectTrigger,\n SelectTriggerGroup,\n SelectValue,\n}\n"],"mappings":";;;;;;;;;;;;;;AAYA,MAAM,SAASA,sBAAAA,OAAgB;AAE/B,SAAS,YAAY,EACnB,WACA,GAAG,SACkD;CACrD,OACE,iBAAA,GAAA,kBAAA,KAACA,sBAAAA,OAAgB,OAAjB;EACE,aAAU;EACV,YAAA,GAAA,GAAA,IAAc,mBAAmB,SAAS;EAC1C,GAAI;CACL,CAAA;AAEL;AAEA,SAAS,YAAY,EACnB,GAAG,SACkD;CACrD,OAAO,iBAAA,GAAA,kBAAA,KAACA,sBAAAA,OAAgB,OAAjB;EAAuB,aAAU;EAAe,GAAI;CAAQ,CAAA;AACrE;AAEA,MAAM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GAAA,kBAAA,KAACA,sBAAAA,OAAgB,eAAjB,EAAA,UACE,iBAAA,GAAA,kBAAA,KAACM,oBAAAA,OAAD,EAAO,WAAU,2BAA4B,CAAA,EAChB,CAAA;EAC3B,CAAA,GACN,iBAAA,GAAA,kBAAA,KAACN,sBAAAA,OAAgB,UAAjB,EAA2B,SAAmC,CAAA,CAC1C;;AAE1B;AAKA,SAAS,gBAAgB,EAAE,WAAW,GAAG,SAAsC;CAC7E,OACE,iBAAA,GAAA,kBAAA,KAAC,OAAD;EACE,eAAY;EACZ,aAAU;EACV,YAAA,GAAA,GAAA,IACE,sFACA,SACF;EACA,GAAI;CACL,CAAA;AAEL;AAEA,SAAS,qBAAqB,EAC5B,WACA,GAAG,SAC0D;CAC7D,OACE,iBAAA,GAAA,kBAAA,KAACA,sBAAAA,OAAgB,eAAjB;EACE,aAAU;EACV,YAAA,GAAA,GAAA,IACE,sIACA,SACF;EACA,GAAI;YAEJ,iBAAA,GAAA,kBAAA,KAACG,oBAAAA,mBAAD,EAAmB,WAAU,sCAAuC,CAAA;CACvC,CAAA;AAEnC;AAEA,SAAS,uBAAuB,EAC9B,WACA,GAAG,SAC4D;CAC/D,OACE,iBAAA,GAAA,kBAAA,KAACH,sBAAAA,OAAgB,iBAAjB;EACE,aAAU;EACV,YAAA,GAAA,GAAA,IACE,yIACA,SACF;EACA,GAAI;YAEJ,iBAAA,GAAA,kBAAA,KAACG,oBAAAA,mBAAD,EAAmB,WAAU,2BAA4B,CAAA;CAC1B,CAAA;AAErC"}
|
|
1
|
+
{"version":3,"file":"select.cjs","names":["SelectPrimitive","useFieldControl","boxChrome","floatingChrome","KeyboardArrowDown","Close","PortalTheme","Check"],"sources":["../../src/components/select.tsx"],"sourcesContent":["'use client'\n\nimport { Select as SelectPrimitive } from '@base-ui/react/select'\nimport { Check, Close, KeyboardArrowDown } from '@epilot/spark-icons'\nimport * as React from 'react'\nimport { boxChrome, floatingChrome } from '../lib/input-box-variants'\nimport type { SparkInputStyle } from '../lib/theme-types'\nimport { cn } from '../utils/cn'\nimport { useFieldControl } from './field'\nimport { PortalTheme } from './theme'\n\n// bare re-export: Root renders no element and its props are generic over Value\nconst Select = SelectPrimitive.Root\n\nfunction SelectGroup({\n className,\n ...props\n}: React.ComponentProps<typeof SelectPrimitive.Group>) {\n return (\n <SelectPrimitive.Group\n data-slot=\"select-group\"\n className={cn('scroll-my-1 p-1', className)}\n {...props}\n />\n )\n}\n\nfunction SelectValue({\n ...props\n}: React.ComponentProps<typeof SelectPrimitive.Value>) {\n return <SelectPrimitive.Value data-slot=\"select-value\" {...props} />\n}\n\nconst TRIGGER_BASE =\n 'relative flex items-center justify-between gap-1.5 rounded-md px-3 text-base whitespace-nowrap text-gray transition-colors select-none data-placeholder:text-gray-placeholder disabled:cursor-not-allowed disabled:text-gray-disabled disabled:data-placeholder:text-gray-disabled *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5 motion-reduce:transition-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*=size-])]:size-4'\n\n// box-chrome sizing only — a ghost/inset trigger sizes via boxChrome.ghost's\n// GHOST_UNDERLINE (h-10), matching Input's underline row exactly (no competing\n// height utility). `min-h-[2.75rem]` is a literal, non-knob-scaled WCAG 2.5.5\n// floor; `sm` stays visually compact but restores the floor via an invisible\n// `before:` hit overlay rather than growing the box, with `my-1` to keep that\n// overlay out of an ancestor scroller's overflow.\nconst TRIGGER_SIZE = {\n default: 'h-11 min-h-[2.75rem]',\n sm: \"my-1 h-9 before:absolute before:inset-x-0 before:top-1/2 before:min-h-[2.75rem] before:-translate-y-1/2 before:content-['']\",\n} as const\n\nfunction SelectTrigger({\n className,\n size = 'default',\n variant,\n id: idProp,\n children,\n 'aria-describedby': ariaDescribedByProp,\n ...props\n}: React.ComponentProps<typeof SelectPrimitive.Trigger> & {\n size?: 'sm' | 'default'\n // input-style override; falls back to Field / <Theme>, then soft (like Input)\n variant?: SparkInputStyle\n}) {\n const { field, id, ariaDescribedBy, ariaInvalid, inputStyle, inputColor } =\n useFieldControl({\n id: idProp,\n ariaDescribedBy: ariaDescribedByProp,\n variant,\n })\n // inside an inset field the shell is the box, so the trigger goes bare\n // (underline row), matching Input's inset chrome; an explicit variant keeps\n // the box even inside an inset field (mirrors Input)\n const inset = !variant && field?.labelPosition === 'inset'\n const isGhost = inputStyle === 'ghost' || inset\n const floating = !variant && field?.labelPosition === 'floating'\n\n return (\n <SelectPrimitive.Trigger\n data-slot=\"select-trigger\"\n data-size={size}\n id={id}\n className={cn(\n TRIGGER_BASE,\n // fills the field shell like an Input; sizes to content when standalone\n field ? 'w-full' : 'w-fit',\n !isGhost && TRIGGER_SIZE[size],\n boxChrome[isGhost ? 'ghost' : inputStyle][inputColor],\n inset && 'focus-visible:outline-hidden',\n floating &&\n cn(\n floatingChrome(inputStyle),\n inputStyle !== 'outlined' &&\n '[&_[data-slot=select-chevron]]:-translate-y-2',\n 'data-placeholder:text-transparent data-placeholder:focus-visible:text-gray-placeholder data-popup-open:text-gray-placeholder',\n ),\n className,\n )}\n aria-invalid={ariaInvalid}\n {...props}\n aria-describedby={ariaDescribedBy}\n >\n {children}\n <SelectPrimitive.Icon\n className=\"pointer-events-none flex text-gray-light\"\n data-slot=\"select-chevron\"\n >\n <KeyboardArrowDown className=\"[--spark-icon-size:14px]\" />\n </SelectPrimitive.Icon>\n </SelectPrimitive.Trigger>\n )\n}\n\n// px floor: axe target-size flags it below 24px at small scalings because it overlays\n// the trigger; autocomplete.tsx ICON_BUTTON sits in flow and does not need one\nconst CLEAR_BUTTON =\n \"relative inline-flex size-6 min-h-[24px] min-w-[24px] shrink-0 items-center justify-center rounded-sm p-0 text-gray-light transition-colors hover:text-gray 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\n// wraps SelectTrigger since Base UI ships no Select.Clear and the trigger is a\n// native <button> — the clear sits beside it, not nested inside it\nfunction SelectTriggerGroup({\n className,\n ...props\n}: React.ComponentProps<'div'>) {\n return (\n <div\n data-slot=\"select-trigger-group\"\n className={cn(\n 'relative inline-flex w-fit items-center [&_[data-slot=select-chevron]]:absolute [&_[data-slot=select-chevron]]:right-3 has-[[data-slot=select-trigger][data-disabled]]:[&_[data-slot=select-clear]]:hidden has-[[data-slot=select-trigger][data-placeholder]]:[&_[data-slot=select-clear]]:hidden has-[[data-slot=select-trigger][data-readonly]]:[&_[data-slot=select-clear]]:hidden [&_[data-slot=select-trigger]]:pr-[calc(--spacing(8)+max(--spacing(6),24px))]',\n className,\n )}\n {...props}\n />\n )\n}\n\nfunction SelectClear({\n className,\n children,\n onClick,\n ...props\n}: React.ComponentProps<'button'>) {\n return (\n <button\n data-slot=\"select-clear\"\n type=\"button\"\n className={cn(CLEAR_BUTTON, 'absolute right-8', className)}\n onClick={(event) => {\n onClick?.(event)\n // clearing hides this button (data-placeholder returns), so keyboard\n // focus would otherwise drop to <body> — return it to the trigger\n event.currentTarget\n .closest('[data-slot=\"select-trigger-group\"]')\n ?.querySelector<HTMLElement>('[data-slot=\"select-trigger\"]')\n ?.focus()\n }}\n {...props}\n >\n {children ?? <Close aria-hidden className=\"[--spark-icon-size:14px]\" />}\n </button>\n )\n}\n\ntype SelectContentProps = React.ComponentProps<typeof SelectPrimitive.Popup> &\n Pick<\n SelectPrimitive.Positioner.Props,\n 'align' | 'alignOffset' | 'side' | 'sideOffset' | 'alignItemWithTrigger'\n > &\n Pick<SelectPrimitive.Portal.Props, 'container'>\n\nfunction SelectContent({\n className,\n children,\n align = 'start',\n alignOffset,\n side,\n sideOffset = 4,\n // drop the menu below the trigger (left-aligned) like a conventional form\n // dropdown; the native-<select>-style overlay (Base UI's inherited default)\n // shifts the popup to align item text with trigger text, exposing a sliver of\n // the trigger's fill at the edge. Opt back in per instance if you want it.\n alignItemWithTrigger = false,\n container,\n ...props\n}: SelectContentProps) {\n return (\n <SelectPrimitive.Portal container={container}>\n <PortalTheme>\n <SelectPrimitive.Positioner\n align={align}\n alignItemWithTrigger={alignItemWithTrigger}\n alignOffset={alignOffset}\n side={side}\n sideOffset={sideOffset}\n >\n <SelectPrimitive.Popup\n data-slot=\"select-content\"\n data-align-trigger={alignItemWithTrigger}\n className={cn(\n // match the trigger's width (never narrower) so the drop-below menu\n // lines up under it; --anchor-width is the trigger width, floored at\n // 9rem for very narrow triggers\n 'relative isolate z-50 max-h-(--available-height) min-w-[max(9rem,var(--anchor-width))] origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-lg border border-gray-a1 bg-gray-1 text-gray-a12 shadow-lg dark:bg-gray-3 [[data-high-contrast]_&]:border-gray-a11',\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 'data-[align-trigger=true]:transition-none',\n className,\n )}\n {...props}\n >\n <SelectScrollUpButton />\n <SelectPrimitive.List>{children}</SelectPrimitive.List>\n <SelectScrollDownButton />\n </SelectPrimitive.Popup>\n </SelectPrimitive.Positioner>\n </PortalTheme>\n </SelectPrimitive.Portal>\n )\n}\n\nfunction SelectLabel({\n className,\n ...props\n}: React.ComponentProps<typeof SelectPrimitive.GroupLabel>) {\n return (\n <SelectPrimitive.GroupLabel\n data-slot=\"select-label\"\n className={cn(\n 'px-1.5 py-1 text-xs text-gray-light [[data-high-contrast]_&]:text-gray-a12',\n className,\n )}\n {...props}\n />\n )\n}\n\nfunction SelectItem({\n className,\n children,\n ...props\n}: React.ComponentProps<typeof SelectPrimitive.Item>) {\n return (\n <SelectPrimitive.Item\n data-slot=\"select-item\"\n className={cn(\n 'relative flex w-full cursor-default items-center gap-1.5 rounded-sm py-1.5 pr-8 pl-1.5 text-sm text-gray outline-hidden transition-colors select-none touch-target-row data-disabled:pointer-events-none data-disabled:opacity-50 data-highlighted:bg-gray-a3 motion-reduce:transition-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*=size-])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2',\n className,\n )}\n {...props}\n >\n <span className=\"pointer-events-none absolute right-2 flex size-4 items-center justify-center\">\n <SelectPrimitive.ItemIndicator>\n <Check className=\"[--spark-icon-size:11px]\" />\n </SelectPrimitive.ItemIndicator>\n </span>\n <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>\n </SelectPrimitive.Item>\n )\n}\n\n// plain div, not Select.Separator: role=\"separator\" isn't a permitted child of a\n// listbox (aria-required-children), and the divider is decorative — the groups\n// carry the semantics. Hidden from assistive tech.\nfunction SelectSeparator({ className, ...props }: React.ComponentProps<'div'>) {\n return (\n <div\n aria-hidden=\"true\"\n data-slot=\"select-separator\"\n className={cn(\n 'pointer-events-none -mx-1 my-1 h-px bg-gray-a3 [[data-high-contrast]_&]:bg-gray-a6',\n className,\n )}\n {...props}\n />\n )\n}\n\nfunction SelectScrollUpButton({\n className,\n ...props\n}: React.ComponentProps<typeof SelectPrimitive.ScrollUpArrow>) {\n return (\n <SelectPrimitive.ScrollUpArrow\n data-slot=\"select-scroll-up-button\"\n className={cn(\n 'top-0 z-10 flex w-full cursor-default items-center justify-center bg-gray-1 py-1 dark:bg-gray-3 [&_svg:not([class*=size-])]:size-4',\n className,\n )}\n {...props}\n >\n <KeyboardArrowDown className=\"rotate-180 [--spark-icon-size:14px]\" />\n </SelectPrimitive.ScrollUpArrow>\n )\n}\n\nfunction SelectScrollDownButton({\n className,\n ...props\n}: React.ComponentProps<typeof SelectPrimitive.ScrollDownArrow>) {\n return (\n <SelectPrimitive.ScrollDownArrow\n data-slot=\"select-scroll-down-button\"\n className={cn(\n 'bottom-0 z-10 flex w-full cursor-default items-center justify-center bg-gray-1 py-1 dark:bg-gray-3 [&_svg:not([class*=size-])]:size-4',\n className,\n )}\n {...props}\n >\n <KeyboardArrowDown className=\"[--spark-icon-size:14px]\" />\n </SelectPrimitive.ScrollDownArrow>\n )\n}\n\nexport {\n Select,\n SelectClear,\n SelectContent,\n SelectGroup,\n SelectItem,\n SelectLabel,\n SelectScrollDownButton,\n SelectScrollUpButton,\n SelectSeparator,\n SelectTrigger,\n SelectTriggerGroup,\n SelectValue,\n}\n"],"mappings":";;;;;;;;;;;;;;AAYA,MAAM,SAASA,sBAAAA,OAAgB;AAE/B,SAAS,YAAY,EACnB,WACA,GAAG,SACkD;CACrD,OACE,iBAAA,GAAA,kBAAA,KAACA,sBAAAA,OAAgB,OAAjB;EACE,aAAU;EACV,YAAA,GAAA,GAAA,IAAc,mBAAmB,SAAS;EAC1C,GAAI;CACL,CAAA;AAEL;AAEA,SAAS,YAAY,EACnB,GAAG,SACkD;CACrD,OAAO,iBAAA,GAAA,kBAAA,KAACA,sBAAAA,OAAgB,OAAjB;EAAuB,aAAU;EAAe,GAAI;CAAQ,CAAA;AACrE;AAEA,MAAM,eACJ;AAQF,MAAM,eAAe;CACnB,SAAS;CACT,IAAI;AACN;AAEA,SAAS,cAAc,EACrB,WACA,OAAO,WACP,SACA,IAAI,QACJ,UACA,oBAAoB,qBACpB,GAAG,SAKF;CACD,MAAM,EAAE,OAAO,IAAI,iBAAiB,aAAa,YAAY,eAC3DC,yBAAAA,gBAAgB;EACd,IAAI;EACJ,iBAAiB;EACjB;CACF,CAAC;CAIH,MAAM,QAAQ,CAAC,WAAW,OAAO,kBAAkB;CACnD,MAAM,UAAU,eAAe,WAAW;CAC1C,MAAM,WAAW,CAAC,WAAW,OAAO,kBAAkB;CAEtD,OACE,iBAAA,GAAA,kBAAA,MAACD,sBAAAA,OAAgB,SAAjB;EACE,aAAU;EACV,aAAW;EACP;EACJ,YAAA,GAAA,GAAA,IACE,cAEA,QAAQ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ACF;EACA,GAAI;CACL,CAAA;AAEL;AAEA,SAAS,qBAAqB,EAC5B,WACA,GAAG,SAC0D;CAC7D,OACE,iBAAA,GAAA,kBAAA,KAACA,sBAAAA,OAAgB,eAAjB;EACE,aAAU;EACV,YAAA,GAAA,GAAA,IACE,sIACA,SACF;EACA,GAAI;YAEJ,iBAAA,GAAA,kBAAA,KAACI,oBAAAA,mBAAD,EAAmB,WAAU,sCAAuC,CAAA;CACvC,CAAA;AAEnC;AAEA,SAAS,uBAAuB,EAC9B,WACA,GAAG,SAC4D;CAC/D,OACE,iBAAA,GAAA,kBAAA,KAACJ,sBAAAA,OAAgB,iBAAjB;EACE,aAAU;EACV,YAAA,GAAA,GAAA,IACE,yIACA,SACF;EACA,GAAI;YAEJ,iBAAA,GAAA,kBAAA,KAACI,oBAAAA,mBAAD,EAAmB,WAAU,2BAA4B,CAAA;CAC1B,CAAA;AAErC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
"use client";
|
|
3
3
|
import { cn } from "../utils/cn.js";
|
|
4
|
+
import { boxChrome, floatingChrome } from "../lib/input-box-variants.js";
|
|
4
5
|
import { PortalTheme } from "./theme.js";
|
|
5
6
|
import { useFieldControl } from "./field.js";
|
|
6
|
-
import { boxChrome } from "../lib/input-box-variants.js";
|
|
7
7
|
import "react";
|
|
8
8
|
import { Check, Close, KeyboardArrowDown } from "@epilot/spark-icons";
|
|
9
9
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -36,11 +36,12 @@ function SelectTrigger({ className, size = "default", variant, id: idProp, child
|
|
|
36
36
|
});
|
|
37
37
|
const inset = !variant && field?.labelPosition === "inset";
|
|
38
38
|
const isGhost = inputStyle === "ghost" || inset;
|
|
39
|
+
const floating = !variant && field?.labelPosition === "floating";
|
|
39
40
|
return /* @__PURE__ */ jsxs(Select$1.Trigger, {
|
|
40
41
|
"data-slot": "select-trigger",
|
|
41
42
|
"data-size": size,
|
|
42
43
|
id,
|
|
43
|
-
className: cn(TRIGGER_BASE, field ? "w-full" : "w-fit", !isGhost && TRIGGER_SIZE[size], boxChrome[isGhost ? "ghost" : inputStyle][inputColor], inset && "focus-visible:outline-hidden", className),
|
|
44
|
+
className: cn(TRIGGER_BASE, field ? "w-full" : "w-fit", !isGhost && TRIGGER_SIZE[size], boxChrome[isGhost ? "ghost" : inputStyle][inputColor], inset && "focus-visible:outline-hidden", floating && cn(floatingChrome(inputStyle), inputStyle !== "outlined" && "[&_[data-slot=select-chevron]]:-translate-y-2", "data-placeholder:text-transparent data-placeholder:focus-visible:text-gray-placeholder data-popup-open:text-gray-placeholder"), className),
|
|
44
45
|
"aria-invalid": ariaInvalid,
|
|
45
46
|
...props,
|
|
46
47
|
"aria-describedby": ariaDescribedBy,
|