@wordpress/components 22.0.0 → 22.1.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 +42 -0
- package/build/angle-picker-control/index.js +3 -1
- package/build/angle-picker-control/index.js.map +1 -1
- package/build/autocomplete/index.js +7 -3
- package/build/autocomplete/index.js.map +1 -1
- package/build/border-box-control/border-box-control/component.js +1 -1
- package/build/border-box-control/border-box-control/component.js.map +1 -1
- package/build/border-box-control/border-box-control/hook.js +13 -1
- package/build/border-box-control/border-box-control/hook.js.map +1 -1
- package/build/border-box-control/border-box-control-split-controls/hook.js +11 -1
- package/build/border-box-control/border-box-control-split-controls/hook.js.map +1 -1
- package/build/border-control/border-control/component.js +2 -2
- package/build/border-control/border-control/component.js.map +1 -1
- package/build/border-control/border-control/hook.js +11 -1
- package/build/border-control/border-control/hook.js.map +1 -1
- package/build/border-control/border-control-dropdown/component.js +1 -1
- package/build/border-control/border-control-dropdown/component.js.map +1 -1
- package/build/border-control/border-control-dropdown/hook.js +10 -2
- package/build/border-control/border-control-dropdown/hook.js.map +1 -1
- package/build/color-palette/index.js +1 -1
- package/build/color-palette/index.js.map +1 -1
- package/build/color-picker/input-with-slider.js +17 -3
- package/build/color-picker/input-with-slider.js.map +1 -1
- package/build/custom-select-control/index.js +5 -2
- package/build/custom-select-control/index.js.map +1 -1
- package/build/dashicon/index.js +17 -2
- package/build/dashicon/index.js.map +1 -1
- package/build/draggable/index.js +58 -38
- package/build/draggable/index.js.map +1 -1
- package/build/draggable/types.js +6 -0
- package/build/draggable/types.js.map +1 -0
- package/build/flex/flex/hook.js +2 -3
- package/build/flex/flex/hook.js.map +1 -1
- package/build/focal-point-picker/focal-point.js +2 -12
- package/build/focal-point-picker/focal-point.js.map +1 -1
- package/build/focal-point-picker/styles/focal-point-style.js +11 -51
- package/build/focal-point-picker/styles/focal-point-style.js.map +1 -1
- package/build/font-size-picker/constants.js +41 -0
- package/build/font-size-picker/constants.js.map +1 -0
- package/build/font-size-picker/font-size-picker-select.js +97 -0
- package/build/font-size-picker/font-size-picker-select.js.map +1 -0
- package/build/font-size-picker/font-size-picker-toggle-group.js +50 -0
- package/build/font-size-picker/font-size-picker-toggle-group.js.map +1 -0
- package/build/font-size-picker/index.js +39 -76
- package/build/font-size-picker/index.js.map +1 -1
- package/build/font-size-picker/utils.js +17 -89
- package/build/font-size-picker/utils.js.map +1 -1
- package/build/form-token-field/index.js +9 -6
- package/build/form-token-field/index.js.map +1 -1
- package/build/higher-order/navigate-regions/index.js +3 -0
- package/build/higher-order/navigate-regions/index.js.map +1 -1
- package/build/icon/index.js +3 -2
- package/build/icon/index.js.map +1 -1
- package/build/index.js +8 -0
- package/build/index.js.map +1 -1
- package/build/menu-group/index.js +17 -3
- package/build/menu-group/index.js.map +1 -1
- package/build/menu-group/types.js +6 -0
- package/build/menu-group/types.js.map +1 -0
- package/build/navigator/navigator-screen/component.js +9 -5
- package/build/navigator/navigator-screen/component.js.map +1 -1
- package/build/palette-edit/index.js +3 -1
- package/build/palette-edit/index.js.map +1 -1
- package/build/popover/index.js +8 -4
- package/build/popover/index.js.map +1 -1
- package/build/range-control/styles/range-control-styles.js +47 -57
- package/build/range-control/styles/range-control-styles.js.map +1 -1
- package/build/spinner/styles.js +4 -4
- package/build/spinner/styles.js.map +1 -1
- package/build/tab-panel/index.js +3 -4
- package/build/tab-panel/index.js.map +1 -1
- package/build/toggle-group-control/toggle-group-control/component.js +1 -0
- package/build/toggle-group-control/toggle-group-control/component.js.map +1 -1
- package/build/toggle-group-control/toggle-group-control/styles.js +11 -6
- package/build/toggle-group-control/toggle-group-control/styles.js.map +1 -1
- package/build/tools-panel/styles.js +14 -14
- package/build/tools-panel/styles.js.map +1 -1
- package/build/tools-panel/tools-panel-item/hook.js +9 -5
- package/build/tools-panel/tools-panel-item/hook.js.map +1 -1
- package/build/utils/colors-values.js +3 -2
- package/build/utils/colors-values.js.map +1 -1
- package/build/utils/input/base.js +2 -2
- package/build/utils/input/base.js.map +1 -1
- package/build/view/index.js.map +1 -1
- package/build-module/angle-picker-control/index.js +2 -1
- package/build-module/angle-picker-control/index.js.map +1 -1
- package/build-module/autocomplete/index.js +7 -3
- package/build-module/autocomplete/index.js.map +1 -1
- package/build-module/border-box-control/border-box-control/component.js +1 -1
- package/build-module/border-box-control/border-box-control/component.js.map +1 -1
- package/build-module/border-box-control/border-box-control/hook.js +13 -1
- 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/hook.js +11 -1
- package/build-module/border-box-control/border-box-control-split-controls/hook.js.map +1 -1
- package/build-module/border-control/border-control/component.js +2 -2
- package/build-module/border-control/border-control/component.js.map +1 -1
- package/build-module/border-control/border-control/hook.js +11 -1
- package/build-module/border-control/border-control/hook.js.map +1 -1
- package/build-module/border-control/border-control-dropdown/component.js +1 -1
- package/build-module/border-control/border-control-dropdown/component.js.map +1 -1
- package/build-module/border-control/border-control-dropdown/hook.js +10 -2
- package/build-module/border-control/border-control-dropdown/hook.js.map +1 -1
- package/build-module/color-palette/index.js +1 -1
- package/build-module/color-palette/index.js.map +1 -1
- package/build-module/color-picker/input-with-slider.js +17 -3
- package/build-module/color-picker/input-with-slider.js.map +1 -1
- package/build-module/custom-select-control/index.js +5 -2
- package/build-module/custom-select-control/index.js.map +1 -1
- package/build-module/dashicon/index.js +17 -2
- package/build-module/dashicon/index.js.map +1 -1
- package/build-module/draggable/index.js +59 -38
- package/build-module/draggable/index.js.map +1 -1
- package/build-module/draggable/types.js +2 -0
- package/build-module/draggable/types.js.map +1 -0
- package/build-module/flex/flex/hook.js +2 -3
- package/build-module/flex/flex/hook.js.map +1 -1
- package/build-module/focal-point-picker/focal-point.js +3 -13
- package/build-module/focal-point-picker/focal-point.js.map +1 -1
- package/build-module/focal-point-picker/styles/focal-point-style.js +6 -52
- package/build-module/focal-point-picker/styles/focal-point-style.js.map +1 -1
- package/build-module/font-size-picker/constants.js +31 -0
- package/build-module/font-size-picker/constants.js.map +1 -0
- package/build-module/font-size-picker/font-size-picker-select.js +83 -0
- package/build-module/font-size-picker/font-size-picker-select.js.map +1 -0
- package/build-module/font-size-picker/font-size-picker-toggle-group.js +40 -0
- package/build-module/font-size-picker/font-size-picker-toggle-group.js.map +1 -0
- package/build-module/font-size-picker/index.js +38 -76
- package/build-module/font-size-picker/index.js.map +1 -1
- package/build-module/font-size-picker/utils.js +15 -86
- package/build-module/font-size-picker/utils.js.map +1 -1
- package/build-module/form-token-field/index.js +9 -6
- package/build-module/form-token-field/index.js.map +1 -1
- package/build-module/higher-order/navigate-regions/index.js +3 -0
- package/build-module/higher-order/navigate-regions/index.js.map +1 -1
- package/build-module/icon/index.js +3 -2
- package/build-module/icon/index.js.map +1 -1
- package/build-module/index.js +1 -0
- package/build-module/index.js.map +1 -1
- package/build-module/menu-group/index.js +20 -2
- package/build-module/menu-group/index.js.map +1 -1
- package/build-module/menu-group/types.js +2 -0
- package/build-module/menu-group/types.js.map +1 -0
- package/build-module/navigator/navigator-screen/component.js +9 -5
- package/build-module/navigator/navigator-screen/component.js.map +1 -1
- package/build-module/palette-edit/index.js +3 -1
- package/build-module/palette-edit/index.js.map +1 -1
- package/build-module/popover/index.js +8 -4
- package/build-module/popover/index.js.map +1 -1
- package/build-module/range-control/styles/range-control-styles.js +47 -57
- package/build-module/range-control/styles/range-control-styles.js.map +1 -1
- package/build-module/spinner/styles.js +4 -4
- package/build-module/spinner/styles.js.map +1 -1
- package/build-module/tab-panel/index.js +4 -5
- package/build-module/tab-panel/index.js.map +1 -1
- package/build-module/toggle-group-control/toggle-group-control/component.js +1 -0
- package/build-module/toggle-group-control/toggle-group-control/component.js.map +1 -1
- package/build-module/toggle-group-control/toggle-group-control/styles.js +12 -6
- package/build-module/toggle-group-control/toggle-group-control/styles.js.map +1 -1
- package/build-module/tools-panel/styles.js +14 -14
- package/build-module/tools-panel/styles.js.map +1 -1
- package/build-module/tools-panel/tools-panel-item/hook.js +9 -5
- package/build-module/tools-panel/tools-panel-item/hook.js.map +1 -1
- package/build-module/utils/colors-values.js +3 -2
- package/build-module/utils/colors-values.js.map +1 -1
- package/build-module/utils/input/base.js +2 -2
- package/build-module/utils/input/base.js.map +1 -1
- package/build-module/view/index.js.map +1 -1
- package/build-style/style-rtl.css +72 -44
- package/build-style/style.css +72 -44
- package/build-types/border-box-control/border-box-control/component.d.ts +4 -4
- package/build-types/border-box-control/border-box-control/component.d.ts.map +1 -1
- package/build-types/border-box-control/border-box-control/hook.d.ts +6 -6
- package/build-types/border-box-control/border-box-control/hook.d.ts.map +1 -1
- package/build-types/border-box-control/border-box-control-linked-button/component.d.ts +4 -2
- package/build-types/border-box-control/border-box-control-linked-button/component.d.ts.map +1 -1
- package/build-types/border-box-control/border-box-control-split-controls/component.d.ts +3 -3
- package/build-types/border-box-control/border-box-control-split-controls/hook.d.ts +5 -5
- 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/component.d.ts +3 -2
- package/build-types/border-box-control/border-box-control-visualizer/component.d.ts.map +1 -1
- package/build-types/border-box-control/stories/index.d.ts +3 -3
- package/build-types/border-box-control/types.d.ts +5 -38
- package/build-types/border-box-control/types.d.ts.map +1 -1
- package/build-types/border-control/border-control/component.d.ts +4 -2
- package/build-types/border-control/border-control/component.d.ts.map +1 -1
- package/build-types/border-control/border-control/hook.d.ts +5 -5
- package/build-types/border-control/border-control/hook.d.ts.map +1 -1
- package/build-types/border-control/border-control-dropdown/component.d.ts +3 -3
- package/build-types/border-control/border-control-dropdown/component.d.ts.map +1 -1
- package/build-types/border-control/border-control-dropdown/hook.d.ts +5 -5
- package/build-types/border-control/border-control-dropdown/hook.d.ts.map +1 -1
- package/build-types/border-control/stories/index.d.ts +24 -12
- package/build-types/border-control/stories/index.d.ts.map +1 -1
- package/build-types/border-control/types.d.ts +10 -51
- package/build-types/border-control/types.d.ts.map +1 -1
- package/build-types/color-palette/index.d.ts +16 -2
- package/build-types/color-palette/index.d.ts.map +1 -1
- package/build-types/color-palette/stories/index.d.ts +31 -2
- package/build-types/color-palette/stories/index.d.ts.map +1 -1
- package/build-types/color-palette/types.d.ts +14 -10
- package/build-types/color-palette/types.d.ts.map +1 -1
- package/build-types/color-picker/input-with-slider.d.ts.map +1 -1
- package/build-types/custom-select-control/index.d.ts.map +1 -1
- package/build-types/dashicon/index.d.ts +6 -1
- package/build-types/dashicon/index.d.ts.map +1 -1
- package/build-types/date-time/types.d.ts +0 -16
- package/build-types/date-time/types.d.ts.map +1 -1
- package/build-types/draggable/index.d.ts +42 -66
- package/build-types/draggable/index.d.ts.map +1 -1
- package/build-types/draggable/stories/index.d.ts +12 -0
- package/build-types/draggable/stories/index.d.ts.map +1 -0
- package/build-types/draggable/types.d.ts +58 -0
- package/build-types/draggable/types.d.ts.map +1 -0
- package/build-types/flex/flex/hook.d.ts.map +1 -1
- package/build-types/focal-point-picker/focal-point.d.ts.map +1 -1
- package/build-types/focal-point-picker/styles/focal-point-picker-style.d.ts +1 -1
- package/build-types/focal-point-picker/styles/focal-point-style.d.ts +1 -12
- package/build-types/focal-point-picker/styles/focal-point-style.d.ts.map +1 -1
- package/build-types/font-size-picker/constants.d.ts +15 -0
- package/build-types/font-size-picker/constants.d.ts.map +1 -0
- package/build-types/font-size-picker/font-size-picker-select.d.ts +5 -0
- package/build-types/font-size-picker/font-size-picker-select.d.ts.map +1 -0
- package/build-types/font-size-picker/font-size-picker-toggle-group.d.ts +5 -0
- package/build-types/font-size-picker/font-size-picker-toggle-group.d.ts.map +1 -0
- package/build-types/font-size-picker/index.d.ts.map +1 -1
- package/build-types/font-size-picker/types.d.ts +13 -13
- package/build-types/font-size-picker/types.d.ts.map +1 -1
- package/build-types/font-size-picker/utils.d.ts +6 -18
- package/build-types/font-size-picker/utils.d.ts.map +1 -1
- package/build-types/form-token-field/index.d.ts.map +1 -1
- package/build-types/icon/index.d.ts +1 -1
- package/build-types/icon/index.d.ts.map +1 -1
- package/build-types/menu-group/index.d.ts +21 -1
- package/build-types/menu-group/index.d.ts.map +1 -1
- package/build-types/menu-group/test/index.d.ts +2 -0
- package/build-types/menu-group/test/index.d.ts.map +1 -0
- package/build-types/menu-group/types.d.ts +23 -0
- package/build-types/menu-group/types.d.ts.map +1 -0
- package/build-types/navigator/navigator-screen/component.d.ts.map +1 -1
- package/build-types/popover/index.d.ts.map +1 -1
- package/build-types/tab-panel/index.d.ts.map +1 -1
- package/build-types/toggle-group-control/stories/index.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control/styles.d.ts +1 -2
- package/build-types/toggle-group-control/toggle-group-control/styles.d.ts.map +1 -1
- package/build-types/toggle-group-control/types.d.ts +2 -1
- package/build-types/toggle-group-control/types.d.ts.map +1 -1
- package/build-types/tools-panel/tools-panel-item/hook.d.ts.map +1 -1
- package/build-types/unit-control/index.d.ts +1 -1
- package/build-types/utils/colors-values.d.ts +1 -0
- package/build-types/utils/colors-values.d.ts.map +1 -1
- package/build-types/view/index.d.ts +1 -1
- package/build-types/view/index.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/angle-picker-control/index.js +2 -1
- package/src/autocomplete/index.js +12 -3
- package/src/autocomplete/style.scss +1 -1
- package/src/base-field/test/__snapshots__/index.js.snap +9 -7
- package/src/base-field/test/index.js +27 -15
- package/src/border-box-control/border-box-control/README.md +5 -17
- package/src/border-box-control/border-box-control/component.tsx +1 -1
- package/src/border-box-control/border-box-control/hook.ts +18 -4
- package/src/border-box-control/border-box-control-split-controls/hook.ts +10 -0
- package/src/border-box-control/types.ts +32 -58
- package/src/border-control/border-control/README.md +4 -17
- package/src/border-control/border-control/component.tsx +2 -2
- package/src/border-control/border-control/hook.ts +10 -0
- package/src/border-control/border-control-dropdown/component.tsx +7 -6
- package/src/border-control/border-control-dropdown/hook.ts +9 -1
- package/src/border-control/types.ts +43 -80
- package/src/card/test/__snapshots__/index.tsx.snap +64 -368
- package/src/card/test/index.tsx +2 -2
- package/src/checkbox-control/style.scss +3 -3
- package/src/color-palette/README.md +12 -16
- package/src/color-palette/index.tsx +1 -1
- package/src/color-palette/style.scss +1 -1
- package/src/color-palette/types.ts +14 -10
- package/src/color-picker/input-with-slider.tsx +13 -2
- package/src/custom-select-control/index.js +7 -0
- package/src/custom-select-control/stories/index.js +1 -0
- package/src/custom-select-control/style.scss +6 -1
- package/src/custom-select-control/test/index.js +39 -0
- package/src/dashicon/index.js +21 -2
- package/src/date-time/date/test/index.tsx +2 -2
- package/src/date-time/types.ts +0 -19
- package/src/divider/test/index.tsx +4 -4
- package/src/draggable/README.md +13 -18
- package/src/draggable/{index.js → index.tsx} +71 -47
- package/src/draggable/stories/index.tsx +83 -0
- package/src/draggable/types.ts +58 -0
- package/src/drop-zone/style.scss +1 -1
- package/src/flex/flex/hook.ts +0 -3
- package/src/flex/test/index.tsx +29 -3
- package/src/focal-point-picker/focal-point.tsx +2 -24
- package/src/focal-point-picker/styles/focal-point-style.ts +8 -32
- package/src/font-size-picker/constants.ts +37 -0
- package/src/font-size-picker/font-size-picker-select.tsx +98 -0
- package/src/font-size-picker/font-size-picker-toggle-group.tsx +41 -0
- package/src/font-size-picker/index.tsx +55 -118
- package/src/font-size-picker/test/index.tsx +253 -44
- package/src/font-size-picker/test/utils.ts +58 -98
- package/src/font-size-picker/types.ts +25 -16
- package/src/font-size-picker/utils.ts +16 -102
- package/src/form-toggle/style.scss +3 -3
- package/src/form-token-field/index.tsx +13 -5
- package/src/form-token-field/style.scss +2 -2
- package/src/form-token-field/test/index.tsx +6 -6
- package/src/higher-order/navigate-regions/index.js +4 -0
- package/src/higher-order/navigate-regions/style.scss +72 -20
- package/src/higher-order/with-notices/test/index.js +1 -1
- package/src/icon/index.tsx +3 -2
- package/src/icon/test/index.js +10 -0
- package/src/index.js +1 -0
- package/src/item-group/stories/index.js +1 -1
- package/src/menu-group/{index.js → index.tsx} +22 -3
- package/src/menu-group/test/{index.js → index.tsx} +0 -0
- package/src/menu-group/types.ts +23 -0
- package/src/menu-item/style.scss +1 -1
- package/src/mobile/bottom-sheet/test/range-cell.native.js +4 -4
- package/src/mobile/html-text-input/test/index.native.js +2 -2
- package/src/mobile/link-settings/test/edit.native.js +29 -29
- package/src/mobile/link-settings/test/link-settings-navigation.native.js +5 -5
- package/src/navigator/navigator-screen/component.tsx +8 -3
- package/src/notice/README.md +2 -1
- package/src/notice/style.scss +1 -1
- package/src/palette-edit/index.js +3 -0
- package/src/panel/style.scss +1 -1
- package/src/popover/index.tsx +18 -7
- package/src/range-control/styles/range-control-styles.ts +2 -2
- package/src/resizable-box/style.scss +2 -2
- package/src/scrollable/test/index.tsx +7 -3
- package/src/search-control/style.scss +1 -1
- package/src/snackbar/style.scss +2 -2
- package/src/spacer/test/index.tsx +33 -3
- package/src/spinner/styles.ts +1 -1
- package/src/surface/test/index.tsx +12 -12
- package/src/tab-panel/index.tsx +9 -6
- package/src/tab-panel/style.scss +4 -5
- package/src/text/test/index.tsx +4 -4
- package/src/toggle-group-control/stories/index.tsx +2 -0
- package/src/toggle-group-control/test/__snapshots__/index.tsx.snap +6 -8
- package/src/toggle-group-control/test/index.tsx +29 -17
- package/src/toggle-group-control/toggle-group-control/README.md +8 -1
- package/src/toggle-group-control/toggle-group-control/component.tsx +1 -1
- package/src/toggle-group-control/toggle-group-control/styles.ts +22 -16
- package/src/toggle-group-control/types.ts +2 -1
- package/src/tools-panel/styles.ts +1 -1
- package/src/tools-panel/tools-panel-item/hook.ts +6 -1
- package/src/tree-grid/test/index.js +12 -12
- package/src/truncate/test/index.tsx +9 -9
- package/src/ui/form-group/test/index.js +16 -17
- package/src/utils/colors-values.js +4 -2
- package/src/utils/hooks/stories/use-cx.js +1 -1
- package/src/utils/input/base.js +2 -2
- package/src/view/{index.js → index.ts} +0 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/src/draggable/stories/index.js +0 -72
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createElement } from "@wordpress/element";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* WordPress dependencies
|
|
5
|
+
*/
|
|
6
|
+
import { __ } from '@wordpress/i18n';
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { ToggleGroupControl, ToggleGroupControlOption } from '../toggle-group-control';
|
|
12
|
+
import { T_SHIRT_ABBREVIATIONS, T_SHIRT_NAMES } from './constants';
|
|
13
|
+
|
|
14
|
+
const FontSizePickerToggleGroup = props => {
|
|
15
|
+
const {
|
|
16
|
+
fontSizes,
|
|
17
|
+
value,
|
|
18
|
+
__nextHasNoMarginBottom,
|
|
19
|
+
size,
|
|
20
|
+
onChange
|
|
21
|
+
} = props;
|
|
22
|
+
return createElement(ToggleGroupControl, {
|
|
23
|
+
__nextHasNoMarginBottom: __nextHasNoMarginBottom,
|
|
24
|
+
label: __('Font size'),
|
|
25
|
+
hideLabelFromVision: true,
|
|
26
|
+
value: value,
|
|
27
|
+
onChange: onChange,
|
|
28
|
+
isBlock: true,
|
|
29
|
+
size: size
|
|
30
|
+
}, fontSizes.map((fontSize, index) => createElement(ToggleGroupControlOption, {
|
|
31
|
+
key: fontSize.slug,
|
|
32
|
+
value: fontSize.size,
|
|
33
|
+
label: T_SHIRT_ABBREVIATIONS[index],
|
|
34
|
+
"aria-label": fontSize.name || T_SHIRT_NAMES[index],
|
|
35
|
+
showTooltip: true
|
|
36
|
+
})));
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export default FontSizePickerToggleGroup;
|
|
40
|
+
//# sourceMappingURL=font-size-picker-toggle-group.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/font-size-picker/font-size-picker-toggle-group.tsx"],"names":["__","ToggleGroupControl","ToggleGroupControlOption","T_SHIRT_ABBREVIATIONS","T_SHIRT_NAMES","FontSizePickerToggleGroup","props","fontSizes","value","__nextHasNoMarginBottom","size","onChange","map","fontSize","index","slug","name"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;;AACA,SACCC,kBADD,EAECC,wBAFD,QAGO,yBAHP;AAIA,SAASC,qBAAT,EAAgCC,aAAhC,QAAqD,aAArD;;AAGA,MAAMC,yBAAyB,GAAKC,KAAF,IAA6C;AAC9E,QAAM;AAAEC,IAAAA,SAAF;AAAaC,IAAAA,KAAb;AAAoBC,IAAAA,uBAApB;AAA6CC,IAAAA,IAA7C;AAAmDC,IAAAA;AAAnD,MAAgEL,KAAtE;AACA,SACC,cAAC,kBAAD;AACC,IAAA,uBAAuB,EAAGG,uBAD3B;AAEC,IAAA,KAAK,EAAGT,EAAE,CAAE,WAAF,CAFX;AAGC,IAAA,mBAAmB,MAHpB;AAIC,IAAA,KAAK,EAAGQ,KAJT;AAKC,IAAA,QAAQ,EAAGG,QALZ;AAMC,IAAA,OAAO,MANR;AAOC,IAAA,IAAI,EAAGD;AAPR,KASGH,SAAS,CAACK,GAAV,CAAe,CAAEC,QAAF,EAAYC,KAAZ,KAChB,cAAC,wBAAD;AACC,IAAA,GAAG,EAAGD,QAAQ,CAACE,IADhB;AAEC,IAAA,KAAK,EAAGF,QAAQ,CAACH,IAFlB;AAGC,IAAA,KAAK,EAAGP,qBAAqB,CAAEW,KAAF,CAH9B;AAIC,kBAAaD,QAAQ,CAACG,IAAT,IAAiBZ,aAAa,CAAEU,KAAF,CAJ5C;AAKC,IAAA,WAAW;AALZ,IADC,CATH,CADD;AAqBA,CAvBD;;AAyBA,eAAeT,yBAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport {\n\tToggleGroupControl,\n\tToggleGroupControlOption,\n} from '../toggle-group-control';\nimport { T_SHIRT_ABBREVIATIONS, T_SHIRT_NAMES } from './constants';\nimport type { FontSizePickerToggleGroupProps } from './types';\n\nconst FontSizePickerToggleGroup = ( props: FontSizePickerToggleGroupProps ) => {\n\tconst { fontSizes, value, __nextHasNoMarginBottom, size, onChange } = props;\n\treturn (\n\t\t<ToggleGroupControl\n\t\t\t__nextHasNoMarginBottom={ __nextHasNoMarginBottom }\n\t\t\tlabel={ __( 'Font size' ) }\n\t\t\thideLabelFromVision\n\t\t\tvalue={ value }\n\t\t\tonChange={ onChange }\n\t\t\tisBlock\n\t\t\tsize={ size }\n\t\t>\n\t\t\t{ fontSizes.map( ( fontSize, index ) => (\n\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\tkey={ fontSize.slug }\n\t\t\t\t\tvalue={ fontSize.size }\n\t\t\t\t\tlabel={ T_SHIRT_ABBREVIATIONS[ index ] }\n\t\t\t\t\taria-label={ fontSize.name || T_SHIRT_NAMES[ index ] }\n\t\t\t\t\tshowTooltip\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t</ToggleGroupControl>\n\t);\n};\n\nexport default FontSizePickerToggleGroup;\n"]}
|
|
@@ -8,7 +8,7 @@ import { createElement } from "@wordpress/element";
|
|
|
8
8
|
* WordPress dependencies
|
|
9
9
|
*/
|
|
10
10
|
import deprecated from '@wordpress/deprecated';
|
|
11
|
-
import { __
|
|
11
|
+
import { __ } from '@wordpress/i18n';
|
|
12
12
|
import { settings } from '@wordpress/icons';
|
|
13
13
|
import { useState, useMemo, forwardRef } from '@wordpress/element';
|
|
14
14
|
/**
|
|
@@ -19,13 +19,14 @@ import Button from '../button';
|
|
|
19
19
|
import RangeControl from '../range-control';
|
|
20
20
|
import { Flex, FlexItem } from '../flex';
|
|
21
21
|
import { default as UnitControl, parseQuantityAndUnitFromRawValue, useCustomUnits } from '../unit-control';
|
|
22
|
-
import CustomSelectControl from '../custom-select-control';
|
|
23
22
|
import { VisuallyHidden } from '../visually-hidden';
|
|
24
|
-
import {
|
|
25
|
-
import { getFontSizeOptions, getSelectedOption, isSimpleCssValue, CUSTOM_FONT_SIZE } from './utils';
|
|
23
|
+
import { getCommonSizeUnit } from './utils';
|
|
26
24
|
import { HStack } from '../h-stack';
|
|
27
25
|
import { Container, HeaderHint, HeaderLabel, Controls, ResetButton } from './styles';
|
|
28
26
|
import { Spacer } from '../spacer';
|
|
27
|
+
import FontSizePickerSelect from './font-size-picker-select';
|
|
28
|
+
import FontSizePickerToggleGroup from './font-size-picker-toggle-group';
|
|
29
|
+
import { T_SHIRT_NAMES } from './constants';
|
|
29
30
|
|
|
30
31
|
const UnforwardedFontSizePicker = (props, ref) => {
|
|
31
32
|
var _fontSizes$;
|
|
@@ -54,59 +55,39 @@ const UnforwardedFontSizePicker = (props, ref) => {
|
|
|
54
55
|
const units = useCustomUnits({
|
|
55
56
|
availableUnits: ['px', 'em', 'rem']
|
|
56
57
|
});
|
|
57
|
-
/**
|
|
58
|
-
* The main font size UI displays a toggle group when the presets are less
|
|
59
|
-
* than six and a select control when they are more.
|
|
60
|
-
*/
|
|
61
|
-
|
|
62
|
-
const fontSizesContainComplexValues = fontSizes.some(_ref => {
|
|
63
|
-
let {
|
|
64
|
-
size: sizeArg
|
|
65
|
-
} = _ref;
|
|
66
|
-
return !isSimpleCssValue(sizeArg);
|
|
67
|
-
});
|
|
68
58
|
const shouldUseSelectControl = fontSizes.length > 5;
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
const isCustomValue = selectedOption.slug === CUSTOM_FONT_SIZE;
|
|
59
|
+
const selectedFontSize = fontSizes.find(fontSize => fontSize.size === value);
|
|
60
|
+
const isCustomValue = !!value && !selectedFontSize;
|
|
72
61
|
const [showCustomValueControl, setShowCustomValueControl] = useState(!disableCustomFontSizes && isCustomValue);
|
|
73
62
|
const headerHint = useMemo(() => {
|
|
74
63
|
if (showCustomValueControl) {
|
|
75
|
-
return
|
|
76
|
-
} // If we have a custom value that is not available in the font sizes,
|
|
77
|
-
// show it as a hint as long as it's a simple CSS value.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (isCustomValue) {
|
|
81
|
-
return value !== undefined && isSimpleCssValue(value) && `(${value})`;
|
|
64
|
+
return __('Custom');
|
|
82
65
|
}
|
|
83
66
|
|
|
84
|
-
if (shouldUseSelectControl) {
|
|
85
|
-
|
|
86
|
-
|
|
67
|
+
if (!shouldUseSelectControl) {
|
|
68
|
+
if (selectedFontSize) {
|
|
69
|
+
return selectedFontSize.name || T_SHIRT_NAMES[fontSizes.indexOf(selectedFontSize)];
|
|
70
|
+
}
|
|
87
71
|
|
|
72
|
+
return '';
|
|
73
|
+
}
|
|
88
74
|
|
|
89
|
-
|
|
75
|
+
const commonUnit = getCommonSizeUnit(fontSizes);
|
|
90
76
|
|
|
91
|
-
if (
|
|
92
|
-
|
|
93
|
-
hint += `(${unit})`;
|
|
77
|
+
if (commonUnit) {
|
|
78
|
+
return `(${commonUnit})`;
|
|
94
79
|
}
|
|
95
80
|
|
|
96
|
-
return
|
|
97
|
-
}, [showCustomValueControl,
|
|
81
|
+
return '';
|
|
82
|
+
}, [showCustomValueControl, shouldUseSelectControl, selectedFontSize, fontSizes]);
|
|
98
83
|
|
|
99
|
-
if (
|
|
84
|
+
if (fontSizes.length === 0 && disableCustomFontSizes) {
|
|
100
85
|
return null;
|
|
101
|
-
} //
|
|
102
|
-
// for ToggleGroupControl.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const currentFontSizeSR = sprintf( // translators: %s: Currently selected font size.
|
|
106
|
-
__('Currently selected font size: %s'), selectedOption.name); // If neither the value or first font size is a string, then FontSizePicker
|
|
86
|
+
} // If neither the value or first font size is a string, then FontSizePicker
|
|
107
87
|
// operates in a legacy "unitless" mode where UnitControl can only be used
|
|
108
88
|
// to select px values and onChange() is always called with number values.
|
|
109
89
|
|
|
90
|
+
|
|
110
91
|
const hasUnits = typeof value === 'string' || typeof ((_fontSizes$ = fontSizes[0]) === null || _fontSizes$ === void 0 ? void 0 : _fontSizes$.size) === 'string';
|
|
111
92
|
const [valueQuantity, valueUnit] = parseQuantityAndUnitFromRawValue(value, units);
|
|
112
93
|
const isValueUnitRelative = !!valueUnit && ['em', 'rem'].includes(valueUnit);
|
|
@@ -132,51 +113,32 @@ const UnforwardedFontSizePicker = (props, ref) => {
|
|
|
132
113
|
}))), createElement(Controls, {
|
|
133
114
|
className: "components-font-size-picker__controls",
|
|
134
115
|
__nextHasNoMarginBottom: __nextHasNoMarginBottom
|
|
135
|
-
}, !!fontSizes.length && shouldUseSelectControl && !showCustomValueControl && createElement(
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
value: options.find(option => option.key === selectedOption.slug),
|
|
143
|
-
onChange: _ref2 => {
|
|
144
|
-
let {
|
|
145
|
-
selectedItem
|
|
146
|
-
} = _ref2;
|
|
147
|
-
|
|
148
|
-
if (selectedItem.size === undefined) {
|
|
116
|
+
}, !!fontSizes.length && shouldUseSelectControl && !showCustomValueControl && createElement(FontSizePickerSelect, {
|
|
117
|
+
fontSizes: fontSizes,
|
|
118
|
+
value: value,
|
|
119
|
+
disableCustomFontSizes: disableCustomFontSizes,
|
|
120
|
+
size: size,
|
|
121
|
+
onChange: newValue => {
|
|
122
|
+
if (newValue === undefined) {
|
|
149
123
|
onChange === null || onChange === void 0 ? void 0 : onChange(undefined);
|
|
150
124
|
} else {
|
|
151
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(hasUnits ?
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (selectedItem.key === CUSTOM_FONT_SIZE) {
|
|
155
|
-
setShowCustomValueControl(true);
|
|
125
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(hasUnits ? newValue : Number(newValue), fontSizes.find(fontSize => fontSize.size === newValue));
|
|
156
126
|
}
|
|
157
127
|
},
|
|
158
|
-
|
|
159
|
-
}), !shouldUseSelectControl && !showCustomValueControl && createElement(
|
|
160
|
-
|
|
161
|
-
label: __('Font size'),
|
|
162
|
-
hideLabelFromVision: true,
|
|
128
|
+
onSelectCustom: () => setShowCustomValueControl(true)
|
|
129
|
+
}), !shouldUseSelectControl && !showCustomValueControl && createElement(FontSizePickerToggleGroup, {
|
|
130
|
+
fontSizes: fontSizes,
|
|
163
131
|
value: value,
|
|
132
|
+
__nextHasNoMarginBottom: __nextHasNoMarginBottom,
|
|
133
|
+
size: size,
|
|
164
134
|
onChange: newValue => {
|
|
165
135
|
if (newValue === undefined) {
|
|
166
136
|
onChange === null || onChange === void 0 ? void 0 : onChange(undefined);
|
|
167
137
|
} else {
|
|
168
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(hasUnits ? newValue : Number(newValue));
|
|
138
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(hasUnits ? newValue : Number(newValue), fontSizes.find(fontSize => fontSize.size === newValue));
|
|
169
139
|
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
size: size
|
|
173
|
-
}, options.map(option => createElement(ToggleGroupControlOption, {
|
|
174
|
-
key: option.key,
|
|
175
|
-
value: option.value,
|
|
176
|
-
label: option.label,
|
|
177
|
-
"aria-label": option.name,
|
|
178
|
-
showTooltip: true
|
|
179
|
-
}))), !disableCustomFontSizes && showCustomValueControl && createElement(Flex, {
|
|
140
|
+
}
|
|
141
|
+
}), !disableCustomFontSizes && showCustomValueControl && createElement(Flex, {
|
|
180
142
|
className: "components-font-size-picker__custom-size-control"
|
|
181
143
|
}, createElement(FlexItem, {
|
|
182
144
|
isBlock: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/font-size-picker/index.tsx"],"names":["deprecated","__","sprintf","settings","useState","useMemo","forwardRef","Button","RangeControl","Flex","FlexItem","default","UnitControl","parseQuantityAndUnitFromRawValue","useCustomUnits","CustomSelectControl","VisuallyHidden","ToggleGroupControl","ToggleGroupControlOption","getFontSizeOptions","getSelectedOption","isSimpleCssValue","CUSTOM_FONT_SIZE","HStack","Container","HeaderHint","HeaderLabel","Controls","ResetButton","Spacer","UnforwardedFontSizePicker","props","ref","__nextHasNoMarginBottom","fallbackFontSize","fontSizes","disableCustomFontSizes","onChange","size","value","withSlider","withReset","since","version","hint","units","availableUnits","fontSizesContainComplexValues","some","sizeArg","shouldUseSelectControl","length","options","selectedOption","isCustomValue","slug","showCustomValueControl","setShowCustomValueControl","headerHint","undefined","name","unit","currentFontSizeSR","hasUnits","valueQuantity","valueUnit","isValueUnitRelative","includes","find","option","key","selectedItem","Number","newValue","map","label","parseInt","FontSizePicker"],"mappings":";;AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,uBAAvB;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,QAAT,QAAyB,kBAAzB;AACA,SAASC,QAAT,EAAmBC,OAAnB,EAA4BC,UAA5B,QAA8C,oBAA9C;AAEA;AACA;AACA;;AACA,OAAOC,MAAP,MAAmB,WAAnB;AACA,OAAOC,YAAP,MAAyB,kBAAzB;AACA,SAASC,IAAT,EAAeC,QAAf,QAA+B,SAA/B;AACA,SACCC,OAAO,IAAIC,WADZ,EAECC,gCAFD,EAGCC,cAHD,QAIO,iBAJP;AAKA,OAAOC,mBAAP,MAAgC,0BAAhC;AACA,SAASC,cAAT,QAA+B,oBAA/B;AACA,SACCC,kBADD,EAECC,wBAFD,QAGO,yBAHP;AAIA,SACCC,kBADD,EAECC,iBAFD,EAGCC,gBAHD,EAICC,gBAJD,QAKO,SALP;AAMA,SAASC,MAAT,QAAuB,YAAvB;AAMA,SACCC,SADD,EAECC,UAFD,EAGCC,WAHD,EAICC,QAJD,EAKCC,WALD,QAMO,UANP;AAOA,SAASC,MAAT,QAAuB,WAAvB;;AAEA,MAAMC,yBAAyB,GAAG,CACjCC,KADiC,EAEjCC,GAFiC,KAG7B;AAAA;;AACJ,QAAM;AACL;AACAC,IAAAA,uBAAuB,GAAG,KAFrB;AAGLC,IAAAA,gBAHK;AAILC,IAAAA,SAAS,GAAG,EAJP;AAKLC,IAAAA,sBAAsB,GAAG,KALpB;AAMLC,IAAAA,QANK;AAOLC,IAAAA,IAAI,GAAG,SAPF;AAQLC,IAAAA,KARK;AASLC,IAAAA,UAAU,GAAG,KATR;A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R,IAAAA,QAAQ,WAAR,YAAAA,QAAQ,CAAIsB,SAAJ,CAAR;AACA,KAJF;AAKC,IAAA,OAAO,MALR;AAMC,IAAA,OAAO,EAAC,WANT;AAOC,IAAA,IAAI,EAAGrB;AAPR,KASGrC,EAAE,CAAE,OAAF,CATL,CADD,CAxDF,CAtEF,CAjCD,CADD;AAmLA,CA3SD;;AA6SA,OAAO,MAAM4E,cAAc,GAAGvE,UAAU,CAAEwB,yBAAF,CAAjC;AAEP,eAAe+C,cAAf","sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { settings } from '@wordpress/icons';\nimport { useState, useMemo, forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport Button from '../button';\nimport RangeControl from '../range-control';\nimport { Flex, FlexItem } from '../flex';\nimport {\n\tdefault as UnitControl,\n\tparseQuantityAndUnitFromRawValue,\n\tuseCustomUnits,\n} from '../unit-control';\nimport CustomSelectControl from '../custom-select-control';\nimport { VisuallyHidden } from '../visually-hidden';\nimport {\n\tToggleGroupControl,\n\tToggleGroupControlOption,\n} from '../toggle-group-control';\nimport {\n\tgetFontSizeOptions,\n\tgetSelectedOption,\n\tisSimpleCssValue,\n\tCUSTOM_FONT_SIZE,\n} from './utils';\nimport { HStack } from '../h-stack';\nimport type {\n\tFontSizePickerProps,\n\tFontSizeSelectOption,\n\tFontSizeToggleGroupOption,\n} from './types';\nimport {\n\tContainer,\n\tHeaderHint,\n\tHeaderLabel,\n\tControls,\n\tResetButton,\n} from './styles';\nimport { Spacer } from '../spacer';\n\nconst UnforwardedFontSizePicker = (\n\tprops: FontSizePickerProps,\n\tref: ForwardedRef< any >\n) => {\n\tconst {\n\t\t/** Start opting into the new margin-free styles that will become the default in a future version. */\n\t\t__nextHasNoMarginBottom = false,\n\t\tfallbackFontSize,\n\t\tfontSizes = [],\n\t\tdisableCustomFontSizes = false,\n\t\tonChange,\n\t\tsize = 'default',\n\t\tvalue,\n\t\twithSlider = false,\n\t\twithReset = true,\n\t} = props;\n\tif ( ! __nextHasNoMarginBottom ) {\n\t\tdeprecated( 'Bottom margin styles for wp.components.FontSizePicker', {\n\t\t\tsince: '6.1',\n\t\t\tversion: '6.4',\n\t\t\thint: 'Set the `__nextHasNoMarginBottom` prop to true to start opting into the new styles, which will become the default in a future version.',\n\t\t} );\n\t}\n\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: [ 'px', 'em', 'rem' ],\n\t} );\n\n\t/**\n\t * The main font size UI displays a toggle group when the presets are less\n\t * than six and a select control when they are more.\n\t */\n\tconst fontSizesContainComplexValues = fontSizes.some(\n\t\t( { size: sizeArg } ) => ! isSimpleCssValue( sizeArg )\n\t);\n\tconst shouldUseSelectControl = fontSizes.length > 5;\n\tconst options = useMemo(\n\t\t() =>\n\t\t\tgetFontSizeOptions(\n\t\t\t\tshouldUseSelectControl,\n\t\t\t\tfontSizes,\n\t\t\t\tdisableCustomFontSizes\n\t\t\t),\n\t\t[ shouldUseSelectControl, fontSizes, disableCustomFontSizes ]\n\t);\n\tconst selectedOption = getSelectedOption( fontSizes, value );\n\tconst isCustomValue = selectedOption.slug === CUSTOM_FONT_SIZE;\n\tconst [ showCustomValueControl, setShowCustomValueControl ] = useState(\n\t\t! disableCustomFontSizes && isCustomValue\n\t);\n\tconst headerHint = useMemo( () => {\n\t\tif ( showCustomValueControl ) {\n\t\t\treturn `(${ __( 'Custom' ) })`;\n\t\t}\n\n\t\t// If we have a custom value that is not available in the font sizes,\n\t\t// show it as a hint as long as it's a simple CSS value.\n\t\tif ( isCustomValue ) {\n\t\t\treturn (\n\t\t\t\tvalue !== undefined &&\n\t\t\t\tisSimpleCssValue( value ) &&\n\t\t\t\t`(${ value })`\n\t\t\t);\n\t\t}\n\t\tif ( shouldUseSelectControl ) {\n\t\t\treturn (\n\t\t\t\tselectedOption?.size !== undefined &&\n\t\t\t\tisSimpleCssValue( selectedOption?.size ) &&\n\t\t\t\t`(${ selectedOption?.size })`\n\t\t\t);\n\t\t}\n\n\t\t// Calculate the `hint` for toggle group control.\n\t\tlet hint = selectedOption?.name || selectedOption.slug;\n\t\tif (\n\t\t\t! fontSizesContainComplexValues &&\n\t\t\ttypeof selectedOption.size === 'string'\n\t\t) {\n\t\t\tconst [ , unit ] = parseQuantityAndUnitFromRawValue(\n\t\t\t\tselectedOption.size,\n\t\t\t\tunits\n\t\t\t);\n\t\t\thint += `(${ unit })`;\n\t\t}\n\t\treturn hint;\n\t}, [\n\t\tshowCustomValueControl,\n\t\tselectedOption?.name,\n\t\tselectedOption?.size,\n\t\tvalue,\n\t\tisCustomValue,\n\t\tshouldUseSelectControl,\n\t\tfontSizesContainComplexValues,\n\t] );\n\n\tif ( ! options ) {\n\t\treturn null;\n\t}\n\n\t// This is used for select control only. We need to add support\n\t// for ToggleGroupControl.\n\tconst currentFontSizeSR = sprintf(\n\t\t// translators: %s: Currently selected font size.\n\t\t__( 'Currently selected font size: %s' ),\n\t\tselectedOption.name\n\t);\n\n\t// If neither the value or first font size is a string, then FontSizePicker\n\t// operates in a legacy \"unitless\" mode where UnitControl can only be used\n\t// to select px values and onChange() is always called with number values.\n\tconst hasUnits =\n\t\ttypeof value === 'string' || typeof fontSizes[ 0 ]?.size === 'string';\n\n\tconst [ valueQuantity, valueUnit ] = parseQuantityAndUnitFromRawValue(\n\t\tvalue,\n\t\tunits\n\t);\n\tconst isValueUnitRelative =\n\t\t!! valueUnit && [ 'em', 'rem' ].includes( valueUnit );\n\n\treturn (\n\t\t<Container ref={ ref } className=\"components-font-size-picker\">\n\t\t\t<VisuallyHidden as=\"legend\">{ __( 'Font size' ) }</VisuallyHidden>\n\t\t\t<Spacer>\n\t\t\t\t<HStack className=\"components-font-size-picker__header\">\n\t\t\t\t\t<HeaderLabel\n\t\t\t\t\t\taria-label={ `${ __( 'Size' ) } ${ headerHint || '' }` }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Size' ) }\n\t\t\t\t\t\t{ headerHint && (\n\t\t\t\t\t\t\t<HeaderHint className=\"components-font-size-picker__header__hint\">\n\t\t\t\t\t\t\t\t{ headerHint }\n\t\t\t\t\t\t\t</HeaderHint>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</HeaderLabel>\n\t\t\t\t\t{ ! disableCustomFontSizes && (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\t\tshowCustomValueControl\n\t\t\t\t\t\t\t\t\t? __( 'Use size preset' )\n\t\t\t\t\t\t\t\t\t: __( 'Set custom size' )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\ticon={ settings }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tsetShowCustomValueControl(\n\t\t\t\t\t\t\t\t\t! showCustomValueControl\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tisPressed={ showCustomValueControl }\n\t\t\t\t\t\t\tisSmall\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</HStack>\n\t\t\t</Spacer>\n\t\t\t<Controls\n\t\t\t\tclassName=\"components-font-size-picker__controls\"\n\t\t\t\t__nextHasNoMarginBottom={ __nextHasNoMarginBottom }\n\t\t\t>\n\t\t\t\t{ !! fontSizes.length &&\n\t\t\t\t\tshouldUseSelectControl &&\n\t\t\t\t\t! showCustomValueControl && (\n\t\t\t\t\t\t<CustomSelectControl\n\t\t\t\t\t\t\t__nextUnconstrainedWidth\n\t\t\t\t\t\t\tclassName=\"components-font-size-picker__select\"\n\t\t\t\t\t\t\tlabel={ __( 'Font size' ) }\n\t\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\t\tdescribedBy={ currentFontSizeSR }\n\t\t\t\t\t\t\toptions={ options as FontSizeSelectOption[] }\n\t\t\t\t\t\t\tvalue={ ( options as FontSizeSelectOption[] ).find(\n\t\t\t\t\t\t\t\t( option ) => option.key === selectedOption.slug\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tonChange={ ( {\n\t\t\t\t\t\t\t\tselectedItem,\n\t\t\t\t\t\t\t}: {\n\t\t\t\t\t\t\t\tselectedItem: FontSizeSelectOption;\n\t\t\t\t\t\t\t} ) => {\n\t\t\t\t\t\t\t\tif ( selectedItem.size === undefined ) {\n\t\t\t\t\t\t\t\t\tonChange?.( undefined );\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tonChange?.(\n\t\t\t\t\t\t\t\t\t\thasUnits\n\t\t\t\t\t\t\t\t\t\t\t? selectedItem.size\n\t\t\t\t\t\t\t\t\t\t\t: Number( selectedItem.size )\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\tif ( selectedItem.key === CUSTOM_FONT_SIZE ) {\n\t\t\t\t\t\t\t\t\tsetShowCustomValueControl( true );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tsize={ size }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t{ ! shouldUseSelectControl && ! showCustomValueControl && (\n\t\t\t\t\t<ToggleGroupControl\n\t\t\t\t\t\t__nextHasNoMarginBottom={ __nextHasNoMarginBottom }\n\t\t\t\t\t\tlabel={ __( 'Font size' ) }\n\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t\tonChange={ ( newValue ) => {\n\t\t\t\t\t\t\tif ( newValue === undefined ) {\n\t\t\t\t\t\t\t\tonChange?.( undefined );\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tonChange?.(\n\t\t\t\t\t\t\t\t\thasUnits ? newValue : Number( newValue )\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tisBlock\n\t\t\t\t\t\tsize={ size }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ ( options as FontSizeToggleGroupOption[] ).map(\n\t\t\t\t\t\t\t( option ) => (\n\t\t\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\t\t\tkey={ option.key }\n\t\t\t\t\t\t\t\t\tvalue={ option.value }\n\t\t\t\t\t\t\t\t\tlabel={ option.label }\n\t\t\t\t\t\t\t\t\taria-label={ option.name }\n\t\t\t\t\t\t\t\t\tshowTooltip={ true }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t) }\n\t\t\t\t\t</ToggleGroupControl>\n\t\t\t\t) }\n\t\t\t\t{ ! disableCustomFontSizes && showCustomValueControl && (\n\t\t\t\t\t<Flex className=\"components-font-size-picker__custom-size-control\">\n\t\t\t\t\t\t<FlexItem isBlock>\n\t\t\t\t\t\t\t<UnitControl\n\t\t\t\t\t\t\t\tlabel={ __( 'Custom' ) }\n\t\t\t\t\t\t\t\tlabelPosition=\"top\"\n\t\t\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t\t\t\tonChange={ ( newValue ) => {\n\t\t\t\t\t\t\t\t\tif ( newValue === undefined ) {\n\t\t\t\t\t\t\t\t\t\tonChange?.( undefined );\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tonChange?.(\n\t\t\t\t\t\t\t\t\t\t\thasUnits\n\t\t\t\t\t\t\t\t\t\t\t\t? newValue\n\t\t\t\t\t\t\t\t\t\t\t\t: parseInt( newValue, 10 )\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\tsize={ size }\n\t\t\t\t\t\t\t\tunits={ hasUnits ? units : [] }\n\t\t\t\t\t\t\t\tmin={ 0 }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t{ withSlider && (\n\t\t\t\t\t\t\t<FlexItem isBlock>\n\t\t\t\t\t\t\t\t<Spacer marginX={ 2 } marginBottom={ 0 }>\n\t\t\t\t\t\t\t\t\t<RangeControl\n\t\t\t\t\t\t\t\t\t\t__nextHasNoMarginBottom={\n\t\t\t\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tclassName=\"components-font-size-picker__custom-input\"\n\t\t\t\t\t\t\t\t\t\tlabel={ __( 'Custom Size' ) }\n\t\t\t\t\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\t\t\t\t\tvalue={ valueQuantity }\n\t\t\t\t\t\t\t\t\t\tinitialPosition={ fallbackFontSize }\n\t\t\t\t\t\t\t\t\t\twithInputField={ false }\n\t\t\t\t\t\t\t\t\t\tonChange={ ( newValue ) => {\n\t\t\t\t\t\t\t\t\t\t\tif ( newValue === undefined ) {\n\t\t\t\t\t\t\t\t\t\t\t\tonChange?.( undefined );\n\t\t\t\t\t\t\t\t\t\t\t} else if ( hasUnits ) {\n\t\t\t\t\t\t\t\t\t\t\t\tonChange?.(\n\t\t\t\t\t\t\t\t\t\t\t\t\tnewValue +\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t( valueUnit ?? 'px' )\n\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\t\tonChange?.( newValue );\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\tmin={ 0 }\n\t\t\t\t\t\t\t\t\t\tmax={ isValueUnitRelative ? 10 : 100 }\n\t\t\t\t\t\t\t\t\t\tstep={ isValueUnitRelative ? 0.1 : 1 }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</Spacer>\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ withReset && (\n\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t<ResetButton\n\t\t\t\t\t\t\t\t\tdisabled={ value === undefined }\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tonChange?.( undefined );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\tisSmall\n\t\t\t\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\t\t\t\tsize={ size }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Reset' ) }\n\t\t\t\t\t\t\t\t</ResetButton>\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Flex>\n\t\t\t\t) }\n\t\t\t</Controls>\n\t\t</Container>\n\t);\n};\n\nexport const FontSizePicker = forwardRef( UnforwardedFontSizePicker );\n\nexport default FontSizePicker;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/font-size-picker/index.tsx"],"names":["deprecated","__","settings","useState","useMemo","forwardRef","Button","RangeControl","Flex","FlexItem","default","UnitControl","parseQuantityAndUnitFromRawValue","useCustomUnits","VisuallyHidden","getCommonSizeUnit","HStack","Container","HeaderHint","HeaderLabel","Controls","ResetButton","Spacer","FontSizePickerSelect","FontSizePickerToggleGroup","T_SHIRT_NAMES","UnforwardedFontSizePicker","props","ref","__nextHasNoMarginBottom","fallbackFontSize","fontSizes","disableCustomFontSizes","onChange","size","value","withSlider","withReset","since","version","hint","units","availableUnits","shouldUseSelectControl","length","selectedFontSize","find","fontSize","isCustomValue","showCustomValueControl","setShowCustomValueControl","headerHint","name","indexOf","commonUnit","hasUnits","valueQuantity","valueUnit","isValueUnitRelative","includes","newValue","undefined","Number","parseInt","FontSizePicker"],"mappings":";;AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,uBAAvB;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,QAAT,QAAyB,kBAAzB;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B;AACtBtB,QAAAA,QAAQ,SAAR,IAAAA,QAAQ,WAAR,YAAAA,QAAQ,CACP2B,QAAQ,IACLH,SADK,aACLA,SADK,cACLA,SADK,GACQ,IADR,CADD,CAAR;AAIA,OALM,MAKA;AACNxB,QAAAA,QAAQ,SAAR,IAAAA,QAAQ,WAAR,YAAAA,QAAQ,CAAI2B,QAAJ,CAAR;AACA;AACD,KArBF;AAsBC,IAAA,GAAG,EAAG,CAtBP;AAuBC,IAAA,GAAG,EAAGF,mBAAmB,GAAG,EAAH,GAAQ,GAvBlC;AAwBC,IAAA,IAAI,EAAGA,mBAAmB,GAAG,GAAH,GAAS;AAxBpC,IADD,CADD,CAxBF,EAuDGrB,SAAS,IACV,cAAC,QAAD,QACC,cAAC,WAAD;AACC,IAAA,QAAQ,EAAGF,KAAK,KAAK0B,SADtB;AAEC,IAAA,OAAO,EAAG,MAAM;AACf5B,MAAAA,QAAQ,SAAR,IAAAA,QAAQ,WAAR,YAAAA,QAAQ,CAAI4B,SAAJ,CAAR;AACA,KAJF;AAKC,IAAA,OAAO,MALR;AAMC,IAAA,OAAO,EAAC,WANT;AAOC,IAAA,IAAI,EAAG3B;AAPR,KASGjC,EAAE,CAAE,OAAF,CATL,CADD,CAxDF,CAtDF,CAjCD,CADD;AAmKA,CAvPD;;AAyPA,OAAO,MAAM+D,cAAc,GAAG3D,UAAU,CAAEqB,yBAAF,CAAjC;AAEP,eAAesC,cAAf","sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\nimport { __ } from '@wordpress/i18n';\nimport { settings } from '@wordpress/icons';\nimport { useState, useMemo, forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport Button from '../button';\nimport RangeControl from '../range-control';\nimport { Flex, FlexItem } from '../flex';\nimport {\n\tdefault as UnitControl,\n\tparseQuantityAndUnitFromRawValue,\n\tuseCustomUnits,\n} from '../unit-control';\nimport { VisuallyHidden } from '../visually-hidden';\nimport { getCommonSizeUnit } from './utils';\nimport { HStack } from '../h-stack';\nimport type { FontSizePickerProps } from './types';\nimport {\n\tContainer,\n\tHeaderHint,\n\tHeaderLabel,\n\tControls,\n\tResetButton,\n} from './styles';\nimport { Spacer } from '../spacer';\nimport FontSizePickerSelect from './font-size-picker-select';\nimport FontSizePickerToggleGroup from './font-size-picker-toggle-group';\nimport { T_SHIRT_NAMES } from './constants';\n\nconst UnforwardedFontSizePicker = (\n\tprops: FontSizePickerProps,\n\tref: ForwardedRef< any >\n) => {\n\tconst {\n\t\t/** Start opting into the new margin-free styles that will become the default in a future version. */\n\t\t__nextHasNoMarginBottom = false,\n\t\tfallbackFontSize,\n\t\tfontSizes = [],\n\t\tdisableCustomFontSizes = false,\n\t\tonChange,\n\t\tsize = 'default',\n\t\tvalue,\n\t\twithSlider = false,\n\t\twithReset = true,\n\t} = props;\n\n\tif ( ! __nextHasNoMarginBottom ) {\n\t\tdeprecated( 'Bottom margin styles for wp.components.FontSizePicker', {\n\t\t\tsince: '6.1',\n\t\t\tversion: '6.4',\n\t\t\thint: 'Set the `__nextHasNoMarginBottom` prop to true to start opting into the new styles, which will become the default in a future version.',\n\t\t} );\n\t}\n\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: [ 'px', 'em', 'rem' ],\n\t} );\n\n\tconst shouldUseSelectControl = fontSizes.length > 5;\n\tconst selectedFontSize = fontSizes.find(\n\t\t( fontSize ) => fontSize.size === value\n\t);\n\tconst isCustomValue = !! value && ! selectedFontSize;\n\n\tconst [ showCustomValueControl, setShowCustomValueControl ] = useState(\n\t\t! disableCustomFontSizes && isCustomValue\n\t);\n\n\tconst headerHint = useMemo( () => {\n\t\tif ( showCustomValueControl ) {\n\t\t\treturn __( 'Custom' );\n\t\t}\n\n\t\tif ( ! shouldUseSelectControl ) {\n\t\t\tif ( selectedFontSize ) {\n\t\t\t\treturn (\n\t\t\t\t\tselectedFontSize.name ||\n\t\t\t\t\tT_SHIRT_NAMES[ fontSizes.indexOf( selectedFontSize ) ]\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn '';\n\t\t}\n\n\t\tconst commonUnit = getCommonSizeUnit( fontSizes );\n\t\tif ( commonUnit ) {\n\t\t\treturn `(${ commonUnit })`;\n\t\t}\n\n\t\treturn '';\n\t}, [\n\t\tshowCustomValueControl,\n\t\tshouldUseSelectControl,\n\t\tselectedFontSize,\n\t\tfontSizes,\n\t] );\n\n\tif ( fontSizes.length === 0 && disableCustomFontSizes ) {\n\t\treturn null;\n\t}\n\n\t// If neither the value or first font size is a string, then FontSizePicker\n\t// operates in a legacy \"unitless\" mode where UnitControl can only be used\n\t// to select px values and onChange() is always called with number values.\n\tconst hasUnits =\n\t\ttypeof value === 'string' || typeof fontSizes[ 0 ]?.size === 'string';\n\n\tconst [ valueQuantity, valueUnit ] = parseQuantityAndUnitFromRawValue(\n\t\tvalue,\n\t\tunits\n\t);\n\tconst isValueUnitRelative =\n\t\t!! valueUnit && [ 'em', 'rem' ].includes( valueUnit );\n\n\treturn (\n\t\t<Container ref={ ref } className=\"components-font-size-picker\">\n\t\t\t<VisuallyHidden as=\"legend\">{ __( 'Font size' ) }</VisuallyHidden>\n\t\t\t<Spacer>\n\t\t\t\t<HStack className=\"components-font-size-picker__header\">\n\t\t\t\t\t<HeaderLabel\n\t\t\t\t\t\taria-label={ `${ __( 'Size' ) } ${ headerHint || '' }` }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Size' ) }\n\t\t\t\t\t\t{ headerHint && (\n\t\t\t\t\t\t\t<HeaderHint className=\"components-font-size-picker__header__hint\">\n\t\t\t\t\t\t\t\t{ headerHint }\n\t\t\t\t\t\t\t</HeaderHint>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</HeaderLabel>\n\t\t\t\t\t{ ! disableCustomFontSizes && (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\t\tshowCustomValueControl\n\t\t\t\t\t\t\t\t\t? __( 'Use size preset' )\n\t\t\t\t\t\t\t\t\t: __( 'Set custom size' )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\ticon={ settings }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tsetShowCustomValueControl(\n\t\t\t\t\t\t\t\t\t! showCustomValueControl\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tisPressed={ showCustomValueControl }\n\t\t\t\t\t\t\tisSmall\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</HStack>\n\t\t\t</Spacer>\n\t\t\t<Controls\n\t\t\t\tclassName=\"components-font-size-picker__controls\"\n\t\t\t\t__nextHasNoMarginBottom={ __nextHasNoMarginBottom }\n\t\t\t>\n\t\t\t\t{ !! fontSizes.length &&\n\t\t\t\t\tshouldUseSelectControl &&\n\t\t\t\t\t! showCustomValueControl && (\n\t\t\t\t\t\t<FontSizePickerSelect\n\t\t\t\t\t\t\tfontSizes={ fontSizes }\n\t\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t\t\tdisableCustomFontSizes={ disableCustomFontSizes }\n\t\t\t\t\t\t\tsize={ size }\n\t\t\t\t\t\t\tonChange={ ( newValue ) => {\n\t\t\t\t\t\t\t\tif ( newValue === undefined ) {\n\t\t\t\t\t\t\t\t\tonChange?.( undefined );\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tonChange?.(\n\t\t\t\t\t\t\t\t\t\thasUnits\n\t\t\t\t\t\t\t\t\t\t\t? newValue\n\t\t\t\t\t\t\t\t\t\t\t: Number( newValue ),\n\t\t\t\t\t\t\t\t\t\tfontSizes.find(\n\t\t\t\t\t\t\t\t\t\t\t( fontSize ) =>\n\t\t\t\t\t\t\t\t\t\t\t\tfontSize.size === newValue\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} }\n\t\t\t\t\t\t\tonSelectCustom={ () =>\n\t\t\t\t\t\t\t\tsetShowCustomValueControl( true )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t{ ! shouldUseSelectControl && ! showCustomValueControl && (\n\t\t\t\t\t<FontSizePickerToggleGroup\n\t\t\t\t\t\tfontSizes={ fontSizes }\n\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t\t__nextHasNoMarginBottom={ __nextHasNoMarginBottom }\n\t\t\t\t\t\tsize={ size }\n\t\t\t\t\t\tonChange={ ( newValue ) => {\n\t\t\t\t\t\t\tif ( newValue === undefined ) {\n\t\t\t\t\t\t\t\tonChange?.( undefined );\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tonChange?.(\n\t\t\t\t\t\t\t\t\thasUnits ? newValue : Number( newValue ),\n\t\t\t\t\t\t\t\t\tfontSizes.find(\n\t\t\t\t\t\t\t\t\t\t( fontSize ) =>\n\t\t\t\t\t\t\t\t\t\t\tfontSize.size === newValue\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}\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ ! disableCustomFontSizes && showCustomValueControl && (\n\t\t\t\t\t<Flex className=\"components-font-size-picker__custom-size-control\">\n\t\t\t\t\t\t<FlexItem isBlock>\n\t\t\t\t\t\t\t<UnitControl\n\t\t\t\t\t\t\t\tlabel={ __( 'Custom' ) }\n\t\t\t\t\t\t\t\tlabelPosition=\"top\"\n\t\t\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t\t\t\tonChange={ ( newValue ) => {\n\t\t\t\t\t\t\t\t\tif ( newValue === undefined ) {\n\t\t\t\t\t\t\t\t\t\tonChange?.( undefined );\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tonChange?.(\n\t\t\t\t\t\t\t\t\t\t\thasUnits\n\t\t\t\t\t\t\t\t\t\t\t\t? newValue\n\t\t\t\t\t\t\t\t\t\t\t\t: parseInt( newValue, 10 )\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\tsize={ size }\n\t\t\t\t\t\t\t\tunits={ hasUnits ? units : [] }\n\t\t\t\t\t\t\t\tmin={ 0 }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t{ withSlider && (\n\t\t\t\t\t\t\t<FlexItem isBlock>\n\t\t\t\t\t\t\t\t<Spacer marginX={ 2 } marginBottom={ 0 }>\n\t\t\t\t\t\t\t\t\t<RangeControl\n\t\t\t\t\t\t\t\t\t\t__nextHasNoMarginBottom={\n\t\t\t\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tclassName=\"components-font-size-picker__custom-input\"\n\t\t\t\t\t\t\t\t\t\tlabel={ __( 'Custom Size' ) }\n\t\t\t\t\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\t\t\t\t\tvalue={ valueQuantity }\n\t\t\t\t\t\t\t\t\t\tinitialPosition={ fallbackFontSize }\n\t\t\t\t\t\t\t\t\t\twithInputField={ false }\n\t\t\t\t\t\t\t\t\t\tonChange={ ( newValue ) => {\n\t\t\t\t\t\t\t\t\t\t\tif ( newValue === undefined ) {\n\t\t\t\t\t\t\t\t\t\t\t\tonChange?.( undefined );\n\t\t\t\t\t\t\t\t\t\t\t} else if ( hasUnits ) {\n\t\t\t\t\t\t\t\t\t\t\t\tonChange?.(\n\t\t\t\t\t\t\t\t\t\t\t\t\tnewValue +\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t( valueUnit ?? 'px' )\n\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\t\tonChange?.( newValue );\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\tmin={ 0 }\n\t\t\t\t\t\t\t\t\t\tmax={ isValueUnitRelative ? 10 : 100 }\n\t\t\t\t\t\t\t\t\t\tstep={ isValueUnitRelative ? 0.1 : 1 }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</Spacer>\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ withReset && (\n\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t<ResetButton\n\t\t\t\t\t\t\t\t\tdisabled={ value === undefined }\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tonChange?.( undefined );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\tisSmall\n\t\t\t\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\t\t\t\tsize={ size }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Reset' ) }\n\t\t\t\t\t\t\t\t</ResetButton>\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Flex>\n\t\t\t\t) }\n\t\t\t</Controls>\n\t\t</Container>\n\t);\n};\n\nexport const FontSizePicker = forwardRef( UnforwardedFontSizePicker );\n\nexport default FontSizePicker;\n"]}
|
|
@@ -1,38 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { __ } from '@wordpress/i18n';
|
|
5
|
-
/**
|
|
6
|
-
* Internal dependencies
|
|
7
|
-
*/
|
|
8
4
|
|
|
9
|
-
const DEFAULT_FONT_SIZE = 'default';
|
|
10
|
-
const DEFAULT_FONT_SIZE_OPTION = {
|
|
11
|
-
slug: DEFAULT_FONT_SIZE,
|
|
12
|
-
name: __('Default')
|
|
13
|
-
};
|
|
14
|
-
export const CUSTOM_FONT_SIZE = 'custom';
|
|
15
|
-
const CUSTOM_FONT_SIZE_OPTION = {
|
|
16
|
-
slug: CUSTOM_FONT_SIZE,
|
|
17
|
-
name: __('Custom')
|
|
18
|
-
};
|
|
19
5
|
/**
|
|
20
|
-
*
|
|
21
|
-
* alias as a label of the font size. The label assumes that the font sizes
|
|
22
|
-
* are ordered accordingly - from smallest to largest.
|
|
6
|
+
* Internal dependencies
|
|
23
7
|
*/
|
|
24
|
-
|
|
25
|
-
const FONT_SIZES_ALIASES = [
|
|
26
|
-
/* translators: S stands for 'small' and is a size label. */
|
|
27
|
-
__('S'),
|
|
28
|
-
/* translators: M stands for 'medium' and is a size label. */
|
|
29
|
-
__('M'),
|
|
30
|
-
/* translators: L stands for 'large' and is a size label. */
|
|
31
|
-
__('L'),
|
|
32
|
-
/* translators: XL stands for 'extra large' and is a size label. */
|
|
33
|
-
__('XL'),
|
|
34
|
-
/* translators: XXL stands for 'extra extra large' and is a size label. */
|
|
35
|
-
__('XXL')];
|
|
8
|
+
import { parseQuantityAndUnitFromRawValue } from '../unit-control';
|
|
36
9
|
/**
|
|
37
10
|
* Some themes use css vars for their font sizes, so until we
|
|
38
11
|
* have the way of calculating them don't display them.
|
|
@@ -46,69 +19,25 @@ export function isSimpleCssValue(value) {
|
|
|
46
19
|
return sizeRegex.test(String(value));
|
|
47
20
|
}
|
|
48
21
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
22
|
+
* If all of the given font sizes have the same unit (e.g. 'px'), return that
|
|
23
|
+
* unit. Otherwise return null.
|
|
51
24
|
*
|
|
52
|
-
* @param
|
|
53
|
-
* @
|
|
54
|
-
* @param disableCustomFontSizes Flag that indicates if custom font sizes are disabled.
|
|
55
|
-
* @return Array of font sizes in proper format for the used control.
|
|
25
|
+
* @param fontSizes List of font sizes.
|
|
26
|
+
* @return The common unit, or null.
|
|
56
27
|
*/
|
|
57
28
|
|
|
58
|
-
export function
|
|
59
|
-
|
|
29
|
+
export function getCommonSizeUnit(fontSizes) {
|
|
30
|
+
const [firstFontSize, ...otherFontSizes] = fontSizes;
|
|
31
|
+
|
|
32
|
+
if (!firstFontSize) {
|
|
60
33
|
return null;
|
|
61
34
|
}
|
|
62
35
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const options = [DEFAULT_FONT_SIZE_OPTION, ...optionsArray, ...(disableCustomFontSizes ? [] : [CUSTOM_FONT_SIZE_OPTION])];
|
|
68
|
-
return options.map(_ref => {
|
|
69
|
-
let {
|
|
70
|
-
slug,
|
|
71
|
-
name,
|
|
72
|
-
size
|
|
73
|
-
} = _ref;
|
|
74
|
-
return {
|
|
75
|
-
key: slug,
|
|
76
|
-
name: name || slug,
|
|
77
|
-
size,
|
|
78
|
-
__experimentalHint: size && isSimpleCssValue(size) && parseFloat(String(size))
|
|
79
|
-
};
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Build options for the toggle group options.
|
|
84
|
-
*
|
|
85
|
-
* @param optionsArray An array of font size options.
|
|
86
|
-
* @param labelAliases An array of alternative labels.
|
|
87
|
-
* @return Remapped optionsArray.
|
|
88
|
-
*/
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
export function getToggleGroupOptions(optionsArray) {
|
|
92
|
-
let labelAliases = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : FONT_SIZES_ALIASES;
|
|
93
|
-
return optionsArray.map((_ref2, index) => {
|
|
94
|
-
let {
|
|
95
|
-
slug,
|
|
96
|
-
size,
|
|
97
|
-
name
|
|
98
|
-
} = _ref2;
|
|
99
|
-
return {
|
|
100
|
-
key: slug,
|
|
101
|
-
value: size,
|
|
102
|
-
label: labelAliases[index],
|
|
103
|
-
name: name || labelAliases[index]
|
|
104
|
-
};
|
|
36
|
+
const [, firstUnit] = parseQuantityAndUnitFromRawValue(firstFontSize.size);
|
|
37
|
+
const areAllSizesSameUnit = otherFontSizes.every(fontSize => {
|
|
38
|
+
const [, unit] = parseQuantityAndUnitFromRawValue(fontSize.size);
|
|
39
|
+
return unit === firstUnit;
|
|
105
40
|
});
|
|
106
|
-
|
|
107
|
-
export function getSelectedOption(fontSizes, value) {
|
|
108
|
-
if (!value) {
|
|
109
|
-
return DEFAULT_FONT_SIZE_OPTION;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return fontSizes.find(font => font.size === value) || CUSTOM_FONT_SIZE_OPTION;
|
|
41
|
+
return areAllSizesSameUnit ? firstUnit : null;
|
|
113
42
|
}
|
|
114
43
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/font-size-picker/utils.ts"],"names":["
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/font-size-picker/utils.ts"],"names":["parseQuantityAndUnitFromRawValue","isSimpleCssValue","value","sizeRegex","test","String","getCommonSizeUnit","fontSizes","firstFontSize","otherFontSizes","firstUnit","size","areAllSizesSameUnit","every","fontSize","unit"],"mappings":"AAAA;AACA;AACA;;AAGA;AACA;AACA;AAEA,SAASA,gCAAT,QAAiD,iBAAjD;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,gBAAT,CACNC,KADM,EAEL;AACD,QAAMC,SAAS,GAAG,gCAAlB;AACA,SAAOA,SAAS,CAACC,IAAV,CAAgBC,MAAM,CAAEH,KAAF,CAAtB,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASI,iBAAT,CAA4BC,SAA5B,EAAoD;AAC1D,QAAM,CAAEC,aAAF,EAAiB,GAAGC,cAApB,IAAuCF,SAA7C;;AACA,MAAK,CAAEC,aAAP,EAAuB;AACtB,WAAO,IAAP;AACA;;AACD,QAAM,GAAIE,SAAJ,IAAkBV,gCAAgC,CACvDQ,aAAa,CAACG,IADyC,CAAxD;AAGA,QAAMC,mBAAmB,GAAGH,cAAc,CAACI,KAAf,CAAwBC,QAAF,IAAgB;AACjE,UAAM,GAAIC,IAAJ,IAAaf,gCAAgC,CAAEc,QAAQ,CAACH,IAAX,CAAnD;AACA,WAAOI,IAAI,KAAKL,SAAhB;AACA,GAH2B,CAA5B;AAIA,SAAOE,mBAAmB,GAAGF,SAAH,GAAe,IAAzC;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { FontSizePickerProps, FontSize } from './types';\nimport { parseQuantityAndUnitFromRawValue } from '../unit-control';\n\n/**\n * Some themes use css vars for their font sizes, so until we\n * have the way of calculating them don't display them.\n *\n * @param value The value that is checked.\n * @return Whether the value is a simple css value.\n */\nexport function isSimpleCssValue(\n\tvalue: NonNullable< FontSizePickerProps[ 'value' ] >\n) {\n\tconst sizeRegex = /^[\\d\\.]+(px|em|rem|vw|vh|%)?$/i;\n\treturn sizeRegex.test( String( value ) );\n}\n\n/**\n * If all of the given font sizes have the same unit (e.g. 'px'), return that\n * unit. Otherwise return null.\n *\n * @param fontSizes List of font sizes.\n * @return The common unit, or null.\n */\nexport function getCommonSizeUnit( fontSizes: FontSize[] ) {\n\tconst [ firstFontSize, ...otherFontSizes ] = fontSizes;\n\tif ( ! firstFontSize ) {\n\t\treturn null;\n\t}\n\tconst [ , firstUnit ] = parseQuantityAndUnitFromRawValue(\n\t\tfirstFontSize.size\n\t);\n\tconst areAllSizesSameUnit = otherFontSizes.every( ( fontSize ) => {\n\t\tconst [ , unit ] = parseQuantityAndUnitFromRawValue( fontSize.size );\n\t\treturn unit === firstUnit;\n\t} );\n\treturn areAllSizesSameUnit ? firstUnit : null;\n}\n"]}
|
|
@@ -158,11 +158,15 @@ export function FormTokenField(props) {
|
|
|
158
158
|
function onKeyDown(event) {
|
|
159
159
|
let preventDefault = false;
|
|
160
160
|
|
|
161
|
-
if (event.defaultPrevented
|
|
161
|
+
if (event.defaultPrevented || // Ignore keydowns from IMEs
|
|
162
|
+
event.nativeEvent.isComposing || // Workaround for Mac Safari where the final Enter/Backspace of an IME composition
|
|
163
|
+
// is `isComposing=false`, even though it's technically still part of the composition.
|
|
164
|
+
// These can only be detected by keyCode.
|
|
165
|
+
event.keyCode === 229) {
|
|
162
166
|
return;
|
|
163
167
|
}
|
|
164
168
|
|
|
165
|
-
switch (event.
|
|
169
|
+
switch (event.key) {
|
|
166
170
|
case 'Backspace':
|
|
167
171
|
preventDefault = handleDeleteKey(deleteTokenBeforeInput);
|
|
168
172
|
break;
|
|
@@ -212,11 +216,10 @@ export function FormTokenField(props) {
|
|
|
212
216
|
}
|
|
213
217
|
|
|
214
218
|
function onKeyPress(event) {
|
|
215
|
-
let preventDefault = false;
|
|
219
|
+
let preventDefault = false;
|
|
216
220
|
|
|
217
|
-
switch (event.
|
|
218
|
-
case
|
|
219
|
-
// Comma.
|
|
221
|
+
switch (event.key) {
|
|
222
|
+
case ',':
|
|
220
223
|
preventDefault = handleCommaKey();
|
|
221
224
|
break;
|
|
222
225
|
|