@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,143 @@
|
|
|
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, { AnchorHTMLAttributes, ButtonHTMLAttributes } from "react";
|
|
26
|
+
import { Link as ReactRouterLink, LinkProps as ReactRouterLinkProps } from "react-router-dom";
|
|
27
|
+
import classNames from "classnames";
|
|
28
|
+
import { createAttributesForTesting } from "../helpers";
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @beta
|
|
32
|
+
* @since 2.41.0
|
|
33
|
+
*/
|
|
34
|
+
export const ButtonVariants = {
|
|
35
|
+
PRIMARY: "primary",
|
|
36
|
+
SECONDARY: "secondary",
|
|
37
|
+
TERTIARY: "tertiary",
|
|
38
|
+
SIGNAL: "signal",
|
|
39
|
+
} as const;
|
|
40
|
+
|
|
41
|
+
export const ButtonVariantList = Object.values(ButtonVariants);
|
|
42
|
+
|
|
43
|
+
type ButtonVariant = typeof ButtonVariants[keyof typeof ButtonVariants];
|
|
44
|
+
|
|
45
|
+
const createButtonClasses = (variant?: ButtonVariant, isLoading?: boolean) =>
|
|
46
|
+
classNames("button", {
|
|
47
|
+
"is-primary": variant === "primary",
|
|
48
|
+
"is-primary is-outlined": variant === "secondary",
|
|
49
|
+
"is-primary is-inverted": variant === "tertiary",
|
|
50
|
+
"is-warning": variant === "signal",
|
|
51
|
+
"is-loading": isLoading,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
type BaseButtonProps = {
|
|
55
|
+
variant?: ButtonVariant;
|
|
56
|
+
isLoading?: boolean;
|
|
57
|
+
testId?: string;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
type ButtonProps = BaseButtonProps & ButtonHTMLAttributes<HTMLButtonElement>;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Styled html button.
|
|
64
|
+
*
|
|
65
|
+
* A button has to declare an `aria-label` if it exclusively contains an {@link Icon} as its children.
|
|
66
|
+
*
|
|
67
|
+
* @beta
|
|
68
|
+
* @since 2.41.0
|
|
69
|
+
*/
|
|
70
|
+
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
71
|
+
({ className, variant, isLoading, testId, type, children, ...props }, ref) => (
|
|
72
|
+
<button
|
|
73
|
+
type={type ?? "button"}
|
|
74
|
+
{...props}
|
|
75
|
+
className={classNames(createButtonClasses(variant, isLoading), className)}
|
|
76
|
+
ref={ref}
|
|
77
|
+
{...createAttributesForTesting(testId)}
|
|
78
|
+
>
|
|
79
|
+
{children}
|
|
80
|
+
</button>
|
|
81
|
+
)
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
type LinkButtonProps = BaseButtonProps & ReactRouterLinkProps;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Styled react router link.
|
|
88
|
+
*
|
|
89
|
+
* A button has to declare an `aria-label` if it exclusively contains an {@link Icon} as its children.
|
|
90
|
+
*
|
|
91
|
+
* @beta
|
|
92
|
+
* @since 2.41.0
|
|
93
|
+
*/
|
|
94
|
+
export const LinkButton = React.forwardRef<HTMLAnchorElement, LinkButtonProps>(
|
|
95
|
+
({ className, variant, isLoading, testId, children, ...props }, ref) => (
|
|
96
|
+
<ReactRouterLink
|
|
97
|
+
{...props}
|
|
98
|
+
className={classNames(createButtonClasses(variant, isLoading), className)}
|
|
99
|
+
ref={ref}
|
|
100
|
+
{...createAttributesForTesting(testId)}
|
|
101
|
+
>
|
|
102
|
+
{children}
|
|
103
|
+
</ReactRouterLink>
|
|
104
|
+
)
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* External links open in a new browser tab with rel flags "noopener" and "noreferrer" set by default.
|
|
109
|
+
*
|
|
110
|
+
* @beta
|
|
111
|
+
* @since 2.44.0
|
|
112
|
+
*/
|
|
113
|
+
export const ExternalLink = React.forwardRef<HTMLAnchorElement, AnchorHTMLAttributes<HTMLAnchorElement>>(
|
|
114
|
+
({ children, ...props }, ref) => (
|
|
115
|
+
<a target="_blank" rel="noreferrer noopener" {...props} ref={ref}>
|
|
116
|
+
{children}
|
|
117
|
+
</a>
|
|
118
|
+
)
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
type ExternalLinkButtonProps = BaseButtonProps & AnchorHTMLAttributes<HTMLAnchorElement>;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Styled {@link ExternalLink}.
|
|
125
|
+
*
|
|
126
|
+
* A button has to declare an `aria-label` if it exclusively contains an {@link Icon} as its children.
|
|
127
|
+
*
|
|
128
|
+
* @beta
|
|
129
|
+
* @since 2.41.0
|
|
130
|
+
* @see ExternalLink
|
|
131
|
+
*/
|
|
132
|
+
export const ExternalLinkButton = React.forwardRef<HTMLAnchorElement, ExternalLinkButtonProps>(
|
|
133
|
+
({ className, variant, isLoading, testId, children, ...props }, ref) => (
|
|
134
|
+
<ExternalLink
|
|
135
|
+
{...props}
|
|
136
|
+
className={classNames(createButtonClasses(variant, isLoading), className)}
|
|
137
|
+
ref={ref}
|
|
138
|
+
{...createAttributesForTesting(testId)}
|
|
139
|
+
>
|
|
140
|
+
{children}
|
|
141
|
+
</ExternalLink>
|
|
142
|
+
)
|
|
143
|
+
);
|
|
@@ -0,0 +1,58 @@
|
|
|
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 = React.HTMLProps<HTMLElement> & {
|
|
29
|
+
children?: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Icons are hidden to assistive technologies by default.
|
|
34
|
+
*
|
|
35
|
+
* If your icon does convey a state, unset `aria-hidden` and set an appropriate `aria-label`.
|
|
36
|
+
*
|
|
37
|
+
* The children have to be a single text node containing a valid fontawesome icon name.
|
|
38
|
+
*
|
|
39
|
+
* @beta
|
|
40
|
+
* @since 2.44.0
|
|
41
|
+
* @see https://bulma.io/documentation/elements/icon/
|
|
42
|
+
* @see https://fontawesome.com/search?o=r&m=free
|
|
43
|
+
*/
|
|
44
|
+
const Icon = React.forwardRef<HTMLElement, Props>(({ children, className, ...props }, ref) => {
|
|
45
|
+
return (
|
|
46
|
+
<span className={classNames(className, "icon")} aria-hidden="true" {...props} ref={ref}>
|
|
47
|
+
<i
|
|
48
|
+
className={classNames(`fas fa-fw fa-${children}`, {
|
|
49
|
+
"fa-xs": className?.includes("is-small"),
|
|
50
|
+
"fa-lg": className?.includes("is-medium"),
|
|
51
|
+
"fa-2x": className?.includes("is-large"),
|
|
52
|
+
})}
|
|
53
|
+
/>
|
|
54
|
+
</span>
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export default Icon;
|
|
@@ -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
|
+
import initStoryshots from "@storybook/addon-storyshots";
|
|
25
|
+
import { axeTest } from "@storybook/addon-storyshots-puppeteer";
|
|
26
|
+
import path from "path";
|
|
27
|
+
|
|
28
|
+
initStoryshots({
|
|
29
|
+
suite: "A11y checks",
|
|
30
|
+
test: axeTest({
|
|
31
|
+
storybookUrl: `file://${path.resolve(__dirname, "../storybook-static")}`,
|
|
32
|
+
}),
|
|
33
|
+
storyNameRegex: /High-Contrast States/,
|
|
34
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Meta } from "@storybook/addon-docs";
|
|
2
|
+
import { Button } from "../";
|
|
3
|
+
|
|
4
|
+
<Meta title="Introduction"/>
|
|
5
|
+
|
|
6
|
+
# Buttons
|
|
7
|
+
|
|
8
|
+
The `@scm-manager/ui-core` library provides [atoms](https://atomicdesign.bradfrost.com/chapter-2/#atoms) implemented
|
|
9
|
+
as minimal wrappers around native html elements styled to match the general SCM-Manager aesthetic.
|
|
10
|
+
|
|
11
|
+
## Components
|
|
12
|
+
|
|
13
|
+
There are three actionable components available. Styling is consistent amongst them and all have the required `variant` property.
|
|
14
|
+
|
|
15
|
+
1. [Button](?path=/story/components--button)
|
|
16
|
+
2. [Link Button](?path=/story/components--link-button)
|
|
17
|
+
3. [External Link Button](?path=/story/components--external-link-button)
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
Actionable components serve a dedicated purpose. It is therefore important to know when and how to use them.
|
|
22
|
+
|
|
23
|
+
### Variants
|
|
24
|
+
|
|
25
|
+
There are four variants available to each of the three button types, varying in importance.
|
|
26
|
+
|
|
27
|
+
<table>
|
|
28
|
+
<thead>
|
|
29
|
+
<tr>
|
|
30
|
+
<th>Emphasis</th>
|
|
31
|
+
<th>Button Variant</th>
|
|
32
|
+
<th>Usage Examples</th>
|
|
33
|
+
</tr>
|
|
34
|
+
</thead>
|
|
35
|
+
<tbody>
|
|
36
|
+
<tr>
|
|
37
|
+
<td>Very High</td>
|
|
38
|
+
<td><Button variant="signal">Signal</Button></td>
|
|
39
|
+
<td>Destructive actions</td>
|
|
40
|
+
</tr>
|
|
41
|
+
<tr>
|
|
42
|
+
<td>High</td>
|
|
43
|
+
<td><Button variant="primary">Primary</Button></td>
|
|
44
|
+
<td>Form submit</td>
|
|
45
|
+
</tr>
|
|
46
|
+
<tr>
|
|
47
|
+
<td>Normal</td>
|
|
48
|
+
<td><Button variant="secondary">Secondary</Button></td>
|
|
49
|
+
<td>Cancel action in dialog</td>
|
|
50
|
+
</tr>
|
|
51
|
+
<tr>
|
|
52
|
+
<td>Low</td>
|
|
53
|
+
<td><Button variant="tertiary">Tertiary</Button></td>
|
|
54
|
+
<td>Circumstantially relevant action on page with many actionable elements</td>
|
|
55
|
+
</tr>
|
|
56
|
+
</tbody>
|
|
57
|
+
</table>
|
|
58
|
+
|
|
59
|
+
## Content
|
|
60
|
+
|
|
61
|
+
Buttons exclusively contain text and no icons. Icons tend to be ambiguous and not always applicable which leads to inconsistent
|
|
62
|
+
and cluttered layouts.
|
|
63
|
+
|
|
64
|
+
Button text should be short, concise and describe the action performed.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Meta, Story } from "@storybook/addon-docs";
|
|
2
|
+
import { Button } from "../";
|
|
3
|
+
|
|
4
|
+
<Meta title="Usage" parameters={{
|
|
5
|
+
storyshots: { disable: true }
|
|
6
|
+
}} />
|
|
7
|
+
|
|
8
|
+
In confirmation dialogs, there are two actions.<br/>
|
|
9
|
+
One to cancel the current process and one to confirm it.<br/>
|
|
10
|
+
Aborting is always the secondary action, confirmation always the primary.
|
|
11
|
+
Focus is always on the cancelling action.
|
|
12
|
+
|
|
13
|
+
<Story name="Confirmation Dialog">
|
|
14
|
+
<div>
|
|
15
|
+
<h4>Delete User</h4>
|
|
16
|
+
<p>Do you really want to delete this user ?</p>
|
|
17
|
+
<div>
|
|
18
|
+
<Button variant="secondary">Cancel</Button>
|
|
19
|
+
<Button variant="primary">Delete</Button>
|
|
20
|
+
</div>
|
|
21
|
+
</div>
|
|
22
|
+
</Story>
|
|
@@ -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
|
+
import path from "path";
|
|
25
|
+
import initStoryshots from "@storybook/addon-storyshots";
|
|
26
|
+
import { imageSnapshot } from "@storybook/addon-storyshots-puppeteer";
|
|
27
|
+
|
|
28
|
+
initStoryshots({
|
|
29
|
+
suite: "Image snapshots",
|
|
30
|
+
test: imageSnapshot({
|
|
31
|
+
storybookUrl: `file://${path.resolve(__dirname, "../storybook-static")}`,
|
|
32
|
+
})
|
|
33
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
export { Button, LinkButton, ExternalLinkButton, ExternalLink, ButtonVariants } from "./Button";
|
|
26
|
+
export { default as Icon } from "./Icon";
|
|
@@ -0,0 +1,127 @@
|
|
|
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, { useCallback, useEffect } from "react";
|
|
26
|
+
import { ScmFormPathContextProvider, useScmFormPathContext } from "./FormPathContext";
|
|
27
|
+
import { ScmFormContextProvider, useScmFormContext } from "./ScmFormContext";
|
|
28
|
+
import { DeepPartial, UseFieldArrayReturn, useForm, UseFormReturn } from "react-hook-form";
|
|
29
|
+
import { Button } from "../buttons";
|
|
30
|
+
import { prefixWithoutIndices } from "./helpers";
|
|
31
|
+
import { useScmFormListContext } from "./ScmFormListContext";
|
|
32
|
+
import { useTranslation } from "react-i18next";
|
|
33
|
+
import styled from "styled-components";
|
|
34
|
+
|
|
35
|
+
const StyledHr = styled.hr`
|
|
36
|
+
&:last-child {
|
|
37
|
+
display: none;
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
|
|
41
|
+
type RenderProps<T extends Record<string, unknown>> = Omit<
|
|
42
|
+
UseFormReturn<T>,
|
|
43
|
+
"register" | "unregister" | "handleSubmit" | "control"
|
|
44
|
+
>;
|
|
45
|
+
|
|
46
|
+
type Props<FormType extends Record<string, unknown>, DefaultValues extends FormType> = {
|
|
47
|
+
children: ((renderProps: RenderProps<FormType>) => React.ReactNode | React.ReactNode[]) | React.ReactNode;
|
|
48
|
+
defaultValues: DefaultValues;
|
|
49
|
+
submit?: (data: FormType, append: UseFieldArrayReturn["append"]) => unknown;
|
|
50
|
+
/**
|
|
51
|
+
* @default true
|
|
52
|
+
*/
|
|
53
|
+
disableSubmitWhenDirty?: boolean;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @beta
|
|
58
|
+
* @since 2.43.0
|
|
59
|
+
*/
|
|
60
|
+
function AddListEntryForm<FormType extends Record<string, unknown>, DefaultValues extends FormType>({
|
|
61
|
+
children,
|
|
62
|
+
defaultValues,
|
|
63
|
+
submit,
|
|
64
|
+
disableSubmitWhenDirty = true,
|
|
65
|
+
}: Props<FormType, DefaultValues>) {
|
|
66
|
+
const [defaultTranslate] = useTranslation("commons", { keyPrefix: "form" });
|
|
67
|
+
const { readOnly, t } = useScmFormContext();
|
|
68
|
+
const nameWithPrefix = useScmFormPathContext();
|
|
69
|
+
const prefixedNameWithoutIndices = prefixWithoutIndices(nameWithPrefix);
|
|
70
|
+
const { append, isNested } = useScmFormListContext();
|
|
71
|
+
const form = useForm<FormType, DefaultValues>({
|
|
72
|
+
mode: "onChange",
|
|
73
|
+
defaultValues: defaultValues as DeepPartial<FormType>,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const {
|
|
77
|
+
reset,
|
|
78
|
+
formState: { isSubmitSuccessful, isDirty, isValid },
|
|
79
|
+
} = form;
|
|
80
|
+
|
|
81
|
+
const translateWithExtraPrefix = useCallback<typeof t>(
|
|
82
|
+
(key, ...args) => t(`${prefixedNameWithoutIndices}.${key}`, ...(args as any)),
|
|
83
|
+
[prefixedNameWithoutIndices, t]
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const onSubmit = useCallback((data) => (submit ? submit(data, append) : append(data)), [append, submit]);
|
|
87
|
+
|
|
88
|
+
const submitButtonLabel = translateWithExtraPrefix("add", {
|
|
89
|
+
defaultValue: defaultTranslate("list.add.label", { entity: translateWithExtraPrefix("entity") }),
|
|
90
|
+
});
|
|
91
|
+
const titleLabel = translateWithExtraPrefix("title", {
|
|
92
|
+
defaultValue: defaultTranslate("list.title.label", { entity: translateWithExtraPrefix("entity") }),
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
if (isSubmitSuccessful) {
|
|
97
|
+
reset(defaultValues);
|
|
98
|
+
}
|
|
99
|
+
}, [defaultValues, isSubmitSuccessful, reset]);
|
|
100
|
+
|
|
101
|
+
if (readOnly) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<ScmFormContextProvider {...form} t={translateWithExtraPrefix} formId={nameWithPrefix}>
|
|
107
|
+
<ScmFormPathContextProvider path="">
|
|
108
|
+
<h3 className="subtitle is-5">{titleLabel}</h3>
|
|
109
|
+
<form id={nameWithPrefix} onSubmit={form.handleSubmit(onSubmit)} noValidate></form>
|
|
110
|
+
{typeof children === "function" ? children(form) : children}
|
|
111
|
+
<div className="level-left">
|
|
112
|
+
<Button
|
|
113
|
+
form={nameWithPrefix}
|
|
114
|
+
type="submit"
|
|
115
|
+
variant={isNested ? undefined : "secondary"}
|
|
116
|
+
disabled={(disableSubmitWhenDirty && !isDirty) || !isValid}
|
|
117
|
+
>
|
|
118
|
+
{submitButtonLabel}
|
|
119
|
+
</Button>
|
|
120
|
+
</div>
|
|
121
|
+
<StyledHr />
|
|
122
|
+
</ScmFormPathContextProvider>
|
|
123
|
+
</ScmFormContextProvider>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export default AddListEntryForm;
|
|
@@ -0,0 +1,59 @@
|
|
|
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 { useConfigLink } from "@scm-manager/ui-api";
|
|
26
|
+
import { Loading } from "../misc";
|
|
27
|
+
import React, { ComponentProps } from "react";
|
|
28
|
+
import { HalRepresentation } from "@scm-manager/ui-types";
|
|
29
|
+
import Form from "./Form";
|
|
30
|
+
import { useTranslation } from "react-i18next";
|
|
31
|
+
|
|
32
|
+
type Props<T extends HalRepresentation> =
|
|
33
|
+
// eslint-disable-next-line prettier/prettier
|
|
34
|
+
Omit<ComponentProps<typeof Form<T>>, "onSubmit" | "defaultValues" | "readOnly" | "successMessageFallback">
|
|
35
|
+
& {
|
|
36
|
+
link: string;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @beta
|
|
41
|
+
* @since 2.41.0
|
|
42
|
+
*/
|
|
43
|
+
export function ConfigurationForm<T extends HalRepresentation>({ link, children, ...formProps }: Props<T>) {
|
|
44
|
+
const { initialConfiguration, isReadOnly, update, isLoading } = useConfigLink<T>(link);
|
|
45
|
+
const [t] = useTranslation("commons", { keyPrefix: "form" });
|
|
46
|
+
|
|
47
|
+
if (isLoading || !initialConfiguration) {
|
|
48
|
+
return <Loading />;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<Form onSubmit={update} defaultValues={initialConfiguration} readOnly={isReadOnly}
|
|
53
|
+
successMessageFallback={t("submit-success-notification")} {...formProps}>
|
|
54
|
+
{children}
|
|
55
|
+
</Form>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export default ConfigurationForm;
|