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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
import React from 'react';
import CharLimit from './decorators/CharLimit'
import styled from 'styled-components'
import FloatingLabel from './decorators/FloatingLabel'
import Dropdown from 'react-dropdown';
import { LANGS, THEMES } from './renderers/Code';
const RelPositioning = styled.div`
position: relative;
height: calc(100% - 4em);
`
const FlexChild = styled.div`
display: block;
margin-left: 2em;
`
class TitleInput extends React.Component {
render() {
return (
<RelPositioning>
<FloatingLabel
label="title"
id={this.props.id}
value={this.props.value} />
<input
name="title"
readOnly={this.props.readOnly}
className="lt-shadow"
placeholder="Title"
id={this.props.id}
type="text"
autoFocus
autoComplete="off"
onChange={this.props.onChange}
value={this.props.value} />
<CharLimit
content={this.props.value}
maxLength={this.props.maxLength} />
</RelPositioning>
);
}
}
class PasteInput extends React.Component {
constructor(props) {
super(props)
this.textArea = React.createRef()
this.handleKeyDown = this.handleKeyDown.bind(this)
}
handleKeyDown(e) {
if (e.keyCode === 9) { // tab was pressed
// prevent autofocus on next intput
e.preventDefault();
// get selection start and end
const start = e.target.selectionStart
const end = e.target.selectionEnd
this.props.insertTabCallback(start, end)
// set cursor position to be at start
e.target.selectionEnd = end + 4;
}
}
render() {
return (
<RelPositioning>
<FloatingLabel
label="content"
id={this.props.id}
value={this.props.content} />
<textarea
name="content"
readOnly={this.props.readOnly}
placeholder="Paste your text here"
value={this.props.content}
id={this.props.id}
required
onChange={this.props.onChange}
onKeyDown={this.handleKeyDown}
className="lt-shadow" />
<CharLimit
content={this.props.content}
maxLength={this.props.maxLength} />
</RelPositioning>
);
}
}
class PassInput extends React.Component {
render() {
return (
<FlexChild>
<RelPositioning>
<FloatingLabel
label="password"
id={this.props.id}
value={this.props.value} />
<input
name="pass"
className="lt-shadow"
placeholder="password"
type="password"
autoComplete="off"
onChange={this.props.onChange}
value={this.props.value}
id={this.props.id} />
</RelPositioning>
</FlexChild>
);
}
}
class GenericDropdown extends React.Component {
constructor(props) {
super(props)
this._onSelect = this._onSelect.bind(this)
}
_onSelect(option) {
this.props.onChange({
target: {
name: this.props.label,
value: option.label
}
});
}
render() {
return (
<FlexChild>
<Dropdown
options={this.props.options}
onChange={this._onSelect}
callBackRef={this.props.onChange}
value={this.props.value}
placeholder={this.props.placeholder}
id={this.props.id} />
<FloatingLabel
label={this.props.label}
id={this.props.id}
value={this.props.value} />
</FlexChild>
);
}
}
const ExpiryInput = (props) => {
const options = [
'5 years',
'1 year',
'1 month',
'1 week',
'1 day',
'1 hour',
'10 min',
];
return (
<GenericDropdown
{...props}
options={options}
placeholder='1 week'
label='expiry'
/>
);
}
const LangInput = (props) => {
const options = Object.entries(LANGS).map((key, _) => {
return {
'value': key[1],
'label': key[0]
}
})
return (
<GenericDropdown
{...props}
options={options}
placeholder={LANGS.raw}
label='language'
/>
);
}
const ThemeInput = (props) => {
const options = Object.entries(THEMES).map((key, _) => {
return {
'value': key[1],
'label': key[0]
}
})
return (
<GenericDropdown
{...props}
options={options}
placeholder={'atom'}
label='theme'
/>
);
}
class PasteURLInput extends React.Component {
render() {
return (
<FlexChild>
<RelPositioning>
<FloatingLabel
label="url"
id={this.props.id}
value={this.props.id} />
<input
name="paste_url"
className="lt-shadow"
type="text"
readOnly
autoFocus
id={this.props.id}
value={this.props.fullURL} />
</RelPositioning>
</FlexChild>
);
}
}
export { TitleInput, PasteInput, PassInput, ExpiryInput, PasteURLInput, LangInput, ThemeInput }
|