@scm-manager/ui-forms 2.40.2-SNAPSHOT-1

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 (39) hide show
  1. package/.storybook/RemoveThemesPlugin.js +57 -0
  2. package/.storybook/main.js +92 -0
  3. package/.storybook/preview-head.html +26 -0
  4. package/.storybook/preview.js +72 -0
  5. package/.turbo/turbo-build.log +15 -0
  6. package/build/index.d.ts +124 -0
  7. package/build/index.js +639 -0
  8. package/build/index.mjs +602 -0
  9. package/package.json +50 -0
  10. package/src/ConfigurationForm.tsx +54 -0
  11. package/src/Form.stories.mdx +160 -0
  12. package/src/Form.tsx +164 -0
  13. package/src/FormRow.tsx +37 -0
  14. package/src/ScmFormContext.tsx +42 -0
  15. package/src/base/Control.tsx +34 -0
  16. package/src/base/Field.tsx +33 -0
  17. package/src/base/field-message/FieldMessage.tsx +34 -0
  18. package/src/base/help/Help.tsx +36 -0
  19. package/src/base/label/Label.tsx +33 -0
  20. package/src/checkbox/Checkbox.stories.mdx +26 -0
  21. package/src/checkbox/Checkbox.tsx +85 -0
  22. package/src/checkbox/CheckboxField.tsx +39 -0
  23. package/src/checkbox/ControlledCheckboxField.stories.mdx +36 -0
  24. package/src/checkbox/ControlledCheckboxField.tsx +76 -0
  25. package/src/index.ts +27 -0
  26. package/src/input/ControlledInputField.stories.mdx +36 -0
  27. package/src/input/ControlledInputField.tsx +77 -0
  28. package/src/input/ControlledSecretConfirmationField.stories.mdx +39 -0
  29. package/src/input/ControlledSecretConfirmationField.tsx +121 -0
  30. package/src/input/Input.stories.mdx +22 -0
  31. package/src/input/Input.tsx +46 -0
  32. package/src/input/InputField.stories.mdx +22 -0
  33. package/src/input/InputField.tsx +60 -0
  34. package/src/resourceHooks.ts +155 -0
  35. package/src/select/ControlledSelectField.tsx +77 -0
  36. package/src/select/Select.tsx +43 -0
  37. package/src/select/SelectField.tsx +59 -0
  38. package/src/variants.ts +27 -0
  39. package/tsconfig.json +3 -0
@@ -0,0 +1,160 @@
1
+ import { Meta, Story } from "@storybook/addon-docs";
2
+ import Form from "./Form";
3
+ import FormRow from "./FormRow";
4
+ import ControlledInputField from "./input/ControlledInputField";
5
+ import ControlledSecretConfirmationField from "./input/ControlledSecretConfirmationField";
6
+ import ControlledCheckboxField from "./checkbox/ControlledCheckboxField";
7
+
8
+ <Meta title="Form" />
9
+
10
+ <Story name="Creation">
11
+ <Form
12
+ onSubmit={console.log}
13
+ translationPath={["sample", "form"]}
14
+ defaultValues={{
15
+ name: "",
16
+ password: "",
17
+ active: true,
18
+ }}
19
+ >
20
+ <FormRow>
21
+ <ControlledInputField name="name" />
22
+ </FormRow>
23
+ <FormRow>
24
+ <ControlledSecretConfirmationField name="password" />
25
+ </FormRow>
26
+ <FormRow>
27
+ <ControlledCheckboxField name="active" />
28
+ </FormRow>
29
+ </Form>
30
+ </Story>
31
+
32
+ <Story name="Editing">
33
+ <Form
34
+ onSubmit={console.log}
35
+ translationPath={["sample", "form"]}
36
+ defaultValues={{
37
+ name: "trillian",
38
+ password: "secret",
39
+ active: true,
40
+ }}
41
+ >
42
+ <FormRow>
43
+ <ControlledInputField name="name" />
44
+ </FormRow>
45
+ <FormRow>
46
+ <ControlledSecretConfirmationField name="password" />
47
+ </FormRow>
48
+ <FormRow>
49
+ <ControlledCheckboxField name="active" />
50
+ </FormRow>
51
+ </Form>
52
+ </Story>
53
+
54
+ <Story name="GlobalConfiguration">
55
+ <Form
56
+ onSubmit={console.log}
57
+ translationPath={["sample", "form"]}
58
+ defaultValues={{
59
+ url: "",
60
+ filter: "",
61
+ username: "",
62
+ password: "",
63
+ roleLevel: "",
64
+ updateIssues: false,
65
+ disableRepoConfig: false,
66
+ }}
67
+ >
68
+ {({ watch }) => (
69
+ <>
70
+ <FormRow>
71
+ <ControlledInputField name="url" label="URL" helpText="URL of Jira installation (with context path)." />
72
+ </FormRow>
73
+ <FormRow>
74
+ <ControlledInputField name="filter" label="Project Filter" helpText="Filters for jira project key." />
75
+ </FormRow>
76
+ <FormRow>
77
+ <ControlledCheckboxField
78
+ name="updateIssues"
79
+ label="Update Jira Issues"
80
+ helpText="Enable the automatic update function."
81
+ />
82
+ </FormRow>
83
+ <FormRow hide={watch("filter")}>
84
+ <ControlledInputField
85
+ name="username"
86
+ label="Username"
87
+ helpText="Jira username for connection."
88
+ className="is-half"
89
+ />
90
+ <ControlledInputField
91
+ name="password"
92
+ label="Password"
93
+ helpText="Jira password for connection."
94
+ type="password"
95
+ className="is-half"
96
+ />
97
+ </FormRow>
98
+ <FormRow hide={watch("filter")}>
99
+ <ControlledInputField
100
+ name="roleLevel"
101
+ label="Role Visibility"
102
+ helpText="Defines for which Project Role the comments are visible."
103
+ />
104
+ </FormRow>
105
+ <FormRow>
106
+ <ControlledCheckboxField
107
+ name="disableRepoConfig"
108
+ label="Do not allow repository configuration"
109
+ helpText="Do not allow repository owners to configure jira instances."
110
+ />
111
+ </FormRow>
112
+ </>
113
+ )}
114
+ </Form>
115
+ </Story>
116
+
117
+ <Story name="RepoConfiguration">
118
+ <Form
119
+ onSubmit={console.log}
120
+ translationPath={["sample", "form"]}
121
+ defaultValues={{
122
+ url: "",
123
+ option: "",
124
+ anotherOption: "",
125
+ disableA: false,
126
+ disableB: false,
127
+ disableC: true,
128
+ }}
129
+ >
130
+ <ControlledInputField name="url" />
131
+ <ControlledInputField name="option" />
132
+ <ControlledInputField name="anotherOption" />
133
+ <ControlledCheckboxField name="disableA" />
134
+ <ControlledCheckboxField name="disableB" />
135
+ <ControlledCheckboxField name="disableC" />
136
+ </Form>
137
+ </Story>
138
+
139
+ <Story name="ReadOnly">
140
+ <Form
141
+ onSubmit={console.log}
142
+ translationPath={["sample", "form"]}
143
+ defaultValues={{
144
+ name: "trillian",
145
+ password: "secret",
146
+ active: true,
147
+ }}
148
+ readOnly
149
+ >
150
+ <FormRow>
151
+ <ControlledInputField name="name" />
152
+ </FormRow>
153
+ <FormRow>
154
+ <ControlledSecretConfirmationField name="password" />
155
+ </FormRow>
156
+ <FormRow>
157
+ <ControlledCheckboxField name="active" />
158
+ </FormRow>
159
+ </Form>
160
+ </Story>
package/src/Form.tsx ADDED
@@ -0,0 +1,164 @@
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, { FC, useCallback, useEffect, useState } from "react";
26
+ import { DeepPartial, SubmitHandler, useForm, UseFormReturn } from "react-hook-form";
27
+ import { ErrorNotification, Level } from "@scm-manager/ui-components";
28
+ import { ScmFormContextProvider } from "./ScmFormContext";
29
+ import { useTranslation } from "react-i18next";
30
+ import { Button } from "@scm-manager/ui-buttons";
31
+ import FormRow from "./FormRow";
32
+ import ControlledInputField from "./input/ControlledInputField";
33
+ import ControlledCheckboxField from "./checkbox/ControlledCheckboxField";
34
+ import ControlledSecretConfirmationField from "./input/ControlledSecretConfirmationField";
35
+ import { HalRepresentation } from "@scm-manager/ui-types";
36
+ import ControlledSelectField from "./select/ControlledSelectField";
37
+
38
+ type RenderProps<T extends Record<string, unknown>> = Omit<
39
+ UseFormReturn<T>,
40
+ "register" | "unregister" | "handleSubmit" | "control"
41
+ >;
42
+
43
+ const SuccessNotification: FC<{ label?: string; hide: () => void }> = ({ label, hide }) => {
44
+ if (!label) {
45
+ return null;
46
+ }
47
+
48
+ return (
49
+ <div className="notification is-success">
50
+ <button className="delete" onClick={hide} />
51
+ {label}
52
+ </div>
53
+ );
54
+ };
55
+
56
+ type Props<FormType extends Record<string, unknown>, DefaultValues extends FormType> = {
57
+ children: ((renderProps: RenderProps<FormType>) => React.ReactNode | React.ReactNode[]) | React.ReactNode;
58
+ translationPath: [namespace: string, prefix: string];
59
+ onSubmit: SubmitHandler<FormType>;
60
+ defaultValues: Omit<DefaultValues, keyof HalRepresentation>;
61
+ readOnly?: boolean;
62
+ submitButtonTestId?: string;
63
+ };
64
+
65
+ /** @Beta */
66
+ function Form<FormType extends Record<string, unknown>, DefaultValues extends FormType>({
67
+ children,
68
+ onSubmit,
69
+ defaultValues,
70
+ translationPath,
71
+ readOnly,
72
+ submitButtonTestId,
73
+ }: Props<FormType, DefaultValues>) {
74
+ const form = useForm<FormType>({
75
+ mode: "onChange",
76
+ defaultValues: defaultValues as DeepPartial<FormType>,
77
+ });
78
+ const { formState, handleSubmit, reset } = form;
79
+ const [ns, prefix] = translationPath;
80
+ const { t } = useTranslation(ns, { keyPrefix: prefix });
81
+ const { isDirty, isValid, isSubmitting, isSubmitSuccessful } = formState;
82
+ const [error, setError] = useState<Error | null | undefined>();
83
+ const [showSuccessNotification, setShowSuccessNotification] = useState(false);
84
+
85
+ // See https://react-hook-form.com/api/useform/reset/
86
+ useEffect(() => {
87
+ if (isSubmitSuccessful) {
88
+ setShowSuccessNotification(true);
89
+ }
90
+ }, [isSubmitSuccessful]);
91
+
92
+ useEffect(() => reset(defaultValues as never), [defaultValues, reset]);
93
+
94
+ useEffect(() => {
95
+ if (isDirty) {
96
+ setShowSuccessNotification(false);
97
+ }
98
+ }, [isDirty]);
99
+
100
+ const translateWithFallback = useCallback<typeof t>(
101
+ (key, ...args) => {
102
+ const translation = t(key, ...(args as any));
103
+ if (translation === `${prefix}.${key}`) {
104
+ return "";
105
+ }
106
+ return translation;
107
+ },
108
+ [prefix, t]
109
+ );
110
+
111
+ const submit = useCallback(
112
+ async (data) => {
113
+ setError(null);
114
+ try {
115
+ return await onSubmit(data);
116
+ } catch (e) {
117
+ if (e instanceof Error) {
118
+ setError(e);
119
+ } else {
120
+ throw e;
121
+ }
122
+ }
123
+ },
124
+ [onSubmit]
125
+ );
126
+
127
+ return (
128
+ <ScmFormContextProvider {...form} readOnly={isSubmitting || readOnly} t={translateWithFallback}>
129
+ <form onSubmit={handleSubmit(submit)}>
130
+ {showSuccessNotification ? (
131
+ <SuccessNotification
132
+ label={translateWithFallback("submit-success-notification")}
133
+ hide={() => setShowSuccessNotification(false)}
134
+ />
135
+ ) : null}
136
+ {typeof children === "function" ? children(form) : children}
137
+ {error ? <ErrorNotification error={error} /> : null}
138
+ {!readOnly ? (
139
+ <Level
140
+ right={
141
+ <Button
142
+ type="submit"
143
+ variant="primary"
144
+ testId={submitButtonTestId ?? "submit-button"}
145
+ disabled={!isDirty || !isValid}
146
+ isLoading={isSubmitting}
147
+ >
148
+ {t("submit")}
149
+ </Button>
150
+ }
151
+ />
152
+ ) : null}
153
+ </form>
154
+ </ScmFormContextProvider>
155
+ );
156
+ }
157
+
158
+ export default Object.assign(Form, {
159
+ Row: FormRow,
160
+ Input: ControlledInputField,
161
+ Checkbox: ControlledCheckboxField,
162
+ SecretConfirmation: ControlledSecretConfirmationField,
163
+ Select: ControlledSelectField,
164
+ });
@@ -0,0 +1,37 @@
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, { HTMLProps } from "react";
26
+ import classNames from "classnames";
27
+
28
+ const FormRow = React.forwardRef<HTMLDivElement, HTMLProps<HTMLDivElement>>(
29
+ ({ className, children, hidden, ...rest }, ref) =>
30
+ hidden ? null : (
31
+ <div ref={ref} className={classNames("columns", className)} {...rest}>
32
+ {children}
33
+ </div>
34
+ )
35
+ );
36
+
37
+ export default FormRow;
@@ -0,0 +1,42 @@
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, { PropsWithChildren, useContext } from "react";
26
+ import { UseFormReturn } from "react-hook-form";
27
+ import type { TFunction } from "i18next";
28
+
29
+ type ContextType<T = any> = UseFormReturn<T> & {
30
+ t: TFunction;
31
+ readOnly?: boolean;
32
+ };
33
+
34
+ const ScmFormContext = React.createContext<ContextType>(null as unknown as ContextType);
35
+
36
+ export function ScmFormContextProvider<T>({ children, ...props }: PropsWithChildren<ContextType<T>>) {
37
+ return <ScmFormContext.Provider value={props}>{children}</ScmFormContext.Provider>;
38
+ }
39
+
40
+ export function useScmFormContext() {
41
+ return useContext(ScmFormContext);
42
+ }
@@ -0,0 +1,34 @@
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, { FC, HTMLProps } from "react";
26
+ import classNames from "classnames";
27
+
28
+ const Control: FC<HTMLProps<HTMLDivElement>> = ({ className, children, ...rest }) => (
29
+ <div className={classNames("control", className)} {...rest}>
30
+ {children}
31
+ </div>
32
+ );
33
+
34
+ export default Control;
@@ -0,0 +1,33 @@
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, { FC, HTMLProps } from "react";
26
+ import classNames from "classnames";
27
+
28
+ const Field: FC<HTMLProps<HTMLDivElement>> = ({ className, children, ...rest }) => (
29
+ <div className={classNames("field", className)} {...rest}>
30
+ {children}
31
+ </div>
32
+ );
33
+ export default Field;
@@ -0,0 +1,34 @@
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, { ReactNode } from "react";
26
+ import classNames from "classnames";
27
+ import { createVariantClass, Variant } from "../../variants";
28
+
29
+ type Props = { variant?: Variant; className?: string; children?: ReactNode };
30
+
31
+ const FieldMessage = ({ variant, className, children }: Props) => (
32
+ <p className={classNames("help", createVariantClass(variant), className)}>{children}</p>
33
+ );
34
+ export default FieldMessage;
@@ -0,0 +1,36 @@
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 classNames from "classnames";
27
+
28
+ type Props = { text?: string; className?: string };
29
+
30
+ /**
31
+ * TODO: Implement tooltip
32
+ */
33
+ const Help = ({ text, className }: Props) => (
34
+ <span className={classNames("fas fa-fw fa-question-circle has-text-blue-light", className)} title={text} />
35
+ );
36
+ export default Help;
@@ -0,0 +1,33 @@
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, { FC, HTMLProps } from "react";
26
+ import classNames from "classnames";
27
+
28
+ const Label: FC<HTMLProps<HTMLLabelElement>> = ({ className, children, ...rest }) => (
29
+ <label className={classNames("label", className)} {...rest}>
30
+ {children}
31
+ </label>
32
+ );
33
+ export default Label;
@@ -0,0 +1,26 @@
1
+ import {Meta, Story} from "@storybook/addon-docs";
2
+ import Checkbox from "./Checkbox";
3
+
4
+ <Meta
5
+ title="Checkbox"
6
+ />
7
+
8
+ <Story name="Default">
9
+ <Checkbox name="name"/>
10
+ </Story>
11
+
12
+ <Story name="WithHardcodedText">
13
+ <Checkbox name="name" label="Name" helpText="A help text"/>
14
+ </Story>
15
+
16
+ <Story name="WithStyling">
17
+ <Checkbox name="name" className="has-background-blue-light"/>
18
+ </Story>
19
+
20
+ <Story name="WithInitialFocus">
21
+ <Checkbox name="name" autoFocus/>
22
+ </Story>
23
+
24
+ <Story name="Readonly">
25
+ <Checkbox name="name" checked readOnly/>
26
+ </Story>