@wordpress/components 25.14.0 → 25.15.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 +50 -0
- 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-style-picker/component.js +1 -1
- package/build/border-control/border-control-style-picker/component.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/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/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/font-size-picker/index.js +4 -2
- 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/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 -3
- 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/global-styles-context/utils.native.js +26 -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 -54
- 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/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/styles.js +3 -3
- package/build/tabs/styles.js.map +1 -1
- package/build/tabs/tabpanel.js +9 -7
- package/build/tabs/tabpanel.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-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/types.js.map +1 -1
- package/build/tooltip/index.js +1 -1
- package/build/tooltip/index.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-style-picker/component.js +1 -1
- package/build-module/border-control/border-control-style-picker/component.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/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/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/font-size-picker/index.js +4 -2
- 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/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 -1
- 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/global-styles-context/utils.native.js +25 -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 +15 -51
- 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/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/styles.js +3 -3
- package/build-module/tabs/styles.js.map +1 -1
- package/build-module/tabs/tabpanel.js +9 -7
- package/build-module/tabs/tabpanel.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-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/types.js.map +1 -1
- package/build-module/tooltip/index.js +1 -1
- package/build-module/tooltip/index.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 +29 -5
- package/build-style/style.css +29 -5
- 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/color-picker/component.d.ts +1 -1
- 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/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/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/font-size-picker/index.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/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/lock-unlock.d.ts +3 -0
- package/build-types/lock-unlock.d.ts.map +1 -0
- 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/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.map +1 -1
- package/build-types/number-control/types.d.ts +1 -1
- package/build-types/palette-edit/index.d.ts +3 -8
- package/build-types/palette-edit/index.d.ts.map +1 -1
- 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/radio-control/index.d.ts.map +1 -1
- 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/tabs/styles.d.ts.map +1 -1
- package/build-types/tabs/tabpanel.d.ts +1 -1
- package/build-types/tabs/tabpanel.d.ts.map +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-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/tools-panel/tools-panel/component.d.ts.map +1 -1
- package/build-types/tools-panel/tools-panel/hook.d.ts +1 -0
- 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 +1 -0
- package/build-types/tools-panel/tools-panel-header/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/truncate/hook.d.ts +1 -1
- 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/utils/strings.d.ts +14 -2
- package/build-types/utils/strings.d.ts.map +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-style-picker/component.tsx +1 -1
- 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 +1 -9
- 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-v2/index.tsx +13 -12
- package/src/date-time/date/styles.ts +3 -3
- 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/font-size-picker/index.native.js +8 -2
- package/src/font-size-picker/index.tsx +4 -2
- package/src/form-toggle/README.md +0 -6
- 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 -1
- 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/global-styles-context/test/fixtures/theme.native.js +0 -20
- package/src/mobile/global-styles-context/utils.native.js +28 -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/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 +15 -58
- package/src/palette-edit/test/index.tsx +1 -75
- package/src/panel/README.md +0 -6
- package/src/private-apis.native.js +13 -0
- package/src/private-apis.ts +12 -37
- 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 +0 -6
- 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/tab-panel/README.md +0 -5
- package/src/tab-panel/test/index.tsx +39 -56
- package/src/tabs/styles.ts +7 -1
- package/src/tabs/tabpanel.tsx +7 -6
- package/src/tabs/test/index.tsx +56 -0
- 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 +58 -45
- 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-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/types.ts +9 -0
- package/src/tooltip/index.tsx +1 -1
- package/src/tooltip/test/index.tsx +360 -256
- 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/keyboard-aware-flat-list/use-scroll-to-text-input.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/keyboard-aware-flat-list/use-scroll-to-text-input.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/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 -345
- package/src/dropdown-menu-v2-ariakit/test/index.tsx +0 -1108
- package/src/dropdown-menu-v2-ariakit/types.ts +0 -179
- /package/build-types/{dropdown-menu-v2-ariakit → composite}/test/index.d.ts +0 -0
|
@@ -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;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
default as memoizedGetPxFromCssUnit,
|
|
6
|
+
getPxFromCssUnit,
|
|
7
|
+
} from '../get-px-from-css-unit';
|
|
8
|
+
|
|
9
|
+
describe( 'getPxFromCssUnit', () => {
|
|
10
|
+
// Absolute units.
|
|
11
|
+
describe( 'absolute unites should return px values', () => {
|
|
12
|
+
const testData = [
|
|
13
|
+
[ '25px', '25px' ],
|
|
14
|
+
[ '25.5', '26px' ],
|
|
15
|
+
[ '1cm', '38px' ],
|
|
16
|
+
[ '10mm', '38px' ],
|
|
17
|
+
[ '1in', '96px' ],
|
|
18
|
+
[ '12pt', '16px' ],
|
|
19
|
+
[ '1pc', '16px' ],
|
|
20
|
+
[ '40Q', '38px' ], // 40 Q should be 1 cm.
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
test.each( testData )( 'getPxFromCssUnit( %s )', ( unit, expected ) => {
|
|
24
|
+
expect( getPxFromCssUnit( unit ) ).toBe( expected );
|
|
25
|
+
} );
|
|
26
|
+
test.each( testData )(
|
|
27
|
+
'memoizedGetPxFromCssUnit( %s )',
|
|
28
|
+
( unit, expected ) => {
|
|
29
|
+
expect( memoizedGetPxFromCssUnit( unit ) ).toBe( expected );
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
test.each( testData )(
|
|
33
|
+
'cached memoizedGetPxFromCssUnit( %s )',
|
|
34
|
+
( unit, expected ) => {
|
|
35
|
+
expect( memoizedGetPxFromCssUnit( unit ) ).toBe( expected );
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
} );
|
|
39
|
+
|
|
40
|
+
describe( 'relative unites should return px values', () => {
|
|
41
|
+
const settings = {
|
|
42
|
+
fontSize: 10,
|
|
43
|
+
width: 100,
|
|
44
|
+
height: 200,
|
|
45
|
+
lineHeight: 2,
|
|
46
|
+
type: 'font',
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const testData = [
|
|
50
|
+
[ '2em', '20px' ],
|
|
51
|
+
[ '2rem', '20px' ],
|
|
52
|
+
[ '1.125rem', '11px' ],
|
|
53
|
+
[ '20vw', '20px' ],
|
|
54
|
+
[ '20vh', '40px' ],
|
|
55
|
+
[ '20vmin', '20px' ],
|
|
56
|
+
[ '20vmax', '40px' ],
|
|
57
|
+
[ '20lh', '40px' ],
|
|
58
|
+
[ '120%', '12px' ],
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
test.each( testData )( 'getPxFromCssUnit( %s )', ( unit, expected ) => {
|
|
62
|
+
expect( getPxFromCssUnit( unit, settings ) ).toBe( expected );
|
|
63
|
+
} );
|
|
64
|
+
test.each( testData )(
|
|
65
|
+
'memoizedGetPxFromCssUnit( %s )',
|
|
66
|
+
( unit, expected ) => {
|
|
67
|
+
expect( memoizedGetPxFromCssUnit( unit, settings ) ).toBe(
|
|
68
|
+
expected
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
test.each( testData )(
|
|
73
|
+
'cached memoizedGetPxFromCssUnit( %s )',
|
|
74
|
+
( unit, expected ) => {
|
|
75
|
+
expect( memoizedGetPxFromCssUnit( unit, settings ) ).toBe(
|
|
76
|
+
expected
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
} );
|
|
81
|
+
|
|
82
|
+
// Function units.
|
|
83
|
+
|
|
84
|
+
describe( 'function unites should return px values', () => {
|
|
85
|
+
const settings = {
|
|
86
|
+
fontSize: 10,
|
|
87
|
+
width: 100,
|
|
88
|
+
height: 200,
|
|
89
|
+
lineHeight: 2,
|
|
90
|
+
type: 'font',
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const testData = [
|
|
94
|
+
[ 'min(20px, 25px)', '20px' ],
|
|
95
|
+
[ 'min(20px, 9px, 12pt, 25px)', '9px' ],
|
|
96
|
+
[ 'max(20px, 25px)', '25px' ],
|
|
97
|
+
[ 'clamp(10px, 9px, 25px)', '10px' ],
|
|
98
|
+
[ 'clamp(10px, 35px, 25px)', '25px' ],
|
|
99
|
+
[ 'clamp(10px, 15px, 25px)', '15px' ],
|
|
100
|
+
[ 'min(max(20px,25px), 35px)', '25px' ],
|
|
101
|
+
[ 'max(min(20px,25px), 35px)', '35px' ],
|
|
102
|
+
[ '10px + 25px', '35px' ],
|
|
103
|
+
[ 'calc(10px + 25px)', '35px' ],
|
|
104
|
+
[ 'calc( 2 * 20px)', '40px' ],
|
|
105
|
+
[ 'calc(25px - 10px)', '15px' ],
|
|
106
|
+
[ 'min(10px + 25px, 55pt)', '35px' ],
|
|
107
|
+
[ 'calc(12vw * 10px)', '450px' ],
|
|
108
|
+
[ 'calc(45vw / 10px)', '17px' ],
|
|
109
|
+
[ '', null ],
|
|
110
|
+
[ undefined, null ],
|
|
111
|
+
[ 123, '123px' ],
|
|
112
|
+
[ 123.456, '123px' ],
|
|
113
|
+
[ 'abc', null ],
|
|
114
|
+
[ 'console.log("howdy"); + 10px', null ],
|
|
115
|
+
[ 'calc(12vw * 10px', null ], // Missing closing bracket.
|
|
116
|
+
[ 'calc( 1em + 0.875rem )', '30px' ], // Decimals
|
|
117
|
+
[
|
|
118
|
+
'clamp(1.8rem, 1.8rem + ((1vw / 0.48rem + 1rem) * 2.885), 3rem)',
|
|
119
|
+
'48px',
|
|
120
|
+
],
|
|
121
|
+
[
|
|
122
|
+
'clamp(5rem, 5.25rem + ((1vw - 0.48rem) * 9.096), 8rem)',
|
|
123
|
+
'80px',
|
|
124
|
+
],
|
|
125
|
+
[
|
|
126
|
+
'clamp(2.625rem, calc(2.625rem + ((1vw - 0.48rem) * 8.4135)), 3.25rem)',
|
|
127
|
+
'42px',
|
|
128
|
+
],
|
|
129
|
+
[ 'var:preset|font-size|medium', null ],
|
|
130
|
+
];
|
|
131
|
+
|
|
132
|
+
test.each( testData )( 'getPxFromCssUnit( %s )', ( unit, expected ) => {
|
|
133
|
+
expect( getPxFromCssUnit( unit, settings ) ).toBe( expected );
|
|
134
|
+
} );
|
|
135
|
+
test.each( testData )(
|
|
136
|
+
'memoizedGetPxFromCssUnit( %s )',
|
|
137
|
+
( unit, expected ) => {
|
|
138
|
+
expect( memoizedGetPxFromCssUnit( unit, settings ) ).toBe(
|
|
139
|
+
expected
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
);
|
|
143
|
+
test.each( testData )(
|
|
144
|
+
'cached memoizedGetPxFromCssUnit( %s )',
|
|
145
|
+
( unit, expected ) => {
|
|
146
|
+
expect( memoizedGetPxFromCssUnit( unit, settings ) ).toBe(
|
|
147
|
+
expected
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
} );
|
|
152
|
+
// Skip this test it might be useful in dev.
|
|
153
|
+
it.skip( 'test performance of memoizedGetPxFromCssUnit function', () => {
|
|
154
|
+
const start = Date.now();
|
|
155
|
+
let i = 0;
|
|
156
|
+
const intervals = 1000;
|
|
157
|
+
while ( i < intervals ) {
|
|
158
|
+
getPxFromCssUnit( 'max(25px, 35px)', { width: 200 } );
|
|
159
|
+
i++;
|
|
160
|
+
}
|
|
161
|
+
const rawDuration = Date.now() - start;
|
|
162
|
+
|
|
163
|
+
const startM = Date.now();
|
|
164
|
+
i = 0;
|
|
165
|
+
// The memoized Version should be at 10X better then the non default one.
|
|
166
|
+
while ( i < intervals * 10 ) {
|
|
167
|
+
memoizedGetPxFromCssUnit( 'max(25px, 35px)', { width: 201 } );
|
|
168
|
+
i++;
|
|
169
|
+
}
|
|
170
|
+
expect( rawDuration > Date.now() - startM ).toBe( true );
|
|
171
|
+
} );
|
|
172
|
+
} );
|
package/src/modal/README.md
CHANGED
|
@@ -4,12 +4,6 @@ Modals give users information and choices related to a task they’re trying to
|
|
|
4
4
|
|
|
5
5
|

|
|
6
6
|
|
|
7
|
-
## Table of contents
|
|
8
|
-
|
|
9
|
-
1. [Design guidelines](#design-guidelines)
|
|
10
|
-
2. [Development guidelines](#development-guidelines)
|
|
11
|
-
3. [Related components](#related-components)
|
|
12
|
-
|
|
13
7
|
## Design guidelines
|
|
14
8
|
|
|
15
9
|
### Usage
|
package/src/modal/index.tsx
CHANGED
|
@@ -43,12 +43,12 @@ import StyleProvider from '../style-provider';
|
|
|
43
43
|
import type { ModalProps } from './types';
|
|
44
44
|
|
|
45
45
|
// Used to track and dismiss the prior modal when another opens unless nested.
|
|
46
|
-
const
|
|
47
|
-
ModalProps[ 'onRequestClose' ] | undefined
|
|
48
|
-
>[]
|
|
49
|
-
const ModalContext = createContext( level0Dismissers );
|
|
46
|
+
const ModalContext = createContext<
|
|
47
|
+
MutableRefObject< ModalProps[ 'onRequestClose' ] | undefined >[]
|
|
48
|
+
>( [] );
|
|
50
49
|
|
|
51
|
-
|
|
50
|
+
// Used to track body class names applied while modals are open.
|
|
51
|
+
const bodyOpenClasses = new Map< string, number >();
|
|
52
52
|
|
|
53
53
|
function UnforwardedModal(
|
|
54
54
|
props: ModalProps,
|
|
@@ -146,7 +146,7 @@ function UnforwardedModal(
|
|
|
146
146
|
// one should remain open at a time and the list enables closing prior ones.
|
|
147
147
|
const dismissers = useContext( ModalContext );
|
|
148
148
|
// Used for the tracking and dismissing any nested modals.
|
|
149
|
-
const nestedDismissers = useRef< typeof
|
|
149
|
+
const nestedDismissers = useRef< typeof dismissers >( [] );
|
|
150
150
|
|
|
151
151
|
// Updates the stack tracking open modals at this level and calls
|
|
152
152
|
// onRequestClose for any prior and/or nested modals as applicable.
|
|
@@ -162,20 +162,22 @@ function UnforwardedModal(
|
|
|
162
162
|
};
|
|
163
163
|
}, [ dismissers ] );
|
|
164
164
|
|
|
165
|
-
const isLevel0 = dismissers === level0Dismissers;
|
|
166
165
|
// Adds/removes the value of bodyOpenClassName to body element.
|
|
167
166
|
useEffect( () => {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
167
|
+
const theClass = bodyOpenClassName;
|
|
168
|
+
const oneMore = 1 + ( bodyOpenClasses.get( theClass ) ?? 0 );
|
|
169
|
+
bodyOpenClasses.set( theClass, oneMore );
|
|
170
|
+
document.body.classList.add( bodyOpenClassName );
|
|
172
171
|
return () => {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
172
|
+
const oneLess = bodyOpenClasses.get( theClass )! - 1;
|
|
173
|
+
if ( oneLess === 0 ) {
|
|
174
|
+
document.body.classList.remove( theClass );
|
|
175
|
+
bodyOpenClasses.delete( theClass );
|
|
176
|
+
} else {
|
|
177
|
+
bodyOpenClasses.set( theClass, oneLess );
|
|
176
178
|
}
|
|
177
179
|
};
|
|
178
|
-
}, [ bodyOpenClassName
|
|
180
|
+
}, [ bodyOpenClassName ] );
|
|
179
181
|
|
|
180
182
|
// Calls the isContentScrollable callback when the Modal children container resizes.
|
|
181
183
|
useLayoutEffect( () => {
|
|
@@ -207,7 +209,7 @@ function UnforwardedModal(
|
|
|
207
209
|
|
|
208
210
|
if (
|
|
209
211
|
shouldCloseOnEsc &&
|
|
210
|
-
event.code === 'Escape' &&
|
|
212
|
+
( event.code === 'Escape' || event.key === 'Escape' ) &&
|
|
211
213
|
! event.defaultPrevented
|
|
212
214
|
) {
|
|
213
215
|
event.preventDefault();
|
package/src/modal/test/index.tsx
CHANGED
|
@@ -7,7 +7,7 @@ import userEvent from '@testing-library/user-event';
|
|
|
7
7
|
/**
|
|
8
8
|
* WordPress dependencies
|
|
9
9
|
*/
|
|
10
|
-
import { useState } from '@wordpress/element';
|
|
10
|
+
import { useEffect, useState } from '@wordpress/element';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Internal dependencies
|
|
@@ -388,4 +388,93 @@ describe( 'Modal', () => {
|
|
|
388
388
|
expect( opener ).toHaveFocus();
|
|
389
389
|
} );
|
|
390
390
|
} );
|
|
391
|
+
|
|
392
|
+
describe( 'Body class name', () => {
|
|
393
|
+
const overrideClass = 'is-any-open';
|
|
394
|
+
const BodyClassDemo = () => {
|
|
395
|
+
const [ isAShown, setIsAShown ] = useState( false );
|
|
396
|
+
const [ isA1Shown, setIsA1Shown ] = useState( false );
|
|
397
|
+
const [ isBShown, setIsBShown ] = useState( false );
|
|
398
|
+
const [ isClassOverriden, setIsClassOverriden ] = useState( false );
|
|
399
|
+
useEffect( () => {
|
|
400
|
+
const toggles: ( e: KeyboardEvent ) => void = ( {
|
|
401
|
+
key,
|
|
402
|
+
metaKey,
|
|
403
|
+
} ) => {
|
|
404
|
+
if ( key === 'a' ) {
|
|
405
|
+
if ( metaKey ) return setIsA1Shown( ( v ) => ! v );
|
|
406
|
+
return setIsAShown( ( v ) => ! v );
|
|
407
|
+
}
|
|
408
|
+
if ( key === 'b' ) return setIsBShown( ( v ) => ! v );
|
|
409
|
+
if ( key === 'c' )
|
|
410
|
+
return setIsClassOverriden( ( v ) => ! v );
|
|
411
|
+
};
|
|
412
|
+
document.addEventListener( 'keydown', toggles );
|
|
413
|
+
return () =>
|
|
414
|
+
void document.removeEventListener( 'keydown', toggles );
|
|
415
|
+
}, [] );
|
|
416
|
+
return (
|
|
417
|
+
<>
|
|
418
|
+
{ isAShown && (
|
|
419
|
+
<Modal
|
|
420
|
+
bodyOpenClassName={
|
|
421
|
+
isClassOverriden ? overrideClass : 'is-A-open'
|
|
422
|
+
}
|
|
423
|
+
onRequestClose={ () => setIsAShown( false ) }
|
|
424
|
+
>
|
|
425
|
+
<p>Modal A contents</p>
|
|
426
|
+
{ isA1Shown && (
|
|
427
|
+
<Modal
|
|
428
|
+
title="Nested"
|
|
429
|
+
onRequestClose={ () =>
|
|
430
|
+
setIsA1Shown( false )
|
|
431
|
+
}
|
|
432
|
+
>
|
|
433
|
+
<p>Modal A1 contents</p>
|
|
434
|
+
</Modal>
|
|
435
|
+
) }
|
|
436
|
+
</Modal>
|
|
437
|
+
) }
|
|
438
|
+
{ isBShown && (
|
|
439
|
+
<Modal
|
|
440
|
+
bodyOpenClassName={
|
|
441
|
+
isClassOverriden ? overrideClass : 'is-B-open'
|
|
442
|
+
}
|
|
443
|
+
onRequestClose={ () => setIsBShown( false ) }
|
|
444
|
+
>
|
|
445
|
+
<p>Modal B contents</p>
|
|
446
|
+
</Modal>
|
|
447
|
+
) }
|
|
448
|
+
</>
|
|
449
|
+
);
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
it( 'is added and removed when modal opens and closes including when closed due to another modal opening', async () => {
|
|
453
|
+
const user = userEvent.setup();
|
|
454
|
+
|
|
455
|
+
const { baseElement } = render( <BodyClassDemo /> );
|
|
456
|
+
|
|
457
|
+
await user.keyboard( 'a' ); // Opens modal A.
|
|
458
|
+
expect( baseElement ).toHaveClass( 'is-A-open' );
|
|
459
|
+
|
|
460
|
+
await user.keyboard( 'b' ); // Opens modal B > closes modal A.
|
|
461
|
+
expect( baseElement ).toHaveClass( 'is-B-open' );
|
|
462
|
+
expect( baseElement ).not.toHaveClass( 'is-A-open' );
|
|
463
|
+
|
|
464
|
+
await user.keyboard( 'b' ); // Closes modal B.
|
|
465
|
+
expect( baseElement ).not.toHaveClass( 'is-B-open' );
|
|
466
|
+
} );
|
|
467
|
+
|
|
468
|
+
it( 'is removed even when prop changes while nested modal is open', async () => {
|
|
469
|
+
const user = userEvent.setup();
|
|
470
|
+
|
|
471
|
+
const { baseElement } = render( <BodyClassDemo /> );
|
|
472
|
+
|
|
473
|
+
await user.keyboard( 'a' ); // Opens modal A.
|
|
474
|
+
await user.keyboard( '{Meta>}a{/Meta}' ); // Opens nested modal.
|
|
475
|
+
await user.keyboard( 'c' ); // Changes `bodyOpenClassName`.
|
|
476
|
+
await user.keyboard( 'a' ); // Closes modal A.
|
|
477
|
+
expect( baseElement ).not.toHaveClass( 'is-A-open' );
|
|
478
|
+
} );
|
|
479
|
+
} );
|
|
391
480
|
} );
|