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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/.storybook/.babelrc +3 -0
  2. package/.storybook/RemoveThemesPlugin.js +57 -0
  3. package/.storybook/main.js +92 -0
  4. package/.storybook/preview-head.html +25 -0
  5. package/.storybook/preview.js +95 -0
  6. package/.storybook/withApiProvider.js +46 -0
  7. package/docs/introduction.stories.mdx +64 -0
  8. package/docs/usage.stories.mdx +22 -0
  9. package/package.json +81 -0
  10. package/src/base/buttons/Button.stories.tsx +89 -0
  11. package/src/base/buttons/Button.test.stories.mdx +74 -0
  12. package/src/base/buttons/Button.tsx +143 -0
  13. package/src/base/buttons/Icon.tsx +58 -0
  14. package/src/base/buttons/a11y.test.ts +34 -0
  15. package/src/base/buttons/docs/introduction.stories.mdx +64 -0
  16. package/src/base/buttons/docs/usage.stories.mdx +22 -0
  17. package/src/base/buttons/image-snapshot.test.ts +33 -0
  18. package/src/base/buttons/index.ts +26 -0
  19. package/src/base/forms/AddListEntryForm.tsx +127 -0
  20. package/src/base/forms/ConfigurationForm.tsx +59 -0
  21. package/src/base/forms/Form.stories.tsx +453 -0
  22. package/src/base/forms/Form.tsx +215 -0
  23. package/src/base/forms/FormPathContext.tsx +73 -0
  24. package/src/base/forms/FormRow.tsx +37 -0
  25. package/src/base/forms/ScmFormContext.tsx +43 -0
  26. package/src/base/forms/ScmFormListContext.tsx +65 -0
  27. package/src/base/forms/base/Control.tsx +34 -0
  28. package/src/base/forms/base/Field.tsx +35 -0
  29. package/src/base/forms/base/field-message/FieldMessage.tsx +34 -0
  30. package/src/base/forms/base/help/Help.tsx +34 -0
  31. package/src/base/forms/base/label/Label.tsx +35 -0
  32. package/src/base/forms/checkbox/Checkbox.stories.mdx +26 -0
  33. package/src/base/forms/checkbox/Checkbox.tsx +118 -0
  34. package/src/base/forms/checkbox/CheckboxField.tsx +39 -0
  35. package/src/base/forms/checkbox/ControlledCheckboxField.stories.mdx +36 -0
  36. package/src/base/forms/checkbox/ControlledCheckboxField.tsx +82 -0
  37. package/src/base/forms/chip-input/ChipInputField.stories.tsx +75 -0
  38. package/src/base/forms/chip-input/ChipInputField.tsx +169 -0
  39. package/src/base/forms/chip-input/ControlledChipInputField.tsx +111 -0
  40. package/src/base/forms/combobox/Combobox.stories.tsx +125 -0
  41. package/src/base/forms/combobox/Combobox.tsx +223 -0
  42. package/src/base/forms/combobox/ComboboxField.tsx +62 -0
  43. package/src/base/forms/combobox/ControlledComboboxField.tsx +96 -0
  44. package/src/base/forms/headless-chip-input/ChipInput.tsx +237 -0
  45. package/src/base/forms/helpers.ts +74 -0
  46. package/src/base/forms/index.ts +85 -0
  47. package/src/base/forms/input/ControlledInputField.stories.mdx +36 -0
  48. package/src/base/forms/input/ControlledInputField.tsx +87 -0
  49. package/src/base/forms/input/ControlledSecretConfirmationField.stories.mdx +39 -0
  50. package/src/base/forms/input/ControlledSecretConfirmationField.tsx +138 -0
  51. package/src/base/forms/input/Input.stories.mdx +22 -0
  52. package/src/base/forms/input/Input.tsx +46 -0
  53. package/src/base/forms/input/InputField.stories.mdx +22 -0
  54. package/src/base/forms/input/InputField.tsx +61 -0
  55. package/src/base/forms/input/Textarea.stories.mdx +28 -0
  56. package/src/base/forms/input/Textarea.tsx +46 -0
  57. package/src/base/forms/list/ControlledList.tsx +88 -0
  58. package/src/base/forms/radio-button/ControlledRadioGroupField.tsx +94 -0
  59. package/src/base/forms/radio-button/RadioButton.stories.tsx +226 -0
  60. package/src/base/forms/radio-button/RadioButton.tsx +116 -0
  61. package/src/base/forms/radio-button/RadioButtonContext.tsx +42 -0
  62. package/src/base/forms/radio-button/RadioGroup.tsx +49 -0
  63. package/src/base/forms/radio-button/RadioGroupField.tsx +58 -0
  64. package/src/base/forms/resourceHooks.ts +164 -0
  65. package/src/base/forms/select/ControlledSelectField.tsx +87 -0
  66. package/src/base/forms/select/Select.tsx +57 -0
  67. package/src/base/forms/select/SelectField.tsx +63 -0
  68. package/src/base/forms/table/ControlledColumn.tsx +49 -0
  69. package/src/base/forms/table/ControlledTable.tsx +99 -0
  70. package/src/base/forms/variants.ts +27 -0
  71. package/src/base/helpers/devbuild.ts +44 -0
  72. package/src/base/helpers/index.ts +26 -0
  73. package/src/base/helpers/useAriaId.tsx +31 -0
  74. package/src/base/index.ts +34 -0
  75. package/src/base/layout/_helpers/with-classes.tsx +52 -0
  76. package/src/base/layout/card/Card.stories.tsx +113 -0
  77. package/src/base/layout/card/Card.tsx +76 -0
  78. package/src/base/layout/card/CardDetail.tsx +196 -0
  79. package/src/base/layout/card/CardRow.tsx +46 -0
  80. package/src/base/layout/card/CardTitle.tsx +59 -0
  81. package/src/base/layout/card-list/CardList.stories.tsx +201 -0
  82. package/src/base/layout/card-list/CardList.tsx +76 -0
  83. package/src/base/layout/collapsible/Collapsible.stories.tsx +45 -0
  84. package/src/base/layout/collapsible/Collapsible.tsx +87 -0
  85. package/src/base/layout/index.ts +93 -0
  86. package/src/base/layout/tabs/TabTrigger.tsx +46 -0
  87. package/src/base/layout/tabs/Tabs.stories.tsx +48 -0
  88. package/src/base/layout/tabs/Tabs.tsx +52 -0
  89. package/src/base/layout/tabs/TabsContent.tsx +33 -0
  90. package/src/base/layout/tabs/TabsList.tsx +41 -0
  91. package/src/base/layout/templates/data-page/DataPage.stories.tsx +201 -0
  92. package/src/base/layout/templates/data-page/DataPageHeader.tsx +100 -0
  93. package/src/base/misc/Image.tsx +32 -0
  94. package/src/base/misc/Level.tsx +40 -0
  95. package/src/base/misc/Loading.tsx +64 -0
  96. package/src/base/misc/SubSubtitle.tsx +36 -0
  97. package/src/base/misc/Subtitle.tsx +37 -0
  98. package/src/base/misc/Title.tsx +56 -0
  99. package/src/base/misc/index.ts +30 -0
  100. package/src/base/notifications/BackendErrorNotification.tsx +160 -0
  101. package/src/base/notifications/ErrorNotification.tsx +73 -0
  102. package/src/base/notifications/Notification.tsx +48 -0
  103. package/src/base/notifications/index.tsx +27 -0
  104. package/src/base/overlays/dialog/Dialog.stories.tsx +64 -0
  105. package/src/base/overlays/dialog/Dialog.tsx +85 -0
  106. package/src/base/overlays/index.ts +44 -0
  107. package/src/base/overlays/menu/Menu.stories.tsx +78 -0
  108. package/src/base/overlays/menu/Menu.tsx +213 -0
  109. package/src/base/overlays/menu/MenuTrigger.tsx +63 -0
  110. package/src/base/overlays/popover/Popover.stories.tsx +69 -0
  111. package/src/base/overlays/popover/Popover.tsx +95 -0
  112. package/src/base/overlays/tooltip/Tooltip.examples.js +41 -0
  113. package/src/base/overlays/tooltip/Tooltip.stories.mdx +52 -0
  114. package/src/base/overlays/tooltip/Tooltip.tsx +96 -0
  115. package/src/base/shortcuts/index.ts +28 -0
  116. package/src/base/shortcuts/iterator/callbackIterator.ts +220 -0
  117. package/src/base/shortcuts/iterator/keyboardIterator.test.tsx +431 -0
  118. package/src/base/shortcuts/iterator/keyboardIterator.tsx +141 -0
  119. package/src/base/shortcuts/usePauseShortcuts.ts +44 -0
  120. package/src/base/shortcuts/useShortcut.ts +110 -0
  121. package/src/base/shortcuts/useShortcutDocs.tsx +54 -0
  122. package/src/base/text/SplitAndReplace.stories.tsx +83 -0
  123. package/src/base/text/SplitAndReplace.tsx +65 -0
  124. package/src/base/text/index.ts +25 -0
  125. package/src/base/text/textSplitAndReplace.test.ts +134 -0
  126. package/src/base/text/textSplitAndReplace.ts +86 -0
  127. package/src/index.ts +25 -0
  128. package/tsconfig.json +6 -0
@@ -0,0 +1,160 @@
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 React, { ComponentProps, FC } from "react";
25
+ import { BackendError } from "@scm-manager/ui-api";
26
+ import Notification from "./Notification";
27
+ import { useTranslation } from "react-i18next";
28
+
29
+ type Props = Omit<ComponentProps<typeof Notification>, "type" | "role"> & {
30
+ error: BackendError;
31
+ };
32
+
33
+ const BackendErrorNotification: FC<Props> = ({ error, ...props }) => {
34
+ const [t] = useTranslation("plugins");
35
+
36
+ const renderErrorName = () => {
37
+ const translation = t(`errors.${error.errorCode}.displayName`);
38
+ if (translation === error.errorCode) {
39
+ return error.message;
40
+ }
41
+ return translation;
42
+ };
43
+
44
+ const renderErrorDescription = () => {
45
+ const translation = t(`errors.${error.errorCode}.description`);
46
+ if (translation === error.errorCode) {
47
+ return "";
48
+ }
49
+ return translation;
50
+ };
51
+
52
+ const renderAdditionalMessages = () => {
53
+ if (error.additionalMessages) {
54
+ return (
55
+ <>
56
+ <hr />
57
+ {error.additionalMessages
58
+ .map((additionalMessage) =>
59
+ additionalMessage.key ? t(`errors.${additionalMessage.key}.description`) : additionalMessage.message
60
+ )
61
+ .map((message) => (
62
+ <p>{message}</p>
63
+ ))}
64
+ <hr />
65
+ </>
66
+ );
67
+ }
68
+ };
69
+
70
+ const renderViolations = () => {
71
+ if (error.violations) {
72
+ return (
73
+ <>
74
+ <p>
75
+ <strong>{t("errors.violations")}</strong>
76
+ </p>
77
+ <ul>
78
+ {error.violations.map((violation, index) => {
79
+ return (
80
+ <li key={index}>
81
+ {violation.path && <strong>{violation.path}:</strong>} {violation.message}{" "}
82
+ {violation.key && t(violation.key)}
83
+ </li>
84
+ );
85
+ })}
86
+ </ul>
87
+ </>
88
+ );
89
+ }
90
+ };
91
+
92
+ const renderMetadata = () => {
93
+ return (
94
+ <>
95
+ {renderContext()}
96
+ {renderMoreInformationLink()}
97
+ <div className="level is-size-7">
98
+ <div className="left" aria-hidden={true}>
99
+ {t("errors.transactionId")} {error.transactionId}
100
+ </div>
101
+ <div className="right" aria-hidden={true}>
102
+ {t("errors.errorCode")} {error.errorCode}
103
+ </div>
104
+ </div>
105
+ </>
106
+ );
107
+ };
108
+
109
+ const renderContext = () => {
110
+ if (error.context) {
111
+ return (
112
+ <>
113
+ <p>
114
+ <strong>{t("errors.context")}</strong>
115
+ </p>
116
+ <ul>
117
+ {error.context.map((context, index) => {
118
+ return (
119
+ <li key={index}>
120
+ <strong>{context.type}:</strong> {context.id}
121
+ </li>
122
+ );
123
+ })}
124
+ </ul>
125
+ </>
126
+ );
127
+ }
128
+ };
129
+
130
+ const renderMoreInformationLink = () => {
131
+ if (error.url) {
132
+ return (
133
+ <p>
134
+ {t("errors.moreInfo")}{" "}
135
+ <a href={error.url} target="_blank" rel="noreferrer" aria-label={t("error.link")}>
136
+ {error.errorCode}
137
+ </a>
138
+ </p>
139
+ );
140
+ }
141
+ };
142
+
143
+ return (
144
+ <Notification type="danger" role="alert" {...props}>
145
+ <div className="content">
146
+ <p className="subtitle">
147
+ {t("error.subtitle")}
148
+ {": "}
149
+ {renderErrorName()}
150
+ </p>
151
+ <p>{renderErrorDescription()}</p>
152
+ {renderAdditionalMessages()}
153
+ <p>{renderViolations()}</p>
154
+ {renderMetadata()}
155
+ </div>
156
+ </Notification>
157
+ );
158
+ };
159
+
160
+ export default BackendErrorNotification;
@@ -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
+ import React, { ComponentProps, FC } from "react";
25
+ import { useTranslation } from "react-i18next";
26
+ import { BackendError, ForbiddenError, UnauthorizedError, urls } from "@scm-manager/ui-api";
27
+ import Notification from "./Notification";
28
+ import BackendErrorNotification from "./BackendErrorNotification";
29
+ import { useLocation } from "react-router-dom";
30
+
31
+ type Props = ComponentProps<typeof BasicErrorMessage> & {
32
+ error?: Error | null;
33
+ };
34
+
35
+ const LoginLink: FC = () => {
36
+ const [t] = useTranslation("commons");
37
+ const location = useLocation();
38
+ const from = encodeURIComponent(location.hash ? location.pathname + location.hash : location.pathname);
39
+
40
+ return <a href={urls.withContextPath(`/login?from=${from}`)}>{t("errorNotification.loginLink")}</a>;
41
+ };
42
+
43
+ const BasicErrorMessage: FC<Omit<ComponentProps<typeof Notification>, "type" | "role">> = ({ children, ...props }) => {
44
+ const [t] = useTranslation("commons");
45
+
46
+ return (
47
+ <Notification type="danger" role="alert" {...props}>
48
+ <strong>{t("errorNotification.prefix")}:</strong> {children}
49
+ </Notification>
50
+ );
51
+ };
52
+
53
+ const ErrorNotification: FC<Props> = ({ error, ...props }) => {
54
+ const [t] = useTranslation("commons");
55
+ if (error) {
56
+ if (error instanceof BackendError) {
57
+ return <BackendErrorNotification error={error} {...props} />;
58
+ } else if (error instanceof UnauthorizedError) {
59
+ return (
60
+ <BasicErrorMessage {...props}>
61
+ {t("errorNotification.timeout")} <LoginLink />
62
+ </BasicErrorMessage>
63
+ );
64
+ } else if (error instanceof ForbiddenError) {
65
+ return <BasicErrorMessage {...props}>{t("errorNotification.forbidden")}</BasicErrorMessage>;
66
+ } else {
67
+ return <BasicErrorMessage {...props}>{error.message}</BasicErrorMessage>;
68
+ }
69
+ }
70
+ return null;
71
+ };
72
+
73
+ export default ErrorNotification;
@@ -0,0 +1,48 @@
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 React, { HTMLAttributes } from "react";
25
+ import classNames from "classnames";
26
+
27
+ type NotificationType = "primary" | "info" | "success" | "warning" | "danger" | "inherit";
28
+
29
+ type Props = {
30
+ type?: NotificationType;
31
+ onClose?: () => void;
32
+ role?: string;
33
+ };
34
+
35
+ const Notification = React.forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement> & Props>(
36
+ ({ type = "info", onClose, className, children, role, ...props }, ref) => {
37
+ const color = type !== "inherit" ? "is-" + type : "";
38
+
39
+ return (
40
+ <div className={classNames("notification", color, className)} role={role} ref={ref}>
41
+ {onClose ? <button className="delete" onClick={onClose} /> : null}
42
+ {children}
43
+ </div>
44
+ );
45
+ }
46
+ );
47
+
48
+ export default Notification;
@@ -0,0 +1,27 @@
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 { default as Notification } from "./Notification";
26
+ export { default as ErrorNotification } from "./ErrorNotification";
27
+ export { default as BackendErrorNotification } from "./BackendErrorNotification";
@@ -0,0 +1,64 @@
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 StoryRouter from "storybook-react-router";
26
+ import { ComponentMeta, StoryFn } from "@storybook/react";
27
+ import React, { ComponentProps } from "react";
28
+ import { Button } from "../../buttons";
29
+ import Dialog from "./Dialog";
30
+
31
+ export default {
32
+ title: "Dialog",
33
+ component: Dialog,
34
+ decorators: [StoryRouter()],
35
+ render: (story) => <div style={{ height: "100vh" }}>{story}</div>,
36
+ } as ComponentMeta<typeof Dialog>;
37
+
38
+ const Template: StoryFn<ComponentProps<typeof Dialog>> = (args) => <Dialog {...args} />;
39
+
40
+ export const Default = Template.bind({});
41
+ // More on args: https://storybook.js.org/docs/react/writing-stories/args
42
+ Default.args = {
43
+ title: "My Dialog",
44
+ trigger: <Button>Open Dialog</Button>,
45
+ description: "Do you really want to do this ?",
46
+ children: (
47
+ <table>
48
+ <tr>
49
+ <th>Yes</th>
50
+ <th>No</th>
51
+ </tr>
52
+ <tr>
53
+ <td>42</td>
54
+ <td>12</td>
55
+ </tr>
56
+ </table>
57
+ ),
58
+ footer: [
59
+ <Button>Do it</Button>,
60
+ <Button variant="primary" autoFocus>
61
+ Cancel
62
+ </Button>,
63
+ ],
64
+ } as ComponentProps<typeof Dialog>;
@@ -0,0 +1,85 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2020-present Cloudogu GmbH and Contributors
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import * as RadixDialog from "@radix-ui/react-dialog";
26
+ import { DialogProps } from "@radix-ui/react-dialog";
27
+ import React, { ComponentProps, ReactComponentElement, ReactElement, ReactNode, useCallback } from "react";
28
+ import { Button } from "../../buttons";
29
+ import { useTranslation } from "react-i18next";
30
+
31
+ export const CloseButton = React.forwardRef<HTMLButtonElement, ComponentProps<typeof Button>>(
32
+ ({ children, ...props }, ref) => (
33
+ <RadixDialog.Close asChild>
34
+ <Button {...props} ref={ref}>
35
+ {children}
36
+ </Button>
37
+ </RadixDialog.Close>
38
+ )
39
+ );
40
+
41
+ type Props = {
42
+ trigger: ReactComponentElement<typeof Button>;
43
+ title: ReactNode;
44
+ description?: ReactNode;
45
+ footer?: ReactElement[] | ((close: () => void) => ReactElement[]);
46
+ } & Pick<DialogProps, "onOpenChange" | "open" | "children">;
47
+
48
+ /**
49
+ * @beta
50
+ * @since 2.46.0
51
+ */
52
+ const Dialog = React.forwardRef<HTMLDivElement, Props>(
53
+ ({ children, onOpenChange, open, footer, title, trigger, description }, ref) => {
54
+ const contentProps = description ? {} : { "aria-describedby": undefined };
55
+ const close = useCallback(() => onOpenChange && onOpenChange(false), [onOpenChange]);
56
+ const [t] = useTranslation("commons");
57
+ return (
58
+ <RadixDialog.Root open={open} onOpenChange={onOpenChange}>
59
+ <RadixDialog.Trigger asChild>{trigger}</RadixDialog.Trigger>
60
+ <RadixDialog.Portal>
61
+ <RadixDialog.Overlay className="modal-background" />
62
+ <RadixDialog.Content className="modal is-active" ref={ref} {...contentProps}>
63
+ <div className="modal-card">
64
+ <div className="modal-card-head">
65
+ <RadixDialog.Title className="modal-card-title">{title}</RadixDialog.Title>
66
+ <RadixDialog.Close asChild>
67
+ <button className="delete" aria-label={t("dialog.closeButton.ariaLabel")} />
68
+ </RadixDialog.Close>
69
+ </div>
70
+ <div className="modal-card-body">
71
+ {description ? <RadixDialog.Description>{description}</RadixDialog.Description> : null}
72
+ {children}
73
+ </div>
74
+ {footer ? (
75
+ <div className="modal-card-foot">{typeof footer === "function" ? footer(close) : footer}</div>
76
+ ) : null}
77
+ </div>
78
+ </RadixDialog.Content>
79
+ </RadixDialog.Portal>
80
+ </RadixDialog.Root>
81
+ );
82
+ }
83
+ );
84
+
85
+ export default Dialog;
@@ -0,0 +1,44 @@
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 MenuComponent, { MenuButton, MenuDialog, MenuExternalLink, MenuLink } from "./menu/Menu";
26
+ import MenuTrigger, { DefaultMenuTrigger } from "./menu/MenuTrigger";
27
+ import DialogComponent, { CloseButton } from "./dialog/Dialog";
28
+
29
+ export { default as Tooltip } from "./tooltip/Tooltip";
30
+
31
+ export const Menu = Object.assign(MenuComponent, {
32
+ Button: MenuButton,
33
+ Link: MenuLink,
34
+ ExternalLink: MenuExternalLink,
35
+ DialogButton: MenuDialog,
36
+ Trigger: MenuTrigger,
37
+ DefaultTrigger: DefaultMenuTrigger,
38
+ });
39
+
40
+ export const Dialog = Object.assign(DialogComponent, {
41
+ CloseButton,
42
+ });
43
+
44
+ export { default as Popover } from "./popover/Popover";
@@ -0,0 +1,78 @@
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 StoryRouter from "storybook-react-router";
26
+ import { ComponentMeta, StoryFn } from "@storybook/react";
27
+ import React, { ComponentProps } from "react";
28
+ import Menu, { MenuButton, MenuDialog, MenuExternalLink, MenuLink } from "./Menu";
29
+ import { Button, Icon } from "../../buttons";
30
+ import { CloseButton } from "../dialog/Dialog";
31
+
32
+ export default {
33
+ title: "Menu",
34
+ component: Menu,
35
+ decorators: [StoryRouter()],
36
+ } as ComponentMeta<typeof Menu>;
37
+
38
+ const Template: StoryFn<ComponentProps<typeof Menu>> = (args) => <Menu {...args} />;
39
+
40
+ export const Default = Template.bind({});
41
+ // More on args: https://storybook.js.org/docs/react/writing-stories/args
42
+ Default.args = {
43
+ children: [
44
+ // eslint-disable-next-line no-console
45
+ <MenuButton onSelect={() => console.log("A button has been clicked")}>
46
+ <Icon />A button
47
+ </MenuButton>,
48
+ <MenuLink to="/repos">
49
+ <Icon />A link
50
+ </MenuLink>,
51
+ <MenuExternalLink href="https://scm-manager.org">
52
+ <Icon>link</Icon>An external link
53
+ </MenuExternalLink>,
54
+ <MenuButton disabled>
55
+ <Icon>trash</Icon>A disabled button
56
+ </MenuButton>,
57
+ <MenuDialog
58
+ title="My Dialog"
59
+ description="Do you really want to do this ?"
60
+ footer={[<Button autoFocus>Do it</Button>, <CloseButton variant="primary">Cancel</CloseButton>]}
61
+ dialogContent={
62
+ <table>
63
+ <tr>
64
+ <th>Yes</th>
65
+ <th>No</th>
66
+ </tr>
67
+ <tr>
68
+ <td>42</td>
69
+ <td>12</td>
70
+ </tr>
71
+ </table>
72
+ }
73
+ >
74
+ <Icon />
75
+ Open Dialog
76
+ </MenuDialog>,
77
+ ],
78
+ } as ComponentProps<typeof Menu>;