@wordpress/dataviews 7.0.1-next.f34ab90e9.0 → 8.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.
Files changed (60) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +5 -5
  3. package/build/components/dataform-context/index.js +1 -0
  4. package/build/components/dataform-context/index.js.map +1 -1
  5. package/build/components/dataviews/index.js +4 -4
  6. package/build/components/dataviews/index.js.map +1 -1
  7. package/build/components/dataviews-context/index.js +1 -0
  8. package/build/components/dataviews-context/index.js.map +1 -1
  9. package/build/dataforms-layouts/card/index.js +6 -3
  10. package/build/dataforms-layouts/card/index.js.map +1 -1
  11. package/build/dataviews-layouts/grid/index.js +11 -3
  12. package/build/dataviews-layouts/grid/index.js.map +1 -1
  13. package/build/types.js.map +1 -1
  14. package/build-module/components/dataform-context/index.js +1 -0
  15. package/build-module/components/dataform-context/index.js.map +1 -1
  16. package/build-module/components/dataviews/index.js +4 -4
  17. package/build-module/components/dataviews/index.js.map +1 -1
  18. package/build-module/components/dataviews-context/index.js +1 -0
  19. package/build-module/components/dataviews-context/index.js.map +1 -1
  20. package/build-module/dataforms-layouts/card/index.js +6 -3
  21. package/build-module/dataforms-layouts/card/index.js.map +1 -1
  22. package/build-module/dataviews-layouts/grid/index.js +11 -3
  23. package/build-module/dataviews-layouts/grid/index.js.map +1 -1
  24. package/build-module/types.js.map +1 -1
  25. package/build-style/style-rtl.css +56 -3
  26. package/build-style/style.css +56 -3
  27. package/build-types/components/dataform/stories/index.story.d.ts.map +1 -1
  28. package/build-types/components/dataform-context/index.d.ts.map +1 -1
  29. package/build-types/components/dataviews/index.d.ts +3 -1
  30. package/build-types/components/dataviews/index.d.ts.map +1 -1
  31. package/build-types/components/dataviews/stories/index.story.d.ts +12 -1
  32. package/build-types/components/dataviews/stories/index.story.d.ts.map +1 -1
  33. package/build-types/components/dataviews-context/index.d.ts +1 -1
  34. package/build-types/components/dataviews-context/index.d.ts.map +1 -1
  35. package/build-types/dataforms-layouts/card/index.d.ts.map +1 -1
  36. package/build-types/dataviews-layouts/grid/index.d.ts.map +1 -1
  37. package/build-types/field-types/stories/index.story.d.ts +69 -0
  38. package/build-types/field-types/stories/index.story.d.ts.map +1 -0
  39. package/build-types/types.d.ts +1 -0
  40. package/build-types/types.d.ts.map +1 -1
  41. package/build-wp/index.js +58 -30
  42. package/package.json +15 -15
  43. package/src/components/dataform/stories/index.story.tsx +2 -0
  44. package/src/components/dataform-context/index.tsx +1 -0
  45. package/src/components/dataviews/index.tsx +14 -16
  46. package/src/components/dataviews/stories/fixtures.tsx +1 -1
  47. package/src/components/dataviews/stories/index.story.tsx +41 -7
  48. package/src/components/dataviews-context/index.ts +3 -1
  49. package/src/dataforms-layouts/card/index.tsx +5 -0
  50. package/src/dataforms-layouts/card/style.scss +7 -0
  51. package/src/dataviews-layouts/grid/index.tsx +31 -19
  52. package/src/dataviews-layouts/grid/style.scss +43 -3
  53. package/src/field-types/stories/index.story.tsx +581 -0
  54. package/src/style.scss +1 -0
  55. package/src/test/dataviews.tsx +86 -0
  56. package/src/types.ts +1 -0
  57. package/tsconfig.tsbuildinfo +1 -1
  58. package/build-types/components/stories/index.story.d.ts +0 -63
  59. package/build-types/components/stories/index.story.d.ts.map +0 -1
  60. package/src/components/stories/index.story.tsx +0 -372
@@ -1,63 +0,0 @@
1
- import DataForm from '../dataform/index';
2
- declare const meta: {
3
- readonly title: "DataViews/FieldTypes";
4
- readonly component: typeof DataForm;
5
- readonly argTypes: {
6
- readonly type: {
7
- readonly control: {
8
- readonly type: "select";
9
- };
10
- readonly description: "Chooses the default layout of each field. \"regular\" is the default layout.";
11
- readonly options: readonly ["default", "regular", "panel"];
12
- };
13
- readonly labelPosition: {
14
- readonly control: {
15
- readonly type: "select";
16
- };
17
- readonly description: "Chooses the label position of the layout.";
18
- readonly options: readonly ["default", "top", "side", "none"];
19
- };
20
- };
21
- };
22
- export default meta;
23
- export declare const All: ({ type, labelPosition, }: {
24
- type: "default" | "regular" | "panel";
25
- labelPosition: "default" | "top" | "side" | "none";
26
- }) => import("react").JSX.Element;
27
- export declare const Text: ({ type, labelPosition, }: {
28
- type: "default" | "regular" | "panel";
29
- labelPosition: "default" | "top" | "side" | "none";
30
- }) => import("react").JSX.Element;
31
- export declare const Integer: ({ type, labelPosition, }: {
32
- type: "default" | "regular" | "panel";
33
- labelPosition: "default" | "top" | "side" | "none";
34
- }) => import("react").JSX.Element;
35
- export declare const Boolean: ({ type, labelPosition, }: {
36
- type: "default" | "regular" | "panel";
37
- labelPosition: "default" | "top" | "side" | "none";
38
- }) => import("react").JSX.Element;
39
- export declare const DateTime: ({ type, labelPosition, }: {
40
- type: "default" | "regular" | "panel";
41
- labelPosition: "default" | "top" | "side" | "none";
42
- }) => import("react").JSX.Element;
43
- export declare const Date: ({ type, labelPosition, }: {
44
- type: "default" | "regular" | "panel";
45
- labelPosition: "default" | "top" | "side" | "none";
46
- }) => import("react").JSX.Element;
47
- export declare const Email: ({ type, labelPosition, }: {
48
- type: "default" | "regular" | "panel";
49
- labelPosition: "default" | "top" | "side" | "none";
50
- }) => import("react").JSX.Element;
51
- export declare const Media: ({ type, labelPosition, }: {
52
- type: "default" | "regular" | "panel";
53
- labelPosition: "default" | "top" | "side" | "none";
54
- }) => import("react").JSX.Element;
55
- export declare const Array: ({ type, labelPosition, }: {
56
- type: "default" | "regular" | "panel";
57
- labelPosition: "default" | "top" | "side" | "none";
58
- }) => import("react").JSX.Element;
59
- export declare const NoType: ({ type, labelPosition, }: {
60
- type: "default" | "regular" | "panel";
61
- labelPosition: "default" | "top" | "side" | "none";
62
- }) => import("react").JSX.Element;
63
- //# sourceMappingURL=index.story.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.story.d.ts","sourceRoot":"","sources":["../../../src/components/stories/index.story.tsx"],"names":[],"mappings":"AAaA,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AAUzC,QAAA,MAAM,IAAI;;;;;;;;;;;;;;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AAC;AAEF,eAAO,MAAM,KAAK,6BAGf;IACF,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;IACtC,aAAa,EAAE,SAAS,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;CACnD,gCAaA,CAAC;AAEF,eAAO,MAAM,KAAK,6BAGf;IACF,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;IACtC,aAAa,EAAE,SAAS,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;CACnD,gCAaA,CAAC;AAEF,eAAO,MAAM,MAAM,6BAGhB;IACF,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;IACtC,aAAa,EAAE,SAAS,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;CACnD,gCAaA,CAAC"}
@@ -1,372 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useState, useMemo } from '@wordpress/element';
5
- import {
6
- __experimentalHStack as HStack,
7
- __experimentalVStack as VStack,
8
- } from '@wordpress/components';
9
-
10
- /**
11
- * Internal dependencies
12
- */
13
- import DataViews from '../dataviews/index';
14
- import DataForm from '../dataform/index';
15
- import {
16
- actions,
17
- data,
18
- fields,
19
- type SpaceObject,
20
- } from '../dataviews/stories/fixtures';
21
- import { filterSortAndPaginate } from '../../filter-and-sort-data-view';
22
- import type { View, Form, Field } from '../../types';
23
-
24
- const meta = {
25
- title: 'DataViews/FieldTypes',
26
- component: DataForm,
27
- argTypes: {
28
- type: {
29
- control: { type: 'select' },
30
- description:
31
- 'Chooses the default layout of each field. "regular" is the default layout.',
32
- options: [ 'default', 'regular', 'panel' ],
33
- },
34
- labelPosition: {
35
- control: { type: 'select' },
36
- description: 'Chooses the label position of the layout.',
37
- options: [ 'default', 'top', 'side', 'none' ],
38
- },
39
- },
40
- } as const;
41
- export default meta;
42
-
43
- const defaultLayouts = {
44
- table: {},
45
- grid: {},
46
- list: {},
47
- };
48
-
49
- interface FieldTypeStoryProps {
50
- fields: Field< SpaceObject >[];
51
- titleField?: string;
52
- descriptionField?: string;
53
- mediaField?: string;
54
- type?: 'default' | 'regular' | 'panel';
55
- labelPosition?: 'default' | 'top' | 'side' | 'none';
56
- }
57
-
58
- const FieldTypeStory = ( {
59
- fields: storyFields,
60
- titleField,
61
- descriptionField,
62
- mediaField,
63
- type = 'default',
64
- labelPosition = 'default',
65
- }: FieldTypeStoryProps ) => {
66
- const form = useMemo(
67
- () => ( {
68
- type,
69
- labelPosition,
70
- fields: storyFields.map( ( field ) => field.id ),
71
- } ),
72
- [ type, labelPosition, storyFields ]
73
- ) as Form;
74
-
75
- const [ view, setView ] = useState< View >( {
76
- type: 'table' as const,
77
- search: '',
78
- page: 1,
79
- perPage: 10,
80
- layout: {},
81
- filters: [],
82
- titleField,
83
- descriptionField,
84
- mediaField,
85
- fields: storyFields
86
- .filter(
87
- ( field ) =>
88
- ! [ titleField, descriptionField, mediaField ].includes(
89
- field.id
90
- )
91
- )
92
- .map( ( field ) => field.id ),
93
- } );
94
-
95
- const [ selectedIds, setSelectedIds ] = useState< number[] >( [] );
96
- const [ modifiedData, setModifiedData ] = useState< SpaceObject[] >( data );
97
-
98
- const { data: shownData, paginationInfo } = useMemo( () => {
99
- return filterSortAndPaginate( modifiedData, view, storyFields );
100
- }, [ modifiedData, view, storyFields ] );
101
-
102
- const selectedItem =
103
- ( selectedIds.length === 1 &&
104
- shownData.find( ( item ) => item.id === selectedIds[ 0 ] ) ) ||
105
- null;
106
-
107
- return (
108
- <HStack alignment="stretch">
109
- <div style={ { flex: 2 } }>
110
- <DataViews
111
- getItemId={ ( item ) => item.id.toString() }
112
- data={ shownData }
113
- paginationInfo={ paginationInfo }
114
- view={ view }
115
- fields={ storyFields }
116
- onChangeView={ setView }
117
- actions={ actions }
118
- defaultLayouts={ defaultLayouts }
119
- selection={ selectedIds.map( ( id ) => id.toString() ) }
120
- onChangeSelection={ ( newSelection ) =>
121
- setSelectedIds(
122
- newSelection.map( ( id ) => parseInt( id, 10 ) )
123
- )
124
- }
125
- // eslint-disable-next-line no-alert
126
- onClickItem={ ( item ) => alert( 'clicked ' + item.title ) }
127
- />
128
- </div>
129
- { selectedItem ? (
130
- <VStack alignment="top">
131
- <DataForm
132
- data={ selectedItem }
133
- form={ form }
134
- fields={ storyFields }
135
- onChange={ ( updatedValues ) => {
136
- const updatedItem = {
137
- ...selectedItem,
138
- ...updatedValues,
139
- };
140
-
141
- setModifiedData(
142
- modifiedData.map( ( item ) =>
143
- item.id === selectedItem.id
144
- ? updatedItem
145
- : item
146
- )
147
- );
148
- } }
149
- />
150
- </VStack>
151
- ) : (
152
- <VStack alignment="center">
153
- <span
154
- style={ {
155
- color: '#888',
156
- } }
157
- >
158
- Please, select a single item.
159
- </span>
160
- </VStack>
161
- ) }
162
- </HStack>
163
- );
164
- };
165
-
166
- export const All = ( {
167
- type,
168
- labelPosition,
169
- }: {
170
- type: 'default' | 'regular' | 'panel';
171
- labelPosition: 'default' | 'top' | 'side' | 'none';
172
- } ) => {
173
- return (
174
- <FieldTypeStory
175
- fields={ fields }
176
- titleField="title"
177
- descriptionField="description"
178
- mediaField="image"
179
- type={ type }
180
- labelPosition={ labelPosition }
181
- />
182
- );
183
- };
184
-
185
- export const Text = ( {
186
- type,
187
- labelPosition,
188
- }: {
189
- type: 'default' | 'regular' | 'panel';
190
- labelPosition: 'default' | 'top' | 'side' | 'none';
191
- } ) => {
192
- const textFields = useMemo(
193
- () => fields.filter( ( field ) => field.type === 'text' ),
194
- []
195
- );
196
-
197
- return (
198
- <FieldTypeStory
199
- fields={ textFields }
200
- type={ type }
201
- labelPosition={ labelPosition }
202
- />
203
- );
204
- };
205
-
206
- export const Integer = ( {
207
- type,
208
- labelPosition,
209
- }: {
210
- type: 'default' | 'regular' | 'panel';
211
- labelPosition: 'default' | 'top' | 'side' | 'none';
212
- } ) => {
213
- const integerFields = useMemo(
214
- () => fields.filter( ( field ) => field.type === 'integer' ),
215
- []
216
- );
217
-
218
- return (
219
- <FieldTypeStory
220
- fields={ integerFields }
221
- type={ type }
222
- labelPosition={ labelPosition }
223
- />
224
- );
225
- };
226
-
227
- export const Boolean = ( {
228
- type,
229
- labelPosition,
230
- }: {
231
- type: 'default' | 'regular' | 'panel';
232
- labelPosition: 'default' | 'top' | 'side' | 'none';
233
- } ) => {
234
- const booleanFields = useMemo(
235
- () => fields.filter( ( field ) => field.type === 'boolean' ),
236
- []
237
- );
238
-
239
- return (
240
- <FieldTypeStory
241
- fields={ booleanFields }
242
- type={ type }
243
- labelPosition={ labelPosition }
244
- />
245
- );
246
- };
247
-
248
- export const DateTime = ( {
249
- type,
250
- labelPosition,
251
- }: {
252
- type: 'default' | 'regular' | 'panel';
253
- labelPosition: 'default' | 'top' | 'side' | 'none';
254
- } ) => {
255
- const dateTimeFields = useMemo(
256
- () => fields.filter( ( field ) => field.type === 'datetime' ),
257
- []
258
- );
259
-
260
- return (
261
- <FieldTypeStory
262
- fields={ dateTimeFields }
263
- type={ type }
264
- labelPosition={ labelPosition }
265
- />
266
- );
267
- };
268
-
269
- export const Date = ( {
270
- type,
271
- labelPosition,
272
- }: {
273
- type: 'default' | 'regular' | 'panel';
274
- labelPosition: 'default' | 'top' | 'side' | 'none';
275
- } ) => {
276
- const dateFields = useMemo(
277
- () => fields.filter( ( field ) => field.type === 'date' ),
278
- []
279
- );
280
-
281
- return (
282
- <FieldTypeStory
283
- fields={ dateFields }
284
- type={ type }
285
- labelPosition={ labelPosition }
286
- />
287
- );
288
- };
289
-
290
- export const Email = ( {
291
- type,
292
- labelPosition,
293
- }: {
294
- type: 'default' | 'regular' | 'panel';
295
- labelPosition: 'default' | 'top' | 'side' | 'none';
296
- } ) => {
297
- const emailFields = useMemo(
298
- () => fields.filter( ( field ) => field.type === 'email' ),
299
- []
300
- );
301
-
302
- return (
303
- <FieldTypeStory
304
- fields={ emailFields }
305
- type={ type }
306
- labelPosition={ labelPosition }
307
- />
308
- );
309
- };
310
-
311
- export const Media = ( {
312
- type,
313
- labelPosition,
314
- }: {
315
- type: 'default' | 'regular' | 'panel';
316
- labelPosition: 'default' | 'top' | 'side' | 'none';
317
- } ) => {
318
- const mediaFields = useMemo(
319
- () => fields.filter( ( field ) => field.type === 'media' ),
320
- []
321
- );
322
-
323
- return (
324
- <FieldTypeStory
325
- fields={ mediaFields }
326
- type={ type }
327
- labelPosition={ labelPosition }
328
- />
329
- );
330
- };
331
-
332
- export const Array = ( {
333
- type,
334
- labelPosition,
335
- }: {
336
- type: 'default' | 'regular' | 'panel';
337
- labelPosition: 'default' | 'top' | 'side' | 'none';
338
- } ) => {
339
- const arrayTextFields = useMemo(
340
- () => fields.filter( ( field ) => field.type === 'array' ),
341
- []
342
- );
343
-
344
- return (
345
- <FieldTypeStory
346
- fields={ arrayTextFields }
347
- type={ type }
348
- labelPosition={ labelPosition }
349
- />
350
- );
351
- };
352
-
353
- export const NoType = ( {
354
- type,
355
- labelPosition,
356
- }: {
357
- type: 'default' | 'regular' | 'panel';
358
- labelPosition: 'default' | 'top' | 'side' | 'none';
359
- } ) => {
360
- const noTypeFields = useMemo(
361
- () => fields.filter( ( field ) => field.type === undefined ),
362
- []
363
- );
364
-
365
- return (
366
- <FieldTypeStory
367
- fields={ noTypeFields }
368
- type={ type }
369
- labelPosition={ labelPosition }
370
- />
371
- );
372
- };