@12-apps/ui 6.99.0 → 6.101.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/NATIVE.md +2 -1
- package/components-catalog.md +2 -1
- package/dist/_internal/components/data-display/Alert/Alert.content.js +2 -2
- package/dist/_internal/components/data-display/Alert/Alert.js +4 -4
- package/dist/_internal/components/data-display/Avatar/Avatar.js +2 -2
- package/dist/_internal/components/data-display/Badge/Badge.js +2 -2
- package/dist/_internal/components/data-display/CardKit/card-actions-context.js +5 -5
- package/dist/_internal/components/data-display/CardKit/use-remove-confirm.js +6 -6
- package/dist/_internal/components/data-display/Carousel/Carousel.js +3 -3
- package/dist/_internal/components/data-display/Chart/Chart.js +4 -4
- package/dist/_internal/components/data-display/Chart/SpecChart.js +6 -6
- package/dist/_internal/components/data-display/Chart/chart-context.js +2 -2
- package/dist/_internal/components/data-display/Chart/chart-renderers.js +3 -3
- package/dist/_internal/components/data-display/DataGrid/DataGrid.js +3 -3
- package/dist/_internal/components/data-display/DataViews/DataViewsGrid.js +45 -45
- package/dist/_internal/components/data-display/DataViews/DataViewsTableBase.js +60 -60
- package/dist/_internal/components/data-display/DataViews/DeleteViewDialog.js +4 -4
- package/dist/_internal/components/data-display/DataViews/ManageViewsDialog.js +4 -4
- package/dist/_internal/components/data-display/DataViews/SaveViewModal.js +4 -4
- package/dist/_internal/components/data-display/DataViews/base-list-card-geometry.js +4 -4
- package/dist/_internal/components/data-display/DataViews/base-list-card-layout.js +4 -4
- package/dist/_internal/components/data-display/DataViews/base-list-card-slots.js +3 -3
- package/dist/_internal/components/data-display/DataViews/base-list-card.js +5 -5
- package/dist/_internal/components/data-display/DataViews/data-views-category-pill.js +8 -8
- package/dist/_internal/components/data-display/DataViews/data-views-display-panel.js +1 -1
- package/dist/_internal/components/data-display/DataViews/data-views-filter-panel.js +20 -20
- package/dist/_internal/components/data-display/DataViews/data-views-grid-bodies.js +9 -9
- package/dist/_internal/components/data-display/DataViews/data-views-grid-parts.js +42 -42
- package/dist/_internal/components/data-display/DataViews/data-views-inline-bar.js +24 -24
- package/dist/_internal/components/data-display/DataViews/data-views-more-fields.js +21 -21
- package/dist/_internal/components/data-display/DataViews/data-views-more-filters.js +22 -22
- package/dist/_internal/components/data-display/DataViews/data-views-range-bounds.js +9 -9
- package/dist/_internal/components/data-display/DataViews/data-views-range-calendar.js +6 -6
- package/dist/_internal/components/data-display/DataViews/data-views-range-pill.js +11 -11
- package/dist/_internal/components/data-display/DataViews/data-views-scope-tabs.js +2 -2
- package/dist/_internal/components/data-display/DataViews/data-views-shell-toolbar.js +4 -4
- package/dist/_internal/components/data-display/DataViews/data-views-table-parts.js +10 -10
- package/dist/_internal/components/data-display/DataViews/data-views-toolbar.js +3 -3
- package/dist/_internal/components/data-display/DataViews/list-card-rails.js +3 -3
- package/dist/_internal/components/data-display/DataViews/use-data-views-state.js +2 -2
- package/dist/_internal/components/data-display/DayRuler/DayRuler.footer.js +3 -3
- package/dist/_internal/components/data-display/DayRuler/DayRuler.js +10 -10
- package/dist/_internal/components/data-display/DayRuler/DayRuler.keyboard.js +2 -2
- package/dist/_internal/components/data-display/DayRuler/DayRuler.labels.js +2 -2
- package/dist/_internal/components/data-display/DayRuler/DayRuler.parts.js +3 -3
- package/dist/_internal/components/data-display/DayRuler/useRulerDrag.js +2 -2
- package/dist/_internal/components/data-display/FleetMap/FleetBody.js +10 -10
- package/dist/_internal/components/data-display/FleetMap/FleetCanvas.js +9 -9
- package/dist/_internal/components/data-display/FleetMap/FleetMap.js +12 -12
- package/dist/_internal/components/data-display/HoverCard/HoverCard.js +2 -2
- package/dist/_internal/components/data-display/Lightbox/Lightbox.js +7 -7
- package/dist/_internal/components/data-display/Lightbox/LightboxControls.js +2 -2
- package/dist/_internal/components/data-display/Lightbox/LightboxOverlay.js +3 -3
- package/dist/_internal/components/data-display/Lightbox/LightboxThumbnails.js +2 -2
- package/dist/_internal/components/data-display/MapPreview/MapLayers.js +3 -3
- package/dist/_internal/components/data-display/MapPreview/MapMarkers.js +2 -2
- package/dist/_internal/components/data-display/MapPreview/MapPreview.js +8 -8
- package/dist/_internal/components/data-display/Progress/Progress.js +2 -2
- package/dist/_internal/components/data-display/RegionMap/RegionMap.js +4 -4
- package/dist/_internal/components/data-display/RegionMap/RegionMapDrawing.js +2 -2
- package/dist/_internal/components/data-display/RegionMap/RegionMapPin.js +1 -1
- package/dist/_internal/components/data-display/ScheduleGrid/ScheduleGrid.js +8 -8
- package/dist/_internal/components/data-display/ScheduleGrid/ScheduleGrid.parts.js +3 -3
- package/dist/_internal/components/data-display/Sheet/Sheet.js +2 -2
- package/dist/_internal/components/data-display/Table/Table.js +3 -3
- package/dist/_internal/components/data-display/index.js +75 -75
- package/dist/_internal/components/feedback/Dialog/Dialog.js +3 -3
- package/dist/_internal/components/feedback/Modal/Modal.js +2 -2
- package/dist/_internal/components/feedback/NotificationStatusNotice/NotificationStatusNotice.js +5 -5
- package/dist/_internal/components/feedback/SequenceResolver/SequenceResolver.frame.js +8 -8
- package/dist/_internal/components/feedback/SequenceResolver/SequenceResolver.header.js +4 -4
- package/dist/_internal/components/feedback/SequenceResolver/SequenceResolver.js +16 -16
- package/dist/_internal/components/feedback/SequenceResolver/SequenceResolver.overview.js +6 -6
- package/dist/_internal/components/feedback/SequenceResolver/SequenceResolver.parts.js +5 -5
- package/dist/_internal/components/feedback/TutorialOverlay/TutorialOverlay.js +2 -2
- package/dist/_internal/components/feedback/UsableModal/UsableModal.js +1 -1
- package/dist/_internal/components/feedback/UsableModal/UsableModal.sheet.js +2 -2
- package/dist/_internal/components/feedback/index.js +21 -21
- package/dist/_internal/components/form/AddressAutocomplete/AddressAutocomplete.hooks.js +2 -2
- package/dist/_internal/components/form/AddressAutocomplete/AddressAutocomplete.js +7 -7
- package/dist/_internal/components/form/AddressAutocomplete/AddressAutocompleteField.js +2 -2
- package/dist/_internal/components/form/Autocomplete/Autocomplete.js +1 -1
- package/dist/_internal/components/form/Calendar/Calendar.js +5 -5
- package/dist/_internal/components/form/Calendar/CalendarSelectorsMonth.js +3 -3
- package/dist/_internal/components/form/CategorySelect/CategoryPanel.js +4 -4
- package/dist/_internal/components/form/CategorySelect/CategorySelect.js +7 -7
- package/dist/_internal/components/form/CodeEditor/CodeEditor.js +2 -2
- package/dist/_internal/components/form/DateRangePicker/DateRangePicker.js +8 -8
- package/dist/_internal/components/form/InputOTP/InputOTP.base.js +1 -0
- package/dist/_internal/components/form/InputOTP/InputOTP.base.js.map +1 -0
- package/dist/_internal/components/form/InputOTP/InputOTP.core.js +16 -0
- package/dist/_internal/components/form/InputOTP/InputOTP.core.js.map +1 -0
- package/dist/_internal/components/form/InputOTP/InputOTP.hooks.js +2 -1
- package/dist/_internal/components/form/InputOTP/InputOTP.js +5 -3
- package/dist/_internal/components/form/InputOTP/InputOTP.metrics.js +12 -0
- package/dist/_internal/components/form/InputOTP/InputOTP.metrics.js.map +1 -0
- package/dist/_internal/components/form/InputOTP/InputOTP.styles.js +2 -1
- package/dist/_internal/components/form/index.js +25 -23
- package/dist/_internal/components/form/total-form/Fields/CategoryField.js +8 -8
- package/dist/_internal/components/form/total-form/Fields/index.js +9 -9
- package/dist/_internal/components/index.js +123 -121
- package/dist/_internal/components/navigation/AppHeader/AppHeader.details.js +6 -6
- package/dist/_internal/components/navigation/SectionNav/SectionNav.bar.js +6 -6
- package/dist/_internal/components/navigation/SectionNav/SectionNav.js +9 -9
- package/dist/_internal/components/navigation/SectionNav/SectionNav.parts.js +3 -3
- package/dist/_internal/components/navigation/SectionNav/SectionNav.primary.js +4 -4
- package/dist/_internal/components/navigation/SectionNav/SectionNav.rail.js +5 -5
- package/dist/_internal/components/navigation/SectionNav/SectionNav.railCreate.js +4 -4
- package/dist/_internal/components/navigation/SectionNav/SectionNav.sheet.js +4 -4
- package/dist/_internal/components/navigation/index.js +15 -15
- package/dist/_internal/user-avatar/user-avatar.js +3 -3
- package/dist/charts.js +6 -6
- package/dist/{chunk-37MJZLQU.js → chunk-24OFA44S.js} +4 -4
- package/dist/{chunk-R775ISK6.js → chunk-2L6TANRY.js} +5 -5
- package/dist/{chunk-B4OZU7J4.js → chunk-423A7NUP.js} +7 -7
- package/dist/{chunk-LFECE4R7.js → chunk-4EDCF7TC.js} +2 -2
- package/dist/{chunk-HI7JPDD6.js → chunk-5357QUVE.js} +2 -2
- package/dist/{chunk-F7JRQ2EI.js → chunk-5YX2VQFP.js} +7 -7
- package/dist/{chunk-QZOQVJ5L.js → chunk-645GGNTW.js} +3 -3
- package/dist/{chunk-N5PVD4J5.js → chunk-6DO672AG.js} +7 -7
- package/dist/{chunk-PGJIWCQR.js → chunk-6EZQLNPK.js} +4 -4
- package/dist/{chunk-YQMJJ7AL.js → chunk-6G2RAZTS.js} +5 -5
- package/dist/{chunk-KNW63H63.js → chunk-6PQZIZMN.js} +5 -5
- package/dist/{chunk-FZZMNKVF.js → chunk-6TAPAIRR.js} +8 -8
- package/dist/{chunk-ERAMSYPR.js → chunk-7N4O632I.js} +2 -2
- package/dist/{chunk-XFOKLWJZ.js → chunk-7S5PXEO7.js} +2 -2
- package/dist/{chunk-DRYBA76G.js → chunk-7XVT4RME.js} +2 -2
- package/dist/{chunk-DRYBA76G.js.map → chunk-7XVT4RME.js.map} +1 -1
- package/dist/{chunk-UIJLDAV7.js → chunk-AA6YMOEK.js} +2 -2
- package/dist/{chunk-CRD2WCU7.js → chunk-AFWUQJ4P.js} +8 -8
- package/dist/{chunk-SNWCT6JN.js → chunk-AMIUZRDQ.js} +3 -3
- package/dist/{chunk-NQYC7V5N.js → chunk-BAYCMSMI.js} +5 -9
- package/dist/chunk-BAYCMSMI.js.map +1 -0
- package/dist/{chunk-3I7KE2N6.js → chunk-BNV7P52K.js} +2 -2
- package/dist/{chunk-64UNVW6D.js → chunk-BP3ZKIPE.js} +4 -4
- package/dist/{chunk-3V7OTBUZ.js → chunk-BQ2SFA27.js} +2 -2
- package/dist/{chunk-Q5SCBQLY.js → chunk-BXLC3TBQ.js} +8 -8
- package/dist/{chunk-Z5V5E3JW.js → chunk-COKPPU42.js} +11 -11
- package/dist/{chunk-QADTI63U.js → chunk-CZVAVX5L.js} +4 -4
- package/dist/{chunk-WDEVKND3.js → chunk-D2YJPZMU.js} +9 -9
- package/dist/{chunk-OA6T2ME3.js → chunk-DYHOBKPU.js} +5 -5
- package/dist/{chunk-6WAP7BJS.js → chunk-E6SPWZRN.js} +2 -2
- package/dist/{chunk-UTIYB6VE.js → chunk-E73PAU4U.js} +19 -19
- package/dist/{chunk-XR474YYX.js → chunk-EDVAFY76.js} +2 -2
- package/dist/{chunk-MEMVZW64.js → chunk-EPNZQWS4.js} +3 -3
- package/dist/{chunk-GZITNT7O.js → chunk-FGZIEZEP.js} +11 -11
- package/dist/{chunk-4X2TOMK6.js → chunk-FKUVFPQZ.js} +4 -4
- package/dist/{chunk-UN5WU2OX.js → chunk-GDWU7WF4.js} +4 -4
- package/dist/{chunk-643YFWNK.js → chunk-GPWDP5FF.js} +3 -3
- package/dist/{chunk-XA5ES25V.js → chunk-HKQWFICM.js} +2 -2
- package/dist/chunk-IH6DZXTG.js +22 -0
- package/dist/chunk-IH6DZXTG.js.map +1 -0
- package/dist/{chunk-255WTBZ5.js → chunk-IWSTMVCA.js} +4 -4
- package/dist/{chunk-TZC6KIK2.js → chunk-JG733RMP.js} +5 -5
- package/dist/{chunk-7MLT66DE.js → chunk-K33X3PDT.js} +2 -2
- package/dist/{chunk-K3PMMW23.js → chunk-K6VEN5VN.js} +4 -4
- package/dist/{chunk-HOWAMSUY.js → chunk-KAWVH3AA.js} +3 -3
- package/dist/{chunk-IJVBLU25.js → chunk-KJZ4PINO.js} +3 -3
- package/dist/{chunk-REHGWN5M.js → chunk-KXDLLS62.js} +4 -4
- package/dist/{chunk-YQ5GQ32T.js → chunk-KZP5YTE7.js} +2 -2
- package/dist/{chunk-3V3Z4EML.js → chunk-L4FWEI2P.js} +5 -5
- package/dist/{chunk-UKUGSU3Y.js → chunk-L4V7FZJI.js} +2 -2
- package/dist/{chunk-W56KN53D.js → chunk-L6IDPTNX.js} +6 -6
- package/dist/{chunk-AYDVNXGR.js → chunk-LCKUEYU2.js} +2 -2
- package/dist/{chunk-24HHUCWB.js → chunk-LDCZPZPD.js} +2 -2
- package/dist/{chunk-KV7LTOWC.js → chunk-M225SD4H.js} +13 -13
- package/dist/{chunk-R6L376KR.js → chunk-M6R32IBO.js} +8 -13
- package/dist/chunk-M6R32IBO.js.map +1 -0
- package/dist/{chunk-FQMLTCXT.js → chunk-MAHY7PK3.js} +4 -4
- package/dist/{chunk-Z2J4MRTF.js → chunk-MKNW4FRR.js} +4 -4
- package/dist/{chunk-ILJ3FXIC.js → chunk-MM3QESLI.js} +2 -2
- package/dist/{chunk-FYJL432J.js → chunk-MQPUS773.js} +6 -6
- package/dist/{chunk-VRSW7PIO.js → chunk-NKBSWAP3.js} +4 -4
- package/dist/{chunk-ULC4SCFC.js → chunk-NLJ7LL6H.js} +4 -4
- package/dist/{chunk-RAQD5QCM.js → chunk-NQ6JP5CC.js} +6 -6
- package/dist/{chunk-IFOHCY4O.js → chunk-OF3KG5EV.js} +2 -2
- package/dist/{chunk-W676GY42.js → chunk-P772HCHI.js} +4 -4
- package/dist/{chunk-CWRQGA2T.js → chunk-POIENBXE.js} +7 -7
- package/dist/{chunk-FW5GTAUY.js → chunk-Q4AX4FOK.js} +11 -11
- package/dist/{chunk-XQAFSC66.js → chunk-Q4FNCT4C.js} +2 -2
- package/dist/{chunk-PIELY4BJ.js → chunk-Q5Z66LKI.js} +1 -1
- package/dist/{chunk-4Y3QLISA.js → chunk-Q7AONB4G.js} +4 -4
- package/dist/{chunk-EZBBLLEU.js → chunk-QQBYZ3B3.js} +4 -4
- package/dist/{chunk-FT3LJZWZ.js → chunk-RWUXMBSO.js} +4 -4
- package/dist/{chunk-KWBMM6MJ.js → chunk-RZKKWIGQ.js} +9 -9
- package/dist/{chunk-RVBLOR32.js → chunk-S7CXVIEF.js} +2 -2
- package/dist/{chunk-WLLUARTC.js → chunk-T2G4LDU5.js} +2 -2
- package/dist/{chunk-OFRQMFWD.js → chunk-T5D3DYVN.js} +2 -2
- package/dist/{chunk-O4UXH7BM.js → chunk-TP6KZ2YR.js} +7 -7
- package/dist/{chunk-HAWOS4SF.js → chunk-TPDN3B5T.js} +2 -2
- package/dist/{chunk-54DOLCJ3.js → chunk-TXIIJW6C.js} +5 -5
- package/dist/{chunk-HN36UVOE.js → chunk-U4Z6GZDW.js} +4 -4
- package/dist/{chunk-J2IQ6FJ5.js → chunk-UKLNLWTP.js} +3 -3
- package/dist/chunk-VAHJCRNW.js +17 -0
- package/dist/chunk-VAHJCRNW.js.map +1 -0
- package/dist/{chunk-MKHNLRVX.js → chunk-VPPD2AJN.js} +7 -7
- package/dist/{chunk-TIM4PXWN.js → chunk-VWRXSBT2.js} +2 -2
- package/dist/{chunk-KVP5A3YK.js → chunk-WDWZKTGA.js} +2 -2
- package/dist/{chunk-FYSS2PYA.js → chunk-WH5ZEBKS.js} +7 -7
- package/dist/{chunk-KAGXV3ID.js → chunk-WMMXOSZG.js} +7 -7
- package/dist/{chunk-4RSFYS2V.js → chunk-X6D5JEUV.js} +6 -6
- package/dist/{chunk-GFYDOH7D.js → chunk-XEPNAU3T.js} +2 -2
- package/dist/{chunk-VMACQT3T.js → chunk-XH7UDC5Y.js} +3 -3
- package/dist/{chunk-PDWQJFMK.js → chunk-XHMHHP7B.js} +10 -10
- package/dist/{chunk-SA3KLZDZ.js → chunk-XNAI7QGU.js} +5 -5
- package/dist/{chunk-7TENMQNQ.js → chunk-XZMSRHFD.js} +4 -4
- package/dist/{chunk-HBHBRRSW.js → chunk-YBAK2WN5.js} +7 -7
- package/dist/{chunk-QLKUWDMQ.js → chunk-YDJ5GAGL.js} +13 -13
- package/dist/{chunk-3V5V44UP.js → chunk-YHFLI2FD.js} +2 -2
- package/dist/{chunk-LOLYBFYY.js → chunk-ZCNR4DN5.js} +5 -5
- package/dist/data-display/Alert.js +4 -4
- package/dist/data-display/Avatar.js +2 -2
- package/dist/data-display/Badge.js +2 -2
- package/dist/data-display/CardKit.js +14 -14
- package/dist/data-display/Carousel.js +3 -3
- package/dist/data-display/Chart.js +6 -6
- package/dist/data-display/DataGrid.js +3 -3
- package/dist/data-display/DataViews.js +74 -74
- package/dist/data-display/DayRuler.js +12 -12
- package/dist/data-display/FleetMap.js +12 -12
- package/dist/data-display/HoverCard.js +2 -2
- package/dist/data-display/Lightbox.js +7 -7
- package/dist/data-display/MapPreview.js +8 -8
- package/dist/data-display/Progress.js +2 -2
- package/dist/data-display/RegionMap.js +7 -7
- package/dist/data-display/ScheduleGrid.js +10 -10
- package/dist/data-display/Sheet.js +2 -2
- package/dist/data-display/Table.js +3 -3
- package/dist/feedback/Dialog.js +3 -3
- package/dist/feedback/Modal.js +2 -2
- package/dist/feedback/NotificationStatusNotice.js +5 -5
- package/dist/feedback/SequenceResolver.js +16 -16
- package/dist/feedback/TutorialOverlay.js +2 -2
- package/dist/feedback/UsableModal.js +1 -1
- package/dist/form/AddressAutocomplete.js +7 -7
- package/dist/form/Autocomplete.js +1 -1
- package/dist/form/Calendar.js +5 -5
- package/dist/form/CategorySelect.js +7 -7
- package/dist/form/CodeEditor.js +2 -2
- package/dist/form/DateRangePicker.js +10 -10
- package/dist/form/InputOTP.js +5 -3
- package/dist/form/total-form.js +9 -9
- package/dist/native/form/InputOTP.js +192 -0
- package/dist/native/form/InputOTP.js.map +1 -0
- package/dist/navigation/AppHeader.js +6 -6
- package/dist/navigation/SectionNav.js +9 -9
- package/dist/types/components/form/InputOTP/InputOTP.base.d.ts +63 -0
- package/dist/types/components/form/InputOTP/InputOTP.base.d.ts.map +1 -0
- package/dist/types/components/form/InputOTP/InputOTP.core.d.ts +38 -0
- package/dist/types/components/form/InputOTP/InputOTP.core.d.ts.map +1 -0
- package/dist/types/components/form/InputOTP/InputOTP.d.ts +1 -2
- package/dist/types/components/form/InputOTP/InputOTP.d.ts.map +1 -1
- package/dist/types/components/form/InputOTP/InputOTP.hooks.d.ts.map +1 -1
- package/dist/types/components/form/InputOTP/InputOTP.metrics.d.ts +15 -0
- package/dist/types/components/form/InputOTP/InputOTP.metrics.d.ts.map +1 -0
- package/dist/types/components/form/InputOTP/InputOTP.styles.d.ts.map +1 -1
- package/dist/types/components/form/InputOTP/InputOTP.types.d.ts +3 -56
- package/dist/types/components/form/InputOTP/InputOTP.types.d.ts.map +1 -1
- package/dist/types-native/components/form/InputOTP/InputOTP.base.d.ts +63 -0
- package/dist/types-native/components/form/InputOTP/InputOTP.base.d.ts.map +1 -0
- package/dist/types-native/components/form/InputOTP/InputOTP.core.d.ts +38 -0
- package/dist/types-native/components/form/InputOTP/InputOTP.core.d.ts.map +1 -0
- package/dist/types-native/components/form/InputOTP/InputOTP.hooks.native.d.ts +28 -0
- package/dist/types-native/components/form/InputOTP/InputOTP.hooks.native.d.ts.map +1 -0
- package/dist/types-native/components/form/InputOTP/InputOTP.metrics.d.ts +15 -0
- package/dist/types-native/components/form/InputOTP/InputOTP.metrics.d.ts.map +1 -0
- package/dist/types-native/components/form/InputOTP/InputOTP.native.d.ts +14 -0
- package/dist/types-native/components/form/InputOTP/InputOTP.native.d.ts.map +1 -0
- package/dist/types-native/components/form/InputOTP/InputOTP.types.native.d.ts +14 -0
- package/dist/types-native/components/form/InputOTP/InputOTP.types.native.d.ts.map +1 -0
- package/dist/types-native/components/form/InputOTP/index.native.d.ts +3 -0
- package/dist/types-native/components/form/InputOTP/index.native.d.ts.map +1 -0
- package/dist/user-avatar.js +3 -3
- package/package.json +5 -1
- package/src/components/data-display/RegionMap/RegionMapPin.tsx +1 -1
- package/src/components/form/InputOTP/InputOTP.base.ts +76 -0
- package/src/components/form/InputOTP/InputOTP.core.ts +51 -0
- package/src/components/form/InputOTP/InputOTP.hooks.native.ts +84 -0
- package/src/components/form/InputOTP/InputOTP.hooks.ts +1 -46
- package/src/components/form/InputOTP/InputOTP.metrics.ts +19 -0
- package/src/components/form/InputOTP/InputOTP.native.tsx +154 -0
- package/src/components/form/InputOTP/InputOTP.styles.ts +4 -11
- package/src/components/form/InputOTP/InputOTP.types.native.ts +15 -0
- package/src/components/form/InputOTP/InputOTP.types.ts +3 -68
- package/src/components/form/InputOTP/NATIVE-NOTES.md +8 -0
- package/src/components/form/InputOTP/index.native.ts +2 -0
- package/dist/chunk-NQYC7V5N.js.map +0 -1
- package/dist/chunk-R6L376KR.js.map +0 -1
- /package/dist/{chunk-37MJZLQU.js.map → chunk-24OFA44S.js.map} +0 -0
- /package/dist/{chunk-R775ISK6.js.map → chunk-2L6TANRY.js.map} +0 -0
- /package/dist/{chunk-B4OZU7J4.js.map → chunk-423A7NUP.js.map} +0 -0
- /package/dist/{chunk-LFECE4R7.js.map → chunk-4EDCF7TC.js.map} +0 -0
- /package/dist/{chunk-HI7JPDD6.js.map → chunk-5357QUVE.js.map} +0 -0
- /package/dist/{chunk-F7JRQ2EI.js.map → chunk-5YX2VQFP.js.map} +0 -0
- /package/dist/{chunk-QZOQVJ5L.js.map → chunk-645GGNTW.js.map} +0 -0
- /package/dist/{chunk-N5PVD4J5.js.map → chunk-6DO672AG.js.map} +0 -0
- /package/dist/{chunk-PGJIWCQR.js.map → chunk-6EZQLNPK.js.map} +0 -0
- /package/dist/{chunk-YQMJJ7AL.js.map → chunk-6G2RAZTS.js.map} +0 -0
- /package/dist/{chunk-KNW63H63.js.map → chunk-6PQZIZMN.js.map} +0 -0
- /package/dist/{chunk-FZZMNKVF.js.map → chunk-6TAPAIRR.js.map} +0 -0
- /package/dist/{chunk-ERAMSYPR.js.map → chunk-7N4O632I.js.map} +0 -0
- /package/dist/{chunk-XFOKLWJZ.js.map → chunk-7S5PXEO7.js.map} +0 -0
- /package/dist/{chunk-UIJLDAV7.js.map → chunk-AA6YMOEK.js.map} +0 -0
- /package/dist/{chunk-CRD2WCU7.js.map → chunk-AFWUQJ4P.js.map} +0 -0
- /package/dist/{chunk-SNWCT6JN.js.map → chunk-AMIUZRDQ.js.map} +0 -0
- /package/dist/{chunk-3I7KE2N6.js.map → chunk-BNV7P52K.js.map} +0 -0
- /package/dist/{chunk-64UNVW6D.js.map → chunk-BP3ZKIPE.js.map} +0 -0
- /package/dist/{chunk-3V7OTBUZ.js.map → chunk-BQ2SFA27.js.map} +0 -0
- /package/dist/{chunk-Q5SCBQLY.js.map → chunk-BXLC3TBQ.js.map} +0 -0
- /package/dist/{chunk-Z5V5E3JW.js.map → chunk-COKPPU42.js.map} +0 -0
- /package/dist/{chunk-QADTI63U.js.map → chunk-CZVAVX5L.js.map} +0 -0
- /package/dist/{chunk-WDEVKND3.js.map → chunk-D2YJPZMU.js.map} +0 -0
- /package/dist/{chunk-OA6T2ME3.js.map → chunk-DYHOBKPU.js.map} +0 -0
- /package/dist/{chunk-6WAP7BJS.js.map → chunk-E6SPWZRN.js.map} +0 -0
- /package/dist/{chunk-UTIYB6VE.js.map → chunk-E73PAU4U.js.map} +0 -0
- /package/dist/{chunk-XR474YYX.js.map → chunk-EDVAFY76.js.map} +0 -0
- /package/dist/{chunk-MEMVZW64.js.map → chunk-EPNZQWS4.js.map} +0 -0
- /package/dist/{chunk-GZITNT7O.js.map → chunk-FGZIEZEP.js.map} +0 -0
- /package/dist/{chunk-4X2TOMK6.js.map → chunk-FKUVFPQZ.js.map} +0 -0
- /package/dist/{chunk-UN5WU2OX.js.map → chunk-GDWU7WF4.js.map} +0 -0
- /package/dist/{chunk-643YFWNK.js.map → chunk-GPWDP5FF.js.map} +0 -0
- /package/dist/{chunk-XA5ES25V.js.map → chunk-HKQWFICM.js.map} +0 -0
- /package/dist/{chunk-255WTBZ5.js.map → chunk-IWSTMVCA.js.map} +0 -0
- /package/dist/{chunk-TZC6KIK2.js.map → chunk-JG733RMP.js.map} +0 -0
- /package/dist/{chunk-7MLT66DE.js.map → chunk-K33X3PDT.js.map} +0 -0
- /package/dist/{chunk-K3PMMW23.js.map → chunk-K6VEN5VN.js.map} +0 -0
- /package/dist/{chunk-HOWAMSUY.js.map → chunk-KAWVH3AA.js.map} +0 -0
- /package/dist/{chunk-IJVBLU25.js.map → chunk-KJZ4PINO.js.map} +0 -0
- /package/dist/{chunk-REHGWN5M.js.map → chunk-KXDLLS62.js.map} +0 -0
- /package/dist/{chunk-YQ5GQ32T.js.map → chunk-KZP5YTE7.js.map} +0 -0
- /package/dist/{chunk-3V3Z4EML.js.map → chunk-L4FWEI2P.js.map} +0 -0
- /package/dist/{chunk-UKUGSU3Y.js.map → chunk-L4V7FZJI.js.map} +0 -0
- /package/dist/{chunk-W56KN53D.js.map → chunk-L6IDPTNX.js.map} +0 -0
- /package/dist/{chunk-AYDVNXGR.js.map → chunk-LCKUEYU2.js.map} +0 -0
- /package/dist/{chunk-24HHUCWB.js.map → chunk-LDCZPZPD.js.map} +0 -0
- /package/dist/{chunk-KV7LTOWC.js.map → chunk-M225SD4H.js.map} +0 -0
- /package/dist/{chunk-FQMLTCXT.js.map → chunk-MAHY7PK3.js.map} +0 -0
- /package/dist/{chunk-Z2J4MRTF.js.map → chunk-MKNW4FRR.js.map} +0 -0
- /package/dist/{chunk-ILJ3FXIC.js.map → chunk-MM3QESLI.js.map} +0 -0
- /package/dist/{chunk-FYJL432J.js.map → chunk-MQPUS773.js.map} +0 -0
- /package/dist/{chunk-VRSW7PIO.js.map → chunk-NKBSWAP3.js.map} +0 -0
- /package/dist/{chunk-ULC4SCFC.js.map → chunk-NLJ7LL6H.js.map} +0 -0
- /package/dist/{chunk-RAQD5QCM.js.map → chunk-NQ6JP5CC.js.map} +0 -0
- /package/dist/{chunk-IFOHCY4O.js.map → chunk-OF3KG5EV.js.map} +0 -0
- /package/dist/{chunk-W676GY42.js.map → chunk-P772HCHI.js.map} +0 -0
- /package/dist/{chunk-CWRQGA2T.js.map → chunk-POIENBXE.js.map} +0 -0
- /package/dist/{chunk-FW5GTAUY.js.map → chunk-Q4AX4FOK.js.map} +0 -0
- /package/dist/{chunk-XQAFSC66.js.map → chunk-Q4FNCT4C.js.map} +0 -0
- /package/dist/{chunk-PIELY4BJ.js.map → chunk-Q5Z66LKI.js.map} +0 -0
- /package/dist/{chunk-4Y3QLISA.js.map → chunk-Q7AONB4G.js.map} +0 -0
- /package/dist/{chunk-EZBBLLEU.js.map → chunk-QQBYZ3B3.js.map} +0 -0
- /package/dist/{chunk-FT3LJZWZ.js.map → chunk-RWUXMBSO.js.map} +0 -0
- /package/dist/{chunk-KWBMM6MJ.js.map → chunk-RZKKWIGQ.js.map} +0 -0
- /package/dist/{chunk-RVBLOR32.js.map → chunk-S7CXVIEF.js.map} +0 -0
- /package/dist/{chunk-WLLUARTC.js.map → chunk-T2G4LDU5.js.map} +0 -0
- /package/dist/{chunk-OFRQMFWD.js.map → chunk-T5D3DYVN.js.map} +0 -0
- /package/dist/{chunk-O4UXH7BM.js.map → chunk-TP6KZ2YR.js.map} +0 -0
- /package/dist/{chunk-HAWOS4SF.js.map → chunk-TPDN3B5T.js.map} +0 -0
- /package/dist/{chunk-54DOLCJ3.js.map → chunk-TXIIJW6C.js.map} +0 -0
- /package/dist/{chunk-HN36UVOE.js.map → chunk-U4Z6GZDW.js.map} +0 -0
- /package/dist/{chunk-J2IQ6FJ5.js.map → chunk-UKLNLWTP.js.map} +0 -0
- /package/dist/{chunk-MKHNLRVX.js.map → chunk-VPPD2AJN.js.map} +0 -0
- /package/dist/{chunk-TIM4PXWN.js.map → chunk-VWRXSBT2.js.map} +0 -0
- /package/dist/{chunk-KVP5A3YK.js.map → chunk-WDWZKTGA.js.map} +0 -0
- /package/dist/{chunk-FYSS2PYA.js.map → chunk-WH5ZEBKS.js.map} +0 -0
- /package/dist/{chunk-KAGXV3ID.js.map → chunk-WMMXOSZG.js.map} +0 -0
- /package/dist/{chunk-4RSFYS2V.js.map → chunk-X6D5JEUV.js.map} +0 -0
- /package/dist/{chunk-GFYDOH7D.js.map → chunk-XEPNAU3T.js.map} +0 -0
- /package/dist/{chunk-VMACQT3T.js.map → chunk-XH7UDC5Y.js.map} +0 -0
- /package/dist/{chunk-PDWQJFMK.js.map → chunk-XHMHHP7B.js.map} +0 -0
- /package/dist/{chunk-SA3KLZDZ.js.map → chunk-XNAI7QGU.js.map} +0 -0
- /package/dist/{chunk-7TENMQNQ.js.map → chunk-XZMSRHFD.js.map} +0 -0
- /package/dist/{chunk-HBHBRRSW.js.map → chunk-YBAK2WN5.js.map} +0 -0
- /package/dist/{chunk-QLKUWDMQ.js.map → chunk-YDJ5GAGL.js.map} +0 -0
- /package/dist/{chunk-3V5V44UP.js.map → chunk-YHFLI2FD.js.map} +0 -0
- /package/dist/{chunk-LOLYBFYY.js.map → chunk-ZCNR4DN5.js.map} +0 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { ColorValue, SizeValue } from '../../../tokens/vocabulary';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* THE CONTRACT BOTH RENDERERS HONOUR (see `Button.base.ts`).
|
|
5
|
+
*
|
|
6
|
+
* No MUI and no react-native here: this file ships in both declaration
|
|
7
|
+
* outputs, and a native consumer has no `@mui/material` to resolve against.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export interface InputOTPBaseProps {
|
|
11
|
+
/**
|
|
12
|
+
* The variant of the OTP input
|
|
13
|
+
*/
|
|
14
|
+
variant?: 'numeric' | 'alphanumeric' | 'masked';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The color theme of the OTP input
|
|
18
|
+
*/
|
|
19
|
+
color?: ColorValue;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The size of the OTP input
|
|
23
|
+
*/
|
|
24
|
+
size?: SizeValue;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Number of OTP digits
|
|
28
|
+
*/
|
|
29
|
+
length?: number;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Current value
|
|
33
|
+
*/
|
|
34
|
+
value?: string;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Called when value changes
|
|
38
|
+
*/
|
|
39
|
+
onChange?: (value: string) => void;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Called when OTP is complete
|
|
43
|
+
*/
|
|
44
|
+
onComplete?: (value: string) => void;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Whether the input should have glass morphism effect
|
|
48
|
+
*/
|
|
49
|
+
glass?: boolean;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Whether the input should have gradient effects
|
|
53
|
+
*/
|
|
54
|
+
gradient?: boolean;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Whether to auto-focus first input
|
|
58
|
+
*/
|
|
59
|
+
autoFocus?: boolean;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Error state
|
|
63
|
+
*/
|
|
64
|
+
error?: boolean;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Disabled state
|
|
68
|
+
*/
|
|
69
|
+
disabled?: boolean;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Test ID for automated testing
|
|
73
|
+
* Container will have this ID, and individual slots will have {dataTestId}-slot-{index}
|
|
74
|
+
*/
|
|
75
|
+
dataTestId?: string;
|
|
76
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The digits' arithmetic, shared by both renderers' hooks (`InputOTP.hooks.ts`
|
|
3
|
+
* on the web, `InputOTP.hooks.native.ts` on React Native). Pure: no React, no
|
|
4
|
+
* DOM, no react-native.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* What each variant accepts. `masked` constrains nothing — it only changes what
|
|
9
|
+
* is drawn — so it has no pattern here.
|
|
10
|
+
*/
|
|
11
|
+
export const PATTERNS: Record<string, RegExp> = {
|
|
12
|
+
numeric: /^\d*$/,
|
|
13
|
+
alphanumeric: /^[a-zA-Z0-9]*$/,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/** Whether `text` is something this variant will take. */
|
|
17
|
+
export const isAllowed = (variant: string, text: string) => (PATTERNS[variant] ?? /.*/).test(text);
|
|
18
|
+
|
|
19
|
+
/** The digit array is always `length` long, blank-padded on the right. */
|
|
20
|
+
export const padTo = (digits: string[], length: number) =>
|
|
21
|
+
Array.from({ length }, (_, i) => digits[i] ?? '');
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* What a change to the numeric FIRST slot is, now that its `maxLength` is the
|
|
25
|
+
* code's length rather than 1 (FUT-4144).
|
|
26
|
+
*
|
|
27
|
+
* That slot carries `one-time-code`, and the phone's SMS fill (or a password
|
|
28
|
+
* manager) writes the WHOLE code into it as one change, not a paste — kept to
|
|
29
|
+
* one character, the code lost every digit but the last. So:
|
|
30
|
+
*
|
|
31
|
+
* - `overtype`: a keystroke into the already-filled slot (its old character
|
|
32
|
+
* plus the new one). Ignored, exactly as `maxLength={1}` refused it before.
|
|
33
|
+
* - `code`: anything else longer than one character, written in one go.
|
|
34
|
+
* Spread across the slots like a paste.
|
|
35
|
+
*
|
|
36
|
+
* Every other slot and variant keeps `maxLength={1}` and never gets here.
|
|
37
|
+
*/
|
|
38
|
+
export function firstSlotFill(variant: string, index: number, inputValue: string, current: string) {
|
|
39
|
+
if (variant !== 'numeric' || index !== 0 || inputValue.length < 2) return null;
|
|
40
|
+
const overtype = inputValue.length === 2 && current !== '' && inputValue.includes(current);
|
|
41
|
+
return overtype ? 'overtype' : 'code';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The code inside a first-slot fill. A phone that INSERTS the SMS code at the
|
|
46
|
+
* caret rather than replacing the slot leaves the digit already there in
|
|
47
|
+
* front: `4` + `482913` arrives as `4482913`, which spread as-is would give
|
|
48
|
+
* `448291`. Longer than the code and led by that digit: the digit is dropped.
|
|
49
|
+
*/
|
|
50
|
+
export const codeOfFill = (inputValue: string, current: string, length: number): string =>
|
|
51
|
+
inputValue.length > length && current !== '' && inputValue.startsWith(current) ? inputValue.slice(1) : inputValue;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { codeOfFill, firstSlotFill, isAllowed, padTo } from './InputOTP.core';
|
|
4
|
+
|
|
5
|
+
/** What a box needs from the element behind it: to take the focus. */
|
|
6
|
+
interface Focusable {
|
|
7
|
+
focus: () => void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface NativeOtpInput {
|
|
11
|
+
variant: string;
|
|
12
|
+
length: number;
|
|
13
|
+
value: string;
|
|
14
|
+
onChange?: (value: string) => void;
|
|
15
|
+
onComplete?: (value: string) => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The native boxes' digits — the web hook's rules (`InputOTP.hooks.ts`) over
|
|
20
|
+
* React Native's events: `onChangeText` carries the box's whole new text and
|
|
21
|
+
* `onKeyPress` carries only the key's name, and there is no paste event at
|
|
22
|
+
* all. A pasted or SMS-filled code arrives as a change of the FIRST box, whose
|
|
23
|
+
* `maxLength` is the code's length plus one for exactly that reason, and is
|
|
24
|
+
* spread across the boxes by the same `firstSlotFill` / `codeOfFill` the web
|
|
25
|
+
* uses.
|
|
26
|
+
*/
|
|
27
|
+
export const useNativeOtpDigits = ({ variant, length, value, onChange, onComplete }: NativeOtpInput) => {
|
|
28
|
+
const [digits, setDigits] = useState<string[]>(() => padTo([], length));
|
|
29
|
+
const boxRefs = useRef<(Focusable | null)[]>([]);
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
setDigits(padTo(value.split('').slice(0, length), length));
|
|
33
|
+
}, [value, length]);
|
|
34
|
+
|
|
35
|
+
const focusBox = useCallback((index: number) => boxRefs.current[index]?.focus(), []);
|
|
36
|
+
|
|
37
|
+
const publish = useCallback(
|
|
38
|
+
(next: string) => {
|
|
39
|
+
onChange?.(next);
|
|
40
|
+
if (next.length === length) onComplete?.(next);
|
|
41
|
+
},
|
|
42
|
+
[length, onChange, onComplete],
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
/** A whole code laid across the boxes from the first one. */
|
|
46
|
+
const spread = useCallback(
|
|
47
|
+
(text: string) => {
|
|
48
|
+
const code = text.slice(0, length);
|
|
49
|
+
if (!code || !isAllowed(variant, code)) return;
|
|
50
|
+
setDigits(padTo(code.split(''), length));
|
|
51
|
+
publish(code);
|
|
52
|
+
focusBox(Math.min(code.length, length - 1));
|
|
53
|
+
},
|
|
54
|
+
[variant, length, publish, focusBox],
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const handleChangeText = useCallback(
|
|
58
|
+
(index: number, text: string) => {
|
|
59
|
+
// The web's paste spreads a code for EVERY variant; React Native has no
|
|
60
|
+
// paste event, so a code arrives as a change of the first box, read by
|
|
61
|
+
// the numeric rule for `alphanumeric` too (`masked` shows a bullet, whose
|
|
62
|
+
// text no longer holds the digit it hides: it keeps one character a box).
|
|
63
|
+
const fill = firstSlotFill(variant === 'alphanumeric' ? 'numeric' : variant, index, text, digits[0] ?? '');
|
|
64
|
+
if (fill) return fill === 'code' ? spread(codeOfFill(text, digits[0] ?? '', length)) : undefined;
|
|
65
|
+
if (!isAllowed(variant, text)) return;
|
|
66
|
+
const next = [...digits];
|
|
67
|
+
next[index] = text.slice(-1);
|
|
68
|
+
setDigits(next);
|
|
69
|
+
publish(next.join(''));
|
|
70
|
+
if (text && index < length - 1) focusBox(index + 1);
|
|
71
|
+
},
|
|
72
|
+
[variant, digits, length, publish, focusBox, spread],
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
/** Backspace in a box that is already empty steps back to the one before. */
|
|
76
|
+
const handleKey = useCallback(
|
|
77
|
+
(index: number, key: string) => {
|
|
78
|
+
if (key === 'Backspace' && !digits[index] && index > 0) focusBox(index - 1);
|
|
79
|
+
},
|
|
80
|
+
[digits, focusBox],
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
return { digits, boxRefs, handleChangeText, handleKey };
|
|
84
|
+
};
|
|
@@ -1,51 +1,6 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* What each variant accepts. `masked` constrains nothing — it only changes what
|
|
6
|
-
* is drawn — so it has no pattern here.
|
|
7
|
-
*/
|
|
8
|
-
const PATTERNS: Record<string, RegExp> = {
|
|
9
|
-
numeric: /^\d*$/,
|
|
10
|
-
alphanumeric: /^[a-zA-Z0-9]*$/,
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
/** Whether `text` is something this variant will take. */
|
|
14
|
-
const isAllowed = (variant: string, text: string) => (PATTERNS[variant] ?? /.*/).test(text);
|
|
15
|
-
|
|
16
|
-
/** The digit array is always `length` long, blank-padded on the right. */
|
|
17
|
-
const padTo = (digits: string[], length: number) =>
|
|
18
|
-
Array.from({ length }, (_, i) => digits[i] ?? '');
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* What a change to the numeric FIRST slot is, now that its `maxLength` is the
|
|
22
|
-
* code's length rather than 1 (FUT-4144).
|
|
23
|
-
*
|
|
24
|
-
* That slot carries `one-time-code`, and the phone's SMS fill (or a password
|
|
25
|
-
* manager) writes the WHOLE code into it as one change, not a paste — kept to
|
|
26
|
-
* one character, the code lost every digit but the last. So:
|
|
27
|
-
*
|
|
28
|
-
* - `overtype`: a keystroke into the already-filled slot (its old character
|
|
29
|
-
* plus the new one). Ignored, exactly as `maxLength={1}` refused it before.
|
|
30
|
-
* - `code`: anything else longer than one character, written in one go.
|
|
31
|
-
* Spread across the slots like a paste.
|
|
32
|
-
*
|
|
33
|
-
* Every other slot and variant keeps `maxLength={1}` and never gets here.
|
|
34
|
-
*/
|
|
35
|
-
function firstSlotFill(variant: string, index: number, inputValue: string, current: string) {
|
|
36
|
-
if (variant !== 'numeric' || index !== 0 || inputValue.length < 2) return null;
|
|
37
|
-
const overtype = inputValue.length === 2 && current !== '' && inputValue.includes(current);
|
|
38
|
-
return overtype ? 'overtype' : 'code';
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* The code inside a first-slot fill. A phone that INSERTS the SMS code at the
|
|
43
|
-
* caret rather than replacing the slot leaves the digit already there in
|
|
44
|
-
* front: `4` + `482913` arrives as `4482913`, which spread as-is would give
|
|
45
|
-
* `448291`. Longer than the code and led by that digit: the digit is dropped.
|
|
46
|
-
*/
|
|
47
|
-
const codeOfFill = (inputValue: string, current: string, length: number): string =>
|
|
48
|
-
inputValue.length > length && current !== '' && inputValue.startsWith(current) ? inputValue.slice(1) : inputValue;
|
|
3
|
+
import { codeOfFill, firstSlotFill, isAllowed, padTo } from './InputOTP.core';
|
|
49
4
|
|
|
50
5
|
interface OtpInput {
|
|
51
6
|
variant: string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The numbers both renderers read (see `NATIVE.md`, "Numbers").
|
|
3
|
+
*
|
|
4
|
+
* Each box's type size, in design px, per size step; its side is the theme's
|
|
5
|
+
* field height for that step (a square), its weight 600.
|
|
6
|
+
*/
|
|
7
|
+
export const OTP_FONT_PX: Record<'xs' | 'sm' | 'md' | 'lg' | 'xl', number> = {
|
|
8
|
+
xs: 12,
|
|
9
|
+
sm: 14,
|
|
10
|
+
md: 16,
|
|
11
|
+
lg: 18,
|
|
12
|
+
xl: 20,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/** The gap between two boxes: MUI's `gap: 1`, one 8px spacing unit. */
|
|
16
|
+
export const OTP_GAP_PX = 8;
|
|
17
|
+
|
|
18
|
+
/** The border: 1px at rest, 2px focused (MUI's focused outline). */
|
|
19
|
+
export const OTP_BORDER = { rest: 1, focused: 2 } as const;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Platform, StyleSheet, TextInput, View, type TextInputProps, type TextStyle } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { useNativeOtpDigits } from './InputOTP.hooks.native';
|
|
5
|
+
import { OTP_BORDER, OTP_FONT_PX, OTP_GAP_PX } from './InputOTP.metrics';
|
|
6
|
+
import type { InputOTPProps } from './InputOTP.types.native';
|
|
7
|
+
import { webAria, webDisabled } from '../../../platform/aria';
|
|
8
|
+
import { resolveFieldEdge } from '../../../tokens/field-edge.core';
|
|
9
|
+
import { fieldHeightPx } from '../../../tokens/field-height.core';
|
|
10
|
+
import type { UiPaletteKey, UiTheme } from '../../../tokens/theme';
|
|
11
|
+
import type { SizeValue } from '../../../tokens/vocabulary';
|
|
12
|
+
import { useUiTheme } from '../../../provider/use-ui-theme.native';
|
|
13
|
+
|
|
14
|
+
const PALETTE_KEYS: readonly UiPaletteKey[] = ['primary', 'secondary', 'success', 'warning', 'info', 'danger', 'neutral'];
|
|
15
|
+
|
|
16
|
+
/** The palette slot a `color` names; anything else is `primary`, as on the web. */
|
|
17
|
+
function accentOf(theme: UiTheme, color: string): string {
|
|
18
|
+
const key = PALETTE_KEYS.find((candidate) => candidate === color) ?? 'primary';
|
|
19
|
+
return theme.palette[key].main;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The keypad and the one-time-code fill, the web's `keypadProps` in React
|
|
24
|
+
* Native's words: digits only for `numeric`, and on the FIRST box the hint that
|
|
25
|
+
* lets the phone offer the code from an SMS — `oneTimeCode` on iOS,
|
|
26
|
+
* `sms-otp` on Android.
|
|
27
|
+
*/
|
|
28
|
+
function keypadProps(variant: string, index: number): Partial<TextInputProps> {
|
|
29
|
+
// A code is not prose: no capital on the first letter, no autocorrect.
|
|
30
|
+
if (variant !== 'numeric') return { autoCapitalize: 'none', autoCorrect: false, spellCheck: false };
|
|
31
|
+
const fill: Partial<TextInputProps> =
|
|
32
|
+
index === 0
|
|
33
|
+
? Platform.select<Partial<TextInputProps>>({
|
|
34
|
+
ios: { textContentType: 'oneTimeCode', autoComplete: 'one-time-code' },
|
|
35
|
+
android: { autoComplete: 'sms-otp' },
|
|
36
|
+
default: { autoComplete: 'one-time-code' },
|
|
37
|
+
})
|
|
38
|
+
: {};
|
|
39
|
+
return { keyboardType: 'number-pad', inputMode: 'numeric', ...fill };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The first box takes a whole code in one change (see the web's `slotMaxLength`), except `masked`'s. */
|
|
43
|
+
const boxMaxLength = (variant: string, index: number, length: number): number =>
|
|
44
|
+
variant !== 'masked' && index === 0 ? length + 1 : 1;
|
|
45
|
+
|
|
46
|
+
interface BoxState {
|
|
47
|
+
focused: boolean;
|
|
48
|
+
error: boolean;
|
|
49
|
+
disabled: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** One box's paint: the web slot's square, border and type, from the same numbers. */
|
|
53
|
+
function boxStyle(theme: UiTheme, size: SizeValue, accent: string, state: BoxState): TextStyle {
|
|
54
|
+
const side = fieldHeightPx(theme.fieldHeight, size);
|
|
55
|
+
const edge = resolveFieldEdge(theme.palette.divider, theme.palette.background.paper);
|
|
56
|
+
// Error and disabled outrank focus, as in MUI's outlined input (and the native `Input`).
|
|
57
|
+
const borderColor = state.error
|
|
58
|
+
? theme.palette.danger.main
|
|
59
|
+
: state.disabled
|
|
60
|
+
? theme.palette.action.disabled
|
|
61
|
+
: state.focused
|
|
62
|
+
? accent
|
|
63
|
+
: edge;
|
|
64
|
+
return {
|
|
65
|
+
width: side,
|
|
66
|
+
height: side,
|
|
67
|
+
borderRadius: theme.radius.field,
|
|
68
|
+
borderWidth: state.focused ? OTP_BORDER.focused : OTP_BORDER.rest,
|
|
69
|
+
borderColor,
|
|
70
|
+
backgroundColor: theme.palette.background.paper,
|
|
71
|
+
color: state.disabled ? theme.palette.text.disabled : theme.palette.text.primary,
|
|
72
|
+
fontFamily: theme.typography.fontFamily,
|
|
73
|
+
fontSize: OTP_FONT_PX[size],
|
|
74
|
+
fontWeight: '600',
|
|
75
|
+
textAlign: 'center',
|
|
76
|
+
padding: 0,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The native `InputOTP`: one row of boxes, one character each, that moves
|
|
82
|
+
* forward as it is typed, steps back on Backspace in an empty box, and spreads
|
|
83
|
+
* a code the phone fills (or a paste) across every box from the first.
|
|
84
|
+
*
|
|
85
|
+
* The same props as the web one; the row is a `group` named by `aria-label`,
|
|
86
|
+
* each box is `${dataTestId}-slot-${index}`. Gaps against the web:
|
|
87
|
+
* `NATIVE-NOTES.md`.
|
|
88
|
+
*/
|
|
89
|
+
export const InputOTP = React.forwardRef<View, InputOTPProps>((props, ref) => {
|
|
90
|
+
const {
|
|
91
|
+
variant = 'numeric',
|
|
92
|
+
color = 'primary',
|
|
93
|
+
size = 'md',
|
|
94
|
+
length = 6,
|
|
95
|
+
value = '',
|
|
96
|
+
onChange,
|
|
97
|
+
onComplete,
|
|
98
|
+
autoFocus = false,
|
|
99
|
+
error = false,
|
|
100
|
+
disabled = false,
|
|
101
|
+
dataTestId,
|
|
102
|
+
style,
|
|
103
|
+
'aria-label': ariaLabel,
|
|
104
|
+
} = props;
|
|
105
|
+
|
|
106
|
+
const theme = useUiTheme();
|
|
107
|
+
const accent = accentOf(theme, color);
|
|
108
|
+
const [focusedIndex, setFocusedIndex] = React.useState<number | null>(null);
|
|
109
|
+
const { digits, boxRefs, handleChangeText, handleKey } = useNativeOtpDigits({
|
|
110
|
+
variant,
|
|
111
|
+
length,
|
|
112
|
+
value,
|
|
113
|
+
onChange,
|
|
114
|
+
onComplete,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<View ref={ref} testID={dataTestId} role="group" aria-label={ariaLabel} style={[styles.row, style]}>
|
|
119
|
+
{digits.map((digit, index) => (
|
|
120
|
+
<TextInput
|
|
121
|
+
key={index}
|
|
122
|
+
ref={(element) => {
|
|
123
|
+
boxRefs.current[index] = element;
|
|
124
|
+
}}
|
|
125
|
+
testID={dataTestId ? `${dataTestId}-slot-${index}` : undefined}
|
|
126
|
+
value={variant === 'masked' ? (digit ? '•' : '') : digit}
|
|
127
|
+
onChangeText={(text) => handleChangeText(index, text)}
|
|
128
|
+
onKeyPress={(event) => handleKey(index, event.nativeEvent.key)}
|
|
129
|
+
onFocus={() => setFocusedIndex(index)}
|
|
130
|
+
onBlur={() => setFocusedIndex((current) => (current === index ? null : current))}
|
|
131
|
+
autoFocus={autoFocus && index === 0}
|
|
132
|
+
editable={!disabled}
|
|
133
|
+
aria-disabled={disabled}
|
|
134
|
+
{...webAria({ 'aria-invalid': error })}
|
|
135
|
+
maxLength={boxMaxLength(variant, index, length)}
|
|
136
|
+
style={boxStyle(theme, size, accent, { focused: focusedIndex === index && !disabled, error, disabled })}
|
|
137
|
+
{...webDisabled(disabled)}
|
|
138
|
+
{...keypadProps(variant, index)}
|
|
139
|
+
/>
|
|
140
|
+
))}
|
|
141
|
+
</View>
|
|
142
|
+
);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
InputOTP.displayName = 'InputOTP';
|
|
146
|
+
|
|
147
|
+
const styles = StyleSheet.create({
|
|
148
|
+
row: {
|
|
149
|
+
flexDirection: 'row',
|
|
150
|
+
justifyContent: 'center',
|
|
151
|
+
alignItems: 'center',
|
|
152
|
+
gap: OTP_GAP_PX,
|
|
153
|
+
},
|
|
154
|
+
});
|
|
@@ -7,6 +7,8 @@ import { asFieldSize, fieldHeight } from '../../../tokens/field-height';
|
|
|
7
7
|
import { absoluteInk, controlNeutral } from '../../../tokens/ink';
|
|
8
8
|
import { rem } from '../../../tokens/relative';
|
|
9
9
|
|
|
10
|
+
import { OTP_FONT_PX } from './InputOTP.metrics';
|
|
11
|
+
|
|
10
12
|
interface ColorPalette {
|
|
11
13
|
main: string;
|
|
12
14
|
dark?: string;
|
|
@@ -47,16 +49,7 @@ const getColorFromTheme = (theme: Theme, color: string): ColorPalette => {
|
|
|
47
49
|
};
|
|
48
50
|
};
|
|
49
51
|
|
|
50
|
-
type SizeKey =
|
|
51
|
-
|
|
52
|
-
/** Each slot's type, in design px. Its side is the theme's field height for the size (a square). */
|
|
53
|
-
const SIZES: Record<SizeKey, { fontPx: number }> = {
|
|
54
|
-
xs: { fontPx: 12 },
|
|
55
|
-
sm: { fontPx: 14 },
|
|
56
|
-
md: { fontPx: 16 },
|
|
57
|
-
lg: { fontPx: 18 },
|
|
58
|
-
xl: { fontPx: 20 },
|
|
59
|
-
};
|
|
52
|
+
type SizeKey = keyof typeof OTP_FONT_PX;
|
|
60
53
|
|
|
61
54
|
export interface OtpSlotFlags {
|
|
62
55
|
customColor?: string;
|
|
@@ -68,7 +61,7 @@ export interface OtpSlotFlags {
|
|
|
68
61
|
export const otpSlotSx = (theme: Theme, flags: OtpSlotFlags): CSSObject => {
|
|
69
62
|
const { customColor = 'primary', customSize = 'md', glass, gradient } = flags;
|
|
70
63
|
const palette = getColorFromTheme(theme, customColor);
|
|
71
|
-
const
|
|
64
|
+
const fontPx = OTP_FONT_PX[customSize as SizeKey] ?? OTP_FONT_PX.md;
|
|
72
65
|
// A slot is a field: a square of the theme's field height for its size.
|
|
73
66
|
const side = fieldHeight(theme, asFieldSize(customSize));
|
|
74
67
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { StyleProp, ViewStyle } from 'react-native';
|
|
2
|
+
|
|
3
|
+
import type { InputOTPBaseProps } from './InputOTP.base';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The native `InputOTP`'s props: the shared contract, plus the group's
|
|
7
|
+
* accessible name (the web takes it as a plain `aria-label` attribute) and the
|
|
8
|
+
* row's `style`.
|
|
9
|
+
*/
|
|
10
|
+
export interface InputOTPProps extends InputOTPBaseProps {
|
|
11
|
+
/** Names the boxes together, as one group. */
|
|
12
|
+
'aria-label'?: string;
|
|
13
|
+
/** The row's own style; the boxes keep theirs. */
|
|
14
|
+
style?: StyleProp<ViewStyle>;
|
|
15
|
+
}
|
|
@@ -1,69 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { InputOTPBaseProps } from './InputOTP.base';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* The variant of the OTP input
|
|
6
|
-
*/
|
|
7
|
-
variant?: 'numeric' | 'alphanumeric' | 'masked';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* The color theme of the OTP input
|
|
11
|
-
*/
|
|
12
|
-
color?: ColorValue;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* The size of the OTP input
|
|
16
|
-
*/
|
|
17
|
-
size?: SizeValue;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Number of OTP digits
|
|
21
|
-
*/
|
|
22
|
-
length?: number;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Current value
|
|
26
|
-
*/
|
|
27
|
-
value?: string;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Called when value changes
|
|
31
|
-
*/
|
|
32
|
-
onChange?: (value: string) => void;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Called when OTP is complete
|
|
36
|
-
*/
|
|
37
|
-
onComplete?: (value: string) => void;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Whether the input should have glass morphism effect
|
|
41
|
-
*/
|
|
42
|
-
glass?: boolean;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Whether the input should have gradient effects
|
|
46
|
-
*/
|
|
47
|
-
gradient?: boolean;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Whether to auto-focus first input
|
|
51
|
-
*/
|
|
52
|
-
autoFocus?: boolean;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Error state
|
|
56
|
-
*/
|
|
57
|
-
error?: boolean;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Disabled state
|
|
61
|
-
*/
|
|
62
|
-
disabled?: boolean;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Test ID for automated testing
|
|
66
|
-
* Container will have this ID, and individual slots will have {dataTestId}-slot-{index}
|
|
67
|
-
*/
|
|
68
|
-
dataTestId?: string;
|
|
69
|
-
}
|
|
3
|
+
/** The web `InputOTP`'s props: the shared contract, nothing MUI adds. */
|
|
4
|
+
export type InputOTPProps = InputOTPBaseProps;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# InputOTP on React Native
|
|
2
|
+
|
|
3
|
+
Known rendering gaps, one bullet each; `pnpm native:ledger` reads them.
|
|
4
|
+
|
|
5
|
+
- There is no paste event on React Native: a pasted or SMS-filled code arrives as a change of the first box (its `maxLength` is the code's length plus one), and is spread from there by the same rules the web's paste uses — for `numeric` and `alphanumeric`. A `masked` box shows a bullet, so a paste into it keeps one character: the web spreads it.
|
|
6
|
+
- Hover has no touch equivalent, so the web's hover border is not drawn; focus is, in the same colour and 2px width.
|
|
7
|
+
- `glass` and `gradient` are accepted and draw the plain box: React Native core has no backdrop blur and no gradient border.
|
|
8
|
+
- Arrow keys do not move between boxes (a phone keypad has none); Backspace in an empty box steps back, as on the web.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/form/InputOTP/InputOTP.styles.ts"],"sourcesContent":["import { alpha } from '@mui/material/styles/index.js';\nimport type { CSSObject, Theme } from '@mui/material/styles/index.js';\n\nimport { fieldEdge } from '../../../tokens/field-edge';\nimport { fieldRadius } from '../../../tokens/field-radius';\nimport { asFieldSize, fieldHeight } from '../../../tokens/field-height';\nimport { absoluteInk, controlNeutral } from '../../../tokens/ink';\nimport { rem } from '../../../tokens/relative';\n\ninterface ColorPalette {\n main: string;\n dark?: string;\n light?: string;\n contrastText?: string;\n}\n\n/** `neutral` is not a MUI palette entry, so it is built from the grey ramp. */\nconst neutralPalette = (theme: Theme): ColorPalette => controlNeutral(theme);\n\n/** `danger` is this component's name for the error palette. */\nconst namedPalette = (theme: Theme, color: string): ColorPalette => {\n const colorMap: Record<string, ColorPalette> = {\n primary: theme.palette.primary,\n secondary: theme.palette.secondary,\n success: theme.palette.success,\n warning: theme.palette.warning,\n info: theme.palette.info,\n danger: theme.palette.error,\n };\n\n return colorMap[color] || theme.palette.primary;\n};\n\nconst getColorFromTheme = (theme: Theme, color: string): ColorPalette => {\n if (color === 'neutral') {\n return neutralPalette(theme);\n }\n\n const palette = namedPalette(theme, color);\n const { primary } = theme.palette;\n\n return {\n main: palette.main || primary.main,\n dark: palette.dark || palette.main || primary.dark,\n light: palette.light || palette.main || primary.light,\n contrastText: palette.contrastText || absoluteInk(theme).white,\n };\n};\n\ntype SizeKey = 'xs' | 'sm' | 'md' | 'lg' | 'xl';\n\n/** Each slot's type, in design px. Its side is the theme's field height for the size (a square). */\nconst SIZES: Record<SizeKey, { fontPx: number }> = {\n xs: { fontPx: 12 },\n sm: { fontPx: 14 },\n md: { fontPx: 16 },\n lg: { fontPx: 18 },\n xl: { fontPx: 20 },\n};\n\nexport interface OtpSlotFlags {\n customColor?: string;\n customSize?: string;\n glass?: boolean;\n gradient?: boolean;\n}\n\nexport const otpSlotSx = (theme: Theme, flags: OtpSlotFlags): CSSObject => {\n const { customColor = 'primary', customSize = 'md', glass, gradient } = flags;\n const palette = getColorFromTheme(theme, customColor);\n const { fontPx } = SIZES[customSize as SizeKey] ?? SIZES.md;\n // A slot is a field: a square of the theme's field height for its size.\n const side = fieldHeight(theme, asFieldSize(customSize));\n\n return {\n width: side,\n height: side,\n '& .MuiOutlinedInput-root': {\n width: side,\n height: side,\n fontSize: rem(theme, fontPx),\n fontWeight: 600,\n textAlign: 'center',\n borderRadius: fieldRadius(theme),\n ...(glass && {\n backgroundColor: alpha(theme.palette.background.paper, 0.1),\n backdropFilter: `blur(${rem(theme, 20)})`,\n '& fieldset': { border: `1px solid ${fieldEdge(theme)}` },\n }),\n ...(gradient && {\n '&.Mui-focused fieldset': {\n background: `linear-gradient(135deg, ${palette.main}, ${palette.light})`,\n borderWidth: rem(theme, 2),\n },\n }),\n '& input': { textAlign: 'center', padding: 0, fontWeight: 'inherit' },\n ...(!glass && { '& fieldset': { borderColor: fieldEdge(theme) } }),\n '&:hover fieldset': { borderColor: palette.main },\n '&.Mui-focused fieldset': { borderColor: palette.main, borderWidth: rem(theme, 2) },\n },\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,SAAS,aAAa;AAiBtB,IAAM,iBAAiB,CAAC,UAA+B,eAAe,KAAK;AAG3E,IAAM,eAAe,CAAC,OAAc,UAAgC;AAClE,QAAM,WAAyC;AAAA,IAC7C,SAAS,MAAM,QAAQ;AAAA,IACvB,WAAW,MAAM,QAAQ;AAAA,IACzB,SAAS,MAAM,QAAQ;AAAA,IACvB,SAAS,MAAM,QAAQ;AAAA,IACvB,MAAM,MAAM,QAAQ;AAAA,IACpB,QAAQ,MAAM,QAAQ;AAAA,EACxB;AAEA,SAAO,SAAS,KAAK,KAAK,MAAM,QAAQ;AAC1C;AAEA,IAAM,oBAAoB,CAAC,OAAc,UAAgC;AACvE,MAAI,UAAU,WAAW;AACvB,WAAO,eAAe,KAAK;AAAA,EAC7B;AAEA,QAAM,UAAU,aAAa,OAAO,KAAK;AACzC,QAAM,EAAE,QAAQ,IAAI,MAAM;AAE1B,SAAO;AAAA,IACL,MAAM,QAAQ,QAAQ,QAAQ;AAAA,IAC9B,MAAM,QAAQ,QAAQ,QAAQ,QAAQ,QAAQ;AAAA,IAC9C,OAAO,QAAQ,SAAS,QAAQ,QAAQ,QAAQ;AAAA,IAChD,cAAc,QAAQ,gBAAgB,YAAY,KAAK,EAAE;AAAA,EAC3D;AACF;AAKA,IAAM,QAA6C;AAAA,EACjD,IAAI,EAAE,QAAQ,GAAG;AAAA,EACjB,IAAI,EAAE,QAAQ,GAAG;AAAA,EACjB,IAAI,EAAE,QAAQ,GAAG;AAAA,EACjB,IAAI,EAAE,QAAQ,GAAG;AAAA,EACjB,IAAI,EAAE,QAAQ,GAAG;AACnB;AASO,IAAM,YAAY,CAAC,OAAc,UAAmC;AACzE,QAAM,EAAE,cAAc,WAAW,aAAa,MAAM,OAAO,SAAS,IAAI;AACxE,QAAM,UAAU,kBAAkB,OAAO,WAAW;AACpD,QAAM,EAAE,OAAO,IAAI,MAAM,UAAqB,KAAK,MAAM;AAEzD,QAAM,OAAO,YAAY,OAAO,YAAY,UAAU,CAAC;AAEvD,SAAO;AAAA,IACL,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,4BAA4B;AAAA,MAC1B,OAAO;AAAA,MACP,QAAQ;AAAA,MACR,UAAU,IAAI,OAAO,MAAM;AAAA,MAC3B,YAAY;AAAA,MACZ,WAAW;AAAA,MACX,cAAc,YAAY,KAAK;AAAA,MAC/B,GAAI,SAAS;AAAA,QACX,iBAAiB,MAAM,MAAM,QAAQ,WAAW,OAAO,GAAG;AAAA,QAC1D,gBAAgB,QAAQ,IAAI,OAAO,EAAE,CAAC;AAAA,QACtC,cAAc,EAAE,QAAQ,aAAa,UAAU,KAAK,CAAC,GAAG;AAAA,MAC1D;AAAA,MACA,GAAI,YAAY;AAAA,QACd,0BAA0B;AAAA,UACxB,YAAY,2BAA2B,QAAQ,IAAI,KAAK,QAAQ,KAAK;AAAA,UACrE,aAAa,IAAI,OAAO,CAAC;AAAA,QAC3B;AAAA,MACF;AAAA,MACA,WAAW,EAAE,WAAW,UAAU,SAAS,GAAG,YAAY,UAAU;AAAA,MACpE,GAAI,CAAC,SAAS,EAAE,cAAc,EAAE,aAAa,UAAU,KAAK,EAAE,EAAE;AAAA,MAChE,oBAAoB,EAAE,aAAa,QAAQ,KAAK;AAAA,MAChD,0BAA0B,EAAE,aAAa,QAAQ,MAAM,aAAa,IAAI,OAAO,CAAC,EAAE;AAAA,IACpF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/form/InputOTP/InputOTP.hooks.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\n\n\n/**\n * What each variant accepts. `masked` constrains nothing — it only changes what\n * is drawn — so it has no pattern here.\n */\nconst PATTERNS: Record<string, RegExp> = {\n numeric: /^\\d*$/,\n alphanumeric: /^[a-zA-Z0-9]*$/,\n};\n\n/** Whether `text` is something this variant will take. */\nconst isAllowed = (variant: string, text: string) => (PATTERNS[variant] ?? /.*/).test(text);\n\n/** The digit array is always `length` long, blank-padded on the right. */\nconst padTo = (digits: string[], length: number) =>\n Array.from({ length }, (_, i) => digits[i] ?? '');\n\n/**\n * What a change to the numeric FIRST slot is, now that its `maxLength` is the\n * code's length rather than 1 (FUT-4144).\n *\n * That slot carries `one-time-code`, and the phone's SMS fill (or a password\n * manager) writes the WHOLE code into it as one change, not a paste — kept to\n * one character, the code lost every digit but the last. So:\n *\n * - `overtype`: a keystroke into the already-filled slot (its old character\n * plus the new one). Ignored, exactly as `maxLength={1}` refused it before.\n * - `code`: anything else longer than one character, written in one go.\n * Spread across the slots like a paste.\n *\n * Every other slot and variant keeps `maxLength={1}` and never gets here.\n */\nfunction firstSlotFill(variant: string, index: number, inputValue: string, current: string) {\n if (variant !== 'numeric' || index !== 0 || inputValue.length < 2) return null;\n const overtype = inputValue.length === 2 && current !== '' && inputValue.includes(current);\n return overtype ? 'overtype' : 'code';\n}\n\n/**\n * The code inside a first-slot fill. A phone that INSERTS the SMS code at the\n * caret rather than replacing the slot leaves the digit already there in\n * front: `4` + `482913` arrives as `4482913`, which spread as-is would give\n * `448291`. Longer than the code and led by that digit: the digit is dropped.\n */\nconst codeOfFill = (inputValue: string, current: string, length: number): string =>\n inputValue.length > length && current !== '' && inputValue.startsWith(current) ? inputValue.slice(1) : inputValue;\n\ninterface OtpInput {\n variant: string;\n length: number;\n value: string;\n onChange?: (value: string) => void;\n onComplete?: (value: string) => void;\n}\n\n/**\n * The digits, and the three ways they change: typing, the keys that move\n * between slots, and a paste into the first one.\n *\n * Focus moves as a consequence of entry, so the input refs live here with the\n * state that drives them.\n */\nexport const useOtpDigits = ({ variant, length, value, onChange, onComplete }: OtpInput) => {\n const [digits, setDigits] = useState<string[]>(() => padTo([], length));\n const inputRefs = useRef<(globalThis.HTMLInputElement | null)[]>([]);\n\n useEffect(() => {\n setDigits(padTo(value.split('').slice(0, length), length));\n }, [value, length]);\n\n const focusSlot = useCallback((index: number) => {\n inputRefs.current[index]?.focus();\n }, []);\n\n /** Publishes the joined value, and reports completion when every slot is full. */\n const publish = useCallback(\n (next: string) => {\n onChange?.(next);\n if (next.length === length) {\n onComplete?.(next);\n }\n },\n [length, onChange, onComplete],\n );\n\n /** Lays a whole code across the slots from the first: a paste, or an OS/SMS fill. */\n const spread = useCallback(\n (text: string) => {\n const code = text.slice(0, length);\n // An empty code is not a rejection, but it is nothing to apply either.\n if (!code || !isAllowed(variant, code)) return;\n\n setDigits(padTo(code.split(''), length));\n publish(code);\n },\n [variant, length, publish],\n );\n\n const handleInputChange = useCallback(\n (index: number, inputValue: string) => {\n const fill = firstSlotFill(variant, index, inputValue, digits[0] ?? '');\n if (fill) return fill === 'code' ? spread(codeOfFill(inputValue, digits[0] ?? '', length)) : undefined;\n if (!isAllowed(variant, inputValue)) return;\n\n const next = [...digits];\n next[index] = inputValue.slice(-1); // one character per slot\n setDigits(next);\n publish(next.join(''));\n\n if (inputValue && index < length - 1) {\n focusSlot(index + 1);\n }\n },\n [variant, digits, length, publish, focusSlot, spread],\n );\n\n const handleKeyDown = useCallback(\n (index: number, e: React.KeyboardEvent) => {\n // Backspace in an already-empty slot steps back rather than deleting.\n const back =\n (e.key === 'Backspace' && !digits[index]) || e.key === 'ArrowLeft';\n\n if (back && index > 0) {\n focusSlot(index - 1);\n } else if (e.key === 'ArrowRight' && index < length - 1) {\n focusSlot(index + 1);\n }\n },\n [digits, length, focusSlot],\n );\n\n const handlePaste = useCallback(\n (e: React.ClipboardEvent) => {\n e.preventDefault();\n spread(e.clipboardData.getData('text'));\n },\n [spread],\n );\n\n return { digits, inputRefs, handleInputChange, handleKeyDown, handlePaste };\n};\n"],"mappings":";AAAA,SAAS,aAAa,WAAW,QAAQ,gBAAgB;AAOzD,IAAM,WAAmC;AAAA,EACvC,SAAS;AAAA,EACT,cAAc;AAChB;AAGA,IAAM,YAAY,CAAC,SAAiB,UAAkB,SAAS,OAAO,KAAK,MAAM,KAAK,IAAI;AAG1F,IAAM,QAAQ,CAAC,QAAkB,WAC/B,MAAM,KAAK,EAAE,OAAO,GAAG,CAAC,GAAG,MAAM,OAAO,CAAC,KAAK,EAAE;AAiBlD,SAAS,cAAc,SAAiB,OAAe,YAAoB,SAAiB;AAC1F,MAAI,YAAY,aAAa,UAAU,KAAK,WAAW,SAAS,EAAG,QAAO;AAC1E,QAAM,WAAW,WAAW,WAAW,KAAK,YAAY,MAAM,WAAW,SAAS,OAAO;AACzF,SAAO,WAAW,aAAa;AACjC;AAQA,IAAM,aAAa,CAAC,YAAoB,SAAiB,WACvD,WAAW,SAAS,UAAU,YAAY,MAAM,WAAW,WAAW,OAAO,IAAI,WAAW,MAAM,CAAC,IAAI;AAiBlG,IAAM,eAAe,CAAC,EAAE,SAAS,QAAQ,OAAO,UAAU,WAAW,MAAgB;AAC1F,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAmB,MAAM,MAAM,CAAC,GAAG,MAAM,CAAC;AACtE,QAAM,YAAY,OAA+C,CAAC,CAAC;AAEnE,YAAU,MAAM;AACd,cAAU,MAAM,MAAM,MAAM,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAAA,EAC3D,GAAG,CAAC,OAAO,MAAM,CAAC;AAElB,QAAM,YAAY,YAAY,CAAC,UAAkB;AAC/C,cAAU,QAAQ,KAAK,GAAG,MAAM;AAAA,EAClC,GAAG,CAAC,CAAC;AAGL,QAAM,UAAU;AAAA,IACd,CAAC,SAAiB;AAChB,iBAAW,IAAI;AACf,UAAI,KAAK,WAAW,QAAQ;AAC1B,qBAAa,IAAI;AAAA,MACnB;AAAA,IACF;AAAA,IACA,CAAC,QAAQ,UAAU,UAAU;AAAA,EAC/B;AAGA,QAAM,SAAS;AAAA,IACb,CAAC,SAAiB;AAChB,YAAM,OAAO,KAAK,MAAM,GAAG,MAAM;AAEjC,UAAI,CAAC,QAAQ,CAAC,UAAU,SAAS,IAAI,EAAG;AAExC,gBAAU,MAAM,KAAK,MAAM,EAAE,GAAG,MAAM,CAAC;AACvC,cAAQ,IAAI;AAAA,IACd;AAAA,IACA,CAAC,SAAS,QAAQ,OAAO;AAAA,EAC3B;AAEA,QAAM,oBAAoB;AAAA,IACxB,CAAC,OAAe,eAAuB;AACrC,YAAM,OAAO,cAAc,SAAS,OAAO,YAAY,OAAO,CAAC,KAAK,EAAE;AACtE,UAAI,KAAM,QAAO,SAAS,SAAS,OAAO,WAAW,YAAY,OAAO,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI;AAC7F,UAAI,CAAC,UAAU,SAAS,UAAU,EAAG;AAErC,YAAM,OAAO,CAAC,GAAG,MAAM;AACvB,WAAK,KAAK,IAAI,WAAW,MAAM,EAAE;AACjC,gBAAU,IAAI;AACd,cAAQ,KAAK,KAAK,EAAE,CAAC;AAErB,UAAI,cAAc,QAAQ,SAAS,GAAG;AACpC,kBAAU,QAAQ,CAAC;AAAA,MACrB;AAAA,IACF;AAAA,IACA,CAAC,SAAS,QAAQ,QAAQ,SAAS,WAAW,MAAM;AAAA,EACtD;AAEA,QAAM,gBAAgB;AAAA,IACpB,CAAC,OAAe,MAA2B;AAEzC,YAAM,OACH,EAAE,QAAQ,eAAe,CAAC,OAAO,KAAK,KAAM,EAAE,QAAQ;AAEzD,UAAI,QAAQ,QAAQ,GAAG;AACrB,kBAAU,QAAQ,CAAC;AAAA,MACrB,WAAW,EAAE,QAAQ,gBAAgB,QAAQ,SAAS,GAAG;AACvD,kBAAU,QAAQ,CAAC;AAAA,MACrB;AAAA,IACF;AAAA,IACA,CAAC,QAAQ,QAAQ,SAAS;AAAA,EAC5B;AAEA,QAAM,cAAc;AAAA,IAClB,CAAC,MAA4B;AAC3B,QAAE,eAAe;AACjB,aAAO,EAAE,cAAc,QAAQ,MAAM,CAAC;AAAA,IACxC;AAAA,IACA,CAAC,MAAM;AAAA,EACT;AAEA,SAAO,EAAE,QAAQ,WAAW,mBAAmB,eAAe,YAAY;AAC5E;","names":[]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|