@spark-ui/components 15.1.0 → 16.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/rating/Rating.d.ts +17 -12
- package/dist/rating/RatingStar.d.ts +12 -3
- package/dist/rating/index.js +1 -1
- package/dist/rating/index.js.map +1 -1
- package/dist/rating/index.mjs +210 -163
- package/dist/rating/index.mjs.map +1 -1
- package/dist/rating/types.d.ts +2 -1
- package/dist/rating/utils.d.ts +1 -2
- package/dist/rating-display/RatingDisplay.d.ts +26 -0
- package/dist/rating-display/RatingDisplayContext.d.ts +12 -0
- package/dist/rating-display/RatingDisplayCount.d.ts +12 -0
- package/dist/rating-display/RatingDisplayStar.d.ts +16 -0
- package/dist/rating-display/RatingDisplayStars.d.ts +22 -0
- package/dist/rating-display/RatingDisplayValue.d.ts +13 -0
- package/dist/rating-display/index.d.mts +14 -0
- package/dist/rating-display/index.d.ts +14 -0
- package/dist/rating-display/index.js +2 -0
- package/dist/rating-display/index.js.map +1 -0
- package/dist/rating-display/index.mjs +172 -0
- package/dist/rating-display/index.mjs.map +1 -0
- package/dist/rating-display/types.d.ts +1 -0
- package/dist/rating-display/utils.d.ts +10 -0
- package/dist/switch/index.js +1 -1
- package/dist/switch/index.js.map +1 -1
- package/dist/switch/index.mjs +1 -1
- package/dist/switch/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/rating/Rating.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { ComponentPropsWithRef, PropsWithChildren } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { RatingValue } from './types';
|
|
3
3
|
export interface RatingProps extends PropsWithChildren<ComponentPropsWithRef<'div'>> {
|
|
4
4
|
/**
|
|
5
5
|
* Use the `defaultValue` prop to set the default value of the input, on a from 0 to 5.
|
|
6
6
|
*
|
|
7
7
|
* Use this when you want to use it in an uncontrolled manner
|
|
8
8
|
*/
|
|
9
|
-
defaultValue?:
|
|
9
|
+
defaultValue?: RatingValue;
|
|
10
10
|
/**
|
|
11
11
|
* The value is the number of the rating selected, on a scale from 0 to 5.
|
|
12
12
|
*
|
|
13
13
|
* Use this when you want to use it in a controlled manner,
|
|
14
14
|
* in conjunction with the `onValueChange` prop
|
|
15
15
|
*/
|
|
16
|
-
value?:
|
|
16
|
+
value?: RatingValue;
|
|
17
17
|
/**
|
|
18
18
|
* Event handler called when the value changes.
|
|
19
19
|
*/
|
|
20
|
-
onValueChange?: (value:
|
|
20
|
+
onValueChange?: (value: RatingValue) => void;
|
|
21
21
|
/**
|
|
22
22
|
* Sets the component as interactive or not.
|
|
23
23
|
* @default undefined
|
|
@@ -29,24 +29,29 @@ export interface RatingProps extends PropsWithChildren<ComponentPropsWithRef<'di
|
|
|
29
29
|
*/
|
|
30
30
|
disabled?: boolean;
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
33
|
-
* @default
|
|
32
|
+
* When true, indicates that the user must select a rating before form submission.
|
|
33
|
+
* @default false
|
|
34
34
|
*/
|
|
35
|
-
|
|
35
|
+
required?: boolean;
|
|
36
36
|
/**
|
|
37
|
-
* Name of the underlying input.
|
|
37
|
+
* Name of the underlying hidden input (for form submission).
|
|
38
38
|
* @default undefined
|
|
39
39
|
*/
|
|
40
40
|
name?: string;
|
|
41
41
|
/**
|
|
42
|
-
* id of the underlying input.
|
|
42
|
+
* id of the underlying hidden input.
|
|
43
43
|
* @default undefined
|
|
44
44
|
*/
|
|
45
45
|
id?: string;
|
|
46
46
|
/**
|
|
47
|
-
* aria-label of the
|
|
47
|
+
* aria-label of the radiogroup.
|
|
48
48
|
* @default undefined
|
|
49
49
|
*/
|
|
50
|
-
'aria-label'
|
|
50
|
+
'aria-label'?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Returns the aria-label applied to each radio star.
|
|
53
|
+
* Defaults to `${aria-label} ${index + 1}`.
|
|
54
|
+
*/
|
|
55
|
+
getStarLabel?: (index: number) => string;
|
|
51
56
|
}
|
|
52
|
-
export declare const Rating: ({ defaultValue, value: propValue, onValueChange,
|
|
57
|
+
export declare const Rating: ({ defaultValue, value: propValue, onValueChange, disabled, readOnly, required: requiredProp, name, id, "aria-label": ariaLabel, getStarLabel, ref, ...rest }: RatingProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
import { MouseEvent, Ref } from 'react';
|
|
1
|
+
import { KeyboardEvent, MouseEvent, PropsWithChildren, Ref } from 'react';
|
|
2
2
|
import { RatingStarIconStylesProps, RatingStarstylesProps } from './RatingStar.styles';
|
|
3
3
|
import { StarValue } from './types';
|
|
4
|
-
export interface RatingStarProps extends RatingStarstylesProps
|
|
4
|
+
export interface RatingStarProps extends PropsWithChildren<RatingStarstylesProps>, RatingStarIconStylesProps {
|
|
5
5
|
value: StarValue;
|
|
6
|
+
/** Whether this radio option is selected (for radiogroup pattern). */
|
|
7
|
+
checked?: boolean;
|
|
8
|
+
/** Accessible name for the radio (e.g. "one star", "two stars"). */
|
|
9
|
+
ariaLabel?: string;
|
|
10
|
+
/** Accessible ids used to compose the radio name. */
|
|
11
|
+
ariaLabelledBy?: string;
|
|
12
|
+
/** Tab index for roving tabindex (0 or -1). */
|
|
13
|
+
tabIndex?: number;
|
|
6
14
|
onClick?: (event: MouseEvent<HTMLDivElement>) => void;
|
|
15
|
+
onKeyDown?: (event: KeyboardEvent<HTMLDivElement>) => void;
|
|
7
16
|
onMouseEnter?: (event: MouseEvent<HTMLDivElement>) => void;
|
|
8
17
|
ref?: Ref<HTMLDivElement>;
|
|
9
18
|
}
|
|
10
|
-
export declare const RatingStar: ({ value, size, disabled, readOnly, onClick, onMouseEnter, ref: forwardedRef, }: RatingStarProps) => import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
export declare const RatingStar: ({ value, size, disabled, readOnly, checked, ariaLabel, ariaLabelledBy, tabIndex, onClick, onKeyDown, onMouseEnter, children, ref: forwardedRef, }: RatingStarProps) => import("react/jsx-runtime").JSX.Element;
|
package/dist/rating/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),G=require("@spark-ui/hooks/use-combined-state"),f=require("class-variance-authority"),u=require("react"),Q=require("../form-field/index.js"),W=require("@spark-ui/icons/StarFill"),X=require("@spark-ui/icons/StarOutline"),V=require("../Icon-CF0W0LKr.js"),Y=f.cx("[&_>_div]:peer-hover:w-0!"),Z=f.cva(["peer after:inset-0 group relative after:block after:absolute"],{variants:{disabled:{true:"opacity-dim-3",false:""},readOnly:{true:"",false:""},gap:{sm:["after:w-[calc(100%+(var(--spacing-sm)))]","last-of-type:after:content-none"],md:["after:w-[calc(100%+(var(--spacing-md)))]","last-of-type:after:content-none"]}},compoundVariants:[{readOnly:!1,disabled:!1,className:f.cx(Y,"cursor-pointer transition-all duration-200 scale-100","hover:scale-150 focus-visible:scale-150","[&[data-suppress-scale]]:hover:scale-100 [&[data-suppress-scale]]:focus-visible:scale-100")}],defaultVariants:{disabled:!1,readOnly:!1,gap:"sm"}}),H=f.cva("",{variants:{size:{sm:"text-caption-link",md:"text-body-1",lg:"text-display-1"},design:{filled:["text-main-variant","group-[[data-part=star][data-hovered]]:text-main-variant-hovered"],outlined:["text-on-surface/dim-3"]}}}),ee=({value:e,size:t,disabled:r,readOnly:o,checked:i=!1,ariaLabel:l,ariaLabelledBy:c,tabIndex:I,onClick:v,onKeyDown:h,onMouseEnter:k,children:w,ref:p})=>{const g=!r&&!o,[j,y]=u.useState(!1),C=R=>{v?.(R),g&&y(!0)},S=()=>y(!1);return n.jsxs("div",{ref:p,role:"radio","aria-checked":i,"aria-label":l,"aria-labelledby":c,tabIndex:I,"data-spark-component":"rating-star","data-part":"star",...g&&j&&{"data-suppress-scale":""},className:Z({gap:t==="lg"?"md":"sm",disabled:r,readOnly:o}),onClick:C,onKeyDown:h,onMouseEnter:k,onMouseLeave:S,onMouseMove:S,children:[n.jsx("div",{className:f.cx("z-raised absolute overflow-hidden","group-[[data-part=star][data-hovered]]:overflow-visible"),style:{width:e*100+"%"},children:n.jsx(V.Icon,{className:H({size:t,design:"filled"}),children:n.jsx(W.StarFill,{})})}),n.jsx(V.Icon,{className:H({size:t,design:"outlined"}),children:n.jsx(X.StarOutline,{})}),w]})};function ae({value:e,index:t}){if(e===void 0)return 0;const r=t+1;return e>=r?1:0}function te(e,t){const r=e.slice(0,t),o=e.slice(t);return[r,o]}const re=e=>e===void 0||!Number.isInteger(e)||e<1?0:Math.min(5,Math.max(1,e));function se(e,t,r,o){return i=>{if(o)switch(i.key){case"ArrowRight":case"ArrowDown":i.preventDefault();const l=Math.min(4,e+1);r(l+1),t.current[l]?.focus();break;case"ArrowLeft":case"ArrowUp":i.preventDefault();const c=Math.max(0,e-1);r(c+1),t.current[c]?.focus();break;case" ":i.preventDefault(),r(e+1);break}}}function ne(e,t){return t>=1?t-1===e?0:-1:e===0?0:-1}const oe=({defaultValue:e,value:t,onValueChange:r,disabled:o,readOnly:i,required:l,name:c,id:I,"aria-label":v,getStarLabel:h,ref:k,...w})=>{const{labelId:p,isInvalid:g,isRequired:j,description:y,name:C,disabled:S,readOnly:R}=Q.useFormFieldControl(),d=u.useRef([]),N=u.useId(),[D,O]=u.useState(null),[K,q]=G.useCombinedState(t,e,r),x=re(K??0),F=o??S,$=i??R,L=l!==void 0?l:j,E=c??C,m=!(F||$),A=h!==void 0||v!==void 0,_=D!==null?D+1:x;function J(s){if(!m)return;const a=s+1;q(a),d.current[s]?.focus()}const P=u.useCallback(s=>se(s,d,q,m),[m,q]);function T({currentTarget:s}){const a=d.current.findIndex(b=>b===s);O(a>=0?a:null);const[M,U]=te(d.current,a+1);M.forEach(b=>b?.setAttribute("data-hovered","")),U.forEach(b=>b?.removeAttribute("data-hovered"))}const z=u.useCallback(s=>a=>{d.current[s]=a},[]);function B(){O(null),d.current.forEach(s=>s?.removeAttribute("data-hovered"))}return n.jsxs("div",{ref:k,id:I,role:"radiogroup","aria-label":v,"aria-labelledby":p,"aria-invalid":g,"aria-required":L,"aria-describedby":y,className:"relative inline-flex","data-spark-component":"rating",...w,onMouseLeave:B,children:[E!==void 0&&n.jsx("input",{type:"hidden",name:E,value:x,"aria-hidden":!0,"data-part":"input"}),n.jsx("div",{className:f.cx("gap-x-md","flex"),children:Array.from({length:5}).map((s,a)=>n.jsx(ee,{ref:z(a),disabled:F,readOnly:$,size:"lg",value:ae({index:a,value:_}),checked:x===a+1,ariaLabel:A?h?.(a)??`${v} ${a+1}`:void 0,ariaLabelledBy:!A&&p?`${p} ${N}-star-${a+1}`:void 0,tabIndex:m?ne(a,x):-1,onClick:()=>J(a),onKeyDown:P(a),onMouseEnter:M=>m&&T(M),children:!A&&n.jsx("span",{id:`${N}-star-${a+1}`,className:"sr-only",children:a+1})},a))})]})};exports.Rating=oe;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/rating/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/rating/RatingStar.styles.ts","../../src/rating/RatingStar.tsx","../../src/rating/utils.ts","../../src/rating/Rating.tsx"],"sourcesContent":["import { cva, cx, VariantProps } from 'class-variance-authority'\n\nconst emptyRemainingStarsOnHoverClass = cx('[&_>_div]:peer-hover:w-0!')\n\nconst ratingStarStyles = cva(\n ['peer', 'after:inset-0', 'group', 'relative', 'after:block after:absolute'],\n {\n variants: {\n disabled: {\n true: 'opacity-dim-3',\n false: '',\n },\n readOnly: {\n true: '',\n false: '',\n },\n gap: {\n sm: ['after:w-[calc(100%+(var(--spacing-sm)))]', 'last-of-type:after:content-none'],\n md: ['after:w-[calc(100%+(var(--spacing-md)))]', 'last-of-type:after:content-none'],\n },\n },\n compoundVariants: [\n {\n readOnly: false,\n disabled: false,\n className: cx(emptyRemainingStarsOnHoverClass, 'cursor-pointer'),\n },\n ],\n defaultVariants: {\n disabled: false,\n readOnly: false,\n gap: 'sm',\n },\n }\n)\n\nconst ratingStarIconStyles = cva('', {\n variants: {\n size: {\n sm: 'text-caption-link',\n md: 'text-body-1',\n lg: 'text-display-1',\n },\n design: {\n filled: [\n 'text-main-variant',\n 'group-[[data-part=star][data-hovered]]:text-main-variant-hovered',\n ],\n outlined: ['text-on-surface/dim-3'],\n },\n },\n})\n\ntype RatingStarstylesProps = Omit<VariantProps<typeof ratingStarStyles>, 'gap'>\ntype RatingStarIconStylesProps = Omit<VariantProps<typeof ratingStarIconStyles>, 'design'>\n\nexport { ratingStarStyles, ratingStarIconStyles }\nexport type { RatingStarstylesProps, RatingStarIconStylesProps }\n","import { StarFill } from '@spark-ui/icons/StarFill'\nimport { StarOutline } from '@spark-ui/icons/StarOutline'\nimport { cx } from 'class-variance-authority'\nimport { type MouseEvent, Ref } from 'react'\n\nimport { Icon } from '../icon'\nimport {\n ratingStarIconStyles,\n type RatingStarIconStylesProps,\n ratingStarStyles,\n type RatingStarstylesProps,\n} from './RatingStar.styles'\nimport type { StarValue } from './types'\n\nexport interface RatingStarProps extends RatingStarstylesProps, RatingStarIconStylesProps {\n value: StarValue\n onClick?: (event: MouseEvent<HTMLDivElement>) => void\n onMouseEnter?: (event: MouseEvent<HTMLDivElement>) => void\n ref?: Ref<HTMLDivElement>\n}\n\nexport const RatingStar = ({\n value,\n size,\n disabled,\n readOnly,\n onClick,\n onMouseEnter,\n ref: forwardedRef,\n}: RatingStarProps) => {\n return (\n <div\n data-spark-component=\"rating-star\"\n ref={forwardedRef}\n onMouseEnter={onMouseEnter}\n className={ratingStarStyles({\n gap: size === 'lg' ? 'md' : 'sm',\n disabled,\n readOnly,\n })}\n data-part=\"star\"\n onClick={onClick}\n >\n <div\n className={cx(\n 'z-raised absolute overflow-hidden',\n 'group-[[data-part=star][data-hovered]]:overflow-visible'\n )}\n style={{ width: value * 100 + '%' }}\n >\n <Icon\n className={ratingStarIconStyles({\n size,\n design: 'filled',\n })}\n >\n <StarFill />\n </Icon>\n </div>\n\n <Icon className={ratingStarIconStyles({ size, design: 'outlined' })}>\n <StarOutline />\n </Icon>\n </div>\n )\n}\n","import { type StarValue } from './types'\n\nfunction getNearestHalfDecimal(num: number): number {\n return Math.round(num / 0.5) * 0.5\n}\n\nfunction getStarValue({ value, index }: { value?: number; index: number }): StarValue {\n if (value === undefined) return 0\n\n const starPosition = index + 1\n const formattedValue = getNearestHalfDecimal(value)\n\n if (Math.ceil(formattedValue) < starPosition) return 0\n\n return formattedValue >= starPosition ? 1 : 0.5\n}\n\nfunction splitAt<T>(arr: T[], index: number): [T[], T[]] {\n const prev = arr.slice(0, index)\n const next = arr.slice(index)\n\n return [prev, next]\n}\n\nexport { getNearestHalfDecimal, getStarValue, splitAt }\n","import { useCombinedState } from '@spark-ui/hooks/use-combined-state'\nimport { cx } from 'class-variance-authority'\nimport {\n type ChangeEvent,\n type ComponentPropsWithRef,\n type MouseEvent,\n type PropsWithChildren,\n useCallback,\n useRef,\n} from 'react'\n\nimport { RatingStar, type RatingStarProps } from './RatingStar'\nimport { getNearestHalfDecimal, getStarValue, splitAt } from './utils'\n\nexport interface RatingProps extends PropsWithChildren<ComponentPropsWithRef<'div'>> {\n /**\n * Use the `defaultValue` prop to set the default value of the input, on a from 0 to 5.\n *\n * Use this when you want to use it in an uncontrolled manner\n */\n defaultValue?: number\n /**\n * The value is the number of the rating selected, on a scale from 0 to 5.\n *\n * Use this when you want to use it in a controlled manner,\n * in conjunction with the `onValueChange` prop\n */\n value?: number\n /**\n * Event handler called when the value changes.\n */\n onValueChange?: (value: number) => void\n /**\n * Sets the component as interactive or not.\n * @default undefined\n */\n readOnly?: boolean\n /**\n * When `true`, prevents the user from interacting.\n * @default false\n */\n disabled?: boolean\n /**\n * Sets the size of the stars.\n * @default 'md'\n */\n size?: RatingStarProps['size']\n /**\n * Name of the underlying input.\n * @default undefined\n */\n name?: string\n /**\n * id of the underlying input.\n * @default undefined\n */\n id?: string\n /**\n * aria-label of the underlying input.\n * @default undefined\n */\n 'aria-label': string\n}\n\nexport const Rating = ({\n defaultValue,\n value: propValue,\n onValueChange,\n size = 'md',\n disabled,\n readOnly,\n name,\n id,\n 'aria-label': ariaLabel,\n ref,\n ...rest\n}: RatingProps) => {\n const inputRef = useRef<HTMLInputElement>(null)\n const starRefList = useRef<HTMLDivElement[]>([])\n\n const [value, setRatingValue] = useCombinedState(propValue, defaultValue, onValueChange)\n\n const valueRef = useRef(value)\n const isInteractive = !(disabled || readOnly)\n\n function onStarClick(index: number) {\n if (!inputRef.current) return\n\n setRatingValue(index + 1)\n valueRef.current = index + 1\n\n inputRef.current.focus()\n inputRef.current.setAttribute('data-clicked', '')\n }\n\n function onInputChange(event: ChangeEvent<HTMLInputElement>) {\n // 1. Avoiding unnecessary calls to onValueChange prop if value doesn't change\n // 2. Preventing value to be resetted to 0\n if (valueRef.current === Number(event.target.value) || Number(event.target.value) === 0) {\n return\n }\n valueRef.current = Number(event.target.value)\n\n setRatingValue(Number(event.target.value))\n }\n\n function onStarMouseEnter({ currentTarget }: MouseEvent<HTMLDivElement>) {\n const currentStarIndex = starRefList.current.findIndex(star => star === currentTarget)\n\n const [previousStars, followingStars] = splitAt(starRefList.current, currentStarIndex + 1)\n\n previousStars.forEach(star => star.setAttribute('data-hovered', ''))\n followingStars.forEach(star => star.removeAttribute('data-hovered'))\n }\n\n const handleStarRef = useCallback((elm: HTMLDivElement | null) => {\n if (!elm) return\n starRefList.current.push(elm)\n }, [])\n\n function resetDataPartInputAttr() {\n inputRef.current?.removeAttribute('data-clicked')\n }\n\n function resetDataPartStarAttr() {\n starRefList.current.forEach(star => star.removeAttribute('data-hovered'))\n }\n\n return (\n <div\n className=\"relative inline-flex\"\n ref={ref}\n data-spark-component=\"rating\"\n {...rest}\n onMouseLeave={resetDataPartStarAttr}\n >\n <input\n name={name}\n id={id}\n aria-label={ariaLabel}\n ref={inputRef}\n data-part=\"input\"\n className=\"peer absolute inset-0 opacity-0\"\n type=\"range\"\n min=\"0\"\n max=\"5\"\n step={readOnly ? 0.5 : 1}\n disabled={disabled}\n readOnly={readOnly}\n value={getNearestHalfDecimal(value ?? 0)}\n onChange={event => isInteractive && onInputChange(event)}\n onBlur={resetDataPartInputAttr}\n />\n <div\n className={cx(\n size === 'lg' ? 'gap-x-md' : 'gap-x-sm',\n 'flex',\n 'peer-focus-visible:u-outline peer-[[data-part=input][data-clicked]]:shadow-none'\n )}\n >\n {Array.from({ length: 5 }).map((_, index) => (\n <RatingStar\n disabled={disabled}\n readOnly={readOnly}\n size={size}\n onClick={() => isInteractive && onStarClick(index)}\n onMouseEnter={event => isInteractive && onStarMouseEnter(event)}\n ref={handleStarRef}\n key={index}\n value={getStarValue({ index, value })}\n />\n ))}\n </div>\n </div>\n )\n}\n"],"names":["emptyRemainingStarsOnHoverClass","cx","ratingStarStyles","cva","ratingStarIconStyles","RatingStar","value","size","disabled","readOnly","onClick","onMouseEnter","forwardedRef","jsxs","jsx","Icon","StarFill","StarOutline","getNearestHalfDecimal","num","getStarValue","index","starPosition","formattedValue","splitAt","arr","prev","next","Rating","defaultValue","propValue","onValueChange","name","id","ariaLabel","ref","rest","inputRef","useRef","starRefList","setRatingValue","useCombinedState","valueRef","isInteractive","onStarClick","onInputChange","event","onStarMouseEnter","currentTarget","currentStarIndex","star","previousStars","followingStars","handleStarRef","useCallback","elm","resetDataPartInputAttr","resetDataPartStarAttr","_"],"mappings":"8UAEMA,EAAkCC,EAAAA,GAAG,2BAA2B,EAEhEC,EAAmBC,EAAAA,IACvB,CAAC,OAAQ,gBAAiB,QAAS,WAAY,4BAA4B,EAC3E,CACE,SAAU,CACR,SAAU,CACR,KAAM,gBACN,MAAO,EAAA,EAET,SAAU,CACR,KAAM,GACN,MAAO,EAAA,EAET,IAAK,CACH,GAAI,CAAC,2CAA4C,iCAAiC,EAClF,GAAI,CAAC,2CAA4C,iCAAiC,CAAA,CACpF,EAEF,iBAAkB,CAChB,CACE,SAAU,GACV,SAAU,GACV,UAAWF,EAAAA,GAAG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../../src/rating/RatingStar.styles.ts","../../src/rating/RatingStar.tsx","../../src/rating/utils.ts","../../src/rating/Rating.tsx"],"sourcesContent":["import { cva, cx, VariantProps } from 'class-variance-authority'\n\nconst emptyRemainingStarsOnHoverClass = cx('[&_>_div]:peer-hover:w-0!')\n\nconst ratingStarStyles = cva(['peer after:inset-0 group relative after:block after:absolute'], {\n variants: {\n disabled: {\n true: 'opacity-dim-3',\n false: '',\n },\n readOnly: {\n true: '',\n false: '',\n },\n gap: {\n sm: ['after:w-[calc(100%+(var(--spacing-sm)))]', 'last-of-type:after:content-none'],\n md: ['after:w-[calc(100%+(var(--spacing-md)))]', 'last-of-type:after:content-none'],\n },\n },\n compoundVariants: [\n {\n readOnly: false,\n disabled: false,\n className: cx(\n emptyRemainingStarsOnHoverClass,\n 'cursor-pointer transition-all duration-200 scale-100',\n /* mouseOver / focusIn => scale 150 */\n 'hover:scale-150 focus-visible:scale-150',\n /* mouseOut / focusOut / selection (click) => no scale; mouseMove clears selection => scale again */\n '[&[data-suppress-scale]]:hover:scale-100 [&[data-suppress-scale]]:focus-visible:scale-100'\n ),\n },\n ],\n defaultVariants: {\n disabled: false,\n readOnly: false,\n gap: 'sm',\n },\n})\n\nconst ratingStarIconStyles = cva('', {\n variants: {\n size: {\n sm: 'text-caption-link',\n md: 'text-body-1',\n lg: 'text-display-1',\n },\n design: {\n filled: [\n 'text-main-variant',\n 'group-[[data-part=star][data-hovered]]:text-main-variant-hovered',\n ],\n outlined: ['text-on-surface/dim-3'],\n },\n },\n})\n\ntype RatingStarstylesProps = Omit<VariantProps<typeof ratingStarStyles>, 'gap'>\ntype RatingStarIconStylesProps = Omit<VariantProps<typeof ratingStarIconStyles>, 'design'>\n\nexport { ratingStarStyles, ratingStarIconStyles }\nexport type { RatingStarstylesProps, RatingStarIconStylesProps }\n","import { StarFill } from '@spark-ui/icons/StarFill'\nimport { StarOutline } from '@spark-ui/icons/StarOutline'\nimport { cx } from 'class-variance-authority'\nimport { type KeyboardEvent, type MouseEvent, type PropsWithChildren, Ref, useState } from 'react'\n\nimport { Icon } from '../icon'\nimport {\n ratingStarIconStyles,\n type RatingStarIconStylesProps,\n ratingStarStyles,\n type RatingStarstylesProps,\n} from './RatingStar.styles'\nimport type { StarValue } from './types'\n\nexport interface RatingStarProps\n extends PropsWithChildren<RatingStarstylesProps>,\n RatingStarIconStylesProps {\n value: StarValue\n /** Whether this radio option is selected (for radiogroup pattern). */\n checked?: boolean\n /** Accessible name for the radio (e.g. \"one star\", \"two stars\"). */\n ariaLabel?: string\n /** Accessible ids used to compose the radio name. */\n ariaLabelledBy?: string\n /** Tab index for roving tabindex (0 or -1). */\n tabIndex?: number\n onClick?: (event: MouseEvent<HTMLDivElement>) => void\n onKeyDown?: (event: KeyboardEvent<HTMLDivElement>) => void\n onMouseEnter?: (event: MouseEvent<HTMLDivElement>) => void\n ref?: Ref<HTMLDivElement>\n}\n\nexport const RatingStar = ({\n value,\n size,\n disabled,\n readOnly,\n checked = false,\n ariaLabel,\n ariaLabelledBy,\n tabIndex,\n onClick,\n onKeyDown,\n onMouseEnter,\n children,\n ref: forwardedRef,\n}: RatingStarProps) => {\n const isInteractive = !disabled && !readOnly\n const [justClicked, setJustClicked] = useState(false)\n\n const handleClick = (event: MouseEvent<HTMLDivElement>) => {\n onClick?.(event)\n if (isInteractive) setJustClicked(true)\n }\n\n const clearJustClicked = () => setJustClicked(false)\n\n return (\n <div\n ref={forwardedRef}\n role=\"radio\"\n aria-checked={checked}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n tabIndex={tabIndex}\n data-spark-component=\"rating-star\"\n data-part=\"star\"\n {...(isInteractive && justClicked && { 'data-suppress-scale': '' })}\n className={ratingStarStyles({\n gap: size === 'lg' ? 'md' : 'sm',\n disabled,\n readOnly,\n })}\n onClick={handleClick}\n onKeyDown={onKeyDown}\n onMouseEnter={onMouseEnter}\n onMouseLeave={clearJustClicked}\n onMouseMove={clearJustClicked}\n >\n <div\n className={cx(\n 'z-raised absolute overflow-hidden',\n 'group-[[data-part=star][data-hovered]]:overflow-visible'\n )}\n style={{ width: value * 100 + '%' }}\n >\n <Icon\n className={ratingStarIconStyles({\n size,\n design: 'filled',\n })}\n >\n <StarFill />\n </Icon>\n </div>\n\n <Icon className={ratingStarIconStyles({ size, design: 'outlined' })}>\n <StarOutline />\n </Icon>\n {children}\n </div>\n )\n}\n","import { type StarValue } from './types'\n\nfunction getStarValue({ value, index }: { value?: number; index: number }): StarValue {\n if (value === undefined) return 0\n\n const starPosition = index + 1\n\n return value >= starPosition ? 1 : 0\n}\n\nfunction splitAt<T>(arr: T[], index: number): [T[], T[]] {\n const prev = arr.slice(0, index)\n const next = arr.slice(index)\n\n return [prev, next]\n}\n\nexport { getStarValue, splitAt }\n","/* eslint-disable max-lines-per-function */\nimport { useCombinedState } from '@spark-ui/hooks/use-combined-state'\nimport { cx } from 'class-variance-authority'\nimport {\n type ComponentPropsWithRef,\n type KeyboardEvent,\n type MouseEvent,\n type PropsWithChildren,\n type RefObject,\n useCallback,\n useId,\n useRef,\n useState,\n} from 'react'\n\nimport { useFormFieldControl } from '../form-field'\nimport { RatingStar } from './RatingStar'\nimport type { RatingValue } from './types'\nimport { getStarValue, splitAt } from './utils'\n\nconst getRatingInteger = (value: number | undefined): RatingValue => {\n if (value === undefined || !Number.isInteger(value) || value < 1) {\n return 0\n }\n\n return Math.min(5, Math.max(1, value)) as RatingValue\n}\n\nfunction createStarKeyDownHandler(\n index: number,\n starRefList: RefObject<(HTMLDivElement | null)[]>,\n setRatingValue: (value: RatingValue) => void,\n isInteractive: boolean\n) {\n return (event: KeyboardEvent<HTMLDivElement>) => {\n if (!isInteractive) return\n\n switch (event.key) {\n case 'ArrowRight':\n case 'ArrowDown':\n event.preventDefault()\n const nextIndex = Math.min(4, index + 1)\n setRatingValue((nextIndex + 1) as RatingValue)\n starRefList.current[nextIndex]?.focus()\n break\n case 'ArrowLeft':\n case 'ArrowUp':\n event.preventDefault()\n const prevIndex = Math.max(0, index - 1)\n setRatingValue((prevIndex + 1) as RatingValue)\n starRefList.current[prevIndex]?.focus()\n break\n case ' ':\n event.preventDefault()\n setRatingValue((index + 1) as RatingValue)\n break\n default:\n break\n }\n }\n}\n\nfunction getStarTabIndex(index: number, ratingValue: RatingValue): number {\n if (ratingValue >= 1) {\n return ratingValue - 1 === index ? 0 : -1\n }\n\n return index === 0 ? 0 : -1\n}\n\nexport interface RatingProps extends PropsWithChildren<ComponentPropsWithRef<'div'>> {\n /**\n * Use the `defaultValue` prop to set the default value of the input, on a from 0 to 5.\n *\n * Use this when you want to use it in an uncontrolled manner\n */\n defaultValue?: RatingValue\n /**\n * The value is the number of the rating selected, on a scale from 0 to 5.\n *\n * Use this when you want to use it in a controlled manner,\n * in conjunction with the `onValueChange` prop\n */\n value?: RatingValue\n /**\n * Event handler called when the value changes.\n */\n onValueChange?: (value: RatingValue) => void\n /**\n * Sets the component as interactive or not.\n * @default undefined\n */\n readOnly?: boolean\n /**\n * When `true`, prevents the user from interacting.\n * @default false\n */\n disabled?: boolean\n /**\n * When true, indicates that the user must select a rating before form submission.\n * @default false\n */\n required?: boolean\n /**\n * Name of the underlying hidden input (for form submission).\n * @default undefined\n */\n name?: string\n /**\n * id of the underlying hidden input.\n * @default undefined\n */\n id?: string\n /**\n * aria-label of the radiogroup.\n * @default undefined\n */\n 'aria-label'?: string\n /**\n * Returns the aria-label applied to each radio star.\n * Defaults to `${aria-label} ${index + 1}`.\n */\n getStarLabel?: (index: number) => string\n}\n\nexport const Rating = ({\n defaultValue,\n value: propValue,\n onValueChange,\n disabled,\n readOnly,\n required: requiredProp,\n name,\n id,\n 'aria-label': ariaLabel,\n getStarLabel,\n ref,\n ...rest\n}: RatingProps) => {\n const {\n labelId,\n isInvalid,\n isRequired,\n description,\n name: formFieldName,\n disabled: formFieldDisabled,\n readOnly: formFieldReadOnly,\n } = useFormFieldControl()\n const starRefList = useRef<(HTMLDivElement | null)[]>([])\n const ratingId = useId()\n const [hoveredStarIndex, setHoveredStarIndex] = useState<number | null>(null)\n const [value, setRatingValue] = useCombinedState(propValue, defaultValue, onValueChange)\n const ratingValue = getRatingInteger(value ?? 0)\n const resolvedDisabled = disabled ?? formFieldDisabled\n const resolvedReadOnly = readOnly ?? formFieldReadOnly\n const required = requiredProp !== undefined ? requiredProp : isRequired\n const groupName = name ?? formFieldName\n const isInteractive = !(resolvedDisabled || resolvedReadOnly)\n const hasExplicitStarLabel = getStarLabel !== undefined || ariaLabel !== undefined\n const displayValue = hoveredStarIndex !== null ? hoveredStarIndex + 1 : ratingValue\n\n function onStarClick(index: number) {\n if (!isInteractive) return\n\n const newValue = (index + 1) as RatingValue\n setRatingValue(newValue)\n starRefList.current[index]?.focus()\n }\n\n const onStarKeyDown = useCallback(\n (index: number) => createStarKeyDownHandler(index, starRefList, setRatingValue, isInteractive),\n [isInteractive, setRatingValue]\n )\n\n function onStarMouseEnter({ currentTarget }: MouseEvent<HTMLDivElement>) {\n const currentStarIndex = starRefList.current.findIndex(star => star === currentTarget)\n setHoveredStarIndex(currentStarIndex >= 0 ? currentStarIndex : null)\n const [previousStars, followingStars] = splitAt(starRefList.current, currentStarIndex + 1)\n previousStars.forEach(star => star?.setAttribute('data-hovered', ''))\n followingStars.forEach(star => star?.removeAttribute('data-hovered'))\n }\n\n const handleStarRef = useCallback(\n (index: number) => (elm: HTMLDivElement | null) => {\n starRefList.current[index] = elm\n },\n []\n )\n\n function resetDataPartStarAttr() {\n setHoveredStarIndex(null)\n starRefList.current.forEach(star => star?.removeAttribute('data-hovered'))\n }\n\n return (\n <div\n ref={ref}\n id={id}\n role=\"radiogroup\"\n aria-label={ariaLabel}\n aria-labelledby={labelId}\n aria-invalid={isInvalid}\n aria-required={required}\n aria-describedby={description}\n className=\"relative inline-flex\"\n data-spark-component=\"rating\"\n {...rest}\n onMouseLeave={resetDataPartStarAttr}\n >\n {groupName !== undefined && (\n <input type=\"hidden\" name={groupName} value={ratingValue} aria-hidden data-part=\"input\" />\n )}\n <div className={cx('gap-x-md', 'flex')}>\n {Array.from({ length: 5 }).map((_, index) => (\n <RatingStar\n ref={handleStarRef(index)}\n key={index}\n disabled={resolvedDisabled}\n readOnly={resolvedReadOnly}\n size=\"lg\"\n value={getStarValue({ index, value: displayValue })}\n checked={ratingValue === index + 1}\n ariaLabel={\n hasExplicitStarLabel\n ? (getStarLabel?.(index) ?? `${ariaLabel} ${index + 1}`)\n : undefined\n }\n ariaLabelledBy={\n !hasExplicitStarLabel && labelId\n ? `${labelId} ${ratingId}-star-${index + 1}`\n : undefined\n }\n tabIndex={isInteractive ? getStarTabIndex(index, ratingValue) : -1}\n onClick={() => onStarClick(index)}\n onKeyDown={onStarKeyDown(index)}\n onMouseEnter={event => isInteractive && onStarMouseEnter(event)}\n >\n {!hasExplicitStarLabel && (\n <span id={`${ratingId}-star-${index + 1}`} className=\"sr-only\">\n {index + 1}\n </span>\n )}\n </RatingStar>\n ))}\n </div>\n </div>\n )\n}\n"],"names":["emptyRemainingStarsOnHoverClass","cx","ratingStarStyles","cva","ratingStarIconStyles","RatingStar","value","size","disabled","readOnly","checked","ariaLabel","ariaLabelledBy","tabIndex","onClick","onKeyDown","onMouseEnter","children","forwardedRef","isInteractive","justClicked","setJustClicked","useState","handleClick","event","clearJustClicked","jsxs","jsx","Icon","StarFill","StarOutline","getStarValue","index","starPosition","splitAt","arr","prev","next","getRatingInteger","createStarKeyDownHandler","starRefList","setRatingValue","nextIndex","prevIndex","getStarTabIndex","ratingValue","Rating","defaultValue","propValue","onValueChange","requiredProp","name","id","getStarLabel","ref","rest","labelId","isInvalid","isRequired","description","formFieldName","formFieldDisabled","formFieldReadOnly","useFormFieldControl","useRef","ratingId","useId","hoveredStarIndex","setHoveredStarIndex","useCombinedState","resolvedDisabled","resolvedReadOnly","required","groupName","hasExplicitStarLabel","displayValue","onStarClick","newValue","onStarKeyDown","useCallback","onStarMouseEnter","currentTarget","currentStarIndex","star","previousStars","followingStars","handleStarRef","elm","resetDataPartStarAttr","_"],"mappings":"kX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,CAAE,OAAQ,CAAA,CAAG,EAAE,IAAI,CAACwF,EAAGzD,IACjCL,EAAAA,IAACtB,GAAA,CACC,IAAKiF,EAActD,CAAK,EAExB,SAAUsC,EACV,SAAUC,EACV,KAAK,KACL,MAAOxC,GAAa,CAAE,MAAAC,EAAO,MAAO2C,EAAc,EAClD,QAAS9B,IAAgBb,EAAQ,EACjC,UACE0C,EACKrB,IAAerB,CAAK,GAAK,GAAGrB,CAAS,IAAIqB,EAAQ,CAAC,GACnD,OAEN,eACE,CAAC0C,GAAwBlB,EACrB,GAAGA,CAAO,IAAIS,CAAQ,SAASjC,EAAQ,CAAC,GACxC,OAEN,SAAUb,EAAgByB,GAAgBZ,EAAOa,CAAW,EAAI,GAChE,QAAS,IAAM+B,EAAY5C,CAAK,EAChC,UAAW8C,EAAc9C,CAAK,EAC9B,aAAcR,GAASL,GAAiB6D,EAAiBxD,CAAK,EAE7D,SAAA,CAACkD,GACA/C,EAAAA,IAAC,OAAA,CAAK,GAAI,GAAGsC,CAAQ,SAASjC,EAAQ,CAAC,GAAI,UAAU,UAClD,WAAQ,CAAA,CACX,CAAA,EAxBGA,CAAA,CA2BR,CAAA,CACH,CAAA,CAAA,CAAA,CAGN"}
|
package/dist/rating/index.mjs
CHANGED
|
@@ -1,41 +1,46 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useCombinedState as
|
|
3
|
-
import { cx as
|
|
4
|
-
import { useRef as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
{
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
false: ""
|
|
15
|
-
},
|
|
16
|
-
readOnly: {
|
|
17
|
-
true: "",
|
|
18
|
-
false: ""
|
|
19
|
-
},
|
|
20
|
-
gap: {
|
|
21
|
-
sm: ["after:w-[calc(100%+(var(--spacing-sm)))]", "last-of-type:after:content-none"],
|
|
22
|
-
md: ["after:w-[calc(100%+(var(--spacing-md)))]", "last-of-type:after:content-none"]
|
|
23
|
-
}
|
|
1
|
+
import { jsxs as K, jsx as n } from "react/jsx-runtime";
|
|
2
|
+
import { useCombinedState as X } from "@spark-ui/hooks/use-combined-state";
|
|
3
|
+
import { cx as S, cva as L } from "class-variance-authority";
|
|
4
|
+
import { useState as _, useRef as Y, useId as Z, useCallback as j } from "react";
|
|
5
|
+
import { useFormFieldControl as ee } from "../form-field/index.mjs";
|
|
6
|
+
import { StarFill as ae } from "@spark-ui/icons/StarFill";
|
|
7
|
+
import { StarOutline as te } from "@spark-ui/icons/StarOutline";
|
|
8
|
+
import { I as q } from "../Icon-Ck-dhfLd.mjs";
|
|
9
|
+
const re = S("[&_>_div]:peer-hover:w-0!"), se = L(["peer after:inset-0 group relative after:block after:absolute"], {
|
|
10
|
+
variants: {
|
|
11
|
+
disabled: {
|
|
12
|
+
true: "opacity-dim-3",
|
|
13
|
+
false: ""
|
|
24
14
|
},
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
15
|
+
readOnly: {
|
|
16
|
+
true: "",
|
|
17
|
+
false: ""
|
|
18
|
+
},
|
|
19
|
+
gap: {
|
|
20
|
+
sm: ["after:w-[calc(100%+(var(--spacing-sm)))]", "last-of-type:after:content-none"],
|
|
21
|
+
md: ["after:w-[calc(100%+(var(--spacing-md)))]", "last-of-type:after:content-none"]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
compoundVariants: [
|
|
25
|
+
{
|
|
34
26
|
readOnly: !1,
|
|
35
|
-
|
|
27
|
+
disabled: !1,
|
|
28
|
+
className: S(
|
|
29
|
+
re,
|
|
30
|
+
"cursor-pointer transition-all duration-200 scale-100",
|
|
31
|
+
/* mouseOver / focusIn => scale 150 */
|
|
32
|
+
"hover:scale-150 focus-visible:scale-150",
|
|
33
|
+
/* mouseOut / focusOut / selection (click) => no scale; mouseMove clears selection => scale again */
|
|
34
|
+
"[&[data-suppress-scale]]:hover:scale-100 [&[data-suppress-scale]]:focus-visible:scale-100"
|
|
35
|
+
)
|
|
36
36
|
}
|
|
37
|
+
],
|
|
38
|
+
defaultVariants: {
|
|
39
|
+
disabled: !1,
|
|
40
|
+
readOnly: !1,
|
|
41
|
+
gap: "sm"
|
|
37
42
|
}
|
|
38
|
-
),
|
|
43
|
+
}), H = L("", {
|
|
39
44
|
variants: {
|
|
40
45
|
size: {
|
|
41
46
|
sm: "text-caption-link",
|
|
@@ -50,154 +55,196 @@ const F = f("[&_>_div]:peer-hover:w-0!"), q = k(
|
|
|
50
55
|
outlined: ["text-on-surface/dim-3"]
|
|
51
56
|
}
|
|
52
57
|
}
|
|
53
|
-
}),
|
|
58
|
+
}), ne = ({
|
|
54
59
|
value: e,
|
|
55
|
-
size:
|
|
56
|
-
disabled:
|
|
57
|
-
readOnly:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
"
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
60
|
+
size: t,
|
|
61
|
+
disabled: r,
|
|
62
|
+
readOnly: o,
|
|
63
|
+
checked: i = !1,
|
|
64
|
+
ariaLabel: l,
|
|
65
|
+
ariaLabelledBy: c,
|
|
66
|
+
tabIndex: I,
|
|
67
|
+
onClick: u,
|
|
68
|
+
onKeyDown: v,
|
|
69
|
+
onMouseEnter: k,
|
|
70
|
+
children: w,
|
|
71
|
+
ref: f
|
|
72
|
+
}) => {
|
|
73
|
+
const h = !r && !o, [C, b] = _(!1), N = (x) => {
|
|
74
|
+
u?.(x), h && b(!0);
|
|
75
|
+
}, g = () => b(!1);
|
|
76
|
+
return /* @__PURE__ */ K(
|
|
77
|
+
"div",
|
|
78
|
+
{
|
|
79
|
+
ref: f,
|
|
80
|
+
role: "radio",
|
|
81
|
+
"aria-checked": i,
|
|
82
|
+
"aria-label": l,
|
|
83
|
+
"aria-labelledby": c,
|
|
84
|
+
tabIndex: I,
|
|
85
|
+
"data-spark-component": "rating-star",
|
|
86
|
+
"data-part": "star",
|
|
87
|
+
...h && C && { "data-suppress-scale": "" },
|
|
88
|
+
className: se({
|
|
89
|
+
gap: t === "lg" ? "md" : "sm",
|
|
90
|
+
disabled: r,
|
|
91
|
+
readOnly: o
|
|
92
|
+
}),
|
|
93
|
+
onClick: N,
|
|
94
|
+
onKeyDown: v,
|
|
95
|
+
onMouseEnter: k,
|
|
96
|
+
onMouseLeave: g,
|
|
97
|
+
onMouseMove: g,
|
|
98
|
+
children: [
|
|
99
|
+
/* @__PURE__ */ n(
|
|
100
|
+
"div",
|
|
101
|
+
{
|
|
102
|
+
className: S(
|
|
103
|
+
"z-raised absolute overflow-hidden",
|
|
104
|
+
"group-[[data-part=star][data-hovered]]:overflow-visible"
|
|
105
|
+
),
|
|
106
|
+
style: { width: e * 100 + "%" },
|
|
107
|
+
children: /* @__PURE__ */ n(
|
|
108
|
+
q,
|
|
109
|
+
{
|
|
110
|
+
className: H({
|
|
111
|
+
size: t,
|
|
112
|
+
design: "filled"
|
|
113
|
+
}),
|
|
114
|
+
children: /* @__PURE__ */ n(ae, {})
|
|
115
|
+
}
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
),
|
|
119
|
+
/* @__PURE__ */ n(q, { className: H({ size: t, design: "outlined" }), children: /* @__PURE__ */ n(te, {}) }),
|
|
120
|
+
w
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
);
|
|
124
|
+
};
|
|
125
|
+
function oe({ value: e, index: t }) {
|
|
103
126
|
if (e === void 0) return 0;
|
|
104
|
-
const
|
|
105
|
-
return
|
|
127
|
+
const r = t + 1;
|
|
128
|
+
return e >= r ? 1 : 0;
|
|
129
|
+
}
|
|
130
|
+
function ie(e, t) {
|
|
131
|
+
const r = e.slice(0, t), o = e.slice(t);
|
|
132
|
+
return [r, o];
|
|
106
133
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return
|
|
134
|
+
const le = (e) => e === void 0 || !Number.isInteger(e) || e < 1 ? 0 : Math.min(5, Math.max(1, e));
|
|
135
|
+
function ce(e, t, r, o) {
|
|
136
|
+
return (i) => {
|
|
137
|
+
if (o)
|
|
138
|
+
switch (i.key) {
|
|
139
|
+
case "ArrowRight":
|
|
140
|
+
case "ArrowDown":
|
|
141
|
+
i.preventDefault();
|
|
142
|
+
const l = Math.min(4, e + 1);
|
|
143
|
+
r(l + 1), t.current[l]?.focus();
|
|
144
|
+
break;
|
|
145
|
+
case "ArrowLeft":
|
|
146
|
+
case "ArrowUp":
|
|
147
|
+
i.preventDefault();
|
|
148
|
+
const c = Math.max(0, e - 1);
|
|
149
|
+
r(c + 1), t.current[c]?.focus();
|
|
150
|
+
break;
|
|
151
|
+
case " ":
|
|
152
|
+
i.preventDefault(), r(e + 1);
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function de(e, t) {
|
|
158
|
+
return t >= 1 ? t - 1 === e ? 0 : -1 : e === 0 ? 0 : -1;
|
|
110
159
|
}
|
|
111
|
-
const
|
|
160
|
+
const ye = ({
|
|
112
161
|
defaultValue: e,
|
|
113
|
-
value:
|
|
114
|
-
onValueChange:
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
name:
|
|
119
|
-
id:
|
|
120
|
-
"aria-label":
|
|
121
|
-
|
|
122
|
-
|
|
162
|
+
value: t,
|
|
163
|
+
onValueChange: r,
|
|
164
|
+
disabled: o,
|
|
165
|
+
readOnly: i,
|
|
166
|
+
required: l,
|
|
167
|
+
name: c,
|
|
168
|
+
id: I,
|
|
169
|
+
"aria-label": u,
|
|
170
|
+
getStarLabel: v,
|
|
171
|
+
ref: k,
|
|
172
|
+
...w
|
|
123
173
|
}) => {
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
174
|
+
const {
|
|
175
|
+
labelId: f,
|
|
176
|
+
isInvalid: h,
|
|
177
|
+
isRequired: C,
|
|
178
|
+
description: b,
|
|
179
|
+
name: N,
|
|
180
|
+
disabled: g,
|
|
181
|
+
readOnly: x
|
|
182
|
+
} = ee(), d = Y([]), R = Z(), [O, $] = _(null), [J, A] = X(t, e, r), y = le(J ?? 0), E = o ?? g, F = i ?? x, z = l !== void 0 ? l : C, V = c ?? N, m = !(E || F), D = v !== void 0 || u !== void 0, B = O !== null ? O + 1 : y;
|
|
183
|
+
function P(s) {
|
|
184
|
+
if (!m) return;
|
|
185
|
+
const a = s + 1;
|
|
186
|
+
A(a), d.current[s]?.focus();
|
|
130
187
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
188
|
+
const T = j(
|
|
189
|
+
(s) => ce(s, d, A, m),
|
|
190
|
+
[m, A]
|
|
191
|
+
);
|
|
192
|
+
function U({ currentTarget: s }) {
|
|
193
|
+
const a = d.current.findIndex((p) => p === s);
|
|
194
|
+
$(a >= 0 ? a : null);
|
|
195
|
+
const [M, W] = ie(d.current, a + 1);
|
|
196
|
+
M.forEach((p) => p?.setAttribute("data-hovered", "")), W.forEach((p) => p?.removeAttribute("data-hovered"));
|
|
140
197
|
}
|
|
141
|
-
|
|
142
|
-
|
|
198
|
+
const G = j(
|
|
199
|
+
(s) => (a) => {
|
|
200
|
+
d.current[s] = a;
|
|
201
|
+
},
|
|
202
|
+
[]
|
|
203
|
+
);
|
|
204
|
+
function Q() {
|
|
205
|
+
$(null), d.current.forEach((s) => s?.removeAttribute("data-hovered"));
|
|
143
206
|
}
|
|
144
|
-
return /* @__PURE__ */
|
|
207
|
+
return /* @__PURE__ */ K(
|
|
145
208
|
"div",
|
|
146
209
|
{
|
|
210
|
+
ref: k,
|
|
211
|
+
id: I,
|
|
212
|
+
role: "radiogroup",
|
|
213
|
+
"aria-label": u,
|
|
214
|
+
"aria-labelledby": f,
|
|
215
|
+
"aria-invalid": h,
|
|
216
|
+
"aria-required": z,
|
|
217
|
+
"aria-describedby": b,
|
|
147
218
|
className: "relative inline-flex",
|
|
148
|
-
ref: I,
|
|
149
219
|
"data-spark-component": "rating",
|
|
150
|
-
...
|
|
151
|
-
onMouseLeave:
|
|
220
|
+
...w,
|
|
221
|
+
onMouseLeave: Q,
|
|
152
222
|
children: [
|
|
153
|
-
/* @__PURE__ */
|
|
154
|
-
|
|
223
|
+
V !== void 0 && /* @__PURE__ */ n("input", { type: "hidden", name: V, value: y, "aria-hidden": !0, "data-part": "input" }),
|
|
224
|
+
/* @__PURE__ */ n("div", { className: S("gap-x-md", "flex"), children: Array.from({ length: 5 }).map((s, a) => /* @__PURE__ */ n(
|
|
225
|
+
ne,
|
|
155
226
|
{
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
),
|
|
173
|
-
/* @__PURE__ */ o(
|
|
174
|
-
"div",
|
|
175
|
-
{
|
|
176
|
-
className: f(
|
|
177
|
-
r === "lg" ? "gap-x-md" : "gap-x-sm",
|
|
178
|
-
"flex",
|
|
179
|
-
"peer-focus-visible:u-outline peer-[[data-part=input][data-clicked]]:shadow-none"
|
|
180
|
-
),
|
|
181
|
-
children: Array.from({ length: 5 }).map((t, c) => /* @__PURE__ */ o(
|
|
182
|
-
G,
|
|
183
|
-
{
|
|
184
|
-
disabled: i,
|
|
185
|
-
readOnly: s,
|
|
186
|
-
size: r,
|
|
187
|
-
onClick: () => g && E(c),
|
|
188
|
-
onMouseEnter: (h) => g && V(h),
|
|
189
|
-
ref: D,
|
|
190
|
-
value: J({ index: c, value: p })
|
|
191
|
-
},
|
|
192
|
-
c
|
|
193
|
-
))
|
|
194
|
-
}
|
|
195
|
-
)
|
|
227
|
+
ref: G(a),
|
|
228
|
+
disabled: E,
|
|
229
|
+
readOnly: F,
|
|
230
|
+
size: "lg",
|
|
231
|
+
value: oe({ index: a, value: B }),
|
|
232
|
+
checked: y === a + 1,
|
|
233
|
+
ariaLabel: D ? v?.(a) ?? `${u} ${a + 1}` : void 0,
|
|
234
|
+
ariaLabelledBy: !D && f ? `${f} ${R}-star-${a + 1}` : void 0,
|
|
235
|
+
tabIndex: m ? de(a, y) : -1,
|
|
236
|
+
onClick: () => P(a),
|
|
237
|
+
onKeyDown: T(a),
|
|
238
|
+
onMouseEnter: (M) => m && U(M),
|
|
239
|
+
children: !D && /* @__PURE__ */ n("span", { id: `${R}-star-${a + 1}`, className: "sr-only", children: a + 1 })
|
|
240
|
+
},
|
|
241
|
+
a
|
|
242
|
+
)) })
|
|
196
243
|
]
|
|
197
244
|
}
|
|
198
245
|
);
|
|
199
246
|
};
|
|
200
247
|
export {
|
|
201
|
-
|
|
248
|
+
ye as Rating
|
|
202
249
|
};
|
|
203
250
|
//# sourceMappingURL=index.mjs.map
|