@wordpress/components 37.0.0 → 38.0.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/AGENTS.md +2 -2
- package/CHANGELOG.md +46 -0
- package/build/autocomplete/index.cjs +3 -1
- package/build/autocomplete/index.cjs.map +2 -2
- package/build/color-picker/component.cjs +14 -5
- package/build/color-picker/component.cjs.map +2 -2
- package/build/color-picker/picker.cjs +95 -23
- package/build/color-picker/picker.cjs.map +2 -2
- package/build/confirm-dialog/component.cjs +86 -4
- package/build/confirm-dialog/component.cjs.map +3 -3
- package/build/content-editable-control/index.cjs +19 -9
- package/build/content-editable-control/index.cjs.map +3 -3
- package/build/custom-select-control/index.cjs +1 -2
- package/build/custom-select-control/index.cjs.map +2 -2
- package/build/disabled/index.cjs +87 -4
- package/build/disabled/index.cjs.map +4 -4
- package/build/form-token-field/index.cjs +87 -2
- package/build/form-token-field/index.cjs.map +3 -3
- package/build/gradient-picker/index.cjs +26 -20
- package/build/gradient-picker/index.cjs.map +2 -2
- package/build/input-control/index.cjs +0 -1
- package/build/input-control/index.cjs.map +2 -2
- package/build/input-control/styles/input-control-styles.cjs +23 -31
- package/build/input-control/styles/input-control-styles.cjs.map +2 -2
- package/build/private-apis.cjs +0 -2
- package/build/private-apis.cjs.map +3 -3
- package/build/range-control/index.cjs +0 -1
- package/build/range-control/index.cjs.map +2 -2
- package/build/sandbox/index.cjs +23 -4
- package/build/sandbox/index.cjs.map +3 -3
- package/build/search-control/index.cjs +93 -10
- package/build/search-control/index.cjs.map +4 -4
- package/build/select-control/index.cjs +0 -1
- package/build/select-control/index.cjs.map +2 -2
- package/build/select-control/styles/select-control-styles.cjs +9 -16
- package/build/select-control/styles/select-control-styles.cjs.map +2 -2
- package/build/slot-fill/fill.cjs.map +2 -2
- package/build/toggle-group-control/toggle-group-control/component.cjs +91 -8
- package/build/toggle-group-control/toggle-group-control/component.cjs.map +4 -4
- package/build/toggle-group-control/toggle-group-control-option-base/component.cjs +98 -17
- package/build/toggle-group-control/toggle-group-control-option-base/component.cjs.map +4 -4
- package/build/tools-panel/tools-panel/component.cjs +6 -0
- package/build/tools-panel/tools-panel/component.cjs.map +2 -2
- package/build/tools-panel/tools-panel/hook.cjs +87 -11
- package/build/tools-panel/tools-panel/hook.cjs.map +4 -4
- package/build/tools-panel/tools-panel-header/component.cjs +87 -2
- package/build/tools-panel/tools-panel-header/component.cjs.map +3 -3
- package/build/tools-panel/tools-panel-header/hook.cjs +90 -20
- package/build/tools-panel/tools-panel-header/hook.cjs.map +4 -4
- package/build/tools-panel/tools-panel-item/hook.cjs +88 -9
- package/build/tools-panel/tools-panel-item/hook.cjs.map +4 -4
- package/build/validated-form-controls/control-with-error.cjs +3 -0
- package/build/validated-form-controls/control-with-error.cjs.map +2 -2
- package/build-module/autocomplete/index.mjs +3 -1
- package/build-module/autocomplete/index.mjs.map +2 -2
- package/build-module/color-picker/component.mjs +14 -5
- package/build-module/color-picker/component.mjs.map +2 -2
- package/build-module/color-picker/picker.mjs +96 -24
- package/build-module/color-picker/picker.mjs.map +2 -2
- package/build-module/confirm-dialog/component.mjs +86 -4
- package/build-module/confirm-dialog/component.mjs.map +3 -3
- package/build-module/content-editable-control/index.mjs +21 -11
- package/build-module/content-editable-control/index.mjs.map +2 -2
- package/build-module/custom-select-control/index.mjs +1 -2
- package/build-module/custom-select-control/index.mjs.map +2 -2
- package/build-module/disabled/index.mjs +87 -4
- package/build-module/disabled/index.mjs.map +3 -3
- package/build-module/form-token-field/index.mjs +88 -3
- package/build-module/form-token-field/index.mjs.map +3 -3
- package/build-module/gradient-picker/index.mjs +26 -20
- package/build-module/gradient-picker/index.mjs.map +2 -2
- package/build-module/input-control/index.mjs +0 -1
- package/build-module/input-control/index.mjs.map +2 -2
- package/build-module/input-control/styles/input-control-styles.mjs +23 -31
- package/build-module/input-control/styles/input-control-styles.mjs.map +2 -2
- package/build-module/private-apis.mjs +0 -2
- package/build-module/private-apis.mjs.map +2 -2
- package/build-module/range-control/index.mjs +0 -1
- package/build-module/range-control/index.mjs.map +2 -2
- package/build-module/sandbox/index.mjs +13 -4
- package/build-module/sandbox/index.mjs.map +2 -2
- package/build-module/search-control/index.mjs +93 -10
- package/build-module/search-control/index.mjs.map +3 -3
- package/build-module/select-control/index.mjs +0 -1
- package/build-module/select-control/index.mjs.map +2 -2
- package/build-module/select-control/styles/select-control-styles.mjs +9 -16
- package/build-module/select-control/styles/select-control-styles.mjs.map +2 -2
- package/build-module/slot-fill/fill.mjs.map +2 -2
- package/build-module/toggle-group-control/toggle-group-control/component.mjs +92 -9
- package/build-module/toggle-group-control/toggle-group-control/component.mjs.map +3 -3
- package/build-module/toggle-group-control/toggle-group-control-option-base/component.mjs +99 -18
- package/build-module/toggle-group-control/toggle-group-control-option-base/component.mjs.map +3 -3
- package/build-module/tools-panel/tools-panel/component.mjs +6 -0
- package/build-module/tools-panel/tools-panel/component.mjs.map +2 -2
- package/build-module/tools-panel/tools-panel/hook.mjs +87 -11
- package/build-module/tools-panel/tools-panel/hook.mjs.map +3 -3
- package/build-module/tools-panel/tools-panel-header/component.mjs +87 -2
- package/build-module/tools-panel/tools-panel-header/component.mjs.map +3 -3
- package/build-module/tools-panel/tools-panel-header/hook.mjs +90 -20
- package/build-module/tools-panel/tools-panel-header/hook.mjs.map +3 -3
- package/build-module/tools-panel/tools-panel-item/hook.mjs +89 -10
- package/build-module/tools-panel/tools-panel-item/hook.mjs.map +3 -3
- package/build-module/validated-form-controls/control-with-error.mjs +3 -0
- package/build-module/validated-form-controls/control-with-error.mjs.map +2 -2
- package/build-style/style-rtl.css +20 -24
- package/build-style/style.css +20 -24
- package/build-types/autocomplete/index.d.ts +7 -3
- package/build-types/autocomplete/index.d.ts.map +1 -1
- package/build-types/border-box-control/border-box-control/component.d.ts +1 -3
- package/build-types/border-box-control/border-box-control/component.d.ts.map +1 -1
- package/build-types/border-box-control/stories/index.story.d.ts +1 -3
- package/build-types/border-box-control/stories/index.story.d.ts.map +1 -1
- package/build-types/border-box-control/types.d.ts +1 -15
- package/build-types/border-box-control/types.d.ts.map +1 -1
- package/build-types/box-control/input-control.d.ts +3 -0
- package/build-types/box-control/input-control.d.ts.map +1 -0
- package/build-types/box-control/styles/box-control-styles.d.ts +4 -8
- package/build-types/box-control/styles/box-control-styles.d.ts.map +1 -1
- package/build-types/box-control/types.d.ts +1 -8
- package/build-types/box-control/types.d.ts.map +1 -1
- package/build-types/card/context.d.ts +3 -0
- package/build-types/card/context.d.ts.map +1 -0
- package/build-types/color-picker/component.d.ts.map +1 -1
- package/build-types/color-picker/picker.d.ts +17 -1
- package/build-types/color-picker/picker.d.ts.map +1 -1
- package/build-types/color-picker/styles.d.ts +4 -8
- package/build-types/color-picker/styles.d.ts.map +1 -1
- package/build-types/color-picker/types.d.ts +2 -0
- package/build-types/color-picker/types.d.ts.map +1 -1
- package/build-types/confirm-dialog/component.d.ts.map +1 -1
- package/build-types/content-editable-control/index.d.ts.map +1 -1
- package/build-types/context/wordpress-component.d.ts +2 -1
- package/build-types/context/wordpress-component.d.ts.map +1 -1
- package/build-types/custom-select-control/index.d.ts.map +1 -1
- package/build-types/custom-select-control/types.d.ts +1 -8
- package/build-types/custom-select-control/types.d.ts.map +1 -1
- package/build-types/date-time/date/index.d.ts +23 -0
- package/build-types/date-time/date/index.d.ts.map +1 -0
- package/build-types/date-time/date/styles.d.ts +45 -0
- package/build-types/date-time/date/styles.d.ts.map +1 -0
- package/build-types/date-time/date/test/index.d.ts +2 -0
- package/build-types/date-time/date/test/index.d.ts.map +1 -0
- package/build-types/date-time/date/test/use-lilius.d.ts +2 -0
- package/build-types/date-time/date/test/use-lilius.d.ts.map +1 -0
- package/build-types/date-time/date/use-lilius/index.d.ts +169 -0
- package/build-types/date-time/date/use-lilius/index.d.ts.map +1 -0
- package/build-types/date-time/time/index.d.ts +27 -0
- package/build-types/date-time/time/index.d.ts.map +1 -0
- package/build-types/date-time/time/styles.d.ts +93 -0
- package/build-types/date-time/time/styles.d.ts.map +1 -0
- package/build-types/date-time/time/test/index.d.ts +2 -0
- package/build-types/date-time/time/test/index.d.ts.map +1 -0
- package/build-types/date-time/time/time-input/index.d.ts +4 -0
- package/build-types/date-time/time/time-input/index.d.ts.map +1 -0
- package/build-types/date-time/time/time-input/test/index.d.ts +2 -0
- package/build-types/date-time/time/time-input/test/index.d.ts.map +1 -0
- package/build-types/date-time/time/timezone.d.ts +7 -0
- package/build-types/date-time/time/timezone.d.ts.map +1 -0
- package/build-types/date-time/time-picker/styles.d.ts +8 -16
- package/build-types/date-time/time-picker/styles.d.ts.map +1 -1
- package/build-types/disabled/index.d.ts.map +1 -1
- package/build-types/divider/styles.d.ts +10 -0
- package/build-types/divider/styles.d.ts.map +1 -0
- package/build-types/flex/styles.d.ts +17 -0
- package/build-types/flex/styles.d.ts.map +1 -0
- package/build-types/focal-point-picker/styles/focal-point-picker-style.d.ts +2 -4
- package/build-types/focal-point-picker/styles/focal-point-picker-style.d.ts.map +1 -1
- package/build-types/font-size-picker/index.d.ts +12 -2
- package/build-types/font-size-picker/index.d.ts.map +1 -1
- package/build-types/font-size-picker/stories/e2e/index.story.d.ts +12 -1
- package/build-types/font-size-picker/stories/e2e/index.story.d.ts.map +1 -1
- package/build-types/font-size-picker/types.d.ts +2 -15
- 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/gradient-picker/index.d.ts.map +1 -1
- package/build-types/gradient-picker/stories/index.story.d.ts +1 -0
- package/build-types/gradient-picker/stories/index.story.d.ts.map +1 -1
- package/build-types/gradient-picker/test/index.d.ts +2 -0
- package/build-types/gradient-picker/test/index.d.ts.map +1 -0
- package/build-types/gradient-picker/types.d.ts +19 -4
- package/build-types/gradient-picker/types.d.ts.map +1 -1
- package/build-types/input-control/index.d.ts.map +1 -1
- package/build-types/input-control/styles/input-control-styles.d.ts +0 -6
- package/build-types/input-control/styles/input-control-styles.d.ts.map +1 -1
- package/build-types/input-control/types.d.ts +1 -8
- package/build-types/input-control/types.d.ts.map +1 -1
- package/build-types/mobile/image/constants.d.ts +5 -0
- package/build-types/mobile/image/constants.d.ts.map +1 -0
- package/build-types/navigation/back-button/index.d.ts +7 -0
- package/build-types/navigation/back-button/index.d.ts.map +1 -0
- package/build-types/navigation/constants.d.ts +3 -0
- package/build-types/navigation/constants.d.ts.map +1 -0
- package/build-types/navigation/context.d.ts +4 -0
- package/build-types/navigation/context.d.ts.map +1 -0
- package/build-types/navigation/group/context.d.ts +7 -0
- package/build-types/navigation/group/context.d.ts.map +1 -0
- package/build-types/navigation/group/index.d.ts +7 -0
- package/build-types/navigation/group/index.d.ts.map +1 -0
- package/build-types/navigation/index.d.ts +46 -0
- package/build-types/navigation/index.d.ts.map +1 -0
- package/build-types/navigation/item/base-content.d.ts +3 -0
- package/build-types/navigation/item/base-content.d.ts.map +1 -0
- package/build-types/navigation/item/base.d.ts +3 -0
- package/build-types/navigation/item/base.d.ts.map +1 -0
- package/build-types/navigation/item/index.d.ts +7 -0
- package/build-types/navigation/item/index.d.ts.map +1 -0
- package/build-types/navigation/item/use-navigation-tree-item.d.ts +3 -0
- package/build-types/navigation/item/use-navigation-tree-item.d.ts.map +1 -0
- package/build-types/navigation/menu/context.d.ts +7 -0
- package/build-types/navigation/menu/context.d.ts.map +1 -0
- package/build-types/navigation/menu/index.d.ts +7 -0
- package/build-types/navigation/menu/index.d.ts.map +1 -0
- package/build-types/navigation/menu/menu-title-search.d.ts +3 -0
- package/build-types/navigation/menu/menu-title-search.d.ts.map +1 -0
- package/build-types/navigation/menu/menu-title.d.ts +3 -0
- package/build-types/navigation/menu/menu-title.d.ts.map +1 -0
- package/build-types/navigation/menu/search-no-results-found.d.ts +3 -0
- package/build-types/navigation/menu/search-no-results-found.d.ts.map +1 -0
- package/build-types/navigation/menu/use-navigation-tree-menu.d.ts +3 -0
- package/build-types/navigation/menu/use-navigation-tree-menu.d.ts.map +1 -0
- package/build-types/navigation/stories/index.story.d.ts +23 -0
- package/build-types/navigation/stories/index.story.d.ts.map +1 -0
- package/build-types/navigation/stories/utils/controlled-state.d.ts +7 -0
- package/build-types/navigation/stories/utils/controlled-state.d.ts.map +1 -0
- package/build-types/navigation/stories/utils/default.d.ts +10 -0
- package/build-types/navigation/stories/utils/default.d.ts.map +1 -0
- package/build-types/navigation/stories/utils/group.d.ts +10 -0
- package/build-types/navigation/stories/utils/group.d.ts.map +1 -0
- package/build-types/navigation/stories/utils/hide-if-empty.d.ts +10 -0
- package/build-types/navigation/stories/utils/hide-if-empty.d.ts.map +1 -0
- package/build-types/navigation/stories/utils/more-examples.d.ts +10 -0
- package/build-types/navigation/stories/utils/more-examples.d.ts.map +1 -0
- package/build-types/navigation/stories/utils/search.d.ts +10 -0
- package/build-types/navigation/stories/utils/search.d.ts.map +1 -0
- package/build-types/navigation/styles/navigation-styles.d.ts +55 -0
- package/build-types/navigation/styles/navigation-styles.d.ts.map +1 -0
- package/build-types/navigation/test/index.d.ts +2 -0
- package/build-types/navigation/test/index.d.ts.map +1 -0
- package/build-types/navigation/types.d.ts +266 -0
- package/build-types/navigation/types.d.ts.map +1 -0
- package/build-types/navigation/use-create-navigation-tree.d.ts +15 -0
- package/build-types/navigation/use-create-navigation-tree.d.ts.map +1 -0
- package/build-types/navigation/use-navigation-tree-nodes.d.ts +10 -0
- package/build-types/navigation/use-navigation-tree-nodes.d.ts.map +1 -0
- package/build-types/navigation/utils.d.ts +3 -0
- package/build-types/navigation/utils.d.ts.map +1 -0
- package/build-types/number-control/index.d.ts +2 -4
- package/build-types/number-control/index.d.ts.map +1 -1
- package/build-types/number-control/stories/index.story.d.ts +2 -4
- package/build-types/number-control/stories/index.story.d.ts.map +1 -1
- package/build-types/number-control/types.d.ts +1 -15
- package/build-types/number-control/types.d.ts.map +1 -1
- package/build-types/private-apis.d.ts.map +1 -1
- package/build-types/range-control/index.d.ts +2 -4
- package/build-types/range-control/index.d.ts.map +1 -1
- package/build-types/range-control/styles/range-control-styles.d.ts +2 -4
- package/build-types/range-control/styles/range-control-styles.d.ts.map +1 -1
- package/build-types/range-control/types.d.ts +2 -16
- package/build-types/range-control/types.d.ts.map +1 -1
- package/build-types/sandbox/index.d.ts.map +1 -1
- package/build-types/sandbox/types.d.ts +11 -0
- package/build-types/sandbox/types.d.ts.map +1 -1
- package/build-types/search-control/index.d.ts.map +1 -1
- package/build-types/search-control/types.d.ts +1 -1
- package/build-types/search-control/types.d.ts.map +1 -1
- package/build-types/select-control/index.d.ts.map +1 -1
- package/build-types/select-control/styles/select-control-styles.d.ts.map +1 -1
- package/build-types/select-control/types.d.ts +0 -7
- package/build-types/select-control/types.d.ts.map +1 -1
- package/build-types/slot-fill/fill.d.ts.map +1 -1
- package/build-types/slot-fill/stories/index.story.d.ts +1 -6
- package/build-types/slot-fill/stories/index.story.d.ts.map +1 -1
- package/build-types/surface/styles.d.ts +11 -0
- package/build-types/surface/styles.d.ts.map +1 -0
- package/build-types/theme/styles.d.ts +10 -0
- package/build-types/theme/styles.d.ts.map +1 -0
- package/build-types/toggle-group-control/toggle-group-control/component.d.ts +0 -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-option-base/component.d.ts.map +1 -1
- package/build-types/toggle-group-control/types.d.ts +0 -7
- package/build-types/toggle-group-control/types.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.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.map +1 -1
- package/build-types/tools-panel/tools-panel-item/hook.d.ts.map +1 -1
- package/build-types/tree-select/types.d.ts +1 -8
- package/build-types/tree-select/types.d.ts.map +1 -1
- package/build-types/truncate/styles.d.ts +2 -0
- package/build-types/truncate/styles.d.ts.map +1 -0
- package/build-types/unit-control/index.d.ts +2 -4
- package/build-types/unit-control/index.d.ts.map +1 -1
- package/build-types/unit-control/styles/unit-control-styles.d.ts +2 -4
- package/build-types/unit-control/styles/unit-control-styles.d.ts.map +1 -1
- package/build-types/unit-control/types.d.ts +1 -15
- package/build-types/unit-control/types.d.ts.map +1 -1
- package/build-types/utils/deprecated-36px-size.d.ts +7 -0
- package/build-types/utils/deprecated-36px-size.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/number-control.d.ts +2 -4
- package/build-types/validated-form-controls/components/number-control.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/range-control.d.ts +2 -4
- package/build-types/validated-form-controls/components/range-control.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/stories/overview.story.d.ts +5 -0
- package/build-types/validated-form-controls/components/stories/overview.story.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/toggle-group-control.d.ts +1 -2
- package/build-types/validated-form-controls/components/toggle-group-control.d.ts.map +1 -1
- package/build-types/validated-form-controls/control-with-error.d.ts.map +1 -1
- package/build-types/visually-hidden/test/index.d.ts +2 -0
- package/build-types/visually-hidden/test/index.d.ts.map +1 -0
- package/package.json +27 -27
- package/src/autocomplete/index.tsx +16 -3
- package/src/base-control/README.md +2 -2
- package/src/border-box-control/types.ts +4 -15
- package/src/box-control/types.ts +4 -8
- package/src/card/test/__snapshots__/index.tsx.snap +1 -1
- package/src/checkbox-control/test/__snapshots__/index.tsx.snap +1 -1
- package/src/color-indicator/test/__snapshots__/index.tsx.snap +1 -1
- package/src/color-picker/component.tsx +23 -19
- package/src/color-picker/picker.tsx +144 -21
- package/src/color-picker/test/index.tsx +502 -0
- package/src/color-picker/types.ts +2 -0
- package/src/combobox-control/style.scss +2 -2
- package/src/confirm-dialog/component.tsx +2 -4
- package/src/confirm-dialog/style.module.scss +7 -0
- package/src/confirm-dialog/test/index.tsx +5 -0
- package/src/content-editable-control/index.tsx +24 -5
- package/src/content-editable-control/style.module.scss +1 -1
- package/src/content-editable-control/test/index.tsx +20 -8
- package/src/context/test/__snapshots__/context-system-provider.js.snap +1 -1
- package/src/context/wordpress-component.ts +7 -2
- package/src/custom-gradient-picker/test/index.tsx +111 -1
- package/src/custom-select-control/index.tsx +1 -2
- package/src/custom-select-control/test/__snapshots__/index.tsx.snap +6 -0
- package/src/custom-select-control/test/index.tsx +23 -0
- package/src/custom-select-control/types.ts +1 -8
- package/src/disabled/index.tsx +7 -5
- package/src/disabled/style.module.scss +15 -0
- package/src/disabled/test/index.tsx +6 -4
- package/src/elevation/test/__snapshots__/index.tsx.snap +1 -1
- package/src/external-link/style.scss +6 -12
- package/src/flex/test/__snapshots__/index.tsx.snap +1 -1
- package/src/font-size-picker/types.ts +6 -15
- package/src/form-toggle/test/__snapshots__/index.tsx.snap +1 -1
- package/src/form-token-field/index.tsx +5 -4
- package/src/form-token-field/style.module.scss +6 -0
- package/src/form-token-field/style.scss +2 -2
- package/src/gradient-picker/README.md +21 -3
- package/src/gradient-picker/index.tsx +43 -28
- package/src/gradient-picker/stories/index.story.tsx +41 -5
- package/src/gradient-picker/test/index.tsx +148 -0
- package/src/gradient-picker/types.ts +24 -4
- package/src/h-stack/test/__snapshots__/index.tsx.snap +1 -1
- package/src/heading/test/__snapshots__/index.tsx.snap +1 -1
- package/src/higher-order/with-filters/test/__snapshots__/index.tsx.snap +1 -1
- package/src/input-control/index.tsx +0 -1
- package/src/input-control/styles/input-control-styles.tsx +0 -8
- package/src/input-control/test/__snapshots__/index.js.snap +11 -0
- package/src/input-control/test/index.js +28 -0
- package/src/input-control/types.ts +1 -8
- package/src/item-group/test/__snapshots__/index.js.snap +1 -1
- package/src/menu/README.md +2 -2
- package/src/menu-item/test/__snapshots__/index.js.snap +1 -1
- package/src/modal/test/index.tsx +42 -0
- package/src/notice/test/__snapshots__/index.tsx.snap +1 -1
- package/src/number-control/types.ts +1 -22
- package/src/panel/test/__snapshots__/body.tsx.snap +1 -1
- package/src/panel/test/__snapshots__/header.tsx.snap +1 -1
- package/src/panel/test/__snapshots__/index.tsx.snap +1 -1
- package/src/panel/test/__snapshots__/row.tsx.snap +1 -1
- package/src/private-apis.ts +0 -2
- package/src/range-control/index.tsx +0 -1
- package/src/range-control/types.ts +2 -15
- package/src/sandbox/index.tsx +22 -2
- package/src/sandbox/test/index.tsx +21 -0
- package/src/sandbox/types.ts +11 -0
- package/src/scrollable/test/__snapshots__/index.tsx.snap +1 -1
- package/src/search-control/index.tsx +23 -20
- package/src/search-control/style.module.scss +16 -0
- package/src/search-control/test/index.tsx +8 -0
- package/src/search-control/types.ts +1 -1
- package/src/select-control/index.tsx +0 -1
- package/src/select-control/styles/select-control-styles.ts +0 -7
- package/src/select-control/test/__snapshots__/select-control.tsx.snap +11 -0
- package/src/select-control/test/select-control.tsx +37 -0
- package/src/select-control/types.ts +0 -7
- package/src/shortcut/test/__snapshots__/index.tsx.snap +1 -1
- package/src/slot-fill/fill.tsx +3 -9
- package/src/slot-fill/stories/index.story.tsx +52 -10
- package/src/slot-fill/test/__snapshots__/slot.js.snap +1 -1
- package/src/slot-fill/test/slot.js +53 -11
- package/src/spacer/test/__snapshots__/index.tsx.snap +1 -1
- package/src/text/test/__snapshots__/index.tsx.snap +1 -1
- package/src/text-control/style.scss +1 -1
- package/src/toggle-group-control/test/__snapshots__/index.tsx.snap +29 -707
- package/src/toggle-group-control/test/index.tsx +33 -3
- package/src/toggle-group-control/toggle-group-control/component.tsx +11 -16
- package/src/toggle-group-control/toggle-group-control/style.module.scss +63 -0
- package/src/toggle-group-control/toggle-group-control-option-base/component.tsx +22 -24
- package/src/toggle-group-control/toggle-group-control-option-base/style.module.scss +88 -0
- package/src/toggle-group-control/types.ts +0 -7
- package/src/tools-panel/style.module.scss +117 -0
- package/src/tools-panel/test/index.tsx +105 -39
- package/src/tools-panel/tools-panel/component.tsx +12 -1
- package/src/tools-panel/tools-panel/hook.ts +13 -15
- package/src/tools-panel/tools-panel-header/component.tsx +6 -2
- package/src/tools-panel/tools-panel-header/hook.ts +7 -25
- package/src/tools-panel/tools-panel-item/hook.ts +16 -34
- package/src/tooltip/test/index.tsx +1 -1
- package/src/tree-grid/test/__snapshots__/cell.tsx.snap +1 -1
- package/src/tree-grid/test/__snapshots__/index.tsx.snap +1 -1
- package/src/tree-grid/test/__snapshots__/roving-tab-index-item.tsx.snap +1 -1
- package/src/tree-grid/test/__snapshots__/roving-tab-index.tsx.snap +1 -1
- package/src/tree-grid/test/__snapshots__/row.tsx.snap +1 -1
- package/src/tree-select/README.md +1 -1
- package/src/tree-select/types.ts +1 -8
- package/src/unit-control/types.ts +1 -18
- package/src/utils/theme-variables.scss +1 -0
- package/src/v-stack/test/__snapshots__/index.tsx.snap +1 -1
- package/src/validated-form-controls/components/stories/overview.story.tsx +51 -0
- package/src/validated-form-controls/control-with-error.tsx +9 -0
- package/src/validated-form-controls/style.scss +3 -3
- package/src/validated-form-controls/test/control-with-error.tsx +42 -0
- package/src/view/test/__snapshots__/index.js.snap +1 -1
- package/build/confirm-dialog/styles.cjs +0 -42
- package/build/confirm-dialog/styles.cjs.map +0 -7
- package/build/disabled/styles/disabled-styles.cjs +0 -42
- package/build/disabled/styles/disabled-styles.cjs.map +0 -7
- package/build/form-token-field/styles.cjs +0 -49
- package/build/form-token-field/styles.cjs.map +0 -7
- package/build/search-control/styles.cjs +0 -74
- package/build/search-control/styles.cjs.map +0 -7
- package/build/theme/color-algorithms.cjs +0 -131
- package/build/theme/color-algorithms.cjs.map +0 -7
- package/build/theme/index.cjs +0 -160
- package/build/theme/index.cjs.map +0 -7
- package/build/theme/types.cjs +0 -19
- package/build/theme/types.cjs.map +0 -7
- package/build/toggle-group-control/toggle-group-control/styles.cjs +0 -53
- package/build/toggle-group-control/toggle-group-control/styles.cjs.map +0 -7
- package/build/toggle-group-control/toggle-group-control-option-base/styles.cjs +0 -94
- package/build/toggle-group-control/toggle-group-control-option-base/styles.cjs.map +0 -7
- package/build/tools-panel/styles.cjs +0 -129
- package/build/tools-panel/styles.cjs.map +0 -7
- package/build/utils/use-deprecated-props.cjs +0 -41
- package/build/utils/use-deprecated-props.cjs.map +0 -7
- package/build-module/confirm-dialog/styles.mjs +0 -17
- package/build-module/confirm-dialog/styles.mjs.map +0 -7
- package/build-module/disabled/styles/disabled-styles.mjs +0 -17
- package/build-module/disabled/styles/disabled-styles.mjs.map +0 -7
- package/build-module/form-token-field/styles.mjs +0 -14
- package/build-module/form-token-field/styles.mjs.map +0 -7
- package/build-module/search-control/styles.mjs +0 -38
- package/build-module/search-control/styles.mjs.map +0 -7
- package/build-module/theme/color-algorithms.mjs +0 -94
- package/build-module/theme/color-algorithms.mjs.map +0 -7
- package/build-module/theme/index.mjs +0 -129
- package/build-module/theme/index.mjs.map +0 -7
- package/build-module/theme/types.mjs +0 -1
- package/build-module/theme/types.mjs.map +0 -7
- package/build-module/toggle-group-control/toggle-group-control/styles.mjs +0 -27
- package/build-module/toggle-group-control/toggle-group-control/styles.mjs.map +0 -7
- package/build-module/toggle-group-control/toggle-group-control-option-base/styles.mjs +0 -56
- package/build-module/toggle-group-control/toggle-group-control-option-base/styles.mjs.map +0 -7
- package/build-module/tools-panel/styles.mjs +0 -84
- package/build-module/tools-panel/styles.mjs.map +0 -7
- package/build-module/utils/use-deprecated-props.mjs +0 -16
- package/build-module/utils/use-deprecated-props.mjs.map +0 -7
- package/src/confirm-dialog/styles.ts +0 -18
- package/src/disabled/styles/disabled-styles.tsx +0 -23
- package/src/form-token-field/styles.ts +0 -15
- package/src/search-control/styles.ts +0 -27
- package/src/theme/README.md +0 -47
- package/src/theme/color-algorithms.ts +0 -142
- package/src/theme/index.tsx +0 -80
- package/src/theme/stories/index.story.tsx +0 -127
- package/src/theme/style.module.scss +0 -4
- package/src/theme/test/color-algorithms.ts +0 -100
- package/src/theme/test/index.tsx +0 -151
- package/src/theme/types.ts +0 -61
- package/src/toggle-group-control/toggle-group-control/styles.ts +0 -84
- package/src/toggle-group-control/toggle-group-control-option-base/styles.ts +0 -109
- package/src/tools-panel/styles.ts +0 -176
- package/src/utils/use-deprecated-props.ts +0 -14
package/src/theme/README.md
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# Theme
|
|
2
|
-
|
|
3
|
-
<div class="callout callout-alert">
|
|
4
|
-
This feature is still experimental. “Experimental” means this is an early implementation subject to drastic and breaking changes.
|
|
5
|
-
</div>
|
|
6
|
-
|
|
7
|
-
`Theme` allows defining theme variables for components in the `@wordpress/components` package.
|
|
8
|
-
|
|
9
|
-
Multiple `Theme` components can be nested in order to override specific theme variables.
|
|
10
|
-
|
|
11
|
-
## Props
|
|
12
|
-
|
|
13
|
-
### `accent`: `string`
|
|
14
|
-
|
|
15
|
-
The accent color (used by components as the primary color). If an accent color is not defined, the default fallback value is the original WP Admin main theme color.
|
|
16
|
-
|
|
17
|
-
Not all valid CSS color syntaxes are supported — in particular, keywords (like `'currentcolor'`, `'inherit'`, `'initial'`, `'revert'`, `'unset'`...) and CSS custom properties (e.g. `var(--my-custom-property)`) are _not_ supported values for this property.
|
|
18
|
-
|
|
19
|
-
- Required: No
|
|
20
|
-
|
|
21
|
-
### `background`: `string`
|
|
22
|
-
|
|
23
|
-
The background color. If a component explicitly has a background, it will be this color. Otherwise, this color will simply be used to determine what the foreground colors should be. The actual background color will need to be set on the component's container element. If a background color is not defined, the default fallback value is #fff.
|
|
24
|
-
|
|
25
|
-
Not all valid CSS color syntaxes are supported — in particular, keywords (like `'currentcolor'`, `'inherit'`, `'initial'`, `'revert'`, `'unset'`...) and CSS custom properties (e.g. `var(--my-custom-property)`) are _not_ supported values for this property.
|
|
26
|
-
|
|
27
|
-
- Required: No
|
|
28
|
-
|
|
29
|
-
## Writing themeable components
|
|
30
|
-
|
|
31
|
-
If you would like your custom component to be themeable as a child of the `Theme` component, it should use these color variables. (This is a work in progress, and this list of variables may change. We do not recommend using these variables in production at this time.)
|
|
32
|
-
|
|
33
|
-
- `--wp-components-color-accent`: The accent color.
|
|
34
|
-
- `--wp-components-color-accent-darker-10`: A slightly darker version of the accent color.
|
|
35
|
-
- `--wp-components-color-accent-darker-20`: An even darker version of the accent color.
|
|
36
|
-
- `--wp-components-color-accent-inverted`: The foreground color when the accent color is the background, for example when placing text on the accent color.
|
|
37
|
-
- `--wp-components-color-background`: The background color.
|
|
38
|
-
- `--wp-components-color-foreground`: The foreground color, for example text.
|
|
39
|
-
- `--wp-components-color-foreground-inverted`: The foreground color when the foreground color is the background, for example when placing text on the foreground color.
|
|
40
|
-
- Grayscale:
|
|
41
|
-
- `--wp-components-color-gray-100`: Used for light gray backgrounds.
|
|
42
|
-
- `--wp-components-color-gray-200`: Used sparingly for light borders.
|
|
43
|
-
- `--wp-components-color-gray-300`: Used for most borders.
|
|
44
|
-
- `--wp-components-color-gray-400`
|
|
45
|
-
- `--wp-components-color-gray-600`: Meets 3:1 UI or large text contrast against white.
|
|
46
|
-
- `--wp-components-color-gray-700`: Meets 4.6:1 text contrast against white.
|
|
47
|
-
- `--wp-components-color-gray-800`
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { colord, extend } from 'colord';
|
|
5
|
-
import a11yPlugin from 'colord/plugins/a11y';
|
|
6
|
-
import namesPlugin from 'colord/plugins/names';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* WordPress dependencies
|
|
10
|
-
*/
|
|
11
|
-
import warning from '@wordpress/warning';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Internal dependencies
|
|
15
|
-
*/
|
|
16
|
-
import type { ThemeInputValues, ThemeOutputValues } from './types';
|
|
17
|
-
import { COLORS } from '../utils';
|
|
18
|
-
|
|
19
|
-
extend( [ namesPlugin, a11yPlugin ] );
|
|
20
|
-
|
|
21
|
-
export function generateThemeVariables(
|
|
22
|
-
inputs: ThemeInputValues
|
|
23
|
-
): ThemeOutputValues {
|
|
24
|
-
validateInputs( inputs );
|
|
25
|
-
|
|
26
|
-
const generatedColors = {
|
|
27
|
-
...generateAccentDependentColors( inputs.accent ),
|
|
28
|
-
...generateBackgroundDependentColors( inputs.background ),
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
warnContrastIssues( checkContrasts( inputs, generatedColors ) );
|
|
32
|
-
|
|
33
|
-
return { colors: generatedColors };
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function validateInputs( inputs: ThemeInputValues ) {
|
|
37
|
-
for ( const [ key, value ] of Object.entries( inputs ) ) {
|
|
38
|
-
if ( typeof value !== 'undefined' && ! colord( value ).isValid() ) {
|
|
39
|
-
warning(
|
|
40
|
-
`wp.components.Theme: "${ value }" is not a valid color value for the '${ key }' prop.`
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function checkContrasts(
|
|
47
|
-
inputs: ThemeInputValues,
|
|
48
|
-
outputs: ThemeOutputValues[ 'colors' ]
|
|
49
|
-
) {
|
|
50
|
-
const background = inputs.background || COLORS.white;
|
|
51
|
-
const accent = inputs.accent || '#3858e9';
|
|
52
|
-
const foreground = outputs.foreground || COLORS.gray[ 900 ];
|
|
53
|
-
const gray = outputs.gray || COLORS.gray;
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
accent: colord( background ).isReadable( accent )
|
|
57
|
-
? undefined
|
|
58
|
-
: `The background color ("${ background }") does not have sufficient contrast against the accent color ("${ accent }").`,
|
|
59
|
-
foreground: colord( background ).isReadable( foreground )
|
|
60
|
-
? undefined
|
|
61
|
-
: `The background color provided ("${ background }") does not have sufficient contrast against the standard foreground colors.`,
|
|
62
|
-
grays:
|
|
63
|
-
colord( background ).contrast( gray[ 600 ] ) >= 3 &&
|
|
64
|
-
colord( background ).contrast( gray[ 700 ] ) >= 4.5
|
|
65
|
-
? undefined
|
|
66
|
-
: `The background color provided ("${ background }") cannot generate a set of grayscale foreground colors with sufficient contrast. Try adjusting the color to be lighter or darker.`,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function warnContrastIssues( issues: ReturnType< typeof checkContrasts > ) {
|
|
71
|
-
for ( const error of Object.values( issues ) ) {
|
|
72
|
-
if ( error ) {
|
|
73
|
-
warning( 'wp.components.Theme: ' + error );
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function generateAccentDependentColors( accent?: string ) {
|
|
79
|
-
if ( ! accent ) {
|
|
80
|
-
return {};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
accent,
|
|
85
|
-
accentDarker10: colord( accent ).darken( 0.1 ).toHex(),
|
|
86
|
-
accentDarker20: colord( accent ).darken( 0.2 ).toHex(),
|
|
87
|
-
accentInverted: getForegroundForColor( accent ),
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function generateBackgroundDependentColors( background?: string ) {
|
|
92
|
-
if ( ! background ) {
|
|
93
|
-
return {};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const foreground = getForegroundForColor( background );
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
background,
|
|
100
|
-
foreground,
|
|
101
|
-
foregroundInverted: getForegroundForColor( foreground ),
|
|
102
|
-
gray: generateShades( background, foreground ),
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function getForegroundForColor( color: string ) {
|
|
107
|
-
return colord( color ).isDark() ? COLORS.white : COLORS.gray[ 900 ];
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export function generateShades( background: string, foreground: string ) {
|
|
111
|
-
// How much darkness you need to add to #fff to get the COLORS.gray[n] color
|
|
112
|
-
const SHADES = {
|
|
113
|
-
100: 0.06,
|
|
114
|
-
200: 0.121,
|
|
115
|
-
300: 0.132,
|
|
116
|
-
400: 0.2,
|
|
117
|
-
600: 0.42,
|
|
118
|
-
700: 0.543,
|
|
119
|
-
800: 0.821,
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
// Darkness of COLORS.gray[ 900 ], relative to #fff
|
|
123
|
-
const limit = 0.884;
|
|
124
|
-
|
|
125
|
-
const direction = colord( background ).isDark() ? 'lighten' : 'darken';
|
|
126
|
-
|
|
127
|
-
// Lightness delta between the background and foreground colors
|
|
128
|
-
const range =
|
|
129
|
-
Math.abs(
|
|
130
|
-
colord( background ).toHsl().l - colord( foreground ).toHsl().l
|
|
131
|
-
) / 100;
|
|
132
|
-
|
|
133
|
-
const result: Record< number, string > = {};
|
|
134
|
-
|
|
135
|
-
Object.entries( SHADES ).forEach( ( [ key, value ] ) => {
|
|
136
|
-
result[ parseInt( key ) ] = colord( background )
|
|
137
|
-
[ direction ]( ( value / limit ) * range )
|
|
138
|
-
.toHex();
|
|
139
|
-
} );
|
|
140
|
-
|
|
141
|
-
return result as NonNullable< ThemeOutputValues[ 'colors' ][ 'gray' ] >;
|
|
142
|
-
}
|
package/src/theme/index.tsx
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import clsx from 'clsx';
|
|
2
|
-
import type { CSSProperties } from 'react';
|
|
3
|
-
|
|
4
|
-
import { useMemo } from '@wordpress/element';
|
|
5
|
-
|
|
6
|
-
import type { ThemeOutputValues, ThemeProps } from './types';
|
|
7
|
-
import type { WordPressComponentProps } from '../context';
|
|
8
|
-
import { generateThemeVariables } from './color-algorithms';
|
|
9
|
-
import styles from './style.module.scss';
|
|
10
|
-
import { PolymorphicElement } from '../utils/polymorphic-element';
|
|
11
|
-
|
|
12
|
-
const getColorVariables = ( {
|
|
13
|
-
colors,
|
|
14
|
-
}: ThemeOutputValues ): CSSProperties => ( {
|
|
15
|
-
'--wp-components-color-accent': colors.accent,
|
|
16
|
-
'--wp-components-color-accent-darker-10': colors.accentDarker10,
|
|
17
|
-
'--wp-components-color-accent-darker-20': colors.accentDarker20,
|
|
18
|
-
'--wp-components-color-accent-inverted': colors.accentInverted,
|
|
19
|
-
'--wp-components-color-background': colors.background,
|
|
20
|
-
'--wp-components-color-foreground': colors.foreground,
|
|
21
|
-
'--wp-components-color-foreground-inverted': colors.foregroundInverted,
|
|
22
|
-
...Object.fromEntries(
|
|
23
|
-
Object.entries( colors.gray ?? {} ).map( ( [ key, value ] ) => [
|
|
24
|
-
`--wp-components-color-gray-${ key }`,
|
|
25
|
-
value,
|
|
26
|
-
] )
|
|
27
|
-
),
|
|
28
|
-
} );
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* `Theme` allows defining theme variables for components in the `@wordpress/components` package.
|
|
32
|
-
*
|
|
33
|
-
* Multiple `Theme` components can be nested in order to override specific theme variables.
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* ```jsx
|
|
37
|
-
* const Example = () => {
|
|
38
|
-
* return (
|
|
39
|
-
* <Theme accent="red">
|
|
40
|
-
* <Button variant="primary">I'm red</Button>
|
|
41
|
-
* <Theme accent="blue">
|
|
42
|
-
* <Button variant="primary">I'm blue</Button>
|
|
43
|
-
* </Theme>
|
|
44
|
-
* </Theme>
|
|
45
|
-
* );
|
|
46
|
-
* };
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
function Theme( {
|
|
50
|
-
accent,
|
|
51
|
-
background,
|
|
52
|
-
className,
|
|
53
|
-
style,
|
|
54
|
-
...props
|
|
55
|
-
}: WordPressComponentProps< ThemeProps, 'div', true > ) {
|
|
56
|
-
const themeVariables = useMemo(
|
|
57
|
-
() =>
|
|
58
|
-
getColorVariables(
|
|
59
|
-
generateThemeVariables( { accent, background } )
|
|
60
|
-
),
|
|
61
|
-
[ accent, background ]
|
|
62
|
-
);
|
|
63
|
-
const wrapperStyle = useMemo(
|
|
64
|
-
() => ( {
|
|
65
|
-
...themeVariables,
|
|
66
|
-
...style,
|
|
67
|
-
} ),
|
|
68
|
-
[ style, themeVariables ]
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
return (
|
|
72
|
-
<PolymorphicElement
|
|
73
|
-
className={ clsx( styles.wrapper, className ) }
|
|
74
|
-
style={ wrapperStyle }
|
|
75
|
-
{ ...props }
|
|
76
|
-
/>
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export default Theme;
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Meta, StoryFn } from '@storybook/react-vite';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import Theme from '../index';
|
|
10
|
-
import Button from '../../button';
|
|
11
|
-
import { generateThemeVariables, checkContrasts } from '../color-algorithms';
|
|
12
|
-
import { HStack } from '../../h-stack';
|
|
13
|
-
|
|
14
|
-
const meta: Meta< typeof Theme > = {
|
|
15
|
-
component: Theme,
|
|
16
|
-
title: 'Components/Utilities/Theme',
|
|
17
|
-
id: 'components-theme',
|
|
18
|
-
argTypes: {
|
|
19
|
-
accent: { control: { type: 'color' } },
|
|
20
|
-
background: { control: { type: 'color' } },
|
|
21
|
-
},
|
|
22
|
-
tags: [ 'status-private' ],
|
|
23
|
-
parameters: {
|
|
24
|
-
controls: { expanded: true },
|
|
25
|
-
docs: { canvas: { sourceState: 'shown' } },
|
|
26
|
-
componentStatus: {
|
|
27
|
-
status: 'not-recommended',
|
|
28
|
-
whereUsed: 'global',
|
|
29
|
-
notes: 'This is an internal experiment and not meant for external use. Will be superseded by `@wordpress/theme`.',
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
export default meta;
|
|
34
|
-
|
|
35
|
-
const Template: StoryFn< typeof Theme > = ( args ) => (
|
|
36
|
-
<Theme { ...args }>
|
|
37
|
-
<Button __next40pxDefaultSize variant="primary">
|
|
38
|
-
Hello
|
|
39
|
-
</Button>
|
|
40
|
-
</Theme>
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
export const Default = Template.bind( {} );
|
|
44
|
-
Default.args = {};
|
|
45
|
-
|
|
46
|
-
export const Nested: StoryFn< typeof Theme > = ( args ) => (
|
|
47
|
-
<Theme accent="crimson">
|
|
48
|
-
<Button __next40pxDefaultSize variant="primary">
|
|
49
|
-
Outer theme (hardcoded)
|
|
50
|
-
</Button>
|
|
51
|
-
|
|
52
|
-
<Theme { ...args }>
|
|
53
|
-
<Button __next40pxDefaultSize variant="primary">
|
|
54
|
-
Inner theme (set via Storybook controls)
|
|
55
|
-
</Button>
|
|
56
|
-
</Theme>
|
|
57
|
-
</Theme>
|
|
58
|
-
);
|
|
59
|
-
Nested.args = {
|
|
60
|
-
accent: 'blue',
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* The rest of the required colors are generated based on the given accent and background colors.
|
|
65
|
-
*/
|
|
66
|
-
export const ColorScheme: StoryFn< typeof Theme > = ( {
|
|
67
|
-
accent,
|
|
68
|
-
background,
|
|
69
|
-
} ) => {
|
|
70
|
-
const { colors } = generateThemeVariables( { accent, background } );
|
|
71
|
-
const { gray, ...otherColors } = colors;
|
|
72
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
73
|
-
const contrastIssues = Object.entries(
|
|
74
|
-
checkContrasts( { accent, background }, colors )
|
|
75
|
-
).filter( ( [ _, error ] ) => !! error );
|
|
76
|
-
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
77
|
-
|
|
78
|
-
const Chip = ( { color, name }: { color: string; name: string } ) => (
|
|
79
|
-
<HStack justify="flex-start">
|
|
80
|
-
<div
|
|
81
|
-
style={ {
|
|
82
|
-
backgroundColor: color,
|
|
83
|
-
height: '1.25em',
|
|
84
|
-
width: 40,
|
|
85
|
-
} }
|
|
86
|
-
/>
|
|
87
|
-
<div style={ { fontSize: 14 } }>{ name }</div>
|
|
88
|
-
</HStack>
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
return (
|
|
92
|
-
<>
|
|
93
|
-
{ Object.entries( otherColors ).map( ( [ key, value ] ) => (
|
|
94
|
-
<Chip color={ value } name={ key } key={ key } />
|
|
95
|
-
) ) }
|
|
96
|
-
{ Object.entries( gray as NonNullable< typeof gray > ).map(
|
|
97
|
-
( [ key, value ] ) => (
|
|
98
|
-
<Chip
|
|
99
|
-
color={ value }
|
|
100
|
-
name={ `gray ${ key }` }
|
|
101
|
-
key={ key }
|
|
102
|
-
/>
|
|
103
|
-
)
|
|
104
|
-
) }
|
|
105
|
-
{ !! contrastIssues.length && (
|
|
106
|
-
<>
|
|
107
|
-
<h2>Contrast issues</h2>
|
|
108
|
-
<ul>
|
|
109
|
-
{ contrastIssues.map( ( [ key, error ] ) => (
|
|
110
|
-
<li key={ key }>{ error }</li>
|
|
111
|
-
) ) }
|
|
112
|
-
</ul>
|
|
113
|
-
</>
|
|
114
|
-
) }
|
|
115
|
-
</>
|
|
116
|
-
);
|
|
117
|
-
};
|
|
118
|
-
ColorScheme.args = {
|
|
119
|
-
accent: '#3858e9',
|
|
120
|
-
background: '#fff',
|
|
121
|
-
};
|
|
122
|
-
ColorScheme.argTypes = {
|
|
123
|
-
children: { table: { disable: true } },
|
|
124
|
-
};
|
|
125
|
-
ColorScheme.parameters = {
|
|
126
|
-
docs: { canvas: { sourceState: 'hidden' } },
|
|
127
|
-
};
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { colord } from 'colord';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { COLORS } from '../../utils';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Internal dependencies
|
|
13
|
-
*/
|
|
14
|
-
import { generateShades, generateThemeVariables } from '../color-algorithms';
|
|
15
|
-
|
|
16
|
-
describe( 'Theme color algorithms', () => {
|
|
17
|
-
describe( 'generateThemeVariables', () => {
|
|
18
|
-
it( 'should allow explicitly undefined values', () => {
|
|
19
|
-
generateThemeVariables( {
|
|
20
|
-
accent: undefined,
|
|
21
|
-
background: undefined,
|
|
22
|
-
} );
|
|
23
|
-
expect( console ).not.toHaveWarned();
|
|
24
|
-
} );
|
|
25
|
-
|
|
26
|
-
it( 'should warn if invalid colors are passed', () => {
|
|
27
|
-
generateThemeVariables( { accent: 'var(--invalid)' } );
|
|
28
|
-
expect( console ).toHaveWarned();
|
|
29
|
-
} );
|
|
30
|
-
|
|
31
|
-
it( 'should warn if standard foreground colors are not readable against background', () => {
|
|
32
|
-
generateThemeVariables( { background: '#777' } );
|
|
33
|
-
expect( console ).toHaveWarnedWith(
|
|
34
|
-
'wp.components.Theme: The background color provided ("#777") does not have sufficient contrast against the standard foreground colors.'
|
|
35
|
-
);
|
|
36
|
-
} );
|
|
37
|
-
|
|
38
|
-
it( 'should warn if accent color is not readable against background', () => {
|
|
39
|
-
generateThemeVariables( { background: '#fefefe' } );
|
|
40
|
-
expect( console ).not.toHaveWarned();
|
|
41
|
-
|
|
42
|
-
generateThemeVariables( {
|
|
43
|
-
accent: '#000',
|
|
44
|
-
background: '#fff',
|
|
45
|
-
} );
|
|
46
|
-
expect( console ).not.toHaveWarned();
|
|
47
|
-
|
|
48
|
-
generateThemeVariables( {
|
|
49
|
-
accent: '#111',
|
|
50
|
-
background: '#000',
|
|
51
|
-
} );
|
|
52
|
-
expect( console ).toHaveWarnedWith(
|
|
53
|
-
'wp.components.Theme: The background color ("#000") does not have sufficient contrast against the accent color ("#111").'
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
generateThemeVariables( { background: '#1a1a1a' } );
|
|
57
|
-
expect( console ).toHaveWarnedWith(
|
|
58
|
-
'wp.components.Theme: The background color ("#1a1a1a") does not have sufficient contrast against the accent color ("#3858e9").'
|
|
59
|
-
);
|
|
60
|
-
} );
|
|
61
|
-
|
|
62
|
-
it( 'should warn if a readable grayscale cannot be generated', () => {
|
|
63
|
-
generateThemeVariables( { background: '#ddd' } );
|
|
64
|
-
expect( console ).toHaveWarnedWith(
|
|
65
|
-
'wp.components.Theme: The background color provided ("#ddd") cannot generate a set of grayscale foreground colors with sufficient contrast. Try adjusting the color to be lighter or darker.'
|
|
66
|
-
);
|
|
67
|
-
} );
|
|
68
|
-
} );
|
|
69
|
-
|
|
70
|
-
describe( 'generateShades', () => {
|
|
71
|
-
it( 'should generate the default WP shades when the default WP background/foreground colors are given', () => {
|
|
72
|
-
const shades = generateShades( '#fff', '#1e1e1e' );
|
|
73
|
-
|
|
74
|
-
Object.entries( shades ).forEach( ( [ k, color ] ) => {
|
|
75
|
-
const key = parseInt( k, 10 ) as keyof typeof shades;
|
|
76
|
-
const normalizedExpectedColor = colord(
|
|
77
|
-
COLORS.gray[ key ]
|
|
78
|
-
).toHex();
|
|
79
|
-
|
|
80
|
-
expect( color ).toBe( normalizedExpectedColor );
|
|
81
|
-
} );
|
|
82
|
-
} );
|
|
83
|
-
|
|
84
|
-
it.each( [
|
|
85
|
-
[ '#000', '#fff' ], // wide delta
|
|
86
|
-
[ '#fff', '#000' ], // flipped
|
|
87
|
-
[ '#eee', '#fff' ], // narrow delta
|
|
88
|
-
] )( 'should generate unique shades (bg: %s, fg: %s)', ( bg, fg ) => {
|
|
89
|
-
const shades = generateShades( bg, fg );
|
|
90
|
-
|
|
91
|
-
// The darkest and lightest shades should be different from the fg/bg colors
|
|
92
|
-
expect( colord( shades[ 100 ] ).isEqual( bg ) ).toBe( false );
|
|
93
|
-
expect( colord( shades[ 800 ] ).isEqual( fg ) ).toBe( false );
|
|
94
|
-
|
|
95
|
-
// The shades should be unique
|
|
96
|
-
const shadeValues = Object.values( shades );
|
|
97
|
-
expect( shadeValues ).toHaveLength( new Set( shadeValues ).size );
|
|
98
|
-
} );
|
|
99
|
-
} );
|
|
100
|
-
} );
|
package/src/theme/test/index.tsx
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { render, screen } from '@testing-library/react';
|
|
2
|
-
import type { ReactNode } from 'react';
|
|
3
|
-
|
|
4
|
-
import Theme from '../';
|
|
5
|
-
|
|
6
|
-
type MyThemableComponentProps = {
|
|
7
|
-
children: ReactNode;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
const MyThemableComponent = ( props: MyThemableComponentProps ) => {
|
|
11
|
-
return (
|
|
12
|
-
<div
|
|
13
|
-
{ ...props }
|
|
14
|
-
style={ {
|
|
15
|
-
color: 'var(--wp-components-color-accent)',
|
|
16
|
-
} }
|
|
17
|
-
/>
|
|
18
|
-
);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
describe( 'Theme', () => {
|
|
22
|
-
it( 'should support the as prop', () => {
|
|
23
|
-
render( <Theme as="section" data-testid="theme" /> );
|
|
24
|
-
|
|
25
|
-
expect( screen.getByTestId( 'theme' ) ).toHaveProperty(
|
|
26
|
-
'tagName',
|
|
27
|
-
'SECTION'
|
|
28
|
-
);
|
|
29
|
-
} );
|
|
30
|
-
|
|
31
|
-
it( 'lets user styles override generated theme variables', () => {
|
|
32
|
-
render(
|
|
33
|
-
<Theme
|
|
34
|
-
accent="#123abc"
|
|
35
|
-
style={ { '--wp-components-color-accent': '#654321' } }
|
|
36
|
-
data-testid="theme"
|
|
37
|
-
/>
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
expect( screen.getByTestId( 'theme' ) ).toHaveStyle( {
|
|
41
|
-
'--wp-components-color-accent': '#654321',
|
|
42
|
-
} );
|
|
43
|
-
} );
|
|
44
|
-
|
|
45
|
-
describe( 'accent color', () => {
|
|
46
|
-
it( 'does not define the accent color (and its variations) as a CSS variable when the `accent` prop is undefined', () => {
|
|
47
|
-
render(
|
|
48
|
-
<Theme data-testid="theme">
|
|
49
|
-
<MyThemableComponent>Inner</MyThemableComponent>
|
|
50
|
-
</Theme>
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
const innerElementStyles = window.getComputedStyle(
|
|
54
|
-
screen.getByTestId( 'theme' )
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
[
|
|
58
|
-
'--wp-components-color-accent',
|
|
59
|
-
'--wp-components-color-accent-darker-10',
|
|
60
|
-
'--wp-components-color-accent-darker-20',
|
|
61
|
-
'--wp-components-color-accent-inverted',
|
|
62
|
-
].forEach( ( cssVariable ) => {
|
|
63
|
-
expect(
|
|
64
|
-
innerElementStyles.getPropertyValue( cssVariable )
|
|
65
|
-
).toBe( '' );
|
|
66
|
-
} );
|
|
67
|
-
} );
|
|
68
|
-
|
|
69
|
-
it( 'defines the accent color (and its variations) as a CSS variable', () => {
|
|
70
|
-
render(
|
|
71
|
-
<Theme accent="#123abc" data-testid="theme">
|
|
72
|
-
<MyThemableComponent>Inner</MyThemableComponent>
|
|
73
|
-
</Theme>
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
expect( screen.getByTestId( 'theme' ) ).toHaveStyle( {
|
|
77
|
-
'--wp-components-color-accent': '#123abc',
|
|
78
|
-
'--wp-components-color-accent-darker-10': '#0e2c8d',
|
|
79
|
-
'--wp-components-color-accent-darker-20': '#091d5f',
|
|
80
|
-
'--wp-components-color-accent-inverted': '#fff',
|
|
81
|
-
} );
|
|
82
|
-
} );
|
|
83
|
-
} );
|
|
84
|
-
|
|
85
|
-
describe( 'background color', () => {
|
|
86
|
-
it( 'does not define the background color (and its dependent colors) as a CSS variable when the `background` prop is undefined', () => {
|
|
87
|
-
render(
|
|
88
|
-
<Theme data-testid="theme">
|
|
89
|
-
<MyThemableComponent>Inner</MyThemableComponent>
|
|
90
|
-
</Theme>
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
const innerElementStyles = window.getComputedStyle(
|
|
94
|
-
screen.getByTestId( 'theme' )
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
[
|
|
98
|
-
'--wp-components-color-background',
|
|
99
|
-
'--wp-components-color-foreground',
|
|
100
|
-
'--wp-components-color-foreground-inverted',
|
|
101
|
-
...[ '100', '200', '300', '400', '600', '700', '800' ].map(
|
|
102
|
-
( shade ) => `--wp-components-color-gray-${ shade }`
|
|
103
|
-
),
|
|
104
|
-
].forEach( ( cssVariable ) => {
|
|
105
|
-
expect(
|
|
106
|
-
innerElementStyles.getPropertyValue( cssVariable )
|
|
107
|
-
).toBe( '' );
|
|
108
|
-
} );
|
|
109
|
-
} );
|
|
110
|
-
|
|
111
|
-
it( 'defines the background color (and its dependent colors) as a CSS variable', () => {
|
|
112
|
-
render(
|
|
113
|
-
<Theme background="#ffffff" data-testid="theme">
|
|
114
|
-
<MyThemableComponent>Inner</MyThemableComponent>
|
|
115
|
-
</Theme>
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
expect( screen.getByTestId( 'theme' ) ).toHaveStyle( {
|
|
119
|
-
'--wp-components-color-background': '#ffffff',
|
|
120
|
-
'--wp-components-color-foreground': '#1e1e1e',
|
|
121
|
-
'--wp-components-color-foreground-inverted': '#fff',
|
|
122
|
-
'--wp-components-color-gray-100': '#f0f0f0',
|
|
123
|
-
'--wp-components-color-gray-200': '#e0e0e0',
|
|
124
|
-
'--wp-components-color-gray-300': '#dddddd',
|
|
125
|
-
'--wp-components-color-gray-400': '#cccccc',
|
|
126
|
-
'--wp-components-color-gray-600': '#949494',
|
|
127
|
-
'--wp-components-color-gray-700': '#757575',
|
|
128
|
-
'--wp-components-color-gray-800': '#2f2f2f',
|
|
129
|
-
} );
|
|
130
|
-
} );
|
|
131
|
-
} );
|
|
132
|
-
|
|
133
|
-
describe( 'unsupported values', () => {
|
|
134
|
-
describe.each( [ 'accent', 'background' ] )( '%s', ( propName ) => {
|
|
135
|
-
it.each( [
|
|
136
|
-
// Keywords
|
|
137
|
-
'currentcolor',
|
|
138
|
-
'initial',
|
|
139
|
-
'reset',
|
|
140
|
-
'inherit',
|
|
141
|
-
'revert',
|
|
142
|
-
'unset',
|
|
143
|
-
// CSS Custom properties
|
|
144
|
-
'var( --my-variable )',
|
|
145
|
-
] )( 'should warn when the value is "%s"', ( value ) => {
|
|
146
|
-
render( <Theme { ...{ [ propName ]: value } } /> );
|
|
147
|
-
expect( console ).toHaveWarned();
|
|
148
|
-
} );
|
|
149
|
-
} );
|
|
150
|
-
} );
|
|
151
|
-
} );
|