@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,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
+ export * from "./buttons"
26
+ export * from "./forms"
27
+ export * from "./helpers"
28
+ export * from "./misc"
29
+ export * from "./layout"
30
+ export * from "./notifications"
31
+ export * from "./overlays"
32
+ export * from "./shortcuts"
33
+ export * from "./text"
34
+
@@ -0,0 +1,52 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2020-present Cloudogu GmbH and Contributors
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import React, { ComponentProps, ElementRef, ForwardRefExoticComponent, ReactElement } from "react";
26
+ import classNames from "classnames";
27
+ import { Slot } from "@radix-ui/react-slot";
28
+
29
+ const withClasses = <Element extends React.ElementType | ForwardRefExoticComponent<any>>(
30
+ typ: Element,
31
+ additionalClassNames: string[],
32
+ additionalProps?: Partial<ComponentProps<Element>>
33
+ ) =>
34
+ React.forwardRef<
35
+ ElementRef<Element>,
36
+ | (ComponentProps<Element> & { asChild?: false; className?: string })
37
+ | { asChild: true; children: ReactElement<{ className?: string }> }
38
+ >((props, ref) => {
39
+ // @ts-ignore Typescript doesn't get it for some reason
40
+ if (props.asChild) {
41
+ return <Slot {...props} className={classNames(...additionalClassNames)} />;
42
+ } else {
43
+ return React.createElement(typ, {
44
+ ...additionalProps,
45
+ ...props,
46
+ className: classNames((props as any).className, ...additionalClassNames),
47
+ ref,
48
+ });
49
+ }
50
+ });
51
+
52
+ export default withClasses;
@@ -0,0 +1,113 @@
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, ComponentStory } from "@storybook/react";
27
+ import React from "react";
28
+ import { Link } from "react-router-dom";
29
+ import CardTitle from "../card/CardTitle";
30
+ import CardRow, { SecondaryRow, TertiaryRow } from "../card/CardRow";
31
+ import {
32
+ CardButtonDetail,
33
+ CardDetail,
34
+ CardDetailIcon,
35
+ CardDetailLabel,
36
+ CardDetails,
37
+ CardDetailTag,
38
+ CardLinkDetail,
39
+ } from "./CardDetail";
40
+ import Card from "./Card";
41
+ import { Popover } from "../../overlays";
42
+ import { Icon } from "../../buttons";
43
+
44
+ export default {
45
+ title: "Card",
46
+ component: Card,
47
+ decorators: [StoryRouter()],
48
+ } as ComponentMeta<typeof Card>;
49
+
50
+ export const Default: ComponentStory<typeof Card> = () => (
51
+ <Card
52
+ className="box"
53
+ avatar={<Icon className="is-large">user</Icon>}
54
+ action={<Icon className="is-medium">ellipsis-v</Icon>}
55
+ >
56
+ <CardRow>
57
+ <CardTitle>
58
+ <Link aria-label="Edit My least liked repo" to="/cards/1">
59
+ 3c991eec687444630c0929e4e23d8a1a2565011d4bea28d4338dd1d024bb74c8
60
+ c076ca5eea66545ee227c8854acc8b9bf075676a6848d54fa0bc1fa291f78887
61
+ 72d7e2ef64c9575dd8ceeed8ed6b24f185646deb6595b13fd51c5705c61a2c46
62
+ 9127daa67e066bc49f39cca9670b92de3d576ac1fb9c916e9b44692923e12a9d
63
+ 14d07434e8c5b3d0ba2e752bc580888a30963d4e8021be573392bb625f6150da
64
+ 60fc6f2e7503b1ca5963afb627ef560f4e2191c0da4c9328ae4ab088e177fb41
65
+ 749e63a6af1731d5c599e960a2f6c8cb9a15d6cf6a82493f419d417829f7b2a8
66
+ 0ca9334aeda2e5dab101e4af13c9610839afc3b9dd2ec56ffb067d6914ce9b67
67
+ b708983948a1750f79fbb91875399fcce453410dad6191c5dc5059f4b28aee1d
68
+ 0d13a4349270947bc79cfc59c7c2aa59960d847a49b40feccd3388fa9a600a68
69
+ </Link>
70
+ </CardTitle>
71
+ </CardRow>
72
+ <SecondaryRow className="is-ellipsis-overflow">
73
+ 7cab5486ab8cd946af71a77d37c84bac c05156ef54a1f0bfd5d4fa12f774148c 4f2964e1895470b6313e3264fef276d8
74
+ 8c57fdf7fde5fc227ea0c59a0f359122 3bc64067ff6fb9c64f4ae5ac15e4375d 91943ad0c020859ad6cc3723fe9bd325
75
+ 07bb6d93d9faf2df68d02949ec10e58e 0bee2b579b7ab5777683f3d5b5975960 4a3009269d971f555524374e7da745ad
76
+ a693ffb57da89f191249de6480c2387b
77
+ </SecondaryRow>
78
+ <TertiaryRow>This is information is not important</TertiaryRow>
79
+ <CardRow>
80
+ <CardDetails>
81
+ <Popover
82
+ trigger={
83
+ <CardButtonDetail>
84
+ <CardDetailLabel>Popover Detail with Tag</CardDetailLabel>
85
+ <CardDetailTag>3</CardDetailTag>
86
+ </CardButtonDetail>
87
+ }
88
+ title="My Popover Details"
89
+ >
90
+ <>This is some additional detail for my Popover.</>
91
+ </Popover>
92
+ <CardDetail>
93
+ <CardDetailLabel>Normal Detail with Tag</CardDetailLabel>
94
+ <CardDetailTag>2/3</CardDetailTag>
95
+ </CardDetail>
96
+ <CardLinkDetail to="/workers">
97
+ <CardDetailLabel>Link Detail</CardDetailLabel>
98
+ </CardLinkDetail>
99
+ <Popover
100
+ trigger={
101
+ <CardButtonDetail>
102
+ <CardDetailLabel>Popover Detail with Icon</CardDetailLabel>
103
+ <CardDetailIcon className="has-text-success">check-circle</CardDetailIcon>
104
+ </CardButtonDetail>
105
+ }
106
+ title="My Popover Details"
107
+ >
108
+ <>This is some additional detail for my Popover.</>
109
+ </Popover>
110
+ </CardDetails>
111
+ </CardRow>
112
+ </Card>
113
+ );
@@ -0,0 +1,76 @@
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, { ComponentType, HTMLAttributes, ReactHTML, Ref } from "react";
26
+ import classNames from "classnames";
27
+ import CSS from "csstype";
28
+ import styled from "styled-components";
29
+
30
+ const RowsContainer = styled.div`
31
+ margin-left: -0.25rem;
32
+ `;
33
+
34
+ type Props = HTMLAttributes<HTMLElement> & {
35
+ action?: React.ReactElement;
36
+ avatar?: React.ReactElement;
37
+ /**
38
+ * @default "div"
39
+ */
40
+ as?: keyof ReactHTML | ComponentType<HTMLAttributes<HTMLElement> & { ref?: Ref<HTMLElement> }>;
41
+
42
+ /**
43
+ * @default "0.5rem"
44
+ * @since 2.46.0
45
+ */
46
+ rowGap?: CSS.Properties<string | number>["gap"];
47
+ };
48
+
49
+ /**
50
+ * If the Card's title contains a link, the whole Card becomes a click target for that link.
51
+ * Because of this, any interactive elements require the <code>is-relative</code> class to receive cursor events.
52
+ *
53
+ * @beta
54
+ * @since 2.44.0
55
+ */
56
+ const Card = React.forwardRef<HTMLElement, Props>(
57
+ ({ className, avatar, rowGap = "0.25rem", children, as: Comp = "div", action, ...props }, ref) =>
58
+ React.createElement(
59
+ Comp,
60
+ {
61
+ className: classNames(className, "is-relative", "is-flex", "scmm-card"),
62
+ ref,
63
+ ...props,
64
+ },
65
+ avatar ? avatar : null,
66
+ <RowsContainer
67
+ className="is-flex is-flex-direction-column is-justify-content-center is-flex-grow-1 is-overflow-hidden is-overflow-wrap-anywhere"
68
+ style={{ gap: rowGap }}
69
+ >
70
+ {children}
71
+ </RowsContainer>,
72
+ action ? action : null
73
+ )
74
+ );
75
+
76
+ export default Card;
@@ -0,0 +1,196 @@
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, {
26
+ ButtonHTMLAttributes,
27
+ ComponentProps,
28
+ ComponentPropsWithoutRef,
29
+ HTMLAttributes,
30
+ ReactNode,
31
+ } from "react";
32
+ import classNames from "classnames";
33
+ import { useAriaId } from "../../helpers";
34
+ import styled from "styled-components";
35
+ import { Link } from "react-router-dom";
36
+ import { Icon } from "../../buttons";
37
+
38
+ export const CardVariants = {
39
+ LIGHT: "light",
40
+ INFO: "info",
41
+ } as const;
42
+
43
+ type CardVariant = typeof CardVariants[keyof typeof CardVariants];
44
+
45
+ const createCardVariantClasses = (variant?: string | undefined) =>
46
+ classNames({
47
+ "is-light": variant === "light" || !variant,
48
+ "is-info": variant === "info",
49
+ });
50
+
51
+ type CardDetailProps = HTMLAttributes<HTMLSpanElement> & {
52
+ children: ReactNode | ((props: { labelId: string }) => ReactNode);
53
+ };
54
+
55
+ type CardVariantProps = {
56
+ cardVariant?: CardVariant;
57
+ };
58
+
59
+ /**
60
+ * @beta
61
+ * @since 2.46.0
62
+ */
63
+ export const CardDetail = React.forwardRef<HTMLSpanElement, CardDetailProps>(
64
+ ({ children, className, ...props }, ref) => {
65
+ const labelId = useAriaId();
66
+ return (
67
+ <span {...props} className={classNames("is-flex is-align-items-center has-gap-1 p-1", className)} ref={ref}>
68
+ {typeof children === "function" ? children({ labelId }) : children}
69
+ </span>
70
+ );
71
+ }
72
+ );
73
+
74
+ const InteractiveDetailStyles = `
75
+ &:focus {
76
+ outline-offset: -0.125rem;
77
+ outline-width: 0.125rem;
78
+ }
79
+ `;
80
+
81
+ const StyledCardButtonDetail = styled.button`
82
+ ${InteractiveDetailStyles}
83
+
84
+ &[aria-expanded="true"] {
85
+ outline: var(--scm-border-color) solid 0.125rem;
86
+ outline-offset: -0.125rem;
87
+ }
88
+ `;
89
+
90
+ /**
91
+ * @beta
92
+ * @since 2.47.0
93
+ */
94
+ export const CardButtonDetail = React.forwardRef<HTMLButtonElement, ButtonHTMLAttributes<HTMLButtonElement>>(
95
+ ({ children, className, ...props }, ref) => (
96
+ <StyledCardButtonDetail
97
+ {...props}
98
+ className={classNames(
99
+ "is-flex is-align-items-center has-gap-1 p-1 is-borderless has-background-transparent is-relative has-hover-background-blue has-rounded-border is-clickable",
100
+ className
101
+ )}
102
+ ref={ref}
103
+ >
104
+ {children}
105
+ </StyledCardButtonDetail>
106
+ )
107
+ );
108
+
109
+ const StyledCardLinkDetail = styled(Link)`
110
+ ${InteractiveDetailStyles}
111
+
112
+ min-height: 2rem;
113
+ `;
114
+
115
+ /**
116
+ * @beta
117
+ * @since 2.47.0
118
+ */
119
+ export const CardLinkDetail = React.forwardRef<HTMLAnchorElement, ComponentPropsWithoutRef<typeof Link>>(
120
+ ({ children, className, ...props }, ref) => (
121
+ <StyledCardLinkDetail
122
+ {...props}
123
+ className={classNames(
124
+ "is-flex is-align-items-center has-gap-1 p-1 is-borderless has-background-transparent is-relative has-hover-background-blue has-rounded-border is-clickable",
125
+ className
126
+ )}
127
+ ref={ref}
128
+ >
129
+ {children}
130
+ </StyledCardLinkDetail>
131
+ )
132
+ );
133
+
134
+ /**
135
+ * @beta
136
+ * @since 2.46.0
137
+ */
138
+ export const CardDetailLabel = React.forwardRef<HTMLSpanElement, HTMLAttributes<HTMLSpanElement>>(
139
+ ({ children, className, ...props }, ref) => (
140
+ <span {...props} className={classNames("has-text-secondary is-size-7", className)} ref={ref}>
141
+ {children}
142
+ </span>
143
+ )
144
+ );
145
+
146
+ /**
147
+ * @beta
148
+ * @since 2.46.0
149
+ */
150
+ export const CardDetailTag = React.forwardRef<HTMLSpanElement, HTMLAttributes<HTMLSpanElement> & CardVariantProps>(
151
+ ({ children, className, ...props }, ref) => (
152
+ <span
153
+ {...props}
154
+ className={classNames("tag is-rounded", createCardVariantClasses(props.cardVariant), className)}
155
+ ref={ref}
156
+ >
157
+ {children}
158
+ </span>
159
+ )
160
+ );
161
+
162
+ /**
163
+ * @beta
164
+ * @since 2.47.0
165
+ */
166
+ export const CardDetailIcon = React.forwardRef<HTMLElement, ComponentProps<typeof Icon>>(
167
+ ({ children, className, ...props }, ref) => (
168
+ <Icon {...props} className={classNames("is-size-5", className)} ref={ref}>
169
+ {children}
170
+ </Icon>
171
+ )
172
+ );
173
+
174
+ const CardDetailsRowContainer = styled.div`
175
+ gap: 0.125rem 1rem;
176
+
177
+ &:first-child {
178
+ margin-left: -0.25rem;
179
+ }
180
+ `;
181
+
182
+ /**
183
+ * @beta
184
+ * @since 2.46.0
185
+ */
186
+ export const CardDetails = React.forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
187
+ ({ children, className, ...props }, ref) => (
188
+ <CardDetailsRowContainer
189
+ {...props}
190
+ className={classNames("is-flex is-flex-wrap-wrap is-align-items-center", className)}
191
+ ref={ref}
192
+ >
193
+ {children}
194
+ </CardDetailsRowContainer>
195
+ )
196
+ );
@@ -0,0 +1,46 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2020-present Cloudogu GmbH and Contributors
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import React, { ComponentProps, HTMLAttributes } from "react";
26
+ import classNames from "classnames";
27
+
28
+ /**
29
+ * @beta
30
+ * @since 2.44.0
31
+ */
32
+ const CardRow = React.forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(({ className, ...props }, ref) => (
33
+ <div className={classNames(className, "ml-1")} {...props} ref={ref} />
34
+ ));
35
+
36
+ export default CardRow;
37
+
38
+ export const SecondaryRow = React.forwardRef<HTMLDivElement, ComponentProps<typeof CardRow>>(
39
+ ({ className, ...props }, ref) => <CardRow className={classNames(className, "is-size-7")} {...props} ref={ref} />
40
+ );
41
+
42
+ export const TertiaryRow = React.forwardRef<HTMLDivElement, ComponentProps<typeof CardRow>>(
43
+ ({ className, ...props }, ref) => (
44
+ <CardRow className={classNames(className, "is-size-7", "has-text-secondary")} {...props} ref={ref} />
45
+ )
46
+ );
@@ -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 React, { HTMLAttributes } from "react";
26
+
27
+ type Props = HTMLAttributes<HTMLHeadingElement> & {
28
+ /**
29
+ * @default 3
30
+ */
31
+ level?: number;
32
+ };
33
+
34
+ /**
35
+ * A card title may contain a link as its only child which will be automatically stretched to cover the whole card area.
36
+ *
37
+ * If a card title has a link, individual card elements which should be interactive have to get the `is-relative` class.
38
+ *
39
+ * The card title (or enclosed link) content must be an accessible text and must not contain any other interactive elements.
40
+ *
41
+ * You can wrap the title in a {@link CardList.Card.Row} to introduce other elements next to the title.
42
+ *
43
+ * The title (or its enclosing row) must be the first element in a {@link CardList.Card}.
44
+ *
45
+ * @beta
46
+ * @since 2.44.0
47
+ */
48
+ const CardTitle = React.forwardRef<HTMLHeadingElement, Props>(({ children, level = 3, ...props }, ref) =>
49
+ React.createElement(
50
+ `h${level}`,
51
+ {
52
+ ref,
53
+ ...props,
54
+ },
55
+ children
56
+ )
57
+ );
58
+
59
+ export default CardTitle;