Skip to content

Commit a64cc60

Browse files
authored
Revise docs to clarify installation guidance (#638)
* Revise docs to clarify installation guidance * Fix broken link * Clarify `:where(:root)`, add CSS part example
1 parent c5f91ec commit a64cc60

File tree

8 files changed

+181
-66
lines changed

8 files changed

+181
-66
lines changed

docs/_layouts/component.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@
255255
{# Importing #}
256256
<h2>Importing</h2>
257257
<p>
258-
The <a href="/docs/#autoloading">autoloader</a> is the recommended way to import components. If you prefer to do it manually, use one of the following code snippets.
258+
The <a href="/docs/installation/#quick-start-autoloading-via-cdn">autoloader</a> is the recommended way to import components. If you prefer to do it manually, use one of the following code snippets.
259259
</p>
260260

261261
<wa-tab-group label="How would you like to import this component?">

docs/_layouts/overview.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ tags: ["overview"]
2020
<script type="module" src="/assets/scripts/filter.js"></script>
2121

2222
{% if content | trim %}
23-
<br> {# Temp fix for spacing issue #}
23+
<wa-divider style="--spacing: var(--wa-space-3xl)"></wa-divider> {# Temp fix for spacing issue #}
2424
{{ content | safe }}
2525
{% endif %}

docs/docs/customizing.md

Lines changed: 91 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
---
22
title: Customizing
3-
description: Learn how to customize Web Awesome through parts and custom properties.
3+
description: Learn how to customize Web Awesome through themes, parts, and custom properties.
44
layout: page-outline
55
---
66

7-
Web Awesome components can be customized at a high level through a theming API. This gives you control over theme colors and general styling. For more advanced customizations, you can make use of CSS parts and custom properties to target individual components.
7+
You can customize the look and feel of Web Awesome at a high level with themes. For more advanced customizations, you can make use of CSS parts and custom properties to target individual components.
88

99
## Themes
1010

11-
Web Awesome uses numerous CSS custom properties that make up a high-level theming API and provide a consistent look and feel across the entire library. You can customize them and use them in your own application just with CSS — no preprocessor required.
11+
Web Awesome uses [themes](/docs/themes) to apply a cohesive look and feel across the entire library. Themes are built with a collection of predefined CSS custom properties, which we call [design tokens](/docs/tokens), and there are many premade themes you can choose from.
1212

13-
Because these custom properties live at the page level, they're prefixed with `--wa-` to avoid collisions with other libraries or your own custom properties.
13+
To use a theme, simply add a link to the theme's stylesheet to the `<head>` of your page. For example, you can replace the link to `default.css` in the [installation code](/docs/installation/#quick-start-autoloading-via-cdn) with this snippet to use the *Awesome* theme:
1414

15-
To customize a theme, simply override any of these custom properties in your own stylesheet by scoping your styles to `:root`, `:host`, and, if needed, the class for the specific theme you want to override. Here's an example that changes the default brand color (blue) to violet in the light theme using existing [literal colors](/docs/tokens/color/#literal-colors).
15+
```html
16+
<link rel="stylesheet" href="{% cdnUrl 'styles/themes/awesome.css' %}" />
17+
```
18+
19+
You can [customize any theme](/docs/themes/creating) just with CSS — no preprocessor required. All design tokens are prefixed with `--wa-` to avoid collisions with other libraries or your own custom properties. Simply override any design token in your own stylesheet by scoping your styles to `:where(:root)`, `:host`, the class for the specific theme you want to override (if needed), and the class for the relevant color scheme (if needed). Here's an example that changes the default brand color to violet in light mode:
1620

1721
```css
1822
:where(:root),
1923
:host,
20-
.wa-theme-default {
21-
/* Changes the brand color to violet across the library */
24+
.wa-light,
25+
.wa-dark .wa-invert {
2226
--wa-color-brand-fill-quiet: var(--wa-color-violet-95);
2327
--wa-color-brand-fill-normal: var(--wa-color-violet-90);
2428
--wa-color-brand-fill-loud: var(--wa-color-violet-50);
@@ -31,11 +35,15 @@ To customize a theme, simply override any of these custom properties in your own
3135
}
3236
```
3337

34-
For more examples and further guidance, refer to [Themes](/docs/themes) and the Theming section of this documentation. For a complete list of all custom properties used for theming, refer to `src/styles/themes/default.css` in the project's source code.
38+
:::info
39+
Wrapping the `:root` selector in `:where()` gives this selector 0 specificity. This allows us to define our design tokens' default values while ensuring they can be cleanly overridden as needed.
40+
:::
41+
42+
For a complete list of all custom properties used for theming, refer to `src/styles/themes/default.css` in the project's source code.
3543

3644
## Components
3745

38-
Whereas a theme offers a high-level way to customize the library, components offer different hooks as a low-level way to customize them individually.
46+
While themes offer a high-level way to customize the library, components offer different hooks as a low-level way to customize them individually.
3947

4048
Web Awesome components use a [shadow DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM) to encapsulate their styles and behaviors. As a result, you can't simply target their internals with the usual CSS selectors. Instead, components expose a set of custom properties and CSS parts that can be targeted to customize their appearance.
4149

@@ -122,3 +130,77 @@ CSS parts have a few important advantages:
122130
- It encourages us to think more about how components are designed and how customizations should be allowed before users can take advantage of them. Once we opt a part into the component's API, it's guaranteed to be supported and can't be removed until a major version of the library is released.
123131

124132
Most (but not all) components expose parts. You can find them in each component's API documentation under the "CSS Parts" section.
133+
134+
## Native Elements
135+
136+
If you're using [native styles](/docs/native), any custom styles added for a component should also target the corresponding native element. In general, the same styles you declare for components will work just the same to style their native counterparts.
137+
138+
For example, we can give `<input type="checkbox">` the same custom styles as `<wa-checkbox>` by using the custom properties required to style the component:
139+
```html {.example}
140+
<wa-checkbox class="pinkify">Web Awesome checkbox</wa-checkbox>
141+
<br />
142+
<label>
143+
<input type="checkbox" class="pinkify" />
144+
HTML checkbox
145+
</label>
146+
147+
<style>
148+
wa-checkbox.pinkify,
149+
input[type="checkbox"].pinkify {
150+
--background-color-checked: hotpink;
151+
--border-color-checked: hotpink;
152+
--border-width: 3px;
153+
--checked-icon-color: lavenderblush;
154+
}
155+
</style>
156+
```
157+
158+
Or, if using CSS parts, we can give both checkboxes the same custom styles using standard CSS properties:
159+
```html {.example}
160+
<wa-checkbox class="purpleify">Web Awesome checkbox</wa-checkbox>
161+
<br />
162+
<label>
163+
<input type="checkbox" class="purpleify" />
164+
HTML checkbox
165+
</label>
166+
167+
<style>
168+
wa-checkbox.purpleify::part(control),
169+
input[type="checkbox"].purpleify {
170+
border-width: 3px;
171+
}
172+
173+
wa-checkbox.purpleify:state(checked)::part(control),
174+
input[type="checkbox"].purpleify:checked {
175+
background-color: darkorchid;
176+
border-color: darkorchid;
177+
color: lavender;
178+
}
179+
</style>
180+
```
181+
182+
183+
## Style Utilities
184+
185+
Similarly, if you're using [style utilities](/docs/utilities), any custom styles added for a specific attribute variation of a component — such as `appearance`, `variant`, or `size` — should also target the corresponding style utility class. This ensures that the attribute and its utility class counterpart work interchangeably.
186+
187+
For example, we can give all outlined callouts a thick left border, regardless of whether they are styled with `appearance="outlined"` or `class="wa-outlined"`:
188+
```html {.example}
189+
<wa-callout appearance="outlined filled">
190+
<wa-icon slot="icon" name="circle-star"></wa-icon>
191+
Here's a callout with <code>appearance="outlined"</code>
192+
</wa-callout>
193+
<wa-callout class="wa-outlined wa-filled">
194+
<wa-icon slot="icon" name="circle-star"></wa-icon>
195+
Here's a callout with <code>class="wa-outlined"</code>
196+
</wa-callout>
197+
198+
<style>
199+
wa-callout:is(
200+
[appearance~="outlined"],
201+
.wa-outlined
202+
) {
203+
border-left-width: var(--wa-panel-border-radius);
204+
}
205+
</style>
206+
```

docs/docs/installation.md

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ layout: page-outline
66

77
Welcome to the Web Awesome alpha release for early backers! 👋
88

9-
==This is a very early alpha release!== For this preview, we're only offering access to the free components through a temporary CDN. Please be aware: Things can change. Things can break. You probably shouldn't be using this software in production yet! But fear not, we're working hard to polish up the free stuff you see here _plus_ all the great stuff we have planned for Web Awesome Pro!
9+
==This is a very early alpha release!== For this preview, we're offering access to Web Awesome through a temporary CDN. Please be aware: Things can change. Things can break. You probably shouldn't be using this software in production yet! But fear not, we're working hard to polish up everything you see here _plus_ all the great stuff we have planned for Web Awesome Pro!
1010

1111
Thank you so much for backing us!
1212

@@ -20,95 +20,110 @@ As a Web Awesome backer, this early alpha release is _just for you_. Please refr
2020

2121
---
2222

23-
## Autoloading via CDN (Easiest)
23+
## Quick Start (Autoloading via CDN)
2424

25-
The autoloader is the easiest way to use Web Awesome. A lightweight script watches the DOM for unregistered Web Awesome elements and lazy loads them for you — even if they're added dynamically.
25+
To get everything included in Web Awesome, add the following code to the `<head>` of your site:
2626

2727
```html
2828
<link rel="stylesheet" href="{% cdnUrl 'styles/themes/default.css' %}" />
29+
<link rel="stylesheet" href="{% cdnUrl 'styles/webawesome.css' %}" />
2930
<script type="module" src="{% cdnUrl 'webawesome.loader.js' %}"></script>
3031
```
3132

33+
This snippet includes three parts:
34+
1. **The default theme**, a stylesheet that gives a cohesive look to Web Awesome components with both light and dark modes
35+
2. **Web Awesome styles**, an optional stylesheet that [styles native HTML elements](/docs/native) and includes [utility classes](/docs/utilities) you can use in your project
36+
3. **The autoloader**, a lightweight script watches the DOM for unregistered Web Awesome elements and lazy loads them for you — even if they're added dynamically
37+
3238
Now you can [start using Web Awesome!](/docs/usage)
3339

3440
:::info
3541
While convenient, autoloading may lead to a [Flash of Undefined Custom Elements](https://www.abeautifulsite.net/posts/flash-of-undefined-custom-elements/). The linked article describes some ways to alleviate it.
3642
:::
3743

38-
## Setting the Base Path
44+
---
3945

40-
Some components rely on assets (icons, images, etc.) and Web Awesome needs to know where they're located. For convenience, Web Awesome will try to auto-detect the correct location based on the script you've loaded it from. This assumes assets are colocated with `webawesome.loader.js` and will "just work" for most users.
46+
## Using Font Awesome Kit Codes
4147

42-
==If you're using the CDN, you can skip this section.== However, if you're [cherry picking](#cherry-picking) or bundling Web Awesome, you'll need to set the base path. You can do this one of two ways.
48+
Font Awesome users can set their kit code to unlock Font Awesome Pro icons. You can provide it by adding the `data-fa-kit-code` attribute to any element on the page, or by calling the `setKitCode()` method.
4349

4450
```html
45-
<!-- Option 1: the data-webawesome attribute -->
46-
<script src="bundle.js" data-webawesome="/path/to/web-awesome/dist"></script>
51+
<!-- Option 1: the data-fa-kit-code attribute -->
52+
<script src="bundle.js" data-fa-kit-code="abc123"></script>
4753

48-
<!-- Option 2: the setBasePath() method -->
54+
<!-- Option 2: the setKitCode() method -->
4955
<script type="module">
50-
import { setBasePath } from '/path/to/web-awesome/dist/webawesome.js';
51-
setBasePath('/path/to/web-awesome/dist');
56+
import { setKitCode } from '{% cdnUrl 'webawesome.loader.js' %}';
57+
setKitCode('YOUR_KIT_CODE_HERE');
5258
</script>
5359
```
5460

55-
### Referencing Assets
61+
---
5662

57-
Most of the magic behind assets is handled internally by Web Awesome, but if you need to reference the base path for any reason, the same module exports a function called `getBasePath()`. An optional string argument can be passed, allowing you to get the full path to any asset.
63+
## Advanced Setup
5864

59-
```html
60-
<script type="module">
61-
import { getBasePath, setBasePath } from '/path/to/web-awesome/dist/webawesome.js';
65+
The autoloader is the easiest way to use Web Awesome, but different projects (or your own preferences!) may require different installation methods.
6266

63-
setBasePath('/path/to/assets');
67+
### Installing via npm
6468

65-
// ...
69+
An npm package isn't available in the early backer alpha release, but we'll have one soon! For now, please enjoy [Web Awesome from the CDN](#quick-start-autoloading-via-cdn).
6670

67-
// Get the base path, e.g. /path/to/assets
68-
const basePath = getBasePath();
71+
### Cherry Picking
6972

70-
// Get the path to an asset, e.g. /path/to/assets/file.ext
71-
const assetPath = getBasePath('file.ext');
72-
</script>
73-
```
73+
Cherry picking will only load the components you need up front, while limiting the number of files the browser has to download. The disadvantage is that you need to import each individual component on each page it's used. You'll still need to include the default theme (`styles/themes/default.css`) or another theme to style any imported components.
7474

75-
## Using Font Awesome Kit Codes
76-
77-
Font Awesome users can set their kit code to unlock Font Awesome Pro icons. You can provide it by adding the `data-fa-kit-code` attribute to any element on the page, or by calling the `setKitCode()` method.
75+
Here's an example that loads only the button component.
7876

7977
```html
80-
<!-- Option 1: the data-fa-kit-code attribute -->
81-
<script src="bundle.js" data-fa-kit-code="abc123"></script>
78+
<link rel="stylesheet" href="{% cdnUrl 'styles/themes/default.css' %}" />
8279

83-
<!-- Option 2: the setKitCode() method -->
8480
<script type="module">
85-
import { setKitCode } from '/path/to/web-awesome/dist/webawesome.js';
86-
setKitCode('YOUR_KIT_CODE_HERE');
81+
import '{% cdnUrl 'components/button/button.js' %}';
82+
83+
// <wa-button> is ready to use!
8784
</script>
8885
```
8986

90-
## Cherry Picking
87+
You can copy and paste the code to import a component from the "Importing" section of the component's documentation. Note that some components have dependencies that are automatically imported when you cherry pick. If a component has dependencies, they will be listed in the "Dependencies" section of its docs.
9188

92-
Cherry picking will only load the components you need up front, while limiting the number of files the browser has to download. The disadvantage is that you need to import each individual component on each page it's used.
89+
:::warning
90+
You will see files named `chunk.[hash].js` in the `chunks` directory. Never import these files directly, as they are generated and change from version to version.
91+
:::
9392

94-
Here's an example that loads only the button component.
9593

96-
```html
97-
<link rel="stylesheet" href="/path/to/web-awesome/dist/styles/themes/default.css" />
94+
### Setting the Base Path
9895

99-
<script type="module" data-webawesome="/path/to/web-awesome/dist">
100-
import '/path/to/web-awesome/dist/components/button/button.js';
96+
Some components rely on assets (icons, images, etc.) and Web Awesome needs to know where they're located. For convenience, Web Awesome will try to auto-detect the correct location based on the script you've loaded it from. This assumes assets are colocated with `webawesome.loader.js` and will "just work" for most users.
10197

102-
// <wa-button> is ready to use!
98+
==If you're using the CDN, you can skip this section.== However, if you're [cherry picking](#cherry-picking) or bundling Web Awesome, you'll need to set the base path. You can do this one of two ways.
99+
100+
```html
101+
<!-- Option 1: the data-webawesome attribute -->
102+
<script src="bundle.js" data-webawesome="/path/to/web-awesome/dist"></script>
103+
104+
<!-- Option 2: the setBasePath() method -->
105+
<script type="module">
106+
import { setBasePath } from '/path/to/web-awesome/dist/webawesome.js';
107+
setBasePath('/path/to/web-awesome/dist');
103108
</script>
104109
```
105110

106-
You can copy and paste the code to import a component from the "Importing" section of the component's documentation. Note that some components have dependencies that are automatically imported when you cherry pick. If a component has dependencies, they will be listed in the "Dependencies" section of its docs.
111+
### Referencing Assets
107112

108-
:::warning
109-
You will see files named `chunk.[hash].js` in the `chunks` directory. Never import these files directly, as they are generated and change from version to version.
110-
:::
113+
Most of the magic behind assets is handled internally by Web Awesome, but if you need to reference the base path for any reason, the same module exports a function called `getBasePath()`. An optional string argument can be passed, allowing you to get the full path to any asset.
111114

112-
## Using Web Awesome with npm
115+
```html
116+
<script type="module">
117+
import { getBasePath, setBasePath } from '/path/to/web-awesome/dist/webawesome.js';
113118
114-
An npm package isn't available in the early backer alpha release, but we'll have one soon! For now, please enjoy Web Awesome from the CDN as shown above.
119+
setBasePath('/path/to/assets');
120+
121+
// ...
122+
123+
// Get the base path, e.g. /path/to/assets
124+
const basePath = getBasePath();
125+
126+
// Get the path to an asset, e.g. /path/to/assets/file.ext
127+
const assetPath = getBasePath('file.ext');
128+
</script>
129+
```

docs/docs/layout.njk

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
---
22
title: Layout
3-
description: Layout components and utility classes help you organize content that can adapt to any device or screen size. Browse the collection of responsive layout tools included in Web Awesome Pro.
3+
description: Layout components and utility classes help you organize content that can adapt to any device or screen size. See the [installation instructions](#installation) to use Web Awesome's layout tools in your project.
44
layout: overview
55
categories: ["components", "utilities"]
66
override:tags: []
77
---
8+
9+
{% markdown %}
10+
## Installation
11+
12+
Layout components are included in Web Awesome's [autoloader](/docs/installation/#quick-start-autoloading-via-cdn). You can also import them individually via [cherry picking](/docs/installation/#cherry-picking).
13+
14+
Layout utilities are bundled with all [style utilities](/docs/utilities). You can import all Web Awesome page styles (including [native styles](/docs/native/)) by including the following stylesheet in your project:
15+
16+
```html
17+
<link rel="stylesheet" href="{% cdnUrl 'styles/webawesome.css' %}" />
18+
```
19+
20+
Or, you can choose to import _only_ the utilities:
21+
22+
```html
23+
<link rel="stylesheet" href="{% cdnUrl 'styles/utilities.css' %}" />
24+
```
25+
{% endmarkdown %}

docs/docs/native/index.njk

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: Native Styles
3-
description: Native Styles use your theme to style native HTML elements to match the look and feel of Web Awesome components.
3+
description: Native styles apply your theme to native HTML elements so they match the look and feel of Web Awesome components.
4+
See the [installation instructions](#installation) to use native styles in your project.
45
layout: overview
56
categories: ['forms', 'apps', 'content']
67
override:tags: []
@@ -19,7 +20,7 @@ To use all Web Awesome page styles (including [utilities](/docs/utilities/)), in
1920
<link rel="stylesheet" href="{% cdnUrl 'styles/webawesome.css' %}" />
2021
```
2122

22-
Or, to _only_ include styles for built-in elements:
23+
Or, to _only_ include styles for native elements:
2324

2425
```html
2526
<link rel="stylesheet" href="{% cdnUrl 'styles/native.css' %}" />

0 commit comments

Comments
 (0)