@koine/react 2.0.0-beta.2 → 2.0.0-beta.5
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/Alert/Alert.js +27 -12
- package/Alert/Alert.mjs +16 -8
- package/Alert/Alert.stories.js +36 -0
- package/Alert/Alert.stories.mjs +15 -0
- package/Alert/index.js +5 -3
- package/Animations/Reveal.js +48 -18
- package/Animations/Reveal.mjs +38 -14
- package/Animations/Underline.js +25 -7
- package/Animations/Underline.mjs +14 -4
- package/Animations/index.js +7 -5
- package/Animations/useReveal.js +51 -43
- package/Animations/useReveal.mjs +42 -40
- package/Autocomplete/AutocompleteDownshift.js +166 -160
- package/Autocomplete/AutocompleteDownshift.mjs +156 -157
- package/Autocomplete/AutocompleteDownshiftMultiselect.js +361 -355
- package/Autocomplete/AutocompleteDownshiftMultiselect.mjs +351 -352
- package/Autocomplete/AutocompleteMui.d.ts +1 -1
- package/Autocomplete/AutocompleteMui.js +111 -137
- package/Autocomplete/AutocompleteMui.mjs +98 -90
- package/Autocomplete/AutocompleteReach.js +120 -114
- package/Autocomplete/AutocompleteReach.mjs +110 -111
- package/Autocomplete/components.js +129 -34
- package/Autocomplete/components.mjs +76 -23
- package/Autocomplete/helpers.js +25 -25
- package/Autocomplete/helpers.mjs +11 -5
- package/Autocomplete/index.js +14 -6
- package/Autocomplete/index.mjs +4 -3
- package/Bg/BgColor.js +55 -21
- package/Bg/BgColor.mjs +32 -16
- package/Bg/BgPhoto.js +78 -18
- package/Bg/BgPhoto.mjs +65 -12
- package/Bg/BgSvg.js +27 -14
- package/Bg/BgSvg.mjs +16 -8
- package/Bg/index.js +7 -5
- package/Breadcrumbs/Breadcrumbs.d.ts +1 -1
- package/Breadcrumbs/Breadcrumbs.js +85 -26
- package/Breadcrumbs/Breadcrumbs.mjs +70 -19
- package/Breadcrumbs/index.js +5 -3
- package/Buttons/Button.js +105 -16
- package/Buttons/Button.mjs +73 -9
- package/Buttons/ButtonComposite.d.ts +1 -1
- package/Buttons/ButtonComposite.js +76 -25
- package/Buttons/ButtonComposite.mjs +66 -22
- package/Buttons/ButtonFab.js +26 -8
- package/Buttons/ButtonFab.mjs +6 -4
- package/Buttons/ButtonLink.d.ts +1 -1
- package/Buttons/ButtonLink.js +26 -13
- package/Buttons/ButtonLink.mjs +14 -8
- package/Buttons/IconButton.js +40 -9
- package/Buttons/IconButton.mjs +18 -6
- package/Buttons/index.js +9 -7
- package/Calendar/CalendarDaygridCell.d.ts +2 -2
- package/Calendar/CalendarDaygridCell.js +70 -49
- package/Calendar/CalendarDaygridCell.mjs +58 -43
- package/Calendar/CalendarDaygridNav.d.ts +1 -1
- package/Calendar/CalendarDaygridNav.js +41 -20
- package/Calendar/CalendarDaygridNav.mjs +28 -13
- package/Calendar/CalendarDaygridTable.d.ts +3 -3
- package/Calendar/CalendarDaygridTable.js +88 -39
- package/Calendar/CalendarDaygridTable.mjs +73 -31
- package/Calendar/CalendarLegend.d.ts +1 -1
- package/Calendar/CalendarLegend.js +17 -10
- package/Calendar/CalendarLegend.mjs +8 -7
- package/Calendar/calendar-api-google.d.ts +1 -1
- package/Calendar/calendar-api-google.js +90 -113
- package/Calendar/calendar-api-google.mjs +75 -105
- package/Calendar/index.js +10 -8
- package/Calendar/types.js +3 -1
- package/Calendar/types.mjs +1 -1
- package/Calendar/useCalendar.d.ts +2 -2
- package/Calendar/useCalendar.js +196 -148
- package/Calendar/useCalendar.mjs +184 -142
- package/Calendar/utils.js +152 -115
- package/Calendar/utils.mjs +101 -94
- package/Carousel/Carousel.js +386 -380
- package/Carousel/Carousel.mjs +377 -378
- package/Carousel/CarouselCss.d.ts +1 -1
- package/Carousel/CarouselCss.js +59 -23
- package/Carousel/CarouselCss.mjs +37 -17
- package/Carousel/index.js +5 -3
- package/Collapsable/Collapsable.js +10 -3
- package/Collapsable/Collapsable.mjs +1 -1
- package/Collapsable/CollapsableReach.js +2 -3
- package/Collapsable/CollapsableReach.mjs +1 -3
- package/Collapsable/index.js +6 -4
- package/Collapsable/index.mjs +1 -2
- package/Debug/Debug.js +29 -11
- package/Debug/Debug.mjs +18 -7
- package/Debug/index.js +5 -3
- package/Details/Details.d.ts +5 -5
- package/Details/Details.js +87 -44
- package/Details/Details.mjs +60 -41
- package/Details/Details.stories.js +38 -0
- package/Details/Details.stories.mjs +20 -0
- package/Details/index.js +5 -3
- package/Dialog/DialogMui.d.ts +7 -7
- package/Dialog/DialogMui.js +78 -31
- package/Dialog/DialogMui.mjs +38 -26
- package/Dialog/DialogMui.stories.js +37 -0
- package/Dialog/DialogMui.stories.mjs +19 -0
- package/Dialog/css/bare.d.ts +6 -6
- package/Dialog/css/bare.js +53 -22
- package/Dialog/css/bare.mjs +15 -17
- package/Dialog/css/index.stories.js +85 -0
- package/Dialog/css/index.stories.mjs +67 -0
- package/Dialog/index.js +10 -4
- package/Dialog/m/bare.d.ts +6 -6
- package/Dialog/m/bare.js +55 -30
- package/Dialog/m/bare.mjs +40 -22
- package/Dialog/m/basic.js +29 -14
- package/Dialog/m/basic.mjs +10 -10
- package/Dialog/m/index.js +13 -7
- package/Dialog/m/index.mjs +4 -4
- package/Dialog/sc/bare.d.ts +6 -6
- package/Dialog/sc/bare.js +79 -42
- package/Dialog/sc/bare.mjs +40 -29
- package/Dialog/sc/framer.d.ts +6 -6
- package/Dialog/sc/framer.js +24 -17
- package/Dialog/sc/framer.mjs +9 -9
- package/Dialog/sc/framerMaterial.d.ts +6 -6
- package/Dialog/sc/framerMaterial.js +24 -17
- package/Dialog/sc/framerMaterial.mjs +9 -9
- package/Dialog/sc/index.stories.js +74 -0
- package/Dialog/sc/index.stories.mjs +47 -0
- package/Dialog/sc/material.d.ts +6 -6
- package/Dialog/sc/material.js +76 -22
- package/Dialog/sc/material.mjs +37 -17
- package/Dialog/tw/bare.d.ts +6 -6
- package/Dialog/tw/bare.js +51 -41
- package/Dialog/tw/bare.mjs +15 -28
- package/Dialog/tw/elegant.d.ts +6 -6
- package/Dialog/tw/elegant.js +52 -21
- package/Dialog/tw/elegant.mjs +15 -17
- package/Dialog/tw/framer.d.ts +6 -6
- package/Dialog/tw/framer.js +24 -17
- package/Dialog/tw/framer.mjs +9 -9
- package/Dialog/tw/framerMaterial.d.ts +6 -6
- package/Dialog/tw/framerMaterial.js +24 -17
- package/Dialog/tw/framerMaterial.mjs +9 -9
- package/Dialog/tw/index.stories.js +112 -0
- package/Dialog/tw/index.stories.mjs +82 -0
- package/Dialog/tw/material.d.ts +6 -6
- package/Dialog/tw/material.js +52 -21
- package/Dialog/tw/material.mjs +15 -17
- package/Editor/Editor--tiptap.d.ts +1 -1
- package/Editor/Editor--tiptap.js +50 -24
- package/Editor/Editor--tiptap.mjs +31 -19
- package/Editor/components.js +58 -14
- package/Editor/components.mjs +26 -8
- package/Editor/index.js +5 -3
- package/FaviconTags.js +59 -0
- package/FaviconTags.mjs +50 -0
- package/Form/Form.js +100 -52
- package/Form/Form.mjs +64 -47
- package/Form/index.js +5 -3
- package/Form/sc/bare.js +53 -21
- package/Form/sc/bare.mjs +21 -12
- package/Forms/Checkbox/Checkbox.js +46 -19
- package/Forms/Checkbox/Checkbox.mjs +16 -12
- package/Forms/Checkbox/index.js +5 -3
- package/Forms/Feedback/Feedback.js +21 -11
- package/Forms/Feedback/Feedback.mjs +10 -7
- package/Forms/Feedback/index.js +5 -3
- package/Forms/Field/Field.js +55 -21
- package/Forms/Field/Field.mjs +30 -17
- package/Forms/Field/FieldControl.js +41 -37
- package/Forms/Field/FieldControl.mjs +26 -20
- package/Forms/Field/FieldHint.js +16 -6
- package/Forms/Field/FieldHint.mjs +5 -3
- package/Forms/Field/index.js +6 -4
- package/Forms/Input/Input.js +56 -17
- package/Forms/Input/Input.mjs +22 -11
- package/Forms/Input/index.js +5 -3
- package/Forms/InputGroup/InputGroup.js +73 -17
- package/Forms/InputGroup/InputGroup.mjs +43 -11
- package/Forms/InputGroup/index.js +5 -3
- package/Forms/Label/Label.js +45 -8
- package/Forms/Label/Label.mjs +23 -5
- package/Forms/Label/index.js +5 -3
- package/Forms/Password/Password.js +56 -18
- package/Forms/Password/Password.mjs +35 -13
- package/Forms/Password/index.js +5 -3
- package/Forms/Radio/Radio.js +46 -25
- package/Forms/Radio/Radio.mjs +32 -19
- package/Forms/Radio/index.js +5 -3
- package/Forms/Switch/Switch.js +66 -21
- package/Forms/Switch/Switch.mjs +41 -13
- package/Forms/Switch/index.js +5 -3
- package/Forms/Textarea/Textarea.js +35 -13
- package/Forms/Textarea/Textarea.mjs +13 -7
- package/Forms/Textarea/TextareaRich.js +48 -29
- package/Forms/Textarea/TextareaRich.mjs +34 -22
- package/Forms/Textarea/index.js +6 -4
- package/Forms/Toggle/Toggle-tailwind.js +1 -1
- package/Forms/Toggle/Toggle-tailwind.mjs +0 -1
- package/Forms/Toggle/Toggle.js +149 -29
- package/Forms/Toggle/Toggle.mjs +95 -22
- package/Forms/Toggle/index.js +5 -3
- package/Forms/Toggle/useToggle-tailwind.js +1 -1
- package/Forms/Toggle/useToggle-tailwind.mjs +0 -1
- package/Forms/Toggle/useToggle.js +91 -101
- package/Forms/Toggle/useToggle.mjs +80 -68
- package/Forms/antispam.js +38 -45
- package/Forms/antispam.mjs +19 -21
- package/Forms/helpers.js +49 -31
- package/Forms/helpers.mjs +25 -19
- package/Forms/index.js +18 -18
- package/Forms/styles.js +90 -29
- package/Forms/styles.mjs +50 -19
- package/Gauge/Gauge.js +109 -104
- package/Gauge/Gauge.mjs +99 -100
- package/Grid/Grid.d.ts +4 -3
- package/Grid/Grid.js +84 -34
- package/Grid/Grid.mjs +54 -32
- package/Grid/index.js +5 -3
- package/Hamburger/Hamburger.js +68 -41
- package/Hamburger/Hamburger.mjs +58 -38
- package/Hamburger/index.js +5 -3
- package/Header/index.js +5 -3
- package/Header/useHeader.js +44 -25
- package/Header/useHeader.mjs +23 -18
- package/Hidden/Hidden.js +19 -11
- package/Hidden/Hidden.mjs +9 -9
- package/Hidden/index.js +5 -3
- package/Img/index.js +5 -3
- package/Img/sc/bare.js +42 -41
- package/Img/sc/bare.mjs +31 -34
- package/Img/types.js +5 -1
- package/Img/types.mjs +1 -1
- package/Link/Link.js +12 -6
- package/Link/Link.mjs +1 -3
- package/Link/LinkBlank.js +42 -18
- package/Link/LinkBlank.mjs +19 -11
- package/Link/index.js +6 -4
- package/Menu/Menu.js +21 -6
- package/Menu/Menu.mjs +10 -3
- package/Menu/MenuMui.js +2 -2
- package/Menu/MenuMui.mjs +1 -2
- package/Menu/index.js +5 -3
- package/MenuItem/MenuItem.js +30 -6
- package/MenuItem/MenuItem.mjs +19 -3
- package/MenuItem/MenuItemMui.js +1 -1
- package/MenuItem/MenuItemMui.mjs +0 -1
- package/MenuItem/index.js +5 -3
- package/MenuItem/useMenuItem.js +65 -33
- package/MenuItem/useMenuItem.mjs +45 -27
- package/Meta/Meta.js +23 -8
- package/Meta/Meta.mjs +5 -4
- package/Meta/index.js +11 -6
- package/NoJs/NoJs.js +25 -9
- package/NoJs/NoJs.mjs +7 -5
- package/NoJs/index.js +11 -6
- package/Pagination/PaginationNav.d.ts +1 -1
- package/Pagination/PaginationNav.js +86 -44
- package/Pagination/PaginationNav.mjs +72 -30
- package/Pagination/PaginationResults.js +38 -13
- package/Pagination/PaginationResults.mjs +27 -9
- package/Pagination/index.js +6 -4
- package/Pill/Pill.js +61 -9
- package/Pill/Pill.mjs +36 -6
- package/Pill/index.js +5 -3
- package/Progress/ProgressCircular.js +58 -17
- package/Progress/ProgressCircular.mjs +47 -11
- package/Progress/ProgressLinear.js +49 -26
- package/Progress/ProgressLinear.mjs +38 -20
- package/Progress/ProgressOverlay.js +65 -24
- package/Progress/ProgressOverlay.mjs +51 -17
- package/Progress/index.js +7 -5
- package/Rating/Rating.js +128 -41
- package/Rating/Rating.mjs +93 -35
- package/Rating/index.js +61 -33
- package/Rating/index.mjs +37 -24
- package/Select/SelectDownshift.js +46 -40
- package/Select/SelectDownshift.mjs +37 -38
- package/Select/components.js +40 -13
- package/Select/components.mjs +20 -9
- package/Select/index.js +12 -6
- package/Select/index.mjs +2 -3
- package/Sidebar/Sidebar.js +61 -23
- package/Sidebar/Sidebar.mjs +48 -17
- package/Sidebar/index.js +5 -3
- package/Spacing/Spacing.d.ts +1 -1
- package/Spacing/Spacing.js +36 -33
- package/Spacing/Spacing.mjs +24 -17
- package/Spacing/index.js +5 -3
- package/Sticky/Sticky.js +227 -221
- package/Sticky/Sticky.mjs +218 -219
- package/Sticky/StickyCss.js +17 -8
- package/Sticky/StickyCss.mjs +8 -5
- package/Sticky/index.js +18 -4
- package/Sticky/index.mjs +1 -1
- package/Tabs/TabsMui.d.ts +8 -8
- package/Tabs/TabsMui.js +64 -34
- package/Tabs/TabsMui.mjs +31 -28
- package/Tabs/TabsMui.stories.js +37 -0
- package/Tabs/TabsMui.stories.mjs +19 -0
- package/Tabs/index.js +5 -3
- package/Tabs/sc/bare.js +2 -3
- package/Tabs/sc/bare.mjs +1 -3
- package/Tabs/sc/index.stories.js +1 -0
- package/Tabs/sc/index.stories.mjs +0 -0
- package/Tabs/tw/bare.d.ts +6 -6
- package/Tabs/tw/bare.js +43 -18
- package/Tabs/tw/bare.mjs +11 -13
- package/Tabs/tw/index.stories.js +45 -0
- package/Tabs/tw/index.stories.mjs +24 -0
- package/Tabs/tw/material.d.ts +6 -6
- package/Tabs/tw/material.js +41 -18
- package/Tabs/tw/material.mjs +11 -15
- package/Tabs/useTabs.js +44 -25
- package/Tabs/useTabs.mjs +24 -21
- package/Typography/CopyPasteVisible.js +16 -6
- package/Typography/CopyPasteVisible.mjs +5 -3
- package/Typography/Native.js +89 -16
- package/Typography/Native.mjs +45 -12
- package/Typography/ReadMore.js +99 -36
- package/Typography/ReadMore.mjs +86 -30
- package/Typography/TextLoop.js +94 -45
- package/Typography/TextLoop.mjs +76 -40
- package/Typography/TypeStairs.js +43 -32
- package/Typography/TypeStairs.mjs +33 -29
- package/Typography/index.js +9 -7
- package/css/index.js +32 -35
- package/css/index.mjs +20 -21
- package/helpers/classed.js +39 -51
- package/helpers/classed.mjs +21 -30
- package/helpers/classed.stories.js +122 -0
- package/helpers/classed.stories.mjs +103 -0
- package/helpers/createUseMediaQueryWidth.js +163 -153
- package/helpers/createUseMediaQueryWidth.mjs +140 -140
- package/helpers/extend-component.js +26 -11
- package/helpers/extend-component.mjs +7 -7
- package/helpers/index.js +8 -6
- package/helpers/mergeRefs.js +21 -8
- package/helpers/mergeRefs.mjs +3 -4
- package/hooks/index.js +91 -43
- package/hooks/index.mjs +3 -3
- package/hooks/types.js +6 -2
- package/hooks/types.mjs +3 -1
- package/hooks/useAsyncFn.js +48 -33
- package/hooks/useAsyncFn.mjs +28 -26
- package/hooks/useDateLocale.js +42 -32
- package/hooks/useDateLocale.mjs +22 -22
- package/hooks/useFirstMountState.js +20 -9
- package/hooks/useFirstMountState.mjs +2 -3
- package/hooks/useFixedOffset.js +45 -40
- package/hooks/useFixedOffset.mjs +23 -24
- package/hooks/useFocus.js +26 -12
- package/hooks/useFocus.mjs +7 -5
- package/hooks/useInterval.js +37 -25
- package/hooks/useInterval.mjs +15 -14
- package/hooks/useIsomorphicLayoutEffect.js +22 -12
- package/hooks/useIsomorphicLayoutEffect.mjs +1 -4
- package/hooks/useKeyUp.js +30 -17
- package/hooks/useKeyUp.mjs +9 -11
- package/hooks/useMeasure.js +98 -80
- package/hooks/useMeasure.mjs +74 -67
- package/hooks/useMountedState.js +23 -12
- package/hooks/useMountedState.mjs +5 -6
- package/hooks/useNavigateAway.js +47 -51
- package/hooks/useNavigateAway.mjs +26 -25
- package/hooks/usePrevious.js +27 -10
- package/hooks/usePrevious.mjs +9 -4
- package/hooks/usePreviousRef.js +21 -7
- package/hooks/usePreviousRef.mjs +2 -2
- package/hooks/useScrollPosition.js +53 -43
- package/hooks/useScrollPosition.mjs +28 -26
- package/hooks/useScrollThreshold.js +41 -22
- package/hooks/useScrollThreshold.mjs +18 -13
- package/hooks/useScrollTo.js +28 -16
- package/hooks/useScrollTo.mjs +6 -8
- package/hooks/useSmoothScroll.js +39 -34
- package/hooks/useSmoothScroll.mjs +12 -16
- package/hooks/useSpinDelay.js +42 -37
- package/hooks/useSpinDelay.mjs +24 -22
- package/hooks/useTraceUpdate.js +26 -13
- package/hooks/useTraceUpdate.mjs +8 -7
- package/hooks/useUpdateEffect.js +24 -13
- package/hooks/useUpdateEffect.mjs +4 -5
- package/hooks/useWindowSize.js +34 -25
- package/hooks/useWindowSize.mjs +13 -10
- package/index.js +9 -7
- package/index.mjs +4 -5
- package/m/MotionProvider.js +23 -41
- package/m/MotionProvider.mjs +4 -5
- package/m/index.js +6 -5
- package/m/index.mjs +1 -2
- package/m/lite.js +11 -3
- package/m/max.js +11 -3
- package/package.json +16 -13
- package/sc/index.js +48 -36
- package/scm/index.js +39 -35
- package/shared/index.js +12 -10
- package/shared/index.mjs +35 -0
- package/styles/Body.js +27 -15
- package/styles/Body.mjs +8 -5
- package/styles/Global.js +54 -20
- package/styles/Global.mjs +36 -5
- package/styles/index.js +141 -40
- package/styles/index.mjs +5 -5
- package/styles/media.js +98 -120
- package/styles/media.mjs +63 -68
- package/styles/spacing.js +49 -31
- package/styles/spacing.mjs +26 -25
- package/styles/styled.js +56 -15
- package/styles/styled.mjs +23 -10
- package/styles/theme--vanilla.js +58 -42
- package/styles/theme--vanilla.mjs +25 -20
- package/styles/theme.js +38 -34
- package/styles/theme.mjs +16 -19
- package/tw/index.js +32 -35
- package/tw/index.mjs +20 -21
- package/twm/index.js +32 -35
- package/twm/index.mjs +20 -21
- package/types.js +3 -1
- package/types.mjs +1 -1
- package/typings.d.ts +1 -0
- package/Alert/package.json +0 -6
- package/Animations/package.json +0 -6
- package/Autocomplete/package.json +0 -6
- package/Bg/package.json +0 -6
- package/Breadcrumbs/package.json +0 -6
- package/Buttons/package.json +0 -6
- package/Calendar/package.json +0 -6
- package/Carousel/package.json +0 -6
- package/Collapsable/package.json +0 -6
- package/Debug/package.json +0 -6
- package/Details/package.json +0 -6
- package/Dialog/m/package.json +0 -6
- package/Dialog/package.json +0 -6
- package/Editor/package.json +0 -6
- package/FaviconTags/FaviconTags.js +0 -20
- package/FaviconTags/FaviconTags.mjs +0 -16
- package/FaviconTags/index.d.ts +0 -2
- package/FaviconTags/index.js +0 -7
- package/FaviconTags/index.mjs +0 -2
- package/FaviconTags/package.json +0 -6
- package/Form/package.json +0 -6
- package/Forms/Checkbox/package.json +0 -6
- package/Forms/Feedback/package.json +0 -6
- package/Forms/Field/package.json +0 -6
- package/Forms/Input/package.json +0 -6
- package/Forms/InputGroup/package.json +0 -6
- package/Forms/Label/package.json +0 -6
- package/Forms/Password/package.json +0 -6
- package/Forms/Radio/package.json +0 -6
- package/Forms/Switch/package.json +0 -6
- package/Forms/Textarea/package.json +0 -6
- package/Forms/Toggle/package.json +0 -6
- package/Forms/package.json +0 -6
- package/Grid/package.json +0 -6
- package/Hamburger/package.json +0 -6
- package/Header/package.json +0 -6
- package/Hidden/package.json +0 -6
- package/Img/package.json +0 -6
- package/Link/package.json +0 -6
- package/Menu/package.json +0 -6
- package/MenuItem/package.json +0 -6
- package/Meta/package.json +0 -6
- package/NoJs/package.json +0 -6
- package/Pagination/package.json +0 -6
- package/Pill/package.json +0 -6
- package/Progress/package.json +0 -6
- package/Rating/package.json +0 -6
- package/Select/package.json +0 -6
- package/Sidebar/package.json +0 -6
- package/Spacing/package.json +0 -6
- package/Sticky/package.json +0 -6
- package/Tabs/package.json +0 -6
- package/Typography/package.json +0 -6
- package/css/package.json +0 -6
- package/helpers/package.json +0 -6
- package/hooks/package.json +0 -6
- package/m/package.json +0 -6
- package/sc/package.json +0 -6
- package/scm/package.json +0 -6
- package/shared/package.json +0 -6
- package/styles/package.json +0 -6
- package/tw/package.json +0 -6
- package/twm/package.json +0 -6
- /package/{FaviconTags/FaviconTags.d.ts → FaviconTags.d.ts} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import type { Option } from "../types";
|
|
3
2
|
import { FormControl } from "../Forms/helpers";
|
|
3
|
+
import type { Option } from "../types";
|
|
4
4
|
export type AutocompleteOption = Option | string;
|
|
5
5
|
export type AutocompleteValue<TMultiple extends boolean | undefined = undefined> = TMultiple extends undefined ? null | Option[] | string[] | Option | string : TMultiple extends true ? Option[] | string[] : null | Option | string;
|
|
6
6
|
export type AutocompleteConfig<TOption extends AutocompleteOption, TValue extends AutocompleteValue> = {
|
|
@@ -1,71 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*
|
|
29
|
-
* ```ts
|
|
30
|
-
* const schema = object({
|
|
31
|
-
* // the value must be an array with at least one non-empty string
|
|
32
|
-
* test1: array(string().required()).required().min(1),
|
|
33
|
-
* // the value must be an array of strings or an empty array
|
|
34
|
-
* test2: array(string().required()).required(),
|
|
35
|
-
* }).required();
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
// export const Autocomplete = <TOption, TValue>forwardRef<
|
|
39
|
-
// HTMLInputElement,
|
|
40
|
-
// PropsWithChildren<AutocompleteProps<TOption, TValue>
|
|
41
|
-
// >(function Autocomplete(
|
|
42
|
-
// {
|
|
43
|
-
// creatable,
|
|
44
|
-
// multiple,
|
|
45
|
-
// autoComplete,
|
|
46
|
-
// loadOptions,
|
|
47
|
-
// options: defaultOptions = [],
|
|
48
|
-
// defaultValue = [],
|
|
49
|
-
// label,
|
|
50
|
-
// register,
|
|
51
|
-
// setValue,
|
|
52
|
-
// // trigger,
|
|
53
|
-
// name,
|
|
54
|
-
// onChange,
|
|
55
|
-
// $ref,
|
|
56
|
-
// children,
|
|
57
|
-
// ...props
|
|
58
|
-
// },
|
|
59
|
-
// ref
|
|
60
|
-
// ) {
|
|
61
|
-
var Autocomplete = function (_a) {
|
|
62
|
-
var creatable = _a.creatable, multiple = _a.multiple, autoComplete = _a.autoComplete, loadOptions = _a.loadOptions, _b = _a.options, defaultOptions = _b === void 0 ? [] : _b, defaultValue = _a.defaultValue, controlledValue = _a.value, defaultInputValue = _a.defaultInputValue, label = _a.label, placeholder = _a.placeholder, register = _a.register, setValue = _a.setValue,
|
|
63
|
-
// trigger,
|
|
64
|
-
name = _a.name, onChange = _a.onChange, $ref = _a.$ref, children = _a.children, props = tslib_1.__rest(_a, ["creatable", "multiple", "autoComplete", "loadOptions", "options", "defaultValue", "value", "defaultInputValue", "label", "placeholder", "register", "setValue", "name", "onChange", "$ref", "children"]);
|
|
65
|
-
var defaultOptionsMemo = (0, react_1.useMemo)(function () { return (0, helpers_1.normaliseOptions)(defaultOptions); }, [defaultOptions]);
|
|
66
|
-
var _c = (0, react_1.useState)(defaultOptionsMemo), options = _c[0], setOptions = _c[1];
|
|
67
|
-
var _d = (0, react_1.useState)(false), loading = _d[0], setLoading = _d[1];
|
|
68
|
-
var _e = (0, useAutocomplete_1.default)({
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "Autocomplete", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Autocomplete;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
12
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
13
|
+
const _useAutocomplete = /*#__PURE__*/ _interop_require_default._(require("@mui/base/useAutocomplete"));
|
|
14
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
15
|
+
const _isString = /*#__PURE__*/ _interop_require_default._(require("@koine/utils/isString"));
|
|
16
|
+
const _helpers = require("../Forms/helpers");
|
|
17
|
+
const _styles = require("../Forms/styles");
|
|
18
|
+
const _components = require("./components");
|
|
19
|
+
const _helpers1 = require("./helpers");
|
|
20
|
+
const Autocomplete = ({ creatable, multiple, autoComplete, loadOptions, options: defaultOptions = [], defaultValue, value: controlledValue, defaultInputValue, label, placeholder, register, setValue, // trigger,
|
|
21
|
+
name, onChange, $ref, children, ...props })=>{
|
|
22
|
+
const defaultOptionsMemo = (0, _react.useMemo)(()=>(0, _helpers.normaliseOptions)(defaultOptions), [
|
|
23
|
+
defaultOptions
|
|
24
|
+
]);
|
|
25
|
+
const [options, setOptions] = (0, _react.useState)(defaultOptionsMemo);
|
|
26
|
+
const [loading, setLoading] = (0, _react.useState)(false);
|
|
27
|
+
const { getRootProps, getInputLabelProps, getInputProps, getTagProps, getListboxProps, getOptionProps, getPopupIndicatorProps, groupedOptions, value: stateValue, setAnchorEl, popupOpen, focused } = (0, _useAutocomplete.default)({
|
|
69
28
|
id: "Autocomplete",
|
|
70
29
|
multiple: multiple ? true : undefined,
|
|
71
30
|
freeSolo: creatable ? true : undefined,
|
|
@@ -79,86 +38,81 @@ var Autocomplete = function (_a) {
|
|
|
79
38
|
// ourselves
|
|
80
39
|
// inputValue: defaultInputValue,
|
|
81
40
|
// @ts-expect-error FIXME: how?
|
|
82
|
-
defaultValue
|
|
41
|
+
defaultValue,
|
|
83
42
|
// @ts-expect-error FIXME: how?
|
|
84
43
|
value: controlledValue,
|
|
85
44
|
// defaultValue: useMemo(
|
|
86
45
|
// () => normaliseAutocompleteValue(defaultValue, multiple),
|
|
87
46
|
// [defaultValue]
|
|
88
47
|
// ),
|
|
89
|
-
options: (0,
|
|
48
|
+
options: (0, _react.useMemo)(()=>loadOptions ? options : defaultOptions, [
|
|
49
|
+
loadOptions,
|
|
50
|
+
options,
|
|
51
|
+
defaultOptions
|
|
52
|
+
]),
|
|
90
53
|
// update input change only if we are searching as you type, @see
|
|
91
54
|
// https://mui.com/components/autocomplete/#search-as-you-type
|
|
92
|
-
onInputChange: (0,
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return [4 /*yield*/, loadOptions(inputValue)];
|
|
106
|
-
case 2:
|
|
107
|
-
newOptions = _a.sent();
|
|
108
|
-
setOptions(newOptions);
|
|
109
|
-
return [3 /*break*/, 5];
|
|
110
|
-
case 3:
|
|
111
|
-
e_1 = _a.sent();
|
|
112
|
-
console.warn(e_1);
|
|
113
|
-
return [3 /*break*/, 5];
|
|
114
|
-
case 4:
|
|
115
|
-
setLoading(false);
|
|
116
|
-
return [7 /*endfinally*/];
|
|
117
|
-
case 5: return [3 /*break*/, 7];
|
|
118
|
-
case 6:
|
|
119
|
-
setOptions(options);
|
|
120
|
-
_a.label = 7;
|
|
121
|
-
case 7: return [2 /*return*/];
|
|
55
|
+
onInputChange: (0, _react.useCallback)(async (_event, inputValue)=>{
|
|
56
|
+
if (!loadOptions) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (inputValue) {
|
|
60
|
+
setLoading(true);
|
|
61
|
+
try {
|
|
62
|
+
const newOptions = await loadOptions(inputValue);
|
|
63
|
+
setOptions(newOptions);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
console.warn(e);
|
|
66
|
+
} finally{
|
|
67
|
+
setLoading(false);
|
|
122
68
|
}
|
|
123
|
-
}
|
|
124
|
-
|
|
69
|
+
} else {
|
|
70
|
+
setOptions(options);
|
|
71
|
+
// TODO: clear like behaviour?
|
|
72
|
+
// triggerChange({ value: "", label: "" });
|
|
73
|
+
}
|
|
74
|
+
}, [
|
|
75
|
+
loadOptions,
|
|
76
|
+
options
|
|
77
|
+
]),
|
|
125
78
|
// TODO: check if we need this, probably, and check how to structure the
|
|
126
79
|
// callback, here we get the actual input event
|
|
127
|
-
onChange:
|
|
128
|
-
|
|
80
|
+
onChange: (event, newValue)=>{
|
|
81
|
+
const value = (0, _helpers1.normaliseAutocompleteValue)(newValue, multiple);
|
|
129
82
|
// @ts-expect-error FIXME: how?
|
|
130
|
-
if (onChange)
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
83
|
+
if (onChange) onChange(newValue);
|
|
84
|
+
if (setValue) setValue(name, value, {
|
|
85
|
+
shouldValidate: true
|
|
86
|
+
});
|
|
87
|
+
// triggerOnChange(onChange, name, value);
|
|
135
88
|
},
|
|
136
89
|
// support both freeSolo free text and full option structure
|
|
137
|
-
isOptionEqualToValue:
|
|
138
|
-
|
|
139
|
-
|
|
90
|
+
isOptionEqualToValue: (option, value)=>{
|
|
91
|
+
const optValue = (0, _isString.default)(option) ? option : option.value;
|
|
92
|
+
const valValue = (0, _isString.default)(value) ? value : value.value;
|
|
140
93
|
return optValue === valValue;
|
|
141
94
|
},
|
|
142
|
-
getOptionLabel:
|
|
95
|
+
getOptionLabel: (option)=>{
|
|
143
96
|
// @ts-expect-error TODO: I don't get this error
|
|
144
|
-
return (0,
|
|
145
|
-
}
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
97
|
+
return (0, _isString.default)(option) ? option : option.label || "";
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
const value = typeof controlledValue !== "undefined" ? controlledValue : stateValue;
|
|
101
|
+
const inputProps = ()=>{
|
|
102
|
+
const autocompleteProps = getInputProps();
|
|
150
103
|
// here we merge the mui's `useAutocomplete` props with the react-hook-form's
|
|
151
104
|
// `register` props
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
105
|
+
const registerProps = register ? register(name, {
|
|
106
|
+
// @ts-expect-error FIXME: can't remember
|
|
107
|
+
ref: autocompleteProps.ref.current,
|
|
108
|
+
// this makes the validation works when a valid `defaultValue`
|
|
109
|
+
// is provided
|
|
110
|
+
value: (0, _helpers1.normaliseAutocompleteValue)(value, multiple)
|
|
111
|
+
}) : {};
|
|
112
|
+
return {
|
|
113
|
+
...registerProps,
|
|
114
|
+
...autocompleteProps
|
|
115
|
+
};
|
|
162
116
|
};
|
|
163
117
|
// to focus the input on error this works too
|
|
164
118
|
// @see https://react-hook-form.com/faqs#question12 but probably it is
|
|
@@ -168,13 +122,33 @@ var Autocomplete = function (_a) {
|
|
|
168
122
|
// inputProps.ref.current.focus();
|
|
169
123
|
// }
|
|
170
124
|
// }, [errors, name, inputProps.ref]);
|
|
171
|
-
return
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
125
|
+
return /*#__PURE__*/ _react.default.createElement(_components.AutocompleteRoot, null, label && /*#__PURE__*/ _react.default.createElement(_components.AutocompleteLabel, getInputLabelProps(), label), /*#__PURE__*/ _react.default.createElement(_components.AutocompleteWrap, {
|
|
126
|
+
...getRootProps(),
|
|
127
|
+
"data-focus": focused
|
|
128
|
+
}, /*#__PURE__*/ _react.default.createElement(_components.AutocompleteInner, {
|
|
129
|
+
ref: setAnchorEl
|
|
130
|
+
}, multiple && value.map((valueItem, index)=>{
|
|
131
|
+
const { onDelete, key, ...tagProps } = getTagProps({
|
|
132
|
+
index
|
|
133
|
+
});
|
|
134
|
+
return /*#__PURE__*/ _react.default.createElement(_components.AutocompleteItem, {
|
|
135
|
+
key: key,
|
|
136
|
+
...tagProps
|
|
137
|
+
}, /*#__PURE__*/ _react.default.createElement(_components.AutocompleteItemLabel, null, (0, _isString.default)(valueItem) ? valueItem : valueItem.Label || valueItem.label), /*#__PURE__*/ _react.default.createElement(_components.AutocompleteItemRemove, {
|
|
138
|
+
onClick: onDelete
|
|
139
|
+
}, "✕"));
|
|
140
|
+
}), /*#__PURE__*/ _react.default.createElement(_components.AutocompleteInput, {
|
|
141
|
+
...inputProps(),
|
|
142
|
+
placeholder: placeholder
|
|
143
|
+
})), !!options.length && /*#__PURE__*/ _react.default.createElement(_components.AutocompleteInputArrow, {
|
|
144
|
+
...getPopupIndicatorProps(),
|
|
145
|
+
isOpen: popupOpen
|
|
146
|
+
}), loading && /*#__PURE__*/ _react.default.createElement(_styles.InputProgress, null)), groupedOptions.length ? /*#__PURE__*/ _react.default.createElement(_components.AutocompleteMenu, getListboxProps(), groupedOptions.map((option, index)=>/*#__PURE__*/ _react.default.createElement(_components.AutocompleteMenuItem, {
|
|
147
|
+
key: index,
|
|
148
|
+
...getOptionProps({
|
|
149
|
+
option,
|
|
150
|
+
index
|
|
151
|
+
})
|
|
152
|
+
}, (0, _isString.default)(option) ? option : option.Label || option.label))) : null, children);
|
|
153
|
+
// });
|
|
179
154
|
};
|
|
180
|
-
exports.Autocomplete = Autocomplete;
|
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
import { __assign, __awaiter, __generator, __rest } from "tslib";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
4
|
-
// forwardRef,
|
|
5
|
-
useCallback, useMemo, useState, } from "react";
|
|
6
1
|
import useAutocomplete from "@mui/base/useAutocomplete";
|
|
2
|
+
import React, { useCallback, useMemo, useState } from "react";
|
|
3
|
+
// forwardRef,
|
|
7
4
|
import isString from "@koine/utils/isString";
|
|
8
|
-
import {
|
|
9
|
-
// triggerOnChange,
|
|
10
|
-
normaliseOptions, } from "../Forms/helpers";
|
|
11
|
-
import { normaliseAutocompleteValue } from "./helpers";
|
|
12
|
-
import { AutocompleteRoot, AutocompleteLabel, AutocompleteWrap, AutocompleteInner, AutocompleteItem, AutocompleteItemLabel, AutocompleteItemRemove,
|
|
13
|
-
// AutocompleteInputWrap,
|
|
14
|
-
AutocompleteInput, AutocompleteInputArrow, AutocompleteMenu, AutocompleteMenuItem, } from "./components";
|
|
5
|
+
import { normaliseOptions } from "../Forms/helpers";
|
|
15
6
|
import { InputProgress } from "../Forms/styles";
|
|
7
|
+
import { AutocompleteInner, AutocompleteInput, AutocompleteInputArrow, AutocompleteItem, AutocompleteItemLabel, AutocompleteItemRemove, AutocompleteLabel, AutocompleteMenu, AutocompleteMenuItem, AutocompleteRoot, AutocompleteWrap } from "./components";
|
|
8
|
+
import { normaliseAutocompleteValue } from "./helpers";
|
|
16
9
|
/**
|
|
17
10
|
* Autocomplete/autocomplete component based on [`@mui useAutocomplete hook`](https://mui.com/components/autocomplete/#useautocomplete/useAutocomplete).
|
|
18
11
|
*
|
|
@@ -37,8 +30,7 @@ import { InputProgress } from "../Forms/styles";
|
|
|
37
30
|
* test2: array(string().required()).required(),
|
|
38
31
|
* }).required();
|
|
39
32
|
* ```
|
|
40
|
-
*/
|
|
41
|
-
// export const Autocomplete = <TOption, TValue>forwardRef<
|
|
33
|
+
*/ // export const Autocomplete = <TOption, TValue>forwardRef<
|
|
42
34
|
// HTMLInputElement,
|
|
43
35
|
// PropsWithChildren<AutocompleteProps<TOption, TValue>
|
|
44
36
|
// >(function Autocomplete(
|
|
@@ -61,14 +53,14 @@ import { InputProgress } from "../Forms/styles";
|
|
|
61
53
|
// },
|
|
62
54
|
// ref
|
|
63
55
|
// ) {
|
|
64
|
-
export
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
56
|
+
export const Autocomplete = ({ creatable, multiple, autoComplete, loadOptions, options: defaultOptions = [], defaultValue, value: controlledValue, defaultInputValue, label, placeholder, register, setValue, // trigger,
|
|
57
|
+
name, onChange, $ref, children, ...props })=>{
|
|
58
|
+
const defaultOptionsMemo = useMemo(()=>normaliseOptions(defaultOptions), [
|
|
59
|
+
defaultOptions
|
|
60
|
+
]);
|
|
61
|
+
const [options, setOptions] = useState(defaultOptionsMemo);
|
|
62
|
+
const [loading, setLoading] = useState(false);
|
|
63
|
+
const { getRootProps, getInputLabelProps, getInputProps, getTagProps, getListboxProps, getOptionProps, getPopupIndicatorProps, groupedOptions, value: stateValue, setAnchorEl, popupOpen, focused } = useAutocomplete({
|
|
72
64
|
id: "Autocomplete",
|
|
73
65
|
multiple: multiple ? true : undefined,
|
|
74
66
|
freeSolo: creatable ? true : undefined,
|
|
@@ -82,86 +74,81 @@ export var Autocomplete = function (_a) {
|
|
|
82
74
|
// ourselves
|
|
83
75
|
// inputValue: defaultInputValue,
|
|
84
76
|
// @ts-expect-error FIXME: how?
|
|
85
|
-
defaultValue
|
|
77
|
+
defaultValue,
|
|
86
78
|
// @ts-expect-error FIXME: how?
|
|
87
79
|
value: controlledValue,
|
|
88
80
|
// defaultValue: useMemo(
|
|
89
81
|
// () => normaliseAutocompleteValue(defaultValue, multiple),
|
|
90
82
|
// [defaultValue]
|
|
91
83
|
// ),
|
|
92
|
-
options: useMemo(
|
|
84
|
+
options: useMemo(()=>loadOptions ? options : defaultOptions, [
|
|
85
|
+
loadOptions,
|
|
86
|
+
options,
|
|
87
|
+
defaultOptions
|
|
88
|
+
]),
|
|
93
89
|
// update input change only if we are searching as you type, @see
|
|
94
90
|
// https://mui.com/components/autocomplete/#search-as-you-type
|
|
95
|
-
onInputChange: useCallback(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return [4 /*yield*/, loadOptions(inputValue)];
|
|
109
|
-
case 2:
|
|
110
|
-
newOptions = _a.sent();
|
|
111
|
-
setOptions(newOptions);
|
|
112
|
-
return [3 /*break*/, 5];
|
|
113
|
-
case 3:
|
|
114
|
-
e_1 = _a.sent();
|
|
115
|
-
console.warn(e_1);
|
|
116
|
-
return [3 /*break*/, 5];
|
|
117
|
-
case 4:
|
|
118
|
-
setLoading(false);
|
|
119
|
-
return [7 /*endfinally*/];
|
|
120
|
-
case 5: return [3 /*break*/, 7];
|
|
121
|
-
case 6:
|
|
122
|
-
setOptions(options);
|
|
123
|
-
_a.label = 7;
|
|
124
|
-
case 7: return [2 /*return*/];
|
|
91
|
+
onInputChange: useCallback(async (_event, inputValue)=>{
|
|
92
|
+
if (!loadOptions) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (inputValue) {
|
|
96
|
+
setLoading(true);
|
|
97
|
+
try {
|
|
98
|
+
const newOptions = await loadOptions(inputValue);
|
|
99
|
+
setOptions(newOptions);
|
|
100
|
+
} catch (e) {
|
|
101
|
+
console.warn(e);
|
|
102
|
+
} finally{
|
|
103
|
+
setLoading(false);
|
|
125
104
|
}
|
|
126
|
-
}
|
|
127
|
-
|
|
105
|
+
} else {
|
|
106
|
+
setOptions(options);
|
|
107
|
+
// TODO: clear like behaviour?
|
|
108
|
+
// triggerChange({ value: "", label: "" });
|
|
109
|
+
}
|
|
110
|
+
}, [
|
|
111
|
+
loadOptions,
|
|
112
|
+
options
|
|
113
|
+
]),
|
|
128
114
|
// TODO: check if we need this, probably, and check how to structure the
|
|
129
115
|
// callback, here we get the actual input event
|
|
130
|
-
onChange:
|
|
131
|
-
|
|
116
|
+
onChange: (event, newValue)=>{
|
|
117
|
+
const value = normaliseAutocompleteValue(newValue, multiple);
|
|
132
118
|
// @ts-expect-error FIXME: how?
|
|
133
|
-
if (onChange)
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
119
|
+
if (onChange) onChange(newValue);
|
|
120
|
+
if (setValue) setValue(name, value, {
|
|
121
|
+
shouldValidate: true
|
|
122
|
+
});
|
|
123
|
+
// triggerOnChange(onChange, name, value);
|
|
138
124
|
},
|
|
139
125
|
// support both freeSolo free text and full option structure
|
|
140
|
-
isOptionEqualToValue:
|
|
141
|
-
|
|
142
|
-
|
|
126
|
+
isOptionEqualToValue: (option, value)=>{
|
|
127
|
+
const optValue = isString(option) ? option : option.value;
|
|
128
|
+
const valValue = isString(value) ? value : value.value;
|
|
143
129
|
return optValue === valValue;
|
|
144
130
|
},
|
|
145
|
-
getOptionLabel:
|
|
131
|
+
getOptionLabel: (option)=>{
|
|
146
132
|
// @ts-expect-error TODO: I don't get this error
|
|
147
133
|
return isString(option) ? option : option.label || "";
|
|
148
|
-
}
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
const value = typeof controlledValue !== "undefined" ? controlledValue : stateValue;
|
|
137
|
+
const inputProps = ()=>{
|
|
138
|
+
const autocompleteProps = getInputProps();
|
|
153
139
|
// here we merge the mui's `useAutocomplete` props with the react-hook-form's
|
|
154
140
|
// `register` props
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
141
|
+
const registerProps = register ? register(name, {
|
|
142
|
+
// @ts-expect-error FIXME: can't remember
|
|
143
|
+
ref: autocompleteProps.ref.current,
|
|
144
|
+
// this makes the validation works when a valid `defaultValue`
|
|
145
|
+
// is provided
|
|
146
|
+
value: normaliseAutocompleteValue(value, multiple)
|
|
147
|
+
}) : {};
|
|
148
|
+
return {
|
|
149
|
+
...registerProps,
|
|
150
|
+
...autocompleteProps
|
|
151
|
+
};
|
|
165
152
|
};
|
|
166
153
|
// to focus the input on error this works too
|
|
167
154
|
// @see https://react-hook-form.com/faqs#question12 but probably it is
|
|
@@ -171,12 +158,33 @@ export var Autocomplete = function (_a) {
|
|
|
171
158
|
// inputProps.ref.current.focus();
|
|
172
159
|
// }
|
|
173
160
|
// }, [errors, name, inputProps.ref]);
|
|
174
|
-
return (
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
161
|
+
return /*#__PURE__*/ React.createElement(AutocompleteRoot, null, label && /*#__PURE__*/ React.createElement(AutocompleteLabel, getInputLabelProps(), label), /*#__PURE__*/ React.createElement(AutocompleteWrap, {
|
|
162
|
+
...getRootProps(),
|
|
163
|
+
"data-focus": focused
|
|
164
|
+
}, /*#__PURE__*/ React.createElement(AutocompleteInner, {
|
|
165
|
+
ref: setAnchorEl
|
|
166
|
+
}, multiple && value.map((valueItem, index)=>{
|
|
167
|
+
const { onDelete, key, ...tagProps } = getTagProps({
|
|
168
|
+
index
|
|
169
|
+
});
|
|
170
|
+
return /*#__PURE__*/ React.createElement(AutocompleteItem, {
|
|
171
|
+
key: key,
|
|
172
|
+
...tagProps
|
|
173
|
+
}, /*#__PURE__*/ React.createElement(AutocompleteItemLabel, null, isString(valueItem) ? valueItem : valueItem.Label || valueItem.label), /*#__PURE__*/ React.createElement(AutocompleteItemRemove, {
|
|
174
|
+
onClick: onDelete
|
|
175
|
+
}, "✕"));
|
|
176
|
+
}), /*#__PURE__*/ React.createElement(AutocompleteInput, {
|
|
177
|
+
...inputProps(),
|
|
178
|
+
placeholder: placeholder
|
|
179
|
+
})), !!options.length && /*#__PURE__*/ React.createElement(AutocompleteInputArrow, {
|
|
180
|
+
...getPopupIndicatorProps(),
|
|
181
|
+
isOpen: popupOpen
|
|
182
|
+
}), loading && /*#__PURE__*/ React.createElement(InputProgress, null)), groupedOptions.length ? /*#__PURE__*/ React.createElement(AutocompleteMenu, getListboxProps(), groupedOptions.map((option, index)=>/*#__PURE__*/ React.createElement(AutocompleteMenuItem, {
|
|
183
|
+
key: index,
|
|
184
|
+
...getOptionProps({
|
|
185
|
+
option,
|
|
186
|
+
index
|
|
187
|
+
})
|
|
188
|
+
}, isString(option) ? option : option.Label || option.label))) : null, children);
|
|
189
|
+
// });
|
|
182
190
|
};
|