@scm-manager/ui-core 3.0.0-20240024-101702

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 (128) hide show
  1. package/.storybook/.babelrc +3 -0
  2. package/.storybook/RemoveThemesPlugin.js +57 -0
  3. package/.storybook/main.js +92 -0
  4. package/.storybook/preview-head.html +25 -0
  5. package/.storybook/preview.js +95 -0
  6. package/.storybook/withApiProvider.js +46 -0
  7. package/docs/introduction.stories.mdx +64 -0
  8. package/docs/usage.stories.mdx +22 -0
  9. package/package.json +81 -0
  10. package/src/base/buttons/Button.stories.tsx +89 -0
  11. package/src/base/buttons/Button.test.stories.mdx +74 -0
  12. package/src/base/buttons/Button.tsx +143 -0
  13. package/src/base/buttons/Icon.tsx +58 -0
  14. package/src/base/buttons/a11y.test.ts +34 -0
  15. package/src/base/buttons/docs/introduction.stories.mdx +64 -0
  16. package/src/base/buttons/docs/usage.stories.mdx +22 -0
  17. package/src/base/buttons/image-snapshot.test.ts +33 -0
  18. package/src/base/buttons/index.ts +26 -0
  19. package/src/base/forms/AddListEntryForm.tsx +127 -0
  20. package/src/base/forms/ConfigurationForm.tsx +59 -0
  21. package/src/base/forms/Form.stories.tsx +453 -0
  22. package/src/base/forms/Form.tsx +215 -0
  23. package/src/base/forms/FormPathContext.tsx +73 -0
  24. package/src/base/forms/FormRow.tsx +37 -0
  25. package/src/base/forms/ScmFormContext.tsx +43 -0
  26. package/src/base/forms/ScmFormListContext.tsx +65 -0
  27. package/src/base/forms/base/Control.tsx +34 -0
  28. package/src/base/forms/base/Field.tsx +35 -0
  29. package/src/base/forms/base/field-message/FieldMessage.tsx +34 -0
  30. package/src/base/forms/base/help/Help.tsx +34 -0
  31. package/src/base/forms/base/label/Label.tsx +35 -0
  32. package/src/base/forms/checkbox/Checkbox.stories.mdx +26 -0
  33. package/src/base/forms/checkbox/Checkbox.tsx +118 -0
  34. package/src/base/forms/checkbox/CheckboxField.tsx +39 -0
  35. package/src/base/forms/checkbox/ControlledCheckboxField.stories.mdx +36 -0
  36. package/src/base/forms/checkbox/ControlledCheckboxField.tsx +82 -0
  37. package/src/base/forms/chip-input/ChipInputField.stories.tsx +75 -0
  38. package/src/base/forms/chip-input/ChipInputField.tsx +169 -0
  39. package/src/base/forms/chip-input/ControlledChipInputField.tsx +111 -0
  40. package/src/base/forms/combobox/Combobox.stories.tsx +125 -0
  41. package/src/base/forms/combobox/Combobox.tsx +223 -0
  42. package/src/base/forms/combobox/ComboboxField.tsx +62 -0
  43. package/src/base/forms/combobox/ControlledComboboxField.tsx +96 -0
  44. package/src/base/forms/headless-chip-input/ChipInput.tsx +237 -0
  45. package/src/base/forms/helpers.ts +74 -0
  46. package/src/base/forms/index.ts +85 -0
  47. package/src/base/forms/input/ControlledInputField.stories.mdx +36 -0
  48. package/src/base/forms/input/ControlledInputField.tsx +87 -0
  49. package/src/base/forms/input/ControlledSecretConfirmationField.stories.mdx +39 -0
  50. package/src/base/forms/input/ControlledSecretConfirmationField.tsx +138 -0
  51. package/src/base/forms/input/Input.stories.mdx +22 -0
  52. package/src/base/forms/input/Input.tsx +46 -0
  53. package/src/base/forms/input/InputField.stories.mdx +22 -0
  54. package/src/base/forms/input/InputField.tsx +61 -0
  55. package/src/base/forms/input/Textarea.stories.mdx +28 -0
  56. package/src/base/forms/input/Textarea.tsx +46 -0
  57. package/src/base/forms/list/ControlledList.tsx +88 -0
  58. package/src/base/forms/radio-button/ControlledRadioGroupField.tsx +94 -0
  59. package/src/base/forms/radio-button/RadioButton.stories.tsx +226 -0
  60. package/src/base/forms/radio-button/RadioButton.tsx +116 -0
  61. package/src/base/forms/radio-button/RadioButtonContext.tsx +42 -0
  62. package/src/base/forms/radio-button/RadioGroup.tsx +49 -0
  63. package/src/base/forms/radio-button/RadioGroupField.tsx +58 -0
  64. package/src/base/forms/resourceHooks.ts +164 -0
  65. package/src/base/forms/select/ControlledSelectField.tsx +87 -0
  66. package/src/base/forms/select/Select.tsx +57 -0
  67. package/src/base/forms/select/SelectField.tsx +63 -0
  68. package/src/base/forms/table/ControlledColumn.tsx +49 -0
  69. package/src/base/forms/table/ControlledTable.tsx +99 -0
  70. package/src/base/forms/variants.ts +27 -0
  71. package/src/base/helpers/devbuild.ts +44 -0
  72. package/src/base/helpers/index.ts +26 -0
  73. package/src/base/helpers/useAriaId.tsx +31 -0
  74. package/src/base/index.ts +34 -0
  75. package/src/base/layout/_helpers/with-classes.tsx +52 -0
  76. package/src/base/layout/card/Card.stories.tsx +113 -0
  77. package/src/base/layout/card/Card.tsx +76 -0
  78. package/src/base/layout/card/CardDetail.tsx +196 -0
  79. package/src/base/layout/card/CardRow.tsx +46 -0
  80. package/src/base/layout/card/CardTitle.tsx +59 -0
  81. package/src/base/layout/card-list/CardList.stories.tsx +201 -0
  82. package/src/base/layout/card-list/CardList.tsx +76 -0
  83. package/src/base/layout/collapsible/Collapsible.stories.tsx +45 -0
  84. package/src/base/layout/collapsible/Collapsible.tsx +87 -0
  85. package/src/base/layout/index.ts +93 -0
  86. package/src/base/layout/tabs/TabTrigger.tsx +46 -0
  87. package/src/base/layout/tabs/Tabs.stories.tsx +48 -0
  88. package/src/base/layout/tabs/Tabs.tsx +52 -0
  89. package/src/base/layout/tabs/TabsContent.tsx +33 -0
  90. package/src/base/layout/tabs/TabsList.tsx +41 -0
  91. package/src/base/layout/templates/data-page/DataPage.stories.tsx +201 -0
  92. package/src/base/layout/templates/data-page/DataPageHeader.tsx +100 -0
  93. package/src/base/misc/Image.tsx +32 -0
  94. package/src/base/misc/Level.tsx +40 -0
  95. package/src/base/misc/Loading.tsx +64 -0
  96. package/src/base/misc/SubSubtitle.tsx +36 -0
  97. package/src/base/misc/Subtitle.tsx +37 -0
  98. package/src/base/misc/Title.tsx +56 -0
  99. package/src/base/misc/index.ts +30 -0
  100. package/src/base/notifications/BackendErrorNotification.tsx +160 -0
  101. package/src/base/notifications/ErrorNotification.tsx +73 -0
  102. package/src/base/notifications/Notification.tsx +48 -0
  103. package/src/base/notifications/index.tsx +27 -0
  104. package/src/base/overlays/dialog/Dialog.stories.tsx +64 -0
  105. package/src/base/overlays/dialog/Dialog.tsx +85 -0
  106. package/src/base/overlays/index.ts +44 -0
  107. package/src/base/overlays/menu/Menu.stories.tsx +78 -0
  108. package/src/base/overlays/menu/Menu.tsx +213 -0
  109. package/src/base/overlays/menu/MenuTrigger.tsx +63 -0
  110. package/src/base/overlays/popover/Popover.stories.tsx +69 -0
  111. package/src/base/overlays/popover/Popover.tsx +95 -0
  112. package/src/base/overlays/tooltip/Tooltip.examples.js +41 -0
  113. package/src/base/overlays/tooltip/Tooltip.stories.mdx +52 -0
  114. package/src/base/overlays/tooltip/Tooltip.tsx +96 -0
  115. package/src/base/shortcuts/index.ts +28 -0
  116. package/src/base/shortcuts/iterator/callbackIterator.ts +220 -0
  117. package/src/base/shortcuts/iterator/keyboardIterator.test.tsx +431 -0
  118. package/src/base/shortcuts/iterator/keyboardIterator.tsx +141 -0
  119. package/src/base/shortcuts/usePauseShortcuts.ts +44 -0
  120. package/src/base/shortcuts/useShortcut.ts +110 -0
  121. package/src/base/shortcuts/useShortcutDocs.tsx +54 -0
  122. package/src/base/text/SplitAndReplace.stories.tsx +83 -0
  123. package/src/base/text/SplitAndReplace.tsx +65 -0
  124. package/src/base/text/index.ts +25 -0
  125. package/src/base/text/textSplitAndReplace.test.ts +134 -0
  126. package/src/base/text/textSplitAndReplace.ts +86 -0
  127. package/src/index.ts +25 -0
  128. package/tsconfig.json +6 -0
@@ -0,0 +1,85 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2020-present Cloudogu GmbH and Contributors
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import FormCmp from "./Form";
26
+ import FormRow from "./FormRow";
27
+ import ControlledInputField from "./input/ControlledInputField";
28
+ import ControlledCheckboxField from "./checkbox/ControlledCheckboxField";
29
+ import ControlledSecretConfirmationField from "./input/ControlledSecretConfirmationField";
30
+ import ControlledSelectField from "./select/ControlledSelectField";
31
+ import ControlledChipInputField from "./chip-input/ControlledChipInputField";
32
+ import { ScmFormListContextProvider } from "./ScmFormListContext";
33
+ import ControlledList from "./list/ControlledList";
34
+ import ControlledTable from "./table/ControlledTable";
35
+ import ControlledColumn from "./table/ControlledColumn";
36
+ import AddListEntryForm from "./AddListEntryForm";
37
+ import { ScmNestedFormPathContextProvider } from "./FormPathContext";
38
+ import ControlledComboboxField from "./combobox/ControlledComboboxField";
39
+ import ChipInputFieldComponent from "./chip-input/ChipInputField";
40
+ import ChipInput from "./headless-chip-input/ChipInput";
41
+ import ControlledRadioGroupField from "./radio-button/ControlledRadioGroupField";
42
+ import RadioGroupComponent from "./radio-button/RadioGroup";
43
+ import RadioButton from "./radio-button/RadioButton";
44
+ import RadioGroupFieldComponent from "./radio-button/RadioGroupField";
45
+
46
+ export { default as Field } from "./base/Field";
47
+ export { default as Checkbox } from "./checkbox/Checkbox";
48
+ export { default as Combobox } from "./combobox/Combobox";
49
+ export { default as ConfigurationForm } from "./ConfigurationForm";
50
+ export { default as SelectField } from "./select/SelectField";
51
+ export { default as ComboboxField } from "./combobox/ComboboxField";
52
+ export { default as Input } from "./input/Input";
53
+ export { default as Textarea } from "./input/Textarea";
54
+ export { default as Select } from "./select/Select";
55
+ export * from "./resourceHooks";
56
+ export { default as Label } from "./base/label/Label";
57
+
58
+ const RadioGroupExport = {
59
+ Option: RadioButton,
60
+ };
61
+
62
+ export const RadioGroup = Object.assign(RadioGroupComponent, RadioGroupExport);
63
+ export const RadioGroupField = Object.assign(RadioGroupFieldComponent, RadioGroupExport);
64
+
65
+ export const ChipInputField = Object.assign(ChipInputFieldComponent, {
66
+ AddButton: ChipInput.AddButton,
67
+ });
68
+
69
+ export const Form = Object.assign(FormCmp, {
70
+ Row: FormRow,
71
+ Input: ControlledInputField,
72
+ Checkbox: ControlledCheckboxField,
73
+ SecretConfirmation: ControlledSecretConfirmationField,
74
+ Select: ControlledSelectField,
75
+ PathContext: ScmNestedFormPathContextProvider,
76
+ ListContext: ScmFormListContextProvider,
77
+ List: ControlledList,
78
+ AddListEntryForm: AddListEntryForm,
79
+ Table: Object.assign(ControlledTable, {
80
+ Column: ControlledColumn,
81
+ }),
82
+ ChipInput: ControlledChipInputField,
83
+ Combobox: ControlledComboboxField,
84
+ RadioGroup: Object.assign(ControlledRadioGroupField, RadioGroupExport),
85
+ });
@@ -0,0 +1,36 @@
1
+ import { Meta, Story } from "@storybook/addon-docs";
2
+ import Form from "../Form";
3
+ import ControlledInputField from "./ControlledInputField";
4
+
5
+ <Meta
6
+ title="ControlledInputField"
7
+ decorators={[
8
+ (Story) => (
9
+ <Form onSubmit={console.log} defaultValues={{name: "Initial value"}} translationPath={["sample", "form"]}>
10
+ <Story />
11
+ </Form>
12
+ ),
13
+ ]}
14
+ />
15
+
16
+ <Story name="Default">
17
+ <ControlledInputField name="name" />
18
+ </Story>
19
+
20
+ <Story name="WithHardcodedText">
21
+ <ControlledInputField name="name" label="Name" helpText="A help text" />
22
+ </Story>
23
+
24
+ <Story name="WithStyling">
25
+ <ControlledInputField name="name" className="has-background-blue-light" />
26
+ </Story>
27
+
28
+ <Story name="WithCheck">
29
+ <ControlledInputField name="name" rules={{
30
+ required: true
31
+ }} />
32
+ </Story>
33
+
34
+ <Story name="WithInitialFocus">
35
+ <ControlledInputField name="name" autoFocus={true} />
36
+ </Story>
@@ -0,0 +1,87 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2020-present Cloudogu GmbH and Contributors
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import React, { ComponentProps } from "react";
26
+ import { Controller, ControllerRenderProps, Path } from "react-hook-form";
27
+ import { useScmFormContext } from "../ScmFormContext";
28
+ import InputField from "./InputField";
29
+ import { useScmFormPathContext } from "../FormPathContext";
30
+ import { prefixWithoutIndices } from "../helpers";
31
+ import classNames from "classnames";
32
+
33
+ type Props<T extends Record<string, unknown>> = Omit<
34
+ ComponentProps<typeof InputField>,
35
+ "error" | "label" | "defaultChecked" | "required" | keyof ControllerRenderProps
36
+ > & {
37
+ rules?: ComponentProps<typeof Controller>["rules"];
38
+ name: Path<T>;
39
+ label?: string;
40
+ };
41
+
42
+ function ControlledInputField<T extends Record<string, unknown>>({
43
+ name,
44
+ label,
45
+ helpText,
46
+ rules,
47
+ testId,
48
+ defaultValue,
49
+ readOnly,
50
+ className,
51
+ ...props
52
+ }: Props<T>) {
53
+ const { control, t, readOnly: formReadonly, formId } = useScmFormContext();
54
+ const formPathPrefix = useScmFormPathContext();
55
+ const nameWithPrefix = formPathPrefix ? `${formPathPrefix}.${name}` : name;
56
+ const prefixedNameWithoutIndices = prefixWithoutIndices(nameWithPrefix);
57
+ const labelTranslation = label || t(`${prefixedNameWithoutIndices}.label`) || "";
58
+ const helpTextTranslation = helpText || t(`${prefixedNameWithoutIndices}.helpText`);
59
+ return (
60
+ <Controller
61
+ control={control}
62
+ name={nameWithPrefix}
63
+ rules={rules}
64
+ defaultValue={defaultValue as never}
65
+ render={({ field, fieldState }) => (
66
+ <InputField
67
+ readOnly={readOnly ?? formReadonly}
68
+ required={rules?.required as boolean}
69
+ className={classNames("column", className)}
70
+ {...props}
71
+ {...field}
72
+ form={formId}
73
+ label={labelTranslation}
74
+ helpText={helpTextTranslation}
75
+ error={
76
+ fieldState.error
77
+ ? fieldState.error.message || t(`${prefixedNameWithoutIndices}.error.${fieldState.error.type}`)
78
+ : undefined
79
+ }
80
+ testId={testId ?? `input-${nameWithPrefix}`}
81
+ />
82
+ )}
83
+ />
84
+ );
85
+ }
86
+
87
+ export default ControlledInputField;
@@ -0,0 +1,39 @@
1
+ import { Meta, Story } from "@storybook/addon-docs";
2
+ import Form from "../Form";
3
+ import ControlledSecretConfirmationField from "./ControlledSecretConfirmationField";
4
+
5
+ <Meta
6
+ title="ControlledSecretConfirmationField"
7
+ decorators={[
8
+ (Story) => (
9
+ <Form onSubmit={console.log} defaultValues={{ password: "", passwordConfirmation: "" }} translationPath={["sample", "form"]}>
10
+ <Story />
11
+ </Form>
12
+ ),
13
+ ]}
14
+ />
15
+
16
+ <Story name="Default">
17
+ <ControlledSecretConfirmationField name="password" />
18
+ </Story>
19
+
20
+ <Story name="WithHardcodedText">
21
+ <ControlledSecretConfirmationField name="password" label="Password" confirmationLabel="Password Confirmation" helpText="A help text" confirmationHelpText="Another help text" />
22
+ </Story>
23
+
24
+ <Story name="WithStyling">
25
+ <ControlledSecretConfirmationField name="password" className="has-background-blue-light" />
26
+ </Story>
27
+
28
+ <Story name="WithCheck">
29
+ <ControlledSecretConfirmationField
30
+ name="password"
31
+ rules={{
32
+ required: true,
33
+ }}
34
+ />
35
+ </Story>
36
+
37
+ <Story name="WithInitialFocus">
38
+ <ControlledSecretConfirmationField name="password" autoFocus={true} />
39
+ </Story>
@@ -0,0 +1,138 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2020-present Cloudogu GmbH and Contributors
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import React, { ComponentProps, useCallback, useMemo } from "react";
26
+ import { Controller, ControllerRenderProps, Path } from "react-hook-form";
27
+ import { useScmFormContext } from "../ScmFormContext";
28
+ import InputField from "./InputField";
29
+ import { useScmFormPathContext } from "../FormPathContext";
30
+ import { prefixWithoutIndices } from "../helpers";
31
+ import classNames from "classnames";
32
+
33
+ type Props<T extends Record<string, unknown>> = Omit<
34
+ ComponentProps<typeof InputField>,
35
+ "error" | "label" | "defaultChecked" | "required" | keyof ControllerRenderProps
36
+ > & {
37
+ rules?: ComponentProps<typeof Controller>["rules"];
38
+ name: Path<T>;
39
+ label?: string;
40
+ confirmationLabel?: string;
41
+ confirmationHelpText?: string;
42
+ confirmationErrorMessage?: string;
43
+ confirmationTestId?: string;
44
+ };
45
+
46
+ export default function ControlledSecretConfirmationField<T extends Record<string, unknown>>({
47
+ name,
48
+ label,
49
+ confirmationLabel,
50
+ helpText,
51
+ confirmationHelpText,
52
+ rules,
53
+ confirmationErrorMessage,
54
+ className,
55
+ testId,
56
+ confirmationTestId,
57
+ defaultValue,
58
+ readOnly,
59
+ ...props
60
+ }: Props<T>) {
61
+ const { control, watch, t, readOnly: formReadonly, formId } = useScmFormContext();
62
+ const formPathPrefix = useScmFormPathContext();
63
+ const nameWithPrefix = formPathPrefix ? `${formPathPrefix}.${name}` : name;
64
+ const prefixedNameWithoutIndices = prefixWithoutIndices(nameWithPrefix);
65
+ const labelTranslation = label || t(`${prefixedNameWithoutIndices}.label`) || "";
66
+ const helpTextTranslation = helpText || t(`${prefixedNameWithoutIndices}.helpText`);
67
+ const confirmationLabelTranslation = confirmationLabel || t(`${prefixedNameWithoutIndices}.confirmation.label`) || "";
68
+ const confirmationHelpTextTranslation =
69
+ confirmationHelpText || t(`${prefixedNameWithoutIndices}.confirmation.helpText`);
70
+ const confirmationErrorMessageTranslation =
71
+ confirmationErrorMessage || t(`${prefixedNameWithoutIndices}.confirmation.errorMessage`);
72
+ const secretValue = watch(nameWithPrefix);
73
+ const validateConfirmField = useCallback(
74
+ (value) => secretValue === value || confirmationErrorMessageTranslation,
75
+ [confirmationErrorMessageTranslation, secretValue]
76
+ );
77
+ const confirmFieldRules = useMemo(
78
+ () => ({
79
+ validate: validateConfirmField,
80
+ }),
81
+ [validateConfirmField]
82
+ );
83
+
84
+ return (
85
+ <>
86
+ <Controller
87
+ control={control}
88
+ name={nameWithPrefix}
89
+ defaultValue={defaultValue as never}
90
+ rules={{
91
+ ...rules,
92
+ deps: [`${nameWithPrefix}Confirmation`],
93
+ }}
94
+ render={({ field, fieldState }) => (
95
+ <InputField
96
+ className={classNames("column", className)}
97
+ readOnly={readOnly ?? formReadonly}
98
+ {...props}
99
+ {...field}
100
+ form={formId}
101
+ required={rules?.required as boolean}
102
+ type="password"
103
+ label={labelTranslation}
104
+ helpText={helpTextTranslation}
105
+ error={
106
+ fieldState.error
107
+ ? fieldState.error.message || t(`${prefixedNameWithoutIndices}.error.${fieldState.error.type}`)
108
+ : undefined
109
+ }
110
+ testId={testId ?? `input-${nameWithPrefix}`}
111
+ />
112
+ )}
113
+ />
114
+ <Controller
115
+ control={control}
116
+ name={`${nameWithPrefix}Confirmation`}
117
+ defaultValue={defaultValue as never}
118
+ render={({ field, fieldState: { error } }) => (
119
+ <InputField
120
+ className={classNames("column", className)}
121
+ type="password"
122
+ readOnly={readOnly ?? formReadonly}
123
+ disabled={props.disabled}
124
+ {...field}
125
+ form={formId}
126
+ label={confirmationLabelTranslation}
127
+ helpText={confirmationHelpTextTranslation}
128
+ error={
129
+ error ? error.message || t(`${prefixedNameWithoutIndices}.confirmation.error.${error.type}`) : undefined
130
+ }
131
+ testId={confirmationTestId ?? `input-${nameWithPrefix}-confirmation`}
132
+ />
133
+ )}
134
+ rules={confirmFieldRules}
135
+ />
136
+ </>
137
+ );
138
+ }
@@ -0,0 +1,22 @@
1
+ import { Meta, Story } from "@storybook/addon-docs";
2
+ import Input from "./Input"
3
+
4
+ <Meta title="Input" />
5
+
6
+ This will be our latest input component
7
+
8
+ <Story name="Default">
9
+ <Input />
10
+ </Story>
11
+
12
+ <Story name="With Variant">
13
+ <Input variant="danger" />
14
+ </Story>
15
+
16
+ <Story name="With Custom Class">
17
+ <Input className="is-warning" />
18
+ </Story>
19
+
20
+ <Story name="With Ref">
21
+ <Input ref={r => {r.focus()}} />
22
+ </Story>
@@ -0,0 +1,46 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2020-present Cloudogu GmbH and Contributors
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import React, { InputHTMLAttributes } from "react";
26
+ import classNames from "classnames";
27
+ import { createVariantClass, Variant } from "../variants";
28
+ import { createAttributesForTesting } from "../../helpers";
29
+
30
+ type Props = {
31
+ variant?: Variant;
32
+ testId?: string;
33
+ } & InputHTMLAttributes<HTMLInputElement>;
34
+
35
+ const Input = React.forwardRef<HTMLInputElement, Props>(({ variant, className, testId, ...props }, ref) => {
36
+ return (
37
+ <input
38
+ ref={ref}
39
+ className={classNames("input", createVariantClass(variant), className)}
40
+ {...props}
41
+ {...createAttributesForTesting(testId)}
42
+ />
43
+ );
44
+ });
45
+
46
+ export default Input;
@@ -0,0 +1,22 @@
1
+ import { Meta, Story } from "@storybook/addon-docs";
2
+ import InputField from "./InputField";
3
+
4
+ <Meta title="InputField" />
5
+
6
+ This will be our first form field molecule
7
+
8
+ <Story name="Default">
9
+ <InputField label="MyInput" />
10
+ </Story>
11
+
12
+ <Story name="WithHelp">
13
+ <InputField label="MyInput" helpText="You can do all sorts of things with this input" />
14
+ </Story>
15
+
16
+ <Story name="WithError">
17
+ <InputField label="MyInput" error="This field is super required" />
18
+ </Story>
19
+
20
+ <Story name="WithWidth">
21
+ <InputField label="MyInput" className="column is-half" />
22
+ </Story>
@@ -0,0 +1,61 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2020-present Cloudogu GmbH and Contributors
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import React from "react";
26
+ import Field from "../base/Field";
27
+ import Control from "../base/Control";
28
+ import Label from "../base/label/Label";
29
+ import FieldMessage from "../base/field-message/FieldMessage";
30
+ import Input from "./Input";
31
+ import Help from "../base/help/Help";
32
+ import { useAriaId } from "../../helpers";
33
+
34
+ type InputFieldProps = {
35
+ label: string;
36
+ helpText?: string;
37
+ error?: string;
38
+ } & React.ComponentProps<typeof Input>;
39
+
40
+ /**
41
+ * @see https://bulma.io/documentation/form/input/
42
+ */
43
+ const InputField = React.forwardRef<HTMLInputElement, InputFieldProps>(
44
+ ({ label, helpText, error, className, id, ...props }, ref) => {
45
+ const inputId = useAriaId(id ?? props.testId);
46
+ const variant = error ? "danger" : undefined;
47
+ return (
48
+ <Field className={className}>
49
+ <Label htmlFor={inputId}>
50
+ {label}
51
+ {helpText ? <Help className="ml-1" text={helpText} /> : null}
52
+ </Label>
53
+ <Control>
54
+ <Input variant={variant} ref={ref} id={inputId} {...props}></Input>
55
+ </Control>
56
+ {error ? <FieldMessage variant={variant}>{error}</FieldMessage> : null}
57
+ </Field>
58
+ );
59
+ }
60
+ );
61
+ export default InputField;
@@ -0,0 +1,28 @@
1
+ import { Meta, Story } from "@storybook/addon-docs";
2
+ import Textarea from "./Textarea"
3
+
4
+ <Meta title="Textarea" />
5
+
6
+ This will be our latest Textarea component
7
+
8
+ <Story name="Default">
9
+ <Textarea />
10
+ </Story>
11
+
12
+ <Story name="With Variant">
13
+ <Textarea variant="danger" />
14
+ </Story>
15
+
16
+ <Story name="With Custom Class">
17
+ <Textarea className="is-warning" />
18
+ </Story>
19
+
20
+ <Story name="With Ref">
21
+ <Textarea ref={r => {r.focus()}} />
22
+ </Story>
23
+
24
+ <Story name="With Default Value">
25
+ <Textarea>
26
+ value
27
+ </Textarea>
28
+ </Story>
@@ -0,0 +1,46 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2020-present Cloudogu GmbH and Contributors
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import React, { InputHTMLAttributes } from "react";
26
+ import classNames from "classnames";
27
+ import { createVariantClass, Variant } from "../variants";
28
+ import { createAttributesForTesting } from "../../helpers";
29
+
30
+ type Props = {
31
+ variant?: Variant;
32
+ testId?: string;
33
+ } & InputHTMLAttributes<HTMLTextAreaElement>;
34
+
35
+ const Textarea = React.forwardRef<HTMLTextAreaElement, Props>(({ variant, className, testId, ...props }, ref) => {
36
+ return (
37
+ <textarea
38
+ ref={ref}
39
+ className={classNames("textarea", createVariantClass(variant), className)}
40
+ {...props}
41
+ {...createAttributesForTesting(testId)}
42
+ />
43
+ );
44
+ });
45
+
46
+ export default Textarea;