-
Notifications
You must be signed in to change notification settings - Fork 344
/
Copy pathHeader.tsx
115 lines (103 loc) · 3.86 KB
/
Header.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import React, { useContext, useState } from 'react'
import { useEditor } from '@craftjs/core'
import SimpleTooltip from '../components/Tooltip'
import CheckIcon from '@heroicons/react/24/outline/CheckIcon'
import PencilSquareIcon from '@heroicons/react/24/outline/PencilSquareIcon'
import ArrowUturnLeftIcon from '@heroicons/react/24/outline/ArrowUturnLeftIcon'
import ArrowUturnRightIcon from '@heroicons/react/24/outline/ArrowUturnRightIcon'
import ChevronDownIcon from '@heroicons/react/24/outline/ChevronDownIcon'
import { ThemeContext } from '../store'
import Select from '../components/Select'
export const Header = () => {
const { state, query, actions } = useEditor((state, query) => ({ state, query }))
const { updateIndex, themeNames, themeIndex } = useContext(ThemeContext)
const [selectOpen, setSelectOpen] = useState(false)
const enabled = state.options.enabled
const onExport = () => {
console.log(query.serialize())
alert('Export done!')
}
const onChange = (name: string) => {
updateIndex(themeNames.indexOf(name))
}
const togglePreview = () => {
actions.setOptions((o) => (o.enabled = !enabled))
}
return (
<div className="transition w-full bg-gray-300">
<div className="flex px-4 py-2 justify-end">
{enabled && (
<div className="flex-1 flex">
<SimpleTooltip text="Undo" side="bottom" offset={4}>
<a
className={` ${
query.history.canUndo()
? 'hover:opacity-50 cursor-pointer'
: 'opacity-50 cursor-not-allowed'
} p-2`}
onClick={actions.history.undo}
>
<ArrowUturnLeftIcon className="h-4 w-4" />
</a>
</SimpleTooltip>
<SimpleTooltip text="Redo" side="bottom" offset={4}>
<a
className={` ${
query.history.canRedo()
? 'hover:opacity-50 cursor-pointer'
: 'opacity-50 cursor-not-allowed'
} p-2`}
onClick={actions.history.redo}
>
<ArrowUturnRightIcon className="h-4 w-4" />
</a>
</SimpleTooltip>
{/* <SimpleTooltip text="Export" side="bottom" offset={4}>
<a
className={`hover:opacity-50 ${
query ? 'cursor-pointer' : 'cursor-not-allowed'
} p-2`}
onClick={onExport}
>
<ArrowUpTrayIcon className="h-4 w-4" />
</a>
</SimpleTooltip> */}
<div className="mr-auto ml-auto">
<div
className="flex rounded py-2 px-4 transition cursor-pointer items-center justify-center mr-auto ml-auto"
onClick={() => setSelectOpen(true)}
>
{themeNames[themeIndex]}
<ChevronDownIcon className="h-4 w-4 ml-2" />
</div>
<Select
defaultValue={themeNames[themeIndex]}
values={themeNames}
open={selectOpen}
setOpen={setSelectOpen}
onChange={onChange}
/>
</div>
</div>
)}
<div className="flex">
{enabled ? (
<a
className="flex bg-green-600 text-white rounded py-2 px-4 transition cursor-pointer items-center"
onClick={togglePreview}
>
<CheckIcon className="h-4 w-4 mr-2" /> Preview
</a>
) : (
<a
className="flex bg-primary text-white rounded py-2 px-4 transition cursor-pointer items-center"
onClick={togglePreview}
>
<PencilSquareIcon className="h-4 w-4 mr-2" /> Edit
</a>
)}
</div>
</div>
</div>
)
}