@wordpress/components 25.13.0 → 25.15.1-next.79a6196f.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 +89 -1
- package/CONTRIBUTING.md +57 -115
- package/LICENSE.md +1 -1
- package/build/base-control/index.js +17 -13
- package/build/base-control/index.js.map +1 -1
- package/build/border-box-control/border-box-control-linked-button/component.js +1 -1
- package/build/border-box-control/border-box-control-linked-button/component.js.map +1 -1
- package/build/border-control/border-control-dropdown/component.js +4 -2
- package/build/border-control/border-control-dropdown/component.js.map +1 -1
- package/build/border-control/border-control-dropdown/hook.js +3 -2
- package/build/border-control/border-control-dropdown/hook.js.map +1 -1
- package/build/border-control/border-control-style-picker/component.js +1 -1
- package/build/border-control/border-control-style-picker/component.js.map +1 -1
- package/build/border-control/styles.js +17 -17
- package/build/border-control/styles.js.map +1 -1
- package/build/box-control/index.js +1 -1
- package/build/box-control/index.js.map +1 -1
- package/build/box-control/linked-button.js +1 -1
- package/build/box-control/linked-button.js.map +1 -1
- package/build/button/index.js +1 -1
- package/build/button/index.js.map +1 -1
- package/build/checkbox-control/index.js +1 -1
- package/build/checkbox-control/index.js.map +1 -1
- package/build/checkbox-control/types.js.map +1 -1
- package/build/color-palette/index.native.js +11 -7
- package/build/color-palette/index.native.js.map +1 -1
- package/build/color-picker/color-copy-button.js +1 -1
- package/build/color-picker/color-copy-button.js.map +1 -1
- package/build/context/wordpress-component.js.map +1 -1
- package/build/custom-select-control-v2/index.js +11 -10
- package/build/custom-select-control-v2/index.js.map +1 -1
- package/build/date-time/date/styles.js +8 -8
- package/build/date-time/date/styles.js.map +1 -1
- package/build/date-time/time/timezone.js +11 -2
- package/build/date-time/time/timezone.js.map +1 -1
- package/build/dimension-control/index.js +2 -0
- package/build/dimension-control/index.js.map +1 -1
- package/build/dimension-control/types.js.map +1 -1
- package/build/dropdown-menu-v2/index.js +205 -159
- package/build/dropdown-menu-v2/index.js.map +1 -1
- package/build/dropdown-menu-v2/styles.js +86 -77
- package/build/dropdown-menu-v2/styles.js.map +1 -1
- package/build/dropdown-menu-v2/types.js.map +1 -1
- package/build/duotone-picker/duotone-picker.js +4 -3
- package/build/duotone-picker/duotone-picker.js.map +1 -1
- package/build/focal-point-picker/controls.js +5 -1
- package/build/focal-point-picker/controls.js.map +1 -1
- package/build/focal-point-picker/index.js +2 -0
- package/build/focal-point-picker/index.js.map +1 -1
- package/build/focal-point-picker/styles/focal-point-picker-style.js +15 -15
- package/build/focal-point-picker/styles/focal-point-picker-style.js.map +1 -1
- package/build/focal-point-picker/types.js.map +1 -1
- package/build/font-size-picker/font-size-picker-select.js +2 -0
- package/build/font-size-picker/font-size-picker-select.js.map +1 -1
- package/build/font-size-picker/font-size-picker-toggle-group.js +2 -0
- package/build/font-size-picker/font-size-picker-toggle-group.js.map +1 -1
- package/build/font-size-picker/index.js +10 -3
- package/build/font-size-picker/index.js.map +1 -1
- package/build/font-size-picker/index.native.js +6 -3
- package/build/font-size-picker/index.native.js.map +1 -1
- package/build/font-size-picker/types.js.map +1 -1
- package/build/form-token-field/index.js +10 -5
- package/build/form-token-field/index.js.map +1 -1
- package/build/form-token-field/token.js +1 -0
- package/build/form-token-field/token.js.map +1 -1
- package/build/gradient-picker/index.js +3 -2
- package/build/gradient-picker/index.js.map +1 -1
- package/build/index.native.js +20 -19
- package/build/index.native.js.map +1 -1
- package/build/input-control/styles/input-control-styles.js +32 -29
- package/build/input-control/styles/input-control-styles.js.map +1 -1
- package/build/input-control/types.js.map +1 -1
- package/build/lock-unlock.js +18 -0
- package/build/lock-unlock.js.map +1 -0
- package/build/mobile/bottom-sheet/index.native.js +8 -0
- package/build/mobile/bottom-sheet/index.native.js.map +1 -1
- package/build/mobile/color-settings/palette.screen.native.js +8 -4
- package/build/mobile/color-settings/palette.screen.native.js.map +1 -1
- package/build/mobile/global-styles-context/utils.native.js +39 -13
- package/build/mobile/global-styles-context/utils.native.js.map +1 -1
- package/build/mobile/image/constants.js +12 -0
- package/build/mobile/image/constants.js.map +1 -0
- package/build/mobile/image/index.native.js +26 -18
- package/build/mobile/image/index.native.js.map +1 -1
- package/build/mobile/keyboard-aware-flat-list/index.android.js +40 -8
- package/build/mobile/keyboard-aware-flat-list/index.android.js.map +1 -1
- package/build/mobile/keyboard-aware-flat-list/index.ios.js +44 -68
- package/build/mobile/keyboard-aware-flat-list/index.ios.js.map +1 -1
- package/build/mobile/keyboard-aware-flat-list/use-scroll-to-element.native.js +39 -0
- package/build/mobile/keyboard-aware-flat-list/use-scroll-to-element.native.js.map +1 -0
- package/build/mobile/keyboard-aware-flat-list/{use-scroll-to-text-input.native.js → use-scroll-to-section.native.js} +22 -29
- package/build/mobile/keyboard-aware-flat-list/use-scroll-to-section.native.js.map +1 -0
- package/build/mobile/keyboard-aware-flat-list/use-scroll.native.js +93 -0
- package/build/mobile/keyboard-aware-flat-list/use-scroll.native.js.map +1 -0
- package/build/mobile/utils/get-px-from-css-unit.native.js +302 -0
- package/build/mobile/utils/get-px-from-css-unit.native.js.map +1 -0
- package/build/modal/index.js +18 -13
- package/build/modal/index.js.map +1 -1
- package/build/navigation/menu/menu-title.js +1 -1
- package/build/navigation/menu/menu-title.js.map +1 -1
- package/build/navigator/navigator-provider/component.js +13 -15
- package/build/navigator/navigator-provider/component.js.map +1 -1
- package/build/navigator/navigator-screen/component.js +23 -63
- package/build/navigator/navigator-screen/component.js.map +1 -1
- package/build/navigator/styles.js +52 -0
- package/build/navigator/styles.js.map +1 -0
- package/build/number-control/index.js +4 -8
- package/build/number-control/index.js.map +1 -1
- package/build/number-control/types.js.map +1 -1
- package/build/palette-edit/index.js +15 -34
- package/build/palette-edit/index.js.map +1 -1
- package/build/private-apis.js +11 -26
- package/build/private-apis.js.map +1 -1
- package/build/private-apis.native.js +21 -0
- package/build/private-apis.native.js.map +1 -0
- package/build/query-controls/author-select.js +3 -1
- package/build/query-controls/author-select.js.map +1 -1
- package/build/query-controls/category-select.js +3 -1
- package/build/query-controls/category-select.js.map +1 -1
- package/build/query-controls/index.js +6 -1
- package/build/query-controls/index.js.map +1 -1
- package/build/query-controls/types.js.map +1 -1
- package/build/radio-control/index.js +1 -0
- package/build/radio-control/index.js.map +1 -1
- package/build/range-control/index.js +1 -1
- package/build/range-control/index.js.map +1 -1
- package/build/select-control/styles/select-control-styles.js +15 -25
- package/build/select-control/styles/select-control-styles.js.map +1 -1
- package/build/slot-fill/index.js +3 -2
- package/build/slot-fill/index.js.map +1 -1
- package/build/slot-fill/types.js.map +1 -1
- package/build/snackbar/types.js.map +1 -1
- package/build/tabs/index.js +18 -1
- package/build/tabs/index.js.map +1 -1
- package/build/tabs/styles.js +3 -3
- package/build/tabs/styles.js.map +1 -1
- package/build/tabs/tab.js +2 -2
- package/build/tabs/tab.js.map +1 -1
- package/build/tabs/tabpanel.js +11 -8
- package/build/tabs/tabpanel.js.map +1 -1
- package/build/tabs/types.js.map +1 -1
- package/build/toggle-group-control/toggle-group-control/component.js +4 -4
- package/build/toggle-group-control/toggle-group-control/component.js.map +1 -1
- package/build/toggle-group-control/toggle-group-control/styles.js +29 -15
- package/build/toggle-group-control/toggle-group-control/styles.js.map +1 -1
- package/build/toggle-group-control/toggle-group-control/utils.js +17 -17
- package/build/toggle-group-control/toggle-group-control/utils.js.map +1 -1
- package/build/toggle-group-control/toggle-group-control-option-base/styles.js +9 -9
- package/build/toggle-group-control/toggle-group-control-option-base/styles.js.map +1 -1
- package/build/tools-panel/tools-panel/component.js +3 -1
- package/build/tools-panel/tools-panel/component.js.map +1 -1
- package/build/tools-panel/tools-panel-header/component.js +9 -8
- package/build/tools-panel/tools-panel-header/component.js.map +1 -1
- package/build/tools-panel/tools-panel-item/hook.js +11 -11
- package/build/tools-panel/tools-panel-item/hook.js.map +1 -1
- package/build/tools-panel/types.js.map +1 -1
- package/build/tooltip/index.js +34 -10
- package/build/tooltip/index.js.map +1 -1
- package/build/tooltip/types.js.map +1 -1
- package/build/truncate/hook.js +10 -4
- package/build/truncate/hook.js.map +1 -1
- package/build/truncate/types.js.map +1 -1
- package/build/unit-control/index.js +1 -1
- package/build/unit-control/index.js.map +1 -1
- package/build/utils/strings.js +34 -3
- package/build/utils/strings.js.map +1 -1
- package/build-module/base-control/index.js +16 -12
- package/build-module/base-control/index.js.map +1 -1
- package/build-module/border-box-control/border-box-control-linked-button/component.js +1 -1
- package/build-module/border-box-control/border-box-control-linked-button/component.js.map +1 -1
- package/build-module/border-control/border-control-dropdown/component.js +4 -2
- package/build-module/border-control/border-control-dropdown/component.js.map +1 -1
- package/build-module/border-control/border-control-dropdown/hook.js +3 -2
- package/build-module/border-control/border-control-dropdown/hook.js.map +1 -1
- package/build-module/border-control/border-control-style-picker/component.js +1 -1
- package/build-module/border-control/border-control-style-picker/component.js.map +1 -1
- package/build-module/border-control/styles.js +17 -17
- package/build-module/border-control/styles.js.map +1 -1
- package/build-module/box-control/index.js +1 -1
- package/build-module/box-control/index.js.map +1 -1
- package/build-module/box-control/linked-button.js +1 -1
- package/build-module/box-control/linked-button.js.map +1 -1
- package/build-module/button/index.js +1 -1
- package/build-module/button/index.js.map +1 -1
- package/build-module/checkbox-control/index.js +1 -1
- package/build-module/checkbox-control/index.js.map +1 -1
- package/build-module/checkbox-control/types.js.map +1 -1
- package/build-module/color-palette/index.native.js +11 -7
- package/build-module/color-palette/index.native.js.map +1 -1
- package/build-module/color-picker/color-copy-button.js +1 -1
- package/build-module/color-picker/color-copy-button.js.map +1 -1
- package/build-module/context/wordpress-component.js.map +1 -1
- package/build-module/custom-select-control-v2/index.js +11 -10
- package/build-module/custom-select-control-v2/index.js.map +1 -1
- package/build-module/date-time/date/styles.js +8 -8
- package/build-module/date-time/date/styles.js.map +1 -1
- package/build-module/date-time/time/timezone.js +11 -2
- package/build-module/date-time/time/timezone.js.map +1 -1
- package/build-module/dimension-control/index.js +2 -0
- package/build-module/dimension-control/index.js.map +1 -1
- package/build-module/dimension-control/types.js.map +1 -1
- package/build-module/dropdown-menu-v2/index.js +201 -154
- package/build-module/dropdown-menu-v2/index.js.map +1 -1
- package/build-module/dropdown-menu-v2/styles.js +68 -61
- package/build-module/dropdown-menu-v2/styles.js.map +1 -1
- package/build-module/dropdown-menu-v2/types.js.map +1 -1
- package/build-module/duotone-picker/duotone-picker.js +4 -3
- package/build-module/duotone-picker/duotone-picker.js.map +1 -1
- package/build-module/focal-point-picker/controls.js +5 -1
- package/build-module/focal-point-picker/controls.js.map +1 -1
- package/build-module/focal-point-picker/index.js +2 -0
- package/build-module/focal-point-picker/index.js.map +1 -1
- package/build-module/focal-point-picker/styles/focal-point-picker-style.js +15 -15
- package/build-module/focal-point-picker/styles/focal-point-picker-style.js.map +1 -1
- package/build-module/focal-point-picker/types.js.map +1 -1
- package/build-module/font-size-picker/font-size-picker-select.js +2 -0
- package/build-module/font-size-picker/font-size-picker-select.js.map +1 -1
- package/build-module/font-size-picker/font-size-picker-toggle-group.js +2 -0
- package/build-module/font-size-picker/font-size-picker-toggle-group.js.map +1 -1
- package/build-module/font-size-picker/index.js +10 -3
- package/build-module/font-size-picker/index.js.map +1 -1
- package/build-module/font-size-picker/index.native.js +5 -2
- package/build-module/font-size-picker/index.native.js.map +1 -1
- package/build-module/font-size-picker/types.js.map +1 -1
- package/build-module/form-token-field/index.js +10 -5
- package/build-module/form-token-field/index.js.map +1 -1
- package/build-module/form-token-field/token.js +1 -0
- package/build-module/form-token-field/token.js.map +1 -1
- package/build-module/gradient-picker/index.js +3 -2
- package/build-module/gradient-picker/index.js.map +1 -1
- package/build-module/index.native.js +6 -3
- package/build-module/index.native.js.map +1 -1
- package/build-module/input-control/styles/input-control-styles.js +31 -29
- package/build-module/input-control/styles/input-control-styles.js.map +1 -1
- package/build-module/input-control/types.js.map +1 -1
- package/build-module/lock-unlock.js +9 -0
- package/build-module/lock-unlock.js.map +1 -0
- package/build-module/mobile/bottom-sheet/index.native.js +9 -1
- package/build-module/mobile/bottom-sheet/index.native.js.map +1 -1
- package/build-module/mobile/color-settings/palette.screen.native.js +8 -4
- package/build-module/mobile/color-settings/palette.screen.native.js.map +1 -1
- package/build-module/mobile/global-styles-context/utils.native.js +38 -13
- package/build-module/mobile/global-styles-context/utils.native.js.map +1 -1
- package/build-module/mobile/image/constants.js +5 -0
- package/build-module/mobile/image/constants.js.map +1 -0
- package/build-module/mobile/image/index.native.js +25 -16
- package/build-module/mobile/image/index.native.js.map +1 -1
- package/build-module/mobile/keyboard-aware-flat-list/index.android.js +40 -6
- package/build-module/mobile/keyboard-aware-flat-list/index.android.js.map +1 -1
- package/build-module/mobile/keyboard-aware-flat-list/index.ios.js +46 -68
- package/build-module/mobile/keyboard-aware-flat-list/index.ios.js.map +1 -1
- package/build-module/mobile/keyboard-aware-flat-list/use-scroll-to-element.native.js +33 -0
- package/build-module/mobile/keyboard-aware-flat-list/use-scroll-to-element.native.js.map +1 -0
- package/build-module/mobile/keyboard-aware-flat-list/{use-scroll-to-text-input.native.js → use-scroll-to-section.native.js} +21 -27
- package/build-module/mobile/keyboard-aware-flat-list/use-scroll-to-section.native.js.map +1 -0
- package/build-module/mobile/keyboard-aware-flat-list/use-scroll.native.js +86 -0
- package/build-module/mobile/keyboard-aware-flat-list/use-scroll.native.js.map +1 -0
- package/build-module/mobile/utils/get-px-from-css-unit.native.js +294 -0
- package/build-module/mobile/utils/get-px-from-css-unit.native.js.map +1 -0
- package/build-module/modal/index.js +18 -13
- package/build-module/modal/index.js.map +1 -1
- package/build-module/navigation/menu/menu-title.js +1 -1
- package/build-module/navigation/menu/menu-title.js.map +1 -1
- package/build-module/navigator/navigator-provider/component.js +3 -16
- package/build-module/navigator/navigator-provider/component.js.map +1 -1
- package/build-module/navigator/navigator-screen/component.js +16 -70
- package/build-module/navigator/navigator-screen/component.js.map +1 -1
- package/build-module/navigator/styles.js +47 -0
- package/build-module/navigator/styles.js.map +1 -0
- package/build-module/number-control/index.js +4 -8
- package/build-module/number-control/index.js.map +1 -1
- package/build-module/number-control/types.js.map +1 -1
- package/build-module/palette-edit/index.js +14 -33
- package/build-module/palette-edit/index.js.map +1 -1
- package/build-module/private-apis.js +10 -23
- package/build-module/private-apis.js.map +1 -1
- package/build-module/private-apis.native.js +14 -0
- package/build-module/private-apis.native.js.map +1 -0
- package/build-module/query-controls/author-select.js +3 -1
- package/build-module/query-controls/author-select.js.map +1 -1
- package/build-module/query-controls/category-select.js +3 -1
- package/build-module/query-controls/category-select.js.map +1 -1
- package/build-module/query-controls/index.js +6 -1
- package/build-module/query-controls/index.js.map +1 -1
- package/build-module/query-controls/types.js.map +1 -1
- package/build-module/radio-control/index.js +1 -0
- package/build-module/radio-control/index.js.map +1 -1
- package/build-module/range-control/index.js +1 -1
- package/build-module/range-control/index.js.map +1 -1
- package/build-module/select-control/styles/select-control-styles.js +15 -25
- package/build-module/select-control/styles/select-control-styles.js.map +1 -1
- package/build-module/slot-fill/index.js +3 -2
- package/build-module/slot-fill/index.js.map +1 -1
- package/build-module/slot-fill/types.js.map +1 -1
- package/build-module/snackbar/types.js.map +1 -1
- package/build-module/tabs/index.js +18 -1
- package/build-module/tabs/index.js.map +1 -1
- package/build-module/tabs/styles.js +3 -3
- package/build-module/tabs/styles.js.map +1 -1
- package/build-module/tabs/tab.js +2 -2
- package/build-module/tabs/tab.js.map +1 -1
- package/build-module/tabs/tabpanel.js +11 -8
- package/build-module/tabs/tabpanel.js.map +1 -1
- package/build-module/tabs/types.js.map +1 -1
- package/build-module/toggle-group-control/toggle-group-control/component.js +4 -4
- 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 +29 -15
- package/build-module/toggle-group-control/toggle-group-control/styles.js.map +1 -1
- package/build-module/toggle-group-control/toggle-group-control/utils.js +17 -17
- package/build-module/toggle-group-control/toggle-group-control/utils.js.map +1 -1
- package/build-module/toggle-group-control/toggle-group-control-option-base/styles.js +9 -9
- package/build-module/toggle-group-control/toggle-group-control-option-base/styles.js.map +1 -1
- package/build-module/tools-panel/tools-panel/component.js +3 -1
- package/build-module/tools-panel/tools-panel/component.js.map +1 -1
- package/build-module/tools-panel/tools-panel-header/component.js +9 -8
- package/build-module/tools-panel/tools-panel-header/component.js.map +1 -1
- package/build-module/tools-panel/tools-panel-item/hook.js +11 -11
- package/build-module/tools-panel/tools-panel-item/hook.js.map +1 -1
- package/build-module/tools-panel/types.js.map +1 -1
- package/build-module/tooltip/index.js +34 -12
- package/build-module/tooltip/index.js.map +1 -1
- package/build-module/tooltip/types.js.map +1 -1
- package/build-module/truncate/hook.js +10 -4
- package/build-module/truncate/hook.js.map +1 -1
- package/build-module/truncate/types.js.map +1 -1
- package/build-module/unit-control/index.js +1 -1
- package/build-module/unit-control/index.js.map +1 -1
- package/build-module/utils/strings.js +32 -2
- package/build-module/utils/strings.js.map +1 -1
- package/build-style/style-rtl.css +30 -6
- package/build-style/style.css +30 -6
- package/build-types/base-control/index.d.ts +3 -27
- package/build-types/base-control/index.d.ts.map +1 -1
- package/build-types/base-control/stories/index.story.d.ts +4 -1
- package/build-types/base-control/stories/index.story.d.ts.map +1 -1
- package/build-types/border-box-control/border-box-control/hook.d.ts +4 -4
- package/build-types/border-box-control/border-box-control-linked-button/hook.d.ts +6 -6
- package/build-types/border-box-control/border-box-control-split-controls/hook.d.ts +4 -4
- package/build-types/border-box-control/border-box-control-visualizer/hook.d.ts +4 -4
- package/build-types/border-box-control/stories/index.story.d.ts +1 -1
- package/build-types/border-control/border-control/hook.d.ts +4 -4
- 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 -4
- package/build-types/border-control/border-control-dropdown/hook.d.ts.map +1 -1
- package/build-types/border-control/border-control-style-picker/hook.d.ts +4 -4
- package/build-types/border-control/stories/index.story.d.ts +6 -6
- package/build-types/border-control/styles.d.ts +1 -1
- package/build-types/border-control/styles.d.ts.map +1 -1
- package/build-types/box-control/stories/index.story.d.ts +42 -42
- package/build-types/box-control/styles/box-control-styles.d.ts +1 -1
- package/build-types/button/deprecated.d.ts +3 -3
- package/build-types/card/card/hook.d.ts +4 -4
- package/build-types/card/card-body/hook.d.ts +4 -4
- package/build-types/card/card-divider/hook.d.ts +4 -4
- package/build-types/card/card-footer/hook.d.ts +4 -4
- package/build-types/card/card-header/hook.d.ts +4 -4
- package/build-types/card/card-media/hook.d.ts +4 -4
- package/build-types/checkbox-control/index.d.ts.map +1 -1
- package/build-types/checkbox-control/types.d.ts +3 -2
- package/build-types/checkbox-control/types.d.ts.map +1 -1
- package/build-types/color-palette/styles.d.ts +2 -2
- package/build-types/color-picker/component.d.ts +2 -2
- package/build-types/color-picker/stories/index.story.d.ts +1 -1
- package/build-types/color-picker/stories/index.story.d.ts.map +1 -1
- package/build-types/color-picker/styles.d.ts +3 -3
- package/build-types/composite/test/index.d.ts.map +1 -0
- package/build-types/context/wordpress-component.d.ts +3 -3
- package/build-types/context/wordpress-component.d.ts.map +1 -1
- package/build-types/custom-select-control-v2/index.d.ts +3 -2
- package/build-types/custom-select-control-v2/index.d.ts.map +1 -1
- package/build-types/custom-select-control-v2/stories/index.story.d.ts +4 -3
- package/build-types/custom-select-control-v2/stories/index.story.d.ts.map +1 -1
- package/build-types/date-time/date/styles.d.ts +3 -3
- package/build-types/date-time/date-time/styles.d.ts +1 -1
- package/build-types/date-time/time/styles.d.ts +4 -4
- package/build-types/date-time/time/timezone.d.ts.map +1 -1
- package/build-types/dimension-control/index.d.ts.map +1 -1
- package/build-types/dimension-control/types.d.ts +6 -0
- package/build-types/dimension-control/types.d.ts.map +1 -1
- package/build-types/dropdown/index.d.ts +1 -1
- package/build-types/dropdown/index.d.ts.map +1 -1
- package/build-types/dropdown/stories/index.story.d.ts +3 -3
- package/build-types/dropdown/stories/index.story.d.ts.map +1 -1
- package/build-types/dropdown-menu/index.d.ts +1 -1
- package/build-types/dropdown-menu/index.d.ts.map +1 -1
- package/build-types/dropdown-menu/stories/index.story.d.ts +2 -2
- package/build-types/dropdown-menu/stories/index.story.d.ts.map +1 -1
- package/build-types/dropdown-menu-v2/index.d.ts +18 -15
- package/build-types/dropdown-menu-v2/index.d.ts.map +1 -1
- package/build-types/dropdown-menu-v2/stories/index.story.d.ts +7 -2
- package/build-types/dropdown-menu-v2/stories/index.story.d.ts.map +1 -1
- package/build-types/dropdown-menu-v2/styles.d.ts +77 -23
- package/build-types/dropdown-menu-v2/styles.d.ts.map +1 -1
- package/build-types/dropdown-menu-v2/types.d.ts +89 -173
- package/build-types/dropdown-menu-v2/types.d.ts.map +1 -1
- package/build-types/duotone-picker/duotone-picker.d.ts.map +1 -1
- package/build-types/elevation/hook.d.ts +4 -4
- package/build-types/flex/flex/hook.d.ts +4 -4
- package/build-types/flex/flex-block/hook.d.ts +4 -4
- package/build-types/flex/flex-item/hook.d.ts +4 -4
- package/build-types/focal-point-picker/controls.d.ts +1 -1
- package/build-types/focal-point-picker/controls.d.ts.map +1 -1
- package/build-types/focal-point-picker/index.d.ts +1 -1
- package/build-types/focal-point-picker/index.d.ts.map +1 -1
- package/build-types/focal-point-picker/stories/index.story.d.ts +8 -4
- package/build-types/focal-point-picker/stories/index.story.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/types.d.ts +7 -0
- package/build-types/focal-point-picker/types.d.ts.map +1 -1
- package/build-types/font-size-picker/font-size-picker-select.d.ts.map +1 -1
- package/build-types/font-size-picker/font-size-picker-toggle-group.d.ts.map +1 -1
- package/build-types/font-size-picker/index.d.ts.map +1 -1
- package/build-types/font-size-picker/styles.d.ts +1 -1
- package/build-types/font-size-picker/types.d.ts +8 -1
- package/build-types/font-size-picker/types.d.ts.map +1 -1
- package/build-types/form-token-field/index.d.ts.map +1 -1
- package/build-types/form-token-field/token.d.ts.map +1 -1
- package/build-types/grid/hook.d.ts +4 -4
- package/build-types/h-stack/hook.d.ts +4 -4
- package/build-types/heading/component.d.ts +1 -1
- package/build-types/heading/hook.d.ts +4 -4
- package/build-types/input-control/styles/input-control-styles.d.ts +11 -0
- package/build-types/input-control/styles/input-control-styles.d.ts.map +1 -1
- package/build-types/input-control/types.d.ts +1 -1
- package/build-types/input-control/types.d.ts.map +1 -1
- package/build-types/item-group/item/hook.d.ts +4 -4
- package/build-types/item-group/item-group/hook.d.ts +4 -4
- package/build-types/lock-unlock.d.ts +3 -0
- package/build-types/lock-unlock.d.ts.map +1 -0
- package/build-types/menu-item/index.d.ts +1 -1
- package/build-types/menu-item/stories/index.story.d.ts +4 -4
- package/build-types/mobile/image/constants.d.ts +5 -0
- package/build-types/mobile/image/constants.d.ts.map +1 -0
- package/build-types/modal/index.d.ts.map +1 -1
- package/build-types/navigation/styles/navigation-styles.d.ts +3 -3
- package/build-types/navigator/navigator-back-button/hook.d.ts +6 -6
- package/build-types/navigator/navigator-button/hook.d.ts +6 -6
- package/build-types/navigator/navigator-provider/component.d.ts.map +1 -1
- package/build-types/navigator/navigator-screen/component.d.ts +1 -7
- package/build-types/navigator/navigator-screen/component.d.ts.map +1 -1
- package/build-types/navigator/styles.d.ts +9 -0
- package/build-types/navigator/styles.d.ts.map +1 -0
- package/build-types/number-control/index.d.ts +1 -1
- package/build-types/number-control/index.d.ts.map +1 -1
- package/build-types/number-control/stories/index.story.d.ts +1 -1
- package/build-types/number-control/types.d.ts +1 -1
- package/build-types/palette-edit/index.d.ts +2 -2
- package/build-types/palette-edit/index.d.ts.map +1 -1
- package/build-types/palette-edit/styles.d.ts +3 -3
- package/build-types/popover/index.d.ts +1 -1
- package/build-types/popover/index.d.ts.map +1 -1
- package/build-types/popover/stories/e2e/index.story.d.ts +1 -1
- package/build-types/private-apis.d.ts +0 -1
- package/build-types/private-apis.d.ts.map +1 -1
- package/build-types/query-controls/author-select.d.ts +1 -1
- package/build-types/query-controls/author-select.d.ts.map +1 -1
- package/build-types/query-controls/category-select.d.ts +1 -1
- package/build-types/query-controls/category-select.d.ts.map +1 -1
- package/build-types/query-controls/index.d.ts +1 -1
- package/build-types/query-controls/index.d.ts.map +1 -1
- package/build-types/query-controls/types.d.ts +9 -0
- package/build-types/query-controls/types.d.ts.map +1 -1
- package/build-types/radio-control/index.d.ts.map +1 -1
- package/build-types/range-control/index.d.ts +1 -1
- package/build-types/range-control/styles/range-control-styles.d.ts +1 -1
- package/build-types/resizable-box/index.d.ts +1 -1
- package/build-types/resizable-box/resize-tooltip/index.d.ts +1 -1
- package/build-types/resizable-box/stories/index.story.d.ts +2 -2
- package/build-types/scrollable/hook.d.ts +4 -4
- package/build-types/search-control/index.d.ts +1 -1
- package/build-types/search-control/stories/index.story.d.ts +2 -2
- package/build-types/select-control/styles/select-control-styles.d.ts.map +1 -1
- package/build-types/slot-fill/index.d.ts +1 -1
- package/build-types/slot-fill/index.d.ts.map +1 -1
- package/build-types/slot-fill/types.d.ts +4 -0
- package/build-types/slot-fill/types.d.ts.map +1 -1
- package/build-types/snackbar/index.d.ts +2 -2
- package/build-types/snackbar/stories/index.story.d.ts +0 -3
- package/build-types/snackbar/stories/index.story.d.ts.map +1 -1
- package/build-types/snackbar/types.d.ts +1 -1
- package/build-types/snackbar/types.d.ts.map +1 -1
- package/build-types/spacer/hook.d.ts +4 -4
- package/build-types/surface/hook.d.ts +4 -4
- package/build-types/tabs/index.d.ts +2 -2
- package/build-types/tabs/index.d.ts.map +1 -1
- package/build-types/tabs/styles.d.ts.map +1 -1
- package/build-types/tabs/tab.d.ts +2 -1
- package/build-types/tabs/tab.d.ts.map +1 -1
- package/build-types/tabs/tabpanel.d.ts +3 -2
- package/build-types/tabs/tabpanel.d.ts.map +1 -1
- package/build-types/tabs/types.d.ts +8 -3
- package/build-types/tabs/types.d.ts.map +1 -1
- package/build-types/text/hook.d.ts +4 -4
- package/build-types/text-control/index.d.ts +1 -1
- package/build-types/textarea-control/index.d.ts +1 -1
- package/build-types/toggle-control/stories/index.story.d.ts +2 -2
- package/build-types/toggle-group-control/toggle-group-control/as-button-group.d.ts +1 -1
- package/build-types/toggle-group-control/toggle-group-control/as-radio-group.d.ts +1 -1
- package/build-types/toggle-group-control/toggle-group-control/component.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control/styles.d.ts +2 -2
- package/build-types/toggle-group-control/toggle-group-control/styles.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control/utils.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control-option/component.d.ts +1 -1
- package/build-types/toggle-group-control/toggle-group-control-option-base/component.d.ts +1 -1
- package/build-types/toggle-group-control/toggle-group-control-option-base/component.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control-option-base/styles.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control-option-icon/component.d.ts +1 -1
- package/build-types/toolbar/toolbar-button/index.d.ts +3 -3
- package/build-types/tools-panel/tools-panel/component.d.ts.map +1 -1
- package/build-types/tools-panel/tools-panel/hook.d.ts +5 -4
- package/build-types/tools-panel/tools-panel/hook.d.ts.map +1 -1
- package/build-types/tools-panel/tools-panel-header/component.d.ts.map +1 -1
- package/build-types/tools-panel/tools-panel-header/hook.d.ts +5 -4
- package/build-types/tools-panel/tools-panel-header/hook.d.ts.map +1 -1
- package/build-types/tools-panel/tools-panel-item/hook.d.ts +4 -4
- package/build-types/tools-panel/tools-panel-item/hook.d.ts.map +1 -1
- package/build-types/tools-panel/types.d.ts +9 -0
- package/build-types/tools-panel/types.d.ts.map +1 -1
- package/build-types/tooltip/index.d.ts +1 -1
- package/build-types/tooltip/index.d.ts.map +1 -1
- package/build-types/tooltip/stories/index.story.d.ts +10 -1
- package/build-types/tooltip/stories/index.story.d.ts.map +1 -1
- package/build-types/tooltip/types.d.ts +3 -0
- package/build-types/tooltip/types.d.ts.map +1 -1
- package/build-types/truncate/hook.d.ts +5 -5
- package/build-types/truncate/hook.d.ts.map +1 -1
- package/build-types/truncate/types.d.ts +4 -0
- package/build-types/truncate/types.d.ts.map +1 -1
- package/build-types/unit-control/index.d.ts +1 -1
- package/build-types/unit-control/styles/unit-control-styles.d.ts +1 -1
- package/build-types/utils/strings.d.ts +14 -2
- package/build-types/utils/strings.d.ts.map +1 -1
- package/build-types/v-stack/hook.d.ts +4 -4
- package/build-types/v-stack/stories/index.story.d.ts +1 -1
- package/package.json +20 -21
- package/src/alignment-matrix-control/test/index.tsx +10 -16
- package/src/base-control/index.tsx +21 -16
- package/src/border-box-control/border-box-control-linked-button/component.tsx +1 -1
- package/src/border-control/border-control-dropdown/component.tsx +3 -1
- package/src/border-control/border-control-dropdown/hook.ts +3 -2
- package/src/border-control/border-control-style-picker/component.tsx +1 -1
- package/src/border-control/styles.ts +2 -9
- package/src/box-control/index.tsx +1 -1
- package/src/box-control/linked-button.tsx +1 -1
- package/src/button/README.md +32 -6
- package/src/button/index.tsx +1 -1
- package/src/button-group/README.md +0 -6
- package/src/card/card/README.md +1 -1
- package/src/checkbox-control/README.md +3 -10
- package/src/checkbox-control/index.tsx +8 -6
- package/src/checkbox-control/test/__snapshots__/index.tsx.snap +3 -8
- package/src/checkbox-control/test/index.tsx +7 -0
- package/src/checkbox-control/types.ts +3 -2
- package/src/color-palette/index.native.js +18 -7
- package/src/color-picker/color-copy-button.tsx +1 -1
- package/src/combobox-control/README.md +0 -6
- package/src/composite/test/index.tsx +576 -0
- package/src/context/wordpress-component.ts +11 -6
- package/src/custom-select-control/README.md +0 -6
- package/src/custom-select-control/test/index.js +367 -35
- package/src/custom-select-control-v2/index.tsx +13 -12
- package/src/date-time/date/styles.ts +3 -3
- package/src/date-time/time/timezone.tsx +15 -3
- package/src/dimension-control/index.tsx +2 -0
- package/src/dimension-control/test/__snapshots__/index.test.js.snap +2 -2
- package/src/dimension-control/types.ts +6 -0
- package/src/dropdown-menu/README.md +0 -5
- package/src/dropdown-menu-v2/README.md +75 -136
- package/src/dropdown-menu-v2/index.tsx +321 -231
- package/src/dropdown-menu-v2/stories/index.story.tsx +522 -126
- package/src/dropdown-menu-v2/styles.ts +226 -151
- package/src/dropdown-menu-v2/test/index.tsx +480 -188
- package/src/dropdown-menu-v2/types.ts +98 -184
- package/src/duotone-picker/duotone-picker.tsx +7 -3
- package/src/focal-point-picker/controls.tsx +4 -0
- package/src/focal-point-picker/index.tsx +2 -0
- package/src/focal-point-picker/styles/focal-point-picker-style.ts +1 -1
- package/src/focal-point-picker/types.ts +7 -0
- package/src/font-size-picker/font-size-picker-select.tsx +2 -0
- package/src/font-size-picker/font-size-picker-toggle-group.tsx +9 -1
- package/src/font-size-picker/index.native.js +8 -2
- package/src/font-size-picker/index.tsx +15 -5
- package/src/font-size-picker/types.ts +8 -1
- package/src/form-toggle/README.md +0 -6
- package/src/form-toggle/style.scss +4 -2
- package/src/form-token-field/index.tsx +11 -7
- package/src/form-token-field/test/index.tsx +97 -0
- package/src/form-token-field/token.tsx +1 -0
- package/src/gradient-picker/index.tsx +2 -2
- package/src/index.native.js +6 -3
- package/src/input-control/styles/input-control-styles.tsx +10 -8
- package/src/input-control/types.ts +1 -1
- package/src/lock-unlock.js +10 -0
- package/src/menu-group/README.md +0 -8
- package/src/menu-items-choice/README.md +0 -7
- package/src/mobile/bottom-sheet/index.native.js +15 -1
- package/src/mobile/color-settings/palette.screen.native.js +7 -5
- package/src/mobile/global-styles-context/test/fixtures/theme.native.js +0 -20
- package/src/mobile/global-styles-context/test/utils.native.js +22 -0
- package/src/mobile/global-styles-context/utils.native.js +42 -19
- package/src/mobile/image/constants.js +1 -0
- package/src/mobile/image/index.native.js +55 -18
- package/src/mobile/image/style.native.scss +35 -9
- package/src/mobile/keyboard-aware-flat-list/index.android.js +50 -5
- package/src/mobile/keyboard-aware-flat-list/index.ios.js +65 -91
- package/src/mobile/keyboard-aware-flat-list/test/{use-scroll-to-text-input.native.js → use-scroll-to-section.native.js} +27 -25
- package/src/mobile/keyboard-aware-flat-list/test/use-scroll.native.js +71 -0
- package/src/mobile/keyboard-aware-flat-list/use-scroll-to-element.native.js +41 -0
- package/src/mobile/keyboard-aware-flat-list/{use-scroll-to-text-input.native.js → use-scroll-to-section.native.js} +22 -27
- package/src/mobile/keyboard-aware-flat-list/use-scroll.native.js +100 -0
- package/src/mobile/link-settings/style.native.scss +0 -17
- package/src/mobile/utils/get-px-from-css-unit.native.js +329 -0
- package/src/mobile/utils/test/get-px-from-css-unit.native.js +172 -0
- package/src/modal/README.md +0 -6
- package/src/modal/index.tsx +18 -16
- package/src/modal/test/index.tsx +90 -1
- package/src/navigation/menu/menu-title.tsx +1 -1
- package/src/navigator/navigator-provider/component.tsx +3 -4
- package/src/navigator/navigator-screen/component.tsx +15 -93
- package/src/navigator/styles.ts +71 -0
- package/src/navigator/test/index.tsx +0 -64
- package/src/notice/README.md +0 -6
- package/src/number-control/README.md +2 -2
- package/src/number-control/index.tsx +4 -8
- package/src/number-control/types.ts +1 -1
- package/src/palette-edit/index.tsx +14 -43
- package/src/palette-edit/style.scss +2 -2
- package/src/panel/README.md +0 -6
- package/src/private-apis.native.js +13 -0
- package/src/private-apis.ts +12 -37
- package/src/query-controls/author-select.tsx +2 -0
- package/src/query-controls/category-select.tsx +2 -0
- package/src/query-controls/index.tsx +6 -1
- package/src/query-controls/types.ts +9 -0
- package/src/radio-control/README.md +0 -6
- package/src/radio-control/index.tsx +4 -1
- package/src/radio-control/style.scss +29 -2
- package/src/radio-group/README.md +0 -6
- package/src/range-control/README.md +1 -9
- package/src/range-control/index.tsx +1 -1
- package/src/search-control/README.md +1 -5
- package/src/select-control/README.md +0 -6
- package/src/select-control/styles/select-control-styles.ts +10 -28
- package/src/slot-fill/index.tsx +5 -2
- package/src/slot-fill/types.ts +5 -0
- package/src/snackbar/README.md +0 -6
- package/src/snackbar/stories/index.story.tsx +7 -5
- package/src/snackbar/style.scss +4 -3
- package/src/snackbar/types.ts +2 -1
- package/src/spacer/README.md +0 -2
- package/src/spinner/README.md +2 -0
- package/src/tab-panel/README.md +0 -5
- package/src/tab-panel/test/index.tsx +39 -56
- package/src/tabs/README.md +4 -4
- package/src/tabs/index.tsx +22 -1
- package/src/tabs/stories/index.story.tsx +48 -48
- package/src/tabs/styles.ts +7 -1
- package/src/tabs/tab.tsx +3 -3
- package/src/tabs/tabpanel.tsx +13 -8
- package/src/tabs/test/index.tsx +236 -106
- package/src/tabs/types.ts +8 -3
- package/src/text-control/README.md +0 -6
- package/src/textarea-control/README.md +0 -6
- package/src/toggle-group-control/test/__snapshots__/index.tsx.snap +12 -16
- package/src/toggle-group-control/test/index.tsx +107 -41
- package/src/toggle-group-control/toggle-group-control/component.tsx +5 -4
- package/src/toggle-group-control/toggle-group-control/styles.ts +13 -19
- package/src/toggle-group-control/toggle-group-control/utils.ts +15 -20
- package/src/toggle-group-control/toggle-group-control-option/README.md +1 -1
- package/src/toggle-group-control/toggle-group-control-option-base/README.md +1 -1
- package/src/toggle-group-control/toggle-group-control-option-base/styles.ts +3 -2
- package/src/toggle-group-control/toggle-group-control-option-icon/README.md +1 -1
- package/src/toolbar/toolbar/README.md +0 -6
- package/src/tools-panel/test/index.tsx +12 -20
- package/src/tools-panel/tools-panel/README.md +7 -0
- package/src/tools-panel/tools-panel/component.tsx +2 -0
- package/src/tools-panel/tools-panel-header/README.md +7 -0
- package/src/tools-panel/tools-panel-header/component.tsx +20 -13
- package/src/tools-panel/tools-panel-item/hook.ts +10 -21
- package/src/tools-panel/types.ts +9 -0
- package/src/tooltip/README.md +4 -0
- package/src/tooltip/index.tsx +48 -10
- package/src/tooltip/stories/index.story.tsx +18 -1
- package/src/tooltip/test/index.tsx +404 -254
- package/src/tooltip/types.ts +4 -0
- package/src/tree-grid/README.md +0 -4
- package/src/truncate/README.md +8 -0
- package/src/truncate/hook.ts +17 -10
- package/src/truncate/test/index.tsx +54 -27
- package/src/truncate/types.ts +4 -0
- package/src/unit-control/index.tsx +1 -1
- package/src/utils/strings.ts +30 -2
- package/src/utils/test/strings.js +96 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/build/dropdown-menu-v2-ariakit/index.js +0 -256
- package/build/dropdown-menu-v2-ariakit/index.js.map +0 -1
- package/build/dropdown-menu-v2-ariakit/styles.js +0 -180
- package/build/dropdown-menu-v2-ariakit/styles.js.map +0 -1
- package/build/dropdown-menu-v2-ariakit/types.js +0 -6
- package/build/dropdown-menu-v2-ariakit/types.js.map +0 -1
- package/build/mobile/inserter-button/index.native.js +0 -98
- package/build/mobile/inserter-button/index.native.js.map +0 -1
- package/build/mobile/inserter-button/sparkles.js +0 -23
- package/build/mobile/inserter-button/sparkles.js.map +0 -1
- package/build/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js.map +0 -1
- package/build/mobile/link-settings/image-link-destinations-screen.native.js +0 -119
- package/build/mobile/link-settings/image-link-destinations-screen.native.js.map +0 -1
- package/build-module/dropdown-menu-v2-ariakit/index.js +0 -237
- package/build-module/dropdown-menu-v2-ariakit/index.js.map +0 -1
- package/build-module/dropdown-menu-v2-ariakit/styles.js +0 -165
- package/build-module/dropdown-menu-v2-ariakit/styles.js.map +0 -1
- package/build-module/dropdown-menu-v2-ariakit/types.js +0 -2
- package/build-module/dropdown-menu-v2-ariakit/types.js.map +0 -1
- package/build-module/mobile/inserter-button/index.native.js +0 -89
- package/build-module/mobile/inserter-button/index.native.js.map +0 -1
- package/build-module/mobile/inserter-button/sparkles.js +0 -15
- package/build-module/mobile/inserter-button/sparkles.js.map +0 -1
- package/build-module/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js.map +0 -1
- package/build-module/mobile/link-settings/image-link-destinations-screen.native.js +0 -110
- package/build-module/mobile/link-settings/image-link-destinations-screen.native.js.map +0 -1
- package/build-types/dropdown-menu-v2-ariakit/index.d.ts +0 -20
- package/build-types/dropdown-menu-v2-ariakit/index.d.ts.map +0 -1
- package/build-types/dropdown-menu-v2-ariakit/stories/index.story.d.ts +0 -16
- package/build-types/dropdown-menu-v2-ariakit/stories/index.story.d.ts.map +0 -1
- package/build-types/dropdown-menu-v2-ariakit/styles.d.ts +0 -96
- package/build-types/dropdown-menu-v2-ariakit/styles.d.ts.map +0 -1
- package/build-types/dropdown-menu-v2-ariakit/test/index.d.ts.map +0 -1
- package/build-types/dropdown-menu-v2-ariakit/types.d.ts +0 -168
- package/build-types/dropdown-menu-v2-ariakit/types.d.ts.map +0 -1
- package/build-types/mobile/inserter-button/sparkles.d.ts +0 -3
- package/build-types/mobile/inserter-button/sparkles.d.ts.map +0 -1
- package/src/dropdown-menu-v2-ariakit/README.md +0 -331
- package/src/dropdown-menu-v2-ariakit/index.tsx +0 -383
- package/src/dropdown-menu-v2-ariakit/stories/index.story.tsx +0 -617
- package/src/dropdown-menu-v2-ariakit/styles.ts +0 -333
- package/src/dropdown-menu-v2-ariakit/test/index.tsx +0 -1108
- package/src/dropdown-menu-v2-ariakit/types.ts +0 -179
- package/src/mobile/inserter-button/README.md +0 -62
- package/src/mobile/inserter-button/index.native.js +0 -116
- package/src/mobile/inserter-button/sparkles.js +0 -15
- package/src/mobile/inserter-button/style.native.scss +0 -72
- package/src/mobile/link-settings/image-link-destinations-screen.native.js +0 -152
- /package/build-types/{dropdown-menu-v2-ariakit → composite}/test/index.d.ts +0 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { renderHook } from 'test/helpers';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import useScroll from '../use-scroll';
|
|
11
|
+
|
|
12
|
+
// Mock Reanimated with default mock
|
|
13
|
+
jest.mock( 'react-native-reanimated', () => ( {
|
|
14
|
+
...require( 'react-native-reanimated/mock' ),
|
|
15
|
+
useAnimatedScrollHandler: jest.fn( ( args ) => args ),
|
|
16
|
+
} ) );
|
|
17
|
+
|
|
18
|
+
describe( 'useScroll', () => {
|
|
19
|
+
it( 'scrolls using current scroll position', () => {
|
|
20
|
+
const sectionY = 50;
|
|
21
|
+
const sectionHeight = 10;
|
|
22
|
+
const scrollViewMeasurements = { x: 0, y: 0, width: 0, height: 600 };
|
|
23
|
+
const extraScrollHeight = 50;
|
|
24
|
+
const scrollEnabled = true;
|
|
25
|
+
const shouldPreventAutomaticScroll = false;
|
|
26
|
+
|
|
27
|
+
const scrollTo = jest.fn();
|
|
28
|
+
const measureInWindow = jest.fn( ( callback ) =>
|
|
29
|
+
callback( ...Object.values( scrollViewMeasurements ) )
|
|
30
|
+
);
|
|
31
|
+
const scrollRef = { scrollTo, measureInWindow };
|
|
32
|
+
const onScroll = jest.fn();
|
|
33
|
+
const onSizeChange = jest.fn();
|
|
34
|
+
|
|
35
|
+
const { result } = renderHook( () =>
|
|
36
|
+
useScroll( {
|
|
37
|
+
scrollEnabled,
|
|
38
|
+
shouldPreventAutomaticScroll,
|
|
39
|
+
onScroll,
|
|
40
|
+
onSizeChange,
|
|
41
|
+
extraScrollHeight,
|
|
42
|
+
} )
|
|
43
|
+
);
|
|
44
|
+
const {
|
|
45
|
+
scrollViewRef,
|
|
46
|
+
onContentSizeChange,
|
|
47
|
+
scrollHandler,
|
|
48
|
+
scrollToSection,
|
|
49
|
+
} = result.current;
|
|
50
|
+
|
|
51
|
+
// Assign ref
|
|
52
|
+
scrollViewRef.current = scrollRef;
|
|
53
|
+
|
|
54
|
+
// Check content size changes
|
|
55
|
+
onContentSizeChange();
|
|
56
|
+
expect( measureInWindow ).toHaveBeenCalled();
|
|
57
|
+
expect( onSizeChange ).toHaveBeenCalled();
|
|
58
|
+
|
|
59
|
+
// Set up initial scroll offset
|
|
60
|
+
scrollHandler.onScroll( { contentOffset: { y: 150 } } );
|
|
61
|
+
|
|
62
|
+
// Scroll to section
|
|
63
|
+
scrollToSection( sectionY, sectionHeight );
|
|
64
|
+
|
|
65
|
+
// Assert
|
|
66
|
+
expect( scrollTo ).toHaveBeenCalledWith( {
|
|
67
|
+
y: sectionY,
|
|
68
|
+
animated: true,
|
|
69
|
+
} );
|
|
70
|
+
} );
|
|
71
|
+
} );
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useCallback } from '@wordpress/element';
|
|
5
|
+
|
|
6
|
+
/** @typedef {import('@wordpress/element').RefObject} RefObject */
|
|
7
|
+
/**
|
|
8
|
+
* Hook to scroll to a specified element by taking into account the Keyboard
|
|
9
|
+
* and the Header.
|
|
10
|
+
*
|
|
11
|
+
* @param {RefObject} scrollViewRef Scroll view reference.
|
|
12
|
+
* @param {Function} scrollToSection Function to scroll.
|
|
13
|
+
* @return {Function[]} Function to scroll to an element.
|
|
14
|
+
*/
|
|
15
|
+
export default function useScrollToElement( scrollViewRef, scrollToSection ) {
|
|
16
|
+
/**
|
|
17
|
+
* Function to scroll to an element.
|
|
18
|
+
*
|
|
19
|
+
* @param {RefObject} elementRef Ref of the element.
|
|
20
|
+
*/
|
|
21
|
+
const scrollToElement = useCallback(
|
|
22
|
+
( elementRef ) => {
|
|
23
|
+
if ( ! scrollViewRef.current || ! elementRef ) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
elementRef.current.measureLayout(
|
|
28
|
+
scrollViewRef.current,
|
|
29
|
+
( _x, y, _width, height ) => {
|
|
30
|
+
if ( height || y ) {
|
|
31
|
+
scrollToSection( Math.round( y ), height );
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
() => {}
|
|
35
|
+
);
|
|
36
|
+
},
|
|
37
|
+
[ scrollViewRef, scrollToSection ]
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
return [ scrollToElement ];
|
|
41
|
+
}
|
|
@@ -8,24 +8,21 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
|
8
8
|
*/
|
|
9
9
|
import { useCallback } from '@wordpress/element';
|
|
10
10
|
|
|
11
|
-
const DEFAULT_FONT_SIZE = 16;
|
|
12
|
-
|
|
13
11
|
/** @typedef {import('@wordpress/element').RefObject} RefObject */
|
|
14
12
|
/** @typedef {import('react-native-reanimated').SharedValue} SharedValue */
|
|
15
13
|
/**
|
|
16
|
-
* Hook to scroll to
|
|
17
|
-
*
|
|
18
|
-
* account the Keyboard and the Header.
|
|
14
|
+
* Hook to scroll to a specified section by taking into account the Keyboard
|
|
15
|
+
* and the Header.
|
|
19
16
|
*
|
|
20
17
|
* @param {number} extraScrollHeight Extra space to not overlap the content.
|
|
21
18
|
* @param {number} keyboardOffset Keyboard space offset.
|
|
22
19
|
* @param {boolean} scrollEnabled Whether the scroll is enabled or not.
|
|
23
20
|
* @param {RefObject} scrollViewMeasurements ScrollView Layout measurements.
|
|
24
|
-
* @param {RefObject} scrollViewRef
|
|
21
|
+
* @param {RefObject} scrollViewRef Scroll view reference.
|
|
25
22
|
* @param {SharedValue} scrollViewYOffset Current offset position of the ScrollView.
|
|
26
|
-
* @return {Function[]} Function to scroll to
|
|
23
|
+
* @return {Function[]} Function to scroll to a section.
|
|
27
24
|
*/
|
|
28
|
-
export default function
|
|
25
|
+
export default function useScrollToSection(
|
|
29
26
|
extraScrollHeight,
|
|
30
27
|
keyboardOffset,
|
|
31
28
|
scrollEnabled,
|
|
@@ -37,33 +34,31 @@ export default function useScrollToTextInput(
|
|
|
37
34
|
const insets = top + bottom;
|
|
38
35
|
|
|
39
36
|
/**
|
|
40
|
-
* Function to scroll to
|
|
37
|
+
* Function to scroll to a section.
|
|
41
38
|
*
|
|
42
|
-
* @param {Object}
|
|
43
|
-
* @param {number}
|
|
44
|
-
* @param {number}
|
|
45
|
-
* TextInput's Y coord or height value.
|
|
39
|
+
* @param {Object} section Section data to scroll to.
|
|
40
|
+
* @param {number} section.y Y-coordinate of of the section.
|
|
41
|
+
* @param {number} section.height Height of the section.
|
|
46
42
|
*/
|
|
47
|
-
const
|
|
48
|
-
(
|
|
49
|
-
const { caretHeight = DEFAULT_FONT_SIZE } = caret ?? {};
|
|
50
|
-
|
|
43
|
+
const scrollToSection = useCallback(
|
|
44
|
+
( sectionY, sectionHeight ) => {
|
|
51
45
|
if (
|
|
52
46
|
! scrollViewRef.current ||
|
|
53
47
|
! scrollEnabled ||
|
|
54
|
-
! scrollViewMeasurements
|
|
48
|
+
! scrollViewMeasurements
|
|
55
49
|
) {
|
|
56
50
|
return;
|
|
57
51
|
}
|
|
52
|
+
|
|
58
53
|
const currentScrollViewYOffset = Math.max(
|
|
59
54
|
0,
|
|
60
55
|
scrollViewYOffset.value
|
|
61
56
|
);
|
|
62
57
|
|
|
63
|
-
// Scroll
|
|
64
|
-
if (
|
|
58
|
+
// Scroll to the top of the section.
|
|
59
|
+
if ( sectionY < currentScrollViewYOffset ) {
|
|
65
60
|
scrollViewRef.current.scrollTo( {
|
|
66
|
-
y:
|
|
61
|
+
y: sectionY,
|
|
67
62
|
animated: true,
|
|
68
63
|
} );
|
|
69
64
|
return;
|
|
@@ -72,7 +67,7 @@ export default function useScrollToTextInput(
|
|
|
72
67
|
const availableScreenSpace = Math.abs(
|
|
73
68
|
Math.floor(
|
|
74
69
|
scrollViewMeasurements.current.height -
|
|
75
|
-
( keyboardOffset + extraScrollHeight +
|
|
70
|
+
( keyboardOffset + extraScrollHeight + sectionHeight )
|
|
76
71
|
)
|
|
77
72
|
);
|
|
78
73
|
const maxOffset = Math.floor(
|
|
@@ -80,12 +75,12 @@ export default function useScrollToTextInput(
|
|
|
80
75
|
);
|
|
81
76
|
|
|
82
77
|
const isAtTheTop =
|
|
83
|
-
|
|
78
|
+
sectionY < scrollViewMeasurements.current.y + insets;
|
|
84
79
|
|
|
85
|
-
// Scroll
|
|
86
|
-
if (
|
|
80
|
+
// Scroll to the bottom of the section.
|
|
81
|
+
if ( sectionY > maxOffset && ! isAtTheTop ) {
|
|
87
82
|
scrollViewRef.current.scrollTo( {
|
|
88
|
-
y:
|
|
83
|
+
y: sectionY - availableScreenSpace,
|
|
89
84
|
animated: true,
|
|
90
85
|
} );
|
|
91
86
|
}
|
|
@@ -101,5 +96,5 @@ export default function useScrollToTextInput(
|
|
|
101
96
|
]
|
|
102
97
|
);
|
|
103
98
|
|
|
104
|
-
return [
|
|
99
|
+
return [ scrollToSection ];
|
|
105
100
|
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { useWindowDimensions } from 'react-native';
|
|
6
|
+
import {
|
|
7
|
+
useAnimatedScrollHandler,
|
|
8
|
+
useSharedValue,
|
|
9
|
+
} from 'react-native-reanimated';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* WordPress dependencies
|
|
13
|
+
*/
|
|
14
|
+
import { useCallback, useEffect, useRef } from '@wordpress/element';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Internal dependencies
|
|
18
|
+
*/
|
|
19
|
+
import useKeyboardOffset from './use-keyboard-offset';
|
|
20
|
+
import useScrollToSection from './use-scroll-to-section';
|
|
21
|
+
import useScrollToElement from './use-scroll-to-element';
|
|
22
|
+
|
|
23
|
+
export default function useScroll( {
|
|
24
|
+
scrollEnabled,
|
|
25
|
+
shouldPreventAutomaticScroll,
|
|
26
|
+
onScroll,
|
|
27
|
+
onSizeChange,
|
|
28
|
+
extraScrollHeight,
|
|
29
|
+
} ) {
|
|
30
|
+
const scrollViewRef = useRef();
|
|
31
|
+
const scrollViewMeasurements = useRef();
|
|
32
|
+
const scrollViewYOffset = useSharedValue( -1 );
|
|
33
|
+
const lastScrollTo = useRef( {
|
|
34
|
+
clientId: null,
|
|
35
|
+
} );
|
|
36
|
+
|
|
37
|
+
const { height: windowHeight, width: windowWidth } = useWindowDimensions();
|
|
38
|
+
const isLandscape = windowWidth >= windowHeight;
|
|
39
|
+
|
|
40
|
+
const [ keyboardOffset ] = useKeyboardOffset(
|
|
41
|
+
scrollEnabled,
|
|
42
|
+
shouldPreventAutomaticScroll
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const scrollHandler = useAnimatedScrollHandler( {
|
|
46
|
+
onScroll: ( event ) => {
|
|
47
|
+
const { contentOffset } = event;
|
|
48
|
+
scrollViewYOffset.value = contentOffset.y;
|
|
49
|
+
onScroll( event );
|
|
50
|
+
},
|
|
51
|
+
} );
|
|
52
|
+
|
|
53
|
+
// When the orientation changes, the ScrollView measurements
|
|
54
|
+
// need to be re-calculated.
|
|
55
|
+
useEffect( () => {
|
|
56
|
+
scrollViewMeasurements.current = null;
|
|
57
|
+
}, [ isLandscape ] );
|
|
58
|
+
|
|
59
|
+
const [ scrollToSection ] = useScrollToSection(
|
|
60
|
+
extraScrollHeight,
|
|
61
|
+
keyboardOffset,
|
|
62
|
+
scrollEnabled,
|
|
63
|
+
scrollViewMeasurements,
|
|
64
|
+
scrollViewRef,
|
|
65
|
+
scrollViewYOffset
|
|
66
|
+
);
|
|
67
|
+
const [ scrollToElement ] = useScrollToElement(
|
|
68
|
+
scrollViewRef,
|
|
69
|
+
scrollToSection
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const measureScrollView = useCallback( () => {
|
|
73
|
+
if ( scrollViewRef.current ) {
|
|
74
|
+
scrollViewRef.current.measureInWindow( ( _x, y, width, height ) => {
|
|
75
|
+
scrollViewMeasurements.current = { y, width, height };
|
|
76
|
+
} );
|
|
77
|
+
}
|
|
78
|
+
}, [ scrollViewRef ] );
|
|
79
|
+
|
|
80
|
+
const onContentSizeChange = useCallback( () => {
|
|
81
|
+
if ( onSizeChange ) {
|
|
82
|
+
onSizeChange();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Sets the first values when the content size changes.
|
|
86
|
+
if ( ! scrollViewMeasurements.current ) {
|
|
87
|
+
measureScrollView();
|
|
88
|
+
}
|
|
89
|
+
}, [ measureScrollView, onSizeChange ] );
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
scrollViewRef,
|
|
93
|
+
scrollHandler,
|
|
94
|
+
keyboardOffset,
|
|
95
|
+
scrollToSection,
|
|
96
|
+
scrollToElement,
|
|
97
|
+
onContentSizeChange,
|
|
98
|
+
lastScrollTo,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
@@ -2,20 +2,3 @@
|
|
|
2
2
|
padding-left: 0;
|
|
3
3
|
padding-right: 0;
|
|
4
4
|
}
|
|
5
|
-
|
|
6
|
-
// used in both light and dark modes
|
|
7
|
-
.placeholderTextColor {
|
|
8
|
-
color: #87a6bc;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
.optionIcon {
|
|
12
|
-
color: $blue-50;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
.optionIconDark {
|
|
16
|
-
color: $blue-30;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
.unselectedOptionIcon {
|
|
20
|
-
opacity: 0;
|
|
21
|
-
}
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts string to object { value, unit }.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} cssUnit
|
|
5
|
+
* @return {Object} parsedUnit
|
|
6
|
+
*/
|
|
7
|
+
function parseUnit( cssUnit ) {
|
|
8
|
+
const match = cssUnit
|
|
9
|
+
?.trim()
|
|
10
|
+
.match(
|
|
11
|
+
/^(0?[-.]?\d*\.?\d+)(r?e[m|x]|v[h|w|min|max]+|p[x|t|c]|[c|m]m|%|in|ch|Q|lh)$/
|
|
12
|
+
);
|
|
13
|
+
if ( ! isNaN( cssUnit ) && ! isNaN( parseFloat( cssUnit ) ) ) {
|
|
14
|
+
return { value: parseFloat( cssUnit ), unit: 'px' };
|
|
15
|
+
}
|
|
16
|
+
return match
|
|
17
|
+
? { value: parseFloat( match[ 1 ] ) || match[ 1 ], unit: match[ 2 ] }
|
|
18
|
+
: { value: cssUnit, unit: undefined };
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Evaluate a math expression.
|
|
22
|
+
*
|
|
23
|
+
* @param {string} expression
|
|
24
|
+
* @return {number} evaluated expression.
|
|
25
|
+
*/
|
|
26
|
+
function calculate( expression ) {
|
|
27
|
+
try {
|
|
28
|
+
return Function( `'use strict'; return (${ expression })` )();
|
|
29
|
+
} catch ( err ) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Calculates the css function value for the supported css functions such as max, min, clamp and calc.
|
|
36
|
+
*
|
|
37
|
+
* @param {string} functionUnitValue string should be in a particular format (for example min(12px,12px) ) no nested loops.
|
|
38
|
+
* @param {Object} options
|
|
39
|
+
* @return {string} unit containing the unit in PX.
|
|
40
|
+
*/
|
|
41
|
+
function getFunctionUnitValue( functionUnitValue, options ) {
|
|
42
|
+
const functionUnit = functionUnitValue.split( /[(),]/g ).filter( Boolean );
|
|
43
|
+
|
|
44
|
+
const units = functionUnit
|
|
45
|
+
.slice( 1 )
|
|
46
|
+
.map( ( unit ) => parseUnit( getPxFromCssUnit( unit, options ) ).value )
|
|
47
|
+
.filter( Boolean );
|
|
48
|
+
|
|
49
|
+
switch ( functionUnit[ 0 ] ) {
|
|
50
|
+
case 'min':
|
|
51
|
+
return Math.min( ...units ) + 'px';
|
|
52
|
+
case 'max':
|
|
53
|
+
return Math.max( ...units ) + 'px';
|
|
54
|
+
case 'clamp':
|
|
55
|
+
if ( units.length !== 3 ) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
if ( units[ 1 ] < units[ 0 ] ) {
|
|
59
|
+
return units[ 0 ] + 'px';
|
|
60
|
+
}
|
|
61
|
+
if ( units[ 1 ] > units[ 2 ] ) {
|
|
62
|
+
return units[ 2 ] + 'px';
|
|
63
|
+
}
|
|
64
|
+
return units[ 1 ] + 'px';
|
|
65
|
+
case 'calc':
|
|
66
|
+
return units[ 0 ] + 'px';
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Take a css function such as min, max, calc, clamp and returns parsedUnit
|
|
72
|
+
*
|
|
73
|
+
* How this works for the nested function is that it first replaces the inner function call.
|
|
74
|
+
* Then it tackles the outer onces.
|
|
75
|
+
* So for example: min( max(25px, 35px), 40px )
|
|
76
|
+
* in the first pass we would replace max(25px, 35px) with 35px.
|
|
77
|
+
* then we would try to evaluate min( 35px, 40px )
|
|
78
|
+
* and then finally return 35px.
|
|
79
|
+
*
|
|
80
|
+
* @param {string} cssUnit
|
|
81
|
+
* @return {Object} parsedUnit object.
|
|
82
|
+
*/
|
|
83
|
+
function parseUnitFunction( cssUnit ) {
|
|
84
|
+
while ( true ) {
|
|
85
|
+
const currentCssUnit = cssUnit;
|
|
86
|
+
const regExp = /(max|min|calc|clamp)\(([^()]*)\)/g;
|
|
87
|
+
const matches = regExp.exec( cssUnit ) || [];
|
|
88
|
+
if ( matches[ 0 ] ) {
|
|
89
|
+
const functionUnitValue = getFunctionUnitValue( matches[ 0 ] );
|
|
90
|
+
cssUnit = cssUnit.replace( matches[ 0 ], functionUnitValue );
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// If the unit hasn't been modified or we have a single value break free.
|
|
94
|
+
if ( cssUnit === currentCssUnit || parseFloat( cssUnit ) ) {
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return parseUnit( cssUnit );
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Return true if we think this is a math expression.
|
|
103
|
+
*
|
|
104
|
+
* @param {string} cssUnit the cssUnit value being evaluted.
|
|
105
|
+
* @return {boolean} Whether the cssUnit is a math expression.
|
|
106
|
+
*/
|
|
107
|
+
function isMathExpression( cssUnit ) {
|
|
108
|
+
for ( let i = 0; i < cssUnit.length; i++ ) {
|
|
109
|
+
if ( [ '+', '-', '/', '*' ].includes( cssUnit[ i ] ) ) {
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Evaluates the math expression and return a px value.
|
|
117
|
+
*
|
|
118
|
+
* @param {string} cssUnit the cssUnit value being evaluted.
|
|
119
|
+
* @return {string} return a converfted value to px.
|
|
120
|
+
*/
|
|
121
|
+
function evalMathExpression( cssUnit ) {
|
|
122
|
+
let errorFound = false;
|
|
123
|
+
// Convert every part of the expression to px values.
|
|
124
|
+
// The following regex matches numbers that have a following unit
|
|
125
|
+
// E.g. 5.25rem, 1vw
|
|
126
|
+
const cssUnitsBits = cssUnit.match( /\d+\.?\d*[a-zA-Z]+|\.\d+[a-zA-Z]+/g );
|
|
127
|
+
if ( cssUnitsBits ) {
|
|
128
|
+
for ( const unit of cssUnitsBits ) {
|
|
129
|
+
// Standardize the unit to px and extract the value.
|
|
130
|
+
const parsedUnit = parseUnit( getPxFromCssUnit( unit ) );
|
|
131
|
+
if ( ! parseFloat( parsedUnit.value ) ) {
|
|
132
|
+
errorFound = true;
|
|
133
|
+
// End early since we are dealing with a null value.
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
cssUnit = cssUnit.replace( unit, parsedUnit.value );
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
errorFound = true;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// For mixed math expressions wrapped within CSS expressions
|
|
143
|
+
const expressionsMatches = cssUnit.match( /(max|min|clamp)/g );
|
|
144
|
+
if ( ! errorFound && expressionsMatches ) {
|
|
145
|
+
const values = cssUnit.split( ',' );
|
|
146
|
+
for ( const currentValue of values ) {
|
|
147
|
+
// Check for nested calc() and remove them to calculate the value.
|
|
148
|
+
const rawCurrentValue = currentValue.replace( /\s|calc/g, '' );
|
|
149
|
+
|
|
150
|
+
if ( isMathExpression( rawCurrentValue ) ) {
|
|
151
|
+
const calculatedExpression = calculate( rawCurrentValue );
|
|
152
|
+
|
|
153
|
+
if ( calculatedExpression ) {
|
|
154
|
+
const calculatedValue =
|
|
155
|
+
calculatedExpression.toFixed( 0 ) + 'px';
|
|
156
|
+
cssUnit = cssUnit.replace( currentValue, calculatedValue );
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const parsedValue = parseUnitFunction( cssUnit );
|
|
161
|
+
return ! parsedValue ? null : parsedValue.value + parsedValue.unit;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if ( errorFound ) {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const calculatedResult = calculate( cssUnit );
|
|
169
|
+
return calculatedResult ? calculatedResult.toFixed( 0 ) + 'px' : null;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Convert a parsedUnit object to px value.
|
|
174
|
+
*
|
|
175
|
+
* @param {Object} parsedUnit
|
|
176
|
+
* @param {Object} options
|
|
177
|
+
* @return {string} or {null} returns the converted with in a px value format.
|
|
178
|
+
*/
|
|
179
|
+
function convertParsedUnitToPx( parsedUnit, options ) {
|
|
180
|
+
const PIXELS_PER_INCH = 96;
|
|
181
|
+
const ONE_PERCENT = 0.01;
|
|
182
|
+
|
|
183
|
+
const defaultProperties = {
|
|
184
|
+
fontSize: 16,
|
|
185
|
+
lineHeight: 16,
|
|
186
|
+
width: 375,
|
|
187
|
+
height: 812,
|
|
188
|
+
type: 'font',
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const setOptions = Object.assign( {}, defaultProperties, options );
|
|
192
|
+
|
|
193
|
+
const relativeUnits = {
|
|
194
|
+
em: setOptions.fontSize,
|
|
195
|
+
rem: setOptions.fontSize,
|
|
196
|
+
vh: setOptions.height * ONE_PERCENT,
|
|
197
|
+
vw: setOptions.width * ONE_PERCENT,
|
|
198
|
+
vmin:
|
|
199
|
+
( setOptions.width < setOptions.height
|
|
200
|
+
? setOptions.width
|
|
201
|
+
: setOptions.height ) * ONE_PERCENT,
|
|
202
|
+
vmax:
|
|
203
|
+
( setOptions.width > setOptions.height
|
|
204
|
+
? setOptions.width
|
|
205
|
+
: setOptions.height ) * ONE_PERCENT,
|
|
206
|
+
'%':
|
|
207
|
+
( setOptions.type === 'font'
|
|
208
|
+
? setOptions.fontSize
|
|
209
|
+
: setOptions.width ) * ONE_PERCENT,
|
|
210
|
+
ch: 8, // The advance measure (width) of the glyph "0" of the element's font. Approximate
|
|
211
|
+
ex: 7.15625, // X-height of the element's font. Approximate.
|
|
212
|
+
lh: setOptions.lineHeight,
|
|
213
|
+
};
|
|
214
|
+
relativeUnits.svw = relativeUnits.vmin;
|
|
215
|
+
relativeUnits.lvw = relativeUnits.vmax;
|
|
216
|
+
relativeUnits.dvw = relativeUnits.vw;
|
|
217
|
+
relativeUnits.svh = relativeUnits.vmin;
|
|
218
|
+
relativeUnits.lvh = relativeUnits.vmax;
|
|
219
|
+
relativeUnits.dvh = relativeUnits.vh;
|
|
220
|
+
relativeUnits.vi = relativeUnits.vh;
|
|
221
|
+
relativeUnits.svi = relativeUnits.vmin;
|
|
222
|
+
relativeUnits.lvi = relativeUnits.vmax;
|
|
223
|
+
relativeUnits.dvi = relativeUnits.vw;
|
|
224
|
+
relativeUnits.vb = relativeUnits.vh;
|
|
225
|
+
relativeUnits.svb = relativeUnits.vmin;
|
|
226
|
+
relativeUnits.lvb = relativeUnits.vmax;
|
|
227
|
+
relativeUnits.dvb = relativeUnits.vh;
|
|
228
|
+
relativeUnits.svmin = relativeUnits.vmin;
|
|
229
|
+
relativeUnits.lvmin = relativeUnits.vmin;
|
|
230
|
+
relativeUnits.dvmin = relativeUnits.vmin;
|
|
231
|
+
relativeUnits.svmax = relativeUnits.vmax;
|
|
232
|
+
relativeUnits.lvmax = relativeUnits.vmax;
|
|
233
|
+
relativeUnits.dvmax = relativeUnits.vmax;
|
|
234
|
+
|
|
235
|
+
const absoluteUnits = {
|
|
236
|
+
in: PIXELS_PER_INCH,
|
|
237
|
+
cm: PIXELS_PER_INCH / 2.54,
|
|
238
|
+
mm: PIXELS_PER_INCH / 25.4,
|
|
239
|
+
pt: PIXELS_PER_INCH / 72,
|
|
240
|
+
pc: PIXELS_PER_INCH / 6,
|
|
241
|
+
px: 1,
|
|
242
|
+
Q: PIXELS_PER_INCH / 2.54 / 40,
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
if ( relativeUnits[ parsedUnit.unit ] ) {
|
|
246
|
+
return (
|
|
247
|
+
( relativeUnits[ parsedUnit.unit ] * parsedUnit.value ).toFixed(
|
|
248
|
+
0
|
|
249
|
+
) + 'px'
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if ( absoluteUnits[ parsedUnit.unit ] ) {
|
|
254
|
+
return (
|
|
255
|
+
( absoluteUnits[ parsedUnit.unit ] * parsedUnit.value ).toFixed(
|
|
256
|
+
0
|
|
257
|
+
) + 'px'
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Returns the px value of a cssUnit.
|
|
266
|
+
*
|
|
267
|
+
* @param {string} cssUnit
|
|
268
|
+
* @param {Object} options
|
|
269
|
+
* @return {string} returns the cssUnit value in a simple px format.
|
|
270
|
+
*/
|
|
271
|
+
export function getPxFromCssUnit( cssUnit, options = {} ) {
|
|
272
|
+
if ( Number.isFinite( cssUnit ) ) {
|
|
273
|
+
return cssUnit.toFixed( 0 ) + 'px';
|
|
274
|
+
}
|
|
275
|
+
if ( cssUnit === undefined ) {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
let parsedUnit = parseUnit( cssUnit );
|
|
279
|
+
|
|
280
|
+
if ( ! parsedUnit.unit ) {
|
|
281
|
+
parsedUnit = parseUnitFunction( cssUnit );
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if ( isMathExpression( cssUnit ) && ! parsedUnit.unit ) {
|
|
285
|
+
return evalMathExpression( cssUnit );
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return convertParsedUnitToPx( parsedUnit, options );
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Use simple cache.
|
|
292
|
+
const cache = {};
|
|
293
|
+
/**
|
|
294
|
+
* Returns the px value of a cssUnit. The memoized version of getPxFromCssUnit;
|
|
295
|
+
*
|
|
296
|
+
* @param {string} cssUnit
|
|
297
|
+
* @param {Object} options
|
|
298
|
+
* @return {string} returns the cssUnit value in a simple px format.
|
|
299
|
+
*/
|
|
300
|
+
function memoizedGetPxFromCssUnit( cssUnit, options = {} ) {
|
|
301
|
+
const hash = cssUnit + hashOptions( options );
|
|
302
|
+
|
|
303
|
+
if ( ! cache[ hash ] ) {
|
|
304
|
+
cache[ hash ] = getPxFromCssUnit( cssUnit, options );
|
|
305
|
+
}
|
|
306
|
+
return cache[ hash ];
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function hashOptions( options ) {
|
|
310
|
+
let hash = '';
|
|
311
|
+
if ( options.hasOwnProperty( 'fontSize' ) ) {
|
|
312
|
+
hash = ':' + options.width;
|
|
313
|
+
}
|
|
314
|
+
if ( options.hasOwnProperty( 'lineHeight' ) ) {
|
|
315
|
+
hash = ':' + options.lineHeight;
|
|
316
|
+
}
|
|
317
|
+
if ( options.hasOwnProperty( 'width' ) ) {
|
|
318
|
+
hash = ':' + options.width;
|
|
319
|
+
}
|
|
320
|
+
if ( options.hasOwnProperty( 'height' ) ) {
|
|
321
|
+
hash = ':' + options.height;
|
|
322
|
+
}
|
|
323
|
+
if ( options.hasOwnProperty( 'type' ) ) {
|
|
324
|
+
hash = ':' + options.type;
|
|
325
|
+
}
|
|
326
|
+
return hash;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export default memoizedGetPxFromCssUnit;
|