@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,164 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { apiClient, requiredLink } from "@scm-manager/ui-api";
|
|
26
|
+
import { useMutation, useQueryClient } from "react-query";
|
|
27
|
+
import { HalRepresentation, Link } from "@scm-manager/ui-types";
|
|
28
|
+
|
|
29
|
+
type QueryKeyPair = [singular: string, plural: string];
|
|
30
|
+
type LinkOrHalLink = string | [entity: HalRepresentation, link: string] | HalRepresentation;
|
|
31
|
+
const unwrapLink = (input: LinkOrHalLink, linkName: string) => {
|
|
32
|
+
if (Array.isArray(input)) {
|
|
33
|
+
return requiredLink(input[0], input[1]);
|
|
34
|
+
} else if (typeof input === "string") {
|
|
35
|
+
return input;
|
|
36
|
+
} else {
|
|
37
|
+
return (input._links[linkName] as Link).href;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
type MutationResult<I, O = unknown> = {
|
|
42
|
+
submit: (resource: I) => Promise<O>;
|
|
43
|
+
isLoading: boolean;
|
|
44
|
+
error: Error | null;
|
|
45
|
+
submissionResult?: O;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
type MutatingResourceOptions = {
|
|
49
|
+
contentType?: string;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const createResource = <I, O = never>(link: string, contentType: string) => {
|
|
53
|
+
return (payload: I): Promise<O> => {
|
|
54
|
+
return apiClient
|
|
55
|
+
.post(link, payload, contentType)
|
|
56
|
+
.then((response) => {
|
|
57
|
+
const location = response.headers.get("Location");
|
|
58
|
+
if (!location) {
|
|
59
|
+
throw new Error("Server does not return required Location header");
|
|
60
|
+
}
|
|
61
|
+
return apiClient.get(location);
|
|
62
|
+
})
|
|
63
|
+
.then((response) => response.json());
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
type CreateResourceOptions = MutatingResourceOptions;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @beta
|
|
71
|
+
* @since 2.41.0
|
|
72
|
+
*/
|
|
73
|
+
export const useCreateResource = <I, O>(
|
|
74
|
+
link: string,
|
|
75
|
+
[entityKey, collectionName]: QueryKeyPair,
|
|
76
|
+
idFactory: (createdResource: O) => string,
|
|
77
|
+
{ contentType = "application/json" }: CreateResourceOptions = {}
|
|
78
|
+
): MutationResult<I, O> => {
|
|
79
|
+
const queryClient = useQueryClient();
|
|
80
|
+
const { mutateAsync, data, isLoading, error } = useMutation<O, Error, I>(createResource<I, O>(link, contentType), {
|
|
81
|
+
onSuccess: (result) => {
|
|
82
|
+
queryClient.setQueryData([entityKey, idFactory(result)], result);
|
|
83
|
+
return queryClient.invalidateQueries(collectionName);
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
submit: (payload: I) => mutateAsync(payload),
|
|
88
|
+
isLoading,
|
|
89
|
+
error,
|
|
90
|
+
submissionResult: data,
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
type UpdateResourceOptions = MutatingResourceOptions & {
|
|
95
|
+
collectionName?: QueryKeyPair;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @beta
|
|
100
|
+
* @since 2.41.0
|
|
101
|
+
*/
|
|
102
|
+
export const useUpdateResource = <T>(
|
|
103
|
+
link: LinkOrHalLink,
|
|
104
|
+
idFactory: (createdResource: T) => string,
|
|
105
|
+
{
|
|
106
|
+
contentType = "application/json",
|
|
107
|
+
collectionName: [entityQueryKey, collectionName] = ["", ""],
|
|
108
|
+
}: UpdateResourceOptions = {}
|
|
109
|
+
): MutationResult<T> => {
|
|
110
|
+
const queryClient = useQueryClient();
|
|
111
|
+
const { mutateAsync, isLoading, error, data } = useMutation<unknown, Error, T>(
|
|
112
|
+
(resource) => apiClient.put(unwrapLink(link, "update"), resource, contentType),
|
|
113
|
+
{
|
|
114
|
+
onSuccess: async (_, payload) => {
|
|
115
|
+
await queryClient.invalidateQueries(entityQueryKey ? [entityQueryKey, idFactory(payload)] : idFactory(payload));
|
|
116
|
+
if (collectionName) {
|
|
117
|
+
await queryClient.invalidateQueries(collectionName);
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
return {
|
|
123
|
+
submit: (resource: T) => mutateAsync(resource),
|
|
124
|
+
isLoading,
|
|
125
|
+
error,
|
|
126
|
+
submissionResult: data,
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
type DeleteResourceOptions = {
|
|
131
|
+
collectionName?: QueryKeyPair;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @beta
|
|
136
|
+
* @since 2.41.0
|
|
137
|
+
*/
|
|
138
|
+
export const useDeleteResource = <T extends HalRepresentation>(
|
|
139
|
+
idFactory: (createdResource: T) => string,
|
|
140
|
+
{ collectionName: [entityQueryKey, collectionName] = ["", ""] }: DeleteResourceOptions = {}
|
|
141
|
+
): MutationResult<T> => {
|
|
142
|
+
const queryClient = useQueryClient();
|
|
143
|
+
const { mutateAsync, isLoading, error, data } = useMutation<unknown, Error, T>(
|
|
144
|
+
(resource) => {
|
|
145
|
+
const deleteUrl = (resource._links.delete as Link).href;
|
|
146
|
+
return apiClient.delete(deleteUrl);
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
onSuccess: async (_, resource) => {
|
|
150
|
+
const id = idFactory(resource);
|
|
151
|
+
await queryClient.removeQueries(entityQueryKey ? [entityQueryKey, id] : id);
|
|
152
|
+
if (collectionName) {
|
|
153
|
+
await queryClient.invalidateQueries(collectionName);
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
return {
|
|
159
|
+
submit: (resource: T) => mutateAsync(resource),
|
|
160
|
+
isLoading,
|
|
161
|
+
error,
|
|
162
|
+
submissionResult: data,
|
|
163
|
+
};
|
|
164
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
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 } from "react";
|
|
26
|
+
import { Controller, ControllerRenderProps, Path } from "react-hook-form";
|
|
27
|
+
import { useScmFormContext } from "../ScmFormContext";
|
|
28
|
+
import SelectField from "./SelectField";
|
|
29
|
+
import { useScmFormPathContext } from "../FormPathContext";
|
|
30
|
+
import { prefixWithoutIndices } from "../helpers";
|
|
31
|
+
import classNames from "classnames";
|
|
32
|
+
|
|
33
|
+
type Props<T extends Record<string, unknown>> = Omit<
|
|
34
|
+
ComponentProps<typeof SelectField>,
|
|
35
|
+
"error" | "label" | "required" | keyof ControllerRenderProps
|
|
36
|
+
> & {
|
|
37
|
+
rules?: ComponentProps<typeof Controller>["rules"];
|
|
38
|
+
name: Path<T>;
|
|
39
|
+
label?: string;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
function ControlledSelectField<T extends Record<string, unknown>>({
|
|
43
|
+
name,
|
|
44
|
+
label,
|
|
45
|
+
helpText,
|
|
46
|
+
rules,
|
|
47
|
+
testId,
|
|
48
|
+
defaultValue,
|
|
49
|
+
readOnly,
|
|
50
|
+
className,
|
|
51
|
+
...props
|
|
52
|
+
}: Props<T>) {
|
|
53
|
+
const { control, t, readOnly: formReadonly, formId } = useScmFormContext();
|
|
54
|
+
const formPathPrefix = useScmFormPathContext();
|
|
55
|
+
const nameWithPrefix = formPathPrefix ? `${formPathPrefix}.${name}` : name;
|
|
56
|
+
const prefixedNameWithoutIndices = prefixWithoutIndices(nameWithPrefix);
|
|
57
|
+
const labelTranslation = label || t(`${prefixedNameWithoutIndices}.label`) || "";
|
|
58
|
+
const helpTextTranslation = helpText || t(`${prefixedNameWithoutIndices}.helpText`);
|
|
59
|
+
return (
|
|
60
|
+
<Controller
|
|
61
|
+
control={control}
|
|
62
|
+
name={nameWithPrefix}
|
|
63
|
+
rules={rules}
|
|
64
|
+
defaultValue={defaultValue as never}
|
|
65
|
+
render={({ field, fieldState }) => (
|
|
66
|
+
<SelectField
|
|
67
|
+
form={formId}
|
|
68
|
+
readOnly={readOnly ?? formReadonly}
|
|
69
|
+
required={rules?.required as boolean}
|
|
70
|
+
className={classNames("column", className)}
|
|
71
|
+
{...props}
|
|
72
|
+
{...field}
|
|
73
|
+
label={labelTranslation}
|
|
74
|
+
helpText={helpTextTranslation}
|
|
75
|
+
error={
|
|
76
|
+
fieldState.error
|
|
77
|
+
? fieldState.error.message || t(`${prefixedNameWithoutIndices}.error.${fieldState.error.type}`)
|
|
78
|
+
: undefined
|
|
79
|
+
}
|
|
80
|
+
testId={testId ?? `select-${nameWithPrefix}`}
|
|
81
|
+
/>
|
|
82
|
+
)}
|
|
83
|
+
/>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export default ControlledSelectField;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import React, { InputHTMLAttributes, Key, OptionHTMLAttributes } from "react";
|
|
26
|
+
import classNames from "classnames";
|
|
27
|
+
import { createVariantClass, Variant } from "../variants";
|
|
28
|
+
import { createAttributesForTesting } from "../../helpers";
|
|
29
|
+
|
|
30
|
+
type Props = {
|
|
31
|
+
variant?: Variant;
|
|
32
|
+
options?: Array<OptionHTMLAttributes<HTMLOptionElement> & { label: string }>;
|
|
33
|
+
testId?: string;
|
|
34
|
+
} & InputHTMLAttributes<HTMLSelectElement>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @beta
|
|
38
|
+
* @since 2.44.0
|
|
39
|
+
*/
|
|
40
|
+
const Select = React.forwardRef<HTMLSelectElement, Props>(
|
|
41
|
+
({ variant, children, className, options, testId, ...props }, ref) => (
|
|
42
|
+
<div className={classNames("select", { "is-multiple": props.multiple }, createVariantClass(variant), className)}>
|
|
43
|
+
<select ref={ref} {...props} {...createAttributesForTesting(testId)} className={className}>
|
|
44
|
+
{options
|
|
45
|
+
? options.map((opt) => (
|
|
46
|
+
<option {...opt} key={opt.value as Key}>
|
|
47
|
+
{opt.label}
|
|
48
|
+
{opt.children}
|
|
49
|
+
</option>
|
|
50
|
+
))
|
|
51
|
+
: children}
|
|
52
|
+
</select>
|
|
53
|
+
</div>
|
|
54
|
+
)
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
export default Select;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import React from "react";
|
|
26
|
+
import Field from "../base/Field";
|
|
27
|
+
import Control from "../base/Control";
|
|
28
|
+
import Label from "../base/label/Label";
|
|
29
|
+
import FieldMessage from "../base/field-message/FieldMessage";
|
|
30
|
+
import Help from "../base/help/Help";
|
|
31
|
+
import Select from "./Select";
|
|
32
|
+
import { useAriaId } from "../../helpers";
|
|
33
|
+
|
|
34
|
+
type Props = {
|
|
35
|
+
label: string;
|
|
36
|
+
helpText?: string;
|
|
37
|
+
error?: string;
|
|
38
|
+
} & React.ComponentProps<typeof Select>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @see https://bulma.io/documentation/form/select/
|
|
42
|
+
* @beta
|
|
43
|
+
* @since 2.44.0
|
|
44
|
+
*/
|
|
45
|
+
const SelectField = React.forwardRef<HTMLSelectElement, Props>(
|
|
46
|
+
({ label, helpText, error, className, id, ...props }, ref) => {
|
|
47
|
+
const selectId = useAriaId(id ?? props.testId);
|
|
48
|
+
const variant = error ? "danger" : undefined;
|
|
49
|
+
return (
|
|
50
|
+
<Field className={className}>
|
|
51
|
+
<Label htmlFor={selectId}>
|
|
52
|
+
{label}
|
|
53
|
+
{helpText ? <Help className="ml-1" text={helpText} /> : null}
|
|
54
|
+
</Label>
|
|
55
|
+
<Control>
|
|
56
|
+
<Select id={selectId} variant={variant} ref={ref} className="is-full-width" {...props}></Select>
|
|
57
|
+
</Control>
|
|
58
|
+
{error ? <FieldMessage variant={variant}>{error}</FieldMessage> : null}
|
|
59
|
+
</Field>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
export default SelectField;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import React, { FC, HTMLAttributes, useMemo } from "react";
|
|
26
|
+
import { useScmFormPathContext } from "../FormPathContext";
|
|
27
|
+
import { useScmFormContext } from "../ScmFormContext";
|
|
28
|
+
import { useWatch } from "react-hook-form";
|
|
29
|
+
|
|
30
|
+
type Props = {
|
|
31
|
+
name: string;
|
|
32
|
+
children?: (value: unknown) => React.ReactNode | React.ReactNode[];
|
|
33
|
+
} & HTMLAttributes<HTMLTableCellElement>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @beta
|
|
37
|
+
* @since 2.43.0
|
|
38
|
+
*/
|
|
39
|
+
const ControlledColumn: FC<Props> = ({ name, children, ...props }) => {
|
|
40
|
+
const { control } = useScmFormContext();
|
|
41
|
+
const formPathPrefix = useScmFormPathContext();
|
|
42
|
+
const nameWithPrefix = useMemo(() => (formPathPrefix ? `${formPathPrefix}.${name}` : name), [formPathPrefix, name]);
|
|
43
|
+
const value = useWatch({ control, name: nameWithPrefix, disabled: typeof children === "function" });
|
|
44
|
+
const allValues = useWatch({ control, name: formPathPrefix, disabled: typeof children !== "function" });
|
|
45
|
+
|
|
46
|
+
return <td {...props}>{typeof children === "function" ? children(allValues) : value}</td>;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default ControlledColumn;
|
|
@@ -0,0 +1,99 @@
|
|
|
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, { ReactElement } from "react";
|
|
26
|
+
import { Path, PathValue } from "react-hook-form";
|
|
27
|
+
import { useScmFormContext } from "../ScmFormContext";
|
|
28
|
+
import { ScmFormPathContextProvider, useScmFormPathContext } from "../FormPathContext";
|
|
29
|
+
import { Button } from "../../buttons";
|
|
30
|
+
import { prefixWithoutIndices } from "../helpers";
|
|
31
|
+
import classNames from "classnames";
|
|
32
|
+
import { useScmFormListContext } from "../ScmFormListContext";
|
|
33
|
+
import { useTranslation } from "react-i18next";
|
|
34
|
+
import { Notification } from "../../notifications";
|
|
35
|
+
|
|
36
|
+
type RenderProps<T extends Record<string, unknown>, PATH extends Path<T>> = {
|
|
37
|
+
value: PathValue<T, PATH>;
|
|
38
|
+
index: number;
|
|
39
|
+
remove: () => void;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
type Props<T extends Record<string, unknown>, PATH extends Path<T>> = {
|
|
43
|
+
withDelete?: boolean;
|
|
44
|
+
children: ((renderProps: RenderProps<T, PATH>) => React.ReactNode | React.ReactNode[]) | React.ReactNode;
|
|
45
|
+
className?: string;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @beta
|
|
50
|
+
* @since 2.43.0
|
|
51
|
+
*/
|
|
52
|
+
function ControlledTable<T extends Record<string, unknown>, PATH extends Path<T>>({
|
|
53
|
+
withDelete,
|
|
54
|
+
children,
|
|
55
|
+
className,
|
|
56
|
+
}: Props<T, PATH>) {
|
|
57
|
+
const [defaultTranslate] = useTranslation("commons", { keyPrefix: "form.table" });
|
|
58
|
+
const { readOnly, t } = useScmFormContext();
|
|
59
|
+
const nameWithPrefix = useScmFormPathContext();
|
|
60
|
+
const prefixedNameWithoutIndices = prefixWithoutIndices(nameWithPrefix);
|
|
61
|
+
const { fields, remove } = useScmFormListContext();
|
|
62
|
+
const deleteLabel = t(`${prefixedNameWithoutIndices}.delete`) || defaultTranslate("delete.label");
|
|
63
|
+
const emptyTableLabel = t(`${prefixedNameWithoutIndices}.empty`) || defaultTranslate("empty.label");
|
|
64
|
+
const actionHeaderLabel = t(`${prefixedNameWithoutIndices}.action.label`) || defaultTranslate("headers.action.label");
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<table className={classNames("table content is-hoverable", className)}>
|
|
68
|
+
<thead>
|
|
69
|
+
<tr>
|
|
70
|
+
{React.Children.map(children, (child) => (
|
|
71
|
+
<th>{t(`${prefixedNameWithoutIndices}.${(child as ReactElement).props.name}.label`)}</th>
|
|
72
|
+
))}
|
|
73
|
+
{withDelete && !readOnly ? <th className="has-text-right">{actionHeaderLabel}</th> : null}
|
|
74
|
+
</tr>
|
|
75
|
+
</thead>
|
|
76
|
+
<tbody>
|
|
77
|
+
{fields.length === 0 ? <tr><td colSpan={1000}><Notification type="info">{emptyTableLabel}</Notification></td></tr> : null}
|
|
78
|
+
{fields.map((value, index) => (
|
|
79
|
+
<ScmFormPathContextProvider key={value.id} path={`${nameWithPrefix}.${index}`}>
|
|
80
|
+
<tr>
|
|
81
|
+
{children}
|
|
82
|
+
{withDelete && !readOnly ? (
|
|
83
|
+
<td className="has-text-right">
|
|
84
|
+
<Button className="px-4" onClick={() => remove(index)} aria-label={deleteLabel}>
|
|
85
|
+
<span className="icon is-small">
|
|
86
|
+
<i className="fas fa-trash" />
|
|
87
|
+
</span>
|
|
88
|
+
</Button>
|
|
89
|
+
</td>
|
|
90
|
+
) : null}
|
|
91
|
+
</tr>
|
|
92
|
+
</ScmFormPathContextProvider>
|
|
93
|
+
))}
|
|
94
|
+
</tbody>
|
|
95
|
+
</table>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export default ControlledTable;
|
|
@@ -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 const variants = ["danger"] as const;
|
|
26
|
+
export type Variant = typeof variants[number];
|
|
27
|
+
export const createVariantClass = (variant?: Variant) => (variant ? `is-${variant}` : undefined);
|
|
@@ -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
|
+
export const isDevBuild = () =>
|
|
26
|
+
((window as unknown as { scmStage: string }).scmStage || "").toUpperCase() !== "PRODUCTION";
|
|
27
|
+
|
|
28
|
+
export const createAttributesForTesting = (testId?: string) => {
|
|
29
|
+
if (!testId) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
"data-testid": normalizeTestId(testId),
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// keep this weird function instead of replaceAll because of browser compatibility
|
|
38
|
+
const normalizeTestId = (testId?: string) => {
|
|
39
|
+
let id = testId?.toLowerCase();
|
|
40
|
+
while (id?.includes(" ")) {
|
|
41
|
+
id = id.replace(" ", "-");
|
|
42
|
+
}
|
|
43
|
+
return id;
|
|
44
|
+
};
|
|
@@ -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 { default as useAriaId } from "./useAriaId";
|
|
26
|
+
export { createAttributesForTesting, isDevBuild } from "./devbuild";
|
|
@@ -0,0 +1,31 @@
|
|
|
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 { useMemo } from "react";
|
|
26
|
+
|
|
27
|
+
let counter = 0;
|
|
28
|
+
|
|
29
|
+
export default function useAriaId(id?: string) {
|
|
30
|
+
return useMemo(() => id ?? `scm-id-${++counter}`, [id]);
|
|
31
|
+
}
|