newspack-components 4.1.0 → 4.3.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 (135) hide show
  1. package/colors/colors.module.scss +1 -1
  2. package/dist/cjs/action-card/index.js +21 -12
  3. package/dist/cjs/action-card/style.scss +32 -14
  4. package/dist/cjs/autocomplete-tokenfield/index.js +2 -2
  5. package/dist/cjs/autocomplete-with-latest-posts/index.js +289 -0
  6. package/dist/cjs/autocomplete-with-latest-posts/style.scss +150 -0
  7. package/dist/cjs/badge/index.js +32 -0
  8. package/dist/cjs/badge/style.scss +36 -0
  9. package/dist/cjs/button/index.js +2 -0
  10. package/dist/cjs/card/core-card.js +141 -0
  11. package/dist/cjs/card/index.js +33 -0
  12. package/dist/cjs/card/style-core.scss +227 -0
  13. package/dist/cjs/card/style.scss +2 -2
  14. package/dist/cjs/card-settings-group/index.js +49 -0
  15. package/dist/cjs/card-settings-group/style.scss +33 -0
  16. package/dist/cjs/card-sortable-list/index.js +390 -0
  17. package/dist/cjs/card-sortable-list/style.scss +48 -0
  18. package/dist/cjs/confirm-dialog/index.js +59 -0
  19. package/dist/cjs/divider/index.js +42 -0
  20. package/dist/cjs/divider/style.scss +51 -0
  21. package/dist/cjs/form-token-field/style.scss +0 -5
  22. package/dist/cjs/grid/index.js +2 -1
  23. package/dist/cjs/grid/style.scss +63 -9
  24. package/dist/cjs/index.js +42 -0
  25. package/dist/cjs/modal/index.js +11 -4
  26. package/dist/cjs/modal/style.scss +43 -13
  27. package/dist/cjs/newspack-icon/style.scss +5 -3
  28. package/dist/cjs/popover/style.scss +1 -1
  29. package/dist/cjs/section-header/index.js +76 -17
  30. package/dist/cjs/section-header/style.scss +109 -4
  31. package/dist/cjs/style.scss +2 -0
  32. package/dist/cjs/waiting/index.js +3 -1
  33. package/dist/cjs/waiting/style.scss +4 -0
  34. package/dist/cjs/web-preview/index.js +98 -39
  35. package/dist/cjs/web-preview/style.scss +20 -53
  36. package/dist/cjs/with-wizard/index.js +1 -1
  37. package/dist/cjs/with-wizard/style.scss +24 -6
  38. package/dist/cjs/with-wizard-screen/style.scss +39 -10
  39. package/dist/cjs/wizard/components/WizardSnackbar.js +70 -0
  40. package/dist/cjs/wizard/components/style.scss +48 -0
  41. package/dist/cjs/wizard/index.js +97 -16
  42. package/dist/cjs/wizard/store/index.js +46 -0
  43. package/dist/esm/action-card/index.js +21 -12
  44. package/dist/esm/action-card/style.scss +32 -14
  45. package/dist/esm/autocomplete-tokenfield/index.js +2 -2
  46. package/dist/esm/autocomplete-with-latest-posts/index.js +281 -0
  47. package/dist/esm/autocomplete-with-latest-posts/style.scss +150 -0
  48. package/dist/esm/badge/index.js +24 -0
  49. package/dist/esm/badge/style.scss +36 -0
  50. package/dist/esm/button/index.js +2 -0
  51. package/dist/esm/card/core-card.js +133 -0
  52. package/dist/esm/card/index.js +33 -0
  53. package/dist/esm/card/style-core.scss +227 -0
  54. package/dist/esm/card/style.scss +2 -2
  55. package/dist/esm/card-settings-group/index.js +42 -0
  56. package/dist/esm/card-settings-group/style.scss +33 -0
  57. package/dist/esm/card-sortable-list/index.js +381 -0
  58. package/dist/esm/card-sortable-list/style.scss +48 -0
  59. package/dist/esm/confirm-dialog/index.js +49 -0
  60. package/dist/esm/divider/index.js +34 -0
  61. package/dist/esm/divider/style.scss +51 -0
  62. package/dist/esm/form-token-field/style.scss +0 -5
  63. package/dist/esm/grid/index.js +2 -1
  64. package/dist/esm/grid/style.scss +63 -9
  65. package/dist/esm/index.js +6 -0
  66. package/dist/esm/modal/index.js +11 -4
  67. package/dist/esm/modal/style.scss +43 -13
  68. package/dist/esm/newspack-icon/style.scss +5 -3
  69. package/dist/esm/popover/style.scss +1 -1
  70. package/dist/esm/section-header/index.js +75 -18
  71. package/dist/esm/section-header/style.scss +109 -4
  72. package/dist/esm/style.scss +2 -0
  73. package/dist/esm/waiting/index.js +3 -1
  74. package/dist/esm/waiting/style.scss +4 -0
  75. package/dist/esm/web-preview/index.js +101 -42
  76. package/dist/esm/web-preview/style.scss +20 -53
  77. package/dist/esm/with-wizard/index.js +1 -1
  78. package/dist/esm/with-wizard/style.scss +24 -6
  79. package/dist/esm/with-wizard-screen/style.scss +39 -10
  80. package/dist/esm/wizard/components/WizardSnackbar.js +64 -0
  81. package/dist/esm/wizard/components/style.scss +48 -0
  82. package/dist/esm/wizard/index.js +101 -20
  83. package/dist/esm/wizard/store/index.js +46 -0
  84. package/package.json +5 -6
  85. package/shared/author-context.js +26 -0
  86. package/shared/hooks/use-coauthors.js +220 -0
  87. package/shared/hooks/use-coauthors.test.js +624 -0
  88. package/shared/hooks/use-custom-byline.js +47 -0
  89. package/shared/hooks/use-custom-byline.test.js +133 -0
  90. package/shared/scss/_mixins.scss +46 -0
  91. package/src/action-card/action-card.d.ts +7 -3
  92. package/src/action-card/index.js +24 -11
  93. package/src/action-card/style.scss +32 -14
  94. package/src/autocomplete-tokenfield/index.js +2 -2
  95. package/src/autocomplete-with-latest-posts/index.js +290 -0
  96. package/src/autocomplete-with-latest-posts/style.scss +150 -0
  97. package/src/badge/index.tsx +24 -0
  98. package/src/badge/style.scss +36 -0
  99. package/src/button/index.tsx +3 -2
  100. package/src/card/core-card.js +147 -0
  101. package/src/card/index.js +39 -1
  102. package/src/card/style-core.scss +227 -0
  103. package/src/card/style.scss +2 -2
  104. package/src/card-settings-group/README.md +43 -0
  105. package/src/card-settings-group/index.tsx +53 -0
  106. package/src/card-settings-group/style.scss +33 -0
  107. package/src/card-sortable-list/README.md +51 -0
  108. package/src/card-sortable-list/index.tsx +412 -0
  109. package/src/card-sortable-list/style.scss +48 -0
  110. package/src/confirm-dialog/index.tsx +64 -0
  111. package/src/divider/README.md +25 -0
  112. package/src/divider/index.js +31 -0
  113. package/src/divider/style.scss +51 -0
  114. package/src/form-token-field/style.scss +0 -5
  115. package/src/grid/index.tsx +2 -1
  116. package/src/grid/style.scss +63 -9
  117. package/src/index.js +6 -0
  118. package/src/modal/index.js +12 -3
  119. package/src/modal/style.scss +43 -13
  120. package/src/newspack-icon/style.scss +5 -3
  121. package/src/popover/style.scss +1 -1
  122. package/src/section-header/index.js +72 -13
  123. package/src/section-header/style.scss +109 -4
  124. package/src/style.scss +2 -0
  125. package/src/waiting/index.js +2 -1
  126. package/src/waiting/style.scss +4 -0
  127. package/src/web-preview/index.js +90 -35
  128. package/src/web-preview/style.scss +20 -53
  129. package/src/with-wizard/index.js +1 -1
  130. package/src/with-wizard/style.scss +24 -6
  131. package/src/with-wizard-screen/style.scss +39 -10
  132. package/src/wizard/components/WizardSnackbar.js +58 -0
  133. package/src/wizard/components/style.scss +48 -0
  134. package/src/wizard/index.js +108 -14
  135. package/src/wizard/store/index.js +26 -0
@@ -0,0 +1,412 @@
1
+ /**
2
+ * Card - Sortable list component.
3
+ */
4
+
5
+ /**
6
+ * WordPress dependencies.
7
+ */
8
+ import { Disabled, Draggable, __experimentalVStack as VStack } from '@wordpress/components'; // eslint-disable-line @wordpress/no-unsafe-wp-apis
9
+ import { useEffect, useLayoutEffect, useRef, useState } from '@wordpress/element';
10
+
11
+ /**
12
+ * Internal dependencies
13
+ */
14
+ import { Badge, Card } from '../';
15
+ import './style.scss';
16
+
17
+ /**
18
+ * External dependencies
19
+ */
20
+ import classNames from 'classnames';
21
+
22
+ const DROP_ANIMATION_DURATION = 400; // ms — must match $drop-duration in style.scss
23
+ const BUTTON_MOVE_DURATION = 200; // ms — must match $shift-duration in style.scss
24
+
25
+ type DraggableItem = {
26
+ id: string | number;
27
+ title: string;
28
+ badgeLevel: 'default' | 'success' | 'info' | 'warning' | 'error';
29
+ badgeText: string;
30
+ };
31
+
32
+ type DragMeasurements = {
33
+ lockedHeight: number;
34
+ sourceHeight: number;
35
+ // Height of each item (including the VStack gap after it, except the last).
36
+ itemStrides: number[];
37
+ // Top edge of each item, used for drop position hit-testing in onDragEnd.
38
+ itemTops: number[];
39
+ };
40
+
41
+ const CardSortableList = ( {
42
+ disabled = false,
43
+ items = [],
44
+ onDragCallback = () => {},
45
+ }: {
46
+ disabled?: boolean;
47
+ items?: DraggableItem[];
48
+ onDragCallback?: ( index: number, targetIndex: number ) => void;
49
+ } ) => {
50
+ const [ sortedItems, setSortedItems ] = useState( items );
51
+ const [ draggingIndex, setDraggingIndex ] = useState< number | null >( null );
52
+ const [ hoverIndex, setHoverIndex ] = useState< number | null >( null );
53
+ const [ droppedIndex, setDroppedIndex ] = useState< number | null >( null );
54
+ const [ measurements, setMeasurements ] = useState< DragMeasurements | null >( null );
55
+ const listRef = useRef< HTMLDivElement | null >( null );
56
+ const itemRefs = useRef< ( HTMLDivElement | null )[] >( [] );
57
+ const dropAnimationTimer = useRef< ReturnType< typeof setTimeout > | null >( null );
58
+ const buttonMoveTimer = useRef< ReturnType< typeof setTimeout > | null >( null );
59
+ const buttonFlipRef = useRef< {
60
+ fromIndex: number;
61
+ toIndex: number;
62
+ stride: number;
63
+ direction: number;
64
+ } | null >( null );
65
+ const [ buttonMoveId, setButtonMoveId ] = useState( 0 );
66
+ const documentDragOverRef = useRef< ( ( e: Event ) => void ) | null >( null );
67
+
68
+ // Keep sortedItems in sync when the items prop changes externally (e.g. after a save).
69
+ useEffect( () => {
70
+ setSortedItems( items );
71
+ }, [ items ] );
72
+
73
+ // Clean up any pending animation timer on unmount.
74
+ useEffect( () => {
75
+ return () => {
76
+ if ( dropAnimationTimer.current ) {
77
+ clearTimeout( dropAnimationTimer.current );
78
+ }
79
+ if ( buttonMoveTimer.current ) {
80
+ clearTimeout( buttonMoveTimer.current );
81
+ }
82
+ if ( documentDragOverRef.current ) {
83
+ document.removeEventListener( 'dragover', documentDragOverRef.current );
84
+ }
85
+ };
86
+ }, [] );
87
+
88
+ /**
89
+ * Handle a chevron-button move. Records item positions before the reorder so
90
+ * the FLIP animation can play after React commits the new DOM order.
91
+ */
92
+ const handleButtonMove = ( fromIndex: number, toIndex: number ) => {
93
+ if ( toIndex < 0 || toIndex >= sortedItems.length ) {
94
+ return;
95
+ }
96
+
97
+ const fromEl = itemRefs.current[ fromIndex ];
98
+ const toEl = itemRefs.current[ toIndex ];
99
+ if ( ! fromEl || ! toEl ) {
100
+ return;
101
+ }
102
+
103
+ const stride = Math.abs( toEl.getBoundingClientRect().top - fromEl.getBoundingClientRect().top );
104
+ const direction = toIndex > fromIndex ? 1 : -1;
105
+ buttonFlipRef.current = { fromIndex, toIndex, stride, direction };
106
+
107
+ const reordered = [ ...sortedItems ];
108
+ const [ moved ] = reordered.splice( fromIndex, 1 );
109
+ reordered.splice( toIndex, 0, moved );
110
+ setSortedItems( reordered );
111
+ setButtonMoveId( id => id + 1 );
112
+ };
113
+
114
+ /**
115
+ * FLIP Invert+Play step: runs synchronously after React commits the reordered
116
+ * DOM. Animate each swapped item from its previous position to its new one
117
+ * using inline CSS transitions (no CSS classes, to avoid creating a new
118
+ * containing block that would break position:fixed on the Draggable clone).
119
+ */
120
+ useLayoutEffect( () => {
121
+ const flipData = buttonFlipRef.current;
122
+ if ( ! flipData ) {
123
+ return;
124
+ }
125
+ buttonFlipRef.current = null;
126
+
127
+ const { fromIndex, toIndex, stride, direction } = flipData;
128
+
129
+ const startAnimation = ( el: HTMLDivElement | null, startY: number ) => {
130
+ if ( ! el ) {
131
+ return;
132
+ }
133
+ // Snap to the starting position with no transition.
134
+ el.style.transition = 'none';
135
+ el.style.transform = `translateY(${ startY }px)`;
136
+ // Force a reflow so the browser registers the starting position
137
+ // before we switch to the animated transition.
138
+ el.getBoundingClientRect();
139
+ // Animate from startY back to 0 (its new natural position).
140
+ el.style.transition = `transform ${ BUTTON_MOVE_DURATION }ms ease-out`;
141
+ el.style.transform = '';
142
+ };
143
+
144
+ // Moved item is now at toIndex: animate it in from its old position.
145
+ startAnimation( itemRefs.current[ toIndex ], -direction * stride );
146
+ // Displaced item is now at fromIndex: animate it in from its old position.
147
+ startAnimation( itemRefs.current[ fromIndex ], direction * stride );
148
+
149
+ if ( buttonMoveTimer.current ) {
150
+ clearTimeout( buttonMoveTimer.current );
151
+ }
152
+ buttonMoveTimer.current = setTimeout( () => {
153
+ // Clear inline animation styles before calling the external callback so
154
+ // the subsequent React re-render doesn't fight a live animation.
155
+ [ fromIndex, toIndex ].forEach( i => {
156
+ const el = itemRefs.current[ i ];
157
+ if ( el ) {
158
+ el.style.transition = '';
159
+ el.style.transform = '';
160
+ }
161
+ } );
162
+
163
+ // Move focus to the matching chevron button on the card at toIndex.
164
+ // Focus before onDragCallback so a parent rerender can't steal focus.
165
+ const targetEl = itemRefs.current[ toIndex ];
166
+ if ( targetEl ) {
167
+ const moveButtons = targetEl.querySelectorAll< HTMLButtonElement >(
168
+ '.newspack-card--core__header__draggable-controls__move-buttons button'
169
+ );
170
+ // direction > 0 = moved down → prefer the down button (index 1).
171
+ // direction < 0 = moved up → prefer the up button (index 0).
172
+ const preferred = direction > 0 ? moveButtons[ 1 ] : moveButtons[ 0 ];
173
+ const fallback = direction > 0 ? moveButtons[ 0 ] : moveButtons[ 1 ];
174
+ if ( preferred && ! preferred.disabled ) {
175
+ preferred.focus();
176
+ } else if ( fallback && ! fallback.disabled ) {
177
+ fallback.focus();
178
+ }
179
+ }
180
+
181
+ onDragCallback( fromIndex, toIndex );
182
+ buttonMoveTimer.current = null;
183
+ }, BUTTON_MOVE_DURATION );
184
+ }, [ buttonMoveId ] ); // eslint-disable-line react-hooks/exhaustive-deps
185
+
186
+ const handleDragStart = ( index: number ) => {
187
+ // Cancel any in-progress button-move animation so no item wrapper keeps
188
+ // an inline transform. A transformed ancestor breaks position:fixed on
189
+ // the Draggable clone (CSS spec: fixed positioning is relative to the
190
+ // nearest ancestor with a transform/filter/perspective).
191
+ if ( buttonMoveTimer.current ) {
192
+ clearTimeout( buttonMoveTimer.current );
193
+ buttonMoveTimer.current = null;
194
+ itemRefs.current.forEach( el => {
195
+ if ( el ) {
196
+ el.style.transition = '';
197
+ el.style.transform = '';
198
+ }
199
+ } );
200
+ }
201
+
202
+ const listEl = listRef.current;
203
+ if ( listEl ) {
204
+ const itemEls = itemRefs.current;
205
+ const rects = itemEls.map( el => el?.getBoundingClientRect() );
206
+
207
+ // Stride = item height + gap to next item (difference between consecutive tops).
208
+ const itemStrides = rects.map( ( rect, i ) => {
209
+ if ( ! rect ) {
210
+ return 0;
211
+ }
212
+ const nextRect = rects[ i + 1 ];
213
+ return nextRect ? nextRect.top - rect.top : rect.height;
214
+ } );
215
+
216
+ setMeasurements( {
217
+ lockedHeight: listEl.getBoundingClientRect().height,
218
+ sourceHeight: rects[ index ]?.height ?? 0,
219
+ itemStrides,
220
+ itemTops: rects.map( rect => rect?.top ?? 0 ),
221
+ } );
222
+ }
223
+ // Make the entire document a valid drop target so the browser skips
224
+ // its snap-back animation when the cursor is released outside the list.
225
+ const preventSnapback = ( e: Event ) => e.preventDefault();
226
+ document.addEventListener( 'dragover', preventSnapback );
227
+ documentDragOverRef.current = preventSnapback;
228
+
229
+ setDraggingIndex( index );
230
+ setDroppedIndex( null );
231
+ };
232
+
233
+ const clearDragState = () => {
234
+ if ( documentDragOverRef.current ) {
235
+ document.removeEventListener( 'dragover', documentDragOverRef.current );
236
+ documentDragOverRef.current = null;
237
+ }
238
+ setDraggingIndex( null );
239
+ setHoverIndex( null );
240
+ setMeasurements( null );
241
+ };
242
+
243
+ /**
244
+ * Determine the drop target index from cursor coordinates and the item
245
+ * top positions snapshotted at drag start. Mirrors the midpoint logic
246
+ * previously used in getDropIndex but works without a live event target.
247
+ */
248
+ const getDropIndexFromCursor = ( clientY: number, m: DragMeasurements, sourceIndex: number ): number => {
249
+ const { itemTops, itemStrides, sourceHeight } = m;
250
+ for ( let i = 0; i < itemTops.length; i++ ) {
251
+ const movingDown = sourceIndex > i;
252
+ const midpoint = itemTops[ i ] + ( movingDown ? itemStrides[ i ] : itemStrides[ i ] - sourceHeight );
253
+ if ( clientY < midpoint ) {
254
+ return i;
255
+ }
256
+ }
257
+ return itemTops.length; // below all items
258
+ };
259
+
260
+ const handleDragEnd = ( event: DragEvent ) => {
261
+ // Take a local copy of measurements before clearDragState nulls it.
262
+ const m = measurements;
263
+ const sourceIndex = draggingIndex;
264
+
265
+ clearDragState();
266
+
267
+ if ( m === null || sourceIndex === null ) {
268
+ return;
269
+ }
270
+
271
+ const dropIndex = getDropIndexFromCursor( event.clientY, m, sourceIndex );
272
+
273
+ // Compute the destination index in the post-removal array.
274
+ // After splicing out the dragged item, indices above it shift down by one.
275
+ const insertIndex = dropIndex > sourceIndex ? dropIndex - 1 : dropIndex;
276
+ if ( insertIndex === sourceIndex ) {
277
+ return;
278
+ }
279
+
280
+ const reordered = [ ...sortedItems ];
281
+ const [ moved ] = reordered.splice( sourceIndex, 1 );
282
+ reordered.splice( insertIndex, 0, moved );
283
+
284
+ // First render: show items in their new order with no animation.
285
+ // The dragging CSS classes are already cleared by clearDragState() above,
286
+ // so no transitions will fire on this paint.
287
+ setSortedItems( reordered );
288
+
289
+ // Next frame: trigger the drop animation on the newly-positioned item,
290
+ // then call onDragCallback after the animation completes.
291
+ requestAnimationFrame( () => {
292
+ setDroppedIndex( insertIndex );
293
+ dropAnimationTimer.current = setTimeout( () => {
294
+ setDroppedIndex( null );
295
+ onDragCallback( sourceIndex, insertIndex );
296
+ }, DROP_ANIMATION_DURATION );
297
+ } );
298
+ };
299
+
300
+ const handleDragOver = ( event: React.DragEvent< HTMLDivElement >, index: number ) => {
301
+ event.preventDefault();
302
+ if ( ! measurements ) {
303
+ return;
304
+ }
305
+ const rect = event.currentTarget.getBoundingClientRect();
306
+ const midpoint = rect.top + rect.height / 2;
307
+ setHoverIndex( event.clientY < midpoint ? index : index + 1 );
308
+ };
309
+
310
+ /**
311
+ * Compute the translateY for a non-source item at `index` given the current
312
+ * draggingIndex and hoverIndex, so that items visually shift to show the gap
313
+ * while the container's layout height stays fixed.
314
+ *
315
+ * The source item has been visually hidden but still occupies its layout slot.
316
+ * Items between the source and the hover position need to slide by the source
317
+ * item's stride (height + gap) to either fill the vacated source slot or make
318
+ * room for the incoming gap at the hover position.
319
+ */
320
+ const getTranslateY = ( index: number ): number => {
321
+ if ( draggingIndex === null || hoverIndex === null || ! measurements ) {
322
+ return 0;
323
+ }
324
+ if ( index === draggingIndex ) {
325
+ return 0;
326
+ }
327
+
328
+ const { itemStrides, sourceHeight } = measurements;
329
+ const sourceStride = itemStrides[ draggingIndex ] ?? sourceHeight;
330
+
331
+ if ( hoverIndex > draggingIndex ) {
332
+ // Dragging downward: items strictly between source and hover position slide up.
333
+ if ( index > draggingIndex && index < hoverIndex ) {
334
+ return -sourceStride;
335
+ }
336
+ } else if ( index >= hoverIndex && index < draggingIndex ) {
337
+ // Dragging upward: items between hover position and source slide down.
338
+ return sourceStride;
339
+ }
340
+
341
+ return 0;
342
+ };
343
+
344
+ const isDragging = draggingIndex !== null;
345
+
346
+ return (
347
+ <VStack
348
+ ref={ listRef }
349
+ className={ classNames(
350
+ 'newspack-card--core--sortable-list',
351
+ disabled && 'newspack-card--core--sortable-list__is-disabled',
352
+ isDragging && 'newspack-card--core--sortable-list__is-dragging'
353
+ ) }
354
+ style={ measurements ? { height: measurements.lockedHeight } : undefined }
355
+ spacing={ 4 }
356
+ >
357
+ { sortedItems.map( ( item, index ) => {
358
+ const translateY = getTranslateY( index );
359
+ return (
360
+ <Disabled key={ item.id } isDisabled={ disabled }>
361
+ <div
362
+ ref={ el => {
363
+ itemRefs.current[ index ] = el;
364
+ } }
365
+ className={ classNames( 'newspack-card--core--sortable-list__item', {
366
+ 'is-source': draggingIndex === index,
367
+ 'is-dropped': droppedIndex === index,
368
+ } ) }
369
+ style={ translateY ? { transform: `translateY(${ translateY }px)` } : { transition: ! isDragging ? 'none' : undefined } }
370
+ id={ `draggable-card-${ index }` }
371
+ onDragOver={ e => handleDragOver( e, index ) }
372
+ >
373
+ <Draggable
374
+ transferData={ {} }
375
+ cloneClassname="newspack-card--core--sortable-list__item__clone"
376
+ elementId={ `draggable-card-${ index }` }
377
+ onDragStart={ () => handleDragStart( index ) }
378
+ onDragEnd={ handleDragEnd }
379
+ appendToOwnerDocument
380
+ >
381
+ { ( { onDraggableStart, onDraggableEnd } ) => (
382
+ <Card
383
+ isSmall
384
+ draggable
385
+ onDragStart={ onDraggableStart }
386
+ onDragEnd={ onDraggableEnd }
387
+ __experimentalCoreCard
388
+ __experimentalCoreProps={ {
389
+ header: (
390
+ <h3>
391
+ { item.title }
392
+ <Badge level={ item.badgeLevel } text={ item.badgeText } />
393
+ </h3>
394
+ ),
395
+ isDraggable: true,
396
+ isFirstTarget: index === 0,
397
+ isLastTarget: index === sortedItems.length - 1,
398
+ dragIndex: index,
399
+ onDragCallback: handleButtonMove,
400
+ } }
401
+ />
402
+ ) }
403
+ </Draggable>
404
+ </div>
405
+ </Disabled>
406
+ );
407
+ } ) }
408
+ </VStack>
409
+ );
410
+ };
411
+
412
+ export default CardSortableList;
@@ -0,0 +1,48 @@
1
+ $collapse-duration: 200ms;
2
+ $shift-duration: 150ms;
3
+ $drop-duration: 400ms; /* must match DROP_ANIMATION_DURATION in index.tsx */
4
+
5
+ .newspack-card--core--sortable-list {
6
+ &__item {
7
+ cursor: grab;
8
+
9
+ /*
10
+ * Animate items sliding to fill/make space around the dragged item.
11
+ */
12
+ transition: transform $shift-duration ease;
13
+
14
+ /*
15
+ * Collapse the source item's content — the wrapper stays in layout as the
16
+ * anchor point, and the container height is locked via inline style in JS.
17
+ */
18
+ &.is-source {
19
+ cursor: grabbing;
20
+ opacity: 0;
21
+ transition: opacity $collapse-duration ease;
22
+ }
23
+
24
+ /*
25
+ * Drop landing animation: brief fade-in and scale on the newly placed item.
26
+ */
27
+ &.is-dropped {
28
+ animation: newspack-sortable-drop $drop-duration ease forwards;
29
+ opacity: 0;
30
+ }
31
+
32
+ }
33
+ }
34
+
35
+ @keyframes newspack-sortable-drop {
36
+ 0% {
37
+ opacity: 0;
38
+ transform: scale(0.98);
39
+ }
40
+ 60% {
41
+ opacity: 1;
42
+ transform: scale(1.01);
43
+ }
44
+ 100% {
45
+ opacity: 1;
46
+ transform: scale(1);
47
+ }
48
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Modal
3
+ */
4
+
5
+ /**
6
+ * WordPress dependencies.
7
+ */
8
+ import { forwardRef } from '@wordpress/element';
9
+ import { __experimentalConfirmDialog as BaseComponent } from '@wordpress/components'; // eslint-disable-line @wordpress/no-unsafe-wp-apis
10
+
11
+ /**
12
+ * External dependencies.
13
+ */
14
+ import classnames from 'classnames';
15
+
16
+ /*
17
+ * See both https://wordpress.github.io/gutenberg/?path=/docs/components-confirmdialog--docs and
18
+ * https://wordpress.github.io/gutenberg/?path=/docs/components-modal--docs for all supported props.
19
+ */
20
+ type ConfirmDialogProps = {
21
+ className?: string;
22
+ size?: 'small' | 'medium' | 'large' | 'x-large' | 'full';
23
+ hideTitle?: boolean;
24
+ title?: string;
25
+ isDestructive?: boolean;
26
+ cancelButtonText?: string;
27
+ confirmButtonText?: string;
28
+ onConfirm: () => void;
29
+ onCancel: () => void;
30
+ children?: React.ReactNode;
31
+ };
32
+
33
+ const sizeClassMap = {
34
+ small: 'newspack-modal--size-small',
35
+ medium: 'newspack-modal--size-medium',
36
+ large: 'newspack-modal--size-large',
37
+ 'x-large': 'newspack-modal--size-x-large',
38
+ full: 'newspack-modal--size-full',
39
+ };
40
+
41
+ function ConfirmDialog(
42
+ { className, size = 'small', hideTitle, isDestructive, onConfirm, onCancel, ...otherProps }: ConfirmDialogProps,
43
+ ref: React.Ref< HTMLDivElement >
44
+ ) {
45
+ const classes = classnames(
46
+ 'newspack-modal',
47
+ sizeClassMap[ size ],
48
+ hideTitle && 'newspack-modal--hide-title', // Note: also hides the X close button.
49
+ isDestructive && 'newspack-modal--destructive',
50
+ className
51
+ );
52
+
53
+ return (
54
+ <BaseComponent
55
+ className={ classes }
56
+ { ...otherProps }
57
+ ref={ ref }
58
+ onConfirm={ onConfirm }
59
+ onCancel={ onCancel }
60
+ __experimentalHideHeader={ false }
61
+ />
62
+ );
63
+ }
64
+ export default forwardRef( ConfirmDialog );
@@ -0,0 +1,25 @@
1
+ # Divider
2
+
3
+ Horizontal rule component with alignment, variant, and margin options.
4
+
5
+ ## Props
6
+
7
+ | Prop | Type | Default | Description |
8
+ |------|------|---------|-------------|
9
+ | `alignment` | `'full-width'` \| `'none'` | `'none'` | `full-width` breaks out of the container to span the viewport; `none` stays within the container. |
10
+ | `className` | `string` | — | Additional CSS class. |
11
+ | `marginBottom` | `number` \| `string` | `64` | Bottom margin (e.g. `64` or `"2rem"`). Capped at 32px on viewports &lt; 783px. |
12
+ | `marginTop` | `number` \| `string` | `64` | Top margin (e.g. `64` or `"2rem"`). Capped at 32px on viewports &lt; 783px. |
13
+ | `variant` | `'default'` \| `'primary'` \| `'secondary'` \| `'tertiary'` | `'default'` | Line color: `default` uses `$gray-300`; `primary` uses the admin theme color (`--wp-admin-theme-color`); `secondary` uses `$gray-900`; `tertiary` uses `$gray-100`. |
14
+
15
+ ## Usage
16
+
17
+ ```jsx
18
+ import { Divider } from 'newspack-components';
19
+
20
+ <Divider />
21
+
22
+ <Divider alignment="full-width" variant="primary" />
23
+
24
+ <Divider marginBottom={ 48 } marginTop={ 32 } variant="secondary" />
25
+ ```
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Divider
3
+ */
4
+
5
+ /**
6
+ * Internal dependencies
7
+ */
8
+ import './style.scss';
9
+
10
+ /**
11
+ * External dependencies
12
+ */
13
+ import classNames from 'classnames';
14
+
15
+ const Divider = ( { alignment = 'none', className = undefined, marginBottom = 64, marginTop = 64, variant = 'default', ...otherProps } ) => {
16
+ const classes = classNames(
17
+ 'newspack-divider',
18
+ className,
19
+ alignment && `newspack-divider--alignment-${ alignment }`,
20
+ variant && `newspack-divider--variant-${ variant }`
21
+ );
22
+
23
+ const style = {
24
+ '--divider-margin-bottom': typeof marginBottom === 'number' ? `${ marginBottom }px` : marginBottom,
25
+ '--divider-margin-top': typeof marginTop === 'number' ? `${ marginTop }px` : marginTop,
26
+ };
27
+
28
+ return <hr className={ classes } style={ style } { ...otherProps } />;
29
+ };
30
+
31
+ export default Divider;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Divider
3
+ */
4
+
5
+ @use "~@wordpress/base-styles/colors" as wp-colors;
6
+
7
+ .newspack-divider {
8
+ background: transparent;
9
+ border: 0;
10
+ display: block;
11
+ height: 1px;
12
+ margin-bottom: min(32px, var(--divider-margin-bottom, 64px));
13
+ margin-left: 0;
14
+ margin-right: 0;
15
+ margin-top: min(32px, var(--divider-margin-top, 64px));
16
+ padding: 0;
17
+
18
+ @media screen and (min-width: 783px) {
19
+ margin-bottom: var(--divider-margin-bottom, 64px);
20
+ margin-top: var(--divider-margin-top, 64px);
21
+ }
22
+
23
+ // Alignment
24
+
25
+ &--alignment-full-width {
26
+ margin-left: calc(-50vw + 50%);
27
+ width: 100vw;
28
+ }
29
+
30
+ &--alignment-none {
31
+ width: 100%;
32
+ }
33
+
34
+ // Variant
35
+
36
+ &--variant-default {
37
+ background-color: wp-colors.$gray-300;
38
+ }
39
+
40
+ &--variant-primary {
41
+ background-color: var(--wp-admin-theme-color);
42
+ }
43
+
44
+ &--variant-secondary {
45
+ background-color: wp-colors.$gray-900;
46
+ }
47
+
48
+ &--variant-tertiary {
49
+ background-color: wp-colors.$gray-100;
50
+ }
51
+ }
@@ -7,11 +7,6 @@
7
7
  .newspack-form-token-field {
8
8
  width: 100%;
9
9
 
10
- .components-form-token-field__input-container {
11
- padding-bottom: 1px;
12
- padding-top: 1px;
13
- }
14
-
15
10
  // Help
16
11
 
17
12
  &__help {
@@ -12,9 +12,10 @@ import './style.scss';
12
12
  */
13
13
  import classnames from 'classnames';
14
14
 
15
- const Grid = ( { className = '', columns = 2, gutter = 32, noMargin = false, rowGap = 0, ...otherProps } ) => {
15
+ const Grid = ( { className = '', borders = false, columns = 2, gutter = 32, noMargin = false, rowGap = 0, ...otherProps } ) => {
16
16
  const classes = classnames(
17
17
  'newspack-grid',
18
+ borders && 'newspack-grid__borders',
18
19
  noMargin && 'newspack-grid--no-margin',
19
20
  columns && 'newspack-grid__columns-' + columns,
20
21
  gutter && 'newspack-grid__gutter-' + gutter,