@agnos-ui/core 0.0.1-alpha.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/README.md +15 -0
- package/dist/lib/accordion.d.ts +318 -0
- package/dist/lib/accordion.js +263 -0
- package/dist/lib/alert.d.ts +100 -0
- package/dist/lib/alert.js +66 -0
- package/dist/lib/config.d.ts +71 -0
- package/dist/lib/config.js +53 -0
- package/dist/lib/index.d.ts +11 -0
- package/dist/lib/index.js +11 -0
- package/dist/lib/modal/modal.d.ts +318 -0
- package/dist/lib/modal/modal.js +156 -0
- package/dist/lib/modal/scrollbars.d.ts +2 -0
- package/dist/lib/modal/scrollbars.js +27 -0
- package/dist/lib/pagination.d.ts +464 -0
- package/dist/lib/pagination.js +148 -0
- package/dist/lib/pagination.utils.d.ts +8 -0
- package/dist/lib/pagination.utils.js +110 -0
- package/dist/lib/rating.d.ts +209 -0
- package/dist/lib/rating.js +141 -0
- package/dist/lib/select.d.ts +199 -0
- package/dist/lib/select.js +240 -0
- package/dist/lib/services/checks.d.ts +32 -0
- package/dist/lib/services/checks.js +43 -0
- package/dist/lib/services/directiveUtils.d.ts +95 -0
- package/dist/lib/services/directiveUtils.js +190 -0
- package/dist/lib/services/focustrack.d.ts +19 -0
- package/dist/lib/services/focustrack.js +46 -0
- package/dist/lib/services/index.d.ts +6 -0
- package/dist/lib/services/index.js +6 -0
- package/dist/lib/services/portal.d.ts +6 -0
- package/dist/lib/services/portal.js +33 -0
- package/dist/lib/services/siblingsInert.d.ts +7 -0
- package/dist/lib/services/siblingsInert.js +40 -0
- package/dist/lib/services/stores.d.ts +140 -0
- package/dist/lib/services/stores.js +219 -0
- package/dist/lib/services/writables.d.ts +7 -0
- package/dist/lib/services/writables.js +16 -0
- package/dist/lib/transitions/baseTransitions.d.ts +136 -0
- package/dist/lib/transitions/baseTransitions.js +171 -0
- package/dist/lib/transitions/bootstrap/collapse.d.ts +2 -0
- package/dist/lib/transitions/bootstrap/collapse.js +15 -0
- package/dist/lib/transitions/bootstrap/fade.d.ts +1 -0
- package/dist/lib/transitions/bootstrap/fade.js +7 -0
- package/dist/lib/transitions/bootstrap/index.d.ts +2 -0
- package/dist/lib/transitions/bootstrap/index.js +2 -0
- package/dist/lib/transitions/collapse.d.ts +29 -0
- package/dist/lib/transitions/collapse.js +39 -0
- package/dist/lib/transitions/cssTransitions.d.ts +15 -0
- package/dist/lib/transitions/cssTransitions.js +38 -0
- package/dist/lib/transitions/index.d.ts +5 -0
- package/dist/lib/transitions/index.js +5 -0
- package/dist/lib/transitions/simpleClassTransition.d.ts +29 -0
- package/dist/lib/transitions/simpleClassTransition.js +28 -0
- package/dist/lib/transitions/utils.d.ts +20 -0
- package/dist/lib/transitions/utils.js +83 -0
- package/dist/lib/tsdoc-metadata.json +11 -0
- package/dist/lib/types.d.ts +58 -0
- package/dist/lib/types.js +7 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/lib/utils.js +2 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @agnos-ui/core
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@agnos-ui/core)
|
|
4
|
+
|
|
5
|
+
[AgnosUI](https://amadeusitgroup.github.io/AgnosUI/latest/) is a framework-agnostic widget library with adapters for multiple frameworks:
|
|
6
|
+
|
|
7
|
+
- [Angular](https://www.npmjs.com/package/@agnos-ui/angular)
|
|
8
|
+
- [React](https://www.npmjs.com/package/@agnos-ui/react)
|
|
9
|
+
- [Svelte](https://www.npmjs.com/package/@agnos-ui/svelte)
|
|
10
|
+
|
|
11
|
+
This `@agnos-ui/core` package contains the framework-agnostic common code used by the above framework adapters.
|
|
12
|
+
|
|
13
|
+
Please check [our demo site](https://amadeusitgroup.github.io/AgnosUI/latest/) to see all the available widgets and how to use them.
|
|
14
|
+
|
|
15
|
+
Unless you want to develop an adapter for a framework, you probably do not need to use `@agnos-ui/core` directly. Please refer to one of the framework-specific packages.
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import type { PropsConfig } from './services';
|
|
2
|
+
import type { TransitionFn } from './transitions';
|
|
3
|
+
import type { Directive, SlotContent, Widget, WidgetSlotContext } from './types';
|
|
4
|
+
export interface AccordionCommonPropsAndState {
|
|
5
|
+
/**
|
|
6
|
+
* Classes to add on the accordion DOM element.
|
|
7
|
+
*/
|
|
8
|
+
accordionClass: string;
|
|
9
|
+
}
|
|
10
|
+
export interface AccordionProps extends AccordionCommonPropsAndState {
|
|
11
|
+
/**
|
|
12
|
+
* If `true`, only one item at the time can stay open.
|
|
13
|
+
*/
|
|
14
|
+
closeOthers: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* An event fired when an item is shown.
|
|
17
|
+
*
|
|
18
|
+
* Event payload is the id of the item.
|
|
19
|
+
*/
|
|
20
|
+
onShown: (itemId: string) => void;
|
|
21
|
+
/**
|
|
22
|
+
* An event fired when an item is hidden.
|
|
23
|
+
*
|
|
24
|
+
* Event payload is the id of the item.
|
|
25
|
+
*/
|
|
26
|
+
onHidden: (itemId: string) => void;
|
|
27
|
+
/**
|
|
28
|
+
* The id of the accordion-item. It can be used for controlling the accordion-item via the accordion api.
|
|
29
|
+
*
|
|
30
|
+
* It is a prop of the accordion-item.
|
|
31
|
+
*/
|
|
32
|
+
itemId: string;
|
|
33
|
+
/**
|
|
34
|
+
* If `true`, the content of the accordion-item collapse will be removed from the DOM. It will be just hidden otherwise.
|
|
35
|
+
*
|
|
36
|
+
* It is a prop of the accordion-item.
|
|
37
|
+
*/
|
|
38
|
+
itemDestroyOnHide: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* If `true`, the accordion-item will be disabled.
|
|
41
|
+
* It will not react to user's clicks, but still will be possible to toggle programmatically.
|
|
42
|
+
*
|
|
43
|
+
* It is a prop of the accordion-item.
|
|
44
|
+
*/
|
|
45
|
+
itemDisabled: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* If `true`, the accordion-item will be collapsed. Otherwise, it will be expanded.
|
|
48
|
+
*
|
|
49
|
+
* It is a prop of the accordion-item.
|
|
50
|
+
*/
|
|
51
|
+
itemCollapsed: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* If `true`, accordion-item will be animated.
|
|
54
|
+
*
|
|
55
|
+
* It is a prop of the accordion-item.
|
|
56
|
+
*/
|
|
57
|
+
itemAnimation: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* The transition to use for the accordion-item collapse when is toggled.
|
|
60
|
+
*
|
|
61
|
+
* It is a prop of the accordion-item.
|
|
62
|
+
*/
|
|
63
|
+
itemTransition: TransitionFn;
|
|
64
|
+
/**
|
|
65
|
+
* An event fired when an item is shown.
|
|
66
|
+
*
|
|
67
|
+
* It is a prop of the accordion-item.
|
|
68
|
+
*/
|
|
69
|
+
onItemShown: () => void;
|
|
70
|
+
/**
|
|
71
|
+
* An event fired when an item is hidden.
|
|
72
|
+
*
|
|
73
|
+
* It is a prop of the accordion-item.
|
|
74
|
+
*/
|
|
75
|
+
onItemHidden: () => void;
|
|
76
|
+
/**
|
|
77
|
+
* An event fired when the `collapsed` value changes.
|
|
78
|
+
*
|
|
79
|
+
* Event payload is the new value of collapsed.
|
|
80
|
+
*
|
|
81
|
+
* It is a prop of the accordion-item.
|
|
82
|
+
*/
|
|
83
|
+
onItemCollapsedChange: (collapsed: boolean) => void;
|
|
84
|
+
/**
|
|
85
|
+
* Structure of the accordion-item. The default item structure is: accordion-item
|
|
86
|
+
* contains accordion header and accordion collapse; the accordion header contains the accordion button
|
|
87
|
+
* (that contains `slotItemHeader`), while the accordion collapse contains the accordion body (that contains slotItemBody).
|
|
88
|
+
*
|
|
89
|
+
* It is a prop of the accordion-item.
|
|
90
|
+
*/
|
|
91
|
+
slotItemStructure: SlotContent<AccordionItemContext>;
|
|
92
|
+
/**
|
|
93
|
+
* Content present in the accordion body.
|
|
94
|
+
*
|
|
95
|
+
* It is a prop of the accordion-item.
|
|
96
|
+
*/
|
|
97
|
+
slotItemBody: SlotContent<AccordionItemContext>;
|
|
98
|
+
/**
|
|
99
|
+
* Content present in the accordion button inside the accordion header.
|
|
100
|
+
*
|
|
101
|
+
* It is a prop of the accordion-item.
|
|
102
|
+
*/
|
|
103
|
+
slotItemHeader: SlotContent<AccordionItemContext>;
|
|
104
|
+
/**
|
|
105
|
+
* Classes to add on the accordion-item DOM element.
|
|
106
|
+
*
|
|
107
|
+
* It is a prop of the accordion-item.
|
|
108
|
+
*/
|
|
109
|
+
itemClass: string;
|
|
110
|
+
/**
|
|
111
|
+
* Classes to add on the accordion-item header DOM element.
|
|
112
|
+
*
|
|
113
|
+
* It is a prop of the accordion-item.
|
|
114
|
+
*/
|
|
115
|
+
itemHeaderClass: string;
|
|
116
|
+
/**
|
|
117
|
+
* Classes to add on the accordion-item toggle button DOM element.
|
|
118
|
+
*
|
|
119
|
+
* It is a prop of the accordion-item.
|
|
120
|
+
*/
|
|
121
|
+
itemButtonClass: string;
|
|
122
|
+
/**
|
|
123
|
+
* Classes to add on the accordion-item collapse DOM element.
|
|
124
|
+
*
|
|
125
|
+
* It is a prop of the accordion-item.
|
|
126
|
+
*/
|
|
127
|
+
itemCollapseClass: string;
|
|
128
|
+
/**
|
|
129
|
+
* Classes to add on the accordion-item body DOM element.
|
|
130
|
+
*
|
|
131
|
+
* It is a prop of the accordion-item.
|
|
132
|
+
*/
|
|
133
|
+
itemBodyClass: string;
|
|
134
|
+
}
|
|
135
|
+
export interface AccordionState extends AccordionCommonPropsAndState {
|
|
136
|
+
/**
|
|
137
|
+
* Array containing all the accordion-items contained in the accordion.
|
|
138
|
+
*/
|
|
139
|
+
itemsWidget: AccordionItemWidget[];
|
|
140
|
+
}
|
|
141
|
+
export interface AccordionApi {
|
|
142
|
+
/**
|
|
143
|
+
* Given the itemId, it will return if such item is expanded or not.
|
|
144
|
+
*
|
|
145
|
+
* If the itemId is not a valid id it will return `false`.
|
|
146
|
+
*/
|
|
147
|
+
isExpanded(itemId: string): boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Given the itemId, will expand the corresponding accordion-item.
|
|
150
|
+
*
|
|
151
|
+
* If the itemId is not valid, nothing will happen.
|
|
152
|
+
*/
|
|
153
|
+
expand(itemId: string): void;
|
|
154
|
+
/**
|
|
155
|
+
* Given the itemId, will collapse the corresponding accordion-item.
|
|
156
|
+
*
|
|
157
|
+
* If the itemId is not valid, nothing will happen.
|
|
158
|
+
*/
|
|
159
|
+
collapse(itemId: string): void;
|
|
160
|
+
/**
|
|
161
|
+
* Given the itemId, will toggle the corresponding accordion-item.
|
|
162
|
+
*
|
|
163
|
+
* If the itemId is not valid, nothing will happen.
|
|
164
|
+
*/
|
|
165
|
+
toggle(itemId: string): void;
|
|
166
|
+
/**
|
|
167
|
+
* It will expand all the items in the accordion.
|
|
168
|
+
*
|
|
169
|
+
* If `closeOthers` is `true` it will expand only the last accordion-item.
|
|
170
|
+
*/
|
|
171
|
+
expandAll(): void;
|
|
172
|
+
/**
|
|
173
|
+
* It will collapse all the accordion-items in the accordion.
|
|
174
|
+
*/
|
|
175
|
+
collapseAll(): void;
|
|
176
|
+
/**
|
|
177
|
+
* Creates a new in accordionItem.
|
|
178
|
+
*/
|
|
179
|
+
registerItem(itemConfig?: PropsConfig<AccordionItemProps>): AccordionItemWidget;
|
|
180
|
+
}
|
|
181
|
+
export interface AccordionDirectives {
|
|
182
|
+
/**
|
|
183
|
+
* Directive to put on the accordion DOM element
|
|
184
|
+
*/
|
|
185
|
+
accordionDirective: Directive;
|
|
186
|
+
}
|
|
187
|
+
export type AccordionWidget = Widget<AccordionProps, AccordionState, AccordionApi, object, AccordionDirectives>;
|
|
188
|
+
export type AccordionItemContext = WidgetSlotContext<AccordionItemWidget>;
|
|
189
|
+
export interface AccordionItemActions {
|
|
190
|
+
/**
|
|
191
|
+
* Action to be called when the user clicks on the accordion-item button. If the accordion-item is disabled nothing will happen.
|
|
192
|
+
*/
|
|
193
|
+
click(): void;
|
|
194
|
+
}
|
|
195
|
+
export interface AccordionItemApi {
|
|
196
|
+
/**
|
|
197
|
+
* It will collapse the accordion-item.
|
|
198
|
+
*/
|
|
199
|
+
collapse(): void;
|
|
200
|
+
/**
|
|
201
|
+
* It will expand the accordion-item.
|
|
202
|
+
*/
|
|
203
|
+
expand(): void;
|
|
204
|
+
/**
|
|
205
|
+
* It will toggle the accordion-item.
|
|
206
|
+
*/
|
|
207
|
+
toggle(): void;
|
|
208
|
+
/**
|
|
209
|
+
* Method to be called after the initialization to allow animations.
|
|
210
|
+
*/
|
|
211
|
+
initDone(): void;
|
|
212
|
+
}
|
|
213
|
+
export interface AccordionItemDirectives {
|
|
214
|
+
/**
|
|
215
|
+
* Directive to be put on the accordion-item collapse. It will handle the animation.
|
|
216
|
+
*/
|
|
217
|
+
collapseDirective: Directive;
|
|
218
|
+
/**
|
|
219
|
+
* Directive to be put on the accordion-item. It will handle adding the accordion-item to the accordion.
|
|
220
|
+
*/
|
|
221
|
+
accordionItemDirective: Directive;
|
|
222
|
+
}
|
|
223
|
+
export interface AccordionItemCommonPropsAndState {
|
|
224
|
+
/**
|
|
225
|
+
* If `true`, the accordion-item will be collapsed. Otherwise, it will be expanded.
|
|
226
|
+
*/
|
|
227
|
+
itemCollapsed: boolean;
|
|
228
|
+
/**
|
|
229
|
+
* If `true`, the accordion-item will be disabled.
|
|
230
|
+
* It will not react to user's clicks, but still will be possible to toggle programmatically.
|
|
231
|
+
*/
|
|
232
|
+
itemDisabled: boolean;
|
|
233
|
+
/**
|
|
234
|
+
* The id of the accordion-item. It can be used for controlling the accordion-item via the accordion api.
|
|
235
|
+
*/
|
|
236
|
+
itemId: string;
|
|
237
|
+
/**
|
|
238
|
+
* Content present in the accordion button inside the accordion header.
|
|
239
|
+
*/
|
|
240
|
+
slotItemHeader: SlotContent<AccordionItemContext>;
|
|
241
|
+
/**
|
|
242
|
+
* Content present in the accordion body.
|
|
243
|
+
*/
|
|
244
|
+
slotItemBody: SlotContent<AccordionItemContext>;
|
|
245
|
+
/**
|
|
246
|
+
* Structure of the accordion-item. The default item structure is: accordion-item
|
|
247
|
+
* contains accordion header and accordion collapse; the accordion header contains the accordion button
|
|
248
|
+
* (that contains `slotItemHeader`), while the accordion collapse contains the accordion body (that contains slotItemBody).
|
|
249
|
+
*/
|
|
250
|
+
slotItemStructure: SlotContent<AccordionItemContext>;
|
|
251
|
+
/**
|
|
252
|
+
* Classes to add on the accordion-item DOM element.
|
|
253
|
+
*/
|
|
254
|
+
itemClass: string;
|
|
255
|
+
/**
|
|
256
|
+
* Classes to add on the accordion-item header DOM element.
|
|
257
|
+
*/
|
|
258
|
+
itemHeaderClass: string;
|
|
259
|
+
/**
|
|
260
|
+
* Classes to add on the accordion-item collapse DOM element.
|
|
261
|
+
*/
|
|
262
|
+
itemButtonClass: string;
|
|
263
|
+
/**
|
|
264
|
+
* Classes to add on the accordion-item collapse DOM element.
|
|
265
|
+
*/
|
|
266
|
+
itemCollapseClass: string;
|
|
267
|
+
/**
|
|
268
|
+
* Classes to add on the accordion-item body DOM element.
|
|
269
|
+
*/
|
|
270
|
+
itemBodyClass: string;
|
|
271
|
+
}
|
|
272
|
+
export interface AccordionItemProps extends AccordionItemCommonPropsAndState {
|
|
273
|
+
/**
|
|
274
|
+
* If `true`, accordion-item will be animated.
|
|
275
|
+
*/
|
|
276
|
+
itemAnimation: boolean;
|
|
277
|
+
/**
|
|
278
|
+
* The transition to use for the accordion-item collapse when is toggled.
|
|
279
|
+
*/
|
|
280
|
+
itemTransition: TransitionFn;
|
|
281
|
+
/**
|
|
282
|
+
* If `true`, the content of the accordion-item collapse will be removed from the DOM. It will be just hidden otherwise.
|
|
283
|
+
*/
|
|
284
|
+
itemDestroyOnHide: boolean;
|
|
285
|
+
/**
|
|
286
|
+
* An event fired when an item is shown.
|
|
287
|
+
*/
|
|
288
|
+
onItemShown: () => void;
|
|
289
|
+
/**
|
|
290
|
+
* An event fired when an item is hidden.
|
|
291
|
+
*/
|
|
292
|
+
onItemHidden: () => void;
|
|
293
|
+
/**
|
|
294
|
+
* An event fired when the `collapsed` value changes.
|
|
295
|
+
*
|
|
296
|
+
* Event payload is the new value of collapsed.
|
|
297
|
+
*/
|
|
298
|
+
onItemCollapsedChange: (collapsed: boolean) => void;
|
|
299
|
+
}
|
|
300
|
+
export interface AccordionItemState extends AccordionItemCommonPropsAndState {
|
|
301
|
+
/**
|
|
302
|
+
* If `true` the collapse inside the accordion-item should be in DOM. Its value depends on the
|
|
303
|
+
* value of the `itemCollapse` and `itemDestroyOnHide`.
|
|
304
|
+
*/
|
|
305
|
+
shouldBeInDOM: boolean;
|
|
306
|
+
}
|
|
307
|
+
export type AccordionItemWidget = Widget<AccordionItemProps, AccordionItemState, AccordionItemApi, AccordionItemActions, AccordionItemDirectives>;
|
|
308
|
+
/**
|
|
309
|
+
* Retrieve a shallow copy of the default accordion config
|
|
310
|
+
* @returns the default accordion config
|
|
311
|
+
*/
|
|
312
|
+
export declare function getAccordionDefaultConfig(): AccordionProps;
|
|
313
|
+
/**
|
|
314
|
+
* Creates a new Accordion widget instance.
|
|
315
|
+
* @param config - config of the accordion, either as a store or as an object containing values or stores.
|
|
316
|
+
* @returns a new accordion widget instance
|
|
317
|
+
*/
|
|
318
|
+
export declare function createAccordion(config?: PropsConfig<AccordionProps>): AccordionWidget;
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { bindDirectiveNoArg, bindableDerived, directiveSubscribe, registrationArray, stateStores, typeBoolean, typeFunction, typeString, writablesForProps, } from './services';
|
|
2
|
+
import { createTransition } from './transitions';
|
|
3
|
+
import { collapseVerticalTransition } from './transitions/bootstrap';
|
|
4
|
+
import { computed, readable, writable } from '@amadeus-it-group/tansu';
|
|
5
|
+
import { noop } from './utils';
|
|
6
|
+
let itemId = 0;
|
|
7
|
+
function getItemId() {
|
|
8
|
+
return `accordion-item-${itemId++}`;
|
|
9
|
+
}
|
|
10
|
+
function adjustItemsCloseOthers(items, openItems, oldOpen) {
|
|
11
|
+
if (openItems.length == 2) {
|
|
12
|
+
oldOpen = oldOpen ?? openItems[0];
|
|
13
|
+
const keepOpen = openItems.find((id) => id !== oldOpen);
|
|
14
|
+
items.forEach((item) => {
|
|
15
|
+
if (item.state$().itemId !== keepOpen && !item.state$().itemCollapsed) {
|
|
16
|
+
item.patch({ itemCollapsed: true });
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
else if (openItems.length > 2) {
|
|
21
|
+
//this case can happen when you have multiple items open and you toggle the close others
|
|
22
|
+
const keepOpen = openItems[0];
|
|
23
|
+
items.forEach((item) => {
|
|
24
|
+
if (item.state$().itemId !== keepOpen && !item.state$().itemCollapsed) {
|
|
25
|
+
item.patch({ itemCollapsed: true });
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return items;
|
|
30
|
+
}
|
|
31
|
+
function getItem(items, itemId) {
|
|
32
|
+
return items.find((item) => item.state$().itemId === itemId);
|
|
33
|
+
}
|
|
34
|
+
const defaultAccordionConfig = {
|
|
35
|
+
closeOthers: false,
|
|
36
|
+
onShown: noop,
|
|
37
|
+
onHidden: noop,
|
|
38
|
+
accordionClass: '',
|
|
39
|
+
itemId: '',
|
|
40
|
+
itemDestroyOnHide: false,
|
|
41
|
+
itemDisabled: false,
|
|
42
|
+
itemCollapsed: true,
|
|
43
|
+
itemAnimation: true,
|
|
44
|
+
itemTransition: collapseVerticalTransition,
|
|
45
|
+
onItemShown: noop,
|
|
46
|
+
onItemHidden: noop,
|
|
47
|
+
onItemCollapsedChange: noop,
|
|
48
|
+
slotItemStructure: undefined,
|
|
49
|
+
slotItemBody: undefined,
|
|
50
|
+
slotItemHeader: undefined,
|
|
51
|
+
itemClass: '',
|
|
52
|
+
itemHeaderClass: '',
|
|
53
|
+
itemButtonClass: '',
|
|
54
|
+
itemCollapseClass: '',
|
|
55
|
+
itemBodyClass: '',
|
|
56
|
+
};
|
|
57
|
+
const defaultItemConfig = {
|
|
58
|
+
itemId: defaultAccordionConfig.itemId,
|
|
59
|
+
itemDestroyOnHide: defaultAccordionConfig.itemDestroyOnHide,
|
|
60
|
+
itemDisabled: defaultAccordionConfig.itemDisabled,
|
|
61
|
+
itemCollapsed: defaultAccordionConfig.itemCollapsed,
|
|
62
|
+
itemAnimation: defaultAccordionConfig.itemAnimation,
|
|
63
|
+
itemTransition: defaultAccordionConfig.itemTransition,
|
|
64
|
+
onItemShown: defaultAccordionConfig.onItemShown,
|
|
65
|
+
onItemHidden: defaultAccordionConfig.onItemHidden,
|
|
66
|
+
onItemCollapsedChange: defaultAccordionConfig.onItemCollapsedChange,
|
|
67
|
+
slotItemStructure: defaultAccordionConfig.slotItemStructure,
|
|
68
|
+
slotItemBody: defaultAccordionConfig.slotItemBody,
|
|
69
|
+
slotItemHeader: defaultAccordionConfig.slotItemHeader,
|
|
70
|
+
itemClass: defaultAccordionConfig.itemClass,
|
|
71
|
+
itemHeaderClass: defaultAccordionConfig.itemHeaderClass,
|
|
72
|
+
itemButtonClass: defaultAccordionConfig.itemButtonClass,
|
|
73
|
+
itemCollapseClass: defaultAccordionConfig.itemCollapseClass,
|
|
74
|
+
itemBodyClass: defaultAccordionConfig.itemBodyClass,
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Retrieve a shallow copy of the default accordion config
|
|
78
|
+
* @returns the default accordion config
|
|
79
|
+
*/
|
|
80
|
+
export function getAccordionDefaultConfig() {
|
|
81
|
+
return { ...defaultAccordionConfig };
|
|
82
|
+
}
|
|
83
|
+
const configAccordionValidator = {
|
|
84
|
+
closeOthers: typeBoolean,
|
|
85
|
+
onShown: typeFunction,
|
|
86
|
+
onHidden: typeFunction,
|
|
87
|
+
itemId: typeString,
|
|
88
|
+
itemDestroyOnHide: typeBoolean,
|
|
89
|
+
itemDisabled: typeBoolean,
|
|
90
|
+
itemCollapsed: typeBoolean,
|
|
91
|
+
itemAnimation: typeBoolean,
|
|
92
|
+
itemTransition: typeFunction,
|
|
93
|
+
onItemShown: typeFunction,
|
|
94
|
+
onItemHidden: typeFunction,
|
|
95
|
+
onItemCollapsedChange: typeFunction,
|
|
96
|
+
itemClass: typeString,
|
|
97
|
+
itemHeaderClass: typeString,
|
|
98
|
+
itemButtonClass: typeString,
|
|
99
|
+
itemCollapseClass: typeString,
|
|
100
|
+
itemBodyClass: typeString,
|
|
101
|
+
};
|
|
102
|
+
const configItemValidator = {
|
|
103
|
+
itemId: typeString,
|
|
104
|
+
itemDestroyOnHide: typeBoolean,
|
|
105
|
+
itemDisabled: typeBoolean,
|
|
106
|
+
itemCollapsed: typeBoolean,
|
|
107
|
+
itemAnimation: typeBoolean,
|
|
108
|
+
itemTransition: typeFunction,
|
|
109
|
+
onItemShown: typeFunction,
|
|
110
|
+
onItemHidden: typeFunction,
|
|
111
|
+
onItemCollapsedChange: typeFunction,
|
|
112
|
+
itemClass: typeString,
|
|
113
|
+
itemHeaderClass: typeString,
|
|
114
|
+
itemButtonClass: typeString,
|
|
115
|
+
itemCollapseClass: typeString,
|
|
116
|
+
itemBodyClass: typeString,
|
|
117
|
+
};
|
|
118
|
+
function createAccordionItem(accordionOnShown, accordionOnHidden, config) {
|
|
119
|
+
const [{ itemAnimation$, itemTransition$, itemDestroyOnHide$, onItemShown$, onItemHidden$, onItemCollapsedChange$, itemCollapsed$, itemId$: _dirtyItemId$, itemDisabled$, ...stateProps }, patch,] = writablesForProps(defaultItemConfig, config, configItemValidator);
|
|
120
|
+
const initDone$ = writable(false);
|
|
121
|
+
const itemId$ = bindableDerived(readable(noop), [_dirtyItemId$], ([dirtyItemId]) => (dirtyItemId ? dirtyItemId : getItemId()));
|
|
122
|
+
const shouldBeInDOM$ = computed(() => {
|
|
123
|
+
return itemDestroyOnHide$() === false || !itemTransition.state$().hidden;
|
|
124
|
+
});
|
|
125
|
+
const itemTransition = createTransition({
|
|
126
|
+
transition: itemTransition$,
|
|
127
|
+
visible: computed(() => {
|
|
128
|
+
const collapsed = itemCollapsed$();
|
|
129
|
+
onItemCollapsedChange$()(collapsed);
|
|
130
|
+
return !collapsed;
|
|
131
|
+
}),
|
|
132
|
+
animation: itemAnimation$,
|
|
133
|
+
animationOnInit: false,
|
|
134
|
+
initDone: initDone$,
|
|
135
|
+
onHidden: () => {
|
|
136
|
+
accordionOnHidden()(itemId$());
|
|
137
|
+
onItemHidden$()();
|
|
138
|
+
},
|
|
139
|
+
onShown: () => {
|
|
140
|
+
accordionOnShown()(itemId$());
|
|
141
|
+
onItemShown$()();
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
return {
|
|
145
|
+
...stateStores({
|
|
146
|
+
itemCollapsed$,
|
|
147
|
+
itemId$,
|
|
148
|
+
shouldBeInDOM$,
|
|
149
|
+
itemDisabled$,
|
|
150
|
+
...stateProps,
|
|
151
|
+
}),
|
|
152
|
+
patch,
|
|
153
|
+
actions: {
|
|
154
|
+
click: () => {
|
|
155
|
+
if (!itemDisabled$()) {
|
|
156
|
+
itemCollapsed$.update((c) => !c);
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
api: {
|
|
161
|
+
initDone: () => {
|
|
162
|
+
initDone$.set(true);
|
|
163
|
+
},
|
|
164
|
+
collapse: () => {
|
|
165
|
+
itemCollapsed$.set(true);
|
|
166
|
+
},
|
|
167
|
+
expand: () => {
|
|
168
|
+
itemCollapsed$.set(false);
|
|
169
|
+
},
|
|
170
|
+
toggle: () => {
|
|
171
|
+
itemCollapsed$.update((c) => !c);
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
directives: { collapseDirective: bindDirectiveNoArg(itemTransition.directives.directive), accordionItemDirective: noop },
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Creates a new Accordion widget instance.
|
|
179
|
+
* @param config - config of the accordion, either as a store or as an object containing values or stores.
|
|
180
|
+
* @returns a new accordion widget instance
|
|
181
|
+
*/
|
|
182
|
+
export function createAccordion(config) {
|
|
183
|
+
const [{ closeOthers$, onShown$, onHidden$, itemId$, itemAnimation$, itemClass$, itemDisabled$, itemCollapsed$, itemTransition$, itemDestroyOnHide$, itemBodyClass$, itemButtonClass$, itemCollapseClass$, itemHeaderClass$, onItemCollapsedChange$, onItemHidden$, onItemShown$, slotItemStructure$, slotItemBody$, slotItemHeader$, ...stateProps }, patch,] = writablesForProps(defaultAccordionConfig, config, configAccordionValidator);
|
|
184
|
+
const itemsWidget$ = registrationArray();
|
|
185
|
+
const openItems$ = computed(() => {
|
|
186
|
+
const openItems = [];
|
|
187
|
+
itemsWidget$().forEach((item) => {
|
|
188
|
+
if (!item.state$().itemCollapsed) {
|
|
189
|
+
openItems.push(item.state$().itemId);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
return openItems;
|
|
193
|
+
});
|
|
194
|
+
const oldOpenItem$ = writable(openItems$()[0]);
|
|
195
|
+
const checkCloseOthersAction$ = computed(() => {
|
|
196
|
+
if (closeOthers$()) {
|
|
197
|
+
adjustItemsCloseOthers(itemsWidget$(), openItems$(), oldOpenItem$());
|
|
198
|
+
oldOpenItem$.set(openItems$()[0]);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
itemsWidget$();
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
const action$ = computed(() => {
|
|
205
|
+
checkCloseOthersAction$();
|
|
206
|
+
});
|
|
207
|
+
return {
|
|
208
|
+
...stateStores({ itemsWidget$, ...stateProps }),
|
|
209
|
+
patch,
|
|
210
|
+
actions: {},
|
|
211
|
+
api: {
|
|
212
|
+
isExpanded: (id) => {
|
|
213
|
+
const item = getItem(itemsWidget$(), id);
|
|
214
|
+
if (item) {
|
|
215
|
+
return !item.state$().itemCollapsed;
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
expand: (id) => {
|
|
222
|
+
getItem(itemsWidget$(), id)?.api.expand();
|
|
223
|
+
},
|
|
224
|
+
collapse: (id) => {
|
|
225
|
+
getItem(itemsWidget$(), id)?.api.collapse();
|
|
226
|
+
},
|
|
227
|
+
toggle: (id) => {
|
|
228
|
+
getItem(itemsWidget$(), id)?.api.toggle();
|
|
229
|
+
},
|
|
230
|
+
expandAll: () => {
|
|
231
|
+
itemsWidget$().forEach((i) => i.api.expand());
|
|
232
|
+
},
|
|
233
|
+
collapseAll: () => {
|
|
234
|
+
itemsWidget$().forEach((i) => i.api.collapse());
|
|
235
|
+
},
|
|
236
|
+
registerItem: (itemConfig) => {
|
|
237
|
+
const item = createAccordionItem(onShown$, onHidden$, computed(() => ({
|
|
238
|
+
itemId: itemId$(),
|
|
239
|
+
itemClass: itemClass$(),
|
|
240
|
+
itemAnimation: itemAnimation$(),
|
|
241
|
+
itemDisabled: itemDisabled$(),
|
|
242
|
+
itemCollapsed: itemCollapsed$(),
|
|
243
|
+
itemTransition: itemTransition$(),
|
|
244
|
+
itemDestroyOnHide: itemDestroyOnHide$(),
|
|
245
|
+
itemBodyClass: itemBodyClass$(),
|
|
246
|
+
itemButtonClass: itemButtonClass$(),
|
|
247
|
+
itemCollapseClass: itemCollapseClass$(),
|
|
248
|
+
itemHeaderClass: itemHeaderClass$(),
|
|
249
|
+
onItemCollapsedChange: onItemCollapsedChange$(),
|
|
250
|
+
onItemHidden: onItemHidden$(),
|
|
251
|
+
onItemShown: onItemShown$(),
|
|
252
|
+
slotItemStructure: slotItemStructure$(),
|
|
253
|
+
slotItemBody: slotItemBody$(),
|
|
254
|
+
slotItemHeader: slotItemHeader$(),
|
|
255
|
+
...itemConfig?.(),
|
|
256
|
+
})));
|
|
257
|
+
item.directives.accordionItemDirective = () => ({ destroy: itemsWidget$.register(item) });
|
|
258
|
+
return item;
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
directives: { accordionDirective: directiveSubscribe(action$) },
|
|
262
|
+
};
|
|
263
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { PropsConfig } from './services';
|
|
2
|
+
import type { TransitionFn } from './transitions';
|
|
3
|
+
import type { Directive, SlotContent, Widget, WidgetSlotContext } from './types';
|
|
4
|
+
export type AlertContext = WidgetSlotContext<AlertWidget>;
|
|
5
|
+
export interface AlertCommonPropsAndState {
|
|
6
|
+
/**
|
|
7
|
+
* If `true`, alert can be dismissed by the user.
|
|
8
|
+
* The close button (×) will be displayed and you can be notified of the event with the (close) output.
|
|
9
|
+
*/
|
|
10
|
+
dismissible: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Type of the alert.
|
|
13
|
+
* There are the following types: 'success', 'info', 'warning', 'danger', 'primary', 'secondary', 'light' and 'dark'.
|
|
14
|
+
*/
|
|
15
|
+
type: string;
|
|
16
|
+
/**
|
|
17
|
+
* Template for the alert content
|
|
18
|
+
*/
|
|
19
|
+
slotDefault: SlotContent<AlertContext>;
|
|
20
|
+
/**
|
|
21
|
+
* Global template for the alert component
|
|
22
|
+
*/
|
|
23
|
+
slotStructure: SlotContent<AlertContext>;
|
|
24
|
+
/**
|
|
25
|
+
* If `true` the alert is visible to the user
|
|
26
|
+
*/
|
|
27
|
+
visible: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Accessibility close button label
|
|
30
|
+
*/
|
|
31
|
+
ariaCloseButtonLabel: string;
|
|
32
|
+
}
|
|
33
|
+
export interface AlertState extends AlertCommonPropsAndState {
|
|
34
|
+
/**
|
|
35
|
+
* Is `true` when the alert is hidden. Compared to `visible`, this is updated after the transition is executed.
|
|
36
|
+
*/
|
|
37
|
+
hidden: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface AlertProps extends AlertCommonPropsAndState {
|
|
40
|
+
/**
|
|
41
|
+
* Callback called when the alert visibility changed.
|
|
42
|
+
*/
|
|
43
|
+
onVisibleChange: (visible: boolean) => void;
|
|
44
|
+
/**
|
|
45
|
+
* Callback called when the alert is hidden.
|
|
46
|
+
*/
|
|
47
|
+
onHidden: () => void;
|
|
48
|
+
/**
|
|
49
|
+
* Callback called when the alert is shown.
|
|
50
|
+
*/
|
|
51
|
+
onShown: () => void;
|
|
52
|
+
/**
|
|
53
|
+
* The transition function will be executed when the alert is displayed or hidden.
|
|
54
|
+
*
|
|
55
|
+
* Depending on the value of {@link AlertProps.animationOnInit}, the animation can be optionally skipped during the showing process.
|
|
56
|
+
*/
|
|
57
|
+
transition: TransitionFn;
|
|
58
|
+
/**
|
|
59
|
+
* If `true`, alert opening will be animated.
|
|
60
|
+
*
|
|
61
|
+
* Animation is triggered when the `.open()` function is called
|
|
62
|
+
* or the visible prop is changed
|
|
63
|
+
*/
|
|
64
|
+
animationOnInit: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* If `true`, alert closing will be animated.
|
|
67
|
+
*
|
|
68
|
+
* Animation is triggered when clicked on the close button (×),
|
|
69
|
+
* via the `.close()` function or the visible prop is changed
|
|
70
|
+
*/
|
|
71
|
+
animation: boolean;
|
|
72
|
+
}
|
|
73
|
+
export interface AlertApi {
|
|
74
|
+
/**
|
|
75
|
+
* Triggers alert closing programmatically (same as clicking on the close button (×)).
|
|
76
|
+
*/
|
|
77
|
+
close(): void;
|
|
78
|
+
/**
|
|
79
|
+
* Triggers the alert to be displayed for the user.
|
|
80
|
+
*/
|
|
81
|
+
open(): void;
|
|
82
|
+
}
|
|
83
|
+
export interface AlertDirectives {
|
|
84
|
+
/**
|
|
85
|
+
* the transition directive, piloting what is the visual effect of going from hidden to visible
|
|
86
|
+
*/
|
|
87
|
+
transitionDirective: Directive;
|
|
88
|
+
}
|
|
89
|
+
export type AlertWidget = Widget<AlertProps, AlertState, AlertApi, object, AlertDirectives>;
|
|
90
|
+
/**
|
|
91
|
+
* Retrieve a shallow copy of the default alert config
|
|
92
|
+
* @returns the default alert config
|
|
93
|
+
*/
|
|
94
|
+
export declare function getAlertDefaultConfig(): AlertProps;
|
|
95
|
+
/**
|
|
96
|
+
* Create an AlertWidget with given config props
|
|
97
|
+
* @param config - an optional alert config
|
|
98
|
+
* @returns an AlertWidget
|
|
99
|
+
*/
|
|
100
|
+
export declare function createAlert(config?: PropsConfig<AlertProps>): AlertWidget;
|