This repository has been archived by the owner on Jul 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
112 lines (105 loc) · 2.45 KB
/
index.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
import React from 'react'
import tags from 'html-tags'
import voids from 'html-tags/void'
import H, { H2 } from '../index'
const demoCSS = `color: red;
font-size: 32px;
text-transform: uppercase;
letter-spacing: 0.1em;
margin: 0;
`
const Button = ({
primary,
...props
}) =>
<H.button
{...props}
css={{
fontFamily: 'inherit',
fontSize: '14px',
fontWeight: 'bold',
textAlign: 'center',
textDecoration: 'none',
display: 'inline-block',
margin: 0,
paddingLeft: '16px',
paddingRight: '16px',
paddingTop: '8px',
paddingBottom: '8px',
verticalAlign: 'middle',
appearance: 'none',
border: 0,
borderRadius: '4px',
color: 'white',
backgroundColor: primary ? '#07c' : '#444',
'&:hover': {
boxShadow: 'inset 0 0 0 64px rgba(0, 0, 0, .125)'
}
}}
/>
export default class extends React.Component {
state = {
css: demoCSS,
type: 'h2',
}
update = (fn) => this.setState(fn)
render () {
const {
type,
css
} = this.state
return (
<H css={{ padding: '32px' }}>
<H.header>
<H.h1 css='color:red'>Horror</H.h1>
<H is='h2'>
React HTML elements with CSS-in-JS
</H>
<H.pre>npm i horror</H.pre>
<Button primary>Beep</Button>
</H.header>
<H css={{
paddingTop: '48px',
paddingBottom: '48px',
}}>
<H2>
Demo
</H2>
<H css={{ display: 'flex' }}>
<H css={{}}>
{React.createElement(H, {
is: type,
css,
children: voids.includes(type) ? undefined : 'Demo'
})}
</H>
<H css={{}}>
<H.select
type='text'
name='type'
value={type}
onChange={e => {
this.update({ type: e.target.value })
}}>
{tags.map(t => (
<option
key={t}
value={t}
label={t}
/>
))}
</H.select>
<H.textarea
name='css'
value={css}
onChange={e => {
this.update({ css: e.target.value })
}}
/>
</H>
</H>
</H>
</H>
)
}
}