@wordpress/components 28.7.0 → 28.8.1-next.1f6eadc42.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.
- package/CHANGELOG.md +32 -0
- package/build/box-control/utils.js +1 -1
- package/build/box-control/utils.js.map +1 -1
- package/build/composite/context.js +1 -1
- package/build/composite/context.js.map +1 -1
- package/build/composite/group-label.js +1 -1
- package/build/composite/group-label.js.map +1 -1
- package/build/composite/group.js +1 -1
- package/build/composite/group.js.map +1 -1
- package/build/composite/hover.js +1 -1
- package/build/composite/hover.js.map +1 -1
- package/build/composite/index.js +17 -26
- package/build/composite/index.js.map +1 -1
- package/build/composite/item.js +1 -1
- package/build/composite/item.js.map +1 -1
- package/build/composite/legacy/index.js +59 -8
- package/build/composite/legacy/index.js.map +1 -1
- package/build/composite/row.js +1 -1
- package/build/composite/row.js.map +1 -1
- package/build/composite/typeahead.js +1 -1
- package/build/composite/typeahead.js.map +1 -1
- package/build/composite/types.js.map +1 -1
- package/build/date-time/date/index.js +1 -1
- package/build/date-time/date/index.js.map +1 -1
- package/build/date-time/date/styles.js +35 -24
- package/build/date-time/date/styles.js.map +1 -1
- package/build/date-time/date/use-lilius/index.js +163 -0
- package/build/date-time/date/use-lilius/index.js.map +1 -0
- package/build/index.js +7 -0
- package/build/index.js.map +1 -1
- package/build/modal/index.js +11 -4
- package/build/modal/index.js.map +1 -1
- package/build/navigator/navigator-screen/component.js +5 -0
- package/build/navigator/navigator-screen/component.js.map +1 -1
- package/build/private-apis.js +0 -9
- package/build/private-apis.js.map +1 -1
- package/build/slot-fill/index.js +1 -0
- package/build/slot-fill/index.js.map +1 -1
- package/build/tabs/styles.js +3 -3
- package/build/tabs/styles.js.map +1 -1
- package/build/tabs/tablist.js +5 -4
- package/build/tabs/tablist.js.map +1 -1
- package/build/utils/element-rect.js +73 -105
- package/build/utils/element-rect.js.map +1 -1
- package/build-module/box-control/utils.js +1 -1
- package/build-module/box-control/utils.js.map +1 -1
- package/build-module/composite/context.js +1 -1
- package/build-module/composite/context.js.map +1 -1
- package/build-module/composite/group-label.js +1 -1
- package/build-module/composite/group-label.js.map +1 -1
- package/build-module/composite/group.js +1 -1
- package/build-module/composite/group.js.map +1 -1
- package/build-module/composite/hover.js +1 -1
- package/build-module/composite/hover.js.map +1 -1
- package/build-module/composite/index.js +17 -26
- package/build-module/composite/index.js.map +1 -1
- package/build-module/composite/item.js +1 -1
- package/build-module/composite/item.js.map +1 -1
- package/build-module/composite/legacy/index.js +56 -8
- package/build-module/composite/legacy/index.js.map +1 -1
- package/build-module/composite/row.js +1 -1
- package/build-module/composite/row.js.map +1 -1
- package/build-module/composite/typeahead.js +1 -1
- package/build-module/composite/typeahead.js.map +1 -1
- package/build-module/composite/types.js.map +1 -1
- package/build-module/date-time/date/index.js +1 -2
- package/build-module/date-time/date/index.js.map +1 -1
- package/build-module/date-time/date/styles.js +31 -24
- package/build-module/date-time/date/styles.js.map +1 -1
- package/build-module/date-time/date/use-lilius/index.js +158 -0
- package/build-module/date-time/date/use-lilius/index.js.map +1 -0
- package/build-module/index.js +1 -0
- package/build-module/index.js.map +1 -1
- package/build-module/modal/index.js +12 -4
- package/build-module/modal/index.js.map +1 -1
- package/build-module/navigator/navigator-screen/component.js +4 -0
- package/build-module/navigator/navigator-screen/component.js.map +1 -1
- package/build-module/private-apis.js +0 -9
- package/build-module/private-apis.js.map +1 -1
- package/build-module/slot-fill/index.js +1 -0
- package/build-module/slot-fill/index.js.map +1 -1
- package/build-module/tabs/styles.js +3 -3
- package/build-module/tabs/styles.js.map +1 -1
- package/build-module/tabs/tablist.js +5 -4
- package/build-module/tabs/tablist.js.map +1 -1
- package/build-module/utils/element-rect.js +74 -105
- package/build-module/utils/element-rect.js.map +1 -1
- package/build-style/style-rtl.css +1 -4
- package/build-style/style.css +1 -4
- package/build-types/box-control/utils.d.ts +1 -1
- package/build-types/box-control/utils.d.ts.map +1 -1
- package/build-types/composite/context.d.ts.map +1 -1
- package/build-types/composite/index.d.ts +36 -24
- package/build-types/composite/index.d.ts.map +1 -1
- package/build-types/composite/legacy/index.d.ts +25 -2
- package/build-types/composite/legacy/index.d.ts.map +1 -1
- package/build-types/composite/legacy/stories/index.story.d.ts.map +1 -1
- package/build-types/composite/stories/index.story.d.ts +9 -9
- package/build-types/composite/stories/index.story.d.ts.map +1 -1
- package/build-types/composite/types.d.ts +11 -10
- package/build-types/composite/types.d.ts.map +1 -1
- package/build-types/date-time/date/index.d.ts +0 -3
- package/build-types/date-time/date/index.d.ts.map +1 -1
- package/build-types/date-time/date/styles.d.ts.map +1 -1
- package/build-types/date-time/date/test/use-lilius.d.ts +2 -0
- package/build-types/date-time/date/test/use-lilius.d.ts.map +1 -0
- package/build-types/date-time/date/use-lilius/index.d.ts +169 -0
- package/build-types/date-time/date/use-lilius/index.d.ts.map +1 -0
- package/build-types/index.d.ts +1 -0
- package/build-types/index.d.ts.map +1 -1
- package/build-types/modal/index.d.ts.map +1 -1
- package/build-types/modal/stories/index.story.d.ts +3 -0
- package/build-types/modal/stories/index.story.d.ts.map +1 -1
- package/build-types/navigator/navigator-screen/component.d.ts.map +1 -1
- package/build-types/private-apis.d.ts.map +1 -1
- package/build-types/slot-fill/index.d.ts +3 -0
- package/build-types/slot-fill/index.d.ts.map +1 -1
- package/build-types/tabs/styles.d.ts.map +1 -1
- package/build-types/tabs/tablist.d.ts.map +1 -1
- package/build-types/utils/element-rect.d.ts +32 -74
- package/build-types/utils/element-rect.d.ts.map +1 -1
- package/package.json +19 -20
- package/src/box-control/utils.ts +1 -1
- package/src/composite/README.md +5 -24
- package/src/composite/{context.ts → context.tsx} +1 -2
- package/src/composite/group-label.tsx +1 -1
- package/src/composite/group.tsx +1 -1
- package/src/composite/hover.tsx +1 -1
- package/src/composite/index.tsx +17 -28
- package/src/composite/item.tsx +1 -1
- package/src/composite/legacy/index.tsx +72 -11
- package/src/composite/legacy/stories/index.story.tsx +2 -1
- package/src/composite/legacy/test/index.tsx +57 -1
- package/src/composite/row.tsx +1 -1
- package/src/composite/stories/index.story.tsx +185 -169
- package/src/composite/typeahead.tsx +1 -1
- package/src/composite/types.ts +13 -15
- package/src/date-time/date/index.tsx +1 -1
- package/src/date-time/date/styles.ts +31 -11
- package/src/date-time/date/test/use-lilius.ts +417 -0
- package/src/date-time/date/use-lilius/index.ts +394 -0
- package/src/index.ts +1 -0
- package/src/modal/index.tsx +16 -7
- package/src/modal/stories/index.story.tsx +8 -14
- package/src/modal/style.scss +0 -5
- package/src/navigator/navigator-screen/component.tsx +7 -0
- package/src/navigator/test/index.tsx +8 -0
- package/src/popover/style.scss +2 -1
- package/src/private-apis.ts +0 -9
- package/src/select-control/README.md +2 -2
- package/src/slot-fill/index.tsx +1 -0
- package/src/tabs/styles.ts +40 -11
- package/src/tabs/tablist.tsx +5 -4
- package/src/utils/element-rect.ts +93 -130
- package/tsconfig.tsbuildinfo +1 -1
- package/build/composite/store.js +0 -54
- package/build/composite/store.js.map +0 -1
- package/build-module/composite/store.js +0 -46
- package/build-module/composite/store.js.map +0 -1
- package/build-types/composite/store.d.ts +0 -25
- package/build-types/composite/store.d.ts.map +0 -1
- package/build-types/composite/stories/utils.d.ts +0 -29
- package/build-types/composite/stories/utils.d.ts.map +0 -1
- package/src/composite/store.ts +0 -46
- package/src/composite/stories/utils.tsx +0 -76
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This source is a local copy of the use-lilius library, since the original
|
|
3
|
+
* library is not actively maintained.
|
|
4
|
+
* @see https://github.com/WordPress/gutenberg/discussions/64968
|
|
5
|
+
*
|
|
6
|
+
* use-lilius@2.0.5
|
|
7
|
+
* https://github.com/Avarios/use-lilius
|
|
8
|
+
*
|
|
9
|
+
* The MIT License (MIT)
|
|
10
|
+
*
|
|
11
|
+
* Copyright (c) 2021-Present Danny Tatom
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
* in the Software without restriction, including without limitation the rights
|
|
16
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
* furnished to do so, subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
* copies or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
* SOFTWARE.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* External dependencies
|
|
34
|
+
*/
|
|
35
|
+
import {
|
|
36
|
+
addMonths,
|
|
37
|
+
addYears,
|
|
38
|
+
eachDayOfInterval,
|
|
39
|
+
eachMonthOfInterval,
|
|
40
|
+
eachWeekOfInterval,
|
|
41
|
+
endOfMonth,
|
|
42
|
+
endOfWeek,
|
|
43
|
+
isAfter,
|
|
44
|
+
isBefore,
|
|
45
|
+
isEqual,
|
|
46
|
+
set,
|
|
47
|
+
setMonth,
|
|
48
|
+
setYear,
|
|
49
|
+
startOfMonth,
|
|
50
|
+
startOfToday,
|
|
51
|
+
startOfWeek,
|
|
52
|
+
subMonths,
|
|
53
|
+
subYears,
|
|
54
|
+
} from 'date-fns';
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* WordPress dependencies
|
|
58
|
+
*/
|
|
59
|
+
import { useCallback, useMemo, useState } from '@wordpress/element';
|
|
60
|
+
|
|
61
|
+
export enum Month {
|
|
62
|
+
JANUARY,
|
|
63
|
+
FEBRUARY,
|
|
64
|
+
MARCH,
|
|
65
|
+
APRIL,
|
|
66
|
+
MAY,
|
|
67
|
+
JUNE,
|
|
68
|
+
JULY,
|
|
69
|
+
AUGUST,
|
|
70
|
+
SEPTEMBER,
|
|
71
|
+
OCTOBER,
|
|
72
|
+
NOVEMBER,
|
|
73
|
+
DECEMBER,
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export enum Day {
|
|
77
|
+
SUNDAY,
|
|
78
|
+
MONDAY,
|
|
79
|
+
TUESDAY,
|
|
80
|
+
WEDNESDAY,
|
|
81
|
+
THURSDAY,
|
|
82
|
+
FRIDAY,
|
|
83
|
+
SATURDAY,
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface Options {
|
|
87
|
+
/**
|
|
88
|
+
* What day a week starts on within the calendar matrix.
|
|
89
|
+
*
|
|
90
|
+
* @default Day.SUNDAY
|
|
91
|
+
*/
|
|
92
|
+
weekStartsOn?: Day;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The initial viewing date.
|
|
96
|
+
*
|
|
97
|
+
* @default new Date()
|
|
98
|
+
*/
|
|
99
|
+
viewing?: Date;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The initial date(s) selection.
|
|
103
|
+
*
|
|
104
|
+
* @default []
|
|
105
|
+
*/
|
|
106
|
+
selected?: Date[];
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The number of months in the calendar.
|
|
110
|
+
*
|
|
111
|
+
* @default 1
|
|
112
|
+
*/
|
|
113
|
+
numberOfMonths?: number;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface Returns {
|
|
117
|
+
/**
|
|
118
|
+
* Returns a copy of the given date with the time set to 00:00:00:00.
|
|
119
|
+
*/
|
|
120
|
+
clearTime: ( date: Date ) => Date;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Returns whether or not a date is between 2 other dates (inclusive).
|
|
124
|
+
*/
|
|
125
|
+
inRange: ( date: Date, min: Date, max: Date ) => boolean;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The date represented in the calendar matrix. Note that
|
|
129
|
+
* the month and year are the only parts used.
|
|
130
|
+
*/
|
|
131
|
+
viewing: Date;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Set the date represented in the calendar matrix. Note that
|
|
135
|
+
* the month and year are the only parts used.
|
|
136
|
+
*/
|
|
137
|
+
setViewing: React.Dispatch< React.SetStateAction< Date > >;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Set the viewing date to today.
|
|
141
|
+
*/
|
|
142
|
+
viewToday: () => void;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Set the viewing date to the given month.
|
|
146
|
+
*/
|
|
147
|
+
viewMonth: ( month: Month ) => void;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Set the viewing date to the month before the current.
|
|
151
|
+
*/
|
|
152
|
+
viewPreviousMonth: () => void;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Set the viewing date to the month after the current.
|
|
156
|
+
*/
|
|
157
|
+
viewNextMonth: () => void;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Set the viewing date to the given year.
|
|
161
|
+
*/
|
|
162
|
+
viewYear: ( year: number ) => void;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Set the viewing date to the year before the current.
|
|
166
|
+
*/
|
|
167
|
+
viewPreviousYear: () => void;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Set the viewing date to the year after the current.
|
|
171
|
+
*/
|
|
172
|
+
viewNextYear: () => void;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* The dates currently selected.
|
|
176
|
+
*/
|
|
177
|
+
selected: Date[];
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Override the currently selected dates.
|
|
181
|
+
*/
|
|
182
|
+
setSelected: React.Dispatch< React.SetStateAction< Date[] > >;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Reset the selected dates to [].
|
|
186
|
+
*/
|
|
187
|
+
clearSelected: () => void;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Determine whether or not a date has been selected.
|
|
191
|
+
*/
|
|
192
|
+
isSelected: ( date: Date ) => boolean;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Select one or more dates.
|
|
196
|
+
*/
|
|
197
|
+
select: ( date: Date | Date[], replaceExisting?: boolean ) => void;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Deselect one or more dates.
|
|
201
|
+
*/
|
|
202
|
+
deselect: ( date: Date | Date[] ) => void;
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Toggle the selection of a date.
|
|
206
|
+
*/
|
|
207
|
+
toggle: ( date: Date, replaceExisting?: boolean ) => void;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Select a range of dates (inclusive).
|
|
211
|
+
*/
|
|
212
|
+
selectRange: ( start: Date, end: Date, replaceExisting?: boolean ) => void;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Deselect a range of dates (inclusive).
|
|
216
|
+
*/
|
|
217
|
+
deselectRange: ( start: Date, end: Date ) => void;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* A matrix of days based on the current viewing date.
|
|
221
|
+
*/
|
|
222
|
+
calendar: Date[][][];
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const inRange = ( date: Date, min: Date, max: Date ) =>
|
|
226
|
+
( isEqual( date, min ) || isAfter( date, min ) ) &&
|
|
227
|
+
( isEqual( date, max ) || isBefore( date, max ) );
|
|
228
|
+
|
|
229
|
+
const clearTime = ( date: Date ) =>
|
|
230
|
+
set( date, { hours: 0, minutes: 0, seconds: 0, milliseconds: 0 } );
|
|
231
|
+
|
|
232
|
+
export const useLilius = ( {
|
|
233
|
+
weekStartsOn = Day.SUNDAY,
|
|
234
|
+
viewing: initialViewing = new Date(),
|
|
235
|
+
selected: initialSelected = [],
|
|
236
|
+
numberOfMonths = 1,
|
|
237
|
+
}: Options = {} ): Returns => {
|
|
238
|
+
const [ viewing, setViewing ] = useState< Date >( initialViewing );
|
|
239
|
+
|
|
240
|
+
const viewToday = useCallback(
|
|
241
|
+
() => setViewing( startOfToday() ),
|
|
242
|
+
[ setViewing ]
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
const viewMonth = useCallback(
|
|
246
|
+
( month: Month ) => setViewing( ( v ) => setMonth( v, month ) ),
|
|
247
|
+
[]
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
const viewPreviousMonth = useCallback(
|
|
251
|
+
() => setViewing( ( v ) => subMonths( v, 1 ) ),
|
|
252
|
+
[]
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
const viewNextMonth = useCallback(
|
|
256
|
+
() => setViewing( ( v ) => addMonths( v, 1 ) ),
|
|
257
|
+
[]
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
const viewYear = useCallback(
|
|
261
|
+
( year: number ) => setViewing( ( v ) => setYear( v, year ) ),
|
|
262
|
+
[]
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
const viewPreviousYear = useCallback(
|
|
266
|
+
() => setViewing( ( v ) => subYears( v, 1 ) ),
|
|
267
|
+
[]
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
const viewNextYear = useCallback(
|
|
271
|
+
() => setViewing( ( v ) => addYears( v, 1 ) ),
|
|
272
|
+
[]
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
const [ selected, setSelected ] = useState< Date[] >(
|
|
276
|
+
initialSelected.map( clearTime )
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
const clearSelected = () => setSelected( [] );
|
|
280
|
+
|
|
281
|
+
const isSelected = useCallback(
|
|
282
|
+
( date: Date ) =>
|
|
283
|
+
selected.findIndex( ( s ) => isEqual( s, date ) ) > -1,
|
|
284
|
+
[ selected ]
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
const select = useCallback(
|
|
288
|
+
( date: Date | Date[], replaceExisting?: boolean ) => {
|
|
289
|
+
if ( replaceExisting ) {
|
|
290
|
+
setSelected( Array.isArray( date ) ? date : [ date ] );
|
|
291
|
+
} else {
|
|
292
|
+
setSelected( ( selectedItems ) =>
|
|
293
|
+
selectedItems.concat(
|
|
294
|
+
Array.isArray( date ) ? date : [ date ]
|
|
295
|
+
)
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
[]
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
const deselect = useCallback(
|
|
303
|
+
( date: Date | Date[] ) =>
|
|
304
|
+
setSelected( ( selectedItems ) =>
|
|
305
|
+
Array.isArray( date )
|
|
306
|
+
? selectedItems.filter(
|
|
307
|
+
( s ) =>
|
|
308
|
+
! date
|
|
309
|
+
.map( ( d ) => d.getTime() )
|
|
310
|
+
.includes( s.getTime() )
|
|
311
|
+
)
|
|
312
|
+
: selectedItems.filter( ( s ) => ! isEqual( s, date ) )
|
|
313
|
+
),
|
|
314
|
+
[]
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
const toggle = useCallback(
|
|
318
|
+
( date: Date, replaceExisting?: boolean ) =>
|
|
319
|
+
isSelected( date )
|
|
320
|
+
? deselect( date )
|
|
321
|
+
: select( date, replaceExisting ),
|
|
322
|
+
[ deselect, isSelected, select ]
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
const selectRange = useCallback(
|
|
326
|
+
( start: Date, end: Date, replaceExisting?: boolean ) => {
|
|
327
|
+
if ( replaceExisting ) {
|
|
328
|
+
setSelected( eachDayOfInterval( { start, end } ) );
|
|
329
|
+
} else {
|
|
330
|
+
setSelected( ( selectedItems ) =>
|
|
331
|
+
selectedItems.concat( eachDayOfInterval( { start, end } ) )
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
[]
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
const deselectRange = useCallback( ( start: Date, end: Date ) => {
|
|
339
|
+
setSelected( ( selectedItems ) =>
|
|
340
|
+
selectedItems.filter(
|
|
341
|
+
( s ) =>
|
|
342
|
+
! eachDayOfInterval( { start, end } )
|
|
343
|
+
.map( ( d ) => d.getTime() )
|
|
344
|
+
.includes( s.getTime() )
|
|
345
|
+
)
|
|
346
|
+
);
|
|
347
|
+
}, [] );
|
|
348
|
+
|
|
349
|
+
const calendar = useMemo< Date[][][] >(
|
|
350
|
+
() =>
|
|
351
|
+
eachMonthOfInterval( {
|
|
352
|
+
start: startOfMonth( viewing ),
|
|
353
|
+
end: endOfMonth( addMonths( viewing, numberOfMonths - 1 ) ),
|
|
354
|
+
} ).map( ( month ) =>
|
|
355
|
+
eachWeekOfInterval(
|
|
356
|
+
{
|
|
357
|
+
start: startOfMonth( month ),
|
|
358
|
+
end: endOfMonth( month ),
|
|
359
|
+
},
|
|
360
|
+
{ weekStartsOn }
|
|
361
|
+
).map( ( week ) =>
|
|
362
|
+
eachDayOfInterval( {
|
|
363
|
+
start: startOfWeek( week, { weekStartsOn } ),
|
|
364
|
+
end: endOfWeek( week, { weekStartsOn } ),
|
|
365
|
+
} )
|
|
366
|
+
)
|
|
367
|
+
),
|
|
368
|
+
[ viewing, weekStartsOn, numberOfMonths ]
|
|
369
|
+
);
|
|
370
|
+
|
|
371
|
+
return {
|
|
372
|
+
clearTime,
|
|
373
|
+
inRange,
|
|
374
|
+
viewing,
|
|
375
|
+
setViewing,
|
|
376
|
+
viewToday,
|
|
377
|
+
viewMonth,
|
|
378
|
+
viewPreviousMonth,
|
|
379
|
+
viewNextMonth,
|
|
380
|
+
viewYear,
|
|
381
|
+
viewPreviousYear,
|
|
382
|
+
viewNextYear,
|
|
383
|
+
selected,
|
|
384
|
+
setSelected,
|
|
385
|
+
clearSelected,
|
|
386
|
+
isSelected,
|
|
387
|
+
select,
|
|
388
|
+
deselect,
|
|
389
|
+
toggle,
|
|
390
|
+
selectRange,
|
|
391
|
+
deselectRange,
|
|
392
|
+
calendar,
|
|
393
|
+
};
|
|
394
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -66,6 +66,7 @@ export {
|
|
|
66
66
|
CompositeItem as __unstableCompositeItem,
|
|
67
67
|
useCompositeState as __unstableUseCompositeState,
|
|
68
68
|
} from './composite/legacy';
|
|
69
|
+
export { Composite } from './composite';
|
|
69
70
|
export { ConfirmDialog as __experimentalConfirmDialog } from './confirm-dialog';
|
|
70
71
|
export { default as CustomSelectControl } from './custom-select-control';
|
|
71
72
|
export { default as Dashicon } from './dashicon';
|
package/src/modal/index.tsx
CHANGED
|
@@ -37,6 +37,7 @@ import Button from '../button';
|
|
|
37
37
|
import StyleProvider from '../style-provider';
|
|
38
38
|
import type { ModalProps } from './types';
|
|
39
39
|
import { withIgnoreIMEEvents } from '../utils/with-ignore-ime-events';
|
|
40
|
+
import { Spacer } from '../spacer';
|
|
40
41
|
|
|
41
42
|
// Used to track and dismiss the prior modal when another opens unless nested.
|
|
42
43
|
type Dismissers = Set<
|
|
@@ -323,13 +324,21 @@ function UnforwardedModal(
|
|
|
323
324
|
</div>
|
|
324
325
|
{ headerActions }
|
|
325
326
|
{ isDismissible && (
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
327
|
+
<>
|
|
328
|
+
<Spacer
|
|
329
|
+
marginBottom={ 0 }
|
|
330
|
+
marginLeft={ 3 }
|
|
331
|
+
/>
|
|
332
|
+
<Button
|
|
333
|
+
size="small"
|
|
334
|
+
onClick={ onRequestClose }
|
|
335
|
+
icon={ close }
|
|
336
|
+
label={
|
|
337
|
+
closeButtonLabel ||
|
|
338
|
+
__( 'Close' )
|
|
339
|
+
}
|
|
340
|
+
/>
|
|
341
|
+
</>
|
|
333
342
|
) }
|
|
334
343
|
</div>
|
|
335
344
|
) }
|
|
@@ -7,7 +7,7 @@ import type { StoryFn, Meta } from '@storybook/react';
|
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
9
|
import { useState } from '@wordpress/element';
|
|
10
|
-
import {
|
|
10
|
+
import { fullscreen } from '@wordpress/icons';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Internal dependencies
|
|
@@ -103,22 +103,16 @@ WithsizeSmall.args = {
|
|
|
103
103
|
};
|
|
104
104
|
WithsizeSmall.storyName = 'With size: small';
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
<Button
|
|
110
|
-
icon={ isLiked ? starFilled : starEmpty }
|
|
111
|
-
label="Like"
|
|
112
|
-
onClick={ () => setIsLiked( ! isLiked ) }
|
|
113
|
-
/>
|
|
114
|
-
);
|
|
115
|
-
};
|
|
116
|
-
|
|
106
|
+
/**
|
|
107
|
+
* The `headerActions` prop can be used to add auxiliary actions to the header, for example a fullscreen mode toggle.
|
|
108
|
+
*/
|
|
117
109
|
export const WithHeaderActions: StoryFn< typeof Modal > = Template.bind( {} );
|
|
118
110
|
WithHeaderActions.args = {
|
|
119
111
|
...Default.args,
|
|
120
|
-
headerActions:
|
|
121
|
-
|
|
112
|
+
headerActions: (
|
|
113
|
+
<Button icon={ fullscreen } label="Fullscreen mode" size="small" />
|
|
114
|
+
),
|
|
115
|
+
children: <div style={ { height: '200px' } } />,
|
|
122
116
|
};
|
|
123
117
|
WithHeaderActions.parameters = {
|
|
124
118
|
...Default.parameters,
|
package/src/modal/style.scss
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
import { useMergeRefs } from '@wordpress/compose';
|
|
18
18
|
import { isRTL as isRTLFn } from '@wordpress/i18n';
|
|
19
19
|
import { escapeAttribute } from '@wordpress/escape-html';
|
|
20
|
+
import warning from '@wordpress/warning';
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* Internal dependencies
|
|
@@ -33,6 +34,12 @@ function UnconnectedNavigatorScreen(
|
|
|
33
34
|
props: WordPressComponentProps< NavigatorScreenProps, 'div', false >,
|
|
34
35
|
forwardedRef: ForwardedRef< any >
|
|
35
36
|
) {
|
|
37
|
+
if ( ! /^\//.test( props.path ) ) {
|
|
38
|
+
warning(
|
|
39
|
+
'wp.components.NavigatorScreen: the `path` should follow a URL-like scheme; it should start with and be separated by the `/` character.'
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
36
43
|
const screenId = useId();
|
|
37
44
|
const { children, className, path, ...otherProps } = useContextSystem(
|
|
38
45
|
props,
|
|
@@ -642,6 +642,14 @@ describe( 'Navigator', () => {
|
|
|
642
642
|
).toHaveAttribute( 'id', INVALID_HTML_ATTRIBUTE.escaped );
|
|
643
643
|
} );
|
|
644
644
|
|
|
645
|
+
it( 'should warn if the `path` prop does not follow the required format', () => {
|
|
646
|
+
render( <NavigatorScreen path="not-valid">Test</NavigatorScreen> );
|
|
647
|
+
|
|
648
|
+
expect( console ).toHaveWarnedWith(
|
|
649
|
+
'wp.components.NavigatorScreen: the `path` should follow a URL-like scheme; it should start with and be separated by the `/` character.'
|
|
650
|
+
);
|
|
651
|
+
} );
|
|
652
|
+
|
|
645
653
|
it( 'should match correctly paths with named arguments', async () => {
|
|
646
654
|
const user = userEvent.setup();
|
|
647
655
|
|
package/src/popover/style.scss
CHANGED
|
@@ -27,9 +27,10 @@ $shadow-popover-border-top-only-alternate: 0 #{-$border-width} 0 $gray-900;
|
|
|
27
27
|
box-sizing: border-box;
|
|
28
28
|
width: min-content;
|
|
29
29
|
|
|
30
|
-
// Alternate treatment for popovers that put them at elevation zero with high contrast.
|
|
30
|
+
// Alternate treatment for popovers that put them at elevation zero with high contrast and smaller radius.
|
|
31
31
|
.is-alternate & {
|
|
32
32
|
box-shadow: $shadow-popover-border-default-alternate;
|
|
33
|
+
border-radius: $radius-small;
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
// A style that gives the popover no visible ui.
|
package/src/private-apis.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { Composite } from './composite';
|
|
5
|
-
import { useCompositeStore } from './composite/store';
|
|
6
4
|
import { positionToPlacement as __experimentalPopoverLegacyPositionToPlacement } from './popover/utils';
|
|
7
5
|
import { createPrivateSlotFill } from './slot-fill';
|
|
8
6
|
import { DropdownMenuV2 } from './dropdown-menu-v2';
|
|
@@ -14,13 +12,6 @@ import { lock } from './lock-unlock';
|
|
|
14
12
|
|
|
15
13
|
export const privateApis = {};
|
|
16
14
|
lock( privateApis, {
|
|
17
|
-
CompositeV2: Composite,
|
|
18
|
-
CompositeGroupV2: Composite.Group,
|
|
19
|
-
CompositeItemV2: Composite.Item,
|
|
20
|
-
CompositeRowV2: Composite.Row,
|
|
21
|
-
CompositeTypeaheadV2: Composite.Typeahead,
|
|
22
|
-
CompositeHoverV2: Composite.Hover,
|
|
23
|
-
useCompositeStoreV2: useCompositeStore,
|
|
24
15
|
__experimentalPopoverLegacyPositionToPlacement,
|
|
25
16
|
createPrivateSlotFill,
|
|
26
17
|
ComponentsContext,
|
|
@@ -103,7 +103,7 @@ Render a user interface to select multiple users from a list.
|
|
|
103
103
|
```jsx
|
|
104
104
|
<SelectControl
|
|
105
105
|
multiple
|
|
106
|
-
label={ __( '
|
|
106
|
+
label={ __( 'User' ) }
|
|
107
107
|
value={ this.state.users } // e.g: value = [ 'a', 'c' ]
|
|
108
108
|
onChange={ ( users ) => {
|
|
109
109
|
this.setState( { users } );
|
|
@@ -126,7 +126,7 @@ const [ item, setItem ] = useState( '' );
|
|
|
126
126
|
// ...
|
|
127
127
|
|
|
128
128
|
<SelectControl
|
|
129
|
-
label={ __( '
|
|
129
|
+
label={ __( 'My dinosaur' ) }
|
|
130
130
|
value={ item } // e.g: value = 'a'
|
|
131
131
|
onChange={ ( selection ) => { setItem( selection ) } }
|
|
132
132
|
__nextHasNoMarginBottom
|
package/src/slot-fill/index.tsx
CHANGED
package/src/tabs/styles.ts
CHANGED
|
@@ -22,36 +22,65 @@ export const TabListWrapper = styled.div`
|
|
|
22
22
|
text-align: start;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
@media not ( prefers-reduced-motion
|
|
25
|
+
@media not ( prefers-reduced-motion ) {
|
|
26
26
|
&.is-animation-enabled::after {
|
|
27
|
-
transition-property:
|
|
27
|
+
transition-property: transform;
|
|
28
28
|
transition-duration: 0.2s;
|
|
29
29
|
transition-timing-function: ease-out;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
+
--direction-factor: 1;
|
|
33
|
+
--direction-origin-x: left;
|
|
34
|
+
--indicator-start: var( --indicator-left );
|
|
35
|
+
&:dir( rtl ) {
|
|
36
|
+
--direction-factor: -1;
|
|
37
|
+
--direction-origin-x: right;
|
|
38
|
+
--indicator-start: var( --indicator-right );
|
|
39
|
+
}
|
|
32
40
|
&::after {
|
|
33
41
|
content: '';
|
|
34
42
|
position: absolute;
|
|
35
43
|
pointer-events: none;
|
|
44
|
+
transform-origin: var( --direction-origin-x ) top;
|
|
36
45
|
|
|
37
46
|
// Windows high contrast mode.
|
|
38
47
|
outline: 2px solid transparent;
|
|
39
48
|
outline-offset: -1px;
|
|
40
49
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
|
|
51
|
+
/* Using a large value to avoid antialiasing rounding issues
|
|
52
|
+
when scaling in the transform, see: https://stackoverflow.com/a/52159123 */
|
|
53
|
+
--antialiasing-factor: 100;
|
|
54
|
+
&:not( [aria-orientation='vertical'] ) {
|
|
55
|
+
&::after {
|
|
56
|
+
bottom: 0;
|
|
57
|
+
height: 0;
|
|
58
|
+
width: calc( var( --antialiasing-factor ) * 1px );
|
|
59
|
+
transform: translateX(
|
|
60
|
+
calc(
|
|
61
|
+
var( --indicator-start ) * var( --direction-factor ) *
|
|
62
|
+
1px
|
|
63
|
+
)
|
|
64
|
+
)
|
|
65
|
+
scaleX(
|
|
66
|
+
calc(
|
|
67
|
+
var( --indicator-width ) / var( --antialiasing-factor )
|
|
68
|
+
)
|
|
69
|
+
);
|
|
70
|
+
border-bottom: var( --wp-admin-border-width-focus ) solid
|
|
71
|
+
${ COLORS.theme.accent };
|
|
72
|
+
}
|
|
48
73
|
}
|
|
49
74
|
&[aria-orientation='vertical']::after {
|
|
50
75
|
z-index: -1;
|
|
76
|
+
top: 0;
|
|
51
77
|
left: 0;
|
|
52
78
|
width: 100%;
|
|
53
|
-
|
|
54
|
-
|
|
79
|
+
width: calc( var( --antialiasing-factor ) * 1px );
|
|
80
|
+
transform: translateY( calc( var( --indicator-top ) * 1px ) )
|
|
81
|
+
scaleY(
|
|
82
|
+
calc( var( --indicator-height ) / var( --antialiasing-factor ) )
|
|
83
|
+
);
|
|
55
84
|
background-color: ${ COLORS.theme.gray[ 100 ] };
|
|
56
85
|
}
|
|
57
86
|
`;
|
package/src/tabs/tablist.tsx
CHANGED
|
@@ -78,10 +78,11 @@ export const TabList = forwardRef<
|
|
|
78
78
|
onBlur={ onBlur }
|
|
79
79
|
{ ...otherProps }
|
|
80
80
|
style={ {
|
|
81
|
-
'--indicator-
|
|
82
|
-
'--indicator-
|
|
83
|
-
'--indicator-
|
|
84
|
-
'--indicator-
|
|
81
|
+
'--indicator-top': indicatorPosition.top,
|
|
82
|
+
'--indicator-right': indicatorPosition.right,
|
|
83
|
+
'--indicator-left': indicatorPosition.left,
|
|
84
|
+
'--indicator-width': indicatorPosition.width,
|
|
85
|
+
'--indicator-height': indicatorPosition.height,
|
|
85
86
|
...otherProps.style,
|
|
86
87
|
} }
|
|
87
88
|
className={ clsx(
|