-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathdocs.css-variables.jsx
256 lines (241 loc) · 8.55 KB
/
docs.css-variables.jsx
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
import { useRef } from "react";
import Code from "~/components/Code";
import Heading from "~/components/Heading";
import Link from "~/components/Link";
import Content from "~/components/docs/Content";
import EditOnGithub from "~/components/docs/EditOnGithub";
import Header from "~/components/docs/Header";
import TableOfContents from "~/components/docs/TableOfContents";
import colorsCssVars from "~/data/code-snippets/default-theme-color-schemes.txt";
import stylesCssVars from "~/data/code-snippets/default-theme-styles.txt";
import orangeCssCode from "~/data/code-snippets/orange.txt";
import metaData from "~/data/meta";
import { removeLines } from "~/utils";
const { titleSuffix } = metaData;
export const meta = () => [
{ title: `CSS variables ${titleSuffix}` },
{
name: "description",
content:
"Customize Pico's design system with over 130 CSS variables to create a unique look and feel.",
},
];
export function links() {
return [
{ rel: "stylesheet", href: "https://fonts.googleapis.com/css2?family=Pacifico&display=swap" },
];
}
export default function CssVariables() {
const introductionRef = useRef();
const exampleRef = useRef();
const cssVariablesForColorSchemesRef = useRef();
const allCssVariablesRef = useRef();
return (
<>
{/* Header */}
<Header
title="CSS variables"
description="Customize Pico's design system with over 130 CSS variables to create a unique look and feel."
/>
{/* Table of content */}
<TableOfContents
data={[
{
anchor: "",
title: "Introduction",
ref: introductionRef,
},
{
anchor: "example",
title: "Example",
ref: exampleRef,
},
{
anchor: "css-variables-for-color-schemes",
title: "Color schemes",
ref: cssVariablesForColorSchemesRef,
},
{
anchor: "all-css-variables",
title: "All CSS variables",
ref: allCssVariablesRef,
},
]}
/>
{/* Content */}
<Content>
<section ref={introductionRef}>
<p>
Pico includes many custom properties (variables) that allow easy access to frequently
used values such as <code>font-family</code>, <code>font-size</code>,
<code>border-radius</code>, <code>margin</code>, <code>padding</code>, and more.
</p>
<p>
All CSS variables are prefixed with <code>pico-</code> to avoid collisions with other
CSS frameworks or your own vars. You can remove or customize this prefix by recompiling
the CSS files with <Link to="/docs/sass">SASS</Link>.
</p>
<p>
You can define the CSS variables within the <code>:root</code> selector to apply the
changes globally or overwrite the CSS variables on specific selectors to apply the
changes locally.
</p>
</section>
<section ref={exampleRef}>
<Heading level={2} anchor="example">
Example
</Heading>
<article aria-label="Button colors example" className="component" id="css-var-example">
<style>{`
#css-var-example h1,
#css-var-example p,
#css-var-example button {
--pico-border-radius: 2rem;
--pico-typography-spacing-vertical: 1.5rem;
--pico-form-element-spacing-vertical: 1rem;
--pico-form-element-spacing-horizontal: 1.5rem;
}
#css-var-example h1 {
--pico-font-family: Pacifico, cursive;
--pico-font-weight: 400;
--pico-typography-spacing-vertical: 0.5rem;
}
#css-var-example button {
--pico-font-weight: 700;
margin-bottom: 0;
}
`}</style>
<h1>Music fest mania</h1>
<p>
Get ready to dance and sing your heart out at our Music Fest Mania. Join the crowd,
jam to your favorite band, and discover new artists.
</p>
<button>Let’s rock out!</button>
<Code as="footer">{`<style>
:root {
--pico-border-radius: 2rem;
--pico-typography-spacing-vertical: 1.5rem;
--pico-form-element-spacing-vertical: 1rem;
--pico-form-element-spacing-horizontal: 1.25rem;
}
h1 {
--pico-font-family: Pacifico, cursive;
--pico-font-weight: 400;
--pico-typography-spacing-vertical: 0.5rem;
}
button {
--pico-font-weight: 700;
}
</style>
<h1>Music fest mania</h1>
<p>
Get ready to dance and sing your heart out at
our Music Fest Mania. Join the crowd, jam to
your favorite band, and discover new artists.
</p>
<button>Let's rock out!</button>
`}</Code>
</article>
</section>
<section ref={cssVariablesForColorSchemesRef}>
<Heading level={2} anchor="css-variables-for-color-schemes">
CSS variables for color schemes
</Heading>
<p>
To add or edit CSS variables for light mode only (the default mode), define them inside:
</p>
<Code language="css">{`/* Light color scheme (Default) */
/* Can be forced with data-theme="light" */
[data-theme="light"],
:root:not([data-theme="dark"]) {
...
}`}</Code>
<p>To add or edit CSS variables for dark mode, you need to define them twice.</p>
<p>
The first inclusion is in the <code>{`@media`}</code>query that checks if the user has
dark mode enabled through their device settings with{" "}
<code>{`prefers-color-scheme:
dark`}</code>
. In this case, the dark mode styling is applied to the <code>{`:root`}</code> element
if there is no explicit <code>{`data-theme`}</code> attribute set.
</p>
<p>
The second inclusion is when you force the dark mode with{" "}
<code>{`data-theme="dark"`}</code>. This allows you to manually toggle between the light
and dark themes regardless of the user’s device settings.
</p>
<Code language="css">{`/* Dark color scheme (Auto) */
/* Automatically enabled if user has Dark mode enabled */
@media only screen and (prefers-color-scheme: dark) {
:root:not([data-theme]) {
...
}
}
/* Dark color scheme (Forced) */
/* Enabled if forced with data-theme="dark" */
[data-theme="dark"] {
...
}`}</Code>
<details>
<summary role="button" className="secondary">
Detailed example to override the primary color
</summary>
<Code language="css">
{removeLines({
code: orangeCssCode,
linesMatching: [
" --pico-switch-thumb-box-shadow: 0 0 0 rgba(0, 0, 0, 0);",
" --pico-switch-thumb-box-shadow: 0 0 0 rgba(0, 0, 0, 0);",
],
linesToRemoveFromEnd: 2,
})}
</Code>
</details>
</section>
<section ref={allCssVariablesRef}>
<Heading level={2} anchor="all-css-variables">
All CSS variables
</Heading>
<p>There are two categories of CSS variables:</p>
<ol>
<li>
<strong>Style variables</strong>, which do not depend on the color scheme,
</li>
<li>
<strong>Color variables</strong>, which depend on the color scheme.
</li>
</ol>
<p style={{ marginBottom: "2rem" }}>
Here is the list of all CSS variables used in Pico:
</p>
<details>
<summary role="button" className="secondary">
Default styles CSS variables
</summary>
<Code language="css">
{removeLines({
code: stylesCssVars,
linesToRemoveFromStart: 3,
linesToRemoveFromEnd: 2,
})}
</Code>
</details>
<details>
<summary role="button" className="secondary">
Default colors CSS variables
</summary>
<Code language="css">
{removeLines({
code: colorsCssVars,
linesToRemoveFromStart: 3,
linesToRemoveFromEnd: 2,
})}
</Code>
</details>
</section>
{/* Edit on GitHub */}
<EditOnGithub file="docs.css-variables.jsx" />
</Content>
</>
);
}