grommet 2.19.1 → 2.21.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/components/Accordion/Accordion.js +26 -23
- package/components/Accordion/stories/CustomHeader.js +36 -34
- package/components/Accordion/stories/CustomThemed/Custom.js +2 -9
- package/components/Accordion/stories/{typescript → CustomThemed}/Rich.tsx +2 -2
- package/components/Accordion/stories/DarkNoAnimation.js +34 -32
- package/components/Accordion/stories/Multiple.js +32 -30
- package/components/Accordion/stories/Simple.js +33 -31
- package/components/Anchor/propTypes.js +1 -1
- package/components/Anchor/stories/Color.js +1 -5
- package/components/Anchor/stories/Default.js +2 -6
- package/components/Anchor/stories/Disabled.js +2 -6
- package/components/Anchor/stories/Gap.js +2 -6
- package/components/Anchor/stories/Inline.js +2 -6
- package/components/Anchor/stories/Size.js +2 -6
- package/components/Anchor/stories/Weight.js +2 -6
- package/components/Avatar/Avatar.js +12 -11
- package/components/Avatar/stories/Basic.js +23 -21
- package/components/Avatar/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
- package/components/Avatar/stories/Round.js +35 -33
- package/components/Avatar/stories/Sizes.js +80 -78
- package/components/Avatar/stories/typescript/Stacked.tsx +10 -11
- package/components/Button/Button.js +3 -3
- package/components/Button/StyledButton.js +3 -1
- package/components/Button/StyledButtonKind.js +5 -9
- package/components/Calendar/Calendar.js +113 -87
- package/components/Calendar/StyledCalendar.js +1 -1
- package/components/Calendar/index.d.ts +4 -0
- package/components/Calendar/stories/ActiveDate.js +35 -34
- package/components/Calendar/stories/CustomDay.js +69 -67
- package/components/Calendar/stories/CustomHeader.js +39 -37
- package/{es6/components/Calendar/stories/typescript → components/Calendar/stories/CustomThemed}/CustomDate.tsx +1 -1
- package/components/Calendar/stories/{CustomSizeHeading.js → CustomThemed/CustomSizeHeading.js} +1 -1
- package/components/Calendar/stories/DaylightSavings.js +55 -53
- package/components/Calendar/stories/Dual.js +86 -84
- package/components/Calendar/stories/Fill.js +16 -14
- package/components/Calendar/stories/Multiple.js +26 -24
- package/components/Calendar/stories/Range.js +13 -11
- package/components/Calendar/stories/ShowAdjacentDays.js +36 -34
- package/components/Calendar/stories/Simple.js +24 -22
- package/components/Calendar/stories/SundayFirstDay.js +13 -11
- package/components/Calendar/utils.js +60 -10
- package/components/Card/stories/{Clickable.js → CustomThemed/Clickable.js} +2 -2
- package/components/Card/stories/{Stacked.js → CustomThemed/Stacked.js} +2 -2
- package/components/Card/stories/{Themed.js → CustomThemed/Themed.js} +2 -2
- package/components/Card/stories/Simple.js +26 -23
- package/components/Carousel/Carousel.js +145 -93
- package/components/Carousel/CarouselChild.js +17 -27
- package/components/Carousel/StyledCarousel.js +44 -0
- package/components/Carousel/index.d.ts +5 -0
- package/components/Carousel/propTypes.js +13 -9
- package/components/Carousel/stories/Autoplay.js +52 -0
- package/components/Carousel/stories/ControlVariations.js +170 -0
- package/components/Carousel/stories/Controlled.js +43 -37
- package/components/Carousel/stories/{Custom.js → CustomThemed/Custom.js} +1 -1
- package/components/Carousel/stories/CustomThemed/Icons.tsx +50 -0
- package/components/Carousel/stories/InteractiveChild.js +73 -0
- package/components/Carousel/stories/Multiple.js +7 -1
- package/components/Carousel/stories/Simple.js +25 -19
- package/components/Chart/Chart.js +16 -7
- package/components/Chart/calcs.js +1 -1
- package/components/Chart/utils.js +1 -1
- package/components/CheckBox/StyledCheckBox.js +1 -1
- package/components/Clock/Clock.js +1 -1
- package/components/Clock/StyledClock.js +1 -1
- package/components/Collapsible/stories/Horizontal.js +54 -50
- package/components/Collapsible/stories/Nested.js +78 -76
- package/components/Collapsible/stories/Simple.js +24 -22
- package/components/DataChart/DataChart.js +84 -21
- package/components/DataChart/Detail.js +8 -0
- package/components/DataChart/XAxis.js +19 -10
- package/components/DataChart/index.d.ts +10 -2
- package/components/DataChart/propTypes.js +2 -1
- package/components/DataChart/stories/Offset.js +82 -0
- package/components/DataChart/stories/StackedAreas.js +77 -0
- package/components/DataChart/stories/StackedLines.js +73 -0
- package/components/DataChart/utils.js +1 -1
- package/components/DataTable/DataTable.js +1 -1
- package/components/DataTable/StyledDataTable.js +1 -1
- package/components/DataTable/buildState.js +3 -2
- package/components/DataTable/index.d.ts +3 -3
- package/components/DataTable/stories/ColumnSize.js +63 -61
- package/components/DataTable/stories/Controlled.js +34 -32
- package/components/DataTable/stories/ControlledGrouped.js +16 -14
- package/components/DataTable/stories/{Fill.js → CustomThemed/Fill.js} +2 -2
- package/components/DataTable/stories/Grouped.js +15 -13
- package/components/DataTable/stories/GroupedOnSelect.js +16 -14
- package/components/DataTable/stories/InfiniteScrollDataTable.js +22 -20
- package/components/DataTable/stories/MultiplePin.js +48 -44
- package/components/DataTable/stories/NoPrimary.js +15 -13
- package/components/DataTable/stories/OnUpdate.js +24 -22
- package/components/DataTable/stories/Placeholder.js +27 -25
- package/components/DataTable/stories/ResizableColumns.js +17 -15
- package/components/DataTable/stories/Served.js +18 -16
- package/components/DataTable/stories/Show.js +29 -23
- package/components/DataTable/stories/Simple.js +14 -12
- package/components/DataTable/stories/Sized.js +14 -12
- package/components/DataTable/stories/Sort.js +20 -18
- package/components/DataTable/stories/SpaceX.js +36 -34
- package/components/DataTable/stories/SpaceXUngrouped.js +26 -24
- package/components/DataTable/stories/Styled.js +43 -41
- package/components/DataTable/stories/Tunable.js +19 -17
- package/components/DataTable/stories/Units.js +16 -14
- package/components/DataTable/stories/data.js +1 -1
- package/components/DataTable/stories/rowDetails.js +40 -38
- package/components/DataTable/stories/typescript/Clickable.tsx +30 -29
- package/components/DataTable/stories/typescript/OnSelect.tsx +13 -13
- package/components/DataTable/stories/typescript/Paginated.tsx +15 -15
- package/components/DateInput/DateInput.js +85 -30
- package/components/DateInput/index.d.ts +1 -0
- package/components/DateInput/propTypes.js +1 -0
- package/components/DateInput/stories/FormatInline.js +172 -16
- package/components/DateInput/stories/ResetDate.js +1 -1
- package/components/DateInput/utils.js +20 -17
- package/components/Drop/DropContainer.js +16 -9
- package/components/Drop/stories/AllNotStretched.js +166 -164
- package/components/Drop/stories/{Lazy.js → CustomThemed/Lazy.js} +1 -1
- package/components/Drop/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
- package/components/Drop/stories/Meter.js +35 -30
- package/components/Drop/stories/Multiple.js +56 -52
- package/components/Drop/stories/Overflow.js +54 -50
- package/components/Drop/stories/Plain.js +30 -26
- package/components/Drop/stories/Progressive.js +52 -48
- package/components/Drop/stories/Simple.js +28 -24
- package/components/Drop/stories/Styled.js +45 -41
- package/components/Drop/stories/TrapFocus.js +21 -16
- package/components/DropButton/stories/Menu.js +5 -7
- package/components/DropButton/stories/Simple.js +2 -6
- package/components/DropButton/stories/typescript/Calendar.tsx +17 -20
- package/components/FileInput/stories/CustomThemed/Custom.js +5 -7
- package/components/Footer/stories/data.js +1 -1
- package/components/Form/Form.js +321 -265
- package/components/Form/stories/ArrayOfFormFields.js +161 -0
- package/components/Form/stories/FieldBorderPosition.js +1 -0
- package/components/Form/stories/FieldWithChildren.js +4 -4
- package/components/FormField/FormField.js +5 -1
- package/components/Grommet/Grommet.js +8 -1
- package/components/Layer/LayerContainer.js +9 -4
- package/components/Layer/StyledLayer.js +1 -1
- package/components/List/List.js +11 -2
- package/components/List/index.d.ts +1 -0
- package/components/List/propTypes.js +1 -0
- package/components/Markdown/Markdown.js +4 -2
- package/components/MaskedInput/StyledMaskedInput.js +1 -1
- package/components/Menu/Menu.js +39 -12
- package/components/Menu/stories/BottomControlButton.js +2 -6
- package/components/Menu/stories/{typescript → CustomThemed}/Themed.tsx +1 -1
- package/components/Menu/stories/ItemWithIcon.js +2 -6
- package/components/Menu/stories/Justify.js +2 -6
- package/components/Menu/stories/Reverse.js +2 -6
- package/components/Menu/stories/Simple.js +2 -6
- package/components/Menu/stories/typescript/Children.tsx +10 -13
- package/components/Meter/utils.js +1 -1
- package/components/NameValueList/NameValueList.js +8 -5
- package/components/NameValueList/stories/CustomValue.js +1 -1
- package/components/NameValueList/stories/data.js +1 -1
- package/components/NameValuePair/NameValuePair.js +1 -4
- package/components/Nav/stories/Collapsable.js +39 -37
- package/components/Nav/stories/{CustomAnchor.js → CustomThemed/CustomAnchor.js} +2 -2
- package/components/Nav/stories/{JustifySidebar.js → CustomThemed/JustifySidebar.js} +1 -1
- package/components/Nav/stories/OnHeader.js +29 -27
- package/components/Nav/stories/Sidebar.js +24 -18
- package/components/Nav/stories/Simple.js +15 -13
- package/components/Notification/Notification.js +17 -6
- package/components/Notification/index.d.ts +7 -1
- package/components/Notification/propTypes.js +4 -1
- package/components/Pagination/StyledPageControl.js +2 -2
- package/components/RadioButton/StyledRadioButton.js +1 -1
- package/components/RadioButtonGroup/RadioButtonGroup.js +3 -1
- package/components/RangeInput/StyledRangeInput.js +1 -1
- package/components/RangeInput/stories/SimpleRange.js +2 -6
- package/components/Select/Select.js +45 -12
- package/components/Select/SelectContainer.js +22 -6
- package/components/Select/stories/ChildrenRender.js +37 -33
- package/components/Select/stories/Clear.js +7 -3
- package/components/Select/stories/Controlled.js +32 -28
- package/components/Select/stories/{CustomSearch.js → CustomThemed/CustomSearch.js} +2 -2
- package/components/Select/stories/Disabled.js +29 -25
- package/components/Select/stories/InsideFormField.js +29 -27
- package/components/Select/stories/LazyLoadingOptions.js +27 -25
- package/components/Select/stories/ManyOptions.js +47 -43
- package/components/Select/stories/Multiple.js +25 -21
- package/components/Select/stories/ObjectOptions.js +27 -25
- package/components/Select/stories/Search.js +62 -58
- package/components/Select/stories/Simple.js +26 -22
- package/components/Select/stories/Uncontrolled.js +24 -20
- package/components/Select/stories/ValueLabel.js +40 -36
- package/components/Select/stories/typescript/CreateOption.tsx +34 -30
- package/components/Sidebar/stories/Labels.js +25 -19
- package/components/Sidebar/stories/typescript/Simple.tsx +17 -12
- package/components/SkipLinks/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
- package/components/SkipLinks/stories/Simple.js +82 -78
- package/components/Stack/stories/Fill.js +15 -11
- package/components/Stack/stories/Simple.js +15 -9
- package/components/Tab/Tab.js +6 -1
- package/components/Table/StyledTable.js +1 -1
- package/components/Table/stories/Default.js +30 -28
- package/components/Table/stories/InfiniteScrollInTable.js +39 -35
- package/components/Table/stories/MeterInTable.js +26 -24
- package/components/Table/stories/data.js +1 -1
- package/components/Tabs/StyledTabs.js +1 -1
- package/components/Tabs/Tabs.js +23 -19
- package/components/Tabs/stories/{AlignControls.js → CustomThemed/AlignControls.js} +1 -1
- package/components/Tabs/stories/{Custom.js → CustomThemed/Custom.js} +3 -3
- package/components/Tabs/stories/{Icon.js → CustomThemed/Icon.js} +1 -1
- package/components/Tabs/stories/{States.js → CustomThemed/States.js} +1 -1
- package/components/Tabs/stories/Plain.js +45 -41
- package/components/Tabs/stories/Responsive.js +191 -189
- package/components/Tabs/stories/Rich.js +30 -28
- package/components/Tabs/stories/Scrollable.js +32 -28
- package/components/Tabs/stories/Uncontrolled.js +45 -41
- package/components/Tabs/stories/typescript/Controlled.tsx +21 -21
- package/components/Tag/README.md +2 -0
- package/components/Tag/StyledTag.js +35 -0
- package/components/Tag/Tag.js +94 -0
- package/components/Tag/index.d.ts +35 -0
- package/components/Tag/index.js +8 -0
- package/components/Tag/propTypes.js +28 -0
- package/components/Tag/stories/OnClick.js +34 -0
- package/components/Tag/stories/OnRemove.js +38 -0
- package/components/Tag/stories/Simple.js +32 -0
- package/components/Tag/stories/Size.js +45 -0
- package/components/Text/Text.js +23 -9
- package/components/TextArea/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
- package/components/TextArea/stories/Fill.js +18 -16
- package/components/TextArea/stories/InsideFormField.js +43 -41
- package/components/TextArea/stories/NonResizable.js +13 -11
- package/components/TextArea/stories/Simple.js +13 -11
- package/components/TextInput/StyledTextInput.js +1 -1
- package/components/TextInput/TextInput.js +13 -4
- package/components/TextInput/index.d.ts +6 -1
- package/{es6/components/TextInput/stories/typescript → components/TextInput/stories/CustomThemed}/CustomSuggestions.tsx +1 -1
- package/components/TextInput/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
- package/components/TextInput/stories/DefaultSuggestion.js +20 -19
- package/components/TextInput/stories/Icon.js +22 -21
- package/components/TextInput/stories/InsideFormField.js +32 -30
- package/components/TextInput/stories/OnSelect.js +20 -19
- package/components/TextInput/stories/Password.js +30 -29
- package/components/TextInput/stories/Simple.js +17 -16
- package/components/TextInput/stories/StyledPlaceholder.js +10 -9
- package/components/TextInput/stories/Suggestions.js +19 -18
- package/components/TextInput/stories/Uncontrolled.js +18 -17
- package/components/TextInput/stories/WithTags.js +19 -18
- package/components/Tip/stories/Caret.js +37 -31
- package/components/Tip/stories/{ResponsiveTip.js → CustomThemed/ResponsiveTip.js} +1 -1
- package/components/Tip/stories/{SidebarTip.js → CustomThemed/SidebarTip.js} +1 -1
- package/{es6/components/Tip/stories/typescript → components/Tip/stories/CustomThemed}/Themed.tsx +1 -1
- package/components/Tip/stories/HeaderActions.js +66 -60
- package/components/Tip/stories/InfoTip.js +59 -56
- package/components/Tip/stories/typescript/Animated.tsx +26 -21
- package/components/Tip/stories/typescript/Children.tsx +52 -51
- package/components/Tip/stories/typescript/Simple.tsx +12 -7
- package/components/Video/Video.js +98 -38
- package/components/Video/index.d.ts +15 -2
- package/components/Video/propTypes.js +8 -1
- package/components/Video/stories/typescript/TheaterMode.tsx +46 -0
- package/components/index.d.ts +1 -0
- package/components/index.js +8 -0
- package/contexts/MessageContext/MessageContext.js +3 -2
- package/contexts/MessageContext/index.js +1 -1
- package/es6/components/Accordion/Accordion.js +26 -23
- package/es6/components/Accordion/stories/CustomHeader.js +37 -34
- package/es6/components/Accordion/stories/CustomThemed/Custom.js +2 -9
- package/es6/components/Accordion/stories/{typescript → CustomThemed}/Rich.tsx +2 -2
- package/es6/components/Accordion/stories/DarkNoAnimation.js +35 -32
- package/es6/components/Accordion/stories/Multiple.js +33 -30
- package/es6/components/Accordion/stories/Simple.js +34 -31
- package/es6/components/Anchor/propTypes.js +1 -1
- package/es6/components/Anchor/stories/Color.js +2 -5
- package/es6/components/Anchor/stories/Default.js +3 -6
- package/es6/components/Anchor/stories/Disabled.js +3 -6
- package/es6/components/Anchor/stories/Gap.js +3 -6
- package/es6/components/Anchor/stories/Inline.js +3 -6
- package/es6/components/Anchor/stories/Size.js +3 -6
- package/es6/components/Anchor/stories/Weight.js +3 -6
- package/es6/components/Avatar/Avatar.js +13 -12
- package/es6/components/Avatar/stories/Basic.js +24 -21
- package/es6/components/Avatar/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
- package/es6/components/Avatar/stories/Round.js +36 -33
- package/es6/components/Avatar/stories/Sizes.js +81 -78
- package/es6/components/Avatar/stories/typescript/Stacked.tsx +10 -11
- package/es6/components/Button/Button.js +3 -3
- package/es6/components/Button/StyledButton.js +3 -1
- package/es6/components/Button/StyledButtonKind.js +5 -9
- package/es6/components/Calendar/Calendar.js +114 -88
- package/es6/components/Calendar/index.d.ts +4 -0
- package/es6/components/Calendar/stories/ActiveDate.js +36 -34
- package/es6/components/Calendar/stories/CustomDay.js +70 -67
- package/es6/components/Calendar/stories/CustomHeader.js +40 -37
- package/{components/Calendar/stories/typescript → es6/components/Calendar/stories/CustomThemed}/CustomDate.tsx +1 -1
- package/es6/components/Calendar/stories/{CustomSizeHeading.js → CustomThemed/CustomSizeHeading.js} +1 -1
- package/es6/components/Calendar/stories/DaylightSavings.js +56 -53
- package/es6/components/Calendar/stories/Dual.js +87 -84
- package/es6/components/Calendar/stories/Fill.js +17 -14
- package/es6/components/Calendar/stories/Multiple.js +25 -22
- package/es6/components/Calendar/stories/Range.js +14 -11
- package/es6/components/Calendar/stories/ShowAdjacentDays.js +37 -34
- package/es6/components/Calendar/stories/Simple.js +25 -22
- package/es6/components/Calendar/stories/SundayFirstDay.js +14 -11
- package/es6/components/Calendar/utils.js +48 -4
- package/es6/components/Card/stories/{Clickable.js → CustomThemed/Clickable.js} +2 -2
- package/es6/components/Card/stories/{Stacked.js → CustomThemed/Stacked.js} +2 -2
- package/es6/components/Card/stories/{Themed.js → CustomThemed/Themed.js} +2 -2
- package/es6/components/Card/stories/Simple.js +27 -24
- package/es6/components/Carousel/Carousel.js +145 -94
- package/es6/components/Carousel/CarouselChild.js +17 -25
- package/es6/components/Carousel/StyledCarousel.js +31 -0
- package/es6/components/Carousel/index.d.ts +5 -0
- package/es6/components/Carousel/propTypes.js +13 -9
- package/es6/components/Carousel/stories/Autoplay.js +41 -0
- package/es6/components/Carousel/stories/ControlVariations.js +161 -0
- package/es6/components/Carousel/stories/Controlled.js +44 -38
- package/es6/components/Carousel/stories/{Custom.js → CustomThemed/Custom.js} +1 -1
- package/es6/components/Carousel/stories/CustomThemed/Icons.tsx +50 -0
- package/es6/components/Carousel/stories/InteractiveChild.js +61 -0
- package/es6/components/Carousel/stories/Multiple.js +8 -2
- package/es6/components/Carousel/stories/Simple.js +26 -20
- package/es6/components/Chart/Chart.js +16 -7
- package/es6/components/Clock/Clock.js +1 -1
- package/es6/components/Collapsible/stories/Horizontal.js +55 -50
- package/es6/components/Collapsible/stories/Nested.js +79 -76
- package/es6/components/Collapsible/stories/Simple.js +25 -22
- package/es6/components/DataChart/DataChart.js +84 -21
- package/es6/components/DataChart/Detail.js +7 -0
- package/es6/components/DataChart/XAxis.js +19 -10
- package/es6/components/DataChart/index.d.ts +10 -2
- package/es6/components/DataChart/propTypes.js +2 -1
- package/es6/components/DataChart/stories/Offset.js +70 -0
- package/es6/components/DataChart/stories/StackedAreas.js +65 -0
- package/es6/components/DataChart/stories/StackedLines.js +61 -0
- package/es6/components/DataTable/DataTable.js +1 -1
- package/es6/components/DataTable/buildState.js +2 -1
- package/es6/components/DataTable/index.d.ts +3 -3
- package/es6/components/DataTable/stories/ColumnSize.js +64 -61
- package/es6/components/DataTable/stories/Controlled.js +35 -32
- package/es6/components/DataTable/stories/ControlledGrouped.js +17 -14
- package/es6/components/DataTable/stories/{Fill.js → CustomThemed/Fill.js} +2 -2
- package/es6/components/DataTable/stories/Grouped.js +16 -13
- package/es6/components/DataTable/stories/GroupedOnSelect.js +17 -14
- package/es6/components/DataTable/stories/InfiniteScrollDataTable.js +23 -20
- package/es6/components/DataTable/stories/MultiplePin.js +49 -45
- package/es6/components/DataTable/stories/NoPrimary.js +16 -13
- package/es6/components/DataTable/stories/OnUpdate.js +25 -22
- package/es6/components/DataTable/stories/Placeholder.js +28 -25
- package/es6/components/DataTable/stories/ResizableColumns.js +18 -15
- package/es6/components/DataTable/stories/Served.js +19 -16
- package/es6/components/DataTable/stories/Show.js +27 -21
- package/es6/components/DataTable/stories/Simple.js +15 -12
- package/es6/components/DataTable/stories/Sized.js +15 -12
- package/es6/components/DataTable/stories/Sort.js +21 -18
- package/es6/components/DataTable/stories/SpaceX.js +37 -34
- package/es6/components/DataTable/stories/SpaceXUngrouped.js +27 -24
- package/es6/components/DataTable/stories/Styled.js +44 -41
- package/es6/components/DataTable/stories/Tunable.js +20 -17
- package/es6/components/DataTable/stories/Units.js +17 -14
- package/es6/components/DataTable/stories/rowDetails.js +41 -38
- package/es6/components/DataTable/stories/typescript/Clickable.tsx +30 -29
- package/es6/components/DataTable/stories/typescript/OnSelect.tsx +13 -13
- package/es6/components/DataTable/stories/typescript/Paginated.tsx +15 -15
- package/es6/components/DateInput/DateInput.js +80 -28
- package/es6/components/DateInput/index.d.ts +1 -0
- package/es6/components/DateInput/propTypes.js +1 -0
- package/es6/components/DateInput/stories/FormatInline.js +169 -16
- package/es6/components/DateInput/utils.js +18 -13
- package/es6/components/Drop/DropContainer.js +15 -9
- package/es6/components/Drop/stories/AllNotStretched.js +167 -164
- package/es6/components/Drop/stories/{Lazy.js → CustomThemed/Lazy.js} +1 -1
- package/es6/components/Drop/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
- package/es6/components/Drop/stories/Meter.js +36 -30
- package/es6/components/Drop/stories/Multiple.js +57 -52
- package/es6/components/Drop/stories/Overflow.js +55 -50
- package/es6/components/Drop/stories/Plain.js +31 -26
- package/es6/components/Drop/stories/Progressive.js +53 -48
- package/es6/components/Drop/stories/Simple.js +29 -24
- package/es6/components/Drop/stories/Styled.js +46 -41
- package/es6/components/Drop/stories/TrapFocus.js +22 -17
- package/es6/components/DropButton/stories/Menu.js +6 -7
- package/es6/components/DropButton/stories/Simple.js +3 -6
- package/es6/components/DropButton/stories/typescript/Calendar.tsx +17 -20
- package/es6/components/FileInput/stories/CustomThemed/Custom.js +5 -7
- package/es6/components/Form/Form.js +321 -265
- package/es6/components/Form/stories/ArrayOfFormFields.js +147 -0
- package/es6/components/Form/stories/FieldBorderPosition.js +1 -0
- package/es6/components/Form/stories/FieldWithChildren.js +4 -4
- package/es6/components/FormField/FormField.js +6 -2
- package/es6/components/Grommet/Grommet.js +8 -1
- package/es6/components/Layer/LayerContainer.js +9 -4
- package/es6/components/List/List.js +11 -2
- package/es6/components/List/index.d.ts +1 -0
- package/es6/components/List/propTypes.js +1 -0
- package/es6/components/Markdown/Markdown.js +4 -2
- package/es6/components/Menu/Menu.js +40 -13
- package/es6/components/Menu/stories/BottomControlButton.js +3 -6
- package/es6/components/Menu/stories/{typescript → CustomThemed}/Themed.tsx +1 -1
- package/es6/components/Menu/stories/ItemWithIcon.js +3 -6
- package/es6/components/Menu/stories/Justify.js +3 -6
- package/es6/components/Menu/stories/Reverse.js +3 -6
- package/es6/components/Menu/stories/Simple.js +3 -6
- package/es6/components/Menu/stories/typescript/Children.tsx +10 -13
- package/es6/components/NameValueList/NameValueList.js +9 -6
- package/es6/components/NameValueList/stories/CustomValue.js +1 -1
- package/es6/components/NameValuePair/NameValuePair.js +1 -4
- package/es6/components/Nav/stories/Collapsable.js +40 -37
- package/es6/components/Nav/stories/{CustomAnchor.js → CustomThemed/CustomAnchor.js} +2 -2
- package/es6/components/Nav/stories/{JustifySidebar.js → CustomThemed/JustifySidebar.js} +1 -1
- package/es6/components/Nav/stories/OnHeader.js +30 -27
- package/es6/components/Nav/stories/Sidebar.js +25 -19
- package/es6/components/Nav/stories/Simple.js +16 -13
- package/es6/components/Notification/Notification.js +18 -7
- package/es6/components/Notification/index.d.ts +7 -1
- package/es6/components/Notification/propTypes.js +4 -1
- package/es6/components/Pagination/StyledPageControl.js +1 -1
- package/es6/components/RadioButtonGroup/RadioButtonGroup.js +3 -1
- package/es6/components/RangeInput/StyledRangeInput.js +1 -1
- package/es6/components/RangeInput/stories/SimpleRange.js +3 -6
- package/es6/components/Select/Select.js +45 -12
- package/es6/components/Select/SelectContainer.js +22 -6
- package/es6/components/Select/stories/ChildrenRender.js +38 -33
- package/es6/components/Select/stories/Clear.js +8 -4
- package/es6/components/Select/stories/Controlled.js +33 -28
- package/es6/components/Select/stories/{CustomSearch.js → CustomThemed/CustomSearch.js} +2 -2
- package/es6/components/Select/stories/Disabled.js +30 -25
- package/es6/components/Select/stories/InsideFormField.js +30 -27
- package/es6/components/Select/stories/LazyLoadingOptions.js +28 -25
- package/es6/components/Select/stories/ManyOptions.js +48 -43
- package/es6/components/Select/stories/Multiple.js +26 -21
- package/es6/components/Select/stories/ObjectOptions.js +28 -25
- package/es6/components/Select/stories/Search.js +63 -58
- package/es6/components/Select/stories/Simple.js +27 -22
- package/es6/components/Select/stories/Uncontrolled.js +25 -20
- package/es6/components/Select/stories/ValueLabel.js +41 -36
- package/es6/components/Select/stories/typescript/CreateOption.tsx +34 -30
- package/es6/components/Sidebar/stories/Labels.js +26 -20
- package/es6/components/Sidebar/stories/typescript/Simple.tsx +17 -12
- package/es6/components/SkipLinks/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
- package/es6/components/SkipLinks/stories/Simple.js +83 -79
- package/es6/components/Stack/stories/Fill.js +16 -11
- package/es6/components/Stack/stories/Simple.js +16 -10
- package/es6/components/Tab/Tab.js +6 -1
- package/es6/components/Table/stories/Default.js +31 -28
- package/es6/components/Table/stories/InfiniteScrollInTable.js +40 -36
- package/es6/components/Table/stories/MeterInTable.js +27 -24
- package/es6/components/Tabs/Tabs.js +23 -20
- package/es6/components/Tabs/stories/{AlignControls.js → CustomThemed/AlignControls.js} +1 -1
- package/es6/components/Tabs/stories/{Custom.js → CustomThemed/Custom.js} +3 -3
- package/es6/components/Tabs/stories/{Icon.js → CustomThemed/Icon.js} +1 -1
- package/es6/components/Tabs/stories/{States.js → CustomThemed/States.js} +1 -1
- package/es6/components/Tabs/stories/Plain.js +45 -40
- package/es6/components/Tabs/stories/Responsive.js +191 -188
- package/es6/components/Tabs/stories/Rich.js +30 -27
- package/es6/components/Tabs/stories/Scrollable.js +32 -27
- package/es6/components/Tabs/stories/Uncontrolled.js +45 -40
- package/es6/components/Tabs/stories/typescript/Controlled.tsx +21 -21
- package/es6/components/Tag/README.md +2 -0
- package/es6/components/Tag/StyledTag.js +22 -0
- package/es6/components/Tag/Tag.js +77 -0
- package/es6/components/Tag/index.d.ts +35 -0
- package/es6/components/Tag/index.js +1 -0
- package/es6/components/Tag/propTypes.js +18 -0
- package/es6/components/Tag/stories/OnClick.js +22 -0
- package/es6/components/Tag/stories/OnRemove.js +26 -0
- package/es6/components/Tag/stories/Simple.js +20 -0
- package/es6/components/Tag/stories/Size.js +33 -0
- package/es6/components/Text/Text.js +23 -10
- package/es6/components/TextArea/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
- package/es6/components/TextArea/stories/Fill.js +19 -16
- package/es6/components/TextArea/stories/InsideFormField.js +44 -41
- package/es6/components/TextArea/stories/NonResizable.js +14 -11
- package/es6/components/TextArea/stories/Simple.js +14 -11
- package/es6/components/TextInput/TextInput.js +13 -4
- package/es6/components/TextInput/index.d.ts +6 -1
- package/{components/TextInput/stories/typescript → es6/components/TextInput/stories/CustomThemed}/CustomSuggestions.tsx +1 -1
- package/es6/components/TextInput/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
- package/es6/components/TextInput/stories/DefaultSuggestion.js +21 -19
- package/es6/components/TextInput/stories/Icon.js +23 -21
- package/es6/components/TextInput/stories/InsideFormField.js +33 -30
- package/es6/components/TextInput/stories/OnSelect.js +21 -19
- package/es6/components/TextInput/stories/Password.js +31 -29
- package/es6/components/TextInput/stories/Simple.js +18 -16
- package/es6/components/TextInput/stories/StyledPlaceholder.js +11 -9
- package/es6/components/TextInput/stories/Suggestions.js +20 -18
- package/es6/components/TextInput/stories/Uncontrolled.js +19 -17
- package/es6/components/TextInput/stories/WithTags.js +20 -18
- package/es6/components/Tip/stories/Caret.js +38 -32
- package/es6/components/Tip/stories/{ResponsiveTip.js → CustomThemed/ResponsiveTip.js} +1 -1
- package/es6/components/Tip/stories/{SidebarTip.js → CustomThemed/SidebarTip.js} +1 -1
- package/{components/Tip/stories/typescript → es6/components/Tip/stories/CustomThemed}/Themed.tsx +1 -1
- package/es6/components/Tip/stories/HeaderActions.js +67 -61
- package/es6/components/Tip/stories/InfoTip.js +60 -57
- package/es6/components/Tip/stories/typescript/Animated.tsx +26 -21
- package/es6/components/Tip/stories/typescript/Children.tsx +52 -51
- package/es6/components/Tip/stories/typescript/Simple.tsx +12 -7
- package/es6/components/Video/Video.js +99 -39
- package/es6/components/Video/index.d.ts +15 -2
- package/es6/components/Video/propTypes.js +8 -1
- package/es6/components/Video/stories/typescript/TheaterMode.tsx +46 -0
- package/es6/components/index.d.ts +1 -0
- package/es6/components/index.js +1 -0
- package/es6/contexts/MessageContext/MessageContext.js +2 -1
- package/es6/index.d.ts +1 -0
- package/es6/languages/default.json +11 -3
- package/es6/themes/base.d.ts +59 -12
- package/es6/themes/base.js +60 -2
- package/es6/utils/DOM.js +13 -3
- package/es6/utils/background.js +2 -1
- package/grommet.min.js +1 -1
- package/grommet.min.js.map +1 -1
- package/index.d.ts +1 -0
- package/languages/default.json +11 -3
- package/package.json +59 -58
- package/themes/base.d.ts +59 -12
- package/themes/base.js +61 -3
- package/themes/index.js +1 -1
- package/utils/DOM.js +20 -4
- package/utils/animation.js +1 -1
- package/utils/background.js +3 -2
- package/utils/border.js +1 -1
- package/utils/colors.js +1 -1
- package/utils/general-prop-types.js +1 -1
- package/utils/graphics.js +1 -1
- package/utils/mixins.js +1 -1
- package/utils/object.js +1 -1
- package/utils/responsive.js +1 -1
- package/utils/styles.js +1 -1
- package/utils/use-isomorphic-layout-effect.js +1 -1
- package/components/Carousel/stories/InitialChild.js +0 -43
- package/components/Carousel/stories/WithClickableChild.js +0 -51
- package/components/Carousel/stories/WithoutControls.js +0 -44
- package/es6/components/Carousel/stories/InitialChild.js +0 -32
- package/es6/components/Carousel/stories/WithClickableChild.js +0 -40
- package/es6/components/Carousel/stories/WithoutControls.js +0 -33
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
var _excluded = ["children", "errors", "infos", "messages", "onChange", "onReset", "onSubmit", "onValidate", "validate", "value"];
|
|
2
2
|
|
|
3
|
-
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
4
|
-
|
|
5
3
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
6
4
|
|
|
5
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
6
|
+
|
|
7
7
|
import React, { forwardRef, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
8
8
|
import { MessageContext } from '../../contexts/MessageContext';
|
|
9
9
|
import { FormContext } from './FormContext';
|
|
@@ -13,24 +13,82 @@ var defaultTouched = {};
|
|
|
13
13
|
var defaultValidationResults = {
|
|
14
14
|
errors: {},
|
|
15
15
|
infos: {}
|
|
16
|
-
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
var stringToArray = function stringToArray(string) {
|
|
19
|
+
var match = string == null ? void 0 : string.match(/^(.+)\[([0-9]+)\]\.(.*)$/);
|
|
20
|
+
|
|
21
|
+
if (match) {
|
|
22
|
+
var arrayName = match[1],
|
|
23
|
+
indexOfArray = match[2],
|
|
24
|
+
arrayObjName = match[3];
|
|
25
|
+
return {
|
|
26
|
+
indexOfArray: indexOfArray,
|
|
27
|
+
arrayName: arrayName,
|
|
28
|
+
arrayObjName: arrayObjName
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return undefined;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
var getFieldValue = function getFieldValue(name, value) {
|
|
36
|
+
var isArrayField = stringToArray(name);
|
|
37
|
+
|
|
38
|
+
if (isArrayField) {
|
|
39
|
+
var _value$arrayName;
|
|
40
|
+
|
|
41
|
+
var indexOfArray = isArrayField.indexOfArray,
|
|
42
|
+
arrayName = isArrayField.arrayName,
|
|
43
|
+
arrayObjName = isArrayField.arrayObjName;
|
|
44
|
+
var obj = (_value$arrayName = value[arrayName]) == null ? void 0 : _value$arrayName[indexOfArray];
|
|
45
|
+
return arrayObjName ? obj == null ? void 0 : obj[arrayObjName] : obj;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return value[name];
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
var setFieldValue = function setFieldValue(name, componentValue, prevValue) {
|
|
52
|
+
var nextValue = _extends({}, prevValue);
|
|
53
|
+
|
|
54
|
+
var isArrayField = stringToArray(name);
|
|
55
|
+
|
|
56
|
+
if (isArrayField) {
|
|
57
|
+
var indexOfArray = isArrayField.indexOfArray,
|
|
58
|
+
arrayName = isArrayField.arrayName,
|
|
59
|
+
arrayObjName = isArrayField.arrayObjName;
|
|
60
|
+
if (!nextValue[arrayName]) nextValue[arrayName] = [];
|
|
17
61
|
|
|
18
|
-
|
|
62
|
+
if (arrayObjName) {
|
|
63
|
+
var _nextValue$arrayName$;
|
|
64
|
+
|
|
65
|
+
if (!nextValue[arrayName][indexOfArray]) nextValue[arrayName][indexOfArray] = (_nextValue$arrayName$ = {}, _nextValue$arrayName$[arrayObjName] = componentValue, _nextValue$arrayName$);
|
|
66
|
+
nextValue[arrayName][indexOfArray][arrayObjName] = componentValue;
|
|
67
|
+
} else nextValue[arrayName][indexOfArray] = componentValue;
|
|
68
|
+
} else {
|
|
69
|
+
nextValue[name] = componentValue;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return nextValue;
|
|
73
|
+
}; // Apply validation rule to field value and send correct messaging.
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
var validate = function validate(rule, fieldValue, formValue, format, messages) {
|
|
19
77
|
var result;
|
|
20
78
|
|
|
21
|
-
if (typeof
|
|
22
|
-
result =
|
|
23
|
-
} else if (
|
|
24
|
-
if (!
|
|
25
|
-
result =
|
|
79
|
+
if (typeof rule === 'function') {
|
|
80
|
+
result = rule(fieldValue, formValue);
|
|
81
|
+
} else if (rule.regexp) {
|
|
82
|
+
if (!rule.regexp.test(fieldValue)) {
|
|
83
|
+
result = rule.message || format({
|
|
26
84
|
id: 'form.invalid',
|
|
27
85
|
messages: messages
|
|
28
86
|
});
|
|
29
87
|
|
|
30
|
-
if (
|
|
88
|
+
if (rule.status) {
|
|
31
89
|
result = {
|
|
32
90
|
message: result,
|
|
33
|
-
status:
|
|
91
|
+
status: rule.status
|
|
34
92
|
};
|
|
35
93
|
}
|
|
36
94
|
}
|
|
@@ -40,39 +98,37 @@ var validate = function validate(validator, nameValue, formValue, format, messag
|
|
|
40
98
|
}; // Validates particular key in formValue
|
|
41
99
|
|
|
42
100
|
|
|
43
|
-
var validateName = function validateName(
|
|
101
|
+
var validateName = function validateName(validationRules, required) {
|
|
44
102
|
return function (name, formValue, format, messages) {
|
|
45
|
-
var
|
|
46
|
-
var
|
|
47
|
-
// See 'validate' prop in FormField
|
|
103
|
+
var fieldValue = getFieldValue(name, formValue);
|
|
104
|
+
var validationResult;
|
|
48
105
|
|
|
49
|
-
if (required && (
|
|
50
|
-
|
|
51
|
-
|
|
106
|
+
if (required && ( // false is for CheckBox
|
|
107
|
+
fieldValue === undefined || fieldValue === '' || fieldValue === false || Array.isArray(fieldValue) && !fieldValue.length)) {
|
|
108
|
+
validationResult = format({
|
|
52
109
|
id: 'form.required',
|
|
53
110
|
messages: messages
|
|
54
111
|
});
|
|
55
|
-
} else if (
|
|
56
|
-
if (Array.isArray(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return !!
|
|
112
|
+
} else if (validationRules) {
|
|
113
|
+
if (Array.isArray(validationRules)) {
|
|
114
|
+
validationRules.some(function (rule) {
|
|
115
|
+
validationResult = validate(rule, fieldValue, formValue, format, messages);
|
|
116
|
+
return !!validationResult;
|
|
60
117
|
});
|
|
61
118
|
} else {
|
|
62
|
-
|
|
119
|
+
validationResult = validate(validationRules, fieldValue, formValue, format, messages);
|
|
63
120
|
}
|
|
64
121
|
}
|
|
65
122
|
|
|
66
|
-
return
|
|
123
|
+
return validationResult;
|
|
67
124
|
};
|
|
68
|
-
}; //
|
|
69
|
-
// Validates all keys in formValue
|
|
125
|
+
}; // Validates all keys in formValue
|
|
70
126
|
|
|
71
127
|
|
|
72
|
-
var validateForm = function validateForm(
|
|
128
|
+
var validateForm = function validateForm(validationRules, formValue, format, messages, omitValid) {
|
|
73
129
|
var nextErrors = {};
|
|
74
130
|
var nextInfos = {};
|
|
75
|
-
|
|
131
|
+
validationRules.forEach(function (_ref) {
|
|
76
132
|
var name = _ref[0],
|
|
77
133
|
_ref$ = _ref[1],
|
|
78
134
|
field = _ref$.field,
|
|
@@ -86,12 +142,12 @@ var validateForm = function validateForm(validations, formValue, format, message
|
|
|
86
142
|
var result;
|
|
87
143
|
|
|
88
144
|
if (input) {
|
|
89
|
-
// input()
|
|
145
|
+
// input() a validation function supplied through useFormInput()
|
|
90
146
|
result = input(name, formValue, format, messages);
|
|
91
147
|
}
|
|
92
148
|
|
|
93
149
|
if (field && !result) {
|
|
94
|
-
// field()
|
|
150
|
+
// field() a validation function supplied through useFormField()
|
|
95
151
|
result = field(name, formValue, format, messages);
|
|
96
152
|
} // typeof error === 'object' is implied for both cases of error with
|
|
97
153
|
// a status message and for an error object that is a react node
|
|
@@ -141,147 +197,138 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
141
197
|
touched = _useState2[0],
|
|
142
198
|
setTouched = _useState2[1];
|
|
143
199
|
|
|
144
|
-
var _useState3 = useState(
|
|
200
|
+
var _useState3 = useState({
|
|
201
|
+
errors: errorsProp,
|
|
202
|
+
infos: infosProp
|
|
203
|
+
}),
|
|
145
204
|
validationResults = _useState3[0],
|
|
146
|
-
setValidationResults = _useState3[1]; //
|
|
147
|
-
//
|
|
148
|
-
//
|
|
149
|
-
// for a detailed scenario/discussion,
|
|
150
|
-
// see: https://github.com/grommet/grommet/issues/4863
|
|
151
|
-
// the value of pendingValidation is the name of the FormField
|
|
152
|
-
// awaiting validation.
|
|
205
|
+
setValidationResults = _useState3[1]; // maintain a copy of validationResults in a ref for useEffects
|
|
206
|
+
// which can't depend on validationResults directly without
|
|
207
|
+
// causing infinite renders.
|
|
153
208
|
|
|
154
209
|
|
|
155
|
-
var
|
|
156
|
-
|
|
157
|
-
|
|
210
|
+
var validationResultsRef = useRef({}); // Simulated onMount state. Consider Form to be mounted once it has
|
|
211
|
+
// accounted for values originating from controlled inputs (available
|
|
212
|
+
// at second rendering).
|
|
213
|
+
|
|
214
|
+
var _useState4 = useState('unmounted'),
|
|
215
|
+
mounted = _useState4[0],
|
|
216
|
+
setMounted = _useState4[1];
|
|
158
217
|
|
|
159
218
|
useEffect(function () {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
219
|
+
if (!mounted) setMounted('mounting');else if (mounted === 'mounting') setMounted('mounted');
|
|
220
|
+
}, [mounted]); // `pendingValidation` is the name of the FormField awaiting validation.
|
|
221
|
+
|
|
222
|
+
var _useState5 = useState(undefined),
|
|
223
|
+
pendingValidation = _useState5[0],
|
|
224
|
+
setPendingValidation = _useState5[1];
|
|
225
|
+
|
|
226
|
+
var validationRulesRef = useRef({});
|
|
167
227
|
var requiredFields = useRef([]);
|
|
168
228
|
var buildValid = useCallback(function (nextErrors) {
|
|
169
229
|
var valid = false;
|
|
170
230
|
valid = requiredFields.current.filter(function (n) {
|
|
171
|
-
return Object.keys(
|
|
231
|
+
return Object.keys(validationRulesRef.current).includes(n);
|
|
172
232
|
}).every(function (field) {
|
|
173
233
|
return value[field] && (value[field] !== '' || value[field] !== false);
|
|
174
234
|
});
|
|
175
235
|
if (Object.keys(nextErrors).length > 0) valid = false;
|
|
176
236
|
return valid;
|
|
177
|
-
}, [value]); //
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
237
|
+
}, [value]); // Only keep validation results for current form fields. In the case of a
|
|
238
|
+
// dynamic form, a field possessing an error may have been removed from the
|
|
239
|
+
// form; need to clean up any previous related validation results.
|
|
240
|
+
|
|
241
|
+
var filterRemovedFields = function filterRemovedFields(prevValidations) {
|
|
242
|
+
var nextValidations = prevValidations;
|
|
243
|
+
return Object.keys(nextValidations).filter(function (n) {
|
|
244
|
+
return !validationRulesRef.current[n] || nextValidations[n] === undefined;
|
|
183
245
|
}).forEach(function (n) {
|
|
184
|
-
return delete
|
|
246
|
+
return delete nextValidations[n];
|
|
185
247
|
});
|
|
186
|
-
};
|
|
248
|
+
};
|
|
187
249
|
|
|
250
|
+
var applyValidationRules = useCallback(function (validationRules) {
|
|
251
|
+
var _validateForm = validateForm(validationRules, value, format, messages),
|
|
252
|
+
validatedErrors = _validateForm[0],
|
|
253
|
+
validatedInfos = _validateForm[1];
|
|
188
254
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}).forEach(function (n) {
|
|
194
|
-
return delete nextInfos[n];
|
|
195
|
-
});
|
|
196
|
-
}; // On initial mount, when validateOn is change or blur,
|
|
197
|
-
// set validation results for any set fields and calculate whether
|
|
198
|
-
// the form is valid overall.
|
|
199
|
-
|
|
255
|
+
setValidationResults(function (prevValidationResults) {
|
|
256
|
+
// Keep any previous errors and infos for untouched keys,
|
|
257
|
+
// these may have come from a Submit.
|
|
258
|
+
var nextErrors = _extends({}, prevValidationResults.errors, validatedErrors);
|
|
200
259
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
var n = _ref3[0];
|
|
204
|
-
return value[n];
|
|
205
|
-
});
|
|
260
|
+
var nextInfos = _extends({}, prevValidationResults.infos, validatedInfos); // Remove previous errors and infos for keys no longer in the
|
|
261
|
+
// form, these may have been fields removed from a dynamic form.
|
|
206
262
|
|
|
207
|
-
if (validationsForSetFields.length > 0 && validateOn !== 'submit') {
|
|
208
|
-
var _validateForm = validateForm(validationsForSetFields, value, format, messages),
|
|
209
|
-
errors = _validateForm[0],
|
|
210
|
-
infos = _validateForm[1];
|
|
211
263
|
|
|
212
|
-
|
|
213
|
-
|
|
264
|
+
filterRemovedFields(nextErrors);
|
|
265
|
+
filterRemovedFields(nextInfos);
|
|
214
266
|
var nextValidationResults = {
|
|
215
|
-
errors:
|
|
216
|
-
infos:
|
|
217
|
-
valid: buildValid(errors)
|
|
267
|
+
errors: nextErrors,
|
|
268
|
+
infos: nextInfos
|
|
218
269
|
};
|
|
219
|
-
if (onValidate) onValidate(nextValidationResults
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
270
|
+
if (onValidate) onValidate(_extends({}, nextValidationResults, {
|
|
271
|
+
valid: buildValid(nextErrors)
|
|
272
|
+
}));
|
|
273
|
+
validationResultsRef.current = nextValidationResults;
|
|
274
|
+
return nextValidationResults;
|
|
275
|
+
});
|
|
276
|
+
}, [buildValid, format, messages, onValidate, value]); // Validate all fields holding values onMount if set to
|
|
277
|
+
// validate when blur or change.
|
|
224
278
|
|
|
225
|
-
|
|
279
|
+
useEffect(function () {
|
|
280
|
+
var validationRules = Object.entries(validationRulesRef.current); // Use simulated onMount state to account for values provided by
|
|
281
|
+
// controlled inputs.
|
|
282
|
+
|
|
283
|
+
if (mounted !== 'mounted' && ['blur', 'change'].includes(validateOn) && Object.keys(value).length > 0 && Object.keys(touched).length === 0) {
|
|
284
|
+
applyValidationRules(validationRules.filter(function (_ref3) {
|
|
285
|
+
var n = _ref3[0];
|
|
286
|
+
return value[n];
|
|
287
|
+
}) // Exlude empty arrays which may be initial values in
|
|
288
|
+
// an input such as DateInput.
|
|
289
|
+
.filter(function (_ref4) {
|
|
290
|
+
var n = _ref4[0];
|
|
291
|
+
return !(Array.isArray(value[n]) && value[n].length === 0);
|
|
292
|
+
}));
|
|
293
|
+
}
|
|
294
|
+
}, [applyValidationRules, mounted, touched, validateOn, value]); // Run validation against fields with pendingValidations from onBlur
|
|
295
|
+
// and/or onChange.
|
|
226
296
|
|
|
227
297
|
useEffect(function () {
|
|
298
|
+
var validationRules = Object.entries(validationRulesRef.current);
|
|
228
299
|
var timer = setTimeout(function () {
|
|
229
|
-
if (pendingValidation) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
var n = _ref4[0];
|
|
300
|
+
if (pendingValidation && ['blur', 'change'].includes(validateOn)) {
|
|
301
|
+
applyValidationRules(validationRules.filter(function (_ref5) {
|
|
302
|
+
var n = _ref5[0];
|
|
233
303
|
return touched[n] || pendingValidation.includes(n);
|
|
234
|
-
})
|
|
235
|
-
validatedErrors = _validateForm2[0],
|
|
236
|
-
validatedInfos = _validateForm2[1];
|
|
237
|
-
|
|
304
|
+
}));
|
|
238
305
|
setPendingValidation(undefined);
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
var nextInfos = _extends({}, prevValidationResults.infos, validatedInfos);
|
|
245
|
-
|
|
246
|
-
filterErrorValidations(nextErrors);
|
|
247
|
-
filterInfoValidations(nextInfos);
|
|
248
|
-
var nextValidationResults = {
|
|
249
|
-
errors: nextErrors,
|
|
250
|
-
infos: nextInfos,
|
|
251
|
-
valid: buildValid(nextErrors)
|
|
252
|
-
};
|
|
253
|
-
if (onValidate) onValidate(nextValidationResults);
|
|
254
|
-
return nextValidationResults;
|
|
255
|
-
});
|
|
256
|
-
} // a timeout is needed to ensure that a click event (like one on a reset
|
|
257
|
-
// button) completes prior to running the validation. without a timeout,
|
|
258
|
-
// the blur will always complete and trigger a validation prematurely
|
|
259
|
-
// The following values have been empirically tested, but 120 was
|
|
260
|
-
// selected because it is the largest value
|
|
306
|
+
} // Complete any potential click events before running onBlur validation.
|
|
307
|
+
// Otherwise, click events like reset, etc. may not be registered. For a
|
|
308
|
+
// detailed scenario/discussion, see: https://github.com/grommet/grommet/issues/4863
|
|
309
|
+
// Values empirically tested; 120 was selected because it is the largest
|
|
261
310
|
// Chrome: 100, Safari: 120, Firefox: 80
|
|
262
311
|
|
|
263
312
|
}, 120);
|
|
264
313
|
return function () {
|
|
265
314
|
return clearTimeout(timer);
|
|
266
315
|
};
|
|
267
|
-
}, [
|
|
316
|
+
}, [applyValidationRules, pendingValidation, touched, validateOn]); // Re-run validation rules for all fields with prior errors.
|
|
317
|
+
// if validate=blur this helps re-validate if there are errors
|
|
318
|
+
// as the user fixes them (basically act like validate=change for that)
|
|
268
319
|
|
|
269
320
|
useEffect(function () {
|
|
270
|
-
|
|
271
|
-
setValidationResults(function (prevValidationResults) {
|
|
272
|
-
var _validateForm3 = validateForm(Object.entries(validations.current).filter(function (_ref5) {
|
|
273
|
-
var n = _ref5[0];
|
|
274
|
-
return prevValidationResults.errors[n] || prevValidationResults.infos[n];
|
|
275
|
-
}), value, format, messages),
|
|
276
|
-
nextErrors = _validateForm3[0],
|
|
277
|
-
nextInfos = _validateForm3[1];
|
|
321
|
+
var _validationResultsRef;
|
|
278
322
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
323
|
+
var validationRules = Object.entries(validationRulesRef.current);
|
|
324
|
+
|
|
325
|
+
if ((_validationResultsRef = validationResultsRef.current) != null && _validationResultsRef.errors && Object.keys(validationResultsRef.current.errors).length > 0) {
|
|
326
|
+
applyValidationRules(validationRules.filter(function (_ref6) {
|
|
327
|
+
var n = _ref6[0];
|
|
328
|
+
return touched[n] && validationResultsRef.current.errors[n];
|
|
329
|
+
}));
|
|
330
|
+
}
|
|
331
|
+
}, [applyValidationRules, touched]); // There are three basic patterns of handling form input value state:
|
|
285
332
|
//
|
|
286
333
|
// 1 - form controlled
|
|
287
334
|
//
|
|
@@ -314,144 +361,155 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
314
361
|
// they can have access to it.
|
|
315
362
|
//
|
|
316
363
|
|
|
317
|
-
var
|
|
318
|
-
var
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
var nextValue = _extends({}, prevValue);
|
|
341
|
-
|
|
342
|
-
nextValue[name] = componentValue;
|
|
343
|
-
return nextValue;
|
|
344
|
-
}); // don't onChange on programmatic changes
|
|
345
|
-
}
|
|
346
|
-
}, [componentValue, formValue, name]); // on unmount, if the form is uncontrolled, remove the key/value
|
|
347
|
-
// from the form value
|
|
348
|
-
|
|
349
|
-
useEffect(function () {
|
|
350
|
-
return function () {
|
|
351
|
-
if (keyCreated.current) {
|
|
352
|
-
keyCreated.current = false;
|
|
364
|
+
var formContextValue = useMemo(function () {
|
|
365
|
+
var useFormInput = function useFormInput(_ref7) {
|
|
366
|
+
var name = _ref7.name,
|
|
367
|
+
componentValue = _ref7.value,
|
|
368
|
+
initialValue = _ref7.initialValue,
|
|
369
|
+
validateArg = _ref7.validate;
|
|
370
|
+
|
|
371
|
+
var _useState6 = useState(initialValue),
|
|
372
|
+
inputValue = _useState6[0],
|
|
373
|
+
setInputValue = _useState6[1];
|
|
374
|
+
|
|
375
|
+
var formValue = name ? getFieldValue(name, value) : undefined; // for dynamic forms, we need to track when an input has been added to
|
|
376
|
+
// the form value. if the input is unmounted, we will delete its
|
|
377
|
+
// key/value from the form value.
|
|
378
|
+
|
|
379
|
+
var keyCreated = useRef(false); // This effect is for pattern #2, where the controlled input
|
|
380
|
+
// component is driving the value via componentValue.
|
|
381
|
+
|
|
382
|
+
useEffect(function () {
|
|
383
|
+
if (name && // we have somewhere to put this
|
|
384
|
+
componentValue !== undefined && // input driving
|
|
385
|
+
componentValue !== formValue // don't already have it
|
|
386
|
+
) {
|
|
353
387
|
setValueState(function (prevValue) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
delete nextValue[name];
|
|
357
|
-
return nextValue;
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
};
|
|
361
|
-
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
362
|
-
[] // only run onmount and unmount
|
|
363
|
-
);
|
|
364
|
-
useEffect(function () {
|
|
365
|
-
if (validateArg) {
|
|
366
|
-
if (!validations.current[name]) {
|
|
367
|
-
validations.current[name] = {};
|
|
388
|
+
return setFieldValue(name, componentValue, prevValue);
|
|
389
|
+
}); // don't onChange on programmatic changes
|
|
368
390
|
}
|
|
391
|
+
}, [componentValue, formValue, name]); // on unmount, if the form is uncontrolled, remove the key/value
|
|
392
|
+
// from the form value
|
|
369
393
|
|
|
370
|
-
|
|
394
|
+
useEffect(function () {
|
|
371
395
|
return function () {
|
|
372
|
-
|
|
396
|
+
if (keyCreated.current) {
|
|
397
|
+
keyCreated.current = false;
|
|
398
|
+
setValueState(function (prevValue) {
|
|
399
|
+
var nextValue = _extends({}, prevValue);
|
|
400
|
+
|
|
401
|
+
var isArrayField = stringToArray(name);
|
|
402
|
+
|
|
403
|
+
if (isArrayField) {
|
|
404
|
+
var arrayName = isArrayField.arrayName;
|
|
405
|
+
delete nextValue[arrayName];
|
|
406
|
+
} else {
|
|
407
|
+
delete nextValue[name];
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
return nextValue;
|
|
411
|
+
});
|
|
412
|
+
}
|
|
373
413
|
};
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
nextTouched[name] = true;
|
|
389
|
-
|
|
390
|
-
if (!touched[name]) {
|
|
391
|
-
// don't update if not needed
|
|
392
|
-
setTouched(nextTouched);
|
|
414
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
415
|
+
[] // only run onmount and unmount
|
|
416
|
+
); // Create validation rules for fields
|
|
417
|
+
|
|
418
|
+
useEffect(function () {
|
|
419
|
+
if (validateArg) {
|
|
420
|
+
if (!validationRulesRef.current[name]) {
|
|
421
|
+
validationRulesRef.current[name] = {};
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
validationRulesRef.current[name].input = validateName(validateArg);
|
|
425
|
+
return function () {
|
|
426
|
+
return delete validationRulesRef.current[name].input;
|
|
427
|
+
};
|
|
393
428
|
}
|
|
394
429
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
430
|
+
return undefined;
|
|
431
|
+
}, [validateArg, name]);
|
|
432
|
+
var useValue;
|
|
433
|
+
if (componentValue !== undefined) // input component drives, pattern #2
|
|
434
|
+
useValue = componentValue;else if (valueProp && name && formValue !== undefined) // form drives, pattern #1
|
|
435
|
+
useValue = formValue;else if (formValue === undefined && name) // form has reset, so reset input value as well
|
|
436
|
+
useValue = initialValue;else useValue = inputValue;
|
|
437
|
+
return [useValue, function (nextComponentValue) {
|
|
438
|
+
if (name) {
|
|
439
|
+
// we have somewhere to put this
|
|
440
|
+
var nextTouched = _extends({}, touched);
|
|
441
|
+
|
|
442
|
+
nextTouched[name] = true;
|
|
443
|
+
|
|
444
|
+
if (!touched[name]) {
|
|
445
|
+
// don't update if not needed
|
|
446
|
+
setTouched(nextTouched);
|
|
447
|
+
} // if nextValue doesn't have a key for name, this must be
|
|
448
|
+
// uncontrolled form. we will flag this field was added so
|
|
449
|
+
// we know to remove its value from the form if it is dynamically
|
|
450
|
+
// removed
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
if (!(name in value)) keyCreated.current = true;
|
|
454
|
+
var nextValue = setFieldValue(name, nextComponentValue, value);
|
|
455
|
+
setValueState(nextValue);
|
|
456
|
+
if (onChange) onChange(nextValue, {
|
|
457
|
+
touched: nextTouched
|
|
458
|
+
});
|
|
459
|
+
}
|
|
408
460
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
461
|
+
if (initialValue !== undefined) setInputValue(nextComponentValue);
|
|
462
|
+
}];
|
|
463
|
+
};
|
|
412
464
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
if (
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
if (
|
|
431
|
-
|
|
465
|
+
var useFormField = function useFormField(_ref8) {
|
|
466
|
+
var errorArg = _ref8.error,
|
|
467
|
+
infoArg = _ref8.info,
|
|
468
|
+
name = _ref8.name,
|
|
469
|
+
required = _ref8.required,
|
|
470
|
+
disabled = _ref8.disabled,
|
|
471
|
+
validateArg = _ref8.validate;
|
|
472
|
+
var error = disabled ? undefined : errorArg || validationResults.errors[name];
|
|
473
|
+
var info = infoArg || validationResults.infos[name]; // Create validation rules for field
|
|
474
|
+
|
|
475
|
+
useEffect(function () {
|
|
476
|
+
var index = requiredFields.current.indexOf(name);
|
|
477
|
+
|
|
478
|
+
if (required) {
|
|
479
|
+
if (index === -1) requiredFields.current.push(name);
|
|
480
|
+
} else if (index !== -1) requiredFields.current.splice(index, 1);
|
|
481
|
+
|
|
482
|
+
if (validateArg || required) {
|
|
483
|
+
if (!validationRulesRef.current[name]) {
|
|
484
|
+
validationRulesRef.current[name] = {};
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
validationRulesRef.current[name].field = validateName(validateArg, required);
|
|
488
|
+
return function () {
|
|
489
|
+
return delete validationRulesRef.current[name].field;
|
|
490
|
+
};
|
|
432
491
|
}
|
|
433
492
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
493
|
+
return undefined;
|
|
494
|
+
}, [error, name, required, validateArg, disabled]);
|
|
495
|
+
return {
|
|
496
|
+
error: error,
|
|
497
|
+
info: info,
|
|
498
|
+
inForm: true,
|
|
499
|
+
onBlur: validateOn === 'blur' ? function () {
|
|
500
|
+
return setPendingValidation(pendingValidation ? [].concat(pendingValidation, [name]) : [name]);
|
|
501
|
+
} : undefined,
|
|
502
|
+
onChange: validateOn === 'change' ? function () {
|
|
503
|
+
return setPendingValidation(pendingValidation ? [].concat(pendingValidation, [name]) : [name]);
|
|
504
|
+
} : undefined
|
|
505
|
+
};
|
|
506
|
+
};
|
|
439
507
|
|
|
440
|
-
return undefined;
|
|
441
|
-
}, [error, name, required, validateArg, disabled]);
|
|
442
508
|
return {
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
inForm: true,
|
|
446
|
-
onBlur: validateOn === 'blur' ? function () {
|
|
447
|
-
return setPendingValidation(pendingValidation ? [].concat(pendingValidation, [name]) : [name]);
|
|
448
|
-
} : undefined,
|
|
449
|
-
onChange: validateOn === 'change' ? function () {
|
|
450
|
-
return setPendingValidation(pendingValidation ? [].concat(pendingValidation, [name]) : [name]);
|
|
451
|
-
} : undefined
|
|
509
|
+
useFormField: useFormField,
|
|
510
|
+
useFormInput: useFormInput
|
|
452
511
|
};
|
|
453
|
-
};
|
|
454
|
-
|
|
512
|
+
}, [onChange, pendingValidation, touched, validateOn, validationResults.errors, validationResults.infos, value, valueProp]);
|
|
455
513
|
return /*#__PURE__*/React.createElement("form", _extends({
|
|
456
514
|
ref: ref
|
|
457
515
|
}, rest, {
|
|
@@ -484,9 +542,9 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
484
542
|
event.preventDefault();
|
|
485
543
|
setPendingValidation(undefined);
|
|
486
544
|
|
|
487
|
-
var
|
|
488
|
-
nextErrors =
|
|
489
|
-
nextInfos =
|
|
545
|
+
var _validateForm2 = validateForm(Object.entries(validationRulesRef.current), value, format, messages, true),
|
|
546
|
+
nextErrors = _validateForm2[0],
|
|
547
|
+
nextInfos = _validateForm2[1];
|
|
490
548
|
|
|
491
549
|
setValidationResults(function () {
|
|
492
550
|
var nextValidationResults = {
|
|
@@ -496,6 +554,7 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
496
554
|
valid: buildValid(nextErrors)
|
|
497
555
|
};
|
|
498
556
|
if (onValidate) onValidate(nextValidationResults);
|
|
557
|
+
validationResultsRef.current = nextValidationResults;
|
|
499
558
|
return nextValidationResults;
|
|
500
559
|
});
|
|
501
560
|
|
|
@@ -510,10 +569,7 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
510
569
|
}
|
|
511
570
|
}
|
|
512
571
|
}), /*#__PURE__*/React.createElement(FormContext.Provider, {
|
|
513
|
-
value:
|
|
514
|
-
useFormField: useFormField,
|
|
515
|
-
useFormInput: useFormInput
|
|
516
|
-
}
|
|
572
|
+
value: formContextValue
|
|
517
573
|
}, children));
|
|
518
574
|
});
|
|
519
575
|
Form.displayName = 'Form';
|