athena-ui-js 2.0.0 → 2.1.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.
Files changed (83) hide show
  1. package/README.md +47 -5
  2. package/docs/migration-2.0.md +1 -1
  3. package/docs/styling.md +3 -1
  4. package/package.json +5 -2
  5. package/src/athena-ui.js +1 -1
  6. package/src/libs/config/config.js +1 -1
  7. package/src/libs/core/popover.js +96 -0
  8. package/src/libs/hephaestus/chartGenerator/chartGenerator.js +26 -2
  9. package/src/libs/hephaestus/componentGenerator/componentGenerator.js +26 -2
  10. package/src/libs/hephaestus/navigationGenerator/navigationGenerator.js +45 -9
  11. package/src/res/themes/default/style.css +32 -0
  12. package/types/athena-ui.d.ts +96 -96
  13. package/types/chart.d.ts +1 -1
  14. package/types/classic.d.ts +1 -1
  15. package/types/components.d.ts +1 -1
  16. package/types/controls.d.ts +3 -3
  17. package/types/csv.d.ts +1 -1
  18. package/types/dialog.d.ts +2 -2
  19. package/types/dom.d.ts +1 -1
  20. package/types/feedback.d.ts +1 -1
  21. package/types/format.d.ts +1 -1
  22. package/types/forms.d.ts +2 -2
  23. package/types/i18n.d.ts +1 -1
  24. package/types/inputs.d.ts +4 -4
  25. package/types/libs/config/config.d.ts +3 -3
  26. package/types/libs/config/hooks.d.ts +8 -8
  27. package/types/libs/core/combobox.d.ts +10 -10
  28. package/types/libs/core/controls.d.ts +28 -28
  29. package/types/libs/core/cookies.d.ts +27 -27
  30. package/types/libs/core/csv.d.ts +12 -12
  31. package/types/libs/core/dateRange.d.ts +72 -72
  32. package/types/libs/core/dom.d.ts +65 -65
  33. package/types/libs/core/elementGenerator.d.ts +30 -30
  34. package/types/libs/core/errors.d.ts +29 -29
  35. package/types/libs/core/focus.d.ts +6 -6
  36. package/types/libs/core/format.d.ts +21 -21
  37. package/types/libs/core/hungarianControls.d.ts +2 -2
  38. package/types/libs/core/i18n.d.ts +17 -17
  39. package/types/libs/core/pagination.d.ts +5 -5
  40. package/types/libs/core/popover.d.ts +36 -0
  41. package/types/libs/core/sanitize.d.ts +6 -6
  42. package/types/libs/core/tableMath.d.ts +26 -26
  43. package/types/libs/core/theme.d.ts +39 -39
  44. package/types/libs/core/validation.d.ts +56 -56
  45. package/types/libs/hephaestus/LayoutGenerator/basicLayoutGenerator.d.ts +10 -10
  46. package/types/libs/hephaestus/LayoutGenerator/footerContentGenerator.d.ts +4 -4
  47. package/types/libs/hephaestus/LayoutGenerator/headerContentGenerator.d.ts +20 -20
  48. package/types/libs/hephaestus/LayoutGenerator/wrapperContentGenerator.d.ts +1 -1
  49. package/types/libs/hephaestus/MenuGenerator/basicMenuGenerator.d.ts +14 -14
  50. package/types/libs/hephaestus/MenuGenerator/menuGenerator.d.ts +65 -65
  51. package/types/libs/hephaestus/auth/authState.d.ts +26 -26
  52. package/types/libs/hephaestus/auth/session.d.ts +26 -26
  53. package/types/libs/hephaestus/chartGenerator/chartGenerator.d.ts +93 -91
  54. package/types/libs/hephaestus/componentGenerator/componentGenerator.d.ts +3 -1
  55. package/types/libs/hephaestus/componentGenerator/themePicker.d.ts +24 -24
  56. package/types/libs/hephaestus/dialogGenerator/dialogGenerator.d.ts +120 -120
  57. package/types/libs/hephaestus/feedbackGenerator/feedbackGenerator.d.ts +86 -86
  58. package/types/libs/hephaestus/formGenerator/authForms.d.ts +122 -122
  59. package/types/libs/hephaestus/formGenerator/changePasswordFormGenerator.d.ts +6 -6
  60. package/types/libs/hephaestus/formGenerator/formBuilder.d.ts +113 -113
  61. package/types/libs/hephaestus/formGenerator/formUtils.d.ts +8 -8
  62. package/types/libs/hephaestus/formGenerator/loginFormGenerator.d.ts +11 -11
  63. package/types/libs/hephaestus/formGenerator/lostPasswordFormGenerator.d.ts +4 -4
  64. package/types/libs/hephaestus/formGenerator/registrationFormGenerator.d.ts +7 -7
  65. package/types/libs/hephaestus/hephaestus.d.ts +3 -3
  66. package/types/libs/hephaestus/inputGenerator/dropZoneGenerator.d.ts +48 -48
  67. package/types/libs/hephaestus/inputGenerator/inputGenerator.d.ts +185 -185
  68. package/types/libs/hephaestus/inputGenerator/richTextGenerator.d.ts +49 -49
  69. package/types/libs/hephaestus/modalGenerator/modalGenerator.d.ts +2 -2
  70. package/types/libs/hephaestus/navigationGenerator/navigationGenerator.d.ts +4 -1
  71. package/types/libs/hephaestus/router/matchRoute.d.ts +12 -12
  72. package/types/libs/hephaestus/router/router.d.ts +67 -67
  73. package/types/libs/hephaestus/tableGenerator/tableGenerator.d.ts +120 -120
  74. package/types/menu.d.ts +1 -1
  75. package/types/navigation.d.ts +1 -1
  76. package/types/res/themes/themes.d.ts +7 -7
  77. package/types/router.d.ts +1 -1
  78. package/types/sanitize.d.ts +1 -1
  79. package/types/session.d.ts +3 -3
  80. package/types/table.d.ts +1 -1
  81. package/types/testing.d.ts +27 -27
  82. package/types/theme.d.ts +2 -2
  83. package/types/validation.d.ts +1 -1
@@ -1,86 +1,86 @@
1
- /**
2
- * Shows a toast notification in the corner of the page.
3
- *
4
- * @param {object|string} options a message, or an options object
5
- * @param {string} options.message
6
- * @param {string} [options.title]
7
- * @param {"info"|"success"|"warning"|"error"} [options.type="info"]
8
- * @param {number} [options.duration=4000] ms before it disappears, 0 keeps it until it is closed
9
- * @returns {{close: Function}}
10
- */
11
- export function showToast(options: object | string): {
12
- close: Function;
13
- };
14
- /**
15
- * Generates an inline alert box.
16
- *
17
- * @param {object} options
18
- * @param {string|Element} [options.parent]
19
- * @param {string} [options.id]
20
- * @param {string|Node} options.message
21
- * @param {string} [options.title]
22
- * @param {"info"|"success"|"warning"|"error"} [options.type="info"]
23
- * @param {boolean} [options.dismissible]
24
- * @returns {HTMLElement}
25
- */
26
- export function generateAlert(options?: {
27
- parent?: string | Element;
28
- id?: string;
29
- message: string | Node;
30
- title?: string;
31
- type?: "info" | "success" | "warning" | "error";
32
- dismissible?: boolean;
33
- }): HTMLElement;
34
- /**
35
- * Copies text to the clipboard and says so in a toast. Resolves with true when it worked (it needs a secure page and a click or key
36
- * press of the person), false otherwise (a toast with the error is shown).
37
- *
38
- * @param {string} text
39
- * @param {object} [options]
40
- * @param {string} [options.message] text of the toast (default: the translated "Copied")
41
- * @param {boolean} [options.toast=true] false copies silently
42
- * @returns {Promise<boolean>}
43
- */
44
- export function copyToClipboard(text: string, { message, toast }?: {
45
- message?: string;
46
- toast?: boolean;
47
- }): Promise<boolean>;
48
- /**
49
- * Generates a loading spinner.
50
- *
51
- * @param {object} [options]
52
- * @param {string|Element} [options.parent]
53
- * @param {string} [options.id]
54
- * @param {"small"|"large"} [options.size]
55
- * @param {string} [options.label] accessible text, defaults to the translated "Loading..."
56
- * @returns {HTMLElement}
57
- */
58
- export function generateSpinner(options?: {
59
- parent?: string | Element;
60
- id?: string;
61
- size?: "small" | "large";
62
- label?: string;
63
- }): HTMLElement;
64
- /**
65
- * Generates a progress bar. Without a value it is indeterminate.
66
- *
67
- * @param {object} [options]
68
- * @param {string|Element} [options.parent]
69
- * @param {string} [options.id]
70
- * @param {number} [options.value] 0..max
71
- * @param {number} [options.max=100]
72
- * @param {string} [options.label] text shown above the bar
73
- * @param {"info"|"success"|"warning"|"error"} [options.type]
74
- * @returns {{element: HTMLElement, setValue: (value: number) => void}}
75
- */
76
- export function generateProgress(options?: {
77
- parent?: string | Element;
78
- id?: string;
79
- value?: number;
80
- max?: number;
81
- label?: string;
82
- type?: "info" | "success" | "warning" | "error";
83
- }): {
84
- element: HTMLElement;
85
- setValue: (value: number) => void;
86
- };
1
+ /**
2
+ * Shows a toast notification in the corner of the page.
3
+ *
4
+ * @param {object|string} options a message, or an options object
5
+ * @param {string} options.message
6
+ * @param {string} [options.title]
7
+ * @param {"info"|"success"|"warning"|"error"} [options.type="info"]
8
+ * @param {number} [options.duration=4000] ms before it disappears, 0 keeps it until it is closed
9
+ * @returns {{close: Function}}
10
+ */
11
+ export function showToast(options: object | string): {
12
+ close: Function;
13
+ };
14
+ /**
15
+ * Generates an inline alert box.
16
+ *
17
+ * @param {object} options
18
+ * @param {string|Element} [options.parent]
19
+ * @param {string} [options.id]
20
+ * @param {string|Node} options.message
21
+ * @param {string} [options.title]
22
+ * @param {"info"|"success"|"warning"|"error"} [options.type="info"]
23
+ * @param {boolean} [options.dismissible]
24
+ * @returns {HTMLElement}
25
+ */
26
+ export function generateAlert(options?: {
27
+ parent?: string | Element;
28
+ id?: string;
29
+ message: string | Node;
30
+ title?: string;
31
+ type?: "info" | "success" | "warning" | "error";
32
+ dismissible?: boolean;
33
+ }): HTMLElement;
34
+ /**
35
+ * Copies text to the clipboard and says so in a toast. Resolves with true when it worked (it needs a secure page and a click or key
36
+ * press of the person), false otherwise (a toast with the error is shown).
37
+ *
38
+ * @param {string} text
39
+ * @param {object} [options]
40
+ * @param {string} [options.message] text of the toast (default: the translated "Copied")
41
+ * @param {boolean} [options.toast=true] false copies silently
42
+ * @returns {Promise<boolean>}
43
+ */
44
+ export function copyToClipboard(text: string, { message, toast }?: {
45
+ message?: string;
46
+ toast?: boolean;
47
+ }): Promise<boolean>;
48
+ /**
49
+ * Generates a loading spinner.
50
+ *
51
+ * @param {object} [options]
52
+ * @param {string|Element} [options.parent]
53
+ * @param {string} [options.id]
54
+ * @param {"small"|"large"} [options.size]
55
+ * @param {string} [options.label] accessible text, defaults to the translated "Loading..."
56
+ * @returns {HTMLElement}
57
+ */
58
+ export function generateSpinner(options?: {
59
+ parent?: string | Element;
60
+ id?: string;
61
+ size?: "small" | "large";
62
+ label?: string;
63
+ }): HTMLElement;
64
+ /**
65
+ * Generates a progress bar. Without a value it is indeterminate.
66
+ *
67
+ * @param {object} [options]
68
+ * @param {string|Element} [options.parent]
69
+ * @param {string} [options.id]
70
+ * @param {number} [options.value] 0..max
71
+ * @param {number} [options.max=100]
72
+ * @param {string} [options.label] text shown above the bar
73
+ * @param {"info"|"success"|"warning"|"error"} [options.type]
74
+ * @returns {{element: HTMLElement, setValue: (value: number) => void}}
75
+ */
76
+ export function generateProgress(options?: {
77
+ parent?: string | Element;
78
+ id?: string;
79
+ value?: number;
80
+ max?: number;
81
+ label?: string;
82
+ type?: "info" | "success" | "warning" | "error";
83
+ }): {
84
+ element: HTMLElement;
85
+ setValue: (value: number) => void;
86
+ };
@@ -1,122 +1,122 @@
1
- /**
2
- * A sign in form: username (or email), password, and optionally "Remember me".
3
- *
4
- * @param {object} options
5
- * @param {string|Element} [options.parent]
6
- * @param {(values: {username: string, password: string, remember?: boolean}, form: object) => (void|Promise)} options.onSubmit
7
- * @param {boolean} [options.remember=false] shows "Remember me"
8
- * @param {"username"|"email"} [options.identifier="username"] what the first field asks for
9
- * @param {string} [options.submitText]
10
- */
11
- export function generateSignInForm(options?: {
12
- parent?: string | Element;
13
- onSubmit: (values: {
14
- username: string;
15
- password: string;
16
- remember?: boolean;
17
- }, form: object) => (void | Promise<any>);
18
- remember?: boolean;
19
- identifier?: "username" | "email";
20
- submitText?: string;
21
- }): {
22
- element: HTMLFormElement;
23
- fields: {
24
- [x: string]: any;
25
- };
26
- getValues: Function;
27
- setValues: Function;
28
- setErrors: Function;
29
- validate: Function;
30
- reset: Function;
31
- setMessage: Function;
32
- submitButton: object;
33
- };
34
- /**
35
- * A registration form: username, email, password and its confirmation.
36
- *
37
- * @param {object} options
38
- * @param {string|Element} [options.parent]
39
- * @param {(values: {username: string, email: string, password: string}, form: object) => (void|Promise)} options.onSubmit
40
- * the confirmation is checked here and not sent
41
- * @param {number} [options.passwordMinLength=8]
42
- * @param {boolean} [options.username=true] false leaves the username out (sign in with the email)
43
- * @param {string} [options.submitText]
44
- */
45
- export function generateSignUpForm(options?: {
46
- parent?: string | Element;
47
- onSubmit: (values: {
48
- username: string;
49
- email: string;
50
- password: string;
51
- }, form: object) => (void | Promise<any>);
52
- passwordMinLength?: number;
53
- username?: boolean;
54
- submitText?: string;
55
- }): {
56
- element: HTMLFormElement;
57
- fields: {
58
- [x: string]: any;
59
- };
60
- getValues: Function;
61
- setValues: Function;
62
- setErrors: Function;
63
- validate: Function;
64
- reset: Function;
65
- setMessage: Function;
66
- submitButton: object;
67
- };
68
- /**
69
- * Asks for the email address to send a reset link to.
70
- *
71
- * @param {object} options
72
- * @param {string|Element} [options.parent]
73
- * @param {(values: {email: string}, form: object) => (void|Promise)} options.onSubmit
74
- */
75
- export function generatePasswordResetForm(options?: {
76
- parent?: string | Element;
77
- onSubmit: (values: {
78
- email: string;
79
- }, form: object) => (void | Promise<any>);
80
- }): {
81
- element: HTMLFormElement;
82
- fields: {
83
- [x: string]: any;
84
- };
85
- getValues: Function;
86
- setValues: Function;
87
- setErrors: Function;
88
- validate: Function;
89
- reset: Function;
90
- setMessage: Function;
91
- submitButton: object;
92
- };
93
- /**
94
- * Change of the password of the person who is signed in: the current one, the new one and its confirmation.
95
- *
96
- * @param {object} options
97
- * @param {string|Element} [options.parent]
98
- * @param {(values: {currentPassword: string, newPassword: string}, form: object) => (void|Promise)} options.onSubmit
99
- * @param {number} [options.passwordMinLength=8]
100
- * @param {string} [options.username] when given, a hidden username field helps the password manager to update the right entry
101
- */
102
- export function generatePasswordChangeForm(options?: {
103
- parent?: string | Element;
104
- onSubmit: (values: {
105
- currentPassword: string;
106
- newPassword: string;
107
- }, form: object) => (void | Promise<any>);
108
- passwordMinLength?: number;
109
- username?: string;
110
- }): {
111
- element: HTMLFormElement;
112
- fields: {
113
- [x: string]: any;
114
- };
115
- getValues: Function;
116
- setValues: Function;
117
- setErrors: Function;
118
- validate: Function;
119
- reset: Function;
120
- setMessage: Function;
121
- submitButton: object;
122
- };
1
+ /**
2
+ * A sign in form: username (or email), password, and optionally "Remember me".
3
+ *
4
+ * @param {object} options
5
+ * @param {string|Element} [options.parent]
6
+ * @param {(values: {username: string, password: string, remember?: boolean}, form: object) => (void|Promise)} options.onSubmit
7
+ * @param {boolean} [options.remember=false] shows "Remember me"
8
+ * @param {"username"|"email"} [options.identifier="username"] what the first field asks for
9
+ * @param {string} [options.submitText]
10
+ */
11
+ export function generateSignInForm(options?: {
12
+ parent?: string | Element;
13
+ onSubmit: (values: {
14
+ username: string;
15
+ password: string;
16
+ remember?: boolean;
17
+ }, form: object) => (void | Promise<any>);
18
+ remember?: boolean;
19
+ identifier?: "username" | "email";
20
+ submitText?: string;
21
+ }): {
22
+ element: HTMLFormElement;
23
+ fields: {
24
+ [x: string]: any;
25
+ };
26
+ getValues: Function;
27
+ setValues: Function;
28
+ setErrors: Function;
29
+ validate: Function;
30
+ reset: Function;
31
+ setMessage: Function;
32
+ submitButton: object;
33
+ };
34
+ /**
35
+ * A registration form: username, email, password and its confirmation.
36
+ *
37
+ * @param {object} options
38
+ * @param {string|Element} [options.parent]
39
+ * @param {(values: {username: string, email: string, password: string}, form: object) => (void|Promise)} options.onSubmit
40
+ * the confirmation is checked here and not sent
41
+ * @param {number} [options.passwordMinLength=8]
42
+ * @param {boolean} [options.username=true] false leaves the username out (sign in with the email)
43
+ * @param {string} [options.submitText]
44
+ */
45
+ export function generateSignUpForm(options?: {
46
+ parent?: string | Element;
47
+ onSubmit: (values: {
48
+ username: string;
49
+ email: string;
50
+ password: string;
51
+ }, form: object) => (void | Promise<any>);
52
+ passwordMinLength?: number;
53
+ username?: boolean;
54
+ submitText?: string;
55
+ }): {
56
+ element: HTMLFormElement;
57
+ fields: {
58
+ [x: string]: any;
59
+ };
60
+ getValues: Function;
61
+ setValues: Function;
62
+ setErrors: Function;
63
+ validate: Function;
64
+ reset: Function;
65
+ setMessage: Function;
66
+ submitButton: object;
67
+ };
68
+ /**
69
+ * Asks for the email address to send a reset link to.
70
+ *
71
+ * @param {object} options
72
+ * @param {string|Element} [options.parent]
73
+ * @param {(values: {email: string}, form: object) => (void|Promise)} options.onSubmit
74
+ */
75
+ export function generatePasswordResetForm(options?: {
76
+ parent?: string | Element;
77
+ onSubmit: (values: {
78
+ email: string;
79
+ }, form: object) => (void | Promise<any>);
80
+ }): {
81
+ element: HTMLFormElement;
82
+ fields: {
83
+ [x: string]: any;
84
+ };
85
+ getValues: Function;
86
+ setValues: Function;
87
+ setErrors: Function;
88
+ validate: Function;
89
+ reset: Function;
90
+ setMessage: Function;
91
+ submitButton: object;
92
+ };
93
+ /**
94
+ * Change of the password of the person who is signed in: the current one, the new one and its confirmation.
95
+ *
96
+ * @param {object} options
97
+ * @param {string|Element} [options.parent]
98
+ * @param {(values: {currentPassword: string, newPassword: string}, form: object) => (void|Promise)} options.onSubmit
99
+ * @param {number} [options.passwordMinLength=8]
100
+ * @param {string} [options.username] when given, a hidden username field helps the password manager to update the right entry
101
+ */
102
+ export function generatePasswordChangeForm(options?: {
103
+ parent?: string | Element;
104
+ onSubmit: (values: {
105
+ currentPassword: string;
106
+ newPassword: string;
107
+ }, form: object) => (void | Promise<any>);
108
+ passwordMinLength?: number;
109
+ username?: string;
110
+ }): {
111
+ element: HTMLFormElement;
112
+ fields: {
113
+ [x: string]: any;
114
+ };
115
+ getValues: Function;
116
+ setValues: Function;
117
+ setErrors: Function;
118
+ validate: Function;
119
+ reset: Function;
120
+ setMessage: Function;
121
+ submitButton: object;
122
+ };
@@ -1,6 +1,6 @@
1
- export function getChangePasswordFormData(): {
2
- currentPassword: any;
3
- newPassword: any;
4
- };
5
- export function validateChangePasswordForm(): string;
6
- export function generateChangePasswordForm(parent?: string): void;
1
+ export function getChangePasswordFormData(): {
2
+ currentPassword: any;
3
+ newPassword: any;
4
+ };
5
+ export function validateChangePasswordForm(): string;
6
+ export function generateChangePasswordForm(parent?: string): void;
@@ -1,113 +1,113 @@
1
- /**
2
- * Generates a button.
3
- *
4
- * @param {object} options
5
- * @param {string|Element} [options.parent] id or element, defaults to the body
6
- * @param {string} [options.id]
7
- * @param {string} [options.text]
8
- * @param {"primary"|"secondary"|"danger"|"link"} [options.variant="primary"]
9
- * @param {"button"|"submit"|"reset"} [options.type="button"]
10
- * @param {"small"|"large"} [options.size]
11
- * @param {boolean} [options.disabled]
12
- * @param {boolean} [options.loading] shows a spinner and blocks clicks
13
- * @param {(event: Event) => void} [options.onclick]
14
- * @returns {{element: HTMLButtonElement, setLoading: Function, setDisabled: Function, setText: Function}}
15
- */
16
- export function generateButton(options?: {
17
- parent?: string | Element;
18
- id?: string;
19
- text?: string;
20
- variant?: "primary" | "secondary" | "danger" | "link";
21
- type?: "button" | "submit" | "reset";
22
- size?: "small" | "large";
23
- disabled?: boolean;
24
- loading?: boolean;
25
- onclick?: (event: Event) => void;
26
- }): {
27
- element: HTMLButtonElement;
28
- setLoading: Function;
29
- setDisabled: Function;
30
- setText: Function;
31
- };
32
- /**
33
- * Generates one labelled form field with help text and an error line.
34
- *
35
- * @param {object} options
36
- * @param {string} options.name key of the field in the form values
37
- * @param {"text"|"password"|"email"|"number"|"date"|"datetime-local"|"time"|"url"|"tel"|"search"|"color"|"range"|"file"|"hidden"|"textarea"|"select"|"checkbox"|"switch"|"radio"|"checkboxes"|"autocomplete"|"multiselect"|"daterange"|"richtext"|"wysiwyg"} [options.type="text"]
38
- * @param {string} [options.label]
39
- * @param {string} [options.help] help text under the control
40
- * @param {*} [options.value] initial value (boolean for checkbox / switch, array for checkboxes / multiple select)
41
- * @param {(string|{value: string, text?: string, disabled?: boolean})[]} [options.options] choices of select / radio / checkboxes
42
- * @param {boolean} [options.multiple] select / file: allow several values
43
- * @param {string} [options.placeholder]
44
- * @param {number} [options.rows] textarea rows
45
- * @param {object} [options.rules] validation rules, see validateValue. They can also be given directly
46
- * (required, email, minLength, ...)
47
- * @param {(value, field) => void} [options.onChange]
48
- * @param {() => object} [options.getValues] all form values (set by generateForm, used by `match`)
49
- * @returns {{element: HTMLElement, name: string, getValue: Function, setValue: Function, validate: Function,
50
- * setError: Function, focus: Function}}
51
- */
52
- export function generateField(options?: {
53
- name: string;
54
- type?: "text" | "password" | "email" | "number" | "date" | "datetime-local" | "time" | "url" | "tel" | "search" | "color" | "range" | "file" | "hidden" | "textarea" | "select" | "checkbox" | "switch" | "radio" | "checkboxes" | "autocomplete" | "multiselect" | "daterange" | "richtext" | "wysiwyg";
55
- label?: string;
56
- help?: string;
57
- value?: any;
58
- options?: (string | {
59
- value: string;
60
- text?: string;
61
- disabled?: boolean;
62
- })[];
63
- multiple?: boolean;
64
- placeholder?: string;
65
- rows?: number;
66
- rules?: object;
67
- onChange?: (value: any, field: any) => void;
68
- getValues?: () => object;
69
- }): {
70
- element: HTMLElement;
71
- name: string;
72
- getValue: Function;
73
- setValue: Function;
74
- validate: Function;
75
- setError: Function;
76
- focus: Function;
77
- };
78
- /**
79
- * Generates a form from a list of field definitions.
80
- *
81
- * @param {object} options
82
- * @param {string|Element} [options.parent]
83
- * @param {string} [options.id]
84
- * @param {object[]} options.fields field definitions, see generateField
85
- * @param {string} [options.submitText]
86
- * @param {string|false} [options.resetText] adds a reset button when set
87
- * @param {(values: object, form: object) => (void|Promise)} [options.onSubmit] called with the values when every
88
- * field is valid. A returned promise keeps the submit button busy; a rejection is shown as form message.
89
- * @param {(values: object, field: object) => void} [options.onChange]
90
- * @returns {{element: HTMLFormElement, fields: Object<string, object>, getValues: Function, setValues: Function,
91
- * setErrors: Function, validate: Function, reset: Function, setMessage: Function, submitButton: object}}
92
- */
93
- export function generateForm(options?: {
94
- parent?: string | Element;
95
- id?: string;
96
- fields: object[];
97
- submitText?: string;
98
- resetText?: string | false;
99
- onSubmit?: (values: object, form: object) => (void | Promise<any>);
100
- onChange?: (values: object, field: object) => void;
101
- }): {
102
- element: HTMLFormElement;
103
- fields: {
104
- [x: string]: object;
105
- };
106
- getValues: Function;
107
- setValues: Function;
108
- setErrors: Function;
109
- validate: Function;
110
- reset: Function;
111
- setMessage: Function;
112
- submitButton: object;
113
- };
1
+ /**
2
+ * Generates a button.
3
+ *
4
+ * @param {object} options
5
+ * @param {string|Element} [options.parent] id or element, defaults to the body
6
+ * @param {string} [options.id]
7
+ * @param {string} [options.text]
8
+ * @param {"primary"|"secondary"|"danger"|"link"} [options.variant="primary"]
9
+ * @param {"button"|"submit"|"reset"} [options.type="button"]
10
+ * @param {"small"|"large"} [options.size]
11
+ * @param {boolean} [options.disabled]
12
+ * @param {boolean} [options.loading] shows a spinner and blocks clicks
13
+ * @param {(event: Event) => void} [options.onclick]
14
+ * @returns {{element: HTMLButtonElement, setLoading: Function, setDisabled: Function, setText: Function}}
15
+ */
16
+ export function generateButton(options?: {
17
+ parent?: string | Element;
18
+ id?: string;
19
+ text?: string;
20
+ variant?: "primary" | "secondary" | "danger" | "link";
21
+ type?: "button" | "submit" | "reset";
22
+ size?: "small" | "large";
23
+ disabled?: boolean;
24
+ loading?: boolean;
25
+ onclick?: (event: Event) => void;
26
+ }): {
27
+ element: HTMLButtonElement;
28
+ setLoading: Function;
29
+ setDisabled: Function;
30
+ setText: Function;
31
+ };
32
+ /**
33
+ * Generates one labelled form field with help text and an error line.
34
+ *
35
+ * @param {object} options
36
+ * @param {string} options.name key of the field in the form values
37
+ * @param {"text"|"password"|"email"|"number"|"date"|"datetime-local"|"time"|"url"|"tel"|"search"|"color"|"range"|"file"|"hidden"|"textarea"|"select"|"checkbox"|"switch"|"radio"|"checkboxes"|"autocomplete"|"multiselect"|"daterange"|"richtext"|"wysiwyg"} [options.type="text"]
38
+ * @param {string} [options.label]
39
+ * @param {string} [options.help] help text under the control
40
+ * @param {*} [options.value] initial value (boolean for checkbox / switch, array for checkboxes / multiple select)
41
+ * @param {(string|{value: string, text?: string, disabled?: boolean})[]} [options.options] choices of select / radio / checkboxes
42
+ * @param {boolean} [options.multiple] select / file: allow several values
43
+ * @param {string} [options.placeholder]
44
+ * @param {number} [options.rows] textarea rows
45
+ * @param {object} [options.rules] validation rules, see validateValue. They can also be given directly
46
+ * (required, email, minLength, ...)
47
+ * @param {(value, field) => void} [options.onChange]
48
+ * @param {() => object} [options.getValues] all form values (set by generateForm, used by `match`)
49
+ * @returns {{element: HTMLElement, name: string, getValue: Function, setValue: Function, validate: Function,
50
+ * setError: Function, focus: Function}}
51
+ */
52
+ export function generateField(options?: {
53
+ name: string;
54
+ type?: "text" | "password" | "email" | "number" | "date" | "datetime-local" | "time" | "url" | "tel" | "search" | "color" | "range" | "file" | "hidden" | "textarea" | "select" | "checkbox" | "switch" | "radio" | "checkboxes" | "autocomplete" | "multiselect" | "daterange" | "richtext" | "wysiwyg";
55
+ label?: string;
56
+ help?: string;
57
+ value?: any;
58
+ options?: (string | {
59
+ value: string;
60
+ text?: string;
61
+ disabled?: boolean;
62
+ })[];
63
+ multiple?: boolean;
64
+ placeholder?: string;
65
+ rows?: number;
66
+ rules?: object;
67
+ onChange?: (value: any, field: any) => void;
68
+ getValues?: () => object;
69
+ }): {
70
+ element: HTMLElement;
71
+ name: string;
72
+ getValue: Function;
73
+ setValue: Function;
74
+ validate: Function;
75
+ setError: Function;
76
+ focus: Function;
77
+ };
78
+ /**
79
+ * Generates a form from a list of field definitions.
80
+ *
81
+ * @param {object} options
82
+ * @param {string|Element} [options.parent]
83
+ * @param {string} [options.id]
84
+ * @param {object[]} options.fields field definitions, see generateField
85
+ * @param {string} [options.submitText]
86
+ * @param {string|false} [options.resetText] adds a reset button when set
87
+ * @param {(values: object, form: object) => (void|Promise)} [options.onSubmit] called with the values when every
88
+ * field is valid. A returned promise keeps the submit button busy; a rejection is shown as form message.
89
+ * @param {(values: object, field: object) => void} [options.onChange]
90
+ * @returns {{element: HTMLFormElement, fields: Object<string, object>, getValues: Function, setValues: Function,
91
+ * setErrors: Function, validate: Function, reset: Function, setMessage: Function, submitButton: object}}
92
+ */
93
+ export function generateForm(options?: {
94
+ parent?: string | Element;
95
+ id?: string;
96
+ fields: object[];
97
+ submitText?: string;
98
+ resetText?: string | false;
99
+ onSubmit?: (values: object, form: object) => (void | Promise<any>);
100
+ onChange?: (values: object, field: object) => void;
101
+ }): {
102
+ element: HTMLFormElement;
103
+ fields: {
104
+ [x: string]: object;
105
+ };
106
+ getValues: Function;
107
+ setValues: Function;
108
+ setErrors: Function;
109
+ validate: Function;
110
+ reset: Function;
111
+ setMessage: Function;
112
+ submitButton: object;
113
+ };