@oussemasahbeni/keycloakify-login-shadcn 250004.0.2 → 250004.0.7

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 (174) hide show
  1. package/keycloak-theme/components/ui/alert.tsx +4 -4
  2. package/keycloak-theme/components/ui/dropdown-menu.tsx +5 -5
  3. package/keycloak-theme/components/ui/input.tsx +1 -1
  4. package/keycloak-theme/components/ui/select.tsx +4 -4
  5. package/keycloak-theme/components/ui/separator.tsx +1 -1
  6. package/keycloak-theme/login/KcContext.ts +23 -19
  7. package/keycloak-theme/login/KcPage.tsx +47 -60
  8. package/keycloak-theme/login/assets/img/auth-logo.svg +100 -100
  9. package/keycloak-theme/login/assets/img/shape.svg +71 -71
  10. package/keycloak-theme/login/components/LogoutOtherSessions.tsx +26 -26
  11. package/keycloak-theme/login/components/PasswordWrapper.tsx +35 -35
  12. package/keycloak-theme/login/components/Template/Template.tsx +227 -226
  13. package/keycloak-theme/login/components/Template/index.ts +1 -1
  14. package/keycloak-theme/login/components/Template/useInitializeTemplate.ts +61 -61
  15. package/keycloak-theme/login/components/UserProfileFormFields/AddRemoveButtonsMultiValuedAttribute.tsx +61 -61
  16. package/keycloak-theme/login/components/UserProfileFormFields/DO_MAKE_USER_CONFIRM_PASSWORD.ts +2 -2
  17. package/keycloak-theme/login/components/UserProfileFormFields/FieldErrors.tsx +28 -28
  18. package/keycloak-theme/login/components/UserProfileFormFields/GroupLabel.tsx +70 -70
  19. package/keycloak-theme/login/components/UserProfileFormFields/InputFieldByType.tsx +58 -58
  20. package/keycloak-theme/login/components/UserProfileFormFields/InputTag.tsx +116 -116
  21. package/keycloak-theme/login/components/UserProfileFormFields/InputTagSelects.tsx +135 -135
  22. package/keycloak-theme/login/components/UserProfileFormFields/SelectTag.tsx +114 -114
  23. package/keycloak-theme/login/components/UserProfileFormFields/TextareaTag.tsx +42 -42
  24. package/keycloak-theme/login/components/UserProfileFormFields/UserProfileFormFields.tsx +127 -127
  25. package/keycloak-theme/login/components/UserProfileFormFields/index.ts +1 -1
  26. package/keycloak-theme/login/i18n.ts +47 -51
  27. package/keycloak-theme/login/mocks/getKcContextMock.ts +22 -18
  28. package/keycloak-theme/login/pages/PageIndex.tsx +134 -134
  29. package/keycloak-theme/login/pages/code/Page.stories.tsx +62 -78
  30. package/keycloak-theme/login/pages/code/Page.tsx +89 -89
  31. package/keycloak-theme/login/pages/code/index.ts +3 -3
  32. package/keycloak-theme/login/pages/delete-account-confirm/Page.stories.tsx +39 -46
  33. package/keycloak-theme/login/pages/delete-account-confirm/Page.tsx +63 -63
  34. package/keycloak-theme/login/pages/delete-account-confirm/index.ts +3 -3
  35. package/keycloak-theme/login/pages/delete-credential/Page.stories.tsx +26 -30
  36. package/keycloak-theme/login/pages/delete-credential/Page.tsx +51 -51
  37. package/keycloak-theme/login/pages/delete-credential/index.ts +3 -3
  38. package/keycloak-theme/login/pages/error/Page.stories.tsx +47 -58
  39. package/keycloak-theme/login/pages/error/Page.tsx +42 -42
  40. package/keycloak-theme/login/pages/error/index.ts +3 -3
  41. package/keycloak-theme/login/pages/frontchannel-logout/Page.stories.tsx +25 -32
  42. package/keycloak-theme/login/pages/frontchannel-logout/Page.tsx +84 -84
  43. package/keycloak-theme/login/pages/frontchannel-logout/index.ts +3 -3
  44. package/keycloak-theme/login/pages/idp-review-user-profile/Page.stories.tsx +46 -58
  45. package/keycloak-theme/login/pages/idp-review-user-profile/Page.tsx +52 -52
  46. package/keycloak-theme/login/pages/idp-review-user-profile/index.ts +3 -3
  47. package/keycloak-theme/login/pages/info/Page.stories.tsx +50 -60
  48. package/keycloak-theme/login/pages/info/Page.tsx +92 -92
  49. package/keycloak-theme/login/pages/link-idp-action/Page.stories.tsx +32 -16
  50. package/keycloak-theme/login/pages/link-idp-action/Page.tsx +43 -43
  51. package/keycloak-theme/login/pages/link-idp-action/index.ts +3 -3
  52. package/keycloak-theme/login/pages/login/Form.tsx +242 -242
  53. package/keycloak-theme/login/pages/login/Info.tsx +29 -29
  54. package/keycloak-theme/login/pages/login/Page.stories.tsx +345 -365
  55. package/keycloak-theme/login/pages/login/Page.tsx +44 -44
  56. package/keycloak-theme/login/pages/login/SocialProviders.tsx +107 -107
  57. package/keycloak-theme/login/pages/login/index.ts +3 -3
  58. package/keycloak-theme/login/pages/login/providers/apple.svg +3 -3
  59. package/keycloak-theme/login/pages/login/providers/bitbucket.svg +11 -11
  60. package/keycloak-theme/login/pages/login/providers/discord.svg +4 -4
  61. package/keycloak-theme/login/pages/login/providers/facebook.svg +5 -5
  62. package/keycloak-theme/login/pages/login/providers/github.svg +3 -3
  63. package/keycloak-theme/login/pages/login/providers/gitlab.svg +7 -7
  64. package/keycloak-theme/login/pages/login/providers/google.svg +7 -7
  65. package/keycloak-theme/login/pages/login/providers/instagram.svg +31 -31
  66. package/keycloak-theme/login/pages/login/providers/linkedin.svg +3 -3
  67. package/keycloak-theme/login/pages/login/providers/microsoft.svg +6 -6
  68. package/keycloak-theme/login/pages/login/providers/oidc.svg +5 -5
  69. package/keycloak-theme/login/pages/login/providers/openshift.svg +7 -7
  70. package/keycloak-theme/login/pages/login/providers/paypal.svg +6 -6
  71. package/keycloak-theme/login/pages/login/providers/slack.svg +11 -11
  72. package/keycloak-theme/login/pages/login/providers/stackoverflow.svg +5 -5
  73. package/keycloak-theme/login/pages/login/providers/x.svg +3 -3
  74. package/keycloak-theme/login/pages/login/useProviderLogos.tsx +39 -39
  75. package/keycloak-theme/login/pages/login/useScript.tsx +62 -62
  76. package/keycloak-theme/login/pages/login-config-totp/Page.stories.tsx +45 -59
  77. package/keycloak-theme/login/pages/login-config-totp/Page.tsx +240 -240
  78. package/keycloak-theme/login/pages/login-config-totp/index.ts +3 -3
  79. package/keycloak-theme/login/pages/login-idp-link-confirm/Page.stories.tsx +30 -34
  80. package/keycloak-theme/login/pages/login-idp-link-confirm/Page.tsx +43 -43
  81. package/keycloak-theme/login/pages/login-idp-link-confirm/index.ts +3 -3
  82. package/keycloak-theme/login/pages/login-idp-link-confirm-override/Page.stories.tsx +16 -22
  83. package/keycloak-theme/login/pages/login-idp-link-confirm-override/Page.tsx +47 -47
  84. package/keycloak-theme/login/pages/login-idp-link-confirm-override/index.ts +3 -3
  85. package/keycloak-theme/login/pages/login-idp-link-email/Page.stories.tsx +54 -62
  86. package/keycloak-theme/login/pages/login-idp-link-email/Page.tsx +54 -54
  87. package/keycloak-theme/login/pages/login-idp-link-email/index.ts +3 -3
  88. package/keycloak-theme/login/pages/login-oauth-grant/Page.stories.tsx +39 -45
  89. package/keycloak-theme/login/pages/login-oauth-grant/Page.tsx +126 -126
  90. package/keycloak-theme/login/pages/login-oauth-grant/index.ts +3 -3
  91. package/keycloak-theme/login/pages/login-oauth2-device-verify-user-code/Page.stories.tsx +38 -48
  92. package/keycloak-theme/login/pages/login-oauth2-device-verify-user-code/Page.tsx +58 -58
  93. package/keycloak-theme/login/pages/login-oauth2-device-verify-user-code/index.ts +3 -3
  94. package/keycloak-theme/login/pages/login-otp/Page.stories.tsx +82 -96
  95. package/keycloak-theme/login/pages/login-otp/Page.tsx +108 -108
  96. package/keycloak-theme/login/pages/login-otp/index.ts +3 -3
  97. package/keycloak-theme/login/pages/login-page-expired/Page.stories.tsx +28 -36
  98. package/keycloak-theme/login/pages/login-page-expired/Page.tsx +47 -47
  99. package/keycloak-theme/login/pages/login-page-expired/index.ts +3 -3
  100. package/keycloak-theme/login/pages/login-passkeys-conditional-authenticate/Page.stories.tsx +20 -0
  101. package/keycloak-theme/login/pages/login-passkeys-conditional-authenticate/Page.tsx +233 -233
  102. package/keycloak-theme/login/pages/login-passkeys-conditional-authenticate/index.ts +3 -3
  103. package/keycloak-theme/login/pages/login-passkeys-conditional-authenticate/useScript.tsx +63 -63
  104. package/keycloak-theme/login/pages/login-password/Page.stories.tsx +55 -56
  105. package/keycloak-theme/login/pages/login-password/Page.tsx +149 -149
  106. package/keycloak-theme/login/pages/login-password/index.ts +3 -3
  107. package/keycloak-theme/login/pages/login-password/useScript.tsx +63 -63
  108. package/keycloak-theme/login/pages/login-recovery-authn-code-config/Page.stories.tsx +28 -36
  109. package/keycloak-theme/login/pages/login-recovery-authn-code-config/Page.tsx +181 -181
  110. package/keycloak-theme/login/pages/login-recovery-authn-code-config/index.ts +3 -3
  111. package/keycloak-theme/login/pages/login-recovery-authn-code-config/useScript.tsx +145 -145
  112. package/keycloak-theme/login/pages/login-recovery-authn-code-input/Page.stories.tsx +16 -22
  113. package/keycloak-theme/login/pages/login-recovery-authn-code-input/Page.tsx +70 -70
  114. package/keycloak-theme/login/pages/login-recovery-authn-code-input/index.ts +3 -3
  115. package/keycloak-theme/login/pages/login-reset-otp/Page.stories.tsx +62 -74
  116. package/keycloak-theme/login/pages/login-reset-otp/Page.tsx +86 -86
  117. package/keycloak-theme/login/pages/login-reset-otp/index.ts +3 -3
  118. package/keycloak-theme/login/pages/login-reset-password/Form.tsx +68 -68
  119. package/keycloak-theme/login/pages/login-reset-password/Page.stories.tsx +44 -54
  120. package/keycloak-theme/login/pages/login-reset-password/Page.tsx +27 -27
  121. package/keycloak-theme/login/pages/login-reset-password/index.ts +3 -3
  122. package/keycloak-theme/login/pages/login-update-password/Page.stories.tsx +40 -50
  123. package/keycloak-theme/login/pages/login-update-password/Page.tsx +111 -111
  124. package/keycloak-theme/login/pages/login-update-password/index.ts +3 -3
  125. package/keycloak-theme/login/pages/login-update-profile/Page.stories.tsx +28 -36
  126. package/keycloak-theme/login/pages/login-update-profile/Page.tsx +68 -68
  127. package/keycloak-theme/login/pages/login-update-profile/index.ts +3 -3
  128. package/keycloak-theme/login/pages/login-username/Page.stories.tsx +32 -42
  129. package/keycloak-theme/login/pages/login-username/Page.tsx +246 -246
  130. package/keycloak-theme/login/pages/login-username/index.ts +3 -3
  131. package/keycloak-theme/login/pages/login-username/useScript.tsx +62 -62
  132. package/keycloak-theme/login/pages/login-verify-email/Page.stories.tsx +68 -80
  133. package/keycloak-theme/login/pages/login-verify-email/Page.tsx +38 -38
  134. package/keycloak-theme/login/pages/login-verify-email/index.ts +3 -3
  135. package/keycloak-theme/login/pages/login-x509-info/Page.stories.tsx +29 -37
  136. package/keycloak-theme/login/pages/login-x509-info/Page.tsx +75 -75
  137. package/keycloak-theme/login/pages/login-x509-info/index.ts +3 -3
  138. package/keycloak-theme/login/pages/logout-confirm/Page.stories.tsx +34 -42
  139. package/keycloak-theme/login/pages/logout-confirm/Page.tsx +53 -53
  140. package/keycloak-theme/login/pages/logout-confirm/index.ts +3 -3
  141. package/keycloak-theme/login/pages/register/Form.tsx +106 -106
  142. package/keycloak-theme/login/pages/register/Page.stories.tsx +23 -6
  143. package/keycloak-theme/login/pages/register/Page.tsx +26 -26
  144. package/keycloak-theme/login/pages/register/TermsAcceptance.tsx +56 -56
  145. package/keycloak-theme/login/pages/register/index.ts +3 -3
  146. package/keycloak-theme/login/pages/saml-post-form/Page.stories.tsx +16 -22
  147. package/keycloak-theme/login/pages/saml-post-form/Page.tsx +66 -66
  148. package/keycloak-theme/login/pages/saml-post-form/index.ts +3 -3
  149. package/keycloak-theme/login/pages/select-authenticator/Page.stories.tsx +83 -95
  150. package/keycloak-theme/login/pages/select-authenticator/Page.tsx +100 -100
  151. package/keycloak-theme/login/pages/select-authenticator/index.ts +3 -3
  152. package/keycloak-theme/login/pages/select-organization/Page.stories.tsx +62 -49
  153. package/keycloak-theme/login/pages/select-organization/Page.tsx +126 -126
  154. package/keycloak-theme/login/pages/select-organization/index.ts +3 -3
  155. package/keycloak-theme/login/pages/terms/Page.stories.tsx +15 -0
  156. package/keycloak-theme/login/pages/terms/Page.tsx +51 -51
  157. package/keycloak-theme/login/pages/terms/index.ts +3 -3
  158. package/keycloak-theme/login/pages/update-email/Page.stories.tsx +27 -35
  159. package/keycloak-theme/login/pages/update-email/Page.tsx +62 -62
  160. package/keycloak-theme/login/pages/update-email/index.ts +3 -3
  161. package/keycloak-theme/login/pages/webauthn-authenticate/Page.stories.tsx +112 -126
  162. package/keycloak-theme/login/pages/webauthn-authenticate/Page.tsx +202 -202
  163. package/keycloak-theme/login/pages/webauthn-authenticate/index.ts +3 -3
  164. package/keycloak-theme/login/pages/webauthn-authenticate/useScript.tsx +55 -55
  165. package/keycloak-theme/login/pages/webauthn-error/Page.stories.tsx +54 -66
  166. package/keycloak-theme/login/pages/webauthn-error/Page.tsx +73 -73
  167. package/keycloak-theme/login/pages/webauthn-error/index.ts +3 -3
  168. package/keycloak-theme/login/pages/webauthn-register/Page.stories.tsx +39 -49
  169. package/keycloak-theme/login/pages/webauthn-register/Page.tsx +78 -78
  170. package/keycloak-theme/login/pages/webauthn-register/index.ts +3 -3
  171. package/keycloak-theme/login/pages/webauthn-register/useScript.tsx +62 -62
  172. package/keycloak-theme/login/shared/getColorScheme.ts +45 -0
  173. package/keycloak-theme/login/styleLevelCustomization.tsx +36 -17
  174. package/package.json +6 -5
@@ -1,116 +1,116 @@
1
-
2
- import { Input } from '@/components/ui/input';
3
- import { assert } from "tsafe/assert";
4
- import { useI18n } from "../../i18n";
5
- import { AddRemoveButtonsMultiValuedAttribute } from "./AddRemoveButtonsMultiValuedAttribute";
6
- import { FieldErrors } from "./FieldErrors";
7
- import type { InputFieldByTypeProps } from "./InputFieldByType";
8
-
9
- export function InputTag(
10
- props: InputFieldByTypeProps & { fieldIndex: number | undefined }
11
- ) {
12
- const {
13
- attribute,
14
- fieldIndex,
15
- dispatchFormAction,
16
- valueOrValues,
17
- displayableErrors
18
- } = props;
19
-
20
- const { advancedMsgStr } = useI18n();
21
-
22
- return (
23
- <>
24
- <Input
25
- type={(() => {
26
- const { inputType } = attribute.annotations;
27
-
28
- if (inputType?.startsWith("html5-")) {
29
- return inputType.slice(6);
30
- }
31
-
32
- return inputType ?? "text";
33
- })()}
34
- id={attribute.name}
35
- name={attribute.name}
36
- value={(() => {
37
- if (fieldIndex !== undefined) {
38
- assert(valueOrValues instanceof Array);
39
- return valueOrValues[fieldIndex];
40
- }
41
-
42
- assert(typeof valueOrValues === "string");
43
-
44
- return valueOrValues;
45
- })()}
46
- aria-invalid={displayableErrors.length !== 0}
47
- disabled={attribute.readOnly}
48
- autoComplete={attribute.autocomplete}
49
- placeholder={
50
- attribute.annotations.inputTypePlaceholder === undefined ? undefined : advancedMsgStr(attribute.annotations.inputTypePlaceholder)
51
- }
52
- pattern={attribute.annotations.inputTypePattern}
53
- size={attribute.annotations.inputTypeSize === undefined ? undefined : parseInt(`${attribute.annotations.inputTypeSize}`)}
54
- maxLength={
55
- attribute.annotations.inputTypeMaxlength === undefined ? undefined : parseInt(`${attribute.annotations.inputTypeMaxlength}`)
56
- }
57
- minLength={
58
- attribute.annotations.inputTypeMinlength === undefined ? undefined : parseInt(`${attribute.annotations.inputTypeMinlength}`)
59
- }
60
- max={attribute.annotations.inputTypeMax}
61
- min={attribute.annotations.inputTypeMin}
62
- step={attribute.annotations.inputTypeStep}
63
- {...Object.fromEntries(Object.entries(attribute.html5DataAnnotations ?? {}).map(([key, value]) => [`data-${key}`, value]))}
64
- onChange={event =>
65
- dispatchFormAction({
66
- action: "update",
67
- name: attribute.name,
68
- valueOrValues: (() => {
69
- if (fieldIndex !== undefined) {
70
- assert(valueOrValues instanceof Array);
71
-
72
- return valueOrValues.map((value, i) => {
73
- if (i === fieldIndex) {
74
- return event.target.value;
75
- }
76
-
77
- return value;
78
- });
79
- }
80
-
81
- return event.target.value;
82
- })()
83
- })
84
- }
85
- onBlur={() =>
86
- dispatchFormAction({
87
- action: "focus lost",
88
- name: attribute.name,
89
- fieldIndex: fieldIndex
90
- })
91
- }
92
- />
93
- {(() => {
94
- if (fieldIndex === undefined) {
95
- return null;
96
- }
97
-
98
- assert(valueOrValues instanceof Array);
99
-
100
- const values = valueOrValues;
101
-
102
- return (
103
- <>
104
- <FieldErrors attribute={attribute} displayableErrors={displayableErrors} fieldIndex={fieldIndex} />
105
- <AddRemoveButtonsMultiValuedAttribute
106
- attribute={attribute}
107
- values={values}
108
- fieldIndex={fieldIndex}
109
- dispatchFormAction={dispatchFormAction}
110
- />
111
- </>
112
- );
113
- })()}
114
- </>
115
- );
116
- }
1
+
2
+ import { Input } from '@/components/ui/input';
3
+ import { assert } from "tsafe/assert";
4
+ import { useI18n } from "../../i18n";
5
+ import { AddRemoveButtonsMultiValuedAttribute } from "./AddRemoveButtonsMultiValuedAttribute";
6
+ import { FieldErrors } from "./FieldErrors";
7
+ import type { InputFieldByTypeProps } from "./InputFieldByType";
8
+
9
+ export function InputTag(
10
+ props: InputFieldByTypeProps & { fieldIndex: number | undefined }
11
+ ) {
12
+ const {
13
+ attribute,
14
+ fieldIndex,
15
+ dispatchFormAction,
16
+ valueOrValues,
17
+ displayableErrors
18
+ } = props;
19
+
20
+ const { advancedMsgStr } = useI18n();
21
+
22
+ return (
23
+ <>
24
+ <Input
25
+ type={(() => {
26
+ const { inputType } = attribute.annotations;
27
+
28
+ if (inputType?.startsWith("html5-")) {
29
+ return inputType.slice(6);
30
+ }
31
+
32
+ return inputType ?? "text";
33
+ })()}
34
+ id={attribute.name}
35
+ name={attribute.name}
36
+ value={(() => {
37
+ if (fieldIndex !== undefined) {
38
+ assert(valueOrValues instanceof Array);
39
+ return valueOrValues[fieldIndex];
40
+ }
41
+
42
+ assert(typeof valueOrValues === "string");
43
+
44
+ return valueOrValues;
45
+ })()}
46
+ aria-invalid={displayableErrors.length !== 0}
47
+ disabled={attribute.readOnly}
48
+ autoComplete={attribute.autocomplete}
49
+ placeholder={
50
+ attribute.annotations.inputTypePlaceholder === undefined ? undefined : advancedMsgStr(attribute.annotations.inputTypePlaceholder)
51
+ }
52
+ pattern={attribute.annotations.inputTypePattern}
53
+ size={attribute.annotations.inputTypeSize === undefined ? undefined : parseInt(`${attribute.annotations.inputTypeSize}`)}
54
+ maxLength={
55
+ attribute.annotations.inputTypeMaxlength === undefined ? undefined : parseInt(`${attribute.annotations.inputTypeMaxlength}`)
56
+ }
57
+ minLength={
58
+ attribute.annotations.inputTypeMinlength === undefined ? undefined : parseInt(`${attribute.annotations.inputTypeMinlength}`)
59
+ }
60
+ max={attribute.annotations.inputTypeMax}
61
+ min={attribute.annotations.inputTypeMin}
62
+ step={attribute.annotations.inputTypeStep}
63
+ {...Object.fromEntries(Object.entries(attribute.html5DataAnnotations ?? {}).map(([key, value]) => [`data-${key}`, value]))}
64
+ onChange={event =>
65
+ dispatchFormAction({
66
+ action: "update",
67
+ name: attribute.name,
68
+ valueOrValues: (() => {
69
+ if (fieldIndex !== undefined) {
70
+ assert(valueOrValues instanceof Array);
71
+
72
+ return valueOrValues.map((value, i) => {
73
+ if (i === fieldIndex) {
74
+ return event.target.value;
75
+ }
76
+
77
+ return value;
78
+ });
79
+ }
80
+
81
+ return event.target.value;
82
+ })()
83
+ })
84
+ }
85
+ onBlur={() =>
86
+ dispatchFormAction({
87
+ action: "focus lost",
88
+ name: attribute.name,
89
+ fieldIndex: fieldIndex
90
+ })
91
+ }
92
+ />
93
+ {(() => {
94
+ if (fieldIndex === undefined) {
95
+ return null;
96
+ }
97
+
98
+ assert(valueOrValues instanceof Array);
99
+
100
+ const values = valueOrValues;
101
+
102
+ return (
103
+ <>
104
+ <FieldErrors attribute={attribute} displayableErrors={displayableErrors} fieldIndex={fieldIndex} />
105
+ <AddRemoveButtonsMultiValuedAttribute
106
+ attribute={attribute}
107
+ values={values}
108
+ fieldIndex={fieldIndex}
109
+ dispatchFormAction={dispatchFormAction}
110
+ />
111
+ </>
112
+ );
113
+ })()}
114
+ </>
115
+ );
116
+ }
@@ -1,136 +1,136 @@
1
-
2
- import { cn } from '@/components/lib/utils';
3
- import { Checkbox } from '@/components/ui/checkbox';
4
- import { Label } from '@/components/ui/label';
5
- import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group';
6
- import { assert } from 'tsafe/assert';
7
- import type { InputFieldByTypeProps } from "./InputFieldByType";
8
- import { InputLabel } from './InputLabel';
9
-
10
- export function InputTagSelects(props: InputFieldByTypeProps) {
11
- const { attribute, dispatchFormAction, valueOrValues } = props;
12
-
13
-
14
-
15
- const isRadio = (() => {
16
- const { inputType } = attribute.annotations;
17
-
18
- assert(inputType === "select-radiobuttons" || inputType === "multiselect-checkboxes");
19
-
20
- return inputType === "select-radiobuttons";
21
- })();
22
-
23
- const options = (() => {
24
- walk: {
25
- const { inputOptionsFromValidation } = attribute.annotations;
26
-
27
- if (inputOptionsFromValidation === undefined) {
28
- break walk;
29
- }
30
-
31
- const validator = (attribute.validators as Record<string, { options?: string[] }>)[inputOptionsFromValidation];
32
-
33
- if (validator === undefined) {
34
- break walk;
35
- }
36
-
37
- if (validator.options === undefined) {
38
- break walk;
39
- }
40
-
41
- return validator.options;
42
- }
43
-
44
- return attribute.validators.options?.options ?? [];
45
- })();
46
-
47
- if (isRadio) {
48
- return (
49
- <RadioGroup
50
- value={typeof valueOrValues === "string" ? valueOrValues : ""}
51
- onValueChange={value =>
52
- dispatchFormAction({
53
- action: "update",
54
- name: attribute.name,
55
- valueOrValues: value
56
- })
57
- }
58
- disabled={attribute.readOnly}
59
- className="space-y-2"
60
- >
61
- {options.map(option => (
62
- <div key={option} className="flex items-center space-x-2">
63
- <RadioGroupItem
64
- value={option}
65
- id={`${attribute.name}-${option}`}
66
- aria-invalid={props.displayableErrors.length !== 0}
67
- onBlur={() =>
68
- dispatchFormAction({
69
- action: "focus lost",
70
- name: attribute.name,
71
- fieldIndex: undefined
72
- })
73
- }
74
- />
75
- <Label
76
- htmlFor={`${attribute.name}-${option}`}
77
- className={cn("text-sm font-normal", attribute.readOnly && "opacity-50 cursor-not-allowed")}
78
- >
79
- <InputLabel attribute={attribute} option={option} />
80
- </Label>
81
- </div>
82
- ))}
83
- </RadioGroup>
84
- );
85
- }
86
-
87
- return (
88
- <div className="space-y-2">
89
- {options.map(option => (
90
- <div key={option} className="flex items-center space-x-2">
91
- <Checkbox
92
- id={`${attribute.name}-${option}`}
93
- checked={valueOrValues instanceof Array ? valueOrValues.includes(option) : valueOrValues === option}
94
- disabled={attribute.readOnly}
95
- onCheckedChange={checked =>
96
- dispatchFormAction({
97
- action: "update",
98
- name: attribute.name,
99
- valueOrValues: (() => {
100
- const isChecked = checked === true;
101
-
102
- if (valueOrValues instanceof Array) {
103
- const newValues = [...valueOrValues];
104
-
105
- if (isChecked) {
106
- newValues.push(option);
107
- } else {
108
- newValues.splice(newValues.indexOf(option), 1);
109
- }
110
-
111
- return newValues;
112
- }
113
-
114
- return isChecked ? option : "";
115
- })()
116
- })
117
- }
118
- onBlur={() =>
119
- dispatchFormAction({
120
- action: "focus lost",
121
- name: attribute.name,
122
- fieldIndex: undefined
123
- })
124
- }
125
- />
126
- <Label
127
- htmlFor={`${attribute.name}-${option}`}
128
- className={cn("text-sm font-normal", attribute.readOnly && "opacity-50 cursor-not-allowed")}
129
- >
130
- <InputLabel attribute={attribute} option={option} />
131
- </Label>
132
- </div>
133
- ))}
134
- </div>
135
- );
1
+
2
+ import { cn } from '@/components/lib/utils';
3
+ import { Checkbox } from '@/components/ui/checkbox';
4
+ import { Label } from '@/components/ui/label';
5
+ import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group';
6
+ import { assert } from 'tsafe/assert';
7
+ import type { InputFieldByTypeProps } from "./InputFieldByType";
8
+ import { InputLabel } from './InputLabel';
9
+
10
+ export function InputTagSelects(props: InputFieldByTypeProps) {
11
+ const { attribute, dispatchFormAction, valueOrValues } = props;
12
+
13
+
14
+
15
+ const isRadio = (() => {
16
+ const { inputType } = attribute.annotations;
17
+
18
+ assert(inputType === "select-radiobuttons" || inputType === "multiselect-checkboxes");
19
+
20
+ return inputType === "select-radiobuttons";
21
+ })();
22
+
23
+ const options = (() => {
24
+ walk: {
25
+ const { inputOptionsFromValidation } = attribute.annotations;
26
+
27
+ if (inputOptionsFromValidation === undefined) {
28
+ break walk;
29
+ }
30
+
31
+ const validator = (attribute.validators as Record<string, { options?: string[] }>)[inputOptionsFromValidation];
32
+
33
+ if (validator === undefined) {
34
+ break walk;
35
+ }
36
+
37
+ if (validator.options === undefined) {
38
+ break walk;
39
+ }
40
+
41
+ return validator.options;
42
+ }
43
+
44
+ return attribute.validators.options?.options ?? [];
45
+ })();
46
+
47
+ if (isRadio) {
48
+ return (
49
+ <RadioGroup
50
+ value={typeof valueOrValues === "string" ? valueOrValues : ""}
51
+ onValueChange={value =>
52
+ dispatchFormAction({
53
+ action: "update",
54
+ name: attribute.name,
55
+ valueOrValues: value
56
+ })
57
+ }
58
+ disabled={attribute.readOnly}
59
+ className="space-y-2"
60
+ >
61
+ {options.map(option => (
62
+ <div key={option} className="flex items-center space-x-2">
63
+ <RadioGroupItem
64
+ value={option}
65
+ id={`${attribute.name}-${option}`}
66
+ aria-invalid={props.displayableErrors.length !== 0}
67
+ onBlur={() =>
68
+ dispatchFormAction({
69
+ action: "focus lost",
70
+ name: attribute.name,
71
+ fieldIndex: undefined
72
+ })
73
+ }
74
+ />
75
+ <Label
76
+ htmlFor={`${attribute.name}-${option}`}
77
+ className={cn("text-sm font-normal", attribute.readOnly && "opacity-50 cursor-not-allowed")}
78
+ >
79
+ <InputLabel attribute={attribute} option={option} />
80
+ </Label>
81
+ </div>
82
+ ))}
83
+ </RadioGroup>
84
+ );
85
+ }
86
+
87
+ return (
88
+ <div className="space-y-2">
89
+ {options.map(option => (
90
+ <div key={option} className="flex items-center space-x-2">
91
+ <Checkbox
92
+ id={`${attribute.name}-${option}`}
93
+ checked={valueOrValues instanceof Array ? valueOrValues.includes(option) : valueOrValues === option}
94
+ disabled={attribute.readOnly}
95
+ onCheckedChange={checked =>
96
+ dispatchFormAction({
97
+ action: "update",
98
+ name: attribute.name,
99
+ valueOrValues: (() => {
100
+ const isChecked = checked === true;
101
+
102
+ if (valueOrValues instanceof Array) {
103
+ const newValues = [...valueOrValues];
104
+
105
+ if (isChecked) {
106
+ newValues.push(option);
107
+ } else {
108
+ newValues.splice(newValues.indexOf(option), 1);
109
+ }
110
+
111
+ return newValues;
112
+ }
113
+
114
+ return isChecked ? option : "";
115
+ })()
116
+ })
117
+ }
118
+ onBlur={() =>
119
+ dispatchFormAction({
120
+ action: "focus lost",
121
+ name: attribute.name,
122
+ fieldIndex: undefined
123
+ })
124
+ }
125
+ />
126
+ <Label
127
+ htmlFor={`${attribute.name}-${option}`}
128
+ className={cn("text-sm font-normal", attribute.readOnly && "opacity-50 cursor-not-allowed")}
129
+ >
130
+ <InputLabel attribute={attribute} option={option} />
131
+ </Label>
132
+ </div>
133
+ ))}
134
+ </div>
135
+ );
136
136
  }