forked from badges/shields
-
Notifications
You must be signed in to change notification settings - Fork 1
/
static-badge-maker.js
66 lines (60 loc) · 1.63 KB
/
static-badge-maker.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
import React, { useState } from 'react'
import PropTypes from 'prop-types'
import { staticBadgeUrl } from '../../core/badge-urls/make-badge-url'
import { InlineInput } from './common'
export default function StaticBadgeMaker({ baseUrl = document.location.href }) {
const [values, setValues] = useState({
label: '',
message: '',
color: '',
})
const isValid = ['message', 'color'].every(k => values[k])
const onChange = ({ target: { name, value } }) => {
setValues({
...values,
[name]: value,
})
}
const onSubmit = e => {
e.preventDefault()
const { label, message, color } = values
document.location = staticBadgeUrl({ baseUrl, label, message, color })
}
return (
<form onSubmit={onSubmit}>
<InlineInput
name="label"
onChange={onChange}
placeholder="label"
value={values.label}
/>
<InlineInput
name="message"
onChange={onChange}
placeholder="message"
value={values.message}
/>
<InlineInput
list="default-colors"
name="color"
onChange={onChange}
placeholder="color"
value={values.color}
/>
<datalist id="default-colors">
<option value="brightgreen" />
<option value="green" />
<option value="yellowgreen" />
<option value="yellow" />
<option value="orange" />
<option value="red" />
<option value="lightgrey" />
<option value="blue" />
</datalist>
<button disabled={!isValid}>Make Badge</button>
</form>
)
}
StaticBadgeMaker.propTypes = {
baseUrl: PropTypes.string,
}