@sofyan/glass 0.0.0-stage → 0.1.0

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 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,132 @@
1
- # Temporary Holding Version
1
+ # @sofyan/glass
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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
+ ### Classes
37
+
38
+ | Class | What |
39
+ | ------------------------------------------------------------------------------------- | ------------------------------------------ |
40
+ | `glass` | The base material |
41
+ | `glass-btn` (+ `glass-btn-sm`, `glass-btn-lg`, `glass-block`) | Button, 44px touch target |
42
+ | `glass-menu`, `glass-menu-item`, `glass-menu-separator` | Popover menus |
43
+ | `glass-sheet`, `glass-scrim` | A panel and backdrop you position yourself |
44
+ | `glass-dialog` | The `<dialog>` sheet (use `<GlassSheet>`) |
45
+ | `glass-input`, `glass-chip` | Text field, badge |
46
+ | `glass-dark`, `glass-clear`, `glass-tinted`, `glass-tinted-secondary`, `glass-danger` | Tones |
47
+ | `glass-thin`, `glass-thick`, `glass-flat` | Thickness |
48
+ | `glass-sm`, `glass-lg`, `glass-xl`, `glass-pill` | Shape |
49
+ | `glass-interactive`, `glass-lift`, `glass-refract` | Press/hover, float on hover, refraction |
50
+ | `glass-canvas` | Neutral page background |
51
+
52
+ ### Theming
53
+
54
+ Every value is a custom property. Override any of them on `:root` (or on an element):
55
+
56
+ ```css
57
+ :root {
58
+ --lg-accent: #7c3aed; /* defaults to --color-primary, then iOS blue */
59
+ --lg-blur: 20px;
60
+ --lg-radius-sheet: 24px;
61
+ }
62
+
63
+ /* Dark mode: the neutrals are RGB triplets. */
64
+ .dark {
65
+ --lg-c-canvas: 11 11 12;
66
+ --lg-c-paper: 28 28 30;
67
+ --lg-c-ink: 245 245 247;
68
+ --lg-c-line: 255 255 255;
69
+ }
70
+ ```
71
+
72
+ See the top of [`src/glass.css`](src/glass.css) for the full list.
73
+
74
+ ## React
75
+
76
+ ```tsx
77
+ import { Glass, GlassButton, GlassSheet } from '@sofyan/glass/react';
78
+
79
+ <Glass as="nav" tone="dark" shape="pill">…</Glass>
80
+
81
+ <GlassButton variant="primary" size="lg" block>Buy tickets</GlassButton>
82
+
83
+ <GlassSheet
84
+ open={open}
85
+ onClose={() => setOpen(false)}
86
+ eyebrow="About event"
87
+ title={event.title}
88
+ closeLabel={t('close')}
89
+ >
90
+ {description}
91
+ </GlassSheet>
92
+ ```
93
+
94
+ ### `GlassSheet`
95
+
96
+ A modal on a native `<dialog>`: the page goes inert, focus stays inside, Esc closes it and
97
+ focus returns to the opener. A tap outside closes it too.
98
+
99
+ - **Phones (< 640px):** a bottom sheet with a grabber. Pull it down to close: past a quarter
100
+ of its height, or with a quick flick. Otherwise it settles back. The header always drags;
101
+ the body drags only when scrolled to the top, so scrolling the text never closes it.
102
+ - **640px and up:** a centred card. No swipe.
103
+ - Opening focuses the dialog itself, so a screen reader starts at the title and no focus
104
+ ring shows on the close button.
105
+ - `swipeToClose={false}` turns the gesture off. Add `data-glass-no-drag` to an element to
106
+ stop a drag starting on it (e.g. a horizontal carousel).
107
+
108
+ To add the gesture to your own sheet, use the hook:
109
+
110
+ ```tsx
111
+ useSwipeToClose(sheetRef, { enabled: open, scrollRef: bodyRef, onClose });
112
+ ```
113
+
114
+ ### Refraction (Chromium only)
115
+
116
+ Mount `<GlassFilter />` once near the root, then add `refract` (or `glass-refract`). Safari
117
+ and Firefox keep the plain blur.
118
+
119
+ ## Develop
120
+
121
+ ```sh
122
+ pnpm install
123
+ pnpm test # vitest
124
+ pnpm typecheck
125
+ pnpm build # dist/
126
+ ```
127
+
128
+ Release: bump `version`, then `npm publish` (needs an npm token that can publish).
129
+
130
+ ## License
131
+
132
+ MIT