@spark-ui/components 17.9.0-beta.0 → 17.9.0-beta.2
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/avatar/index.js +1 -1
- package/dist/avatar/index.js.map +1 -1
- package/dist/avatar/index.mjs +2 -2
- package/dist/avatar/index.mjs.map +1 -1
- package/dist/badge/index.js +1 -1
- package/dist/badge/index.js.map +1 -1
- package/dist/badge/index.mjs +3 -3
- package/dist/badge/index.mjs.map +1 -1
- package/dist/breadcrumb/index.js +1 -1
- package/dist/breadcrumb/index.js.map +1 -1
- package/dist/breadcrumb/index.mjs +1 -1
- package/dist/breadcrumb/index.mjs.map +1 -1
- package/dist/button/index.js +1 -1
- package/dist/button/index.mjs +1 -1
- package/dist/{button-B-sMnDc_.js → button-3F9Xrf4E.js} +2 -2
- package/dist/{button-B-sMnDc_.js.map → button-3F9Xrf4E.js.map} +1 -1
- package/dist/{button-C6nlNPdv.mjs → button-BFQ3w9CA.mjs} +2 -2
- package/dist/{button-C6nlNPdv.mjs.map → button-BFQ3w9CA.mjs.map} +1 -1
- package/dist/card/index.js +1 -1
- package/dist/card/index.js.map +1 -1
- package/dist/card/index.mjs +1 -1
- package/dist/card/index.mjs.map +1 -1
- package/dist/carousel/index.js +1 -1
- package/dist/carousel/index.mjs +1 -1
- package/dist/circular-meter/index.js +1 -1
- package/dist/circular-meter/index.js.map +1 -1
- package/dist/circular-meter/index.mjs +5 -5
- package/dist/circular-meter/index.mjs.map +1 -1
- package/dist/combobox/index.js +1 -1
- package/dist/combobox/index.mjs +2 -2
- package/dist/dialog/index.js +1 -1
- package/dist/dialog/index.mjs +1 -1
- package/dist/drawer/index.js +1 -1
- package/dist/drawer/index.mjs +1 -1
- package/dist/dropdown/index.js +1 -1
- package/dist/dropdown/index.mjs +1 -1
- package/dist/file-upload/index.js +1 -1
- package/dist/file-upload/index.mjs +3 -3
- package/dist/form-field/index.js +1 -1
- package/dist/form-field/index.mjs +1 -1
- package/dist/{form-field-OhKW7u5I.mjs → form-field-CV5dzt-I.mjs} +2 -2
- package/dist/{form-field-OhKW7u5I.mjs.map → form-field-CV5dzt-I.mjs.map} +1 -1
- package/dist/{form-field-1sKqNg7F.js → form-field-CYGgse45.js} +2 -2
- package/dist/{form-field-1sKqNg7F.js.map → form-field-CYGgse45.js.map} +1 -1
- package/dist/icon-button/index.js +1 -1
- package/dist/icon-button/index.mjs +1 -1
- package/dist/{icon-button-DpucUC_L.mjs → icon-button-C3RgGf2o.mjs} +2 -2
- package/dist/{icon-button-DpucUC_L.mjs.map → icon-button-C3RgGf2o.mjs.map} +1 -1
- package/dist/{icon-button-CYz_Fitz.js → icon-button-jcPwRD21.js} +2 -2
- package/dist/{icon-button-CYz_Fitz.js.map → icon-button-jcPwRD21.js.map} +1 -1
- package/dist/kbd/index.js +1 -1
- package/dist/kbd/index.js.map +1 -1
- package/dist/kbd/index.mjs +1 -1
- package/dist/kbd/index.mjs.map +1 -1
- package/dist/meter/index.js +1 -1
- package/dist/meter/index.js.map +1 -1
- package/dist/meter/index.mjs +1 -1
- package/dist/meter/index.mjs.map +1 -1
- package/dist/pagination/index.js +1 -1
- package/dist/pagination/index.mjs +2 -2
- package/dist/popover/index.js +1 -1
- package/dist/popover/index.mjs +1 -1
- package/dist/{popover-DsBY8eYl.mjs → popover-DKa4WOQV.mjs} +2 -2
- package/dist/{popover-DsBY8eYl.mjs.map → popover-DKa4WOQV.mjs.map} +1 -1
- package/dist/{popover-CrKp_TKk.js → popover-ayPbAw59.js} +2 -2
- package/dist/{popover-CrKp_TKk.js.map → popover-ayPbAw59.js.map} +1 -1
- package/dist/progress/index.js +1 -1
- package/dist/progress/index.mjs +1 -1
- package/dist/{progress-C3w4PmxY.mjs → progress-C-Zs94G2.mjs} +2 -2
- package/dist/{progress-C3w4PmxY.mjs.map → progress-C-Zs94G2.mjs.map} +1 -1
- package/dist/{progress-BjqJSRnK.js → progress-DaQt4olK.js} +2 -2
- package/dist/{progress-BjqJSRnK.js.map → progress-DaQt4olK.js.map} +1 -1
- package/dist/progress-tracker/index.js +1 -1
- package/dist/progress-tracker/index.js.map +1 -1
- package/dist/progress-tracker/index.mjs +3 -3
- package/dist/progress-tracker/index.mjs.map +1 -1
- package/dist/rating/index.js +1 -1
- package/dist/rating/index.mjs +1 -1
- package/dist/rating-display/index.js +1 -1
- package/dist/rating-display/index.js.map +1 -1
- package/dist/rating-display/index.mjs +3 -3
- package/dist/rating-display/index.mjs.map +1 -1
- package/dist/scrolling-list/index.js +1 -1
- package/dist/scrolling-list/index.mjs +2 -2
- package/dist/slider/index.js +1 -1
- package/dist/slider/index.js.map +1 -1
- package/dist/slider/index.mjs +1 -1
- package/dist/slider/index.mjs.map +1 -1
- package/dist/stepper/index.js +1 -1
- package/dist/stepper/index.mjs +1 -1
- package/dist/table/index.js +1 -1
- package/dist/table/index.js.map +1 -1
- package/dist/table/index.mjs +2 -2
- package/dist/table/index.mjs.map +1 -1
- package/dist/tabs/index.js +1 -1
- package/dist/tabs/index.js.map +1 -1
- package/dist/tabs/index.mjs +4 -4
- package/dist/tabs/index.mjs.map +1 -1
- package/dist/tag/index.js +1 -1
- package/dist/tag/index.js.map +1 -1
- package/dist/tag/index.mjs +1 -1
- package/dist/tag/index.mjs.map +1 -1
- package/dist/text-link/index.js +1 -1
- package/dist/text-link/index.js.map +1 -1
- package/dist/text-link/index.mjs +1 -1
- package/dist/text-link/index.mjs.map +1 -1
- package/dist/toast/index.js +1 -1
- package/dist/toast/index.mjs +2 -2
- package/package.json +5 -5
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../chunk-C91j1N6u.js`);const e=require(`../icon-CRPcdgYp.js`);let t=require(`class-variance-authority`),n=require(`react`),r=require(`react/jsx-runtime`),i=require(`@spark-ui/icons/Check`);var a=(0,t.cx)([`flex flex-nowrap items-start group/list`,`data-[orientation=horizontal]:flex-row data-[orientation=horizontal]:w-full`,`data-[orientation=vertical]:flex-col`]),o=(0,n.createContext)({}),s=(0,n.createContext)({}),c=()=>(0,n.useContext)(o),l=()=>(0,n.useContext)(s),u=`:progress-tracker`,d=({stepIndex:e=0,onStepClick:i,readOnly:s=!1,intent:c=`support`,size:l=`lg`,orientation:u=`horizontal`,children:d,className:f,ref:p,...m})=>{let[h,g]=(0,n.useState)(new Map),_=s?`div`:`nav`;return(0,r.jsx)(o.Provider,{value:{stepIndex:e,onStepClick:i,steps:h,setSteps:g,size:l,intent:c,readOnly:s},children:(0,r.jsx)(_,{ref:p,"data-spark-component":`progress-tracker`,className:(0,t.cx)(`inline-flex`,f),...m,children:(0,r.jsx)(`ol`,{"data-orientation":u,className:a,style:{counterReset:`step`},children:d})})})};d.displayName=`ProgressTracker`;var f=(0,t.cva)([`relative inline-flex items-start flex-auto first:grow-0 justify-center group/item`,`after:absolute after:z-base`,`last:after:content-none`,`after:bg-outline`,`group-data-[orientation=horizontal]/list:before:bg-outline`,`group-data-[orientation=horizontal]/list:px-[1px]`,`group-data-[orientation=horizontal]/list:before:absolute group-data-[orientation=horizontal]/list:before:z-base`,`group-data-[orientation=horizontal]/list:before:left-0 group-data-[orientation=horizontal]/list:after:right-0`,`group-data-[orientation=horizontal]/list:before:h-[1px] group-data-[orientation=horizontal]/list:after:h-[1px]`,`first:group-data-[orientation=horizontal]/list:before:content-none`,`group-data-[orientation=vertical]/list:py-[1px]`,`group-data-[orientation=vertical]/list:items-start`,`group-data-[orientation=vertical]/list:after:w-[1px] group-data-[orientation=vertical]/list:after:bottom-[-1px]`],{variants:{size:{sm:[`group-data-[orientation=horizontal]/list:before:top-[8px] group-data-[orientation=horizontal]/list:after:top-[8px]`,`group-data-[orientation=horizontal]/list:before:right-[calc(50%+12px)] group-data-[orientation=horizontal]/list:after:left-[calc(50%+12px)]`,`first:group-data-[orientation=horizontal]/list:after:left-[calc(50%+10px)]`,`last:group-data-[orientation=horizontal]/list:before:right-[calc(50%+10px)]`,`group-data-[orientation=vertical]/list:after:left-[8px]`,`group-data-[orientation=vertical]/list:after:top-[25px]`,`first:group-data-[orientation=vertical]/list:after:top-[21px]`],md:[`group-data-[orientation=horizontal]/list:before:top-[12px] group-data-[orientation=horizontal]/list:after:top-[12px]`,`group-data-[orientation=horizontal]/list:before:right-[calc(50%+16px)] group-data-[orientation=horizontal]/list:after:left-[calc(50%+16px)]`,`first:group-data-[orientation=horizontal]/list:after:left-[calc(50%+14px)]`,`last:group-data-[orientation=horizontal]/list:before:right-[calc(50%+14px)]`,`group-data-[orientation=vertical]/list:after:left-[12px]`,`group-data-[orientation=vertical]/list:after:top-[33px]`,`first:group-data-[orientation=vertical]/list:after:top-[29px]`],lg:[`group-data-[orientation=horizontal]/list:before:top-[16px] group-data-[orientation=horizontal]/list:after:top-[16px]`,`group-data-[orientation=horizontal]/list:before:right-[calc(50%+20px)] group-data-[orientation=horizontal]/list:after:left-[calc(50%+20px)]`,`first:group-data-[orientation=horizontal]/list:after:left-[calc(50%+18px)]`,`last:group-data-[orientation=horizontal]/list:before:right-[calc(50%+18px)]`,`group-data-[orientation=vertical]/list:after:left-[16px]`,`group-data-[orientation=vertical]/list:after:top-[41px]`,`first:group-data-[orientation=vertical]/list:after:top-[37px]`]},intent:{support:``,neutral:``,success:``},disabled:{true:`before:opacity-dim-3`,false:``},disabledAfter:{true:`after:opacity-dim-3`,false:``}},defaultVariants:{disabled:!1,disabledAfter:!1,size:`lg`,intent:`support`}}),p=(0,t.cva)([`relative flex group/btn disabled:cursor-default`,`group-data-[orientation=horizontal]/list:flex-col group-data-[orientation=horizontal]/list:items-center`,`group-data-[orientation=horizontal]/list:text-center group-data-[orientation=horizontal]/list:mx-sm`,`group-first/item:group-data-[orientation=horizontal]/list:ml-0 group-last/item:group-data-[orientation=horizontal]/list:mr-0`,`group-data-[orientation=vertical]/list:flex-row group-data-[orientation=vertical]/list:items-start`,`group-data-[orientation=vertical]/list:text-left group-data-[orientation=vertical]/list:my-sm`,`group-first/item:group-data-[orientation=vertical]/list:mt-0 group-last/item:group-data-[orientation=vertical]/list:mb-0`],{variants:{size:{sm:[`group-data-[orientation=horizontal]/list:min-w-sz-16 group-data-[orientation=horizontal]/list:mt-[16px]`,`group-data-[orientation=vertical]/list:min-h-sz-16 group-data-[orientation=vertical]/list:ml-[16px]`],md:[`group-data-[orientation=horizontal]/list:min-w-sz-24 group-data-[orientation=horizontal]/list:mt-[24px]`,`group-data-[orientation=vertical]/list:min-h-sz-24 group-data-[orientation=vertical]/list:ml-[24px]`],lg:[`group-data-[orientation=horizontal]/list:min-w-sz-32 group-data-[orientation=horizontal]/list:mt-[32px]`,`group-data-[orientation=vertical]/list:min-h-sz-32 group-data-[orientation=vertical]/list:ml-[32px]`]},readOnly:{true:`cursor-default`,false:`cursor-pointer`}},defaultVariants:{size:`lg`,readOnly:!1}}),m=(0,t.cva)([`relative flex shrink-0 justify-center items-center`,`rounded-full`,`text-body-2
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../chunk-C91j1N6u.js`);const e=require(`../icon-CRPcdgYp.js`);let t=require(`class-variance-authority`),n=require(`react`),r=require(`react/jsx-runtime`),i=require(`@spark-ui/icons/Check`);var a=(0,t.cx)([`flex flex-nowrap items-start group/list`,`data-[orientation=horizontal]:flex-row data-[orientation=horizontal]:w-full`,`data-[orientation=vertical]:flex-col`]),o=(0,n.createContext)({}),s=(0,n.createContext)({}),c=()=>(0,n.useContext)(o),l=()=>(0,n.useContext)(s),u=`:progress-tracker`,d=({stepIndex:e=0,onStepClick:i,readOnly:s=!1,intent:c=`support`,size:l=`lg`,orientation:u=`horizontal`,children:d,className:f,ref:p,...m})=>{let[h,g]=(0,n.useState)(new Map),_=s?`div`:`nav`;return(0,r.jsx)(o.Provider,{value:{stepIndex:e,onStepClick:i,steps:h,setSteps:g,size:l,intent:c,readOnly:s},children:(0,r.jsx)(_,{ref:p,"data-spark-component":`progress-tracker`,className:(0,t.cx)(`inline-flex`,f),...m,children:(0,r.jsx)(`ol`,{"data-orientation":u,className:a,style:{counterReset:`step`},children:d})})})};d.displayName=`ProgressTracker`;var f=(0,t.cva)([`relative inline-flex items-start flex-auto first:grow-0 justify-center group/item`,`after:absolute after:z-base`,`last:after:content-none`,`after:bg-outline`,`group-data-[orientation=horizontal]/list:before:bg-outline`,`group-data-[orientation=horizontal]/list:px-[1px]`,`group-data-[orientation=horizontal]/list:before:absolute group-data-[orientation=horizontal]/list:before:z-base`,`group-data-[orientation=horizontal]/list:before:left-0 group-data-[orientation=horizontal]/list:after:right-0`,`group-data-[orientation=horizontal]/list:before:h-[1px] group-data-[orientation=horizontal]/list:after:h-[1px]`,`first:group-data-[orientation=horizontal]/list:before:content-none`,`group-data-[orientation=vertical]/list:py-[1px]`,`group-data-[orientation=vertical]/list:items-start`,`group-data-[orientation=vertical]/list:after:w-[1px] group-data-[orientation=vertical]/list:after:bottom-[-1px]`],{variants:{size:{sm:[`group-data-[orientation=horizontal]/list:before:top-[8px] group-data-[orientation=horizontal]/list:after:top-[8px]`,`group-data-[orientation=horizontal]/list:before:right-[calc(50%+12px)] group-data-[orientation=horizontal]/list:after:left-[calc(50%+12px)]`,`first:group-data-[orientation=horizontal]/list:after:left-[calc(50%+10px)]`,`last:group-data-[orientation=horizontal]/list:before:right-[calc(50%+10px)]`,`group-data-[orientation=vertical]/list:after:left-[8px]`,`group-data-[orientation=vertical]/list:after:top-[25px]`,`first:group-data-[orientation=vertical]/list:after:top-[21px]`],md:[`group-data-[orientation=horizontal]/list:before:top-[12px] group-data-[orientation=horizontal]/list:after:top-[12px]`,`group-data-[orientation=horizontal]/list:before:right-[calc(50%+16px)] group-data-[orientation=horizontal]/list:after:left-[calc(50%+16px)]`,`first:group-data-[orientation=horizontal]/list:after:left-[calc(50%+14px)]`,`last:group-data-[orientation=horizontal]/list:before:right-[calc(50%+14px)]`,`group-data-[orientation=vertical]/list:after:left-[12px]`,`group-data-[orientation=vertical]/list:after:top-[33px]`,`first:group-data-[orientation=vertical]/list:after:top-[29px]`],lg:[`group-data-[orientation=horizontal]/list:before:top-[16px] group-data-[orientation=horizontal]/list:after:top-[16px]`,`group-data-[orientation=horizontal]/list:before:right-[calc(50%+20px)] group-data-[orientation=horizontal]/list:after:left-[calc(50%+20px)]`,`first:group-data-[orientation=horizontal]/list:after:left-[calc(50%+18px)]`,`last:group-data-[orientation=horizontal]/list:before:right-[calc(50%+18px)]`,`group-data-[orientation=vertical]/list:after:left-[16px]`,`group-data-[orientation=vertical]/list:after:top-[41px]`,`first:group-data-[orientation=vertical]/list:after:top-[37px]`]},intent:{support:``,neutral:``,success:``},disabled:{true:`before:opacity-dim-3`,false:``},disabledAfter:{true:`after:opacity-dim-3`,false:``}},defaultVariants:{disabled:!1,disabledAfter:!1,size:`lg`,intent:`support`}}),p=(0,t.cva)([`relative flex group/btn disabled:cursor-default`,`group-data-[orientation=horizontal]/list:flex-col group-data-[orientation=horizontal]/list:items-center`,`group-data-[orientation=horizontal]/list:text-center group-data-[orientation=horizontal]/list:mx-sm`,`group-first/item:group-data-[orientation=horizontal]/list:ml-0 group-last/item:group-data-[orientation=horizontal]/list:mr-0`,`group-data-[orientation=vertical]/list:flex-row group-data-[orientation=vertical]/list:items-start`,`group-data-[orientation=vertical]/list:text-left group-data-[orientation=vertical]/list:my-sm`,`group-first/item:group-data-[orientation=vertical]/list:mt-0 group-last/item:group-data-[orientation=vertical]/list:mb-0`],{variants:{size:{sm:[`group-data-[orientation=horizontal]/list:min-w-sz-16 group-data-[orientation=horizontal]/list:mt-[16px]`,`group-data-[orientation=vertical]/list:min-h-sz-16 group-data-[orientation=vertical]/list:ml-[16px]`],md:[`group-data-[orientation=horizontal]/list:min-w-sz-24 group-data-[orientation=horizontal]/list:mt-[24px]`,`group-data-[orientation=vertical]/list:min-h-sz-24 group-data-[orientation=vertical]/list:ml-[24px]`],lg:[`group-data-[orientation=horizontal]/list:min-w-sz-32 group-data-[orientation=horizontal]/list:mt-[32px]`,`group-data-[orientation=vertical]/list:min-h-sz-32 group-data-[orientation=vertical]/list:ml-[32px]`]},readOnly:{true:`cursor-default`,false:`cursor-pointer`}},defaultVariants:{size:`lg`,readOnly:!1}}),m=(0,t.cva)([`relative flex shrink-0 justify-center items-center`,`rounded-full`,`text-body-2-highlight`,`group-disabled/btn:opacity-dim-3`],{variants:{size:{sm:[`w-sz-16 h-sz-16`,`group-data-[orientation=horizontal]/list:mt-[-16px]`,`group-data-[orientation=vertical]/list:ml-[-16px]`],md:[`w-sz-24 h-sz-24`,`group-data-[orientation=horizontal]/list:mt-[-24px]`,`group-data-[orientation=vertical]/list:ml-[-24px]`],lg:[`w-sz-32 h-sz-32`,`group-data-[orientation=horizontal]/list:mt-[-32px]`,`group-data-[orientation=vertical]/list:ml-[-32px]`]},intent:{support:``,neutral:``,success:``},state:{complete:``,incomplete:``,active:``}},compoundVariants:[{intent:`support`,state:[`complete`,`incomplete`],class:[`text-on-support-container bg-support-container`,`group-hover/btn:group-data-[interactive=true]/btn:bg-support-container-hovered`,`group-hover/btn:group-data-[interactive=false]/btn:bg-support-container`]},{intent:`support`,state:`active`,class:`text-on-support bg-support`},{intent:`neutral`,state:[`complete`,`incomplete`],class:[`text-on-neutral-container bg-neutral-container`,`group-hover/btn:group-data-[interactive=true]/btn:bg-neutral-container-hovered`,`group-hover/btn:group-data-[interactive=false]/btn:bg-neutral-container`]},{intent:`neutral`,state:`active`,class:`text-on-neutral bg-neutral`},{intent:`success`,state:[`complete`,`incomplete`],class:[`text-on-success-container bg-success-container`,`group-hover/btn:group-data-[interactive=true]/btn:bg-success-container-hovered`,`group-hover/btn:group-data-[interactive=false]/btn:bg-success-container`]},{intent:`success`,state:`active`,class:`text-on-success bg-success`}],defaultVariants:{size:`lg`,state:`incomplete`,intent:`support`}}),h=()=>(0,r.jsx)(e.t,{size:`sm`,children:(0,r.jsx)(i.Check,{})}),g=({complete:e,incomplete:t,className:n})=>{let{size:i,intent:a}=c(),{index:o,state:s}=l();return(0,r.jsx)(`span`,{className:m({size:i,intent:a,state:s,className:n}),"aria-hidden":`true`,children:i!==`sm`&&(0,r.jsxs)(r.Fragment,{children:[s===`complete`&&(e===void 0?(0,r.jsx)(h,{}):e),s!==`complete`&&(t===void 0?`${o+1}`:t)]})})};g.displayName=`ProgressTracker.StepIndicator`;var _=({disabled:e=!1,children:t,"aria-label":i,className:a,ref:o,...l})=>{let{stepIndex:d,steps:m,onStepClick:h,setSteps:_,size:v,intent:y,readOnly:b}=c(),x=`${u}-step-${(0,n.useId)()}`,S=[...m.keys()].indexOf(x),C=(()=>{let e=[...m.keys()][S+1];return!!(e&&m.get(e)?.includes(`disabled`))})(),w=S===d?`active`:S<d?`complete`:`incomplete`;return(0,n.useEffect)(()=>(_(t=>new Map(t).set(x,[w,e?`disabled`:``].filter(e=>!!e))),()=>{_(e=>(e.delete(x),e))}),[]),(0,r.jsx)(`li`,{"data-spark-component":`progress-tracker-step`,id:x,ref:o,"data-state":w,...w===`active`&&{"aria-current":`step`},className:f({size:v,intent:y,disabled:e,disabledAfter:C}),...l,children:(0,r.jsx)(`button`,{type:`button`,"aria-label":i,"data-interactive":!e&&!b,...!e&&!b&&{onClick:()=>h?.(S)},disabled:e,className:p({size:v,readOnly:b,className:a}),children:(0,r.jsx)(s.Provider,{value:{index:S,state:w},children:t||(0,r.jsx)(g,{})})})})};_.displayName=`ProgressTracker.Step`;var v=(0,t.cva)([`flex text-body-2`,`text-on-surface group-disabled/btn:text-on-surface/dim-1`,`group-data-[orientation=horizontal]/list:mt-md`,`group-data-[orientation=vertical]/list:ml-md`,`group-data-[orientation=vertical]/list:my-auto`],{variants:{state:{complete:``,incomplete:``,active:`font-medium`}}}),y=({className:e,children:t})=>{let{state:n}=l();return(0,r.jsx)(`span`,{className:v({state:n,className:e}),children:t})};y.displayName=`ProgressTracker.StepLabel`;var b=Object.assign(d,{Step:_,StepLabel:y,StepIndicator:g});b.displayName=`ProgressTracker`,_.displayName=`ProgressTracker.Step`,y.displayName=`ProgressTracker.StepLabel`,g.displayName=`ProgressTracker.StepIndicator`,exports.ProgressTracker=b;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/progress-tracker/ProgressTracker.styles.ts","../../src/progress-tracker/ProgressTrackerContext.ts","../../src/progress-tracker/ProgressTracker.tsx","../../src/progress-tracker/ProgressTrackerStep.styles.ts","../../src/progress-tracker/ProgressTrackerStepIndicator.styles.ts","../../src/progress-tracker/ProgressTrackerStepIndicator.tsx","../../src/progress-tracker/ProgressTrackerStep.tsx","../../src/progress-tracker/ProgressTrackerStepLabel.tsx","../../src/progress-tracker/index.ts"],"sourcesContent":["import { cx } from 'class-variance-authority'\n\nexport const progressList = cx([\n 'flex flex-nowrap items-start group/list',\n 'data-[orientation=horizontal]:flex-row data-[orientation=horizontal]:w-full',\n 'data-[orientation=vertical]:flex-col',\n])\n","import { createContext, type Dispatch, type SetStateAction, useContext } from 'react'\n\nimport type { ProgressTrackerProps } from './ProgressTracker'\n\n// Interfaces\nexport type ProgressTrackerContextInterface = Required<\n Pick<ProgressTrackerProps, 'stepIndex' | 'size' | 'intent' | 'readOnly'>\n> &\n Pick<ProgressTrackerProps, 'onStepClick'> & {\n steps: Map<string, string[]>\n setSteps: Dispatch<SetStateAction<Map<string, string[]>>>\n }\n\nexport interface ProgressTrackerStepContextInterface {\n index: number\n state: 'active' | 'complete' | 'incomplete'\n}\n\n// Contexts\nexport const ProgressTrackerContext = createContext<ProgressTrackerContextInterface>(\n {} as ProgressTrackerContextInterface\n)\n\nexport const ProgressTrackerStepContext = createContext<ProgressTrackerStepContextInterface>(\n {} as ProgressTrackerStepContextInterface\n)\n\n// Hooks\nexport const useProgressTrackerContext = () => useContext(ProgressTrackerContext)\n\nexport const useProgressTrackerStepContext = () => useContext(ProgressTrackerStepContext)\n\nexport const ID_PREFIX = ':progress-tracker'\n","import { cx } from 'class-variance-authority'\nimport { type ComponentPropsWithRef, type PropsWithChildren, useState } from 'react'\n\nimport { progressList } from './ProgressTracker.styles'\nimport {\n ProgressTrackerContext,\n type ProgressTrackerContextInterface,\n} from './ProgressTrackerContext'\nimport type { StepIndicatorVariantProps } from './ProgressTrackerStepIndicator.styles'\n\nexport interface ProgressTrackerProps\n extends ComponentPropsWithRef<'div'>, Pick<StepIndicatorVariantProps, 'size' | 'intent'> {\n /**\n * The orientation of the progress tracker\n * @default 'horizontal\"\n */\n orientation?: 'horizontal' | 'vertical'\n /**\n * The index of the current step.\n * @default 0\n */\n stepIndex?: number\n /**\n * Event handler called when clicking on a step.\n */\n onStepClick?: (stepIndex: number) => void\n /**\n * Sets the component as interactive or not.\n * @default false\n */\n readOnly?: boolean\n}\n\nexport const ProgressTracker = ({\n stepIndex = 0,\n onStepClick,\n readOnly = false,\n intent = 'support',\n size = 'lg',\n orientation = 'horizontal',\n children,\n className,\n ref,\n ...rest\n}: PropsWithChildren<ProgressTrackerProps>) => {\n const [steps, setSteps] = useState<ProgressTrackerContextInterface['steps']>(new Map())\n\n const Component = readOnly ? 'div' : 'nav'\n\n return (\n <ProgressTrackerContext.Provider\n value={{ stepIndex, onStepClick, steps, setSteps, size, intent, readOnly }}\n >\n <Component\n ref={ref}\n data-spark-component=\"progress-tracker\"\n className={cx('inline-flex', className)}\n {...rest}\n >\n <ol\n data-orientation={orientation}\n className={progressList}\n style={{ counterReset: 'step' }}\n >\n {children}\n </ol>\n </Component>\n </ProgressTrackerContext.Provider>\n )\n}\n\nProgressTracker.displayName = 'ProgressTracker'\n","import { cva } from 'class-variance-authority'\n\nexport const stepItemVariant = cva(\n [\n 'relative inline-flex items-start flex-auto first:grow-0 justify-center group/item',\n // Progress Track\n 'after:absolute after:z-base',\n 'last:after:content-none',\n 'after:bg-outline',\n 'group-data-[orientation=horizontal]/list:before:bg-outline',\n // Horizontal orientation\n 'group-data-[orientation=horizontal]/list:px-[1px]',\n 'group-data-[orientation=horizontal]/list:before:absolute group-data-[orientation=horizontal]/list:before:z-base',\n 'group-data-[orientation=horizontal]/list:before:left-0 group-data-[orientation=horizontal]/list:after:right-0',\n 'group-data-[orientation=horizontal]/list:before:h-[1px] group-data-[orientation=horizontal]/list:after:h-[1px]',\n 'first:group-data-[orientation=horizontal]/list:before:content-none',\n // Vertical orientation\n 'group-data-[orientation=vertical]/list:py-[1px]',\n 'group-data-[orientation=vertical]/list:items-start',\n 'group-data-[orientation=vertical]/list:after:w-[1px] group-data-[orientation=vertical]/list:after:bottom-[-1px]',\n ],\n {\n variants: {\n size: {\n sm: [\n // Horizontal orientation\n 'group-data-[orientation=horizontal]/list:before:top-[8px] group-data-[orientation=horizontal]/list:after:top-[8px]',\n 'group-data-[orientation=horizontal]/list:before:right-[calc(50%+12px)] group-data-[orientation=horizontal]/list:after:left-[calc(50%+12px)]',\n 'first:group-data-[orientation=horizontal]/list:after:left-[calc(50%+10px)]',\n 'last:group-data-[orientation=horizontal]/list:before:right-[calc(50%+10px)]',\n // Vertical orientation\n 'group-data-[orientation=vertical]/list:after:left-[8px]',\n 'group-data-[orientation=vertical]/list:after:top-[25px]',\n 'first:group-data-[orientation=vertical]/list:after:top-[21px]',\n ],\n md: [\n // Horizontal orientation\n 'group-data-[orientation=horizontal]/list:before:top-[12px] group-data-[orientation=horizontal]/list:after:top-[12px]',\n 'group-data-[orientation=horizontal]/list:before:right-[calc(50%+16px)] group-data-[orientation=horizontal]/list:after:left-[calc(50%+16px)]',\n 'first:group-data-[orientation=horizontal]/list:after:left-[calc(50%+14px)]',\n 'last:group-data-[orientation=horizontal]/list:before:right-[calc(50%+14px)]',\n // Vertical orientation\n 'group-data-[orientation=vertical]/list:after:left-[12px]',\n 'group-data-[orientation=vertical]/list:after:top-[33px]',\n 'first:group-data-[orientation=vertical]/list:after:top-[29px]',\n ],\n lg: [\n // Horizontal orientation\n 'group-data-[orientation=horizontal]/list:before:top-[16px] group-data-[orientation=horizontal]/list:after:top-[16px]',\n 'group-data-[orientation=horizontal]/list:before:right-[calc(50%+20px)] group-data-[orientation=horizontal]/list:after:left-[calc(50%+20px)]',\n 'first:group-data-[orientation=horizontal]/list:after:left-[calc(50%+18px)]',\n 'last:group-data-[orientation=horizontal]/list:before:right-[calc(50%+18px)]',\n // Vertical orientation\n 'group-data-[orientation=vertical]/list:after:left-[16px]',\n 'group-data-[orientation=vertical]/list:after:top-[41px]',\n 'first:group-data-[orientation=vertical]/list:after:top-[37px]',\n ],\n },\n intent: {\n support: '',\n neutral: '',\n success: '',\n },\n disabled: {\n true: 'before:opacity-dim-3',\n false: '',\n },\n disabledAfter: {\n true: 'after:opacity-dim-3',\n false: '',\n },\n },\n defaultVariants: {\n disabled: false,\n disabledAfter: false,\n size: 'lg',\n intent: 'support',\n },\n }\n)\n\nexport const stepButtonVariant = cva(\n [\n 'relative flex group/btn disabled:cursor-default',\n // Horizontal orientation\n 'group-data-[orientation=horizontal]/list:flex-col group-data-[orientation=horizontal]/list:items-center',\n 'group-data-[orientation=horizontal]/list:text-center group-data-[orientation=horizontal]/list:mx-sm',\n 'group-first/item:group-data-[orientation=horizontal]/list:ml-0 group-last/item:group-data-[orientation=horizontal]/list:mr-0',\n // Vertical orientation\n 'group-data-[orientation=vertical]/list:flex-row group-data-[orientation=vertical]/list:items-start',\n 'group-data-[orientation=vertical]/list:text-left group-data-[orientation=vertical]/list:my-sm',\n 'group-first/item:group-data-[orientation=vertical]/list:mt-0 group-last/item:group-data-[orientation=vertical]/list:mb-0',\n ],\n {\n variants: {\n size: {\n sm: [\n 'group-data-[orientation=horizontal]/list:min-w-sz-16 group-data-[orientation=horizontal]/list:mt-[16px]',\n 'group-data-[orientation=vertical]/list:min-h-sz-16 group-data-[orientation=vertical]/list:ml-[16px]',\n ],\n md: [\n 'group-data-[orientation=horizontal]/list:min-w-sz-24 group-data-[orientation=horizontal]/list:mt-[24px]',\n 'group-data-[orientation=vertical]/list:min-h-sz-24 group-data-[orientation=vertical]/list:ml-[24px]',\n ],\n lg: [\n 'group-data-[orientation=horizontal]/list:min-w-sz-32 group-data-[orientation=horizontal]/list:mt-[32px]',\n 'group-data-[orientation=vertical]/list:min-h-sz-32 group-data-[orientation=vertical]/list:ml-[32px]',\n ],\n },\n readOnly: {\n true: 'cursor-default',\n false: 'cursor-pointer',\n },\n },\n defaultVariants: {\n size: 'lg',\n readOnly: false,\n },\n }\n)\n","import { cva, VariantProps } from 'class-variance-authority'\n\nexport const stepIndicatorVariant = cva(\n [\n 'relative flex shrink-0 justify-center items-center',\n 'rounded-full',\n 'text-body-2 font-bold',\n 'group-disabled/btn:opacity-dim-3',\n ],\n {\n variants: {\n size: {\n sm: [\n 'w-sz-16 h-sz-16',\n 'group-data-[orientation=horizontal]/list:mt-[-16px]',\n 'group-data-[orientation=vertical]/list:ml-[-16px]',\n ],\n md: [\n 'w-sz-24 h-sz-24',\n 'group-data-[orientation=horizontal]/list:mt-[-24px]',\n 'group-data-[orientation=vertical]/list:ml-[-24px]',\n ],\n lg: [\n 'w-sz-32 h-sz-32',\n 'group-data-[orientation=horizontal]/list:mt-[-32px]',\n 'group-data-[orientation=vertical]/list:ml-[-32px]',\n ],\n },\n intent: {\n support: '',\n neutral: '',\n success: '',\n },\n state: {\n complete: '',\n incomplete: '',\n active: '',\n },\n },\n /**\n * Known type issue with CVA compoundVariants and VS Code/Intellisense:\n * https://github.com/joe-bell/cva/discussions/195#discussioncomment-6750163\n * */\n /* @ts-ignore */\n compoundVariants: [\n // Support\n {\n intent: 'support',\n state: ['complete', 'incomplete'],\n class: [\n 'text-on-support-container bg-support-container',\n 'group-hover/btn:group-data-[interactive=true]/btn:bg-support-container-hovered',\n 'group-hover/btn:group-data-[interactive=false]/btn:bg-support-container',\n ],\n },\n {\n intent: 'support',\n state: 'active',\n class: 'text-on-support bg-support',\n },\n // Neutral\n {\n intent: 'neutral',\n state: ['complete', 'incomplete'],\n class: [\n 'text-on-neutral-container bg-neutral-container',\n 'group-hover/btn:group-data-[interactive=true]/btn:bg-neutral-container-hovered',\n 'group-hover/btn:group-data-[interactive=false]/btn:bg-neutral-container',\n ],\n },\n {\n intent: 'neutral',\n state: 'active',\n class: 'text-on-neutral bg-neutral',\n },\n // Success\n {\n intent: 'success',\n state: ['complete', 'incomplete'],\n class: [\n 'text-on-success-container bg-success-container',\n 'group-hover/btn:group-data-[interactive=true]/btn:bg-success-container-hovered',\n 'group-hover/btn:group-data-[interactive=false]/btn:bg-success-container',\n ],\n },\n {\n intent: 'success',\n state: 'active',\n class: 'text-on-success bg-success',\n },\n ],\n defaultVariants: {\n size: 'lg',\n state: 'incomplete',\n intent: 'support',\n },\n }\n)\n\nexport type StepIndicatorVariantProps = VariantProps<typeof stepIndicatorVariant>\n","import { Check } from '@spark-ui/icons/Check'\nimport type { ComponentPropsWithoutRef, ReactNode } from 'react'\n\nimport { Icon } from '../icon'\nimport { useProgressTrackerContext, useProgressTrackerStepContext } from './ProgressTrackerContext'\nimport { stepIndicatorVariant } from './ProgressTrackerStepIndicator.styles'\n\nexport type ProgressTrackerStepIndicatorProps = ComponentPropsWithoutRef<'span'> & {\n /**\n * The content to be rendered when step status is complete (checkmark icon by default)\n */\n complete?: ReactNode\n /**\n * The content to be rendered when step status is incomplete (step index by default)\n */\n incomplete?: ReactNode\n}\n\nconst CompleteIndicator = () => (\n <Icon size=\"sm\">\n <Check />\n </Icon>\n)\n\nexport const ProgressTrackerStepIndicator = ({\n complete,\n incomplete,\n className,\n}: ProgressTrackerStepIndicatorProps) => {\n const { size, intent } = useProgressTrackerContext()\n const { index, state } = useProgressTrackerStepContext()\n\n return (\n <span className={stepIndicatorVariant({ size, intent, state, className })} aria-hidden=\"true\">\n {size !== 'sm' && (\n <>\n {state === 'complete' && (complete === undefined ? <CompleteIndicator /> : complete)}\n {state !== 'complete' && (incomplete === undefined ? `${index + 1}` : incomplete)}\n </>\n )}\n </span>\n )\n}\n\nProgressTrackerStepIndicator.displayName = 'ProgressTracker.StepIndicator'\n","import { type ComponentPropsWithRef, type ReactNode, useEffect, useId } from 'react'\n\nimport {\n ID_PREFIX,\n ProgressTrackerStepContext,\n useProgressTrackerContext,\n} from './ProgressTrackerContext'\nimport { stepButtonVariant, stepItemVariant } from './ProgressTrackerStep.styles'\nimport { ProgressTrackerStepIndicator } from './ProgressTrackerStepIndicator'\n\nexport type ProgressTrackerStepProps = ComponentPropsWithRef<'li'> &\n (\n | {\n disabled?: boolean\n children: ReactNode\n }\n | {\n disabled?: boolean\n 'aria-label': string\n }\n )\n\nexport const ProgressTrackerStep = ({\n disabled = false,\n children,\n 'aria-label': ariaLabel,\n className,\n ref,\n ...rest\n}: ProgressTrackerStepProps) => {\n const {\n stepIndex: currentStepIndex,\n steps,\n onStepClick,\n setSteps,\n size,\n intent,\n readOnly,\n } = useProgressTrackerContext()\n\n const stepId = `${ID_PREFIX}-step-${useId()}`\n const stepIndex = [...steps.keys()].indexOf(stepId)\n\n const disabledAfter = (() => {\n const nextStepId = [...steps.keys()][stepIndex + 1]\n\n return !!(nextStepId && steps.get(nextStepId)?.includes('disabled'))\n })()\n\n const progressState = (() => {\n if (stepIndex === currentStepIndex) return 'active'\n else if (stepIndex < currentStepIndex) return 'complete'\n else return 'incomplete'\n })()\n\n useEffect(() => {\n setSteps(steps => {\n const newSteps = new Map(steps)\n\n return newSteps.set(\n stepId,\n [progressState, disabled ? 'disabled' : ''].filter(v => !!v)\n )\n })\n\n return () => {\n setSteps(steps => {\n steps.delete(stepId)\n\n return steps\n })\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n return (\n <li\n data-spark-component=\"progress-tracker-step\"\n id={stepId}\n ref={ref}\n data-state={progressState}\n {...(progressState === 'active' && {\n 'aria-current': 'step',\n })}\n className={stepItemVariant({\n size,\n intent,\n disabled,\n disabledAfter,\n })}\n {...rest}\n >\n <button\n type=\"button\"\n aria-label={ariaLabel}\n data-interactive={!disabled && !readOnly}\n {...(!disabled &&\n !readOnly && {\n onClick: () => onStepClick?.(stepIndex),\n })}\n disabled={disabled}\n className={stepButtonVariant({\n size,\n readOnly,\n className,\n })}\n >\n <ProgressTrackerStepContext.Provider\n value={{\n index: stepIndex,\n state: progressState,\n }}\n >\n {children || <ProgressTrackerStepIndicator />}\n </ProgressTrackerStepContext.Provider>\n </button>\n </li>\n )\n}\n\nProgressTrackerStep.displayName = 'ProgressTracker.Step'\n","import { cva } from 'class-variance-authority'\nimport type { ComponentPropsWithoutRef, ReactNode } from 'react'\n\nimport { useProgressTrackerStepContext } from './ProgressTrackerContext'\n\ntype ProgressTrackerStepLabelProps = ComponentPropsWithoutRef<'span'> & {\n children: ReactNode\n}\n\nconst stepLabel = cva(\n [\n 'flex text-body-2 ',\n 'text-on-surface group-disabled/btn:text-on-surface/dim-1',\n 'group-data-[orientation=horizontal]/list:mt-md',\n 'group-data-[orientation=vertical]/list:ml-md',\n 'group-data-[orientation=vertical]/list:my-auto',\n ],\n {\n variants: {\n state: {\n complete: '',\n incomplete: '',\n active: 'font-bold',\n },\n },\n }\n)\n\nexport const ProgressTrackerStepLabel = ({\n className,\n children,\n}: ProgressTrackerStepLabelProps) => {\n const { state } = useProgressTrackerStepContext()\n\n return <span className={stepLabel({ state, className })}>{children}</span>\n}\n\nProgressTrackerStepLabel.displayName = 'ProgressTracker.StepLabel'\n","import { ProgressTracker as Root, type ProgressTrackerProps } from './ProgressTracker'\nimport { ProgressTrackerStep as Step, type ProgressTrackerStepProps } from './ProgressTrackerStep'\nimport {\n ProgressTrackerStepIndicator as StepIndicator,\n type ProgressTrackerStepIndicatorProps,\n} from './ProgressTrackerStepIndicator'\nimport { ProgressTrackerStepLabel as StepLabel } from './ProgressTrackerStepLabel'\n\n/**\n * A component that displays a multi-step process with visual indicators for completed, current, and upcoming steps.\n */\nexport const ProgressTracker: typeof Root & {\n Step: typeof Step\n StepLabel: typeof StepLabel\n StepIndicator: typeof StepIndicator\n} = Object.assign(Root, {\n Step,\n StepLabel,\n StepIndicator,\n})\n\nProgressTracker.displayName = 'ProgressTracker'\nStep.displayName = 'ProgressTracker.Step'\nStepLabel.displayName = 'ProgressTracker.StepLabel'\nStepIndicator.displayName = 'ProgressTracker.StepIndicator'\n\nexport type { ProgressTrackerProps, ProgressTrackerStepProps, ProgressTrackerStepIndicatorProps }\n"],"mappings":"yQAEA,IAAa,GAAA,EAAA,EAAA,IAAkB,CAC7B,0CACA,8EACA,uCACD,CAAC,CCaW,GAAA,EAAA,EAAA,eACX,EAAE,CACH,CAEY,GAAA,EAAA,EAAA,eACX,EAAE,CACH,CAGY,OAAA,EAAA,EAAA,YAA6C,EAAuB,CAEpE,OAAA,EAAA,EAAA,YAAiD,EAA2B,CAE5E,EAAY,oBCCZ,GAAmB,CAC9B,YAAY,EACZ,cACA,WAAW,GACX,SAAS,UACT,OAAO,KACP,cAAc,aACd,WACA,YACA,MACA,GAAG,KAC0C,CAC7C,GAAM,CAAC,EAAO,IAAA,EAAA,EAAA,UAA+D,IAAI,IAAM,CAEjF,EAAY,EAAW,MAAQ,MAErC,OACE,EAAA,EAAA,KAAC,EAAuB,SAAxB,CACE,MAAO,CAAE,YAAW,cAAa,QAAO,WAAU,OAAM,SAAQ,WAAU,WAE1E,EAAA,EAAA,KAAC,EAAD,CACO,MACL,uBAAqB,mBACrB,WAAA,EAAA,EAAA,IAAc,cAAe,EAAU,CACvC,GAAI,YAEJ,EAAA,EAAA,KAAC,KAAD,CACE,mBAAkB,EAClB,UAAW,EACX,MAAO,CAAE,aAAc,OAAQ,CAE9B,WACE,CAAA,CACK,CAAA,CACoB,CAAA,EAItC,EAAgB,YAAc,kBCrE9B,IAAa,GAAA,EAAA,EAAA,KACX,CACE,oFAEA,8BACA,0BACA,mBACA,6DAEA,oDACA,kHACA,gHACA,iHACA,qEAEA,kDACA,qDACA,kHACD,CACD,CACE,SAAU,CACR,KAAM,CACJ,GAAI,CAEF,qHACA,8IACA,6EACA,8EAEA,0DACA,0DACA,gEACD,CACD,GAAI,CAEF,uHACA,8IACA,6EACA,8EAEA,2DACA,0DACA,gEACD,CACD,GAAI,CAEF,uHACA,8IACA,6EACA,8EAEA,2DACA,0DACA,gEACD,CACF,CACD,OAAQ,CACN,QAAS,GACT,QAAS,GACT,QAAS,GACV,CACD,SAAU,CACR,KAAM,uBACN,MAAO,GACR,CACD,cAAe,CACb,KAAM,sBACN,MAAO,GACR,CACF,CACD,gBAAiB,CACf,SAAU,GACV,cAAe,GACf,KAAM,KACN,OAAQ,UACT,CACF,CACF,CAEY,GAAA,EAAA,EAAA,KACX,CACE,kDAEA,0GACA,sGACA,+HAEA,qGACA,gGACA,2HACD,CACD,CACE,SAAU,CACR,KAAM,CACJ,GAAI,CACF,0GACA,sGACD,CACD,GAAI,CACF,0GACA,sGACD,CACD,GAAI,CACF,0GACA,sGACD,CACF,CACD,SAAU,CACR,KAAM,iBACN,MAAO,iBACR,CACF,CACD,gBAAiB,CACf,KAAM,KACN,SAAU,GACX,CACF,CACF,CCrHY,GAAA,EAAA,EAAA,KACX,CACE,qDACA,eACA,wBACA,mCACD,CACD,CACE,SAAU,CACR,KAAM,CACJ,GAAI,CACF,kBACA,sDACA,oDACD,CACD,GAAI,CACF,kBACA,sDACA,oDACD,CACD,GAAI,CACF,kBACA,sDACA,oDACD,CACF,CACD,OAAQ,CACN,QAAS,GACT,QAAS,GACT,QAAS,GACV,CACD,MAAO,CACL,SAAU,GACV,WAAY,GACZ,OAAQ,GACT,CACF,CAMD,iBAAkB,CAEhB,CACE,OAAQ,UACR,MAAO,CAAC,WAAY,aAAa,CACjC,MAAO,CACL,iDACA,iFACA,0EACD,CACF,CACD,CACE,OAAQ,UACR,MAAO,SACP,MAAO,6BACR,CAED,CACE,OAAQ,UACR,MAAO,CAAC,WAAY,aAAa,CACjC,MAAO,CACL,iDACA,iFACA,0EACD,CACF,CACD,CACE,OAAQ,UACR,MAAO,SACP,MAAO,6BACR,CAED,CACE,OAAQ,UACR,MAAO,CAAC,WAAY,aAAa,CACjC,MAAO,CACL,iDACA,iFACA,0EACD,CACF,CACD,CACE,OAAQ,UACR,MAAO,SACP,MAAO,6BACR,CACF,CACD,gBAAiB,CACf,KAAM,KACN,MAAO,aACP,OAAQ,U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b,GACP,GAGH,EAAE,CAAC,EAGJ,EAAA,EAAA,KAAC,KAAD,CACE,uBAAqB,wBACrB,GAAI,EACC,MACL,aAAY,EACZ,GAAK,IAAkB,UAAY,CACjC,eAAgB,OACjB,CACD,UAAW,EAAgB,CACzB,OACA,SACA,WACA,gBACD,CAAC,CACF,GAAI,YAEJ,EAAA,EAAA,KAAC,SAAD,CACE,KAAK,SACL,aAAY,EACZ,mBAAkB,CAAC,GAAY,CAAC,EAChC,GAAK,CAAC,GACJ,CAAC,GAAY,CACX,YAAe,IAAc,EAAU,CACxC,CACO,WACV,UAAW,EAAkB,CAC3B,OACA,WACA,YACD,CAAC,WAEF,EAAA,EAAA,KAAC,EAA2B,SAA5B,CACE,MAAO,CACL,MAAO,EACP,MAAO,EACR,UAEA,IAAY,EAAA,EAAA,KAAC,EAAD,EAAgC,CAAA,CACT,CAAA,CAC/B,CAAA,CACN,CAAA,EAIT,EAAoB,YAAc,uBC/GlC,IAAM,GAAA,EAAA,EAAA,KACJ,CACE,oBACA,2DACA,iDACA,+CACA,iDACD,CACD,CACE,SAAU,CACR,MAAO,CACL,SAAU,GACV,WAAY,GACZ,OAAQ,YACT,CACF,CACF,CACF,CAEY,GAA4B,CACvC,YACA,cACmC,CACnC,GAAM,CAAE,SAAU,GAA+B,CAEjD,OAAO,EAAA,EAAA,KAAC,OAAD,CAAM,UAAW,EAAU,CAAE,QAAO,YAAW,CAAC,CAAG,WAAgB,CAAA,EAG5E,EAAyB,YAAc,4BC1BvC,IAAa,EAIT,OAAO,OAAO,EAAM,CACtB,KAAA,EACA,UAAA,EACA,cAAA,EACD,CAAC,CAEF,EAAgB,YAAc,kBAC9B,EAAK,YAAc,uBACnB,EAAU,YAAc,4BACxB,EAAc,YAAc"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/progress-tracker/ProgressTracker.styles.ts","../../src/progress-tracker/ProgressTrackerContext.ts","../../src/progress-tracker/ProgressTracker.tsx","../../src/progress-tracker/ProgressTrackerStep.styles.ts","../../src/progress-tracker/ProgressTrackerStepIndicator.styles.ts","../../src/progress-tracker/ProgressTrackerStepIndicator.tsx","../../src/progress-tracker/ProgressTrackerStep.tsx","../../src/progress-tracker/ProgressTrackerStepLabel.tsx","../../src/progress-tracker/index.ts"],"sourcesContent":["import { cx } from 'class-variance-authority'\n\nexport const progressList = cx([\n 'flex flex-nowrap items-start group/list',\n 'data-[orientation=horizontal]:flex-row data-[orientation=horizontal]:w-full',\n 'data-[orientation=vertical]:flex-col',\n])\n","import { createContext, type Dispatch, type SetStateAction, useContext } from 'react'\n\nimport type { ProgressTrackerProps } from './ProgressTracker'\n\n// Interfaces\nexport type ProgressTrackerContextInterface = Required<\n Pick<ProgressTrackerProps, 'stepIndex' | 'size' | 'intent' | 'readOnly'>\n> &\n Pick<ProgressTrackerProps, 'onStepClick'> & {\n steps: Map<string, string[]>\n setSteps: Dispatch<SetStateAction<Map<string, string[]>>>\n }\n\nexport interface ProgressTrackerStepContextInterface {\n index: number\n state: 'active' | 'complete' | 'incomplete'\n}\n\n// Contexts\nexport const ProgressTrackerContext = createContext<ProgressTrackerContextInterface>(\n {} as ProgressTrackerContextInterface\n)\n\nexport const ProgressTrackerStepContext = createContext<ProgressTrackerStepContextInterface>(\n {} as ProgressTrackerStepContextInterface\n)\n\n// Hooks\nexport const useProgressTrackerContext = () => useContext(ProgressTrackerContext)\n\nexport const useProgressTrackerStepContext = () => useContext(ProgressTrackerStepContext)\n\nexport const ID_PREFIX = ':progress-tracker'\n","import { cx } from 'class-variance-authority'\nimport { type ComponentPropsWithRef, type PropsWithChildren, useState } from 'react'\n\nimport { progressList } from './ProgressTracker.styles'\nimport {\n ProgressTrackerContext,\n type ProgressTrackerContextInterface,\n} from './ProgressTrackerContext'\nimport type { StepIndicatorVariantProps } from './ProgressTrackerStepIndicator.styles'\n\nexport interface ProgressTrackerProps\n extends ComponentPropsWithRef<'div'>, Pick<StepIndicatorVariantProps, 'size' | 'intent'> {\n /**\n * The orientation of the progress tracker\n * @default 'horizontal\"\n */\n orientation?: 'horizontal' | 'vertical'\n /**\n * The index of the current step.\n * @default 0\n */\n stepIndex?: number\n /**\n * Event handler called when clicking on a step.\n */\n onStepClick?: (stepIndex: number) => void\n /**\n * Sets the component as interactive or not.\n * @default false\n */\n readOnly?: boolean\n}\n\nexport const ProgressTracker = ({\n stepIndex = 0,\n onStepClick,\n readOnly = false,\n intent = 'support',\n size = 'lg',\n orientation = 'horizontal',\n children,\n className,\n ref,\n ...rest\n}: PropsWithChildren<ProgressTrackerProps>) => {\n const [steps, setSteps] = useState<ProgressTrackerContextInterface['steps']>(new Map())\n\n const Component = readOnly ? 'div' : 'nav'\n\n return (\n <ProgressTrackerContext.Provider\n value={{ stepIndex, onStepClick, steps, setSteps, size, intent, readOnly }}\n >\n <Component\n ref={ref}\n data-spark-component=\"progress-tracker\"\n className={cx('inline-flex', className)}\n {...rest}\n >\n <ol\n data-orientation={orientation}\n className={progressList}\n style={{ counterReset: 'step' }}\n >\n {children}\n </ol>\n </Component>\n </ProgressTrackerContext.Provider>\n )\n}\n\nProgressTracker.displayName = 'ProgressTracker'\n","import { cva } from 'class-variance-authority'\n\nexport const stepItemVariant = cva(\n [\n 'relative inline-flex items-start flex-auto first:grow-0 justify-center group/item',\n // Progress Track\n 'after:absolute after:z-base',\n 'last:after:content-none',\n 'after:bg-outline',\n 'group-data-[orientation=horizontal]/list:before:bg-outline',\n // Horizontal orientation\n 'group-data-[orientation=horizontal]/list:px-[1px]',\n 'group-data-[orientation=horizontal]/list:before:absolute group-data-[orientation=horizontal]/list:before:z-base',\n 'group-data-[orientation=horizontal]/list:before:left-0 group-data-[orientation=horizontal]/list:after:right-0',\n 'group-data-[orientation=horizontal]/list:before:h-[1px] group-data-[orientation=horizontal]/list:after:h-[1px]',\n 'first:group-data-[orientation=horizontal]/list:before:content-none',\n // Vertical orientation\n 'group-data-[orientation=vertical]/list:py-[1px]',\n 'group-data-[orientation=vertical]/list:items-start',\n 'group-data-[orientation=vertical]/list:after:w-[1px] group-data-[orientation=vertical]/list:after:bottom-[-1px]',\n ],\n {\n variants: {\n size: {\n sm: [\n // Horizontal orientation\n 'group-data-[orientation=horizontal]/list:before:top-[8px] group-data-[orientation=horizontal]/list:after:top-[8px]',\n 'group-data-[orientation=horizontal]/list:before:right-[calc(50%+12px)] group-data-[orientation=horizontal]/list:after:left-[calc(50%+12px)]',\n 'first:group-data-[orientation=horizontal]/list:after:left-[calc(50%+10px)]',\n 'last:group-data-[orientation=horizontal]/list:before:right-[calc(50%+10px)]',\n // Vertical orientation\n 'group-data-[orientation=vertical]/list:after:left-[8px]',\n 'group-data-[orientation=vertical]/list:after:top-[25px]',\n 'first:group-data-[orientation=vertical]/list:after:top-[21px]',\n ],\n md: [\n // Horizontal orientation\n 'group-data-[orientation=horizontal]/list:before:top-[12px] group-data-[orientation=horizontal]/list:after:top-[12px]',\n 'group-data-[orientation=horizontal]/list:before:right-[calc(50%+16px)] group-data-[orientation=horizontal]/list:after:left-[calc(50%+16px)]',\n 'first:group-data-[orientation=horizontal]/list:after:left-[calc(50%+14px)]',\n 'last:group-data-[orientation=horizontal]/list:before:right-[calc(50%+14px)]',\n // Vertical orientation\n 'group-data-[orientation=vertical]/list:after:left-[12px]',\n 'group-data-[orientation=vertical]/list:after:top-[33px]',\n 'first:group-data-[orientation=vertical]/list:after:top-[29px]',\n ],\n lg: [\n // Horizontal orientation\n 'group-data-[orientation=horizontal]/list:before:top-[16px] group-data-[orientation=horizontal]/list:after:top-[16px]',\n 'group-data-[orientation=horizontal]/list:before:right-[calc(50%+20px)] group-data-[orientation=horizontal]/list:after:left-[calc(50%+20px)]',\n 'first:group-data-[orientation=horizontal]/list:after:left-[calc(50%+18px)]',\n 'last:group-data-[orientation=horizontal]/list:before:right-[calc(50%+18px)]',\n // Vertical orientation\n 'group-data-[orientation=vertical]/list:after:left-[16px]',\n 'group-data-[orientation=vertical]/list:after:top-[41px]',\n 'first:group-data-[orientation=vertical]/list:after:top-[37px]',\n ],\n },\n intent: {\n support: '',\n neutral: '',\n success: '',\n },\n disabled: {\n true: 'before:opacity-dim-3',\n false: '',\n },\n disabledAfter: {\n true: 'after:opacity-dim-3',\n false: '',\n },\n },\n defaultVariants: {\n disabled: false,\n disabledAfter: false,\n size: 'lg',\n intent: 'support',\n },\n }\n)\n\nexport const stepButtonVariant = cva(\n [\n 'relative flex group/btn disabled:cursor-default',\n // Horizontal orientation\n 'group-data-[orientation=horizontal]/list:flex-col group-data-[orientation=horizontal]/list:items-center',\n 'group-data-[orientation=horizontal]/list:text-center group-data-[orientation=horizontal]/list:mx-sm',\n 'group-first/item:group-data-[orientation=horizontal]/list:ml-0 group-last/item:group-data-[orientation=horizontal]/list:mr-0',\n // Vertical orientation\n 'group-data-[orientation=vertical]/list:flex-row group-data-[orientation=vertical]/list:items-start',\n 'group-data-[orientation=vertical]/list:text-left group-data-[orientation=vertical]/list:my-sm',\n 'group-first/item:group-data-[orientation=vertical]/list:mt-0 group-last/item:group-data-[orientation=vertical]/list:mb-0',\n ],\n {\n variants: {\n size: {\n sm: [\n 'group-data-[orientation=horizontal]/list:min-w-sz-16 group-data-[orientation=horizontal]/list:mt-[16px]',\n 'group-data-[orientation=vertical]/list:min-h-sz-16 group-data-[orientation=vertical]/list:ml-[16px]',\n ],\n md: [\n 'group-data-[orientation=horizontal]/list:min-w-sz-24 group-data-[orientation=horizontal]/list:mt-[24px]',\n 'group-data-[orientation=vertical]/list:min-h-sz-24 group-data-[orientation=vertical]/list:ml-[24px]',\n ],\n lg: [\n 'group-data-[orientation=horizontal]/list:min-w-sz-32 group-data-[orientation=horizontal]/list:mt-[32px]',\n 'group-data-[orientation=vertical]/list:min-h-sz-32 group-data-[orientation=vertical]/list:ml-[32px]',\n ],\n },\n readOnly: {\n true: 'cursor-default',\n false: 'cursor-pointer',\n },\n },\n defaultVariants: {\n size: 'lg',\n readOnly: false,\n },\n }\n)\n","import { cva, VariantProps } from 'class-variance-authority'\n\nexport const stepIndicatorVariant = cva(\n [\n 'relative flex shrink-0 justify-center items-center',\n 'rounded-full',\n 'text-body-2-highlight',\n 'group-disabled/btn:opacity-dim-3',\n ],\n {\n variants: {\n size: {\n sm: [\n 'w-sz-16 h-sz-16',\n 'group-data-[orientation=horizontal]/list:mt-[-16px]',\n 'group-data-[orientation=vertical]/list:ml-[-16px]',\n ],\n md: [\n 'w-sz-24 h-sz-24',\n 'group-data-[orientation=horizontal]/list:mt-[-24px]',\n 'group-data-[orientation=vertical]/list:ml-[-24px]',\n ],\n lg: [\n 'w-sz-32 h-sz-32',\n 'group-data-[orientation=horizontal]/list:mt-[-32px]',\n 'group-data-[orientation=vertical]/list:ml-[-32px]',\n ],\n },\n intent: {\n support: '',\n neutral: '',\n success: '',\n },\n state: {\n complete: '',\n incomplete: '',\n active: '',\n },\n },\n /**\n * Known type issue with CVA compoundVariants and VS Code/Intellisense:\n * https://github.com/joe-bell/cva/discussions/195#discussioncomment-6750163\n * */\n /* @ts-ignore */\n compoundVariants: [\n // Support\n {\n intent: 'support',\n state: ['complete', 'incomplete'],\n class: [\n 'text-on-support-container bg-support-container',\n 'group-hover/btn:group-data-[interactive=true]/btn:bg-support-container-hovered',\n 'group-hover/btn:group-data-[interactive=false]/btn:bg-support-container',\n ],\n },\n {\n intent: 'support',\n state: 'active',\n class: 'text-on-support bg-support',\n },\n // Neutral\n {\n intent: 'neutral',\n state: ['complete', 'incomplete'],\n class: [\n 'text-on-neutral-container bg-neutral-container',\n 'group-hover/btn:group-data-[interactive=true]/btn:bg-neutral-container-hovered',\n 'group-hover/btn:group-data-[interactive=false]/btn:bg-neutral-container',\n ],\n },\n {\n intent: 'neutral',\n state: 'active',\n class: 'text-on-neutral bg-neutral',\n },\n // Success\n {\n intent: 'success',\n state: ['complete', 'incomplete'],\n class: [\n 'text-on-success-container bg-success-container',\n 'group-hover/btn:group-data-[interactive=true]/btn:bg-success-container-hovered',\n 'group-hover/btn:group-data-[interactive=false]/btn:bg-success-container',\n ],\n },\n {\n intent: 'success',\n state: 'active',\n class: 'text-on-success bg-success',\n },\n ],\n defaultVariants: {\n size: 'lg',\n state: 'incomplete',\n intent: 'support',\n },\n }\n)\n\nexport type StepIndicatorVariantProps = VariantProps<typeof stepIndicatorVariant>\n","import { Check } from '@spark-ui/icons/Check'\nimport type { ComponentPropsWithoutRef, ReactNode } from 'react'\n\nimport { Icon } from '../icon'\nimport { useProgressTrackerContext, useProgressTrackerStepContext } from './ProgressTrackerContext'\nimport { stepIndicatorVariant } from './ProgressTrackerStepIndicator.styles'\n\nexport type ProgressTrackerStepIndicatorProps = ComponentPropsWithoutRef<'span'> & {\n /**\n * The content to be rendered when step status is complete (checkmark icon by default)\n */\n complete?: ReactNode\n /**\n * The content to be rendered when step status is incomplete (step index by default)\n */\n incomplete?: ReactNode\n}\n\nconst CompleteIndicator = () => (\n <Icon size=\"sm\">\n <Check />\n </Icon>\n)\n\nexport const ProgressTrackerStepIndicator = ({\n complete,\n incomplete,\n className,\n}: ProgressTrackerStepIndicatorProps) => {\n const { size, intent } = useProgressTrackerContext()\n const { index, state } = useProgressTrackerStepContext()\n\n return (\n <span className={stepIndicatorVariant({ size, intent, state, className })} aria-hidden=\"true\">\n {size !== 'sm' && (\n <>\n {state === 'complete' && (complete === undefined ? <CompleteIndicator /> : complete)}\n {state !== 'complete' && (incomplete === undefined ? `${index + 1}` : incomplete)}\n </>\n )}\n </span>\n )\n}\n\nProgressTrackerStepIndicator.displayName = 'ProgressTracker.StepIndicator'\n","import { type ComponentPropsWithRef, type ReactNode, useEffect, useId } from 'react'\n\nimport {\n ID_PREFIX,\n ProgressTrackerStepContext,\n useProgressTrackerContext,\n} from './ProgressTrackerContext'\nimport { stepButtonVariant, stepItemVariant } from './ProgressTrackerStep.styles'\nimport { ProgressTrackerStepIndicator } from './ProgressTrackerStepIndicator'\n\nexport type ProgressTrackerStepProps = ComponentPropsWithRef<'li'> &\n (\n | {\n disabled?: boolean\n children: ReactNode\n }\n | {\n disabled?: boolean\n 'aria-label': string\n }\n )\n\nexport const ProgressTrackerStep = ({\n disabled = false,\n children,\n 'aria-label': ariaLabel,\n className,\n ref,\n ...rest\n}: ProgressTrackerStepProps) => {\n const {\n stepIndex: currentStepIndex,\n steps,\n onStepClick,\n setSteps,\n size,\n intent,\n readOnly,\n } = useProgressTrackerContext()\n\n const stepId = `${ID_PREFIX}-step-${useId()}`\n const stepIndex = [...steps.keys()].indexOf(stepId)\n\n const disabledAfter = (() => {\n const nextStepId = [...steps.keys()][stepIndex + 1]\n\n return !!(nextStepId && steps.get(nextStepId)?.includes('disabled'))\n })()\n\n const progressState = (() => {\n if (stepIndex === currentStepIndex) return 'active'\n else if (stepIndex < currentStepIndex) return 'complete'\n else return 'incomplete'\n })()\n\n useEffect(() => {\n setSteps(steps => {\n const newSteps = new Map(steps)\n\n return newSteps.set(\n stepId,\n [progressState, disabled ? 'disabled' : ''].filter(v => !!v)\n )\n })\n\n return () => {\n setSteps(steps => {\n steps.delete(stepId)\n\n return steps\n })\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n return (\n <li\n data-spark-component=\"progress-tracker-step\"\n id={stepId}\n ref={ref}\n data-state={progressState}\n {...(progressState === 'active' && {\n 'aria-current': 'step',\n })}\n className={stepItemVariant({\n size,\n intent,\n disabled,\n disabledAfter,\n })}\n {...rest}\n >\n <button\n type=\"button\"\n aria-label={ariaLabel}\n data-interactive={!disabled && !readOnly}\n {...(!disabled &&\n !readOnly && {\n onClick: () => onStepClick?.(stepIndex),\n })}\n disabled={disabled}\n className={stepButtonVariant({\n size,\n readOnly,\n className,\n })}\n >\n <ProgressTrackerStepContext.Provider\n value={{\n index: stepIndex,\n state: progressState,\n }}\n >\n {children || <ProgressTrackerStepIndicator />}\n </ProgressTrackerStepContext.Provider>\n </button>\n </li>\n )\n}\n\nProgressTrackerStep.displayName = 'ProgressTracker.Step'\n","import { cva } from 'class-variance-authority'\nimport type { ComponentPropsWithoutRef, ReactNode } from 'react'\n\nimport { useProgressTrackerStepContext } from './ProgressTrackerContext'\n\ntype ProgressTrackerStepLabelProps = ComponentPropsWithoutRef<'span'> & {\n children: ReactNode\n}\n\nconst stepLabel = cva(\n [\n 'flex text-body-2',\n 'text-on-surface group-disabled/btn:text-on-surface/dim-1',\n 'group-data-[orientation=horizontal]/list:mt-md',\n 'group-data-[orientation=vertical]/list:ml-md',\n 'group-data-[orientation=vertical]/list:my-auto',\n ],\n {\n variants: {\n state: {\n complete: '',\n incomplete: '',\n active: 'font-medium',\n },\n },\n }\n)\n\nexport const ProgressTrackerStepLabel = ({\n className,\n children,\n}: ProgressTrackerStepLabelProps) => {\n const { state } = useProgressTrackerStepContext()\n\n return <span className={stepLabel({ state, className })}>{children}</span>\n}\n\nProgressTrackerStepLabel.displayName = 'ProgressTracker.StepLabel'\n","import { ProgressTracker as Root, type ProgressTrackerProps } from './ProgressTracker'\nimport { ProgressTrackerStep as Step, type ProgressTrackerStepProps } from './ProgressTrackerStep'\nimport {\n ProgressTrackerStepIndicator as StepIndicator,\n type ProgressTrackerStepIndicatorProps,\n} from './ProgressTrackerStepIndicator'\nimport { ProgressTrackerStepLabel as StepLabel } from './ProgressTrackerStepLabel'\n\n/**\n * A component that displays a multi-step process with visual indicators for completed, current, and upcoming steps.\n */\nexport const ProgressTracker: typeof Root & {\n Step: typeof Step\n StepLabel: typeof StepLabel\n StepIndicator: typeof StepIndicator\n} = Object.assign(Root, {\n Step,\n StepLabel,\n StepIndicator,\n})\n\nProgressTracker.displayName = 'ProgressTracker'\nStep.displayName = 'ProgressTracker.Step'\nStepLabel.displayName = 'ProgressTracker.StepLabel'\nStepIndicator.displayName = 'ProgressTracker.StepIndicator'\n\nexport type { ProgressTrackerProps, ProgressTrackerStepProps, ProgressTrackerStepIndicatorProps }\n"],"mappings":"yQAEA,IAAa,GAAA,EAAA,EAAA,IAAkB,CAC7B,0CACA,8EACA,uCACD,CAAC,CCaW,GAAA,EAAA,EAAA,eACX,EAAE,CACH,CAEY,GAAA,EAAA,EAAA,eACX,EAA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EA,0GACA,sGACA,+HAEA,qGACA,gGACA,2HACD,CACD,CACE,SAAU,CACR,KAAM,CACJ,GAAI,CACF,0GACA,sGACD,CACD,GAAI,CACF,0GACA,sGACD,CACD,GAAI,CACF,0GACA,sGACD,CACF,CACD,SAAU,CACR,KAAM,iBACN,MAAO,iBACR,CACF,CACD,gBAAiB,CACf,KAAM,KACN,SAAU,GACX,CACF,CACF,CCrHY,GAAA,EAAA,EAAA,KACX,CACE,qDACA,eACA,wBACA,mCACD,CACD,CACE,SAAU,CACR,KAAM,CACJ,GAAI,CACF,kBACA,sDACA,oDACD,CACD,GAAI,CACF,kBACA,sDACA,oDACD,CACD,GAAI,CACF,kBACA,sDACA,oDACD,CACF,CACD,OAAQ,CACN,QAAS,GACT,QAAS,GACT,QAAS,GACV,CACD,MAAO,CACL,SAAU,GACV,WAAY,GACZ,OAAQ,GACT,CACF,CAMD,iBAAkB,CAEhB,CACE,OAAQ,UACR,MAAO,CAAC,WAAY,aAAa,CACjC,MAAO,CACL,iDACA,iFACA,0EACD,CACF,CACD,CACE,OAAQ,UACR,MAAO,SACP,MAAO,6BACR,CAED,CACE,OAAQ,UACR,MAAO,CAAC,WAAY,aAAa,CACjC,MAAO,CACL,iDACA,iFACA,0EACD,CACF,CACD,CACE,OAAQ,UACR,MAAO,SACP,MAAO,6BACR,CAED,CACE,OAAQ,UACR,MAAO,CAAC,WAAY,aAAa,CACjC,MAAO,CACL,iDACA,iFACA,0EACD,CACF,CACD,CACE,OAAQ,UACR,MAAO,SACP,MAAO,6BACR,CACF,CACD,gBAAiB,CACf,KAAM,KACN,MAAO,aACP,OAAQ,UACT,CACF,CACF,CC/EK,OACJ,EAAA,EAAA,KAAC,EAAA,EAAD,CAAM,KAAK,eACT,EAAA,EAAA,KAAC,EAAA,MAAD,EAAS,CAAA,CACJ,CAAA,CAGI,GAAgC,CAC3C,WACA,aACA,eACuC,CACvC,GAAM,CAAE,OAAM,UAAW,GAA2B,CAC9C,CAAE,QAAO,SAAU,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AC,SAAD,CACE,KAAK,SACL,aAAY,EACZ,mBAAkB,CAAC,GAAY,CAAC,EAChC,GAAK,CAAC,GACJ,CAAC,GAAY,CACX,YAAe,IAAc,EAAU,CACxC,CACO,WACV,UAAW,EAAkB,CAC3B,OACA,WACA,YACD,CAAC,WAEF,EAAA,EAAA,KAAC,EAA2B,SAA5B,CACE,MAAO,CACL,MAAO,EACP,MAAO,EACR,UAEA,IAAY,EAAA,EAAA,KAAC,EAAD,EAAgC,CAAA,CACT,CAAA,CAC/B,CAAA,CACN,CAAA,EAIT,EAAoB,YAAc,uBC/GlC,IAAM,GAAA,EAAA,EAAA,KACJ,CACE,mBACA,2DACA,iDACA,+CACA,iDACD,CACD,CACE,SAAU,CACR,MAAO,CACL,SAAU,GACV,WAAY,GACZ,OAAQ,cACT,CACF,CACF,CACF,CAEY,GAA4B,CACvC,YACA,cACmC,CACnC,GAAM,CAAE,SAAU,GAA+B,CAEjD,OAAO,EAAA,EAAA,KAAC,OAAD,CAAM,UAAW,EAAU,CAAE,QAAO,YAAW,CAAC,CAAG,WAAgB,CAAA,EAG5E,EAAyB,YAAc,4BC1BvC,IAAa,EAIT,OAAO,OAAO,EAAM,CACtB,KAAA,EACA,UAAA,EACA,cAAA,EACD,CAAC,CAEF,EAAgB,YAAc,kBAC9B,EAAK,YAAc,uBACnB,EAAU,YAAc,4BACxB,EAAc,YAAc"}
|
|
@@ -129,7 +129,7 @@ var y = t([
|
|
|
129
129
|
}), x = t([
|
|
130
130
|
"relative flex shrink-0 justify-center items-center",
|
|
131
131
|
"rounded-full",
|
|
132
|
-
"text-body-2
|
|
132
|
+
"text-body-2-highlight",
|
|
133
133
|
"group-disabled/btn:opacity-dim-3"
|
|
134
134
|
], {
|
|
135
135
|
variants: {
|
|
@@ -274,7 +274,7 @@ w.displayName = "ProgressTracker.Step";
|
|
|
274
274
|
//#endregion
|
|
275
275
|
//#region src/progress-tracker/ProgressTrackerStepLabel.tsx
|
|
276
276
|
var T = t([
|
|
277
|
-
"flex text-body-2
|
|
277
|
+
"flex text-body-2",
|
|
278
278
|
"text-on-surface group-disabled/btn:text-on-surface/dim-1",
|
|
279
279
|
"group-data-[orientation=horizontal]/list:mt-md",
|
|
280
280
|
"group-data-[orientation=vertical]/list:ml-md",
|
|
@@ -282,7 +282,7 @@ var T = t([
|
|
|
282
282
|
], { variants: { state: {
|
|
283
283
|
complete: "",
|
|
284
284
|
incomplete: "",
|
|
285
|
-
active: "font-
|
|
285
|
+
active: "font-medium"
|
|
286
286
|
} } }), E = ({ className: e, children: t }) => {
|
|
287
287
|
let { state: n } = g();
|
|
288
288
|
return /* @__PURE__ */ l("span", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/progress-tracker/ProgressTracker.styles.ts","../../src/progress-tracker/ProgressTrackerContext.ts","../../src/progress-tracker/ProgressTracker.tsx","../../src/progress-tracker/ProgressTrackerStep.styles.ts","../../src/progress-tracker/ProgressTrackerStepIndicator.styles.ts","../../src/progress-tracker/ProgressTrackerStepIndicator.tsx","../../src/progress-tracker/ProgressTrackerStep.tsx","../../src/progress-tracker/ProgressTrackerStepLabel.tsx","../../src/progress-tracker/index.ts"],"sourcesContent":["import { cx } from 'class-variance-authority'\n\nexport const progressList = cx([\n 'flex flex-nowrap items-start group/list',\n 'data-[orientation=horizontal]:flex-row data-[orientation=horizontal]:w-full',\n 'data-[orientation=vertical]:flex-col',\n])\n","import { createContext, type Dispatch, type SetStateAction, useContext } from 'react'\n\nimport type { ProgressTrackerProps } from './ProgressTracker'\n\n// Interfaces\nexport type ProgressTrackerContextInterface = Required<\n Pick<ProgressTrackerProps, 'stepIndex' | 'size' | 'intent' | 'readOnly'>\n> &\n Pick<ProgressTrackerProps, 'onStepClick'> & {\n steps: Map<string, string[]>\n setSteps: Dispatch<SetStateAction<Map<string, string[]>>>\n }\n\nexport interface ProgressTrackerStepContextInterface {\n index: number\n state: 'active' | 'complete' | 'incomplete'\n}\n\n// Contexts\nexport const ProgressTrackerContext = createContext<ProgressTrackerContextInterface>(\n {} as ProgressTrackerContextInterface\n)\n\nexport const ProgressTrackerStepContext = createContext<ProgressTrackerStepContextInterface>(\n {} as ProgressTrackerStepContextInterface\n)\n\n// Hooks\nexport const useProgressTrackerContext = () => useContext(ProgressTrackerContext)\n\nexport const useProgressTrackerStepContext = () => useContext(ProgressTrackerStepContext)\n\nexport const ID_PREFIX = ':progress-tracker'\n","import { cx } from 'class-variance-authority'\nimport { type ComponentPropsWithRef, type PropsWithChildren, useState } from 'react'\n\nimport { progressList } from './ProgressTracker.styles'\nimport {\n ProgressTrackerContext,\n type ProgressTrackerContextInterface,\n} from './ProgressTrackerContext'\nimport type { StepIndicatorVariantProps } from './ProgressTrackerStepIndicator.styles'\n\nexport interface ProgressTrackerProps\n extends ComponentPropsWithRef<'div'>, Pick<StepIndicatorVariantProps, 'size' | 'intent'> {\n /**\n * The orientation of the progress tracker\n * @default 'horizontal\"\n */\n orientation?: 'horizontal' | 'vertical'\n /**\n * The index of the current step.\n * @default 0\n */\n stepIndex?: number\n /**\n * Event handler called when clicking on a step.\n */\n onStepClick?: (stepIndex: number) => void\n /**\n * Sets the component as interactive or not.\n * @default false\n */\n readOnly?: boolean\n}\n\nexport const ProgressTracker = ({\n stepIndex = 0,\n onStepClick,\n readOnly = false,\n intent = 'support',\n size = 'lg',\n orientation = 'horizontal',\n children,\n className,\n ref,\n ...rest\n}: PropsWithChildren<ProgressTrackerProps>) => {\n const [steps, setSteps] = useState<ProgressTrackerContextInterface['steps']>(new Map())\n\n const Component = readOnly ? 'div' : 'nav'\n\n return (\n <ProgressTrackerContext.Provider\n value={{ stepIndex, onStepClick, steps, setSteps, size, intent, readOnly }}\n >\n <Component\n ref={ref}\n data-spark-component=\"progress-tracker\"\n className={cx('inline-flex', className)}\n {...rest}\n >\n <ol\n data-orientation={orientation}\n className={progressList}\n style={{ counterReset: 'step' }}\n >\n {children}\n </ol>\n </Component>\n </ProgressTrackerContext.Provider>\n )\n}\n\nProgressTracker.displayName = 'ProgressTracker'\n","import { cva } from 'class-variance-authority'\n\nexport const stepItemVariant = cva(\n [\n 'relative inline-flex items-start flex-auto first:grow-0 justify-center group/item',\n // Progress Track\n 'after:absolute after:z-base',\n 'last:after:content-none',\n 'after:bg-outline',\n 'group-data-[orientation=horizontal]/list:before:bg-outline',\n // Horizontal orientation\n 'group-data-[orientation=horizontal]/list:px-[1px]',\n 'group-data-[orientation=horizontal]/list:before:absolute group-data-[orientation=horizontal]/list:before:z-base',\n 'group-data-[orientation=horizontal]/list:before:left-0 group-data-[orientation=horizontal]/list:after:right-0',\n 'group-data-[orientation=horizontal]/list:before:h-[1px] group-data-[orientation=horizontal]/list:after:h-[1px]',\n 'first:group-data-[orientation=horizontal]/list:before:content-none',\n // Vertical orientation\n 'group-data-[orientation=vertical]/list:py-[1px]',\n 'group-data-[orientation=vertical]/list:items-start',\n 'group-data-[orientation=vertical]/list:after:w-[1px] group-data-[orientation=vertical]/list:after:bottom-[-1px]',\n ],\n {\n variants: {\n size: {\n sm: [\n // Horizontal orientation\n 'group-data-[orientation=horizontal]/list:before:top-[8px] group-data-[orientation=horizontal]/list:after:top-[8px]',\n 'group-data-[orientation=horizontal]/list:before:right-[calc(50%+12px)] group-data-[orientation=horizontal]/list:after:left-[calc(50%+12px)]',\n 'first:group-data-[orientation=horizontal]/list:after:left-[calc(50%+10px)]',\n 'last:group-data-[orientation=horizontal]/list:before:right-[calc(50%+10px)]',\n // Vertical orientation\n 'group-data-[orientation=vertical]/list:after:left-[8px]',\n 'group-data-[orientation=vertical]/list:after:top-[25px]',\n 'first:group-data-[orientation=vertical]/list:after:top-[21px]',\n ],\n md: [\n // Horizontal orientation\n 'group-data-[orientation=horizontal]/list:before:top-[12px] group-data-[orientation=horizontal]/list:after:top-[12px]',\n 'group-data-[orientation=horizontal]/list:before:right-[calc(50%+16px)] group-data-[orientation=horizontal]/list:after:left-[calc(50%+16px)]',\n 'first:group-data-[orientation=horizontal]/list:after:left-[calc(50%+14px)]',\n 'last:group-data-[orientation=horizontal]/list:before:right-[calc(50%+14px)]',\n // Vertical orientation\n 'group-data-[orientation=vertical]/list:after:left-[12px]',\n 'group-data-[orientation=vertical]/list:after:top-[33px]',\n 'first:group-data-[orientation=vertical]/list:after:top-[29px]',\n ],\n lg: [\n // Horizontal orientation\n 'group-data-[orientation=horizontal]/list:before:top-[16px] group-data-[orientation=horizontal]/list:after:top-[16px]',\n 'group-data-[orientation=horizontal]/list:before:right-[calc(50%+20px)] group-data-[orientation=horizontal]/list:after:left-[calc(50%+20px)]',\n 'first:group-data-[orientation=horizontal]/list:after:left-[calc(50%+18px)]',\n 'last:group-data-[orientation=horizontal]/list:before:right-[calc(50%+18px)]',\n // Vertical orientation\n 'group-data-[orientation=vertical]/list:after:left-[16px]',\n 'group-data-[orientation=vertical]/list:after:top-[41px]',\n 'first:group-data-[orientation=vertical]/list:after:top-[37px]',\n ],\n },\n intent: {\n support: '',\n neutral: '',\n success: '',\n },\n disabled: {\n true: 'before:opacity-dim-3',\n false: '',\n },\n disabledAfter: {\n true: 'after:opacity-dim-3',\n false: '',\n },\n },\n defaultVariants: {\n disabled: false,\n disabledAfter: false,\n size: 'lg',\n intent: 'support',\n },\n }\n)\n\nexport const stepButtonVariant = cva(\n [\n 'relative flex group/btn disabled:cursor-default',\n // Horizontal orientation\n 'group-data-[orientation=horizontal]/list:flex-col group-data-[orientation=horizontal]/list:items-center',\n 'group-data-[orientation=horizontal]/list:text-center group-data-[orientation=horizontal]/list:mx-sm',\n 'group-first/item:group-data-[orientation=horizontal]/list:ml-0 group-last/item:group-data-[orientation=horizontal]/list:mr-0',\n // Vertical orientation\n 'group-data-[orientation=vertical]/list:flex-row group-data-[orientation=vertical]/list:items-start',\n 'group-data-[orientation=vertical]/list:text-left group-data-[orientation=vertical]/list:my-sm',\n 'group-first/item:group-data-[orientation=vertical]/list:mt-0 group-last/item:group-data-[orientation=vertical]/list:mb-0',\n ],\n {\n variants: {\n size: {\n sm: [\n 'group-data-[orientation=horizontal]/list:min-w-sz-16 group-data-[orientation=horizontal]/list:mt-[16px]',\n 'group-data-[orientation=vertical]/list:min-h-sz-16 group-data-[orientation=vertical]/list:ml-[16px]',\n ],\n md: [\n 'group-data-[orientation=horizontal]/list:min-w-sz-24 group-data-[orientation=horizontal]/list:mt-[24px]',\n 'group-data-[orientation=vertical]/list:min-h-sz-24 group-data-[orientation=vertical]/list:ml-[24px]',\n ],\n lg: [\n 'group-data-[orientation=horizontal]/list:min-w-sz-32 group-data-[orientation=horizontal]/list:mt-[32px]',\n 'group-data-[orientation=vertical]/list:min-h-sz-32 group-data-[orientation=vertical]/list:ml-[32px]',\n ],\n },\n readOnly: {\n true: 'cursor-default',\n false: 'cursor-pointer',\n },\n },\n defaultVariants: {\n size: 'lg',\n readOnly: false,\n },\n }\n)\n","import { cva, VariantProps } from 'class-variance-authority'\n\nexport const stepIndicatorVariant = cva(\n [\n 'relative flex shrink-0 justify-center items-center',\n 'rounded-full',\n 'text-body-2 font-bold',\n 'group-disabled/btn:opacity-dim-3',\n ],\n {\n variants: {\n size: {\n sm: [\n 'w-sz-16 h-sz-16',\n 'group-data-[orientation=horizontal]/list:mt-[-16px]',\n 'group-data-[orientation=vertical]/list:ml-[-16px]',\n ],\n md: [\n 'w-sz-24 h-sz-24',\n 'group-data-[orientation=horizontal]/list:mt-[-24px]',\n 'group-data-[orientation=vertical]/list:ml-[-24px]',\n ],\n lg: [\n 'w-sz-32 h-sz-32',\n 'group-data-[orientation=horizontal]/list:mt-[-32px]',\n 'group-data-[orientation=vertical]/list:ml-[-32px]',\n ],\n },\n intent: {\n support: '',\n neutral: '',\n success: '',\n },\n state: {\n complete: '',\n incomplete: '',\n active: '',\n },\n },\n /**\n * Known type issue with CVA compoundVariants and VS Code/Intellisense:\n * https://github.com/joe-bell/cva/discussions/195#discussioncomment-6750163\n * */\n /* @ts-ignore */\n compoundVariants: [\n // Support\n {\n intent: 'support',\n state: ['complete', 'incomplete'],\n class: [\n 'text-on-support-container bg-support-container',\n 'group-hover/btn:group-data-[interactive=true]/btn:bg-support-container-hovered',\n 'group-hover/btn:group-data-[interactive=false]/btn:bg-support-container',\n ],\n },\n {\n intent: 'support',\n state: 'active',\n class: 'text-on-support bg-support',\n },\n // Neutral\n {\n intent: 'neutral',\n state: ['complete', 'incomplete'],\n class: [\n 'text-on-neutral-container bg-neutral-container',\n 'group-hover/btn:group-data-[interactive=true]/btn:bg-neutral-container-hovered',\n 'group-hover/btn:group-data-[interactive=false]/btn:bg-neutral-container',\n ],\n },\n {\n intent: 'neutral',\n state: 'active',\n class: 'text-on-neutral bg-neutral',\n },\n // Success\n {\n intent: 'success',\n state: ['complete', 'incomplete'],\n class: [\n 'text-on-success-container bg-success-container',\n 'group-hover/btn:group-data-[interactive=true]/btn:bg-success-container-hovered',\n 'group-hover/btn:group-data-[interactive=false]/btn:bg-success-container',\n ],\n },\n {\n intent: 'success',\n state: 'active',\n class: 'text-on-success bg-success',\n },\n ],\n defaultVariants: {\n size: 'lg',\n state: 'incomplete',\n intent: 'support',\n },\n }\n)\n\nexport type StepIndicatorVariantProps = VariantProps<typeof stepIndicatorVariant>\n","import { Check } from '@spark-ui/icons/Check'\nimport type { ComponentPropsWithoutRef, ReactNode } from 'react'\n\nimport { Icon } from '../icon'\nimport { useProgressTrackerContext, useProgressTrackerStepContext } from './ProgressTrackerContext'\nimport { stepIndicatorVariant } from './ProgressTrackerStepIndicator.styles'\n\nexport type ProgressTrackerStepIndicatorProps = ComponentPropsWithoutRef<'span'> & {\n /**\n * The content to be rendered when step status is complete (checkmark icon by default)\n */\n complete?: ReactNode\n /**\n * The content to be rendered when step status is incomplete (step index by default)\n */\n incomplete?: ReactNode\n}\n\nconst CompleteIndicator = () => (\n <Icon size=\"sm\">\n <Check />\n </Icon>\n)\n\nexport const ProgressTrackerStepIndicator = ({\n complete,\n incomplete,\n className,\n}: ProgressTrackerStepIndicatorProps) => {\n const { size, intent } = useProgressTrackerContext()\n const { index, state } = useProgressTrackerStepContext()\n\n return (\n <span className={stepIndicatorVariant({ size, intent, state, className })} aria-hidden=\"true\">\n {size !== 'sm' && (\n <>\n {state === 'complete' && (complete === undefined ? <CompleteIndicator /> : complete)}\n {state !== 'complete' && (incomplete === undefined ? `${index + 1}` : incomplete)}\n </>\n )}\n </span>\n )\n}\n\nProgressTrackerStepIndicator.displayName = 'ProgressTracker.StepIndicator'\n","import { type ComponentPropsWithRef, type ReactNode, useEffect, useId } from 'react'\n\nimport {\n ID_PREFIX,\n ProgressTrackerStepContext,\n useProgressTrackerContext,\n} from './ProgressTrackerContext'\nimport { stepButtonVariant, stepItemVariant } from './ProgressTrackerStep.styles'\nimport { ProgressTrackerStepIndicator } from './ProgressTrackerStepIndicator'\n\nexport type ProgressTrackerStepProps = ComponentPropsWithRef<'li'> &\n (\n | {\n disabled?: boolean\n children: ReactNode\n }\n | {\n disabled?: boolean\n 'aria-label': string\n }\n )\n\nexport const ProgressTrackerStep = ({\n disabled = false,\n children,\n 'aria-label': ariaLabel,\n className,\n ref,\n ...rest\n}: ProgressTrackerStepProps) => {\n const {\n stepIndex: currentStepIndex,\n steps,\n onStepClick,\n setSteps,\n size,\n intent,\n readOnly,\n } = useProgressTrackerContext()\n\n const stepId = `${ID_PREFIX}-step-${useId()}`\n const stepIndex = [...steps.keys()].indexOf(stepId)\n\n const disabledAfter = (() => {\n const nextStepId = [...steps.keys()][stepIndex + 1]\n\n return !!(nextStepId && steps.get(nextStepId)?.includes('disabled'))\n })()\n\n const progressState = (() => {\n if (stepIndex === currentStepIndex) return 'active'\n else if (stepIndex < currentStepIndex) return 'complete'\n else return 'incomplete'\n })()\n\n useEffect(() => {\n setSteps(steps => {\n const newSteps = new Map(steps)\n\n return newSteps.set(\n stepId,\n [progressState, disabled ? 'disabled' : ''].filter(v => !!v)\n )\n })\n\n return () => {\n setSteps(steps => {\n steps.delete(stepId)\n\n return steps\n })\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n return (\n <li\n data-spark-component=\"progress-tracker-step\"\n id={stepId}\n ref={ref}\n data-state={progressState}\n {...(progressState === 'active' && {\n 'aria-current': 'step',\n })}\n className={stepItemVariant({\n size,\n intent,\n disabled,\n disabledAfter,\n })}\n {...rest}\n >\n <button\n type=\"button\"\n aria-label={ariaLabel}\n data-interactive={!disabled && !readOnly}\n {...(!disabled &&\n !readOnly && {\n onClick: () => onStepClick?.(stepIndex),\n })}\n disabled={disabled}\n className={stepButtonVariant({\n size,\n readOnly,\n className,\n })}\n >\n <ProgressTrackerStepContext.Provider\n value={{\n index: stepIndex,\n state: progressState,\n }}\n >\n {children || <ProgressTrackerStepIndicator />}\n </ProgressTrackerStepContext.Provider>\n </button>\n </li>\n )\n}\n\nProgressTrackerStep.displayName = 'ProgressTracker.Step'\n","import { cva } from 'class-variance-authority'\nimport type { ComponentPropsWithoutRef, ReactNode } from 'react'\n\nimport { useProgressTrackerStepContext } from './ProgressTrackerContext'\n\ntype ProgressTrackerStepLabelProps = ComponentPropsWithoutRef<'span'> & {\n children: ReactNode\n}\n\nconst stepLabel = cva(\n [\n 'flex text-body-2 ',\n 'text-on-surface group-disabled/btn:text-on-surface/dim-1',\n 'group-data-[orientation=horizontal]/list:mt-md',\n 'group-data-[orientation=vertical]/list:ml-md',\n 'group-data-[orientation=vertical]/list:my-auto',\n ],\n {\n variants: {\n state: {\n complete: '',\n incomplete: '',\n active: 'font-bold',\n },\n },\n }\n)\n\nexport const ProgressTrackerStepLabel = ({\n className,\n children,\n}: ProgressTrackerStepLabelProps) => {\n const { state } = useProgressTrackerStepContext()\n\n return <span className={stepLabel({ state, className })}>{children}</span>\n}\n\nProgressTrackerStepLabel.displayName = 'ProgressTracker.StepLabel'\n","import { ProgressTracker as Root, type ProgressTrackerProps } from './ProgressTracker'\nimport { ProgressTrackerStep as Step, type ProgressTrackerStepProps } from './ProgressTrackerStep'\nimport {\n ProgressTrackerStepIndicator as StepIndicator,\n type ProgressTrackerStepIndicatorProps,\n} from './ProgressTrackerStepIndicator'\nimport { ProgressTrackerStepLabel as StepLabel } from './ProgressTrackerStepLabel'\n\n/**\n * A component that displays a multi-step process with visual indicators for completed, current, and upcoming steps.\n */\nexport const ProgressTracker: typeof Root & {\n Step: typeof Step\n StepLabel: typeof StepLabel\n StepIndicator: typeof StepIndicator\n} = Object.assign(Root, {\n Step,\n StepLabel,\n StepIndicator,\n})\n\nProgressTracker.displayName = 'ProgressTracker'\nStep.displayName = 'ProgressTracker.Step'\nStepLabel.displayName = 'ProgressTracker.StepLabel'\nStepIndicator.displayName = 'ProgressTracker.StepIndicator'\n\nexport type { ProgressTrackerProps, ProgressTrackerStepProps, ProgressTrackerStepIndicatorProps }\n"],"mappings":";;;;;;AAEA,IAAa,IAAe,EAAG;CAC7B;CACA;CACA;CACD,CAAC,ECaW,IAAyB,EACpC,EAAE,CACH,EAEY,IAA6B,EACxC,EAAE,CACH,EAGY,UAAkC,EAAW,EAAuB,EAEpE,UAAsC,EAAW,EAA2B,EAE5E,IAAY,qBCCZ,KAAmB,EAC9B,eAAY,GACZ,gBACA,cAAW,IACX,YAAS,WACT,UAAO,MACP,iBAAc,cACd,aACA,cACA,QACA,GAAG,QAC0C;CAC7C,IAAM,CAAC,GAAO,KAAY,kBAAmD,IAAI,KAAK,CAAC,EAEjF,IAAY,IAAW,QAAQ;AAErC,QACE,kBAAC,EAAuB,UAAxB;EACE,OAAO;GAAE;GAAW;GAAa;GAAO;GAAU;GAAM;GAAQ;GAAU;YAE1E,kBAAC,GAAD;GACO;GACL,wBAAqB;GACrB,WAAW,EAAG,eAAe,EAAU;GACvC,GAAI;aAEJ,kBAAC,MAAD;IACE,oBAAkB;IAClB,WAAW;IACX,OAAO,EAAE,cAAc,QAAQ;IAE9B;IACE,CAAA;GACK,CAAA;EACoB,CAAA;;AAItC,EAAgB,cAAc;;;ACrE9B,IAAa,IAAkB,EAC7B;CACE;CAEA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACD,EACD;CACE,UAAU;EACR,MAAM;GACJ,IAAI;IAEF;IACA;IACA;IACA;IAEA;IACA;IACA;IACD;GACD,IAAI;IAEF;IACA;IACA;IACA;IAEA;IACA;IACA;IACD;GACD,IAAI;IAEF;IACA;IACA;IACA;IAEA;IACA;IACA;IACD;GACF;EACD,QAAQ;GACN,SAAS;GACT,SAAS;GACT,SAAS;GACV;EACD,UAAU;GACR,MAAM;GACN,OAAO;GACR;EACD,eAAe;GACb,MAAM;GACN,OAAO;GACR;EACF;CACD,iBAAiB;EACf,UAAU;EACV,eAAe;EACf,MAAM;EACN,QAAQ;EACT;CACF,CACF,EAEY,IAAoB,EAC/B;CACE;CAEA;CACA;CACA;CAEA;CACA;CACA;CACD,EACD;CACE,UAAU;EACR,MAAM;GACJ,IAAI,CACF,2GACA,sGACD;GACD,IAAI,CACF,2GACA,sGACD;GACD,IAAI,CACF,2GACA,sGACD;GACF;EACD,UAAU;GACR,MAAM;GACN,OAAO;GACR;EACF;CACD,iBAAiB;EACf,MAAM;EACN,UAAU;EACX;CACF,CACF,ECrHY,IAAuB,EAClC;CACE;CACA;CACA;CACA;CACD,EACD;CACE,UAAU;EACR,MAAM;GACJ,IAAI;IACF;IACA;IACA;IACD;GACD,IAAI;IACF;IACA;IACA;IACD;GACD,IAAI;IACF;IACA;IACA;IACD;GACF;EACD,QAAQ;GACN,SAAS;GACT,SAAS;GACT,SAAS;GACV;EACD,OAAO;GACL,UAAU;GACV,YAAY;GACZ,QAAQ;GACT;EACF;CAMD,kBAAkB;EAEhB;GACE,QAAQ;GACR,OAAO,CAAC,YAAY,aAAa;GACjC,OAAO;IACL;IACA;IACA;IACD;GACF;EACD;GACE,QAAQ;GACR,OAAO;GACP,OAAO;GACR;EAED;GACE,QAAQ;GACR,OAAO,CAAC,YAAY,aAAa;GACjC,OAAO;IACL;IACA;IACA;IACD;GACF;EACD;GACE,QAAQ;GACR,OAAO;GACP,OAAO;GACR;EAED;GACE,QAAQ;GACR,OAAO,CAAC,YAAY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CACD,QAEW;AACX,KAAS,OACP,EAAM,OAAO,EAAO,EAEb,GACP;KAGH,EAAE,CAAC,EAGJ,kBAAC,MAAD;EACE,wBAAqB;EACrB,IAAI;EACC;EACL,cAAY;EACZ,GAAK,MAAkB,YAAY,EACjC,gBAAgB,QACjB;EACD,WAAW,EAAgB;GACzB;GACA;GACA;GACA;GACD,CAAC;EACF,GAAI;YAEJ,kBAAC,UAAD;GACE,MAAK;GACL,cAAY;GACZ,oBAAkB,CAAC,KAAY,CAAC;GAChC,GAAK,CAAC,KACJ,CAAC,KAAY,EACX,eAAe,IAAc,EAAU,EACxC;GACO;GACV,WAAW,EAAkB;IAC3B;IACA;IACA;IACD,CAAC;aAEF,kBAAC,EAA2B,UAA5B;IACE,OAAO;KACL,OAAO;KACP,OAAO;KACR;cAEA,KAAY,kBAAC,GAAD,EAAgC,CAAA;IACT,CAAA;GAC/B,CAAA;EACN,CAAA;;AAIT,EAAoB,cAAc;;;AC/GlC,IAAM,IAAY,EAChB;CACE;CACA;CACA;CACA;CACA;CACD,EACD,EACE,UAAU,EACR,OAAO;CACL,UAAU;CACV,YAAY;CACZ,QAAQ;CACT,EACF,EACF,CACF,EAEY,KAA4B,EACvC,cACA,kBACmC;CACnC,IAAM,EAAE,aAAU,GAA+B;AAEjD,QAAO,kBAAC,QAAD;EAAM,WAAW,EAAU;GAAE;GAAO;GAAW,CAAC;EAAG;EAAgB,CAAA;;AAG5E,EAAyB,cAAc;;;AC1BvC,IAAa,IAIT,OAAO,OAAO,GAAM;CACtB,MAAA;CACA,WAAA;CACA,eAAA;CACD,CAAC;AAEF,EAAgB,cAAc,mBAC9B,EAAK,cAAc,wBACnB,EAAU,cAAc,6BACxB,EAAc,cAAc"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/progress-tracker/ProgressTracker.styles.ts","../../src/progress-tracker/ProgressTrackerContext.ts","../../src/progress-tracker/ProgressTracker.tsx","../../src/progress-tracker/ProgressTrackerStep.styles.ts","../../src/progress-tracker/ProgressTrackerStepIndicator.styles.ts","../../src/progress-tracker/ProgressTrackerStepIndicator.tsx","../../src/progress-tracker/ProgressTrackerStep.tsx","../../src/progress-tracker/ProgressTrackerStepLabel.tsx","../../src/progress-tracker/index.ts"],"sourcesContent":["import { cx } from 'class-variance-authority'\n\nexport const progressList = cx([\n 'flex flex-nowrap items-start group/list',\n 'data-[orientation=horizontal]:flex-row data-[orientation=horizontal]:w-full',\n 'data-[orientation=vertical]:flex-col',\n])\n","import { createContext, type Dispatch, type SetStateAction, useContext } from 'react'\n\nimport type { ProgressTrackerProps } from './ProgressTracker'\n\n// Interfaces\nexport type ProgressTrackerContextInterface = Required<\n Pick<ProgressTrackerProps, 'stepIndex' | 'size' | 'intent' | 'readOnly'>\n> &\n Pick<ProgressTrackerProps, 'onStepClick'> & {\n steps: Map<string, string[]>\n setSteps: Dispatch<SetStateAction<Map<string, string[]>>>\n }\n\nexport interface ProgressTrackerStepContextInterface {\n index: number\n state: 'active' | 'complete' | 'incomplete'\n}\n\n// Contexts\nexport const ProgressTrackerContext = createContext<ProgressTrackerContextInterface>(\n {} as ProgressTrackerContextInterface\n)\n\nexport const ProgressTrackerStepContext = createContext<ProgressTrackerStepContextInterface>(\n {} as ProgressTrackerStepContextInterface\n)\n\n// Hooks\nexport const useProgressTrackerContext = () => useContext(ProgressTrackerContext)\n\nexport const useProgressTrackerStepContext = () => useContext(ProgressTrackerStepContext)\n\nexport const ID_PREFIX = ':progress-tracker'\n","import { cx } from 'class-variance-authority'\nimport { type ComponentPropsWithRef, type PropsWithChildren, useState } from 'react'\n\nimport { progressList } from './ProgressTracker.styles'\nimport {\n ProgressTrackerContext,\n type ProgressTrackerContextInterface,\n} from './ProgressTrackerContext'\nimport type { StepIndicatorVariantProps } from './ProgressTrackerStepIndicator.styles'\n\nexport interface ProgressTrackerProps\n extends ComponentPropsWithRef<'div'>, Pick<StepIndicatorVariantProps, 'size' | 'intent'> {\n /**\n * The orientation of the progress tracker\n * @default 'horizontal\"\n */\n orientation?: 'horizontal' | 'vertical'\n /**\n * The index of the current step.\n * @default 0\n */\n stepIndex?: number\n /**\n * Event handler called when clicking on a step.\n */\n onStepClick?: (stepIndex: number) => void\n /**\n * Sets the component as interactive or not.\n * @default false\n */\n readOnly?: boolean\n}\n\nexport const ProgressTracker = ({\n stepIndex = 0,\n onStepClick,\n readOnly = false,\n intent = 'support',\n size = 'lg',\n orientation = 'horizontal',\n children,\n className,\n ref,\n ...rest\n}: PropsWithChildren<ProgressTrackerProps>) => {\n const [steps, setSteps] = useState<ProgressTrackerContextInterface['steps']>(new Map())\n\n const Component = readOnly ? 'div' : 'nav'\n\n return (\n <ProgressTrackerContext.Provider\n value={{ stepIndex, onStepClick, steps, setSteps, size, intent, readOnly }}\n >\n <Component\n ref={ref}\n data-spark-component=\"progress-tracker\"\n className={cx('inline-flex', className)}\n {...rest}\n >\n <ol\n data-orientation={orientation}\n className={progressList}\n style={{ counterReset: 'step' }}\n >\n {children}\n </ol>\n </Component>\n </ProgressTrackerContext.Provider>\n )\n}\n\nProgressTracker.displayName = 'ProgressTracker'\n","import { cva } from 'class-variance-authority'\n\nexport const stepItemVariant = cva(\n [\n 'relative inline-flex items-start flex-auto first:grow-0 justify-center group/item',\n // Progress Track\n 'after:absolute after:z-base',\n 'last:after:content-none',\n 'after:bg-outline',\n 'group-data-[orientation=horizontal]/list:before:bg-outline',\n // Horizontal orientation\n 'group-data-[orientation=horizontal]/list:px-[1px]',\n 'group-data-[orientation=horizontal]/list:before:absolute group-data-[orientation=horizontal]/list:before:z-base',\n 'group-data-[orientation=horizontal]/list:before:left-0 group-data-[orientation=horizontal]/list:after:right-0',\n 'group-data-[orientation=horizontal]/list:before:h-[1px] group-data-[orientation=horizontal]/list:after:h-[1px]',\n 'first:group-data-[orientation=horizontal]/list:before:content-none',\n // Vertical orientation\n 'group-data-[orientation=vertical]/list:py-[1px]',\n 'group-data-[orientation=vertical]/list:items-start',\n 'group-data-[orientation=vertical]/list:after:w-[1px] group-data-[orientation=vertical]/list:after:bottom-[-1px]',\n ],\n {\n variants: {\n size: {\n sm: [\n // Horizontal orientation\n 'group-data-[orientation=horizontal]/list:before:top-[8px] group-data-[orientation=horizontal]/list:after:top-[8px]',\n 'group-data-[orientation=horizontal]/list:before:right-[calc(50%+12px)] group-data-[orientation=horizontal]/list:after:left-[calc(50%+12px)]',\n 'first:group-data-[orientation=horizontal]/list:after:left-[calc(50%+10px)]',\n 'last:group-data-[orientation=horizontal]/list:before:right-[calc(50%+10px)]',\n // Vertical orientation\n 'group-data-[orientation=vertical]/list:after:left-[8px]',\n 'group-data-[orientation=vertical]/list:after:top-[25px]',\n 'first:group-data-[orientation=vertical]/list:after:top-[21px]',\n ],\n md: [\n // Horizontal orientation\n 'group-data-[orientation=horizontal]/list:before:top-[12px] group-data-[orientation=horizontal]/list:after:top-[12px]',\n 'group-data-[orientation=horizontal]/list:before:right-[calc(50%+16px)] group-data-[orientation=horizontal]/list:after:left-[calc(50%+16px)]',\n 'first:group-data-[orientation=horizontal]/list:after:left-[calc(50%+14px)]',\n 'last:group-data-[orientation=horizontal]/list:before:right-[calc(50%+14px)]',\n // Vertical orientation\n 'group-data-[orientation=vertical]/list:after:left-[12px]',\n 'group-data-[orientation=vertical]/list:after:top-[33px]',\n 'first:group-data-[orientation=vertical]/list:after:top-[29px]',\n ],\n lg: [\n // Horizontal orientation\n 'group-data-[orientation=horizontal]/list:before:top-[16px] group-data-[orientation=horizontal]/list:after:top-[16px]',\n 'group-data-[orientation=horizontal]/list:before:right-[calc(50%+20px)] group-data-[orientation=horizontal]/list:after:left-[calc(50%+20px)]',\n 'first:group-data-[orientation=horizontal]/list:after:left-[calc(50%+18px)]',\n 'last:group-data-[orientation=horizontal]/list:before:right-[calc(50%+18px)]',\n // Vertical orientation\n 'group-data-[orientation=vertical]/list:after:left-[16px]',\n 'group-data-[orientation=vertical]/list:after:top-[41px]',\n 'first:group-data-[orientation=vertical]/list:after:top-[37px]',\n ],\n },\n intent: {\n support: '',\n neutral: '',\n success: '',\n },\n disabled: {\n true: 'before:opacity-dim-3',\n false: '',\n },\n disabledAfter: {\n true: 'after:opacity-dim-3',\n false: '',\n },\n },\n defaultVariants: {\n disabled: false,\n disabledAfter: false,\n size: 'lg',\n intent: 'support',\n },\n }\n)\n\nexport const stepButtonVariant = cva(\n [\n 'relative flex group/btn disabled:cursor-default',\n // Horizontal orientation\n 'group-data-[orientation=horizontal]/list:flex-col group-data-[orientation=horizontal]/list:items-center',\n 'group-data-[orientation=horizontal]/list:text-center group-data-[orientation=horizontal]/list:mx-sm',\n 'group-first/item:group-data-[orientation=horizontal]/list:ml-0 group-last/item:group-data-[orientation=horizontal]/list:mr-0',\n // Vertical orientation\n 'group-data-[orientation=vertical]/list:flex-row group-data-[orientation=vertical]/list:items-start',\n 'group-data-[orientation=vertical]/list:text-left group-data-[orientation=vertical]/list:my-sm',\n 'group-first/item:group-data-[orientation=vertical]/list:mt-0 group-last/item:group-data-[orientation=vertical]/list:mb-0',\n ],\n {\n variants: {\n size: {\n sm: [\n 'group-data-[orientation=horizontal]/list:min-w-sz-16 group-data-[orientation=horizontal]/list:mt-[16px]',\n 'group-data-[orientation=vertical]/list:min-h-sz-16 group-data-[orientation=vertical]/list:ml-[16px]',\n ],\n md: [\n 'group-data-[orientation=horizontal]/list:min-w-sz-24 group-data-[orientation=horizontal]/list:mt-[24px]',\n 'group-data-[orientation=vertical]/list:min-h-sz-24 group-data-[orientation=vertical]/list:ml-[24px]',\n ],\n lg: [\n 'group-data-[orientation=horizontal]/list:min-w-sz-32 group-data-[orientation=horizontal]/list:mt-[32px]',\n 'group-data-[orientation=vertical]/list:min-h-sz-32 group-data-[orientation=vertical]/list:ml-[32px]',\n ],\n },\n readOnly: {\n true: 'cursor-default',\n false: 'cursor-pointer',\n },\n },\n defaultVariants: {\n size: 'lg',\n readOnly: false,\n },\n }\n)\n","import { cva, VariantProps } from 'class-variance-authority'\n\nexport const stepIndicatorVariant = cva(\n [\n 'relative flex shrink-0 justify-center items-center',\n 'rounded-full',\n 'text-body-2-highlight',\n 'group-disabled/btn:opacity-dim-3',\n ],\n {\n variants: {\n size: {\n sm: [\n 'w-sz-16 h-sz-16',\n 'group-data-[orientation=horizontal]/list:mt-[-16px]',\n 'group-data-[orientation=vertical]/list:ml-[-16px]',\n ],\n md: [\n 'w-sz-24 h-sz-24',\n 'group-data-[orientation=horizontal]/list:mt-[-24px]',\n 'group-data-[orientation=vertical]/list:ml-[-24px]',\n ],\n lg: [\n 'w-sz-32 h-sz-32',\n 'group-data-[orientation=horizontal]/list:mt-[-32px]',\n 'group-data-[orientation=vertical]/list:ml-[-32px]',\n ],\n },\n intent: {\n support: '',\n neutral: '',\n success: '',\n },\n state: {\n complete: '',\n incomplete: '',\n active: '',\n },\n },\n /**\n * Known type issue with CVA compoundVariants and VS Code/Intellisense:\n * https://github.com/joe-bell/cva/discussions/195#discussioncomment-6750163\n * */\n /* @ts-ignore */\n compoundVariants: [\n // Support\n {\n intent: 'support',\n state: ['complete', 'incomplete'],\n class: [\n 'text-on-support-container bg-support-container',\n 'group-hover/btn:group-data-[interactive=true]/btn:bg-support-container-hovered',\n 'group-hover/btn:group-data-[interactive=false]/btn:bg-support-container',\n ],\n },\n {\n intent: 'support',\n state: 'active',\n class: 'text-on-support bg-support',\n },\n // Neutral\n {\n intent: 'neutral',\n state: ['complete', 'incomplete'],\n class: [\n 'text-on-neutral-container bg-neutral-container',\n 'group-hover/btn:group-data-[interactive=true]/btn:bg-neutral-container-hovered',\n 'group-hover/btn:group-data-[interactive=false]/btn:bg-neutral-container',\n ],\n },\n {\n intent: 'neutral',\n state: 'active',\n class: 'text-on-neutral bg-neutral',\n },\n // Success\n {\n intent: 'success',\n state: ['complete', 'incomplete'],\n class: [\n 'text-on-success-container bg-success-container',\n 'group-hover/btn:group-data-[interactive=true]/btn:bg-success-container-hovered',\n 'group-hover/btn:group-data-[interactive=false]/btn:bg-success-container',\n ],\n },\n {\n intent: 'success',\n state: 'active',\n class: 'text-on-success bg-success',\n },\n ],\n defaultVariants: {\n size: 'lg',\n state: 'incomplete',\n intent: 'support',\n },\n }\n)\n\nexport type StepIndicatorVariantProps = VariantProps<typeof stepIndicatorVariant>\n","import { Check } from '@spark-ui/icons/Check'\nimport type { ComponentPropsWithoutRef, ReactNode } from 'react'\n\nimport { Icon } from '../icon'\nimport { useProgressTrackerContext, useProgressTrackerStepContext } from './ProgressTrackerContext'\nimport { stepIndicatorVariant } from './ProgressTrackerStepIndicator.styles'\n\nexport type ProgressTrackerStepIndicatorProps = ComponentPropsWithoutRef<'span'> & {\n /**\n * The content to be rendered when step status is complete (checkmark icon by default)\n */\n complete?: ReactNode\n /**\n * The content to be rendered when step status is incomplete (step index by default)\n */\n incomplete?: ReactNode\n}\n\nconst CompleteIndicator = () => (\n <Icon size=\"sm\">\n <Check />\n </Icon>\n)\n\nexport const ProgressTrackerStepIndicator = ({\n complete,\n incomplete,\n className,\n}: ProgressTrackerStepIndicatorProps) => {\n const { size, intent } = useProgressTrackerContext()\n const { index, state } = useProgressTrackerStepContext()\n\n return (\n <span className={stepIndicatorVariant({ size, intent, state, className })} aria-hidden=\"true\">\n {size !== 'sm' && (\n <>\n {state === 'complete' && (complete === undefined ? <CompleteIndicator /> : complete)}\n {state !== 'complete' && (incomplete === undefined ? `${index + 1}` : incomplete)}\n </>\n )}\n </span>\n )\n}\n\nProgressTrackerStepIndicator.displayName = 'ProgressTracker.StepIndicator'\n","import { type ComponentPropsWithRef, type ReactNode, useEffect, useId } from 'react'\n\nimport {\n ID_PREFIX,\n ProgressTrackerStepContext,\n useProgressTrackerContext,\n} from './ProgressTrackerContext'\nimport { stepButtonVariant, stepItemVariant } from './ProgressTrackerStep.styles'\nimport { ProgressTrackerStepIndicator } from './ProgressTrackerStepIndicator'\n\nexport type ProgressTrackerStepProps = ComponentPropsWithRef<'li'> &\n (\n | {\n disabled?: boolean\n children: ReactNode\n }\n | {\n disabled?: boolean\n 'aria-label': string\n }\n )\n\nexport const ProgressTrackerStep = ({\n disabled = false,\n children,\n 'aria-label': ariaLabel,\n className,\n ref,\n ...rest\n}: ProgressTrackerStepProps) => {\n const {\n stepIndex: currentStepIndex,\n steps,\n onStepClick,\n setSteps,\n size,\n intent,\n readOnly,\n } = useProgressTrackerContext()\n\n const stepId = `${ID_PREFIX}-step-${useId()}`\n const stepIndex = [...steps.keys()].indexOf(stepId)\n\n const disabledAfter = (() => {\n const nextStepId = [...steps.keys()][stepIndex + 1]\n\n return !!(nextStepId && steps.get(nextStepId)?.includes('disabled'))\n })()\n\n const progressState = (() => {\n if (stepIndex === currentStepIndex) return 'active'\n else if (stepIndex < currentStepIndex) return 'complete'\n else return 'incomplete'\n })()\n\n useEffect(() => {\n setSteps(steps => {\n const newSteps = new Map(steps)\n\n return newSteps.set(\n stepId,\n [progressState, disabled ? 'disabled' : ''].filter(v => !!v)\n )\n })\n\n return () => {\n setSteps(steps => {\n steps.delete(stepId)\n\n return steps\n })\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n return (\n <li\n data-spark-component=\"progress-tracker-step\"\n id={stepId}\n ref={ref}\n data-state={progressState}\n {...(progressState === 'active' && {\n 'aria-current': 'step',\n })}\n className={stepItemVariant({\n size,\n intent,\n disabled,\n disabledAfter,\n })}\n {...rest}\n >\n <button\n type=\"button\"\n aria-label={ariaLabel}\n data-interactive={!disabled && !readOnly}\n {...(!disabled &&\n !readOnly && {\n onClick: () => onStepClick?.(stepIndex),\n })}\n disabled={disabled}\n className={stepButtonVariant({\n size,\n readOnly,\n className,\n })}\n >\n <ProgressTrackerStepContext.Provider\n value={{\n index: stepIndex,\n state: progressState,\n }}\n >\n {children || <ProgressTrackerStepIndicator />}\n </ProgressTrackerStepContext.Provider>\n </button>\n </li>\n )\n}\n\nProgressTrackerStep.displayName = 'ProgressTracker.Step'\n","import { cva } from 'class-variance-authority'\nimport type { ComponentPropsWithoutRef, ReactNode } from 'react'\n\nimport { useProgressTrackerStepContext } from './ProgressTrackerContext'\n\ntype ProgressTrackerStepLabelProps = ComponentPropsWithoutRef<'span'> & {\n children: ReactNode\n}\n\nconst stepLabel = cva(\n [\n 'flex text-body-2',\n 'text-on-surface group-disabled/btn:text-on-surface/dim-1',\n 'group-data-[orientation=horizontal]/list:mt-md',\n 'group-data-[orientation=vertical]/list:ml-md',\n 'group-data-[orientation=vertical]/list:my-auto',\n ],\n {\n variants: {\n state: {\n complete: '',\n incomplete: '',\n active: 'font-medium',\n },\n },\n }\n)\n\nexport const ProgressTrackerStepLabel = ({\n className,\n children,\n}: ProgressTrackerStepLabelProps) => {\n const { state } = useProgressTrackerStepContext()\n\n return <span className={stepLabel({ state, className })}>{children}</span>\n}\n\nProgressTrackerStepLabel.displayName = 'ProgressTracker.StepLabel'\n","import { ProgressTracker as Root, type ProgressTrackerProps } from './ProgressTracker'\nimport { ProgressTrackerStep as Step, type ProgressTrackerStepProps } from './ProgressTrackerStep'\nimport {\n ProgressTrackerStepIndicator as StepIndicator,\n type ProgressTrackerStepIndicatorProps,\n} from './ProgressTrackerStepIndicator'\nimport { ProgressTrackerStepLabel as StepLabel } from './ProgressTrackerStepLabel'\n\n/**\n * A component that displays a multi-step process with visual indicators for completed, current, and upcoming steps.\n */\nexport const ProgressTracker: typeof Root & {\n Step: typeof Step\n StepLabel: typeof StepLabel\n StepIndicator: typeof StepIndicator\n} = Object.assign(Root, {\n Step,\n StepLabel,\n StepIndicator,\n})\n\nProgressTracker.displayName = 'ProgressTracker'\nStep.displayName = 'ProgressTracker.Step'\nStepLabel.displayName = 'ProgressTracker.StepLabel'\nStepIndicator.displayName = 'ProgressTracker.StepIndicator'\n\nexport type { ProgressTrackerProps, ProgressTrackerStepProps, ProgressTrackerStepIndicatorProps }\n"],"mappings":";;;;;;AAEA,IAAa,IAAe,EAAG;CAC7B;CACA;CACA;CACD,CAAC,ECaW,IAAyB,EACpC,EAAE,CACH,EAEY,IAA6B,EACxC,EAAE,CACH,EAGY,UAAkC,EAAW,EAAuB,EAEpE,UAAsC,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C/GlC,IAAM,IAAY,EAChB;CACE;CACA;CACA;CACA;CACA;CACD,EACD,EACE,UAAU,EACR,OAAO;CACL,UAAU;CACV,YAAY;CACZ,QAAQ;CACT,EACF,EACF,CACF,EAEY,KAA4B,EACvC,cACA,kBACmC;CACnC,IAAM,EAAE,aAAU,GAA+B;AAEjD,QAAO,kBAAC,QAAD;EAAM,WAAW,EAAU;GAAE;GAAO;GAAW,CAAC;EAAG;EAAgB,CAAA;;AAG5E,EAAyB,cAAc;;;AC1BvC,IAAa,IAIT,OAAO,OAAO,GAAM;CACtB,MAAA;CACA,WAAA;CACA,eAAA;CACD,CAAC;AAEF,EAAgB,cAAc,mBAC9B,EAAK,cAAc,wBACnB,EAAU,cAAc,6BACxB,EAAc,cAAc"}
|
package/dist/rating/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../chunk-C91j1N6u.js`);const e=require(`../icon-CRPcdgYp.js`),t=require(`../form-field-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../chunk-C91j1N6u.js`);const e=require(`../icon-CRPcdgYp.js`),t=require(`../form-field-CYGgse45.js`);let n=require(`class-variance-authority`),r=require(`react`),i=require(`react/jsx-runtime`),a=require(`@spark-ui/hooks/use-combined-state`),o=require(`@spark-ui/icons/StarFill`),s=require(`@spark-ui/icons/StarOutline`);var c=(0,n.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:(0,n.cx)((0,n.cx)(`[&_>_div]:peer-hover:w-0!`),`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`}}),l=(0,n.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`]}}}),u=({value:t,size:a,disabled:u,readOnly:d,checked:f=!1,ariaLabel:p,ariaLabelledBy:m,tabIndex:h,onClick:g,onKeyDown:_,onMouseEnter:v,children:y,ref:b})=>{let x=!u&&!d,[S,C]=(0,r.useState)(!1),w=e=>{g?.(e),x&&C(!0)},T=()=>C(!1);return(0,i.jsxs)(`div`,{ref:b,role:`radio`,"aria-checked":f,"aria-label":p,"aria-labelledby":m,tabIndex:h,"data-spark-component":`rating-star`,"data-part":`star`,...x&&S&&{"data-suppress-scale":``},className:c({gap:a===`lg`?`md`:`sm`,disabled:u,readOnly:d}),onClick:w,onKeyDown:_,onMouseEnter:v,onMouseLeave:T,onMouseMove:T,children:[(0,i.jsx)(`div`,{className:(0,n.cx)(`z-raised absolute overflow-hidden`,`group-[[data-part=star][data-hovered]]:overflow-visible`),style:{width:t*100+`%`},children:(0,i.jsx)(e.t,{className:l({size:a,design:`filled`}),children:(0,i.jsx)(o.StarFill,{})})}),(0,i.jsx)(e.t,{className:l({size:a,design:`outlined`}),children:(0,i.jsx)(s.StarOutline,{})}),y]})};function d({value:e,index:t}){return e===void 0?0:+(e>=t+1)}function f(e,t){return[e.slice(0,t),e.slice(t)]}var p=e=>e===void 0||!Number.isInteger(e)||e<1?0:Math.min(5,Math.max(1,e));function m(e,t,n,r){return i=>{if(r)switch(i.key){case`ArrowRight`:case`ArrowDown`:i.preventDefault();let r=Math.min(4,e+1);n(r+1),t.current[r]?.focus();break;case`ArrowLeft`:case`ArrowUp`:i.preventDefault();let a=Math.max(0,e-1);n(a+1),t.current[a]?.focus();break;case` `:i.preventDefault(),n(e+1);break;default:break}}}function h(e,t){return t>=1?t-1===e?0:-1:e===0?0:-1}var g=({defaultValue:e,value:o,onValueChange:s,disabled:c,readOnly:l,required:g,name:_,id:v,"aria-label":y,getStarLabel:b,ref:x,...S})=>{let{labelId:C,isInvalid:w,isRequired:T,description:E,name:D,disabled:O,readOnly:k}=t.n(),A=(0,r.useRef)([]),j=(0,r.useId)(),[M,N]=(0,r.useState)(null),[P,F]=(0,a.useCombinedState)(o,e,s),I=p(P??0),L=c??O,R=l??k,z=g===void 0?T:g,B=_??D,V=!(L||R),H=b!==void 0||y!==void 0,U=M===null?I:M+1;function W(e){V&&(F(e+1),A.current[e]?.focus())}let G=(0,r.useCallback)(e=>m(e,A,F,V),[V,F]);function K({currentTarget:e}){let t=A.current.findIndex(t=>t===e);N(t>=0?t:null);let[n,r]=f(A.current,t+1);n.forEach(e=>e?.setAttribute(`data-hovered`,``)),r.forEach(e=>e?.removeAttribute(`data-hovered`))}let q=(0,r.useCallback)(e=>t=>{A.current[e]=t},[]);function J(){N(null),A.current.forEach(e=>e?.removeAttribute(`data-hovered`))}return(0,i.jsxs)(`div`,{ref:x,id:v,role:`radiogroup`,"aria-label":y,"aria-labelledby":C,"aria-invalid":w,"aria-required":z,"aria-describedby":E,className:`relative inline-flex`,"data-spark-component":`rating`,...S,onMouseLeave:J,children:[B!==void 0&&(0,i.jsx)(`input`,{type:`hidden`,name:B,value:I,"aria-hidden":!0,"data-part":`input`}),(0,i.jsx)(`div`,{className:(0,n.cx)(`gap-x-md`,`flex`),children:Array.from({length:5}).map((e,t)=>(0,i.jsx)(u,{ref:q(t),disabled:L,readOnly:R,size:`lg`,value:d({index:t,value:U}),checked:I===t+1,ariaLabel:H?b?.(t)??`${y} ${t+1}`:void 0,ariaLabelledBy:!H&&C?`${C} ${j}-star-${t+1}`:void 0,tabIndex:V?h(t,I):-1,onClick:()=>W(t),onKeyDown:G(t),onMouseEnter:e=>V&&K(e),children:!H&&(0,i.jsx)(`span`,{id:`${j}-star-${t+1}`,className:`sr-only`,children:t+1})},t))})]})};exports.Rating=g;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/rating/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as e } from "../icon-D05Uqh8_.mjs";
|
|
2
|
-
import { n as t } from "../form-field-
|
|
2
|
+
import { n as t } from "../form-field-CV5dzt-I.mjs";
|
|
3
3
|
import { cva as n, cx as r } from "class-variance-authority";
|
|
4
4
|
import { useCallback as i, useId as a, useRef as o, useState as s } from "react";
|
|
5
5
|
import { jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../chunk-C91j1N6u.js`);const e=require(`../slot/index.js`),t=require(`../icon-CRPcdgYp.js`);let n=require(`class-variance-authority`),r=require(`react`),i=require(`react/jsx-runtime`),a=require(`@spark-ui/icons/StarFill`),o=require(`@spark-ui/icons/StarOutline`);var s=(0,r.createContext)(null),c=({value:e,size:t,count:n,children:r})=>(0,i.jsx)(s.Provider,{value:{value:e,size:t,count:n},children:r}),l=()=>{let e=(0,r.useContext)(s);if(!e)throw Error(`RatingDisplay compound components must be used within RatingDisplay.`);return e},u=({value:t=0,size:n=`md`,count:r,asChild:a=!1,ref:o,children:s,...l})=>(0,i.jsx)(c,{value:t??0,size:n,count:r,children:(0,i.jsx)(a?e.Slot:`div`,{ref:o,className:`gap-x-sm relative inline-flex items-center`,"data-spark-component":`rating-display`,...l,children:s})});u.displayName=`RatingDisplay`;var d=(0,n.cva)(`text-on-surface/dim-1`,{variants:{size:{sm:`text-caption`,md:`text-body-2`,lg:`text-display-3`}},defaultVariants:{size:`md`}}),f=({className:e,children:t,...n})=>{let{count:r,size:a}=l();if(r===void 0)return null;let o=typeof t==`function`?t(r):t??r;return(0,i.jsxs)(`span`,{className:d({size:a??`md`,className:e}),...n,children:[`(`,o,`)`]})};f.displayName=`RatingDisplay.Count`;var p=(0,n.cva)([`relative block after:absolute after:block after:inset-0`],{variants:{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`]}},defaultVariants:{gap:`sm`}}),m=(0,n.cva)(``,{variants:{size:{sm:`text-caption-link`,md:`text-body-1`,lg:`text-display-3`},design:{filled:[`text-main-variant`],outlined:[`text-on-surface/dim-3`]}}}),h=({value:e,size:r})=>(0,i.jsxs)(`div`,{"data-spark-component":`rating-display-star`,"data-part":`star`,className:p({gap:r===`lg`?`md`:`sm`}),children:[(0,i.jsx)(`div`,{className:(0,n.cx)(`z-raised absolute overflow-hidden`),style:{width:e*100+`%`},children:(0,i.jsx)(t.t,{className:m({size:r,design:`filled`}),children:(0,i.jsx)(a.StarFill,{})})}),(0,i.jsx)(t.t,{className:m({size:r,design:`outlined`}),children:(0,i.jsx)(o.StarOutline,{})})]});function g(e){return Math.round(e/.5)*.5}function _(e){let t=Intl.DateTimeFormat().resolvedOptions().locale;return new Intl.NumberFormat(t,{minimumFractionDigits:0,maximumFractionDigits:1}).format(e)}function v({value:e,index:t}){if(e===void 0)return 0;let n=t+1,r=g(e);return Math.ceil(r)<n?0:r>=n?1:.5}function y(e){return e===void 0||e<1?0:e<4?.5:1}var b=({size:e,variant:t=`default`,getFillMode:r})=>{let{value:a,size:o}=l(),s=e??o,c=e=>r?r({index:e,value:a}):t===`single-star`?y(a):v({index:e,value:a}),u=t===`single-star`?[c(0)]:Array.from({length:5},(e,t)=>c(t));return(0,i.jsx)(`div`,{"data-spark-component":`rating-display-stars`,className:(0,n.cx)(s===`lg`?`gap-x-md`:`gap-x-sm`,`flex`),children:u.map((e,t)=>(0,i.jsx)(h,{size:s,value:e},t))})};b.displayName=`RatingDisplay.Stars`;var x=(0,n.cva)(`text-on-surface
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../chunk-C91j1N6u.js`);const e=require(`../slot/index.js`),t=require(`../icon-CRPcdgYp.js`);let n=require(`class-variance-authority`),r=require(`react`),i=require(`react/jsx-runtime`),a=require(`@spark-ui/icons/StarFill`),o=require(`@spark-ui/icons/StarOutline`);var s=(0,r.createContext)(null),c=({value:e,size:t,count:n,children:r})=>(0,i.jsx)(s.Provider,{value:{value:e,size:t,count:n},children:r}),l=()=>{let e=(0,r.useContext)(s);if(!e)throw Error(`RatingDisplay compound components must be used within RatingDisplay.`);return e},u=({value:t=0,size:n=`md`,count:r,asChild:a=!1,ref:o,children:s,...l})=>(0,i.jsx)(c,{value:t??0,size:n,count:r,children:(0,i.jsx)(a?e.Slot:`div`,{ref:o,className:`gap-x-sm relative inline-flex items-center`,"data-spark-component":`rating-display`,...l,children:s})});u.displayName=`RatingDisplay`;var d=(0,n.cva)(`text-on-surface/dim-1`,{variants:{size:{sm:`text-caption`,md:`text-body-2`,lg:`text-display-3`}},defaultVariants:{size:`md`}}),f=({className:e,children:t,...n})=>{let{count:r,size:a}=l();if(r===void 0)return null;let o=typeof t==`function`?t(r):t??r;return(0,i.jsxs)(`span`,{className:d({size:a??`md`,className:e}),...n,children:[`(`,o,`)`]})};f.displayName=`RatingDisplay.Count`;var p=(0,n.cva)([`relative block after:absolute after:block after:inset-0`],{variants:{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`]}},defaultVariants:{gap:`sm`}}),m=(0,n.cva)(``,{variants:{size:{sm:`text-caption-link`,md:`text-body-1`,lg:`text-display-3`},design:{filled:[`text-main-variant`],outlined:[`text-on-surface/dim-3`]}}}),h=({value:e,size:r})=>(0,i.jsxs)(`div`,{"data-spark-component":`rating-display-star`,"data-part":`star`,className:p({gap:r===`lg`?`md`:`sm`}),children:[(0,i.jsx)(`div`,{className:(0,n.cx)(`z-raised absolute overflow-hidden`),style:{width:e*100+`%`},children:(0,i.jsx)(t.t,{className:m({size:r,design:`filled`}),children:(0,i.jsx)(a.StarFill,{})})}),(0,i.jsx)(t.t,{className:m({size:r,design:`outlined`}),children:(0,i.jsx)(o.StarOutline,{})})]});function g(e){return Math.round(e/.5)*.5}function _(e){let t=Intl.DateTimeFormat().resolvedOptions().locale;return new Intl.NumberFormat(t,{minimumFractionDigits:0,maximumFractionDigits:1}).format(e)}function v({value:e,index:t}){if(e===void 0)return 0;let n=t+1,r=g(e);return Math.ceil(r)<n?0:r>=n?1:.5}function y(e){return e===void 0||e<1?0:e<4?.5:1}var b=({size:e,variant:t=`default`,getFillMode:r})=>{let{value:a,size:o}=l(),s=e??o,c=e=>r?r({index:e,value:a}):t===`single-star`?y(a):v({index:e,value:a}),u=t===`single-star`?[c(0)]:Array.from({length:5},(e,t)=>c(t));return(0,i.jsx)(`div`,{"data-spark-component":`rating-display-stars`,className:(0,n.cx)(s===`lg`?`gap-x-md`:`gap-x-sm`,`flex`),children:u.map((e,t)=>(0,i.jsx)(h,{size:s,value:e},t))})};b.displayName=`RatingDisplay.Stars`;var x=(0,n.cva)(`text-on-surface`,{variants:{size:{sm:`text-caption-highlight`,md:`text-body-2-highlight`,lg:`text-display-3`}},defaultVariants:{size:`md`}}),S=({className:e,children:t,...n})=>{let{value:r,size:a}=l(),o=_(r),s=typeof t==`function`?t(o,r):t??o;return(0,i.jsx)(`span`,{"data-spark-component":`rating-display-value`,className:x({size:a??`md`,className:e}),...n,children:s})};S.displayName=`RatingDisplay.Value`;var C=Object.assign(u,{Stars:b,Value:S,Count:f});C.displayName=`RatingDisplay`,b.displayName=`RatingDisplay.Stars`,S.displayName=`RatingDisplay.Value`,f.displayName=`RatingDisplay.Count`,exports.RatingDisplay=C;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/rating-display/RatingDisplayContext.tsx","../../src/rating-display/RatingDisplay.tsx","../../src/rating-display/RatingDisplayCount.tsx","../../src/rating-display/RatingDisplayStar.tsx","../../src/rating-display/utils.ts","../../src/rating-display/RatingDisplayStars.tsx","../../src/rating-display/RatingDisplayValue.tsx","../../src/rating-display/index.ts"],"sourcesContent":["import { createContext, type PropsWithChildren, useContext } from 'react'\n\nimport type { RatingDisplayStarProps } from './RatingDisplayStar'\n\ninterface RatingDisplayContextValue {\n value: number\n size: RatingDisplayStarProps['size']\n count?: number\n}\n\nconst RatingDisplayContext = createContext<RatingDisplayContextValue | null>(null)\n\ninterface RatingDisplayProviderProps extends PropsWithChildren<RatingDisplayContextValue> {}\n\nexport const RatingDisplayProvider = ({\n value,\n size,\n count,\n children,\n}: RatingDisplayProviderProps) => {\n return (\n <RatingDisplayContext.Provider value={{ value, size, count }}>\n {children}\n </RatingDisplayContext.Provider>\n )\n}\n\nexport const useRatingDisplay = () => {\n const context = useContext(RatingDisplayContext)\n if (!context) {\n throw new Error('RatingDisplay compound components must be used within RatingDisplay.')\n }\n\n return context\n}\n","import { type ComponentPropsWithRef, type PropsWithChildren } from 'react'\n\nimport { Slot } from '../slot'\nimport { RatingDisplayProvider } from './RatingDisplayContext'\nimport type { RatingDisplayStarProps } from './RatingDisplayStar'\n\nexport interface RatingDisplayProps extends PropsWithChildren<ComponentPropsWithRef<'div'>> {\n /**\n * When true, merges props onto the single child element instead of rendering a div.\n * Use to render the root as a link or another custom element.\n */\n asChild?: boolean\n /**\n * The rating value to display, on a scale from 0 to 5.\n */\n value?: number\n /**\n * Sets the size of the stars.\n * @default 'md'\n */\n size?: RatingDisplayStarProps['size']\n /**\n * Optional count value available to `RatingDisplay.Count`.\n */\n count?: number\n /**\n * Accessible description of the rating content.\n */\n 'aria-label': string\n}\n\nexport type RatingDisplayRootProps = RatingDisplayProps\n\nexport const RatingDisplay = ({\n value = 0,\n size = 'md',\n count,\n asChild = false,\n ref,\n children,\n ...rest\n}: RatingDisplayProps) => {\n const ratingValue = value ?? 0\n const Component = asChild ? Slot : 'div'\n\n return (\n <RatingDisplayProvider value={ratingValue} size={size} count={count}>\n <Component\n ref={ref}\n className=\"gap-x-sm relative inline-flex items-center\"\n data-spark-component=\"rating-display\"\n {...rest}\n >\n {children}\n </Component>\n </RatingDisplayProvider>\n )\n}\n\nRatingDisplay.displayName = 'RatingDisplay'\n","import { cva } from 'class-variance-authority'\nimport { type ComponentPropsWithRef, type ReactNode } from 'react'\n\nimport { useRatingDisplay } from './RatingDisplayContext'\n\nexport interface RatingDisplayCountProps extends Omit<ComponentPropsWithRef<'span'>, 'children'> {\n /**\n * Custom count content.\n * Pass a render function to receive the count value and return the content to render.\n */\n children?: ReactNode | ((count: number) => ReactNode)\n}\n\nconst ratingDisplayCountStyles = cva('text-on-surface/dim-1', {\n variants: {\n size: {\n sm: 'text-caption',\n md: 'text-body-2',\n lg: 'text-display-3',\n },\n },\n defaultVariants: {\n size: 'md',\n },\n})\n\nexport const RatingDisplayCount = ({ className, children, ...rest }: RatingDisplayCountProps) => {\n const { count, size } = useRatingDisplay()\n if (count === undefined) return null\n const renderedCount = typeof children === 'function' ? children(count) : (children ?? count)\n\n return (\n <span className={ratingDisplayCountStyles({ size: size ?? 'md', className })} {...rest}>\n ({renderedCount})\n </span>\n )\n}\n\nRatingDisplayCount.displayName = 'RatingDisplay.Count'\n","import { StarFill } from '@spark-ui/icons/StarFill'\nimport { StarOutline } from '@spark-ui/icons/StarOutline'\nimport { cva, cx, type VariantProps } from 'class-variance-authority'\n\nimport { Icon } from '../icon'\nimport type { StarValue } from './types'\n\nconst ratingDisplayStarStyles = cva(['relative block after:absolute after:block after:inset-0'], {\n variants: {\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 defaultVariants: {\n gap: 'sm',\n },\n})\n\nconst ratingDisplayStarIconStyles = cva('', {\n variants: {\n size: {\n sm: 'text-caption-link',\n md: 'text-body-1',\n lg: 'text-display-3',\n },\n design: {\n filled: ['text-main-variant'],\n outlined: ['text-on-surface/dim-3'],\n },\n },\n})\n\ntype RatingDisplayStarstylesProps = Omit<VariantProps<typeof ratingDisplayStarStyles>, never>\ntype RatingDisplayStarIconStylesProps = Omit<\n VariantProps<typeof ratingDisplayStarIconStyles>,\n 'design'\n>\n\nexport interface RatingDisplayStarProps\n extends RatingDisplayStarstylesProps, RatingDisplayStarIconStylesProps {\n value: StarValue\n}\n\nexport const RatingDisplayStar = ({ value, size }: RatingDisplayStarProps) => {\n return (\n <div\n data-spark-component=\"rating-display-star\"\n data-part=\"star\"\n className={ratingDisplayStarStyles({\n gap: size === 'lg' ? 'md' : 'sm',\n })}\n >\n <div className={cx('z-raised absolute overflow-hidden')} style={{ width: value * 100 + '%' }}>\n <Icon\n className={ratingDisplayStarIconStyles({\n size,\n design: 'filled',\n })}\n >\n <StarFill />\n </Icon>\n </div>\n\n <Icon className={ratingDisplayStarIconStyles({ 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 formatRatingValue(value: number): string {\n const locale = Intl.DateTimeFormat().resolvedOptions().locale\n\n return new Intl.NumberFormat(locale, {\n minimumFractionDigits: 0,\n maximumFractionDigits: 1,\n }).format(value)\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 getSingleStarValue(value?: number): StarValue {\n if (value === undefined) return 0\n if (value < 1) return 0\n if (value < 4) return 0.5\n return 1\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 { formatRatingValue, getNearestHalfDecimal, getSingleStarValue, getStarValue, splitAt }\n","import { cx } from 'class-variance-authority'\n\nimport { useRatingDisplay } from './RatingDisplayContext'\nimport { RatingDisplayStar, type RatingDisplayStarProps } from './RatingDisplayStar'\nimport type { StarValue } from './types'\nimport { getSingleStarValue, getStarValue } from './utils'\n\nexport interface RatingDisplayStarsProps {\n size?: RatingDisplayStarProps['size']\n /**\n * Sets the rendering mode for stars.\n * @default 'default'\n */\n variant?: 'default' | 'single-star'\n /**\n * Custom fill algorithm for each star.\n * By default, stars are rounded to the nearest 0.5.\n */\n getFillMode?: ({ value, index }: { value?: number; index: number }) => StarValue\n}\n\nexport const RatingDisplayStars = ({\n size,\n variant = 'default',\n getFillMode,\n}: RatingDisplayStarsProps) => {\n const { value, size: contextSize } = useRatingDisplay()\n const resolvedSize = size ?? contextSize\n const getDisplayValue = (index: number) => {\n if (getFillMode) {\n return getFillMode({ index, value })\n }\n\n return variant === 'single-star' ? getSingleStarValue(value) : getStarValue({ index, value })\n }\n\n const stars =\n variant === 'single-star'\n ? [getDisplayValue(0)]\n : Array.from({ length: 5 }, (_, index) => getDisplayValue(index))\n\n return (\n <div\n data-spark-component=\"rating-display-stars\"\n className={cx(resolvedSize === 'lg' ? 'gap-x-md' : 'gap-x-sm', 'flex')}\n >\n {stars.map((starValue, index) => (\n <RatingDisplayStar key={index} size={resolvedSize} value={starValue} />\n ))}\n </div>\n )\n}\n\nRatingDisplayStars.displayName = 'RatingDisplay.Stars'\n","import { cva } from 'class-variance-authority'\nimport { type ComponentPropsWithRef, type ReactNode } from 'react'\n\nimport { useRatingDisplay } from './RatingDisplayContext'\nimport { formatRatingValue } from './utils'\n\nexport interface RatingDisplayValueProps extends Omit<ComponentPropsWithRef<'span'>, 'children'> {\n /**\n * Custom value content.\n * Pass a render function to receive the formatted value (first arg) and raw value (second arg),\n * then return the content to render.\n */\n children?: ReactNode | ((formattedValue: string, value: number) => ReactNode)\n}\n\nconst ratingDisplayValueStyles = cva('text-on-surface font-bold', {\n variants: {\n size: {\n sm: 'text-caption',\n md: 'text-body-2',\n lg: 'text-display-3',\n },\n },\n defaultVariants: {\n size: 'md',\n },\n})\n\nexport const RatingDisplayValue = ({ className, children, ...rest }: RatingDisplayValueProps) => {\n const { value, size } = useRatingDisplay()\n const formattedValue = formatRatingValue(value)\n const renderedValue =\n typeof children === 'function' ? children(formattedValue, value) : (children ?? formattedValue)\n\n return (\n <span\n data-spark-component=\"rating-display-value\"\n className={ratingDisplayValueStyles({ size: size ?? 'md', className })}\n {...rest}\n >\n {renderedValue}\n </span>\n )\n}\n\nRatingDisplayValue.displayName = 'RatingDisplay.Value'\n","import { RatingDisplay as Root } from './RatingDisplay'\nimport { RatingDisplayCount as Count } from './RatingDisplayCount'\nimport { RatingDisplayStars as Stars } from './RatingDisplayStars'\nimport { RatingDisplayValue as Value } from './RatingDisplayValue'\n\n/**\n * A read-only component that displays a rating value using stars.\n */\nexport const RatingDisplay: typeof Root & {\n Stars: typeof Stars\n Value: typeof Value\n Count: typeof Count\n} = Object.assign(Root, {\n Stars,\n Value,\n Count,\n})\n\nRatingDisplay.displayName = 'RatingDisplay'\nStars.displayName = 'RatingDisplay.Stars'\nValue.displayName = 'RatingDisplay.Value'\nCount.displayName = 'RatingDisplay.Count'\n\nexport { type RatingDisplayProps, type RatingDisplayRootProps } from './RatingDisplay'\nexport { type RatingDisplayStarsProps } from './RatingDisplayStars'\nexport { type RatingDisplayValueProps } from './RatingDisplayValue'\nexport { type RatingDisplayCountProps } from './RatingDisplayCount'\nexport type { StarValue } from './types'\n"],"mappings":"mVAUA,IAAM,GAAA,EAAA,EAAA,eAAuE,KAAK,CAIrE,GAAyB,CACpC,QACA,OACA,QACA,eAGE,EAAA,EAAA,KAAC,EAAqB,SAAtB,CAA+B,MAAO,CAAE,QAAO,OAAM,QAAO,CACzD,WAC6B,CAAA,CAIvB,MAAyB,CACpC,IAAM,GAAA,EAAA,EAAA,YAAqB,EAAqB,CAChD,GAAI,CAAC,EACH,MAAU,MAAM,uEAAuE,CAGzF,OAAO,GCAI,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AAmB,EAAM,CAAG,EAAa,CAAE,QAAO,QAAO,CAAC,CAGzF,EACJ,IAAY,cACR,CAAC,EAAgB,EAAE,CAAC,CACpB,MAAM,KAAK,CAAE,OAAQ,EAAG,EAAG,EAAG,IAAU,EAAgB,EAAM,CAAC,CAErE,OACE,EAAA,EAAA,KAAC,MAAD,CACE,uBAAqB,uBACrB,WAAA,EAAA,EAAA,IAAc,IAAiB,KAAO,WAAa,WAAY,OAAO,UAErE,EAAM,KAAK,EAAW,KACrB,EAAA,EAAA,KAAC,EAAD,CAA+B,KAAM,EAAc,MAAO,EAAa,CAA/C,EAA+C,CACvE,CACE,CAAA,EAIV,EAAmB,YAAc,sBCtCjC,IAAM,GAAA,EAAA,EAAA,KAA+B,4BAA6B,CAChE,SAAU,CACR,KAAM,CACJ,GAAI,eACJ,GAAI,cACJ,GAAI,iBACL,CACF,CACD,gBAAiB,CACf,KAAM,KACP,CACF,CAAC,CAEW,GAAsB,CAAE,YAAW,WAAU,GAAG,KAAoC,CAC/F,GAAM,CAAE,QAAO,QAAS,GAAkB,CACpC,EAAiB,EAAkB,EAAM,CACzC,EACJ,OAAO,GAAa,WAAa,EAAS,EAAgB,EAAM,CAAI,GAAY,EAElF,OACE,EAAA,EAAA,KAAC,OAAD,CACE,uBAAqB,uBACrB,UAAW,EAAyB,CAAE,KAAM,GAAQ,KAAM,YAAW,CAAC,CACtE,GAAI,WAEH,EACI,CAAA,EAIX,EAAmB,YAAc,sBCrCjC,IAAa,EAIT,OAAO,OAAO,EAAM,CACtB,MAAA,EACA,MAAA,EACA,MAAA,EACD,CAAC,CAEF,EAAc,YAAc,gBAC5B,EAAM,YAAc,sBACpB,EAAM,YAAc,sBACpB,EAAM,YAAc"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/rating-display/RatingDisplayContext.tsx","../../src/rating-display/RatingDisplay.tsx","../../src/rating-display/RatingDisplayCount.tsx","../../src/rating-display/RatingDisplayStar.tsx","../../src/rating-display/utils.ts","../../src/rating-display/RatingDisplayStars.tsx","../../src/rating-display/RatingDisplayValue.tsx","../../src/rating-display/index.ts"],"sourcesContent":["import { createContext, type PropsWithChildren, useContext } from 'react'\n\nimport type { RatingDisplayStarProps } from './RatingDisplayStar'\n\ninterface RatingDisplayContextValue {\n value: number\n size: RatingDisplayStarProps['size']\n count?: number\n}\n\nconst RatingDisplayContext = createContext<RatingDisplayContextValue | null>(null)\n\ninterface RatingDisplayProviderProps extends PropsWithChildren<RatingDisplayContextValue> {}\n\nexport const RatingDisplayProvider = ({\n value,\n size,\n count,\n children,\n}: RatingDisplayProviderProps) => {\n return (\n <RatingDisplayContext.Provider value={{ value, size, count }}>\n {children}\n </RatingDisplayContext.Provider>\n )\n}\n\nexport const useRatingDisplay = () => {\n const context = useContext(RatingDisplayContext)\n if (!context) {\n throw new Error('RatingDisplay compound components must be used within RatingDisplay.')\n }\n\n return context\n}\n","import { type ComponentPropsWithRef, type PropsWithChildren } from 'react'\n\nimport { Slot } from '../slot'\nimport { RatingDisplayProvider } from './RatingDisplayContext'\nimport type { RatingDisplayStarProps } from './RatingDisplayStar'\n\nexport interface RatingDisplayProps extends PropsWithChildren<ComponentPropsWithRef<'div'>> {\n /**\n * When true, merges props onto the single child element instead of rendering a div.\n * Use to render the root as a link or another custom element.\n */\n asChild?: boolean\n /**\n * The rating value to display, on a scale from 0 to 5.\n */\n value?: number\n /**\n * Sets the size of the stars.\n * @default 'md'\n */\n size?: RatingDisplayStarProps['size']\n /**\n * Optional count value available to `RatingDisplay.Count`.\n */\n count?: number\n /**\n * Accessible description of the rating content.\n */\n 'aria-label': string\n}\n\nexport type RatingDisplayRootProps = RatingDisplayProps\n\nexport const RatingDisplay = ({\n value = 0,\n size = 'md',\n count,\n asChild = false,\n ref,\n children,\n ...rest\n}: RatingDisplayProps) => {\n const ratingValue = value ?? 0\n const Component = asChild ? Slot : 'div'\n\n return (\n <RatingDisplayProvider value={ratingValue} size={size} count={count}>\n <Component\n ref={ref}\n className=\"gap-x-sm relative inline-flex items-center\"\n data-spark-component=\"rating-display\"\n {...rest}\n >\n {children}\n </Component>\n </RatingDisplayProvider>\n )\n}\n\nRatingDisplay.displayName = 'RatingDisplay'\n","import { cva } from 'class-variance-authority'\nimport { type ComponentPropsWithRef, type ReactNode } from 'react'\n\nimport { useRatingDisplay } from './RatingDisplayContext'\n\nexport interface RatingDisplayCountProps extends Omit<ComponentPropsWithRef<'span'>, 'children'> {\n /**\n * Custom count content.\n * Pass a render function to receive the count value and return the content to render.\n */\n children?: ReactNode | ((count: number) => ReactNode)\n}\n\nconst ratingDisplayCountStyles = cva('text-on-surface/dim-1', {\n variants: {\n size: {\n sm: 'text-caption',\n md: 'text-body-2',\n lg: 'text-display-3',\n },\n },\n defaultVariants: {\n size: 'md',\n },\n})\n\nexport const RatingDisplayCount = ({ className, children, ...rest }: RatingDisplayCountProps) => {\n const { count, size } = useRatingDisplay()\n if (count === undefined) return null\n const renderedCount = typeof children === 'function' ? children(count) : (children ?? count)\n\n return (\n <span className={ratingDisplayCountStyles({ size: size ?? 'md', className })} {...rest}>\n ({renderedCount})\n </span>\n )\n}\n\nRatingDisplayCount.displayName = 'RatingDisplay.Count'\n","import { StarFill } from '@spark-ui/icons/StarFill'\nimport { StarOutline } from '@spark-ui/icons/StarOutline'\nimport { cva, cx, type VariantProps } from 'class-variance-authority'\n\nimport { Icon } from '../icon'\nimport type { StarValue } from './types'\n\nconst ratingDisplayStarStyles = cva(['relative block after:absolute after:block after:inset-0'], {\n variants: {\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 defaultVariants: {\n gap: 'sm',\n },\n})\n\nconst ratingDisplayStarIconStyles = cva('', {\n variants: {\n size: {\n sm: 'text-caption-link',\n md: 'text-body-1',\n lg: 'text-display-3',\n },\n design: {\n filled: ['text-main-variant'],\n outlined: ['text-on-surface/dim-3'],\n },\n },\n})\n\ntype RatingDisplayStarstylesProps = Omit<VariantProps<typeof ratingDisplayStarStyles>, never>\ntype RatingDisplayStarIconStylesProps = Omit<\n VariantProps<typeof ratingDisplayStarIconStyles>,\n 'design'\n>\n\nexport interface RatingDisplayStarProps\n extends RatingDisplayStarstylesProps, RatingDisplayStarIconStylesProps {\n value: StarValue\n}\n\nexport const RatingDisplayStar = ({ value, size }: RatingDisplayStarProps) => {\n return (\n <div\n data-spark-component=\"rating-display-star\"\n data-part=\"star\"\n className={ratingDisplayStarStyles({\n gap: size === 'lg' ? 'md' : 'sm',\n })}\n >\n <div className={cx('z-raised absolute overflow-hidden')} style={{ width: value * 100 + '%' }}>\n <Icon\n className={ratingDisplayStarIconStyles({\n size,\n design: 'filled',\n })}\n >\n <StarFill />\n </Icon>\n </div>\n\n <Icon className={ratingDisplayStarIconStyles({ 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 formatRatingValue(value: number): string {\n const locale = Intl.DateTimeFormat().resolvedOptions().locale\n\n return new Intl.NumberFormat(locale, {\n minimumFractionDigits: 0,\n maximumFractionDigits: 1,\n }).format(value)\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 getSingleStarValue(value?: number): StarValue {\n if (value === undefined) return 0\n if (value < 1) return 0\n if (value < 4) return 0.5\n return 1\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 { formatRatingValue, getNearestHalfDecimal, getSingleStarValue, getStarValue, splitAt }\n","import { cx } from 'class-variance-authority'\n\nimport { useRatingDisplay } from './RatingDisplayContext'\nimport { RatingDisplayStar, type RatingDisplayStarProps } from './RatingDisplayStar'\nimport type { StarValue } from './types'\nimport { getSingleStarValue, getStarValue } from './utils'\n\nexport interface RatingDisplayStarsProps {\n size?: RatingDisplayStarProps['size']\n /**\n * Sets the rendering mode for stars.\n * @default 'default'\n */\n variant?: 'default' | 'single-star'\n /**\n * Custom fill algorithm for each star.\n * By default, stars are rounded to the nearest 0.5.\n */\n getFillMode?: ({ value, index }: { value?: number; index: number }) => StarValue\n}\n\nexport const RatingDisplayStars = ({\n size,\n variant = 'default',\n getFillMode,\n}: RatingDisplayStarsProps) => {\n const { value, size: contextSize } = useRatingDisplay()\n const resolvedSize = size ?? contextSize\n const getDisplayValue = (index: number) => {\n if (getFillMode) {\n return getFillMode({ index, value })\n }\n\n return variant === 'single-star' ? getSingleStarValue(value) : getStarValue({ index, value })\n }\n\n const stars =\n variant === 'single-star'\n ? [getDisplayValue(0)]\n : Array.from({ length: 5 }, (_, index) => getDisplayValue(index))\n\n return (\n <div\n data-spark-component=\"rating-display-stars\"\n className={cx(resolvedSize === 'lg' ? 'gap-x-md' : 'gap-x-sm', 'flex')}\n >\n {stars.map((starValue, index) => (\n <RatingDisplayStar key={index} size={resolvedSize} value={starValue} />\n ))}\n </div>\n )\n}\n\nRatingDisplayStars.displayName = 'RatingDisplay.Stars'\n","import { cva } from 'class-variance-authority'\nimport { type ComponentPropsWithRef, type ReactNode } from 'react'\n\nimport { useRatingDisplay } from './RatingDisplayContext'\nimport { formatRatingValue } from './utils'\n\nexport interface RatingDisplayValueProps extends Omit<ComponentPropsWithRef<'span'>, 'children'> {\n /**\n * Custom value content.\n * Pass a render function to receive the formatted value (first arg) and raw value (second arg),\n * then return the content to render.\n */\n children?: ReactNode | ((formattedValue: string, value: number) => ReactNode)\n}\n\nconst ratingDisplayValueStyles = cva('text-on-surface', {\n variants: {\n size: {\n sm: 'text-caption-highlight',\n md: 'text-body-2-highlight',\n lg: 'text-display-3',\n },\n },\n defaultVariants: {\n size: 'md',\n },\n})\n\nexport const RatingDisplayValue = ({ className, children, ...rest }: RatingDisplayValueProps) => {\n const { value, size } = useRatingDisplay()\n const formattedValue = formatRatingValue(value)\n const renderedValue =\n typeof children === 'function' ? children(formattedValue, value) : (children ?? formattedValue)\n\n return (\n <span\n data-spark-component=\"rating-display-value\"\n className={ratingDisplayValueStyles({ size: size ?? 'md', className })}\n {...rest}\n >\n {renderedValue}\n </span>\n )\n}\n\nRatingDisplayValue.displayName = 'RatingDisplay.Value'\n","import { RatingDisplay as Root } from './RatingDisplay'\nimport { RatingDisplayCount as Count } from './RatingDisplayCount'\nimport { RatingDisplayStars as Stars } from './RatingDisplayStars'\nimport { RatingDisplayValue as Value } from './RatingDisplayValue'\n\n/**\n * A read-only component that displays a rating value using stars.\n */\nexport const RatingDisplay: typeof Root & {\n Stars: typeof Stars\n Value: typeof Value\n Count: typeof Count\n} = Object.assign(Root, {\n Stars,\n Value,\n Count,\n})\n\nRatingDisplay.displayName = 'RatingDisplay'\nStars.displayName = 'RatingDisplay.Stars'\nValue.displayName = 'RatingDisplay.Value'\nCount.displayName = 'RatingDisplay.Count'\n\nexport { type RatingDisplayProps, type RatingDisplayRootProps } from './RatingDisplay'\nexport { type RatingDisplayStarsProps } from './RatingDisplayStars'\nexport { type RatingDisplayValueProps } from './RatingDisplayValue'\nexport { type RatingDisplayCountProps } from './RatingDisplayCount'\nexport type { StarValue } from './types'\n"],"mappings":"mVAUA,IAAM,GAAA,EAAA,EAAA,eAAuE,KAAK,CAIrE,GAAyB,CACpC,QACA,OACA,QACA,eAGE,EAAA,EAAA,KAAC,EAAqB,SAAtB,CAA+B,MAAO,CAAE,QAAO,OAAM,QAAO,CACzD,WAC6B,CAAA,CAIvB,MAAyB,CACpC,IAAM,GAAA,EAAA,EAAA,YAAqB,EAAqB,CAChD,GAAI,CAAC,EACH,MAAU,MAAM,uEAAuE,CAGzF,OAAO,GCAI,GAAiB,CAC5B,QAAQ,EACR,OA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,QAAO,QAAO,CAAC,CAGzF,EACJ,IAAY,cACR,CAAC,EAAgB,EAAE,CAAC,CACpB,MAAM,KAAK,CAAE,OAAQ,EAAG,EAAG,EAAG,IAAU,EAAgB,EAAM,CAAC,CAErE,OACE,EAAA,EAAA,KAAC,MAAD,CACE,uBAAqB,uBACrB,WAAA,EAAA,EAAA,IAAc,IAAiB,KAAO,WAAa,WAAY,OAAO,UAErE,EAAM,KAAK,EAAW,KACrB,EAAA,EAAA,KAAC,EAAD,CAA+B,KAAM,EAAc,MAAO,EAAa,CAA/C,EAA+C,CACvE,CACE,CAAA,EAIV,EAAmB,YAAc,sBCtCjC,IAAM,GAAA,EAAA,EAAA,KAA+B,kBAAmB,CACtD,SAAU,CACR,KAAM,CACJ,GAAI,yBACJ,GAAI,wBACJ,GAAI,iBACL,CACF,CACD,gBAAiB,CACf,KAAM,KACP,CACF,CAAC,CAEW,GAAsB,CAAE,YAAW,WAAU,GAAG,KAAoC,CAC/F,GAAM,CAAE,QAAO,QAAS,GAAkB,CACpC,EAAiB,EAAkB,EAAM,CACzC,EACJ,OAAO,GAAa,WAAa,EAAS,EAAgB,EAAM,CAAI,GAAY,EAElF,OACE,EAAA,EAAA,KAAC,OAAD,CACE,uBAAqB,uBACrB,UAAW,EAAyB,CAAE,KAAM,GAAQ,KAAM,YAAW,CAAC,CACtE,GAAI,WAEH,EACI,CAAA,EAIX,EAAmB,YAAc,sBCrCjC,IAAa,EAIT,OAAO,OAAO,EAAM,CACtB,MAAA,EACA,MAAA,EACA,MAAA,EACD,CAAC,CAEF,EAAc,YAAc,gBAC5B,EAAM,YAAc,sBACpB,EAAM,YAAc,sBACpB,EAAM,YAAc"}
|
|
@@ -139,10 +139,10 @@ var C = ({ size: e, variant: t = "default", getFillMode: n }) => {
|
|
|
139
139
|
C.displayName = "RatingDisplay.Stars";
|
|
140
140
|
//#endregion
|
|
141
141
|
//#region src/rating-display/RatingDisplayValue.tsx
|
|
142
|
-
var w = n("text-on-surface
|
|
142
|
+
var w = n("text-on-surface", {
|
|
143
143
|
variants: { size: {
|
|
144
|
-
sm: "text-caption",
|
|
145
|
-
md: "text-body-2",
|
|
144
|
+
sm: "text-caption-highlight",
|
|
145
|
+
md: "text-body-2-highlight",
|
|
146
146
|
lg: "text-display-3"
|
|
147
147
|
} },
|
|
148
148
|
defaultVariants: { size: "md" }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/rating-display/RatingDisplayContext.tsx","../../src/rating-display/RatingDisplay.tsx","../../src/rating-display/RatingDisplayCount.tsx","../../src/rating-display/RatingDisplayStar.tsx","../../src/rating-display/utils.ts","../../src/rating-display/RatingDisplayStars.tsx","../../src/rating-display/RatingDisplayValue.tsx","../../src/rating-display/index.ts"],"sourcesContent":["import { createContext, type PropsWithChildren, useContext } from 'react'\n\nimport type { RatingDisplayStarProps } from './RatingDisplayStar'\n\ninterface RatingDisplayContextValue {\n value: number\n size: RatingDisplayStarProps['size']\n count?: number\n}\n\nconst RatingDisplayContext = createContext<RatingDisplayContextValue | null>(null)\n\ninterface RatingDisplayProviderProps extends PropsWithChildren<RatingDisplayContextValue> {}\n\nexport const RatingDisplayProvider = ({\n value,\n size,\n count,\n children,\n}: RatingDisplayProviderProps) => {\n return (\n <RatingDisplayContext.Provider value={{ value, size, count }}>\n {children}\n </RatingDisplayContext.Provider>\n )\n}\n\nexport const useRatingDisplay = () => {\n const context = useContext(RatingDisplayContext)\n if (!context) {\n throw new Error('RatingDisplay compound components must be used within RatingDisplay.')\n }\n\n return context\n}\n","import { type ComponentPropsWithRef, type PropsWithChildren } from 'react'\n\nimport { Slot } from '../slot'\nimport { RatingDisplayProvider } from './RatingDisplayContext'\nimport type { RatingDisplayStarProps } from './RatingDisplayStar'\n\nexport interface RatingDisplayProps extends PropsWithChildren<ComponentPropsWithRef<'div'>> {\n /**\n * When true, merges props onto the single child element instead of rendering a div.\n * Use to render the root as a link or another custom element.\n */\n asChild?: boolean\n /**\n * The rating value to display, on a scale from 0 to 5.\n */\n value?: number\n /**\n * Sets the size of the stars.\n * @default 'md'\n */\n size?: RatingDisplayStarProps['size']\n /**\n * Optional count value available to `RatingDisplay.Count`.\n */\n count?: number\n /**\n * Accessible description of the rating content.\n */\n 'aria-label': string\n}\n\nexport type RatingDisplayRootProps = RatingDisplayProps\n\nexport const RatingDisplay = ({\n value = 0,\n size = 'md',\n count,\n asChild = false,\n ref,\n children,\n ...rest\n}: RatingDisplayProps) => {\n const ratingValue = value ?? 0\n const Component = asChild ? Slot : 'div'\n\n return (\n <RatingDisplayProvider value={ratingValue} size={size} count={count}>\n <Component\n ref={ref}\n className=\"gap-x-sm relative inline-flex items-center\"\n data-spark-component=\"rating-display\"\n {...rest}\n >\n {children}\n </Component>\n </RatingDisplayProvider>\n )\n}\n\nRatingDisplay.displayName = 'RatingDisplay'\n","import { cva } from 'class-variance-authority'\nimport { type ComponentPropsWithRef, type ReactNode } from 'react'\n\nimport { useRatingDisplay } from './RatingDisplayContext'\n\nexport interface RatingDisplayCountProps extends Omit<ComponentPropsWithRef<'span'>, 'children'> {\n /**\n * Custom count content.\n * Pass a render function to receive the count value and return the content to render.\n */\n children?: ReactNode | ((count: number) => ReactNode)\n}\n\nconst ratingDisplayCountStyles = cva('text-on-surface/dim-1', {\n variants: {\n size: {\n sm: 'text-caption',\n md: 'text-body-2',\n lg: 'text-display-3',\n },\n },\n defaultVariants: {\n size: 'md',\n },\n})\n\nexport const RatingDisplayCount = ({ className, children, ...rest }: RatingDisplayCountProps) => {\n const { count, size } = useRatingDisplay()\n if (count === undefined) return null\n const renderedCount = typeof children === 'function' ? children(count) : (children ?? count)\n\n return (\n <span className={ratingDisplayCountStyles({ size: size ?? 'md', className })} {...rest}>\n ({renderedCount})\n </span>\n )\n}\n\nRatingDisplayCount.displayName = 'RatingDisplay.Count'\n","import { StarFill } from '@spark-ui/icons/StarFill'\nimport { StarOutline } from '@spark-ui/icons/StarOutline'\nimport { cva, cx, type VariantProps } from 'class-variance-authority'\n\nimport { Icon } from '../icon'\nimport type { StarValue } from './types'\n\nconst ratingDisplayStarStyles = cva(['relative block after:absolute after:block after:inset-0'], {\n variants: {\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 defaultVariants: {\n gap: 'sm',\n },\n})\n\nconst ratingDisplayStarIconStyles = cva('', {\n variants: {\n size: {\n sm: 'text-caption-link',\n md: 'text-body-1',\n lg: 'text-display-3',\n },\n design: {\n filled: ['text-main-variant'],\n outlined: ['text-on-surface/dim-3'],\n },\n },\n})\n\ntype RatingDisplayStarstylesProps = Omit<VariantProps<typeof ratingDisplayStarStyles>, never>\ntype RatingDisplayStarIconStylesProps = Omit<\n VariantProps<typeof ratingDisplayStarIconStyles>,\n 'design'\n>\n\nexport interface RatingDisplayStarProps\n extends RatingDisplayStarstylesProps, RatingDisplayStarIconStylesProps {\n value: StarValue\n}\n\nexport const RatingDisplayStar = ({ value, size }: RatingDisplayStarProps) => {\n return (\n <div\n data-spark-component=\"rating-display-star\"\n data-part=\"star\"\n className={ratingDisplayStarStyles({\n gap: size === 'lg' ? 'md' : 'sm',\n })}\n >\n <div className={cx('z-raised absolute overflow-hidden')} style={{ width: value * 100 + '%' }}>\n <Icon\n className={ratingDisplayStarIconStyles({\n size,\n design: 'filled',\n })}\n >\n <StarFill />\n </Icon>\n </div>\n\n <Icon className={ratingDisplayStarIconStyles({ 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 formatRatingValue(value: number): string {\n const locale = Intl.DateTimeFormat().resolvedOptions().locale\n\n return new Intl.NumberFormat(locale, {\n minimumFractionDigits: 0,\n maximumFractionDigits: 1,\n }).format(value)\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 getSingleStarValue(value?: number): StarValue {\n if (value === undefined) return 0\n if (value < 1) return 0\n if (value < 4) return 0.5\n return 1\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 { formatRatingValue, getNearestHalfDecimal, getSingleStarValue, getStarValue, splitAt }\n","import { cx } from 'class-variance-authority'\n\nimport { useRatingDisplay } from './RatingDisplayContext'\nimport { RatingDisplayStar, type RatingDisplayStarProps } from './RatingDisplayStar'\nimport type { StarValue } from './types'\nimport { getSingleStarValue, getStarValue } from './utils'\n\nexport interface RatingDisplayStarsProps {\n size?: RatingDisplayStarProps['size']\n /**\n * Sets the rendering mode for stars.\n * @default 'default'\n */\n variant?: 'default' | 'single-star'\n /**\n * Custom fill algorithm for each star.\n * By default, stars are rounded to the nearest 0.5.\n */\n getFillMode?: ({ value, index }: { value?: number; index: number }) => StarValue\n}\n\nexport const RatingDisplayStars = ({\n size,\n variant = 'default',\n getFillMode,\n}: RatingDisplayStarsProps) => {\n const { value, size: contextSize } = useRatingDisplay()\n const resolvedSize = size ?? contextSize\n const getDisplayValue = (index: number) => {\n if (getFillMode) {\n return getFillMode({ index, value })\n }\n\n return variant === 'single-star' ? getSingleStarValue(value) : getStarValue({ index, value })\n }\n\n const stars =\n variant === 'single-star'\n ? [getDisplayValue(0)]\n : Array.from({ length: 5 }, (_, index) => getDisplayValue(index))\n\n return (\n <div\n data-spark-component=\"rating-display-stars\"\n className={cx(resolvedSize === 'lg' ? 'gap-x-md' : 'gap-x-sm', 'flex')}\n >\n {stars.map((starValue, index) => (\n <RatingDisplayStar key={index} size={resolvedSize} value={starValue} />\n ))}\n </div>\n )\n}\n\nRatingDisplayStars.displayName = 'RatingDisplay.Stars'\n","import { cva } from 'class-variance-authority'\nimport { type ComponentPropsWithRef, type ReactNode } from 'react'\n\nimport { useRatingDisplay } from './RatingDisplayContext'\nimport { formatRatingValue } from './utils'\n\nexport interface RatingDisplayValueProps extends Omit<ComponentPropsWithRef<'span'>, 'children'> {\n /**\n * Custom value content.\n * Pass a render function to receive the formatted value (first arg) and raw value (second arg),\n * then return the content to render.\n */\n children?: ReactNode | ((formattedValue: string, value: number) => ReactNode)\n}\n\nconst ratingDisplayValueStyles = cva('text-on-surface font-bold', {\n variants: {\n size: {\n sm: 'text-caption',\n md: 'text-body-2',\n lg: 'text-display-3',\n },\n },\n defaultVariants: {\n size: 'md',\n },\n})\n\nexport const RatingDisplayValue = ({ className, children, ...rest }: RatingDisplayValueProps) => {\n const { value, size } = useRatingDisplay()\n const formattedValue = formatRatingValue(value)\n const renderedValue =\n typeof children === 'function' ? children(formattedValue, value) : (children ?? formattedValue)\n\n return (\n <span\n data-spark-component=\"rating-display-value\"\n className={ratingDisplayValueStyles({ size: size ?? 'md', className })}\n {...rest}\n >\n {renderedValue}\n </span>\n )\n}\n\nRatingDisplayValue.displayName = 'RatingDisplay.Value'\n","import { RatingDisplay as Root } from './RatingDisplay'\nimport { RatingDisplayCount as Count } from './RatingDisplayCount'\nimport { RatingDisplayStars as Stars } from './RatingDisplayStars'\nimport { RatingDisplayValue as Value } from './RatingDisplayValue'\n\n/**\n * A read-only component that displays a rating value using stars.\n */\nexport const RatingDisplay: typeof Root & {\n Stars: typeof Stars\n Value: typeof Value\n Count: typeof Count\n} = Object.assign(Root, {\n Stars,\n Value,\n Count,\n})\n\nRatingDisplay.displayName = 'RatingDisplay'\nStars.displayName = 'RatingDisplay.Stars'\nValue.displayName = 'RatingDisplay.Value'\nCount.displayName = 'RatingDisplay.Count'\n\nexport { type RatingDisplayProps, type RatingDisplayRootProps } from './RatingDisplay'\nexport { type RatingDisplayStarsProps } from './RatingDisplayStars'\nexport { type RatingDisplayValueProps } from './RatingDisplayValue'\nexport { type RatingDisplayCountProps } from './RatingDisplayCount'\nexport type { StarValue } from './types'\n"],"mappings":";;;;;;;;AAUA,IAAM,IAAuB,EAAgD,KAAK,EAIrE,KAAyB,EACpC,UACA,SACA,UACA,kBAGE,kBAAC,EAAqB,UAAtB;CAA+B,OAAO;EAAE;EAAO;EAAM;EAAO;CACzD;CAC6B,CAAA,EAIvB,UAAyB;CACpC,IAAM,IAAU,EAAW,EAAqB;AAChD,KAAI,CAAC,EACH,OAAU,MAAM,uEAAuE;AAGzF,QAAO;GCAI,KAAiB,EAC5B,WAAQ,GACR,UAAO,MACP,UACA,aAAU,IACV,QACA,aACA,GAAG,QAMD,kBAAC,GAAD;CAAuB,OAJL,KAAS;CAIsB;CAAa;WAC5D,kBAJc,IAAU,IAAO,OAI/B;EACO;EACL,WAAU;EACV,wBAAqB;EACrB,GAAI;EAEH;EACS,CAAA;CACU,CAAA;AAI5B,EAAc,cAAc;;;AC9C5B,IAAM,IAA2B,EAAI,yBAAyB;CAC5D,UAAU,EACR,MAAM;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;EACL,EACF;CACD,iBAAiB,EACf,MAAM,MACP;CACF,CAAC,EAEW,KAAsB,EAAE,cAAW,aAAU,GAAG,QAAoC;CAC/F,IAAM,EAAE,UAAO,YAAS,GAAkB;AAC1C,KAAI,MAAU,KAAA,EAAW,QAAO;CAChC,IAAM,IAAgB,OAAO,KAAa,aAAa,EAAS,EAAM,GAAI,KAAY;AAEtF,QACE,kBAAC,QAAD;EAAM,WAAW,EAAyB;GAAE,MAAM,KAAQ;GAAM;GAAW,CAAC;EAAE,GAAI;YAAlF;GAAwF;GACpF;GAAc;GACX;;;AAIX,EAAmB,cAAc;;;AC/BjC,IAAM,IAA0B,EAAI,CAAC,0DAA0D,EAAE;CAC/F,UAAU,EACR,KAAK;EACH,IAAI,CAAC,4CAA4C,kCAAkC;EACnF,IAAI,CAAC,4CAA4C,kCAAkC;EACpF,EACF;CACD,iBAA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sources":["../../src/rating-display/RatingDisplayContext.tsx","../../src/rating-display/RatingDisplay.tsx","../../src/rating-display/RatingDisplayCount.tsx","../../src/rating-display/RatingDisplayStar.tsx","../../src/rating-display/utils.ts","../../src/rating-display/RatingDisplayStars.tsx","../../src/rating-display/RatingDisplayValue.tsx","../../src/rating-display/index.ts"],"sourcesContent":["import { createContext, type PropsWithChildren, useContext } from 'react'\n\nimport type { RatingDisplayStarProps } from './RatingDisplayStar'\n\ninterface RatingDisplayContextValue {\n value: number\n size: RatingDisplayStarProps['size']\n count?: number\n}\n\nconst RatingDisplayContext = createContext<RatingDisplayContextValue | null>(null)\n\ninterface RatingDisplayProviderProps extends PropsWithChildren<RatingDisplayContextValue> {}\n\nexport const RatingDisplayProvider = ({\n value,\n size,\n count,\n children,\n}: RatingDisplayProviderProps) => {\n return (\n <RatingDisplayContext.Provider value={{ value, size, count }}>\n {children}\n </RatingDisplayContext.Provider>\n )\n}\n\nexport const useRatingDisplay = () => {\n const context = useContext(RatingDisplayContext)\n if (!context) {\n throw new Error('RatingDisplay compound components must be used within RatingDisplay.')\n }\n\n return context\n}\n","import { type ComponentPropsWithRef, type PropsWithChildren } from 'react'\n\nimport { Slot } from '../slot'\nimport { RatingDisplayProvider } from './RatingDisplayContext'\nimport type { RatingDisplayStarProps } from './RatingDisplayStar'\n\nexport interface RatingDisplayProps extends PropsWithChildren<ComponentPropsWithRef<'div'>> {\n /**\n * When true, merges props onto the single child element instead of rendering a div.\n * Use to render the root as a link or another custom element.\n */\n asChild?: boolean\n /**\n * The rating value to display, on a scale from 0 to 5.\n */\n value?: number\n /**\n * Sets the size of the stars.\n * @default 'md'\n */\n size?: RatingDisplayStarProps['size']\n /**\n * Optional count value available to `RatingDisplay.Count`.\n */\n count?: number\n /**\n * Accessible description of the rating content.\n */\n 'aria-label': string\n}\n\nexport type RatingDisplayRootProps = RatingDisplayProps\n\nexport const RatingDisplay = ({\n value = 0,\n size = 'md',\n count,\n asChild = false,\n ref,\n children,\n ...rest\n}: RatingDisplayProps) => {\n const ratingValue = value ?? 0\n const Component = asChild ? Slot : 'div'\n\n return (\n <RatingDisplayProvider value={ratingValue} size={size} count={count}>\n <Component\n ref={ref}\n className=\"gap-x-sm relative inline-flex items-center\"\n data-spark-component=\"rating-display\"\n {...rest}\n >\n {children}\n </Component>\n </RatingDisplayProvider>\n )\n}\n\nRatingDisplay.displayName = 'RatingDisplay'\n","import { cva } from 'class-variance-authority'\nimport { type ComponentPropsWithRef, type ReactNode } from 'react'\n\nimport { useRatingDisplay } from './RatingDisplayContext'\n\nexport interface RatingDisplayCountProps extends Omit<ComponentPropsWithRef<'span'>, 'children'> {\n /**\n * Custom count content.\n * Pass a render function to receive the count value and return the content to render.\n */\n children?: ReactNode | ((count: number) => ReactNode)\n}\n\nconst ratingDisplayCountStyles = cva('text-on-surface/dim-1', {\n variants: {\n size: {\n sm: 'text-caption',\n md: 'text-body-2',\n lg: 'text-display-3',\n },\n },\n defaultVariants: {\n size: 'md',\n },\n})\n\nexport const RatingDisplayCount = ({ className, children, ...rest }: RatingDisplayCountProps) => {\n const { count, size } = useRatingDisplay()\n if (count === undefined) return null\n const renderedCount = typeof children === 'function' ? children(count) : (children ?? count)\n\n return (\n <span className={ratingDisplayCountStyles({ size: size ?? 'md', className })} {...rest}>\n ({renderedCount})\n </span>\n )\n}\n\nRatingDisplayCount.displayName = 'RatingDisplay.Count'\n","import { StarFill } from '@spark-ui/icons/StarFill'\nimport { StarOutline } from '@spark-ui/icons/StarOutline'\nimport { cva, cx, type VariantProps } from 'class-variance-authority'\n\nimport { Icon } from '../icon'\nimport type { StarValue } from './types'\n\nconst ratingDisplayStarStyles = cva(['relative block after:absolute after:block after:inset-0'], {\n variants: {\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 defaultVariants: {\n gap: 'sm',\n },\n})\n\nconst ratingDisplayStarIconStyles = cva('', {\n variants: {\n size: {\n sm: 'text-caption-link',\n md: 'text-body-1',\n lg: 'text-display-3',\n },\n design: {\n filled: ['text-main-variant'],\n outlined: ['text-on-surface/dim-3'],\n },\n },\n})\n\ntype RatingDisplayStarstylesProps = Omit<VariantProps<typeof ratingDisplayStarStyles>, never>\ntype RatingDisplayStarIconStylesProps = Omit<\n VariantProps<typeof ratingDisplayStarIconStyles>,\n 'design'\n>\n\nexport interface RatingDisplayStarProps\n extends RatingDisplayStarstylesProps, RatingDisplayStarIconStylesProps {\n value: StarValue\n}\n\nexport const RatingDisplayStar = ({ value, size }: RatingDisplayStarProps) => {\n return (\n <div\n data-spark-component=\"rating-display-star\"\n data-part=\"star\"\n className={ratingDisplayStarStyles({\n gap: size === 'lg' ? 'md' : 'sm',\n })}\n >\n <div className={cx('z-raised absolute overflow-hidden')} style={{ width: value * 100 + '%' }}>\n <Icon\n className={ratingDisplayStarIconStyles({\n size,\n design: 'filled',\n })}\n >\n <StarFill />\n </Icon>\n </div>\n\n <Icon className={ratingDisplayStarIconStyles({ 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 formatRatingValue(value: number): string {\n const locale = Intl.DateTimeFormat().resolvedOptions().locale\n\n return new Intl.NumberFormat(locale, {\n minimumFractionDigits: 0,\n maximumFractionDigits: 1,\n }).format(value)\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 getSingleStarValue(value?: number): StarValue {\n if (value === undefined) return 0\n if (value < 1) return 0\n if (value < 4) return 0.5\n return 1\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 { formatRatingValue, getNearestHalfDecimal, getSingleStarValue, getStarValue, splitAt }\n","import { cx } from 'class-variance-authority'\n\nimport { useRatingDisplay } from './RatingDisplayContext'\nimport { RatingDisplayStar, type RatingDisplayStarProps } from './RatingDisplayStar'\nimport type { StarValue } from './types'\nimport { getSingleStarValue, getStarValue } from './utils'\n\nexport interface RatingDisplayStarsProps {\n size?: RatingDisplayStarProps['size']\n /**\n * Sets the rendering mode for stars.\n * @default 'default'\n */\n variant?: 'default' | 'single-star'\n /**\n * Custom fill algorithm for each star.\n * By default, stars are rounded to the nearest 0.5.\n */\n getFillMode?: ({ value, index }: { value?: number; index: number }) => StarValue\n}\n\nexport const RatingDisplayStars = ({\n size,\n variant = 'default',\n getFillMode,\n}: RatingDisplayStarsProps) => {\n const { value, size: contextSize } = useRatingDisplay()\n const resolvedSize = size ?? contextSize\n const getDisplayValue = (index: number) => {\n if (getFillMode) {\n return getFillMode({ index, value })\n }\n\n return variant === 'single-star' ? getSingleStarValue(value) : getStarValue({ index, value })\n }\n\n const stars =\n variant === 'single-star'\n ? [getDisplayValue(0)]\n : Array.from({ length: 5 }, (_, index) => getDisplayValue(index))\n\n return (\n <div\n data-spark-component=\"rating-display-stars\"\n className={cx(resolvedSize === 'lg' ? 'gap-x-md' : 'gap-x-sm', 'flex')}\n >\n {stars.map((starValue, index) => (\n <RatingDisplayStar key={index} size={resolvedSize} value={starValue} />\n ))}\n </div>\n )\n}\n\nRatingDisplayStars.displayName = 'RatingDisplay.Stars'\n","import { cva } from 'class-variance-authority'\nimport { type ComponentPropsWithRef, type ReactNode } from 'react'\n\nimport { useRatingDisplay } from './RatingDisplayContext'\nimport { formatRatingValue } from './utils'\n\nexport interface RatingDisplayValueProps extends Omit<ComponentPropsWithRef<'span'>, 'children'> {\n /**\n * Custom value content.\n * Pass a render function to receive the formatted value (first arg) and raw value (second arg),\n * then return the content to render.\n */\n children?: ReactNode | ((formattedValue: string, value: number) => ReactNode)\n}\n\nconst ratingDisplayValueStyles = cva('text-on-surface', {\n variants: {\n size: {\n sm: 'text-caption-highlight',\n md: 'text-body-2-highlight',\n lg: 'text-display-3',\n },\n },\n defaultVariants: {\n size: 'md',\n },\n})\n\nexport const RatingDisplayValue = ({ className, children, ...rest }: RatingDisplayValueProps) => {\n const { value, size } = useRatingDisplay()\n const formattedValue = formatRatingValue(value)\n const renderedValue =\n typeof children === 'function' ? children(formattedValue, value) : (children ?? formattedValue)\n\n return (\n <span\n data-spark-component=\"rating-display-value\"\n className={ratingDisplayValueStyles({ size: size ?? 'md', className })}\n {...rest}\n >\n {renderedValue}\n </span>\n )\n}\n\nRatingDisplayValue.displayName = 'RatingDisplay.Value'\n","import { RatingDisplay as Root } from './RatingDisplay'\nimport { RatingDisplayCount as Count } from './RatingDisplayCount'\nimport { RatingDisplayStars as Stars } from './RatingDisplayStars'\nimport { RatingDisplayValue as Value } from './RatingDisplayValue'\n\n/**\n * A read-only component that displays a rating value using stars.\n */\nexport const RatingDisplay: typeof Root & {\n Stars: typeof Stars\n Value: typeof Value\n Count: typeof Count\n} = Object.assign(Root, {\n Stars,\n Value,\n Count,\n})\n\nRatingDisplay.displayName = 'RatingDisplay'\nStars.displayName = 'RatingDisplay.Stars'\nValue.displayName = 'RatingDisplay.Value'\nCount.displayName = 'RatingDisplay.Count'\n\nexport { type RatingDisplayProps, type RatingDisplayRootProps } from './RatingDisplay'\nexport { type RatingDisplayStarsProps } from './RatingDisplayStars'\nexport { type RatingDisplayValueProps } from './RatingDisplayValue'\nexport { type RatingDisplayCountProps } from './RatingDisplayCount'\nexport type { StarValue } from './types'\n"],"mappings":";;;;;;;;AAUA,IAAM,IAAuB,EAAgD,KAAK,EAIrE,KAAyB,EACpC,UACA,SACA,UACA,kBAGE,kBAAC,EAAqB,UAAtB;CAA+B,OAAO;EAAE;EAAO;EAAM;EAAO;CACzD;CAC6B,CAAA,EAIvB,UAAyB;CACpC,IAAM,IAAU,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