@agnos-ui/core 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/accordion-BaWN0_n-.js +330 -0
- package/accordion-BuIgxZ0S.cjs +329 -0
- package/alert-C4jCg9Pl.cjs +8 -0
- package/alert-Dlf-BV98.js +9 -0
- package/common-DRdsw5m8.js +76 -0
- package/common-nJRMXbwj.cjs +75 -0
- package/components/accordion/accordion.d.ts +38 -49
- package/components/accordion/index.cjs +7 -0
- package/components/accordion/index.js +7 -1
- package/components/alert/alert.d.ts +3 -12
- package/components/alert/common.d.ts +4 -13
- package/components/alert/index.cjs +10 -0
- package/components/alert/index.js +10 -2
- package/components/modal/index.cjs +7 -0
- package/components/modal/index.js +7 -1
- package/components/modal/modal.d.ts +7 -49
- package/components/pagination/index.cjs +5 -0
- package/components/pagination/index.d.ts +0 -1
- package/components/pagination/index.js +5 -2
- package/components/pagination/pagination.d.ts +68 -139
- package/components/progressbar/index.cjs +5 -0
- package/components/progressbar/index.js +5 -1
- package/components/progressbar/progressbar.d.ts +6 -22
- package/components/rating/index.cjs +5 -0
- package/components/rating/index.js +5 -1
- package/components/rating/rating.d.ts +16 -11
- package/components/select/index.cjs +6 -0
- package/components/select/index.js +6 -1
- package/components/select/select.d.ts +15 -33
- package/components/slider/index.cjs +5 -0
- package/components/slider/index.js +5 -1
- package/components/slider/slider.d.ts +29 -35
- package/components/toast/index.cjs +5 -0
- package/components/toast/index.js +5 -1
- package/components/toast/toast.d.ts +11 -8
- package/config.cjs +38 -0
- package/config.d.ts +1 -1
- package/config.js +35 -50
- package/directive-BTSEYLF3.cjs +404 -0
- package/directive-DCYlDznf.js +405 -0
- package/func-DR0n-ShK.js +7 -0
- package/func-Qd3cD9a3.cjs +6 -0
- package/index.cjs +119 -0
- package/index.d.ts +1 -1
- package/index.js +119 -33
- package/modal-BI2qUu1M.js +251 -0
- package/modal-rzMpATf5.cjs +250 -0
- package/package.json +29 -19
- package/pagination--GkwduJn.js +263 -0
- package/pagination-EWSWQT1I.cjs +262 -0
- package/progressbar-DH7DHYMp.cjs +83 -0
- package/progressbar-DuRX7_my.js +84 -0
- package/promise-BMJ8qhA8.cjs +118 -0
- package/promise-CY2U8bTP.js +119 -0
- package/rating-BR5wD7y2.js +173 -0
- package/rating-CmuYUSxy.cjs +172 -0
- package/select-BCs6HQWn.js +358 -0
- package/select-CCIKn8WR.cjs +357 -0
- package/services/extendWidget.cjs +32 -0
- package/services/extendWidget.d.ts +2 -1
- package/services/extendWidget.js +31 -34
- package/services/floatingUI.cjs +131 -0
- package/services/floatingUI.d.ts +30 -14
- package/services/floatingUI.js +128 -102
- package/services/focustrack.cjs +47 -0
- package/services/focustrack.js +45 -44
- package/services/hash.cjs +15 -0
- package/services/hash.js +14 -12
- package/services/intersection.cjs +53 -0
- package/services/intersection.js +48 -50
- package/services/matchMedia.cjs +13 -0
- package/services/matchMedia.d.ts +7 -0
- package/services/matchMedia.js +13 -0
- package/services/navManager.cjs +196 -0
- package/services/navManager.d.ts +9 -9
- package/services/navManager.js +186 -168
- package/services/portal.cjs +43 -0
- package/services/portal.js +41 -42
- package/services/resizeObserver.cjs +32 -0
- package/services/resizeObserver.d.ts +1 -1
- package/services/resizeObserver.js +31 -28
- package/services/siblingsInert.cjs +40 -0
- package/services/siblingsInert.js +31 -31
- package/services/transitions/baseTransitions.cjs +171 -0
- package/services/transitions/baseTransitions.d.ts +16 -16
- package/services/transitions/baseTransitions.js +159 -170
- package/services/transitions/collapse.cjs +44 -0
- package/services/transitions/collapse.js +41 -49
- package/services/transitions/cssTransitions.cjs +32 -0
- package/services/transitions/cssTransitions.d.ts +2 -1
- package/services/transitions/cssTransitions.js +29 -39
- package/services/transitions/simpleClassTransition.cjs +31 -0
- package/services/transitions/simpleClassTransition.js +30 -41
- package/slider-CA_fszn7.js +536 -0
- package/slider-DsLvT87U.cjs +535 -0
- package/toast-8tWp6x89.js +63 -0
- package/toast-Aw8o0Iwe.cjs +62 -0
- package/types.cjs +12 -0
- package/types.d.ts +21 -1
- package/types.js +11 -13
- package/utils/directive.cjs +26 -0
- package/utils/directive.d.ts +148 -5
- package/utils/directive.js +25 -205
- package/utils/internal/dom.d.ts +43 -4
- package/utils/internal/promise.d.ts +2 -2
- package/utils/internal/ssrHTMLElement.d.ts +7 -0
- package/utils/stores.cjs +163 -0
- package/utils/stores.d.ts +9 -17
- package/utils/stores.js +149 -284
- package/utils/writables.cjs +13 -0
- package/utils/writables.js +12 -71
- package/writables-D46sFgGK.cjs +85 -0
- package/writables-DoU_XYTX.js +86 -0
- package/components/accordion/accordion.js +0 -264
- package/components/alert/alert.js +0 -22
- package/components/alert/common.js +0 -69
- package/components/commonProps.js +0 -1
- package/components/modal/modal.js +0 -186
- package/components/pagination/bootstrap.d.ts +0 -8
- package/components/pagination/bootstrap.js +0 -110
- package/components/pagination/pagination.js +0 -195
- package/components/progressbar/progressbar.js +0 -78
- package/components/rating/rating.js +0 -137
- package/components/select/select.js +0 -297
- package/components/slider/slider.js +0 -420
- package/components/toast/toast.js +0 -43
- package/services/transitions/bootstrap/collapse.d.ts +0 -2
- package/services/transitions/bootstrap/collapse.js +0 -15
- package/services/transitions/bootstrap/fade.d.ts +0 -1
- package/services/transitions/bootstrap/fade.js +0 -7
- package/services/transitions/bootstrap.d.ts +0 -2
- package/services/transitions/bootstrap.js +0 -2
- package/utils/internal/checks.js +0 -60
- package/utils/internal/dom.js +0 -82
- package/utils/internal/func.js +0 -11
- package/utils/internal/isFocusable.js +0 -37
- package/utils/internal/math.js +0 -13
- package/utils/internal/promise.js +0 -169
- package/utils/internal/scrollbars.js +0 -33
- package/utils/internal/sort.js +0 -28
- package/utils/internal/textDirection.js +0 -7
- package/utils/internal/traversal.js +0 -105
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
// Utility functions
|
|
2
|
-
function _applyPagination(page, maxSize) {
|
|
3
|
-
const pp = Math.ceil(page / maxSize) - 1;
|
|
4
|
-
const start = pp * maxSize;
|
|
5
|
-
// console.log('start', start, 'pp', pp, 'page', page, 'maxSize', maxSize);
|
|
6
|
-
const end = start + maxSize;
|
|
7
|
-
return [start, end];
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Appends ellipses and first/last page number to the displayed pages
|
|
11
|
-
* @param start - the first page number
|
|
12
|
-
* @param end - the last page number
|
|
13
|
-
* @param ellipses - apply ellipses
|
|
14
|
-
* @param pages - the pages to apply the function to
|
|
15
|
-
* @param pageCount - the total number of pages
|
|
16
|
-
*/
|
|
17
|
-
function _applyEllipses(start, end, ellipses, pages, pageCount) {
|
|
18
|
-
if (ellipses) {
|
|
19
|
-
if (start > 0) {
|
|
20
|
-
// The first page will always be included. If the displayed range
|
|
21
|
-
// starts after the third page, then add ellipsis. But if the range
|
|
22
|
-
// starts on the third page, then add the second page instead of
|
|
23
|
-
// an ellipsis, because the ellipsis would only hide a single page.
|
|
24
|
-
if (start > 2) {
|
|
25
|
-
pages.unshift(-1);
|
|
26
|
-
}
|
|
27
|
-
else if (start === 2) {
|
|
28
|
-
pages.unshift(2);
|
|
29
|
-
}
|
|
30
|
-
pages.unshift(1);
|
|
31
|
-
}
|
|
32
|
-
if (end < pageCount) {
|
|
33
|
-
// The last page will always be included. If the displayed range
|
|
34
|
-
// ends before the third-last page, then add ellipsis. But if the range
|
|
35
|
-
// ends on third-last page, then add the second-last page instead of
|
|
36
|
-
// an ellipsis, because the ellipsis would only hide a single page.
|
|
37
|
-
if (end < pageCount - 2) {
|
|
38
|
-
pages.push(-1);
|
|
39
|
-
}
|
|
40
|
-
else if (end === pageCount - 2) {
|
|
41
|
-
pages.push(pageCount - 1);
|
|
42
|
-
}
|
|
43
|
-
pages.push(pageCount);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Rotates page numbers based on maxSize items visible.
|
|
49
|
-
* Currently selected page stays in the middle:
|
|
50
|
-
*
|
|
51
|
-
* Ex. for selected page = 6:
|
|
52
|
-
* [5,*6*,7] for maxSize = 3
|
|
53
|
-
* [4,5,*6*,7] for maxSize = 4
|
|
54
|
-
*
|
|
55
|
-
* @param page - the page number
|
|
56
|
-
* @param maxSize - the max size
|
|
57
|
-
* @param pageCount - the page count
|
|
58
|
-
* @returns the rotated page numbers
|
|
59
|
-
*/
|
|
60
|
-
function _applyRotation(page, maxSize, pageCount) {
|
|
61
|
-
let start = 0;
|
|
62
|
-
let end = pageCount;
|
|
63
|
-
const leftOffset = Math.floor(maxSize / 2);
|
|
64
|
-
const rightOffset = maxSize % 2 === 0 ? leftOffset - 1 : leftOffset;
|
|
65
|
-
if (page <= leftOffset) {
|
|
66
|
-
// very beginning, no rotation -> [0..maxSize]
|
|
67
|
-
end = maxSize;
|
|
68
|
-
}
|
|
69
|
-
else if (pageCount - page < leftOffset) {
|
|
70
|
-
// very end, no rotation -> [len-maxSize..len]
|
|
71
|
-
start = pageCount - maxSize;
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
// rotate
|
|
75
|
-
start = page - leftOffset - 1;
|
|
76
|
-
end = page + rightOffset;
|
|
77
|
-
}
|
|
78
|
-
return [start, end];
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* This is the pagination algorithm used by ng-bootstrap. While this is not the default implementation of our widget, we export it to ease the migration from ng-bootstrap pagination.
|
|
82
|
-
* @param maxSize - the max size
|
|
83
|
-
* @param rotate - rotate the pages
|
|
84
|
-
* @param ellipses - enable ellipses
|
|
85
|
-
* @returns the pages
|
|
86
|
-
*/
|
|
87
|
-
export function ngBootstrapPagination(maxSize, rotate, ellipses) {
|
|
88
|
-
return function (page, pageCount) {
|
|
89
|
-
let pages = [];
|
|
90
|
-
for (let i = 1; i <= pageCount; i++) {
|
|
91
|
-
pages.push(i);
|
|
92
|
-
}
|
|
93
|
-
// apply maxSize if necessary
|
|
94
|
-
if (maxSize > 0 && pageCount > maxSize) {
|
|
95
|
-
let start = 0;
|
|
96
|
-
let end = pageCount;
|
|
97
|
-
// either paginating or rotating page numbers
|
|
98
|
-
if (rotate) {
|
|
99
|
-
[start, end] = _applyRotation(page, maxSize, pageCount);
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
[start, end] = _applyPagination(page, maxSize);
|
|
103
|
-
}
|
|
104
|
-
pages = pages.slice(start, end);
|
|
105
|
-
// adding ellipses
|
|
106
|
-
_applyEllipses(start, end, ellipses, pages, pageCount);
|
|
107
|
-
}
|
|
108
|
-
return pages;
|
|
109
|
-
};
|
|
110
|
-
}
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import { computed } from '@amadeus-it-group/tansu';
|
|
2
|
-
import { INVALID_VALUE } from '../../types';
|
|
3
|
-
import { bindableProp, stateStores, writablesForProps } from '../../utils/stores';
|
|
4
|
-
import { clamp, isNumber } from '../../utils/internal/checks';
|
|
5
|
-
import { typeBoolean, typeFunction, typeNumber, typeString } from '../../utils/writables';
|
|
6
|
-
import { noop } from '../../utils/internal/func';
|
|
7
|
-
const PAGE_LINK_DEFAULT = '#';
|
|
8
|
-
const defaultConfig = {
|
|
9
|
-
page: 1,
|
|
10
|
-
collectionSize: 0,
|
|
11
|
-
pageSize: 10,
|
|
12
|
-
disabled: false,
|
|
13
|
-
directionLinks: true,
|
|
14
|
-
boundaryLinks: false,
|
|
15
|
-
size: null,
|
|
16
|
-
onPageChange: noop,
|
|
17
|
-
pagesFactory: (page, pageCount) => {
|
|
18
|
-
// TODO extract this for testing
|
|
19
|
-
const pages = [];
|
|
20
|
-
for (let i = 1; i <= pageCount; i++) {
|
|
21
|
-
pages.push(i);
|
|
22
|
-
}
|
|
23
|
-
return pages;
|
|
24
|
-
},
|
|
25
|
-
ariaLabel: 'Page navigation',
|
|
26
|
-
activeLabel: '(current)',
|
|
27
|
-
ariaPageLabel: (processPage, pageCount) => `Page ${processPage} of ${pageCount}`,
|
|
28
|
-
ariaFirstLabel: 'Action link for first page',
|
|
29
|
-
ariaPreviousLabel: 'Action link for previous page',
|
|
30
|
-
ariaNextLabel: 'Action link for next page',
|
|
31
|
-
ariaLastLabel: 'Action link for last page',
|
|
32
|
-
className: '',
|
|
33
|
-
slotEllipsis: '…',
|
|
34
|
-
slotFirst: '«',
|
|
35
|
-
slotPrevious: '‹',
|
|
36
|
-
slotNext: '›',
|
|
37
|
-
slotLast: '»',
|
|
38
|
-
slotPages: undefined,
|
|
39
|
-
slotStructure: undefined,
|
|
40
|
-
slotNumberLabel: ({ displayedPage }) => `${displayedPage}`,
|
|
41
|
-
pageLink: (_page) => PAGE_LINK_DEFAULT,
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Returns a shallow copy of the default pagination config
|
|
45
|
-
* @returns a copy of the default config
|
|
46
|
-
*/
|
|
47
|
-
export function getPaginationDefaultConfig() {
|
|
48
|
-
return { ...defaultConfig };
|
|
49
|
-
}
|
|
50
|
-
const configValidator = {
|
|
51
|
-
page: typeNumber,
|
|
52
|
-
collectionSize: typeNumber,
|
|
53
|
-
pageSize: typeNumber,
|
|
54
|
-
disabled: typeBoolean,
|
|
55
|
-
directionLinks: typeBoolean,
|
|
56
|
-
boundaryLinks: typeBoolean,
|
|
57
|
-
size: { normalizeValue: (value) => (value === 'lg' || value === 'sm' || value === null ? value : INVALID_VALUE) },
|
|
58
|
-
onPageChange: typeFunction,
|
|
59
|
-
pagesFactory: typeFunction,
|
|
60
|
-
ariaLabel: typeString,
|
|
61
|
-
activeLabel: typeString,
|
|
62
|
-
ariaPageLabel: typeFunction,
|
|
63
|
-
ariaFirstLabel: typeString,
|
|
64
|
-
ariaPreviousLabel: typeString,
|
|
65
|
-
ariaNextLabel: typeString,
|
|
66
|
-
ariaLastLabel: typeString,
|
|
67
|
-
className: typeString,
|
|
68
|
-
pageLink: typeFunction,
|
|
69
|
-
};
|
|
70
|
-
/**
|
|
71
|
-
* Create a PaginationWidget with given config props
|
|
72
|
-
* @param config - an optional pagination config
|
|
73
|
-
* @returns a PaginationWidget
|
|
74
|
-
*/
|
|
75
|
-
export function createPagination(config) {
|
|
76
|
-
const [{
|
|
77
|
-
// dirty inputs that need adjustment:
|
|
78
|
-
page$: _dirtyPage$,
|
|
79
|
-
// clean inputs with value validation:
|
|
80
|
-
collectionSize$, pageSize$, onPageChange$, pagesFactory$, ariaPageLabel$, pageLink$, ...stateProps }, patch,] = writablesForProps(defaultConfig, config, configValidator);
|
|
81
|
-
// computed
|
|
82
|
-
// nb total of Pages.
|
|
83
|
-
const pageCount$ = computed(() => {
|
|
84
|
-
let pageCount = Math.ceil(collectionSize$() / pageSize$());
|
|
85
|
-
// Here we choose to always display a page when collection size is 0
|
|
86
|
-
if (!isNumber(pageCount) || pageCount < 1) {
|
|
87
|
-
pageCount = 1;
|
|
88
|
-
}
|
|
89
|
-
return pageCount;
|
|
90
|
-
});
|
|
91
|
-
// current page
|
|
92
|
-
const page$ = bindableProp(_dirtyPage$, onPageChange$, (dirtyPage) => clamp(dirtyPage, pageCount$(), 1));
|
|
93
|
-
const pages$ = computed(() => pagesFactory$()(page$(), pageCount$()));
|
|
94
|
-
const nextDisabled$ = computed(() => page$() === pageCount$() || stateProps.disabled$());
|
|
95
|
-
const previousDisabled$ = computed(() => page$() === 1 || stateProps.disabled$());
|
|
96
|
-
const pagesLabel$ = computed(() => {
|
|
97
|
-
const ariaPageLabel = ariaPageLabel$();
|
|
98
|
-
const pageCount = pageCount$();
|
|
99
|
-
return pages$().map((page) => ariaPageLabel(page, pageCount));
|
|
100
|
-
});
|
|
101
|
-
const pagesHrefs$ = computed(() => {
|
|
102
|
-
const pageLinkFactory = pageLink$();
|
|
103
|
-
const pageCount = pageCount$();
|
|
104
|
-
return Array.from({ length: pageCount }, (_, index) => pageLinkFactory(index + 1));
|
|
105
|
-
});
|
|
106
|
-
const directionsHrefs$ = computed(() => {
|
|
107
|
-
const pagesHrefs = pagesHrefs$();
|
|
108
|
-
const pageIndex = page$() - 1;
|
|
109
|
-
return {
|
|
110
|
-
previous: pagesHrefs.at(pageIndex > 0 ? pageIndex - 1 : 0),
|
|
111
|
-
next: pagesHrefs.at(pageIndex + 1) ?? pagesHrefs.at(-1),
|
|
112
|
-
};
|
|
113
|
-
});
|
|
114
|
-
/**
|
|
115
|
-
* Stop event propagation when href is the default value;
|
|
116
|
-
* Update page number when navigation is in the same tab and stop the event propagation;
|
|
117
|
-
* For navigations outside current browser tab let the default behavior, without updating the page number;
|
|
118
|
-
* @param pageNumber current page number
|
|
119
|
-
* @param event UI event triggered when page changed
|
|
120
|
-
* @param pageNavigationHandler change handler callback for navigation elements
|
|
121
|
-
*/
|
|
122
|
-
function handleNavigation(pageNumber, event, pageNavigationHandler) {
|
|
123
|
-
if (pagesHrefs$()[pageNumber - 1] === PAGE_LINK_DEFAULT) {
|
|
124
|
-
event?.preventDefault();
|
|
125
|
-
}
|
|
126
|
-
if (!event || !(event.ctrlKey || event.metaKey)) {
|
|
127
|
-
event?.preventDefault();
|
|
128
|
-
if (pageNavigationHandler) {
|
|
129
|
-
page$.update(pageNavigationHandler);
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
page$.set(pageNumber);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return {
|
|
137
|
-
...stateStores({
|
|
138
|
-
pageCount$,
|
|
139
|
-
page$,
|
|
140
|
-
pages$,
|
|
141
|
-
nextDisabled$,
|
|
142
|
-
previousDisabled$,
|
|
143
|
-
pagesLabel$,
|
|
144
|
-
pagesHrefs$,
|
|
145
|
-
directionsHrefs$,
|
|
146
|
-
...stateProps,
|
|
147
|
-
}),
|
|
148
|
-
patch,
|
|
149
|
-
actions: {
|
|
150
|
-
/**
|
|
151
|
-
* Set the current page pageNumber (starting from 1)
|
|
152
|
-
* @param pageNumber - Current page number to set.
|
|
153
|
-
* Value is normalized between 1 and the number of page
|
|
154
|
-
* @param event UI event that triggered the select
|
|
155
|
-
*/
|
|
156
|
-
select(pageNumber, event) {
|
|
157
|
-
handleNavigation(pageNumber, event);
|
|
158
|
-
},
|
|
159
|
-
/**
|
|
160
|
-
* Select the first page
|
|
161
|
-
* @param event Event triggering the action
|
|
162
|
-
*/
|
|
163
|
-
first(event) {
|
|
164
|
-
handleNavigation(1, event);
|
|
165
|
-
},
|
|
166
|
-
/**
|
|
167
|
-
* Select the previous page
|
|
168
|
-
* @param event Event triggering the action
|
|
169
|
-
*/
|
|
170
|
-
previous(event) {
|
|
171
|
-
handleNavigation(page$() - 1, event, (page) => page - 1);
|
|
172
|
-
},
|
|
173
|
-
/**
|
|
174
|
-
* Select the next page
|
|
175
|
-
* @param event Event triggering the action
|
|
176
|
-
*/
|
|
177
|
-
next(event) {
|
|
178
|
-
handleNavigation(page$() + 1, event, (page) => page + 1);
|
|
179
|
-
},
|
|
180
|
-
/**
|
|
181
|
-
* Select the last page
|
|
182
|
-
* @param event Event triggering the action
|
|
183
|
-
*/
|
|
184
|
-
last(event) {
|
|
185
|
-
handleNavigation(pageCount$(), event);
|
|
186
|
-
},
|
|
187
|
-
},
|
|
188
|
-
api: {
|
|
189
|
-
isEllipsis(pageNumber) {
|
|
190
|
-
return pageNumber === -1;
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
directives: {},
|
|
194
|
-
};
|
|
195
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { clamp } from '../../utils/internal/checks';
|
|
2
|
-
import { typeBoolean, typeFunction, typeNumber, typeString } from '../../utils/writables';
|
|
3
|
-
import { stateStores, writablesForProps } from '../../utils/stores';
|
|
4
|
-
import { computed } from '@amadeus-it-group/tansu';
|
|
5
|
-
const defaultConfig = {
|
|
6
|
-
min: 0,
|
|
7
|
-
max: 100,
|
|
8
|
-
value: 0,
|
|
9
|
-
ariaLabel: 'Progressbar',
|
|
10
|
-
className: '',
|
|
11
|
-
slotStructure: undefined,
|
|
12
|
-
slotDefault: undefined,
|
|
13
|
-
height: '',
|
|
14
|
-
striped: false,
|
|
15
|
-
animated: false,
|
|
16
|
-
ariaValueTextFn: () => undefined,
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Retrieve a shallow copy of the default Progressbar config
|
|
20
|
-
* @returns the default Progressbar config
|
|
21
|
-
*/
|
|
22
|
-
export function getProgressbarDefaultConfig() {
|
|
23
|
-
return { ...defaultConfig };
|
|
24
|
-
}
|
|
25
|
-
const configValidator = {
|
|
26
|
-
min: typeNumber,
|
|
27
|
-
max: typeNumber,
|
|
28
|
-
value: typeNumber,
|
|
29
|
-
ariaLabel: typeString,
|
|
30
|
-
className: typeString,
|
|
31
|
-
height: typeString,
|
|
32
|
-
striped: typeBoolean,
|
|
33
|
-
animated: typeBoolean,
|
|
34
|
-
ariaValueTextFn: typeFunction,
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Create an ProgressbarWidget with given config props
|
|
38
|
-
* @param config - an optional progress bar config
|
|
39
|
-
* @returns an ProgressbarWidget
|
|
40
|
-
*/
|
|
41
|
-
export function createProgressbar(config) {
|
|
42
|
-
const [{
|
|
43
|
-
// dirty inputs that need adjustment:
|
|
44
|
-
max$: _dirtyMaximum$, value$: _dirtyValue$,
|
|
45
|
-
// clean inputs
|
|
46
|
-
min$, ariaValueTextFn$, ...stateProps }, patch,] = writablesForProps(defaultConfig, config, configValidator);
|
|
47
|
-
const max$ = computed(() => Math.max(min$(), _dirtyMaximum$()));
|
|
48
|
-
const value$ = computed(() => clamp(_dirtyValue$(), max$(), min$()));
|
|
49
|
-
const percentage$ = computed(() => {
|
|
50
|
-
const max = max$();
|
|
51
|
-
const min = min$();
|
|
52
|
-
if (max > min) {
|
|
53
|
-
return clamp(((value$() - min) * 100) / (max - min), 100, 0);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
return 0;
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
const started$ = computed(() => value$() > min$());
|
|
60
|
-
const finished$ = computed(() => value$() === max$());
|
|
61
|
-
const ariaValueText$ = computed(() => ariaValueTextFn$()(value$(), min$(), max$()));
|
|
62
|
-
return {
|
|
63
|
-
...stateStores({
|
|
64
|
-
min$,
|
|
65
|
-
max$,
|
|
66
|
-
value$,
|
|
67
|
-
percentage$,
|
|
68
|
-
started$,
|
|
69
|
-
finished$,
|
|
70
|
-
ariaValueText$,
|
|
71
|
-
...stateProps,
|
|
72
|
-
}),
|
|
73
|
-
patch,
|
|
74
|
-
api: {},
|
|
75
|
-
directives: {},
|
|
76
|
-
actions: {},
|
|
77
|
-
};
|
|
78
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { computed, writable } from '@amadeus-it-group/tansu';
|
|
2
|
-
import { INVALID_VALUE } from '../../types';
|
|
3
|
-
import { bindableProp, stateStores, writablesForProps } from '../../utils/stores';
|
|
4
|
-
import { clamp, isNumber } from '../../utils/internal/checks';
|
|
5
|
-
import { typeBoolean, typeFunction, typeNumber, typeString } from '../../utils/writables';
|
|
6
|
-
import { noop } from '../../utils/internal/func';
|
|
7
|
-
const defaultConfig = {
|
|
8
|
-
rating: 0,
|
|
9
|
-
tabindex: 0,
|
|
10
|
-
maxRating: 10,
|
|
11
|
-
disabled: false,
|
|
12
|
-
readonly: false,
|
|
13
|
-
resettable: true,
|
|
14
|
-
ariaValueTextFn: (rating, maxRating) => `${rating} out of ${maxRating}`,
|
|
15
|
-
onHover: noop,
|
|
16
|
-
onLeave: noop,
|
|
17
|
-
onRatingChange: noop,
|
|
18
|
-
className: '',
|
|
19
|
-
slotStar: ({ fill }) => String.fromCharCode(fill === 100 ? 9733 : 9734),
|
|
20
|
-
ariaLabel: 'Rating',
|
|
21
|
-
ariaLabelledBy: '',
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Returns a shallow copy of the default rating config.
|
|
25
|
-
* @returns a copy of the default config
|
|
26
|
-
*/
|
|
27
|
-
export function getRatingDefaultConfig() {
|
|
28
|
-
return { ...defaultConfig };
|
|
29
|
-
}
|
|
30
|
-
// TODO export normalize function in utils and test them.
|
|
31
|
-
const configValidator = {
|
|
32
|
-
rating: typeNumber,
|
|
33
|
-
tabindex: typeNumber,
|
|
34
|
-
maxRating: { normalizeValue: (value) => (isNumber(value) ? Math.max(0, value) : INVALID_VALUE) },
|
|
35
|
-
disabled: typeBoolean,
|
|
36
|
-
readonly: typeBoolean,
|
|
37
|
-
resettable: typeBoolean,
|
|
38
|
-
ariaValueTextFn: typeFunction,
|
|
39
|
-
onHover: typeFunction,
|
|
40
|
-
onLeave: typeFunction,
|
|
41
|
-
onRatingChange: typeFunction,
|
|
42
|
-
className: typeString,
|
|
43
|
-
ariaLabel: typeString,
|
|
44
|
-
ariaLabelledBy: typeString,
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Create a RatingWidget with given config props
|
|
48
|
-
* @param config - an optional alert config
|
|
49
|
-
* @returns a RatingWidget
|
|
50
|
-
*/
|
|
51
|
-
export function createRating(config) {
|
|
52
|
-
const [{
|
|
53
|
-
// dirty inputs that need adjustment:
|
|
54
|
-
rating$: _dirtyRating$, tabindex$: _dirtyTabindex$,
|
|
55
|
-
// clean inputs with value validation:
|
|
56
|
-
ariaValueTextFn$, onHover$, onLeave$, onRatingChange$, ...stateProps }, patch,] = writablesForProps(defaultConfig, config, configValidator);
|
|
57
|
-
const { maxRating$, disabled$, readonly$, resettable$ } = stateProps;
|
|
58
|
-
// clean inputs adjustment to valid range
|
|
59
|
-
const tabindex$ = computed(() => (disabled$() ? -1 : _dirtyTabindex$()));
|
|
60
|
-
const rating$ = bindableProp(_dirtyRating$, onRatingChange$, (dirtyRating) => clamp(dirtyRating, maxRating$()));
|
|
61
|
-
// internal inputs
|
|
62
|
-
const _hoveredRating$ = writable(0);
|
|
63
|
-
// computed
|
|
64
|
-
const isInteractive$ = computed(() => !disabled$() && !readonly$());
|
|
65
|
-
const visibleRating$ = computed(() => {
|
|
66
|
-
const hoveredRating = _hoveredRating$();
|
|
67
|
-
return hoveredRating !== 0 ? hoveredRating : rating$();
|
|
68
|
-
});
|
|
69
|
-
const ariaValueText$ = computed(() => ariaValueTextFn$()(visibleRating$(), maxRating$()));
|
|
70
|
-
const stars$ = computed(() => {
|
|
71
|
-
const visibleRating = visibleRating$();
|
|
72
|
-
return Array.from({ length: maxRating$() }, (_v, i) => ({
|
|
73
|
-
fill: Math.round(Math.max(Math.min(visibleRating - i, 1), 0) * 100),
|
|
74
|
-
index: i,
|
|
75
|
-
}));
|
|
76
|
-
});
|
|
77
|
-
return {
|
|
78
|
-
...stateStores({
|
|
79
|
-
ariaValueText$,
|
|
80
|
-
isInteractive$,
|
|
81
|
-
rating$,
|
|
82
|
-
stars$,
|
|
83
|
-
tabindex$,
|
|
84
|
-
visibleRating$,
|
|
85
|
-
...stateProps,
|
|
86
|
-
}),
|
|
87
|
-
patch,
|
|
88
|
-
actions: {
|
|
89
|
-
click: (index) => {
|
|
90
|
-
if (isInteractive$() && index > 0 && index <= maxRating$()) {
|
|
91
|
-
rating$.update((rating) => (rating === index && resettable$() ? 0 : index));
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
hover: (index) => {
|
|
95
|
-
if (isInteractive$() && index > 0 && index <= maxRating$()) {
|
|
96
|
-
_hoveredRating$.set(index);
|
|
97
|
-
onHover$()(index);
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
leave: () => {
|
|
101
|
-
if (isInteractive$()) {
|
|
102
|
-
onLeave$()(_hoveredRating$());
|
|
103
|
-
_hoveredRating$.set(0);
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
handleKey(event) {
|
|
107
|
-
if (isInteractive$()) {
|
|
108
|
-
const { key } = event;
|
|
109
|
-
switch (key) {
|
|
110
|
-
case 'ArrowLeft':
|
|
111
|
-
case 'ArrowDown':
|
|
112
|
-
rating$.update((rating) => rating - 1);
|
|
113
|
-
break;
|
|
114
|
-
case 'ArrowRight':
|
|
115
|
-
case 'ArrowUp':
|
|
116
|
-
rating$.update((rating) => rating + 1);
|
|
117
|
-
break;
|
|
118
|
-
case 'Home':
|
|
119
|
-
case 'PageDown':
|
|
120
|
-
rating$.set(0);
|
|
121
|
-
break;
|
|
122
|
-
case 'End':
|
|
123
|
-
case 'PageUp':
|
|
124
|
-
rating$.set(maxRating$());
|
|
125
|
-
break;
|
|
126
|
-
default:
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
event.preventDefault();
|
|
130
|
-
event.stopPropagation();
|
|
131
|
-
}
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
directives: {},
|
|
135
|
-
api: {},
|
|
136
|
-
};
|
|
137
|
-
}
|