@uncinq/css-components 1.16.2 → 1.16.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -10
- package/css/components/alert.css +5 -0
- package/css/components/panel.css +8 -6
- package/docs/_index.md +13 -11
- package/docs/buttons/_index.md +75 -0
- package/docs/buttons/btn-close.md +58 -0
- package/docs/buttons/btn-filter.md +36 -0
- package/docs/buttons/btn-menu.md +39 -0
- package/docs/buttons/btn-search.md +40 -0
- package/docs/buttons/btn-share.md +33 -0
- package/docs/buttons/btn-toc.md +23 -0
- package/docs/buttons/btn-toggle-video.md +58 -0
- package/docs/buttons/btn.md +95 -0
- package/docs/cascade-layers.md +8 -6
- package/docs/content/_index.md +39 -0
- package/docs/content/alert.md +97 -0
- package/docs/content/badge.md +50 -0
- package/docs/content/banner.md +43 -0
- package/docs/content/card.md +93 -0
- package/docs/content/items.md +76 -0
- package/docs/content/list.md +41 -0
- package/docs/content/media.md +88 -0
- package/docs/content/surtitle.md +43 -0
- package/docs/embeds/_index.md +25 -0
- package/docs/embeds/embed.md +53 -0
- package/docs/embeds/map.md +57 -0
- package/docs/embeds/video.md +53 -0
- package/docs/forms/_index.md +31 -0
- package/docs/forms/form-check.md +77 -0
- package/docs/forms/form.md +67 -0
- package/docs/navigation/_index.md +29 -0
- package/docs/navigation/breadcrumb.md +59 -0
- package/docs/navigation/nav-accessibility.md +67 -0
- package/docs/navigation/nav-title.md +43 -0
- package/docs/navigation/nav.md +65 -0
- package/docs/navigation/pagination.md +77 -0
- package/docs/overlays/_index.md +34 -0
- package/docs/overlays/drawer.md +58 -0
- package/docs/overlays/dropdown.md +87 -0
- package/docs/overlays/modal.md +75 -0
- package/docs/overlays/panel.md +159 -0
- package/docs/utilities/_index.md +21 -0
- package/docs/{utilities.md → utilities/scrollsnap.md} +26 -9
- package/package.json +1 -1
- package/docs/buttons.md +0 -103
- package/docs/content.md +0 -145
- package/docs/embeds.md +0 -66
- package/docs/forms.md +0 -80
- package/docs/navigation.md +0 -93
- package/docs/overlays.md +0 -133
package/docs/content.md
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
isIndex: false
|
|
3
|
-
title: Content
|
|
4
|
-
description: Alerts, badges, banners, cards, the items grid, labelled lists, media objects and surtitles.
|
|
5
|
-
weight: 4
|
|
6
|
-
icon: card-text
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## `.alert`
|
|
10
|
-
|
|
11
|
-
An inline notification block.
|
|
12
|
-
|
|
13
|
-
```html
|
|
14
|
-
<div class="alert alert-info">
|
|
15
|
-
<p class="alert-heading">Heads up</p>
|
|
16
|
-
<p>Your changes were saved.</p>
|
|
17
|
-
</div>
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
Variants: `.alert-primary`, `.alert-secondary`, `.alert-brand`, `.alert-neutral`, `.alert-dark`, `.alert-light`, `.alert-success`, `.alert-danger`, `.alert-warning`, `.alert-info`.
|
|
21
|
-
|
|
22
|
-
Each sets the background, border and text colour from the matching `-muted` and `-strong` semantic tokens, so the pairing stays legible if the underlying colour changes.
|
|
23
|
-
|
|
24
|
-
Two behaviours are worth knowing. `--color-link` is reassigned to the alert's own text colour, so links inside an alert do not fall back to the page link colour against a tinted background. And an alert whose first child is an `.icon`, with no `.alert-heading`, switches to a horizontal layout automatically.
|
|
25
|
-
|
|
26
|
-
`.container` inside an alert inherits the same flex layout, which is what lets a full-bleed alert keep its content aligned with the rest of the page.
|
|
27
|
-
|
|
28
|
-
## `.banner`
|
|
29
|
-
|
|
30
|
-
A thin variation on the alert, centred rather than start-aligned. It sets `--alert-align: center` and flattens paragraph margins, and nothing else.
|
|
31
|
-
|
|
32
|
-
```html
|
|
33
|
-
<div class="alert banner">
|
|
34
|
-
<p>Site-wide announcement.</p>
|
|
35
|
-
</div>
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
It is a modifier on `.alert`, so use both classes.
|
|
39
|
-
|
|
40
|
-
## `.badge`
|
|
41
|
-
|
|
42
|
-
A small inline label.
|
|
43
|
-
|
|
44
|
-
```html
|
|
45
|
-
<span class="badge badge-success">Published</span>
|
|
46
|
-
<a class="badge" href="/tag/css">css</a>
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
Variants mirror the alert set: `.badge-primary`, `.badge-secondary`, `.badge-brand`, `.badge-neutral`, `.badge-dark`, `.badge-light`, `.badge-success`, `.badge-danger`, `.badge-warning`, `.badge-info`.
|
|
50
|
-
|
|
51
|
-
Hover styles apply only to `a.badge`, guarded by `@media (hover: hover) and (pointer: fine)`, so a static badge never looks interactive.
|
|
52
|
-
|
|
53
|
-
## `.card`
|
|
54
|
-
|
|
55
|
-
A self-contained content card.
|
|
56
|
-
|
|
57
|
-
```html
|
|
58
|
-
<article class="card">
|
|
59
|
-
<div class="content">
|
|
60
|
-
<p class="surtitle">Category</p>
|
|
61
|
-
<p class="title">Card title</p>
|
|
62
|
-
<p class="description">Short description.</p>
|
|
63
|
-
</div>
|
|
64
|
-
<div class="media">
|
|
65
|
-
<picture>...</picture>
|
|
66
|
-
</div>
|
|
67
|
-
</article>
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
The media block sits first visually, through `--card-media-order: -1`, regardless of its position in the markup. Put it after the content so that screen readers and search engines reach the text first.
|
|
71
|
-
|
|
72
|
-
Wrapping the content in `a.content` makes the whole card clickable, using a `::before` overlay that covers the card. Focus is then handled on the card itself with `:has(a.content:focus-visible)`, so the focus ring outlines the card rather than an invisible box. Nested interactive elements inside such a card will be unreachable, which is the known trade-off of this pattern.
|
|
73
|
-
|
|
74
|
-
Sizing with `--card-max-width` and `--card-width` is unset by default. Prefer `ch` units, so the width tracks the text measure.
|
|
75
|
-
|
|
76
|
-
{{< alert-block state="info" >}}
|
|
77
|
-
The source comment in `card.css` describes `.card` as a backwards-compatible alias for `.item` and recommends using `.item` directly. That is misleading for anyone consuming this package on its own: **`.item` is not defined here**. It lives in the Hugolify design system theme. Within `@uncinq/css-components`, `.card` is a complete implementation and the class to use.
|
|
78
|
-
{{< /alert-block >}}
|
|
79
|
-
|
|
80
|
-
## `.items`
|
|
81
|
-
|
|
82
|
-
A responsive grid, and the usual container for cards.
|
|
83
|
-
|
|
84
|
-
```html
|
|
85
|
-
<div class="items">
|
|
86
|
-
<article class="card">...</article>
|
|
87
|
-
<article class="card">...</article>
|
|
88
|
-
</div>
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
The column count is intrinsic rather than breakpoint-driven:
|
|
92
|
-
|
|
93
|
-
```css
|
|
94
|
-
grid-template-columns: repeat(
|
|
95
|
-
var(--items-cols, auto-fill),
|
|
96
|
-
minmax(min(var(--items-min-width, var(--max-width-item)), 100%), 1fr)
|
|
97
|
-
);
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
Items wrap when they no longer fit at `--items-min-width`, with no media query involved. Set `--items-cols` to a number to force a fixed count instead.
|
|
101
|
-
|
|
102
|
-
It also declares `container-type: inline-size` and `container-name: items`, so children can use container queries against the grid rather than the viewport.
|
|
103
|
-
|
|
104
|
-
Pair it with [`.scrollsnap`](../utilities/) to turn the grid into a horizontal carousel below a given breakpoint.
|
|
105
|
-
|
|
106
|
-
## `.list`
|
|
107
|
-
|
|
108
|
-
A compact labelled list with dash markers.
|
|
109
|
-
|
|
110
|
-
```html
|
|
111
|
-
<div class="list">
|
|
112
|
-
<p>Optional label</p>
|
|
113
|
-
<ul>
|
|
114
|
-
<li>First</li>
|
|
115
|
-
<li>Second</li>
|
|
116
|
-
</ul>
|
|
117
|
-
</div>
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
The wrapper is a `div`, with the label as a sibling of the list rather than inside it. Either `ul` or `ol` works.
|
|
121
|
-
|
|
122
|
-
## `.media`
|
|
123
|
-
|
|
124
|
-
The structural base for media blocks, controlling aspect ratio, background and border.
|
|
125
|
-
|
|
126
|
-
| Class | Use |
|
|
127
|
-
| --- | --- |
|
|
128
|
-
| `.media` | Base, for a picture or video |
|
|
129
|
-
| `.media-logo` | Logo, typically contained rather than cropped |
|
|
130
|
-
| `.media-icon` | Icon, sized from `--icon-size` |
|
|
131
|
-
|
|
132
|
-
`.media-logo` and `.media-icon` build on `.media`. Inside a `.card`, the card reassigns `--media-color-background` and `--media-ratio` from its own `--card-media-*` tokens, so a media block adapts to its context without a variant class.
|
|
133
|
-
|
|
134
|
-
A `.video` inside a `.media` is stretched to fill it. See [Embeds](../embeds/).
|
|
135
|
-
|
|
136
|
-
## `.surtitle`
|
|
137
|
-
|
|
138
|
-
An eyebrow label above a heading.
|
|
139
|
-
|
|
140
|
-
```html
|
|
141
|
-
<p class="surtitle">Category</p>
|
|
142
|
-
<h2>Main title</h2>
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
Inside a `.card` it gets a negative `--surtitle-margin-block-end`, pulling it closer to the title so the pair reads as one unit.
|
package/docs/embeds.md
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
isIndex: false
|
|
3
|
-
title: Embeds
|
|
4
|
-
description: Aspect-ratio wrappers for third-party embeds, native video and maps.
|
|
5
|
-
weight: 6
|
|
6
|
-
icon: play-btn
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## `.embed`
|
|
10
|
-
|
|
11
|
-
A responsive container for third-party embeds, holding an aspect ratio so the page does not reflow once the iframe loads.
|
|
12
|
-
|
|
13
|
-
```html
|
|
14
|
-
<div class="embed">
|
|
15
|
-
<iframe src="https://..." title="Video title" allowfullscreen></iframe>
|
|
16
|
-
</div>
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
Accepts `iframe`, `video`, `embed` or `object` as its child. The ratio comes from `--embed-ratio`, which defaults to the video ratio token. Override it per instance for a square or portrait embed:
|
|
20
|
-
|
|
21
|
-
```html
|
|
22
|
-
<div class="embed" style="--embed-ratio: 1">...</div>
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
Always give the `iframe` a `title`. It is the only accessible name an embedded frame has.
|
|
26
|
-
|
|
27
|
-
## `.video`
|
|
28
|
-
|
|
29
|
-
A wrapper for a **native** `<video>`, as opposed to an embedded player.
|
|
30
|
-
|
|
31
|
-
```html
|
|
32
|
-
<div class="video">
|
|
33
|
-
<video autoplay muted loop playsinline></video>
|
|
34
|
-
<button class="btn btn-toggle-video is-playing" aria-label="Pause">
|
|
35
|
-
<span class="icon-pause"></span>
|
|
36
|
-
<span class="icon-play"></span>
|
|
37
|
-
</button>
|
|
38
|
-
</div>
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
The wrapper positions the optional toggle control over the video. Inside a `.media`, the wrapper is stretched to fill it, so a video and an image are interchangeable within a card.
|
|
42
|
-
|
|
43
|
-
The control is there for a reason rather than for decoration. A video that autoplays without native controls must be pausable to meet WCAG, which is exactly what `.btn-toggle-video` provides. If your video carries `controls`, you do not need it. See [Buttons](../buttons/#btn-toggle-video) for the `.is-playing` contract.
|
|
44
|
-
|
|
45
|
-
## `.map`
|
|
46
|
-
|
|
47
|
-
A map container, driven by Leaflet through a `js-map` hook.
|
|
48
|
-
|
|
49
|
-
```html
|
|
50
|
-
<div class="map js-map"
|
|
51
|
-
data-markers="[...]"
|
|
52
|
-
data-zoom="12"
|
|
53
|
-
data-tile="3"
|
|
54
|
-
data-marker-hidden="false"></div>
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
| Attribute | Role |
|
|
58
|
-
| --- | --- |
|
|
59
|
-
| `data-markers` | The markers to plot |
|
|
60
|
-
| `data-zoom` | Initial zoom level |
|
|
61
|
-
| `data-tile` | Tile layer selection |
|
|
62
|
-
| `data-marker-hidden` | Whether markers start hidden |
|
|
63
|
-
|
|
64
|
-
This package provides the container only: sizing, background and border. Leaflet itself, its stylesheet and the script reading those attributes are yours to supply.
|
|
65
|
-
|
|
66
|
-
Leaflet's own CSS is a good example of why the layer order matters. Import it into `@layer libs` and any adjustments you write into `@layer vendors`, so that a lazily loaded Leaflet cannot outrank your own rules on source order. See [Cascade layers](../cascade-layers/).
|
package/docs/forms.md
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
isIndex: false
|
|
3
|
-
title: Forms
|
|
4
|
-
description: The .form grid, its layout helpers, and where the actual control styling lives.
|
|
5
|
-
weight: 7
|
|
6
|
-
icon: ui-checks
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
Form **controls** are styled by [@uncinq/css-base](../../css-base/base/#forms), on the native elements themselves. There is no `.input` or `.select` class to apply.
|
|
10
|
-
|
|
11
|
-
This package adds only what css-base cannot: the layout around those controls.
|
|
12
|
-
|
|
13
|
-
## `.form`
|
|
14
|
-
|
|
15
|
-
A responsive two-column grid that collapses to one column when there is not enough room.
|
|
16
|
-
|
|
17
|
-
```html
|
|
18
|
-
<form class="form">
|
|
19
|
-
<div>
|
|
20
|
-
<label for="first">First name</label>
|
|
21
|
-
<input id="first" type="text">
|
|
22
|
-
</div>
|
|
23
|
-
<div>
|
|
24
|
-
<label for="last">Last name</label>
|
|
25
|
-
<input id="last" type="text">
|
|
26
|
-
</div>
|
|
27
|
-
<div class="full">
|
|
28
|
-
<label for="message">Message</label>
|
|
29
|
-
<textarea id="message"></textarea>
|
|
30
|
-
<p class="help">Markdown is supported.</p>
|
|
31
|
-
</div>
|
|
32
|
-
<div class="actions">
|
|
33
|
-
<button class="btn" type="submit">Send</button>
|
|
34
|
-
</div>
|
|
35
|
-
</form>
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
The column rule is worth reading once:
|
|
39
|
-
|
|
40
|
-
```css
|
|
41
|
-
grid-template-columns: repeat(
|
|
42
|
-
auto-fill,
|
|
43
|
-
minmax(max(var(--form-col-min-width, 25ch), calc(50% - var(--gap) / 2)), 1fr)
|
|
44
|
-
);
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
The `max()` sets a floor of `25ch` **and** caps the result at half the width. The effect is a form that is one column or two, never three, however wide the container gets. A three-column form is almost never what you want, because it breaks the vertical reading order of a sequence of fields.
|
|
48
|
-
|
|
49
|
-
Change the floor with `--form-col-min-width`.
|
|
50
|
-
|
|
51
|
-
## Layout helpers
|
|
52
|
-
|
|
53
|
-
| Class | Effect |
|
|
54
|
-
| --- | --- |
|
|
55
|
-
| `.full` | Spans both columns, `grid-column: 1 / -1` |
|
|
56
|
-
| `.actions` | Spans both columns and stacks its children vertically |
|
|
57
|
-
| `.help` | Help text under a field |
|
|
58
|
-
| `.form-check` | A checkbox or radio laid out inline with its label |
|
|
59
|
-
|
|
60
|
-
```html
|
|
61
|
-
<div class="form-check">
|
|
62
|
-
<input id="terms" type="checkbox">
|
|
63
|
-
<label for="terms">I accept the terms</label>
|
|
64
|
-
</div>
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
`.form-check` is deliberately minimal, just `display: flex`. The checkbox and radio appearance, including the gap with the adjacent label, comes from css-base, which styles `[type='checkbox'] + label` directly.
|
|
68
|
-
|
|
69
|
-
## Accessibility
|
|
70
|
-
|
|
71
|
-
Nothing here supplies an accessible name. Every control needs a `<label for>` pointing at its `id`, or a `.visually-hidden` label when the design has no room for a visible one.
|
|
72
|
-
|
|
73
|
-
Tie `.help` text to its field with `aria-describedby`, otherwise it is visible but never announced:
|
|
74
|
-
|
|
75
|
-
```html
|
|
76
|
-
<input id="message" aria-describedby="message-help">
|
|
77
|
-
<p class="help" id="message-help">Markdown is supported.</p>
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
For error states, use `aria-invalid="true"` on the control and point `aria-describedby` at the error message.
|
package/docs/navigation.md
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
isIndex: false
|
|
3
|
-
title: Navigation
|
|
4
|
-
description: Navigation lists, skip links, breadcrumbs and pagination.
|
|
5
|
-
weight: 5
|
|
6
|
-
icon: signpost
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## `.nav`
|
|
10
|
-
|
|
11
|
-
The base navigation list, vertical by default.
|
|
12
|
-
|
|
13
|
-
```html
|
|
14
|
-
<ul class="nav">
|
|
15
|
-
<li><a href="/">Home</a></li>
|
|
16
|
-
<li><a href="/about">About</a></li>
|
|
17
|
-
</ul>
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
Works on `ul` or `ol`. **Direction is set by context, not by a modifier class**: a header lays its nav out horizontally by setting `flex-direction: row` on it. That keeps the component free of layout variants that would only ever be used in one place.
|
|
21
|
-
|
|
22
|
-
## `.nav-title`
|
|
23
|
-
|
|
24
|
-
A title within a navigation block, for labelling a group of links.
|
|
25
|
-
|
|
26
|
-
## `.nav-accessibility`
|
|
27
|
-
|
|
28
|
-
Skip links, for keyboard and assistive technology users.
|
|
29
|
-
|
|
30
|
-
```html
|
|
31
|
-
<ul class="nav nav-accessibility">
|
|
32
|
-
<li><a href="#main">Skip to content</a></li>
|
|
33
|
-
<li><a href="#navigation">Skip to navigation</a></li>
|
|
34
|
-
<li><a href="#footer">Skip to footer</a></li>
|
|
35
|
-
</ul>
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
Three things matter here, and getting any of them wrong defeats the purpose:
|
|
39
|
-
|
|
40
|
-
**It must be the first focusable element in `<body>`.** A skip link that comes after the navigation it skips is useless.
|
|
41
|
-
|
|
42
|
-
**It is hidden off-screen, not hidden.** It slides into view when a child receives focus. Using `display: none` would remove it from the tab order entirely.
|
|
43
|
-
|
|
44
|
-
**It requires the `.nav` base class** alongside it.
|
|
45
|
-
|
|
46
|
-
The targets must exist and be focusable. An `id` on a non-interactive element needs `tabindex="-1"` for the jump to move focus rather than just scroll.
|
|
47
|
-
|
|
48
|
-
## `.breadcrumb-wrapper`
|
|
49
|
-
|
|
50
|
-
The breadcrumb trail. Note that the class goes on the **wrapper**, not on the list itself.
|
|
51
|
-
|
|
52
|
-
```html
|
|
53
|
-
<nav class="breadcrumb-wrapper" aria-label="Breadcrumb">
|
|
54
|
-
<ol>
|
|
55
|
-
<li><a href="/">Home</a></li>
|
|
56
|
-
<li><a href="/docs">Docs</a></li>
|
|
57
|
-
<li aria-current="page">Navigation</li>
|
|
58
|
-
</ol>
|
|
59
|
-
</nav>
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
The separator is drawn from `--breadcrumb-separator`, which defaults to `"/"`. Mark the current page with `aria-current="page"` rather than relying on it being last.
|
|
63
|
-
|
|
64
|
-
## `.pagination`
|
|
65
|
-
|
|
66
|
-
A page navigation list.
|
|
67
|
-
|
|
68
|
-
```html
|
|
69
|
-
<nav role="navigation" aria-label="Pagination">
|
|
70
|
-
<ul class="pagination">
|
|
71
|
-
<li class="disabled"><a class="first">First</a></li>
|
|
72
|
-
<li><a class="previous">Previous</a></li>
|
|
73
|
-
<li class="item active"><a href="?page=1">1</a></li>
|
|
74
|
-
<li class="item item-adjacent"><a href="?page=2">2</a></li>
|
|
75
|
-
<li><a class="next">Next</a></li>
|
|
76
|
-
<li><a class="last">Last</a></li>
|
|
77
|
-
</ul>
|
|
78
|
-
</nav>
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
| Class | Role |
|
|
82
|
-
| --- | --- |
|
|
83
|
-
| `.first`, `.previous`, `.next`, `.last` | Navigation controls, on the `a` |
|
|
84
|
-
| `.item` | A page number, on the `li` |
|
|
85
|
-
| `.item-adjacent` | A page number next to the current one |
|
|
86
|
-
| `.active` | The current page |
|
|
87
|
-
| `.disabled` | An unavailable control, on the `li` |
|
|
88
|
-
|
|
89
|
-
`.item-adjacent` exists so that a responsive paginator can hide distant page numbers while keeping the immediate neighbours visible, which is the usual mobile treatment.
|
|
90
|
-
|
|
91
|
-
**The glyphs for `.first`, `.last`, `.previous` and `.next` are not provided.** This package positions and spaces them; the theme supplies the arrow through `a::before` or `a::after` content. A paginator with no theme styling will show the text labels only, which is a reasonable fallback but rarely what you want visually.
|
|
92
|
-
|
|
93
|
-
Note that `.item` here means a pagination entry, and is unrelated to the `.item` card unit mentioned in [Content](../content/).
|
package/docs/overlays.md
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
isIndex: false
|
|
3
|
-
title: Overlays
|
|
4
|
-
description: The shared panel skeleton behind .modal and .drawer, the two opening strategies, and the .dropdown contract.
|
|
5
|
-
weight: 3
|
|
6
|
-
icon: window-stack
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## The shared panel skeleton
|
|
10
|
-
|
|
11
|
-
`.modal` and `.drawer` are the same panel. Same structure (header, content, footer), same open and closed contract, same backdrop. They differ only in where they sit: modal centres them, drawer sticks them to an edge.
|
|
12
|
-
|
|
13
|
-
`components/panel.css` owns every rule. The two variants are **pure configuration**: `modal.css` and `drawer.css` declare nothing but `--panel-*` tokens.
|
|
14
|
-
|
|
15
|
-
There is **no `.panel` class to apply.** The file targets `:where(.modal, .drawer)` directly, so the skeleton arrives with either variant class. `panel` names the shared concept and the token namespace, not a class.
|
|
16
|
-
|
|
17
|
-
```html
|
|
18
|
-
<dialog class="modal" id="contact" aria-labelledby="contactLabel">
|
|
19
|
-
<div class="header">
|
|
20
|
-
<p class="title" id="contactLabel">Contact</p>
|
|
21
|
-
<button class="btn-close js-dialog-close" aria-label="Close"></button>
|
|
22
|
-
</div>
|
|
23
|
-
<div class="content">...</div>
|
|
24
|
-
<div class="footer">...</div>
|
|
25
|
-
</dialog>
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
Each variant aliases `--panel-*` from its own namespace, so `--modal-*` and `--drawer-*` remain the public API. Override those, not `--panel-*`.
|
|
29
|
-
|
|
30
|
-
## Two ways to open a panel
|
|
31
|
-
|
|
32
|
-
**The tag picks the strategy, not the class.** Either variant works both ways.
|
|
33
|
-
|
|
34
|
-
### `<dialog>` with `showModal()`
|
|
35
|
-
|
|
36
|
-
The browser handles Escape, the focus trap and making the rest of the page inert. You get `[open]`, the native `::backdrop` and the top layer for free.
|
|
37
|
-
|
|
38
|
-
This is the right choice when the panel is **always** a dialog.
|
|
39
|
-
|
|
40
|
-
### `popover="auto"` with `showPopover()`
|
|
41
|
-
|
|
42
|
-
Same top layer, same native `::backdrop`, but the element carries no implicit role.
|
|
43
|
-
|
|
44
|
-
Use this when the panel becomes a static region of the page above a breakpoint, which is what the `.panel-inline-*` variants do. The reason is an accessibility one: a `<dialog>` is exposed as `role="dialog"` even when it is only styled as a sidebar, whereas a script can set that role solely while the panel is actually open.
|
|
45
|
-
|
|
46
|
-
## `.modal`
|
|
47
|
-
|
|
48
|
-
A centred panel. Size a single instance by overriding `--modal-max-width` on the element itself.
|
|
49
|
-
|
|
50
|
-
```html
|
|
51
|
-
<dialog class="modal" style="--modal-max-width: 40rem">...</dialog>
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
## `.drawer`
|
|
55
|
-
|
|
56
|
-
A panel sliding in from an edge.
|
|
57
|
-
|
|
58
|
-
| Class | Edge |
|
|
59
|
-
| --- | --- |
|
|
60
|
-
| `.drawer-start` | Inline start, left in a left-to-right document |
|
|
61
|
-
| `.drawer-end` | Inline end |
|
|
62
|
-
| `.drawer-top` | Top |
|
|
63
|
-
| `.drawer-bottom` | Bottom |
|
|
64
|
-
|
|
65
|
-
## `.panel-inline-*`
|
|
66
|
-
|
|
67
|
-
Turns a panel into an ordinary region of the page from a breakpoint upwards, while it stays an overlay below.
|
|
68
|
-
|
|
69
|
-
| Class | Becomes inline at |
|
|
70
|
-
| --- | --- |
|
|
71
|
-
| `.panel-inline-sm` | `--sm`, 768px |
|
|
72
|
-
| `.panel-inline-md` | `--md`, 1024px |
|
|
73
|
-
| `.panel-inline-lg` | `--lg`, 1440px |
|
|
74
|
-
| `.panel-inline-xl` | `--xl`, 1600px |
|
|
75
|
-
|
|
76
|
-
This is the case that calls for `popover="auto"` rather than `<dialog>`. A filters sidebar that is a drawer on mobile and a column on desktop should not announce itself as a dialog while it is a column.
|
|
77
|
-
|
|
78
|
-
These variants beat `.modal` and `.drawer` on **source order**, not specificity, which is why `panel.css` is imported last. See [Cascade layers](../cascade-layers/).
|
|
79
|
-
|
|
80
|
-
## `.panel-trigger-*`
|
|
81
|
-
|
|
82
|
-
The companion to `.panel-inline-*`, applied to the **trigger button** rather than to the panel. It hides the trigger at the breakpoint where the panel stops being an overlay.
|
|
83
|
-
|
|
84
|
-
| Class | Trigger hidden from |
|
|
85
|
-
| --- | --- |
|
|
86
|
-
| `.panel-trigger-sm` | `--sm`, 768px |
|
|
87
|
-
| `.panel-trigger-md` | `--md`, 1024px |
|
|
88
|
-
| `.panel-trigger-lg` | `--lg`, 1440px |
|
|
89
|
-
| `.panel-trigger-xl` | `--xl`, 1600px |
|
|
90
|
-
|
|
91
|
-
Pair the suffixes: a panel carrying `.panel-inline-md` needs its button carrying `.panel-trigger-md`, otherwise a button that opens nothing remains on screen at desktop width.
|
|
92
|
-
|
|
93
|
-
The reason this is a second class rather than something CSS derives on its own is worth knowing, because it looks like a redundancy. Nothing structurally connects a trigger to its panel: the only link is `data-target` matching an `id`, and no selector can compare two attribute values. A positional rule would work only until somebody moved the markup, and a filter button typically lives in the page heading rather than beside the panel it opens. In practice both classes come from the same configuration value, so the pair cannot disagree.
|
|
94
|
-
|
|
95
|
-
## The JavaScript contract
|
|
96
|
-
|
|
97
|
-
This package ships no JavaScript. `.modal` and `.drawer` expect a script that provides:
|
|
98
|
-
|
|
99
|
-
| Hook | Role |
|
|
100
|
-
| --- | --- |
|
|
101
|
-
| `.js-dialog-toggle[data-target="#id"]` | Opens the panel it points at |
|
|
102
|
-
| `.js-dialog-close` | Any element inside the panel that closes it |
|
|
103
|
-
|
|
104
|
-
Closing must also work on Escape and on a click outside. With `<dialog>` and `showModal()` the browser already does both. With `popover="auto"` the platform handles light dismiss and Escape too, so in practice the script mainly manages the role and the open call.
|
|
105
|
-
|
|
106
|
-
## `.dropdown`
|
|
107
|
-
|
|
108
|
-
A contextual menu, with a tighter JavaScript contract because it animates.
|
|
109
|
-
|
|
110
|
-
```html
|
|
111
|
-
<div class="dropdown">
|
|
112
|
-
<button class="js-dropdown-toggle" aria-expanded="false">Label</button>
|
|
113
|
-
<ul class="dropdown-menu" role="menu">
|
|
114
|
-
<li><a class="dropdown-item" href="#">Item</a></li>
|
|
115
|
-
<li><hr class="dropdown-divider"></li>
|
|
116
|
-
<li><a class="dropdown-item" href="#">Item</a></li>
|
|
117
|
-
</ul>
|
|
118
|
-
</div>
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
The trigger is `.js-dropdown-toggle`, and its **next element sibling must be** `.dropdown-menu`.
|
|
122
|
-
|
|
123
|
-
The script toggles three classes on the menu, in this sequence:
|
|
124
|
-
|
|
125
|
-
| Class | Meaning |
|
|
126
|
-
| --- | --- |
|
|
127
|
-
| `.showing` | Opening transition has started |
|
|
128
|
-
| `.show` | Fully open |
|
|
129
|
-
| `.hiding` | Closing transition has started |
|
|
130
|
-
|
|
131
|
-
It must also keep `aria-expanded` on the toggle in sync. The three-class sequence exists so the menu can animate out before being removed from the flow; a single `.show` class would make the closing transition impossible.
|
|
132
|
-
|
|
133
|
-
`.dropdown-menu-end` aligns the menu to the inline end of its trigger rather than the start.
|