Repository navigation
Expand file tree
/
Copy pathResponsiveExample.js
More file actions
129 lines (124 loc) · 4.94 KB
/
Copy pathResponsiveExample.js
File metadata and controls
129 lines (124 loc) · 4.94 KB
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
import { useState } from 'react'
import redent from 'redent'
const screens = ['', 'sm:', 'md:', 'lg:', 'xl:']
function Button({ children, active, onClick }) {
return (
<button
type="button"
className={`inline-block text-center cursor-pointer select-none px-3 ${
active ? 'text-gray-800' : 'text-gray-500'
}`}
onClick={onClick}
>
{children}
</button>
)
}
const defaultTemplate = (classNames) => `<div class="${classNames}"></div>`
export function ResponsiveExample({ classNames, template = defaultTemplate, preview }) {
let [active, setActive] = useState(0)
return (
<>
<div className="flex justify-center">
<div className="grid grid-cols-5 mb-2 bg-white">
<Button active={active === 0} onClick={() => setActive(0)}>
<svg
width="8.57142857142857"
height="24"
viewBox="0 0 10 28"
xmlns="http://www.w3.org/2000/svg"
className="fill-current block mx-auto mb-1"
>
<path
d="M1.5 12h7a1.5 1.5 0 0 1 1.5 1.5v13A1.5 1.5 0 0 1 8.5 28h-7A1.5 1.5 0 0 1 0 26.5v-13A1.5 1.5 0 0 1 1.5 12zM1 15v10h8V15H1zm4 12.5a1 1 0 1 0 0-2 1 1 0 0 0 0 2zM4 13v1h2v-1H4z"
fillRule="evenodd"
></path>
</svg>
<p className="text-xs">all</p>
</Button>
<Button active={active === 1} onClick={() => setActive(1)}>
<svg
width="11.999999999999998"
height="24"
viewBox="0 0 14 28"
xmlns="http://www.w3.org/2000/svg"
className="fill-current block mx-auto mb-1"
>
<path
d="M1.5 6h11A1.5 1.5 0 0 1 14 7.5v19a1.5 1.5 0 0 1-1.5 1.5h-11A1.5 1.5 0 0 1 0 26.5v-19A1.5 1.5 0 0 1 1.5 6zM1 9v16h12V9H1zm6 18.5a1 1 0 1 0 0-2 1 1 0 0 0 0 2zM7 8a.5.5 0 1 0 0-1 .5.5 0 0 0 0 1z"
fillRule="evenodd"
></path>
</svg>
<p className="text-xs">sm</p>
</Button>
<Button active={active === 2} onClick={() => setActive(2)}>
<svg
width="22.28571428571428"
height="24"
viewBox="0 0 26 28"
xmlns="http://www.w3.org/2000/svg"
className="fill-current block mx-auto mb-1"
>
<path
d="M26 26.5a1.5 1.5 0 0 1-1.5 1.5h-23A1.5 1.5 0 0 1 0 26.5v-14A1.5 1.5 0 0 1 1.5 11h23a1.5 1.5 0 0 1 1.5 1.5v14zm-3 .5V12H3v15h20zm1.5-6.5a1 1 0 1 0 0-2 1 1 0 0 0 0 2zm-23-.5a.5.5 0 1 0 0-1 .5.5 0 0 0 0 1z"
fillRule="evenodd"
></path>
</svg>
<p className="text-xs">md</p>
</Button>
<Button active={active === 3} onClick={() => setActive(3)}>
<svg
width="32.57142857142856"
height="24"
viewBox="0 0 38 28"
xmlns="http://www.w3.org/2000/svg"
className="fill-current block mx-auto mb-1"
>
<path
d="M34 26h4v1c-1.333.667-2.667 1-4 1H4c-1.333 0-2.667-.333-4-1v-1h4V7.5A1.5 1.5 0 0 1 5.5 6h27A1.5 1.5 0 0 1 34 7.5V26zM6 8v18h26V8H6z"
fillRule="evenodd"
></path>
</svg>
<p className="text-xs">lg</p>
</Button>
<Button active={active === 4} onClick={() => setActive(4)}>
<svg
width="30.85714285714285"
height="24"
viewBox="0 0 36 28"
xmlns="http://www.w3.org/2000/svg"
className="fill-current block mx-auto mb-1"
>
<path d="M20.857 24l.857 3H24v1H12v-1h2.286l.857-3H1.5A1.5 1.5 0 0 1 0 22.5v-21A1.5 1.5 0 0 1 1.5 0h33A1.5 1.5 0 0 1 36 1.5v21a1.5 1.5 0 0 1-1.5 1.5H20.857zM2 2v18h32V2H2z"></path>
</svg>
<p className="text-xs">xl</p>
</Button>
</div>
</div>
<div className="overflow-hidden mb-8">
<div className="rounded-t-lg bg-gray-800 border-b border-gray-300 whitespace-pre font-mono text-gray-500 text-sm">
<pre className="scrollbar-none m-0 p-0 overflow-auto scrolling-touch">
<code className="inline-block p-4">
{redent(template('{{CLASSNAMES}}'))
.trim()
.split(/(\{\{CLASSNAMES\}\})/)
.flatMap((x, i) =>
i === 1
? classNames.map((className, i) => (
<span key={i} className={active === i ? 'text-code-yellow' : ''}>
{i === 0 ? '' : ' '}
{`${screens[i]}${className}`}
</span>
))
: x
)}
</code>
</pre>
</div>
<div className="rounded-b-lg border-l border-r border-b border-gray-400 bg-white p-4">
{preview(classNames[active])}
</div>
</div>
</>
)
}