@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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
3
|
import type { ReactNode } from "react"
|
|
4
|
+
import type { ForbidAsChild } from "../../lib/as-child"
|
|
4
5
|
import {
|
|
5
6
|
type AccordionRootProps,
|
|
6
7
|
Item,
|
|
@@ -46,14 +47,16 @@ export type AccordionData = ReadonlyArray<AccordionItem>
|
|
|
46
47
|
|
|
47
48
|
export type AccordionProps<Data extends AccordionData = AccordionData> = Omit<
|
|
48
49
|
AccordionRootProps,
|
|
49
|
-
"children"
|
|
50
|
-
> &
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
"children" | "asChild"
|
|
51
|
+
> &
|
|
52
|
+
ForbidAsChild & {
|
|
53
|
+
/** Sections, in order. Each needs its own `content`. */
|
|
54
|
+
data: Data
|
|
55
|
+
}
|
|
54
56
|
|
|
55
57
|
const AccordionComponent = <const Data extends AccordionData>({
|
|
56
58
|
data,
|
|
59
|
+
asChild: _asChild,
|
|
57
60
|
...root
|
|
58
61
|
}: AccordionProps<Data>) => (
|
|
59
62
|
<Root {...root}>
|
|
@@ -232,3 +232,43 @@ describe("Accordion", () => {
|
|
|
232
232
|
expect(html).toContain("Section B")
|
|
233
233
|
})
|
|
234
234
|
})
|
|
235
|
+
|
|
236
|
+
describe("Accordion parts under asChild", () => {
|
|
237
|
+
it("ItemTrigger folds the chevron and label into the consumer's element", () => {
|
|
238
|
+
render(
|
|
239
|
+
<Accordion.Root>
|
|
240
|
+
<Accordion.Item value="a">
|
|
241
|
+
<Accordion.ItemTrigger asChild icon={<svg data-testid="icon" aria-hidden="true" />}>
|
|
242
|
+
<button type="button" data-testid="custom">
|
|
243
|
+
Section A
|
|
244
|
+
</button>
|
|
245
|
+
</Accordion.ItemTrigger>
|
|
246
|
+
</Accordion.Item>
|
|
247
|
+
</Accordion.Root>,
|
|
248
|
+
)
|
|
249
|
+
const trigger = screen.getByTestId("custom")
|
|
250
|
+
expect(trigger.getAttribute("aria-controls")).toBeTruthy()
|
|
251
|
+
expect(trigger.contains(screen.getByTestId("icon"))).toBe(true)
|
|
252
|
+
expect(trigger.querySelector('[data-part="item-indicator"]')).toBeTruthy()
|
|
253
|
+
expect(trigger.textContent).toContain("Section A")
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
it("ItemContent makes the consumer's element the panel, the clipped cell inside it", () => {
|
|
257
|
+
render(
|
|
258
|
+
<Accordion.Root defaultValue={["a"]}>
|
|
259
|
+
<Accordion.Item value="a">
|
|
260
|
+
<Accordion.ItemContent asChild>
|
|
261
|
+
<section data-testid="panel">A panel</section>
|
|
262
|
+
</Accordion.ItemContent>
|
|
263
|
+
</Accordion.Item>
|
|
264
|
+
</Accordion.Root>,
|
|
265
|
+
)
|
|
266
|
+
const panel = screen.getByTestId("panel")
|
|
267
|
+
expect(panel.getAttribute("role")).toBe("region")
|
|
268
|
+
expect(panel.getAttribute("data-state")).toBe("open")
|
|
269
|
+
expect(panel.className).toContain("grid-rows-[1fr]")
|
|
270
|
+
const cell = panel.firstElementChild
|
|
271
|
+
expect(cell?.className).toContain("overflow-clip")
|
|
272
|
+
expect(cell?.textContent).toBe("A panel")
|
|
273
|
+
})
|
|
274
|
+
})
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { Accordion as Ark } from "@ark-ui/react/accordion"
|
|
4
4
|
import { cva, type VariantProps } from "class-variance-authority"
|
|
5
5
|
import { createContext, type ReactNode, useContext } from "react"
|
|
6
|
+
import { composeChildren } from "../../lib/as-child"
|
|
6
7
|
import { cn } from "../../lib/cn"
|
|
7
8
|
import { focusStyles } from "../../lib/focus-styles"
|
|
8
9
|
import { props } from "../../lib/props"
|
|
@@ -257,7 +258,14 @@ export type AccordionItemTriggerProps = Ark.ItemTriggerProps &
|
|
|
257
258
|
icon?: ReactNode
|
|
258
259
|
}
|
|
259
260
|
|
|
260
|
-
const ItemTrigger = ({
|
|
261
|
+
const ItemTrigger = ({
|
|
262
|
+
icon,
|
|
263
|
+
children,
|
|
264
|
+
className,
|
|
265
|
+
testId,
|
|
266
|
+
asChild,
|
|
267
|
+
...rest
|
|
268
|
+
}: AccordionItemTriggerProps) => {
|
|
261
269
|
const { size, chevronPosition, chevron, order } = useContext(AccordionStyleContext)
|
|
262
270
|
const indicator =
|
|
263
271
|
chevron === null ? null : <ItemIndicator>{chevron ?? <ChevronIcon />}</ItemIndicator>
|
|
@@ -265,14 +273,19 @@ const ItemTrigger = ({ icon, children, className, testId, ...rest }: AccordionIt
|
|
|
265
273
|
return (
|
|
266
274
|
<Title order={order} className="contents">
|
|
267
275
|
<Ark.ItemTrigger
|
|
276
|
+
asChild={asChild}
|
|
268
277
|
className={cn(accordionTrigger({ size }), className)}
|
|
269
278
|
{...props({ "data-testid": testId })}
|
|
270
279
|
{...rest}
|
|
271
280
|
>
|
|
272
|
-
{
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
281
|
+
{composeChildren(asChild, children, (own) => (
|
|
282
|
+
<>
|
|
283
|
+
{chevronPosition === "start" && indicator}
|
|
284
|
+
{icon && <span className={accordionIcon}>{icon}</span>}
|
|
285
|
+
<span className={accordionLabel}>{own}</span>
|
|
286
|
+
{chevronPosition === "end" && indicator}
|
|
287
|
+
</>
|
|
288
|
+
))}
|
|
276
289
|
</Ark.ItemTrigger>
|
|
277
290
|
</Title>
|
|
278
291
|
)
|
|
@@ -308,6 +321,7 @@ const ItemContent = ({
|
|
|
308
321
|
className,
|
|
309
322
|
classNames,
|
|
310
323
|
testId,
|
|
324
|
+
asChild,
|
|
311
325
|
...rest
|
|
312
326
|
}: AccordionItemContentProps) => {
|
|
313
327
|
const { size } = useContext(AccordionStyleContext)
|
|
@@ -322,8 +336,11 @@ const ItemContent = ({
|
|
|
322
336
|
classNames={classNames}
|
|
323
337
|
{...props({ "data-testid": testId })}
|
|
324
338
|
{...rest}
|
|
339
|
+
asChild={asChild}
|
|
325
340
|
>
|
|
326
|
-
|
|
341
|
+
{composeChildren(asChild, children, (own) => (
|
|
342
|
+
<div className={accordionContent({ size })}>{own}</div>
|
|
343
|
+
))}
|
|
327
344
|
</Collapse>
|
|
328
345
|
</Ark.ItemContent>
|
|
329
346
|
)}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import { ark, type HTMLArkProps } from "@ark-ui/react"
|
|
4
4
|
import { cva, type VariantProps } from "class-variance-authority"
|
|
5
|
-
import {
|
|
5
|
+
import type { MouseEvent } from "react"
|
|
6
|
+
import { withAsChildContent } 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"
|
|
@@ -28,10 +29,9 @@ import { Spinner } from "../spinner/spinner"
|
|
|
28
29
|
* icon children are decoration.
|
|
29
30
|
*
|
|
30
31
|
* `asChild` renders the single child with ActionIcon's styling. Ark's
|
|
31
|
-
* factory
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* `Button`'s `withAsChildContent`. The `onClick` guard (`preventWhileLoading`)
|
|
32
|
+
* factory clones exactly one element, so `loading`'s spinner replaces
|
|
33
|
+
* *that* element's own children (`withAsChildContent`, `lib/as-child.ts`)
|
|
34
|
+
* rather than the element itself. The `onClick` guard (`preventWhileLoading`)
|
|
35
35
|
* goes on the same clone, since `disabled` doesn't do anything on an
|
|
36
36
|
* arbitrary `asChild` element (e.g. an `<a>`) — same reason the `opacity-50`
|
|
37
37
|
* dimming and `pointer-events-none` blocking are keyed off `data-loading`
|
|
@@ -118,23 +118,6 @@ const preventWhileLoading = (event: MouseEvent) => {
|
|
|
118
118
|
event.stopPropagation()
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
/**
|
|
122
|
-
* Replaces the single `asChild` child's own children with the spinner and
|
|
123
|
-
* guards its `onClick`, mirroring `Button`'s `withAsChildContent`. Falls
|
|
124
|
-
* through unchanged when not loading or the child isn't a single element,
|
|
125
|
-
* letting Ark's own `Children.only` handle the misuse case as it already
|
|
126
|
-
* does.
|
|
127
|
-
*/
|
|
128
|
-
const withAsChildLoading = (child: ReactNode, loading: boolean) => {
|
|
129
|
-
if (!loading) return child
|
|
130
|
-
if (!isValidElement<{ children?: ReactNode; onClick?: (event: MouseEvent) => void }>(child))
|
|
131
|
-
return child
|
|
132
|
-
return cloneElement(child, {
|
|
133
|
-
onClick: preventWhileLoading,
|
|
134
|
-
children: <Spinner label={null} />,
|
|
135
|
-
})
|
|
136
|
-
}
|
|
137
|
-
|
|
138
121
|
export const ActionIcon = ({
|
|
139
122
|
className,
|
|
140
123
|
variant,
|
|
@@ -168,8 +151,10 @@ export const ActionIcon = ({
|
|
|
168
151
|
{...props({ "data-testid": testId })}
|
|
169
152
|
{...rest}
|
|
170
153
|
>
|
|
171
|
-
{asChild ? (
|
|
172
|
-
|
|
154
|
+
{asChild && loading ? (
|
|
155
|
+
withAsChildContent(children, () => <Spinner label={null} />, {
|
|
156
|
+
onClick: preventWhileLoading,
|
|
157
|
+
})
|
|
173
158
|
) : loading ? (
|
|
174
159
|
<Spinner label={null} />
|
|
175
160
|
) : (
|
|
@@ -9,8 +9,14 @@ import { Alert, type AlertProps, alertRoot } from "./alert"
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
describe("alertRoot", () => {
|
|
12
|
-
it("paints
|
|
13
|
-
expect(alertRoot()).toContain("
|
|
12
|
+
it("paints its own translucent status tint, not the toast's opaque panel", () => {
|
|
13
|
+
expect(alertRoot()).toContain("bg-(--c-solid)/8")
|
|
14
|
+
expect(alertRoot()).toContain("border-(--c-solid)/45")
|
|
15
|
+
expect(alertRoot()).not.toContain("dark:bg-brand-950/85")
|
|
16
|
+
expect(alertRoot()).not.toContain("backdrop-blur-lg")
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it("is full-width and un-animated", () => {
|
|
14
20
|
expect(alertRoot()).toContain("w-full")
|
|
15
21
|
expect(alertRoot()).not.toContain("animate-toast-in")
|
|
16
22
|
expect(alertRoot()).not.toContain("w-88")
|
|
@@ -123,3 +129,20 @@ describe("Alert", () => {
|
|
|
123
129
|
expect(classes).toContain("focus:outline-none")
|
|
124
130
|
})
|
|
125
131
|
})
|
|
132
|
+
|
|
133
|
+
describe("Alert as a link", () => {
|
|
134
|
+
it("renders the card inside the consumer's link under asChild", () => {
|
|
135
|
+
const html = renderToStaticMarkup(
|
|
136
|
+
<Alert asChild type="info" title="New version available" description="See what changed">
|
|
137
|
+
{/* biome-ignore lint/a11y/useAnchorContent: the card is what fills the empty link */}
|
|
138
|
+
<a href="/changelog" />
|
|
139
|
+
</Alert>,
|
|
140
|
+
)
|
|
141
|
+
// The link is the root: it opens the markup and carries the card's palette.
|
|
142
|
+
expect(html).toMatch(/^<a href="\/changelog"[^>]* data-color="/)
|
|
143
|
+
expect(html).toContain("New version available")
|
|
144
|
+
expect(html).toContain("See what changed")
|
|
145
|
+
expect(html).toContain("<svg")
|
|
146
|
+
expect(html.endsWith("</a>")).toBe(true)
|
|
147
|
+
})
|
|
148
|
+
})
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { ark, type HTMLArkProps } from "@ark-ui/react"
|
|
4
4
|
import { cva } from "class-variance-authority"
|
|
5
5
|
import type { ReactNode, Ref } from "react"
|
|
6
|
+
import { withAsChildContent } 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"
|
|
@@ -13,22 +14,22 @@ import {
|
|
|
13
14
|
CloseTrigger,
|
|
14
15
|
Description,
|
|
15
16
|
Icon,
|
|
16
|
-
notificationSurface,
|
|
17
17
|
Title,
|
|
18
18
|
TOAST_STATUS,
|
|
19
19
|
} from "../notification/notification"
|
|
20
20
|
import type { ToastHue, ToastType } from "../notification/types"
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* Alert — a wide, static status card
|
|
24
|
-
*
|
|
25
|
-
* `
|
|
26
|
-
*
|
|
27
|
-
*
|
|
23
|
+
* Alert — a wide, static status card with `Notification`'s look (`type`
|
|
24
|
+
* presets, the `Icon` / `Title` / `Description` / `ActionTrigger` /
|
|
25
|
+
* `CloseTrigger` parts) but full-width and always-mounted — for an inline note
|
|
26
|
+
* in page content (a doc callout, a form-level warning), not a floating,
|
|
27
|
+
* self-dismissing toast.
|
|
28
28
|
*
|
|
29
|
-
* It reuses `Notification`'s
|
|
30
|
-
*
|
|
31
|
-
*
|
|
29
|
+
* It reuses `Notification`'s parts and `type` → hue/icon presets directly (see
|
|
30
|
+
* `notification.tsx`). The root surface is its own: a toast floats over
|
|
31
|
+
* arbitrary content and needs its opaque, blurred panel, while an alert sits
|
|
32
|
+
* on the page, so it takes a translucent tint of its hue instead.
|
|
32
33
|
*
|
|
33
34
|
* @example
|
|
34
35
|
* ```tsx
|
|
@@ -41,7 +42,14 @@ import type { ToastHue, ToastType } from "../notification/types"
|
|
|
41
42
|
export type AlertType = Exclude<ToastType, "loading">
|
|
42
43
|
|
|
43
44
|
/** The card surface. Full-width and flat (no toast shadow/animation) — meant
|
|
44
|
-
* to sit inline in page content rather than float above it.
|
|
45
|
+
* to sit inline in page content rather than float above it. Translucent, so
|
|
46
|
+
* it blends into whatever surface hosts it: a faint `--c-solid` wash carries
|
|
47
|
+
* the status across the whole card, edged by a translucent `--c-solid` (the
|
|
48
|
+
* edge `ChoiceCardGroup`'s checked `filled` card uses). The wash comes from
|
|
49
|
+
* `--c-solid`, not `--c-soft`: light-mode `--c-soft` is the near-white 50 step
|
|
50
|
+
* for every hue but `neutral` (a 16% black), so warning/error vanished while
|
|
51
|
+
* info turned into the heaviest card. `text-(--c-solid)` still tints the icon
|
|
52
|
+
* and the `current`-based triggers. */
|
|
45
53
|
export const alertRoot = cva([
|
|
46
54
|
"flex flex-col w-full",
|
|
47
55
|
"rounded-card border px-3 py-3",
|
|
@@ -51,7 +59,7 @@ export const alertRoot = cva([
|
|
|
51
59
|
focusStyles({ offset: false }),
|
|
52
60
|
"[&_svg]:shrink-0 [&_svg]:pointer-events-none",
|
|
53
61
|
"overflow-clip",
|
|
54
|
-
|
|
62
|
+
"bg-(--c-solid)/8 dark:bg-(--c-solid)/12 border-(--c-solid)/45 text-(--c-solid)",
|
|
55
63
|
])
|
|
56
64
|
|
|
57
65
|
export type AlertRootProps = HTMLArkProps<"div"> &
|
|
@@ -113,6 +121,8 @@ function AlertComponent({
|
|
|
113
121
|
icon: _icon,
|
|
114
122
|
withCloseButton = false,
|
|
115
123
|
onClose,
|
|
124
|
+
asChild,
|
|
125
|
+
children,
|
|
116
126
|
...rest
|
|
117
127
|
}: AlertProps) {
|
|
118
128
|
const preset = type ? TOAST_STATUS[type] : undefined
|
|
@@ -123,8 +133,8 @@ function AlertComponent({
|
|
|
123
133
|
// through to the preset the way an omitted (`undefined`) icon does.
|
|
124
134
|
const icon = _icon === undefined ? preset?.icon : _icon
|
|
125
135
|
|
|
126
|
-
|
|
127
|
-
|
|
136
|
+
const card = (
|
|
137
|
+
<>
|
|
128
138
|
<div className="flex flex-row gap-3">
|
|
129
139
|
{icon != null && <Icon>{icon}</Icon>}
|
|
130
140
|
{title != null ? (
|
|
@@ -139,6 +149,22 @@ function AlertComponent({
|
|
|
139
149
|
</div>
|
|
140
150
|
{title != null && description != null && <Description>{description}</Description>}
|
|
141
151
|
{action != null && <div className="mt-2 flex flex-wrap items-center gap-2">{action}</div>}
|
|
152
|
+
</>
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
// Under `asChild` the card becomes the consumer's element (a link to the
|
|
157
|
+
// details, say), with the card's rows folded in ahead of that element's
|
|
158
|
+
// own content.
|
|
159
|
+
<Root color={color} asChild={asChild} {...rest}>
|
|
160
|
+
{asChild
|
|
161
|
+
? withAsChildContent(children, (own) => (
|
|
162
|
+
<>
|
|
163
|
+
{card}
|
|
164
|
+
{own}
|
|
165
|
+
</>
|
|
166
|
+
))
|
|
167
|
+
: card}
|
|
142
168
|
</Root>
|
|
143
169
|
)
|
|
144
170
|
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
useRef,
|
|
12
12
|
useState,
|
|
13
13
|
} from "react"
|
|
14
|
+
import type { NoAsChild } from "../../lib/as-child"
|
|
14
15
|
import { cn } from "../../lib/cn"
|
|
15
16
|
import { mergeRefs } from "../../lib/merge-refs"
|
|
16
17
|
import { props } from "../../lib/props"
|
|
@@ -124,7 +125,7 @@ const SIDEBAR_WIDTH: Record<Size, string> = {
|
|
|
124
125
|
xl: "w-96",
|
|
125
126
|
}
|
|
126
127
|
|
|
127
|
-
export type AppShellSidebarProps = HTMLArkProps<"aside"
|
|
128
|
+
export type AppShellSidebarProps = NoAsChild<HTMLArkProps<"aside">> &
|
|
128
129
|
WithTestId & {
|
|
129
130
|
/** Width when expanded, from the kit's Size scale. @default "md" */
|
|
130
131
|
size?: Size
|
|
@@ -163,6 +164,7 @@ const AppShellSidebar = ({
|
|
|
163
164
|
className,
|
|
164
165
|
children,
|
|
165
166
|
testId,
|
|
167
|
+
asChild: _asChild,
|
|
166
168
|
...rest
|
|
167
169
|
}: AppShellSidebarProps) => {
|
|
168
170
|
const { isMobile, mobileOpen, setMobileOpen } = useAppShell()
|
|
@@ -80,6 +80,36 @@ describe("Breadcrumb", () => {
|
|
|
80
80
|
expect(container.querySelector("svg")).toBeTruthy()
|
|
81
81
|
})
|
|
82
82
|
|
|
83
|
+
// #280 — a router link with no children of its own rendered empty.
|
|
84
|
+
it("puts the house icon inside an empty asChild link", () => {
|
|
85
|
+
render(
|
|
86
|
+
<Breadcrumb.Root>
|
|
87
|
+
<Breadcrumb.Home asChild>
|
|
88
|
+
{/* biome-ignore lint/a11y/useAnchorContent: the house icon is what fills the empty link */}
|
|
89
|
+
<a href="/" data-router-link="" />
|
|
90
|
+
</Breadcrumb.Home>
|
|
91
|
+
</Breadcrumb.Root>,
|
|
92
|
+
)
|
|
93
|
+
const home = screen.getByRole("link", { name: "Home" })
|
|
94
|
+
expect(home.hasAttribute("data-router-link")).toBe(true)
|
|
95
|
+
expect(home.querySelector("svg")).toBeTruthy()
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it("keeps an asChild link's own content instead of the house icon", () => {
|
|
99
|
+
render(
|
|
100
|
+
<Breadcrumb.Root>
|
|
101
|
+
<Breadcrumb.Home asChild>
|
|
102
|
+
<a href="/">
|
|
103
|
+
<span data-testid="logo" />
|
|
104
|
+
</a>
|
|
105
|
+
</Breadcrumb.Home>
|
|
106
|
+
</Breadcrumb.Root>,
|
|
107
|
+
)
|
|
108
|
+
const home = screen.getByRole("link", { name: "Home" })
|
|
109
|
+
expect(home.contains(screen.getByTestId("logo"))).toBe(true)
|
|
110
|
+
expect(home.querySelector("svg")).toBeNull()
|
|
111
|
+
})
|
|
112
|
+
|
|
83
113
|
it("forwards asChild on Breadcrumb.Item onto a custom child instead of rendering its own <a>", () => {
|
|
84
114
|
render(
|
|
85
115
|
<Breadcrumb.Root>
|
|
@@ -2,6 +2,7 @@ import { ark, type HTMLArkProps } from "@ark-ui/react"
|
|
|
2
2
|
import { House } from "lucide-react"
|
|
3
3
|
import type { ElementType, ReactElement, ReactNode } from "react"
|
|
4
4
|
import { Children, cloneElement, isValidElement } from "react"
|
|
5
|
+
import { type ForbidAsChild, withAsChildContent } from "../../lib/as-child"
|
|
5
6
|
import { cn } from "../../lib/cn"
|
|
6
7
|
import { props } from "../../lib/props"
|
|
7
8
|
import type { WithTestId } from "../../lib/test-id"
|
|
@@ -244,7 +245,9 @@ const BreadcrumbHome = ({
|
|
|
244
245
|
testId,
|
|
245
246
|
...rest
|
|
246
247
|
}: BreadcrumbHomeProps) => {
|
|
247
|
-
|
|
248
|
+
// Under `asChild`, `children` is the consumer's link, so the house goes
|
|
249
|
+
// inside it whenever that link brings no content of its own.
|
|
250
|
+
const icon = (own: ReactNode) => own ?? <House aria-hidden size={16} />
|
|
248
251
|
if (asChild) {
|
|
249
252
|
return (
|
|
250
253
|
<li className="shrink-0">
|
|
@@ -255,7 +258,7 @@ const BreadcrumbHome = ({
|
|
|
255
258
|
{...props({ "data-testid": testId })}
|
|
256
259
|
{...rest}
|
|
257
260
|
>
|
|
258
|
-
{icon}
|
|
261
|
+
{withAsChildContent(children, icon)}
|
|
259
262
|
</ark.a>
|
|
260
263
|
</li>
|
|
261
264
|
)
|
|
@@ -270,7 +273,7 @@ const BreadcrumbHome = ({
|
|
|
270
273
|
{...props({ "data-testid": testId })}
|
|
271
274
|
{...rest}
|
|
272
275
|
>
|
|
273
|
-
{icon}
|
|
276
|
+
{icon(children)}
|
|
274
277
|
</LinkComponent>
|
|
275
278
|
</li>
|
|
276
279
|
)
|
|
@@ -284,7 +287,7 @@ const BreadcrumbHome = ({
|
|
|
284
287
|
{...props({ "data-testid": testId })}
|
|
285
288
|
{...rest}
|
|
286
289
|
>
|
|
287
|
-
{icon}
|
|
290
|
+
{icon(children)}
|
|
288
291
|
</ark.a>
|
|
289
292
|
</li>
|
|
290
293
|
)
|
|
@@ -301,13 +304,14 @@ export type BreadcrumbDataItem = {
|
|
|
301
304
|
testId?: string
|
|
302
305
|
}
|
|
303
306
|
|
|
304
|
-
export type BreadcrumbProps = Omit<BreadcrumbRootProps, "children"> &
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
}
|
|
307
|
+
export type BreadcrumbProps = Omit<BreadcrumbRootProps, "children" | "asChild"> &
|
|
308
|
+
ForbidAsChild & {
|
|
309
|
+
/** The crumbs to render, in order. */
|
|
310
|
+
data: readonly BreadcrumbDataItem[]
|
|
311
|
+
/** Renders a leading icon-only `Breadcrumb.Home`. `true` uses the default
|
|
312
|
+
* house icon with no link; pass an object (with `href`) to link it. */
|
|
313
|
+
withHome?: boolean | (BreadcrumbHomeProps & { href: string })
|
|
314
|
+
}
|
|
311
315
|
|
|
312
316
|
/** Renders one `data` entry to a `Breadcrumb.Item` — factored out so its
|
|
313
317
|
* `key` (built from position) isn't a bare index inline in a `.map` JSX
|
|
@@ -324,7 +328,12 @@ const renderDataItem = (item: BreadcrumbDataItem, key: string, current: boolean)
|
|
|
324
328
|
</BreadcrumbItem>
|
|
325
329
|
)
|
|
326
330
|
|
|
327
|
-
const BreadcrumbComponent = ({
|
|
331
|
+
const BreadcrumbComponent = ({
|
|
332
|
+
data,
|
|
333
|
+
withHome,
|
|
334
|
+
asChild: _asChild,
|
|
335
|
+
...rootProps
|
|
336
|
+
}: BreadcrumbProps) => {
|
|
328
337
|
const explicitCurrent = data.some((item) => item.current !== undefined)
|
|
329
338
|
|
|
330
339
|
return (
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import { ark, type HTMLArkProps } from "@ark-ui/react"
|
|
4
4
|
import { cva, type VariantProps } from "class-variance-authority"
|
|
5
|
-
import {
|
|
5
|
+
import type { MouseEvent, ReactNode } from "react"
|
|
6
|
+
import { withAsChildContent } 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"
|
|
@@ -28,10 +29,10 @@ import { Spinner } from "../spinner/spinner"
|
|
|
28
29
|
* required.
|
|
29
30
|
*
|
|
30
31
|
* `asChild` (inherited from `HTMLArkProps`) renders the single child element
|
|
31
|
-
* with Button's styling merged in. Ark's factory
|
|
32
|
-
* only one element can survive the swap — `startSlot`/`endSlot` (and the
|
|
32
|
+
* with Button's styling merged in. Ark's factory clones exactly one element,
|
|
33
|
+
* so only one element can survive the swap — `startSlot`/`endSlot` (and the
|
|
33
34
|
* `loading` spinner, which replaces `startSlot`) are folded into *that*
|
|
34
|
-
* element's own children (
|
|
35
|
+
* element's own children (`withAsChildContent`, `lib/as-child.ts`) rather than
|
|
35
36
|
* rendered as siblings, so they keep showing up even when the child is a
|
|
36
37
|
* link. Common case: `<Button asChild startSlot={<Icon />}><a ...>Go</a></Button>`.
|
|
37
38
|
*
|
|
@@ -165,39 +166,6 @@ const preventWhileLoading = (event: MouseEvent) => {
|
|
|
165
166
|
event.stopPropagation()
|
|
166
167
|
}
|
|
167
168
|
|
|
168
|
-
/**
|
|
169
|
-
* Ark's `asChild` clones the single child element in place of `ark.button`,
|
|
170
|
-
* so the start/end content (icon or spinner) can't be rendered as siblings
|
|
171
|
-
* of `children` (that would hand `Children.only` a `Fragment` and lose
|
|
172
|
-
* Button's own props in the clone). Instead, fold them into the child's own
|
|
173
|
-
* children — same trick as `Breadcrumb.Home`. Falls through unchanged when
|
|
174
|
-
* there's nothing to add or the child isn't a single element, letting Ark's
|
|
175
|
-
* own `Children.only` handle the misuse case as it already does.
|
|
176
|
-
*/
|
|
177
|
-
const withAsChildContent = (
|
|
178
|
-
child: ReactNode,
|
|
179
|
-
startContent: ReactNode,
|
|
180
|
-
endContent: ReactNode,
|
|
181
|
-
size: VariantProps<typeof buttonVariants>["size"],
|
|
182
|
-
loading: boolean,
|
|
183
|
-
) => {
|
|
184
|
-
if (!startContent && !endContent && !loading) return child
|
|
185
|
-
if (!isValidElement<{ children?: ReactNode; onClick?: (event: MouseEvent) => void }>(child))
|
|
186
|
-
return child
|
|
187
|
-
return cloneElement(child, {
|
|
188
|
-
onClick: loading ? preventWhileLoading : child.props.onClick,
|
|
189
|
-
children: (
|
|
190
|
-
<>
|
|
191
|
-
{startContent && (
|
|
192
|
-
<HiddenSlot className={startSlotVariants({ size })}>{startContent}</HiddenSlot>
|
|
193
|
-
)}
|
|
194
|
-
{child.props.children}
|
|
195
|
-
{endContent && <HiddenSlot className={endSlotVariants({ size })}>{endContent}</HiddenSlot>}
|
|
196
|
-
</>
|
|
197
|
-
),
|
|
198
|
-
})
|
|
199
|
-
}
|
|
200
|
-
|
|
201
169
|
export const Button = ({
|
|
202
170
|
className,
|
|
203
171
|
variant,
|
|
@@ -218,6 +186,15 @@ export const Button = ({
|
|
|
218
186
|
const startContent = loading ? <Spinner label={null} /> : startSlot
|
|
219
187
|
const endContent = loading ? null : endSlot
|
|
220
188
|
const resolvedOnClick = loading ? preventWhileLoading : onClick
|
|
189
|
+
const content = (own: ReactNode) => (
|
|
190
|
+
<>
|
|
191
|
+
{startContent && (
|
|
192
|
+
<HiddenSlot className={startSlotVariants({ size })}>{startContent}</HiddenSlot>
|
|
193
|
+
)}
|
|
194
|
+
{own}
|
|
195
|
+
{endContent && <HiddenSlot className={endSlotVariants({ size })}>{endContent}</HiddenSlot>}
|
|
196
|
+
</>
|
|
197
|
+
)
|
|
221
198
|
|
|
222
199
|
return (
|
|
223
200
|
<ark.button
|
|
@@ -235,19 +212,13 @@ export const Button = ({
|
|
|
235
212
|
{...props({ "data-testid": testId })}
|
|
236
213
|
{...rest}
|
|
237
214
|
>
|
|
238
|
-
{asChild
|
|
239
|
-
withAsChildContent(
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
{children}
|
|
246
|
-
{endContent && (
|
|
247
|
-
<HiddenSlot className={endSlotVariants({ size })}>{endContent}</HiddenSlot>
|
|
248
|
-
)}
|
|
249
|
-
</>
|
|
250
|
-
)}
|
|
215
|
+
{asChild
|
|
216
|
+
? withAsChildContent(
|
|
217
|
+
children,
|
|
218
|
+
content,
|
|
219
|
+
loading ? { onClick: preventWhileLoading } : undefined,
|
|
220
|
+
)
|
|
221
|
+
: content(children)}
|
|
251
222
|
</ark.button>
|
|
252
223
|
)
|
|
253
224
|
}
|
|
@@ -160,7 +160,14 @@ const weekNumberCell = cn(
|
|
|
160
160
|
)
|
|
161
161
|
|
|
162
162
|
const navIcon = (direction: "prev" | "next", size: Size | undefined, className?: string) => (
|
|
163
|
-
|
|
163
|
+
// The glyphs are physical; prev sits on the inline-start edge, which is the
|
|
164
|
+
// right one under RTL, so both chevrons mirror to keep pointing outward.
|
|
165
|
+
<ActionIcon
|
|
166
|
+
variant="subtle"
|
|
167
|
+
color="neutral"
|
|
168
|
+
size={size}
|
|
169
|
+
className={cn("rtl:[&_svg]:rotate-180", className)}
|
|
170
|
+
>
|
|
164
171
|
{direction === "prev" ? <ChevronLeftIcon /> : <ChevronRightIcon />}
|
|
165
172
|
</ActionIcon>
|
|
166
173
|
)
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
type Ref,
|
|
8
8
|
useId,
|
|
9
9
|
} from "react"
|
|
10
|
+
import type { ForbidAsChild } from "../../lib/as-child"
|
|
10
11
|
import { cn } from "../../lib/cn"
|
|
11
12
|
import type { Color } from "../../lib/colors"
|
|
12
13
|
import type { GradientDir, GradientProps } from "../../lib/gradient"
|
|
@@ -93,8 +94,9 @@ type ArkRootProps = ComponentPropsWithoutRef<typeof Ark.Root>
|
|
|
93
94
|
|
|
94
95
|
export type CircularProgressProps = Omit<
|
|
95
96
|
ArkRootProps,
|
|
96
|
-
"value" | "defaultValue" | "onValueChange" | "ref" | "className" | "children"
|
|
97
|
+
"value" | "defaultValue" | "onValueChange" | "ref" | "className" | "children" | "asChild"
|
|
97
98
|
> &
|
|
99
|
+
ForbidAsChild &
|
|
98
100
|
VariantProps<typeof circularRange> &
|
|
99
101
|
WithTestId & {
|
|
100
102
|
/** Controlled value (0..max). Pass `null` for the indeterminate state. */
|
|
@@ -140,6 +142,7 @@ export const CircularProgress = ({
|
|
|
140
142
|
classNames,
|
|
141
143
|
style,
|
|
142
144
|
testId,
|
|
145
|
+
asChild: _asChild,
|
|
143
146
|
...rest
|
|
144
147
|
}: CircularProgressProps) => {
|
|
145
148
|
const isGradient = variant === "gradient"
|
|
@@ -227,3 +227,21 @@ describe("Clipboard", () => {
|
|
|
227
227
|
})
|
|
228
228
|
})
|
|
229
229
|
})
|
|
230
|
+
|
|
231
|
+
describe("Clipboard.Input under asChild", () => {
|
|
232
|
+
// `children` doubled as the trailing slot, so the consumer's input landed
|
|
233
|
+
// beside an Ark input that had nothing to clone, and rendered unwired.
|
|
234
|
+
it("wires the consumer's own input as the read-only value field", () => {
|
|
235
|
+
render(
|
|
236
|
+
<Clipboard.Root value="https://example.com/s/abc">
|
|
237
|
+
<Clipboard.Input asChild>
|
|
238
|
+
<input data-testid="custom" />
|
|
239
|
+
</Clipboard.Input>
|
|
240
|
+
</Clipboard.Root>,
|
|
241
|
+
)
|
|
242
|
+
const input = screen.getByTestId("custom") as HTMLInputElement
|
|
243
|
+
expect(screen.getAllByRole("textbox")).toHaveLength(1)
|
|
244
|
+
expect(input.value).toBe("https://example.com/s/abc")
|
|
245
|
+
expect(input.readOnly).toBe(true)
|
|
246
|
+
})
|
|
247
|
+
})
|