@wordpress/components 19.11.0 → 19.12.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 +36 -0
- package/README.md +1 -1
- package/build/alignment-matrix-control/index.js +5 -2
- package/build/alignment-matrix-control/index.js.map +1 -1
- package/build/autocomplete/autocompleter-ui.js +1 -1
- package/build/autocomplete/autocompleter-ui.js.map +1 -1
- package/build/autocomplete/autocompleter-ui.native.js +2 -2
- package/build/autocomplete/autocompleter-ui.native.js.map +1 -1
- package/build/autocomplete/index.js +12 -10
- package/build/autocomplete/index.js.map +1 -1
- package/build/border-box-control/border-box-control/hook.js +2 -2
- package/build/border-box-control/border-box-control/hook.js.map +1 -1
- package/build/border-box-control/border-box-control-split-controls/component.js +2 -0
- package/build/border-box-control/border-box-control-split-controls/component.js.map +1 -1
- package/build/border-box-control/border-box-control-split-controls/hook.js +13 -4
- package/build/border-box-control/border-box-control-split-controls/hook.js.map +1 -1
- package/build/border-box-control/border-box-control-visualizer/hook.js +6 -2
- package/build/border-box-control/border-box-control-visualizer/hook.js.map +1 -1
- package/build/border-box-control/styles.js +21 -11
- package/build/border-box-control/styles.js.map +1 -1
- package/build/border-control/border-control/hook.js +2 -2
- package/build/border-control/border-control/hook.js.map +1 -1
- package/build/color-palette/index.js +9 -2
- package/build/color-palette/index.js.map +1 -1
- package/build/color-palette/index.native.js +4 -1
- package/build/color-palette/index.native.js.map +1 -1
- package/build/color-picker/color-copy-button.js +87 -0
- package/build/color-picker/color-copy-button.js.map +1 -0
- package/build/color-picker/component.js +5 -15
- package/build/color-picker/component.js.map +1 -1
- package/build/color-picker/hex-input.js +18 -1
- package/build/color-picker/hex-input.js.map +1 -1
- package/build/color-picker/styles.js +11 -11
- package/build/color-picker/styles.js.map +1 -1
- package/build/custom-gradient-picker/utils.js +1 -1
- package/build/custom-gradient-picker/utils.js.map +1 -1
- package/build/date-time/{date.js → date/index.js} +51 -12
- package/build/date-time/date/index.js.map +1 -0
- package/build/date-time/date/styles.js +70 -0
- package/build/date-time/date/styles.js.map +1 -0
- package/build/date-time/{utils.js → date/utils.js} +0 -0
- package/build/date-time/date/utils.js.map +1 -0
- package/build/date-time/date-time/index.js +175 -0
- package/build/date-time/date-time/index.js.map +1 -0
- package/build/date-time/date-time/styles.js +32 -0
- package/build/date-time/date-time/styles.js.map +1 -0
- package/build/date-time/index.js +2 -109
- package/build/date-time/index.js.map +1 -1
- package/build/date-time/time/index.js +322 -0
- package/build/date-time/time/index.js.map +1 -0
- package/build/date-time/time/styles.js +139 -0
- package/build/date-time/time/styles.js.map +1 -0
- package/build/date-time/{timezone.js → time/timezone.js} +4 -2
- package/build/date-time/time/timezone.js.map +1 -0
- package/build/draggable/index.native.js +10 -5
- package/build/draggable/index.native.js.map +1 -1
- package/build/dropdown/index.js +4 -1
- package/build/dropdown/index.js.map +1 -1
- package/build/input-control/index.js +9 -4
- package/build/input-control/index.js.map +1 -1
- package/build/input-control/input-field.js +1 -26
- package/build/input-control/input-field.js.map +1 -1
- package/build/input-control/reducer/reducer.js +36 -24
- package/build/input-control/reducer/reducer.js.map +1 -1
- package/build/input-control/reducer/state.js +0 -1
- package/build/input-control/reducer/state.js.map +1 -1
- package/build/input-control/utils.js +45 -0
- package/build/input-control/utils.js.map +1 -1
- package/build/popover/index.js +40 -33
- package/build/popover/index.js.map +1 -1
- package/build/search-control/index.js +4 -6
- package/build/search-control/index.js.map +1 -1
- package/build/select-control/index.js +3 -1
- package/build/select-control/index.js.map +1 -1
- package/build/spacer/hook.js +11 -3
- package/build/spacer/hook.js.map +1 -1
- package/build/surface/component.js +7 -7
- package/build/surface/component.js.map +1 -1
- package/build/surface/hook.js +8 -11
- package/build/surface/hook.js.map +1 -1
- package/build/surface/index.js.map +1 -1
- package/build/surface/styles.js +8 -48
- package/build/surface/styles.js.map +1 -1
- package/build/textarea-control/index.js +40 -6
- package/build/textarea-control/index.js.map +1 -1
- package/build/textarea-control/styles/textarea-control-styles.js +3 -3
- package/build/textarea-control/styles/textarea-control-styles.js.map +1 -1
- package/build/textarea-control/types.js +6 -0
- package/build/textarea-control/types.js.map +1 -0
- package/build/utils/hooks/index.js +0 -8
- package/build/utils/hooks/index.js.map +1 -1
- package/build-module/alignment-matrix-control/index.js +5 -2
- package/build-module/alignment-matrix-control/index.js.map +1 -1
- package/build-module/autocomplete/autocompleter-ui.js +1 -1
- package/build-module/autocomplete/autocompleter-ui.js.map +1 -1
- package/build-module/autocomplete/autocompleter-ui.native.js +2 -2
- package/build-module/autocomplete/autocompleter-ui.native.js.map +1 -1
- package/build-module/autocomplete/index.js +13 -11
- package/build-module/autocomplete/index.js.map +1 -1
- package/build-module/border-box-control/border-box-control/hook.js +2 -2
- package/build-module/border-box-control/border-box-control/hook.js.map +1 -1
- package/build-module/border-box-control/border-box-control-split-controls/component.js +2 -0
- package/build-module/border-box-control/border-box-control-split-controls/component.js.map +1 -1
- package/build-module/border-box-control/border-box-control-split-controls/hook.js +11 -4
- package/build-module/border-box-control/border-box-control-split-controls/hook.js.map +1 -1
- package/build-module/border-box-control/border-box-control-visualizer/hook.js +4 -2
- package/build-module/border-box-control/border-box-control-visualizer/hook.js.map +1 -1
- package/build-module/border-box-control/styles.js +13 -8
- package/build-module/border-box-control/styles.js.map +1 -1
- package/build-module/border-control/border-control/hook.js +2 -2
- package/build-module/border-control/border-control/hook.js.map +1 -1
- package/build-module/color-palette/index.js +7 -5
- package/build-module/color-palette/index.js.map +1 -1
- package/build-module/color-palette/index.native.js +4 -1
- package/build-module/color-palette/index.native.js.map +1 -1
- package/build-module/color-picker/color-copy-button.js +73 -0
- package/build-module/color-picker/color-copy-button.js.map +1 -0
- package/build-module/color-picker/component.js +6 -15
- package/build-module/color-picker/component.js.map +1 -1
- package/build-module/color-picker/hex-input.js +18 -1
- package/build-module/color-picker/hex-input.js.map +1 -1
- package/build-module/color-picker/styles.js +9 -9
- package/build-module/color-picker/styles.js.map +1 -1
- package/build-module/custom-gradient-picker/utils.js +1 -1
- package/build-module/custom-gradient-picker/utils.js.map +1 -1
- package/build-module/date-time/{date.js → date/index.js} +46 -14
- package/build-module/date-time/date/index.js.map +1 -0
- package/build-module/date-time/date/styles.js +61 -0
- package/build-module/date-time/date/styles.js.map +1 -0
- package/build-module/date-time/{utils.js → date/utils.js} +0 -0
- package/build-module/date-time/date/utils.js.map +1 -0
- package/build-module/date-time/date-time/index.js +144 -0
- package/build-module/date-time/date-time/index.js.map +1 -0
- package/build-module/date-time/date-time/styles.js +22 -0
- package/build-module/date-time/date-time/styles.js.map +1 -0
- package/build-module/date-time/index.js +1 -105
- package/build-module/date-time/index.js.map +1 -1
- package/build-module/date-time/time/index.js +302 -0
- package/build-module/date-time/time/index.js.map +1 -0
- package/build-module/date-time/time/styles.js +118 -0
- package/build-module/date-time/time/styles.js.map +1 -0
- package/build-module/date-time/{timezone.js → time/timezone.js} +3 -2
- package/build-module/date-time/time/timezone.js.map +1 -0
- package/build-module/draggable/index.native.js +10 -5
- package/build-module/draggable/index.native.js.map +1 -1
- package/build-module/dropdown/index.js +4 -1
- package/build-module/dropdown/index.js.map +1 -1
- package/build-module/input-control/index.js +8 -4
- package/build-module/input-control/index.js.map +1 -1
- package/build-module/input-control/input-field.js +1 -25
- package/build-module/input-control/input-field.js.map +1 -1
- package/build-module/input-control/reducer/reducer.js +38 -26
- package/build-module/input-control/reducer/reducer.js.map +1 -1
- package/build-module/input-control/reducer/state.js +0 -1
- package/build-module/input-control/reducer/state.js.map +1 -1
- package/build-module/input-control/utils.js +48 -2
- package/build-module/input-control/utils.js.map +1 -1
- package/build-module/popover/index.js +40 -33
- package/build-module/popover/index.js.map +1 -1
- package/build-module/search-control/index.js +6 -7
- package/build-module/search-control/index.js.map +1 -1
- package/build-module/select-control/index.js +3 -1
- package/build-module/select-control/index.js.map +1 -1
- package/build-module/spacer/hook.js +10 -2
- package/build-module/spacer/hook.js.map +1 -1
- package/build-module/surface/component.js +7 -7
- package/build-module/surface/component.js.map +1 -1
- package/build-module/surface/hook.js +8 -11
- package/build-module/surface/hook.js.map +1 -1
- package/build-module/surface/index.js.map +1 -1
- package/build-module/surface/styles.js +8 -48
- package/build-module/surface/styles.js.map +1 -1
- package/build-module/textarea-control/index.js +36 -5
- package/build-module/textarea-control/index.js.map +1 -1
- package/build-module/textarea-control/styles/textarea-control-styles.js +3 -3
- package/build-module/textarea-control/styles/textarea-control-styles.js.map +1 -1
- package/build-module/textarea-control/types.js +2 -0
- package/build-module/textarea-control/types.js.map +1 -0
- package/build-module/utils/hooks/index.js +0 -1
- package/build-module/utils/hooks/index.js.map +1 -1
- package/build-style/style-rtl.css +13 -188
- package/build-style/style.css +13 -191
- package/build-types/border-box-control/border-box-control-split-controls/component.d.ts.map +1 -1
- package/build-types/border-box-control/border-box-control-split-controls/hook.d.ts +1 -0
- package/build-types/border-box-control/border-box-control-split-controls/hook.d.ts.map +1 -1
- package/build-types/border-box-control/border-box-control-visualizer/hook.d.ts.map +1 -1
- package/build-types/border-box-control/styles.d.ts +3 -2
- package/build-types/border-box-control/styles.d.ts.map +1 -1
- package/build-types/border-control/border-control/hook.d.ts.map +1 -1
- package/build-types/card/types.d.ts +1 -1
- package/build-types/card/types.d.ts.map +1 -1
- package/build-types/checkbox-control/test/index.d.ts +2 -0
- package/build-types/checkbox-control/test/index.d.ts.map +1 -0
- package/build-types/color-palette/index.d.ts +1 -0
- package/build-types/color-palette/index.d.ts.map +1 -1
- package/build-types/{date-time → color-palette}/test/utils.d.ts +0 -0
- package/build-types/color-palette/test/utils.d.ts.map +1 -0
- package/build-types/color-picker/color-copy-button.d.ts +4 -0
- package/build-types/color-picker/color-copy-button.d.ts.map +1 -0
- package/build-types/color-picker/component.d.ts.map +1 -1
- package/build-types/color-picker/hex-input.d.ts.map +1 -1
- package/build-types/color-picker/styles.d.ts +1 -1
- package/build-types/color-picker/styles.d.ts.map +1 -1
- package/build-types/color-picker/types.d.ts +8 -0
- package/build-types/color-picker/types.d.ts.map +1 -1
- package/build-types/date-time/{date.d.ts → date/index.d.ts} +3 -2
- package/build-types/date-time/date/index.d.ts.map +1 -0
- package/build-types/date-time/date/styles.d.ts +23 -0
- package/build-types/date-time/date/styles.d.ts.map +1 -0
- package/build-types/date-time/date/test/index.d.ts +2 -0
- package/build-types/date-time/date/test/index.d.ts.map +1 -0
- package/build-types/date-time/date/test/utils.d.ts +2 -0
- package/build-types/date-time/date/test/utils.d.ts.map +1 -0
- package/build-types/date-time/{utils.d.ts → date/utils.d.ts} +0 -0
- package/build-types/date-time/date/utils.d.ts.map +1 -0
- package/build-types/date-time/date-time/index.d.ts +33 -0
- package/build-types/date-time/date-time/index.d.ts.map +1 -0
- package/build-types/date-time/date-time/styles.d.ts +6 -0
- package/build-types/date-time/date-time/styles.d.ts.map +1 -0
- package/build-types/date-time/index.d.ts +2 -28
- package/build-types/date-time/index.d.ts.map +1 -1
- package/build-types/date-time/stories/{index.d.ts → date-time.d.ts} +2 -2
- package/build-types/date-time/stories/date-time.d.ts.map +1 -0
- package/build-types/date-time/{time.d.ts → time/index.d.ts} +2 -2
- package/build-types/date-time/time/index.d.ts.map +1 -0
- package/build-types/date-time/time/styles.d.ts +111 -0
- package/build-types/date-time/time/styles.d.ts.map +1 -0
- package/build-types/date-time/time/test/index.d.ts +2 -0
- package/build-types/date-time/time/test/index.d.ts.map +1 -0
- package/build-types/date-time/{timezone.d.ts → time/timezone.d.ts} +0 -0
- package/build-types/date-time/time/timezone.d.ts.map +1 -0
- package/build-types/date-time/types.d.ts +14 -15
- package/build-types/date-time/types.d.ts.map +1 -1
- package/build-types/dropdown/index.d.ts.map +1 -1
- package/build-types/input-control/index.d.ts.map +1 -1
- package/build-types/input-control/input-field.d.ts.map +1 -1
- package/build-types/input-control/reducer/reducer.d.ts +5 -3
- package/build-types/input-control/reducer/reducer.d.ts.map +1 -1
- package/build-types/input-control/reducer/state.d.ts +2 -2
- package/build-types/input-control/reducer/state.d.ts.map +1 -1
- package/build-types/input-control/utils.d.ts +17 -0
- package/build-types/input-control/utils.d.ts.map +1 -1
- package/build-types/popover/index.d.ts +1 -0
- package/build-types/popover/index.d.ts.map +1 -1
- package/build-types/select-control/index.d.ts.map +1 -1
- package/build-types/select-control/types.d.ts +1 -1
- package/build-types/select-control/types.d.ts.map +1 -1
- package/build-types/surface/component.d.ts +3 -2
- package/build-types/surface/component.d.ts.map +1 -1
- package/build-types/surface/hook.d.ts +4 -4
- package/build-types/surface/hook.d.ts.map +1 -1
- package/build-types/surface/index.d.ts +2 -2
- package/build-types/surface/index.d.ts.map +1 -1
- package/build-types/surface/stories/index.d.ts +12 -0
- package/build-types/surface/stories/index.d.ts.map +1 -0
- package/build-types/surface/styles.d.ts +10 -21
- package/build-types/surface/styles.d.ts.map +1 -1
- package/build-types/surface/test/index.d.ts +2 -0
- package/build-types/surface/test/index.d.ts.map +1 -0
- package/build-types/surface/types.d.ts +1 -1
- package/build-types/surface/types.d.ts.map +1 -1
- package/build-types/textarea-control/index.d.ts +29 -0
- package/build-types/textarea-control/index.d.ts.map +1 -0
- package/build-types/textarea-control/stories/index.d.ts +12 -0
- package/build-types/textarea-control/stories/index.d.ts.map +1 -0
- package/build-types/textarea-control/styles/textarea-control-styles.d.ts +6 -0
- package/build-types/textarea-control/styles/textarea-control-styles.d.ts.map +1 -0
- package/build-types/textarea-control/types.d.ts +26 -0
- package/build-types/textarea-control/types.d.ts.map +1 -0
- package/build-types/utils/hooks/index.d.ts +0 -1
- package/package.json +18 -18
- package/src/alignment-matrix-control/index.js +4 -2
- package/src/autocomplete/autocompleter-ui.js +1 -1
- package/src/autocomplete/autocompleter-ui.native.js +2 -2
- package/src/autocomplete/index.js +21 -9
- package/src/border-box-control/border-box-control/hook.ts +2 -2
- package/src/border-box-control/border-box-control-split-controls/component.tsx +2 -0
- package/src/border-box-control/border-box-control-split-controls/hook.ts +18 -4
- package/src/border-box-control/border-box-control-visualizer/hook.ts +5 -2
- package/src/border-box-control/styles.ts +6 -2
- package/src/border-control/border-control/hook.ts +8 -2
- package/src/box-control/test/index.js +120 -109
- package/src/card/types.ts +1 -1
- package/src/checkbox-control/test/__snapshots__/index.tsx.snap +42 -0
- package/src/checkbox-control/test/index.tsx +109 -0
- package/src/color-palette/index.js +11 -4
- package/src/color-palette/index.native.js +3 -0
- package/src/color-palette/stories/index.js +25 -1
- package/src/color-palette/test/utils.ts +24 -0
- package/src/color-picker/color-copy-button.tsx +76 -0
- package/src/color-picker/component.tsx +18 -38
- package/src/color-picker/hex-input.tsx +16 -0
- package/src/color-picker/styles.ts +5 -1
- package/src/color-picker/types.ts +9 -0
- package/src/custom-gradient-picker/utils.js +1 -1
- package/src/date-time/README.md +16 -0
- package/src/date-time/{datepicker.scss → date/datepicker.scss} +0 -0
- package/src/date-time/{date.tsx → date/index.tsx} +38 -15
- package/src/date-time/date/style.scss +75 -0
- package/src/date-time/date/styles.ts +55 -0
- package/src/date-time/{test/date.tsx → date/test/index.tsx} +1 -1
- package/src/date-time/{test → date/test}/utils.ts +0 -0
- package/src/date-time/{utils.ts → date/utils.ts} +0 -0
- package/src/date-time/date-time/index.tsx +217 -0
- package/src/date-time/date-time/styles.ts +8 -0
- package/src/date-time/index.ts +9 -0
- package/src/date-time/stories/{index.tsx → date-time.tsx} +1 -1
- package/src/date-time/style.scss +1 -262
- package/src/date-time/time/index.tsx +356 -0
- package/src/date-time/time/styles.ts +119 -0
- package/src/date-time/{test/time.tsx → time/test/index.tsx} +85 -38
- package/src/date-time/{timezone.tsx → time/timezone.tsx} +5 -2
- package/src/date-time/types.ts +16 -18
- package/src/draggable/index.native.js +14 -3
- package/src/draggable/test/index.native.js +130 -0
- package/src/dropdown/index.js +5 -1
- package/src/input-control/index.tsx +8 -2
- package/src/input-control/input-field.tsx +10 -30
- package/src/input-control/reducer/reducer.ts +40 -26
- package/src/input-control/reducer/state.ts +2 -3
- package/src/input-control/utils.ts +55 -1
- package/src/popover/index.js +42 -27
- package/src/query-controls/README.md +1 -1
- package/src/search-control/index.js +6 -7
- package/src/select-control/README.md +11 -0
- package/src/select-control/index.tsx +6 -1
- package/src/select-control/types.ts +1 -1
- package/src/slot-fill/README.md +1 -1
- package/src/spacer/hook.ts +13 -13
- package/src/surface/README.md +15 -15
- package/src/surface/{component.js → component.tsx} +13 -7
- package/src/surface/{hook.js → hook.ts} +13 -12
- package/src/surface/{index.js → index.ts} +0 -0
- package/src/surface/stories/index.tsx +40 -0
- package/src/surface/{styles.js → styles.ts} +15 -44
- package/src/surface/test/__snapshots__/{index.js.snap → index.tsx.snap} +0 -0
- package/src/surface/test/{index.js → index.tsx} +2 -1
- package/src/surface/types.ts +1 -1
- package/src/textarea-control/README.md +14 -20
- package/src/textarea-control/index.tsx +86 -0
- package/src/textarea-control/stories/index.tsx +58 -0
- package/src/textarea-control/styles/{textarea-control-styles.js → textarea-control-styles.ts} +0 -0
- package/src/textarea-control/types.ts +30 -0
- package/src/utils/hooks/index.js +0 -1
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/color-picker/color-display.js +0 -184
- package/build/color-picker/color-display.js.map +0 -1
- package/build/date-time/date.js.map +0 -1
- package/build/date-time/time.js +0 -289
- package/build/date-time/time.js.map +0 -1
- package/build/date-time/timezone.js.map +0 -1
- package/build/date-time/utils.js.map +0 -1
- package/build/utils/hooks/use-combined-ref.js +0 -32
- package/build/utils/hooks/use-combined-ref.js.map +0 -1
- package/build-module/color-picker/color-display.js +0 -170
- package/build-module/color-picker/color-display.js.map +0 -1
- package/build-module/date-time/date.js.map +0 -1
- package/build-module/date-time/time.js +0 -271
- package/build-module/date-time/time.js.map +0 -1
- package/build-module/date-time/timezone.js.map +0 -1
- package/build-module/date-time/utils.js.map +0 -1
- package/build-module/utils/hooks/use-combined-ref.js +0 -28
- package/build-module/utils/hooks/use-combined-ref.js.map +0 -1
- package/build-types/color-picker/color-display.d.ts +0 -14
- package/build-types/color-picker/color-display.d.ts.map +0 -1
- package/build-types/date-time/date.d.ts.map +0 -1
- package/build-types/date-time/stories/index.d.ts.map +0 -1
- package/build-types/date-time/test/date.d.ts +0 -2
- package/build-types/date-time/test/date.d.ts.map +0 -1
- package/build-types/date-time/test/time.d.ts +0 -2
- package/build-types/date-time/test/time.d.ts.map +0 -1
- package/build-types/date-time/test/utils.d.ts.map +0 -1
- package/build-types/date-time/time.d.ts.map +0 -1
- package/build-types/date-time/timezone.d.ts.map +0 -1
- package/build-types/date-time/utils.d.ts.map +0 -1
- package/build-types/utils/hooks/use-combined-ref.d.ts +0 -8
- package/build-types/utils/hooks/use-combined-ref.d.ts.map +0 -1
- package/src/color-picker/color-display.tsx +0 -169
- package/src/date-time/index.tsx +0 -196
- package/src/date-time/time.tsx +0 -321
- package/src/surface/stories/index.js +0 -46
- package/src/textarea-control/index.js +0 -45
- package/src/textarea-control/stories/index.js +0 -48
- package/src/utils/hooks/use-combined-ref.ts +0 -28
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/border-box-control/styles.ts"],"names":["css","COLORS","CONFIG","rtl","space","BorderBoxControl","LinkedBorderControl","BorderBoxControlLinkedButton","__next36pxDefaultSize","BorderBoxStyleWithFallback","border","color","gray","style","width","borderWidth","clampedWidth","hasVisibleBorder","borderStyle","
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/border-box-control/styles.ts"],"names":["css","COLORS","CONFIG","rtl","space","BorderBoxControl","LinkedBorderControl","BorderBoxControlLinkedButton","__next36pxDefaultSize","BorderBoxStyleWithFallback","border","color","gray","style","width","borderWidth","clampedWidth","hasVisibleBorder","borderStyle","borderBoxControlVisualizer","borders","top","bottom","borderLeft","left","borderRight","right","borderBoxControlSplitControls","marginRight","marginLeft","CenteredBorderControl","rightBorderControl"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,GAAT,QAAoB,gBAApB;AAEA;AACA;AACA;;AACA,SAASC,MAAT,EAAiBC,MAAjB,EAAyBC,GAAzB,QAAoC,UAApC;AACA,SAASC,KAAT,QAAsB,mBAAtB;AAKA,OAAO,MAAMC,gBAAgB,gBAAG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CAAEI,IAAX;AAD/B,GAAF,CAAH,EARJ,OAWIrB,GAAG,CAAE;AACPsB,IAAAA,WAAW,EAAEhB,0BAA0B,CAAEW,OAAF,aAAEA,OAAF,uBAAEA,OAAO,CAAEM,KAAX;AADhC,GAAF,CAAH,EAXJ;AAeA,CAnBM;AAqBP,OAAO,MAAMC,6BAA6B,GAAG,mBAAM3B,GAAN,8BAGzCG,GAAG,CAAE;AAAEyB,EAAAA,WAAW,EAAExB,KAAK,CAAE,CAAF;AAApB,CAAF,EAA+B;AAAEyB,EAAAA,UAAU,EAAEzB,KAAK,CAAE,CAAF;AAAnB,CAA/B,CAAH,EAHyC,+uGAAtC;AAMP,OAAO,MAAM0B,qBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAA3B;AAKP,OAAO,MAAMC,kBAAkB,GAAG,mBAAM/B,GAAN,CAC9BG,GAAG,CAAE;AAAE0B,EAAAA,UAAU,EAAE;AAAd,CAAF,EAA0B;AAAED,EAAAA,WAAW,EAAE;AAAf,CAA1B,CAAH,EAD8B,ouGAA3B","sourcesContent":["/**\n * External dependencies\n */\nimport { css } from '@emotion/react';\n\n/**\n * Internal dependencies\n */\nimport { COLORS, CONFIG, rtl } from '../utils';\nimport { space } from '../ui/utils/space';\n\nimport type { Border } from '../border-control/types';\nimport type { Borders } from './types';\n\nexport const BorderBoxControl = css``;\n\nexport const LinkedBorderControl = css`\n\tflex: 1;\n`;\n\nexport const BorderBoxControlLinkedButton = (\n\t__next36pxDefaultSize?: boolean\n) => {\n\treturn css`\n\t\tflex: 0;\n\t\tflex-basis: 36px;\n\t\tmargin-top: ${ __next36pxDefaultSize ? '6px' : '3px' };\n\t`;\n};\n\nconst BorderBoxStyleWithFallback = ( border?: Border ) => {\n\tconst {\n\t\tcolor = COLORS.gray[ 200 ],\n\t\tstyle = 'solid',\n\t\twidth = CONFIG.borderWidth,\n\t} = border || {};\n\n\tconst clampedWidth =\n\t\twidth !== CONFIG.borderWidth ? `clamp(1px, ${ width }, 10px)` : width;\n\tconst hasVisibleBorder = ( !! width && width !== '0' ) || !! color;\n\tconst borderStyle = hasVisibleBorder ? style || 'solid' : style;\n\n\treturn `${ color } ${ borderStyle } ${ clampedWidth }`;\n};\n\nexport const borderBoxControlVisualizer = (\n\tborders?: Borders,\n\t__next36pxDefaultSize?: boolean\n) => {\n\treturn css`\n\t\tposition: absolute;\n\t\ttop: ${ __next36pxDefaultSize ? '18px' : '15px' };\n\t\tright: 30px;\n\t\tbottom: ${ __next36pxDefaultSize ? '18px' : '15px' };\n\t\tleft: 30px;\n\t\tborder-top: ${ BorderBoxStyleWithFallback( borders?.top ) };\n\t\tborder-bottom: ${ BorderBoxStyleWithFallback( borders?.bottom ) };\n\t\t${ rtl( {\n\t\t\tborderLeft: BorderBoxStyleWithFallback( borders?.left ),\n\t\t} )() }\n\t\t${ rtl( {\n\t\t\tborderRight: BorderBoxStyleWithFallback( borders?.right ),\n\t\t} )() }\n\t`;\n};\n\nexport const borderBoxControlSplitControls = () => css`\n\tposition: relative;\n\tflex: 1;\n\t${ rtl( { marginRight: space( 3 ) }, { marginLeft: space( 3 ) } )() }\n`;\n\nexport const CenteredBorderControl = css`\n\tgrid-column: span 2;\n\tmargin: 0 auto;\n`;\n\nexport const rightBorderControl = () => css`\n\t${ rtl( { marginLeft: 'auto' }, { marginRight: 'auto' } )() }\n`;\n"]}
|
|
@@ -44,7 +44,7 @@ export function useBorderControl(props) {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
onChange(newBorder);
|
|
47
|
-
}, [onChange, shouldSanitizeBorder
|
|
47
|
+
}, [onChange, shouldSanitizeBorder]);
|
|
48
48
|
const onWidthChange = useCallback(newWidth => {
|
|
49
49
|
const newWidthValue = newWidth === '' ? undefined : newWidth;
|
|
50
50
|
const [parsedValue] = parseQuantityAndUnitFromRawValue(newWidth);
|
|
@@ -79,7 +79,7 @@ export function useBorderControl(props) {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
onBorderChange(updatedBorder);
|
|
82
|
-
}, [border, hadPreviousZeroWidth, onBorderChange]);
|
|
82
|
+
}, [border, hadPreviousZeroWidth, colorSelection, styleSelection, onBorderChange]);
|
|
83
83
|
const onSliderChange = useCallback(value => {
|
|
84
84
|
onWidthChange(`${value}${widthUnit}`);
|
|
85
85
|
}, [onWidthChange, widthUnit]); // Generate class names.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/border-control/border-control/hook.ts"],"names":["useCallback","useMemo","useState","styles","parseQuantityAndUnitFromRawValue","useContextSystem","useCx","sanitizeBorder","border","hasNoWidth","width","undefined","hasNoColor","color","useBorderControl","props","className","isCompact","onChange","shouldSanitizeBorder","value","__next36pxDefaultSize","otherProps","widthValue","originalWidthUnit","widthUnit","hadPreviousZeroWidth","colorSelection","setColorSelection","styleSelection","setStyleSelection","onBorderChange","newBorder","onWidthChange","newWidth","newWidthValue","parsedValue","hasZeroWidth","updatedBorder","style","onSliderChange","cx","classes","borderControl","innerWrapperClassName","wrapperWidth","widthStyle","heightStyle","wrapperHeight","innerWrapper","widthControlClassName","borderWidthControl","sliderClassName","borderSlider","previousStyleSelection"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,EAAsBC,OAAtB,EAA+BC,QAA/B,QAA+C,oBAA/C;AAEA;AACA;AACA;;AACA,OAAO,KAAKC,MAAZ,MAAwB,WAAxB;AACA,SAASC,gCAAT,QAAiD,0BAAjD;AACA,SAASC,gBAAT,QAA0D,kBAA1D;AACA,SAASC,KAAT,QAAsB,0BAAtB;;AAIA,MAAMC,cAAc,GAAKC,MAAF,IAAuB;AAC7C,QAAMC,UAAU,GAAG,CAAAD,MAAM,SAAN,IAAAA,MAAM,WAAN,YAAAA,MAAM,CAAEE,KAAR,MAAkBC,SAAlB,IAA+BH,MAAM,CAACE,KAAP,KAAiB,EAAnE;AACA,QAAME,UAAU,GAAG,CAAAJ,MAAM,SAAN,IAAAA,MAAM,WAAN,YAAAA,MAAM,CAAEK,KAAR,MAAkBF,SAArC,CAF6C,CAI7C;;AACA,MAAKF,UAAU,IAAIG,UAAnB,EAAgC;AAC/B,WAAOD,SAAP;AACA;;AAED,SAAOH,MAAP;AACA,CAVD;;AAYA,OAAO,SAASM,gBAAT,CACNC,KADM,EAEL;AACD,QAAM;AACLC,IAAAA,SADK;AAELC,IAAAA,SAFK;AAGLC,IAAAA,QAHK;AAILC,IAAAA,oBAAoB,GAAG,IAJlB;AAKLC,IAAAA,KAAK,EAAEZ,MALF;AAMLE,IAAAA,KANK;AAOLW,IAAAA,qBAAqB,GAAG,KAPnB;AAQL,OAAGC;AARE,MASFjB,gBAAgB,CAAEU,KAAF,EAAS,eAAT,CATpB;AAWA,QAAM,CAAEQ,UAAF,EAAcC,iBAAd,IAAoCpB,gCAAgC,CACzEI,MADyE,aACzEA,MADyE,uBACzEA,MAAM,CAAEE,KADiE,CAA1E;AAGA,QAAMe,SAAS,GAAGD,iBAAiB,IAAI,IAAvC;AACA,QAAME,oBAAoB,GAAGH,UAAU,KAAK,CAA5C;AAEA,QAAM,CAAEI,cAAF,EAAkBC,iBAAlB,IAAwC1B,QAAQ,EAAtD;AACA,QAAM,CAAE2B,cAAF,EAAkBC,iBAAlB,IAAwC5B,QAAQ,EAAtD;AAEA,QAAM6B,cAAc,GAAG/B,WAAW,CAC/BgC,SAAF,IAA0B;AACzB,QAAKb,oBAAL,EAA4B;AAC3B,aAAOD,QAAQ,CAAEX,cAAc,CAAEyB,SAAF,CAAhB,CAAf;AACA;;AAEDd,IAAAA,QAAQ,CAAEc,SAAF,CAAR;AACA,GAPgC,EAQjC,CAAEd,QAAF,EAAYC,oBAAZ,
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/border-control/border-control/hook.ts"],"names":["useCallback","useMemo","useState","styles","parseQuantityAndUnitFromRawValue","useContextSystem","useCx","sanitizeBorder","border","hasNoWidth","width","undefined","hasNoColor","color","useBorderControl","props","className","isCompact","onChange","shouldSanitizeBorder","value","__next36pxDefaultSize","otherProps","widthValue","originalWidthUnit","widthUnit","hadPreviousZeroWidth","colorSelection","setColorSelection","styleSelection","setStyleSelection","onBorderChange","newBorder","onWidthChange","newWidth","newWidthValue","parsedValue","hasZeroWidth","updatedBorder","style","onSliderChange","cx","classes","borderControl","innerWrapperClassName","wrapperWidth","widthStyle","heightStyle","wrapperHeight","innerWrapper","widthControlClassName","borderWidthControl","sliderClassName","borderSlider","previousStyleSelection"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,EAAsBC,OAAtB,EAA+BC,QAA/B,QAA+C,oBAA/C;AAEA;AACA;AACA;;AACA,OAAO,KAAKC,MAAZ,MAAwB,WAAxB;AACA,SAASC,gCAAT,QAAiD,0BAAjD;AACA,SAASC,gBAAT,QAA0D,kBAA1D;AACA,SAASC,KAAT,QAAsB,0BAAtB;;AAIA,MAAMC,cAAc,GAAKC,MAAF,IAAuB;AAC7C,QAAMC,UAAU,GAAG,CAAAD,MAAM,SAAN,IAAAA,MAAM,WAAN,YAAAA,MAAM,CAAEE,KAAR,MAAkBC,SAAlB,IAA+BH,MAAM,CAACE,KAAP,KAAiB,EAAnE;AACA,QAAME,UAAU,GAAG,CAAAJ,MAAM,SAAN,IAAAA,MAAM,WAAN,YAAAA,MAAM,CAAEK,KAAR,MAAkBF,SAArC,CAF6C,CAI7C;;AACA,MAAKF,UAAU,IAAIG,UAAnB,EAAgC;AAC/B,WAAOD,SAAP;AACA;;AAED,SAAOH,MAAP;AACA,CAVD;;AAYA,OAAO,SAASM,gBAAT,CACNC,KADM,EAEL;AACD,QAAM;AACLC,IAAAA,SADK;AAELC,IAAAA,SAFK;AAGLC,IAAAA,QAHK;AAILC,IAAAA,oBAAoB,GAAG,IAJlB;AAKLC,IAAAA,KAAK,EAAEZ,MALF;AAMLE,IAAAA,KANK;AAOLW,IAAAA,qBAAqB,GAAG,KAPnB;AAQL,OAAGC;AARE,MASFjB,gBAAgB,CAAEU,KAAF,EAAS,eAAT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CAAEtC,MAAM,CAAC8C,YAAP,EAAF,EAAyBH,UAAzB,EAAqCC,WAArC,CAAT;AACA,GAPoC,EAOlC,CAAE9B,SAAF,EAAaP,KAAb,EAAoB+B,EAApB,EAAwBpB,qBAAxB,CAPkC,CAArC;AASA,QAAM6B,qBAAqB,GAAGjD,OAAO,CAAE,MAAM;AAC5C,WAAOwC,EAAE,CAAEtC,MAAM,CAACgD,kBAAP,EAAF,CAAT;AACA,GAFoC,EAElC,CAAEV,EAAF,CAFkC,CAArC;AAIA,QAAMW,eAAe,GAAGnD,OAAO,CAAE,MAAM;AACtC,WAAOwC,EAAE,CAAEtC,MAAM,CAACkD,YAAP,EAAF,CAAT;AACA,GAF8B,EAE5B,CAAEZ,EAAF,CAF4B,CAA/B;AAIA,SAAO,EACN,GAAGnB,UADG;AAENN,IAAAA,SAAS,EAAE0B,OAFL;AAGNE,IAAAA,qBAHM;AAINb,IAAAA,cAJM;AAKNS,IAAAA,cALM;AAMNP,IAAAA,aANM;AAONqB,IAAAA,sBAAsB,EAAEzB,cAPlB;AAQNuB,IAAAA,eARM;AASNhC,IAAAA,KAAK,EAAEZ,MATD;AAUN0C,IAAAA,qBAVM;AAWNzB,IAAAA,SAXM;AAYNF,IAAAA,UAZM;AAaNF,IAAAA;AAbM,GAAP;AAeA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport * as styles from '../styles';\nimport { parseQuantityAndUnitFromRawValue } from '../../unit-control/utils';\nimport { useContextSystem, WordPressComponentProps } from '../../ui/context';\nimport { useCx } from '../../utils/hooks/use-cx';\n\nimport type { Border, BorderControlProps } from '../types';\n\nconst sanitizeBorder = ( border?: Border ) => {\n\tconst hasNoWidth = border?.width === undefined || border.width === '';\n\tconst hasNoColor = border?.color === undefined;\n\n\t// If width and color are undefined, unset any style selection as well.\n\tif ( hasNoWidth && hasNoColor ) {\n\t\treturn undefined;\n\t}\n\n\treturn border;\n};\n\nexport function useBorderControl(\n\tprops: WordPressComponentProps< BorderControlProps, 'div' >\n) {\n\tconst {\n\t\tclassName,\n\t\tisCompact,\n\t\tonChange,\n\t\tshouldSanitizeBorder = true,\n\t\tvalue: border,\n\t\twidth,\n\t\t__next36pxDefaultSize = false,\n\t\t...otherProps\n\t} = useContextSystem( props, 'BorderControl' );\n\n\tconst [ widthValue, originalWidthUnit ] = parseQuantityAndUnitFromRawValue(\n\t\tborder?.width\n\t);\n\tconst widthUnit = originalWidthUnit || 'px';\n\tconst hadPreviousZeroWidth = widthValue === 0;\n\n\tconst [ colorSelection, setColorSelection ] = useState< string >();\n\tconst [ styleSelection, setStyleSelection ] = useState< string >();\n\n\tconst onBorderChange = useCallback(\n\t\t( newBorder?: Border ) => {\n\t\t\tif ( shouldSanitizeBorder ) {\n\t\t\t\treturn onChange( sanitizeBorder( newBorder ) );\n\t\t\t}\n\n\t\t\tonChange( newBorder );\n\t\t},\n\t\t[ onChange, shouldSanitizeBorder ]\n\t);\n\n\tconst onWidthChange = useCallback(\n\t\t( newWidth?: string ) => {\n\t\t\tconst newWidthValue = newWidth === '' ? undefined : newWidth;\n\t\t\tconst [ parsedValue ] = parseQuantityAndUnitFromRawValue(\n\t\t\t\tnewWidth\n\t\t\t);\n\t\t\tconst hasZeroWidth = parsedValue === 0;\n\n\t\t\tconst updatedBorder = { ...border, width: newWidthValue };\n\n\t\t\t// Setting the border width explicitly to zero will also set the\n\t\t\t// border style to `none` and clear the border color.\n\t\t\tif ( hasZeroWidth && ! hadPreviousZeroWidth ) {\n\t\t\t\t// Before clearing the color and style selections, keep track of\n\t\t\t\t// the current selections so they can be restored when the width\n\t\t\t\t// changes to a non-zero value.\n\t\t\t\tsetColorSelection( border?.color );\n\t\t\t\tsetStyleSelection( border?.style );\n\n\t\t\t\t// Clear the color and style border properties.\n\t\t\t\tupdatedBorder.color = undefined;\n\t\t\t\tupdatedBorder.style = 'none';\n\t\t\t}\n\n\t\t\t// Selection has changed from zero border width to non-zero width.\n\t\t\tif ( ! hasZeroWidth && hadPreviousZeroWidth ) {\n\t\t\t\t// Restore previous border color and style selections if width\n\t\t\t\t// is now not zero.\n\t\t\t\tif ( updatedBorder.color === undefined ) {\n\t\t\t\t\tupdatedBorder.color = colorSelection;\n\t\t\t\t}\n\t\t\t\tif ( updatedBorder.style === 'none' ) {\n\t\t\t\t\tupdatedBorder.style = styleSelection;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tonBorderChange( updatedBorder );\n\t\t},\n\t\t[\n\t\t\tborder,\n\t\t\thadPreviousZeroWidth,\n\t\t\tcolorSelection,\n\t\t\tstyleSelection,\n\t\t\tonBorderChange,\n\t\t]\n\t);\n\n\tconst onSliderChange = useCallback(\n\t\t( value: string ) => {\n\t\t\tonWidthChange( `${ value }${ widthUnit }` );\n\t\t},\n\t\t[ onWidthChange, widthUnit ]\n\t);\n\n\t// Generate class names.\n\tconst cx = useCx();\n\tconst classes = useMemo( () => {\n\t\treturn cx( styles.borderControl, className );\n\t}, [ className, cx ] );\n\n\tconst innerWrapperClassName = useMemo( () => {\n\t\tconst wrapperWidth = isCompact ? '90px' : width;\n\t\tconst widthStyle =\n\t\t\t!! wrapperWidth && styles.wrapperWidth( wrapperWidth );\n\t\tconst heightStyle = styles.wrapperHeight( __next36pxDefaultSize );\n\n\t\treturn cx( styles.innerWrapper(), widthStyle, heightStyle );\n\t}, [ isCompact, width, cx, __next36pxDefaultSize ] );\n\n\tconst widthControlClassName = useMemo( () => {\n\t\treturn cx( styles.borderWidthControl() );\n\t}, [ cx ] );\n\n\tconst sliderClassName = useMemo( () => {\n\t\treturn cx( styles.borderSlider() );\n\t}, [ cx ] );\n\n\treturn {\n\t\t...otherProps,\n\t\tclassName: classes,\n\t\tinnerWrapperClassName,\n\t\tonBorderChange,\n\t\tonSliderChange,\n\t\tonWidthChange,\n\t\tpreviousStyleSelection: styleSelection,\n\t\tsliderClassName,\n\t\tvalue: border,\n\t\twidthControlClassName,\n\t\twidthUnit,\n\t\twidthValue,\n\t\t__next36pxDefaultSize,\n\t};\n}\n"]}
|
|
@@ -113,15 +113,16 @@ export function CustomColorPickerDropdown(_ref5) {
|
|
|
113
113
|
} : undefined
|
|
114
114
|
}, props));
|
|
115
115
|
}
|
|
116
|
-
|
|
117
|
-
const extractColorNameFromCurrentValue = function (currentValue) {
|
|
116
|
+
export const extractColorNameFromCurrentValue = function (currentValue) {
|
|
118
117
|
let colors = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
119
118
|
let showMultiplePalettes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
120
119
|
|
|
121
120
|
if (!currentValue) {
|
|
122
121
|
return '';
|
|
123
|
-
}
|
|
122
|
+
}
|
|
124
123
|
|
|
124
|
+
const currentValueIsCssVariable = /^var\(/.test(currentValue);
|
|
125
|
+
const normalizedCurrentValue = currentValueIsCssVariable ? currentValue : colord(currentValue).toHex(); // Normalize format of `colors` to simplify the following loop
|
|
125
126
|
|
|
126
127
|
const colorPalettes = showMultiplePalettes ? colors : [{
|
|
127
128
|
colors
|
|
@@ -134,7 +135,9 @@ const extractColorNameFromCurrentValue = function (currentValue) {
|
|
|
134
135
|
name: colorName,
|
|
135
136
|
color: colorValue
|
|
136
137
|
} of paletteColors) {
|
|
137
|
-
|
|
138
|
+
const normalizedColorValue = currentValueIsCssVariable ? colorValue : colord(colorValue).toHex();
|
|
139
|
+
|
|
140
|
+
if (normalizedCurrentValue === normalizedColorValue) {
|
|
138
141
|
return colorName;
|
|
139
142
|
}
|
|
140
143
|
}
|
|
@@ -143,7 +146,6 @@ const extractColorNameFromCurrentValue = function (currentValue) {
|
|
|
143
146
|
|
|
144
147
|
return __('Custom');
|
|
145
148
|
};
|
|
146
|
-
|
|
147
149
|
export default function ColorPalette(_ref6) {
|
|
148
150
|
let {
|
|
149
151
|
clearable = true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/color-palette/index.js"],"names":["map","colord","extend","namesPlugin","a11yPlugin","__","sprintf","useCallback","useMemo","Dropdown","ColorPicker","CircularOptionPicker","VStack","Flex","FlexItem","Truncate","ColorHeading","SinglePalette","className","clearColor","colors","onChange","value","actions","colorOptions","color","name","colordColor","fill","contrast","backgroundColor","MultiplePalettes","index","colorPalette","length","CustomColorPickerDropdown","isRenderedInSidebar","props","placement","offset","undefined","extractColorNameFromCurrentValue","currentValue","showMultiplePalettes","colorPalettes","paletteColors","colorName","colorValue","toHex","ColorPalette","clearable","disableCustomColors","enableAlpha","__experimentalHasMultipleOrigins","__experimentalIsRenderedInSidebar","Component","renderCustomColorPicker","valueWithoutLeadingHash","startsWith","substring","buttonLabelName","customColorAccessibleLabel","isOpen","onToggle","background"],"mappings":";;AAAA;;AACA;AACA;AACA;AACA,SAASA,GAAT,QAAoB,QAApB;AACA,SAASC,MAAT,EAAiBC,MAAjB,QAA+B,QAA/B;AACA,OAAOC,WAAP,MAAwB,sBAAxB;AACA,OAAOC,UAAP,MAAuB,qBAAvB;AAEA;AACA;AACA;;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,WAAT,EAAsBC,OAAtB,QAAqC,oBAArC;AAEA;AACA;AACA;;AACA,OAAOC,QAAP,MAAqB,aAArB;AACA,SAASC,WAAT,QAA4B,iBAA5B;AACA,OAAOC,oBAAP,MAAiC,2BAAjC;AACA,SAASC,MAAT,QAAuB,YAAvB;AACA,SAASC,IAAT,EAAeC,QAAf,QAA+B,SAA/B;AACA,SAASC,QAAT,QAAyB,aAAzB;AACA,SAASC,YAAT,QAA6B,UAA7B;AAEAd,MAAM,CAAE,CAAEC,WAAF,EAAeC,UAAf,CAAF,CAAN;;AAEA,SAASa,aAAT,OAOI;AAAA,MAPoB;AACvBC,IAAAA,SADuB;AAEvBC,IAAAA,UAFuB;AAGvBC,IAAAA,MAHuB;AAIvBC,IAAAA,QAJuB;AAKvBC,IAAAA,KALuB;AAMvBC,IAAAA;AANuB,GAOpB;A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EAAGC,QAPX;AAQC,sBAAaF,0BARd;AASC,QAAA,KAAK,EAAG;AACPG,UAAAA,UAAU,EAAE1C,KADL;AAEPG,UAAAA,KAAK,EACJE,WAAW,CAACE,QAAZ,KACAF,WAAW,CAACE,QAAZ,CAAsB,MAAtB,CADA,GAEG,MAFH,GAGG;AANG;AATT,SAkBC,cAAC,QAAD;AACC,QAAA,OAAO,MADR;AAEC,QAAA,EAAE,EAAGd,QAFN;AAGC,QAAA,SAAS,EAAC;AAHX,SAKG6C,eALH,CAlBD,EAyBC,cAAC,QAAD;AACC,QAAA,EAAE,EAAC,MADJ;AAEC,QAAA,SAAS,EAAC;AAFX,SAIGH,uBAJH,CAzBD,CADc;AAAA;AAHhB,IAFF,EAyCC,cAAC,SAAD;AACC,IAAA,SAAS,EAAGP,SADb;AAEC,IAAA,UAAU,EAAG/B,UAFd;AAGC,IAAA,MAAM,EAAGC,MAHV;AAIC,IAAA,QAAQ,EAAGC,QAJZ;AAKC,IAAA,KAAK,EAAGC,KALT;AAMC,IAAA,OAAO,EACN,CAAC,CAAE4B,SAAH,IACC,cAAC,oBAAD,CAAsB,YAAtB;AACC,MAAA,OAAO,EAAG/B;AADX,OAGGd,EAAE,CAAE,OAAF,CAHL;AARH,IAzCD,CADD;AA4DA","sourcesContent":["// @ts-nocheck\n/**\n * External dependencies\n */\nimport { map } from 'lodash';\nimport { colord, extend } from 'colord';\nimport namesPlugin from 'colord/plugins/names';\nimport a11yPlugin from 'colord/plugins/a11y';\n\n/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useCallback, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport Dropdown from '../dropdown';\nimport { ColorPicker } from '../color-picker';\nimport CircularOptionPicker from '../circular-option-picker';\nimport { VStack } from '../v-stack';\nimport { Flex, FlexItem } from '../flex';\nimport { Truncate } from '../truncate';\nimport { ColorHeading } from './styles';\n\nextend( [ namesPlugin, a11yPlugin ] );\n\nfunction SinglePalette( {\n\tclassName,\n\tclearColor,\n\tcolors,\n\tonChange,\n\tvalue,\n\tactions,\n} ) {\n\tconst colorOptions = useMemo( () => {\n\t\treturn map( colors, ( { color, name } ) => {\n\t\t\tconst colordColor = colord( color );\n\n\t\t\treturn (\n\t\t\t\t<CircularOptionPicker.Option\n\t\t\t\t\tkey={ color }\n\t\t\t\t\tisSelected={ value === color }\n\t\t\t\t\tselectedIconProps={\n\t\t\t\t\t\tvalue === color\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tfill:\n\t\t\t\t\t\t\t\t\t\tcolordColor.contrast() >\n\t\t\t\t\t\t\t\t\t\tcolordColor.contrast( '#000' )\n\t\t\t\t\t\t\t\t\t\t\t? '#fff'\n\t\t\t\t\t\t\t\t\t\t\t: '#000',\n\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t: {}\n\t\t\t\t\t}\n\t\t\t\t\ttooltipText={\n\t\t\t\t\t\tname ||\n\t\t\t\t\t\t// translators: %s: color hex code e.g: \"#f00\".\n\t\t\t\t\t\tsprintf( __( 'Color code: %s' ), color )\n\t\t\t\t\t}\n\t\t\t\t\tstyle={ { backgroundColor: color, color } }\n\t\t\t\t\tonClick={\n\t\t\t\t\t\tvalue === color ? clearColor : () => onChange( color )\n\t\t\t\t\t}\n\t\t\t\t\taria-label={\n\t\t\t\t\t\tname\n\t\t\t\t\t\t\t? // translators: %s: The name of the color e.g: \"vivid red\".\n\t\t\t\t\t\t\t sprintf( __( 'Color: %s' ), name )\n\t\t\t\t\t\t\t: // translators: %s: color hex code e.g: \"#f00\".\n\t\t\t\t\t\t\t sprintf( __( 'Color code: %s' ), color )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t);\n\t\t} );\n\t}, [ colors, value, onChange, clearColor ] );\n\treturn (\n\t\t<CircularOptionPicker\n\t\t\tclassName={ className }\n\t\t\toptions={ colorOptions }\n\t\t\tactions={ actions }\n\t\t/>\n\t);\n}\n\nfunction MultiplePalettes( {\n\tclassName,\n\tclearColor,\n\tcolors,\n\tonChange,\n\tvalue,\n\tactions,\n} ) {\n\treturn (\n\t\t<VStack spacing={ 3 } className={ className }>\n\t\t\t{ colors.map( ( { name, colors: colorPalette }, index ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<VStack spacing={ 2 } key={ index }>\n\t\t\t\t\t\t<ColorHeading>{ name }</ColorHeading>\n\t\t\t\t\t\t<SinglePalette\n\t\t\t\t\t\t\tclearColor={ clearColor }\n\t\t\t\t\t\t\tcolors={ colorPalette }\n\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t\t\tactions={\n\t\t\t\t\t\t\t\tcolors.length === index + 1 ? actions : null\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</VStack>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</VStack>\n\t);\n}\n\nexport function CustomColorPickerDropdown( { isRenderedInSidebar, ...props } ) {\n\treturn (\n\t\t<Dropdown\n\t\t\tcontentClassName=\"components-color-palette__custom-color-dropdown-content\"\n\t\t\tpopoverProps={\n\t\t\t\tisRenderedInSidebar\n\t\t\t\t\t? { placement: 'left-start', offset: 20 }\n\t\t\t\t\t: undefined\n\t\t\t}\n\t\t\t{ ...props }\n\t\t/>\n\t);\n}\n\nconst extractColorNameFromCurrentValue = (\n\tcurrentValue,\n\tcolors = [],\n\tshowMultiplePalettes = false\n) => {\n\tif ( ! currentValue ) {\n\t\treturn '';\n\t}\n\n\t// Normalize format of `colors` to simplify the following loop\n\tconst colorPalettes = showMultiplePalettes ? colors : [ { colors } ];\n\tfor ( const { colors: paletteColors } of colorPalettes ) {\n\t\tfor ( const { name: colorName, color: colorValue } of paletteColors ) {\n\t\t\tif (\n\t\t\t\tcolord( currentValue ).toHex() === colord( colorValue ).toHex()\n\t\t\t) {\n\t\t\t\treturn colorName;\n\t\t\t}\n\t\t}\n\t}\n\n\t// translators: shown when the user has picked a custom color (i.e not in the palette of colors).\n\treturn __( 'Custom' );\n};\n\nexport default function ColorPalette( {\n\tclearable = true,\n\tclassName,\n\tcolors,\n\tdisableCustomColors = false,\n\tenableAlpha,\n\tonChange,\n\tvalue,\n\t__experimentalHasMultipleOrigins = false,\n\t__experimentalIsRenderedInSidebar = false,\n} ) {\n\tconst clearColor = useCallback( () => onChange( undefined ), [ onChange ] );\n\tconst showMultiplePalettes =\n\t\t__experimentalHasMultipleOrigins && colors?.length;\n\tconst Component = showMultiplePalettes ? MultiplePalettes : SinglePalette;\n\n\tconst renderCustomColorPicker = () => (\n\t\t<ColorPicker\n\t\t\tcolor={ value }\n\t\t\tonChange={ ( color ) => onChange( color ) }\n\t\t\tenableAlpha={ enableAlpha }\n\t\t/>\n\t);\n\n\tconst colordColor = colord( value );\n\n\tconst valueWithoutLeadingHash = value?.startsWith( '#' )\n\t\t? value.substring( 1 )\n\t\t: value ?? '';\n\tconst buttonLabelName = useMemo(\n\t\t() =>\n\t\t\textractColorNameFromCurrentValue(\n\t\t\t\tvalue,\n\t\t\t\tcolors,\n\t\t\t\tshowMultiplePalettes\n\t\t\t),\n\t\t[ value, colors, showMultiplePalettes ]\n\t);\n\n\tconst customColorAccessibleLabel = !! valueWithoutLeadingHash\n\t\t? sprintf(\n\t\t\t\t// translators: %1$s: The name of the color e.g: \"vivid red\". %2$s: The color's hex code e.g: \"#f00\".\n\t\t\t\t__(\n\t\t\t\t\t'Custom color picker. The currently selected color is called \"%1$s\" and has a value of \"%2$s\".'\n\t\t\t\t),\n\t\t\t\tbuttonLabelName,\n\t\t\t\tvalueWithoutLeadingHash\n\t\t )\n\t\t: __( 'Custom color picker.' );\n\n\treturn (\n\t\t<VStack spacing={ 3 } className={ className }>\n\t\t\t{ ! disableCustomColors && (\n\t\t\t\t<CustomColorPickerDropdown\n\t\t\t\t\tisRenderedInSidebar={ __experimentalIsRenderedInSidebar }\n\t\t\t\t\trenderContent={ renderCustomColorPicker }\n\t\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t\t\t<Flex\n\t\t\t\t\t\t\tas={ 'button' }\n\t\t\t\t\t\t\tjustify=\"space-between\"\n\t\t\t\t\t\t\talign=\"flex-start\"\n\t\t\t\t\t\t\tclassName=\"components-color-palette__custom-color\"\n\t\t\t\t\t\t\taria-expanded={ isOpen }\n\t\t\t\t\t\t\taria-haspopup=\"true\"\n\t\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t\t\taria-label={ customColorAccessibleLabel }\n\t\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\t\tbackground: value,\n\t\t\t\t\t\t\t\tcolor:\n\t\t\t\t\t\t\t\t\tcolordColor.contrast() >\n\t\t\t\t\t\t\t\t\tcolordColor.contrast( '#000' )\n\t\t\t\t\t\t\t\t\t\t? '#fff'\n\t\t\t\t\t\t\t\t\t\t: '#000',\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<FlexItem\n\t\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\t\tas={ Truncate }\n\t\t\t\t\t\t\t\tclassName=\"components-color-palette__custom-color-name\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ buttonLabelName }\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t\t<FlexItem\n\t\t\t\t\t\t\t\tas=\"span\"\n\t\t\t\t\t\t\t\tclassName=\"components-color-palette__custom-color-value\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ valueWithoutLeadingHash }\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t</Flex>\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t<Component\n\t\t\t\tclearable={ clearable }\n\t\t\t\tclearColor={ clearColor }\n\t\t\t\tcolors={ colors }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tvalue={ value }\n\t\t\t\tactions={\n\t\t\t\t\t!! clearable && (\n\t\t\t\t\t\t<CircularOptionPicker.ButtonAction\n\t\t\t\t\t\t\tonClick={ clearColor }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Clear' ) }\n\t\t\t\t\t\t</CircularOptionPicker.ButtonAction>\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t/>\n\t\t</VStack>\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/color-palette/index.js"],"names":["map","colord","extend","namesPlugin","a11yPlugin","__","sprintf","useCallback","useMemo","Dropdown","ColorPicker","CircularOptionPicker","VStack","Flex","FlexItem","Truncate","ColorHeading","SinglePalette","className","clearColor","colors","onChange","value","actions","colorOptions","color","name","colordColor","fill","contrast","backgroundColor","MultiplePalettes","index","colorPalette","length","CustomColorPickerDropdown","isRenderedInSidebar","props","placement","offset","undefined","extractColorNameFromCurrentValue","currentValue","showMultiplePalettes","currentValueIsCssVariable","test","normalizedCurrentValue","toHex","colorPalettes","paletteColors","colorName","colorValue","normalizedColorValue","ColorPalette","clearable","disableCustomColors","enableAlpha","__experimentalHasMultipleOrigins","__experimentalIsRenderedInSidebar","Component","renderCustomColorPicker","valueWithoutLeadingHash","startsWith","substring","buttonLabelName","customColorAccessibleLabel","isOpen","onToggle","background"],"mappings":";;AAAA;;AACA;AACA;AACA;AACA,SAASA,GAAT,QAAoB,QAApB;AACA,SAASC,MAAT,EAAiBC,MAAjB,QAA+B,QAA/B;AACA,OAAOC,WAAP,MAAwB,sBAAxB;AACA,OAAOC,UAAP,MAAuB,qBAAvB;AAEA;AACA;AACA;;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,WAAT,EAAsBC,OAAtB,QAAqC,oBAArC;AAEA;AACA;AACA;;AACA,OAAOC,QAAP,MAAqB,aAArB;AACA,SAASC,WAAT,QAA4B,iBAA5B;AACA,OAAOC,oBAAP,MAAiC,2BAAjC;AACA,SAASC,MAAT,QAAuB,YAAvB;AACA,SAASC,IAAT,EAAeC,QAAf,QAA+B,SAA/B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EAAGnC;AADX,OAGGd,EAAE,CAAE,OAAF,CAHL;AARH,IAzCD,CADD;AA4DA","sourcesContent":["// @ts-nocheck\n/**\n * External dependencies\n */\nimport { map } from 'lodash';\nimport { colord, extend } from 'colord';\nimport namesPlugin from 'colord/plugins/names';\nimport a11yPlugin from 'colord/plugins/a11y';\n\n/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useCallback, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport Dropdown from '../dropdown';\nimport { ColorPicker } from '../color-picker';\nimport CircularOptionPicker from '../circular-option-picker';\nimport { VStack } from '../v-stack';\nimport { Flex, FlexItem } from '../flex';\nimport { Truncate } from '../truncate';\nimport { ColorHeading } from './styles';\n\nextend( [ namesPlugin, a11yPlugin ] );\n\nfunction SinglePalette( {\n\tclassName,\n\tclearColor,\n\tcolors,\n\tonChange,\n\tvalue,\n\tactions,\n} ) {\n\tconst colorOptions = useMemo( () => {\n\t\treturn map( colors, ( { color, name } ) => {\n\t\t\tconst colordColor = colord( color );\n\n\t\t\treturn (\n\t\t\t\t<CircularOptionPicker.Option\n\t\t\t\t\tkey={ color }\n\t\t\t\t\tisSelected={ value === color }\n\t\t\t\t\tselectedIconProps={\n\t\t\t\t\t\tvalue === color\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tfill:\n\t\t\t\t\t\t\t\t\t\tcolordColor.contrast() >\n\t\t\t\t\t\t\t\t\t\tcolordColor.contrast( '#000' )\n\t\t\t\t\t\t\t\t\t\t\t? '#fff'\n\t\t\t\t\t\t\t\t\t\t\t: '#000',\n\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t: {}\n\t\t\t\t\t}\n\t\t\t\t\ttooltipText={\n\t\t\t\t\t\tname ||\n\t\t\t\t\t\t// translators: %s: color hex code e.g: \"#f00\".\n\t\t\t\t\t\tsprintf( __( 'Color code: %s' ), color )\n\t\t\t\t\t}\n\t\t\t\t\tstyle={ { backgroundColor: color, color } }\n\t\t\t\t\tonClick={\n\t\t\t\t\t\tvalue === color ? clearColor : () => onChange( color )\n\t\t\t\t\t}\n\t\t\t\t\taria-label={\n\t\t\t\t\t\tname\n\t\t\t\t\t\t\t? // translators: %s: The name of the color e.g: \"vivid red\".\n\t\t\t\t\t\t\t sprintf( __( 'Color: %s' ), name )\n\t\t\t\t\t\t\t: // translators: %s: color hex code e.g: \"#f00\".\n\t\t\t\t\t\t\t sprintf( __( 'Color code: %s' ), color )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t);\n\t\t} );\n\t}, [ colors, value, onChange, clearColor ] );\n\treturn (\n\t\t<CircularOptionPicker\n\t\t\tclassName={ className }\n\t\t\toptions={ colorOptions }\n\t\t\tactions={ actions }\n\t\t/>\n\t);\n}\n\nfunction MultiplePalettes( {\n\tclassName,\n\tclearColor,\n\tcolors,\n\tonChange,\n\tvalue,\n\tactions,\n} ) {\n\treturn (\n\t\t<VStack spacing={ 3 } className={ className }>\n\t\t\t{ colors.map( ( { name, colors: colorPalette }, index ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<VStack spacing={ 2 } key={ index }>\n\t\t\t\t\t\t<ColorHeading>{ name }</ColorHeading>\n\t\t\t\t\t\t<SinglePalette\n\t\t\t\t\t\t\tclearColor={ clearColor }\n\t\t\t\t\t\t\tcolors={ colorPalette }\n\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t\t\tactions={\n\t\t\t\t\t\t\t\tcolors.length === index + 1 ? actions : null\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</VStack>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</VStack>\n\t);\n}\n\nexport function CustomColorPickerDropdown( { isRenderedInSidebar, ...props } ) {\n\treturn (\n\t\t<Dropdown\n\t\t\tcontentClassName=\"components-color-palette__custom-color-dropdown-content\"\n\t\t\tpopoverProps={\n\t\t\t\tisRenderedInSidebar\n\t\t\t\t\t? { placement: 'left-start', offset: 20 }\n\t\t\t\t\t: undefined\n\t\t\t}\n\t\t\t{ ...props }\n\t\t/>\n\t);\n}\n\nexport const extractColorNameFromCurrentValue = (\n\tcurrentValue,\n\tcolors = [],\n\tshowMultiplePalettes = false\n) => {\n\tif ( ! currentValue ) {\n\t\treturn '';\n\t}\n\n\tconst currentValueIsCssVariable = /^var\\(/.test( currentValue );\n\tconst normalizedCurrentValue = currentValueIsCssVariable\n\t\t? currentValue\n\t\t: colord( currentValue ).toHex();\n\n\t// Normalize format of `colors` to simplify the following loop\n\tconst colorPalettes = showMultiplePalettes ? colors : [ { colors } ];\n\tfor ( const { colors: paletteColors } of colorPalettes ) {\n\t\tfor ( const { name: colorName, color: colorValue } of paletteColors ) {\n\t\t\tconst normalizedColorValue = currentValueIsCssVariable\n\t\t\t\t? colorValue\n\t\t\t\t: colord( colorValue ).toHex();\n\n\t\t\tif ( normalizedCurrentValue === normalizedColorValue ) {\n\t\t\t\treturn colorName;\n\t\t\t}\n\t\t}\n\t}\n\n\t// translators: shown when the user has picked a custom color (i.e not in the palette of colors).\n\treturn __( 'Custom' );\n};\n\nexport default function ColorPalette( {\n\tclearable = true,\n\tclassName,\n\tcolors,\n\tdisableCustomColors = false,\n\tenableAlpha,\n\tonChange,\n\tvalue,\n\t__experimentalHasMultipleOrigins = false,\n\t__experimentalIsRenderedInSidebar = false,\n} ) {\n\tconst clearColor = useCallback( () => onChange( undefined ), [ onChange ] );\n\tconst showMultiplePalettes =\n\t\t__experimentalHasMultipleOrigins && colors?.length;\n\tconst Component = showMultiplePalettes ? MultiplePalettes : SinglePalette;\n\n\tconst renderCustomColorPicker = () => (\n\t\t<ColorPicker\n\t\t\tcolor={ value }\n\t\t\tonChange={ ( color ) => onChange( color ) }\n\t\t\tenableAlpha={ enableAlpha }\n\t\t/>\n\t);\n\n\tconst colordColor = colord( value );\n\n\tconst valueWithoutLeadingHash = value?.startsWith( '#' )\n\t\t? value.substring( 1 )\n\t\t: value ?? '';\n\tconst buttonLabelName = useMemo(\n\t\t() =>\n\t\t\textractColorNameFromCurrentValue(\n\t\t\t\tvalue,\n\t\t\t\tcolors,\n\t\t\t\tshowMultiplePalettes\n\t\t\t),\n\t\t[ value, colors, showMultiplePalettes ]\n\t);\n\n\tconst customColorAccessibleLabel = !! valueWithoutLeadingHash\n\t\t? sprintf(\n\t\t\t\t// translators: %1$s: The name of the color e.g: \"vivid red\". %2$s: The color's hex code e.g: \"#f00\".\n\t\t\t\t__(\n\t\t\t\t\t'Custom color picker. The currently selected color is called \"%1$s\" and has a value of \"%2$s\".'\n\t\t\t\t),\n\t\t\t\tbuttonLabelName,\n\t\t\t\tvalueWithoutLeadingHash\n\t\t )\n\t\t: __( 'Custom color picker.' );\n\n\treturn (\n\t\t<VStack spacing={ 3 } className={ className }>\n\t\t\t{ ! disableCustomColors && (\n\t\t\t\t<CustomColorPickerDropdown\n\t\t\t\t\tisRenderedInSidebar={ __experimentalIsRenderedInSidebar }\n\t\t\t\t\trenderContent={ renderCustomColorPicker }\n\t\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t\t\t<Flex\n\t\t\t\t\t\t\tas={ 'button' }\n\t\t\t\t\t\t\tjustify=\"space-between\"\n\t\t\t\t\t\t\talign=\"flex-start\"\n\t\t\t\t\t\t\tclassName=\"components-color-palette__custom-color\"\n\t\t\t\t\t\t\taria-expanded={ isOpen }\n\t\t\t\t\t\t\taria-haspopup=\"true\"\n\t\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t\t\taria-label={ customColorAccessibleLabel }\n\t\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\t\tbackground: value,\n\t\t\t\t\t\t\t\tcolor:\n\t\t\t\t\t\t\t\t\tcolordColor.contrast() >\n\t\t\t\t\t\t\t\t\tcolordColor.contrast( '#000' )\n\t\t\t\t\t\t\t\t\t\t? '#fff'\n\t\t\t\t\t\t\t\t\t\t: '#000',\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<FlexItem\n\t\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\t\tas={ Truncate }\n\t\t\t\t\t\t\t\tclassName=\"components-color-palette__custom-color-name\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ buttonLabelName }\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t\t<FlexItem\n\t\t\t\t\t\t\t\tas=\"span\"\n\t\t\t\t\t\t\t\tclassName=\"components-color-palette__custom-color-value\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ valueWithoutLeadingHash }\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t</Flex>\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t<Component\n\t\t\t\tclearable={ clearable }\n\t\t\t\tclearColor={ clearColor }\n\t\t\t\tcolors={ colors }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tvalue={ value }\n\t\t\t\tactions={\n\t\t\t\t\t!! clearable && (\n\t\t\t\t\t\t<CircularOptionPicker.ButtonAction\n\t\t\t\t\t\t\tonClick={ clearColor }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Clear' ) }\n\t\t\t\t\t\t</CircularOptionPicker.ButtonAction>\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t/>\n\t\t</VStack>\n\t);\n}\n"]}
|
|
@@ -68,7 +68,10 @@ function ColorPalette(_ref) {
|
|
|
68
68
|
y: 0
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
|
-
}
|
|
71
|
+
} // Temporarily disabling exhuastive-deps until the component can be refactored and updated safely.
|
|
72
|
+
// Please see https://github.com/WordPress/gutenberg/pull/41253 for discussion and details.
|
|
73
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
74
|
+
|
|
72
75
|
}, [currentSegment]);
|
|
73
76
|
|
|
74
77
|
function isSelectedCustom() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/color-palette/index.native.js"],"names":["ScrollView","TouchableWithoutFeedback","View","Animated","Easing","Dimensions","Platform","Text","map","uniq","__","useRef","useEffect","usePreferredColorSchemeStyle","styles","ColorIndicator","colorsUtils","ANIMATION_DURATION","contentWidth","scrollPosition","customIndicatorWidth","ColorPalette","enableCustomColor","setColor","activeColor","isGradientColor","defaultSettings","currentSegment","onCustomPress","shouldEnableBottomSheetScroll","shouldShowCustomIndicatorOption","shouldShowCustomLabel","shouldShowCustomVerticalSeparator","customColorIndicatorStyles","customIndicatorWrapperStyles","label","customSwatchGradients","scrollViewRef","isIOS","OS","isGradientSegment","segments","scale","Value","current","opacity","defaultColors","colors","mergedColors","allColors","defaultGradientColors","gradients","customIndicatorColor","isCustomGradientColor","isSelectedCustom","shouldShowCustomIndicator","accessibilityHint","customText","scrollToEndWithDelay","scrollTo","x","y","isWithinColors","includes","isSelected","color","timingAnimation","property","toValue","timing","duration","easing","ease","useNativeDriver","performAnimation","setValue","parallel","start","scaleInterpolation","interpolate","inputRange","outputRange","deselectCustomGradient","width","get","isVisible","onColorPress","onContentSizeChange","delayedScroll","setTimeout","scrollToEnd","clearTimeout","onCustomIndicatorLayout","nativeEvent","layout","onScroll","contentOffset","verticalSeparatorStyle","verticalSeparator","verticalSeparatorDark","customTextStyle","customTextAndroid","customTextDark","customIndicatorWrapperStyle","customIndicatorWrapper","headerText","contentContainer","scaleValue","selected","transform","colorIndicator","toUpperCase"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,UADD,EAECC,wBAFD,EAGCC,IAHD,EAICC,QAJD,EAKCC,MALD,EAMCC,UAND,EAOCC,QAPD,EAQCC,IARD,QASO,cATP;AAUA,SAASC,GAAT,EAAcC,IAAd,QAA0B,QAA1B;AAEA;AACA;AACA;;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,MAAT,EAAiBC,SAAjB,QAAkC,oBAAlC;AACA,SAASC,4BAAT,QAA6C,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,EAAGE,gBAAgB,EAH9B;AAIC,IAAA,KAAK,EAAG,CACPxC,MAAM,CAACgG,cADA,EAEP7E,0BAFO;AAJT,IADD,EAUGF,qBAAqB,IACtB,cAAC,IAAD;AAAM,IAAA,KAAK,EAAGqE;AAAd,KACG9D,KAAK,GACJmB,UADI,GAEJA,UAAU,CAACsD,WAAX,EAHJ,CAXF,CARD,CAPD,CAvDF,CAPD,CADD;AAsGA;;AAED,eAAe1F,YAAf","sourcesContent":["/**\n * External dependencies\n */\nimport {\n\tScrollView,\n\tTouchableWithoutFeedback,\n\tView,\n\tAnimated,\n\tEasing,\n\tDimensions,\n\tPlatform,\n\tText,\n} from 'react-native';\nimport { map, uniq } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useRef, useEffect } from '@wordpress/element';\nimport { usePreferredColorSchemeStyle } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport styles from './style.scss';\nimport ColorIndicator from '../color-indicator';\nimport { colorsUtils } from '../mobile/color-settings/utils';\n\nconst ANIMATION_DURATION = 200;\n\nlet contentWidth = 0;\nlet scrollPosition = 0;\nlet customIndicatorWidth = 0;\n\nfunction ColorPalette( {\n\tenableCustomColor = true,\n\tsetColor,\n\tactiveColor,\n\tisGradientColor,\n\tdefaultSettings,\n\tcurrentSegment,\n\tonCustomPress,\n\tshouldEnableBottomSheetScroll,\n\tshouldShowCustomIndicatorOption = true,\n\tshouldShowCustomLabel = true,\n\tshouldShowCustomVerticalSeparator = true,\n\tcustomColorIndicatorStyles,\n\tcustomIndicatorWrapperStyles,\n\tlabel,\n} ) {\n\tconst customSwatchGradients = [\n\t\t'linear-gradient(120deg, rgba(255,0,0,.8) 0%, rgba(255,255,255,1) 70.71%)',\n\t\t'linear-gradient(240deg, rgba(0,255,0,.8) 0%, rgba(0,255,0,0) 70.71%)',\n\t\t'linear-gradient(360deg, rgba(0,0,255,.8) 0%, rgba(0,0,255,0) 70.71%)',\n\t];\n\n\tconst scrollViewRef = useRef();\n\tconst isIOS = Platform.OS === 'ios';\n\n\tconst isGradientSegment = currentSegment === colorsUtils.segments[ 1 ];\n\n\tconst scale = useRef( new Animated.Value( 1 ) ).current;\n\tconst opacity = useRef( new Animated.Value( 1 ) ).current;\n\n\tconst defaultColors = uniq( map( defaultSettings.colors, 'color' ) );\n\tconst mergedColors = uniq( map( defaultSettings.allColors, 'color' ) );\n\tconst defaultGradientColors = uniq(\n\t\tmap( defaultSettings.gradients, 'gradient' )\n\t);\n\tconst colors = isGradientSegment ? defaultGradientColors : defaultColors;\n\n\tconst customIndicatorColor = isGradientSegment\n\t\t? activeColor\n\t\t: customSwatchGradients;\n\tconst isCustomGradientColor = isGradientColor && isSelectedCustom();\n\tconst shouldShowCustomIndicator =\n\t\tenableCustomColor &&\n\t\tshouldShowCustomIndicatorOption &&\n\t\t( ! isGradientSegment || isCustomGradientColor );\n\n\tconst accessibilityHint = isGradientSegment\n\t\t? __( 'Navigates to customize the gradient' )\n\t\t: __( 'Navigates to custom color picker' );\n\tconst customText = __( 'Custom' );\n\n\tuseEffect( () => {\n\t\tif ( scrollViewRef.current ) {\n\t\t\tif ( isSelectedCustom() ) {\n\t\t\t\tscrollToEndWithDelay();\n\t\t\t} else {\n\t\t\t\tscrollViewRef.current.scrollTo( { x: 0, y: 0 } );\n\t\t\t}\n\t\t}\n\t}, [ currentSegment ] );\n\n\tfunction isSelectedCustom() {\n\t\tconst isWithinColors =\n\t\t\tactiveColor && mergedColors && mergedColors.includes( activeColor );\n\t\tif ( enableCustomColor && activeColor ) {\n\t\t\tif ( isGradientSegment ) {\n\t\t\t\treturn isGradientColor && ! isWithinColors;\n\t\t\t}\n\t\t\treturn ! isGradientColor && ! isWithinColors;\n\t\t}\n\t\treturn false;\n\t}\n\n\tfunction isSelected( color ) {\n\t\treturn ! isSelectedCustom() && activeColor === color;\n\t}\n\n\tfunction timingAnimation( property, toValue ) {\n\t\treturn Animated.timing( property, {\n\t\t\ttoValue,\n\t\t\tduration: ANIMATION_DURATION,\n\t\t\teasing: Easing.ease,\n\t\t\tuseNativeDriver: true,\n\t\t} );\n\t}\n\n\tfunction performAnimation( color ) {\n\t\tif ( ! isSelected( color ) ) {\n\t\t\topacity.setValue( 0 );\n\t\t}\n\n\t\tAnimated.parallel( [\n\t\t\ttimingAnimation( scale, 2 ),\n\t\t\ttimingAnimation( opacity, 1 ),\n\t\t] ).start( () => {\n\t\t\topacity.setValue( 1 );\n\t\t\tscale.setValue( 1 );\n\t\t} );\n\t}\n\n\tconst scaleInterpolation = scale.interpolate( {\n\t\tinputRange: [ 1, 1.5, 2 ],\n\t\toutputRange: [ 1, 0.7, 1 ],\n\t} );\n\n\tfunction deselectCustomGradient() {\n\t\tconst { width } = Dimensions.get( 'window' );\n\t\tconst isVisible =\n\t\t\tcontentWidth - scrollPosition - customIndicatorWidth < width;\n\n\t\tif ( isCustomGradientColor ) {\n\t\t\tif ( ! isIOS ) {\n\t\t\t\t// Scroll position on Android doesn't adjust automatically when removing the last item from the horizontal list.\n\t\t\t\t// https://github.com/facebook/react-native/issues/27504\n\t\t\t\t// Workaround: Force the scroll when deselecting custom gradient color and when custom indicator is visible on layout.\n\t\t\t\tif (\n\t\t\t\t\tisCustomGradientColor &&\n\t\t\t\t\tisVisible &&\n\t\t\t\t\tscrollViewRef.current\n\t\t\t\t) {\n\t\t\t\t\tscrollViewRef.current.scrollTo( {\n\t\t\t\t\t\tx: scrollPosition - customIndicatorWidth,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction onColorPress( color ) {\n\t\tdeselectCustomGradient();\n\t\tperformAnimation( color );\n\t\tsetColor( color );\n\t}\n\n\tfunction onContentSizeChange( width ) {\n\t\tcontentWidth = width;\n\t\tif ( isSelectedCustom() && scrollViewRef.current ) {\n\t\t\tscrollToEndWithDelay();\n\t\t}\n\t}\n\n\tfunction scrollToEndWithDelay() {\n\t\tconst delayedScroll = setTimeout( () => {\n\t\t\tscrollViewRef.current.scrollToEnd();\n\t\t}, ANIMATION_DURATION );\n\t\treturn () => {\n\t\t\tclearTimeout( delayedScroll );\n\t\t};\n\t}\n\n\tfunction onCustomIndicatorLayout( { nativeEvent } ) {\n\t\tconst { width } = nativeEvent.layout;\n\t\tif ( width !== customIndicatorWidth ) {\n\t\t\tcustomIndicatorWidth = width;\n\t\t}\n\t}\n\n\tfunction onScroll( { nativeEvent } ) {\n\t\tscrollPosition = nativeEvent.contentOffset.x;\n\t}\n\n\tconst verticalSeparatorStyle = usePreferredColorSchemeStyle(\n\t\tstyles.verticalSeparator,\n\t\tstyles.verticalSeparatorDark\n\t);\n\n\tconst customTextStyle = usePreferredColorSchemeStyle(\n\t\t[ styles.customText, ! isIOS && styles.customTextAndroid ],\n\t\tstyles.customTextDark\n\t);\n\n\tconst customIndicatorWrapperStyle = [\n\t\tstyles.customIndicatorWrapper,\n\t\tcustomIndicatorWrapperStyles,\n\t];\n\n\treturn (\n\t\t<>\n\t\t\t{ label && (\n\t\t\t\t<Text accessibilityRole=\"header\" style={ styles.headerText }>\n\t\t\t\t\t{ label }\n\t\t\t\t</Text>\n\t\t\t) }\n\n\t\t\t<ScrollView\n\t\t\t\tcontentContainerStyle={ styles.contentContainer }\n\t\t\t\thorizontal\n\t\t\t\tshowsHorizontalScrollIndicator={ false }\n\t\t\t\tkeyboardShouldPersistTaps=\"always\"\n\t\t\t\tdisableScrollViewPanResponder\n\t\t\t\tscrollEventThrottle={ 16 }\n\t\t\t\tonScroll={ onScroll }\n\t\t\t\tonContentSizeChange={ onContentSizeChange }\n\t\t\t\tonScrollBeginDrag={ () =>\n\t\t\t\t\tshouldEnableBottomSheetScroll( false )\n\t\t\t\t}\n\t\t\t\tonScrollEndDrag={ () => shouldEnableBottomSheetScroll( true ) }\n\t\t\t\tref={ scrollViewRef }\n\t\t\t\ttestID={ `color-palette${ label ? '-' + label : '' }` }\n\t\t\t>\n\t\t\t\t{ colors.map( ( color ) => {\n\t\t\t\t\tconst scaleValue = isSelected( color )\n\t\t\t\t\t\t? scaleInterpolation\n\t\t\t\t\t\t: 1;\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<View key={ `${ color }-${ isSelected( color ) }` }>\n\t\t\t\t\t\t\t<TouchableWithoutFeedback\n\t\t\t\t\t\t\t\tonPress={ () => onColorPress( color ) }\n\t\t\t\t\t\t\t\taccessibilityRole={ 'button' }\n\t\t\t\t\t\t\t\taccessibilityState={ {\n\t\t\t\t\t\t\t\t\tselected: isSelected( color ),\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\taccessibilityHint={ color }\n\t\t\t\t\t\t\t\ttestID={ color }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<Animated.View\n\t\t\t\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\t\t\t\ttransform: [\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tscale: scaleValue,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<ColorIndicator\n\t\t\t\t\t\t\t\t\t\tcolor={ color }\n\t\t\t\t\t\t\t\t\t\tisSelected={ isSelected( color ) }\n\t\t\t\t\t\t\t\t\t\topacity={ opacity }\n\t\t\t\t\t\t\t\t\t\tstyle={ [\n\t\t\t\t\t\t\t\t\t\t\tstyles.colorIndicator,\n\t\t\t\t\t\t\t\t\t\t\tcustomColorIndicatorStyles,\n\t\t\t\t\t\t\t\t\t\t] }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</Animated.View>\n\t\t\t\t\t\t\t</TouchableWithoutFeedback>\n\t\t\t\t\t\t</View>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t\t{ shouldShowCustomIndicator && (\n\t\t\t\t\t<View\n\t\t\t\t\t\tstyle={ customIndicatorWrapperStyle }\n\t\t\t\t\t\tonLayout={ onCustomIndicatorLayout }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ shouldShowCustomVerticalSeparator && (\n\t\t\t\t\t\t\t<View style={ verticalSeparatorStyle } />\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<TouchableWithoutFeedback\n\t\t\t\t\t\t\tonPress={ onCustomPress }\n\t\t\t\t\t\t\taccessibilityRole={ 'button' }\n\t\t\t\t\t\t\taccessibilityState={ {\n\t\t\t\t\t\t\t\tselected: isSelectedCustom(),\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\taccessibilityHint={ accessibilityHint }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<View style={ customIndicatorWrapperStyle }>\n\t\t\t\t\t\t\t\t<ColorIndicator\n\t\t\t\t\t\t\t\t\twithCustomPicker={ ! isGradientSegment }\n\t\t\t\t\t\t\t\t\tcolor={ customIndicatorColor }\n\t\t\t\t\t\t\t\t\tisSelected={ isSelectedCustom() }\n\t\t\t\t\t\t\t\t\tstyle={ [\n\t\t\t\t\t\t\t\t\t\tstyles.colorIndicator,\n\t\t\t\t\t\t\t\t\t\tcustomColorIndicatorStyles,\n\t\t\t\t\t\t\t\t\t] }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t{ shouldShowCustomLabel && (\n\t\t\t\t\t\t\t\t\t<Text style={ customTextStyle }>\n\t\t\t\t\t\t\t\t\t\t{ isIOS\n\t\t\t\t\t\t\t\t\t\t\t? customText\n\t\t\t\t\t\t\t\t\t\t\t: customText.toUpperCase() }\n\t\t\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t</View>\n\t\t\t\t\t\t</TouchableWithoutFeedback>\n\t\t\t\t\t</View>\n\t\t\t\t) }\n\t\t\t</ScrollView>\n\t\t</>\n\t);\n}\n\nexport default ColorPalette;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/color-palette/index.native.js"],"names":["ScrollView","TouchableWithoutFeedback","View","Animated","Easing","Dimensions","Platform","Text","map","uniq","__","useRef","useEffect","usePreferredColorSchemeStyle","styles","ColorIndicator","colorsUtils","ANIMATION_DURATION","contentWidth","scrollPosition","customIndicatorWidth","ColorPalette","enableCustomColor","setColor","activeColor","isGradientColor","defaultSettings","currentSegment","onCustomPress","shouldEnableBottomSheetScroll","shouldShowCustomIndicatorOption","shouldShowCustomLabel","shouldShowCustomVerticalSeparator","customColorIndicatorStyles","customIndicatorWrapperStyles","label","customSwatchGradients","scrollViewRef","isIOS","OS","isGradientSegment","segments","scale","Value","current","opacity","defaultColors","colors","mergedColors","allColors","defaultGradientColors","gradients","customIndicatorColor","isCustomGradientColor","isSelectedCustom","shouldShowCustomIndicator","accessibilityHint","customText","scrollToEndWithDelay","scrollTo","x","y","isWithinColors","includes","isSelected","color","timingAnimation","property","toValue","timing","duration","easing","ease","useNativeDriver","performAnimation","setValue","parallel","start","scaleInterpolation","interpolate","inputRange","outputRange","deselectCustomGradient","width","get","isVisible","onColorPress","onContentSizeChange","delayedScroll","setTimeout","scrollToEnd","clearTimeout","onCustomIndicatorLayout","nativeEvent","layout","onScroll","contentOffset","verticalSeparatorStyle","verticalSeparator","verticalSeparatorDark","customTextStyle","customTextAndroid","customTextDark","customIndicatorWrapperStyle","customIndicatorWrapper","headerText","contentContainer","scaleValue","selected","transform","colorIndicator","toUpperCase"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,UADD,EAECC,wBAFD,EAGCC,IAHD,EAICC,QAJD,EAKCC,MALD,EAMCC,UAND,EAOCC,QAPD,EAQCC,IARD,QASO,cATP;AAUA,SAASC,GAAT,EAAcC,IAAd,QAA0B,QAA1B;AAEA;AACA;AACA;;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,MAAT,EAAiBC,SAAjB,QAAkC,oBAAlC;AACA,SAASC,4BAAT,QAA6C,oBAA7C;AAEA;AACA;AACA;;AACA,OAAOC,MAAP,MAAmB,cAAnB;AACA,OAAOC,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AAG,CACPxC,MAAM,CAACgG,cADA,EAEP7E,0BAFO;AAJT,IADD,EAUGF,qBAAqB,IACtB,cAAC,IAAD;AAAM,IAAA,KAAK,EAAGqE;AAAd,KACG9D,KAAK,GACJmB,UADI,GAEJA,UAAU,CAACsD,WAAX,EAHJ,CAXF,CARD,CAPD,CAvDF,CAPD,CADD;AAsGA;;AAED,eAAe1F,YAAf","sourcesContent":["/**\n * External dependencies\n */\nimport {\n\tScrollView,\n\tTouchableWithoutFeedback,\n\tView,\n\tAnimated,\n\tEasing,\n\tDimensions,\n\tPlatform,\n\tText,\n} from 'react-native';\nimport { map, uniq } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useRef, useEffect } from '@wordpress/element';\nimport { usePreferredColorSchemeStyle } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport styles from './style.scss';\nimport ColorIndicator from '../color-indicator';\nimport { colorsUtils } from '../mobile/color-settings/utils';\n\nconst ANIMATION_DURATION = 200;\n\nlet contentWidth = 0;\nlet scrollPosition = 0;\nlet customIndicatorWidth = 0;\n\nfunction ColorPalette( {\n\tenableCustomColor = true,\n\tsetColor,\n\tactiveColor,\n\tisGradientColor,\n\tdefaultSettings,\n\tcurrentSegment,\n\tonCustomPress,\n\tshouldEnableBottomSheetScroll,\n\tshouldShowCustomIndicatorOption = true,\n\tshouldShowCustomLabel = true,\n\tshouldShowCustomVerticalSeparator = true,\n\tcustomColorIndicatorStyles,\n\tcustomIndicatorWrapperStyles,\n\tlabel,\n} ) {\n\tconst customSwatchGradients = [\n\t\t'linear-gradient(120deg, rgba(255,0,0,.8) 0%, rgba(255,255,255,1) 70.71%)',\n\t\t'linear-gradient(240deg, rgba(0,255,0,.8) 0%, rgba(0,255,0,0) 70.71%)',\n\t\t'linear-gradient(360deg, rgba(0,0,255,.8) 0%, rgba(0,0,255,0) 70.71%)',\n\t];\n\n\tconst scrollViewRef = useRef();\n\tconst isIOS = Platform.OS === 'ios';\n\n\tconst isGradientSegment = currentSegment === colorsUtils.segments[ 1 ];\n\n\tconst scale = useRef( new Animated.Value( 1 ) ).current;\n\tconst opacity = useRef( new Animated.Value( 1 ) ).current;\n\n\tconst defaultColors = uniq( map( defaultSettings.colors, 'color' ) );\n\tconst mergedColors = uniq( map( defaultSettings.allColors, 'color' ) );\n\tconst defaultGradientColors = uniq(\n\t\tmap( defaultSettings.gradients, 'gradient' )\n\t);\n\tconst colors = isGradientSegment ? defaultGradientColors : defaultColors;\n\n\tconst customIndicatorColor = isGradientSegment\n\t\t? activeColor\n\t\t: customSwatchGradients;\n\tconst isCustomGradientColor = isGradientColor && isSelectedCustom();\n\tconst shouldShowCustomIndicator =\n\t\tenableCustomColor &&\n\t\tshouldShowCustomIndicatorOption &&\n\t\t( ! isGradientSegment || isCustomGradientColor );\n\n\tconst accessibilityHint = isGradientSegment\n\t\t? __( 'Navigates to customize the gradient' )\n\t\t: __( 'Navigates to custom color picker' );\n\tconst customText = __( 'Custom' );\n\n\tuseEffect( () => {\n\t\tif ( scrollViewRef.current ) {\n\t\t\tif ( isSelectedCustom() ) {\n\t\t\t\tscrollToEndWithDelay();\n\t\t\t} else {\n\t\t\t\tscrollViewRef.current.scrollTo( { x: 0, y: 0 } );\n\t\t\t}\n\t\t}\n\t\t// Temporarily disabling exhuastive-deps until the component can be refactored and updated safely.\n\t\t// Please see https://github.com/WordPress/gutenberg/pull/41253 for discussion and details.\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [ currentSegment ] );\n\n\tfunction isSelectedCustom() {\n\t\tconst isWithinColors =\n\t\t\tactiveColor && mergedColors && mergedColors.includes( activeColor );\n\t\tif ( enableCustomColor && activeColor ) {\n\t\t\tif ( isGradientSegment ) {\n\t\t\t\treturn isGradientColor && ! isWithinColors;\n\t\t\t}\n\t\t\treturn ! isGradientColor && ! isWithinColors;\n\t\t}\n\t\treturn false;\n\t}\n\n\tfunction isSelected( color ) {\n\t\treturn ! isSelectedCustom() && activeColor === color;\n\t}\n\n\tfunction timingAnimation( property, toValue ) {\n\t\treturn Animated.timing( property, {\n\t\t\ttoValue,\n\t\t\tduration: ANIMATION_DURATION,\n\t\t\teasing: Easing.ease,\n\t\t\tuseNativeDriver: true,\n\t\t} );\n\t}\n\n\tfunction performAnimation( color ) {\n\t\tif ( ! isSelected( color ) ) {\n\t\t\topacity.setValue( 0 );\n\t\t}\n\n\t\tAnimated.parallel( [\n\t\t\ttimingAnimation( scale, 2 ),\n\t\t\ttimingAnimation( opacity, 1 ),\n\t\t] ).start( () => {\n\t\t\topacity.setValue( 1 );\n\t\t\tscale.setValue( 1 );\n\t\t} );\n\t}\n\n\tconst scaleInterpolation = scale.interpolate( {\n\t\tinputRange: [ 1, 1.5, 2 ],\n\t\toutputRange: [ 1, 0.7, 1 ],\n\t} );\n\n\tfunction deselectCustomGradient() {\n\t\tconst { width } = Dimensions.get( 'window' );\n\t\tconst isVisible =\n\t\t\tcontentWidth - scrollPosition - customIndicatorWidth < width;\n\n\t\tif ( isCustomGradientColor ) {\n\t\t\tif ( ! isIOS ) {\n\t\t\t\t// Scroll position on Android doesn't adjust automatically when removing the last item from the horizontal list.\n\t\t\t\t// https://github.com/facebook/react-native/issues/27504\n\t\t\t\t// Workaround: Force the scroll when deselecting custom gradient color and when custom indicator is visible on layout.\n\t\t\t\tif (\n\t\t\t\t\tisCustomGradientColor &&\n\t\t\t\t\tisVisible &&\n\t\t\t\t\tscrollViewRef.current\n\t\t\t\t) {\n\t\t\t\t\tscrollViewRef.current.scrollTo( {\n\t\t\t\t\t\tx: scrollPosition - customIndicatorWidth,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction onColorPress( color ) {\n\t\tdeselectCustomGradient();\n\t\tperformAnimation( color );\n\t\tsetColor( color );\n\t}\n\n\tfunction onContentSizeChange( width ) {\n\t\tcontentWidth = width;\n\t\tif ( isSelectedCustom() && scrollViewRef.current ) {\n\t\t\tscrollToEndWithDelay();\n\t\t}\n\t}\n\n\tfunction scrollToEndWithDelay() {\n\t\tconst delayedScroll = setTimeout( () => {\n\t\t\tscrollViewRef.current.scrollToEnd();\n\t\t}, ANIMATION_DURATION );\n\t\treturn () => {\n\t\t\tclearTimeout( delayedScroll );\n\t\t};\n\t}\n\n\tfunction onCustomIndicatorLayout( { nativeEvent } ) {\n\t\tconst { width } = nativeEvent.layout;\n\t\tif ( width !== customIndicatorWidth ) {\n\t\t\tcustomIndicatorWidth = width;\n\t\t}\n\t}\n\n\tfunction onScroll( { nativeEvent } ) {\n\t\tscrollPosition = nativeEvent.contentOffset.x;\n\t}\n\n\tconst verticalSeparatorStyle = usePreferredColorSchemeStyle(\n\t\tstyles.verticalSeparator,\n\t\tstyles.verticalSeparatorDark\n\t);\n\n\tconst customTextStyle = usePreferredColorSchemeStyle(\n\t\t[ styles.customText, ! isIOS && styles.customTextAndroid ],\n\t\tstyles.customTextDark\n\t);\n\n\tconst customIndicatorWrapperStyle = [\n\t\tstyles.customIndicatorWrapper,\n\t\tcustomIndicatorWrapperStyles,\n\t];\n\n\treturn (\n\t\t<>\n\t\t\t{ label && (\n\t\t\t\t<Text accessibilityRole=\"header\" style={ styles.headerText }>\n\t\t\t\t\t{ label }\n\t\t\t\t</Text>\n\t\t\t) }\n\n\t\t\t<ScrollView\n\t\t\t\tcontentContainerStyle={ styles.contentContainer }\n\t\t\t\thorizontal\n\t\t\t\tshowsHorizontalScrollIndicator={ false }\n\t\t\t\tkeyboardShouldPersistTaps=\"always\"\n\t\t\t\tdisableScrollViewPanResponder\n\t\t\t\tscrollEventThrottle={ 16 }\n\t\t\t\tonScroll={ onScroll }\n\t\t\t\tonContentSizeChange={ onContentSizeChange }\n\t\t\t\tonScrollBeginDrag={ () =>\n\t\t\t\t\tshouldEnableBottomSheetScroll( false )\n\t\t\t\t}\n\t\t\t\tonScrollEndDrag={ () => shouldEnableBottomSheetScroll( true ) }\n\t\t\t\tref={ scrollViewRef }\n\t\t\t\ttestID={ `color-palette${ label ? '-' + label : '' }` }\n\t\t\t>\n\t\t\t\t{ colors.map( ( color ) => {\n\t\t\t\t\tconst scaleValue = isSelected( color )\n\t\t\t\t\t\t? scaleInterpolation\n\t\t\t\t\t\t: 1;\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<View key={ `${ color }-${ isSelected( color ) }` }>\n\t\t\t\t\t\t\t<TouchableWithoutFeedback\n\t\t\t\t\t\t\t\tonPress={ () => onColorPress( color ) }\n\t\t\t\t\t\t\t\taccessibilityRole={ 'button' }\n\t\t\t\t\t\t\t\taccessibilityState={ {\n\t\t\t\t\t\t\t\t\tselected: isSelected( color ),\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\taccessibilityHint={ color }\n\t\t\t\t\t\t\t\ttestID={ color }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<Animated.View\n\t\t\t\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\t\t\t\ttransform: [\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tscale: scaleValue,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<ColorIndicator\n\t\t\t\t\t\t\t\t\t\tcolor={ color }\n\t\t\t\t\t\t\t\t\t\tisSelected={ isSelected( color ) }\n\t\t\t\t\t\t\t\t\t\topacity={ opacity }\n\t\t\t\t\t\t\t\t\t\tstyle={ [\n\t\t\t\t\t\t\t\t\t\t\tstyles.colorIndicator,\n\t\t\t\t\t\t\t\t\t\t\tcustomColorIndicatorStyles,\n\t\t\t\t\t\t\t\t\t\t] }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</Animated.View>\n\t\t\t\t\t\t\t</TouchableWithoutFeedback>\n\t\t\t\t\t\t</View>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t\t{ shouldShowCustomIndicator && (\n\t\t\t\t\t<View\n\t\t\t\t\t\tstyle={ customIndicatorWrapperStyle }\n\t\t\t\t\t\tonLayout={ onCustomIndicatorLayout }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ shouldShowCustomVerticalSeparator && (\n\t\t\t\t\t\t\t<View style={ verticalSeparatorStyle } />\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<TouchableWithoutFeedback\n\t\t\t\t\t\t\tonPress={ onCustomPress }\n\t\t\t\t\t\t\taccessibilityRole={ 'button' }\n\t\t\t\t\t\t\taccessibilityState={ {\n\t\t\t\t\t\t\t\tselected: isSelectedCustom(),\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\taccessibilityHint={ accessibilityHint }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<View style={ customIndicatorWrapperStyle }>\n\t\t\t\t\t\t\t\t<ColorIndicator\n\t\t\t\t\t\t\t\t\twithCustomPicker={ ! isGradientSegment }\n\t\t\t\t\t\t\t\t\tcolor={ customIndicatorColor }\n\t\t\t\t\t\t\t\t\tisSelected={ isSelectedCustom() }\n\t\t\t\t\t\t\t\t\tstyle={ [\n\t\t\t\t\t\t\t\t\t\tstyles.colorIndicator,\n\t\t\t\t\t\t\t\t\t\tcustomColorIndicatorStyles,\n\t\t\t\t\t\t\t\t\t] }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t{ shouldShowCustomLabel && (\n\t\t\t\t\t\t\t\t\t<Text style={ customTextStyle }>\n\t\t\t\t\t\t\t\t\t\t{ isIOS\n\t\t\t\t\t\t\t\t\t\t\t? customText\n\t\t\t\t\t\t\t\t\t\t\t: customText.toUpperCase() }\n\t\t\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t</View>\n\t\t\t\t\t\t</TouchableWithoutFeedback>\n\t\t\t\t\t</View>\n\t\t\t\t) }\n\t\t\t</ScrollView>\n\t\t</>\n\t);\n}\n\nexport default ColorPalette;\n"]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { createElement } from "@wordpress/element";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* WordPress dependencies
|
|
5
|
+
*/
|
|
6
|
+
import { useCopyToClipboard } from '@wordpress/compose';
|
|
7
|
+
import { useState, useEffect, useRef } from '@wordpress/element';
|
|
8
|
+
import { copy } from '@wordpress/icons';
|
|
9
|
+
import { __ } from '@wordpress/i18n';
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { CopyButton } from './styles';
|
|
15
|
+
import { Text } from '../text';
|
|
16
|
+
import { Tooltip } from '../ui/tooltip';
|
|
17
|
+
export const ColorCopyButton = props => {
|
|
18
|
+
const {
|
|
19
|
+
color,
|
|
20
|
+
colorType
|
|
21
|
+
} = props;
|
|
22
|
+
const [copiedColor, setCopiedColor] = useState(null);
|
|
23
|
+
const copyTimer = useRef();
|
|
24
|
+
const copyRef = useCopyToClipboard(() => {
|
|
25
|
+
switch (colorType) {
|
|
26
|
+
case 'hsl':
|
|
27
|
+
{
|
|
28
|
+
return color.toHslString();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
case 'rgb':
|
|
32
|
+
{
|
|
33
|
+
return color.toRgbString();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
default:
|
|
37
|
+
case 'hex':
|
|
38
|
+
{
|
|
39
|
+
return color.toHex();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}, () => {
|
|
43
|
+
if (copyTimer.current) {
|
|
44
|
+
clearTimeout(copyTimer.current);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
setCopiedColor(color.toHex());
|
|
48
|
+
copyTimer.current = setTimeout(() => {
|
|
49
|
+
setCopiedColor(null);
|
|
50
|
+
copyTimer.current = undefined;
|
|
51
|
+
}, 3000);
|
|
52
|
+
});
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
// Clear copyTimer on component unmount.
|
|
55
|
+
return () => {
|
|
56
|
+
if (copyTimer.current) {
|
|
57
|
+
clearTimeout(copyTimer.current);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}, []);
|
|
61
|
+
return createElement(Tooltip, {
|
|
62
|
+
content: createElement(Text, {
|
|
63
|
+
color: "white"
|
|
64
|
+
}, copiedColor === color.toHex() ? __('Copied!') : __('Copy')),
|
|
65
|
+
placement: "bottom"
|
|
66
|
+
}, createElement(CopyButton, {
|
|
67
|
+
isSmall: true,
|
|
68
|
+
ref: copyRef,
|
|
69
|
+
icon: copy,
|
|
70
|
+
showTooltip: false
|
|
71
|
+
}));
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=color-copy-button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/color-picker/color-copy-button.tsx"],"names":["useCopyToClipboard","useState","useEffect","useRef","copy","__","CopyButton","Text","Tooltip","ColorCopyButton","props","color","colorType","copiedColor","setCopiedColor","copyTimer","copyRef","toHslString","toRgbString","toHex","current","clearTimeout","setTimeout","undefined"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,kBAAT,QAAmC,oBAAnC;AACA,SAASC,QAAT,EAAmBC,SAAnB,EAA8BC,MAA9B,QAA4C,oBAA5C;AACA,SAASC,IAAT,QAAqB,kBAArB;AACA,SAASC,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,UAA3B;AACA,SAASC,IAAT,QAAqB,SAArB;AACA,SAASC,OAAT,QAAwB,eAAxB;AAIA,OAAO,MAAMC,eAAe,GAAKC,KAAF,IAAmC;AACjE,QAAM;AAAEC,IAAAA,KAAF;AAASC,IAAAA;AAAT,MAAuBF,KAA7B;AACA,QAAM,CAAEG,WAAF,EAAeC,cAAf,IAAkCb,QAAQ,CAAmB,IAAnB,CAAhD;AACA,QAAMc,SAAS,GAAGZ,MAAM,EAAxB;AACA,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Content":["/**\n * WordPress dependencies\n */\nimport { useCopyToClipboard } from '@wordpress/compose';\nimport { useState, useEffect, useRef } from '@wordpress/element';\nimport { copy } from '@wordpress/icons';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { CopyButton } from './styles';\nimport { Text } from '../text';\nimport { Tooltip } from '../ui/tooltip';\n\nimport type { ColorCopyButtonProps } from './types';\n\nexport const ColorCopyButton = ( props: ColorCopyButtonProps ) => {\n\tconst { color, colorType } = props;\n\tconst [ copiedColor, setCopiedColor ] = useState< string | null >( null );\n\tconst copyTimer = useRef< ReturnType< typeof setTimeout > | undefined >();\n\tconst copyRef = useCopyToClipboard< HTMLDivElement >(\n\t\t() => {\n\t\t\tswitch ( colorType ) {\n\t\t\t\tcase 'hsl': {\n\t\t\t\t\treturn color.toHslString();\n\t\t\t\t}\n\t\t\t\tcase 'rgb': {\n\t\t\t\t\treturn color.toRgbString();\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\tcase 'hex': {\n\t\t\t\t\treturn color.toHex();\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t() => {\n\t\t\tif ( copyTimer.current ) {\n\t\t\t\tclearTimeout( copyTimer.current );\n\t\t\t}\n\t\t\tsetCopiedColor( color.toHex() );\n\t\t\tcopyTimer.current = setTimeout( () => {\n\t\t\t\tsetCopiedColor( null );\n\t\t\t\tcopyTimer.current = undefined;\n\t\t\t}, 3000 );\n\t\t}\n\t);\n\tuseEffect( () => {\n\t\t// Clear copyTimer on component unmount.\n\t\treturn () => {\n\t\t\tif ( copyTimer.current ) {\n\t\t\t\tclearTimeout( copyTimer.current );\n\t\t\t}\n\t\t};\n\t}, [] );\n\n\treturn (\n\t\t<Tooltip\n\t\t\tcontent={\n\t\t\t\t<Text color=\"white\">\n\t\t\t\t\t{ copiedColor === color.toHex()\n\t\t\t\t\t\t? __( 'Copied!' )\n\t\t\t\t\t\t: __( 'Copy' ) }\n\t\t\t\t</Text>\n\t\t\t}\n\t\t\tplacement=\"bottom\"\n\t\t>\n\t\t\t<CopyButton\n\t\t\t\tisSmall\n\t\t\t\tref={ copyRef }\n\t\t\t\ticon={ copy }\n\t\t\t\tshowTooltip={ false }\n\t\t\t/>\n\t\t</Tooltip>\n\t);\n};\n"]}
|
|
@@ -11,7 +11,6 @@ import namesPlugin from 'colord/plugins/names';
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { useCallback, useState, useMemo } from '@wordpress/element';
|
|
14
|
-
import { settings } from '@wordpress/icons';
|
|
15
14
|
import { useDebounce } from '@wordpress/compose';
|
|
16
15
|
import { __ } from '@wordpress/i18n';
|
|
17
16
|
/**
|
|
@@ -21,8 +20,8 @@ import { __ } from '@wordpress/i18n';
|
|
|
21
20
|
import { useContextSystem, contextConnect } from '../ui/context';
|
|
22
21
|
import { HStack } from '../h-stack';
|
|
23
22
|
import { Spacer } from '../spacer';
|
|
24
|
-
import { ColorfulWrapper, SelectControl, AuxiliaryColorArtefactWrapper
|
|
25
|
-
import {
|
|
23
|
+
import { ColorfulWrapper, SelectControl, AuxiliaryColorArtefactWrapper } from './styles';
|
|
24
|
+
import { ColorCopyButton } from './color-copy-button';
|
|
26
25
|
import { ColorInput } from './color-input';
|
|
27
26
|
import { Picker } from './picker';
|
|
28
27
|
import { useControlledValue } from '../utils/hooks';
|
|
@@ -60,7 +59,6 @@ const ColorPicker = (props, forwardedRef) => {
|
|
|
60
59
|
const handleChange = useCallback(nextValue => {
|
|
61
60
|
debouncedSetColor(nextValue.toHex());
|
|
62
61
|
}, [debouncedSetColor]);
|
|
63
|
-
const [showInputs, setShowInputs] = useState(false);
|
|
64
62
|
const [colorType, setColorType] = useState(copyFormat || 'hex');
|
|
65
63
|
return createElement(ColorfulWrapper, _extends({
|
|
66
64
|
ref: forwardedRef
|
|
@@ -70,25 +68,18 @@ const ColorPicker = (props, forwardedRef) => {
|
|
|
70
68
|
enableAlpha: enableAlpha
|
|
71
69
|
}), createElement(AuxiliaryColorArtefactWrapper, null, createElement(HStack, {
|
|
72
70
|
justify: "space-between"
|
|
73
|
-
},
|
|
71
|
+
}, createElement(SelectControl, {
|
|
74
72
|
options: options,
|
|
75
73
|
value: colorType,
|
|
76
74
|
onChange: nextColorType => setColorType(nextColorType),
|
|
77
75
|
label: __('Color format'),
|
|
78
76
|
hideLabelFromVision: true
|
|
79
|
-
})
|
|
77
|
+
}), createElement(ColorCopyButton, {
|
|
80
78
|
color: safeColordColor,
|
|
81
|
-
colorType: copyFormat || colorType
|
|
82
|
-
enableAlpha: enableAlpha
|
|
83
|
-
}), createElement(DetailsControlButton, {
|
|
84
|
-
isSmall: true,
|
|
85
|
-
onClick: () => setShowInputs(!showInputs),
|
|
86
|
-
icon: settings,
|
|
87
|
-
isPressed: showInputs,
|
|
88
|
-
label: showInputs ? __('Hide detailed inputs') : __('Show detailed inputs')
|
|
79
|
+
colorType: copyFormat || colorType
|
|
89
80
|
})), createElement(Spacer, {
|
|
90
81
|
margin: 4
|
|
91
|
-
}),
|
|
82
|
+
}), createElement(ColorInput, {
|
|
92
83
|
colorType: colorType,
|
|
93
84
|
color: safeColordColor,
|
|
94
85
|
onChange: handleChange,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/color-picker/component.tsx"],"names":["colord","extend","namesPlugin","useCallback","useState","useMemo","
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/color-picker/component.tsx"],"names":["colord","extend","namesPlugin","useCallback","useState","useMemo","useDebounce","__","useContextSystem","contextConnect","HStack","Spacer","ColorfulWrapper","SelectControl","AuxiliaryColorArtefactWrapper","ColorCopyButton","ColorInput","Picker","useControlledValue","options","label","value","ColorPicker","props","forwardedRef","enableAlpha","color","colorProp","onChange","defaultValue","copyFormat","divProps","setColor","safeColordColor","debouncedSetColor","handleChange","nextValue","toHex","colorType","setColorType","nextColorType","ConnectedColorPicker"],"mappings":";;;AAAA;AACA;AACA;AAEA,SAASA,MAAT,EAAiBC,MAAjB,QA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HZ;AAIC,IAAA,WAAW,EAAGV;AAJf,IAjBD,CAND,CADD;AAiCA,CAtED;;AAwEA,MAAMgB,oBAAoB,GAAGhC,cAAc,CAAEa,WAAF,EAAe,aAAf,CAA3C;AAEA,eAAemB,oBAAf","sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\nimport { colord, extend, Colord } from 'colord';\nimport namesPlugin from 'colord/plugins/names';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useState, useMemo } from '@wordpress/element';\nimport { useDebounce } from '@wordpress/compose';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport {\n\tuseContextSystem,\n\tcontextConnect,\n\tWordPressComponentProps,\n} from '../ui/context';\nimport { HStack } from '../h-stack';\nimport { Spacer } from '../spacer';\nimport {\n\tColorfulWrapper,\n\tSelectControl,\n\tAuxiliaryColorArtefactWrapper,\n} from './styles';\nimport { ColorCopyButton } from './color-copy-button';\nimport { ColorInput } from './color-input';\nimport { Picker } from './picker';\nimport { useControlledValue } from '../utils/hooks';\n\nimport type { ColorType } from './types';\n\nextend( [ namesPlugin ] );\n\nexport interface ColorPickerProps {\n\tenableAlpha?: boolean;\n\tcolor?: string;\n\tonChange?: ( color: string ) => void;\n\tdefaultValue?: string;\n\tcopyFormat?: ColorType;\n}\n\nconst options = [\n\t{ label: 'RGB', value: 'rgb' as const },\n\t{ label: 'HSL', value: 'hsl' as const },\n\t{ label: 'Hex', value: 'hex' as const },\n];\n\nconst ColorPicker = (\n\tprops: WordPressComponentProps< ColorPickerProps, 'div', false >,\n\tforwardedRef: ForwardedRef< any >\n) => {\n\tconst {\n\t\tenableAlpha = false,\n\t\tcolor: colorProp,\n\t\tonChange,\n\t\tdefaultValue = '#fff',\n\t\tcopyFormat,\n\t\t...divProps\n\t} = useContextSystem( props, 'ColorPicker' );\n\n\t// Use a safe default value for the color and remove the possibility of `undefined`.\n\tconst [ color, setColor ] = useControlledValue( {\n\t\tonChange,\n\t\tvalue: colorProp,\n\t\tdefaultValue,\n\t} );\n\n\tconst safeColordColor = useMemo( () => {\n\t\treturn colord( color || '' );\n\t}, [ color ] );\n\n\tconst debouncedSetColor = useDebounce( setColor );\n\n\tconst handleChange = useCallback(\n\t\t( nextValue: Colord ) => {\n\t\t\tdebouncedSetColor( nextValue.toHex() );\n\t\t},\n\t\t[ debouncedSetColor ]\n\t);\n\n\tconst [ colorType, setColorType ] = useState< ColorType >(\n\t\tcopyFormat || 'hex'\n\t);\n\n\treturn (\n\t\t<ColorfulWrapper ref={ forwardedRef } { ...divProps }>\n\t\t\t<Picker\n\t\t\t\tonChange={ handleChange }\n\t\t\t\tcolor={ safeColordColor }\n\t\t\t\tenableAlpha={ enableAlpha }\n\t\t\t/>\n\t\t\t<AuxiliaryColorArtefactWrapper>\n\t\t\t\t<HStack justify=\"space-between\">\n\t\t\t\t\t<SelectControl\n\t\t\t\t\t\toptions={ options }\n\t\t\t\t\t\tvalue={ colorType }\n\t\t\t\t\t\tonChange={ ( nextColorType ) =>\n\t\t\t\t\t\t\tsetColorType( nextColorType as ColorType )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlabel={ __( 'Color format' ) }\n\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t/>\n\t\t\t\t\t<ColorCopyButton\n\t\t\t\t\t\tcolor={ safeColordColor }\n\t\t\t\t\t\tcolorType={ copyFormat || colorType }\n\t\t\t\t\t/>\n\t\t\t\t</HStack>\n\t\t\t\t<Spacer margin={ 4 } />\n\t\t\t\t<ColorInput\n\t\t\t\t\tcolorType={ colorType }\n\t\t\t\t\tcolor={ safeColordColor }\n\t\t\t\t\tonChange={ handleChange }\n\t\t\t\t\tenableAlpha={ enableAlpha }\n\t\t\t\t/>\n\t\t\t</AuxiliaryColorArtefactWrapper>\n\t\t</ColorfulWrapper>\n\t);\n};\n\nconst ConnectedColorPicker = contextConnect( ColorPicker, 'ColorPicker' );\n\nexport default ConnectedColorPicker;\n"]}
|
|
@@ -31,6 +31,22 @@ export const HexInput = _ref => {
|
|
|
31
31
|
onChange(colord(hexValue));
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
+
const stateReducer = (state, action) => {
|
|
35
|
+
var _action$payload, _action$payload$event, _state$value, _state$value2;
|
|
36
|
+
|
|
37
|
+
const nativeEvent = (_action$payload = action.payload) === null || _action$payload === void 0 ? void 0 : (_action$payload$event = _action$payload.event) === null || _action$payload$event === void 0 ? void 0 : _action$payload$event.nativeEvent;
|
|
38
|
+
|
|
39
|
+
if ('insertFromPaste' !== (nativeEvent === null || nativeEvent === void 0 ? void 0 : nativeEvent.inputType)) {
|
|
40
|
+
return { ...state
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const value = (_state$value = state.value) !== null && _state$value !== void 0 && _state$value.startsWith('#') ? state.value.slice(1).toUpperCase() : (_state$value2 = state.value) === null || _state$value2 === void 0 ? void 0 : _state$value2.toUpperCase();
|
|
45
|
+
return { ...state,
|
|
46
|
+
value
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
34
50
|
return createElement(ColorHexInputControl, {
|
|
35
51
|
prefix: createElement(Spacer, {
|
|
36
52
|
as: Text,
|
|
@@ -42,7 +58,8 @@ export const HexInput = _ref => {
|
|
|
42
58
|
onChange: handleChange,
|
|
43
59
|
maxLength: enableAlpha ? 9 : 7,
|
|
44
60
|
label: __('Hex color'),
|
|
45
|
-
hideLabelFromVision: true
|
|
61
|
+
hideLabelFromVision: true,
|
|
62
|
+
__unstableStateReducer: stateReducer
|
|
46
63
|
});
|
|
47
64
|
};
|
|
48
65
|
//# sourceMappingURL=hex-input.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/color-picker/hex-input.tsx"],"names":["colord","__","Text","Spacer","space","ColorHexInputControl","COLORS","HexInput","color","onChange","enableAlpha","handleChange","nextValue","hexValue","startsWith","
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/color-picker/hex-input.tsx"],"names":["colord","__","Text","Spacer","space","ColorHexInputControl","COLORS","HexInput","color","onChange","enableAlpha","handleChange","nextValue","hexValue","startsWith","stateReducer","state","action","nativeEvent","payload","event","inputType","value","slice","toUpperCase","ui","theme","toHex"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,MAAT,QAA+B,QAA/B;AAEA;AACA;AACA;;AACA,SAASC,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;;AACA,SAASC,IAAT,QAAqB,SAArB;AACA,SAASC,MAAT,QAAuB,WAAvB;AACA,SAASC,KAAT,QAAsB,mBAAtB;AACA,SAASC,oBAAT,QAAqC,UAArC;AACA,SAASC,MAAT,QAAuB,wBAAvB;AASA,OAAO,MAAMC,QAAQ,GAAG,QAAuD;AAAA,MAArD;AAAEC,IAAAA,KAAF;AAASC,IAAAA,QAAT;AAAmBC,IAAAA;AAAnB,GAAqD;;AAC9E,QAAMC,YAAY,GAAKC,SAAF,IAAqC;AACzD,QAAK,CAAEA,SAAP,EAAmB;AACnB,UAAMC,QAAQ,GAAGD,SAAS,CAACE,UAAV,CAAsB,GAAtB,IACdF,SADc,GAEd,MAAMA,SAFT;AAIAH,IAAAA,QAAQ,CAAET,MAAM,CAAEa,QAAF,CAAR,CAAR;AACA,GAPD;;AASA,QAAME,YAA0B,GAAG,CAAEC,KAAF,EAASC,MAAT,KAAqB;AAAA;;AACvD,UAAMC,WAAW,sBAAGD,MAAM,CAACE,OAAV,6EAAG,gBAAgBC,KAAnB,0DAAG,sBAAuBF,WAA3C;;AAEA,QAAK,uBAAsBA,WAAtB,aAAsBA,WAAtB,uBAAsBA,WAAW,CAAEG,SAAnC,CAAL,EAAoD;AACnD,aAAO,EAAE,GAAGL;AAAL,OAAP;AACA;;AAED,UAAMM,KAAK,GAAG,gBAAAN,KAAK,CAACM,KAAN,sDAAaR,UAAb,CAAyB,GAAzB,IACXE,KAAK,CAACM,KAAN,CAAYC,KAAZ,CAAmB,CAAnB,EAAuBC,WAAvB,EADW,oBAEXR,KAAK,CAACM,KAFK,kDAEX,cAAaE,WAAb,EAFH;AAIA,WAAO,EAAE,GAAGR,KAAL;AAAYM,MAAAA;AAAZ,KAAP;AACA,GAZD;;AAcA,SACC,cAAC,oBAAD;AACC,IAAA,MAAM,EACL,cAAC,MAAD;AACC,MAAA,EAAE,EAAGpB,IADN;AAEC,MAAA,UAAU,EAAGE,KAAK,CAAE,GAAF,CAFnB;AAGC,MAAA,KAAK,EAAGE,MAAM,CAACmB,EAAP,CAAUC,KAHnB;AAIC,MAAA,UAAU,EAAG;AAJd,WAFF;AAWC,IAAA,KAAK,EAAGlB,KAAK,CAACmB,KAAN,GAAcJ,KAAd,CAAqB,CAArB,EAAyBC,WAAzB,EAXT;AAYC,IAAA,QAAQ,EAAGb,YAZZ;AAaC,IAAA,SAAS,EAAGD,WAAW,GAAG,CAAH,GAAO,CAb/B;AAcC,IAAA,KAAK,EAAGT,EAAE,CAAE,WAAF,CAdX;AAeC,IAAA,mBAAmB,MAfpB;AAgBC,IAAA,sBAAsB,EAAGc;AAhB1B,IADD;AAoBA,CA5CM","sourcesContent":["/**\n * External dependencies\n */\nimport { colord, Colord } from 'colord';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { Text } from '../text';\nimport { Spacer } from '../spacer';\nimport { space } from '../ui/utils/space';\nimport { ColorHexInputControl } from './styles';\nimport { COLORS } from '../utils/colors-values';\nimport type { StateReducer } from '../input-control/reducer/state';\n\ninterface HexInputProps {\n\tcolor: Colord;\n\tonChange: ( nextColor: Colord ) => void;\n\tenableAlpha: boolean;\n}\n\nexport const HexInput = ( { color, onChange, enableAlpha }: HexInputProps ) => {\n\tconst handleChange = ( nextValue: string | undefined ) => {\n\t\tif ( ! nextValue ) return;\n\t\tconst hexValue = nextValue.startsWith( '#' )\n\t\t\t? nextValue\n\t\t\t: '#' + nextValue;\n\n\t\tonChange( colord( hexValue ) );\n\t};\n\n\tconst stateReducer: StateReducer = ( state, action ) => {\n\t\tconst nativeEvent = action.payload?.event?.nativeEvent as InputEvent;\n\n\t\tif ( 'insertFromPaste' !== nativeEvent?.inputType ) {\n\t\t\treturn { ...state };\n\t\t}\n\n\t\tconst value = state.value?.startsWith( '#' )\n\t\t\t? state.value.slice( 1 ).toUpperCase()\n\t\t\t: state.value?.toUpperCase();\n\n\t\treturn { ...state, value };\n\t};\n\n\treturn (\n\t\t<ColorHexInputControl\n\t\t\tprefix={\n\t\t\t\t<Spacer\n\t\t\t\t\tas={ Text }\n\t\t\t\t\tmarginLeft={ space( 3.5 ) }\n\t\t\t\t\tcolor={ COLORS.ui.theme }\n\t\t\t\t\tlineHeight={ 1 }\n\t\t\t\t>\n\t\t\t\t\t#\n\t\t\t\t</Spacer>\n\t\t\t}\n\t\t\tvalue={ color.toHex().slice( 1 ).toUpperCase() }\n\t\t\tonChange={ handleChange }\n\t\t\tmaxLength={ enableAlpha ? 9 : 7 }\n\t\t\tlabel={ __( 'Hex color' ) }\n\t\t\thideLabelFromVision\n\t\t\t__unstableStateReducer={ stateReducer }\n\t\t/>\n\t);\n};\n"]}
|