forked from carbon-app/carbon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WindowControls.js
121 lines (111 loc) · 2.91 KB
/
WindowControls.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
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
116
117
118
119
120
121
import React from 'react'
import { useCopyTextHandler } from 'actionsack'
import { COLORS } from '../lib/constants'
import { Controls, ControlsBW, ControlsBoxy } from './svg/Controls'
import CopySVG from './svg/Copy'
import CheckMark from './svg/Checkmark'
const size = 24
const CopyButton = React.memo(function CopyButton({ text }) {
const { onClick, copied } = useCopyTextHandler(text)
return (
<button onClick={onClick} aria-label="Copy Button">
{copied ? (
<CheckMark color={COLORS.GRAY} width={size} height={size} />
) : (
<CopySVG size={size} color={COLORS.GRAY} />
)}
<style jsx>
{`
button {
border: none;
cursor: pointer;
color: ${COLORS.SECONDARY};
background: transparent;
}
&:active {
outline: none;
}
`}
</style>
</button>
)
})
const WINDOW_THEMES_MAP = { bw: <ControlsBW />, boxy: <ControlsBoxy /> }
export function TitleBar({ light, value, onChange }) {
return (
<div>
<input
aria-label="Image title"
type="text"
spellCheck="false"
value={value || ''}
onChange={e => onChange(e.target.value)}
/>
<style jsx>
{`
div {
position: absolute;
margin: 0px;
top: -3px;
left: -9px;
width: 100%;
text-align: center;
}
input {
width: 250px;
background: none;
outline: none;
border: none;
text-align: center;
/**
* 140px is an arbitrary value, but it's roughly equal to:
* 2 * (window theme width + window theme outside margin)
*/
max-width: calc(100% - 140px);
font-size: 14px;
color: ${light ? COLORS.BLACK : COLORS.SECONDARY};
}
`}
</style>
</div>
)
}
export default function WindowControls({
theme,
copyable,
code,
light,
titleBar,
onTitleBarChange,
}) {
return (
<div className="window-controls">
{WINDOW_THEMES_MAP[theme] || <Controls />}
<TitleBar value={titleBar} onChange={onTitleBarChange} light={light} />
{copyable && (
<div className="copy-button">
<CopyButton text={code} />
</div>
)}
<style jsx>
{`
.window-controls {
margin-top: -24px;
position: relative;
top: ${theme === 'bw' ? 36 : 34}px;
margin-left: ${theme === 'bw' ? 16 : 14}px;
margin-right: ${theme === 'boxy' ? 16 : 0}px;
z-index: 2;
text-align: ${theme === 'boxy' ? 'right' : 'initial'};
}
.copy-button {
cursor: pointer;
position: absolute;
top: 0px;
right: 16px;
}
`}
</style>
</div>
)
}