@wordpress/dataviews 4.2.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 (123) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +47 -7
  3. package/build/components/dataviews/index.js +3 -5
  4. package/build/components/dataviews/index.js.map +1 -1
  5. package/build/components/dataviews-bulk-actions/index.js +145 -141
  6. package/build/components/dataviews-bulk-actions/index.js.map +1 -1
  7. package/build/components/dataviews-filters/add-filter.js +4 -6
  8. package/build/components/dataviews-filters/add-filter.js.map +1 -1
  9. package/build/components/dataviews-filters/search-widget.js +28 -18
  10. package/build/components/dataviews-filters/search-widget.js.map +1 -1
  11. package/build/components/dataviews-footer/index.js +45 -0
  12. package/build/components/dataviews-footer/index.js.map +1 -0
  13. package/build/components/dataviews-item-actions/index.js +5 -8
  14. package/build/components/dataviews-item-actions/index.js.map +1 -1
  15. package/build/components/dataviews-pagination/index.js +4 -4
  16. package/build/components/dataviews-pagination/index.js.map +1 -1
  17. package/build/components/dataviews-view-config/index.js +171 -32
  18. package/build/components/dataviews-view-config/index.js.map +1 -1
  19. package/build/dataforms-layouts/panel/index.js +4 -1
  20. package/build/dataforms-layouts/panel/index.js.map +1 -1
  21. package/build/dataviews-layouts/index.js +48 -2
  22. package/build/dataviews-layouts/index.js.map +1 -1
  23. package/build/dataviews-layouts/list/index.js +124 -84
  24. package/build/dataviews-layouts/list/index.js.map +1 -1
  25. package/build/dataviews-layouts/table/column-header-menu.js +52 -54
  26. package/build/dataviews-layouts/table/column-header-menu.js.map +1 -1
  27. package/build/dataviews-layouts/table/index.js +7 -35
  28. package/build/dataviews-layouts/table/index.js.map +1 -1
  29. package/build/normalize-fields.js +4 -2
  30. package/build/normalize-fields.js.map +1 -1
  31. package/build/types.js.map +1 -1
  32. package/build-module/components/dataviews/index.js +3 -5
  33. package/build-module/components/dataviews/index.js.map +1 -1
  34. package/build-module/components/dataviews-bulk-actions/index.js +145 -143
  35. package/build-module/components/dataviews-bulk-actions/index.js.map +1 -1
  36. package/build-module/components/dataviews-filters/add-filter.js +4 -6
  37. package/build-module/components/dataviews-filters/add-filter.js.map +1 -1
  38. package/build-module/components/dataviews-filters/search-widget.js +28 -18
  39. package/build-module/components/dataviews-filters/search-widget.js.map +1 -1
  40. package/build-module/components/dataviews-footer/index.js +38 -0
  41. package/build-module/components/dataviews-footer/index.js.map +1 -0
  42. package/build-module/components/dataviews-item-actions/index.js +5 -8
  43. package/build-module/components/dataviews-item-actions/index.js.map +1 -1
  44. package/build-module/components/dataviews-pagination/index.js +5 -5
  45. package/build-module/components/dataviews-pagination/index.js.map +1 -1
  46. package/build-module/components/dataviews-view-config/index.js +177 -38
  47. package/build-module/components/dataviews-view-config/index.js.map +1 -1
  48. package/build-module/dataforms-layouts/panel/index.js +4 -1
  49. package/build-module/dataforms-layouts/panel/index.js.map +1 -1
  50. package/build-module/dataviews-layouts/index.js +45 -1
  51. package/build-module/dataviews-layouts/index.js.map +1 -1
  52. package/build-module/dataviews-layouts/list/index.js +125 -83
  53. package/build-module/dataviews-layouts/list/index.js.map +1 -1
  54. package/build-module/dataviews-layouts/table/column-header-menu.js +52 -54
  55. package/build-module/dataviews-layouts/table/column-header-menu.js.map +1 -1
  56. package/build-module/dataviews-layouts/table/index.js +9 -37
  57. package/build-module/dataviews-layouts/table/index.js.map +1 -1
  58. package/build-module/normalize-fields.js +4 -2
  59. package/build-module/normalize-fields.js.map +1 -1
  60. package/build-module/types.js.map +1 -1
  61. package/build-style/style-rtl.css +79 -63
  62. package/build-style/style.css +79 -63
  63. package/build-types/components/dataviews/index.d.ts.map +1 -1
  64. package/build-types/components/dataviews/stories/fixtures.d.ts +27 -131
  65. package/build-types/components/dataviews/stories/fixtures.d.ts.map +1 -1
  66. package/build-types/components/dataviews/stories/index.story.d.ts +12 -53
  67. package/build-types/components/dataviews/stories/index.story.d.ts.map +1 -1
  68. package/build-types/components/dataviews-bulk-actions/index.d.ts +11 -1
  69. package/build-types/components/dataviews-bulk-actions/index.d.ts.map +1 -1
  70. package/build-types/components/dataviews-filters/add-filter.d.ts.map +1 -1
  71. package/build-types/components/dataviews-filters/search-widget.d.ts.map +1 -1
  72. package/build-types/components/dataviews-footer/index.d.ts +2 -0
  73. package/build-types/components/dataviews-footer/index.d.ts.map +1 -0
  74. package/build-types/components/dataviews-item-actions/index.d.ts.map +1 -1
  75. package/build-types/components/dataviews-view-config/index.d.ts.map +1 -1
  76. package/build-types/dataforms-layouts/panel/index.d.ts.map +1 -1
  77. package/build-types/dataviews-layouts/index.d.ts +4 -2
  78. package/build-types/dataviews-layouts/index.d.ts.map +1 -1
  79. package/build-types/dataviews-layouts/list/index.d.ts.map +1 -1
  80. package/build-types/dataviews-layouts/table/column-header-menu.d.ts.map +1 -1
  81. package/build-types/dataviews-layouts/table/index.d.ts.map +1 -1
  82. package/build-types/normalize-fields.d.ts.map +1 -1
  83. package/build-types/types.d.ts +2 -0
  84. package/build-types/types.d.ts.map +1 -1
  85. package/package.json +11 -11
  86. package/src/components/dataviews/index.tsx +2 -6
  87. package/src/components/dataviews/stories/fixtures.tsx +690 -0
  88. package/src/components/dataviews/stories/index.story.tsx +164 -0
  89. package/src/components/dataviews/style.scss +2 -0
  90. package/src/components/dataviews-bulk-actions/index.tsx +264 -213
  91. package/src/components/dataviews-bulk-actions/style.scss +9 -4
  92. package/src/components/dataviews-filters/add-filter.tsx +7 -11
  93. package/src/components/dataviews-filters/search-widget.tsx +45 -17
  94. package/src/components/dataviews-filters/style.scss +12 -2
  95. package/src/components/dataviews-footer/index.tsx +50 -0
  96. package/src/components/dataviews-footer/style.scss +40 -0
  97. package/src/components/dataviews-item-actions/index.tsx +8 -14
  98. package/src/components/dataviews-pagination/index.tsx +5 -5
  99. package/src/components/dataviews-pagination/style.scss +0 -19
  100. package/src/components/dataviews-view-config/index.tsx +252 -53
  101. package/src/components/dataviews-view-config/style.scss +25 -0
  102. package/src/dataforms-layouts/panel/index.tsx +2 -0
  103. package/src/dataviews-layouts/grid/style.scss +1 -1
  104. package/src/dataviews-layouts/index.ts +63 -2
  105. package/src/dataviews-layouts/list/index.tsx +199 -127
  106. package/src/dataviews-layouts/list/style.scss +10 -4
  107. package/src/dataviews-layouts/table/column-header-menu.tsx +85 -87
  108. package/src/dataviews-layouts/table/index.tsx +8 -65
  109. package/src/dataviews-layouts/table/style.scss +0 -5
  110. package/src/normalize-fields.ts +2 -0
  111. package/src/style.scss +1 -1
  112. package/src/types.ts +2 -0
  113. package/tsconfig.tsbuildinfo +1 -1
  114. package/build/components/dataviews-bulk-actions-toolbar/index.js +0 -207
  115. package/build/components/dataviews-bulk-actions-toolbar/index.js.map +0 -1
  116. package/build-module/components/dataviews-bulk-actions-toolbar/index.js +0 -201
  117. package/build-module/components/dataviews-bulk-actions-toolbar/index.js.map +0 -1
  118. package/build-types/components/dataviews-bulk-actions-toolbar/index.d.ts +0 -2
  119. package/build-types/components/dataviews-bulk-actions-toolbar/index.d.ts.map +0 -1
  120. package/src/components/dataviews/stories/fixtures.js +0 -250
  121. package/src/components/dataviews/stories/index.story.js +0 -71
  122. package/src/components/dataviews-bulk-actions-toolbar/index.tsx +0 -288
  123. package/src/components/dataviews-bulk-actions-toolbar/style.scss +0 -45
@@ -1,250 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { trash, image, Icon, category } from '@wordpress/icons';
5
- import {
6
- Button,
7
- __experimentalText as Text,
8
- __experimentalHStack as HStack,
9
- __experimentalVStack as VStack,
10
- } from '@wordpress/components';
11
-
12
- /**
13
- * Internal dependencies
14
- */
15
- import { LAYOUT_TABLE } from '../../../constants';
16
-
17
- export const data = [
18
- {
19
- id: 1,
20
- title: 'Apollo',
21
- description: 'Apollo description',
22
- image: 'https://live.staticflickr.com/5725/21726228300_51333bd62c_b.jpg',
23
- type: 'Not a planet',
24
- categories: [ 'Space', 'NASA' ],
25
- satellites: 0,
26
- date: '2021-01-01T00:00:00Z',
27
- },
28
- {
29
- id: 2,
30
- title: 'Space',
31
- description: 'Space description',
32
- image: 'https://live.staticflickr.com/5678/21911065441_92e2d44708_b.jpg',
33
- type: 'Not a planet',
34
- categories: [ 'Space' ],
35
- satellites: 0,
36
- date: '2019-01-02T00:00:00Z',
37
- },
38
- {
39
- id: 3,
40
- title: 'NASA',
41
- description: 'NASA photo',
42
- image: 'https://live.staticflickr.com/742/21712365770_8f70a2c91e_b.jpg',
43
- type: 'Not a planet',
44
- categories: [ 'NASA' ],
45
- satellites: 0,
46
- date: '2025-01-03T00:00:00Z',
47
- },
48
- {
49
- id: 4,
50
- title: 'Neptune',
51
- description: 'Neptune description',
52
- image: 'https://live.staticflickr.com/5725/21726228300_51333bd62c_b.jpg',
53
- type: 'Ice giant',
54
- categories: [ 'Space', 'Planet', 'Solar system' ],
55
- satellites: 14,
56
- date: '2020-01-01T00:00:00Z',
57
- },
58
- {
59
- id: 5,
60
- title: 'Mercury',
61
- description: 'Mercury description',
62
- image: 'https://live.staticflickr.com/5725/21726228300_51333bd62c_b.jpg',
63
- type: 'Terrestrial',
64
- categories: [ 'Space', 'Planet', 'Solar system' ],
65
- satellites: 0,
66
- date: '2020-01-02T01:00:00Z',
67
- },
68
- {
69
- id: 6,
70
- title: 'Venus',
71
- description: 'La planète Vénus',
72
- image: 'https://live.staticflickr.com/5725/21726228300_51333bd62c_b.jpg',
73
- type: 'Terrestrial',
74
- categories: [ 'Space', 'Planet', 'Solar system' ],
75
- satellites: 0,
76
- date: '2020-01-02T00:00:00Z',
77
- },
78
- {
79
- id: 7,
80
- title: 'Earth',
81
- description: 'Earth description',
82
- image: 'https://live.staticflickr.com/5725/21726228300_51333bd62c_b.jpg',
83
- type: 'Terrestrial',
84
- categories: [ 'Space', 'Planet', 'Solar system' ],
85
- satellites: 1,
86
- date: '2023-01-03T00:00:00Z',
87
- },
88
- {
89
- id: 8,
90
- title: 'Mars',
91
- description: 'Mars description',
92
- image: 'https://live.staticflickr.com/5725/21726228300_51333bd62c_b.jpg',
93
- type: 'Terrestrial',
94
- categories: [ 'Space', 'Planet', 'Solar system' ],
95
- satellites: 2,
96
- date: '2020-01-01T00:00:00Z',
97
- },
98
- {
99
- id: 9,
100
- title: 'Jupiter',
101
- description: 'Jupiter description',
102
- image: 'https://live.staticflickr.com/5725/21726228300_51333bd62c_b.jpg',
103
- type: 'Gas giant',
104
- categories: [ 'Space', 'Planet', 'Solar system' ],
105
- satellites: 95,
106
- date: '2017-01-01T00:01:00Z',
107
- },
108
- {
109
- id: 10,
110
- title: 'Saturn',
111
- description: 'Saturn description',
112
- image: 'https://live.staticflickr.com/5725/21726228300_51333bd62c_b.jpg',
113
- type: 'Gas giant',
114
- categories: [ 'Space', 'Planet', 'Solar system' ],
115
- satellites: 146,
116
- date: '2020-02-01T00:02:00Z',
117
- },
118
- {
119
- id: 11,
120
- title: 'Uranus',
121
- description: 'Uranus description',
122
- image: 'https://live.staticflickr.com/5725/21726228300_51333bd62c_b.jpg',
123
- type: 'Ice giant',
124
- categories: [ 'Space', 'Ice giant', 'Solar system' ],
125
- satellites: 28,
126
- date: '2020-03-01T00:00:00Z',
127
- },
128
- ];
129
-
130
- export const DEFAULT_VIEW = {
131
- type: LAYOUT_TABLE,
132
- search: '',
133
- page: 1,
134
- perPage: 10,
135
- fields: [ 'title', 'description', 'categories' ],
136
- layout: {},
137
- filters: [],
138
- };
139
-
140
- export const actions = [
141
- {
142
- id: 'delete',
143
- label: 'Delete item',
144
- isPrimary: true,
145
- icon: trash,
146
- hideModalHeader: true,
147
- RenderModal: ( { item, closeModal } ) => {
148
- return (
149
- <VStack spacing="5">
150
- <Text>
151
- { `Are you sure you want to delete "${ item.title }"?` }
152
- </Text>
153
- <HStack justify="right">
154
- <Button variant="tertiary" onClick={ closeModal }>
155
- Cancel
156
- </Button>
157
- <Button variant="primary" onClick={ closeModal }>
158
- Delete
159
- </Button>
160
- </HStack>
161
- </VStack>
162
- );
163
- },
164
- },
165
- {
166
- id: 'secondary',
167
- label: 'Secondary action',
168
- callback() {},
169
- },
170
- ];
171
-
172
- export const fields = [
173
- {
174
- label: 'Image',
175
- id: 'image',
176
- header: (
177
- <HStack spacing={ 1 } justify="start">
178
- <Icon icon={ image } />
179
- <span>Image</span>
180
- </HStack>
181
- ),
182
- render: ( { item } ) => {
183
- return (
184
- <img src={ item.image } alt="" style={ { width: '100%' } } />
185
- );
186
- },
187
- enableSorting: false,
188
- },
189
- {
190
- label: 'Title',
191
- id: 'title',
192
- enableHiding: false,
193
- enableGlobalSearch: true,
194
- },
195
- {
196
- id: 'date',
197
- label: 'Date',
198
- type: 'datetime',
199
- },
200
- {
201
- label: 'Type',
202
- id: 'type',
203
- enableHiding: false,
204
- elements: [
205
- { value: 'Not a planet', label: 'Not a planet' },
206
- { value: 'Ice giant', label: 'Ice giant' },
207
- { value: 'Terrestrial', label: 'Terrestrial' },
208
- { value: 'Gas giant', label: 'Gas giant' },
209
- ],
210
- },
211
- {
212
- label: 'Satellites',
213
- id: 'satellites',
214
- type: 'integer',
215
- enableSorting: true,
216
- },
217
- {
218
- label: 'Description',
219
- id: 'description',
220
- enableSorting: false,
221
- enableGlobalSearch: true,
222
- },
223
- {
224
- label: 'Categories',
225
- id: 'categories',
226
- header: (
227
- <HStack spacing={ 1 } justify="start">
228
- <Icon icon={ category } />
229
- <span>Categories</span>
230
- </HStack>
231
- ),
232
- elements: [
233
- { value: 'Space', label: 'Space' },
234
- { value: 'NASA', label: 'NASA' },
235
- { value: 'Planet', label: 'Planet' },
236
- { value: 'Solar system', label: 'Solar system' },
237
- { value: 'Ice giant', label: 'Ice giant' },
238
- ],
239
- filterBy: {
240
- operators: [ 'isAny', 'isNone', 'isAll', 'isNotAll' ],
241
- },
242
- getValue: ( { item } ) => {
243
- return item.categories;
244
- },
245
- render: ( { item } ) => {
246
- return item.categories.join( ',' );
247
- },
248
- enableSorting: false,
249
- },
250
- ];
@@ -1,71 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useState, useMemo } from '@wordpress/element';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- import DataViews from '../index';
10
- import { DEFAULT_VIEW, actions, data, fields } from './fixtures';
11
- import { LAYOUT_GRID, LAYOUT_LIST, LAYOUT_TABLE } from '../../../constants';
12
- import { filterSortAndPaginate } from '../../../filter-and-sort-data-view';
13
-
14
- const meta = {
15
- title: 'DataViews/DataViews',
16
- component: DataViews,
17
- };
18
- export default meta;
19
-
20
- export const Default = ( props ) => {
21
- const [ view, setView ] = useState( DEFAULT_VIEW );
22
- const { data: shownData, paginationInfo } = useMemo( () => {
23
- return filterSortAndPaginate( data, view, fields );
24
- }, [ view ] );
25
- return (
26
- <DataViews
27
- { ...props }
28
- paginationInfo={ paginationInfo }
29
- data={ shownData }
30
- view={ view }
31
- fields={ fields }
32
- onChangeView={ setView }
33
- />
34
- );
35
- };
36
- Default.args = {
37
- actions,
38
- defaultLayouts: {
39
- [ LAYOUT_TABLE ]: {
40
- layout: {
41
- primaryField: 'title',
42
- styles: {
43
- image: {
44
- width: 50,
45
- },
46
- title: {
47
- maxWidth: 400,
48
- },
49
- type: {
50
- maxWidth: 400,
51
- },
52
- description: {
53
- maxWidth: 200,
54
- },
55
- },
56
- },
57
- },
58
- [ LAYOUT_GRID ]: {
59
- layout: {
60
- mediaField: 'image',
61
- primaryField: 'title',
62
- },
63
- },
64
- [ LAYOUT_LIST ]: {
65
- layout: {
66
- mediaField: 'image',
67
- primaryField: 'title',
68
- },
69
- },
70
- },
71
- };
@@ -1,288 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import {
5
- ToolbarButton,
6
- Toolbar,
7
- ToolbarGroup,
8
- __unstableMotion as motion,
9
- __unstableAnimatePresence as AnimatePresence,
10
- } from '@wordpress/components';
11
- import { useMemo, useState, useRef, useContext } from '@wordpress/element';
12
- import { _n, sprintf, __ } from '@wordpress/i18n';
13
- import { closeSmall } from '@wordpress/icons';
14
- import { useReducedMotion } from '@wordpress/compose';
15
- import { useRegistry } from '@wordpress/data';
16
-
17
- /**
18
- * Internal dependencies
19
- */
20
- import { useSomeItemHasAPossibleBulkAction } from '../dataviews-bulk-actions';
21
- import DataViewsContext from '../dataviews-context';
22
- import { ActionWithModal } from '../dataviews-item-actions';
23
- import { LAYOUT_GRID, LAYOUT_TABLE } from '../../constants';
24
- import type { Action } from '../../types';
25
- import type { ActionTriggerProps } from '../dataviews-item-actions';
26
- import type { SetSelection } from '../../private-types';
27
-
28
- interface ActionButtonProps< Item > {
29
- action: Action< Item >;
30
- selectedItems: Item[];
31
- actionInProgress: string | null;
32
- setActionInProgress: ( actionId: string | null ) => void;
33
- }
34
-
35
- interface ToolbarContentProps< Item > {
36
- selection: string[];
37
- actionsToShow: Action< Item >[];
38
- selectedItems: Item[];
39
- onChangeSelection: SetSelection;
40
- }
41
-
42
- const SNACKBAR_VARIANTS = {
43
- init: {
44
- bottom: -48,
45
- },
46
- open: {
47
- bottom: 24,
48
- transition: {
49
- bottom: { type: 'tween', duration: 0.2, ease: [ 0, 0, 0.2, 1 ] },
50
- },
51
- },
52
- exit: {
53
- opacity: 0,
54
- bottom: 24,
55
- transition: {
56
- opacity: { type: 'tween', duration: 0.2, ease: [ 0, 0, 0.2, 1 ] },
57
- },
58
- },
59
- };
60
-
61
- function ActionTrigger< Item >( {
62
- action,
63
- onClick,
64
- isBusy,
65
- items,
66
- }: ActionTriggerProps< Item > ) {
67
- const label =
68
- typeof action.label === 'string' ? action.label : action.label( items );
69
- return (
70
- <ToolbarButton
71
- disabled={ isBusy }
72
- label={ label }
73
- icon={ action.icon }
74
- isDestructive={ action.isDestructive }
75
- size="compact"
76
- onClick={ onClick }
77
- isBusy={ isBusy }
78
- tooltipPosition="top"
79
- />
80
- );
81
- }
82
-
83
- const EMPTY_ARRAY: [] = [];
84
-
85
- function ActionButton< Item >( {
86
- action,
87
- selectedItems,
88
- actionInProgress,
89
- setActionInProgress,
90
- }: ActionButtonProps< Item > ) {
91
- const registry = useRegistry();
92
- const selectedEligibleItems = useMemo( () => {
93
- return selectedItems.filter( ( item ) => {
94
- return ! action.isEligible || action.isEligible( item );
95
- } );
96
- }, [ action, selectedItems ] );
97
- if ( 'RenderModal' in action ) {
98
- return (
99
- <ActionWithModal
100
- key={ action.id }
101
- action={ action }
102
- items={ selectedEligibleItems }
103
- ActionTrigger={ ActionTrigger }
104
- />
105
- );
106
- }
107
- return (
108
- <ActionTrigger
109
- key={ action.id }
110
- action={ action }
111
- onClick={ () => {
112
- setActionInProgress( action.id );
113
- action.callback( selectedItems, {
114
- registry,
115
- } );
116
- } }
117
- items={ selectedEligibleItems }
118
- isBusy={ actionInProgress === action.id }
119
- />
120
- );
121
- }
122
-
123
- function renderToolbarContent< Item >(
124
- selection: string[],
125
- actionsToShow: Action< Item >[],
126
- selectedItems: Item[],
127
- actionInProgress: string | null,
128
- setActionInProgress: ( actionId: string | null ) => void,
129
- onChangeSelection: SetSelection
130
- ) {
131
- return (
132
- <>
133
- <ToolbarGroup>
134
- <div className="dataviews-bulk-actions-toolbar__selection-count">
135
- { selection.length === 1
136
- ? __( '1 item selected' )
137
- : sprintf(
138
- // translators: %s: Total number of selected items.
139
- _n(
140
- '%s item selected',
141
- '%s items selected',
142
- selection.length
143
- ),
144
- selection.length
145
- ) }
146
- </div>
147
- </ToolbarGroup>
148
- <ToolbarGroup>
149
- { actionsToShow.map( ( action ) => {
150
- return (
151
- <ActionButton
152
- key={ action.id }
153
- action={ action }
154
- selectedItems={ selectedItems }
155
- actionInProgress={ actionInProgress }
156
- setActionInProgress={ setActionInProgress }
157
- />
158
- );
159
- } ) }
160
- </ToolbarGroup>
161
- <ToolbarGroup>
162
- <ToolbarButton
163
- icon={ closeSmall }
164
- showTooltip
165
- tooltipPosition="top"
166
- label={ __( 'Cancel' ) }
167
- disabled={ !! actionInProgress }
168
- onClick={ () => {
169
- onChangeSelection( EMPTY_ARRAY );
170
- } }
171
- />
172
- </ToolbarGroup>
173
- </>
174
- );
175
- }
176
-
177
- function ToolbarContent< Item >( {
178
- selection,
179
- actionsToShow,
180
- selectedItems,
181
- onChangeSelection,
182
- }: ToolbarContentProps< Item > ) {
183
- const [ actionInProgress, setActionInProgress ] = useState< string | null >(
184
- null
185
- );
186
- const buttons = useRef< JSX.Element | null >( null );
187
- if ( ! actionInProgress ) {
188
- if ( buttons.current ) {
189
- buttons.current = null;
190
- }
191
- return renderToolbarContent(
192
- selection,
193
- actionsToShow,
194
- selectedItems,
195
- actionInProgress,
196
- setActionInProgress,
197
- onChangeSelection
198
- );
199
- } else if ( ! buttons.current ) {
200
- buttons.current = renderToolbarContent(
201
- selection,
202
- actionsToShow,
203
- selectedItems,
204
- actionInProgress,
205
- setActionInProgress,
206
- onChangeSelection
207
- );
208
- }
209
- return buttons.current;
210
- }
211
-
212
- function _BulkActionsToolbar() {
213
- const {
214
- data,
215
- selection,
216
- actions = EMPTY_ARRAY,
217
- onChangeSelection,
218
- getItemId,
219
- } = useContext( DataViewsContext );
220
- const isReducedMotion = useReducedMotion();
221
- const selectedItems = useMemo( () => {
222
- return data.filter( ( item ) =>
223
- selection.includes( getItemId( item ) )
224
- );
225
- }, [ selection, data, getItemId ] );
226
-
227
- const actionsToShow = useMemo(
228
- () =>
229
- actions.filter( ( action ) => {
230
- return (
231
- action.supportsBulk &&
232
- action.icon &&
233
- selectedItems.some(
234
- ( item ) =>
235
- ! action.isEligible || action.isEligible( item )
236
- )
237
- );
238
- } ),
239
- [ actions, selectedItems ]
240
- );
241
-
242
- if (
243
- ( selection && selection.length === 0 ) ||
244
- actionsToShow.length === 0
245
- ) {
246
- return null;
247
- }
248
-
249
- return (
250
- <AnimatePresence>
251
- <motion.div
252
- layout={ ! isReducedMotion } // See https://www.framer.com/docs/animation/#layout-animations
253
- initial="init"
254
- animate="open"
255
- exit="exit"
256
- variants={ isReducedMotion ? undefined : SNACKBAR_VARIANTS }
257
- className="dataviews-bulk-actions-toolbar"
258
- >
259
- <Toolbar label={ __( 'Bulk actions' ) }>
260
- <div className="dataviews-bulk-actions-toolbar__wrapper">
261
- <ToolbarContent
262
- selection={ selection }
263
- actionsToShow={ actionsToShow }
264
- selectedItems={ selectedItems }
265
- onChangeSelection={ onChangeSelection }
266
- />
267
- </div>
268
- </Toolbar>
269
- </motion.div>
270
- </AnimatePresence>
271
- );
272
- }
273
-
274
- export default function BulkActionsToolbar() {
275
- const { data, actions = [], view } = useContext( DataViewsContext );
276
- const hasPossibleBulkAction = useSomeItemHasAPossibleBulkAction(
277
- actions,
278
- data
279
- );
280
- if (
281
- ! [ LAYOUT_TABLE, LAYOUT_GRID ].includes( view.type ) ||
282
- ! hasPossibleBulkAction
283
- ) {
284
- return null;
285
- }
286
-
287
- return <_BulkActionsToolbar />;
288
- }
@@ -1,45 +0,0 @@
1
- .dataviews-bulk-actions-toolbar {
2
- position: sticky;
3
- display: flex;
4
- flex-direction: column;
5
- align-content: center;
6
- flex-wrap: wrap;
7
- width: fit-content;
8
- margin-left: auto;
9
- margin-right: auto;
10
- bottom: $grid-unit-30;
11
- z-index: z-index(".dataviews-bulk-actions-toolbar");
12
-
13
- .components-accessible-toolbar {
14
- border-color: $gray-300;
15
- box-shadow: $elevation-x-small;
16
-
17
- .components-toolbar-group {
18
- border-color: $gray-200;
19
-
20
- &:last-child {
21
- border: 0;
22
- }
23
- }
24
- }
25
-
26
- .dataviews-bulk-actions-toolbar__selection-count {
27
- display: flex;
28
- align-items: center;
29
- margin: 0 $grid-unit-10 0 $grid-unit-10;
30
- }
31
- }
32
-
33
- .dataviews-bulk-actions-toolbar__wrapper {
34
- display: flex;
35
- flex-grow: 1;
36
- width: 100%;
37
-
38
- .components-toolbar-group {
39
- align-items: center;
40
- }
41
-
42
- .components-button.is-busy {
43
- max-height: $button-size;
44
- }
45
- }