@42-central/ui-react 0.20.0 → 0.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-PAFS7TED.js → chunk-2HIX6DKN.js} +3 -3
- package/dist/{chunk-PAFS7TED.js.map → chunk-2HIX6DKN.js.map} +1 -1
- package/dist/{chunk-Z5WYYDG2.js → chunk-2MXWEIMD.js} +7 -4
- package/dist/chunk-2MXWEIMD.js.map +1 -0
- package/dist/{chunk-JYK6JVR3.js → chunk-3BXKTWWD.js} +8 -8
- package/dist/{chunk-JYK6JVR3.js.map → chunk-3BXKTWWD.js.map} +1 -1
- package/dist/{chunk-7R4CDHBK.js → chunk-45QRQKRC.js} +4 -4
- package/dist/{chunk-7R4CDHBK.js.map → chunk-45QRQKRC.js.map} +1 -1
- package/dist/{chunk-MKJKCBRE.js → chunk-47LEAR6G.js} +6 -6
- package/dist/{chunk-MKJKCBRE.js.map → chunk-47LEAR6G.js.map} +1 -1
- package/dist/chunk-4ASNIDV7.js +17 -0
- package/dist/chunk-4ASNIDV7.js.map +1 -0
- package/dist/{chunk-ZN3WYGIQ.js → chunk-5HUEBSIS.js} +3 -3
- package/dist/{chunk-ZN3WYGIQ.js.map → chunk-5HUEBSIS.js.map} +1 -1
- package/dist/{chunk-2TM7UVM2.js → chunk-6M6YZ3PQ.js} +4 -4
- package/dist/{chunk-2TM7UVM2.js.map → chunk-6M6YZ3PQ.js.map} +1 -1
- package/dist/{chunk-4BGU2UQB.js → chunk-6VYGK3Q3.js} +6 -6
- package/dist/{chunk-4BGU2UQB.js.map → chunk-6VYGK3Q3.js.map} +1 -1
- package/dist/{chunk-ZFUTGBJC.js → chunk-6YNLRQ25.js} +3 -3
- package/dist/{chunk-ZFUTGBJC.js.map → chunk-6YNLRQ25.js.map} +1 -1
- package/dist/{chunk-6OV6EJQ2.js → chunk-7AQ4MN4M.js} +6 -6
- package/dist/{chunk-6OV6EJQ2.js.map → chunk-7AQ4MN4M.js.map} +1 -1
- package/dist/{chunk-5337N3FE.js → chunk-7BOSX65U.js} +3 -3
- package/dist/{chunk-5337N3FE.js.map → chunk-7BOSX65U.js.map} +1 -1
- package/dist/{chunk-THLMW5IU.js → chunk-7CNDZZZ6.js} +4 -4
- package/dist/{chunk-THLMW5IU.js.map → chunk-7CNDZZZ6.js.map} +1 -1
- package/dist/{chunk-LJ3GHC4V.js → chunk-BE2LWUHY.js} +5 -5
- package/dist/{chunk-LJ3GHC4V.js.map → chunk-BE2LWUHY.js.map} +1 -1
- package/dist/{chunk-LSIX2PVU.js → chunk-BNWQ7IAZ.js} +7 -7
- package/dist/{chunk-LSIX2PVU.js.map → chunk-BNWQ7IAZ.js.map} +1 -1
- package/dist/{chunk-2KN3MI7I.js → chunk-C4NFRSOR.js} +4 -4
- package/dist/{chunk-2KN3MI7I.js.map → chunk-C4NFRSOR.js.map} +1 -1
- package/dist/{chunk-3REFDGOM.js → chunk-C6NVU4F7.js} +3 -3
- package/dist/{chunk-3REFDGOM.js.map → chunk-C6NVU4F7.js.map} +1 -1
- package/dist/{chunk-HVOEVB4E.js → chunk-D2QIPQ74.js} +3 -3
- package/dist/{chunk-HVOEVB4E.js.map → chunk-D2QIPQ74.js.map} +1 -1
- package/dist/{chunk-4EU6FGGB.js → chunk-DA4QII2N.js} +4 -4
- package/dist/{chunk-4EU6FGGB.js.map → chunk-DA4QII2N.js.map} +1 -1
- package/dist/{chunk-LZWA7V62.js → chunk-DJLNGWMM.js} +5 -5
- package/dist/{chunk-LZWA7V62.js.map → chunk-DJLNGWMM.js.map} +1 -1
- package/dist/{chunk-HEQ2H6VO.js → chunk-DT6LKNZF.js} +4 -4
- package/dist/{chunk-HEQ2H6VO.js.map → chunk-DT6LKNZF.js.map} +1 -1
- package/dist/{chunk-BUFALAEK.js → chunk-E5H3YWZV.js} +4 -4
- package/dist/{chunk-BUFALAEK.js.map → chunk-E5H3YWZV.js.map} +1 -1
- package/dist/{chunk-WR444JRU.js → chunk-E63VD25L.js} +7 -7
- package/dist/{chunk-WR444JRU.js.map → chunk-E63VD25L.js.map} +1 -1
- package/dist/{chunk-H7INUXZD.js → chunk-F342ZT7O.js} +4 -4
- package/dist/{chunk-H7INUXZD.js.map → chunk-F342ZT7O.js.map} +1 -1
- package/dist/{chunk-VALQ2XVA.js → chunk-H3PYSAWN.js} +3 -3
- package/dist/{chunk-VALQ2XVA.js.map → chunk-H3PYSAWN.js.map} +1 -1
- package/dist/{chunk-Q5ZO2O25.js → chunk-HRNWWL3Y.js} +6 -6
- package/dist/{chunk-Q5ZO2O25.js.map → chunk-HRNWWL3Y.js.map} +1 -1
- package/dist/{chunk-DHTSVJ4G.js → chunk-IOYZC7SA.js} +9 -9
- package/dist/{chunk-DHTSVJ4G.js.map → chunk-IOYZC7SA.js.map} +1 -1
- package/dist/{chunk-HBFN5W7Q.js → chunk-JVG5ISPT.js} +4 -4
- package/dist/{chunk-HBFN5W7Q.js.map → chunk-JVG5ISPT.js.map} +1 -1
- package/dist/{chunk-6KER77RS.js → chunk-KMZENCEP.js} +7 -7
- package/dist/{chunk-6KER77RS.js.map → chunk-KMZENCEP.js.map} +1 -1
- package/dist/{chunk-VVM7JMZS.js → chunk-LBAE6FP6.js} +8 -8
- package/dist/{chunk-VVM7JMZS.js.map → chunk-LBAE6FP6.js.map} +1 -1
- package/dist/{chunk-U2PNMMDB.js → chunk-LKFHUDEW.js} +7 -7
- package/dist/{chunk-U2PNMMDB.js.map → chunk-LKFHUDEW.js.map} +1 -1
- package/dist/{chunk-P276SCCV.js → chunk-MKKQE3TM.js} +6 -6
- package/dist/{chunk-P276SCCV.js.map → chunk-MKKQE3TM.js.map} +1 -1
- package/dist/{chunk-2SVX3MQQ.js → chunk-MW42XVPD.js} +3 -3
- package/dist/{chunk-2SVX3MQQ.js.map → chunk-MW42XVPD.js.map} +1 -1
- package/dist/{chunk-S4TRYMCU.js → chunk-MXAACRWE.js} +6 -6
- package/dist/{chunk-S4TRYMCU.js.map → chunk-MXAACRWE.js.map} +1 -1
- package/dist/{chunk-WFHY6NRQ.js → chunk-NJPHZBLI.js} +11 -11
- package/dist/{chunk-WFHY6NRQ.js.map → chunk-NJPHZBLI.js.map} +1 -1
- package/dist/{chunk-DUPE2CRU.js → chunk-NKOTA5TM.js} +3 -3
- package/dist/{chunk-DUPE2CRU.js.map → chunk-NKOTA5TM.js.map} +1 -1
- package/dist/{chunk-RGLNH7A5.js → chunk-NLOBBJAA.js} +3 -3
- package/dist/{chunk-RGLNH7A5.js.map → chunk-NLOBBJAA.js.map} +1 -1
- package/dist/{chunk-FXDLS23K.js → chunk-NS6RGPWR.js} +3 -3
- package/dist/{chunk-FXDLS23K.js.map → chunk-NS6RGPWR.js.map} +1 -1
- package/dist/{chunk-ZWOZL4XX.js → chunk-O5W3QWJ6.js} +5 -5
- package/dist/{chunk-ZWOZL4XX.js.map → chunk-O5W3QWJ6.js.map} +1 -1
- package/dist/{chunk-PD4FX34E.js → chunk-O7LS6OZR.js} +4 -4
- package/dist/{chunk-PD4FX34E.js.map → chunk-O7LS6OZR.js.map} +1 -1
- package/dist/{chunk-JL4QMM46.js → chunk-POKLPMSB.js} +5 -5
- package/dist/{chunk-JL4QMM46.js.map → chunk-POKLPMSB.js.map} +1 -1
- package/dist/{chunk-K6BHDFX3.js → chunk-QKSLDQM2.js} +3 -3
- package/dist/{chunk-K6BHDFX3.js.map → chunk-QKSLDQM2.js.map} +1 -1
- package/dist/{chunk-CDHIF2NV.js → chunk-QNKD2SQM.js} +8 -8
- package/dist/{chunk-CDHIF2NV.js.map → chunk-QNKD2SQM.js.map} +1 -1
- package/dist/{chunk-KOT4PWGE.js → chunk-RCF7HTG5.js} +5 -5
- package/dist/{chunk-KOT4PWGE.js.map → chunk-RCF7HTG5.js.map} +1 -1
- package/dist/{chunk-SE3CGQRO.js → chunk-RLOWPCGG.js} +3 -3
- package/dist/{chunk-SE3CGQRO.js.map → chunk-RLOWPCGG.js.map} +1 -1
- package/dist/{chunk-R57QP43T.js → chunk-SVKN5ZHX.js} +4 -4
- package/dist/{chunk-R57QP43T.js.map → chunk-SVKN5ZHX.js.map} +1 -1
- package/dist/{chunk-NJ4RO3CT.js → chunk-SWVUXEBT.js} +5 -5
- package/dist/{chunk-NJ4RO3CT.js.map → chunk-SWVUXEBT.js.map} +1 -1
- package/dist/{chunk-FZNPJAGJ.js → chunk-SXNAUSEB.js} +5 -5
- package/dist/{chunk-FZNPJAGJ.js.map → chunk-SXNAUSEB.js.map} +1 -1
- package/dist/{chunk-7AWOMWCQ.js → chunk-TWLJQE75.js} +7 -7
- package/dist/{chunk-7AWOMWCQ.js.map → chunk-TWLJQE75.js.map} +1 -1
- package/dist/{chunk-GGT4GJD6.js → chunk-TWNIAF7K.js} +3 -3
- package/dist/{chunk-GGT4GJD6.js.map → chunk-TWNIAF7K.js.map} +1 -1
- package/dist/{chunk-4TCTMRR5.js → chunk-UAYENYS2.js} +5 -5
- package/dist/{chunk-4TCTMRR5.js.map → chunk-UAYENYS2.js.map} +1 -1
- package/dist/{chunk-HDRC6ITF.js → chunk-UT3TOV2Q.js} +3 -3
- package/dist/{chunk-HDRC6ITF.js.map → chunk-UT3TOV2Q.js.map} +1 -1
- package/dist/{chunk-R52P43LZ.js → chunk-UXPINIDN.js} +3 -3
- package/dist/{chunk-R52P43LZ.js.map → chunk-UXPINIDN.js.map} +1 -1
- package/dist/{chunk-45DFYIK5.js → chunk-VD6PB3VA.js} +3 -3
- package/dist/{chunk-45DFYIK5.js.map → chunk-VD6PB3VA.js.map} +1 -1
- package/dist/{chunk-2OQP7UY4.js → chunk-VTDBWU6H.js} +4 -4
- package/dist/{chunk-2OQP7UY4.js.map → chunk-VTDBWU6H.js.map} +1 -1
- package/dist/{chunk-IMP5VHEN.js → chunk-XKDL4QS6.js} +3 -3
- package/dist/{chunk-IMP5VHEN.js.map → chunk-XKDL4QS6.js.map} +1 -1
- package/dist/{chunk-H26K66EU.js → chunk-Y57NW6G7.js} +3 -3
- package/dist/{chunk-H26K66EU.js.map → chunk-Y57NW6G7.js.map} +1 -1
- package/dist/components/accordion/index.js +5 -5
- package/dist/components/action-icon/index.js +4 -4
- package/dist/components/alert/index.js +6 -6
- package/dist/components/ambient-background/index.js +1 -1
- package/dist/components/app-shell/index.js +6 -6
- package/dist/components/aspect-ratio/index.js +1 -1
- package/dist/components/autocomplete/index.js +6 -6
- package/dist/components/avatar/index.js +1 -1
- package/dist/components/badge/index.js +3 -3
- package/dist/components/breadcrumb/index.js +1 -1
- package/dist/components/button/index.js +4 -4
- package/dist/components/button-group/index.js +2 -2
- package/dist/components/button-multi-select/index.js +7 -7
- package/dist/components/button-select/index.js +7 -7
- package/dist/components/calendar/index.js +6 -6
- package/dist/components/camera/index.js +14 -14
- package/dist/components/card/card.d.ts.map +1 -1
- package/dist/components/card/index.js +2 -2
- package/dist/components/carousel/index.js +3 -3
- package/dist/components/chart/index.js +1 -1
- package/dist/components/checkbox/index.js +6 -6
- package/dist/components/choice-card-group/index.js +5 -5
- package/dist/components/circular-progress/index.js +1 -1
- package/dist/components/clipboard/index.js +6 -6
- package/dist/components/code/index.js +2 -2
- package/dist/components/code-block/chrome.js +6 -6
- package/dist/components/code-block/index.js +7 -7
- package/dist/components/code-block/static.js +4 -1
- package/dist/components/code-block/static.js.map +1 -1
- package/dist/components/collapse/index.js +2 -2
- package/dist/components/combobox/index.js +6 -6
- package/dist/components/combobox-list/index.js +8 -8
- package/dist/components/compare/index.js +2 -2
- package/dist/components/container/index.js +1 -1
- package/dist/components/data-table/index.js +32 -32
- package/dist/components/date-picker/index.js +15 -15
- package/dist/components/divider/index.js +2 -2
- package/dist/components/download-button/index.js +5 -5
- package/dist/components/drawer/index.js +6 -6
- package/dist/components/field/index.js +2 -2
- package/dist/components/figure/index.js +2 -2
- package/dist/components/file-item/index.js +8 -8
- package/dist/components/file-preview/index.js +6 -6
- package/dist/components/file-queue-summary/index.js +2 -2
- package/dist/components/file-trigger/index.js +5 -5
- package/dist/components/file-upload/index.js +10 -10
- package/dist/components/flex/index.js +2 -2
- package/dist/components/gallery/index.js +4 -4
- package/dist/components/grid/index.js +1 -1
- package/dist/components/hover-card/index.js +2 -2
- package/dist/components/image/index.js +2 -2
- package/dist/components/image-cropper/index.js +7 -7
- package/dist/components/indicator/index.js +1 -1
- package/dist/components/input/index.js +3 -3
- package/dist/components/kbd/index.js +3 -3
- package/dist/components/lightbox/index.js +9 -9
- package/dist/components/mark/index.js +2 -2
- package/dist/components/menu/index.js +4 -4
- package/dist/components/modal/index.js +6 -6
- package/dist/components/multi-combobox-list/index.js +10 -10
- package/dist/components/multi-select/index.js +9 -9
- package/dist/components/nav-link/index.js +5 -5
- package/dist/components/nav-link/tanstack.js +5 -5
- package/dist/components/notification/index.js +7 -7
- package/dist/components/number-input/index.js +6 -6
- package/dist/components/overlays/index.js +8 -8
- package/dist/components/password-input/index.js +4 -4
- package/dist/components/photo-capture/index.js +17 -17
- package/dist/components/pill/index.js +3 -3
- package/dist/components/pills-input/index.js +6 -6
- package/dist/components/pin-input/index.js +3 -3
- package/dist/components/popover/index.js +2 -2
- package/dist/components/progress/index.js +2 -2
- package/dist/components/radio-group/index.js +4 -4
- package/dist/components/rating/index.js +3 -3
- package/dist/components/schedule/index.js +9 -9
- package/dist/components/segment-group/index.js +3 -3
- package/dist/components/select/index.js +7 -7
- package/dist/components/skeleton/index.js +2 -2
- package/dist/components/slider/index.js +4 -4
- package/dist/components/spinner/index.js +2 -2
- package/dist/components/spotlight/index.js +15 -15
- package/dist/components/switch/index.js +3 -3
- package/dist/components/table/index.js +3 -3
- package/dist/components/tabs/index.js +3 -3
- package/dist/components/tags-input/index.js +8 -8
- package/dist/components/text/index.js +2 -2
- package/dist/components/text-input/index.js +3 -3
- package/dist/components/textarea/index.js +3 -3
- package/dist/components/theme-icon/index.js +3 -3
- package/dist/components/time-input/index.js +8 -8
- package/dist/components/timeline/index.js +1 -1
- package/dist/components/title/index.js +2 -2
- package/dist/components/tooltip/index.js +3 -3
- package/dist/components/tree-multi-select/index.js +10 -10
- package/dist/components/tree-select/index.js +7 -7
- package/dist/index.js +2 -2
- package/dist/lib/cn.d.ts.map +1 -1
- package/dist/lib/cn.js +1 -1
- package/package.json +1 -1
- package/src/components/card/card.test.tsx +10 -0
- package/src/components/card/card.tsx +4 -1
- package/src/lib/cn.test.ts +9 -0
- package/src/lib/cn.ts +9 -1
- package/dist/chunk-QP4I37PA.js +0 -14
- package/dist/chunk-QP4I37PA.js.map +0 -1
- package/dist/chunk-Z5WYYDG2.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/segment-group/segment-group.tsx"],"names":["Ark"],"mappings":";;;;;;;;;;;;AAsEA,IAAM,OAAA,GAAU,GAAA;AAAA,EACd;AAAA,IACE,aAAA;AAAA,IACA,wEAAA;AAAA,IACA,kBAAA,CAAmB,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAKnB,8FAAA;AAAA,IACA,mBAAA;AAAA,IACA,2DAAA;AAAA,IACA;AAAA,GACF;AAAA,EACA;AAAA,IACE,QAAA,EAAU;AAAA,MACR,OAAA,EAAS;AAAA,QACP,MAAA,EAAQ,0CAAA;AAAA,QACR,KAAA,EAAO,sCAAA;AAAA,QACP,OAAA,EAAS,sCAAA;AAAA,QACT,MAAA,EAAQ,sCAAA;AAAA,QACR,OAAA,EAAS;AAAA,OACX;AAAA,MACA,IAAA,EAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAMJ,EAAA,EAAI,+CAAA;AAAA,QACJ,EAAA,EAAI,iDAAA;AAAA,QACJ,EAAA,EAAI,+CAAA;AAAA,QACJ,EAAA,EAAI,+CAAA;AAAA,QACJ,EAAA,EAAI;AAAA;AACN,KACF;AAAA,IACA,eAAA,EAAiB,EAAE,OAAA,EAAS,SAAA,EAAW,MAAM,IAAA;AAAK;AAEtD,CAAA;AAWA,IAAM,cAAc,GAAA,CAAI;AAAA,EACtB,0BAAA;AAAA,EACA,oFAAA;AAAA,EACA,yCAAA;AAAA,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AA;AAAA,gBACpD,SAAA,EAAW,GAAG,YAAA,CAAa,EAAE,SAAS,CAAA,EAAG,YAAY,SAAS;AAAA;AAAA,aAChE;AAAA,YACC,UAAA,CAAW,GAAA,CAAI,CAAC,IAAA,qBACf,IAAA;AAAA,cAACA,cAAA,CAAI,IAAA;AAAA,cAAJ;AAAA,gBAEC,OAAO,IAAA,CAAK,KAAA;AAAA,gBACZ,UAAU,IAAA,CAAK,QAAA;AAAA,gBACf,eAAa,IAAA,CAAK,MAAA;AAAA,gBAClB,SAAA,EAAW,EAAA,CAAG,WAAA,EAAY,EAAG,YAAY,IAAI,CAAA;AAAA,gBAE7C,QAAA,EAAA;AAAA,kCAAA,GAAA;AAAA,oBAACA,cAAA,CAAI,QAAA;AAAA,oBAAJ;AAAA,sBACC,cAAY,IAAA,CAAK,KAAA;AAAA,sBACjB,SAAA,EAAW,GAAG,OAAA,CAAQ,EAAE,MAAM,OAAA,EAAS,CAAA,EAAG,UAAA,EAAY,QAAQ,CAAA;AAAA,sBAI7D,QAAA,EAAA,UAAA,uBACEA,cAAA,CAAI,WAAA,EAAJ,EACE,QAAA,EAAA,CAAC,GAAA,KACA,WAAW,IAAA,EAA4C;AAAA,wBACrD,SAAS,GAAA,CAAI,OAAA;AAAA,wBACb,UAAU,GAAA,CAAI;AAAA,uBACf,CAAA,EAEL,CAAA,GAEA,IAAA,CAAK;AAAA;AAAA,mBAET;AAAA,kCACA,GAAA,CAACA,cAAA,CAAI,WAAA,EAAJ,EAAgB,CAAA;AAAA,kCACjB,GAAA,CAACA,cAAA,CAAI,eAAA,EAAJ,EAAoB;AAAA;AAAA,eAAA;AAAA,cA1BhB,IAAA,CAAK;AAAA,aA4Bb;AAAA;AAAA,SAAA;AAAA,QA/EI;AAAA;AAgFP;AAAA,GACF;AAEJ","file":"chunk-2KN3MI7I.js","sourcesContent":["\"use client\"\n\nimport { useFieldContext } from \"@ark-ui/react/field\"\nimport { SegmentGroup as Ark } from \"@ark-ui/react/segment-group\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport type { FocusEvent, ReactNode, Ref } from \"react\"\nimport { cn } from \"../../lib/cn\"\nimport type { Color } from \"../../lib/colors\"\nimport { useDirectionCheck } from \"../../lib/intl\"\nimport { useMergedRefs } from \"../../lib/merge-refs\"\nimport { props } from \"../../lib/props\"\nimport type { WithTestId } from \"../../lib/test-id\"\nimport { TEXT_COLOR_CLASSES } from \"../../lib/typography-size\"\nimport { useUncontrolled } from \"../../lib/use-uncontrolled\"\nimport { type FieldProps, FieldShell, fieldA11yProps } from \"../field/field\"\n\n/**\n * SegmentGroup — a segmented single-choice control on Ark UI's SegmentGroup\n * machine (the radio-group model under the hood). It renders a row (or column)\n * of mutually exclusive segments with a sliding pill that animates to the\n * selected item. Use it as a compact, always-visible alternative to a `Select`\n * when the option set is small (2–5 items): view toggles, filters, billing\n * cadence, and the like.\n *\n * - Value is a single `string | null`; `onChange` hands it to you directly,\n * matching the kit's value-based `FormControlProps` contract.\n * - `data` accepts bare strings (`value === label`) or\n * `{ value, label?, disabled?, color?, payload? }` objects, mixed freely.\n * The component is generic over `data` (a `const` type parameter), so\n * `value` / `onChange` narrow to the literal value union and an item's\n * `payload` flows—typed—into `renderItem` (the same contract as `Select`).\n * - Label / description / error / required come from the built-in `Field`\n * wrapper, so a `SegmentGroup` is accessible and complete on its own.\n * - `name` renders a hidden radio input per item, so the selected value rides\n * a native `<form>` submission.\n *\n * `variant` mirrors the `Button` family (`filled` / `light` / `outline` /\n * `subtle` / `default`): the tray, the sliding pill, and the checked label all\n * adopt the variant's treatment off the shared `--c-*` slots. Palette rides on\n * `data-color`, so every kit color tints for free, `default` included — its pill\n * falls back to solid black/white with no color set, because `:root` defines\n * `--c-solid`/`--c-on-solid` as black/white (white/brand-950 under dark). A\n * per-item `color` overrides the group palette for whichever segment is\n * selected: it re-stamps `data-color` on that item and on the pill, so both\n * the fill and the checked label resolve from the same block.\n *\n * The moving pill is the Ark `Indicator`: Ark positions it absolutely via the\n * CSS vars `--left` / `--top` / `--width` / `--height` (the selected segment's\n * measured rect), so it sits *behind* the labels (`z-0`). Ark only re-measures\n * that rect on mount and on value change — not when `orientation` flips — so we\n * remount the root with `key={orientation}` to force a fresh measure on the new\n * axis. The value is held in `useUncontrolled` so the selection survives that\n * remount.\n */\n\n/**\n * Per-segment label: size sets the padding / text, `variant` sets the *checked*\n * text color so it reads against that variant's pill. The unchecked color is a\n * neutral gray applied at the call site.\n *\n * The checked label must come from the same source as the pill under it.\n * `default` and `filled` both paint `bg-(--c-solid)`, so both take\n * `--c-on-solid` — which resolves per-item, since each `ItemText` carries its\n * own `data-color`. Pairing a hard-coded neutral foreground with a `--c-solid`\n * fill is what broke `default` at any group `color` (#140): the pill moved with\n * the palette and the label stayed put, reaching 3.27:1 on brand. There is\n * deliberately no hover shift on the checked label — `Button`'s `filled` moves\n * only the background and keeps `--c-on-solid`, and no `--c-on-solid-hover`\n * slot exists in `colors.css`.\n */\nconst segItem = cva(\n [\n \"font-medium\",\n \"cursor-pointer rounded-input text-center whitespace-nowrap select-none\",\n TEXT_COLOR_CLASSES.secondary,\n // Only unchecked segments get the hover lift, as in Tabs. An\n // unscoped `hover:` ties on specificity with the checked foreground and\n // won on source order in dark theme, washing the checked label to\n // near-white over a colored pill.\n \"not-data-[state=checked]:hover:text-brand-950 dark:not-data-[state=checked]:hover:text-white\",\n \"transition-colors\",\n \"data-disabled:cursor-not-allowed data-disabled:opacity-50\",\n \"group-data-invalid:text-red-900 dark:group-data-invalid:text-red-500\",\n ],\n {\n variants: {\n variant: {\n filled: \"data-[state=checked]:text-(--c-on-solid)\",\n light: \"data-[state=checked]:text-(--c-text)\",\n outline: \"data-[state=checked]:text-(--c-text)\",\n subtle: \"data-[state=checked]:text-(--c-text)\",\n default: \"data-[state=checked]:text-(--c-on-solid)\",\n },\n size: {\n // No vertical padding of its own — the tray's `min-h` (below) sets the\n // box height and this item stretches to fill it (the tray's default\n // `align-items: stretch` propagates all the way down), so the label\n // just needs to center itself inside that taller box. This matches an\n // `Input` / `NumberInput`'s exact box height at the same size.\n xs: \"flex items-center justify-center px-1 text-xs\",\n sm: \"flex items-center justify-center px-1.5 text-sm\",\n md: \"flex items-center justify-center px-2 text-md\",\n lg: \"flex items-center justify-center px-3 text-lg\",\n xl: \"flex items-center justify-center px-4 text-xl\",\n },\n },\n defaultVariants: { variant: \"default\", size: \"md\" },\n },\n)\n\n/**\n * Per-segment wrapper. Beyond positioning the label above the pill (`z-1`), it\n * draws a hairline separator in the gap to its leading edge (a `::before`) so\n * inactive neighbours read as divided. That rule fades out next to the active\n * pill — on the checked segment and the one right after it — and is suppressed\n * before the first segment (the indicator is child 1, so the first segment is\n * `:nth-child(2)`). It flips from a vertical rule to a horizontal one when the\n * group is laid out vertically.\n */\nconst segItemWrap = cva([\n \"relative z-1 inline-flex\",\n \"before:absolute before:rounded-full before:bg-brand-900/30 dark:before:bg-white/35\",\n \"group-data-invalid:before:bg-red-500/30\",\n \"before:transition-opacity before:duration-200\",\n // Horizontal: a vertical rule centered on the leading edge, sitting in the gap. Logical\n // (`start`, `-ms-[0.5px]` to center the 1px rule), so under `dir=\"rtl\"` the rule still lands\n // between a segment and the one before it instead of on the far side.\n \"before:top-1/2 before:start-0 before:-ms-[0.5px] before:h-1/2 before:w-px before:-translate-y-1/2\",\n // Vertical: a horizontal rule centered on the top edge instead (`start-1/4` + `w-1/2` is\n // centered in either direction).\n \"in-data-[orientation=vertical]:before:top-0 in-data-[orientation=vertical]:before:start-1/4 in-data-[orientation=vertical]:before:ms-0 in-data-[orientation=vertical]:before:h-px in-data-[orientation=vertical]:before:w-1/2\",\n // No separator before the first segment, or flanking the active pill.\n \"nth-2:before:hidden\",\n \"data-[state=checked]:before:opacity-0 data-[state=checked]:[&+*]:before:opacity-0\",\n])\n\n/**\n * The sliding pill, mirroring each `Button` surface. Its slide + color transition\n * is driven by Ark (see the `--transition-*` overrides on the element); `default`\n * follows `--c-solid` like every other variant, which falls back to solid\n * black/white with no `data-color` set. Filled/soft-fill pills (`filled`, `light`,\n * `default`) use a tighter `rounded-xxs` than the tray's own `rounded-input`, for a\n * nested-corner look inside the tray's padding; bordered/transparent pills\n * (`outline`, `subtle`) keep `rounded-input`.\n */\nconst segIndicator = cva(\n [\n \"z-0\",\n // The slide's duration, read by the inline `transition-duration` (see the\n // pill below); reduced motion zeroes it, so the pill jumps instead.\n \"[--indicator-duration:var(--duration-normal)] motion-reduce:[--indicator-duration:0s]\",\n ],\n {\n variants: {\n variant: {\n filled: \"bg-(--c-solid) rounded-xxs\",\n light: \"bg-(--c-soft) border border-(--c-soft-hover) rounded-xxs\",\n outline: \"bg-transparent border border-(--c-solid) rounded-input\",\n subtle: \"bg-(--c-soft-hover) rounded-input\",\n default: \"bg-(--c-solid) rounded-xxs\",\n },\n },\n defaultVariants: { variant: \"default\" },\n },\n)\n\n/**\n * The tray. Mirrors the `Button` variants: `filled` is a borderless neutral fill\n * so the colored pill pops (the kit's quiet `bg-black/3 dark:bg-white/4`; light\n * mode darkens because a bare `bg-white/4` vanishes on a near-white page), `light` / `default` frame the pill with the same\n * translucent surface as `Input`'s own `default` shell (`bg-white/4` + the\n * hairline `border-brand-900/20 dark:border-white/15`) rather than an opaque\n * gray step, so the tray reads correctly on any host background, `subtle` /\n * `outline` are chromeless.\n */\nconst segTray = cva(\n [\n \"relative inline-flex rounded-input border p-0.5 transition-colors max-w-fit group\",\n \"data-[orientation=vertical]:flex-col\",\n \"data-disabled:cursor-not-allowed data-disabled:opacity-60\",\n // Focus halo + accent border, driven by the active palette's `--c-solid`. Keyed\n // off Zag's `data-focus-visible` (set only when the focus came from the keyboard,\n // never a mouse click) via `:has()`, so the ring stays off when you click a segment.\n //\n // Deliberately NOT `focusStyles`. This is the *shell* idiom, not the ring\n // idiom: an accent border plus a soft `/15` halo on a wrapper whose focus\n // lives on a descendant, with a red invalid twin on the identical selector.\n // That is `input.tsx`'s `shellChrome`, not `Button`'s ring — folding it into\n // `focusStyles` would make that helper grow an alpha, a border half and a\n // concept of invalid, for one call site. The two shells are worth sharing\n // with each other instead; see the follow-up issue.\n \"has-data-focus-visible:border-(--c-solid) has-data-focus-visible:ring-2 has-data-focus-visible:ring-(--c-solid)/15\",\n // Invalid wins over the palette: red border + red halo.\n \"data-invalid:border-red-500 data-invalid:has-data-focus-visible:border-red-500 data-invalid:has-data-focus-visible:ring-red-500/15\",\n // Disabled affordances on the shell.\n ],\n {\n variants: {\n variant: {\n filled: [\"bg-black/3 dark:bg-white/4\", \"border-transparent\"],\n light: [\"bg-white/4\", \"border-brand-900/20 dark:border-white/15\"],\n outline: [\"bg-transparent border-transparent\"],\n subtle: [\"bg-transparent border-transparent\"],\n default: [\"bg-white/4\", \"border-brand-900/20 dark:border-white/15\"],\n },\n size: {\n // The exact `min-h` `inputShell` (input.tsx) uses at the same size —\n // so a `SegmentGroup` sits flush with an `Input` / `NumberInput` of\n // the same size in a row (see `TimeRow`, which composes both).\n xs: \"gap-0 min-h-7\",\n sm: \"gap-0 min-h-8\",\n md: \"gap-0 min-h-9\",\n lg: \"gap-0 min-h-10\",\n xl: \"gap-0 min-h-12\",\n },\n },\n defaultVariants: { variant: \"default\" },\n },\n)\n\nexport type SegmentGroupSize = NonNullable<VariantProps<typeof segItem>[\"size\"]>\nexport type SegmentGroupVariant = VariantProps<typeof segTray>[\"variant\"]\n\n/**\n * A single segment: a bare value-as-label string, or a labelled object. Objects\n * may carry a `payload` of arbitrary data (the machine ignores it; it flows\n * through to `renderItem`, typed off the `data` shape — the same contract as\n * `Select`'s `SelectItem`).\n */\nexport type SegmentGroupItem<P = unknown> =\n | string\n | {\n value: string\n label?: ReactNode\n disabled?: boolean\n /** Overrides the group palette for the pill + label when this item is selected. */\n color?: Color\n /** Arbitrary extra data, surfaced to `renderItem`. */\n payload?: P\n /** `data-testid` on the rendered segment. Defaults to `` `item-${value}` ``. */\n testId?: string\n }\n\n/** The `data` array the component is generic over. */\nexport type SegmentGroupData<P = unknown> = ReadonlyArray<SegmentGroupItem<P>>\n\n/**\n * Extract the value-string union from a `SegmentGroupData` shape — bare strings\n * and item `.value`s both contribute. A `const` type parameter narrows it to the\n * literal union, so `value` / `onChange` are typed off the data (like `Select`).\n */\nexport type SegmentGroupValue<Data extends SegmentGroupData> = ItemValue<Data[number]>\ntype ItemValue<E> = E extends string ? E : E extends { value: infer V extends string } ? V : never\n\n/**\n * Extract the `payload` type carried by a `SegmentGroupData` shape, read\n * structurally off the data's `payload` property. Bare strings contribute\n * `never`; a homogeneous payload resolves precisely, a mixed one to the union.\n */\nexport type SegmentGroupPayload<Data extends SegmentGroupData> = PayloadOf<Data[number]>\ntype PayloadOf<T> = T extends string ? never : T extends { payload?: infer P } ? P : never\n\n/**\n * The segment handed to `renderItem`: `value` narrowed to the data's value union\n * and `payload` to the data's payload type, so a `const`-typed `data` yields\n * literal values and a precise payload in the callback.\n */\nexport type RenderableSegment<Data extends SegmentGroupData> = {\n value: SegmentGroupValue<Data>\n label: ReactNode\n disabled: boolean\n color: Color | undefined\n payload: SegmentGroupPayload<Data> | undefined\n}\n\n/** Live segment state passed alongside the item to `renderItem`. */\nexport type SegmentRenderState = {\n checked: boolean\n disabled: boolean\n}\n\n/**\n * Render a segment's label content yourself. Receives the (value-narrowed) item —\n * including its typed `payload` — and its live `{ checked, disabled }` state. The\n * segment keeps its sizing, pill, and selection wiring; you fill the label. In an\n * RSC tree the function must live in a `\"use client\"` module so the boundary\n * serializes it as a client reference.\n */\nexport type RenderSegment<Data extends SegmentGroupData> = (\n item: RenderableSegment<Data>,\n state: SegmentRenderState,\n) => ReactNode\n\ntype SegmentGroupClassNames = {\n field?: string\n /** The label element itself — e.g. `\"sr-only\"` to keep the accessible name\n * without showing it. */\n label?: string\n root?: string\n indicator?: string\n item?: string\n itemText?: string\n}\n\nexport type SegmentGroupProps<Data extends SegmentGroupData = SegmentGroupData> = Pick<\n FieldProps,\n \"label\" | \"description\" | \"error\" | \"required\"\n> &\n WithTestId & {\n /** Segments: bare strings (`value === label`) or `{ value, label?, disabled?, color?, payload? }`. */\n data: Data\n /** Controlled value. `null` clears the selection. */\n value?: SegmentGroupValue<Data> | null\n /** Uncontrolled initial value. */\n defaultValue?: SegmentGroupValue<Data> | null\n /** Fires with the selected value. */\n onChange?: (value: SegmentGroupValue<Data>) => void\n /** Render each segment's label content yourself, with its typed `payload`. */\n renderItem?: RenderSegment<Data>\n /** Lay the segments in a row (default) or a column. */\n orientation?: \"horizontal\" | \"vertical\"\n /** Red invalid state, independent of (and OR'd with) `error`. */\n invalid?: boolean\n /** Dims and blocks interaction. */\n disabled?: boolean\n /** Keeps full contrast but blocks edits. */\n readOnly?: boolean\n /** `xs`–`xl` match the exact box height of an `Input` / `NumberInput` at\n * that size, so a `SegmentGroup` composes flush inline next to one (see\n * `TimeInput`'s AM/PM toggle). */\n size?: SegmentGroupSize\n variant?: SegmentGroupVariant\n color?: Color\n /** Wires the hidden radio inputs into native form submission. */\n name?: string\n /** Explicit id for label association. */\n id?: string\n /** Lands on the root for focus-on-error. */\n ref?: Ref<HTMLDivElement>\n /** Forwarded to the root; drives touched/blurred validation. */\n onBlur?: (event: FocusEvent<HTMLDivElement>) => void\n className?: string\n classNames?: SegmentGroupClassNames\n }\n\n/** A fully resolved segment — every field present (`label` falls back to `value`). */\ntype NormalizedItem = {\n value: string\n label: ReactNode\n disabled: boolean\n color: Color | undefined\n payload: unknown\n testId: string\n}\n\n/** Normalize a bare string / object into the resolved `NormalizedItem` form. */\nconst normalizeItem = (item: SegmentGroupItem): NormalizedItem =>\n typeof item === \"string\"\n ? {\n value: item,\n label: item,\n disabled: false,\n color: undefined,\n payload: undefined,\n testId: `item-${item}`,\n }\n : {\n value: item.value,\n label: item.label ?? item.value,\n disabled: item.disabled ?? false,\n color: item.color,\n payload: item.payload,\n testId: item.testId ?? `item-${item.value}`,\n }\n\n/**\n * The real `role=\"radiogroup\"` root (and, through it, each item's hidden\n * radio input), split out so it reads the `Field` context from *inside* the\n * wrapping `FieldShell` — `SegmentGroup` itself renders that shell, so\n * calling `useFieldContext()` at its own top level would run too early.\n * Takes plain `string` values rather than the outer component's `Data`-typed\n * union: it only forwards them, so no generic type parameter is needed here.\n */\nconst SegmentGroupRoot = ({\n value,\n onValueChange,\n disabled,\n readOnly,\n required,\n invalid,\n orientation,\n name,\n id,\n ref,\n onBlur,\n color,\n className,\n testId,\n children,\n}: {\n value: string | null\n onValueChange: (value: string | null) => void\n disabled?: boolean\n readOnly?: boolean\n required?: boolean\n invalid: boolean\n orientation: \"horizontal\" | \"vertical\"\n name?: string\n id?: string\n ref?: Ref<HTMLDivElement>\n onBlur?: (event: FocusEvent<HTMLDivElement>) => void\n color?: Color\n className?: string\n children: ReactNode\n} & WithTestId) => {\n const field = useFieldContext()\n const checkDirection = useDirectionCheck()\n const rootRef = useMergedRefs(ref, checkDirection)\n return (\n <Ark.Root\n value={value}\n onValueChange={(d) => onValueChange(d.value)}\n disabled={disabled}\n readOnly={readOnly}\n required={required}\n invalid={invalid}\n orientation={orientation}\n name={name}\n id={id}\n ref={rootRef}\n onBlur={onBlur}\n data-color={color}\n {...props({ \"data-invalid\": invalid, \"data-testid\": testId })}\n {...fieldA11yProps(field)}\n className={className}\n >\n {children}\n </Ark.Root>\n )\n}\n\nexport const SegmentGroup = <const Data extends SegmentGroupData = SegmentGroupData>({\n data,\n value,\n defaultValue,\n onChange,\n renderItem,\n orientation = \"horizontal\",\n invalid,\n disabled,\n readOnly,\n required,\n size = \"md\",\n variant = \"default\",\n color,\n name,\n id,\n ref,\n onBlur,\n label,\n description,\n error,\n className,\n classNames,\n testId,\n}: SegmentGroupProps<Data>) => {\n // Red state is driven independently of the `Field` error slot so a form\n // library can flip it from `fieldState.invalid` (see FormControlProps).\n const isInvalid = invalid || error != null\n\n // Own the value so the pill can read which item is selected (per-item color)\n // and so the `key={orientation}` remount below preserves the selection.\n const [selectedValue, setSelectedValue] = useUncontrolled<SegmentGroupValue<Data> | null>({\n value,\n defaultValue,\n finalValue: null,\n onChange: (v) => v != null && onChange?.(v),\n })\n\n const normalized = (data as SegmentGroupData).map(normalizeItem)\n const selected = normalized.find((item) => item.value === selectedValue)\n\n return (\n <FieldShell\n label={label}\n description={description}\n error={error}\n required={required}\n disabled={disabled}\n size={size}\n className={classNames?.field}\n classNames={{ label: classNames?.label }}\n // A radio group: nothing carries the label's `for` id; the root's `aria-labelledby` names it.\n composite\n >\n {/* `key={orientation}` remounts the root on an axis flip so Ark re-measures\n the indicator rect for the new layout (it only measures on mount + value\n change). `useUncontrolled` keeps the selection across that remount. */}\n <SegmentGroupRoot\n key={orientation}\n value={selectedValue}\n // Ark's value is typed by the collection (`string`); the runtime value\n // always originates from `data`, so narrow it back to the caller's union.\n onValueChange={(v) => setSelectedValue(v as SegmentGroupValue<Data> | null)}\n disabled={disabled}\n readOnly={readOnly}\n required={required}\n invalid={isInvalid}\n orientation={orientation}\n name={name}\n id={id}\n ref={ref}\n onBlur={onBlur}\n color={color}\n testId={testId}\n className={cn(segTray({ variant, size }), className, classNames?.root)}\n >\n {/* The sliding pill. Ark sets `position: absolute` + `--left`/`--top`/\n `--width`/`--height` (the selected segment's rect) inline, so it\n sits behind the labels (`z-0`). It adopts the selected item's `color`\n (falling back to the group `color`), which is the same `data-color`\n that item's own label carries — so the fill and the `--c-on-solid`\n text on top of it always resolve from one block.\n\n We drive the slide ourselves rather than via Ark's gated transition.\n Ark sets `transition-property: none` whenever its `animateIndicator`\n flag is false — including the instant it receives the `transitionend`\n of ANY animated property. With several properties of differing\n end-times (a `left` redirected by an interrupting click vs. a color or\n width that already settled), that early end would null the transition\n and snap the pill mid-slide. Overriding the real `transition-*` props\n (our `style` wins via Ark's `mergeProps`) keeps the transition always\n on, so the flag is irrelevant and interruptions re-target smoothly. The\n first paint stays instant because Ark renders the pill `hidden` until\n its rect is measured, and `display:none` can't transition. The\n duration comes from `--indicator-duration` (set by a class) rather\n than an inline value, so reduced motion can zero it. */}\n <Ark.Indicator\n style={{\n width: \"var(--width)\",\n height: \"var(--height)\",\n transitionProperty: \"left, top, width, height, background-color, border-color\",\n transitionDuration: \"var(--indicator-duration)\",\n transitionTimingFunction: \"var(--ease-emphasized)\",\n }}\n {...props({ \"data-color\": selected?.color ?? color })}\n className={cn(segIndicator({ variant }), classNames?.indicator)}\n />\n {normalized.map((item) => (\n <Ark.Item\n key={item.value}\n value={item.value}\n disabled={item.disabled}\n data-testid={item.testId}\n className={cn(segItemWrap(), classNames?.item)}\n >\n <Ark.ItemText\n data-color={item.color}\n className={cn(segItem({ size, variant }), classNames?.itemText)}\n >\n {/* `renderItem` owns the label content (with the item's typed payload);\n the ItemText keeps its sizing, checked color, and pill wiring. */}\n {renderItem ? (\n <Ark.ItemContext>\n {(ctx) =>\n renderItem(item as unknown as RenderableSegment<Data>, {\n checked: ctx.checked,\n disabled: ctx.disabled,\n })\n }\n </Ark.ItemContext>\n ) : (\n item.label\n )}\n </Ark.ItemText>\n <Ark.ItemControl />\n <Ark.ItemHiddenInput />\n </Ark.Item>\n ))}\n </SegmentGroupRoot>\n </FieldShell>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/components/segment-group/segment-group.tsx"],"names":["Ark"],"mappings":";;;;;;;;;;;;AAsEA,IAAM,OAAA,GAAU,GAAA;AAAA,EACd;AAAA,IACE,aAAA;AAAA,IACA,wEAAA;AAAA,IACA,kBAAA,CAAmB,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAKnB,8FAAA;AAAA,IACA,mBAAA;AAAA,IACA,2DAAA;AAAA,IACA;AAAA,GACF;AAAA,EACA;AAAA,IACE,QAAA,EAAU;AAAA,MACR,OAAA,EAAS;AAAA,QACP,MAAA,EAAQ,0CAAA;AAAA,QACR,KAAA,EAAO,sCAAA;AAAA,QACP,OAAA,EAAS,sCAAA;AAAA,QACT,MAAA,EAAQ,sCAAA;AAAA,QACR,OAAA,EAAS;AAAA,OACX;AAAA,MACA,IAAA,EAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAMJ,EAAA,EAAI,+CAAA;AAAA,QACJ,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;AAAA,kCACjB,GAAA,CAACA,cAAA,CAAI,eAAA,EAAJ,EAAoB;AAAA;AAAA,eAAA;AAAA,cA1BhB,IAAA,CAAK;AAAA,aA4Bb;AAAA;AAAA,SAAA;AAAA,QA/EI;AAAA;AAgFP;AAAA,GACF;AAEJ","file":"chunk-C4NFRSOR.js","sourcesContent":["\"use client\"\n\nimport { useFieldContext } from \"@ark-ui/react/field\"\nimport { SegmentGroup as Ark } from \"@ark-ui/react/segment-group\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport type { FocusEvent, ReactNode, Ref } from \"react\"\nimport { cn } from \"../../lib/cn\"\nimport type { Color } from \"../../lib/colors\"\nimport { useDirectionCheck } from \"../../lib/intl\"\nimport { useMergedRefs } from \"../../lib/merge-refs\"\nimport { props } from \"../../lib/props\"\nimport type { WithTestId } from \"../../lib/test-id\"\nimport { TEXT_COLOR_CLASSES } from \"../../lib/typography-size\"\nimport { useUncontrolled } from \"../../lib/use-uncontrolled\"\nimport { type FieldProps, FieldShell, fieldA11yProps } from \"../field/field\"\n\n/**\n * SegmentGroup — a segmented single-choice control on Ark UI's SegmentGroup\n * machine (the radio-group model under the hood). It renders a row (or column)\n * of mutually exclusive segments with a sliding pill that animates to the\n * selected item. Use it as a compact, always-visible alternative to a `Select`\n * when the option set is small (2–5 items): view toggles, filters, billing\n * cadence, and the like.\n *\n * - Value is a single `string | null`; `onChange` hands it to you directly,\n * matching the kit's value-based `FormControlProps` contract.\n * - `data` accepts bare strings (`value === label`) or\n * `{ value, label?, disabled?, color?, payload? }` objects, mixed freely.\n * The component is generic over `data` (a `const` type parameter), so\n * `value` / `onChange` narrow to the literal value union and an item's\n * `payload` flows—typed—into `renderItem` (the same contract as `Select`).\n * - Label / description / error / required come from the built-in `Field`\n * wrapper, so a `SegmentGroup` is accessible and complete on its own.\n * - `name` renders a hidden radio input per item, so the selected value rides\n * a native `<form>` submission.\n *\n * `variant` mirrors the `Button` family (`filled` / `light` / `outline` /\n * `subtle` / `default`): the tray, the sliding pill, and the checked label all\n * adopt the variant's treatment off the shared `--c-*` slots. Palette rides on\n * `data-color`, so every kit color tints for free, `default` included — its pill\n * falls back to solid black/white with no color set, because `:root` defines\n * `--c-solid`/`--c-on-solid` as black/white (white/brand-950 under dark). A\n * per-item `color` overrides the group palette for whichever segment is\n * selected: it re-stamps `data-color` on that item and on the pill, so both\n * the fill and the checked label resolve from the same block.\n *\n * The moving pill is the Ark `Indicator`: Ark positions it absolutely via the\n * CSS vars `--left` / `--top` / `--width` / `--height` (the selected segment's\n * measured rect), so it sits *behind* the labels (`z-0`). Ark only re-measures\n * that rect on mount and on value change — not when `orientation` flips — so we\n * remount the root with `key={orientation}` to force a fresh measure on the new\n * axis. The value is held in `useUncontrolled` so the selection survives that\n * remount.\n */\n\n/**\n * Per-segment label: size sets the padding / text, `variant` sets the *checked*\n * text color so it reads against that variant's pill. The unchecked color is a\n * neutral gray applied at the call site.\n *\n * The checked label must come from the same source as the pill under it.\n * `default` and `filled` both paint `bg-(--c-solid)`, so both take\n * `--c-on-solid` — which resolves per-item, since each `ItemText` carries its\n * own `data-color`. Pairing a hard-coded neutral foreground with a `--c-solid`\n * fill is what broke `default` at any group `color` (#140): the pill moved with\n * the palette and the label stayed put, reaching 3.27:1 on brand. There is\n * deliberately no hover shift on the checked label — `Button`'s `filled` moves\n * only the background and keeps `--c-on-solid`, and no `--c-on-solid-hover`\n * slot exists in `colors.css`.\n */\nconst segItem = cva(\n [\n \"font-medium\",\n \"cursor-pointer rounded-input text-center whitespace-nowrap select-none\",\n TEXT_COLOR_CLASSES.secondary,\n // Only unchecked segments get the hover lift, as in Tabs. An\n // unscoped `hover:` ties on specificity with the checked foreground and\n // won on source order in dark theme, washing the checked label to\n // near-white over a colored pill.\n \"not-data-[state=checked]:hover:text-brand-950 dark:not-data-[state=checked]:hover:text-white\",\n \"transition-colors\",\n \"data-disabled:cursor-not-allowed data-disabled:opacity-50\",\n \"group-data-invalid:text-red-900 dark:group-data-invalid:text-red-500\",\n ],\n {\n variants: {\n variant: {\n filled: \"data-[state=checked]:text-(--c-on-solid)\",\n light: \"data-[state=checked]:text-(--c-text)\",\n outline: \"data-[state=checked]:text-(--c-text)\",\n subtle: \"data-[state=checked]:text-(--c-text)\",\n default: \"data-[state=checked]:text-(--c-on-solid)\",\n },\n size: {\n // No vertical padding of its own — the tray's `min-h` (below) sets the\n // box height and this item stretches to fill it (the tray's default\n // `align-items: stretch` propagates all the way down), so the label\n // just needs to center itself inside that taller box. This matches an\n // `Input` / `NumberInput`'s exact box height at the same size.\n xs: \"flex items-center justify-center px-1 text-xs\",\n sm: \"flex items-center justify-center px-1.5 text-sm\",\n md: \"flex items-center justify-center px-2 text-md\",\n lg: \"flex items-center justify-center px-3 text-lg\",\n xl: \"flex items-center justify-center px-4 text-xl\",\n },\n },\n defaultVariants: { variant: \"default\", size: \"md\" },\n },\n)\n\n/**\n * Per-segment wrapper. Beyond positioning the label above the pill (`z-1`), it\n * draws a hairline separator in the gap to its leading edge (a `::before`) so\n * inactive neighbours read as divided. That rule fades out next to the active\n * pill — on the checked segment and the one right after it — and is suppressed\n * before the first segment (the indicator is child 1, so the first segment is\n * `:nth-child(2)`). It flips from a vertical rule to a horizontal one when the\n * group is laid out vertically.\n */\nconst segItemWrap = cva([\n \"relative z-1 inline-flex\",\n \"before:absolute before:rounded-full before:bg-brand-900/30 dark:before:bg-white/35\",\n \"group-data-invalid:before:bg-red-500/30\",\n \"before:transition-opacity before:duration-200\",\n // Horizontal: a vertical rule centered on the leading edge, sitting in the gap. Logical\n // (`start`, `-ms-[0.5px]` to center the 1px rule), so under `dir=\"rtl\"` the rule still lands\n // between a segment and the one before it instead of on the far side.\n \"before:top-1/2 before:start-0 before:-ms-[0.5px] before:h-1/2 before:w-px before:-translate-y-1/2\",\n // Vertical: a horizontal rule centered on the top edge instead (`start-1/4` + `w-1/2` is\n // centered in either direction).\n \"in-data-[orientation=vertical]:before:top-0 in-data-[orientation=vertical]:before:start-1/4 in-data-[orientation=vertical]:before:ms-0 in-data-[orientation=vertical]:before:h-px in-data-[orientation=vertical]:before:w-1/2\",\n // No separator before the first segment, or flanking the active pill.\n \"nth-2:before:hidden\",\n \"data-[state=checked]:before:opacity-0 data-[state=checked]:[&+*]:before:opacity-0\",\n])\n\n/**\n * The sliding pill, mirroring each `Button` surface. Its slide + color transition\n * is driven by Ark (see the `--transition-*` overrides on the element); `default`\n * follows `--c-solid` like every other variant, which falls back to solid\n * black/white with no `data-color` set. Filled/soft-fill pills (`filled`, `light`,\n * `default`) use a tighter `rounded-xxs` than the tray's own `rounded-input`, for a\n * nested-corner look inside the tray's padding; bordered/transparent pills\n * (`outline`, `subtle`) keep `rounded-input`.\n */\nconst segIndicator = cva(\n [\n \"z-0\",\n // The slide's duration, read by the inline `transition-duration` (see the\n // pill below); reduced motion zeroes it, so the pill jumps instead.\n \"[--indicator-duration:var(--duration-normal)] motion-reduce:[--indicator-duration:0s]\",\n ],\n {\n variants: {\n variant: {\n filled: \"bg-(--c-solid) rounded-xxs\",\n light: \"bg-(--c-soft) border border-(--c-soft-hover) rounded-xxs\",\n outline: \"bg-transparent border border-(--c-solid) rounded-input\",\n subtle: \"bg-(--c-soft-hover) rounded-input\",\n default: \"bg-(--c-solid) rounded-xxs\",\n },\n },\n defaultVariants: { variant: \"default\" },\n },\n)\n\n/**\n * The tray. Mirrors the `Button` variants: `filled` is a borderless neutral fill\n * so the colored pill pops (the kit's quiet `bg-black/3 dark:bg-white/4`; light\n * mode darkens because a bare `bg-white/4` vanishes on a near-white page), `light` / `default` frame the pill with the same\n * translucent surface as `Input`'s own `default` shell (`bg-white/4` + the\n * hairline `border-brand-900/20 dark:border-white/15`) rather than an opaque\n * gray step, so the tray reads correctly on any host background, `subtle` /\n * `outline` are chromeless.\n */\nconst segTray = cva(\n [\n \"relative inline-flex rounded-input border p-0.5 transition-colors max-w-fit group\",\n \"data-[orientation=vertical]:flex-col\",\n \"data-disabled:cursor-not-allowed data-disabled:opacity-60\",\n // Focus halo + accent border, driven by the active palette's `--c-solid`. Keyed\n // off Zag's `data-focus-visible` (set only when the focus came from the keyboard,\n // never a mouse click) via `:has()`, so the ring stays off when you click a segment.\n //\n // Deliberately NOT `focusStyles`. This is the *shell* idiom, not the ring\n // idiom: an accent border plus a soft `/15` halo on a wrapper whose focus\n // lives on a descendant, with a red invalid twin on the identical selector.\n // That is `input.tsx`'s `shellChrome`, not `Button`'s ring — folding it into\n // `focusStyles` would make that helper grow an alpha, a border half and a\n // concept of invalid, for one call site. The two shells are worth sharing\n // with each other instead; see the follow-up issue.\n \"has-data-focus-visible:border-(--c-solid) has-data-focus-visible:ring-2 has-data-focus-visible:ring-(--c-solid)/15\",\n // Invalid wins over the palette: red border + red halo.\n \"data-invalid:border-red-500 data-invalid:has-data-focus-visible:border-red-500 data-invalid:has-data-focus-visible:ring-red-500/15\",\n // Disabled affordances on the shell.\n ],\n {\n variants: {\n variant: {\n filled: [\"bg-black/3 dark:bg-white/4\", \"border-transparent\"],\n light: [\"bg-white/4\", \"border-brand-900/20 dark:border-white/15\"],\n outline: [\"bg-transparent border-transparent\"],\n subtle: [\"bg-transparent border-transparent\"],\n default: [\"bg-white/4\", \"border-brand-900/20 dark:border-white/15\"],\n },\n size: {\n // The exact `min-h` `inputShell` (input.tsx) uses at the same size —\n // so a `SegmentGroup` sits flush with an `Input` / `NumberInput` of\n // the same size in a row (see `TimeRow`, which composes both).\n xs: \"gap-0 min-h-7\",\n sm: \"gap-0 min-h-8\",\n md: \"gap-0 min-h-9\",\n lg: \"gap-0 min-h-10\",\n xl: \"gap-0 min-h-12\",\n },\n },\n defaultVariants: { variant: \"default\" },\n },\n)\n\nexport type SegmentGroupSize = NonNullable<VariantProps<typeof segItem>[\"size\"]>\nexport type SegmentGroupVariant = VariantProps<typeof segTray>[\"variant\"]\n\n/**\n * A single segment: a bare value-as-label string, or a labelled object. Objects\n * may carry a `payload` of arbitrary data (the machine ignores it; it flows\n * through to `renderItem`, typed off the `data` shape — the same contract as\n * `Select`'s `SelectItem`).\n */\nexport type SegmentGroupItem<P = unknown> =\n | string\n | {\n value: string\n label?: ReactNode\n disabled?: boolean\n /** Overrides the group palette for the pill + label when this item is selected. */\n color?: Color\n /** Arbitrary extra data, surfaced to `renderItem`. */\n payload?: P\n /** `data-testid` on the rendered segment. Defaults to `` `item-${value}` ``. */\n testId?: string\n }\n\n/** The `data` array the component is generic over. */\nexport type SegmentGroupData<P = unknown> = ReadonlyArray<SegmentGroupItem<P>>\n\n/**\n * Extract the value-string union from a `SegmentGroupData` shape — bare strings\n * and item `.value`s both contribute. A `const` type parameter narrows it to the\n * literal union, so `value` / `onChange` are typed off the data (like `Select`).\n */\nexport type SegmentGroupValue<Data extends SegmentGroupData> = ItemValue<Data[number]>\ntype ItemValue<E> = E extends string ? E : E extends { value: infer V extends string } ? V : never\n\n/**\n * Extract the `payload` type carried by a `SegmentGroupData` shape, read\n * structurally off the data's `payload` property. Bare strings contribute\n * `never`; a homogeneous payload resolves precisely, a mixed one to the union.\n */\nexport type SegmentGroupPayload<Data extends SegmentGroupData> = PayloadOf<Data[number]>\ntype PayloadOf<T> = T extends string ? never : T extends { payload?: infer P } ? P : never\n\n/**\n * The segment handed to `renderItem`: `value` narrowed to the data's value union\n * and `payload` to the data's payload type, so a `const`-typed `data` yields\n * literal values and a precise payload in the callback.\n */\nexport type RenderableSegment<Data extends SegmentGroupData> = {\n value: SegmentGroupValue<Data>\n label: ReactNode\n disabled: boolean\n color: Color | undefined\n payload: SegmentGroupPayload<Data> | undefined\n}\n\n/** Live segment state passed alongside the item to `renderItem`. */\nexport type SegmentRenderState = {\n checked: boolean\n disabled: boolean\n}\n\n/**\n * Render a segment's label content yourself. Receives the (value-narrowed) item —\n * including its typed `payload` — and its live `{ checked, disabled }` state. The\n * segment keeps its sizing, pill, and selection wiring; you fill the label. In an\n * RSC tree the function must live in a `\"use client\"` module so the boundary\n * serializes it as a client reference.\n */\nexport type RenderSegment<Data extends SegmentGroupData> = (\n item: RenderableSegment<Data>,\n state: SegmentRenderState,\n) => ReactNode\n\ntype SegmentGroupClassNames = {\n field?: string\n /** The label element itself — e.g. `\"sr-only\"` to keep the accessible name\n * without showing it. */\n label?: string\n root?: string\n indicator?: string\n item?: string\n itemText?: string\n}\n\nexport type SegmentGroupProps<Data extends SegmentGroupData = SegmentGroupData> = Pick<\n FieldProps,\n \"label\" | \"description\" | \"error\" | \"required\"\n> &\n WithTestId & {\n /** Segments: bare strings (`value === label`) or `{ value, label?, disabled?, color?, payload? }`. */\n data: Data\n /** Controlled value. `null` clears the selection. */\n value?: SegmentGroupValue<Data> | null\n /** Uncontrolled initial value. */\n defaultValue?: SegmentGroupValue<Data> | null\n /** Fires with the selected value. */\n onChange?: (value: SegmentGroupValue<Data>) => void\n /** Render each segment's label content yourself, with its typed `payload`. */\n renderItem?: RenderSegment<Data>\n /** Lay the segments in a row (default) or a column. */\n orientation?: \"horizontal\" | \"vertical\"\n /** Red invalid state, independent of (and OR'd with) `error`. */\n invalid?: boolean\n /** Dims and blocks interaction. */\n disabled?: boolean\n /** Keeps full contrast but blocks edits. */\n readOnly?: boolean\n /** `xs`–`xl` match the exact box height of an `Input` / `NumberInput` at\n * that size, so a `SegmentGroup` composes flush inline next to one (see\n * `TimeInput`'s AM/PM toggle). */\n size?: SegmentGroupSize\n variant?: SegmentGroupVariant\n color?: Color\n /** Wires the hidden radio inputs into native form submission. */\n name?: string\n /** Explicit id for label association. */\n id?: string\n /** Lands on the root for focus-on-error. */\n ref?: Ref<HTMLDivElement>\n /** Forwarded to the root; drives touched/blurred validation. */\n onBlur?: (event: FocusEvent<HTMLDivElement>) => void\n className?: string\n classNames?: SegmentGroupClassNames\n }\n\n/** A fully resolved segment — every field present (`label` falls back to `value`). */\ntype NormalizedItem = {\n value: string\n label: ReactNode\n disabled: boolean\n color: Color | undefined\n payload: unknown\n testId: string\n}\n\n/** Normalize a bare string / object into the resolved `NormalizedItem` form. */\nconst normalizeItem = (item: SegmentGroupItem): NormalizedItem =>\n typeof item === \"string\"\n ? {\n value: item,\n label: item,\n disabled: false,\n color: undefined,\n payload: undefined,\n testId: `item-${item}`,\n }\n : {\n value: item.value,\n label: item.label ?? item.value,\n disabled: item.disabled ?? false,\n color: item.color,\n payload: item.payload,\n testId: item.testId ?? `item-${item.value}`,\n }\n\n/**\n * The real `role=\"radiogroup\"` root (and, through it, each item's hidden\n * radio input), split out so it reads the `Field` context from *inside* the\n * wrapping `FieldShell` — `SegmentGroup` itself renders that shell, so\n * calling `useFieldContext()` at its own top level would run too early.\n * Takes plain `string` values rather than the outer component's `Data`-typed\n * union: it only forwards them, so no generic type parameter is needed here.\n */\nconst SegmentGroupRoot = ({\n value,\n onValueChange,\n disabled,\n readOnly,\n required,\n invalid,\n orientation,\n name,\n id,\n ref,\n onBlur,\n color,\n className,\n testId,\n children,\n}: {\n value: string | null\n onValueChange: (value: string | null) => void\n disabled?: boolean\n readOnly?: boolean\n required?: boolean\n invalid: boolean\n orientation: \"horizontal\" | \"vertical\"\n name?: string\n id?: string\n ref?: Ref<HTMLDivElement>\n onBlur?: (event: FocusEvent<HTMLDivElement>) => void\n color?: Color\n className?: string\n children: ReactNode\n} & WithTestId) => {\n const field = useFieldContext()\n const checkDirection = useDirectionCheck()\n const rootRef = useMergedRefs(ref, checkDirection)\n return (\n <Ark.Root\n value={value}\n onValueChange={(d) => onValueChange(d.value)}\n disabled={disabled}\n readOnly={readOnly}\n required={required}\n invalid={invalid}\n orientation={orientation}\n name={name}\n id={id}\n ref={rootRef}\n onBlur={onBlur}\n data-color={color}\n {...props({ \"data-invalid\": invalid, \"data-testid\": testId })}\n {...fieldA11yProps(field)}\n className={className}\n >\n {children}\n </Ark.Root>\n )\n}\n\nexport const SegmentGroup = <const Data extends SegmentGroupData = SegmentGroupData>({\n data,\n value,\n defaultValue,\n onChange,\n renderItem,\n orientation = \"horizontal\",\n invalid,\n disabled,\n readOnly,\n required,\n size = \"md\",\n variant = \"default\",\n color,\n name,\n id,\n ref,\n onBlur,\n label,\n description,\n error,\n className,\n classNames,\n testId,\n}: SegmentGroupProps<Data>) => {\n // Red state is driven independently of the `Field` error slot so a form\n // library can flip it from `fieldState.invalid` (see FormControlProps).\n const isInvalid = invalid || error != null\n\n // Own the value so the pill can read which item is selected (per-item color)\n // and so the `key={orientation}` remount below preserves the selection.\n const [selectedValue, setSelectedValue] = useUncontrolled<SegmentGroupValue<Data> | null>({\n value,\n defaultValue,\n finalValue: null,\n onChange: (v) => v != null && onChange?.(v),\n })\n\n const normalized = (data as SegmentGroupData).map(normalizeItem)\n const selected = normalized.find((item) => item.value === selectedValue)\n\n return (\n <FieldShell\n label={label}\n description={description}\n error={error}\n required={required}\n disabled={disabled}\n size={size}\n className={classNames?.field}\n classNames={{ label: classNames?.label }}\n // A radio group: nothing carries the label's `for` id; the root's `aria-labelledby` names it.\n composite\n >\n {/* `key={orientation}` remounts the root on an axis flip so Ark re-measures\n the indicator rect for the new layout (it only measures on mount + value\n change). `useUncontrolled` keeps the selection across that remount. */}\n <SegmentGroupRoot\n key={orientation}\n value={selectedValue}\n // Ark's value is typed by the collection (`string`); the runtime value\n // always originates from `data`, so narrow it back to the caller's union.\n onValueChange={(v) => setSelectedValue(v as SegmentGroupValue<Data> | null)}\n disabled={disabled}\n readOnly={readOnly}\n required={required}\n invalid={isInvalid}\n orientation={orientation}\n name={name}\n id={id}\n ref={ref}\n onBlur={onBlur}\n color={color}\n testId={testId}\n className={cn(segTray({ variant, size }), className, classNames?.root)}\n >\n {/* The sliding pill. Ark sets `position: absolute` + `--left`/`--top`/\n `--width`/`--height` (the selected segment's rect) inline, so it\n sits behind the labels (`z-0`). It adopts the selected item's `color`\n (falling back to the group `color`), which is the same `data-color`\n that item's own label carries — so the fill and the `--c-on-solid`\n text on top of it always resolve from one block.\n\n We drive the slide ourselves rather than via Ark's gated transition.\n Ark sets `transition-property: none` whenever its `animateIndicator`\n flag is false — including the instant it receives the `transitionend`\n of ANY animated property. With several properties of differing\n end-times (a `left` redirected by an interrupting click vs. a color or\n width that already settled), that early end would null the transition\n and snap the pill mid-slide. Overriding the real `transition-*` props\n (our `style` wins via Ark's `mergeProps`) keeps the transition always\n on, so the flag is irrelevant and interruptions re-target smoothly. The\n first paint stays instant because Ark renders the pill `hidden` until\n its rect is measured, and `display:none` can't transition. The\n duration comes from `--indicator-duration` (set by a class) rather\n than an inline value, so reduced motion can zero it. */}\n <Ark.Indicator\n style={{\n width: \"var(--width)\",\n height: \"var(--height)\",\n transitionProperty: \"left, top, width, height, background-color, border-color\",\n transitionDuration: \"var(--indicator-duration)\",\n transitionTimingFunction: \"var(--ease-emphasized)\",\n }}\n {...props({ \"data-color\": selected?.color ?? color })}\n className={cn(segIndicator({ variant }), classNames?.indicator)}\n />\n {normalized.map((item) => (\n <Ark.Item\n key={item.value}\n value={item.value}\n disabled={item.disabled}\n data-testid={item.testId}\n className={cn(segItemWrap(), classNames?.item)}\n >\n <Ark.ItemText\n data-color={item.color}\n className={cn(segItem({ size, variant }), classNames?.itemText)}\n >\n {/* `renderItem` owns the label content (with the item's typed payload);\n the ItemText keeps its sizing, checked color, and pill wiring. */}\n {renderItem ? (\n <Ark.ItemContext>\n {(ctx) =>\n renderItem(item as unknown as RenderableSegment<Data>, {\n checked: ctx.checked,\n disabled: ctx.disabled,\n })\n }\n </Ark.ItemContext>\n ) : (\n item.label\n )}\n </Ark.ItemText>\n <Ark.ItemControl />\n <Ark.ItemHiddenInput />\n </Ark.Item>\n ))}\n </SegmentGroupRoot>\n </FieldShell>\n )\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cn } from './chunk-
|
|
1
|
+
import { cn } from './chunk-4ASNIDV7.js';
|
|
2
2
|
|
|
3
3
|
// src/lib/focus-styles.ts
|
|
4
4
|
var FOCUS_RING = {
|
|
@@ -85,5 +85,5 @@ var focusStyles = ({
|
|
|
85
85
|
) : cn(FOCUS_RING[source][ring], offset && FOCUS_OFFSET[source], inset && FOCUS_INSET[source]);
|
|
86
86
|
|
|
87
87
|
export { focusStyles };
|
|
88
|
-
//# sourceMappingURL=chunk-
|
|
89
|
-
//# sourceMappingURL=chunk-
|
|
88
|
+
//# sourceMappingURL=chunk-C6NVU4F7.js.map
|
|
89
|
+
//# sourceMappingURL=chunk-C6NVU4F7.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/focus-styles.ts"],"names":[],"mappings":";;;AA0EA,IAAM,UAAA,GAA6D;AAAA,EACjE,eAAA,EAAiB;AAAA,IACf,KAAA,EAAO,8EAAA;AAAA,IACP,OAAA,EAAS;AAAA,GACX;AAAA,EACA,oBAAA,EAAsB;AAAA,IACpB,KAAA,EAAO,6DAAA;AAAA,IACP,OAAA,EAAS;AAAA,GACX;AAAA,EACA,mBAAA,EAAqB;AAAA,IACnB,KAAA,EAAO,2DAAA;AAAA,IACP,OAAA,EAAS;AAAA,GACX;AAAA,EACA,wBAAA,EAA0B;AAAA,IACxB,KAAA,EAAO,qEAAA;AAAA,IACP,OAAA,EAAS;AAAA,GACX;AAAA,EACA,oBAAA,EAAsB;AAAA,IACpB,KAAA,EAAO,6DAAA;AAAA,IACP,OAAA,EAAS;AAAA;AAEb,CAAA;AAQA,IAAM,YAAA,GAA4C;AAAA,EAChD,eAAA,EACE,yGAAA;AAAA,EACF,oBAAA,EACE,wHAAA;AAAA,EACF,mBAAA,EACE,qHAAA;AAAA,EACF,wBAAA,EACE,oIAAA;AAAA,EACF,oBAAA,EACE;AACJ,CAAA;AAMA,IAAM,WAAA,GAA2C;AAAA,EAC/C,eAAA,EAAiB,0BAAA;AAAA,EACjB,oBAAA,EAAsB,+BAAA;AAAA,EACtB,mBAAA,EAAqB,8BAAA;AAAA,EACrB,wBAAA,EAA0B,mCAAA;AAAA,EAC1B,oBAAA,EAAsB;AACxB,CAAA;AAmBA,IAAM,aAAA,GAAgE;AAAA,EACpE,eAAA,EAAiB;AAAA,IACf,KAAA,EACE,gPAAA;AAAA,IACF,OAAA,EACE;AAAA,GACJ;AAAA,EACA,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M,CAAC","file":"chunk-3REFDGOM.js","sourcesContent":["import { cn } from \"./cn\"\n\n/**\n * Where the focused state lives — which selector the ring hangs off.\n *\n * - `focus-visible` — the CSS pseudo-class, on the element itself. The default,\n * and what you want for any ordinary `<button>`, `<a>` or `tabIndex` element.\n * - `data-focus-visible` — Zag's attribute, mirrored onto every part of a\n * machine-driven control (`Checkbox`, `RadioGroup`, `Switch`,\n * `ChoiceCardGroup`) whose real focus target is a visually-hidden `<input>`.\n * The visible part never receives DOM focus, so `:focus-visible` can never\n * match it.\n * - `has-focus-visible` — on an *ancestor* of the focused element. For a\n * focusable that sits inside a clipping box (a `Gallery` tile's button inside\n * an overlay-captioned `Figure`, which clips to its corners): a ring on the\n * button itself would be cut off, and an inset one would paint under the\n * image. The ring goes on the unclipped wrapper instead; the focused element\n * itself takes `focus-visible:outline-none`.\n * - `peer-has-focus-visible` — on a *later sibling* of a Tailwind `peer` that\n * contains the focused element. For a native control that is invisible by\n * design and stands in for a visible part it can't contain (`Compare`'s\n * transparent range input, inside a clipping wrapper, under its drawn grip):\n * the ring goes on the part the user sees. The focused element is invisible,\n * so its own outline needs no suppressing. The `peer` is a wrapper rather\n * than the control itself so the control can be clipped without clipping\n * the part that rings.\n * - `peer-focus-visible` — on a *later sibling* of a Tailwind `peer` that is\n * itself the focused element. For a scroll region whose own ring would be\n * painted under its content (`Table.Content`'s scroller, under a sticky\n * header's fill; a `FilePreview` PDF, under the embedded viewer): the ring\n * goes on a non-scrolling overlay drawn after it. Unlike\n * `peer-has-focus-visible` it ignores focus *inside* the peer, so a button\n * in a table row doesn't ring the whole table. The focused element takes\n * `focus-visible:outline-none`, as with `has-focus-visible`.\n */\nexport type FocusSource =\n | \"focus-visible\"\n | \"data-focus-visible\"\n | \"has-focus-visible\"\n | \"peer-has-focus-visible\"\n | \"peer-focus-visible\"\n\n/**\n * Which color the ring paints in.\n *\n * - `brand` — a fixed `brand-500`, independent of the element's own `color`.\n * The right answer almost everywhere, and the default.\n * - `palette` — the active palette's `--c-text`. Only for a control that sits\n * *inside* an already-accented surface, where a brand ring would read as a\n * second, unrelated color stacked on the one the surface carries.\n *\n * `--c-text`, not `--c-solid`, and at full opacity — because it is the one\n * slot that flips with the theme (700 light, 300 dark), so it can be dark on\n * a pale surface and pale on a dark one. `--c-solid` is 500 in *both*, which\n * leaves it a mid-tone with nowhere to go against a light background, and no\n * alpha can fix that: opacity only ever composites the ring toward whatever\n * sits behind it. Measured on a Schedule chip, `--c-solid` rings at 2.69:1\n * against the grid and 1.80:1 against the chip's own border; `--c-text` rings\n * at 5.41:1 and 3.62:1, clearing the 3:1 that WCAG 2.2 SC 1.4.11 asks for.\n */\nexport type FocusRing = \"brand\" | \"palette\"\n\n/**\n * The ring itself, per source × color.\n *\n * Every entry is a complete class literal, and nothing here is assembled at\n * runtime. Tailwind v4 scans the *built* JS for whole strings, so a class that\n * only ever exists as `` `${prefix}:ring-2` `` is never generated and the ring\n * silently disappears in consumer builds. `focus-styles.test.ts` enforces it.\n *\n * The `data-focus-visible`, `has-focus-visible` and the two `peer-*` rows carry no `outline-none`:\n * the element they land on is not the one focused, so there is no native\n * outline of its own to suppress.\n */\nconst FOCUS_RING: Record<FocusSource, Record<FocusRing, string>> = {\n \"focus-visible\": {\n brand: \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand-500\",\n palette: \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-(--c-text)\",\n },\n \"data-focus-visible\": {\n brand: \"data-focus-visible:ring-2 data-focus-visible:ring-brand-500\",\n palette: \"data-focus-visible:ring-2 data-focus-visible:ring-(--c-text)\",\n },\n \"has-focus-visible\": {\n brand: \"has-focus-visible:ring-2 has-focus-visible:ring-brand-500\",\n palette: \"has-focus-visible:ring-2 has-focus-visible:ring-(--c-text)\",\n },\n \"peer-has-focus-visible\": {\n brand: \"peer-has-focus-visible:ring-2 peer-has-focus-visible:ring-brand-500\",\n palette: \"peer-has-focus-visible:ring-2 peer-has-focus-visible:ring-(--c-text)\",\n },\n \"peer-focus-visible\": {\n brand: \"peer-focus-visible:ring-2 peer-focus-visible:ring-brand-500\",\n palette: \"peer-focus-visible:ring-2 peer-focus-visible:ring-(--c-text)\",\n },\n}\n\n/**\n * The offset gap, per source. The gap is painted in the *page* background —\n * `brand-50` light, `brand-950` dark — which is what makes it read as a gap\n * rather than as a second colored band. A neutral white / gray gap would show\n * as a thin off-ramp halo against the brand-tinted page.\n */\nconst FOCUS_OFFSET: Record<FocusSource, string> = {\n \"focus-visible\":\n \"focus-visible:ring-offset-2 focus-visible:ring-offset-brand-50 dark:focus-visible:ring-offset-brand-950\",\n \"data-focus-visible\":\n \"data-focus-visible:ring-offset-2 data-focus-visible:ring-offset-brand-50 dark:data-focus-visible:ring-offset-brand-950\",\n \"has-focus-visible\":\n \"has-focus-visible:ring-offset-2 has-focus-visible:ring-offset-brand-50 dark:has-focus-visible:ring-offset-brand-950\",\n \"peer-has-focus-visible\":\n \"peer-has-focus-visible:ring-offset-2 peer-has-focus-visible:ring-offset-brand-50 dark:peer-has-focus-visible:ring-offset-brand-950\",\n \"peer-focus-visible\":\n \"peer-focus-visible:ring-offset-2 peer-focus-visible:ring-offset-brand-50 dark:peer-focus-visible:ring-offset-brand-950\",\n}\n\n/**\n * The inset modifier, per source. Kept as whole literals for the same Tailwind\n * scanning reason as `FOCUS_RING`.\n */\nconst FOCUS_INSET: Record<FocusSource, string> = {\n \"focus-visible\": \"focus-visible:ring-inset\",\n \"data-focus-visible\": \"data-focus-visible:ring-inset\",\n \"has-focus-visible\": \"has-focus-visible:ring-inset\",\n \"peer-has-focus-visible\": \"peer-has-focus-visible:ring-inset\",\n \"peer-focus-visible\": \"peer-focus-visible:ring-inset\",\n}\n\n/**\n * The same indicator drawn as a CSS `outline` on an `::after` overlay that\n * covers the element, per source × color. For a focusable whose ring has\n * nowhere to go: a slide in a carousel's scroller, filled edge to edge by an\n * image. The scroller clips anything outside the slide, and a ring drawn\n * inside it is a box-shadow, painted under the element's content.\n *\n * Why an overlay, not the element's own outline: an element paints its own\n * outline before its *positioned* descendants, and media usually is one\n * (`Image`'s root is `relative`), so the image covers it. The overlay is\n * positioned and comes last in tree order, so it paints over everything\n * inside. It only exists while focused (every `after:` class is behind the\n * source variant), and the element is made `relative` to anchor it. On the\n * `focus-visible` source the native outline is suppressed in its favour.\n *\n * Same complete-literal rule as `FOCUS_RING`.\n */\nconst FOCUS_OUTLINE: Record<FocusSource, Record<FocusRing, string>> = {\n \"focus-visible\": {\n brand:\n \"relative focus-visible:outline-none focus-visible:after:pointer-events-none focus-visible:after:absolute focus-visible:after:inset-0 focus-visible:after:rounded-[inherit] focus-visible:after:outline-2 focus-visible:after:outline-brand-500\",\n palette:\n \"relative focus-visible:outline-none focus-visible:after:pointer-events-none focus-visible:after:absolute focus-visible:after:inset-0 focus-visible:after:rounded-[inherit] focus-visible:after:outline-2 focus-visible:after:outline-(--c-text)\",\n },\n \"data-focus-visible\": {\n brand:\n \"relative data-focus-visible:after:pointer-events-none data-focus-visible:after:absolute data-focus-visible:after:inset-0 data-focus-visible:after:rounded-[inherit] data-focus-visible:after:outline-2 data-focus-visible:after:outline-brand-500\",\n palette:\n \"relative data-focus-visible:after:pointer-events-none data-focus-visible:after:absolute data-focus-visible:after:inset-0 data-focus-visible:after:rounded-[inherit] data-focus-visible:after:outline-2 data-focus-visible:after:outline-(--c-text)\",\n },\n \"has-focus-visible\": {\n brand:\n \"relative has-focus-visible:after:pointer-events-none has-focus-visible:after:absolute has-focus-visible:after:inset-0 has-focus-visible:after:rounded-[inherit] has-focus-visible:after:outline-2 has-focus-visible:after:outline-brand-500\",\n palette:\n \"relative has-focus-visible:after:pointer-events-none has-focus-visible:after:absolute has-focus-visible:after:inset-0 has-focus-visible:after:rounded-[inherit] has-focus-visible:after:outline-2 has-focus-visible:after:outline-(--c-text)\",\n },\n \"peer-has-focus-visible\": {\n brand:\n \"relative peer-has-focus-visible:after:pointer-events-none peer-has-focus-visible:after:absolute peer-has-focus-visible:after:inset-0 peer-has-focus-visible:after:rounded-[inherit] peer-has-focus-visible:after:outline-2 peer-has-focus-visible:after:outline-brand-500\",\n palette:\n \"relative peer-has-focus-visible:after:pointer-events-none peer-has-focus-visible:after:absolute peer-has-focus-visible:after:inset-0 peer-has-focus-visible:after:rounded-[inherit] peer-has-focus-visible:after:outline-2 peer-has-focus-visible:after:outline-(--c-text)\",\n },\n \"peer-focus-visible\": {\n brand:\n \"relative peer-focus-visible:after:pointer-events-none peer-focus-visible:after:absolute peer-focus-visible:after:inset-0 peer-focus-visible:after:rounded-[inherit] peer-focus-visible:after:outline-2 peer-focus-visible:after:outline-brand-500\",\n palette:\n \"relative peer-focus-visible:after:pointer-events-none peer-focus-visible:after:absolute peer-focus-visible:after:inset-0 peer-focus-visible:after:rounded-[inherit] peer-focus-visible:after:outline-2 peer-focus-visible:after:outline-(--c-text)\",\n },\n}\n\n/**\n * Where the outline sits: 2px clear of the edge (`offset`), or 2px inside it\n * (`inset`, which wins). An outline's offset gap is transparent, so unlike the\n * ring's it needs no page color. Flush (neither) is the outline's default\n * offset, 0, and emits nothing.\n */\nconst OUTLINE_OFFSET: Record<FocusSource, string> = {\n \"focus-visible\": \"focus-visible:after:outline-offset-2\",\n \"data-focus-visible\": \"data-focus-visible:after:outline-offset-2\",\n \"has-focus-visible\": \"has-focus-visible:after:outline-offset-2\",\n \"peer-has-focus-visible\": \"peer-has-focus-visible:after:outline-offset-2\",\n \"peer-focus-visible\": \"peer-focus-visible:after:outline-offset-2\",\n}\n\nconst OUTLINE_INSET: Record<FocusSource, string> = {\n \"focus-visible\": \"focus-visible:after:-outline-offset-2\",\n \"data-focus-visible\": \"data-focus-visible:after:-outline-offset-2\",\n \"has-focus-visible\": \"has-focus-visible:after:-outline-offset-2\",\n \"peer-has-focus-visible\": \"peer-has-focus-visible:after:-outline-offset-2\",\n \"peer-focus-visible\": \"peer-focus-visible:after:-outline-offset-2\",\n}\n\nexport type FocusStylesOptions = {\n /**\n * Where the focused state lives — the CSS pseudo-class (default), Zag's\n * `data-focus-visible` attribute when you're styling a part of an Ark/Zag\n * machine whose real focus target is a visually-hidden input, an ancestor\n * (`has-focus-visible`), a later sibling of a `peer` wrapping it\n * (`peer-has-focus-visible`), or a later sibling of the focused `peer`\n * itself (`peer-focus-visible`).\n */\n source?: FocusSource\n /**\n * Ring color: the kit's fixed `brand-500` (default), or the active palette's\n * `--c-text` for a control nested inside an accented surface.\n */\n ring?: FocusRing\n /**\n * Gap between the element and its ring, painted in the page background. Keep\n * it on (the default) so the ring stays legible against the element's own\n * fill. Turn it off for something flush inside a container — or sitting on\n * any surface that *isn't* the page background, where the gap would punch a\n * mismatched hole and you want to supply your own `ring-offset-*` colors.\n */\n offset?: boolean\n /**\n * Draw the ring *inside* the element's edge instead of around it. For rows\n * stacked flush in a scroller (`TreeSelect`'s tree): an outer ring would be\n * clipped by the scroller's edge and painted under by the next row. Pair it\n * with `offset: false` — an inset gap would sit inside the row, in the page\n * color rather than the surface's.\n */\n inset?: boolean\n /**\n * Draw it as an outline on an overlay instead of a `ring`, so it paints\n * *over* the element's content, positioned media included. For a focusable\n * filled edge to edge by media inside a clipping scroller (a `Carousel`\n * slide), where an outer ring is clipped and an inset ring hides under the\n * image: pair it with `inset: true`. Makes the element `relative`.\n */\n outline?: boolean\n}\n\n/**\n * The kit's keyboard-focus treatment — one source of truth for every focus\n * ring in the library, and the supported way for consumers to put that same\n * ring on their own elements.\n *\n * Reach for it whenever you render something focusable that isn't already a\n * kit component: a custom trigger, a bare `<button>` wrapping a display\n * component, a link styled as something else.\n *\n * ```tsx\n * import { cn, focusStyles } from \"@42/ui-react\"\n *\n * <button type=\"button\" className={cn(focusStyles(), \"rounded-full\")}>…</button>\n * ```\n *\n * Four axes, plus how it's drawn. Width and alpha are deliberately *not* options:\n * the point of a single ring is that a keyboard user never has to re-learn what\n * \"focused\" looks like, so every ring the kit draws is 2px and fully opaque.\n *\n * The ring is `brand-500` by default rather than the `--c-solid` slot the rest\n * of the color system runs on. That's deliberate: focus is an accessibility\n * affordance, not decoration, so it stays the same recognisable shape no matter\n * what `color` the thing it sits on happens to use — a green badge and a red\n * button get the same ring. `ring: \"palette\"` is the exception, for a control\n * nested inside a surface that already carries the palette.\n *\n * `inset: true` moves the ring inside the element's edge, for rows stacked flush\n * in a scroller (`TreeSelect`, `TreeMultiSelect`).\n *\n * `outline: true` draws the same 2px indicator as an outline on an `::after`\n * overlay instead of a ring, so it paints over the element's content: a\n * `Carousel` slide filled by its image, inside a scroller that clips anything\n * outside it.\n *\n * `offset: true` means *the gap is the page background*. An element on any\n * other surface — a tinted table header, a colored chip — passes\n * `offset: false` and supplies its own `ring-offset-*` pair matched to that\n * surface.\n *\n * What stays hand-written, on purpose:\n * - a ring on a **pseudo-element** rather than the element itself (`Schedule`'s\n * resize grip) — it outlines the small visible mark, not the oversized hit\n * box, and has its own shape and offset. (`DataTable`'s column-resize handle\n * did this too, until its mark became a sibling ringed by `peer-focus-visible`.);\n * - the **shell** idiom — accent border plus a soft halo on a wrapper whose\n * focus lives on a descendant (`Input`'s chrome, `SegmentGroup`'s tray);\n * - a bare `focus:outline-none` with no ring at all, on overlay surfaces that\n * receive *programmatic* focus (`Modal`, `Drawer`, `Popover`, `Tooltip`).\n *\n * Note these classes are inert until the element they land on is actually\n * focusable — `:focus-visible` never matches a plain `<span>` or `<div>`. So a\n * display component (`Badge`, `Kbd`, `ThemeIcon`) can carry them unconditionally\n * and only light up once `asChild` renders it onto a real `<button>`/`<a>`.\n */\nexport const focusStyles = ({\n source = \"focus-visible\",\n ring = \"brand\",\n offset = true,\n inset = false,\n outline = false,\n}: FocusStylesOptions = {}): string =>\n outline\n ? cn(\n FOCUS_OUTLINE[source][ring],\n inset ? OUTLINE_INSET[source] : offset && OUTLINE_OFFSET[source],\n )\n : cn(FOCUS_RING[source][ring], offset && FOCUS_OFFSET[source], inset && FOCUS_INSET[source])\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/lib/focus-styles.ts"],"names":[],"mappings":";;;AA0EA,IAAM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;AAAA,EACA,oBAAA,EAAsB;AAAA,IACpB,KAAA,EACE,mPAAA;AAAA,IACF,OAAA,EACE;AAAA;AAEN,CAAA;AAQA,IAAM,cAAA,GAA8C;AAAA,EAClD,eAAA,EAAiB,sCAAA;AAAA,EACjB,oBAAA,EAAsB,2CAAA;AAAA,EACtB,mBAAA,EAAqB,0CAAA;AAAA,EACrB,wBAAA,EAA0B,+CAAA;AAAA,EAC1B,oBAAA,EAAsB;AACxB,CAAA;AAEA,IAAM,aAAA,GAA6C;AAAA,EACjD,eAAA,EAAiB,uCAAA;AAAA,EACjB,oBAAA,EAAsB,4CAAA;AAAA,EACtB,mBAAA,EAAqB,2CAAA;AAAA,EACrB,wBAAA,EAA0B,gDAAA;AAAA,EAC1B,oBAAA,EAAsB;AACxB,CAAA;AAiGO,IAAM,cAAc,CAAC;AAAA,EAC1B,MAAA,GAAS,eAAA;AAAA,EACT,IAAA,GAAO,OAAA;AAAA,EACP,MAAA,GAAS,IAAA;AAAA,EACT,KAAA,GAAQ,KAAA;AAAA,EACR,OAAA,GAAU;AACZ,CAAA,GAAwB,OACtB,OAAA,GACI,EAAA;AAAA,EACE,aAAA,CAAc,MAAM,CAAA,CAAE,IAAI,CAAA;AAAA,EAC1B,QAAQ,aAAA,CAAc,MAAM,CAAA,GAAI,MAAA,IAAU,eAAe,MAAM;AACjE,CAAA,GACA,EAAA,CAAG,UAAA,CAAW,MAAM,CAAA,CAAE,IAAI,CAAA,EAAG,MAAA,IAAU,YAAA,CAAa,MAAM,CAAA,EAAG,KAAA,IAAS,WAAA,CAAY,MAAM,CAAC","file":"chunk-C6NVU4F7.js","sourcesContent":["import { cn } from \"./cn\"\n\n/**\n * Where the focused state lives — which selector the ring hangs off.\n *\n * - `focus-visible` — the CSS pseudo-class, on the element itself. The default,\n * and what you want for any ordinary `<button>`, `<a>` or `tabIndex` element.\n * - `data-focus-visible` — Zag's attribute, mirrored onto every part of a\n * machine-driven control (`Checkbox`, `RadioGroup`, `Switch`,\n * `ChoiceCardGroup`) whose real focus target is a visually-hidden `<input>`.\n * The visible part never receives DOM focus, so `:focus-visible` can never\n * match it.\n * - `has-focus-visible` — on an *ancestor* of the focused element. For a\n * focusable that sits inside a clipping box (a `Gallery` tile's button inside\n * an overlay-captioned `Figure`, which clips to its corners): a ring on the\n * button itself would be cut off, and an inset one would paint under the\n * image. The ring goes on the unclipped wrapper instead; the focused element\n * itself takes `focus-visible:outline-none`.\n * - `peer-has-focus-visible` — on a *later sibling* of a Tailwind `peer` that\n * contains the focused element. For a native control that is invisible by\n * design and stands in for a visible part it can't contain (`Compare`'s\n * transparent range input, inside a clipping wrapper, under its drawn grip):\n * the ring goes on the part the user sees. The focused element is invisible,\n * so its own outline needs no suppressing. The `peer` is a wrapper rather\n * than the control itself so the control can be clipped without clipping\n * the part that rings.\n * - `peer-focus-visible` — on a *later sibling* of a Tailwind `peer` that is\n * itself the focused element. For a scroll region whose own ring would be\n * painted under its content (`Table.Content`'s scroller, under a sticky\n * header's fill; a `FilePreview` PDF, under the embedded viewer): the ring\n * goes on a non-scrolling overlay drawn after it. Unlike\n * `peer-has-focus-visible` it ignores focus *inside* the peer, so a button\n * in a table row doesn't ring the whole table. The focused element takes\n * `focus-visible:outline-none`, as with `has-focus-visible`.\n */\nexport type FocusSource =\n | \"focus-visible\"\n | \"data-focus-visible\"\n | \"has-focus-visible\"\n | \"peer-has-focus-visible\"\n | \"peer-focus-visible\"\n\n/**\n * Which color the ring paints in.\n *\n * - `brand` — a fixed `brand-500`, independent of the element's own `color`.\n * The right answer almost everywhere, and the default.\n * - `palette` — the active palette's `--c-text`. Only for a control that sits\n * *inside* an already-accented surface, where a brand ring would read as a\n * second, unrelated color stacked on the one the surface carries.\n *\n * `--c-text`, not `--c-solid`, and at full opacity — because it is the one\n * slot that flips with the theme (700 light, 300 dark), so it can be dark on\n * a pale surface and pale on a dark one. `--c-solid` is 500 in *both*, which\n * leaves it a mid-tone with nowhere to go against a light background, and no\n * alpha can fix that: opacity only ever composites the ring toward whatever\n * sits behind it. Measured on a Schedule chip, `--c-solid` rings at 2.69:1\n * against the grid and 1.80:1 against the chip's own border; `--c-text` rings\n * at 5.41:1 and 3.62:1, clearing the 3:1 that WCAG 2.2 SC 1.4.11 asks for.\n */\nexport type FocusRing = \"brand\" | \"palette\"\n\n/**\n * The ring itself, per source × color.\n *\n * Every entry is a complete class literal, and nothing here is assembled at\n * runtime. Tailwind v4 scans the *built* JS for whole strings, so a class that\n * only ever exists as `` `${prefix}:ring-2` `` is never generated and the ring\n * silently disappears in consumer builds. `focus-styles.test.ts` enforces it.\n *\n * The `data-focus-visible`, `has-focus-visible` and the two `peer-*` rows carry no `outline-none`:\n * the element they land on is not the one focused, so there is no native\n * outline of its own to suppress.\n */\nconst FOCUS_RING: Record<FocusSource, Record<FocusRing, string>> = {\n \"focus-visible\": {\n brand: \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand-500\",\n palette: \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-(--c-text)\",\n },\n \"data-focus-visible\": {\n brand: \"data-focus-visible:ring-2 data-focus-visible:ring-brand-500\",\n palette: \"data-focus-visible:ring-2 data-focus-visible:ring-(--c-text)\",\n },\n \"has-focus-visible\": {\n brand: \"has-focus-visible:ring-2 has-focus-visible:ring-brand-500\",\n palette: \"has-focus-visible:ring-2 has-focus-visible:ring-(--c-text)\",\n },\n \"peer-has-focus-visible\": {\n brand: \"peer-has-focus-visible:ring-2 peer-has-focus-visible:ring-brand-500\",\n palette: \"peer-has-focus-visible:ring-2 peer-has-focus-visible:ring-(--c-text)\",\n },\n \"peer-focus-visible\": {\n brand: \"peer-focus-visible:ring-2 peer-focus-visible:ring-brand-500\",\n palette: \"peer-focus-visible:ring-2 peer-focus-visible:ring-(--c-text)\",\n },\n}\n\n/**\n * The offset gap, per source. The gap is painted in the *page* background —\n * `brand-50` light, `brand-950` dark — which is what makes it read as a gap\n * rather than as a second colored band. A neutral white / gray gap would show\n * as a thin off-ramp halo against the brand-tinted page.\n */\nconst FOCUS_OFFSET: Record<FocusSource, string> = {\n \"focus-visible\":\n \"focus-visible:ring-offset-2 focus-visible:ring-offset-brand-50 dark:focus-visible:ring-offset-brand-950\",\n \"data-focus-visible\":\n \"data-focus-visible:ring-offset-2 data-focus-visible:ring-offset-brand-50 dark:data-focus-visible:ring-offset-brand-950\",\n \"has-focus-visible\":\n \"has-focus-visible:ring-offset-2 has-focus-visible:ring-offset-brand-50 dark:has-focus-visible:ring-offset-brand-950\",\n \"peer-has-focus-visible\":\n \"peer-has-focus-visible:ring-offset-2 peer-has-focus-visible:ring-offset-brand-50 dark:peer-has-focus-visible:ring-offset-brand-950\",\n \"peer-focus-visible\":\n \"peer-focus-visible:ring-offset-2 peer-focus-visible:ring-offset-brand-50 dark:peer-focus-visible:ring-offset-brand-950\",\n}\n\n/**\n * The inset modifier, per source. Kept as whole literals for the same Tailwind\n * scanning reason as `FOCUS_RING`.\n */\nconst FOCUS_INSET: Record<FocusSource, string> = {\n \"focus-visible\": \"focus-visible:ring-inset\",\n \"data-focus-visible\": \"data-focus-visible:ring-inset\",\n \"has-focus-visible\": \"has-focus-visible:ring-inset\",\n \"peer-has-focus-visible\": \"peer-has-focus-visible:ring-inset\",\n \"peer-focus-visible\": \"peer-focus-visible:ring-inset\",\n}\n\n/**\n * The same indicator drawn as a CSS `outline` on an `::after` overlay that\n * covers the element, per source × color. For a focusable whose ring has\n * nowhere to go: a slide in a carousel's scroller, filled edge to edge by an\n * image. The scroller clips anything outside the slide, and a ring drawn\n * inside it is a box-shadow, painted under the element's content.\n *\n * Why an overlay, not the element's own outline: an element paints its own\n * outline before its *positioned* descendants, and media usually is one\n * (`Image`'s root is `relative`), so the image covers it. The overlay is\n * positioned and comes last in tree order, so it paints over everything\n * inside. It only exists while focused (every `after:` class is behind the\n * source variant), and the element is made `relative` to anchor it. On the\n * `focus-visible` source the native outline is suppressed in its favour.\n *\n * Same complete-literal rule as `FOCUS_RING`.\n */\nconst FOCUS_OUTLINE: Record<FocusSource, Record<FocusRing, string>> = {\n \"focus-visible\": {\n brand:\n \"relative focus-visible:outline-none focus-visible:after:pointer-events-none focus-visible:after:absolute focus-visible:after:inset-0 focus-visible:after:rounded-[inherit] focus-visible:after:outline-2 focus-visible:after:outline-brand-500\",\n palette:\n \"relative focus-visible:outline-none focus-visible:after:pointer-events-none focus-visible:after:absolute focus-visible:after:inset-0 focus-visible:after:rounded-[inherit] focus-visible:after:outline-2 focus-visible:after:outline-(--c-text)\",\n },\n \"data-focus-visible\": {\n brand:\n \"relative data-focus-visible:after:pointer-events-none data-focus-visible:after:absolute data-focus-visible:after:inset-0 data-focus-visible:after:rounded-[inherit] data-focus-visible:after:outline-2 data-focus-visible:after:outline-brand-500\",\n palette:\n \"relative data-focus-visible:after:pointer-events-none data-focus-visible:after:absolute data-focus-visible:after:inset-0 data-focus-visible:after:rounded-[inherit] data-focus-visible:after:outline-2 data-focus-visible:after:outline-(--c-text)\",\n },\n \"has-focus-visible\": {\n brand:\n \"relative has-focus-visible:after:pointer-events-none has-focus-visible:after:absolute has-focus-visible:after:inset-0 has-focus-visible:after:rounded-[inherit] has-focus-visible:after:outline-2 has-focus-visible:after:outline-brand-500\",\n palette:\n \"relative has-focus-visible:after:pointer-events-none has-focus-visible:after:absolute has-focus-visible:after:inset-0 has-focus-visible:after:rounded-[inherit] has-focus-visible:after:outline-2 has-focus-visible:after:outline-(--c-text)\",\n },\n \"peer-has-focus-visible\": {\n brand:\n \"relative peer-has-focus-visible:after:pointer-events-none peer-has-focus-visible:after:absolute peer-has-focus-visible:after:inset-0 peer-has-focus-visible:after:rounded-[inherit] peer-has-focus-visible:after:outline-2 peer-has-focus-visible:after:outline-brand-500\",\n palette:\n \"relative peer-has-focus-visible:after:pointer-events-none peer-has-focus-visible:after:absolute peer-has-focus-visible:after:inset-0 peer-has-focus-visible:after:rounded-[inherit] peer-has-focus-visible:after:outline-2 peer-has-focus-visible:after:outline-(--c-text)\",\n },\n \"peer-focus-visible\": {\n brand:\n \"relative peer-focus-visible:after:pointer-events-none peer-focus-visible:after:absolute peer-focus-visible:after:inset-0 peer-focus-visible:after:rounded-[inherit] peer-focus-visible:after:outline-2 peer-focus-visible:after:outline-brand-500\",\n palette:\n \"relative peer-focus-visible:after:pointer-events-none peer-focus-visible:after:absolute peer-focus-visible:after:inset-0 peer-focus-visible:after:rounded-[inherit] peer-focus-visible:after:outline-2 peer-focus-visible:after:outline-(--c-text)\",\n },\n}\n\n/**\n * Where the outline sits: 2px clear of the edge (`offset`), or 2px inside it\n * (`inset`, which wins). An outline's offset gap is transparent, so unlike the\n * ring's it needs no page color. Flush (neither) is the outline's default\n * offset, 0, and emits nothing.\n */\nconst OUTLINE_OFFSET: Record<FocusSource, string> = {\n \"focus-visible\": \"focus-visible:after:outline-offset-2\",\n \"data-focus-visible\": \"data-focus-visible:after:outline-offset-2\",\n \"has-focus-visible\": \"has-focus-visible:after:outline-offset-2\",\n \"peer-has-focus-visible\": \"peer-has-focus-visible:after:outline-offset-2\",\n \"peer-focus-visible\": \"peer-focus-visible:after:outline-offset-2\",\n}\n\nconst OUTLINE_INSET: Record<FocusSource, string> = {\n \"focus-visible\": \"focus-visible:after:-outline-offset-2\",\n \"data-focus-visible\": \"data-focus-visible:after:-outline-offset-2\",\n \"has-focus-visible\": \"has-focus-visible:after:-outline-offset-2\",\n \"peer-has-focus-visible\": \"peer-has-focus-visible:after:-outline-offset-2\",\n \"peer-focus-visible\": \"peer-focus-visible:after:-outline-offset-2\",\n}\n\nexport type FocusStylesOptions = {\n /**\n * Where the focused state lives — the CSS pseudo-class (default), Zag's\n * `data-focus-visible` attribute when you're styling a part of an Ark/Zag\n * machine whose real focus target is a visually-hidden input, an ancestor\n * (`has-focus-visible`), a later sibling of a `peer` wrapping it\n * (`peer-has-focus-visible`), or a later sibling of the focused `peer`\n * itself (`peer-focus-visible`).\n */\n source?: FocusSource\n /**\n * Ring color: the kit's fixed `brand-500` (default), or the active palette's\n * `--c-text` for a control nested inside an accented surface.\n */\n ring?: FocusRing\n /**\n * Gap between the element and its ring, painted in the page background. Keep\n * it on (the default) so the ring stays legible against the element's own\n * fill. Turn it off for something flush inside a container — or sitting on\n * any surface that *isn't* the page background, where the gap would punch a\n * mismatched hole and you want to supply your own `ring-offset-*` colors.\n */\n offset?: boolean\n /**\n * Draw the ring *inside* the element's edge instead of around it. For rows\n * stacked flush in a scroller (`TreeSelect`'s tree): an outer ring would be\n * clipped by the scroller's edge and painted under by the next row. Pair it\n * with `offset: false` — an inset gap would sit inside the row, in the page\n * color rather than the surface's.\n */\n inset?: boolean\n /**\n * Draw it as an outline on an overlay instead of a `ring`, so it paints\n * *over* the element's content, positioned media included. For a focusable\n * filled edge to edge by media inside a clipping scroller (a `Carousel`\n * slide), where an outer ring is clipped and an inset ring hides under the\n * image: pair it with `inset: true`. Makes the element `relative`.\n */\n outline?: boolean\n}\n\n/**\n * The kit's keyboard-focus treatment — one source of truth for every focus\n * ring in the library, and the supported way for consumers to put that same\n * ring on their own elements.\n *\n * Reach for it whenever you render something focusable that isn't already a\n * kit component: a custom trigger, a bare `<button>` wrapping a display\n * component, a link styled as something else.\n *\n * ```tsx\n * import { cn, focusStyles } from \"@42/ui-react\"\n *\n * <button type=\"button\" className={cn(focusStyles(), \"rounded-full\")}>…</button>\n * ```\n *\n * Four axes, plus how it's drawn. Width and alpha are deliberately *not* options:\n * the point of a single ring is that a keyboard user never has to re-learn what\n * \"focused\" looks like, so every ring the kit draws is 2px and fully opaque.\n *\n * The ring is `brand-500` by default rather than the `--c-solid` slot the rest\n * of the color system runs on. That's deliberate: focus is an accessibility\n * affordance, not decoration, so it stays the same recognisable shape no matter\n * what `color` the thing it sits on happens to use — a green badge and a red\n * button get the same ring. `ring: \"palette\"` is the exception, for a control\n * nested inside a surface that already carries the palette.\n *\n * `inset: true` moves the ring inside the element's edge, for rows stacked flush\n * in a scroller (`TreeSelect`, `TreeMultiSelect`).\n *\n * `outline: true` draws the same 2px indicator as an outline on an `::after`\n * overlay instead of a ring, so it paints over the element's content: a\n * `Carousel` slide filled by its image, inside a scroller that clips anything\n * outside it.\n *\n * `offset: true` means *the gap is the page background*. An element on any\n * other surface — a tinted table header, a colored chip — passes\n * `offset: false` and supplies its own `ring-offset-*` pair matched to that\n * surface.\n *\n * What stays hand-written, on purpose:\n * - a ring on a **pseudo-element** rather than the element itself (`Schedule`'s\n * resize grip) — it outlines the small visible mark, not the oversized hit\n * box, and has its own shape and offset. (`DataTable`'s column-resize handle\n * did this too, until its mark became a sibling ringed by `peer-focus-visible`.);\n * - the **shell** idiom — accent border plus a soft halo on a wrapper whose\n * focus lives on a descendant (`Input`'s chrome, `SegmentGroup`'s tray);\n * - a bare `focus:outline-none` with no ring at all, on overlay surfaces that\n * receive *programmatic* focus (`Modal`, `Drawer`, `Popover`, `Tooltip`).\n *\n * Note these classes are inert until the element they land on is actually\n * focusable — `:focus-visible` never matches a plain `<span>` or `<div>`. So a\n * display component (`Badge`, `Kbd`, `ThemeIcon`) can carry them unconditionally\n * and only light up once `asChild` renders it onto a real `<button>`/`<a>`.\n */\nexport const focusStyles = ({\n source = \"focus-visible\",\n ring = \"brand\",\n offset = true,\n inset = false,\n outline = false,\n}: FocusStylesOptions = {}): string =>\n outline\n ? cn(\n FOCUS_OUTLINE[source][ring],\n inset ? OUTLINE_INSET[source] : offset && OUTLINE_OFFSET[source],\n )\n : cn(FOCUS_RING[source][ring], offset && FOCUS_OFFSET[source], inset && FOCUS_INSET[source])\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { props } from './chunk-WYCMIIRR.js';
|
|
2
2
|
import { TEXT_COLOR_CLASSES } from './chunk-GIPQUKCN.js';
|
|
3
|
-
import { cn } from './chunk-
|
|
3
|
+
import { cn } from './chunk-4ASNIDV7.js';
|
|
4
4
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
5
5
|
|
|
6
6
|
var SPINNER_SIZE = {
|
|
@@ -76,5 +76,5 @@ var Spinner = ({
|
|
|
76
76
|
};
|
|
77
77
|
|
|
78
78
|
export { Spinner };
|
|
79
|
-
//# sourceMappingURL=chunk-
|
|
80
|
-
//# sourceMappingURL=chunk-
|
|
79
|
+
//# sourceMappingURL=chunk-D2QIPQ74.js.map
|
|
80
|
+
//# sourceMappingURL=chunk-D2QIPQ74.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/spinner/spinner.tsx"],"names":[],"mappings":";;;;;AA0CA,IAAM,YAAA,GAAqC;AAAA,EACzC,EAAA,EAAI,QAAA;AAAA,EACJ,EAAA,EAAI,QAAA;AAAA,EACJ,EAAA,EAAI,QAAA;AAAA,EACJ,EAAA,EAAI,QAAA;AAAA,EACJ,EAAA,EAAI;AACN,CAAA;AAgCO,IAAM,UAAU,CAAC;AAAA,EACtB,SAAA;AAAA,EACA,IAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA,GAAQ,SAAA;AAAA,EACR,SAAA,GAAY,KAAA;AAAA,EACZ,MAAA;AAAA,EACA,GAAG;AACL,CAAA,KAAoB;AAClB,EAAA,MAAM,aAAa,KAAA,KAAU,IAAA;AAI7B,EAAA,MAAM,SAAA,GAAY,KAAA,KAAU,MAAA,IAAa,KAAA,KAAU,kBAAkB,KAAA,KAAU,SAAA;AAC/E,EAAA,uBACE,IAAA;AAAA,IAAC,MAAA;AAAA,IAAA;AAAA,MAGE,GAAI,UAAA,GAAa,EAAE,aAAA,EAAe,IAAA,KAAS,EAAE,IAAA,EAAM,QAAA,EAAU,YAAA,EAAc,KAAA,EAAM;AAAA,MAClF,YAAA,EAAY,YAAY,KAAA,GAAQ,MAAA;AAAA,MAChC,SAAA,EAAW,EAAA;AAAA;AAAA;AAAA,QAGT,sFAAA;AAAA,QACA,sDAAA;AAAA,QACA,IAAA,IAAQ,aAAa,IAAI,CAAA;AAAA,QACzB,SAAA,IAAa,kBAAA;AAAA,QACb,KAAA,KAAU,aAAa,kBAAA,CAAmB,OAAA;AAAA,QAC1C;AAAA,OACF;AAAA,MACC,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A,EAAO,cAAA;AAAA,YACP,aAAA,EAAc,OAAA;AAAA,YACd,cAAA,EAAe,OAAA;AAAA,YACf,aAAA,EAAW,IAAA;AAAA,YAGX,SAAA,EAAW,EAAA,CAAG,OAAA,EAAS,IAAA,IAAQ,WAAW,CAAA;AAAA,YAEzC,QAAA,EAAA;AAAA,cAAA,SAAA,oBAAa,GAAA,CAAC,QAAA,EAAA,EAAO,EAAA,EAAG,IAAA,EAAK,EAAA,EAAG,IAAA,EAAK,CAAA,EAAE,IAAA,EAAK,WAAA,EAAa,CAAA,EAAG,SAAA,EAAU,YAAA,EAAa,CAAA;AAAA,8BACpF,GAAA;AAAA,gBAAC,QAAA;AAAA,gBAAA;AAAA,kBACC,EAAA,EAAG,IAAA;AAAA,kBACH,EAAA,EAAG,IAAA;AAAA,kBACH,CAAA,EAAE,IAAA;AAAA,kBACF,WAAA,EAAa,CAAA;AAAA,kBACb,eAAA,EAAgB,OAAA;AAAA,kBAChB,aAAA,EAAc,OAAA;AAAA,kBACd,SAAA,EAAU;AAAA;AAAA;AACZ;AAAA;AAAA,SACF;AAAA,QACC,CAAC,UAAA,oBAAc,GAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,WAAW,QAAA,EAAA,KAAA,EAAM;AAAA;AAAA;AAAA,GACnD;AAEJ","file":"chunk-D2QIPQ74.js","sourcesContent":["import type { ComponentPropsWithoutRef } from \"react\"\nimport { cn } from \"../../lib/cn\"\nimport type { Color } from \"../../lib/colors\"\nimport { props } from \"../../lib/props\"\nimport type { Size } from \"../../lib/sizes\"\nimport type { WithTestId } from \"../../lib/test-id\"\nimport { TEXT_COLOR_CLASSES } from \"../../lib/typography-size\"\n\n/**\n * Spinner — inline activity indicator.\n *\n * Pure React Server Component. The SVG strokes use `currentColor`, so when\n * `color` is omitted the spinner inherits its parent's text color — that's\n * how Button/ActionIcon embed it without extra plumbing. Pass a palette\n * `color` to route through the `data-color` + slot-var system and emit a\n * palette stroke regardless of the surrounding text color.\n *\n * Two non-palette `color` values round out the prop:\n * - `\"currentColor\"` — the explicit, named form of the omit-color behavior\n * (inherit the surrounding text color); handy when a call site wants to\n * state the intent rather than rely on the absence of a prop.\n * - `\"default\"` — the neutral high-contrast stroke that matches Button's\n * `default` variant. Like that variant, it sidesteps the slot vars and\n * paints the primitives behind Figma's `Text/text-primary` (`brand-950` / `white`).\n *\n * Sizing follows the same logic: omit `size` to inherit from a parent's\n * `[&_svg]:size-*` rule (Button does this), or set it explicitly for\n * standalone use.\n *\n * Accessibility: a standalone spinner is a `role=\"status\"` live region holding\n * visually hidden \"Loading\" text (the `label`), so it is announced as a status\n * rather than read as a picture. Inside containers that already broadcast a\n * busy state (`aria-busy=\"true\"` on Button/ActionIcon), pass `label={null}` to\n * make it decorative (`aria-hidden`) and avoid double announcements.\n *\n * The rotation lives on the root, so `className` (e.g. Button's\n * `[animation-play-state:paused]`) reaches the animated element. Under\n * `prefers-reduced-motion` it stops and the arc rests in place, the same rule\n * the kit applies to `Progress`/`CircularProgress`'s indeterminate loops.\n */\n\n/** One size scale for the root; the ring fills it. */\nconst SPINNER_SIZE: Record<Size, string> = {\n xs: \"size-3\",\n sm: \"size-4\",\n md: \"size-5\",\n lg: \"size-6\",\n xl: \"size-8\",\n}\n\nexport type SpinnerSize = Size\n\n/**\n * The spinner's `color` accepts the shared palette plus two non-palette\n * tokens: `\"currentColor\"` (explicit inherit) and `\"default\"` (neutral\n * high-contrast stroke matching Button's `default` variant).\n */\nexport type SpinnerColor = Color | \"currentColor\" | \"default\"\n\nexport type SpinnerProps = Omit<ComponentPropsWithoutRef<\"span\">, \"color\" | \"children\"> &\n WithTestId & {\n /** Explicit size; omit to inherit from a parent's `[&_svg]:size-*` rule. */\n size?: SpinnerSize\n /**\n * Stroke color. Omit (or pass `\"currentColor\"`) to inherit the surrounding\n * text color; pass a palette name to route through the slot vars; pass\n * `\"default\"` for the neutral high-contrast stroke that matches Button's\n * `default` variant.\n */\n color?: SpinnerColor\n /**\n * Status text announced by assistive tech. Defaults to `\"Loading\"`. Set to\n * `null` for a purely decorative spinner (e.g. inside a button that already\n * has `aria-busy`).\n */\n label?: string | null\n /** Draws a faint full ring under the spinning arc, so the arc reads as moving around a track. */\n withTrack?: boolean\n }\n\nexport const Spinner = ({\n className,\n size,\n color,\n label = \"Loading\",\n withTrack = false,\n testId,\n ...rest\n}: SpinnerProps) => {\n const decorative = label === null\n // Only real palette names drive the slot-var system. `\"currentColor\"` and\n // `\"default\"` are handled with literal classes below, so they neither emit a\n // `data-color` nor reach for `--c-solid`.\n const isPalette = color !== undefined && color !== \"currentColor\" && color !== \"default\"\n return (\n <span\n // A status, not a picture: the label is live text, read when the spinner\n // appears. Decorative spinners leave the tree entirely.\n {...(decorative ? { \"aria-hidden\": true } : { role: \"status\", \"aria-label\": label })}\n data-color={isPalette ? color : undefined}\n className={cn(\n // `relative` contains the sr-only label, so it can't escape a scroller.\n // `w-fit`: the root is what spins, so it must hug the ring, never a whole row.\n \"relative flex w-fit shrink-0 items-center justify-center aspect-square origin-center\",\n \"animate-spin motion-reduce:animate-none text-current\",\n size && SPINNER_SIZE[size],\n isPalette && \"text-(--c-solid)\",\n color === \"default\" && TEXT_COLOR_CLASSES.primary,\n className,\n )}\n {...props({ \"data-testid\": testId })}\n {...rest}\n >\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden\n // Sized: fill the root. Unsized: keep the 24px intrinsic size, or a parent's\n // `[&_svg]:size-*` rule (Button's), which the root then hugs.\n className={cn(\"block\", size && \"size-full\")}\n >\n {withTrack && <circle cx=\"12\" cy=\"12\" r=\"10\" strokeWidth={1} className=\"opacity-20\" />}\n <circle\n cx=\"12\"\n cy=\"12\"\n r=\"10\"\n strokeWidth={2}\n strokeDasharray=\"42 20\"\n strokeLinecap=\"round\"\n className=\"opacity-90\"\n />\n </svg>\n {!decorative && <span className=\"sr-only\">{label}</span>}\n </span>\n )\n}\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { OverlayLayerProvider } from './chunk-H7WOMZXO.js';
|
|
2
|
-
import { ActionIcon } from './chunk-
|
|
2
|
+
import { ActionIcon } from './chunk-BE2LWUHY.js';
|
|
3
3
|
import { devWarn } from './chunk-6N6J2DOE.js';
|
|
4
4
|
import { iconStroke, mergeIcons } from './chunk-XXOR34T4.js';
|
|
5
5
|
import { props } from './chunk-WYCMIIRR.js';
|
|
6
|
-
import { cn } from './chunk-
|
|
6
|
+
import { cn } from './chunk-4ASNIDV7.js';
|
|
7
7
|
import { XIcon } from 'lucide-react';
|
|
8
8
|
import { createContext, useRef, useCallback, useContext } from 'react';
|
|
9
9
|
import { jsx } from 'react/jsx-runtime';
|
|
@@ -100,5 +100,5 @@ var useDialogNameCheck = (component) => {
|
|
|
100
100
|
};
|
|
101
101
|
|
|
102
102
|
export { DIALOG_PADDING, DialogRootProviders, createDialogParts, useDialogNameCheck };
|
|
103
|
-
//# sourceMappingURL=chunk-
|
|
104
|
-
//# sourceMappingURL=chunk-
|
|
103
|
+
//# sourceMappingURL=chunk-DA4QII2N.js.map
|
|
104
|
+
//# sourceMappingURL=chunk-DA4QII2N.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/overlays/dialog-parts.tsx"],"names":[],"mappings":";;;;;;;;;;AAqCO,IAAM,cAAA,GAAuC;AAAA,EAClD,EAAA,EAAI,SAAA;AAAA,EACJ,EAAA,EAAI,MAAA;AAAA,EACJ,EAAA,EAAI,SAAA;AAAA,EACJ,EAAA,EAAI,QAAA;AAAA,EACJ,EAAA,EAAI;AACN;AAEA,IAAM,OAAA,GAAU;AAAA,EACd,KAAA,EAAO;AAAA,IACL,MAAA,EACE,sGAAA;AAAA,IACF,IAAA,EAAM,qDAAA;AAAA,IACN,MAAA,EACE,0FAAA;AAAA,IACF,SAAA,EAA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AAC,IAAA,KACzB,CAAC,CAAC,IAAA,CAAK,YAAA,CAAa,YAAY,CAAA,EAAG,IAAA,EAAK,IAAA,CACvC,IAAA,CAAK,YAAA,CAAa,iBAAiB,CAAA,IAAK,EAAA,EACtC,KAAA,CAAM,KAAK,CAAA,CACX,IAAA,CAAK,CAAC,EAAA,KAAO,EAAA,KAAO,EAAA,IAAM,IAAA,CAAK,aAAA,CAAc,cAAA,CAAe,EAAE,MAAM,IAAI,CAAA;AActE,IAAM,kBAAA,GAAqB,CAAC,SAAA,KAAkC;AACnE,EAAA,MAAM,MAAA,GAAS,OAAO,KAAK,CAAA;AAC3B,EAAA,OAAO,WAAA;AAAA,IACL,CAAC,IAAA,KAA6B;AAC5B,MAAA,IAAI,CAAC,IAAA,IAAQ,MAAA,CAAO,OAAA,EAAS;AAG7B,MAAA,qBAAA,CAAsB,MAAM;AAC1B,QAAA,IAAI,OAAO,OAAA,IAAW,CAAC,KAAK,WAAA,IAAe,iBAAA,CAAkB,IAAI,CAAA,EAAG;AACpE,QAAA,MAAA,CAAO,OAAA,GAAU,IAAA;AACjB,QAAA,OAAA;AAAA,UACE,CAAA,CAAA,EAAI,SAAS,CAAA,mHAAA,EACwC,SAAS,CAAA,wEAAA;AAAA,SAEhE;AAAA,MACF,CAAC,CAAA;AAAA,IACH,CAAA;AAAA,IACA,CAAC,SAAS;AAAA,GACZ;AACF","file":"chunk-4EU6FGGB.js","sourcesContent":["\"use client\"\n\nimport type { HTMLArkProps } from \"@ark-ui/react/factory\"\nimport { XIcon } from \"lucide-react\"\nimport {\n type ComponentPropsWithoutRef,\n createContext,\n type JSXElementConstructor,\n type ReactNode,\n useCallback,\n useContext,\n useRef,\n} from \"react\"\nimport { cn } from \"../../lib/cn\"\nimport { devWarn } from \"../../lib/dev-warn\"\nimport { type IconMap, iconStroke, mergeIcons } from \"../../lib/icons\"\nimport { OverlayLayerProvider, type OverlayLayers } from \"../../lib/overlay-layer\"\nimport { props } from \"../../lib/props\"\nimport type { Size } from \"../../lib/sizes\"\nimport type { WithTestId } from \"../../lib/test-id\"\nimport { ActionIcon } from \"../action-icon/action-icon\"\n\n/**\n * Internal parts shared by `Modal` and `Drawer`, which are the same dialog\n * chrome over two Ark machines. Not re-exported from the overlays barrel: the\n * public parts stay `Modal.*` / `Drawer.*`.\n *\n * The two surfaces differ only by their padding variable (`--modal-px` vs\n * `--drawer-px`), the close button's size, and Modal's header floor. Tailwind\n * only generates classes it finds written out in full, so each surface keeps\n * its literal class strings in one lookup instead of interpolating the var.\n */\n\nexport type DialogSurface = \"modal\" | \"drawer\"\n\n/** The `padding` token → the CSS length both surfaces set as their padding\n * variable (`--modal-px` / `--drawer-px`); the vertical rhythm derives from it. */\nexport const DIALOG_PADDING: Record<Size, string> = {\n xs: \"0.75rem\",\n sm: \"1rem\",\n md: \"1.25rem\",\n lg: \"1.5rem\",\n xl: \"2rem\",\n}\n\nconst SURFACE = {\n modal: {\n header:\n \"flex items-start min-h-15 justify-between gap-4 px-(--modal-px,1.25rem) pt-(--modal-px,1.25rem) pb-3\",\n body: \"flex-1 overflow-y-auto px-(--modal-px,1.25rem) py-1\",\n footer:\n \"flex items-center justify-end gap-2 px-(--modal-px,1.25rem) pb-(--modal-px,1.25rem) pt-4\",\n closeSize: \"xs\",\n },\n drawer: {\n header:\n \"flex items-start justify-between gap-4 px-(--drawer-px,1.25rem) pt-(--drawer-px,1.25rem) pb-3\",\n body: \"flex-1 overflow-y-auto px-(--drawer-px,1.25rem) py-1\",\n footer:\n \"flex items-center justify-end gap-2 px-(--drawer-px,1.25rem) pb-(--drawer-px,1.25rem) pt-4\",\n closeSize: \"sm\",\n },\n} as const\n\nexport type DialogIconSlot = \"close\"\nexport type DialogIcons = IconMap<DialogIconSlot>\n\nconst DEFAULT_ICONS: Record<DialogIconSlot, ReactNode> = {\n close: <XIcon className={iconStroke} />,\n}\n\n/** The root's resolved icons, for the close trigger. */\nconst IconsContext = createContext(DEFAULT_ICONS)\n\n/** What both roots wrap their children in: the resolved `icons` and the\n * nested-layer set from `useLayerGuard`, so a picker opened inside the dialog\n * closes on its own outside click without closing the dialog under it. */\nexport const DialogRootProviders = ({\n icons,\n layers,\n children,\n}: {\n icons?: DialogIcons\n layers: OverlayLayers\n children?: ReactNode\n}) => (\n <IconsContext value={mergeIcons(DEFAULT_ICONS, icons)}>\n <OverlayLayerProvider value={layers}>{children}</OverlayLayerProvider>\n </IconsContext>\n)\n\nexport type DialogCloseTriggerProps = HTMLArkProps<\"button\"> &\n WithTestId & {\n \"aria-label\"?: string\n }\n\nexport type DialogSectionProps = ComponentPropsWithoutRef<\"div\"> & WithTestId\n\n/**\n * Builds a surface's close trigger, header, body and footer. `ArkCloseTrigger`\n * is that machine's own `CloseTrigger` (Dialog's or Drawer's), since each\n * reads its own Ark context.\n */\nexport const createDialogParts = (\n surface: DialogSurface,\n ArkCloseTrigger: JSXElementConstructor<HTMLArkProps<\"button\">>,\n) => {\n const styles = SURFACE[surface]\n\n const CloseTrigger = ({\n children,\n className,\n \"aria-label\": ariaLabel,\n testId,\n asChild,\n ...rest\n }: DialogCloseTriggerProps) => {\n const icons = useContext(IconsContext)\n return asChild ? (\n // The consumer's element (a \"Cancel\" button, say) replaces the kit's icon\n // button outright, rather than nesting inside it.\n <ArkCloseTrigger\n asChild\n aria-label={ariaLabel}\n className={className}\n {...props({ \"data-testid\": testId })}\n {...rest}\n >\n {children}\n </ArkCloseTrigger>\n ) : (\n <ArkCloseTrigger asChild {...rest}>\n <ActionIcon\n variant=\"subtle\"\n color=\"neutral\"\n size={styles.closeSize}\n aria-label={ariaLabel ?? \"Close\"}\n className={className}\n testId={testId}\n >\n {children ?? icons.close}\n </ActionIcon>\n </ArkCloseTrigger>\n )\n }\n\n const Header = ({ className, testId, ...rest }: DialogSectionProps) => (\n <div className={cn(styles.header, className)} {...props({ \"data-testid\": testId })} {...rest} />\n )\n\n const Body = ({ className, testId, ...rest }: DialogSectionProps) => (\n <div className={cn(styles.body, className)} {...props({ \"data-testid\": testId })} {...rest} />\n )\n\n const Footer = ({ className, testId, ...rest }: DialogSectionProps) => (\n <div className={cn(styles.footer, className)} {...props({ \"data-testid\": testId })} {...rest} />\n )\n\n return { CloseTrigger, Header, Body, Footer }\n}\n\n/** True when `node` has an `aria-label`, or an `aria-labelledby` naming an\n * element that is actually in the document. */\nconst hasAccessibleName = (node: HTMLElement) =>\n !!node.getAttribute(\"aria-label\")?.trim() ||\n (node.getAttribute(\"aria-labelledby\") ?? \"\")\n .split(/\\s+/)\n .some((id) => id !== \"\" && node.ownerDocument.getElementById(id) !== null)\n\n/**\n * A ref for a dialog's content that warns, in development, when the open\n * dialog has no accessible name: no `title`, no composed `Title` part, no\n * `aria-label` or `aria-labelledby`.\n *\n * It reads the DOM rather than the props because a composed `Modal.Title` /\n * `Drawer.Title` names the dialog without any prop saying so. Ark points the\n * content's `aria-labelledby` at the title's id before it knows whether a\n * title exists, then drops it a frame after opening once it finds none; so\n * the check waits that same frame and asks whether the id resolves, which\n * covers every way of naming the dialog. Warns once per instance.\n */\nexport const useDialogNameCheck = (component: \"Modal\" | \"Drawer\") => {\n const warned = useRef(false)\n return useCallback(\n (node: HTMLElement | null) => {\n if (!node || warned.current) return\n // Ark composes this ref without forwarding a cleanup, so a frame that\n // lands after the content unmounts is caught by `isConnected` instead.\n requestAnimationFrame(() => {\n if (warned.current || !node.isConnected || hasAccessibleName(node)) return\n warned.current = true\n devWarn(\n `[${component}] This dialog has no accessible name, so a screen reader announces ` +\n `it as just \"dialog\". Pass \\`title\\`, render a \\`${component}.Title\\` inside it, ` +\n \"or give it an `aria-label` or `aria-labelledby`.\",\n )\n })\n },\n [component],\n )\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/components/overlays/dialog-parts.tsx"],"names":[],"mappings":";;;;;;;;;;AAqCO,IAAM,cAAA,GAAuC;AAAA,EAClD,EAAA,EAAI,SAAA;AAAA,EACJ,EAAA,EAAI,MAAA;AAAA,EACJ,EAAA,EAAI,SAAA;AAAA,EACJ,EA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AAA,EAAI,GAAG,KAAA,CAAM,EAAE,eAAe,MAAA,EAAQ,CAAA,EAAI,GAAG,IAAA,EAAM,CAAA;AAGhG,EAAA,OAAO,EAAE,YAAA,EAAc,MAAA,EAAQ,IAAA,EAAM,MAAA,EAAO;AAC9C;AAIA,IAAM,iBAAA,GAAoB,CAAC,IAAA,KACzB,CAAC,CAAC,IAAA,CAAK,YAAA,CAAa,YAAY,CAAA,EAAG,IAAA,EAAK,IAAA,CACvC,IAAA,CAAK,YAAA,CAAa,iBAAiB,CAAA,IAAK,EAAA,EACtC,KAAA,CAAM,KAAK,CAAA,CACX,IAAA,CAAK,CAAC,EAAA,KAAO,EAAA,KAAO,EAAA,IAAM,IAAA,CAAK,aAAA,CAAc,cAAA,CAAe,EAAE,MAAM,IAAI,CAAA;AActE,IAAM,kBAAA,GAAqB,CAAC,SAAA,KAAkC;AACnE,EAAA,MAAM,MAAA,GAAS,OAAO,KAAK,CAAA;AAC3B,EAAA,OAAO,WAAA;AAAA,IACL,CAAC,IAAA,KAA6B;AAC5B,MAAA,IAAI,CAAC,IAAA,IAAQ,MAAA,CAAO,OAAA,EAAS;AAG7B,MAAA,qBAAA,CAAsB,MAAM;AAC1B,QAAA,IAAI,OAAO,OAAA,IAAW,CAAC,KAAK,WAAA,IAAe,iBAAA,CAAkB,IAAI,CAAA,EAAG;AACpE,QAAA,MAAA,CAAO,OAAA,GAAU,IAAA;AACjB,QAAA,OAAA;AAAA,UACE,CAAA,CAAA,EAAI,SAAS,CAAA,mHAAA,EACwC,SAAS,CAAA,wEAAA;AAAA,SAEhE;AAAA,MACF,CAAC,CAAA;AAAA,IACH,CAAA;AAAA,IACA,CAAC,SAAS;AAAA,GACZ;AACF","file":"chunk-DA4QII2N.js","sourcesContent":["\"use client\"\n\nimport type { HTMLArkProps } from \"@ark-ui/react/factory\"\nimport { XIcon } from \"lucide-react\"\nimport {\n type ComponentPropsWithoutRef,\n createContext,\n type JSXElementConstructor,\n type ReactNode,\n useCallback,\n useContext,\n useRef,\n} from \"react\"\nimport { cn } from \"../../lib/cn\"\nimport { devWarn } from \"../../lib/dev-warn\"\nimport { type IconMap, iconStroke, mergeIcons } from \"../../lib/icons\"\nimport { OverlayLayerProvider, type OverlayLayers } from \"../../lib/overlay-layer\"\nimport { props } from \"../../lib/props\"\nimport type { Size } from \"../../lib/sizes\"\nimport type { WithTestId } from \"../../lib/test-id\"\nimport { ActionIcon } from \"../action-icon/action-icon\"\n\n/**\n * Internal parts shared by `Modal` and `Drawer`, which are the same dialog\n * chrome over two Ark machines. Not re-exported from the overlays barrel: the\n * public parts stay `Modal.*` / `Drawer.*`.\n *\n * The two surfaces differ only by their padding variable (`--modal-px` vs\n * `--drawer-px`), the close button's size, and Modal's header floor. Tailwind\n * only generates classes it finds written out in full, so each surface keeps\n * its literal class strings in one lookup instead of interpolating the var.\n */\n\nexport type DialogSurface = \"modal\" | \"drawer\"\n\n/** The `padding` token → the CSS length both surfaces set as their padding\n * variable (`--modal-px` / `--drawer-px`); the vertical rhythm derives from it. */\nexport const DIALOG_PADDING: Record<Size, string> = {\n xs: \"0.75rem\",\n sm: \"1rem\",\n md: \"1.25rem\",\n lg: \"1.5rem\",\n xl: \"2rem\",\n}\n\nconst SURFACE = {\n modal: {\n header:\n \"flex items-start min-h-15 justify-between gap-4 px-(--modal-px,1.25rem) pt-(--modal-px,1.25rem) pb-3\",\n body: \"flex-1 overflow-y-auto px-(--modal-px,1.25rem) py-1\",\n footer:\n \"flex items-center justify-end gap-2 px-(--modal-px,1.25rem) pb-(--modal-px,1.25rem) pt-4\",\n closeSize: \"xs\",\n },\n drawer: {\n header:\n \"flex items-start justify-between gap-4 px-(--drawer-px,1.25rem) pt-(--drawer-px,1.25rem) pb-3\",\n body: \"flex-1 overflow-y-auto px-(--drawer-px,1.25rem) py-1\",\n footer:\n \"flex items-center justify-end gap-2 px-(--drawer-px,1.25rem) pb-(--drawer-px,1.25rem) pt-4\",\n closeSize: \"sm\",\n },\n} as const\n\nexport type DialogIconSlot = \"close\"\nexport type DialogIcons = IconMap<DialogIconSlot>\n\nconst DEFAULT_ICONS: Record<DialogIconSlot, ReactNode> = {\n close: <XIcon className={iconStroke} />,\n}\n\n/** The root's resolved icons, for the close trigger. */\nconst IconsContext = createContext(DEFAULT_ICONS)\n\n/** What both roots wrap their children in: the resolved `icons` and the\n * nested-layer set from `useLayerGuard`, so a picker opened inside the dialog\n * closes on its own outside click without closing the dialog under it. */\nexport const DialogRootProviders = ({\n icons,\n layers,\n children,\n}: {\n icons?: DialogIcons\n layers: OverlayLayers\n children?: ReactNode\n}) => (\n <IconsContext value={mergeIcons(DEFAULT_ICONS, icons)}>\n <OverlayLayerProvider value={layers}>{children}</OverlayLayerProvider>\n </IconsContext>\n)\n\nexport type DialogCloseTriggerProps = HTMLArkProps<\"button\"> &\n WithTestId & {\n \"aria-label\"?: string\n }\n\nexport type DialogSectionProps = ComponentPropsWithoutRef<\"div\"> & WithTestId\n\n/**\n * Builds a surface's close trigger, header, body and footer. `ArkCloseTrigger`\n * is that machine's own `CloseTrigger` (Dialog's or Drawer's), since each\n * reads its own Ark context.\n */\nexport const createDialogParts = (\n surface: DialogSurface,\n ArkCloseTrigger: JSXElementConstructor<HTMLArkProps<\"button\">>,\n) => {\n const styles = SURFACE[surface]\n\n const CloseTrigger = ({\n children,\n className,\n \"aria-label\": ariaLabel,\n testId,\n asChild,\n ...rest\n }: DialogCloseTriggerProps) => {\n const icons = useContext(IconsContext)\n return asChild ? (\n // The consumer's element (a \"Cancel\" button, say) replaces the kit's icon\n // button outright, rather than nesting inside it.\n <ArkCloseTrigger\n asChild\n aria-label={ariaLabel}\n className={className}\n {...props({ \"data-testid\": testId })}\n {...rest}\n >\n {children}\n </ArkCloseTrigger>\n ) : (\n <ArkCloseTrigger asChild {...rest}>\n <ActionIcon\n variant=\"subtle\"\n color=\"neutral\"\n size={styles.closeSize}\n aria-label={ariaLabel ?? \"Close\"}\n className={className}\n testId={testId}\n >\n {children ?? icons.close}\n </ActionIcon>\n </ArkCloseTrigger>\n )\n }\n\n const Header = ({ className, testId, ...rest }: DialogSectionProps) => (\n <div className={cn(styles.header, className)} {...props({ \"data-testid\": testId })} {...rest} />\n )\n\n const Body = ({ className, testId, ...rest }: DialogSectionProps) => (\n <div className={cn(styles.body, className)} {...props({ \"data-testid\": testId })} {...rest} />\n )\n\n const Footer = ({ className, testId, ...rest }: DialogSectionProps) => (\n <div className={cn(styles.footer, className)} {...props({ \"data-testid\": testId })} {...rest} />\n )\n\n return { CloseTrigger, Header, Body, Footer }\n}\n\n/** True when `node` has an `aria-label`, or an `aria-labelledby` naming an\n * element that is actually in the document. */\nconst hasAccessibleName = (node: HTMLElement) =>\n !!node.getAttribute(\"aria-label\")?.trim() ||\n (node.getAttribute(\"aria-labelledby\") ?? \"\")\n .split(/\\s+/)\n .some((id) => id !== \"\" && node.ownerDocument.getElementById(id) !== null)\n\n/**\n * A ref for a dialog's content that warns, in development, when the open\n * dialog has no accessible name: no `title`, no composed `Title` part, no\n * `aria-label` or `aria-labelledby`.\n *\n * It reads the DOM rather than the props because a composed `Modal.Title` /\n * `Drawer.Title` names the dialog without any prop saying so. Ark points the\n * content's `aria-labelledby` at the title's id before it knows whether a\n * title exists, then drops it a frame after opening once it finds none; so\n * the check waits that same frame and asks whether the id resolves, which\n * covers every way of naming the dialog. Warns once per instance.\n */\nexport const useDialogNameCheck = (component: \"Modal\" | \"Drawer\") => {\n const warned = useRef(false)\n return useCallback(\n (node: HTMLElement | null) => {\n if (!node || warned.current) return\n // Ark composes this ref without forwarding a cleanup, so a frame that\n // lands after the content unmounts is caught by `isConnected` instead.\n requestAnimationFrame(() => {\n if (warned.current || !node.isConnected || hasAccessibleName(node)) return\n warned.current = true\n devWarn(\n `[${component}] This dialog has no accessible name, so a screen reader announces ` +\n `it as just \"dialog\". Pass \\`title\\`, render a \\`${component}.Title\\` inside it, ` +\n \"or give it an `aria-label` or `aria-labelledby`.\",\n )\n })\n },\n [component],\n )\n}\n"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Button } from './chunk-
|
|
1
|
+
import { Button } from './chunk-SWVUXEBT.js';
|
|
2
2
|
import { saveFile } from './chunk-EIBDLRAR.js';
|
|
3
3
|
import { mergeIcons, iconStroke } from './chunk-XXOR34T4.js';
|
|
4
|
-
import { Spinner } from './chunk-
|
|
4
|
+
import { Spinner } from './chunk-D2QIPQ74.js';
|
|
5
5
|
import { withAsChildContent } from './chunk-R5LYFTHA.js';
|
|
6
6
|
import { props } from './chunk-WYCMIIRR.js';
|
|
7
|
-
import { cn } from './chunk-
|
|
7
|
+
import { cn } from './chunk-4ASNIDV7.js';
|
|
8
8
|
import { ark } from '@ark-ui/react';
|
|
9
9
|
import { Download } from 'lucide-react';
|
|
10
10
|
import { useState, useRef, useEffect } from 'react';
|
|
@@ -136,5 +136,5 @@ var DownloadButton = ({
|
|
|
136
136
|
};
|
|
137
137
|
|
|
138
138
|
export { DOWNLOAD_BUTTON_DEFAULT_TRANSLATIONS, DownloadButton };
|
|
139
|
-
//# sourceMappingURL=chunk-
|
|
140
|
-
//# sourceMappingURL=chunk-
|
|
139
|
+
//# sourceMappingURL=chunk-DJLNGWMM.js.map
|
|
140
|
+
//# sourceMappingURL=chunk-DJLNGWMM.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/download-button/download-button.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAkEO,IAAM,oCAAA,GAA6E;AAAA,EACxF,KAAA,EAAO,UAAA;AAAA,EACP,OAAA,EAAS,0BAAA;AAAA,EACT,OAAO,CAAC,IAAA,KAAU,IAAA,GAAO,CAAA,EAAG,IAAI,CAAA,uBAAA,CAAA,GAA4B;AAC9D;AAIA,IAAM,aAAA,GAA2D;AAAA,EAC/D,QAAA,kBAAU,GAAA,CAAC,QAAA,EAAA,EAAS,SAAA,EAAW,UAAA,EAAY;AAC7C,CAAA;AAuBA,IAAM,YAAA,GACJ,2FAAA;AAGF,IAAM,OAAA,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AAE,OAAA,EAAQ;AAAA;AAAA;AAAA,KAChD;AAAA,oBAEF,GAAA,CAAC,MAAA,EAAA,EAAK,IAAA,EAAK,QAAA,EAAS,SAAA,EAAW,cAAc,YAAA,EAAW,iBAAA,EAAkB,WAAA,EAAU,QAAA,EACjF,QAAA,EAAA,OAAA,EACH;AAAA,GAAA,EACF,CAAA;AAEJ","file":"chunk-LZWA7V62.js","sourcesContent":["\"use client\"\n\nimport { ark } from \"@ark-ui/react\"\nimport { Download } from \"lucide-react\"\nimport { type MouseEvent, type ReactNode, useEffect, useRef, useState } from \"react\"\nimport { withAsChildContent } from \"../../lib/as-child\"\nimport { cn } from \"../../lib/cn\"\nimport { type IconMap, iconStroke, mergeIcons } from \"../../lib/icons\"\nimport { props } from \"../../lib/props\"\nimport { saveFile } from \"../../lib/save-file\"\nimport { Button, type ButtonProps } from \"../button/button\"\nimport { Spinner } from \"../spinner/spinner\"\n\n/**\n * DownloadButton — a button that saves a file: a Blob you already have, a\n * URL, or whatever a function of yours resolves to (an authenticated fetch,\n * a presign call, a generated CSV). The kit makes no request itself.\n *\n * - **While a function's promise is pending** the button is busy: a\n * spinner, `aria-busy`, and re-clicks are ignored, so a double click\n * saves one file. It stays enabled and focused, unlike Button's\n * `loading`, which sets `disabled` and drops keyboard focus.\n * - **On failure**, a polite status region says so (`translations.error`)\n * and `onError` gets the error. Nothing is announced on success: the\n * browser's own download UI is the feedback.\n * - **Unmounting mid-fetch** aborts: the function's `signal` fires and\n * nothing is saved afterwards.\n * - Renders a kit `Button` by default. With `asChild`, only the behaviour\n * goes onto your element (an `ActionIcon` in a row's actions), and its\n * content is swapped for the spinner while busy.\n *\n * Built on `saveFile` (`lib/save-file.ts`) rather than Ark's\n * `DownloadTrigger`: Ark's trigger has no pending state, drops a rejected\n * promise, can't be aborted, and reads a string as the file's *contents*\n * rather than a URL.\n *\n * ```tsx\n * <DownloadButton\n * name=\"transcript.pdf\"\n * data={({ signal }) => api.get(`/transcripts/${id}`, { signal }).then((r) => r.blob())}\n * onError={() => notify.error(\"Couldn't download the transcript\")}\n * />\n * ```\n */\n\n/** What can be saved: a Blob (or File), or a URL. */\nexport type DownloadData = Blob | string\n\n/** Resolves the file on click. `signal` aborts when the button unmounts first. */\nexport type DownloadLoader = (context: {\n signal: AbortSignal\n}) => DownloadData | Promise<DownloadData>\n\n/** What `data` takes: the value itself, or a function that resolves it on click. */\nexport type DownloadSource = DownloadData | DownloadLoader\n\nexport type DownloadButtonTranslations = {\n /** The default label, when there are no `children`. @default \"Download\" */\n label?: string\n /** Added to the button's name while `data` is resolving. @default \"Preparing download…\" */\n loading?: string\n /** What the status region says when the download fails.\n * @default (name) => name ? `${name} couldn't be downloaded` : \"The download failed\" */\n error?: (name: string | undefined) => string\n}\n\nexport const DOWNLOAD_BUTTON_DEFAULT_TRANSLATIONS: Required<DownloadButtonTranslations> = {\n label: \"Download\",\n loading: \"Preparing download…\",\n error: (name) => (name ? `${name} couldn't be downloaded` : \"The download failed\"),\n}\n\nexport type DownloadButtonIconSlot = \"download\"\n\nconst DEFAULT_ICONS: Record<DownloadButtonIconSlot, ReactNode> = {\n download: <Download className={iconStroke} />,\n}\n\nexport type DownloadButtonProps = Omit<\n ButtonProps,\n \"type\" | \"name\" | \"loading\" | \"startSlot\" | \"onError\"\n> & {\n /** The file: a Blob, a URL, or a function resolving one on click (passed an abort `signal`). */\n data: DownloadSource\n /** The file name. Ignored by browsers for a cross-origin URL; see `saveFile`. */\n name?: string\n /** The MIME type, for a Blob without one. */\n type?: string\n /** Fires when `data` rejects or the save throws. */\n onError?: (error: unknown) => void\n /** Fires once the file has been handed to the browser. */\n onDone?: () => void\n translations?: DownloadButtonTranslations\n /** `download`, the leading icon. `null` renders none. Not shown under `asChild`. */\n icons?: IconMap<DownloadButtonIconSlot>\n}\n\n/** Tailwind's `sr-only`, fixed rather than absolute: it is rendered beside the\n * button, outside any box of ours, and a fixed box can't stretch a scroller. */\nconst statusRegion =\n \"fixed size-px -m-px p-0 overflow-hidden whitespace-nowrap border-0 [clip-path:inset(50%)]\"\n\n/** Calls the loader now, inside the click, and treats a synchronous throw as a rejection. */\nconst started = (load: DownloadLoader, signal: AbortSignal): Promise<DownloadData> => {\n try {\n return Promise.resolve(load({ signal }))\n } catch (error) {\n return Promise.reject(error)\n }\n}\n\nexport const DownloadButton = ({\n data,\n name,\n type,\n onError,\n onDone,\n translations,\n icons,\n asChild,\n children,\n testId,\n onClick,\n variant,\n size,\n color,\n endSlot,\n disabled,\n className,\n ...rest\n}: DownloadButtonProps) => {\n const t = { ...DOWNLOAD_BUTTON_DEFAULT_TRANSLATIONS, ...translations }\n const icon = mergeIcons(DEFAULT_ICONS, icons)\n const [busy, setBusy] = useState(false)\n const [failure, setFailure] = useState(\"\")\n // The run in flight, if any: the re-click guard and the unmount abort. A\n // ref, so two clicks in one frame can't both read a stale `busy`.\n const running = useRef<AbortController | null>(null)\n\n useEffect(() => () => running.current?.abort(), [])\n\n const fail = (error: unknown) => {\n setFailure(t.error(name))\n onError?.(error)\n }\n\n // `onDone` sits outside the try, so a throw in the caller's own callback\n // isn't announced as a failed download.\n const save = (value: DownloadData) => {\n try {\n saveFile(value, name, { type })\n } catch (error) {\n return fail(error)\n }\n onDone?.()\n }\n\n const resolve = async (load: DownloadLoader) => {\n const controller = new AbortController()\n running.current = controller\n setBusy(true)\n const outcome = await started(load, controller.signal).then(\n (value) => ({ value }),\n (error: unknown) => ({ error }),\n )\n running.current = null\n // Unmounted meanwhile: nothing to save, and no state left to update.\n if (controller.signal.aborted) return\n setBusy(false)\n if (\"error\" in outcome) fail(outcome.error)\n else save(outcome.value)\n }\n\n // `onClick` runs first, so a caller can `preventDefault()` to stop the save\n // (a confirm step). A value is saved inside the click itself; a function's\n // promise is awaited, and the save follows when it settles.\n const download = (event: MouseEvent<HTMLButtonElement>) => {\n onClick?.(event)\n if (event.defaultPrevented || disabled || running.current) return\n // An `asChild` link would also follow its own href.\n event.preventDefault()\n setFailure(\"\")\n if (typeof data === \"function\") void resolve(data)\n else save(data)\n }\n\n const trigger = {\n \"data-scope\": \"download-button\",\n \"data-part\": \"trigger\",\n onClick: download,\n ...props({\n \"aria-busy\": busy,\n \"data-loading\": busy,\n \"data-testid\": testId,\n \"data-disabled\": disabled,\n }),\n ...rest,\n }\n\n return (\n <>\n {asChild ? (\n // Only behaviour is merged onto the child: Button's styling would\n // fight an ActionIcon's own. While busy the spinner stands in for the\n // child's content (its icon); its name stays the child's own label.\n <ark.button\n asChild\n disabled={disabled}\n {...props({ \"aria-disabled\": disabled })}\n className={className}\n {...trigger}\n >\n {withAsChildContent(children, (own) => (busy ? <Spinner label={t.loading} /> : own))}\n </ark.button>\n ) : (\n <Button\n variant={variant}\n size={size}\n color={color}\n startSlot={busy ? <Spinner label={null} /> : icon.download}\n endSlot={endSlot}\n disabled={disabled}\n // `relative` holds the sr-only loading text inside the button.\n className={cn(\"relative\", className)}\n {...trigger}\n >\n {children ?? t.label}\n {busy && <span className=\"sr-only\">{t.loading}</span>}\n </Button>\n )}\n <span role=\"status\" className={statusRegion} data-scope=\"download-button\" data-part=\"status\">\n {failure}\n </span>\n </>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/components/download-button/download-button.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAkEO,IAAM,oCAAA,GAA6E;AAAA,EACxF,KAAA,EAAO,UAAA;AAAA,EACP,OAAA,EAAS,0BAAA;AAAA,EACT,OAAO,CAAC,IAAA,KAAU,IAAA,GAAO,CAAA,EAAG,IAAI,CAAA,uBAAA,CAAA,GAA4B;AAC9D;AAIA,IAAM,aAAA,GAA2D;AAAA,EAC/D,QAAA,kBAAU,GAAA,CAAC,QAAA,EAAA,EAAS,SAAA,EAAW,UAAA,EAAY;AAC7C,CAAA;AAuBA,IAAM,YAAA,GACJ,2FAAA;AAGF,IAAM,OAAA,GAAU,CAAC,IAAA,EAAsB,MAAA,KAA+C;AACpF,EAAA,IAAI;AACF,IAAA,OAAO,QAAQ,OAAA,CAAQ,IA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,QAAA,EAAS,SAAA,EAAW,cAAc,YAAA,EAAW,iBAAA,EAAkB,WAAA,EAAU,QAAA,EACjF,QAAA,EAAA,OAAA,EACH;AAAA,GAAA,EACF,CAAA;AAEJ","file":"chunk-DJLNGWMM.js","sourcesContent":["\"use client\"\n\nimport { ark } from \"@ark-ui/react\"\nimport { Download } from \"lucide-react\"\nimport { type MouseEvent, type ReactNode, useEffect, useRef, useState } from \"react\"\nimport { withAsChildContent } from \"../../lib/as-child\"\nimport { cn } from \"../../lib/cn\"\nimport { type IconMap, iconStroke, mergeIcons } from \"../../lib/icons\"\nimport { props } from \"../../lib/props\"\nimport { saveFile } from \"../../lib/save-file\"\nimport { Button, type ButtonProps } from \"../button/button\"\nimport { Spinner } from \"../spinner/spinner\"\n\n/**\n * DownloadButton — a button that saves a file: a Blob you already have, a\n * URL, or whatever a function of yours resolves to (an authenticated fetch,\n * a presign call, a generated CSV). The kit makes no request itself.\n *\n * - **While a function's promise is pending** the button is busy: a\n * spinner, `aria-busy`, and re-clicks are ignored, so a double click\n * saves one file. It stays enabled and focused, unlike Button's\n * `loading`, which sets `disabled` and drops keyboard focus.\n * - **On failure**, a polite status region says so (`translations.error`)\n * and `onError` gets the error. Nothing is announced on success: the\n * browser's own download UI is the feedback.\n * - **Unmounting mid-fetch** aborts: the function's `signal` fires and\n * nothing is saved afterwards.\n * - Renders a kit `Button` by default. With `asChild`, only the behaviour\n * goes onto your element (an `ActionIcon` in a row's actions), and its\n * content is swapped for the spinner while busy.\n *\n * Built on `saveFile` (`lib/save-file.ts`) rather than Ark's\n * `DownloadTrigger`: Ark's trigger has no pending state, drops a rejected\n * promise, can't be aborted, and reads a string as the file's *contents*\n * rather than a URL.\n *\n * ```tsx\n * <DownloadButton\n * name=\"transcript.pdf\"\n * data={({ signal }) => api.get(`/transcripts/${id}`, { signal }).then((r) => r.blob())}\n * onError={() => notify.error(\"Couldn't download the transcript\")}\n * />\n * ```\n */\n\n/** What can be saved: a Blob (or File), or a URL. */\nexport type DownloadData = Blob | string\n\n/** Resolves the file on click. `signal` aborts when the button unmounts first. */\nexport type DownloadLoader = (context: {\n signal: AbortSignal\n}) => DownloadData | Promise<DownloadData>\n\n/** What `data` takes: the value itself, or a function that resolves it on click. */\nexport type DownloadSource = DownloadData | DownloadLoader\n\nexport type DownloadButtonTranslations = {\n /** The default label, when there are no `children`. @default \"Download\" */\n label?: string\n /** Added to the button's name while `data` is resolving. @default \"Preparing download…\" */\n loading?: string\n /** What the status region says when the download fails.\n * @default (name) => name ? `${name} couldn't be downloaded` : \"The download failed\" */\n error?: (name: string | undefined) => string\n}\n\nexport const DOWNLOAD_BUTTON_DEFAULT_TRANSLATIONS: Required<DownloadButtonTranslations> = {\n label: \"Download\",\n loading: \"Preparing download…\",\n error: (name) => (name ? `${name} couldn't be downloaded` : \"The download failed\"),\n}\n\nexport type DownloadButtonIconSlot = \"download\"\n\nconst DEFAULT_ICONS: Record<DownloadButtonIconSlot, ReactNode> = {\n download: <Download className={iconStroke} />,\n}\n\nexport type DownloadButtonProps = Omit<\n ButtonProps,\n \"type\" | \"name\" | \"loading\" | \"startSlot\" | \"onError\"\n> & {\n /** The file: a Blob, a URL, or a function resolving one on click (passed an abort `signal`). */\n data: DownloadSource\n /** The file name. Ignored by browsers for a cross-origin URL; see `saveFile`. */\n name?: string\n /** The MIME type, for a Blob without one. */\n type?: string\n /** Fires when `data` rejects or the save throws. */\n onError?: (error: unknown) => void\n /** Fires once the file has been handed to the browser. */\n onDone?: () => void\n translations?: DownloadButtonTranslations\n /** `download`, the leading icon. `null` renders none. Not shown under `asChild`. */\n icons?: IconMap<DownloadButtonIconSlot>\n}\n\n/** Tailwind's `sr-only`, fixed rather than absolute: it is rendered beside the\n * button, outside any box of ours, and a fixed box can't stretch a scroller. */\nconst statusRegion =\n \"fixed size-px -m-px p-0 overflow-hidden whitespace-nowrap border-0 [clip-path:inset(50%)]\"\n\n/** Calls the loader now, inside the click, and treats a synchronous throw as a rejection. */\nconst started = (load: DownloadLoader, signal: AbortSignal): Promise<DownloadData> => {\n try {\n return Promise.resolve(load({ signal }))\n } catch (error) {\n return Promise.reject(error)\n }\n}\n\nexport const DownloadButton = ({\n data,\n name,\n type,\n onError,\n onDone,\n translations,\n icons,\n asChild,\n children,\n testId,\n onClick,\n variant,\n size,\n color,\n endSlot,\n disabled,\n className,\n ...rest\n}: DownloadButtonProps) => {\n const t = { ...DOWNLOAD_BUTTON_DEFAULT_TRANSLATIONS, ...translations }\n const icon = mergeIcons(DEFAULT_ICONS, icons)\n const [busy, setBusy] = useState(false)\n const [failure, setFailure] = useState(\"\")\n // The run in flight, if any: the re-click guard and the unmount abort. A\n // ref, so two clicks in one frame can't both read a stale `busy`.\n const running = useRef<AbortController | null>(null)\n\n useEffect(() => () => running.current?.abort(), [])\n\n const fail = (error: unknown) => {\n setFailure(t.error(name))\n onError?.(error)\n }\n\n // `onDone` sits outside the try, so a throw in the caller's own callback\n // isn't announced as a failed download.\n const save = (value: DownloadData) => {\n try {\n saveFile(value, name, { type })\n } catch (error) {\n return fail(error)\n }\n onDone?.()\n }\n\n const resolve = async (load: DownloadLoader) => {\n const controller = new AbortController()\n running.current = controller\n setBusy(true)\n const outcome = await started(load, controller.signal).then(\n (value) => ({ value }),\n (error: unknown) => ({ error }),\n )\n running.current = null\n // Unmounted meanwhile: nothing to save, and no state left to update.\n if (controller.signal.aborted) return\n setBusy(false)\n if (\"error\" in outcome) fail(outcome.error)\n else save(outcome.value)\n }\n\n // `onClick` runs first, so a caller can `preventDefault()` to stop the save\n // (a confirm step). A value is saved inside the click itself; a function's\n // promise is awaited, and the save follows when it settles.\n const download = (event: MouseEvent<HTMLButtonElement>) => {\n onClick?.(event)\n if (event.defaultPrevented || disabled || running.current) return\n // An `asChild` link would also follow its own href.\n event.preventDefault()\n setFailure(\"\")\n if (typeof data === \"function\") void resolve(data)\n else save(data)\n }\n\n const trigger = {\n \"data-scope\": \"download-button\",\n \"data-part\": \"trigger\",\n onClick: download,\n ...props({\n \"aria-busy\": busy,\n \"data-loading\": busy,\n \"data-testid\": testId,\n \"data-disabled\": disabled,\n }),\n ...rest,\n }\n\n return (\n <>\n {asChild ? (\n // Only behaviour is merged onto the child: Button's styling would\n // fight an ActionIcon's own. While busy the spinner stands in for the\n // child's content (its icon); its name stays the child's own label.\n <ark.button\n asChild\n disabled={disabled}\n {...props({ \"aria-disabled\": disabled })}\n className={className}\n {...trigger}\n >\n {withAsChildContent(children, (own) => (busy ? <Spinner label={t.loading} /> : own))}\n </ark.button>\n ) : (\n <Button\n variant={variant}\n size={size}\n color={color}\n startSlot={busy ? <Spinner label={null} /> : icon.download}\n endSlot={endSlot}\n disabled={disabled}\n // `relative` holds the sr-only loading text inside the button.\n className={cn(\"relative\", className)}\n {...trigger}\n >\n {children ?? t.label}\n {busy && <span className=\"sr-only\">{t.loading}</span>}\n </Button>\n )}\n <span role=\"status\" className={statusRegion} data-scope=\"download-button\" data-part=\"status\">\n {failure}\n </span>\n </>\n )\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useApplePlatform, hotkeyCaps } from './chunk-FUNTJZX7.js';
|
|
2
2
|
import { composeChildren } from './chunk-R5LYFTHA.js';
|
|
3
3
|
import { props } from './chunk-WYCMIIRR.js';
|
|
4
|
-
import { focusStyles } from './chunk-
|
|
5
|
-
import { cn } from './chunk-
|
|
4
|
+
import { focusStyles } from './chunk-C6NVU4F7.js';
|
|
5
|
+
import { cn } from './chunk-4ASNIDV7.js';
|
|
6
6
|
import { ark } from '@ark-ui/react';
|
|
7
7
|
import { cva } from 'class-variance-authority';
|
|
8
8
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
@@ -144,5 +144,5 @@ var Kbd = (allProps) => {
|
|
|
144
144
|
};
|
|
145
145
|
|
|
146
146
|
export { Kbd };
|
|
147
|
-
//# sourceMappingURL=chunk-
|
|
148
|
-
//# sourceMappingURL=chunk-
|
|
147
|
+
//# sourceMappingURL=chunk-DT6LKNZF.js.map
|
|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GAChD;AAEJ,CAAA;AAEO,IAAM,GAAA,GAAM,CAAC,QAAA,KAAuB;AACzC,EAAA,IAAI,SAAS,MAAA,KAAW,MAAA,yBAAkB,GAAA,CAAC,QAAA,EAAA,EAAU,GAAG,QAAA,EAAU,CAAA;AAClE,EAAA,MAAM;AAAA,IACJ,SAAA;AAAA,IACA,OAAA;AAAA,IACA,IAAA;AAAA,IACA,KAAA;AAAA,IACA,MAAA;AAAA,IACA,MAAA,EAAQ,OAAA;AAAA,IACR,YAAA,EAAc,aAAA;AAAA,IACd,GAAG;AAAA,GACL,GAAI,QAAA;AACJ,EAAA,uBACE,GAAA;AAAA,IAAC,GAAA,CAAI,GAAA;AAAA,IAAJ;AAAA,MACC,YAAA,EAAY,KAAA;AAAA,MACX,GAAG,KAAA,CAAM,EAAE,aAAA,EAAe,QAAQ,CAAA;AAAA,MAClC,GAAG,IAAA;AAAA,MACJ,SAAA,EAAW,GAAG,WAAA,CAAY,EAAE,SAAS,IAAA,EAAM,GAAG,SAAS;AAAA;AAAA,GACzD;AAEJ","file":"chunk-HEQ2H6VO.js","sourcesContent":["\"use client\"\n\nimport { ark, type HTMLArkProps } from \"@ark-ui/react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport type { ReactElement } from \"react\"\nimport { composeChildren } from \"../../lib/as-child\"\nimport { cn } from \"../../lib/cn\"\nimport type { Color } from \"../../lib/colors\"\nimport { focusStyles } from \"../../lib/focus-styles\"\nimport { props } from \"../../lib/props\"\nimport type { WithTestId } from \"../../lib/test-id\"\nimport { hotkeyCaps, type KbdTranslations, useApplePlatform } from \"../../lib/use-hotkey\"\n\n/**\n * Kbd — a keyboard-key / shortcut indicator (`<kbd>`).\n *\n * A client component only for `hotkey`, whose keys depend on the platform\n * (`[⌘] [K]` vs `[Ctrl] [K]`). It borrows Button's (variant × color) system so\n * a shortcut hint speaks the same accent language as the action it labels — but\n * unlike Button it is non-interactive: no hover treatment, no click handling,\n * just a key cap.\n *\n * The shape axis is the exact set Button exposes (filled / light / outline /\n * subtle / default), wired through the same `--c-*` slot vars — `color` routes\n * via a `data-color` attribute resolved in `colors.css`, so the cva matrix\n * enumerates variants only, never (variant × color) pairs. The default\n * treatment is the `default` variant: a neutral, bordered key-cap surface that\n * reads as a physical key regardless of `color` (pairing `default` with a color\n * is a no-op, mirroring Button/Badge).\n *\n * Sizing keeps single-character keys square via a per-size `min-w` equal to the\n * height, while wider labels (`Enter`, `Esc`, `⌘N`) grow horizontally. Padding\n * is symmetric, so a key reads the same in RTL.\n *\n * `asChild` (from `HTMLArkProps`) renders the single child as the root with\n * Kbd's styling merged in — e.g. `<Kbd asChild><a href=\"…\">⌘K</a></Kbd>`. The\n * kit's focus ring (`focusStyles`) comes along with it, so a Kbd composed onto\n * a real control is keyboard-visible without the caller restyling anything; on\n * a plain `<kbd>` those classes never match.\n *\n * `hotkey` draws a key combination the way the HTML spec marks one up: an\n * outer `<kbd>` for the whole combination holding one inner `<kbd>` per key,\n * with no `+` between them. The outer one is an unstyled inline-flex row;\n * each key is a full cap (`variant` / `size` / `color` apply to every cap),\n * so `\"mod+k\"` is two square caps. The rest of the props (`className`,\n * `testId`, `asChild`, `aria-*`, …) land on the outer `<kbd>`, which is the\n * element a layout positions; `color` is set there too and every cap reads\n * its slot vars from it. The words the caps show and speak (\"Ctrl\", \"Esc\",\n * \"Command\", \"Up Arrow\") are English unless `translations` replaces them, per\n * key (`KbdTranslations`); `formatHotkey` takes the same object.\n */\nconst kbdVariants = cva(\n [\n \"inline-flex items-center justify-center gap-1\",\n \"whitespace-nowrap select-none\",\n // Regular weight, not medium: the mono face (Kode Mono) has no ⌘ ⇧ ⌥ ↵\n // glyphs, so they fall back to a system font — and a 500 weight makes that\n // fallback resolve to its *bold* face (Menlo Bold), a heavy blot next to\n // the regular letters around it.\n \"font-mono font-normal leading-none\",\n \"rounded-md border border-transparent\",\n \"[&_svg]:shrink-0 [&_svg]:pointer-events-none\",\n // A 1.5px stroke at every size: the icon is sized by CSS, so a stroke in\n // viewBox units would thin out at `size-3`. `non-scaling-stroke` keeps it in\n // screen pixels (lucide's `absoluteStrokeWidth` ignores CSS sizing).\n \"[&_svg]:stroke-[1.5] [&_svg_*]:[vector-effect:non-scaling-stroke]\",\n // A lone icon is narrower than the cap is tall, but the side padding\n // would push it past `min-w`: drop the padding so the cap stays square.\n \"has-[>svg:only-child]:px-0\",\n // Inert on the default non-focusable <kbd>; applies once `asChild`\n // renders Kbd onto a real <button>/<a>. See `focusStyles`.\n focusStyles(),\n ],\n {\n variants: {\n variant: {\n filled: \"bg-(--c-solid) text-(--c-on-solid)\",\n light: \"bg-(--c-soft) text-(--c-text)\",\n outline: \"bg-transparent text-(--c-text) border-(--c-solid)\",\n subtle: \"bg-transparent text-(--c-text)\",\n // The key cap sits on the kit's translucent surface recipe — a 3%/4%\n // overlay plus the hairline `border-brand-900/20 dark:border-white/15`,\n // the same pair `Input`'s default shell, `Card`, `Tabs` and\n // `ChoiceCardGroup` use. An opaque gray step can only ever be right on\n // the one background it was picked against, and a `Kbd` is most often\n // inlined into a Button, a Menu row or a tinted panel. Light mode\n // darkens (`bg-black/3`) because `bg-white/4` on a near-white page is\n // invisible; dark mode lightens. A 1px inset shade along the bottom\n // edge is the key-cap depth cue — the lip of a physical key — without\n // adding height. The label is the kit's secondary text, not full\n // contrast: a shortcut hint annotates the action, it is not the action.\n default: [\n \"bg-black/3 text-brand-900/70 border-brand-900/20\",\n \"shadow-[inset_0_-1px_0_0_rgb(0_0_0/0.08)]\",\n \"dark:bg-white/4 dark:text-white/80 dark:border-white/15\",\n \"dark:shadow-[inset_0_-1px_0_0_rgb(0_0_0/0.35)]\",\n ],\n },\n // Type is one Tailwind step per size (12 / 14 / 16px), the scale of\n // the text a key sits beside — a 10px label left ⌘ and ↵ unreadable.\n //\n // A single character must fit `min-w` (= height) to stay square. Kode\n // Mono advances 0.6em per glyph, so glyph + 2 × padding + 2 × 1px border:\n // sm: 7.2 + 2 × 5 + 2 = 19.2 ≤ 20 (px-1.5 gave 21.2: one px too wide)\n // md: 8.4 + 2 × 6 + 2 = 22.4 ≤ 24\n // lg: 9.6 + 2 × 8 + 2 = 27.6 ≤ 28\n // Re-check these sums after a font, type step or padding change.\n size: {\n sm: \"h-5 min-w-5 px-1.25 text-xs [&_svg]:size-3\",\n md: \"h-6 min-w-6 px-1.5 text-sm [&_svg]:size-3.5\",\n lg: \"h-7 min-w-7 px-2 text-base [&_svg]:size-4\",\n },\n },\n defaultVariants: {\n variant: \"default\",\n size: \"md\",\n },\n },\n)\n\nexport type KbdVariant = NonNullable<VariantProps<typeof kbdVariants>[\"variant\"]>\nexport type KbdSize = NonNullable<VariantProps<typeof kbdVariants>[\"size\"]>\n\n/** The outer `<kbd>` of a `hotkey` combination: a row of caps, unstyled itself.\n * `align-middle` sits it on the text it annotates the way a lone cap does. */\nconst kbdGroup = \"inline-flex items-center gap-0.5 align-middle\"\n\n/** With `hotkey`: the key words, merged per key onto `KBD_DEFAULT_TRANSLATIONS`. */\ntype KbdHotkeyTranslations = {\n /** The words the caps read as and are spoken by, merged per key onto the English\n * `KBD_DEFAULT_TRANSLATIONS`: `{ ctrl: \"Strg\", enter: \"Eingabe\" }`. Pass the same\n * object to `formatHotkey` / `hotkeyKeys` so plain text reads the same. */\n translations?: Partial<KbdTranslations>\n}\n\ntype KbdHotkeyProps =\n | { hotkey?: undefined; translations?: undefined }\n | (KbdHotkeyTranslations & {\n /** A `useHotkey` string to draw, one cap per key, the way the visitor's\n * platform writes it: `\"mod+k\"` is `[⌘] [K]` on Apple platforms and\n * `[Ctrl] [K]` elsewhere (see `hotkeyKeys`). A key with an icon (Shift,\n * Enter, Tab, the arrows, and ⌘ ⌥ ⌃ ⌫ on Apple) is drawn as one, with a\n * spoken name; Ctrl, Alt, Esc, Space (and Backspace off Apple) stay\n * words. Server-rendered as the non-Apple caps, then corrected on\n * hydration. The caps are the content, so it takes no children. */\n hotkey: string\n asChild?: false\n children?: never\n })\n | (KbdHotkeyTranslations & {\n hotkey: string\n /** With `hotkey`: the single child becomes the outer `<kbd>` of the\n * combination, the caps rendered inside it. */\n asChild: true\n children: ReactElement\n })\n\nexport type KbdProps = HTMLArkProps<\"kbd\"> &\n VariantProps<typeof kbdVariants> &\n WithTestId & {\n /** Accent palette. Re-exported as `Color` from `@42/ui-react`. */\n color?: Color\n } & KbdHotkeyProps\n\ntype KbdComboProps = KbdProps & { hotkey: string }\n\n/** `<Kbd hotkey>`: the combination's outer `<kbd>`, one cap per key inside. */\nconst KbdCombo = ({\n className,\n variant,\n size,\n color,\n testId,\n hotkey,\n translations,\n asChild,\n children,\n ...rest\n}: KbdComboProps) => {\n const apple = useApplePlatform()\n const caps = hotkeyCaps(hotkey, apple, translations).map(({ id, label, icon: Icon, name }) => (\n // A symbol is drawn (an icon, or the glyph where there is none) and its\n // name spoken: an svg says nothing, and `⌘` alone reads inconsistently.\n // `relative` holds the absolutely positioned `sr-only` inside the cap.\n // An icon cap drops its side padding to stay square, as a lone icon does\n // (the `sr-only` name beside the svg keeps `:only-child` from matching).\n <kbd\n key={id}\n className={cn(kbdVariants({ variant, size }), name && \"relative\", Icon && \"px-0\")}\n >\n {name ? (\n <>\n {Icon ? <Icon aria-hidden /> : <span aria-hidden>{label}</span>}\n <span className=\"sr-only\">{name}</span>\n </>\n ) : (\n label\n )}\n </kbd>\n ))\n return (\n <ark.kbd\n // A combination reads left to right in either direction, like the\n // single string it replaces.\n dir=\"ltr\"\n data-color={color}\n {...props({ \"data-testid\": testId })}\n {...rest}\n asChild={asChild}\n className={cn(kbdGroup, className)}\n >\n {composeChildren(asChild, children, () => caps)}\n </ark.kbd>\n )\n}\n\nexport const Kbd = (allProps: KbdProps) => {\n if (allProps.hotkey !== undefined) return <KbdCombo {...allProps} />\n const {\n className,\n variant,\n size,\n color,\n testId,\n hotkey: _hotkey,\n translations: _translations,\n ...rest\n } = allProps\n return (\n <ark.kbd\n data-color={color}\n {...props({ \"data-testid\": testId })}\n {...rest}\n className={cn(kbdVariants({ variant, size }), className)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AAC,QAAA,KAAuB;AACzC,EAAA,IAAI,SAAS,MAAA,KAAW,MAAA,yBAAkB,GAAA,CAAC,QAAA,EAAA,EAAU,GAAG,QAAA,EAAU,CAAA;AAClE,EAAA,MAAM;AAAA,IACJ,SAAA;AAAA,IACA,OAAA;AAAA,IACA,IAAA;AAAA,IACA,KAAA;AAAA,IACA,MAAA;AAAA,IACA,MAAA,EAAQ,OAAA;AAAA,IACR,YAAA,EAAc,aAAA;AAAA,IACd,GAAG;AAAA,GACL,GAAI,QAAA;AACJ,EAAA,uBACE,GAAA;AAAA,IAAC,GAAA,CAAI,GAAA;AAAA,IAAJ;AAAA,MACC,YAAA,EAAY,KAAA;AAAA,MACX,GAAG,KAAA,CAAM,EAAE,aAAA,EAAe,QAAQ,CAAA;AAAA,MAClC,GAAG,IAAA;AAAA,MACJ,SAAA,EAAW,GAAG,WAAA,CAAY,EAAE,SAAS,IAAA,EAAM,GAAG,SAAS;AAAA;AAAA,GACzD;AAEJ","file":"chunk-DT6LKNZF.js","sourcesContent":["\"use client\"\n\nimport { ark, type HTMLArkProps } from \"@ark-ui/react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport type { ReactElement } from \"react\"\nimport { composeChildren } from \"../../lib/as-child\"\nimport { cn } from \"../../lib/cn\"\nimport type { Color } from \"../../lib/colors\"\nimport { focusStyles } from \"../../lib/focus-styles\"\nimport { props } from \"../../lib/props\"\nimport type { WithTestId } from \"../../lib/test-id\"\nimport { hotkeyCaps, type KbdTranslations, useApplePlatform } from \"../../lib/use-hotkey\"\n\n/**\n * Kbd — a keyboard-key / shortcut indicator (`<kbd>`).\n *\n * A client component only for `hotkey`, whose keys depend on the platform\n * (`[⌘] [K]` vs `[Ctrl] [K]`). It borrows Button's (variant × color) system so\n * a shortcut hint speaks the same accent language as the action it labels — but\n * unlike Button it is non-interactive: no hover treatment, no click handling,\n * just a key cap.\n *\n * The shape axis is the exact set Button exposes (filled / light / outline /\n * subtle / default), wired through the same `--c-*` slot vars — `color` routes\n * via a `data-color` attribute resolved in `colors.css`, so the cva matrix\n * enumerates variants only, never (variant × color) pairs. The default\n * treatment is the `default` variant: a neutral, bordered key-cap surface that\n * reads as a physical key regardless of `color` (pairing `default` with a color\n * is a no-op, mirroring Button/Badge).\n *\n * Sizing keeps single-character keys square via a per-size `min-w` equal to the\n * height, while wider labels (`Enter`, `Esc`, `⌘N`) grow horizontally. Padding\n * is symmetric, so a key reads the same in RTL.\n *\n * `asChild` (from `HTMLArkProps`) renders the single child as the root with\n * Kbd's styling merged in — e.g. `<Kbd asChild><a href=\"…\">⌘K</a></Kbd>`. The\n * kit's focus ring (`focusStyles`) comes along with it, so a Kbd composed onto\n * a real control is keyboard-visible without the caller restyling anything; on\n * a plain `<kbd>` those classes never match.\n *\n * `hotkey` draws a key combination the way the HTML spec marks one up: an\n * outer `<kbd>` for the whole combination holding one inner `<kbd>` per key,\n * with no `+` between them. The outer one is an unstyled inline-flex row;\n * each key is a full cap (`variant` / `size` / `color` apply to every cap),\n * so `\"mod+k\"` is two square caps. The rest of the props (`className`,\n * `testId`, `asChild`, `aria-*`, …) land on the outer `<kbd>`, which is the\n * element a layout positions; `color` is set there too and every cap reads\n * its slot vars from it. The words the caps show and speak (\"Ctrl\", \"Esc\",\n * \"Command\", \"Up Arrow\") are English unless `translations` replaces them, per\n * key (`KbdTranslations`); `formatHotkey` takes the same object.\n */\nconst kbdVariants = cva(\n [\n \"inline-flex items-center justify-center gap-1\",\n \"whitespace-nowrap select-none\",\n // Regular weight, not medium: the mono face (Kode Mono) has no ⌘ ⇧ ⌥ ↵\n // glyphs, so they fall back to a system font — and a 500 weight makes that\n // fallback resolve to its *bold* face (Menlo Bold), a heavy blot next to\n // the regular letters around it.\n \"font-mono font-normal leading-none\",\n \"rounded-md border border-transparent\",\n \"[&_svg]:shrink-0 [&_svg]:pointer-events-none\",\n // A 1.5px stroke at every size: the icon is sized by CSS, so a stroke in\n // viewBox units would thin out at `size-3`. `non-scaling-stroke` keeps it in\n // screen pixels (lucide's `absoluteStrokeWidth` ignores CSS sizing).\n \"[&_svg]:stroke-[1.5] [&_svg_*]:[vector-effect:non-scaling-stroke]\",\n // A lone icon is narrower than the cap is tall, but the side padding\n // would push it past `min-w`: drop the padding so the cap stays square.\n \"has-[>svg:only-child]:px-0\",\n // Inert on the default non-focusable <kbd>; applies once `asChild`\n // renders Kbd onto a real <button>/<a>. See `focusStyles`.\n focusStyles(),\n ],\n {\n variants: {\n variant: {\n filled: \"bg-(--c-solid) text-(--c-on-solid)\",\n light: \"bg-(--c-soft) text-(--c-text)\",\n outline: \"bg-transparent text-(--c-text) border-(--c-solid)\",\n subtle: \"bg-transparent text-(--c-text)\",\n // The key cap sits on the kit's translucent surface recipe — a 3%/4%\n // overlay plus the hairline `border-brand-900/20 dark:border-white/15`,\n // the same pair `Input`'s default shell, `Card`, `Tabs` and\n // `ChoiceCardGroup` use. An opaque gray step can only ever be right on\n // the one background it was picked against, and a `Kbd` is most often\n // inlined into a Button, a Menu row or a tinted panel. Light mode\n // darkens (`bg-black/3`) because `bg-white/4` on a near-white page is\n // invisible; dark mode lightens. A 1px inset shade along the bottom\n // edge is the key-cap depth cue — the lip of a physical key — without\n // adding height. The label is the kit's secondary text, not full\n // contrast: a shortcut hint annotates the action, it is not the action.\n default: [\n \"bg-black/3 text-brand-900/70 border-brand-900/20\",\n \"shadow-[inset_0_-1px_0_0_rgb(0_0_0/0.08)]\",\n \"dark:bg-white/4 dark:text-white/80 dark:border-white/15\",\n \"dark:shadow-[inset_0_-1px_0_0_rgb(0_0_0/0.35)]\",\n ],\n },\n // Type is one Tailwind step per size (12 / 14 / 16px), the scale of\n // the text a key sits beside — a 10px label left ⌘ and ↵ unreadable.\n //\n // A single character must fit `min-w` (= height) to stay square. Kode\n // Mono advances 0.6em per glyph, so glyph + 2 × padding + 2 × 1px border:\n // sm: 7.2 + 2 × 5 + 2 = 19.2 ≤ 20 (px-1.5 gave 21.2: one px too wide)\n // md: 8.4 + 2 × 6 + 2 = 22.4 ≤ 24\n // lg: 9.6 + 2 × 8 + 2 = 27.6 ≤ 28\n // Re-check these sums after a font, type step or padding change.\n size: {\n sm: \"h-5 min-w-5 px-1.25 text-xs [&_svg]:size-3\",\n md: \"h-6 min-w-6 px-1.5 text-sm [&_svg]:size-3.5\",\n lg: \"h-7 min-w-7 px-2 text-base [&_svg]:size-4\",\n },\n },\n defaultVariants: {\n variant: \"default\",\n size: \"md\",\n },\n },\n)\n\nexport type KbdVariant = NonNullable<VariantProps<typeof kbdVariants>[\"variant\"]>\nexport type KbdSize = NonNullable<VariantProps<typeof kbdVariants>[\"size\"]>\n\n/** The outer `<kbd>` of a `hotkey` combination: a row of caps, unstyled itself.\n * `align-middle` sits it on the text it annotates the way a lone cap does. */\nconst kbdGroup = \"inline-flex items-center gap-0.5 align-middle\"\n\n/** With `hotkey`: the key words, merged per key onto `KBD_DEFAULT_TRANSLATIONS`. */\ntype KbdHotkeyTranslations = {\n /** The words the caps read as and are spoken by, merged per key onto the English\n * `KBD_DEFAULT_TRANSLATIONS`: `{ ctrl: \"Strg\", enter: \"Eingabe\" }`. Pass the same\n * object to `formatHotkey` / `hotkeyKeys` so plain text reads the same. */\n translations?: Partial<KbdTranslations>\n}\n\ntype KbdHotkeyProps =\n | { hotkey?: undefined; translations?: undefined }\n | (KbdHotkeyTranslations & {\n /** A `useHotkey` string to draw, one cap per key, the way the visitor's\n * platform writes it: `\"mod+k\"` is `[⌘] [K]` on Apple platforms and\n * `[Ctrl] [K]` elsewhere (see `hotkeyKeys`). A key with an icon (Shift,\n * Enter, Tab, the arrows, and ⌘ ⌥ ⌃ ⌫ on Apple) is drawn as one, with a\n * spoken name; Ctrl, Alt, Esc, Space (and Backspace off Apple) stay\n * words. Server-rendered as the non-Apple caps, then corrected on\n * hydration. The caps are the content, so it takes no children. */\n hotkey: string\n asChild?: false\n children?: never\n })\n | (KbdHotkeyTranslations & {\n hotkey: string\n /** With `hotkey`: the single child becomes the outer `<kbd>` of the\n * combination, the caps rendered inside it. */\n asChild: true\n children: ReactElement\n })\n\nexport type KbdProps = HTMLArkProps<\"kbd\"> &\n VariantProps<typeof kbdVariants> &\n WithTestId & {\n /** Accent palette. Re-exported as `Color` from `@42/ui-react`. */\n color?: Color\n } & KbdHotkeyProps\n\ntype KbdComboProps = KbdProps & { hotkey: string }\n\n/** `<Kbd hotkey>`: the combination's outer `<kbd>`, one cap per key inside. */\nconst KbdCombo = ({\n className,\n variant,\n size,\n color,\n testId,\n hotkey,\n translations,\n asChild,\n children,\n ...rest\n}: KbdComboProps) => {\n const apple = useApplePlatform()\n const caps = hotkeyCaps(hotkey, apple, translations).map(({ id, label, icon: Icon, name }) => (\n // A symbol is drawn (an icon, or the glyph where there is none) and its\n // name spoken: an svg says nothing, and `⌘` alone reads inconsistently.\n // `relative` holds the absolutely positioned `sr-only` inside the cap.\n // An icon cap drops its side padding to stay square, as a lone icon does\n // (the `sr-only` name beside the svg keeps `:only-child` from matching).\n <kbd\n key={id}\n className={cn(kbdVariants({ variant, size }), name && \"relative\", Icon && \"px-0\")}\n >\n {name ? (\n <>\n {Icon ? <Icon aria-hidden /> : <span aria-hidden>{label}</span>}\n <span className=\"sr-only\">{name}</span>\n </>\n ) : (\n label\n )}\n </kbd>\n ))\n return (\n <ark.kbd\n // A combination reads left to right in either direction, like the\n // single string it replaces.\n dir=\"ltr\"\n data-color={color}\n {...props({ \"data-testid\": testId })}\n {...rest}\n asChild={asChild}\n className={cn(kbdGroup, className)}\n >\n {composeChildren(asChild, children, () => caps)}\n </ark.kbd>\n )\n}\n\nexport const Kbd = (allProps: KbdProps) => {\n if (allProps.hotkey !== undefined) return <KbdCombo {...allProps} />\n const {\n className,\n variant,\n size,\n color,\n testId,\n hotkey: _hotkey,\n translations: _translations,\n ...rest\n } = allProps\n return (\n <ark.kbd\n data-color={color}\n {...props({ \"data-testid\": testId })}\n {...rest}\n className={cn(kbdVariants({ variant, size }), className)}\n />\n )\n}\n"]}
|