@agnos-ui/core 0.0.1-alpha.0 → 0.0.1-alpha.2
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 +4 -4
- package/{dist/lib/accordion.d.ts → accordion.d.ts} +17 -22
- package/{dist/lib/accordion.js → accordion.js} +66 -68
- package/{dist/lib/alert.d.ts → alert.d.ts} +2 -1
- package/{dist/lib/alert.js → alert.js} +10 -7
- package/commonProps.d.ts +6 -0
- package/commonProps.js +1 -0
- package/{dist/lib/config.d.ts → config.d.ts} +5 -0
- package/extendWidget.d.ts +3 -0
- package/extendWidget.js +28 -0
- package/{dist/lib/index.d.ts → index.d.ts} +3 -0
- package/{dist/lib/index.js → index.js} +3 -0
- package/{dist/lib/modal → modal}/modal.d.ts +3 -9
- package/{dist/lib/modal → modal}/modal.js +18 -14
- package/package.json +14 -28
- package/{dist/lib/pagination.d.ts → pagination.d.ts} +4 -12
- package/{dist/lib/pagination.js → pagination.js} +1 -1
- package/progressbar.d.ts +87 -0
- package/progressbar.js +78 -0
- package/{dist/lib/rating.d.ts → rating.d.ts} +5 -11
- package/{dist/lib/select.d.ts → select.d.ts} +2 -5
- package/{dist/lib/services → services}/checks.d.ts +5 -0
- package/{dist/lib/services → services}/checks.js +5 -0
- package/{dist/lib/services → services}/index.d.ts +2 -0
- package/{dist/lib/services → services}/index.js +2 -0
- package/services/intersection.d.ts +26 -0
- package/services/intersection.js +47 -0
- package/services/navManager.d.ts +5 -0
- package/services/navManager.js +52 -0
- package/services/sortUtils.d.ts +2 -0
- package/services/sortUtils.js +14 -0
- package/{dist/lib/services → services}/stores.d.ts +60 -23
- package/{dist/lib/services → services}/stores.js +92 -53
- package/{dist/lib/services → services}/writables.d.ts +2 -1
- package/{dist/lib/services → services}/writables.js +15 -1
- package/dist/lib/tsdoc-metadata.json +0 -11
- /package/{dist/lib/config.js → config.js} +0 -0
- /package/{dist/lib/modal → modal}/scrollbars.d.ts +0 -0
- /package/{dist/lib/modal → modal}/scrollbars.js +0 -0
- /package/{dist/lib/pagination.utils.d.ts → pagination.utils.d.ts} +0 -0
- /package/{dist/lib/pagination.utils.js → pagination.utils.js} +0 -0
- /package/{dist/lib/rating.js → rating.js} +0 -0
- /package/{dist/lib/select.js → select.js} +0 -0
- /package/{dist/lib/services → services}/directiveUtils.d.ts +0 -0
- /package/{dist/lib/services → services}/directiveUtils.js +0 -0
- /package/{dist/lib/services → services}/focustrack.d.ts +0 -0
- /package/{dist/lib/services → services}/focustrack.js +0 -0
- /package/{dist/lib/services → services}/portal.d.ts +0 -0
- /package/{dist/lib/services → services}/portal.js +0 -0
- /package/{dist/lib/services → services}/siblingsInert.d.ts +0 -0
- /package/{dist/lib/services → services}/siblingsInert.js +0 -0
- /package/{dist/lib/transitions → transitions}/baseTransitions.d.ts +0 -0
- /package/{dist/lib/transitions → transitions}/baseTransitions.js +0 -0
- /package/{dist/lib/transitions → transitions}/bootstrap/collapse.d.ts +0 -0
- /package/{dist/lib/transitions → transitions}/bootstrap/collapse.js +0 -0
- /package/{dist/lib/transitions → transitions}/bootstrap/fade.d.ts +0 -0
- /package/{dist/lib/transitions → transitions}/bootstrap/fade.js +0 -0
- /package/{dist/lib/transitions → transitions}/bootstrap/index.d.ts +0 -0
- /package/{dist/lib/transitions → transitions}/bootstrap/index.js +0 -0
- /package/{dist/lib/transitions → transitions}/collapse.d.ts +0 -0
- /package/{dist/lib/transitions → transitions}/collapse.js +0 -0
- /package/{dist/lib/transitions → transitions}/cssTransitions.d.ts +0 -0
- /package/{dist/lib/transitions → transitions}/cssTransitions.js +0 -0
- /package/{dist/lib/transitions → transitions}/index.d.ts +0 -0
- /package/{dist/lib/transitions → transitions}/index.js +0 -0
- /package/{dist/lib/transitions → transitions}/simpleClassTransition.d.ts +0 -0
- /package/{dist/lib/transitions → transitions}/simpleClassTransition.js +0 -0
- /package/{dist/lib/transitions → transitions}/utils.d.ts +0 -0
- /package/{dist/lib/transitions → transitions}/utils.js +0 -0
- /package/{dist/lib/types.d.ts → types.d.ts} +0 -0
- /package/{dist/lib/types.js → types.js} +0 -0
- /package/{dist/lib/utils.d.ts → utils.d.ts} +0 -0
- /package/{dist/lib/utils.js → utils.js} +0 -0
package/README.md
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@agnos-ui/core)
|
|
4
4
|
|
|
5
|
-
[AgnosUI](https://amadeusitgroup.github.io/AgnosUI/latest/) is a framework-agnostic widget library with adapters for multiple frameworks:
|
|
5
|
+
[AgnosUI](https://amadeusitgroup.github.io/AgnosUI/latest/) is a framework-agnostic widget library with adapters for multiple frameworks, either [Bootstrap](https://getbootstrap.com/)-based or headless:
|
|
6
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)
|
|
7
|
+
- [Angular](https://www.npmjs.com/package/@agnos-ui/angular), [Angular headless](https://www.npmjs.com/package/@agnos-ui/angular-headless)
|
|
8
|
+
- [React](https://www.npmjs.com/package/@agnos-ui/react), [React headless](https://www.npmjs.com/package/@agnos-ui/react-headless)
|
|
9
|
+
- [Svelte](https://www.npmjs.com/package/@agnos-ui/svelte), [Svelte headless](https://www.npmjs.com/package/@agnos-ui/svelte-headless)
|
|
10
10
|
|
|
11
11
|
This `@agnos-ui/core` package contains the framework-agnostic common code used by the above framework adapters.
|
|
12
12
|
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import type { PropsConfig } from './services';
|
|
2
2
|
import type { TransitionFn } from './transitions';
|
|
3
3
|
import type { Directive, SlotContent, Widget, WidgetSlotContext } from './types';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* Classes to add on the accordion DOM element.
|
|
7
|
-
*/
|
|
8
|
-
accordionClass: string;
|
|
9
|
-
}
|
|
10
|
-
export interface AccordionProps extends AccordionCommonPropsAndState {
|
|
4
|
+
import type { WidgetsCommonPropsAndState } from './commonProps';
|
|
5
|
+
export interface AccordionProps extends WidgetsCommonPropsAndState {
|
|
11
6
|
/**
|
|
12
7
|
* If `true`, only one item at the time can stay open.
|
|
13
8
|
*/
|
|
@@ -44,11 +39,11 @@ export interface AccordionProps extends AccordionCommonPropsAndState {
|
|
|
44
39
|
*/
|
|
45
40
|
itemDisabled: boolean;
|
|
46
41
|
/**
|
|
47
|
-
* If `true`, the accordion-item will be
|
|
42
|
+
* If `true`, the accordion-item will be visible (expanded). Otherwise, it will be hidden (collapsed).
|
|
48
43
|
*
|
|
49
44
|
* It is a prop of the accordion-item.
|
|
50
45
|
*/
|
|
51
|
-
|
|
46
|
+
itemVisible: boolean;
|
|
52
47
|
/**
|
|
53
48
|
* If `true`, accordion-item will be animated.
|
|
54
49
|
*
|
|
@@ -74,13 +69,13 @@ export interface AccordionProps extends AccordionCommonPropsAndState {
|
|
|
74
69
|
*/
|
|
75
70
|
onItemHidden: () => void;
|
|
76
71
|
/**
|
|
77
|
-
* An event fired when the `
|
|
72
|
+
* An event fired when the `visible` value changes.
|
|
78
73
|
*
|
|
79
|
-
* Event payload is the new value of
|
|
74
|
+
* Event payload is the new value of visible.
|
|
80
75
|
*
|
|
81
76
|
* It is a prop of the accordion-item.
|
|
82
77
|
*/
|
|
83
|
-
|
|
78
|
+
onItemVisibleChange: (visible: boolean) => void;
|
|
84
79
|
/**
|
|
85
80
|
* Structure of the accordion-item. The default item structure is: accordion-item
|
|
86
81
|
* contains accordion header and accordion collapse; the accordion header contains the accordion button
|
|
@@ -132,7 +127,7 @@ export interface AccordionProps extends AccordionCommonPropsAndState {
|
|
|
132
127
|
*/
|
|
133
128
|
itemBodyClass: string;
|
|
134
129
|
}
|
|
135
|
-
export interface AccordionState extends
|
|
130
|
+
export interface AccordionState extends WidgetsCommonPropsAndState {
|
|
136
131
|
/**
|
|
137
132
|
* Array containing all the accordion-items contained in the accordion.
|
|
138
133
|
*/
|
|
@@ -140,7 +135,7 @@ export interface AccordionState extends AccordionCommonPropsAndState {
|
|
|
140
135
|
}
|
|
141
136
|
export interface AccordionApi {
|
|
142
137
|
/**
|
|
143
|
-
* Given the itemId, it will return if such item is expanded or not.
|
|
138
|
+
* Given the itemId, it will return if such item is visible (expanded) or not.
|
|
144
139
|
*
|
|
145
140
|
* If the itemId is not a valid id it will return `false`.
|
|
146
141
|
*/
|
|
@@ -174,7 +169,7 @@ export interface AccordionApi {
|
|
|
174
169
|
*/
|
|
175
170
|
collapseAll(): void;
|
|
176
171
|
/**
|
|
177
|
-
* Creates a new
|
|
172
|
+
* Creates a new accordionItem.
|
|
178
173
|
*/
|
|
179
174
|
registerItem(itemConfig?: PropsConfig<AccordionItemProps>): AccordionItemWidget;
|
|
180
175
|
}
|
|
@@ -222,9 +217,9 @@ export interface AccordionItemDirectives {
|
|
|
222
217
|
}
|
|
223
218
|
export interface AccordionItemCommonPropsAndState {
|
|
224
219
|
/**
|
|
225
|
-
* If `true`, the accordion-item will be
|
|
220
|
+
* If `true`, the accordion-item will be visible (expanded). Otherwise, it will be hidden (collapsed).
|
|
226
221
|
*/
|
|
227
|
-
|
|
222
|
+
itemVisible: boolean;
|
|
228
223
|
/**
|
|
229
224
|
* If `true`, the accordion-item will be disabled.
|
|
230
225
|
* It will not react to user's clicks, but still will be possible to toggle programmatically.
|
|
@@ -291,16 +286,16 @@ export interface AccordionItemProps extends AccordionItemCommonPropsAndState {
|
|
|
291
286
|
*/
|
|
292
287
|
onItemHidden: () => void;
|
|
293
288
|
/**
|
|
294
|
-
* An event fired when the `
|
|
289
|
+
* An event fired when the `visible` value changes.
|
|
295
290
|
*
|
|
296
|
-
* Event payload is the new value of
|
|
291
|
+
* Event payload is the new value of visible.
|
|
297
292
|
*/
|
|
298
|
-
|
|
293
|
+
onItemVisibleChange: (visible: boolean) => void;
|
|
299
294
|
}
|
|
300
295
|
export interface AccordionItemState extends AccordionItemCommonPropsAndState {
|
|
301
296
|
/**
|
|
302
|
-
* If `true` the
|
|
303
|
-
* value of the `
|
|
297
|
+
* If `true` the content of the accordion-item collapse should be in DOM. Its value depends on the
|
|
298
|
+
* value of the `itemVisible` and `itemDestroyOnHide`.
|
|
304
299
|
*/
|
|
305
300
|
shouldBeInDOM: boolean;
|
|
306
301
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { bindDirectiveNoArg, bindableDerived, directiveSubscribe, registrationArray, stateStores, typeBoolean, typeFunction, typeString, writablesForProps, } from './services';
|
|
1
|
+
import { bindDirectiveNoArg, bindableDerived, directiveSubscribe, registrationArray, stateStores, typeBoolean, typeFunction, typeString, writablesForProps, normalizeConfigStores, mergeConfigStores, } from './services';
|
|
2
2
|
import { createTransition } from './transitions';
|
|
3
3
|
import { collapseVerticalTransition } from './transitions/bootstrap';
|
|
4
4
|
import { computed, readable, writable } from '@amadeus-it-group/tansu';
|
|
@@ -8,21 +8,19 @@ function getItemId() {
|
|
|
8
8
|
return `accordion-item-${itemId++}`;
|
|
9
9
|
}
|
|
10
10
|
function adjustItemsCloseOthers(items, openItems, oldOpen) {
|
|
11
|
+
let keepOpen;
|
|
11
12
|
if (openItems.length == 2) {
|
|
12
13
|
oldOpen = oldOpen ?? openItems[0];
|
|
13
|
-
|
|
14
|
-
items.forEach((item) => {
|
|
15
|
-
if (item.state$().itemId !== keepOpen && !item.state$().itemCollapsed) {
|
|
16
|
-
item.patch({ itemCollapsed: true });
|
|
17
|
-
}
|
|
18
|
-
});
|
|
14
|
+
keepOpen = openItems.find((id) => id !== oldOpen);
|
|
19
15
|
}
|
|
20
16
|
else if (openItems.length > 2) {
|
|
21
17
|
//this case can happen when you have multiple items open and you toggle the close others
|
|
22
|
-
|
|
18
|
+
keepOpen = openItems[0];
|
|
19
|
+
}
|
|
20
|
+
if (keepOpen) {
|
|
23
21
|
items.forEach((item) => {
|
|
24
|
-
if (item.state$().itemId !== keepOpen &&
|
|
25
|
-
item.patch({
|
|
22
|
+
if (item.state$().itemId !== keepOpen && item.state$().itemVisible) {
|
|
23
|
+
item.patch({ itemVisible: false });
|
|
26
24
|
}
|
|
27
25
|
});
|
|
28
26
|
}
|
|
@@ -35,16 +33,16 @@ const defaultAccordionConfig = {
|
|
|
35
33
|
closeOthers: false,
|
|
36
34
|
onShown: noop,
|
|
37
35
|
onHidden: noop,
|
|
38
|
-
|
|
36
|
+
className: '',
|
|
39
37
|
itemId: '',
|
|
40
38
|
itemDestroyOnHide: false,
|
|
41
39
|
itemDisabled: false,
|
|
42
|
-
|
|
40
|
+
itemVisible: false,
|
|
43
41
|
itemAnimation: true,
|
|
44
42
|
itemTransition: collapseVerticalTransition,
|
|
45
43
|
onItemShown: noop,
|
|
46
44
|
onItemHidden: noop,
|
|
47
|
-
|
|
45
|
+
onItemVisibleChange: noop,
|
|
48
46
|
slotItemStructure: undefined,
|
|
49
47
|
slotItemBody: undefined,
|
|
50
48
|
slotItemHeader: undefined,
|
|
@@ -58,12 +56,12 @@ const defaultItemConfig = {
|
|
|
58
56
|
itemId: defaultAccordionConfig.itemId,
|
|
59
57
|
itemDestroyOnHide: defaultAccordionConfig.itemDestroyOnHide,
|
|
60
58
|
itemDisabled: defaultAccordionConfig.itemDisabled,
|
|
61
|
-
|
|
59
|
+
itemVisible: defaultAccordionConfig.itemVisible,
|
|
62
60
|
itemAnimation: defaultAccordionConfig.itemAnimation,
|
|
63
61
|
itemTransition: defaultAccordionConfig.itemTransition,
|
|
64
62
|
onItemShown: defaultAccordionConfig.onItemShown,
|
|
65
63
|
onItemHidden: defaultAccordionConfig.onItemHidden,
|
|
66
|
-
|
|
64
|
+
onItemVisibleChange: defaultAccordionConfig.onItemVisibleChange,
|
|
67
65
|
slotItemStructure: defaultAccordionConfig.slotItemStructure,
|
|
68
66
|
slotItemBody: defaultAccordionConfig.slotItemBody,
|
|
69
67
|
slotItemHeader: defaultAccordionConfig.slotItemHeader,
|
|
@@ -73,6 +71,7 @@ const defaultItemConfig = {
|
|
|
73
71
|
itemCollapseClass: defaultAccordionConfig.itemCollapseClass,
|
|
74
72
|
itemBodyClass: defaultAccordionConfig.itemBodyClass,
|
|
75
73
|
};
|
|
74
|
+
const accordionItemProps = Object.keys(defaultItemConfig);
|
|
76
75
|
/**
|
|
77
76
|
* Retrieve a shallow copy of the default accordion config
|
|
78
77
|
* @returns the default accordion config
|
|
@@ -87,12 +86,12 @@ const configAccordionValidator = {
|
|
|
87
86
|
itemId: typeString,
|
|
88
87
|
itemDestroyOnHide: typeBoolean,
|
|
89
88
|
itemDisabled: typeBoolean,
|
|
90
|
-
|
|
89
|
+
itemVisible: typeBoolean,
|
|
91
90
|
itemAnimation: typeBoolean,
|
|
92
91
|
itemTransition: typeFunction,
|
|
93
92
|
onItemShown: typeFunction,
|
|
94
93
|
onItemHidden: typeFunction,
|
|
95
|
-
|
|
94
|
+
onItemVisibleChange: typeFunction,
|
|
96
95
|
itemClass: typeString,
|
|
97
96
|
itemHeaderClass: typeString,
|
|
98
97
|
itemButtonClass: typeString,
|
|
@@ -103,12 +102,12 @@ const configItemValidator = {
|
|
|
103
102
|
itemId: typeString,
|
|
104
103
|
itemDestroyOnHide: typeBoolean,
|
|
105
104
|
itemDisabled: typeBoolean,
|
|
106
|
-
|
|
105
|
+
itemVisible: typeBoolean,
|
|
107
106
|
itemAnimation: typeBoolean,
|
|
108
107
|
itemTransition: typeFunction,
|
|
109
108
|
onItemShown: typeFunction,
|
|
110
109
|
onItemHidden: typeFunction,
|
|
111
|
-
|
|
110
|
+
onItemVisibleChange: typeFunction,
|
|
112
111
|
itemClass: typeString,
|
|
113
112
|
itemHeaderClass: typeString,
|
|
114
113
|
itemButtonClass: typeString,
|
|
@@ -116,34 +115,33 @@ const configItemValidator = {
|
|
|
116
115
|
itemBodyClass: typeString,
|
|
117
116
|
};
|
|
118
117
|
function createAccordionItem(accordionOnShown, accordionOnHidden, config) {
|
|
119
|
-
const [{ itemAnimation$, itemTransition$, itemDestroyOnHide$, onItemShown$, onItemHidden$,
|
|
118
|
+
const [{ itemAnimation$, itemTransition$, itemDestroyOnHide$, onItemShown$, onItemHidden$, onItemVisibleChange$, itemVisible$, itemId$: _dirtyItemId$, itemDisabled$, ...stateProps }, patch,] = writablesForProps(defaultItemConfig, config, configItemValidator);
|
|
120
119
|
const initDone$ = writable(false);
|
|
121
120
|
const itemId$ = bindableDerived(readable(noop), [_dirtyItemId$], ([dirtyItemId]) => (dirtyItemId ? dirtyItemId : getItemId()));
|
|
122
121
|
const shouldBeInDOM$ = computed(() => {
|
|
123
122
|
return itemDestroyOnHide$() === false || !itemTransition.state$().hidden;
|
|
124
123
|
});
|
|
125
124
|
const itemTransition = createTransition({
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
onItemShown$()();
|
|
125
|
+
props: {
|
|
126
|
+
transition: itemTransition$,
|
|
127
|
+
visible: itemVisible$,
|
|
128
|
+
onVisibleChange: onItemVisibleChange$,
|
|
129
|
+
animation: itemAnimation$,
|
|
130
|
+
animationOnInit: false,
|
|
131
|
+
initDone: initDone$,
|
|
132
|
+
onHidden: () => {
|
|
133
|
+
accordionOnHidden()(itemId$());
|
|
134
|
+
onItemHidden$()();
|
|
135
|
+
},
|
|
136
|
+
onShown: () => {
|
|
137
|
+
accordionOnShown()(itemId$());
|
|
138
|
+
onItemShown$()();
|
|
139
|
+
},
|
|
142
140
|
},
|
|
143
141
|
});
|
|
144
142
|
return {
|
|
145
143
|
...stateStores({
|
|
146
|
-
|
|
144
|
+
itemVisible$,
|
|
147
145
|
itemId$,
|
|
148
146
|
shouldBeInDOM$,
|
|
149
147
|
itemDisabled$,
|
|
@@ -153,7 +151,7 @@ function createAccordionItem(accordionOnShown, accordionOnHidden, config) {
|
|
|
153
151
|
actions: {
|
|
154
152
|
click: () => {
|
|
155
153
|
if (!itemDisabled$()) {
|
|
156
|
-
|
|
154
|
+
itemVisible$.update((c) => !c);
|
|
157
155
|
}
|
|
158
156
|
},
|
|
159
157
|
},
|
|
@@ -162,13 +160,13 @@ function createAccordionItem(accordionOnShown, accordionOnHidden, config) {
|
|
|
162
160
|
initDone$.set(true);
|
|
163
161
|
},
|
|
164
162
|
collapse: () => {
|
|
165
|
-
|
|
163
|
+
itemVisible$.set(false);
|
|
166
164
|
},
|
|
167
165
|
expand: () => {
|
|
168
|
-
|
|
166
|
+
itemVisible$.set(true);
|
|
169
167
|
},
|
|
170
168
|
toggle: () => {
|
|
171
|
-
|
|
169
|
+
itemVisible$.update((c) => !c);
|
|
172
170
|
},
|
|
173
171
|
},
|
|
174
172
|
directives: { collapseDirective: bindDirectiveNoArg(itemTransition.directives.directive), accordionItemDirective: noop },
|
|
@@ -180,12 +178,31 @@ function createAccordionItem(accordionOnShown, accordionOnHidden, config) {
|
|
|
180
178
|
* @returns a new accordion widget instance
|
|
181
179
|
*/
|
|
182
180
|
export function createAccordion(config) {
|
|
183
|
-
const [{ closeOthers$, onShown$, onHidden$, itemId$, itemAnimation$, itemClass$, itemDisabled$,
|
|
181
|
+
const [{ closeOthers$, onShown$, onHidden$, itemId$, itemAnimation$, itemClass$, itemDisabled$, itemVisible$, itemTransition$, itemDestroyOnHide$, itemBodyClass$, itemButtonClass$, itemCollapseClass$, itemHeaderClass$, onItemVisibleChange$, onItemHidden$, onItemShown$, slotItemStructure$, slotItemBody$, slotItemHeader$, ...stateProps }, patch,] = writablesForProps(defaultAccordionConfig, config, configAccordionValidator);
|
|
182
|
+
const accordionItemConfig = {
|
|
183
|
+
itemId: itemId$,
|
|
184
|
+
itemClass: itemClass$,
|
|
185
|
+
itemAnimation: itemAnimation$,
|
|
186
|
+
itemDisabled: itemDisabled$,
|
|
187
|
+
itemVisible: itemVisible$,
|
|
188
|
+
itemTransition: itemTransition$,
|
|
189
|
+
itemDestroyOnHide: itemDestroyOnHide$,
|
|
190
|
+
itemBodyClass: itemBodyClass$,
|
|
191
|
+
itemButtonClass: itemButtonClass$,
|
|
192
|
+
itemCollapseClass: itemCollapseClass$,
|
|
193
|
+
itemHeaderClass: itemHeaderClass$,
|
|
194
|
+
onItemVisibleChange: onItemVisibleChange$,
|
|
195
|
+
onItemHidden: onItemHidden$,
|
|
196
|
+
onItemShown: onItemShown$,
|
|
197
|
+
slotItemStructure: slotItemStructure$,
|
|
198
|
+
slotItemBody: slotItemBody$,
|
|
199
|
+
slotItemHeader: slotItemHeader$,
|
|
200
|
+
};
|
|
184
201
|
const itemsWidget$ = registrationArray();
|
|
185
202
|
const openItems$ = computed(() => {
|
|
186
203
|
const openItems = [];
|
|
187
204
|
itemsWidget$().forEach((item) => {
|
|
188
|
-
if (
|
|
205
|
+
if (item.state$().itemVisible) {
|
|
189
206
|
openItems.push(item.state$().itemId);
|
|
190
207
|
}
|
|
191
208
|
});
|
|
@@ -197,9 +214,6 @@ export function createAccordion(config) {
|
|
|
197
214
|
adjustItemsCloseOthers(itemsWidget$(), openItems$(), oldOpenItem$());
|
|
198
215
|
oldOpenItem$.set(openItems$()[0]);
|
|
199
216
|
}
|
|
200
|
-
else {
|
|
201
|
-
itemsWidget$();
|
|
202
|
-
}
|
|
203
217
|
});
|
|
204
218
|
const action$ = computed(() => {
|
|
205
219
|
checkCloseOthersAction$();
|
|
@@ -212,7 +226,7 @@ export function createAccordion(config) {
|
|
|
212
226
|
isExpanded: (id) => {
|
|
213
227
|
const item = getItem(itemsWidget$(), id);
|
|
214
228
|
if (item) {
|
|
215
|
-
return
|
|
229
|
+
return item.state$().itemVisible;
|
|
216
230
|
}
|
|
217
231
|
else {
|
|
218
232
|
return false;
|
|
@@ -233,27 +247,11 @@ export function createAccordion(config) {
|
|
|
233
247
|
collapseAll: () => {
|
|
234
248
|
itemsWidget$().forEach((i) => i.api.collapse());
|
|
235
249
|
},
|
|
236
|
-
registerItem: (
|
|
237
|
-
const item = createAccordionItem(onShown$, onHidden$,
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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
|
-
})));
|
|
250
|
+
registerItem: (propsConfig) => {
|
|
251
|
+
const item = createAccordionItem(onShown$, onHidden$, {
|
|
252
|
+
config: mergeConfigStores(accordionItemProps, normalizeConfigStores(accordionItemProps, propsConfig?.config), accordionItemConfig),
|
|
253
|
+
props: propsConfig?.props,
|
|
254
|
+
});
|
|
257
255
|
item.directives.accordionItemDirective = () => ({ destroy: itemsWidget$.register(item) });
|
|
258
256
|
return item;
|
|
259
257
|
},
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import type { WidgetsCommonPropsAndState } from './commonProps';
|
|
1
2
|
import type { PropsConfig } from './services';
|
|
2
3
|
import type { TransitionFn } from './transitions';
|
|
3
4
|
import type { Directive, SlotContent, Widget, WidgetSlotContext } from './types';
|
|
4
5
|
export type AlertContext = WidgetSlotContext<AlertWidget>;
|
|
5
|
-
export interface AlertCommonPropsAndState {
|
|
6
|
+
export interface AlertCommonPropsAndState extends WidgetsCommonPropsAndState {
|
|
6
7
|
/**
|
|
7
8
|
* If `true`, alert can be dismissed by the user.
|
|
8
9
|
* The close button (×) will be displayed and you can be notified of the event with the (close) output.
|
|
@@ -15,6 +15,7 @@ const defaultConfig = {
|
|
|
15
15
|
animation: true,
|
|
16
16
|
animationOnInit: false,
|
|
17
17
|
transition: fadeTransition,
|
|
18
|
+
className: '',
|
|
18
19
|
};
|
|
19
20
|
/**
|
|
20
21
|
* Retrieve a shallow copy of the default alert config
|
|
@@ -35,13 +36,15 @@ const configValidator = {
|
|
|
35
36
|
export function createAlert(config) {
|
|
36
37
|
const [{ transition$, animationOnInit$, animation$, visible$: requestedVisible$, onVisibleChange$, onHidden$, onShown$, ...stateProps }, patch,] = writablesForProps(defaultConfig, config, configValidator);
|
|
37
38
|
const transition = createTransition({
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
props: {
|
|
40
|
+
transition: transition$,
|
|
41
|
+
visible: requestedVisible$,
|
|
42
|
+
animation: animation$,
|
|
43
|
+
animationOnInit: animationOnInit$,
|
|
44
|
+
onVisibleChange: onVisibleChange$,
|
|
45
|
+
onHidden: onHidden$,
|
|
46
|
+
onShown: onShown$,
|
|
47
|
+
},
|
|
45
48
|
});
|
|
46
49
|
const close = () => {
|
|
47
50
|
patch({ visible: false });
|
package/commonProps.d.ts
ADDED
package/commonProps.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -5,6 +5,7 @@ import type { PaginationProps } from './pagination';
|
|
|
5
5
|
import type { RatingProps } from './rating';
|
|
6
6
|
import type { SelectProps } from './select';
|
|
7
7
|
import type { AccordionProps } from './accordion';
|
|
8
|
+
import type { ProgressbarProps } from './progressbar';
|
|
8
9
|
export type Partial2Levels<T> = Partial<{
|
|
9
10
|
[Level1 in keyof T]: Partial<T[Level1]>;
|
|
10
11
|
}>;
|
|
@@ -68,4 +69,8 @@ export interface WidgetsConfig {
|
|
|
68
69
|
* the accordion widget config
|
|
69
70
|
*/
|
|
70
71
|
accordion: AccordionProps;
|
|
72
|
+
/**
|
|
73
|
+
* the progress bar widget config
|
|
74
|
+
*/
|
|
75
|
+
progressbar: ProgressbarProps;
|
|
71
76
|
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ConfigValidator } from './services/stores';
|
|
2
|
+
import type { Widget, WidgetFactory, WidgetProps, WidgetState } from './types';
|
|
3
|
+
export declare const extendWidgetProps: <W extends Widget<object, object, object, object, object>, ExtraProps extends object>(factory: WidgetFactory<W>, extraPropsDefaults: ExtraProps, extraPropsConfig?: ConfigValidator<ExtraProps> | undefined) => WidgetFactory<Widget<WidgetProps<W> & ExtraProps, WidgetState<W> & ExtraProps, W["api"], W["actions"], W["directives"]>>;
|
package/extendWidget.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { batch } from '@amadeus-it-group/tansu';
|
|
2
|
+
import { stateStores, writablesWithDefault } from './services/stores';
|
|
3
|
+
export const extendWidgetProps = (factory, extraPropsDefaults, extraPropsConfig) => (propsConfig) => {
|
|
4
|
+
const extraPropsWritables = writablesWithDefault(extraPropsDefaults, propsConfig, extraPropsConfig);
|
|
5
|
+
const widget = factory(propsConfig);
|
|
6
|
+
return {
|
|
7
|
+
...widget,
|
|
8
|
+
...stateStores({ ...widget.stores, ...extraPropsWritables }),
|
|
9
|
+
patch: (storesValues) => batch(() => {
|
|
10
|
+
let widgetProps;
|
|
11
|
+
for (const [name, value] of Object.entries(storesValues ?? {})) {
|
|
12
|
+
const extraPropsStore = extraPropsWritables[`${name}$`];
|
|
13
|
+
if (extraPropsStore) {
|
|
14
|
+
extraPropsStore.set(value);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
if (!widgetProps) {
|
|
18
|
+
widgetProps = {};
|
|
19
|
+
}
|
|
20
|
+
widgetProps[name] = value;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (widgetProps) {
|
|
24
|
+
widget.patch(widgetProps);
|
|
25
|
+
}
|
|
26
|
+
}),
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PropsConfig } from '../services';
|
|
2
2
|
import type { TransitionFn } from '../transitions';
|
|
3
3
|
import type { Widget, Directive, SlotContent, WidgetSlotContext } from '../types';
|
|
4
|
+
import type { WidgetsCommonPropsAndState } from '../commonProps';
|
|
4
5
|
/**
|
|
5
6
|
* Value present in the {@link ModalBeforeCloseEvent.result|result} property of the {@link ModalProps.onBeforeClose|onBeforeClose} event
|
|
6
7
|
* and returned by the {@link ModalApi.open|open} method, when the modal is closed by a click inside the viewport but outside the modal.
|
|
@@ -18,7 +19,7 @@ export type ModalContext = WidgetSlotContext<ModalWidget>;
|
|
|
18
19
|
/**
|
|
19
20
|
* Properties of the modal widget that are also in the state of the modal.
|
|
20
21
|
*/
|
|
21
|
-
export interface ModalCommonPropsAndState {
|
|
22
|
+
export interface ModalCommonPropsAndState extends WidgetsCommonPropsAndState {
|
|
22
23
|
/**
|
|
23
24
|
* Value of the aria-label attribute to put on the close button.
|
|
24
25
|
*/
|
|
@@ -37,10 +38,6 @@ export interface ModalCommonPropsAndState {
|
|
|
37
38
|
* Otherwise, they stay where the widget is located.
|
|
38
39
|
*/
|
|
39
40
|
container: HTMLElement | null;
|
|
40
|
-
/**
|
|
41
|
-
* Classes to add on the modal DOM element.
|
|
42
|
-
*/
|
|
43
|
-
modalClass: string;
|
|
44
41
|
/**
|
|
45
42
|
* Body of the modal.
|
|
46
43
|
*/
|
|
@@ -280,10 +277,6 @@ export declare function getModalDefaultConfig(): {
|
|
|
280
277
|
* Otherwise, they stay where the widget is located.
|
|
281
278
|
*/
|
|
282
279
|
container: HTMLElement | null;
|
|
283
|
-
/**
|
|
284
|
-
* Classes to add on the modal DOM element.
|
|
285
|
-
*/
|
|
286
|
-
modalClass: string;
|
|
287
280
|
/**
|
|
288
281
|
* Body of the modal.
|
|
289
282
|
*/
|
|
@@ -309,6 +302,7 @@ export declare function getModalDefaultConfig(): {
|
|
|
309
302
|
* Whether the modal should be visible when the transition is completed.
|
|
310
303
|
*/
|
|
311
304
|
visible: boolean;
|
|
305
|
+
className: string;
|
|
312
306
|
};
|
|
313
307
|
/**
|
|
314
308
|
* Creates a new modal widget instance.
|
|
@@ -24,7 +24,7 @@ const defaultConfig = {
|
|
|
24
24
|
closeButton: true,
|
|
25
25
|
closeOnOutsideClick: true,
|
|
26
26
|
container: typeof window !== 'undefined' ? document.body : null,
|
|
27
|
-
|
|
27
|
+
className: '',
|
|
28
28
|
modalTransition: fadeTransition,
|
|
29
29
|
onBeforeClose: noop,
|
|
30
30
|
onVisibleChange: noop,
|
|
@@ -65,22 +65,26 @@ const modalsAction$ = computed(() => {
|
|
|
65
65
|
export const createModal = (config$) => {
|
|
66
66
|
const [{ animation$, backdrop$, backdropTransition$, closeOnOutsideClick$, container$, modalTransition$, onBeforeClose$, onVisibleChange$, onHidden$, onShown$, visible$: requestedVisible$, ...stateProps }, patch,] = writablesForProps(defaultConfig, config$);
|
|
67
67
|
const modalTransition = createTransition({
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
68
|
+
props: {
|
|
69
|
+
transition: modalTransition$,
|
|
70
|
+
visible: requestedVisible$,
|
|
71
|
+
animation: animation$,
|
|
72
|
+
animationOnInit: animation$,
|
|
73
|
+
onVisibleChange: onVisibleChange$,
|
|
74
|
+
// TODO: for onHidden and onShown, should we combine with information from the backdrop transition?
|
|
75
|
+
// (especially in case one of the two transitions takes more time than the other)
|
|
76
|
+
onHidden: onHidden$,
|
|
77
|
+
onShown: onShown$,
|
|
78
|
+
},
|
|
77
79
|
});
|
|
78
80
|
const visible$ = modalTransition.stores.visible$;
|
|
79
81
|
const backdropTransition = createTransition({
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
props: {
|
|
83
|
+
transition: backdropTransition$,
|
|
84
|
+
visible: requestedVisible$,
|
|
85
|
+
animation: animation$,
|
|
86
|
+
animationOnInit: animation$,
|
|
87
|
+
},
|
|
84
88
|
});
|
|
85
89
|
const transitioning$ = computed(() => modalTransition.stores.transitioning$() || (backdrop$() && backdropTransition.stores.transitioning$()));
|
|
86
90
|
const hidden$ = computed(() => !transitioning$() && !visible$());
|