@sofyan/glass 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +167 -2
- package/dist/dark.css +97 -0
- package/dist/glass.css +703 -0
- package/dist/react/index.d.ts +119 -0
- package/dist/react/index.js +474 -0
- package/dist/react/index.js.map +1 -0
- package/dist/tailwind.css +21 -0
- package/package.json +70 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sofyan Hadi Ahmad
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,168 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @sofyan/glass
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Liquid Glass for the web: a translucent material (CSS), React components, and a native
|
|
4
|
+
`<dialog>` sheet that closes with a swipe down on phones.
|
|
5
|
+
|
|
6
|
+
- **CSS first.** Plain CSS in cascade layers. Works with Tailwind v4 (its utilities always
|
|
7
|
+
win) and without Tailwind.
|
|
8
|
+
- **Accessible.** Fallbacks for no `backdrop-filter`, reduced transparency, more contrast
|
|
9
|
+
and reduced motion. The sheet keeps a close button as the tap alternative to the swipe
|
|
10
|
+
(WCAG 2.5.1, 2.5.7).
|
|
11
|
+
- **Safari first.** No effect depends on Chromium-only features; refraction is an opt-in
|
|
12
|
+
extra that only Chromium draws.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
pnpm add @sofyan/glass
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## CSS
|
|
21
|
+
|
|
22
|
+
With Tailwind v4, import it after Tailwind. This adds the material and the `lg-*` colours
|
|
23
|
+
(`bg-lg-paper`, `text-lg-ink-2`, `border-lg-line/10`, ...):
|
|
24
|
+
|
|
25
|
+
```css
|
|
26
|
+
@import 'tailwindcss';
|
|
27
|
+
@import '@sofyan/glass/tailwind.css';
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Without Tailwind:
|
|
31
|
+
|
|
32
|
+
```css
|
|
33
|
+
@import '@sofyan/glass/glass.css';
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Optional dark theme, after either of the above (see [Dark mode](#dark-mode)):
|
|
37
|
+
|
|
38
|
+
```css
|
|
39
|
+
@import '@sofyan/glass/dark.css';
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Classes
|
|
43
|
+
|
|
44
|
+
| Class | What |
|
|
45
|
+
| ------------------------------------------------------------------------------------- | ------------------------------------------ |
|
|
46
|
+
| `glass` | The base material |
|
|
47
|
+
| `glass-btn` (+ `glass-btn-sm`, `glass-btn-lg`, `glass-block`) | Button, 44px touch target |
|
|
48
|
+
| `glass-menu`, `glass-menu-item`, `glass-menu-separator` | Popover menus |
|
|
49
|
+
| `glass-sheet`, `glass-scrim` | A panel and backdrop you position yourself |
|
|
50
|
+
| `glass-dialog` | The `<dialog>` sheet (use `<GlassSheet>`) |
|
|
51
|
+
| `glass-input`, `glass-chip` | Text field, badge |
|
|
52
|
+
| `glass-dark`, `glass-clear`, `glass-tinted`, `glass-tinted-secondary`, `glass-danger` | Tones |
|
|
53
|
+
| `glass-thin`, `glass-thick`, `glass-flat` | Thickness |
|
|
54
|
+
| `glass-sm`, `glass-lg`, `glass-xl`, `glass-pill` | Shape |
|
|
55
|
+
| `glass-interactive`, `glass-lift`, `glass-refract` | Press/hover, float on hover, refraction |
|
|
56
|
+
| `glass-canvas` | Neutral page background |
|
|
57
|
+
|
|
58
|
+
### Theming
|
|
59
|
+
|
|
60
|
+
Every value is a custom property. Override any of them on `:root` (or on an element):
|
|
61
|
+
|
|
62
|
+
```css
|
|
63
|
+
:root {
|
|
64
|
+
--lg-accent: #7c3aed; /* defaults to --color-primary, then iOS blue */
|
|
65
|
+
--lg-blur: 20px;
|
|
66
|
+
--lg-radius-sheet: 24px;
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The accent colours (`--lg-accent`, `--lg-accent-strong`, `--lg-accent-2`,
|
|
71
|
+
`--lg-accent-2-strong`) and the sheet fill (`--lg-sheet-fill`) are resolved where they are
|
|
72
|
+
used, so they follow `--color-primary`, `--color-secondary` and the `--lg-c-*` neutrals
|
|
73
|
+
wherever those are set, not only on `:root`.
|
|
74
|
+
|
|
75
|
+
See the top of [`src/glass.css`](src/glass.css) for the full list.
|
|
76
|
+
|
|
77
|
+
#### Dark mode
|
|
78
|
+
|
|
79
|
+
Import `dark.css` after `glass.css` or `tailwind.css`, then add `class="dark"` or
|
|
80
|
+
`data-theme="dark"` to any element: `<html>` for the whole page, or a wrapper for one part
|
|
81
|
+
of it. It sets `color-scheme: dark`, retunes the neutrals, the light glass and the shadows,
|
|
82
|
+
and gives menus and sheets denser dark fills. Surfaces with a tone of their own
|
|
83
|
+
(`glass-dark`, `glass-clear`, `glass-tinted`, ...) keep it. The reduced transparency, more
|
|
84
|
+
contrast and no `backdrop-filter` fallbacks still apply.
|
|
85
|
+
|
|
86
|
+
```html
|
|
87
|
+
<html class="dark">
|
|
88
|
+
…
|
|
89
|
+
</html>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
To build your own dark theme instead, redefine the tokens under your selector. The
|
|
93
|
+
neutrals are RGB triplets:
|
|
94
|
+
|
|
95
|
+
```css
|
|
96
|
+
.dark {
|
|
97
|
+
--lg-c-canvas: 11 11 12;
|
|
98
|
+
--lg-c-paper: 28 28 30;
|
|
99
|
+
--lg-c-ink: 245 245 247;
|
|
100
|
+
--lg-c-line: 255 255 255;
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## React
|
|
105
|
+
|
|
106
|
+
```tsx
|
|
107
|
+
import { Glass, GlassButton, GlassSheet } from '@sofyan/glass/react';
|
|
108
|
+
|
|
109
|
+
<Glass as="nav" tone="dark" shape="pill">…</Glass>
|
|
110
|
+
|
|
111
|
+
<GlassButton variant="primary" size="lg" block>Buy tickets</GlassButton>
|
|
112
|
+
|
|
113
|
+
<GlassSheet
|
|
114
|
+
open={open}
|
|
115
|
+
onClose={() => setOpen(false)}
|
|
116
|
+
eyebrow="About event"
|
|
117
|
+
title={event.title}
|
|
118
|
+
closeLabel={t('close')}
|
|
119
|
+
>
|
|
120
|
+
{description}
|
|
121
|
+
</GlassSheet>
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### `GlassSheet`
|
|
125
|
+
|
|
126
|
+
A modal on a native `<dialog>`: the page goes inert, focus stays inside, Esc closes it and
|
|
127
|
+
focus returns to the opener. A tap outside closes it too.
|
|
128
|
+
|
|
129
|
+
- **Phones (< 640px):** a bottom sheet with a grabber. Pull it down to close: past a quarter
|
|
130
|
+
of its height, or with a quick flick. Otherwise it settles back. The header always drags;
|
|
131
|
+
the body drags only when scrolled to the top, so scrolling the text never closes it.
|
|
132
|
+
- After a swipe, `onClose` runs once the sheet has slid away. If `open` is still true a
|
|
133
|
+
moment later (say you ask "discard changes?" first), the sheet slides back.
|
|
134
|
+
- **640px and up:** a centred card. No swipe.
|
|
135
|
+
- Opening focuses the dialog itself, so a screen reader starts at the title and no focus
|
|
136
|
+
ring shows on the close button.
|
|
137
|
+
- `swipeToClose={false}` turns the gesture off. Add `data-glass-no-drag` to an element to
|
|
138
|
+
stop a drag starting on it (e.g. a horizontal carousel).
|
|
139
|
+
|
|
140
|
+
To add the gesture to your own sheet, use the hook:
|
|
141
|
+
|
|
142
|
+
```tsx
|
|
143
|
+
useSwipeToClose(sheetRef, { enabled: open, scrollRef: bodyRef, onClose });
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Pass `enabled: false` once the sheet is closed. After `onClose` the hook keeps the sheet
|
|
147
|
+
off-screen and clears its inline styles when `enabled` turns false; if that has not
|
|
148
|
+
happened a moment later, it slides the sheet back.
|
|
149
|
+
|
|
150
|
+
### Refraction (Chromium only)
|
|
151
|
+
|
|
152
|
+
Mount `<GlassFilter />` once near the root, then add `refract` (or `glass-refract`). Safari
|
|
153
|
+
and Firefox keep the plain blur.
|
|
154
|
+
|
|
155
|
+
## Develop
|
|
156
|
+
|
|
157
|
+
```sh
|
|
158
|
+
pnpm install
|
|
159
|
+
pnpm test # vitest
|
|
160
|
+
pnpm typecheck
|
|
161
|
+
pnpm build # dist/
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Release: bump `version`, then `npm publish` (needs an npm token that can publish).
|
|
165
|
+
|
|
166
|
+
## License
|
|
167
|
+
|
|
168
|
+
MIT
|
package/dist/dark.css
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @sofyan/glass: opt-in dark theme
|
|
3
|
+
* ---------------------------------------------------------------------------
|
|
4
|
+
* Import it after glass.css (or tailwind.css):
|
|
5
|
+
*
|
|
6
|
+
* @import '@sofyan/glass/tailwind.css';
|
|
7
|
+
* @import '@sofyan/glass/dark.css';
|
|
8
|
+
*
|
|
9
|
+
* Then add class="dark" or data-theme="dark" to any element: <html> for the whole page,
|
|
10
|
+
* or a wrapper for one part of it. Everything inside follows.
|
|
11
|
+
*
|
|
12
|
+
* It only retunes tokens (neutrals, the light glass, shadows) and the denser fills of
|
|
13
|
+
* menus and sheets. Tones you set yourself (glass-dark, glass-clear, glass-tinted, ...)
|
|
14
|
+
* stay as they are.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
@layer theme, base, components, utilities;
|
|
18
|
+
|
|
19
|
+
/* ── Tokens ───────────────────────────────────────────────────────────── */
|
|
20
|
+
/* :is(), not :where(): glass.css sets these tokens on :root, and on <html class="dark">
|
|
21
|
+
a zero-specificity rule would lose to it. :is() ties with :root, so the later rule
|
|
22
|
+
(this file) wins. */
|
|
23
|
+
@layer base {
|
|
24
|
+
:is(.dark, [data-theme='dark']) {
|
|
25
|
+
color-scheme: dark;
|
|
26
|
+
|
|
27
|
+
--lg-c-canvas: 11 11 12;
|
|
28
|
+
--lg-c-paper: 28 28 30;
|
|
29
|
+
--lg-c-raised: 44 44 46;
|
|
30
|
+
--lg-c-ink: 245 245 247;
|
|
31
|
+
--lg-c-ink-2: 152 152 157;
|
|
32
|
+
--lg-c-ink-3: 142 142 147;
|
|
33
|
+
--lg-c-line: 255 255 255;
|
|
34
|
+
|
|
35
|
+
--lg-light-fill: rgba(30, 30, 32, 0.66);
|
|
36
|
+
--lg-light-fill-hover: rgba(44, 44, 46, 0.76);
|
|
37
|
+
--lg-light-text: #f5f5f7;
|
|
38
|
+
--lg-light-rim: rgba(255, 255, 255, 0.14);
|
|
39
|
+
--lg-light-edge: rgba(255, 255, 255, 0.08);
|
|
40
|
+
|
|
41
|
+
--lg-sheen: none;
|
|
42
|
+
|
|
43
|
+
--lg-shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.3);
|
|
44
|
+
--lg-shadow-md: 0 8px 32px rgba(0, 0, 0, 0.4);
|
|
45
|
+
--lg-shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.5);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/* The same fallbacks as glass.css, for the dark fills. They come after the rule above so
|
|
49
|
+
they win over it. */
|
|
50
|
+
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
|
|
51
|
+
:is(.dark, [data-theme='dark']) {
|
|
52
|
+
--lg-light-fill: rgba(30, 30, 32, 0.92);
|
|
53
|
+
--lg-light-fill-hover: rgba(44, 44, 46, 0.96);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@media (prefers-reduced-transparency: reduce) {
|
|
58
|
+
:is(.dark, [data-theme='dark']) {
|
|
59
|
+
--lg-light-fill: rgba(30, 30, 32, 0.97);
|
|
60
|
+
--lg-light-fill-hover: #2c2c2e;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@media (prefers-contrast: more) {
|
|
65
|
+
:is(.dark, [data-theme='dark']) {
|
|
66
|
+
--lg-light-edge: rgba(255, 255, 255, 0.45);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/* ── Composites ───────────────────────────────────────────────────────── */
|
|
72
|
+
@layer components {
|
|
73
|
+
/* Denser fills for floating overlays. The :not() skips surfaces with a tone of their own,
|
|
74
|
+
which glass.css lets win by source order; :where() keeps it out of the specificity. */
|
|
75
|
+
:where(.dark, [data-theme='dark'])
|
|
76
|
+
.glass-menu:where(
|
|
77
|
+
:not(.glass-dark, .glass-clear, .glass-tinted, .glass-tinted-secondary, .glass-danger)
|
|
78
|
+
) {
|
|
79
|
+
--lg-fill: rgba(36, 36, 40, 0.88);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
:where(.dark, [data-theme='dark'])
|
|
83
|
+
.glass-sheet:where(
|
|
84
|
+
:not(.glass-dark, .glass-clear, .glass-tinted, .glass-tinted-secondary, .glass-danger)
|
|
85
|
+
) {
|
|
86
|
+
--lg-fill: rgba(30, 30, 34, 0.92);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
:where(.dark, [data-theme='dark']) .glass-menu-item:hover,
|
|
90
|
+
:where(.dark, [data-theme='dark']) .glass-menu-item:focus-visible {
|
|
91
|
+
background-color: rgba(255, 255, 255, 0.1);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
:where(.dark, [data-theme='dark']) .glass-menu-separator {
|
|
95
|
+
background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.14), transparent);
|
|
96
|
+
}
|
|
97
|
+
}
|