@wordpress/components 19.0.5 → 19.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/build/circular-option-picker/index.js +2 -2
  3. package/build/circular-option-picker/index.js.map +1 -1
  4. package/build/date-time/time.js +17 -3
  5. package/build/date-time/time.js.map +1 -1
  6. package/build/font-size-picker/index.js +2 -1
  7. package/build/font-size-picker/index.js.map +1 -1
  8. package/build/index.js +7 -7
  9. package/build/index.js.map +1 -1
  10. package/build/mobile/global-styles-context/utils.native.js +2 -2
  11. package/build/mobile/global-styles-context/utils.native.js.map +1 -1
  12. package/build/navigation/item/index.js +6 -3
  13. package/build/navigation/item/index.js.map +1 -1
  14. package/build/navigation/styles/navigation-styles.js +37 -30
  15. package/build/navigation/styles/navigation-styles.js.map +1 -1
  16. package/build/palette-edit/index.js +303 -0
  17. package/build/palette-edit/index.js.map +1 -0
  18. package/build/palette-edit/styles.js +112 -0
  19. package/build/palette-edit/styles.js.map +1 -0
  20. package/build/popover/index.js +1 -1
  21. package/build/popover/index.js.map +1 -1
  22. package/build/toggle-group-control/toggle-group-control-option/component.js +30 -4
  23. package/build/toggle-group-control/toggle-group-control-option/component.js.map +1 -1
  24. package/build/tooltip/index.js +4 -4
  25. package/build/tooltip/index.js.map +1 -1
  26. package/build-module/circular-option-picker/index.js +2 -2
  27. package/build-module/circular-option-picker/index.js.map +1 -1
  28. package/build-module/date-time/time.js +17 -3
  29. package/build-module/date-time/time.js.map +1 -1
  30. package/build-module/font-size-picker/index.js +2 -1
  31. package/build-module/font-size-picker/index.js.map +1 -1
  32. package/build-module/index.js +1 -1
  33. package/build-module/index.js.map +1 -1
  34. package/build-module/mobile/global-styles-context/utils.native.js +2 -2
  35. package/build-module/mobile/global-styles-context/utils.native.js.map +1 -1
  36. package/build-module/navigation/item/index.js +7 -4
  37. package/build-module/navigation/item/index.js.map +1 -1
  38. package/build-module/navigation/styles/navigation-styles.js +34 -28
  39. package/build-module/navigation/styles/navigation-styles.js.map +1 -1
  40. package/build-module/palette-edit/index.js +276 -0
  41. package/build-module/palette-edit/index.js.map +1 -0
  42. package/build-module/palette-edit/styles.js +90 -0
  43. package/build-module/palette-edit/styles.js.map +1 -0
  44. package/build-module/popover/index.js +1 -1
  45. package/build-module/popover/index.js.map +1 -1
  46. package/build-module/toggle-group-control/toggle-group-control-option/component.js +26 -5
  47. package/build-module/toggle-group-control/toggle-group-control-option/component.js.map +1 -1
  48. package/build-module/tooltip/index.js +4 -4
  49. package/build-module/tooltip/index.js.map +1 -1
  50. package/build-style/style-rtl.css +12 -1
  51. package/build-style/style.css +12 -1
  52. package/build-types/confirm-dialog/component.d.ts +34 -0
  53. package/build-types/confirm-dialog/component.d.ts.map +1 -0
  54. package/build-types/confirm-dialog/index.d.ts +6 -0
  55. package/build-types/confirm-dialog/index.d.ts.map +1 -0
  56. package/build-types/confirm-dialog/types.d.ts +20 -0
  57. package/build-types/confirm-dialog/types.d.ts.map +1 -0
  58. package/build-types/higher-order/with-focus-outside/index.d.ts +3 -0
  59. package/build-types/higher-order/with-focus-outside/index.d.ts.map +1 -0
  60. package/build-types/modal/aria-helper.d.ts +27 -0
  61. package/build-types/modal/aria-helper.d.ts.map +1 -0
  62. package/build-types/modal/index.d.ts +3 -0
  63. package/build-types/modal/index.d.ts.map +1 -0
  64. package/build-types/popover/index.d.ts.map +1 -1
  65. package/build-types/style-provider/index.d.ts +5 -0
  66. package/build-types/style-provider/index.d.ts.map +1 -0
  67. package/build-types/toggle-group-control/toggle-group-control-option/component.d.ts.map +1 -1
  68. package/build-types/toggle-group-control/types.d.ts +23 -0
  69. package/build-types/toggle-group-control/types.d.ts.map +1 -1
  70. package/build-types/tooltip/index.d.ts +1 -7
  71. package/build-types/tooltip/index.d.ts.map +1 -1
  72. package/package.json +2 -2
  73. package/src/circular-option-picker/index.js +7 -5
  74. package/src/date-time/test/time.js +32 -2
  75. package/src/date-time/time.js +14 -6
  76. package/src/font-size-picker/index.js +1 -0
  77. package/src/index.js +1 -1
  78. package/src/mobile/global-styles-context/utils.native.js +2 -2
  79. package/src/navigation/item/index.js +10 -3
  80. package/src/navigation/stories/more-examples.js +2 -1
  81. package/src/navigation/styles/navigation-styles.js +5 -0
  82. package/src/palette-edit/index.js +392 -0
  83. package/src/palette-edit/style.scss +19 -0
  84. package/src/{color-edit → palette-edit}/styles.js +15 -18
  85. package/src/popover/index.js +5 -1
  86. package/src/style.scss +1 -1
  87. package/src/toggle-group-control/stories/index.js +15 -0
  88. package/src/toggle-group-control/test/index.js +57 -0
  89. package/src/toggle-group-control/toggle-group-control-option/README.md +8 -1
  90. package/src/toggle-group-control/toggle-group-control-option/component.tsx +40 -17
  91. package/src/toggle-group-control/types.ts +24 -0
  92. package/src/tooltip/index.js +2 -7
  93. package/tsconfig.tsbuildinfo +1 -1
  94. package/build/color-edit/index.js +0 -271
  95. package/build/color-edit/index.js.map +0 -1
  96. package/build/color-edit/styles.js +0 -112
  97. package/build/color-edit/styles.js.map +0 -1
  98. package/build-module/color-edit/index.js +0 -247
  99. package/build-module/color-edit/index.js.map +0 -1
  100. package/build-module/color-edit/styles.js +0 -90
  101. package/build-module/color-edit/styles.js.map +0 -1
  102. package/src/color-edit/index.js +0 -329
  103. package/src/color-edit/style.scss +0 -6
@@ -1,329 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { kebabCase } from 'lodash';
5
-
6
- /**
7
- * WordPress dependencies
8
- */
9
- import { useState, useRef, useEffect } from '@wordpress/element';
10
- import { __ } from '@wordpress/i18n';
11
- import { lineSolid, moreVertical, plus } from '@wordpress/icons';
12
- import { __experimentalUseFocusOutside as useFocusOutside } from '@wordpress/compose';
13
-
14
- /**
15
- * Internal dependencies
16
- */
17
- import Button from '../button';
18
- import { ColorPicker } from '../color-picker';
19
- import { FlexItem } from '../flex';
20
- import { HStack } from '../h-stack';
21
- import { ItemGroup } from '../item-group';
22
- import { VStack } from '../v-stack';
23
- import ColorPalette from '../color-palette';
24
- import DropdownMenu from '../dropdown-menu';
25
- import Popover from '../popover';
26
- import {
27
- ColorActionsContainer,
28
- ColorEditStyles,
29
- ColorHeading,
30
- ColorHStackHeader,
31
- ColorIndicatorStyled,
32
- ColorItem,
33
- ColorNameContainer,
34
- ColorNameInputControl,
35
- DoneButton,
36
- RemoveButton,
37
- } from './styles';
38
- import { NavigableMenu } from '../navigable-container';
39
-
40
- function ColorNameInput( { value, onChange } ) {
41
- return (
42
- <ColorNameInputControl
43
- label={ __( 'Color name' ) }
44
- hideLabelFromVision
45
- value={ value }
46
- onChange={ onChange }
47
- />
48
- );
49
- }
50
-
51
- function ColorOption( {
52
- canOnlyChangeValues,
53
- color,
54
- onChange,
55
- isEditing,
56
- onStartEditing,
57
- onRemove,
58
- onStopEditing,
59
- slugPrefix,
60
- } ) {
61
- const focusOutsideProps = useFocusOutside( onStopEditing );
62
- return (
63
- <ColorItem
64
- as="div"
65
- onClick={ onStartEditing }
66
- { ...( isEditing ? focusOutsideProps : {} ) }
67
- >
68
- <HStack justify="flex-start">
69
- <FlexItem>
70
- <ColorIndicatorStyled colorValue={ color.color } />
71
- </FlexItem>
72
- <FlexItem>
73
- { isEditing && ! canOnlyChangeValues ? (
74
- <ColorNameInput
75
- value={ color.name }
76
- onChange={ ( nextName ) =>
77
- onChange( {
78
- ...color,
79
- name: nextName,
80
- slug: slugPrefix + kebabCase( nextName ),
81
- } )
82
- }
83
- />
84
- ) : (
85
- <ColorNameContainer>{ color.name }</ColorNameContainer>
86
- ) }
87
- </FlexItem>
88
- { isEditing && ! canOnlyChangeValues && (
89
- <FlexItem>
90
- <RemoveButton
91
- isSmall
92
- icon={ lineSolid }
93
- label={ __( 'Remove color' ) }
94
- onClick={ onRemove }
95
- />
96
- </FlexItem>
97
- ) }
98
- </HStack>
99
- { isEditing && (
100
- <Popover
101
- position="bottom left"
102
- className="components-color-edit__color-popover"
103
- >
104
- <ColorPicker
105
- color={ color.color }
106
- onChange={ ( newColor ) =>
107
- onChange( {
108
- ...color,
109
- color: newColor,
110
- } )
111
- }
112
- />
113
- </Popover>
114
- ) }
115
- </ColorItem>
116
- );
117
- }
118
-
119
- function ColorPaletteEditListView( {
120
- colors,
121
- onChange,
122
- editingColor,
123
- setEditingColor,
124
- canOnlyChangeValues,
125
- slugPrefix,
126
- } ) {
127
- // When unmounting the component if there are empty colors (the user did not complete the insertion) clean them.
128
- const colorReference = useRef();
129
- useEffect( () => {
130
- colorReference.current = colors;
131
- }, [ colors ] );
132
- useEffect( () => {
133
- return () => {
134
- if ( colorReference.current.some( ( { slug } ) => ! slug ) ) {
135
- const newColors = colorReference.current.filter(
136
- ( { slug } ) => slug
137
- );
138
- onChange( newColors.length ? newColors : undefined );
139
- }
140
- };
141
- }, [] );
142
- return (
143
- <VStack spacing={ 3 }>
144
- <ItemGroup isBordered isSeparated>
145
- { colors.map( ( color, index ) => (
146
- <ColorOption
147
- canOnlyChangeValues={ canOnlyChangeValues }
148
- key={ index }
149
- color={ color }
150
- onStartEditing={ () => {
151
- if ( editingColor !== index ) {
152
- setEditingColor( index );
153
- }
154
- } }
155
- onChange={ ( newColor ) => {
156
- onChange(
157
- colors.map( ( currentColor, currentIndex ) => {
158
- if ( currentIndex === index ) {
159
- return newColor;
160
- }
161
- return currentColor;
162
- } )
163
- );
164
- } }
165
- onRemove={ () => {
166
- setEditingColor( null );
167
- const newColors = colors.filter(
168
- ( _currentColor, currentIndex ) => {
169
- if ( currentIndex === index ) {
170
- return false;
171
- }
172
- return true;
173
- }
174
- );
175
- onChange(
176
- newColors.length ? newColors : undefined
177
- );
178
- } }
179
- isEditing={ index === editingColor }
180
- onStopEditing={ () => {
181
- if ( index === editingColor ) {
182
- setEditingColor( null );
183
- }
184
- } }
185
- slugPrefix={ slugPrefix }
186
- />
187
- ) ) }
188
- </ItemGroup>
189
- </VStack>
190
- );
191
- }
192
-
193
- const EMPTY_ARRAY = [];
194
-
195
- export default function ColorEdit( {
196
- colors = EMPTY_ARRAY,
197
- onChange,
198
- paletteLabel,
199
- emptyMessage,
200
- canOnlyChangeValues,
201
- canReset,
202
- slugPrefix = '',
203
- } ) {
204
- const [ isEditing, setIsEditing ] = useState( false );
205
- const [ editingColor, setEditingColor ] = useState( null );
206
- const isAdding =
207
- isEditing &&
208
- editingColor &&
209
- colors[ editingColor ] &&
210
- ! colors[ editingColor ].slug;
211
-
212
- const hasColors = colors.length > 0;
213
-
214
- return (
215
- <ColorEditStyles>
216
- <ColorHStackHeader>
217
- <ColorHeading>{ paletteLabel }</ColorHeading>
218
- <ColorActionsContainer>
219
- { isEditing && (
220
- <DoneButton
221
- isSmall
222
- onClick={ () => {
223
- setIsEditing( false );
224
- setEditingColor( null );
225
- } }
226
- >
227
- { __( 'Done' ) }
228
- </DoneButton>
229
- ) }
230
- { ! canOnlyChangeValues && (
231
- <Button
232
- isSmall
233
- isPressed={ isAdding }
234
- icon={ plus }
235
- label={ __( 'Add color' ) }
236
- onClick={ () => {
237
- onChange( [
238
- ...colors,
239
- {
240
- color: '#000',
241
- name: '',
242
- slug: '',
243
- },
244
- ] );
245
- setIsEditing( true );
246
- setEditingColor( colors.length );
247
- } }
248
- />
249
- ) }
250
- { ! isEditing && (
251
- <Button
252
- disabled={ ! hasColors }
253
- isSmall
254
- icon={ moreVertical }
255
- label={ __( 'Edit colors' ) }
256
- onClick={ () => {
257
- setIsEditing( true );
258
- } }
259
- />
260
- ) }
261
- { isEditing && ( canReset || ! canOnlyChangeValues ) && (
262
- <DropdownMenu
263
- icon={ moreVertical }
264
- label={ __( 'Color options' ) }
265
- toggleProps={ {
266
- isSmall: true,
267
- } }
268
- >
269
- { ( { onClose } ) => (
270
- <>
271
- <NavigableMenu role="menu">
272
- { ! canOnlyChangeValues && (
273
- <Button
274
- variant="tertiary"
275
- onClick={ () => {
276
- setEditingColor( null );
277
- setIsEditing( false );
278
- onChange();
279
- onClose();
280
- } }
281
- >
282
- { __( 'Remove all colors' ) }
283
- </Button>
284
- ) }
285
- { canReset && (
286
- <Button
287
- variant="tertiary"
288
- onClick={ () => {
289
- setEditingColor( null );
290
- onChange();
291
- onClose();
292
- } }
293
- >
294
- { __( 'Reset colors' ) }
295
- </Button>
296
- ) }
297
- </NavigableMenu>
298
- </>
299
- ) }
300
- </DropdownMenu>
301
- ) }
302
- </ColorActionsContainer>
303
- </ColorHStackHeader>
304
- { hasColors && (
305
- <>
306
- { isEditing && (
307
- <ColorPaletteEditListView
308
- canOnlyChangeValues={ canOnlyChangeValues }
309
- colors={ colors }
310
- onChange={ onChange }
311
- editingColor={ editingColor }
312
- setEditingColor={ setEditingColor }
313
- slugPrefix={ slugPrefix }
314
- />
315
- ) }
316
- { ! isEditing && (
317
- <ColorPalette
318
- colors={ colors }
319
- onChange={ () => {} }
320
- clearable={ false }
321
- disableCustomColors={ true }
322
- />
323
- ) }
324
- </>
325
- ) }
326
- { ! hasColors && emptyMessage }
327
- </ColorEditStyles>
328
- );
329
- }
@@ -1,6 +0,0 @@
1
- @include break-medium() {
2
- .components-color-edit__color-popover.components-popover .components-popover__content.components-popover__content.components-popover__content {
3
- margin-right: #{ math.div($sidebar-width, 2) + $grid-unit-20 };
4
- margin-top: #{ -($grid-unit-60 + $border-width) };
5
- }
6
- }