@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
@@ -0,0 +1,164 @@
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 {
11
+ DEFAULT_VIEW,
12
+ actions,
13
+ data,
14
+ fields,
15
+ themeData,
16
+ themeFields,
17
+ } from './fixtures';
18
+ import { LAYOUT_GRID, LAYOUT_LIST, LAYOUT_TABLE } from '../../../constants';
19
+ import { filterSortAndPaginate } from '../../../filter-and-sort-data-view';
20
+ import type { View } from '../../../types';
21
+
22
+ const meta = {
23
+ title: 'DataViews/DataViews',
24
+ component: DataViews,
25
+ };
26
+ export default meta;
27
+
28
+ const defaultLayouts = {
29
+ [ LAYOUT_TABLE ]: {
30
+ layout: {
31
+ primaryField: 'title',
32
+ styles: {
33
+ image: {
34
+ width: 50,
35
+ },
36
+ title: {
37
+ maxWidth: 400,
38
+ },
39
+ type: {
40
+ maxWidth: 400,
41
+ },
42
+ description: {
43
+ maxWidth: 200,
44
+ },
45
+ },
46
+ },
47
+ },
48
+ [ LAYOUT_GRID ]: {
49
+ layout: {
50
+ mediaField: 'image',
51
+ primaryField: 'title',
52
+ },
53
+ },
54
+ [ LAYOUT_LIST ]: {
55
+ layout: {
56
+ mediaField: 'image',
57
+ primaryField: 'title',
58
+ },
59
+ },
60
+ };
61
+
62
+ export const Default = () => {
63
+ const [ view, setView ] = useState< View >( {
64
+ ...DEFAULT_VIEW,
65
+ fields: [ 'title', 'description', 'categories' ],
66
+ } );
67
+ const { data: shownData, paginationInfo } = useMemo( () => {
68
+ return filterSortAndPaginate( data, view, fields );
69
+ }, [ view ] );
70
+ return (
71
+ <DataViews
72
+ getItemId={ ( item ) => item.id.toString() }
73
+ paginationInfo={ paginationInfo }
74
+ data={ shownData }
75
+ view={ view }
76
+ fields={ fields }
77
+ onChangeView={ setView }
78
+ actions={ actions }
79
+ defaultLayouts={ defaultLayouts }
80
+ />
81
+ );
82
+ };
83
+
84
+ export const Empty = () => {
85
+ const [ view, setView ] = useState< View >( {
86
+ ...DEFAULT_VIEW,
87
+ fields: [ 'title', 'description', 'categories' ],
88
+ } );
89
+
90
+ return (
91
+ <DataViews
92
+ getItemId={ ( item ) => item.id.toString() }
93
+ paginationInfo={ { totalItems: 0, totalPages: 0 } }
94
+ data={ [] }
95
+ view={ view }
96
+ fields={ fields }
97
+ onChangeView={ setView }
98
+ actions={ actions }
99
+ defaultLayouts={ defaultLayouts }
100
+ />
101
+ );
102
+ };
103
+
104
+ export const FieldsNoSortableNoHidable = () => {
105
+ const [ view, setView ] = useState< View >( {
106
+ ...DEFAULT_VIEW,
107
+ fields: [ 'title', 'description', 'categories' ],
108
+ } );
109
+ const { data: shownData, paginationInfo } = useMemo( () => {
110
+ return filterSortAndPaginate( data, view, fields );
111
+ }, [ view ] );
112
+
113
+ const _fields = fields.map( ( field ) => ( {
114
+ ...field,
115
+ enableSorting: false,
116
+ enableHiding: false,
117
+ } ) );
118
+
119
+ return (
120
+ <DataViews
121
+ getItemId={ ( item ) => item.id.toString() }
122
+ paginationInfo={ paginationInfo }
123
+ data={ shownData }
124
+ view={ view }
125
+ fields={ _fields }
126
+ onChangeView={ setView }
127
+ defaultLayouts={ {
128
+ table: {},
129
+ } }
130
+ />
131
+ );
132
+ };
133
+
134
+ export const CombinedFields = () => {
135
+ const [ view, setView ] = useState< View >( {
136
+ ...DEFAULT_VIEW,
137
+ fields: [ 'theme', 'requires', 'tested' ],
138
+ layout: {
139
+ combinedFields: [
140
+ {
141
+ id: 'theme',
142
+ label: 'Theme',
143
+ children: [ 'name', 'description' ],
144
+ direction: 'vertical',
145
+ },
146
+ ],
147
+ },
148
+ } );
149
+ const { data: shownData, paginationInfo } = useMemo( () => {
150
+ return filterSortAndPaginate( themeData, view, themeFields );
151
+ }, [ view ] );
152
+
153
+ return (
154
+ <DataViews
155
+ getItemId={ ( item ) => item.name }
156
+ paginationInfo={ paginationInfo }
157
+ data={ shownData }
158
+ view={ view }
159
+ fields={ themeFields }
160
+ onChangeView={ setView }
161
+ defaultLayouts={ { table: {} } }
162
+ />
163
+ );
164
+ };
@@ -7,6 +7,8 @@
7
7
  container: dataviews-wrapper / inline-size;
8
8
  display: flex;
9
9
  flex-direction: column;
10
+ font-size: $default-font-size;
11
+ line-height: $default-line-height;
10
12
  }
11
13
 
12
14
  .dataviews__view-actions,