@agnos-ui/core 0.0.1-alpha.1 → 0.0.1-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/{accordion.d.ts → components/accordion/accordion.d.ts} +27 -18
  2. package/{accordion.js → components/accordion/accordion.js} +80 -76
  3. package/components/accordion/index.d.ts +1 -0
  4. package/components/accordion/index.js +1 -0
  5. package/components/alert/alert.d.ts +31 -0
  6. package/components/alert/alert.js +22 -0
  7. package/{alert.d.ts → components/alert/common.d.ts} +17 -21
  8. package/{alert.js → components/alert/common.js} +21 -19
  9. package/components/alert/index.d.ts +2 -0
  10. package/components/alert/index.js +2 -0
  11. package/components/modal/index.d.ts +1 -0
  12. package/components/modal/index.js +1 -0
  13. package/{modal → components/modal}/modal.d.ts +28 -21
  14. package/{modal → components/modal}/modal.js +58 -28
  15. package/components/pagination/index.d.ts +2 -0
  16. package/components/pagination/index.js +2 -0
  17. package/{pagination.d.ts → components/pagination/pagination.d.ts} +2 -3
  18. package/{pagination.js → components/pagination/pagination.js} +5 -4
  19. package/components/progressbar/index.d.ts +1 -0
  20. package/components/progressbar/index.js +1 -0
  21. package/components/progressbar/progressbar.d.ts +86 -0
  22. package/components/progressbar/progressbar.js +78 -0
  23. package/components/rating/index.d.ts +1 -0
  24. package/components/rating/index.js +1 -0
  25. package/{rating.d.ts → components/rating/rating.d.ts} +4 -5
  26. package/{rating.js → components/rating/rating.js} +6 -9
  27. package/components/select/index.d.ts +1 -0
  28. package/components/select/index.js +1 -0
  29. package/components/select/select.d.ts +337 -0
  30. package/components/select/select.js +266 -0
  31. package/components/slider/index.d.ts +1 -0
  32. package/components/slider/index.js +1 -0
  33. package/components/slider/slider.d.ts +245 -0
  34. package/components/slider/slider.js +413 -0
  35. package/config.d.ts +17 -7
  36. package/config.js +3 -3
  37. package/index.d.ts +23 -10
  38. package/index.js +29 -10
  39. package/package.json +32 -4
  40. package/services/extendWidget.d.ts +23 -0
  41. package/services/extendWidget.js +35 -0
  42. package/services/floatingUI.d.ts +56 -0
  43. package/services/floatingUI.js +105 -0
  44. package/services/focustrack.js +5 -5
  45. package/services/intersection.d.ts +9 -1
  46. package/services/intersection.js +10 -2
  47. package/services/navManager.d.ts +93 -0
  48. package/services/navManager.js +172 -0
  49. package/services/portal.d.ts +7 -0
  50. package/services/portal.js +15 -4
  51. package/services/siblingsInert.d.ts +2 -1
  52. package/services/siblingsInert.js +2 -2
  53. package/{transitions → services/transitions}/baseTransitions.d.ts +15 -2
  54. package/{transitions → services/transitions}/baseTransitions.js +21 -10
  55. package/services/transitions/bootstrap/collapse.d.ts +2 -0
  56. package/services/transitions/bootstrap/fade.d.ts +1 -0
  57. package/services/transitions/bootstrap.d.ts +2 -0
  58. package/services/transitions/bootstrap.js +2 -0
  59. package/services/transitions/collapse.d.ts +43 -0
  60. package/{transitions → services/transitions}/collapse.js +15 -2
  61. package/{transitions → services/transitions}/cssTransitions.d.ts +6 -0
  62. package/{transitions → services/transitions}/cssTransitions.js +8 -4
  63. package/{transitions → services/transitions}/simpleClassTransition.d.ts +12 -1
  64. package/services/transitions/simpleClassTransition.js +42 -0
  65. package/types.d.ts +43 -4
  66. package/types.js +7 -0
  67. package/{services/directiveUtils.js → utils/directive.js} +1 -1
  68. package/utils/internal/checks.d.ts +49 -0
  69. package/utils/internal/checks.js +60 -0
  70. package/utils/internal/dom.d.ts +25 -0
  71. package/utils/internal/dom.js +61 -0
  72. package/utils/internal/func.d.ts +11 -0
  73. package/utils/internal/func.js +11 -0
  74. package/utils/internal/isFocusable.d.ts +9 -0
  75. package/utils/internal/isFocusable.js +35 -0
  76. package/utils/internal/math.d.ts +5 -0
  77. package/utils/internal/math.js +13 -0
  78. package/utils/internal/promise.d.ts +87 -0
  79. package/utils/internal/promise.js +169 -0
  80. package/utils/internal/scrollbars.d.ts +8 -0
  81. package/{modal → utils/internal}/scrollbars.js +7 -1
  82. package/utils/internal/sort.d.ts +16 -0
  83. package/utils/internal/sort.js +28 -0
  84. package/utils/internal/textDirection.d.ts +7 -0
  85. package/utils/internal/textDirection.js +7 -0
  86. package/utils/internal/traversal.d.ts +54 -0
  87. package/utils/internal/traversal.js +105 -0
  88. package/{services → utils}/stores.d.ts +67 -33
  89. package/{services → utils}/stores.js +121 -59
  90. package/utils/writables.d.ts +32 -0
  91. package/utils/writables.js +72 -0
  92. package/modal/scrollbars.d.ts +0 -2
  93. package/select.d.ts +0 -196
  94. package/select.js +0 -240
  95. package/services/checks.d.ts +0 -32
  96. package/services/checks.js +0 -43
  97. package/services/index.d.ts +0 -7
  98. package/services/index.js +0 -7
  99. package/services/writables.d.ts +0 -7
  100. package/services/writables.js +0 -16
  101. package/transitions/bootstrap/collapse.d.ts +0 -2
  102. package/transitions/bootstrap/fade.d.ts +0 -1
  103. package/transitions/bootstrap/index.d.ts +0 -2
  104. package/transitions/bootstrap/index.js +0 -2
  105. package/transitions/collapse.d.ts +0 -29
  106. package/transitions/index.d.ts +0 -5
  107. package/transitions/index.js +0 -5
  108. package/transitions/simpleClassTransition.js +0 -28
  109. package/transitions/utils.d.ts +0 -20
  110. package/transitions/utils.js +0 -83
  111. package/utils.d.ts +0 -2
  112. package/utils.js +0 -2
  113. /package/{commonProps.d.ts → components/commonProps.d.ts} +0 -0
  114. /package/{commonProps.js → components/commonProps.js} +0 -0
  115. /package/{pagination.utils.d.ts → components/pagination/bootstrap.d.ts} +0 -0
  116. /package/{pagination.utils.js → components/pagination/bootstrap.js} +0 -0
  117. /package/{transitions → services/transitions}/bootstrap/collapse.js +0 -0
  118. /package/{transitions → services/transitions}/bootstrap/fade.js +0 -0
  119. /package/{services/directiveUtils.d.ts → utils/directive.d.ts} +0 -0
@@ -1,7 +1,6 @@
1
- import type { PropsConfig } from '../services';
2
- import type { TransitionFn } from '../transitions';
3
- import type { Widget, Directive, SlotContent, WidgetSlotContext } from '../types';
4
1
  import type { WidgetsCommonPropsAndState } from '../commonProps';
2
+ import type { TransitionFn } from '../../services/transitions/baseTransitions';
3
+ import type { Directive, PropsConfig, SlotContent, Widget, WidgetSlotContext } from '../../types';
5
4
  /**
6
5
  * Value present in the {@link ModalBeforeCloseEvent.result|result} property of the {@link ModalProps.onBeforeClose|onBeforeClose} event
7
6
  * and returned by the {@link ModalApi.open|open} method, when the modal is closed by a click inside the viewport but outside the modal.
@@ -15,11 +14,11 @@ export declare const modalCloseButtonClick: unique symbol;
15
14
  /**
16
15
  * Context of the modal slots.
17
16
  */
18
- export type ModalContext = WidgetSlotContext<ModalWidget>;
17
+ export type ModalContext<Data> = WidgetSlotContext<ModalWidget<Data>>;
19
18
  /**
20
19
  * Properties of the modal widget that are also in the state of the modal.
21
20
  */
22
- export interface ModalCommonPropsAndState extends WidgetsCommonPropsAndState {
21
+ export interface ModalCommonPropsAndState<Data> extends WidgetsCommonPropsAndState {
23
22
  /**
24
23
  * Value of the aria-label attribute to put on the close button.
25
24
  */
@@ -41,28 +40,32 @@ export interface ModalCommonPropsAndState extends WidgetsCommonPropsAndState {
41
40
  /**
42
41
  * Body of the modal.
43
42
  */
44
- slotDefault: SlotContent<ModalContext>;
43
+ slotDefault: SlotContent<ModalContext<Data>>;
45
44
  /**
46
45
  * Footer of the modal.
47
46
  */
48
- slotFooter: SlotContent<ModalContext>;
47
+ slotFooter: SlotContent<ModalContext<Data>>;
49
48
  /**
50
49
  * Header of the modal. The default header includes {@link ModalCommonPropsAndState.slotTitle|slotTitle}.
51
50
  */
52
- slotHeader: SlotContent<ModalContext>;
51
+ slotHeader: SlotContent<ModalContext<Data>>;
53
52
  /**
54
53
  * Structure of the modal.
55
54
  * The default structure uses {@link ModalCommonPropsAndState.slotHeader|slotHeader}, {@link ModalCommonPropsAndState.slotDefault|slotDefault} and {@link ModalCommonPropsAndState.slotFooter|slotFooter}.
56
55
  */
57
- slotStructure: SlotContent<ModalContext>;
56
+ slotStructure: SlotContent<ModalContext<Data>>;
58
57
  /**
59
58
  * Title of the modal.
60
59
  */
61
- slotTitle: SlotContent<ModalContext>;
60
+ slotTitle: SlotContent<ModalContext<Data>>;
62
61
  /**
63
62
  * Whether the modal should be visible when the transition is completed.
64
63
  */
65
64
  visible: boolean;
65
+ /**
66
+ * Data to use in content slots
67
+ */
68
+ contentData: Data;
66
69
  }
67
70
  /**
68
71
  * Type of the parameter of {@link ModalProps.onBeforeClose|onBeforeClose}.
@@ -83,7 +86,7 @@ export interface ModalBeforeCloseEvent {
83
86
  /**
84
87
  * Properties of the modal widget.
85
88
  */
86
- export interface ModalProps extends ModalCommonPropsAndState {
89
+ export interface ModalProps<Data> extends ModalCommonPropsAndState<Data> {
87
90
  /**
88
91
  * Whether the modal and its backdrop (if present) should be animated when shown or hidden.
89
92
  */
@@ -129,7 +132,7 @@ export interface ModalProps extends ModalCommonPropsAndState {
129
132
  /**
130
133
  * State of the modal widget.
131
134
  */
132
- export interface ModalState extends ModalCommonPropsAndState {
135
+ export interface ModalState<Data> extends ModalCommonPropsAndState<Data> {
133
136
  /**
134
137
  * Whether the backdrop is fully hidden. This can be true either because {@link ModalProps.backdrop|backdrop} is false or
135
138
  * because {@link ModalCommonPropsAndState.visible|visible} is false and there is no current transition.
@@ -151,7 +154,7 @@ export interface ModalState extends ModalCommonPropsAndState {
151
154
  /**
152
155
  * API of the modal widget.
153
156
  */
154
- export interface ModalApi {
157
+ export interface ModalApi<Data> {
155
158
  /**
156
159
  * Closes the modal with the given result.
157
160
  *
@@ -168,7 +171,7 @@ export interface ModalApi {
168
171
  /**
169
172
  * Method to change some modal properties.
170
173
  */
171
- patch: ModalWidget['patch'];
174
+ patch: ModalWidget<Data>['patch'];
172
175
  }
173
176
  /**
174
177
  * Actions of the modal widget.
@@ -212,7 +215,7 @@ export interface ModalDirectives {
212
215
  /**
213
216
  * Modal widget.
214
217
  */
215
- export type ModalWidget = Widget<ModalProps, ModalState, ModalApi, ModalActions, ModalDirectives>;
218
+ export type ModalWidget<Data> = Widget<ModalProps<Data>, ModalState<Data>, ModalApi<Data>, ModalActions, ModalDirectives>;
216
219
  /**
217
220
  * Returns a copy of the default modal config.
218
221
  * @returns a copy of the default modal config
@@ -280,28 +283,32 @@ export declare function getModalDefaultConfig(): {
280
283
  /**
281
284
  * Body of the modal.
282
285
  */
283
- slotDefault: SlotContent<ModalContext>;
286
+ slotDefault: SlotContent<ModalContext<any>>;
284
287
  /**
285
288
  * Footer of the modal.
286
289
  */
287
- slotFooter: SlotContent<ModalContext>;
290
+ slotFooter: SlotContent<ModalContext<any>>;
288
291
  /**
289
292
  * Header of the modal. The default header includes {@link ModalCommonPropsAndState.slotTitle|slotTitle}.
290
293
  */
291
- slotHeader: SlotContent<ModalContext>;
294
+ slotHeader: SlotContent<ModalContext<any>>;
292
295
  /**
293
296
  * Structure of the modal.
294
297
  * The default structure uses {@link ModalCommonPropsAndState.slotHeader|slotHeader}, {@link ModalCommonPropsAndState.slotDefault|slotDefault} and {@link ModalCommonPropsAndState.slotFooter|slotFooter}.
295
298
  */
296
- slotStructure: SlotContent<ModalContext>;
299
+ slotStructure: SlotContent<ModalContext<any>>;
297
300
  /**
298
301
  * Title of the modal.
299
302
  */
300
- slotTitle: SlotContent<ModalContext>;
303
+ slotTitle: SlotContent<ModalContext<any>>;
301
304
  /**
302
305
  * Whether the modal should be visible when the transition is completed.
303
306
  */
304
307
  visible: boolean;
308
+ /**
309
+ * Data to use in content slots
310
+ */
311
+ contentData: any;
305
312
  className: string;
306
313
  };
307
314
  /**
@@ -309,4 +316,4 @@ export declare function getModalDefaultConfig(): {
309
316
  * @param config$ - config of the modal, either as a store or as an object containing values or stores.
310
317
  * @returns a new modal widget instance
311
318
  */
312
- export declare const createModal: (config$?: PropsConfig<ModalProps>) => ModalWidget;
319
+ export declare function createModal<Data>(config$?: PropsConfig<ModalProps<Data>>): ModalWidget<Data>;
@@ -1,10 +1,14 @@
1
1
  import { computed, readable } from '@amadeus-it-group/tansu';
2
- import { sliblingsInert, bindDirective, bindDirectiveNoArg, directiveSubscribe, mergeDirectives, portal, registrationArray, stateStores, writablesForProps, } from '../services';
3
- import { createTransition } from '../transitions';
4
- import { fadeTransition } from '../transitions/bootstrap/fade';
5
- import { promiseFromStore } from '../transitions/utils';
6
- import { noop } from '../utils';
7
- import { removeScrollbars, revertScrollbars } from './scrollbars';
2
+ import { typeBoolean, typeFunction, typeHTMLElementOrNull, typeString } from '../../utils/writables';
3
+ import { stateStores, writablesForProps } from '../../utils/stores';
4
+ import { createTransition } from '../../services/transitions/baseTransitions';
5
+ import { fadeTransition } from '../../services/transitions/bootstrap/fade';
6
+ import { promiseFromStore } from '../../utils/internal/promise';
7
+ import { noop } from '../../utils/internal/func';
8
+ import { removeScrollbars, revertScrollbars } from '../../utils/internal/scrollbars';
9
+ import { bindDirective, bindDirectiveNoArg, directiveSubscribe, mergeDirectives, registrationArray } from '../../utils/directive';
10
+ import { portal } from '../../services/portal';
11
+ import { sliblingsInert } from '../../services/siblingsInert';
8
12
  /**
9
13
  * Value present in the {@link ModalBeforeCloseEvent.result|result} property of the {@link ModalProps.onBeforeClose|onBeforeClose} event
10
14
  * and returned by the {@link ModalApi.open|open} method, when the modal is closed by a click inside the viewport but outside the modal.
@@ -20,12 +24,12 @@ const defaultConfig = {
20
24
  ariaCloseButtonLabel: 'Close',
21
25
  backdrop: true,
22
26
  backdropClass: '',
23
- backdropTransition: fadeTransition,
27
+ backdropTransition: fadeTransition, // TODO: is it ok to depend on bootstrap transition?
24
28
  closeButton: true,
25
29
  closeOnOutsideClick: true,
26
30
  container: typeof window !== 'undefined' ? document.body : null,
27
31
  className: '',
28
- modalTransition: fadeTransition,
32
+ modalTransition: fadeTransition, // TODO: is it ok to depend on bootstrap transition?
29
33
  onBeforeClose: noop,
30
34
  onVisibleChange: noop,
31
35
  onHidden: noop,
@@ -36,6 +40,24 @@ const defaultConfig = {
36
40
  slotStructure: undefined,
37
41
  slotTitle: undefined,
38
42
  visible: false,
43
+ contentData: undefined,
44
+ };
45
+ const configValidator = {
46
+ animation: typeBoolean,
47
+ ariaCloseButtonLabel: typeString,
48
+ backdrop: typeBoolean,
49
+ backdropClass: typeString,
50
+ backdropTransition: typeFunction,
51
+ closeButton: typeBoolean,
52
+ closeOnOutsideClick: typeBoolean,
53
+ container: typeHTMLElementOrNull,
54
+ className: typeString,
55
+ modalTransition: typeFunction,
56
+ onBeforeClose: typeFunction,
57
+ onVisibleChange: typeFunction,
58
+ onHidden: typeFunction,
59
+ onShown: typeFunction,
60
+ visible: typeBoolean,
39
61
  };
40
62
  /**
41
63
  * Returns a copy of the default modal config.
@@ -62,25 +84,29 @@ const modalsAction$ = computed(() => {
62
84
  * @param config$ - config of the modal, either as a store or as an object containing values or stores.
63
85
  * @returns a new modal widget instance
64
86
  */
65
- export const createModal = (config$) => {
66
- const [{ animation$, backdrop$, backdropTransition$, closeOnOutsideClick$, container$, modalTransition$, onBeforeClose$, onVisibleChange$, onHidden$, onShown$, visible$: requestedVisible$, ...stateProps }, patch,] = writablesForProps(defaultConfig, config$);
87
+ export function createModal(config$) {
88
+ const [{ animation$, backdrop$, backdropTransition$, closeOnOutsideClick$, container$, modalTransition$, onBeforeClose$, onVisibleChange$, onHidden$, onShown$, visible$: requestedVisible$, ...stateProps }, patch,] = writablesForProps(defaultConfig, config$, configValidator);
67
89
  const modalTransition = createTransition({
68
- transition: modalTransition$,
69
- visible: requestedVisible$,
70
- animation: animation$,
71
- animationOnInit: animation$,
72
- onVisibleChange: onVisibleChange$,
73
- // TODO: for onHidden and onShown, should we combine with information from the backdrop transition?
74
- // (especially in case one of the two transitions takes more time than the other)
75
- onHidden: onHidden$,
76
- onShown: onShown$,
90
+ props: {
91
+ transition: modalTransition$,
92
+ visible: requestedVisible$,
93
+ animation: animation$,
94
+ animationOnInit: animation$,
95
+ onVisibleChange: onVisibleChange$,
96
+ // TODO: for onHidden and onShown, should we combine with information from the backdrop transition?
97
+ // (especially in case one of the two transitions takes more time than the other)
98
+ onHidden: onHidden$,
99
+ onShown: onShown$,
100
+ },
77
101
  });
78
102
  const visible$ = modalTransition.stores.visible$;
79
103
  const backdropTransition = createTransition({
80
- transition: backdropTransition$,
81
- visible: requestedVisible$,
82
- animation: animation$,
83
- animationOnInit: animation$,
104
+ props: {
105
+ transition: backdropTransition$,
106
+ visible: requestedVisible$,
107
+ animation: animation$,
108
+ animationOnInit: animation$,
109
+ },
84
110
  });
85
111
  const transitioning$ = computed(() => modalTransition.stores.transitioning$() || (backdrop$() && backdropTransition.stores.transitioning$()));
86
112
  const hidden$ = computed(() => !transitioning$() && !visible$());
@@ -104,10 +130,14 @@ export const createModal = (config$) => {
104
130
  patch({ visible: false });
105
131
  };
106
132
  const modalPortalDirective = bindDirective(portal, computed(() => ({ container: container$() })));
107
- const backdropPortalDirective = bindDirective(portal, computed(() => ({
108
- container: container$(),
109
- insertBefore: container$() && modalTransition.stores.element$()?.parentElement === container$() ? modalTransition.stores.element$() : undefined,
110
- })));
133
+ const backdropPortalDirective = bindDirective(portal, computed(() => {
134
+ const container = container$();
135
+ const element = container ? modalTransition.stores.element$() : undefined;
136
+ return {
137
+ container,
138
+ insertBefore: element?.parentElement === container ? element : undefined,
139
+ };
140
+ }));
111
141
  const registerModalAction$ = readable(undefined, () => modals$.register(res));
112
142
  const action$ = computed(() => {
113
143
  if (modalTransition.stores.elementPresent$() && !hidden$()) {
@@ -153,4 +183,4 @@ export const createModal = (config$) => {
153
183
  },
154
184
  };
155
185
  return res;
156
- };
186
+ }
@@ -0,0 +1,2 @@
1
+ export * from './bootstrap';
2
+ export * from './pagination';
@@ -0,0 +1,2 @@
1
+ export * from './bootstrap';
2
+ export * from './pagination';
@@ -1,6 +1,5 @@
1
- import type { PropsConfig } from './services';
2
- import type { Widget, SlotContent, WidgetSlotContext } from './types';
3
- import type { WidgetsCommonPropsAndState } from './commonProps';
1
+ import type { PropsConfig, Widget, SlotContent, WidgetSlotContext } from '../../types';
2
+ import type { WidgetsCommonPropsAndState } from '../commonProps';
4
3
  /**
5
4
  * A type for the slot context of the pagination widget
6
5
  */
@@ -1,8 +1,9 @@
1
1
  import { computed } from '@amadeus-it-group/tansu';
2
- import { bindableDerived, INVALID_VALUE, stateStores, writablesForProps } from './services';
3
- import { clamp, isNumber } from './services/checks';
4
- import { typeBoolean, typeFunction, typeNumber, typeString } from './services/writables';
5
- import { noop } from './utils';
2
+ import { INVALID_VALUE } from '../../types';
3
+ import { bindableDerived, 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';
6
7
  const defaultConfig = {
7
8
  page: 1,
8
9
  collectionSize: 0,
@@ -0,0 +1 @@
1
+ export * from './progressbar';
@@ -0,0 +1 @@
1
+ export * from './progressbar';
@@ -0,0 +1,86 @@
1
+ import type { PropsConfig, SlotContent, Widget, WidgetSlotContext } from '../../types';
2
+ import type { WidgetsCommonPropsAndState } from '../commonProps';
3
+ export type ProgressbarContext = WidgetSlotContext<ProgressbarWidget>;
4
+ export interface ProgressbarCommonPropsAndState extends WidgetsCommonPropsAndState {
5
+ /**
6
+ * The minimum value.
7
+ * @defaultValue 0
8
+ */
9
+ min: number;
10
+ /**
11
+ * The maximum value.
12
+ * @defaultValue 100
13
+ */
14
+ max: number;
15
+ /**
16
+ * The current value.
17
+ * @defaultValue 0
18
+ */
19
+ value: number;
20
+ /**
21
+ * The aria label.
22
+ */
23
+ ariaLabel: string;
24
+ /**
25
+ * Global template for the Progressbar content.
26
+ */
27
+ slotContent: SlotContent<ProgressbarContext>;
28
+ /**
29
+ * Label of the progress.
30
+ */
31
+ slotDefault: SlotContent<ProgressbarContext>;
32
+ /**
33
+ * Height of the progressbar, can be any valid css height value.
34
+ */
35
+ height: string;
36
+ /**
37
+ * If `true`, shows a striped progressbar.
38
+ */
39
+ striped: boolean;
40
+ /**
41
+ * If `true`, animates a striped progressbar.
42
+ * Takes effect only for browsers supporting CSS3 animations, and if `striped` is `true`.
43
+ */
44
+ animated: boolean;
45
+ }
46
+ export interface ProgressbarState extends ProgressbarCommonPropsAndState {
47
+ /**
48
+ * Percentage of completion.
49
+ */
50
+ percentage: number;
51
+ /**
52
+ * `true` if the value is above its minimum value.
53
+ */
54
+ started: boolean;
55
+ /**
56
+ * `true` if the value has reached its maximum value.
57
+ */
58
+ finished: boolean;
59
+ /**
60
+ * The aria value text.
61
+ */
62
+ ariaValueText: string | undefined;
63
+ }
64
+ export interface ProgressbarProps extends ProgressbarCommonPropsAndState {
65
+ /**
66
+ * Return the value for the 'aria-valuetext' attribute.
67
+ * @param value - current value
68
+ * @param minimum - minimum value
69
+ * @param maximum - maximum value
70
+ */
71
+ ariaValueTextFn: (value: number, minimum: number, maximum: number) => string | undefined;
72
+ }
73
+ export interface ProgressbarApi {
74
+ }
75
+ export type ProgressbarWidget = Widget<ProgressbarProps, ProgressbarState, ProgressbarApi, object, object>;
76
+ /**
77
+ * Retrieve a shallow copy of the default Progressbar config
78
+ * @returns the default Progressbar config
79
+ */
80
+ export declare function getProgressbarDefaultConfig(): ProgressbarProps;
81
+ /**
82
+ * Create an ProgressbarWidget with given config props
83
+ * @param config - an optional progress bar config
84
+ * @returns an ProgressbarWidget
85
+ */
86
+ export declare function createProgressbar(config?: PropsConfig<ProgressbarProps>): ProgressbarWidget;
@@ -0,0 +1,78 @@
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
+ slotContent: 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
+ }
@@ -0,0 +1 @@
1
+ export * from './rating';
@@ -0,0 +1 @@
1
+ export * from './rating';
@@ -1,6 +1,5 @@
1
- import type { PropsConfig } from './services';
2
- import type { SlotContent, Widget } from './types';
3
- import type { WidgetsCommonPropsAndState } from './commonProps';
1
+ import type { PropsConfig, SlotContent, Widget } from '../../types';
2
+ import type { WidgetsCommonPropsAndState } from '../commonProps';
4
3
  export interface StarContext {
5
4
  /**
6
5
  * indicates how much the current star is filled, from 0 to 100
@@ -54,7 +53,7 @@ export interface RatingCommonPropsAndState extends WidgetsCommonPropsAndState {
54
53
  }
55
54
  export interface RatingProps extends RatingCommonPropsAndState {
56
55
  /**
57
- * Return the value for the 'aria-value' attribute.
56
+ * Return the value for the 'aria-valuetext' attribute.
58
57
  * @param rating - Current rating value.
59
58
  * @param maxRating - maxRating value.
60
59
  */
@@ -131,7 +130,7 @@ export type RatingWidget = Widget<RatingProps, RatingState, object, RatingAction
131
130
  */
132
131
  export declare function getRatingDefaultConfig(): {
133
132
  /**
134
- * Return the value for the 'aria-value' attribute.
133
+ * Return the value for the 'aria-valuetext' attribute.
135
134
  * @param rating - Current rating value.
136
135
  * @param maxRating - maxRating value.
137
136
  */
@@ -1,12 +1,9 @@
1
1
  import { computed, writable } from '@amadeus-it-group/tansu';
2
- import { INVALID_VALUE, bindableDerived, stateStores, writablesForProps } from './services';
3
- import { isNumber } from './services/checks';
4
- import { typeBoolean, typeFunction, typeNumber, typeString } from './services/writables';
5
- // TODO use getValueInRange
6
- function adjustRating(rating, maxRating) {
7
- return Math.max(Math.min(rating, maxRating), 0);
8
- }
9
- const noop = () => { };
2
+ import { INVALID_VALUE } from '../../types';
3
+ import { bindableDerived, 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';
10
7
  const defaultConfig = {
11
8
  rating: 0,
12
9
  tabindex: 0,
@@ -60,7 +57,7 @@ export function createRating(config) {
60
57
  const { maxRating$, disabled$, readonly$, resettable$ } = stateProps;
61
58
  // clean inputs adjustment to valid range
62
59
  const tabindex$ = computed(() => (disabled$() ? -1 : _dirtyTabindex$()));
63
- const rating$ = bindableDerived(onRatingChange$, [_dirtyRating$, maxRating$], ([dirtyRating, maxRating]) => adjustRating(dirtyRating, maxRating));
60
+ const rating$ = bindableDerived(onRatingChange$, [_dirtyRating$, maxRating$], ([dirtyRating, maxRating]) => clamp(dirtyRating, maxRating));
64
61
  // internal inputs
65
62
  const _hoveredRating$ = writable(0);
66
63
  // computed
@@ -0,0 +1 @@
1
+ export * from './select';
@@ -0,0 +1 @@
1
+ export * from './select';