-
Notifications
You must be signed in to change notification settings - Fork 583
/
Settings.js
87 lines (83 loc) · 3.24 KB
/
Settings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//@flow
import * as React from "react";
import { connect } from "@webiny/app-page-builder/editor/redux";
import { Tabs, Tab } from "@webiny/ui/Tabs";
import { isEqual } from "lodash";
import { updateElement } from "@webiny/app-page-builder/editor/actions";
import { getActiveElement } from "@webiny/app-page-builder/editor/selectors";
import ColorPicker from "@webiny/app-page-builder/editor/plugins/elementSettings/components/ColorPicker";
import Select from "@webiny/app-page-builder/editor/plugins/elementSettings/components/Select";
import Slider from "@webiny/app-page-builder/editor/plugins/elementSettings/components/Slider";
import Selector from "./Selector";
import useUpdateHandlers from "../useUpdateHandlers";
type Props = Object & {
getUpdateValue: Function,
getUpdatePreview: Function
};
const options = ["none", "solid", "dashed", "dotted"];
const DATA_NAMESPACE = "data.settings.border";
const EMPTY_OBJECT = {};
const Settings = ({ element, updateElement }: Props) => {
const { getUpdateValue, getUpdatePreview } = useUpdateHandlers({
element,
updateElement,
dataNamespace: DATA_NAMESPACE
});
return (
<React.Fragment>
<Tabs>
<Tab label={"Border"}>
<ColorPicker
label={"Color"}
valueKey={DATA_NAMESPACE + ".color"}
defaultValue={"#fff"}
updateValue={getUpdateValue("color")}
updatePreview={getUpdatePreview("color")}
/>
<Slider
label={"Width"}
valueKey={DATA_NAMESPACE + ".width"}
defaultValue={0}
updateValue={getUpdateValue("width")}
updatePreview={getUpdatePreview("width")}
min={0}
max={20}
step={1}
/>
<Slider
label={"Radius"}
valueKey={DATA_NAMESPACE + ".radius"}
defaultValue={0}
updateValue={getUpdateValue("radius")}
updatePreview={getUpdatePreview("radius")}
min={0}
max={100}
step={1}
/>
<Select
label={"Style"}
valueKey={DATA_NAMESPACE + ".style"}
defaultValue={"none"}
updateValue={getUpdateValue("style")}
options={options}
/>
<Selector
label={"Borders"}
valueKey={DATA_NAMESPACE + ".borders"}
defaultValue={EMPTY_OBJECT}
updateValue={getUpdateValue("borders")}
/>
</Tab>
</Tabs>
</React.Fragment>
);
};
export default connect(
state => {
const { id, type, path } = getActiveElement(state);
return { element: { id, type, path } };
},
{ updateElement },
null,
{ areStatePropsEqual: isEqual }
)(Settings);