@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.
- package/.storybook/.babelrc +3 -0
- package/.storybook/RemoveThemesPlugin.js +57 -0
- package/.storybook/main.js +92 -0
- package/.storybook/preview-head.html +25 -0
- package/.storybook/preview.js +95 -0
- package/.storybook/withApiProvider.js +46 -0
- package/docs/introduction.stories.mdx +64 -0
- package/docs/usage.stories.mdx +22 -0
- package/package.json +81 -0
- package/src/base/buttons/Button.stories.tsx +89 -0
- package/src/base/buttons/Button.test.stories.mdx +74 -0
- package/src/base/buttons/Button.tsx +143 -0
- package/src/base/buttons/Icon.tsx +58 -0
- package/src/base/buttons/a11y.test.ts +34 -0
- package/src/base/buttons/docs/introduction.stories.mdx +64 -0
- package/src/base/buttons/docs/usage.stories.mdx +22 -0
- package/src/base/buttons/image-snapshot.test.ts +33 -0
- package/src/base/buttons/index.ts +26 -0
- package/src/base/forms/AddListEntryForm.tsx +127 -0
- package/src/base/forms/ConfigurationForm.tsx +59 -0
- package/src/base/forms/Form.stories.tsx +453 -0
- package/src/base/forms/Form.tsx +215 -0
- package/src/base/forms/FormPathContext.tsx +73 -0
- package/src/base/forms/FormRow.tsx +37 -0
- package/src/base/forms/ScmFormContext.tsx +43 -0
- package/src/base/forms/ScmFormListContext.tsx +65 -0
- package/src/base/forms/base/Control.tsx +34 -0
- package/src/base/forms/base/Field.tsx +35 -0
- package/src/base/forms/base/field-message/FieldMessage.tsx +34 -0
- package/src/base/forms/base/help/Help.tsx +34 -0
- package/src/base/forms/base/label/Label.tsx +35 -0
- package/src/base/forms/checkbox/Checkbox.stories.mdx +26 -0
- package/src/base/forms/checkbox/Checkbox.tsx +118 -0
- package/src/base/forms/checkbox/CheckboxField.tsx +39 -0
- package/src/base/forms/checkbox/ControlledCheckboxField.stories.mdx +36 -0
- package/src/base/forms/checkbox/ControlledCheckboxField.tsx +82 -0
- package/src/base/forms/chip-input/ChipInputField.stories.tsx +75 -0
- package/src/base/forms/chip-input/ChipInputField.tsx +169 -0
- package/src/base/forms/chip-input/ControlledChipInputField.tsx +111 -0
- package/src/base/forms/combobox/Combobox.stories.tsx +125 -0
- package/src/base/forms/combobox/Combobox.tsx +223 -0
- package/src/base/forms/combobox/ComboboxField.tsx +62 -0
- package/src/base/forms/combobox/ControlledComboboxField.tsx +96 -0
- package/src/base/forms/headless-chip-input/ChipInput.tsx +237 -0
- package/src/base/forms/helpers.ts +74 -0
- package/src/base/forms/index.ts +85 -0
- package/src/base/forms/input/ControlledInputField.stories.mdx +36 -0
- package/src/base/forms/input/ControlledInputField.tsx +87 -0
- package/src/base/forms/input/ControlledSecretConfirmationField.stories.mdx +39 -0
- package/src/base/forms/input/ControlledSecretConfirmationField.tsx +138 -0
- package/src/base/forms/input/Input.stories.mdx +22 -0
- package/src/base/forms/input/Input.tsx +46 -0
- package/src/base/forms/input/InputField.stories.mdx +22 -0
- package/src/base/forms/input/InputField.tsx +61 -0
- package/src/base/forms/input/Textarea.stories.mdx +28 -0
- package/src/base/forms/input/Textarea.tsx +46 -0
- package/src/base/forms/list/ControlledList.tsx +88 -0
- package/src/base/forms/radio-button/ControlledRadioGroupField.tsx +94 -0
- package/src/base/forms/radio-button/RadioButton.stories.tsx +226 -0
- package/src/base/forms/radio-button/RadioButton.tsx +116 -0
- package/src/base/forms/radio-button/RadioButtonContext.tsx +42 -0
- package/src/base/forms/radio-button/RadioGroup.tsx +49 -0
- package/src/base/forms/radio-button/RadioGroupField.tsx +58 -0
- package/src/base/forms/resourceHooks.ts +164 -0
- package/src/base/forms/select/ControlledSelectField.tsx +87 -0
- package/src/base/forms/select/Select.tsx +57 -0
- package/src/base/forms/select/SelectField.tsx +63 -0
- package/src/base/forms/table/ControlledColumn.tsx +49 -0
- package/src/base/forms/table/ControlledTable.tsx +99 -0
- package/src/base/forms/variants.ts +27 -0
- package/src/base/helpers/devbuild.ts +44 -0
- package/src/base/helpers/index.ts +26 -0
- package/src/base/helpers/useAriaId.tsx +31 -0
- package/src/base/index.ts +34 -0
- package/src/base/layout/_helpers/with-classes.tsx +52 -0
- package/src/base/layout/card/Card.stories.tsx +113 -0
- package/src/base/layout/card/Card.tsx +76 -0
- package/src/base/layout/card/CardDetail.tsx +196 -0
- package/src/base/layout/card/CardRow.tsx +46 -0
- package/src/base/layout/card/CardTitle.tsx +59 -0
- package/src/base/layout/card-list/CardList.stories.tsx +201 -0
- package/src/base/layout/card-list/CardList.tsx +76 -0
- package/src/base/layout/collapsible/Collapsible.stories.tsx +45 -0
- package/src/base/layout/collapsible/Collapsible.tsx +87 -0
- package/src/base/layout/index.ts +93 -0
- package/src/base/layout/tabs/TabTrigger.tsx +46 -0
- package/src/base/layout/tabs/Tabs.stories.tsx +48 -0
- package/src/base/layout/tabs/Tabs.tsx +52 -0
- package/src/base/layout/tabs/TabsContent.tsx +33 -0
- package/src/base/layout/tabs/TabsList.tsx +41 -0
- package/src/base/layout/templates/data-page/DataPage.stories.tsx +201 -0
- package/src/base/layout/templates/data-page/DataPageHeader.tsx +100 -0
- package/src/base/misc/Image.tsx +32 -0
- package/src/base/misc/Level.tsx +40 -0
- package/src/base/misc/Loading.tsx +64 -0
- package/src/base/misc/SubSubtitle.tsx +36 -0
- package/src/base/misc/Subtitle.tsx +37 -0
- package/src/base/misc/Title.tsx +56 -0
- package/src/base/misc/index.ts +30 -0
- package/src/base/notifications/BackendErrorNotification.tsx +160 -0
- package/src/base/notifications/ErrorNotification.tsx +73 -0
- package/src/base/notifications/Notification.tsx +48 -0
- package/src/base/notifications/index.tsx +27 -0
- package/src/base/overlays/dialog/Dialog.stories.tsx +64 -0
- package/src/base/overlays/dialog/Dialog.tsx +85 -0
- package/src/base/overlays/index.ts +44 -0
- package/src/base/overlays/menu/Menu.stories.tsx +78 -0
- package/src/base/overlays/menu/Menu.tsx +213 -0
- package/src/base/overlays/menu/MenuTrigger.tsx +63 -0
- package/src/base/overlays/popover/Popover.stories.tsx +69 -0
- package/src/base/overlays/popover/Popover.tsx +95 -0
- package/src/base/overlays/tooltip/Tooltip.examples.js +41 -0
- package/src/base/overlays/tooltip/Tooltip.stories.mdx +52 -0
- package/src/base/overlays/tooltip/Tooltip.tsx +96 -0
- package/src/base/shortcuts/index.ts +28 -0
- package/src/base/shortcuts/iterator/callbackIterator.ts +220 -0
- package/src/base/shortcuts/iterator/keyboardIterator.test.tsx +431 -0
- package/src/base/shortcuts/iterator/keyboardIterator.tsx +141 -0
- package/src/base/shortcuts/usePauseShortcuts.ts +44 -0
- package/src/base/shortcuts/useShortcut.ts +110 -0
- package/src/base/shortcuts/useShortcutDocs.tsx +54 -0
- package/src/base/text/SplitAndReplace.stories.tsx +83 -0
- package/src/base/text/SplitAndReplace.tsx +65 -0
- package/src/base/text/index.ts +25 -0
- package/src/base/text/textSplitAndReplace.test.ts +134 -0
- package/src/base/text/textSplitAndReplace.ts +86 -0
- package/src/index.ts +25 -0
- package/tsconfig.json +6 -0
|
@@ -0,0 +1,73 @@
|
|
|
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, useContext, useMemo } from "react";
|
|
26
|
+
|
|
27
|
+
const ScmFormPathContext = React.createContext<string>("");
|
|
28
|
+
|
|
29
|
+
export function useScmFormPathContext() {
|
|
30
|
+
return useContext(ScmFormPathContext);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const ScmFormPathContextProvider: FC<{ path: string }> = ({ children, path }) => (
|
|
34
|
+
<ScmFormPathContext.Provider value={path}>{children}</ScmFormPathContext.Provider>
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* This component removes redundancy by declaring a prefix that is shared by all enclosed form-related components.
|
|
39
|
+
* It might be helpful when the data structure of a list's items does not correspond with the individual list item's
|
|
40
|
+
* form structure.
|
|
41
|
+
*
|
|
42
|
+
* @beta
|
|
43
|
+
* @since 2.43.0
|
|
44
|
+
* @example ```
|
|
45
|
+
* // For data of structure
|
|
46
|
+
* {
|
|
47
|
+
* subForm: { foo: boolean, bar: string };
|
|
48
|
+
* flag: boolean;
|
|
49
|
+
* tag: string;
|
|
50
|
+
* }
|
|
51
|
+
* // Because we use ConfigurationForm we get and update the whole object.
|
|
52
|
+
* // We only want to create a form for 'subForm' without having to repeat it for every subField
|
|
53
|
+
* // while keeping the original data structure for the whole form. *
|
|
54
|
+
*
|
|
55
|
+
* // Using this component we can write:
|
|
56
|
+
* <Form.PathContext path="subForm">
|
|
57
|
+
* <Form.Input name="foo" />
|
|
58
|
+
* <Form.Checkbox name="bar" />
|
|
59
|
+
* </Form.PathContext>
|
|
60
|
+
*
|
|
61
|
+
* // Instead of
|
|
62
|
+
*
|
|
63
|
+
* <Form.Input name="subForm.foo" />
|
|
64
|
+
* <Form.Checkbox name="subForm.bar" />
|
|
65
|
+
*
|
|
66
|
+
* // This pattern becomes useful in complex or large forms.
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export const ScmNestedFormPathContextProvider: FC<{ path: string }> = ({ children, path }) => {
|
|
70
|
+
const prefix = useScmFormPathContext();
|
|
71
|
+
const pathWithPrefix = useMemo(() => (prefix ? `${prefix}.${path}` : path), [path, prefix]);
|
|
72
|
+
return <ScmFormPathContext.Provider value={pathWithPrefix}>{children}</ScmFormPathContext.Provider>;
|
|
73
|
+
};
|
|
@@ -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,43 @@
|
|
|
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
|
+
formId: string;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const ScmFormContext = React.createContext<ContextType>(null as unknown as ContextType);
|
|
36
|
+
|
|
37
|
+
export function ScmFormContextProvider<T>({ children, ...props }: PropsWithChildren<ContextType<T>>) {
|
|
38
|
+
return <ScmFormContext.Provider value={props}>{children}</ScmFormContext.Provider>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function useScmFormContext() {
|
|
42
|
+
return useContext(ScmFormContext);
|
|
43
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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, useContext, useMemo } from "react";
|
|
26
|
+
import { FieldValues, useFieldArray, UseFieldArrayReturn } from "react-hook-form";
|
|
27
|
+
import { ScmFormPathContextProvider, useScmFormPathContext } from "./FormPathContext";
|
|
28
|
+
import { useScmFormContext } from "./ScmFormContext";
|
|
29
|
+
|
|
30
|
+
type ContextType<T extends FieldValues = any> = UseFieldArrayReturn<T> & { isNested: boolean };
|
|
31
|
+
|
|
32
|
+
const ScmFormListContext = React.createContext<ContextType>(null as unknown as ContextType);
|
|
33
|
+
|
|
34
|
+
type Props = {
|
|
35
|
+
name: string;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Sets up an array field to be displayed in an enclosed *Form.Table* or *Form.List*.
|
|
40
|
+
* A *Form.AddListEntryForm* can be used to implement a sub-form for adding new entries to the list.
|
|
41
|
+
*
|
|
42
|
+
* @beta
|
|
43
|
+
* @since 2.43.0
|
|
44
|
+
*/
|
|
45
|
+
export const ScmFormListContextProvider: FC<Props> = ({ name, children }) => {
|
|
46
|
+
const { control } = useScmFormContext();
|
|
47
|
+
const prefix = useScmFormPathContext();
|
|
48
|
+
const parentForm = useScmFormListContext();
|
|
49
|
+
const nameWithPrefix = useMemo(() => (prefix ? `${prefix}.${name}` : name), [name, prefix]);
|
|
50
|
+
const fieldArray = useFieldArray({
|
|
51
|
+
control,
|
|
52
|
+
name: nameWithPrefix,
|
|
53
|
+
});
|
|
54
|
+
const value = useMemo(() => ({ ...fieldArray, isNested: !!parentForm }), [fieldArray, parentForm]);
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<ScmFormPathContextProvider path={nameWithPrefix}>
|
|
58
|
+
<ScmFormListContext.Provider value={value}>{children}</ScmFormListContext.Provider>
|
|
59
|
+
</ScmFormPathContextProvider>
|
|
60
|
+
);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export function useScmFormListContext() {
|
|
64
|
+
return useContext(ScmFormListContext);
|
|
65
|
+
}
|
|
@@ -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, { HTMLProps } from "react";
|
|
26
|
+
import classNames from "classnames";
|
|
27
|
+
|
|
28
|
+
const Control = React.forwardRef<HTMLDivElement, HTMLProps<HTMLDivElement>>(({ className, children, ...rest }, ref) => (
|
|
29
|
+
<div className={classNames("control", className)} {...rest} ref={ref}>
|
|
30
|
+
{children}
|
|
31
|
+
</div>
|
|
32
|
+
));
|
|
33
|
+
|
|
34
|
+
export default Control;
|
|
@@ -0,0 +1,35 @@
|
|
|
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> | ({ as: keyof JSX.IntrinsicElements } & HTMLProps<HTMLElement>)> = ({
|
|
29
|
+
as = "div",
|
|
30
|
+
className,
|
|
31
|
+
children,
|
|
32
|
+
...rest
|
|
33
|
+
}) => React.createElement(as, { className: classNames("field", className), ...rest }, children);
|
|
34
|
+
|
|
35
|
+
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,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 from "react";
|
|
26
|
+
import { Tooltip } from "../../../overlays";
|
|
27
|
+
|
|
28
|
+
type Props = { text?: string; className?: string };
|
|
29
|
+
const Help = ({ text, className }: Props) => (
|
|
30
|
+
<Tooltip className={className} message={text}>
|
|
31
|
+
<i className="fas fa-fw fa-question-circle has-text-blue-light" aria-hidden />
|
|
32
|
+
</Tooltip>
|
|
33
|
+
);
|
|
34
|
+
export default Help;
|
|
@@ -0,0 +1,35 @@
|
|
|
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> | ({ as: keyof JSX.IntrinsicElements } & HTMLProps<HTMLElement>)> = ({
|
|
29
|
+
as = "label",
|
|
30
|
+
className,
|
|
31
|
+
children,
|
|
32
|
+
...rest
|
|
33
|
+
}) => React.createElement(as, { className: classNames("label", className), ...rest }, children);
|
|
34
|
+
|
|
35
|
+
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>
|
|
@@ -0,0 +1,118 @@
|
|
|
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 { createAttributesForTesting } from "../../helpers";
|
|
27
|
+
import Help from "../base/help/Help";
|
|
28
|
+
import styled from "styled-components";
|
|
29
|
+
import classNames from "classnames";
|
|
30
|
+
|
|
31
|
+
const StyledInput = styled.input`
|
|
32
|
+
height: 1rem;
|
|
33
|
+
width: 1rem;
|
|
34
|
+
`;
|
|
35
|
+
|
|
36
|
+
const StyledLabel = styled.label`
|
|
37
|
+
margin-left: -0.75rem;
|
|
38
|
+
display: inline-flex;
|
|
39
|
+
`;
|
|
40
|
+
|
|
41
|
+
type InputFieldProps = {
|
|
42
|
+
label: string;
|
|
43
|
+
helpText?: string;
|
|
44
|
+
testId?: string;
|
|
45
|
+
labelClassName?: string;
|
|
46
|
+
} & Omit<InputHTMLAttributes<HTMLInputElement>, "type">;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @see https://bulma.io/documentation/form/checkbox/
|
|
50
|
+
*/
|
|
51
|
+
const Checkbox = React.forwardRef<HTMLInputElement, InputFieldProps>(
|
|
52
|
+
(
|
|
53
|
+
{
|
|
54
|
+
readOnly,
|
|
55
|
+
label,
|
|
56
|
+
className,
|
|
57
|
+
labelClassName,
|
|
58
|
+
value,
|
|
59
|
+
name,
|
|
60
|
+
checked,
|
|
61
|
+
defaultChecked,
|
|
62
|
+
defaultValue,
|
|
63
|
+
testId,
|
|
64
|
+
helpText,
|
|
65
|
+
...props
|
|
66
|
+
},
|
|
67
|
+
ref
|
|
68
|
+
) => (
|
|
69
|
+
<StyledLabel
|
|
70
|
+
className={classNames("checkbox is-align-items-center", labelClassName)}
|
|
71
|
+
// @ts-ignore bulma uses the disabled attribute on labels, although it is not part of the html spec
|
|
72
|
+
disabled={readOnly || props.disabled}
|
|
73
|
+
>
|
|
74
|
+
{readOnly ? (
|
|
75
|
+
<>
|
|
76
|
+
<input
|
|
77
|
+
type="hidden"
|
|
78
|
+
name={name}
|
|
79
|
+
value={value}
|
|
80
|
+
defaultValue={defaultValue}
|
|
81
|
+
checked={checked}
|
|
82
|
+
defaultChecked={defaultChecked}
|
|
83
|
+
readOnly
|
|
84
|
+
/>
|
|
85
|
+
<StyledInput
|
|
86
|
+
type="checkbox"
|
|
87
|
+
className={classNames("m-3", className)}
|
|
88
|
+
ref={ref}
|
|
89
|
+
value={value}
|
|
90
|
+
defaultValue={defaultValue}
|
|
91
|
+
checked={checked}
|
|
92
|
+
defaultChecked={defaultChecked}
|
|
93
|
+
{...props}
|
|
94
|
+
{...createAttributesForTesting(testId)}
|
|
95
|
+
disabled
|
|
96
|
+
/>
|
|
97
|
+
</>
|
|
98
|
+
) : (
|
|
99
|
+
<StyledInput
|
|
100
|
+
type="checkbox"
|
|
101
|
+
className={classNames("m-3", className)}
|
|
102
|
+
ref={ref}
|
|
103
|
+
name={name}
|
|
104
|
+
value={value}
|
|
105
|
+
defaultValue={defaultValue}
|
|
106
|
+
checked={checked}
|
|
107
|
+
defaultChecked={defaultChecked}
|
|
108
|
+
{...props}
|
|
109
|
+
{...createAttributesForTesting(testId)}
|
|
110
|
+
/>
|
|
111
|
+
)}
|
|
112
|
+
|
|
113
|
+
{label}
|
|
114
|
+
{helpText ? <Help className="ml-1" text={helpText} /> : null}
|
|
115
|
+
</StyledLabel>
|
|
116
|
+
)
|
|
117
|
+
);
|
|
118
|
+
export default Checkbox;
|
|
@@ -0,0 +1,39 @@
|
|
|
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 Checkbox from "./Checkbox";
|
|
29
|
+
|
|
30
|
+
type Props = React.ComponentProps<typeof Checkbox>;
|
|
31
|
+
|
|
32
|
+
const CheckboxField = React.forwardRef<HTMLInputElement, Props>(({ className, ...props }, ref) => (
|
|
33
|
+
<Field className={className}>
|
|
34
|
+
<Control>
|
|
35
|
+
<Checkbox ref={ref} {...props} />
|
|
36
|
+
</Control>
|
|
37
|
+
</Field>
|
|
38
|
+
));
|
|
39
|
+
export default CheckboxField;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Meta, Story } from "@storybook/addon-docs";
|
|
2
|
+
import Form from "../Form";
|
|
3
|
+
import ControlledCheckboxField from "./ControlledCheckboxField";
|
|
4
|
+
|
|
5
|
+
<Meta
|
|
6
|
+
title="ControlledCheckboxField"
|
|
7
|
+
decorators={[
|
|
8
|
+
(Story) => (
|
|
9
|
+
<Form onSubmit={console.log} defaultValues={{ checkOne: false, checkTwo: true, checkThree: false }} translationPath={["sample", "form"]}>
|
|
10
|
+
<Story />
|
|
11
|
+
</Form>
|
|
12
|
+
),
|
|
13
|
+
]}
|
|
14
|
+
/>
|
|
15
|
+
|
|
16
|
+
<Story name="Default">
|
|
17
|
+
<ControlledCheckboxField name="checkOne" />
|
|
18
|
+
</Story>
|
|
19
|
+
|
|
20
|
+
<Story name="WithHardcodedText">
|
|
21
|
+
<ControlledCheckboxField name="checkOne" label="Name" helpText="A help text" />
|
|
22
|
+
</Story>
|
|
23
|
+
|
|
24
|
+
<Story name="WithStyling">
|
|
25
|
+
<ControlledCheckboxField name="checkOne" className="has-background-blue-light" />
|
|
26
|
+
</Story>
|
|
27
|
+
|
|
28
|
+
<Story name="WithInitialFocus">
|
|
29
|
+
<ControlledCheckboxField name="checkOne" autoFocus={true} />
|
|
30
|
+
</Story>
|
|
31
|
+
|
|
32
|
+
<Story name="WithReadonly">
|
|
33
|
+
<ControlledCheckboxField name="checkOne" readOnly />
|
|
34
|
+
<ControlledCheckboxField name="checkTwo" disabled />
|
|
35
|
+
<ControlledCheckboxField name="checkThree" />
|
|
36
|
+
</Story>
|