@scm-manager/ui-forms 2.47.0 → 2.48.0
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/.turbo/turbo-build.log +7 -7
- package/build/index.d.ts +168 -67
- package/build/index.js +215 -24
- package/build/index.mjs +212 -23
- package/package.json +9 -8
- package/src/Form.stories.tsx +21 -1
- package/src/base/Control.tsx +4 -4
- package/src/base/Field.tsx +7 -5
- package/src/base/label/Label.tsx +7 -5
- package/src/chip-input/ControlledChipInputField.tsx +22 -17
- package/src/index.ts +12 -0
- package/src/radio-button/ControlledRadioGroupField.tsx +94 -0
- package/src/radio-button/RadioButton.stories.tsx +226 -0
- package/src/radio-button/RadioButton.tsx +116 -0
- package/src/radio-button/RadioButtonContext.tsx +42 -0
- package/src/radio-button/RadioGroup.tsx +49 -0
- package/src/radio-button/RadioGroupField.tsx +58 -0
|
@@ -0,0 +1,42 @@
|
|
|
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, { createContext, FC, useContext } from "react";
|
|
26
|
+
import { TFunction } from "i18next";
|
|
27
|
+
|
|
28
|
+
type ContextType = {
|
|
29
|
+
t: TFunction;
|
|
30
|
+
prefix: string;
|
|
31
|
+
formId?: string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const RadioButtonContext = createContext<ContextType | null>(null);
|
|
35
|
+
|
|
36
|
+
export function useRadioButtonContext() {
|
|
37
|
+
return useContext(RadioButtonContext);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const RadioButtonContextProvider: FC<ContextType> = ({ children, ...props }) => (
|
|
41
|
+
<RadioButtonContext.Provider value={props}>{children}</RadioButtonContext.Provider>
|
|
42
|
+
);
|
|
@@ -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, { ComponentProps } from "react";
|
|
26
|
+
import Control from "../base/Control";
|
|
27
|
+
import * as RadixRadio from "@radix-ui/react-radio-group";
|
|
28
|
+
import RadioButton from "./RadioButton";
|
|
29
|
+
|
|
30
|
+
type Props = {
|
|
31
|
+
options?: { value: string; label?: string; helpText?: string }[];
|
|
32
|
+
} & ComponentProps<typeof RadixRadio.Root>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @beta
|
|
36
|
+
* @since 2.48.0
|
|
37
|
+
*/
|
|
38
|
+
const RadioGroup = React.forwardRef<HTMLDivElement, Props>(({ options, children, className, ...props }, ref) => (
|
|
39
|
+
<RadixRadio.Root {...props} asChild>
|
|
40
|
+
<Control ref={ref} className={className}>
|
|
41
|
+
{children ??
|
|
42
|
+
options?.map((option) => (
|
|
43
|
+
<RadioButton key={option.value} value={option.value} label={option.label} helpText={option.helpText} />
|
|
44
|
+
))}
|
|
45
|
+
</Control>
|
|
46
|
+
</RadixRadio.Root>
|
|
47
|
+
));
|
|
48
|
+
|
|
49
|
+
export default RadioGroup;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import React, { ComponentProps } from "react";
|
|
26
|
+
import Field from "../base/Field";
|
|
27
|
+
import Label from "../base/label/Label";
|
|
28
|
+
import Help from "../base/help/Help";
|
|
29
|
+
import RadioGroup from "./RadioGroup";
|
|
30
|
+
|
|
31
|
+
type Props = {
|
|
32
|
+
fieldClassName?: string;
|
|
33
|
+
labelClassName?: string;
|
|
34
|
+
label: string;
|
|
35
|
+
helpText?: string;
|
|
36
|
+
} & ComponentProps<typeof RadioGroup>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @beta
|
|
40
|
+
* @since 2.48.0
|
|
41
|
+
*/
|
|
42
|
+
const RadioGroupField = React.forwardRef<HTMLDivElement, Props>(
|
|
43
|
+
({ fieldClassName, labelClassName, label, helpText, children, ...props }, ref) => {
|
|
44
|
+
return (
|
|
45
|
+
<Field className={fieldClassName} as="fieldset">
|
|
46
|
+
<Label className={labelClassName} as="legend">
|
|
47
|
+
{label}
|
|
48
|
+
{helpText ? <Help className="ml-1" text={helpText} /> : null}
|
|
49
|
+
</Label>
|
|
50
|
+
<RadioGroup ref={ref} {...props}>
|
|
51
|
+
{children}
|
|
52
|
+
</RadioGroup>
|
|
53
|
+
</Field>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
export default RadioGroupField;
|