@wordpress/preferences 3.26.0 → 3.28.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.
Files changed (72) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/components/preference-base-option/index.js +31 -0
  3. package/build/components/preference-base-option/index.js.map +1 -0
  4. package/build/components/preference-toggle-control/index.js +42 -0
  5. package/build/components/preference-toggle-control/index.js.map +1 -0
  6. package/build/components/preference-toggle-menu-item/index.js +4 -1
  7. package/build/components/preference-toggle-menu-item/index.js.map +1 -1
  8. package/build/components/preferences-modal/index.js +24 -0
  9. package/build/components/preferences-modal/index.js.map +1 -0
  10. package/build/components/preferences-modal-section/index.js +24 -0
  11. package/build/components/preferences-modal-section/index.js.map +1 -0
  12. package/build/components/preferences-modal-tabs/index.js +129 -0
  13. package/build/components/preferences-modal-tabs/index.js.map +1 -0
  14. package/build/index.js +12 -0
  15. package/build/index.js.map +1 -1
  16. package/build/lock-unlock.js +18 -0
  17. package/build/lock-unlock.js.map +1 -0
  18. package/build/private-apis.js +26 -0
  19. package/build/private-apis.js.map +1 -0
  20. package/build/store/constants.js +1 -2
  21. package/build/store/constants.js.map +1 -1
  22. package/build/store/index.js +4 -5
  23. package/build/store/index.js.map +1 -1
  24. package/build/store/reducer.js +2 -4
  25. package/build/store/reducer.js.map +1 -1
  26. package/build/store/selectors.js +21 -3
  27. package/build/store/selectors.js.map +1 -1
  28. package/build-module/components/preference-base-option/index.js +24 -0
  29. package/build-module/components/preference-base-option/index.js.map +1 -0
  30. package/build-module/components/preference-toggle-control/index.js +34 -0
  31. package/build-module/components/preference-toggle-control/index.js.map +1 -0
  32. package/build-module/components/preference-toggle-menu-item/index.js +4 -1
  33. package/build-module/components/preference-toggle-menu-item/index.js.map +1 -1
  34. package/build-module/components/preferences-modal/index.js +17 -0
  35. package/build-module/components/preferences-modal/index.js.map +1 -0
  36. package/build-module/components/preferences-modal-section/index.js +18 -0
  37. package/build-module/components/preferences-modal-section/index.js.map +1 -0
  38. package/build-module/components/preferences-modal-tabs/index.js +122 -0
  39. package/build-module/components/preferences-modal-tabs/index.js.map +1 -0
  40. package/build-module/index.js +1 -0
  41. package/build-module/index.js.map +1 -1
  42. package/build-module/lock-unlock.js +9 -0
  43. package/build-module/lock-unlock.js.map +1 -0
  44. package/build-module/private-apis.js +18 -0
  45. package/build-module/private-apis.js.map +1 -0
  46. package/build-module/store/index.js +1 -1
  47. package/build-module/store/index.js.map +1 -1
  48. package/build-module/store/selectors.js +18 -2
  49. package/build-module/store/selectors.js.map +1 -1
  50. package/build-style/style-rtl.css +199 -0
  51. package/build-style/style.css +199 -0
  52. package/package.json +11 -8
  53. package/src/components/preference-base-option/README.md +40 -0
  54. package/src/components/preference-base-option/index.js +21 -0
  55. package/src/components/preference-base-option/style.scss +10 -0
  56. package/src/components/preference-toggle-control/index.js +38 -0
  57. package/src/components/preference-toggle-menu-item/index.js +4 -1
  58. package/src/components/preferences-modal/README.md +69 -0
  59. package/src/components/preferences-modal/index.js +17 -0
  60. package/src/components/preferences-modal/style.scss +21 -0
  61. package/src/components/preferences-modal-section/README.md +31 -0
  62. package/src/components/preferences-modal-section/index.js +15 -0
  63. package/src/components/preferences-modal-section/style.scss +28 -0
  64. package/src/components/preferences-modal-tabs/README.md +14 -0
  65. package/src/components/preferences-modal-tabs/index.js +178 -0
  66. package/src/components/preferences-modal-tabs/style.scss +48 -0
  67. package/src/index.js +1 -0
  68. package/src/lock-unlock.js +9 -0
  69. package/src/private-apis.js +18 -0
  70. package/src/store/index.js +1 -1
  71. package/src/store/selectors.js +42 -2
  72. package/src/style.scss +4 -0
@@ -0,0 +1,199 @@
1
+ /**
2
+ * Converts a hex value into the rgb equivalent.
3
+ *
4
+ * @param {string} hex - the hexadecimal value to convert
5
+ * @return {string} comma separated rgb values
6
+ */
7
+ /**
8
+ * Colors
9
+ */
10
+ /**
11
+ * Breakpoints & Media Queries
12
+ */
13
+ /**
14
+ * SCSS Variables.
15
+ *
16
+ * Please use variables from this sheet to ensure consistency across the UI.
17
+ * Don't add to this sheet unless you're pretty sure the value will be reused in many places.
18
+ * For example, don't add rules to this sheet that affect block visuals. It's purely for UI.
19
+ */
20
+ /**
21
+ * Converts a hex value into the rgb equivalent.
22
+ *
23
+ * @param {string} hex - the hexadecimal value to convert
24
+ * @return {string} comma separated rgb values
25
+ */
26
+ /**
27
+ * Colors
28
+ */
29
+ /**
30
+ * Fonts & basic variables.
31
+ */
32
+ /**
33
+ * Grid System.
34
+ * https://make.wordpress.org/design/2019/10/31/proposal-a-consistent-spacing-system-for-wordpress/
35
+ */
36
+ /**
37
+ * Dimensions.
38
+ */
39
+ /**
40
+ * Shadows.
41
+ */
42
+ /**
43
+ * Editor widths.
44
+ */
45
+ /**
46
+ * Block & Editor UI.
47
+ */
48
+ /**
49
+ * Block paddings.
50
+ */
51
+ /**
52
+ * React Native specific.
53
+ * These variables do not appear to be used anywhere else.
54
+ */
55
+ /**
56
+ * Converts a hex value into the rgb equivalent.
57
+ *
58
+ * @param {string} hex - the hexadecimal value to convert
59
+ * @return {string} comma separated rgb values
60
+ */
61
+ /**
62
+ * Long content fade mixin
63
+ *
64
+ * Creates a fading overlay to signify that the content is longer
65
+ * than the space allows.
66
+ */
67
+ /**
68
+ * Breakpoint mixins
69
+ */
70
+ /**
71
+ * Focus styles.
72
+ */
73
+ /**
74
+ * Applies editor left position to the selector passed as argument
75
+ */
76
+ /**
77
+ * Styles that are reused verbatim in a few places
78
+ */
79
+ /**
80
+ * Allows users to opt-out of animations via OS-level preferences.
81
+ */
82
+ /**
83
+ * Reset default styles for JavaScript UI based pages.
84
+ * This is a WP-admin agnostic reset
85
+ */
86
+ /**
87
+ * Reset the WP Admin page styles for Gutenberg-like pages.
88
+ */
89
+ :root {
90
+ --wp-admin-theme-color: #007cba;
91
+ --wp-admin-theme-color--rgb: 0, 124, 186;
92
+ --wp-admin-theme-color-darker-10: #006ba1;
93
+ --wp-admin-theme-color-darker-10--rgb: 0, 107, 161;
94
+ --wp-admin-theme-color-darker-20: #005a87;
95
+ --wp-admin-theme-color-darker-20--rgb: 0, 90, 135;
96
+ --wp-admin-border-width-focus: 2px;
97
+ --wp-block-synced-color: #7a00df;
98
+ --wp-block-synced-color--rgb: 122, 0, 223;
99
+ }
100
+ @media (min-resolution: 192dpi) {
101
+ :root {
102
+ --wp-admin-border-width-focus: 1.5px;
103
+ }
104
+ }
105
+
106
+ .preference-base-option + .preference-base-option {
107
+ margin-top: 16px;
108
+ }
109
+ .preference-base-option .components-base-control__help {
110
+ margin-top: 0;
111
+ margin-left: 48px;
112
+ }
113
+
114
+ @media (min-width: 600px) {
115
+ .preferences-modal {
116
+ width: calc(100% - 32px);
117
+ height: calc(100% - 120px);
118
+ }
119
+ }
120
+ @media (min-width: 782px) {
121
+ .preferences-modal {
122
+ width: 750px;
123
+ }
124
+ }
125
+ @media (min-width: 960px) {
126
+ .preferences-modal {
127
+ height: 70%;
128
+ }
129
+ }
130
+ @media (max-width: 781px) {
131
+ .preferences-modal .components-modal__content {
132
+ padding: 0;
133
+ }
134
+ }
135
+
136
+ .preferences__tabs-tablist {
137
+ position: absolute;
138
+ top: 84px;
139
+ left: 16px;
140
+ width: 160px;
141
+ }
142
+
143
+ .preferences__tabs-tab {
144
+ border-radius: 2px;
145
+ font-weight: 400;
146
+ }
147
+ .preferences__tabs-tab[aria-selected=true] {
148
+ background: #f0f0f0;
149
+ box-shadow: none;
150
+ font-weight: 500;
151
+ }
152
+ .preferences__tabs-tab[aria-selected=true]::after {
153
+ content: none;
154
+ }
155
+ .preferences__tabs-tab[role=tab]:focus:not(:disabled) {
156
+ box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
157
+ outline: 2px solid transparent;
158
+ }
159
+ .preferences__tabs-tab:focus-visible::before {
160
+ content: none;
161
+ }
162
+
163
+ .preferences__tabs-tabpanel {
164
+ padding-left: 24px;
165
+ margin-left: 160px;
166
+ }
167
+
168
+ @media (max-width: 781px) {
169
+ .preferences__provider {
170
+ height: 100%;
171
+ }
172
+ }
173
+ .preferences-modal__section {
174
+ margin: 0 0 2.5rem 0;
175
+ }
176
+ .preferences-modal__section:last-child {
177
+ margin: 0;
178
+ }
179
+
180
+ .preferences-modal__section-legend {
181
+ margin-bottom: 8px;
182
+ }
183
+
184
+ .preferences-modal__section-title {
185
+ font-size: 0.9rem;
186
+ font-weight: 600;
187
+ margin-top: 0;
188
+ }
189
+
190
+ .preferences-modal__section-description {
191
+ margin: -8px 0 8px 0;
192
+ font-size: 12px;
193
+ font-style: normal;
194
+ color: #757575;
195
+ }
196
+
197
+ .preferences-modal__section:has(.preferences-modal__section-content:empty) {
198
+ display: none;
199
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/preferences",
3
- "version": "3.26.0",
3
+ "version": "3.28.0",
4
4
  "description": "Utilities for managing WordPress preferences.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -29,12 +29,15 @@
29
29
  "sideEffects": false,
30
30
  "dependencies": {
31
31
  "@babel/runtime": "^7.16.0",
32
- "@wordpress/a11y": "^3.49.0",
33
- "@wordpress/components": "^25.15.0",
34
- "@wordpress/data": "^9.19.0",
35
- "@wordpress/element": "^5.26.0",
36
- "@wordpress/i18n": "^4.49.0",
37
- "@wordpress/icons": "^9.40.0",
32
+ "@wordpress/a11y": "^3.51.0",
33
+ "@wordpress/components": "^26.0.0",
34
+ "@wordpress/compose": "^6.28.0",
35
+ "@wordpress/data": "^9.21.0",
36
+ "@wordpress/deprecated": "^3.51.0",
37
+ "@wordpress/element": "^5.28.0",
38
+ "@wordpress/i18n": "^4.51.0",
39
+ "@wordpress/icons": "^9.42.0",
40
+ "@wordpress/private-apis": "^0.33.0",
38
41
  "classnames": "^2.3.1"
39
42
  },
40
43
  "peerDependencies": {
@@ -44,5 +47,5 @@
44
47
  "publishConfig": {
45
48
  "access": "public"
46
49
  },
47
- "gitHead": "5e6f9caa205d3bfdbac131952b7bf9c6ec60569b"
50
+ "gitHead": "eb796371e9630636a4a8837033807b0c4a06ed67"
48
51
  }
@@ -0,0 +1,40 @@
1
+ # PreferenceBaseOption
2
+
3
+ `PreferenceBaseOption` renders a toggle meant to be used within `PreferencesModal`.
4
+
5
+ This component implements a `ToggleControl` component from the `@wordpress/components` package.
6
+
7
+ ## Example
8
+
9
+ ```jsx
10
+ function MyEditorPreferencesOption() {
11
+ return (
12
+ <PreferenceBaseOption
13
+ label={ label }
14
+ isChecked={ isChecked }
15
+ onChange={ setIsChecked }
16
+ >
17
+ { isChecked !== areCustomFieldsEnabled && (
18
+ <CustomFieldsConfirmation willEnable={ isChecked } />
19
+ ) }
20
+ </PreferenceBaseOption>
21
+ )
22
+ }
23
+ ```
24
+
25
+ ## Props
26
+
27
+ ### help
28
+ ### label
29
+ ### isChecked
30
+ ### onChange
31
+
32
+ These props are passed directly to ToggleControl, so see [ToggleControl readme](https://github.com/WordPress/gutenberg/blob/trunk/packages/components/src/toggle-control/README.md) for more info.
33
+
34
+ ### children
35
+
36
+ Components to be rendered as content.
37
+
38
+ - Type: `Element`
39
+ - Required: No.
40
+
@@ -0,0 +1,21 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { ToggleControl } from '@wordpress/components';
5
+
6
+ function BaseOption( { help, label, isChecked, onChange, children } ) {
7
+ return (
8
+ <div className="preference-base-option">
9
+ <ToggleControl
10
+ __nextHasNoMarginBottom
11
+ help={ help }
12
+ label={ label }
13
+ checked={ isChecked }
14
+ onChange={ onChange }
15
+ />
16
+ { children }
17
+ </div>
18
+ );
19
+ }
20
+
21
+ export default BaseOption;
@@ -0,0 +1,10 @@
1
+ .preference-base-option {
2
+ & + & {
3
+ margin-top: $grid-unit-20;
4
+ }
5
+
6
+ .components-base-control__help {
7
+ margin-top: 0;
8
+ margin-left: 48px;
9
+ }
10
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useSelect, useDispatch } from '@wordpress/data';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import { store as preferencesStore } from '../../store';
10
+ import PreferenceBaseOption from '../preference-base-option';
11
+
12
+ function PreferenceToggleControl( props ) {
13
+ const {
14
+ scope,
15
+ featureName,
16
+ onToggle = () => {},
17
+ ...remainingProps
18
+ } = props;
19
+ const isChecked = useSelect(
20
+ ( select ) => !! select( preferencesStore ).get( scope, featureName ),
21
+ [ scope, featureName ]
22
+ );
23
+ const { toggle } = useDispatch( preferencesStore );
24
+ const onChange = () => {
25
+ onToggle();
26
+ toggle( scope, featureName );
27
+ };
28
+
29
+ return (
30
+ <PreferenceBaseOption
31
+ onChange={ onChange }
32
+ isChecked={ isChecked }
33
+ { ...remainingProps }
34
+ />
35
+ );
36
+ }
37
+
38
+ export default PreferenceToggleControl;
@@ -20,6 +20,7 @@ export default function PreferenceToggleMenuItem( {
20
20
  messageActivated,
21
21
  messageDeactivated,
22
22
  shortcut,
23
+ handleToggling = true,
23
24
  onToggle = () => null,
24
25
  disabled = false,
25
26
  } ) {
@@ -56,7 +57,9 @@ export default function PreferenceToggleMenuItem( {
56
57
  isSelected={ isActive }
57
58
  onClick={ () => {
58
59
  onToggle();
59
- toggle( scope, name );
60
+ if ( handleToggling ) {
61
+ toggle( scope, name );
62
+ }
60
63
  speakMessage();
61
64
  } }
62
65
  role="menuitemcheckbox"
@@ -0,0 +1,69 @@
1
+ # PreferencesModal
2
+
3
+ `PreferencesModal` renders a modal with editor preferences. It can take a `PreferencesModalTabs` component, which accepts multiple tabs, and/or other child components. On small viewports, the modal is fullscreen.
4
+
5
+ This component implements a `Modal` component from the `@wordpress/components` package.
6
+
7
+ Sections passed to this component should use `PreferencesModalSection` component from the `@wordpress/preferences` package.
8
+
9
+
10
+ ## Example
11
+
12
+ ```jsx
13
+ function MyEditorPreferencesModal() {
14
+ const { closeModal } = useDispatch( editPostStore );
15
+ const sections = [
16
+ {
17
+ name: 'section 1',
18
+ tabLabel: __( 'Section 1' ),
19
+ content: (
20
+ <PreferencesModalSection
21
+ title={ __( 'Publishing' ) }
22
+ description={ __(
23
+ 'Change options related to publishing.'
24
+ ) }
25
+ >
26
+ <EnablePublishSidebarOption
27
+ help={ __(
28
+ 'Review settings, such as visibility and tags.'
29
+ ) }
30
+ label={ __(
31
+ 'Enable pre-publish checks'
32
+ ) }
33
+ />
34
+ </PreferencesModalSection>
35
+ )
36
+
37
+ }
38
+ {
39
+ name: 'section 2',
40
+ tabLabel: __( 'Section 2' ),
41
+ content: (
42
+ <PreferencesModalSection
43
+ title={ __( 'Additional' ) }
44
+ description={ __(
45
+ 'Add extra areas to the editor.'
46
+ ) }
47
+ >
48
+ // Section content here
49
+ </PreferencesModalSection>
50
+ )
51
+
52
+ }
53
+ ]
54
+ return (
55
+ <PreferencesModal closeModal={ closeModal }>
56
+ <PreferencesModalTabs sections={ sections } />
57
+ <PreferencesModal />
58
+ );
59
+ }
60
+ ```
61
+
62
+ ## Props
63
+
64
+ ### closeModal
65
+
66
+ A function to call when closing the modal.
67
+
68
+ - Type: `Function`
69
+ - Required: Yes.
@@ -0,0 +1,17 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { Modal } from '@wordpress/components';
5
+ import { __ } from '@wordpress/i18n';
6
+
7
+ export default function PreferencesModal( { closeModal, children } ) {
8
+ return (
9
+ <Modal
10
+ className="preferences-modal"
11
+ title={ __( 'Preferences' ) }
12
+ onRequestClose={ closeModal }
13
+ >
14
+ { children }
15
+ </Modal>
16
+ );
17
+ }
@@ -0,0 +1,21 @@
1
+ .preferences-modal {
2
+ // To keep modal dimensions consistent as subsections are navigated, width
3
+ // and height are used instead of max-(width/height).
4
+ @include break-small() {
5
+ width: calc(100% - #{ $grid-unit-20 * 2 });
6
+ height: calc(100% - #{ $header-height * 2 });
7
+ }
8
+ @include break-medium() {
9
+ width: $break-medium - $grid-unit-20 * 2;
10
+ }
11
+ @include break-large() {
12
+ height: 70%;
13
+ }
14
+
15
+ // Clears spacing to flush fit the navigator component to the modal edges.
16
+ @media (max-width: #{ ($break-medium - 1) }) {
17
+ .components-modal__content {
18
+ padding: 0;
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,31 @@
1
+ # PreferencesModalSection
2
+
3
+ `PreferencesModalSection` renders a section (as a fieldset) meant to be used with `PreferencesModal`.
4
+
5
+ ## Example
6
+
7
+ See the `PreferencesModal` readme for usage info.
8
+
9
+
10
+ ## Props
11
+
12
+ ### title
13
+
14
+ The title of the section
15
+
16
+ - Type: `String`
17
+ - Required: Yes.
18
+
19
+ ### description
20
+
21
+ The description for the section.
22
+
23
+ - Type: `String`
24
+ - Required: No.
25
+
26
+ ### children
27
+
28
+ Components to be rendered as content.
29
+
30
+ - Type: `Element`
31
+ - Required: Yes.
@@ -0,0 +1,15 @@
1
+ const Section = ( { description, title, children } ) => (
2
+ <fieldset className="preferences-modal__section">
3
+ <legend className="preferences-modal__section-legend">
4
+ <h2 className="preferences-modal__section-title">{ title }</h2>
5
+ { description && (
6
+ <p className="preferences-modal__section-description">
7
+ { description }
8
+ </p>
9
+ ) }
10
+ </legend>
11
+ <div className="preferences-modal__section-content">{ children }</div>
12
+ </fieldset>
13
+ );
14
+
15
+ export default Section;
@@ -0,0 +1,28 @@
1
+ .preferences-modal__section {
2
+ margin: 0 0 2.5rem 0;
3
+
4
+ &:last-child {
5
+ margin: 0;
6
+ }
7
+ }
8
+
9
+ .preferences-modal__section-legend {
10
+ margin-bottom: $grid-unit-10;
11
+ }
12
+
13
+ .preferences-modal__section-title {
14
+ font-size: 0.9rem;
15
+ font-weight: 600;
16
+ margin-top: 0;
17
+ }
18
+
19
+ .preferences-modal__section-description {
20
+ margin: -$grid-unit-10 0 $grid-unit-10 0;
21
+ font-size: $helptext-font-size;
22
+ font-style: normal;
23
+ color: $gray-700;
24
+ }
25
+
26
+ .preferences-modal__section:has(.preferences-modal__section-content:empty) {
27
+ display: none;
28
+ }
@@ -0,0 +1,14 @@
1
+ # PreferencesModalTabs
2
+
3
+ `PreferencesModalTabs` creates a tabbed interface meant to be used inside a `PreferencesModal`. Markup differs between small and large viewports; on small the tabs are closed by default.
4
+
5
+ ## Example
6
+
7
+ See the `PreferencesModal` readme for usage info.
8
+ ## Props
9
+ ### sections
10
+
11
+ Sections to populate the modal with. Takes an array of objects, where each should include `name`, `tablabel` and `content`.
12
+
13
+ - Type: `Array`
14
+ - Required: Yes.