-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.tsx
69 lines (61 loc) · 2.37 KB
/
index.tsx
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
import { ChangeEvent, useMemo } from "react";
import { Settings } from "lucide-react";
import { useSelector } from "react-redux";
import { twMerge } from "tailwind-merge";
import { ids } from "@/constants";
import { store } from "@/store";
import { locationPlaceholder, setLocation, toggleControls } from "@/store/reducers/editor";
import { ISTKProps } from "@/types";
import { IconButton } from "../core";
import { default as ExportAction } from "./export-button";
import { default as GridSwitch } from "./grid-switch";
const onCogClick = () => store.dispatch(toggleControls());
const Operations: React.FC<ISTKProps> = ({
options: { showGridSwitch = true, exportButtonText, operationTriggerIcon, locationInputPlaceholder } = {},
events,
...props
}) => {
const location = useSelector((state: any) => state.editor.location);
const inputPlaceholder = useMemo(() => locationInputPlaceholder ?? locationPlaceholder, [locationInputPlaceholder]);
const styles = props.styles?.operations;
const OperationTriggerIcon = operationTriggerIcon ?? Settings;
const onLocationChange = (e: ChangeEvent<HTMLInputElement>) => {
store.dispatch(setLocation(e.target.value));
};
return (
<div
id={ids.operationBar}
className={twMerge(
"w-full flex justify-between items-center gap-6 bg-white px-5 py-2 border-b border-gray-200 z-10",
styles?.root?.className
)}
style={styles?.root?.properties}
>
<input
id={ids.location}
className={twMerge(
"w-full bg-transparent font-medium outline-none text-ellipsis",
location === inputPlaceholder && "opacity-60",
styles?.input?.className
)}
value={location}
placeholder={inputPlaceholder}
style={styles?.input?.properties}
onChange={onLocationChange}
/>
<div className="flex justify-between items-center gap-2 shrink-0">
{showGridSwitch && <GridSwitch />}
<ExportAction text={exportButtonText} onExport={events?.onExport} styles={props.styles} />
<IconButton
id={ids.operationTrigger}
className={twMerge("w-10", styles?.trigger?.className)}
style={styles?.trigger?.properties}
icon={<OperationTriggerIcon className="w-5 h-5" />}
variant="secondary"
onClick={onCogClick}
/>
</div>
</div>
);
};
export default Operations;