@wordpress/components 19.13.0 → 19.14.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/CHANGELOG.md +38 -1
- package/build/alignment-matrix-control/utils.js +1 -7
- package/build/alignment-matrix-control/utils.js.map +1 -1
- package/build/autocomplete/autocompleter-ui.js +4 -2
- package/build/autocomplete/autocompleter-ui.js.map +1 -1
- package/build/autocomplete/autocompleter-ui.native.js +9 -3
- package/build/autocomplete/autocompleter-ui.native.js.map +1 -1
- package/build/autocomplete/index.js +4 -2
- package/build/autocomplete/index.js.map +1 -1
- package/build/border-box-control/border-box-control/component.js +2 -1
- package/build/border-box-control/border-box-control/component.js.map +1 -1
- package/build/border-box-control/border-box-control-split-controls/component.js +2 -1
- package/build/border-box-control/border-box-control-split-controls/component.js.map +1 -1
- package/build/border-control/border-control/component.js +40 -4
- package/build/border-control/border-control/component.js.map +1 -1
- package/build/box-control/utils.js +3 -3
- package/build/box-control/utils.js.map +1 -1
- package/build/color-indicator/index.js +27 -10
- package/build/color-indicator/index.js.map +1 -1
- package/build/color-indicator/types.js +6 -0
- package/build/color-indicator/types.js.map +1 -0
- package/build/color-palette/index.js +2 -1
- package/build/color-palette/index.js.map +1 -1
- package/build/color-picker/component.js +6 -9
- package/build/color-picker/component.js.map +1 -1
- package/build/color-picker/input-with-slider.js +1 -2
- package/build/color-picker/input-with-slider.js.map +1 -1
- package/build/color-picker/styles.js +34 -16
- package/build/color-picker/styles.js.map +1 -1
- package/build/custom-gradient-picker/index.js +8 -8
- package/build/custom-gradient-picker/index.js.map +1 -1
- package/build/custom-gradient-picker/index.native.js +8 -9
- package/build/custom-gradient-picker/index.native.js.map +1 -1
- package/build/custom-gradient-picker/serializer.js +4 -7
- package/build/custom-gradient-picker/serializer.js.map +1 -1
- package/build/date-time/date/index.js +3 -1
- package/build/date-time/date/index.js.map +1 -1
- package/build/date-time/date-time/index.js +3 -1
- package/build/date-time/date-time/index.js.map +1 -1
- package/build/duotone-picker/duotone-picker.js +42 -29
- package/build/duotone-picker/duotone-picker.js.map +1 -1
- package/build/elevation/hook.js +13 -13
- package/build/elevation/hook.js.map +1 -1
- package/build/focal-point-picker/index.native.js +4 -4
- package/build/focal-point-picker/index.native.js.map +1 -1
- package/build/form-toggle/index.js +28 -5
- package/build/form-toggle/index.js.map +1 -1
- package/build/form-toggle/types.js +6 -0
- package/build/form-toggle/types.js.map +1 -0
- package/build/h-stack/utils.js +3 -3
- package/build/h-stack/utils.js.map +1 -1
- package/build/heading/component.js +0 -1
- package/build/heading/component.js.map +1 -1
- package/build/heading/hook.js.map +1 -1
- package/build/heading/types.js +6 -0
- package/build/heading/types.js.map +1 -0
- package/build/mobile/bottom-sheet/keyboard-avoiding-view.native.js +0 -1
- package/build/mobile/bottom-sheet/keyboard-avoiding-view.native.js.map +1 -1
- package/build/mobile/link-picker/index.native.js +4 -4
- package/build/mobile/link-picker/index.native.js.map +1 -1
- package/build/mobile/segmented-control/index.native.js +2 -4
- package/build/mobile/segmented-control/index.native.js.map +1 -1
- package/build/navigation/group/index.js +4 -7
- package/build/navigation/group/index.js.map +1 -1
- package/build/navigation/item/base.js +3 -3
- package/build/navigation/item/base.js.map +1 -1
- package/build/navigation/item/use-navigation-tree-item.js +2 -1
- package/build/navigation/item/use-navigation-tree-item.js.map +1 -1
- package/build/navigation/menu/menu-title-search.js +1 -7
- package/build/navigation/menu/menu-title-search.js.map +1 -1
- package/build/navigation/menu/search-no-results-found.js +1 -7
- package/build/navigation/menu/search-no-results-found.js.map +1 -1
- package/build/navigation/use-navigation-tree-nodes.js +18 -10
- package/build/navigation/use-navigation-tree-nodes.js.map +1 -1
- package/build/navigation/utils.js +4 -2
- package/build/navigation/utils.js.map +1 -1
- package/build/range-control/index.js +3 -3
- package/build/range-control/index.js.map +1 -1
- package/build/range-control/utils.js +3 -7
- package/build/range-control/utils.js.map +1 -1
- package/build/spacer/component.js +5 -5
- package/build/spacer/component.js.map +1 -1
- package/build/spinner/index.js +26 -13
- package/build/spinner/index.js.map +1 -1
- package/build/spinner/styles.js +10 -10
- package/build/spinner/styles.js.map +1 -1
- package/build/truncate/component.js +7 -8
- package/build/truncate/component.js.map +1 -1
- package/build/truncate/hook.js +3 -10
- package/build/truncate/hook.js.map +1 -1
- package/build/truncate/index.js.map +1 -1
- package/build/truncate/styles.js +1 -1
- package/build/truncate/styles.js.map +1 -1
- package/build/truncate/utils.js +3 -16
- package/build/truncate/utils.js.map +1 -1
- package/build/utils/math.js +17 -7
- package/build/utils/math.js.map +1 -1
- package/build/v-stack/component.js +9 -9
- package/build/v-stack/component.js.map +1 -1
- package/build/v-stack/hook.js +0 -5
- package/build/v-stack/hook.js.map +1 -1
- package/build/v-stack/index.js.map +1 -1
- package/build-module/alignment-matrix-control/utils.js +1 -6
- package/build-module/alignment-matrix-control/utils.js.map +1 -1
- package/build-module/autocomplete/autocompleter-ui.js +4 -2
- package/build-module/autocomplete/autocompleter-ui.js.map +1 -1
- package/build-module/autocomplete/autocompleter-ui.native.js +9 -3
- package/build-module/autocomplete/autocompleter-ui.native.js.map +1 -1
- package/build-module/autocomplete/index.js +4 -2
- package/build-module/autocomplete/index.js.map +1 -1
- package/build-module/border-box-control/border-box-control/component.js +2 -1
- package/build-module/border-box-control/border-box-control/component.js.map +1 -1
- package/build-module/border-box-control/border-box-control-split-controls/component.js +2 -1
- package/build-module/border-box-control/border-box-control-split-controls/component.js.map +1 -1
- package/build-module/border-control/border-control/component.js +38 -3
- package/build-module/border-control/border-control/component.js.map +1 -1
- package/build-module/box-control/utils.js +4 -4
- package/build-module/box-control/utils.js.map +1 -1
- package/build-module/color-indicator/index.js +29 -8
- package/build-module/color-indicator/index.js.map +1 -1
- package/build-module/color-indicator/types.js +2 -0
- package/build-module/color-indicator/types.js.map +1 -0
- package/build-module/color-palette/index.js +2 -1
- package/build-module/color-palette/index.js.map +1 -1
- package/build-module/color-picker/component.js +7 -8
- package/build-module/color-picker/component.js.map +1 -1
- package/build-module/color-picker/input-with-slider.js +1 -2
- package/build-module/color-picker/input-with-slider.js.map +1 -1
- package/build-module/color-picker/styles.js +28 -14
- package/build-module/color-picker/styles.js.map +1 -1
- package/build-module/custom-gradient-picker/index.js +8 -7
- package/build-module/custom-gradient-picker/index.js.map +1 -1
- package/build-module/custom-gradient-picker/index.native.js +8 -8
- package/build-module/custom-gradient-picker/index.native.js.map +1 -1
- package/build-module/custom-gradient-picker/serializer.js +4 -6
- package/build-module/custom-gradient-picker/serializer.js.map +1 -1
- package/build-module/date-time/date/index.js +3 -1
- package/build-module/date-time/date/index.js.map +1 -1
- package/build-module/date-time/date-time/index.js +3 -1
- package/build-module/date-time/date-time/index.js.map +1 -1
- package/build-module/duotone-picker/duotone-picker.js +42 -29
- package/build-module/duotone-picker/duotone-picker.js.map +1 -1
- package/build-module/elevation/hook.js +12 -12
- package/build-module/elevation/hook.js.map +1 -1
- package/build-module/focal-point-picker/index.native.js +1 -1
- package/build-module/focal-point-picker/index.native.js.map +1 -1
- package/build-module/form-toggle/index.js +30 -6
- package/build-module/form-toggle/index.js.map +1 -1
- package/build-module/form-toggle/types.js +2 -0
- package/build-module/form-toggle/types.js.map +1 -0
- package/build-module/h-stack/utils.js +3 -3
- package/build-module/h-stack/utils.js.map +1 -1
- package/build-module/heading/component.js +0 -1
- package/build-module/heading/component.js.map +1 -1
- package/build-module/heading/hook.js.map +1 -1
- package/build-module/heading/types.js +2 -0
- package/build-module/heading/types.js.map +1 -0
- package/build-module/mobile/bottom-sheet/keyboard-avoiding-view.native.js +0 -1
- package/build-module/mobile/bottom-sheet/keyboard-avoiding-view.native.js.map +1 -1
- package/build-module/mobile/link-picker/index.native.js +4 -3
- package/build-module/mobile/link-picker/index.native.js.map +1 -1
- package/build-module/mobile/segmented-control/index.native.js +2 -3
- package/build-module/mobile/segmented-control/index.native.js.map +1 -1
- package/build-module/navigation/group/index.js +3 -6
- package/build-module/navigation/group/index.js.map +1 -1
- package/build-module/navigation/item/base.js +2 -2
- package/build-module/navigation/item/base.js.map +1 -1
- package/build-module/navigation/item/use-navigation-tree-item.js +2 -1
- package/build-module/navigation/item/use-navigation-tree-item.js.map +1 -1
- package/build-module/navigation/menu/menu-title-search.js +1 -6
- package/build-module/navigation/menu/menu-title-search.js.map +1 -1
- package/build-module/navigation/menu/search-no-results-found.js +1 -6
- package/build-module/navigation/menu/search-no-results-found.js.map +1 -1
- package/build-module/navigation/use-navigation-tree-nodes.js +18 -9
- package/build-module/navigation/use-navigation-tree-nodes.js.map +1 -1
- package/build-module/navigation/utils.js +2 -2
- package/build-module/navigation/utils.js.map +1 -1
- package/build-module/range-control/index.js +1 -1
- package/build-module/range-control/index.js.map +1 -1
- package/build-module/range-control/utils.js +1 -5
- package/build-module/range-control/utils.js.map +1 -1
- package/build-module/spacer/component.js +3 -4
- package/build-module/spacer/component.js.map +1 -1
- package/build-module/spinner/index.js +22 -13
- package/build-module/spinner/index.js.map +1 -1
- package/build-module/spinner/styles.js +10 -10
- package/build-module/spinner/styles.js.map +1 -1
- package/build-module/truncate/component.js +7 -8
- package/build-module/truncate/component.js.map +1 -1
- package/build-module/truncate/hook.js +3 -10
- package/build-module/truncate/hook.js.map +1 -1
- package/build-module/truncate/index.js.map +1 -1
- package/build-module/truncate/styles.js +1 -1
- package/build-module/truncate/styles.js.map +1 -1
- package/build-module/truncate/utils.js +3 -16
- package/build-module/truncate/utils.js.map +1 -1
- package/build-module/utils/math.js +15 -6
- package/build-module/utils/math.js.map +1 -1
- package/build-module/v-stack/component.js +9 -9
- package/build-module/v-stack/component.js.map +1 -1
- package/build-module/v-stack/hook.js +0 -5
- package/build-module/v-stack/hook.js.map +1 -1
- package/build-module/v-stack/index.js.map +1 -1
- package/build-style/style-rtl.css +16 -0
- package/build-style/style.css +16 -0
- package/build-types/border-box-control/border-box-control/component.d.ts.map +1 -1
- package/build-types/border-box-control/border-box-control-split-controls/component.d.ts.map +1 -1
- package/build-types/border-control/border-control/component.d.ts +36 -2
- package/build-types/border-control/border-control/component.d.ts.map +1 -1
- package/build-types/border-control/stories/index.d.ts +33 -0
- package/build-types/border-control/stories/index.d.ts.map +1 -0
- package/build-types/color-indicator/index.d.ts +16 -5
- package/build-types/color-indicator/index.d.ts.map +1 -1
- package/build-types/color-indicator/stories/index.d.ts +12 -0
- package/build-types/color-indicator/stories/index.d.ts.map +1 -0
- package/build-types/color-indicator/test/index.d.ts +2 -0
- package/build-types/color-indicator/test/index.d.ts.map +1 -0
- package/build-types/color-indicator/types.d.ts +12 -0
- package/build-types/color-indicator/types.d.ts.map +1 -0
- package/build-types/color-palette/index.d.ts.map +1 -1
- package/build-types/color-palette/styles.d.ts +4 -2
- package/build-types/color-palette/styles.d.ts.map +1 -1
- package/build-types/color-picker/component.d.ts.map +1 -1
- package/build-types/color-picker/styles.d.ts +17 -0
- package/build-types/color-picker/styles.d.ts.map +1 -1
- package/build-types/date-time/date/index.d.ts +1 -1
- package/build-types/date-time/date/index.d.ts.map +1 -1
- package/build-types/date-time/date-time/index.d.ts.map +1 -1
- package/build-types/date-time/types.d.ts +6 -0
- package/build-types/date-time/types.d.ts.map +1 -1
- package/build-types/form-toggle/index.d.ts +29 -0
- package/build-types/form-toggle/index.d.ts.map +1 -0
- package/build-types/form-toggle/stories/index.d.ts +12 -0
- package/build-types/form-toggle/stories/index.d.ts.map +1 -0
- package/build-types/form-toggle/test/index.d.ts +2 -0
- package/build-types/form-toggle/test/index.d.ts.map +1 -0
- package/build-types/form-toggle/types.d.ts +22 -0
- package/build-types/form-toggle/types.d.ts.map +1 -0
- package/build-types/form-token-field/test/lib/token-field-wrapper.d.ts +3 -0
- package/build-types/form-token-field/test/lib/token-field-wrapper.d.ts.map +1 -1
- package/build-types/heading/component.d.ts +1 -2
- package/build-types/heading/component.d.ts.map +1 -1
- package/build-types/heading/hook.d.ts +1 -28
- package/build-types/heading/hook.d.ts.map +1 -1
- package/build-types/heading/stories/index.d.ts.map +1 -1
- package/build-types/heading/test/index.d.ts +2 -0
- package/build-types/heading/test/index.d.ts.map +1 -0
- package/build-types/heading/types.d.ts +16 -0
- package/build-types/heading/types.d.ts.map +1 -0
- package/build-types/range-control/utils.d.ts.map +1 -1
- package/build-types/spacer/component.d.ts +2 -3
- package/build-types/spacer/component.d.ts.map +1 -1
- package/build-types/spacer/stories/index.d.ts +12 -0
- package/build-types/spacer/stories/index.d.ts.map +1 -0
- package/build-types/spinner/index.d.ts +16 -15
- package/build-types/spinner/index.d.ts.map +1 -1
- package/build-types/spinner/stories/index.d.ts +13 -0
- package/build-types/spinner/stories/index.d.ts.map +1 -0
- package/build-types/spinner/styles.d.ts +4 -3
- package/build-types/spinner/styles.d.ts.map +1 -1
- package/build-types/text/types.d.ts +1 -1
- package/build-types/text/types.d.ts.map +1 -1
- package/build-types/truncate/component.d.ts +3 -3
- package/build-types/truncate/component.d.ts.map +1 -1
- package/build-types/truncate/hook.d.ts +5 -2
- package/build-types/truncate/hook.d.ts.map +1 -1
- package/build-types/truncate/index.d.ts +2 -2
- package/build-types/truncate/index.d.ts.map +1 -1
- package/build-types/truncate/stories/index.d.ts +13 -0
- package/build-types/truncate/stories/index.d.ts.map +1 -0
- package/build-types/truncate/styles.d.ts +1 -1
- package/build-types/truncate/styles.d.ts.map +1 -1
- package/build-types/truncate/test/index.d.ts +2 -0
- package/build-types/truncate/test/index.d.ts.map +1 -0
- package/build-types/truncate/types.d.ts +22 -11
- package/build-types/truncate/types.d.ts.map +1 -1
- package/build-types/truncate/utils.d.ts +17 -28
- package/build-types/truncate/utils.d.ts.map +1 -1
- package/build-types/ui/form-group/use-form-group.d.ts +2 -2
- package/build-types/utils/math.d.ts +10 -0
- package/build-types/utils/math.d.ts.map +1 -1
- package/build-types/v-stack/component.d.ts +5 -4
- package/build-types/v-stack/component.d.ts.map +1 -1
- package/build-types/v-stack/hook.d.ts +5 -3
- package/build-types/v-stack/hook.d.ts.map +1 -1
- package/build-types/v-stack/index.d.ts +2 -2
- package/build-types/v-stack/index.d.ts.map +1 -1
- package/build-types/v-stack/stories/index.d.ts +9 -0
- package/build-types/v-stack/stories/index.d.ts.map +1 -0
- package/build-types/v-stack/test/index.d.ts +2 -0
- package/build-types/v-stack/test/index.d.ts.map +1 -0
- package/build-types/v-stack/types.d.ts +21 -1
- package/build-types/v-stack/types.d.ts.map +1 -1
- package/package.json +18 -17
- package/src/alignment-matrix-control/utils.js +1 -6
- package/src/autocomplete/autocompleter-ui.js +4 -1
- package/src/autocomplete/autocompleter-ui.native.js +8 -2
- package/src/autocomplete/index.js +4 -8
- package/src/border-box-control/border-box-control/component.tsx +1 -0
- package/src/border-box-control/border-box-control-split-controls/component.tsx +1 -0
- package/src/border-control/border-control/component.tsx +41 -4
- package/src/border-control/stories/index.tsx +150 -0
- package/src/box-control/utils.js +4 -4
- package/src/color-indicator/README.md +7 -9
- package/src/color-indicator/index.tsx +47 -0
- package/src/color-indicator/stories/index.tsx +37 -0
- package/src/color-indicator/test/__snapshots__/index.tsx.snap +11 -0
- package/src/color-indicator/test/{index.js → index.tsx} +4 -4
- package/src/color-indicator/types.ts +12 -0
- package/src/color-palette/index.js +5 -1
- package/src/color-picker/component.tsx +12 -11
- package/src/color-picker/input-with-slider.tsx +2 -2
- package/src/color-picker/styles.ts +20 -1
- package/src/custom-gradient-picker/index.js +4 -11
- package/src/custom-gradient-picker/index.native.js +3 -11
- package/src/custom-gradient-picker/serializer.js +5 -11
- package/src/date-time/README.md +7 -0
- package/src/date-time/date/index.tsx +2 -0
- package/src/date-time/date-time/index.tsx +2 -0
- package/src/date-time/types.ts +7 -0
- package/src/dimension-control/README.md +5 -2
- package/src/dimension-control/test/index.test.js +7 -7
- package/src/duotone-picker/duotone-picker.js +58 -37
- package/src/duotone-picker/style.scss +19 -0
- package/src/elevation/hook.js +8 -8
- package/src/flex/flex/README.md +5 -10
- package/src/flex/flex-item/README.md +1 -1
- package/src/focal-point-picker/index.native.js +1 -1
- package/src/form-toggle/README.md +10 -11
- package/src/form-toggle/index.tsx +71 -0
- package/src/form-toggle/stories/index.tsx +52 -0
- package/src/form-toggle/test/__snapshots__/index.tsx.snap +54 -0
- package/src/form-toggle/test/index.tsx +102 -0
- package/src/form-toggle/types.ts +22 -0
- package/src/form-token-field/test/index.js +6 -9
- package/src/form-token-field/test/lib/token-field-wrapper.tsx +2 -2
- package/src/h-stack/utils.js +3 -3
- package/src/heading/README.md +4 -3
- package/src/heading/component.tsx +2 -2
- package/src/heading/hook.ts +1 -42
- package/src/heading/stories/index.tsx +5 -1
- package/src/heading/test/__snapshots__/{index.js.snap → index.tsx.snap} +0 -0
- package/src/heading/test/index.tsx +68 -0
- package/src/heading/types.ts +29 -0
- package/src/input-control/test/index.js +106 -31
- package/src/mobile/bottom-sheet/keyboard-avoiding-view.native.js +2 -7
- package/src/mobile/link-picker/index.native.js +2 -3
- package/src/mobile/segmented-control/index.native.js +6 -5
- package/src/navigation/group/index.js +8 -3
- package/src/navigation/item/base.js +3 -2
- package/src/navigation/item/use-navigation-tree-item.js +2 -0
- package/src/navigation/menu/menu-title-search.js +3 -6
- package/src/navigation/menu/search-no-results-found.js +3 -6
- package/src/navigation/use-navigation-tree-nodes.js +11 -10
- package/src/navigation/utils.js +2 -2
- package/src/number-control/stories/index.js +24 -24
- package/src/range-control/index.js +1 -1
- package/src/range-control/utils.js +1 -4
- package/src/slot-fill/test/slot.js +2 -3
- package/src/spacer/component.tsx +3 -4
- package/src/spacer/stories/index.tsx +70 -0
- package/src/spinner/{index.js → index.tsx} +23 -9
- package/src/spinner/stories/index.tsx +32 -0
- package/src/spinner/{styles.js → styles.ts} +0 -0
- package/src/style.scss +1 -0
- package/src/text/types.ts +1 -1
- package/src/truncate/README.md +16 -12
- package/src/truncate/{component.js → component.tsx} +13 -9
- package/src/truncate/{hook.js → hook.ts} +8 -10
- package/src/truncate/{index.js → index.ts} +0 -0
- package/src/truncate/stories/index.tsx +49 -0
- package/src/truncate/{styles.js → styles.ts} +0 -0
- package/src/truncate/test/{index.js → index.tsx} +4 -4
- package/src/truncate/types.ts +28 -10
- package/src/truncate/{utils.js → utils.ts} +19 -19
- package/src/utils/math.js +14 -5
- package/src/utils/test/math.js +22 -1
- package/src/v-stack/README.md +6 -18
- package/src/v-stack/{component.js → component.tsx} +15 -10
- package/src/v-stack/{hook.js → hook.ts} +5 -6
- package/src/v-stack/{index.js → index.ts} +0 -0
- package/src/v-stack/stories/index.tsx +41 -0
- package/src/v-stack/test/__snapshots__/{index.js.snap → index.tsx.snap} +0 -0
- package/src/v-stack/test/{index.js → index.tsx} +0 -0
- package/src/v-stack/types.ts +21 -1
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/src/border-control/stories/index.js +0 -119
- package/src/color-indicator/index.js +0 -16
- package/src/color-indicator/stories/index.js +0 -22
- package/src/color-indicator/test/__snapshots__/index.js.snap +0 -13
- package/src/form-toggle/index.js +0 -38
- package/src/form-toggle/stories/index.js +0 -28
- package/src/form-toggle/test/index.js +0 -74
- package/src/heading/test/index.js +0 -67
- package/src/spacer/stories/index.js +0 -59
- package/src/spinner/stories/index.js +0 -43
- package/src/truncate/stories/index.js +0 -38
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { get, omit } from 'lodash';
|
|
5
1
|
/**
|
|
6
2
|
* WordPress dependencies
|
|
7
3
|
*/
|
|
@@ -37,7 +33,7 @@ function CustomGradientPicker( { setColor, currentValue, isGradientColor } ) {
|
|
|
37
33
|
}
|
|
38
34
|
|
|
39
35
|
function getGradientColor( type ) {
|
|
40
|
-
const orientation
|
|
36
|
+
const { orientation, ...restGradientAST } = gradientAST;
|
|
41
37
|
|
|
42
38
|
if ( orientation ) {
|
|
43
39
|
setGradientOrientation( orientation );
|
|
@@ -55,7 +51,7 @@ function CustomGradientPicker( { setColor, currentValue, isGradientColor } ) {
|
|
|
55
51
|
type,
|
|
56
52
|
}
|
|
57
53
|
: {
|
|
58
|
-
...
|
|
54
|
+
...restGradientAST,
|
|
59
55
|
type,
|
|
60
56
|
}
|
|
61
57
|
);
|
|
@@ -83,11 +79,7 @@ function CustomGradientPicker( { setColor, currentValue, isGradientColor } ) {
|
|
|
83
79
|
}
|
|
84
80
|
|
|
85
81
|
function getGradientAngle() {
|
|
86
|
-
return
|
|
87
|
-
gradientAST,
|
|
88
|
-
[ 'orientation', 'value' ],
|
|
89
|
-
DEFAULT_LINEAR_GRADIENT_ANGLE
|
|
90
|
-
);
|
|
82
|
+
return gradientAST?.orientation?.value ?? DEFAULT_LINEAR_GRADIENT_ANGLE;
|
|
91
83
|
}
|
|
92
84
|
return (
|
|
93
85
|
<>
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { compact, get } from 'lodash';
|
|
5
|
-
|
|
6
1
|
export function serializeGradientColor( { type, value } ) {
|
|
7
2
|
if ( type === 'literal' ) {
|
|
8
3
|
return value;
|
|
@@ -40,13 +35,12 @@ export function serializeGradient( { type, orientation, colorStops } ) {
|
|
|
40
35
|
const serializedColorStops = colorStops
|
|
41
36
|
.sort( ( colorStop1, colorStop2 ) => {
|
|
42
37
|
return (
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
( colorStop1?.length?.value ?? 0 ) -
|
|
39
|
+
( colorStop2?.length?.value ?? 0 )
|
|
45
40
|
);
|
|
46
41
|
} )
|
|
47
42
|
.map( serializeGradientColorStop );
|
|
48
|
-
return `${ type }(${
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
] ).join( ',' ) })`;
|
|
43
|
+
return `${ type }(${ [ serializedOrientation, ...serializedColorStops ]
|
|
44
|
+
.filter( Boolean )
|
|
45
|
+
.join( ',' ) })`;
|
|
52
46
|
}
|
package/src/date-time/README.md
CHANGED
|
@@ -77,6 +77,13 @@ List of events to show in the date picker. Each event will appear as a dot on th
|
|
|
77
77
|
- Type: `Array`
|
|
78
78
|
- Required: No
|
|
79
79
|
|
|
80
|
+
### `startOfWeek`: `number`
|
|
81
|
+
|
|
82
|
+
The day that the week should start on. 0 for Sunday, 1 for Monday, etc.
|
|
83
|
+
|
|
84
|
+
- Required: No
|
|
85
|
+
- Default: 0
|
|
86
|
+
|
|
80
87
|
### `__nextRemoveHelpButton`: `boolean`
|
|
81
88
|
|
|
82
89
|
Start opting in to not displaying a Help button which will become the default in a future version.
|
|
@@ -103,6 +103,7 @@ export function DatePicker( {
|
|
|
103
103
|
events,
|
|
104
104
|
isInvalidDate,
|
|
105
105
|
onMonthPreviewed,
|
|
106
|
+
startOfWeek = 0,
|
|
106
107
|
}: DatePickerProps ) {
|
|
107
108
|
const nodeRef = useRef< HTMLDivElement >( null );
|
|
108
109
|
|
|
@@ -197,6 +198,7 @@ export function DatePicker( {
|
|
|
197
198
|
isOutsideRange={ ( date ) => {
|
|
198
199
|
return !! isInvalidDate && isInvalidDate( date.toDate() );
|
|
199
200
|
} }
|
|
201
|
+
firstDayOfWeek={ startOfWeek }
|
|
200
202
|
onPrevMonthClick={ onMonthPreviewedHandler }
|
|
201
203
|
onNextMonthClick={ onMonthPreviewedHandler }
|
|
202
204
|
renderDayContents={ ( day ) => (
|
|
@@ -34,6 +34,7 @@ function UnforwardedDateTimePicker(
|
|
|
34
34
|
onMonthPreviewed = noop,
|
|
35
35
|
onChange,
|
|
36
36
|
events,
|
|
37
|
+
startOfWeek,
|
|
37
38
|
__nextRemoveHelpButton = false,
|
|
38
39
|
__nextRemoveResetButton = false,
|
|
39
40
|
}: DateTimePickerProps,
|
|
@@ -76,6 +77,7 @@ function UnforwardedDateTimePicker(
|
|
|
76
77
|
isInvalidDate={ isInvalidDate }
|
|
77
78
|
events={ events }
|
|
78
79
|
onMonthPreviewed={ onMonthPreviewed }
|
|
80
|
+
startOfWeek={ startOfWeek }
|
|
79
81
|
/>
|
|
80
82
|
</>
|
|
81
83
|
) }
|
package/src/date-time/types.ts
CHANGED
|
@@ -76,6 +76,13 @@ export type DatePickerProps = {
|
|
|
76
76
|
* dot on the day of the event.
|
|
77
77
|
*/
|
|
78
78
|
events?: DatePickerEvent[];
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The day that the week should start on. 0 for Sunday, 1 for Monday, etc.
|
|
82
|
+
*
|
|
83
|
+
* @default 0
|
|
84
|
+
*/
|
|
85
|
+
startOfWeek?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
79
86
|
};
|
|
80
87
|
|
|
81
88
|
export type DateTimePickerProps = Omit< DatePickerProps, 'onChange' > &
|
|
@@ -11,12 +11,15 @@ This feature is still experimental. “Experimental” means this is an early im
|
|
|
11
11
|
In a block's `edit` implementation, render a `<DimensionControl />` component.
|
|
12
12
|
|
|
13
13
|
```jsx
|
|
14
|
-
import { partialRight } from 'lodash';
|
|
15
|
-
|
|
16
14
|
import { registerBlockType } from '@wordpress/blocks';
|
|
17
15
|
import { __ } from '@wordpress/i18n';
|
|
18
16
|
import { DimensionControl } from '@wordpress/components';
|
|
19
17
|
|
|
18
|
+
const partialRight =
|
|
19
|
+
( fn, ...partialArgs ) =>
|
|
20
|
+
( ...args ) =>
|
|
21
|
+
fn( ...args, ...partialArgs );
|
|
22
|
+
|
|
20
23
|
registerBlockType( 'my-plugin/my-block', {
|
|
21
24
|
// ...
|
|
22
25
|
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { shallow, mount } from 'enzyme';
|
|
5
|
-
import { uniqueId } from 'lodash';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* WordPress dependencies
|
|
@@ -16,6 +15,7 @@ import { DimensionControl } from '../';
|
|
|
16
15
|
|
|
17
16
|
describe( 'DimensionControl', () => {
|
|
18
17
|
const onChangeHandler = jest.fn();
|
|
18
|
+
const instanceId = 1;
|
|
19
19
|
|
|
20
20
|
afterEach( () => {
|
|
21
21
|
onChangeHandler.mockClear();
|
|
@@ -25,7 +25,7 @@ describe( 'DimensionControl', () => {
|
|
|
25
25
|
it( 'renders with defaults', () => {
|
|
26
26
|
const wrapper = shallow(
|
|
27
27
|
<DimensionControl
|
|
28
|
-
instanceId={
|
|
28
|
+
instanceId={ instanceId }
|
|
29
29
|
label={ 'Padding' }
|
|
30
30
|
/>
|
|
31
31
|
);
|
|
@@ -35,7 +35,7 @@ describe( 'DimensionControl', () => {
|
|
|
35
35
|
it( 'renders with icon and default icon label', () => {
|
|
36
36
|
const wrapper = shallow(
|
|
37
37
|
<DimensionControl
|
|
38
|
-
instanceId={
|
|
38
|
+
instanceId={ instanceId }
|
|
39
39
|
label={ 'Margin' }
|
|
40
40
|
icon={ plus }
|
|
41
41
|
/>
|
|
@@ -46,7 +46,7 @@ describe( 'DimensionControl', () => {
|
|
|
46
46
|
it( 'renders with icon and custom icon label', () => {
|
|
47
47
|
const wrapper = shallow(
|
|
48
48
|
<DimensionControl
|
|
49
|
-
instanceId={
|
|
49
|
+
instanceId={ instanceId }
|
|
50
50
|
label={ 'Margin' }
|
|
51
51
|
icon={ plus }
|
|
52
52
|
iconLabel={ 'Tablet Devices' }
|
|
@@ -76,7 +76,7 @@ describe( 'DimensionControl', () => {
|
|
|
76
76
|
|
|
77
77
|
const wrapper = shallow(
|
|
78
78
|
<DimensionControl
|
|
79
|
-
instanceId={
|
|
79
|
+
instanceId={ instanceId }
|
|
80
80
|
label={ 'Custom Dimension' }
|
|
81
81
|
sizes={ customSizes }
|
|
82
82
|
/>
|
|
@@ -89,7 +89,7 @@ describe( 'DimensionControl', () => {
|
|
|
89
89
|
it( 'should call onChange handler with correct args on size change', () => {
|
|
90
90
|
const wrapper = mount(
|
|
91
91
|
<DimensionControl
|
|
92
|
-
instanceId={
|
|
92
|
+
instanceId={ instanceId }
|
|
93
93
|
label={ 'Padding' }
|
|
94
94
|
onChange={ onChangeHandler }
|
|
95
95
|
/>
|
|
@@ -121,7 +121,7 @@ describe( 'DimensionControl', () => {
|
|
|
121
121
|
it( 'should call onChange handler with undefined value when no size is provided on change', () => {
|
|
122
122
|
const wrapper = mount(
|
|
123
123
|
<DimensionControl
|
|
124
|
-
instanceId={
|
|
124
|
+
instanceId={ instanceId }
|
|
125
125
|
label={ 'Padding' }
|
|
126
126
|
onChange={ onChangeHandler }
|
|
127
127
|
/>
|
|
@@ -20,6 +20,7 @@ import { getDefaultColors, getGradientFromCSSColors } from './utils';
|
|
|
20
20
|
|
|
21
21
|
function DuotonePicker( {
|
|
22
22
|
clearable = true,
|
|
23
|
+
unsetable = true,
|
|
23
24
|
colorPalette,
|
|
24
25
|
duotonePalette,
|
|
25
26
|
disableCustomColors,
|
|
@@ -32,43 +33,60 @@ function DuotonePicker( {
|
|
|
32
33
|
[ colorPalette ]
|
|
33
34
|
);
|
|
34
35
|
|
|
36
|
+
const isUnset = value === 'unset';
|
|
37
|
+
|
|
38
|
+
const unsetOption = (
|
|
39
|
+
<CircularOptionPicker.Option
|
|
40
|
+
key="unset"
|
|
41
|
+
value="unset"
|
|
42
|
+
isSelected={ isUnset }
|
|
43
|
+
tooltipText={ __( 'Unset' ) }
|
|
44
|
+
className="components-duotone-picker__color-indicator"
|
|
45
|
+
onClick={ () => {
|
|
46
|
+
onChange( isUnset ? undefined : 'unset' );
|
|
47
|
+
} }
|
|
48
|
+
/>
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const options = duotonePalette.map( ( { colors, slug, name } ) => {
|
|
52
|
+
const style = {
|
|
53
|
+
background: getGradientFromCSSColors( colors, '135deg' ),
|
|
54
|
+
color: 'transparent',
|
|
55
|
+
};
|
|
56
|
+
const tooltipText =
|
|
57
|
+
name ??
|
|
58
|
+
sprintf(
|
|
59
|
+
// translators: %s: duotone code e.g: "dark-grayscale" or "7f7f7f-ffffff".
|
|
60
|
+
__( 'Duotone code: %s' ),
|
|
61
|
+
slug
|
|
62
|
+
);
|
|
63
|
+
const label = name
|
|
64
|
+
? sprintf(
|
|
65
|
+
// translators: %s: The name of the option e.g: "Dark grayscale".
|
|
66
|
+
__( 'Duotone: %s' ),
|
|
67
|
+
name
|
|
68
|
+
)
|
|
69
|
+
: tooltipText;
|
|
70
|
+
const isSelected = isEqual( colors, value );
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<CircularOptionPicker.Option
|
|
74
|
+
key={ slug }
|
|
75
|
+
value={ colors }
|
|
76
|
+
isSelected={ isSelected }
|
|
77
|
+
aria-label={ label }
|
|
78
|
+
tooltipText={ tooltipText }
|
|
79
|
+
style={ style }
|
|
80
|
+
onClick={ () => {
|
|
81
|
+
onChange( isSelected ? undefined : colors );
|
|
82
|
+
} }
|
|
83
|
+
/>
|
|
84
|
+
);
|
|
85
|
+
} );
|
|
86
|
+
|
|
35
87
|
return (
|
|
36
88
|
<CircularOptionPicker
|
|
37
|
-
options={
|
|
38
|
-
const style = {
|
|
39
|
-
background: getGradientFromCSSColors( colors, '135deg' ),
|
|
40
|
-
color: 'transparent',
|
|
41
|
-
};
|
|
42
|
-
const tooltipText =
|
|
43
|
-
name ??
|
|
44
|
-
sprintf(
|
|
45
|
-
// translators: %s: duotone code e.g: "dark-grayscale" or "7f7f7f-ffffff".
|
|
46
|
-
__( 'Duotone code: %s' ),
|
|
47
|
-
slug
|
|
48
|
-
);
|
|
49
|
-
const label = name
|
|
50
|
-
? sprintf(
|
|
51
|
-
// translators: %s: The name of the option e.g: "Dark grayscale".
|
|
52
|
-
__( 'Duotone: %s' ),
|
|
53
|
-
name
|
|
54
|
-
)
|
|
55
|
-
: tooltipText;
|
|
56
|
-
const isSelected = isEqual( colors, value );
|
|
57
|
-
|
|
58
|
-
return (
|
|
59
|
-
<CircularOptionPicker.Option
|
|
60
|
-
key={ slug }
|
|
61
|
-
value={ colors }
|
|
62
|
-
isSelected={ isSelected }
|
|
63
|
-
aria-label={ label }
|
|
64
|
-
tooltipText={ tooltipText }
|
|
65
|
-
style={ style }
|
|
66
|
-
onClick={ () => {
|
|
67
|
-
onChange( isSelected ? undefined : colors );
|
|
68
|
-
} }
|
|
69
|
-
/>
|
|
70
|
-
);
|
|
71
|
-
} ) }
|
|
89
|
+
options={ unsetable ? [ unsetOption, ...options ] : options }
|
|
72
90
|
actions={
|
|
73
91
|
!! clearable && (
|
|
74
92
|
<CircularOptionPicker.ButtonAction
|
|
@@ -80,13 +98,16 @@ function DuotonePicker( {
|
|
|
80
98
|
}
|
|
81
99
|
>
|
|
82
100
|
{ ! disableCustomColors && ! disableCustomDuotone && (
|
|
83
|
-
<CustomDuotoneBar
|
|
101
|
+
<CustomDuotoneBar
|
|
102
|
+
value={ isUnset ? undefined : value }
|
|
103
|
+
onChange={ onChange }
|
|
104
|
+
/>
|
|
84
105
|
) }
|
|
85
106
|
{ ! disableCustomDuotone && (
|
|
86
107
|
<ColorListPicker
|
|
87
108
|
labels={ [ __( 'Shadows' ), __( 'Highlights' ) ] }
|
|
88
109
|
colors={ colorPalette }
|
|
89
|
-
value={ value }
|
|
110
|
+
value={ isUnset ? undefined : value }
|
|
90
111
|
disableCustomColors={ disableCustomColors }
|
|
91
112
|
enableAlpha
|
|
92
113
|
onChange={ ( newColors ) => {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
.components-duotone-picker__color-indicator::before {
|
|
2
|
+
background: transparent;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.components-duotone-picker__color-indicator > .components-button {
|
|
6
|
+
// Show a diagonal line (crossed out) for empty swatches.
|
|
7
|
+
background: linear-gradient(-45deg, transparent 48%, $gray-300 48%, $gray-300 52%, transparent 52%);
|
|
8
|
+
color: transparent;
|
|
9
|
+
|
|
10
|
+
&.is-pressed:hover:not(:disabled) {
|
|
11
|
+
// Hover state has to be overridden too.
|
|
12
|
+
background: linear-gradient(-45deg, transparent 48%, $gray-300 48%, $gray-300 52%, transparent 52%);
|
|
13
|
+
color: transparent;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
&:not([aria-disabled="true"]):active {
|
|
17
|
+
color: transparent;
|
|
18
|
+
}
|
|
19
|
+
}
|
package/src/elevation/hook.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { css } from '@emotion/react';
|
|
5
|
-
import { isNil } from 'lodash';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* WordPress dependencies
|
|
@@ -16,6 +15,7 @@ import { useContextSystem } from '../ui/context';
|
|
|
16
15
|
import * as styles from './styles';
|
|
17
16
|
import { CONFIG, reduceMotion } from '../utils';
|
|
18
17
|
import { useCx } from '../utils/hooks/use-cx';
|
|
18
|
+
import { isValueDefined } from '../utils/values';
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* @param {number} value
|
|
@@ -49,13 +49,13 @@ export function useElevation( props ) {
|
|
|
49
49
|
|
|
50
50
|
const classes = useMemo( () => {
|
|
51
51
|
/** @type {number | undefined} */
|
|
52
|
-
let hoverValue =
|
|
52
|
+
let hoverValue = isValueDefined( hover ) ? hover : value * 2;
|
|
53
53
|
/** @type {number | undefined} */
|
|
54
|
-
let activeValue =
|
|
54
|
+
let activeValue = isValueDefined( active ) ? active : value / 2;
|
|
55
55
|
|
|
56
56
|
if ( ! isInteractive ) {
|
|
57
|
-
hoverValue =
|
|
58
|
-
activeValue =
|
|
57
|
+
hoverValue = isValueDefined( hover ) ? hover : undefined;
|
|
58
|
+
activeValue = isValueDefined( active ) ? active : undefined;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
const transition = `box-shadow ${ CONFIG.transitionDuration } ${ CONFIG.transitionTimingFunction }`;
|
|
@@ -76,7 +76,7 @@ export function useElevation( props ) {
|
|
|
76
76
|
reduceMotion( 'transition' )
|
|
77
77
|
);
|
|
78
78
|
|
|
79
|
-
if (
|
|
79
|
+
if ( isValueDefined( hoverValue ) ) {
|
|
80
80
|
sx.hover = css`
|
|
81
81
|
*:hover > & {
|
|
82
82
|
box-shadow: ${ getBoxShadow( hoverValue ) };
|
|
@@ -84,7 +84,7 @@ export function useElevation( props ) {
|
|
|
84
84
|
`;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
if (
|
|
87
|
+
if ( isValueDefined( activeValue ) ) {
|
|
88
88
|
sx.active = css`
|
|
89
89
|
*:active > & {
|
|
90
90
|
box-shadow: ${ getBoxShadow( activeValue ) };
|
|
@@ -92,7 +92,7 @@ export function useElevation( props ) {
|
|
|
92
92
|
`;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
if (
|
|
95
|
+
if ( isValueDefined( focus ) ) {
|
|
96
96
|
sx.focus = css`
|
|
97
97
|
*:focus > & {
|
|
98
98
|
box-shadow: ${ getBoxShadow( focus ) };
|
package/src/flex/flex/README.md
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
# Flex
|
|
2
2
|
|
|
3
|
-
<div class="callout callout-alert">
|
|
4
|
-
This feature is still experimental. “Experimental” means this is an early implementation subject to drastic and breaking changes.
|
|
5
|
-
</div>
|
|
6
|
-
|
|
7
3
|
`Flex` is a primitive layout component that adaptively aligns child content horizontally or vertically. `Flex` powers components like `HStack` and `VStack`.
|
|
8
4
|
|
|
9
5
|
## Usage
|
|
@@ -12,20 +8,19 @@ This feature is still experimental. “Experimental” means this is an early im
|
|
|
12
8
|
|
|
13
9
|
```jsx
|
|
14
10
|
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
__experimentalText as Text,
|
|
11
|
+
Flex,
|
|
12
|
+
FlexBlock,
|
|
13
|
+
FlexItem,
|
|
19
14
|
} from '@wordpress/components';
|
|
20
15
|
|
|
21
16
|
function Example() {
|
|
22
17
|
return (
|
|
23
18
|
<Flex>
|
|
24
19
|
<FlexItem>
|
|
25
|
-
<
|
|
20
|
+
<p>Code</p>
|
|
26
21
|
</FlexItem>
|
|
27
22
|
<FlexBlock>
|
|
28
|
-
<
|
|
23
|
+
<p>Poetry</p>
|
|
29
24
|
</FlexBlock>
|
|
30
25
|
</Flex>
|
|
31
26
|
);
|
|
@@ -8,7 +8,7 @@ A layout component to contain items of a fixed width within `Flex`.
|
|
|
8
8
|
|
|
9
9
|
## Usage
|
|
10
10
|
|
|
11
|
-
See [`flex/README.md#usage`](/packages/components/src/flex/README.md#usage) for how to use `FlexItem`.
|
|
11
|
+
See [`flex/README.md#usage`](/packages/components/src/flex/flex/README.md#usage) for how to use `FlexItem`.
|
|
12
12
|
|
|
13
13
|
## Props
|
|
14
14
|
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { Animated, PanResponder, View } from 'react-native';
|
|
5
5
|
import Video from 'react-native-video';
|
|
6
|
-
import { clamp } from 'lodash';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* WordPress dependencies
|
|
@@ -24,6 +23,7 @@ import FocalPoint from './focal-point';
|
|
|
24
23
|
import Tooltip from './tooltip';
|
|
25
24
|
import styles from './style.scss';
|
|
26
25
|
import { isVideoType } from './utils';
|
|
26
|
+
import { clamp } from '../utils/math';
|
|
27
27
|
|
|
28
28
|
const MIN_POSITION_VALUE = 0;
|
|
29
29
|
const MAX_POSITION_VALUE = 100;
|
|
@@ -60,10 +60,12 @@ import { useState } from '@wordpress/element';
|
|
|
60
60
|
const MyFormToggle = () => {
|
|
61
61
|
const [ isChecked, setChecked ] = useState( true );
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
return (
|
|
64
|
+
<FormToggle
|
|
65
|
+
checked={ isChecked }
|
|
66
|
+
onChange={ () => setChecked( ( state ) => ! state ) }
|
|
67
|
+
/>
|
|
68
|
+
);
|
|
67
69
|
};
|
|
68
70
|
```
|
|
69
71
|
|
|
@@ -71,26 +73,23 @@ const MyFormToggle = () => {
|
|
|
71
73
|
|
|
72
74
|
The component accepts the following props:
|
|
73
75
|
|
|
74
|
-
#### checked
|
|
76
|
+
#### `checked`: `boolean`
|
|
75
77
|
|
|
76
78
|
If checked is true the toggle will be checked. If checked is false the toggle will be unchecked.
|
|
77
79
|
If no value is passed the toggle will be unchecked.
|
|
78
80
|
|
|
79
|
-
- Type: `Boolean`
|
|
80
81
|
- Required: No
|
|
81
82
|
|
|
82
|
-
#### disabled
|
|
83
|
+
#### `disabled`: `boolean`
|
|
83
84
|
|
|
84
85
|
If disabled is true the toggle will be disabled and apply the appropriate styles.
|
|
85
86
|
|
|
86
|
-
- Type: `Boolean`
|
|
87
87
|
- Required: No
|
|
88
88
|
|
|
89
|
-
#### onChange
|
|
89
|
+
#### `onChange`: `( event: ChangeEvent<HTMLInputElement> ) => void`
|
|
90
90
|
|
|
91
|
-
A function
|
|
91
|
+
A callback function invoked when the toggle is clicked.
|
|
92
92
|
|
|
93
|
-
- Type: `function`
|
|
94
93
|
- Required: Yes
|
|
95
94
|
|
|
96
95
|
## Related components
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import type { FormToggleProps } from './types';
|
|
10
|
+
import type { WordPressComponentProps } from '../ui/context';
|
|
11
|
+
|
|
12
|
+
export const noop = () => {};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* FormToggle switches a single setting on or off.
|
|
16
|
+
*
|
|
17
|
+
* ```jsx
|
|
18
|
+
* import { FormToggle } from '@wordpress/components';
|
|
19
|
+
* import { useState } from '@wordpress/element';
|
|
20
|
+
*
|
|
21
|
+
* const MyFormToggle = () => {
|
|
22
|
+
* const [ isChecked, setChecked ] = useState( true );
|
|
23
|
+
*
|
|
24
|
+
* return (
|
|
25
|
+
* <FormToggle
|
|
26
|
+
* checked={ isChecked }
|
|
27
|
+
* onChange={ () => setChecked( ( state ) => ! state ) }
|
|
28
|
+
* />
|
|
29
|
+
* );
|
|
30
|
+
* };
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export function FormToggle(
|
|
34
|
+
// ref is omitted until we have `WordPressComponentPropsWithoutRef` or add
|
|
35
|
+
// ref forwarding to FormToggle.
|
|
36
|
+
props: Omit<
|
|
37
|
+
WordPressComponentProps< FormToggleProps, 'input', false >,
|
|
38
|
+
'ref'
|
|
39
|
+
>
|
|
40
|
+
) {
|
|
41
|
+
const {
|
|
42
|
+
className,
|
|
43
|
+
checked,
|
|
44
|
+
id,
|
|
45
|
+
disabled,
|
|
46
|
+
onChange = noop,
|
|
47
|
+
...additionalProps
|
|
48
|
+
} = props;
|
|
49
|
+
const wrapperClasses = classnames( 'components-form-toggle', className, {
|
|
50
|
+
'is-checked': checked,
|
|
51
|
+
'is-disabled': disabled,
|
|
52
|
+
} );
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<span className={ wrapperClasses }>
|
|
56
|
+
<input
|
|
57
|
+
className="components-form-toggle__input"
|
|
58
|
+
id={ id }
|
|
59
|
+
type="checkbox"
|
|
60
|
+
checked={ checked }
|
|
61
|
+
onChange={ onChange }
|
|
62
|
+
disabled={ disabled }
|
|
63
|
+
{ ...additionalProps }
|
|
64
|
+
/>
|
|
65
|
+
<span className="components-form-toggle__track"></span>
|
|
66
|
+
<span className="components-form-toggle__thumb"></span>
|
|
67
|
+
</span>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export default FormToggle;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { ComponentMeta, ComponentStory } from '@storybook/react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { useState } from '@wordpress/element';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import { FormToggle } from '..';
|
|
15
|
+
|
|
16
|
+
const meta: ComponentMeta< typeof FormToggle > = {
|
|
17
|
+
component: FormToggle,
|
|
18
|
+
title: 'Components/FormToggle',
|
|
19
|
+
argTypes: {
|
|
20
|
+
onChange: {
|
|
21
|
+
action: 'onChange',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
parameters: {
|
|
25
|
+
controls: {
|
|
26
|
+
expanded: true,
|
|
27
|
+
},
|
|
28
|
+
docs: { source: { state: 'open' } },
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
export default meta;
|
|
32
|
+
|
|
33
|
+
const Template: ComponentStory< typeof FormToggle > = ( {
|
|
34
|
+
onChange,
|
|
35
|
+
...args
|
|
36
|
+
} ) => {
|
|
37
|
+
const [ isChecked, setChecked ] = useState( true );
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<FormToggle
|
|
41
|
+
{ ...args }
|
|
42
|
+
checked={ isChecked }
|
|
43
|
+
onChange={ ( e ) => {
|
|
44
|
+
setChecked( ( state ) => ! state );
|
|
45
|
+
onChange( e );
|
|
46
|
+
} }
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const Default: ComponentStory< typeof FormToggle > = Template.bind( {} );
|
|
52
|
+
Default.args = {};
|