@gisce/react-ooui 0.11.0 → 0.13.1
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/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/widgets/WidgetFactory.d.ts.map +1 -1
- package/dist/widgets/WidgetFactory.js +4 -0
- package/dist/widgets/WidgetFactory.js.map +1 -1
- package/dist/widgets/base/Label.d.ts.map +1 -1
- package/dist/widgets/base/Label.js +5 -2
- package/dist/widgets/base/Label.js.map +1 -1
- package/dist/widgets/custom/Radio.d.ts +10 -0
- package/dist/widgets/custom/Radio.d.ts.map +1 -0
- package/dist/widgets/custom/Radio.js +42 -0
- package/dist/widgets/custom/Radio.js.map +1 -0
- package/dist/widgets/custom/Switch.d.ts +4 -0
- package/dist/widgets/custom/Switch.d.ts.map +1 -0
- package/dist/widgets/custom/Switch.js +44 -0
- package/dist/widgets/custom/Switch.js.map +1 -0
- package/package.json +2 -2
- package/src/index.ts +4 -0
- package/src/stories/Label.stories.tsx +79 -0
- package/src/stories/custom/Radio.stories.tsx +68 -0
- package/src/stories/custom/Switch.stories.tsx +23 -0
- package/src/stories/mocks/models/polissa.ts +1 -1
- package/src/widgets/WidgetFactory.tsx +6 -0
- package/src/widgets/base/Label.tsx +19 -3
- package/src/widgets/custom/Radio.tsx +49 -0
- package/src/widgets/custom/Switch.tsx +30 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Radio as RadioAnt, Space } from "antd";
|
|
3
|
+
|
|
4
|
+
import Field from "@/common/Field";
|
|
5
|
+
import { Radio as RadioOoui } from "@gisce/ooui";
|
|
6
|
+
import { WidgetProps } from "@/types";
|
|
7
|
+
|
|
8
|
+
export const Radio = (props: WidgetProps) => {
|
|
9
|
+
const { ooui } = props;
|
|
10
|
+
const { required } = ooui;
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<Field required={required} type={"any"} {...props}>
|
|
14
|
+
<SelectionInput {...props} />
|
|
15
|
+
</Field>
|
|
16
|
+
);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type RadioInputProps = WidgetProps & {
|
|
20
|
+
onChange?: (value: any) => void;
|
|
21
|
+
value?: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const SelectionInput = (props: RadioInputProps) => {
|
|
25
|
+
const { ooui, onChange, value } = props;
|
|
26
|
+
const { selectionValues, readOnly, direction } = ooui as RadioOoui;
|
|
27
|
+
|
|
28
|
+
const values = Array.from(selectionValues.entries());
|
|
29
|
+
|
|
30
|
+
const options =
|
|
31
|
+
values &&
|
|
32
|
+
values.length &&
|
|
33
|
+
values.map((entry: string[]) => {
|
|
34
|
+
const [key, value] = entry;
|
|
35
|
+
return (
|
|
36
|
+
<RadioAnt key={key} value={key}>
|
|
37
|
+
{value}
|
|
38
|
+
</RadioAnt>
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<RadioAnt.Group disabled={readOnly} onChange={onChange} value={value}>
|
|
44
|
+
<Space direction={direction}>
|
|
45
|
+
{options}
|
|
46
|
+
</Space>
|
|
47
|
+
</RadioAnt.Group>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Switch as AntdSwitch } from "antd";
|
|
3
|
+
|
|
4
|
+
import Field from "@/common/Field";
|
|
5
|
+
import { WidgetProps } from "@/types";
|
|
6
|
+
|
|
7
|
+
export const Switch = (props: WidgetProps) => {
|
|
8
|
+
const { ooui } = props;
|
|
9
|
+
const { id, readOnly, required } = ooui;
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<Field
|
|
13
|
+
{...props}
|
|
14
|
+
valuePropName="checked"
|
|
15
|
+
>
|
|
16
|
+
<SwitchInput id={id} readOnly={readOnly} required={required} />
|
|
17
|
+
</Field>
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const SwitchInput = (props: any) => {
|
|
22
|
+
const { required, readOnly, ...restProps } = props;
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<div className="flex flex-row">
|
|
27
|
+
<AntdSwitch disabled={readOnly} {...restProps} />
|
|
28
|
+
</div>
|
|
29
|
+
);
|
|
30
|
+
};
|