-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
165 lines (157 loc) · 3.4 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>x-style Demo</title>
<style>
*,
*::before,
*::after {
box-sizing: border-box;
}
* {
margin: 0;
}
html,
body {
height: 100%;
}
body {
line-height: 1.5;
font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif,
"Apple Color Emoji", "Segoe UI Emoji";
}
code,
kbd,
samp,
pre {
font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono",
Menlo, monospace;
font-size: 1em;
}
small {
font-size: 80%;
}
.test-class {
color: red;
}
</style>
<script src="x-style.js"></script>
<script src="x-style-envvar.js"></script>
<script src="x-style-apply.js"></script>
<script src="x-style-unnest.js"></script>
<script>
xstyle("x-style");
xstyle.env = {
"--env-var-test": "orange",
};
</script>
<script>
function testChange() {
const el = document.getElementById("testChange");
el.setAttribute(
"x-style",
`
color: blue;
& span {
color: red;
}
`
);
}
function testAdd() {
const el = document.createElement("li");
el.setAttribute(
"x-style",
`
color: orange;
&:hover {
background-color: yellow;
}
& span {
color: green;
}
`
);
el.innerHTML = "Test 4 <span>123</span>";
document.getElementById("testAdd").appendChild(el);
}
</script>
</head>
<body
x-style="
font
"
>
<div
x-style="
max-width: 640px;
margin: 0 auto;
"
>
<h1>
<a href="https://github.com/samwillis/x-style/">x-style</a> Demo
</h1>
<p>This is a demo of the <code>x-style</code> attribute.</p>
<p
x-style="
color: red;
font-size: 30px;
&:hover {
background-color: yellow;
}
& > span {
color: green;
&::after {
display: inline;
content: '!';
}
}
"
>
Hello <span>World</span> - (Hover me)
</p>
<p
x-style="
color: red;
& span {
color: blue;
}
"
>
I'm red <span> and I'm blue</span>
</p>
<p
id="testChange"
x-style="
color: red;
& span {
color: blue;
}
"
>
I will change <span>to the other way around</span>
<button onclick="testChange()">Change Styles</button>
</p>
<p>
You can add elements with new styles
<button onclick="testAdd()">Add Element</button>
</p>
<ul id="testAdd"></ul>
<p x-style="
> code {
@apply test-class;
}
">
You can <code>@apply</code> styles from classes.
</p>
<p x-style="
> code {
color: env(--env-var-test);
}
">
You can use <code>env(--custom-var-name)</code> to include environment
variables, useful for media queries where you can't use <code>var()</code>.
</p>
</div>
</body>
</html>