@eluan/core 0.5.0 → 0.6.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 +33 -1
- package/dist/{action-popover-D6K9aVFk.cjs → action-popover-DrHKPGqw.cjs} +1 -1
- package/dist/{action-popover-BVJQBuky.js → action-popover-NkXDAHJT.js} +1 -1
- package/dist/action-popover.cjs +1 -1
- package/dist/action-popover.js +1 -1
- package/dist/{avatar-Co-k8KqV.cjs → avatar-B-t3ctR4.cjs} +1 -1
- package/dist/{avatar-CS5f1irF.js → avatar-kDEa0rjF.js} +1 -1
- package/dist/avatar.cjs +1 -1
- package/dist/avatar.js +1 -1
- package/dist/{badge-D9NYZFWH.js → badge-BLZ8V-KC.js} +10 -10
- package/dist/{badge-DXKWztL-.cjs → badge-D1A0Tc79.cjs} +1 -1
- package/dist/badge.cjs +1 -1
- package/dist/badge.js +1 -1
- package/dist/{banner-COlEFRuK.cjs → banner-CNdwDPqA.cjs} +1 -1
- package/dist/{banner-CyYFLZXw.js → banner-DzSp5WfQ.js} +9 -9
- package/dist/banner.cjs +1 -1
- package/dist/banner.js +1 -1
- package/dist/box-DG-tkaYi.cjs +1 -0
- package/dist/box-DKbNgGGG.js +17 -0
- package/dist/box.cjs +1 -0
- package/dist/box.d.ts +1 -0
- package/dist/box.js +5 -0
- package/dist/{breadcrumb-NWXeCH5q.cjs → breadcrumb-BuxXkm6O.cjs} +1 -1
- package/dist/{breadcrumb-Cm1nb9Xj.js → breadcrumb-C6qj-tDx.js} +1 -1
- package/dist/breadcrumb.cjs +1 -1
- package/dist/breadcrumb.js +1 -1
- package/dist/button--_WI-fM6.cjs +1 -0
- package/dist/{button-ANAPDrvs.js → button-DNSNShUc.js} +28 -26
- package/dist/button.cjs +1 -1
- package/dist/button.js +1 -1
- package/dist/{calendar-BpBsomy5.js → calendar-BA2tSwZD.js} +6 -6
- package/dist/{calendar-7LX5YGGT.cjs → calendar-DS5821-k.cjs} +3 -3
- package/dist/calendar.cjs +1 -1
- package/dist/calendar.js +1 -1
- package/dist/{card-C88--zB4.cjs → card-BNdR5aDa.cjs} +1 -1
- package/dist/{card-BC_4C3ns.js → card-BSgN7WSe.js} +1 -1
- package/dist/card.cjs +1 -1
- package/dist/card.js +1 -1
- package/dist/{carousel-BfL7oy_q.cjs → carousel-4AERgboz.cjs} +1 -1
- package/dist/{carousel-DuP0hvF-.js → carousel-Bb7jpzep.js} +1 -1
- package/dist/carousel.cjs +1 -1
- package/dist/carousel.js +1 -1
- package/dist/{checkbox-Bi0Kmuut.js → checkbox-CGUTGery.js} +1 -1
- package/dist/{checkbox-M8DmWKiC.cjs → checkbox-Cq9sHU_S.cjs} +1 -1
- package/dist/{checkbox-group-KBwPhjmW.cjs → checkbox-group-DGXZ4o2-.cjs} +1 -1
- package/dist/{checkbox-group-CQMEJnhD.js → checkbox-group-Tkio3IhK.js} +1 -1
- package/dist/checkbox-group.cjs +1 -1
- package/dist/checkbox-group.js +1 -1
- package/dist/checkbox.cjs +1 -1
- package/dist/checkbox.js +1 -1
- package/dist/{command-BCl0seLL.cjs → command-D02vvta9.cjs} +1 -1
- package/dist/{command-Chs5VlBL.js → command-sUMAxm8S.js} +1 -1
- package/dist/command.cjs +1 -1
- package/dist/command.js +1 -1
- package/dist/components/box.d.ts +12 -0
- package/dist/components/grid.d.ts +35 -0
- package/dist/components/hover-card.d.ts +14 -2
- package/dist/components/icon.d.ts +26 -0
- package/dist/components/layout-shared.d.ts +307 -0
- package/dist/components/multi-select.d.ts +1 -1
- package/dist/components/navigation-drawer.d.ts +25 -5
- package/dist/components/row.d.ts +18 -0
- package/dist/components/stack.d.ts +14 -0
- package/dist/components/tone-shared.d.ts +39 -0
- package/dist/components/tooltip.d.ts +14 -2
- package/dist/components/typography.d.ts +22 -2
- package/dist/components/visually-hidden.d.ts +11 -0
- package/dist/{credit-card-input-DN-8vaFj.js → credit-card-input-9VPlzvDm.js} +1 -1
- package/dist/{credit-card-input-CUqA9CX3.cjs → credit-card-input-DppPJBne.cjs} +1 -1
- package/dist/credit-card-input.cjs +1 -1
- package/dist/credit-card-input.js +1 -1
- package/dist/{date-picker-ni8td8Ru.js → date-picker-M5hLx_1s.js} +2 -2
- package/dist/{date-picker-DGBsfZXx.cjs → date-picker-hE7cDg2B.cjs} +1 -1
- package/dist/date-picker.cjs +1 -1
- package/dist/date-picker.js +1 -1
- package/dist/{datetime-picker-C1d63MaA.cjs → datetime-picker-BeRUPJ7s.cjs} +1 -1
- package/dist/{datetime-picker-DsnHYRK-.js → datetime-picker-CIqBZYMH.js} +3 -3
- package/dist/datetime-picker.cjs +1 -1
- package/dist/datetime-picker.js +1 -1
- package/dist/{decimal-input-yTk35W_5.js → decimal-input-Bg2BPKIr.js} +38 -38
- package/dist/decimal-input-CkTEjo2J.cjs +1 -0
- package/dist/decimal-input.cjs +1 -1
- package/dist/decimal-input.js +1 -1
- package/dist/{dialog-B8eWKqzS.js → dialog-Bsfviqvy.js} +2 -2
- package/dist/dialog-DRAoumvB.cjs +1 -0
- package/dist/dialog.cjs +1 -1
- package/dist/dialog.js +1 -1
- package/dist/{email-input-DFI4h_KN.cjs → email-input-CehmtNUq.cjs} +1 -1
- package/dist/{email-input-pX0hlYV3.js → email-input-DIiY9Q3S.js} +1 -1
- package/dist/email-input.cjs +1 -1
- package/dist/email-input.js +1 -1
- package/dist/{footer-DB0_-IwN.cjs → footer-fovIsy-0.cjs} +1 -1
- package/dist/{footer-B3KUIwXW.js → footer-jWaFq3qk.js} +9 -9
- package/dist/footer.cjs +1 -1
- package/dist/footer.js +1 -1
- package/dist/grid-BDz4Xs6M.cjs +1 -0
- package/dist/grid-BX5vZjDo.js +612 -0
- package/dist/grid.cjs +1 -0
- package/dist/grid.d.ts +1 -0
- package/dist/grid.js +5 -0
- package/dist/{header-CDOWlOAR.js → header-Dnf8AnIx.js} +2 -2
- package/dist/{header-CiZQY_7S.cjs → header-DzItWqW4.cjs} +1 -1
- package/dist/header.cjs +1 -1
- package/dist/header.js +1 -1
- package/dist/hover-card-C5KsTSZR.cjs +1 -0
- package/dist/hover-card-C_FCzE41.js +21 -0
- package/dist/hover-card.cjs +1 -1
- package/dist/hover-card.js +1 -1
- package/dist/icon-BmLOodCQ.cjs +1 -0
- package/dist/icon-BwDfkIdR.js +153 -0
- package/dist/icon.cjs +1 -0
- package/dist/icon.d.ts +1 -0
- package/dist/icon.js +5 -0
- package/dist/index.cjs +10 -5
- package/dist/index.d.ts +6 -0
- package/dist/index.js +612 -541
- package/dist/{input-BrGJn-D9.cjs → input-BcjL2oxv.cjs} +1 -1
- package/dist/{input-Cccufiqn.js → input-CPb9yVU5.js} +8 -8
- package/dist/input-otp-BhJ3ERrY.cjs +1 -0
- package/dist/{input-otp-DmEGB1nu.js → input-otp-CTvJztkH.js} +32 -32
- package/dist/input-otp.cjs +1 -1
- package/dist/input-otp.js +1 -1
- package/dist/input.cjs +1 -1
- package/dist/input.js +1 -1
- package/dist/layout-shared-B_1iX4Hj.js +319 -0
- package/dist/layout-shared-CsBZcT4V.cjs +1 -0
- package/dist/multi-select-CVxkWW29.js +85 -0
- package/dist/multi-select-DBFINH3F.cjs +1 -0
- package/dist/multi-select.cjs +1 -1
- package/dist/multi-select.js +1 -1
- package/dist/navigation-drawer-BCBFtLEq.cjs +1 -0
- package/dist/navigation-drawer-BMyHXhhX.js +198 -0
- package/dist/navigation-drawer.cjs +1 -1
- package/dist/navigation-drawer.js +1 -1
- package/dist/{number-input-vICbRc2y.js → number-input-Cm9YPBOX.js} +1 -1
- package/dist/{number-input-Bc7jUsu-.cjs → number-input-Dr9MbuRV.cjs} +1 -1
- package/dist/number-input.cjs +1 -1
- package/dist/number-input.js +1 -1
- package/dist/{pagination-DTWRjiOm.js → pagination-D2tjMpVU.js} +2 -2
- package/dist/{pagination-4IuE_APs.cjs → pagination-yKmFlFMR.cjs} +1 -1
- package/dist/pagination.cjs +1 -1
- package/dist/pagination.js +1 -1
- package/dist/{password-input-BwnlHPbX.cjs → password-input-CmHubHuU.cjs} +1 -1
- package/dist/{password-input-B9V45d3Q.js → password-input-ljwdGCO6.js} +2 -2
- package/dist/password-input.cjs +1 -1
- package/dist/password-input.js +1 -1
- package/dist/{phone-input-BQjZj5jI.cjs → phone-input-B8VksCer.cjs} +1 -1
- package/dist/{phone-input-CSBpGHvI.js → phone-input-qTL6K8rT.js} +2 -2
- package/dist/phone-input.cjs +1 -1
- package/dist/phone-input.js +1 -1
- package/dist/progress-BpdmBGaX.cjs +1 -0
- package/dist/{progress-Dz_it5I-.js → progress-ChFf9bIq.js} +1 -1
- package/dist/progress.cjs +1 -1
- package/dist/progress.js +1 -1
- package/dist/providers/create-theme.d.ts +10 -1
- package/dist/providers/eluan-provider.d.ts +2 -1
- package/dist/providers/portal-container.d.ts +1 -1
- package/dist/{radio-group-C--1neiq.cjs → radio-group-9gozRouT.cjs} +1 -1
- package/dist/{radio-group-CNMPZx_2.js → radio-group-Bs9933bk.js} +6 -6
- package/dist/radio-group.cjs +1 -1
- package/dist/radio-group.js +1 -1
- package/dist/{rich-text-BZSyuYSo.js → rich-text-DImwK9hN.js} +1 -1
- package/dist/{rich-text-DerWxzdn.cjs → rich-text-DzHLeG7W.cjs} +1 -1
- package/dist/rich-text.cjs +1 -1
- package/dist/rich-text.js +1 -1
- package/dist/row-BYAk7G5d.js +37 -0
- package/dist/row-Bjn-GQAC.cjs +1 -0
- package/dist/row.cjs +1 -0
- package/dist/row.d.ts +1 -0
- package/dist/row.js +5 -0
- package/dist/{search-input-Dmmo-BEL.cjs → search-input-BKTjebg7.cjs} +1 -1
- package/dist/{search-input-bFNW6oiE.js → search-input-Dgr9kT1a.js} +1 -1
- package/dist/search-input.cjs +1 -1
- package/dist/search-input.js +1 -1
- package/dist/select-Cdh991T-.cjs +1 -0
- package/dist/{select-DDSYjKtj.js → select-Dp5AJ6I-.js} +15 -15
- package/dist/select.cjs +1 -1
- package/dist/select.js +1 -1
- package/dist/sheet-CkXjinUG.cjs +1 -0
- package/dist/{sheet-D5HWF66e.js → sheet-uiyHNKEw.js} +6 -6
- package/dist/sheet.cjs +1 -1
- package/dist/sheet.js +1 -1
- package/dist/{slider-CZQBAXup.js → slider-BQmbh0Nl.js} +1 -1
- package/dist/{slider-DdEOapYP.cjs → slider-DK2yk-YK.cjs} +1 -1
- package/dist/slider.cjs +1 -1
- package/dist/slider.js +1 -1
- package/dist/stack-Ck1w2iJu.cjs +1 -0
- package/dist/stack-D2btWM1t.js +27 -0
- package/dist/stack.cjs +1 -0
- package/dist/stack.d.ts +1 -0
- package/dist/stack.js +5 -0
- package/dist/{stepper-D5nDwJUz.cjs → stepper-ByYKX7qw.cjs} +1 -1
- package/dist/{stepper-BtlKiHtd.js → stepper-Copsj87A.js} +4 -4
- package/dist/stepper.cjs +1 -1
- package/dist/stepper.js +1 -1
- package/dist/styles.css +935 -59
- package/dist/{switch-KzBijHMJ.cjs → switch-C2OPCq5Z.cjs} +1 -1
- package/dist/{switch-C7EBLT5H.js → switch-CXBWUZcq.js} +3 -3
- package/dist/switch.cjs +1 -1
- package/dist/switch.js +1 -1
- package/dist/{tabs-DztJ2iVc.cjs → tabs-D8p6Tr5i.cjs} +1 -1
- package/dist/{tabs-C9NKBmH0.js → tabs-TV4_2wi1.js} +9 -9
- package/dist/tabs.cjs +1 -1
- package/dist/tabs.js +1 -1
- package/dist/{textarea-Dl-daLHR.cjs → textarea-BnpQmE74.cjs} +1 -1
- package/dist/{textarea-DXUk1b_-.js → textarea-CJRmnazN.js} +1 -1
- package/dist/textarea.cjs +1 -1
- package/dist/textarea.js +1 -1
- package/dist/{time-input-BPoFvoeM.js → time-input-A603mEFQ.js} +38 -38
- package/dist/time-input-qxljhdEb.cjs +1 -0
- package/dist/time-input.cjs +1 -1
- package/dist/time-input.js +1 -1
- package/dist/{toggle-Dv1VZ5Le.js → toggle-Bx3q15Pu.js} +6 -6
- package/dist/{toggle-Bvh1v32T.cjs → toggle-Z3t4jPdv.cjs} +1 -1
- package/dist/{toggle-group-SyHMwO90.cjs → toggle-group-BZIW4wJp.cjs} +1 -1
- package/dist/{toggle-group-DE8BPZih.js → toggle-group-LaZmOMx_.js} +7 -7
- package/dist/toggle-group.cjs +1 -1
- package/dist/toggle-group.js +1 -1
- package/dist/toggle.cjs +1 -1
- package/dist/toggle.js +1 -1
- package/dist/tooltip-DZqn4wKl.js +23 -0
- package/dist/tooltip-faf1dIXp.cjs +1 -0
- package/dist/tooltip.cjs +1 -1
- package/dist/tooltip.js +1 -1
- package/dist/{tree-view-CyeJR7cW.js → tree-view-DRmm6oL6.js} +23 -23
- package/dist/tree-view-DVQyRQDg.cjs +1 -0
- package/dist/tree-view.cjs +1 -1
- package/dist/tree-view.js +1 -1
- package/dist/visually-hidden-BQMRYGxP.js +14 -0
- package/dist/visually-hidden-DzxxOswl.cjs +1 -0
- package/dist/visually-hidden.cjs +1 -0
- package/dist/visually-hidden.d.ts +1 -0
- package/dist/visually-hidden.js +5 -0
- package/package.json +8 -8
- package/skills/eluan/DESIGN.md +409 -0
- package/skills/eluan/SKILL.md +166 -0
- package/skills/eluan/components/accordion.md +212 -0
- package/skills/eluan/components/action-popover.md +266 -0
- package/skills/eluan/components/aspect-ratio.md +169 -0
- package/skills/eluan/components/avatar.md +277 -0
- package/skills/eluan/components/badge.md +190 -0
- package/skills/eluan/components/banner.md +247 -0
- package/skills/eluan/components/box.md +166 -0
- package/skills/eluan/components/breadcrumb.md +240 -0
- package/skills/eluan/components/button.md +214 -0
- package/skills/eluan/components/calendar.md +192 -0
- package/skills/eluan/components/card.md +270 -0
- package/skills/eluan/components/carousel.md +274 -0
- package/skills/eluan/components/checkbox-group.md +228 -0
- package/skills/eluan/components/checkbox.md +226 -0
- package/skills/eluan/components/code-block.md +193 -0
- package/skills/eluan/components/collapsible.md +240 -0
- package/skills/eluan/components/command.md +359 -0
- package/skills/eluan/components/context-menu.md +296 -0
- package/skills/eluan/components/credit-card-input.md +217 -0
- package/skills/eluan/components/date-picker.md +255 -0
- package/skills/eluan/components/date-time-picker.md +196 -0
- package/skills/eluan/components/decimal-input.md +232 -0
- package/skills/eluan/components/dialog.md +322 -0
- package/skills/eluan/components/drawer.md +292 -0
- package/skills/eluan/components/dropdown-menu.md +450 -0
- package/skills/eluan/components/email-input.md +200 -0
- package/skills/eluan/components/fieldset.md +219 -0
- package/skills/eluan/components/file-input.md +249 -0
- package/skills/eluan/components/footer.md +290 -0
- package/skills/eluan/components/form-label.md +254 -0
- package/skills/eluan/components/grid.md +192 -0
- package/skills/eluan/components/header.md +242 -0
- package/skills/eluan/components/hover-card.md +215 -0
- package/skills/eluan/components/icon.md +161 -0
- package/skills/eluan/components/input-otp.md +227 -0
- package/skills/eluan/components/input.md +249 -0
- package/skills/eluan/components/kbd.md +216 -0
- package/skills/eluan/components/media.md +244 -0
- package/skills/eluan/components/menubar.md +300 -0
- package/skills/eluan/components/multi-select.md +221 -0
- package/skills/eluan/components/navigation-drawer.md +297 -0
- package/skills/eluan/components/navigation-menu.md +291 -0
- package/skills/eluan/components/number-input.md +190 -0
- package/skills/eluan/components/pagination.md +262 -0
- package/skills/eluan/components/password-input.md +218 -0
- package/skills/eluan/components/phone-input.md +205 -0
- package/skills/eluan/components/popover.md +250 -0
- package/skills/eluan/components/progress.md +185 -0
- package/skills/eluan/components/radio-group.md +232 -0
- package/skills/eluan/components/rich-text.md +195 -0
- package/skills/eluan/components/row.md +174 -0
- package/skills/eluan/components/scroll-area.md +203 -0
- package/skills/eluan/components/search-input.md +281 -0
- package/skills/eluan/components/segmented-control.md +201 -0
- package/skills/eluan/components/select.md +296 -0
- package/skills/eluan/components/separator.md +179 -0
- package/skills/eluan/components/sheet.md +326 -0
- package/skills/eluan/components/skeleton.md +202 -0
- package/skills/eluan/components/slider.md +195 -0
- package/skills/eluan/components/spinner.md +187 -0
- package/skills/eluan/components/stack.md +158 -0
- package/skills/eluan/components/stepper.md +236 -0
- package/skills/eluan/components/switch.md +218 -0
- package/skills/eluan/components/table.md +348 -0
- package/skills/eluan/components/tabs.md +277 -0
- package/skills/eluan/components/textarea.md +202 -0
- package/skills/eluan/components/time-input.md +181 -0
- package/skills/eluan/components/toast.md +251 -0
- package/skills/eluan/components/toggle-group.md +241 -0
- package/skills/eluan/components/toggle.md +198 -0
- package/skills/eluan/components/tooltip.md +222 -0
- package/skills/eluan/components/tree-view.md +213 -0
- package/skills/eluan/components/typography.md +207 -0
- package/skills/eluan/components/visually-hidden.md +132 -0
- package/skills/eluan/foundations/colour.md +252 -0
- package/skills/eluan/foundations/elevation.md +57 -0
- package/skills/eluan/foundations/iconography.md +70 -0
- package/skills/eluan/foundations/motion.md +60 -0
- package/skills/eluan/foundations/radius.md +61 -0
- package/skills/eluan/foundations/spacing.md +98 -0
- package/skills/eluan/foundations/theming.md +197 -0
- package/skills/eluan/foundations/typography.md +163 -0
- package/skills/eluan/patterns/empty-states.md +84 -0
- package/skills/eluan/patterns/feedback.md +95 -0
- package/skills/eluan/patterns/forms.md +138 -0
- package/skills/eluan/patterns/navigation.md +95 -0
- package/skills/eluan/patterns/page-layout.md +101 -0
- package/dist/button-Ny6OF8Un.cjs +0 -1
- package/dist/decimal-input-BLmifKF2.cjs +0 -1
- package/dist/dialog-DWYtFhZl.cjs +0 -1
- package/dist/hover-card-BN7Ew2Y1.js +0 -16
- package/dist/hover-card-Dft-08Ha.cjs +0 -1
- package/dist/input-otp-DcZ7wyjs.cjs +0 -1
- package/dist/multi-select-DPoOHWSC.js +0 -74
- package/dist/multi-select-fX5FXYEY.cjs +0 -1
- package/dist/navigation-drawer-BbeDYPhu.js +0 -171
- package/dist/navigation-drawer-DOOHfbY3.cjs +0 -1
- package/dist/progress-DpQjGEyn.cjs +0 -1
- package/dist/select-1Eb3NSrR.cjs +0 -1
- package/dist/sheet-7NP1LuHy.cjs +0 -1
- package/dist/time-input-DR2snTgB.cjs +0 -1
- package/dist/tooltip-BlCQKhUE.js +0 -18
- package/dist/tooltip-Cyu7fWYZ.cjs +0 -1
- package/dist/tree-view-CNvEc1TT.cjs +0 -1
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: CreditCardInput
|
|
3
|
+
use_when: Your app collects card number, expiry and security code in its own fields and needs formatting and brand detection.
|
|
4
|
+
instead_of: Your payment provider's hosted card fields when it offers them; Input for any other text; NumberInput for quantities.
|
|
5
|
+
source: packages/core/src/components/credit-card-input.tsx
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# CreditCardInput
|
|
9
|
+
|
|
10
|
+
## 1. Overview
|
|
11
|
+
|
|
12
|
+
CreditCardInput is a labelled group of three [Input](./input.md)-based fields: card number (grouped by brand, with the detected brand's logo), expiry (MM/YY) and security code (3 digits, 4 for American Express). It reports all three, the brand and a length-based `isValid` through `onCardChange`. The three fields are also exported on their own for custom layouts.
|
|
13
|
+
|
|
14
|
+
## 2. When to use
|
|
15
|
+
|
|
16
|
+
- A checkout or billing form where your app collects card details in its own fields.
|
|
17
|
+
- A custom layout of the same fields, with visible labels, using CreditCardNumberInput, CreditCardExpiryInput and CreditCardCVVInput.
|
|
18
|
+
|
|
19
|
+
### When not to use
|
|
20
|
+
|
|
21
|
+
- Your payment provider offers hosted or embedded card fields → use those, so raw card data never passes through your app.
|
|
22
|
+
- Any other text → use [Input](./input.md).
|
|
23
|
+
- A numeric amount to charge → use [DecimalInput](./decimal-input.md) (`CurrencyInput`).
|
|
24
|
+
|
|
25
|
+
CreditCardInput earns its place through masking and formatting: brand-specific digit groups, the MM/YY slash, brand detection and per-brand length limits. Its validation only checks lengths.
|
|
26
|
+
|
|
27
|
+
## 3. Anatomy
|
|
28
|
+
|
|
29
|
+
1. **Group**: a `role="group"` container named "Credit card details". The number field spans the full width; expiry and security code share a two-column row below. Gaps are `--spacing-md`.
|
|
30
|
+
2. **Card number field**: leading card icon, digits in groups, trailing brand logo (or a generic card icon until a brand is detected).
|
|
31
|
+
3. **Expiry field**: leading calendar icon, MM/YY.
|
|
32
|
+
4. **Security code field**: leading lock icon, 3 or 4 digits.
|
|
33
|
+
5. **Error messages**: one visually hidden `role="alert"` message per field ("Enter a valid card number", "Enter a valid expiration date", "Enter a valid security code").
|
|
34
|
+
|
|
35
|
+
The composite shows no visible labels; each field is named with `aria-label` and shows a placeholder.
|
|
36
|
+
|
|
37
|
+
## 4. Variants
|
|
38
|
+
|
|
39
|
+
| Export | Use for |
|
|
40
|
+
| --- | --- |
|
|
41
|
+
| `CreditCardInput` | The complete group, with validation and one `onCardChange`. |
|
|
42
|
+
| `CreditCardNumberInput` | Card number on its own: formatting, brand detection and logo. |
|
|
43
|
+
| `CreditCardExpiryInput` | Expiry on its own: MM/YY formatting. |
|
|
44
|
+
| `CreditCardCVVInput` | Security code on its own; pass `cardType` so its length follows the brand. |
|
|
45
|
+
|
|
46
|
+
## 5. Sizes
|
|
47
|
+
|
|
48
|
+
No size prop. Each field is `--size-lg` tall, from Input, and follows density.
|
|
49
|
+
|
|
50
|
+
## 6. States
|
|
51
|
+
|
|
52
|
+
| State | Looks like | Notes |
|
|
53
|
+
| --- | --- | --- |
|
|
54
|
+
| Default | Three Input fields with icons and placeholders | |
|
|
55
|
+
| Focus | Border and 1px outline in `--focus-ring`, 1px offset | Never remove or restyle the focus ring. |
|
|
56
|
+
| Brand detected | The trailing icon becomes the brand logo, drawn in `currentColor` | Visa, Mastercard, American Express, Discover, Diners Club, JCB, UnionPay. |
|
|
57
|
+
| Invalid (composite) | `--destructive-border` border, `aria-invalid`, hidden message announced | Only after the user leaves a field that has content failing its length check. Sighted users see only the border colour. |
|
|
58
|
+
| Disabled | All three fields disabled | `disabled` on the composite reaches every field. |
|
|
59
|
+
|
|
60
|
+
## 7. Content guidelines
|
|
61
|
+
|
|
62
|
+
- Introduce the group with a heading or a Fieldset legend: "Payment details" or "Card".
|
|
63
|
+
- In a custom layout, label the fields "Card number", "Expiry date" and "Security code".
|
|
64
|
+
- Write card errors that say what to check: "Check the card number".
|
|
65
|
+
|
|
66
|
+
| Do | Don't |
|
|
67
|
+
| --- | --- |
|
|
68
|
+
| Card number | CC # |
|
|
69
|
+
| Security code | CVV2/CVC2/CID |
|
|
70
|
+
| Check the expiry date | Payment error |
|
|
71
|
+
|
|
72
|
+
## 8. Rules
|
|
73
|
+
|
|
74
|
+
1. Never log card data or send it anywhere but your payment provider. `onCardChange` carries the full number and security code.
|
|
75
|
+
2. Don't trust `isValid` for payment. It checks lengths only: no Luhn checksum, no month range, no past-date check. Let the provider validate.
|
|
76
|
+
3. Read card data from `onCardChange` (or each part's `onValueChange`). The fields have no `name`, so native form submission doesn't include them.
|
|
77
|
+
4. Put the composite under a heading or in a [Fieldset](./fieldset.md) with a legend. When you need visible field labels, compose the parts with Label instead.
|
|
78
|
+
5. When composing parts, pass the brand from the number field's `onValueChange` to CreditCardCVVInput's `cardType`.
|
|
79
|
+
6. Treat the parts as uncontrolled. They ignore `value`; don't pass `defaultValue`.
|
|
80
|
+
7. Keep the default `autoComplete` values (`cc-number`, `cc-exp`, `cc-csc`) so browsers and password managers can fill the card.
|
|
81
|
+
8. Never pass `className` or `style`; they're dropped. Put width on a wrapper.
|
|
82
|
+
|
|
83
|
+
## 9. Dos and don'ts
|
|
84
|
+
|
|
85
|
+
**Do:** keep card data in memory and hand it to the provider on submit.
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
<CreditCardInput onCardChange={(card) => { cardRef.current = card; }} />
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Don't:** log or persist the payload.
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
<CreditCardInput onCardChange={(card) => console.log(card)} />
|
|
95
|
+
<CreditCardInput onCardChange={(card) => localStorage.setItem("card", JSON.stringify(card))} />
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Do:** link the brand to the security code when composing parts.
|
|
99
|
+
|
|
100
|
+
```tsx
|
|
101
|
+
<CreditCardNumberInput id="card-number" onValueChange={(digits, type) => { setNumber(digits); setCardType(type); }} />
|
|
102
|
+
<CreditCardCVVInput id="card-cvc" cardType={cardType} onValueChange={setCvc} />
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Don't:** use a plain Input for card numbers.
|
|
106
|
+
|
|
107
|
+
```tsx
|
|
108
|
+
<Input placeholder="Card number" maxLength={19} />
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## 10. Accessibility
|
|
112
|
+
|
|
113
|
+
- Role: the composite is a `group` named "Credit card details"; each field is a `textbox` with `inputMode="numeric"`.
|
|
114
|
+
- Labels: the fields are named "Card number", "Expiration date (MM/YY)" and "Security code (CVV)" by default. A passed `aria-label` or `aria-labelledby` replaces the default. Because the default `aria-label` outranks `<label htmlFor>`, pass `aria-labelledby` pointing at your Label's `id` when composing parts with visible labels.
|
|
115
|
+
- Errors (composite): after blur, an invalid field gets `aria-invalid` and `aria-describedby` pointing at its message, which is announced through `role="alert"`.
|
|
116
|
+
- Keyboard: standard text input; Tab moves number, expiry, security code.
|
|
117
|
+
- Brand logos and field icons are `aria-hidden`.
|
|
118
|
+
- Contrast: handled by the theme. Don't override colours.
|
|
119
|
+
|
|
120
|
+
## 11. Behaviour
|
|
121
|
+
|
|
122
|
+
- Card number: non-digits are removed. Digits are grouped 4-4-4-4, or 4-6-5 for American Express and 4-6-4 for Diners Club, and capped at the brand's longest length (19 when unknown).
|
|
123
|
+
- Expiry: non-digits are removed and a slash is added after the month. Backspacing from just after the slash puts it straight back, so the user has to move the caret or select to delete the month.
|
|
124
|
+
- Security code: digits only, capped at 4 for American Express and 3 otherwise.
|
|
125
|
+
- Values reported are digits only: the number without spaces, the expiry as `MMYY`.
|
|
126
|
+
- `onCardChange` fires on each edit, never on mount.
|
|
127
|
+
- Responsive: the expiry and security code row stays two columns at every width.
|
|
128
|
+
- Motion: colour transitions over 150ms, from Input. Don't add your own.
|
|
129
|
+
|
|
130
|
+
## 12. API
|
|
131
|
+
|
|
132
|
+
<!-- api:start -->
|
|
133
|
+
### CreditCardInput
|
|
134
|
+
|
|
135
|
+
| Prop | Type | Default | Description |
|
|
136
|
+
| --- | --- | --- | --- |
|
|
137
|
+
| `onCardChange` | `(data: { number: string; expiry: string; cvv: string; cardType: CardType; isValid: boolean }) => void` | | Fires on every edit with digits-only values, the brand and length-based validity. |
|
|
138
|
+
| `disabled` | `boolean` | | Disables all three fields. |
|
|
139
|
+
|
|
140
|
+
Takes no other props. `ref` reaches the group `<div>`. `CardType` is `"visa" \| "mastercard" \| "amex" \| "discover" \| "diners" \| "jcb" \| "unionpay" \| "unknown"`.
|
|
141
|
+
|
|
142
|
+
### CreditCardNumberInput
|
|
143
|
+
|
|
144
|
+
| Prop | Type | Default | Description |
|
|
145
|
+
| --- | --- | --- | --- |
|
|
146
|
+
| `onValueChange` | `(value: string, cardType: CardType) => void` | | Digits without spaces, and the detected brand. |
|
|
147
|
+
| `...props` | `InputHTMLAttributes` without `className`, `style`, `size`, `type`, `onChange` | | Native attributes: `id`, `onBlur`, `required`, `aria-*`. Defaults `aria-label="Card number"`, `autoComplete="cc-number"`, a sample placeholder. `value` is ignored. |
|
|
148
|
+
|
|
149
|
+
### CreditCardExpiryInput
|
|
150
|
+
|
|
151
|
+
| Prop | Type | Default | Description |
|
|
152
|
+
| --- | --- | --- | --- |
|
|
153
|
+
| `onValueChange` | `(value: string) => void` | | Digits only, as `MMYY`. |
|
|
154
|
+
| `...props` | `InputHTMLAttributes` without `className`, `style`, `size`, `type`, `onChange` | | Defaults `aria-label="Expiration date (MM/YY)"`, `autoComplete="cc-exp"`, placeholder `MM/YY`. `value` is ignored. |
|
|
155
|
+
|
|
156
|
+
### CreditCardCVVInput
|
|
157
|
+
|
|
158
|
+
| Prop | Type | Default | Description |
|
|
159
|
+
| --- | --- | --- | --- |
|
|
160
|
+
| `cardType` | `CardType` | `"unknown"` | `"amex"` allows 4 digits; anything else allows 3. |
|
|
161
|
+
| `onValueChange` | `(value: string) => void` | | Digits only. |
|
|
162
|
+
| `...props` | `InputHTMLAttributes` without `className`, `style`, `size`, `type`, `onChange` | | Defaults `aria-label="Security code (CVV)"`, `autoComplete="cc-csc"`, `maxLength` from `cardType`. `value` is ignored. |
|
|
163
|
+
<!-- api:end -->
|
|
164
|
+
|
|
165
|
+
## 13. Examples
|
|
166
|
+
|
|
167
|
+
```tsx
|
|
168
|
+
import { useRef, useState, type FormEvent } from "react";
|
|
169
|
+
import { Banner, Button, CreditCardInput, Fieldset, FieldsetLegend } from "@eluan/core";
|
|
170
|
+
|
|
171
|
+
type Card = { number: string; expiry: string; cvv: string; cardType: string; isValid: boolean };
|
|
172
|
+
|
|
173
|
+
export function PaymentForm({ onPay }: { onPay: (card: Card) => Promise<string | null> }) {
|
|
174
|
+
const cardRef = useRef<Card | null>(null);
|
|
175
|
+
const [error, setError] = useState<string | null>(null);
|
|
176
|
+
|
|
177
|
+
async function handleSubmit(event: FormEvent<HTMLFormElement>) {
|
|
178
|
+
event.preventDefault();
|
|
179
|
+
const card = cardRef.current;
|
|
180
|
+
if (!card?.isValid) return setError("Check the card number, expiry date and security code.");
|
|
181
|
+
setError(await onPay(card));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return (
|
|
185
|
+
<form onSubmit={handleSubmit} noValidate style={{ display: "flex", flexDirection: "column", gap: "var(--spacing-lg)" }}>
|
|
186
|
+
{error && (
|
|
187
|
+
<Banner variant="destructive" position="inline" role="alert">
|
|
188
|
+
{error}
|
|
189
|
+
</Banner>
|
|
190
|
+
)}
|
|
191
|
+
<Fieldset>
|
|
192
|
+
<FieldsetLegend>Payment details</FieldsetLegend>
|
|
193
|
+
<CreditCardInput
|
|
194
|
+
onCardChange={(card) => {
|
|
195
|
+
cardRef.current = card;
|
|
196
|
+
}}
|
|
197
|
+
/>
|
|
198
|
+
</Fieldset>
|
|
199
|
+
<div style={{ display: "flex", justifyContent: "flex-end" }}>
|
|
200
|
+
<Button type="submit">Pay $49.00</Button>
|
|
201
|
+
</div>
|
|
202
|
+
</form>
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## 14. Related components
|
|
208
|
+
|
|
209
|
+
- [Input](./input.md): the base field for all three parts.
|
|
210
|
+
- [Fieldset](./fieldset.md): groups the card fields under a legend.
|
|
211
|
+
- [Banner](./banner.md): a payment error for the whole form.
|
|
212
|
+
- [DecimalInput](./decimal-input.md): amounts, with CurrencyInput.
|
|
213
|
+
- [Forms pattern](../patterns/forms.md): field structure, errors and submit.
|
|
214
|
+
|
|
215
|
+
## 15. Common agent mistakes
|
|
216
|
+
|
|
217
|
+
_Filled from evals._
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: DatePicker
|
|
3
|
+
use_when: The user picks one date (DatePicker) or a start and end date (DateRangePicker) in a form or filter bar.
|
|
4
|
+
instead_of: Input type=date or a hand-built Popover and Calendar; DateTimePicker when a time is needed; TimeInput for a time alone; Calendar for an always-visible grid.
|
|
5
|
+
source: packages/core/src/components/date-picker.tsx
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# DatePicker
|
|
9
|
+
|
|
10
|
+
## 1. Overview
|
|
11
|
+
|
|
12
|
+
DatePicker is a field-style trigger that opens a Calendar in a Popover. The module exports two components: `DatePicker` for one date and `DateRangePicker` for a start and end date. The trigger shows the formatted value, or a placeholder when empty.
|
|
13
|
+
|
|
14
|
+
This file is also where to choose between Eluan's date and time components.
|
|
15
|
+
|
|
16
|
+
## 2. When to use
|
|
17
|
+
|
|
18
|
+
Pick the component by what the user is choosing:
|
|
19
|
+
|
|
20
|
+
| The user picks… | Use |
|
|
21
|
+
| --- | --- |
|
|
22
|
+
| One date in a form or filter: due date, start date | `DatePicker` |
|
|
23
|
+
| A start and end date: report period, booking, a date filter in a toolbar | `DateRangePicker` |
|
|
24
|
+
| One moment with a time of day: scheduled send, meeting start | [DateTimePicker](./date-time-picker.md) |
|
|
25
|
+
| A time of day with no date: opening hours, daily reminder | [TimeInput](./time-input.md) |
|
|
26
|
+
| A date on an always-visible month grid, or several separate dates | [Calendar](./calendar.md) |
|
|
27
|
+
|
|
28
|
+
- A filter bar with a date range uses `DateRangePicker`, next to Select filters and an `outline` reset Button.
|
|
29
|
+
|
|
30
|
+
### When not to use
|
|
31
|
+
|
|
32
|
+
- The time of day matters → use [DateTimePicker](./date-time-picker.md).
|
|
33
|
+
- Only a time → use [TimeInput](./time-input.md).
|
|
34
|
+
- The grid should stay visible, or the user picks several separate dates → use [Calendar](./calendar.md) inline.
|
|
35
|
+
- A birth date or any date many years away → use an [Input](./input.md) with a format hint. The year Select inside the calendar only lists ten years around the current one.
|
|
36
|
+
|
|
37
|
+
## 3. Anatomy
|
|
38
|
+
|
|
39
|
+
1. **Trigger**: a full-width Button in the `input` variant (`inputMuted` while empty), with a leading calendar icon and the value or placeholder text.
|
|
40
|
+
2. **Popover**: opens below the trigger, aligned to its start edge.
|
|
41
|
+
3. **Calendar**: one month for `DatePicker`, two months side by side for `DateRangePicker`. See [Calendar](./calendar.md).
|
|
42
|
+
|
|
43
|
+
## 4. Variants
|
|
44
|
+
|
|
45
|
+
There's no `variant` prop. Choose the component:
|
|
46
|
+
|
|
47
|
+
| Component | Use for |
|
|
48
|
+
| --- | --- |
|
|
49
|
+
| `DatePicker` | One date. Closes as soon as a date is picked. |
|
|
50
|
+
| `DateRangePicker` | A start and end date. Shows two months and stays open until the user presses Escape or clicks outside. |
|
|
51
|
+
|
|
52
|
+
## 5. Sizes
|
|
53
|
+
|
|
54
|
+
No size prop. The trigger is a default-size Button (`--size-lg` tall) and always fills its container's width. Set the width on a wrapper.
|
|
55
|
+
|
|
56
|
+
## 6. States
|
|
57
|
+
|
|
58
|
+
| State | Looks like | Notes |
|
|
59
|
+
| --- | --- | --- |
|
|
60
|
+
| Empty | Placeholder in `--interactive-fg-alt` next to the calendar icon | |
|
|
61
|
+
| Filled | Formatted value in `--interactive-fg` | Range shows "from - to"; after the first click both ends are the same day. |
|
|
62
|
+
| Hover | Trigger background fills | |
|
|
63
|
+
| Focus | 1px outline in `--focus-ring`, 1px offset | Never remove or restyle the focus ring. |
|
|
64
|
+
| Open | Popover below the trigger; focus moves into the calendar | |
|
|
65
|
+
| Disabled | `--interactive-bg-disabled` fill, `--interactive-fg-disabled` text; skipped by Tab | |
|
|
66
|
+
| Error | No built-in error state | Put a FormMessage under the picker and reference it with `aria-describedby` on the group wrapper (see Rules). |
|
|
67
|
+
| Range across months | A selected day from the adjacent month is close to invisible | DateRangePicker always shows outside days and has no prop to hide them; don't patch it. |
|
|
68
|
+
|
|
69
|
+
## 7. Content guidelines
|
|
70
|
+
|
|
71
|
+
- Write the placeholder as what to pick: "Pick a due date", "Any date". It is not a label; add one anyway.
|
|
72
|
+
- Keep the year in `dateFormat`. The defaults are `"PPP"` ("October 27th, 2026") for DatePicker and `"LLL dd, y"` ("Oct 27, 2026") for each end of a range.
|
|
73
|
+
- Prefer formats with a month name over all-number formats such as `"MM/dd/yyyy"`, which read differently by region.
|
|
74
|
+
- Trigger text is English: `dateFormat` uses date-fns without a locale.
|
|
75
|
+
|
|
76
|
+
| Do | Don't |
|
|
77
|
+
| --- | --- |
|
|
78
|
+
| Pick a due date | Click to select |
|
|
79
|
+
| Any date | dd/mm/yyyy |
|
|
80
|
+
|
|
81
|
+
## 8. Rules
|
|
82
|
+
|
|
83
|
+
1. Control the value: pass `value` and `onValueChange`. The pickers keep no value of their own, so without `value` the trigger keeps showing the placeholder.
|
|
84
|
+
2. Label every picker. The trigger accepts no `id` or `aria-label`, so `Label htmlFor` can't reach it: give the Label an `id` and wrap the picker in `<div role="group" aria-labelledby="…">`. Add `aria-describedby` there for a hint or error.
|
|
85
|
+
3. Handle `undefined` from `DateRangePicker`. Its `onValueChange` is typed as always passing a range, but clicking the single selected day again clears it and passes `undefined`. Fall back to an empty range.
|
|
86
|
+
4. Set width on a wrapper; the trigger always stretches to fill it.
|
|
87
|
+
5. Use `DateRangePicker` for a period, not two DatePickers.
|
|
88
|
+
6. For native form submission, add your own `<input type="hidden">` with the date as an ISO string; the pickers have no `name`.
|
|
89
|
+
7. Never pass `className` or `style`; the props don't accept them.
|
|
90
|
+
|
|
91
|
+
## 9. Dos and don'ts
|
|
92
|
+
|
|
93
|
+
**Do:** control the value and name the field.
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
<div style={{ display: "flex", flexDirection: "column", gap: "var(--spacing-sm)" }}>
|
|
97
|
+
<Label id="due-date-label" required>Due date</Label>
|
|
98
|
+
<div role="group" aria-labelledby="due-date-label">
|
|
99
|
+
<DatePicker value={dueDate} onValueChange={setDueDate} placeholder="Pick a due date" />
|
|
100
|
+
</div>
|
|
101
|
+
</div>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**Don't:** leave it uncontrolled or rely on the placeholder as the label.
|
|
105
|
+
|
|
106
|
+
```tsx
|
|
107
|
+
<DatePicker placeholder="Due date" />
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**Do:** guard against a cleared range.
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
<DateRangePicker value={range} onValueChange={(next) => setRange(next ?? { from: undefined, to: undefined })} />
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**Don't:** build your own Popover and Calendar for a plain date field.
|
|
117
|
+
|
|
118
|
+
```tsx
|
|
119
|
+
<Popover>
|
|
120
|
+
<PopoverTrigger asChild><Button variant="input">{label}</Button></PopoverTrigger>
|
|
121
|
+
<PopoverContent><Calendar mode="single" selected={day} onSelect={setDay} /></PopoverContent>
|
|
122
|
+
</Popover>
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## 10. Accessibility
|
|
126
|
+
|
|
127
|
+
- Role: the trigger is a `button` with `aria-haspopup="dialog"` and `aria-expanded` (Radix Popover); the open panel is a `dialog`. The calendar inside is a `grid` (see [Calendar](./calendar.md)).
|
|
128
|
+
- Label: the trigger's name is its text, the formatted date or the placeholder. Name the field with a visible label and a `role="group"` wrapper (Rules 2).
|
|
129
|
+
- Keyboard: Enter or Space opens the popover. Inside, the calendar's arrow, Page Up/Down and Home/End keys apply, and Enter or Space picks. Escape closes.
|
|
130
|
+
- Focus: on open, focus moves to the selected day, or today. The popover doesn't trap focus. On close, focus returns to the trigger.
|
|
131
|
+
- Contrast: handled by the theme. Don't override colours.
|
|
132
|
+
|
|
133
|
+
## 11. Behaviour
|
|
134
|
+
|
|
135
|
+
- Responsive: the trigger fills its container. DatePicker's popover matches the trigger's width (never narrower than the calendar), so a wider trigger stretches the grid. DateRangePicker's popover sizes to its two months, which stack below a 640px viewport.
|
|
136
|
+
- Picking a range: the first click selects a one-day range; the next click before or after it extends the range.
|
|
137
|
+
- Opening month: DateRangePicker opens on the month of `value.from`. DatePicker always opens on the current month, even when its value is in another month.
|
|
138
|
+
- Clearing: clicking the selected date again clears it. DatePicker then calls `onValueChange(undefined)` and closes.
|
|
139
|
+
- Overflow and truncation: the trigger text doesn't wrap. Give a range picker room for both dates.
|
|
140
|
+
- Motion: none of its own. Don't add any.
|
|
141
|
+
|
|
142
|
+
## 12. API
|
|
143
|
+
|
|
144
|
+
<!-- api:start -->
|
|
145
|
+
### DatePicker
|
|
146
|
+
|
|
147
|
+
| Prop | Type | Default | Description |
|
|
148
|
+
| --- | --- | --- | --- |
|
|
149
|
+
| `value` | `Date` | | The selected date. |
|
|
150
|
+
| `onValueChange` | `(date: Date \| undefined) => void` | | Called when a date is picked, with `undefined` when it's cleared. |
|
|
151
|
+
| `placeholder` | `string` | `"Pick a date"` | Trigger text while empty. |
|
|
152
|
+
| `dateFormat` | `string` | `"PPP"` | date-fns format for the trigger text. |
|
|
153
|
+
| `disabled` | `boolean` | `false` | Disables the trigger. |
|
|
154
|
+
| `ref` | `Ref<HTMLButtonElement>` | | Forwarded to the trigger button. |
|
|
155
|
+
|
|
156
|
+
### DateRangePicker
|
|
157
|
+
|
|
158
|
+
| Prop | Type | Default | Description |
|
|
159
|
+
| --- | --- | --- | --- |
|
|
160
|
+
| `value` | `{ from: Date \| undefined; to: Date \| undefined }` | | The selected range. |
|
|
161
|
+
| `onValueChange` | `(range: { from: Date \| undefined; to: Date \| undefined }) => void` | | Called on every pick. Receives `undefined` when the range is cleared, despite the type. |
|
|
162
|
+
| `placeholder` | `string` | `"Pick a date range"` | Trigger text while empty. |
|
|
163
|
+
| `dateFormat` | `string` | `"LLL dd, y"` | date-fns format for each end of the range. |
|
|
164
|
+
| `disabled` | `boolean` | `false` | Disables the trigger. |
|
|
165
|
+
| `ref` | `Ref<HTMLButtonElement>` | | Forwarded to the trigger button. |
|
|
166
|
+
|
|
167
|
+
Neither component accepts other props: no `id`, `name`, `aria-*`, `className` or `style`.
|
|
168
|
+
<!-- api:end -->
|
|
169
|
+
|
|
170
|
+
## 13. Examples
|
|
171
|
+
|
|
172
|
+
A filter bar with a date range, a status filter and a reset action.
|
|
173
|
+
|
|
174
|
+
```tsx
|
|
175
|
+
import * as React from "react";
|
|
176
|
+
import {
|
|
177
|
+
Button,
|
|
178
|
+
DateRangePicker,
|
|
179
|
+
Label,
|
|
180
|
+
Select,
|
|
181
|
+
SelectContent,
|
|
182
|
+
SelectItem,
|
|
183
|
+
SelectTrigger,
|
|
184
|
+
SelectValue,
|
|
185
|
+
} from "@eluan/core";
|
|
186
|
+
|
|
187
|
+
type Range = { from: Date | undefined; to: Date | undefined };
|
|
188
|
+
const anyDate: Range = { from: undefined, to: undefined };
|
|
189
|
+
|
|
190
|
+
export function OrderFilters() {
|
|
191
|
+
const [range, setRange] = React.useState<Range>(anyDate);
|
|
192
|
+
const [status, setStatus] = React.useState("all");
|
|
193
|
+
|
|
194
|
+
const field = { display: "flex", flexDirection: "column", gap: "var(--spacing-sm)" } as const;
|
|
195
|
+
|
|
196
|
+
return (
|
|
197
|
+
<div
|
|
198
|
+
style={{
|
|
199
|
+
display: "grid",
|
|
200
|
+
gridTemplateColumns: "2fr 1fr auto",
|
|
201
|
+
alignItems: "end",
|
|
202
|
+
gap: "var(--spacing-md)",
|
|
203
|
+
}}
|
|
204
|
+
>
|
|
205
|
+
<div style={field}>
|
|
206
|
+
<Label id="order-date-label">Order date</Label>
|
|
207
|
+
<div role="group" aria-labelledby="order-date-label">
|
|
208
|
+
<DateRangePicker
|
|
209
|
+
value={range}
|
|
210
|
+
onValueChange={(next) => setRange(next ?? anyDate)}
|
|
211
|
+
placeholder="Any date"
|
|
212
|
+
/>
|
|
213
|
+
</div>
|
|
214
|
+
</div>
|
|
215
|
+
<div style={field}>
|
|
216
|
+
<Label htmlFor="order-status">Status</Label>
|
|
217
|
+
<Select value={status} onValueChange={setStatus}>
|
|
218
|
+
<SelectTrigger id="order-status">
|
|
219
|
+
<SelectValue />
|
|
220
|
+
</SelectTrigger>
|
|
221
|
+
<SelectContent>
|
|
222
|
+
<SelectItem value="all">All statuses</SelectItem>
|
|
223
|
+
<SelectItem value="pending">Pending</SelectItem>
|
|
224
|
+
<SelectItem value="shipped">Shipped</SelectItem>
|
|
225
|
+
<SelectItem value="delivered">Delivered</SelectItem>
|
|
226
|
+
</SelectContent>
|
|
227
|
+
</Select>
|
|
228
|
+
</div>
|
|
229
|
+
<Button
|
|
230
|
+
type="button"
|
|
231
|
+
variant="outline"
|
|
232
|
+
onClick={() => {
|
|
233
|
+
setRange(anyDate);
|
|
234
|
+
setStatus("all");
|
|
235
|
+
}}
|
|
236
|
+
>
|
|
237
|
+
Reset filters
|
|
238
|
+
</Button>
|
|
239
|
+
</div>
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## 14. Related components
|
|
245
|
+
|
|
246
|
+
- [Calendar](./calendar.md): the grid inside both pickers; use it inline when the grid should stay visible.
|
|
247
|
+
- [DateTimePicker](./date-time-picker.md): the same trigger and popover with a time row.
|
|
248
|
+
- [TimeInput](./time-input.md): a time of day without a date.
|
|
249
|
+
- [Popover](./popover.md): the surface the pickers open in.
|
|
250
|
+
- [Label](./form-label.md): the visible label for each picker; see also [forms](../patterns/forms.md).
|
|
251
|
+
- [Select](./select.md): the other common control in a filter bar.
|
|
252
|
+
|
|
253
|
+
## 15. Common agent mistakes
|
|
254
|
+
|
|
255
|
+
_Filled from evals._
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: DateTimePicker
|
|
3
|
+
use_when: The user picks one moment, a date plus a time of day, such as a scheduled send or a meeting start.
|
|
4
|
+
instead_of: A DatePicker next to a separate TimeInput; DatePicker when the time doesn't matter; TimeInput for a time with no date.
|
|
5
|
+
source: packages/core/src/components/datetime-picker.tsx
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# DateTimePicker
|
|
9
|
+
|
|
10
|
+
## 1. Overview
|
|
11
|
+
|
|
12
|
+
DateTimePicker is a field-style trigger that opens a Popover holding a Calendar and, below a divider, a TimeInput. It emits one `Date` that carries both the day and the time. The module and docs slug are `datetime-picker`; the export is `DateTimePicker`.
|
|
13
|
+
|
|
14
|
+
## 2. When to use
|
|
15
|
+
|
|
16
|
+
- Scheduling something for an exact moment: publish at, send at, starts at, reminder at.
|
|
17
|
+
- Editing an existing timestamp where both parts can change.
|
|
18
|
+
|
|
19
|
+
### When not to use
|
|
20
|
+
|
|
21
|
+
- Only the day matters → use [DatePicker](./date-picker.md).
|
|
22
|
+
- A start and end date → use DateRangePicker, documented in [DatePicker](./date-picker.md).
|
|
23
|
+
- A time of day with no date (opening hours, a daily digest) → use [TimeInput](./time-input.md).
|
|
24
|
+
- The date should stay visible on the page → use [Calendar](./calendar.md) with a [TimeInput](./time-input.md) beside it.
|
|
25
|
+
|
|
26
|
+
## 3. Anatomy
|
|
27
|
+
|
|
28
|
+
1. **Trigger**: a full-width Button in the `input` variant (`inputMuted` while empty), with a leading calendar icon and the formatted date and time.
|
|
29
|
+
2. **Popover**: opens below the trigger, aligned to its start edge, as wide as the trigger.
|
|
30
|
+
3. **Calendar**: one month in single mode. See [Calendar](./calendar.md).
|
|
31
|
+
4. **Time row**: a [TimeInput](./time-input.md) under a `--container-border` divider, with hours, minutes, optional seconds and AM/PM toggles in 12-hour mode.
|
|
32
|
+
|
|
33
|
+
## 4. Variants
|
|
34
|
+
|
|
35
|
+
No `variant` prop. Two booleans set the time format:
|
|
36
|
+
|
|
37
|
+
| Props | Trigger shows | Time row |
|
|
38
|
+
| --- | --- | --- |
|
|
39
|
+
| default | October 27th, 2026 02:30 PM | Hours, minutes, AM/PM |
|
|
40
|
+
| `use24Hour` | October 27th, 2026 14:30 | Hours, minutes |
|
|
41
|
+
| `showSeconds` | October 27th, 2026 02:30:45 PM | Adds a seconds segment |
|
|
42
|
+
|
|
43
|
+
## 5. Sizes
|
|
44
|
+
|
|
45
|
+
No size prop. The trigger is a default-size Button (`--size-lg` tall) and always fills its container's width. Set the width on a wrapper.
|
|
46
|
+
|
|
47
|
+
## 6. States
|
|
48
|
+
|
|
49
|
+
| State | Looks like | Notes |
|
|
50
|
+
| --- | --- | --- |
|
|
51
|
+
| Empty | Placeholder in `--interactive-fg-alt` next to the calendar icon | |
|
|
52
|
+
| Filled | Formatted date and time in `--interactive-fg` | |
|
|
53
|
+
| Hover | Trigger background fills | |
|
|
54
|
+
| Focus | 1px outline in `--focus-ring`, 1px offset | Never remove or restyle the focus ring. |
|
|
55
|
+
| Open | Popover with the calendar and time row; focus moves into the calendar | |
|
|
56
|
+
| Disabled | `--interactive-bg-disabled` fill, `--interactive-fg-disabled` text; skipped by Tab | |
|
|
57
|
+
| Error | No built-in error state | Put a FormMessage under the picker and reference it with `aria-describedby` on the group wrapper. |
|
|
58
|
+
|
|
59
|
+
## 7. Content guidelines
|
|
60
|
+
|
|
61
|
+
- Name what the moment is for in the label: "Publish at", "Reminder".
|
|
62
|
+
- Say which time zone applies when it isn't obviously the user's own; the value is built in the browser's local time.
|
|
63
|
+
- Use `use24Hour` where your audience expects a 24-hour clock.
|
|
64
|
+
- The trigger format is fixed (`PPP` plus the time) and English; there is no `dateFormat` prop.
|
|
65
|
+
|
|
66
|
+
| Do | Don't |
|
|
67
|
+
| --- | --- |
|
|
68
|
+
| Publish at (UTC) | Date/time |
|
|
69
|
+
| Pick a send time | Select… |
|
|
70
|
+
|
|
71
|
+
## 8. Rules
|
|
72
|
+
|
|
73
|
+
1. Control the value: pass `value` and `onValueChange`, and keep the `Date` you receive.
|
|
74
|
+
2. Label every picker. The trigger accepts no `id` or `aria-label`: give the Label an `id` and wrap the picker in `<div role="group" aria-labelledby="…">`.
|
|
75
|
+
3. Expect frequent updates. `onValueChange` fires on every date pick and on every change in the time segments, so validate on blur or submit, not on each call.
|
|
76
|
+
4. Clear the value from outside. Clicking the selected date again does nothing, so offer your own Clear button that sets `value` to `undefined` when the field is optional.
|
|
77
|
+
5. Convert to the time zone your backend expects before sending; the `Date` is local.
|
|
78
|
+
6. Set width on a wrapper; the trigger always stretches to fill it.
|
|
79
|
+
7. Never pass `className` or `style`; the props don't accept them.
|
|
80
|
+
|
|
81
|
+
## 9. Dos and don'ts
|
|
82
|
+
|
|
83
|
+
**Do:** use one DateTimePicker for one moment.
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
<div role="group" aria-labelledby="publish-at-label">
|
|
87
|
+
<DateTimePicker value={publishAt} onValueChange={setPublishAt} placeholder="Pick a publish time" />
|
|
88
|
+
</div>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Don't:** split one moment into a DatePicker and a separate TimeInput.
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
<DatePicker value={day} onValueChange={setDay} />
|
|
95
|
+
<TimeInput value={time} onValueChange={setTime} />
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Do:** offer a clear action when the field is optional.
|
|
99
|
+
|
|
100
|
+
```tsx
|
|
101
|
+
<Button type="button" variant="ghost" size="sm" onClick={() => setRemindAt(undefined)}>
|
|
102
|
+
Remove reminder
|
|
103
|
+
</Button>
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**Don't:** expect clicking the selected day to clear it.
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
<DateTimePicker value={remindAt} onValueChange={(next) => setRemindAt(next)} />
|
|
110
|
+
// next is never undefined from the popover
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## 10. Accessibility
|
|
114
|
+
|
|
115
|
+
- Role: the trigger is a `button` with `aria-haspopup="dialog"` and `aria-expanded` (Radix Popover); the panel is a `dialog` holding a calendar `grid` and the time inputs.
|
|
116
|
+
- Label: the trigger's name is its text, the formatted value or the placeholder. Name the field with a visible label and a `role="group"` wrapper (Rules 2). The time segments are named "Hours", "Minutes" and "Seconds"; the period toggles "AM" and "PM".
|
|
117
|
+
- Keyboard: Enter or Space opens. In the calendar, arrow keys, Page Up/Down and Home/End move and Enter picks. Tab moves on to the time segments, where digits type, Up and Down step, and `:` jumps to the next segment. Escape closes.
|
|
118
|
+
- Focus: on open, focus moves to the selected day, or today. Picking a date keeps the popover open so the user can go on to the time. The popover doesn't trap focus. On close, focus returns to the trigger.
|
|
119
|
+
- Contrast: handled by the theme. Don't override colours.
|
|
120
|
+
|
|
121
|
+
## 11. Behaviour
|
|
122
|
+
|
|
123
|
+
- Picking a date keeps the time already chosen. With no earlier value, the time starts at midnight.
|
|
124
|
+
- Changing the time before picking a date applies it to today.
|
|
125
|
+
- The popover stays open after a date pick; it closes on Escape or a click outside.
|
|
126
|
+
- The calendar always opens on the current month, even when the value is in another month.
|
|
127
|
+
- Responsive: the trigger fills its container; the popover matches the trigger's width (never narrower than the calendar), so a wider trigger stretches the grid.
|
|
128
|
+
- Overflow and truncation: the trigger text doesn't wrap. Leave room for the full date and time.
|
|
129
|
+
- Motion: none of its own. Don't add any.
|
|
130
|
+
|
|
131
|
+
## 12. API
|
|
132
|
+
|
|
133
|
+
<!-- api:start -->
|
|
134
|
+
| Prop | Type | Default | Description |
|
|
135
|
+
| --- | --- | --- | --- |
|
|
136
|
+
| `value` | `Date` | | The selected date and time. |
|
|
137
|
+
| `onValueChange` | `(date: Date \| undefined) => void` | | Called with a new `Date` on every date or time change. |
|
|
138
|
+
| `placeholder` | `string` | `"Pick date and time"` | Trigger text while empty. |
|
|
139
|
+
| `use24Hour` | `boolean` | `false` | 24-hour clock; otherwise 12-hour with AM/PM toggles. |
|
|
140
|
+
| `showSeconds` | `boolean` | `false` | Adds a seconds segment and shows seconds in the trigger. |
|
|
141
|
+
| `disabled` | `boolean` | `false` | Disables the trigger. |
|
|
142
|
+
| `ref` | `Ref<HTMLButtonElement>` | | Forwarded to the trigger button. |
|
|
143
|
+
|
|
144
|
+
No other props are accepted: no `id`, `name`, `aria-*`, `dateFormat`, `className` or `style`.
|
|
145
|
+
<!-- api:end -->
|
|
146
|
+
|
|
147
|
+
## 13. Examples
|
|
148
|
+
|
|
149
|
+
```tsx
|
|
150
|
+
import * as React from "react";
|
|
151
|
+
import { Button, DateTimePicker, FormDescription, Label } from "@eluan/core";
|
|
152
|
+
|
|
153
|
+
export function SchedulePost({ onSchedule }: { onSchedule: (when: Date) => void }) {
|
|
154
|
+
const [publishAt, setPublishAt] = React.useState<Date | undefined>();
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<form
|
|
158
|
+
onSubmit={(event) => {
|
|
159
|
+
event.preventDefault();
|
|
160
|
+
if (publishAt) onSchedule(publishAt);
|
|
161
|
+
}}
|
|
162
|
+
style={{ display: "flex", flexDirection: "column", gap: "var(--spacing-lg)" }}
|
|
163
|
+
>
|
|
164
|
+
<div style={{ display: "flex", flexDirection: "column", gap: "var(--spacing-sm)" }}>
|
|
165
|
+
<Label id="publish-at-label" required>
|
|
166
|
+
Publish at
|
|
167
|
+
</Label>
|
|
168
|
+
<div role="group" aria-labelledby="publish-at-label" aria-describedby="publish-at-hint">
|
|
169
|
+
<DateTimePicker value={publishAt} onValueChange={setPublishAt} placeholder="Pick a publish time" />
|
|
170
|
+
</div>
|
|
171
|
+
<FormDescription id="publish-at-hint">Uses your computer's time zone.</FormDescription>
|
|
172
|
+
</div>
|
|
173
|
+
<div style={{ display: "flex", justifyContent: "flex-end", gap: "var(--spacing-sm)" }}>
|
|
174
|
+
<Button type="button" variant="outline" onClick={() => setPublishAt(undefined)}>
|
|
175
|
+
Clear
|
|
176
|
+
</Button>
|
|
177
|
+
<Button type="submit" disabled={!publishAt}>
|
|
178
|
+
Schedule post
|
|
179
|
+
</Button>
|
|
180
|
+
</div>
|
|
181
|
+
</form>
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## 14. Related components
|
|
187
|
+
|
|
188
|
+
- [DatePicker](./date-picker.md): the same trigger without a time; also the chooser for all date and time components.
|
|
189
|
+
- [TimeInput](./time-input.md): the time row inside the popover; use it alone for a time with no date.
|
|
190
|
+
- [Calendar](./calendar.md): the grid inside the popover.
|
|
191
|
+
- [Popover](./popover.md): the surface the picker opens in.
|
|
192
|
+
- [Label](./form-label.md): the visible label; see also [forms](../patterns/forms.md).
|
|
193
|
+
|
|
194
|
+
## 15. Common agent mistakes
|
|
195
|
+
|
|
196
|
+
_Filled from evals._
|