@42-central/ui-react 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -175
- package/dist/{chunk-FD6P6PLQ.js → chunk-5JHDSVEZ.js} +3 -3
- package/dist/{chunk-FD6P6PLQ.js.map → chunk-5JHDSVEZ.js.map} +1 -1
- package/dist/{chunk-QMW7D5GU.js → chunk-5OQLFX47.js} +4 -3
- package/dist/chunk-5OQLFX47.js.map +1 -0
- package/dist/{chunk-VZ2TPU4B.js → chunk-6GDMSENK.js} +3 -2
- package/dist/chunk-6GDMSENK.js.map +1 -0
- package/dist/{chunk-TNNH3FVQ.js → chunk-6OLTJYSX.js} +24 -8
- package/dist/chunk-6OLTJYSX.js.map +1 -0
- package/dist/{chunk-POKDSVQT.js → chunk-AE7QTLJ5.js} +5 -4
- package/dist/chunk-AE7QTLJ5.js.map +1 -0
- package/dist/{chunk-44OV3PNH.js → chunk-B2YJKRNQ.js} +3 -3
- package/dist/{chunk-44OV3PNH.js.map → chunk-B2YJKRNQ.js.map} +1 -1
- package/dist/{chunk-YIQI2CF3.js → chunk-CTSO6V72.js} +3 -2
- package/dist/chunk-CTSO6V72.js.map +1 -0
- package/dist/{chunk-ACE7FBWE.js → chunk-EBREIC3L.js} +5 -4
- package/dist/chunk-EBREIC3L.js.map +1 -0
- package/dist/{chunk-UNSAA7YG.js → chunk-FHG54IT5.js} +3 -2
- package/dist/chunk-FHG54IT5.js.map +1 -0
- package/dist/{chunk-3GYOIQW7.js → chunk-FZIHZT5R.js} +5 -5
- package/dist/{chunk-3GYOIQW7.js.map → chunk-FZIHZT5R.js.map} +1 -1
- package/dist/{chunk-2H46IXW4.js → chunk-HAQJQFE6.js} +28 -8
- package/dist/chunk-HAQJQFE6.js.map +1 -0
- package/dist/{chunk-IHYFYMHJ.js → chunk-HT5JAHR3.js} +6 -6
- package/dist/{chunk-IHYFYMHJ.js.map → chunk-HT5JAHR3.js.map} +1 -1
- package/dist/chunk-I4SQQIP5.js +12 -0
- package/dist/chunk-I4SQQIP5.js.map +1 -0
- package/dist/{chunk-J3PELDH3.js → chunk-JITF6I7N.js} +22 -6
- package/dist/chunk-JITF6I7N.js.map +1 -0
- package/dist/{chunk-IFWCCAQV.js → chunk-KHMFNH3X.js} +3 -2
- package/dist/chunk-KHMFNH3X.js.map +1 -0
- package/dist/{chunk-SIG4DMNZ.js → chunk-MI2WZRK3.js} +4 -4
- package/dist/{chunk-SIG4DMNZ.js.map → chunk-MI2WZRK3.js.map} +1 -1
- package/dist/{chunk-PJL4ZL5V.js → chunk-O23Y5ML4.js} +8 -8
- package/dist/{chunk-PJL4ZL5V.js.map → chunk-O23Y5ML4.js.map} +1 -1
- package/dist/{chunk-P7A3BCAC.js → chunk-OWG4BCQR.js} +3 -3
- package/dist/{chunk-P7A3BCAC.js.map → chunk-OWG4BCQR.js.map} +1 -1
- package/dist/{chunk-FUWSTUDM.js → chunk-PH354ECN.js} +4 -4
- package/dist/{chunk-FUWSTUDM.js.map → chunk-PH354ECN.js.map} +1 -1
- package/dist/{chunk-U5GW5EBR.js → chunk-RAUOFTUH.js} +12 -20
- package/dist/chunk-RAUOFTUH.js.map +1 -0
- package/dist/{chunk-2762HZYX.js → chunk-S2HWWR2H.js} +47 -25
- package/dist/chunk-S2HWWR2H.js.map +1 -0
- package/dist/{chunk-VLUKI3HL.js → chunk-S7N4LGLZ.js} +6 -13
- package/dist/chunk-S7N4LGLZ.js.map +1 -0
- package/dist/{chunk-TMMEJKLI.js → chunk-UHNRAI6V.js} +17 -4
- package/dist/chunk-UHNRAI6V.js.map +1 -0
- package/dist/{chunk-3NZXWCGF.js → chunk-WHKKN3ZK.js} +6 -6
- package/dist/{chunk-3NZXWCGF.js.map → chunk-WHKKN3ZK.js.map} +1 -1
- package/dist/{chunk-MOI7B3KH.js → chunk-WQN64ZHG.js} +5 -5
- package/dist/{chunk-MOI7B3KH.js.map → chunk-WQN64ZHG.js.map} +1 -1
- package/dist/chunk-WSIVRDRB.js +34 -0
- package/dist/chunk-WSIVRDRB.js.map +1 -0
- package/dist/{chunk-6SWK4XG5.js → chunk-YXE4B6X3.js} +2 -2
- package/dist/chunk-YXE4B6X3.js.map +1 -0
- package/dist/{chunk-NGAQITWP.js → chunk-Z2Z5EXVT.js} +10 -7
- package/dist/chunk-Z2Z5EXVT.js.map +1 -0
- package/dist/{chunk-IXKELBJA.js → chunk-ZDXQ64A7.js} +63 -44
- package/dist/chunk-ZDXQ64A7.js.map +1 -0
- package/dist/components/accordion/accordion-data.d.ts +3 -2
- package/dist/components/accordion/accordion-data.d.ts.map +1 -1
- package/dist/components/accordion/accordion.d.ts +2 -2
- package/dist/components/accordion/accordion.d.ts.map +1 -1
- package/dist/components/accordion/index.js +20 -8
- package/dist/components/accordion/index.js.map +1 -1
- package/dist/components/action-icon/action-icon.d.ts +3 -4
- package/dist/components/action-icon/action-icon.d.ts.map +1 -1
- package/dist/components/action-icon/index.js +2 -1
- package/dist/components/alert/alert.d.ts +18 -10
- package/dist/components/alert/alert.d.ts.map +1 -1
- package/dist/components/alert/index.js +17 -5
- package/dist/components/alert/index.js.map +1 -1
- package/dist/components/app-shell/app-shell.d.ts +3 -2
- package/dist/components/app-shell/app-shell.d.ts.map +1 -1
- package/dist/components/app-shell/index.js +4 -2
- package/dist/components/app-shell/index.js.map +1 -1
- package/dist/components/autocomplete/index.js +5 -4
- package/dist/components/autocomplete/index.js.map +1 -1
- package/dist/components/breadcrumb/breadcrumb.d.ts +3 -2
- package/dist/components/breadcrumb/breadcrumb.d.ts.map +1 -1
- package/dist/components/breadcrumb/index.js +11 -5
- package/dist/components/breadcrumb/index.js.map +1 -1
- package/dist/components/button/button.d.ts +4 -4
- package/dist/components/button/button.d.ts.map +1 -1
- package/dist/components/button/index.js +2 -1
- package/dist/components/button-multi-select/index.js +4 -3
- package/dist/components/button-multi-select/index.js.map +1 -1
- package/dist/components/button-select/index.js +4 -3
- package/dist/components/button-select/index.js.map +1 -1
- package/dist/components/calendar/calendar-body.d.ts.map +1 -1
- package/dist/components/calendar/index.js +3 -2
- package/dist/components/checkbox/index.js +2 -2
- package/dist/components/choice-card-group/index.js +1 -1
- package/dist/components/circular-progress/circular-progress.d.ts +3 -2
- package/dist/components/circular-progress/circular-progress.d.ts.map +1 -1
- package/dist/components/circular-progress/index.js +1 -0
- package/dist/components/circular-progress/index.js.map +1 -1
- package/dist/components/clipboard/clipboard.d.ts +1 -1
- package/dist/components/clipboard/clipboard.d.ts.map +1 -1
- package/dist/components/clipboard/index.js +9 -5
- package/dist/components/clipboard/index.js.map +1 -1
- package/dist/components/code-block/chrome.d.ts +4 -1
- package/dist/components/code-block/chrome.d.ts.map +1 -1
- package/dist/components/code-block/chrome.js +5 -4
- package/dist/components/code-block/code-block.d.ts +7 -1
- package/dist/components/code-block/code-block.d.ts.map +1 -1
- package/dist/components/code-block/index.d.ts +1 -1
- package/dist/components/code-block/index.js +12 -10
- package/dist/components/code-block/index.js.map +1 -1
- package/dist/components/code-block/notation.d.ts +5 -2
- package/dist/components/code-block/notation.d.ts.map +1 -1
- package/dist/components/code-block/static.d.ts +4 -1
- package/dist/components/code-block/static.d.ts.map +1 -1
- package/dist/components/code-block/static.js +5 -4
- package/dist/components/code-block/static.js.map +1 -1
- package/dist/components/collapse/collapse.d.ts +7 -3
- package/dist/components/collapse/collapse.d.ts.map +1 -1
- package/dist/components/collapse/index.js +2 -1
- package/dist/components/combobox/combobox.d.ts +11 -10
- package/dist/components/combobox/combobox.d.ts.map +1 -1
- package/dist/components/combobox/index.js +5 -4
- package/dist/components/combobox-list/index.js +6 -5
- package/dist/components/data-table/index.js +20 -19
- package/dist/components/data-table/index.js.map +1 -1
- package/dist/components/date-picker/index.js +12 -11
- package/dist/components/date-picker/index.js.map +1 -1
- package/dist/components/divider/divider.d.ts +3 -2
- package/dist/components/divider/divider.d.ts.map +1 -1
- package/dist/components/divider/index.js +1 -1
- package/dist/components/drawer/drawer.d.ts +6 -5
- package/dist/components/drawer/drawer.d.ts.map +1 -1
- package/dist/components/drawer/index.js +3 -2
- package/dist/components/field/field.d.ts +7 -4
- package/dist/components/field/field.d.ts.map +1 -1
- package/dist/components/field/index.js +1 -1
- package/dist/components/file-upload/index.js +3 -2
- package/dist/components/file-upload/index.js.map +1 -1
- package/dist/components/hover-card/index.js +1 -1
- package/dist/components/input/index.js +2 -2
- package/dist/components/input/input.d.ts +3 -2
- package/dist/components/input/input.d.ts.map +1 -1
- package/dist/components/menu/index.js +3 -2
- package/dist/components/menu/index.js.map +1 -1
- package/dist/components/menu/menu-data.d.ts +6 -1
- package/dist/components/menu/menu-data.d.ts.map +1 -1
- package/dist/components/menu/menu.d.ts +5 -5
- package/dist/components/menu/menu.d.ts.map +1 -1
- package/dist/components/modal/index.js +3 -2
- package/dist/components/modal/modal.d.ts +4 -3
- package/dist/components/modal/modal.d.ts.map +1 -1
- package/dist/components/multi-combobox-list/index.js +6 -5
- package/dist/components/multi-select/index.js +7 -6
- package/dist/components/multi-select/index.js.map +1 -1
- package/dist/components/nav-link/index.js +3 -2
- package/dist/components/nav-link/tanstack.js +3 -2
- package/dist/components/nav-link/tanstack.js.map +1 -1
- package/dist/components/notification/create-notifier.d.ts.map +1 -1
- package/dist/components/notification/index.js +8 -7
- package/dist/components/notification/index.js.map +1 -1
- package/dist/components/notification/notification.d.ts +7 -6
- package/dist/components/notification/notification.d.ts.map +1 -1
- package/dist/components/number-input/index.js +4 -4
- package/dist/components/overlays/index.js +5 -4
- package/dist/components/overlays/index.js.map +1 -1
- package/dist/components/password-input/index.js +2 -2
- package/dist/components/pill/index.js +2 -1
- package/dist/components/pill/pill.d.ts +4 -2
- package/dist/components/pill/pill.d.ts.map +1 -1
- package/dist/components/pills-input/index.js +5 -4
- package/dist/components/pills-input/pills-input.d.ts +3 -2
- package/dist/components/pills-input/pills-input.d.ts.map +1 -1
- package/dist/components/pin-input/index.js +2 -2
- package/dist/components/popover/index.js +1 -1
- package/dist/components/popover/popover.d.ts +3 -2
- package/dist/components/popover/popover.d.ts.map +1 -1
- package/dist/components/progress/index.js +1 -0
- package/dist/components/progress/index.js.map +1 -1
- package/dist/components/progress/progress.d.ts +3 -2
- package/dist/components/progress/progress.d.ts.map +1 -1
- package/dist/components/radio-group/index.js +1 -1
- package/dist/components/rating/index.js +2 -1
- package/dist/components/rating/index.js.map +1 -1
- package/dist/components/rating/rating.d.ts +3 -2
- package/dist/components/rating/rating.d.ts.map +1 -1
- package/dist/components/schedule/index.d.ts +4 -4
- package/dist/components/schedule/index.js +211 -110
- package/dist/components/schedule/index.js.map +1 -1
- package/dist/components/schedule/schedule-agenda-list.d.ts +6 -7
- package/dist/components/schedule/schedule-agenda-list.d.ts.map +1 -1
- package/dist/components/schedule/schedule-agenda-view.d.ts +19 -16
- package/dist/components/schedule/schedule-agenda-view.d.ts.map +1 -1
- package/dist/components/schedule/schedule-create-draft.d.ts +3 -2
- package/dist/components/schedule/schedule-create-draft.d.ts.map +1 -1
- package/dist/components/schedule/schedule-dates.d.ts.map +1 -1
- package/dist/components/schedule/schedule-days-view.d.ts +3 -2
- package/dist/components/schedule/schedule-days-view.d.ts.map +1 -1
- package/dist/components/schedule/schedule-drag-ghost.d.ts +12 -5
- package/dist/components/schedule/schedule-drag-ghost.d.ts.map +1 -1
- package/dist/components/schedule/schedule-event-chip.d.ts.map +1 -1
- package/dist/components/schedule/schedule-geometry.d.ts +16 -0
- package/dist/components/schedule/schedule-geometry.d.ts.map +1 -1
- package/dist/components/schedule/schedule-grid-gesture.d.ts +29 -6
- package/dist/components/schedule/schedule-grid-gesture.d.ts.map +1 -1
- package/dist/components/schedule/schedule-month-view.d.ts +3 -2
- package/dist/components/schedule/schedule-month-view.d.ts.map +1 -1
- package/dist/components/schedule/schedule-next-up.d.ts +4 -3
- package/dist/components/schedule/schedule-next-up.d.ts.map +1 -1
- package/dist/components/schedule/schedule-timed-grid.d.ts.map +1 -1
- package/dist/components/schedule/schedule-toolbar.d.ts +3 -3
- package/dist/components/schedule/schedule-toolbar.d.ts.map +1 -1
- package/dist/components/schedule/schedule-types.d.ts +9 -4
- package/dist/components/schedule/schedule-types.d.ts.map +1 -1
- package/dist/components/schedule/schedule-views.d.ts +2 -2
- package/dist/components/schedule/schedule-views.d.ts.map +1 -1
- package/dist/components/schedule/schedule-year-view.d.ts +3 -2
- package/dist/components/schedule/schedule-year-view.d.ts.map +1 -1
- package/dist/components/schedule/schedule.d.ts +9 -6
- package/dist/components/schedule/schedule.d.ts.map +1 -1
- package/dist/components/schedule/use-event-create.d.ts.map +1 -1
- package/dist/components/schedule/use-event-drag.d.ts.map +1 -1
- package/dist/components/schedule/use-event-resize.d.ts.map +1 -1
- package/dist/components/segment-group/index.js +2 -2
- package/dist/components/select/index.js +4 -4
- package/dist/components/slider/index.js +2 -1
- package/dist/components/slider/index.js.map +1 -1
- package/dist/components/slider/slider.d.ts +3 -2
- package/dist/components/slider/slider.d.ts.map +1 -1
- package/dist/components/switch/index.js +1 -1
- package/dist/components/tabs/index.js +1 -1
- package/dist/components/tabs/tabs-data.d.ts +3 -2
- package/dist/components/tabs/tabs-data.d.ts.map +1 -1
- package/dist/components/tags-input/index.js +6 -5
- package/dist/components/tags-input/index.js.map +1 -1
- package/dist/components/text-input/index.js +2 -2
- package/dist/components/textarea/index.js +2 -2
- package/dist/components/time-input/index.js +6 -6
- package/dist/components/timeline/index.js +8 -5
- package/dist/components/timeline/index.js.map +1 -1
- package/dist/components/timeline/timeline.d.ts +1 -1
- package/dist/components/timeline/timeline.d.ts.map +1 -1
- package/dist/components/tooltip/index.js +1 -1
- package/dist/components/tooltip/tooltip.d.ts +2 -1
- package/dist/components/tooltip/tooltip.d.ts.map +1 -1
- package/dist/components/tree-multi-select/index.js +6 -5
- package/dist/components/tree-multi-select/index.js.map +1 -1
- package/dist/components/tree-select/index.js +3 -3
- package/dist/lib/as-child.d.ts +104 -0
- package/dist/lib/as-child.d.ts.map +1 -0
- package/dist/theme.css +9 -3
- package/package.json +1 -1
- package/src/as-child.contract.test.tsx +809 -0
- package/src/components/accordion/accordion-data.tsx +8 -5
- package/src/components/accordion/accordion.test.tsx +40 -0
- package/src/components/accordion/accordion.tsx +23 -6
- package/src/components/action-icon/action-icon.tsx +9 -24
- package/src/components/alert/alert.test.tsx +25 -2
- package/src/components/alert/alert.tsx +39 -13
- package/src/components/app-shell/app-shell.tsx +3 -1
- package/src/components/breadcrumb/breadcrumb.test.tsx +30 -0
- package/src/components/breadcrumb/breadcrumb.tsx +21 -12
- package/src/components/button/button.tsx +21 -50
- package/src/components/calendar/calendar-body.tsx +8 -1
- package/src/components/circular-progress/circular-progress.tsx +4 -1
- package/src/components/clipboard/clipboard.test.tsx +18 -0
- package/src/components/clipboard/clipboard.tsx +8 -2
- package/src/components/code-block/chrome.tsx +60 -36
- package/src/components/code-block/code-block.test.tsx +27 -0
- package/src/components/code-block/code-block.tsx +13 -3
- package/src/components/code-block/notation.test.ts +8 -0
- package/src/components/code-block/notation.ts +6 -3
- package/src/components/code-block/static.tsx +8 -2
- package/src/components/collapse/collapse.tsx +33 -15
- package/src/components/combobox/combobox.test.tsx +38 -0
- package/src/components/combobox/combobox.tsx +24 -10
- package/src/components/divider/divider.tsx +3 -1
- package/src/components/drawer/drawer.tsx +37 -16
- package/src/components/field/field.tsx +7 -3
- package/src/components/input/input.tsx +3 -1
- package/src/components/menu/menu-data.tsx +8 -1
- package/src/components/menu/menu.test.tsx +52 -0
- package/src/components/menu/menu.tsx +83 -35
- package/src/components/modal/close-trigger.test.tsx +38 -0
- package/src/components/modal/modal.tsx +29 -13
- package/src/components/notification/create-notifier.tsx +6 -5
- package/src/components/notification/notification.test.tsx +15 -0
- package/src/components/notification/notification.tsx +8 -5
- package/src/components/pill/pill.tsx +29 -20
- package/src/components/pills-input/pills-input.tsx +3 -1
- package/src/components/popover/popover.tsx +3 -1
- package/src/components/progress/progress.tsx +4 -1
- package/src/components/rating/rating.tsx +27 -23
- package/src/components/schedule/index.ts +1 -1
- package/src/components/schedule/now-cursor-line.tsx +1 -1
- package/src/components/schedule/schedule-agenda-list.tsx +6 -7
- package/src/components/schedule/schedule-agenda-view.test.tsx +105 -28
- package/src/components/schedule/schedule-agenda-view.tsx +46 -31
- package/src/components/schedule/schedule-all-day-row.tsx +1 -1
- package/src/components/schedule/schedule-create-draft.tsx +14 -5
- package/src/components/schedule/schedule-dates.test.ts +37 -52
- package/src/components/schedule/schedule-dates.ts +25 -27
- package/src/components/schedule/schedule-days-view.tsx +9 -5
- package/src/components/schedule/schedule-drag-ghost.tsx +27 -12
- package/src/components/schedule/schedule-event-chip.tsx +9 -2
- package/src/components/schedule/schedule-event-list-popover-content.tsx +1 -1
- package/src/components/schedule/schedule-geometry.ts +21 -0
- package/src/components/schedule/schedule-grid-gesture.test.ts +83 -1
- package/src/components/schedule/schedule-grid-gesture.ts +67 -28
- package/src/components/schedule/schedule-month-view.tsx +10 -6
- package/src/components/schedule/schedule-next-up.tsx +11 -5
- package/src/components/schedule/schedule-timed-grid.tsx +41 -3
- package/src/components/schedule/schedule-toolbar.test.tsx +26 -0
- package/src/components/schedule/schedule-toolbar.tsx +35 -17
- package/src/components/schedule/schedule-types.ts +9 -4
- package/src/components/schedule/schedule-views.ts +4 -5
- package/src/components/schedule/schedule-year-view.tsx +10 -6
- package/src/components/schedule/schedule.test.tsx +198 -36
- package/src/components/schedule/schedule.tsx +28 -17
- package/src/components/schedule/use-event-create.ts +7 -6
- package/src/components/schedule/use-event-drag.ts +10 -4
- package/src/components/schedule/use-event-resize.ts +4 -2
- package/src/components/slider/slider.tsx +4 -0
- package/src/components/tabs/tabs-data.tsx +17 -14
- package/src/components/timeline/timeline.tsx +102 -95
- package/src/components/tooltip/tooltip.tsx +2 -1
- package/src/lib/as-child.test.tsx +70 -0
- package/src/lib/as-child.ts +119 -0
- package/src/theme.css +9 -3
- package/dist/chunk-2762HZYX.js.map +0 -1
- package/dist/chunk-2H46IXW4.js.map +0 -1
- package/dist/chunk-6SWK4XG5.js.map +0 -1
- package/dist/chunk-ACE7FBWE.js.map +0 -1
- package/dist/chunk-HWNPXAEN.js +0 -31
- package/dist/chunk-HWNPXAEN.js.map +0 -1
- package/dist/chunk-IFWCCAQV.js.map +0 -1
- package/dist/chunk-IXKELBJA.js.map +0 -1
- package/dist/chunk-J3PELDH3.js.map +0 -1
- package/dist/chunk-NGAQITWP.js.map +0 -1
- package/dist/chunk-POKDSVQT.js.map +0 -1
- package/dist/chunk-QMW7D5GU.js.map +0 -1
- package/dist/chunk-TMMEJKLI.js.map +0 -1
- package/dist/chunk-TNNH3FVQ.js.map +0 -1
- package/dist/chunk-U5GW5EBR.js.map +0 -1
- package/dist/chunk-UNSAA7YG.js.map +0 -1
- package/dist/chunk-VLUKI3HL.js.map +0 -1
- package/dist/chunk-VZ2TPU4B.js.map +0 -1
- package/dist/chunk-YIQI2CF3.js.map +0 -1
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { Field as Ark, type UseFieldContext } from "@ark-ui/react/field"
|
|
4
4
|
import { cva, type VariantProps } from "class-variance-authority"
|
|
5
5
|
import type { ComponentPropsWithoutRef, ReactNode } from "react"
|
|
6
|
+
import type { NoAsChild } from "../../lib/as-child"
|
|
6
7
|
import { cn } from "../../lib/cn"
|
|
7
8
|
import { props } from "../../lib/props"
|
|
8
9
|
import type { WithTestId } from "../../lib/test-id"
|
|
@@ -24,8 +25,10 @@ import type { WithTestId } from "../../lib/test-id"
|
|
|
24
25
|
* - `size` scales only the field's own typography; set the control's `size`
|
|
25
26
|
* separately (the family components forward both).
|
|
26
27
|
*
|
|
27
|
-
* Every other prop (incl. `disabled`, `readOnly`, `id
|
|
28
|
-
*
|
|
28
|
+
* Every other prop (incl. `disabled`, `readOnly`, `id`) forwards to Ark's
|
|
29
|
+
* `Field.Root`. `asChild` is a compile error: the field renders its label,
|
|
30
|
+
* helper and error rows around the control, which can't live inside one
|
|
31
|
+
* element.
|
|
29
32
|
*/
|
|
30
33
|
|
|
31
34
|
// `relative` contains a `sr-only` label (and any hidden input rendered inside
|
|
@@ -112,7 +115,7 @@ type FieldClassNames = {
|
|
|
112
115
|
requiredIndicator?: string
|
|
113
116
|
}
|
|
114
117
|
|
|
115
|
-
export type FieldProps = Omit<ComponentPropsWithoutRef<typeof Ark.Root>, "className"
|
|
118
|
+
export type FieldProps = NoAsChild<Omit<ComponentPropsWithoutRef<typeof Ark.Root>, "className">> &
|
|
116
119
|
VariantProps<typeof fieldRoot> &
|
|
117
120
|
WithTestId & {
|
|
118
121
|
/** Accessible name, rendered as a `<label>` bound to the control. */
|
|
@@ -186,6 +189,7 @@ export const Field = ({
|
|
|
186
189
|
className,
|
|
187
190
|
classNames,
|
|
188
191
|
testId,
|
|
192
|
+
asChild: _asChild,
|
|
189
193
|
...rest
|
|
190
194
|
}: FieldProps) => {
|
|
191
195
|
const isInvalid = invalid ?? error != null
|
|
@@ -4,6 +4,7 @@ import { ark, type HTMLArkProps } from "@ark-ui/react"
|
|
|
4
4
|
import { useFieldContext } from "@ark-ui/react/field"
|
|
5
5
|
import { cva, type VariantProps } from "class-variance-authority"
|
|
6
6
|
import type { ReactNode, Ref } from "react"
|
|
7
|
+
import type { NoAsChild } from "../../lib/as-child"
|
|
7
8
|
import { cn } from "../../lib/cn"
|
|
8
9
|
import { props } from "../../lib/props"
|
|
9
10
|
import type { WithTestId } from "../../lib/test-id"
|
|
@@ -196,7 +197,7 @@ type ShellOwnProps = VariantProps<typeof inputShell> & {
|
|
|
196
197
|
endSlot?: ReactNode
|
|
197
198
|
}
|
|
198
199
|
|
|
199
|
-
export type InputBaseProps = Omit<HTMLArkProps<"div">, "color"
|
|
200
|
+
export type InputBaseProps = NoAsChild<Omit<HTMLArkProps<"div">, "color">> &
|
|
200
201
|
ShellOwnProps &
|
|
201
202
|
WithTestId & {
|
|
202
203
|
classNames?: ShellClassNames
|
|
@@ -215,6 +216,7 @@ export const InputBase = ({
|
|
|
215
216
|
className,
|
|
216
217
|
classNames,
|
|
217
218
|
testId,
|
|
219
|
+
asChild: _asChild,
|
|
218
220
|
...rest
|
|
219
221
|
}: InputBaseProps) => (
|
|
220
222
|
<ark.div
|
|
@@ -98,8 +98,15 @@ export type MenuItemsData = ReadonlyArray<MenuEntry>
|
|
|
98
98
|
* dividers and value-less actions contribute `never`. Checked structurally by
|
|
99
99
|
* key (submenu / group carry `items`, so they must be matched before the action
|
|
100
100
|
* branch, which any labelled object would otherwise satisfy).
|
|
101
|
+
*
|
|
102
|
+
* The un-narrowed `MenuItemsData` itself resolves to `string` up front:
|
|
103
|
+
* `MenuSubItem.items` is `MenuItemsData` again, so recursing into the wide
|
|
104
|
+
* type never bottoms out. tsc gave up and typed the value `any`, and any
|
|
105
|
+
* type-level probe of `MenuProps` hit "excessively deep".
|
|
101
106
|
*/
|
|
102
|
-
export type MenuValue<Data extends MenuItemsData> =
|
|
107
|
+
export type MenuValue<Data extends MenuItemsData> = MenuItemsData extends Data
|
|
108
|
+
? string
|
|
109
|
+
: ExtractValue<Data[number]>
|
|
103
110
|
|
|
104
111
|
type ExtractValue<E> = E extends string
|
|
105
112
|
? E
|
|
@@ -346,6 +346,58 @@ describe("Menu (interaction)", () => {
|
|
|
346
346
|
})
|
|
347
347
|
})
|
|
348
348
|
|
|
349
|
+
/**
|
|
350
|
+
* #281 — an item that navigates renders as the consumer's own link (a plain
|
|
351
|
+
* `<a>` or a router `Link`) through `asChild`, so middle-click, "open in new
|
|
352
|
+
* tab" and the link role all work. The row's sections fold into the link.
|
|
353
|
+
*/
|
|
354
|
+
describe("Menu (link items)", () => {
|
|
355
|
+
it("renders the asChild link as the menuitem, sections and row styling included", () => {
|
|
356
|
+
render(
|
|
357
|
+
<Menu.Root defaultOpen withinPortal={false}>
|
|
358
|
+
<Menu.Trigger>Open</Menu.Trigger>
|
|
359
|
+
<Menu.Content>
|
|
360
|
+
<Menu.Item
|
|
361
|
+
asChild
|
|
362
|
+
color="red"
|
|
363
|
+
startSection={<svg data-testid="start" aria-hidden="true" />}
|
|
364
|
+
endSection={<kbd>⌘O</kbd>}
|
|
365
|
+
>
|
|
366
|
+
<a href="/entities/libft">Open the entity page</a>
|
|
367
|
+
</Menu.Item>
|
|
368
|
+
</Menu.Content>
|
|
369
|
+
</Menu.Root>,
|
|
370
|
+
)
|
|
371
|
+
const link = screen.getByRole("menuitem", { name: /Open the entity page/ })
|
|
372
|
+
expect(link.tagName).toBe("A")
|
|
373
|
+
expect(link.getAttribute("href")).toBe("/entities/libft")
|
|
374
|
+
expect(link.getAttribute("data-color")).toBe("red")
|
|
375
|
+
expect(link.className).toContain("rounded-xs")
|
|
376
|
+
expect(link.contains(screen.getByTestId("start"))).toBe(true)
|
|
377
|
+
expect(link.textContent).toContain("⌘O")
|
|
378
|
+
})
|
|
379
|
+
|
|
380
|
+
// zag's own keyboard "click" doesn't bubble, so a React onClick (where a
|
|
381
|
+
// router Link does its client-side navigation) never ran.
|
|
382
|
+
it("reaches the link's React onClick when selected from the keyboard", async () => {
|
|
383
|
+
const onLinkClick = vi.fn((event: { preventDefault: () => void }) => event.preventDefault())
|
|
384
|
+
render(
|
|
385
|
+
<Menu.Root defaultOpen defaultHighlightedValue="open" withinPortal={false}>
|
|
386
|
+
<Menu.Trigger>Open</Menu.Trigger>
|
|
387
|
+
<Menu.Content>
|
|
388
|
+
<Menu.Item asChild value="open">
|
|
389
|
+
<a href="/entities/libft" onClick={onLinkClick}>
|
|
390
|
+
Open the entity page
|
|
391
|
+
</a>
|
|
392
|
+
</Menu.Item>
|
|
393
|
+
</Menu.Content>
|
|
394
|
+
</Menu.Root>,
|
|
395
|
+
)
|
|
396
|
+
fireEvent.keyDown(screen.getByRole("menu"), { key: "Enter" })
|
|
397
|
+
await waitFor(() => expect(onLinkClick).toHaveBeenCalledTimes(1))
|
|
398
|
+
})
|
|
399
|
+
})
|
|
400
|
+
|
|
349
401
|
/**
|
|
350
402
|
* #227 — Zag's trigger cancels `pointerdown`, which stops the browser from
|
|
351
403
|
* focusing the button on a mouse press. Chromium then treats Zag's later
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
useContext,
|
|
17
17
|
useId,
|
|
18
18
|
} from "react"
|
|
19
|
+
import { composeChildren } from "../../lib/as-child"
|
|
19
20
|
import { cn } from "../../lib/cn"
|
|
20
21
|
import type { Color } from "../../lib/colors"
|
|
21
22
|
import { useOverlayContainer } from "../../lib/overlay-container"
|
|
@@ -131,6 +132,19 @@ export type MenuRootProps = Omit<ArkMenu.RootProps, "positioning" | "onOpenChang
|
|
|
131
132
|
onClose?: () => void
|
|
132
133
|
}
|
|
133
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Selects a link item (`<Menu.Item asChild><Link/></Menu.Item>`) from the
|
|
137
|
+
* keyboard. zag's default `navigate` dispatches `new MouseEvent("click")`,
|
|
138
|
+
* which doesn't bubble, so React's delegated `onClick` never sees it and a
|
|
139
|
+
* router `Link` falls back to a full page load. `node.click()` dispatches a
|
|
140
|
+
* bubbling click instead, which reaches the router. Deferred like zag's own,
|
|
141
|
+
* so the menu settles before the navigation starts. A `navigate` prop still
|
|
142
|
+
* overrides it.
|
|
143
|
+
*/
|
|
144
|
+
const clickLink: NonNullable<ArkMenu.RootProps["navigate"]> = ({ node }) => {
|
|
145
|
+
queueMicrotask(() => node.click())
|
|
146
|
+
}
|
|
147
|
+
|
|
134
148
|
const Root = ({
|
|
135
149
|
position = "bottom",
|
|
136
150
|
offset,
|
|
@@ -146,6 +160,7 @@ const Root = ({
|
|
|
146
160
|
<MenuContext.Provider value={{ withinPortal, container }}>
|
|
147
161
|
<ArkMenu.Root
|
|
148
162
|
positioning={{ placement: resolveLogicalPlacement(position, dir), gutter: offset }}
|
|
163
|
+
navigate={clickLink}
|
|
149
164
|
onOpenChange={({ open }) => {
|
|
150
165
|
onOpenChange?.(open)
|
|
151
166
|
if (!open) onClose?.()
|
|
@@ -225,11 +240,13 @@ const Item = ({
|
|
|
225
240
|
className,
|
|
226
241
|
children,
|
|
227
242
|
testId,
|
|
243
|
+
asChild,
|
|
228
244
|
...rest
|
|
229
245
|
}: MenuItemProps) => {
|
|
230
246
|
const autoId = useId()
|
|
231
247
|
return (
|
|
232
248
|
<ArkMenu.Item
|
|
249
|
+
asChild={asChild}
|
|
233
250
|
value={value ?? autoId}
|
|
234
251
|
onSelect={onClick}
|
|
235
252
|
data-color={color}
|
|
@@ -237,9 +254,13 @@ const Item = ({
|
|
|
237
254
|
{...props({ "data-testid": testId })}
|
|
238
255
|
{...rest}
|
|
239
256
|
>
|
|
240
|
-
{
|
|
241
|
-
|
|
242
|
-
|
|
257
|
+
{composeChildren(asChild, children, (own) => (
|
|
258
|
+
<>
|
|
259
|
+
{startSection != null && <StartSection>{startSection}</StartSection>}
|
|
260
|
+
{own}
|
|
261
|
+
{endSection != null && <EndSection>{endSection}</EndSection>}
|
|
262
|
+
</>
|
|
263
|
+
))}
|
|
243
264
|
</ArkMenu.Item>
|
|
244
265
|
)
|
|
245
266
|
}
|
|
@@ -282,15 +303,21 @@ const ItemGroupLabel = ({
|
|
|
282
303
|
prefix,
|
|
283
304
|
children,
|
|
284
305
|
testId,
|
|
306
|
+
asChild,
|
|
285
307
|
...rest
|
|
286
308
|
}: MenuItemGroupLabelProps) => (
|
|
287
309
|
<ArkMenu.ItemGroupLabel
|
|
310
|
+
asChild={asChild}
|
|
288
311
|
className={cn(popoverGroupLabel, className)}
|
|
289
312
|
{...props({ "data-testid": testId })}
|
|
290
313
|
{...rest}
|
|
291
314
|
>
|
|
292
|
-
|
|
293
|
-
|
|
315
|
+
{composeChildren(asChild, children, (own) => (
|
|
316
|
+
<>
|
|
317
|
+
<HeadingPrefix prefix={prefix} />
|
|
318
|
+
{own}
|
|
319
|
+
</>
|
|
320
|
+
))}
|
|
294
321
|
</ArkMenu.ItemGroupLabel>
|
|
295
322
|
)
|
|
296
323
|
|
|
@@ -314,19 +341,25 @@ const CheckboxItem = ({
|
|
|
314
341
|
className,
|
|
315
342
|
children,
|
|
316
343
|
testId,
|
|
344
|
+
asChild,
|
|
317
345
|
...rest
|
|
318
346
|
}: MenuCheckboxItemProps) => (
|
|
319
347
|
<ArkMenu.CheckboxItem
|
|
348
|
+
asChild={asChild}
|
|
320
349
|
data-color={color}
|
|
321
350
|
className={cn(menuItem({ colored: color != null }), className)}
|
|
322
351
|
{...props({ "data-testid": testId })}
|
|
323
352
|
{...rest}
|
|
324
353
|
>
|
|
325
|
-
{
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
354
|
+
{composeChildren(asChild, children, (own) => (
|
|
355
|
+
<>
|
|
356
|
+
{startSection != null && <StartSection>{startSection}</StartSection>}
|
|
357
|
+
{own}
|
|
358
|
+
<ArkMenu.ItemIndicator className={popoverIndicator}>
|
|
359
|
+
<CheckIcon />
|
|
360
|
+
</ArkMenu.ItemIndicator>
|
|
361
|
+
</>
|
|
362
|
+
))}
|
|
330
363
|
</ArkMenu.CheckboxItem>
|
|
331
364
|
)
|
|
332
365
|
|
|
@@ -357,34 +390,40 @@ const RadioItem = ({
|
|
|
357
390
|
className,
|
|
358
391
|
children,
|
|
359
392
|
testId,
|
|
393
|
+
asChild,
|
|
360
394
|
...rest
|
|
361
395
|
}: MenuRadioItemProps) => (
|
|
362
396
|
<ArkMenu.RadioItem
|
|
397
|
+
asChild={asChild}
|
|
363
398
|
data-color={color}
|
|
364
399
|
className={cn(menuItem({ colored: color != null }), className)}
|
|
365
400
|
{...props({ "data-testid": testId })}
|
|
366
401
|
{...rest}
|
|
367
402
|
>
|
|
368
|
-
{
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
403
|
+
{composeChildren(asChild, children, (own) => (
|
|
404
|
+
<>
|
|
405
|
+
{startSection != null && <StartSection>{startSection}</StartSection>}
|
|
406
|
+
{own}
|
|
407
|
+
<ArkMenu.ItemIndicator className={popoverIndicator}>
|
|
408
|
+
<svg
|
|
409
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
410
|
+
width="24"
|
|
411
|
+
height="24"
|
|
412
|
+
viewBox="0 0 24 24"
|
|
413
|
+
fill="currentColor"
|
|
414
|
+
stroke="currentColor"
|
|
415
|
+
strokeWidth="2"
|
|
416
|
+
strokeLinecap="round"
|
|
417
|
+
strokeLinejoin="round"
|
|
418
|
+
className="lucide lucide-dot-big"
|
|
419
|
+
aria-hidden="true"
|
|
420
|
+
>
|
|
421
|
+
<title>Dot big</title>
|
|
422
|
+
<circle cx="12.1" cy="12.1" r="4"></circle>
|
|
423
|
+
</svg>
|
|
424
|
+
</ArkMenu.ItemIndicator>
|
|
425
|
+
</>
|
|
426
|
+
))}
|
|
388
427
|
</ArkMenu.RadioItem>
|
|
389
428
|
)
|
|
390
429
|
|
|
@@ -414,6 +453,7 @@ const SUBMENU_ALIGN_OFFSET = -5
|
|
|
414
453
|
const Sub = ({ offset = 10, children, ...rest }: MenuSubProps) => (
|
|
415
454
|
<ArkMenu.Root
|
|
416
455
|
positioning={{ offset: { mainAxis: offset, crossAxis: SUBMENU_ALIGN_OFFSET } }}
|
|
456
|
+
navigate={clickLink}
|
|
417
457
|
{...rest}
|
|
418
458
|
>
|
|
419
459
|
{children}
|
|
@@ -432,19 +472,27 @@ const SubTrigger = ({
|
|
|
432
472
|
className,
|
|
433
473
|
children,
|
|
434
474
|
testId,
|
|
475
|
+
asChild,
|
|
435
476
|
...rest
|
|
436
477
|
}: MenuSubTriggerProps) => (
|
|
437
478
|
<ArkMenu.TriggerItem
|
|
479
|
+
asChild={asChild}
|
|
438
480
|
data-color={color}
|
|
439
481
|
className={cn(menuItem({ colored: color != null }), className)}
|
|
440
482
|
{...props({ "data-testid": testId })}
|
|
441
483
|
{...rest}
|
|
442
484
|
>
|
|
443
|
-
{
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
485
|
+
{composeChildren(asChild, children, (own) => (
|
|
486
|
+
<>
|
|
487
|
+
{startSection != null && <StartSection>{startSection}</StartSection>}
|
|
488
|
+
{own}
|
|
489
|
+
<span
|
|
490
|
+
className={cn(popoverChevron, "ms-auto -me-1 -rotate-90 rtl:rotate-90 [&_svg]:size-4")}
|
|
491
|
+
>
|
|
492
|
+
<ChevronIcon />
|
|
493
|
+
</span>
|
|
494
|
+
</>
|
|
495
|
+
))}
|
|
448
496
|
</ArkMenu.TriggerItem>
|
|
449
497
|
)
|
|
450
498
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { fireEvent, render, screen, waitFor } from "@testing-library/react"
|
|
2
|
+
import { describe, expect, it, vi } from "vitest"
|
|
3
|
+
import { Drawer } from "../drawer/drawer"
|
|
4
|
+
import { Modal } from "./modal"
|
|
5
|
+
|
|
6
|
+
/** Modal and Drawer share the close-trigger shape: a kit icon button by
|
|
7
|
+
* default, the consumer's own element under `asChild`. */
|
|
8
|
+
describe.each([
|
|
9
|
+
["Modal", Modal.Root, Modal.CloseTrigger],
|
|
10
|
+
["Drawer", Drawer.Root, Drawer.CloseTrigger],
|
|
11
|
+
] as const)("%s.CloseTrigger", (_, Root, CloseTrigger) => {
|
|
12
|
+
it("renders the kit's labelled icon button by default", () => {
|
|
13
|
+
render(
|
|
14
|
+
<Root open>
|
|
15
|
+
<CloseTrigger />
|
|
16
|
+
</Root>,
|
|
17
|
+
)
|
|
18
|
+
expect(screen.getByRole("button", { name: "Close" }).querySelector("svg")).toBeTruthy()
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
// The consumer's button used to end up nested inside the kit's icon button.
|
|
22
|
+
it("replaces the icon button with the consumer's element under asChild", async () => {
|
|
23
|
+
const onOpenChange = vi.fn()
|
|
24
|
+
render(
|
|
25
|
+
<Root open onOpenChange={onOpenChange}>
|
|
26
|
+
<CloseTrigger asChild>
|
|
27
|
+
<button type="button">Cancel</button>
|
|
28
|
+
</CloseTrigger>
|
|
29
|
+
</Root>,
|
|
30
|
+
)
|
|
31
|
+
const buttons = screen.getAllByRole("button")
|
|
32
|
+
expect(buttons).toHaveLength(1)
|
|
33
|
+
const cancel = screen.getByRole("button", { name: "Cancel" })
|
|
34
|
+
expect(cancel.hasAttribute("aria-label")).toBe(false)
|
|
35
|
+
fireEvent.click(cancel)
|
|
36
|
+
await waitFor(() => expect(onOpenChange).toHaveBeenCalledWith({ open: false }))
|
|
37
|
+
})
|
|
38
|
+
})
|
|
@@ -5,6 +5,7 @@ import { Portal } from "@ark-ui/react/portal"
|
|
|
5
5
|
import { cva, type VariantProps } from "class-variance-authority"
|
|
6
6
|
import { XIcon } from "lucide-react"
|
|
7
7
|
import { type ComponentPropsWithoutRef, type ReactNode, useRef } from "react"
|
|
8
|
+
import type { NoAsChild } from "../../lib/as-child"
|
|
8
9
|
import { cn } from "../../lib/cn"
|
|
9
10
|
import { OverlayContainerProvider } from "../../lib/overlay-container"
|
|
10
11
|
import { OverlayLayerProvider, useLayerGuard } from "../../lib/overlay-layer"
|
|
@@ -121,7 +122,7 @@ const ModalBackdrop = ({ className, testId, ...rest }: ModalBackdropProps) => (
|
|
|
121
122
|
)
|
|
122
123
|
|
|
123
124
|
export type ModalPosition = VariantProps<typeof modalPositioner>["position"]
|
|
124
|
-
export type ModalPositionerProps = ComponentPropsWithoutRef<typeof Ark.Positioner
|
|
125
|
+
export type ModalPositionerProps = NoAsChild<ComponentPropsWithoutRef<typeof Ark.Positioner>> &
|
|
125
126
|
WithTestId & {
|
|
126
127
|
position?: ModalPosition
|
|
127
128
|
}
|
|
@@ -131,6 +132,7 @@ const ModalPositioner = ({
|
|
|
131
132
|
position,
|
|
132
133
|
testId,
|
|
133
134
|
children,
|
|
135
|
+
asChild: _asChild,
|
|
134
136
|
...rest
|
|
135
137
|
}: ModalPositionerProps) => {
|
|
136
138
|
// A ref, not state: overlays read it when they portal, so nothing has to
|
|
@@ -188,23 +190,37 @@ export type ModalCloseTriggerProps = ComponentPropsWithoutRef<typeof Ark.CloseTr
|
|
|
188
190
|
const ModalCloseTrigger = ({
|
|
189
191
|
children,
|
|
190
192
|
className,
|
|
191
|
-
"aria-label": ariaLabel
|
|
193
|
+
"aria-label": ariaLabel,
|
|
192
194
|
testId,
|
|
195
|
+
asChild,
|
|
193
196
|
...rest
|
|
194
|
-
}: ModalCloseTriggerProps) =>
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
197
|
+
}: ModalCloseTriggerProps) =>
|
|
198
|
+
asChild ? (
|
|
199
|
+
// The consumer's element (a "Cancel" button, say) replaces the kit's icon
|
|
200
|
+
// button outright, rather than nesting inside it.
|
|
201
|
+
<Ark.CloseTrigger
|
|
202
|
+
asChild
|
|
200
203
|
aria-label={ariaLabel}
|
|
201
204
|
className={className}
|
|
202
|
-
|
|
205
|
+
{...props({ "data-testid": testId })}
|
|
206
|
+
{...rest}
|
|
203
207
|
>
|
|
204
|
-
{children
|
|
205
|
-
</
|
|
206
|
-
|
|
207
|
-
|
|
208
|
+
{children}
|
|
209
|
+
</Ark.CloseTrigger>
|
|
210
|
+
) : (
|
|
211
|
+
<Ark.CloseTrigger asChild {...rest}>
|
|
212
|
+
<ActionIcon
|
|
213
|
+
variant="subtle"
|
|
214
|
+
color="neutral"
|
|
215
|
+
size="xs"
|
|
216
|
+
aria-label={ariaLabel ?? "Close"}
|
|
217
|
+
className={className}
|
|
218
|
+
testId={testId}
|
|
219
|
+
>
|
|
220
|
+
{children ?? <XIcon />}
|
|
221
|
+
</ActionIcon>
|
|
222
|
+
</Ark.CloseTrigger>
|
|
223
|
+
)
|
|
208
224
|
|
|
209
225
|
export type ModalHeaderProps = ComponentPropsWithoutRef<"div"> & WithTestId
|
|
210
226
|
|
|
@@ -171,14 +171,15 @@ const generateId = (): ToastId => nanoid() as ToastId
|
|
|
171
171
|
const GAP = 12
|
|
172
172
|
|
|
173
173
|
/** Region positioning (fixed + anchored edge) per placement. The stacking
|
|
174
|
-
* geometry itself lives in theme.css, keyed on `data-placement`.
|
|
174
|
+
* geometry itself lives in theme.css, keyed on `data-placement`. `start`/`end`
|
|
175
|
+
* are logical insets, so they follow the document's `dir` (end = left in RTL). */
|
|
175
176
|
const REGION_POSITION = {
|
|
176
|
-
"top-start": "top-4
|
|
177
|
+
"top-start": "top-4 inset-s-4",
|
|
177
178
|
top: "top-4 left-1/2 -translate-x-1/2",
|
|
178
|
-
"top-end": "top-4
|
|
179
|
-
"bottom-start": "bottom-4
|
|
179
|
+
"top-end": "top-4 inset-e-4",
|
|
180
|
+
"bottom-start": "bottom-4 inset-s-4",
|
|
180
181
|
bottom: "bottom-4 left-1/2 -translate-x-1/2",
|
|
181
|
-
"bottom-end": "bottom-4
|
|
182
|
+
"bottom-end": "bottom-4 inset-e-4",
|
|
182
183
|
} as const satisfies Record<NotifyPlacement, string>
|
|
183
184
|
/** Fields `notify.update` copies from the input onto a live toast — the keys
|
|
184
185
|
* shared by `NotifyOptions` and `ToastData` (excludes `id`/`status`/`type`). */
|
|
@@ -175,6 +175,21 @@ describe("notify", () => {
|
|
|
175
175
|
await Promise.resolve()
|
|
176
176
|
expect(notify.getToasts()[0]!).toMatchObject({ type: "success", title: "Saved" })
|
|
177
177
|
})
|
|
178
|
+
|
|
179
|
+
// jsdom has no layout, so this pins the classes: physical left/right would
|
|
180
|
+
// keep an `end` toaster on the right under `dir="rtl"`.
|
|
181
|
+
it.each([
|
|
182
|
+
["top-start", "inset-s-4"],
|
|
183
|
+
["top-end", "inset-e-4"],
|
|
184
|
+
["bottom-start", "inset-s-4"],
|
|
185
|
+
["bottom-end", "inset-e-4"],
|
|
186
|
+
] as const)("anchors %s to the logical %s inset", (placement, inset) => {
|
|
187
|
+
const { Notifications } = createNotifier({ placement, withinPortal: false })
|
|
188
|
+
const markup = renderToStaticMarkup(<Notifications />)
|
|
189
|
+
const region = markup.slice(0, markup.indexOf(">"))
|
|
190
|
+
expect(region).toContain(inset)
|
|
191
|
+
expect(region).not.toMatch(/\b(left|right)-4\b/)
|
|
192
|
+
})
|
|
178
193
|
})
|
|
179
194
|
|
|
180
195
|
/** Split a `CollapseTrigger`'s markup at its glyph: button tag, then icon tag. */
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
} from "lucide-react"
|
|
12
12
|
import { type ComponentPropsWithoutRef, type ReactNode, type Ref, useRef } from "react"
|
|
13
13
|
import { match } from "ts-pattern"
|
|
14
|
+
import type { ForbidAsChild } from "../../lib/as-child"
|
|
14
15
|
import { cn } from "../../lib/cn"
|
|
15
16
|
import type { Color } from "../../lib/colors"
|
|
16
17
|
import { focusStyles } from "../../lib/focus-styles"
|
|
@@ -42,10 +43,10 @@ import type { ToastFields, ToastHue, ToastType } from "./types"
|
|
|
42
43
|
* keyframes (like modal/drawer/popover).
|
|
43
44
|
*/
|
|
44
45
|
|
|
45
|
-
/** The outline surface
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* the border, text and icon through `--c-solid`. */
|
|
46
|
+
/** The outline surface. Deliberately opaque and blurred: a toast floats over
|
|
47
|
+
* arbitrary content. `Alert` (the inline sibling) shares the parts but not
|
|
48
|
+
* this surface — it sits on the page and takes a translucent tint instead.
|
|
49
|
+
* `color` tints the border, text and icon through `--c-solid`. */
|
|
49
50
|
export const notificationSurface = [
|
|
50
51
|
"bg-brand-50/90 dark:bg-brand-950/85",
|
|
51
52
|
"text-(--c-solid) border-(--c-solid) backdrop-blur-lg",
|
|
@@ -236,7 +237,8 @@ export const CollapseTrigger = ({
|
|
|
236
237
|
* the Notifier-managed plumbing (`id` / `status` / `duration`) is optional, so a
|
|
237
238
|
* standalone card is just `<Notification type="success" title="Saved" />`.
|
|
238
239
|
*/
|
|
239
|
-
export type NotificationProps = Omit<NotificationRootProps, "title" | "color"> &
|
|
240
|
+
export type NotificationProps = Omit<NotificationRootProps, "title" | "color" | "asChild"> &
|
|
241
|
+
ForbidAsChild &
|
|
240
242
|
Omit<ToastFields, "id" | "status" | "duration"> &
|
|
241
243
|
Partial<Pick<ToastFields, "id" | "status" | "duration">> &
|
|
242
244
|
ToastHue & {
|
|
@@ -284,6 +286,7 @@ function NotificationComponent({
|
|
|
284
286
|
// Notifier-managed plumbing — not rendered onto the card.
|
|
285
287
|
status: _status,
|
|
286
288
|
duration: _duration,
|
|
289
|
+
asChild: _asChild,
|
|
287
290
|
...rest
|
|
288
291
|
}: NotificationProps) {
|
|
289
292
|
const preset = type ? TOAST_STATUS[type] : undefined
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { ark, type HTMLArkProps } from "@ark-ui/react"
|
|
4
4
|
import { cva, type VariantProps } from "class-variance-authority"
|
|
5
5
|
import { createContext, useContext } from "react"
|
|
6
|
+
import { composeChildren } from "../../lib/as-child"
|
|
6
7
|
import { cn } from "../../lib/cn"
|
|
7
8
|
import type { Color } from "../../lib/colors"
|
|
8
9
|
import { focusStyles } from "../../lib/focus-styles"
|
|
@@ -21,7 +22,9 @@ import type { WithTestId } from "../../lib/test-id"
|
|
|
21
22
|
* - `size` (and `disabled`) can be set per-pill or inherited once from a
|
|
22
23
|
* wrapping `PillGroup` through context — explicit props win.
|
|
23
24
|
*
|
|
24
|
-
* `asChild`
|
|
25
|
+
* `asChild` (from the `ark.span` factory) renders the pill as the consumer's
|
|
26
|
+
* element, a link for a clickable tag, with the label (and remove button)
|
|
27
|
+
* folded inside it.
|
|
25
28
|
*/
|
|
26
29
|
|
|
27
30
|
type PillGroupContextValue = { size?: PillSize; disabled?: boolean }
|
|
@@ -143,6 +146,7 @@ export function Pill<const WithRemoveButton extends boolean = false>({
|
|
|
143
146
|
className,
|
|
144
147
|
classNames,
|
|
145
148
|
testId,
|
|
149
|
+
asChild,
|
|
146
150
|
...rest
|
|
147
151
|
}: PillProps<WithRemoveButton>) {
|
|
148
152
|
const group = useContext(PillGroupContext)
|
|
@@ -151,6 +155,7 @@ export function Pill<const WithRemoveButton extends boolean = false>({
|
|
|
151
155
|
|
|
152
156
|
return (
|
|
153
157
|
<ark.span
|
|
158
|
+
asChild={asChild}
|
|
154
159
|
data-color={color}
|
|
155
160
|
data-disabled={disabled || undefined}
|
|
156
161
|
className={cn(
|
|
@@ -161,25 +166,29 @@ export function Pill<const WithRemoveButton extends boolean = false>({
|
|
|
161
166
|
{...props({ "data-testid": testId })}
|
|
162
167
|
{...rest}
|
|
163
168
|
>
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
169
|
+
{composeChildren(asChild, children, (own) => (
|
|
170
|
+
<>
|
|
171
|
+
<span className={cn("truncate text-trim", classNames?.label)}>{own}</span>
|
|
172
|
+
{withRemoveButton && (
|
|
173
|
+
<button
|
|
174
|
+
type="button"
|
|
175
|
+
aria-label={removeLabel}
|
|
176
|
+
disabled={disabled}
|
|
177
|
+
// Keep focus on the host input (e.g. inside a PillsInput) and stop
|
|
178
|
+
// the click from bubbling to an enclosing option / control.
|
|
179
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
180
|
+
onClick={(e) => {
|
|
181
|
+
e.stopPropagation()
|
|
182
|
+
onRemove?.()
|
|
183
|
+
}}
|
|
184
|
+
className={cn(pillRemove({ size }), classNames?.remove)}
|
|
185
|
+
{...props({ "data-testid": testId && `${testId}-remove` })}
|
|
186
|
+
>
|
|
187
|
+
<RemoveIcon />
|
|
188
|
+
</button>
|
|
189
|
+
)}
|
|
190
|
+
</>
|
|
191
|
+
))}
|
|
183
192
|
</ark.span>
|
|
184
193
|
)
|
|
185
194
|
}
|