@zakisheriff/liquid-glass 0.1.2 → 0.2.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/README.md +51 -569
- package/dist/index.css +670 -1339
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +191 -79
- package/dist/index.d.ts +191 -79
- package/dist/index.js +1764 -701
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1752 -697
- package/dist/index.mjs.map +1 -1
- package/package.json +36 -16
package/README.md
CHANGED
|
@@ -1,627 +1,109 @@
|
|
|
1
1
|
# <div align="center">@zakisheriff/liquid-glass</div>
|
|
2
2
|
|
|
3
3
|
<div align="center">
|
|
4
|
-
<strong>
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
<strong>Real, refracting Liquid Glass for React.</strong>
|
|
5
|
+
<br />
|
|
7
6
|
<br />
|
|
8
|
-
|
|
9
|
-
<div align="center">
|
|
10
7
|
|
|
11
8
|

|
|
12
|
-

|
|
9
|
+

|
|
14
10
|

|
|
15
11
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
<img src="https://img.shields.io/badge/View%20on%20npm-Install%20Package-CB3837?style=for-the-badge&logo=npm&logoColor=white" height="50" />
|
|
20
|
-
</a>
|
|
21
|
-
|
|
22
|
-
<br />
|
|
23
|
-
<br />
|
|
24
|
-
|
|
25
|
-
**[Website: https://liquidglass.theatom.lk](https://liquidglass.theatom.lk)**
|
|
26
|
-
|
|
27
|
-
**[GitHub: https://github.com/zakisheriff/Liquid-Glass](https://github.com/zakisheriff/Liquid-Glass)**
|
|
28
|
-
|
|
29
|
-
**[npm: https://www.npmjs.com/package/@zakisheriff/liquid-glass](https://www.npmjs.com/package/@zakisheriff/liquid-glass)**
|
|
12
|
+
**[liquidglass.theatom.lk](https://liquidglass.theatom.lk)** ·
|
|
13
|
+
**[npm](https://www.npmjs.com/package/@zakisheriff/liquid-glass)** ·
|
|
14
|
+
**[GitHub](https://github.com/zakisheriff/Liquid-Glass)**
|
|
30
15
|
|
|
31
16
|
</div>
|
|
32
17
|
|
|
33
|
-
<br />
|
|
34
|
-
|
|
35
|
-
> **"Glass should feel physical, not painted on."**
|
|
36
|
-
>
|
|
37
|
-
> `@zakisheriff/liquid-glass` brings iOS-style liquid glass surfaces to React with layered shadows, prismatic borders, refraction filters, animated shine, and native CSS blur.
|
|
38
|
-
|
|
39
18
|
---
|
|
40
19
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
- **Ready-made glass components** for buttons, cards, inputs, sheets, nav bars, and sliders
|
|
44
|
-
- **Real depth and refraction** using layered CSS, `backdrop-filter`, masks, gradients, and SVG displacement filters
|
|
45
|
-
- **TypeScript-first API** with exported prop types for every component
|
|
46
|
-
- **No design framework required** because the package ships its own CSS
|
|
47
|
-
- **Customizable surfaces** through intensity, tint, shimmer, thickness, radius, and layout props
|
|
48
|
-
|
|
49
|
-
---
|
|
20
|
+
Glass that bends light rather than just blurring it. Every surface ray-traces its own Snell's-law refraction map through a curved bevel. Lenses magnify and split colour at the rim. Every touch swells, stretches and settles with a jelly wobble, tuned frame by frame against iOS 26 screen recordings.
|
|
50
21
|
|
|
51
22
|
## Install
|
|
52
23
|
|
|
53
24
|
```bash
|
|
54
|
-
npm
|
|
25
|
+
npm i @zakisheriff/liquid-glass
|
|
55
26
|
```
|
|
56
27
|
|
|
57
|
-
```bash
|
|
58
|
-
yarn add @zakisheriff/liquid-glass
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
```bash
|
|
62
|
-
pnpm add @zakisheriff/liquid-glass
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
---
|
|
66
|
-
|
|
67
|
-
## Setup
|
|
68
|
-
|
|
69
|
-
Import the stylesheet once in your app entry file.
|
|
70
|
-
|
|
71
|
-
```tsx
|
|
72
|
-
import '@zakisheriff/liquid-glass/styles.css';
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
Then import only the components you need.
|
|
76
|
-
|
|
77
|
-
```tsx
|
|
78
|
-
import {
|
|
79
|
-
GlassButton,
|
|
80
|
-
GlassCard,
|
|
81
|
-
GlassInput,
|
|
82
|
-
GlassNav,
|
|
83
|
-
GlassSheet,
|
|
84
|
-
GlassSlider,
|
|
85
|
-
LiquidGlassFilter,
|
|
86
|
-
} from '@zakisheriff/liquid-glass';
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
For the cleanest output, wrap the area using glass components with `LiquidGlassFilter`. Components still work without it, but the provider renders one shared SVG filter set instead of each component injecting its own local filter.
|
|
90
|
-
|
|
91
|
-
```tsx
|
|
92
|
-
import { LiquidGlassFilter } from '@zakisheriff/liquid-glass';
|
|
93
|
-
import '@zakisheriff/liquid-glass/styles.css';
|
|
94
|
-
|
|
95
|
-
export default function App() {
|
|
96
|
-
return (
|
|
97
|
-
<LiquidGlassFilter>
|
|
98
|
-
<YourApp />
|
|
99
|
-
</LiquidGlassFilter>
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
If you use Next.js App Router, use these components inside a client component because they rely on browser interaction APIs.
|
|
105
|
-
|
|
106
|
-
```tsx
|
|
107
|
-
'use client';
|
|
108
|
-
|
|
109
|
-
import { GlassButton } from '@zakisheriff/liquid-glass';
|
|
110
|
-
import '@zakisheriff/liquid-glass/styles.css';
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
---
|
|
114
|
-
|
|
115
|
-
## Quick Example
|
|
116
|
-
|
|
117
28
|
```tsx
|
|
118
|
-
import {
|
|
29
|
+
import { GlassSwitch } from '@zakisheriff/liquid-glass';
|
|
119
30
|
import '@zakisheriff/liquid-glass/styles.css';
|
|
120
31
|
|
|
121
|
-
export
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
<main style={{ minHeight: '100vh', padding: 40, background: '#f3f4f6' }}>
|
|
125
|
-
<GlassCard padding="32px" radius="28px" intensity={6} shimmer>
|
|
126
|
-
<h2>Hello, Liquid Glass</h2>
|
|
127
|
-
<p>Build tactile glass interfaces with React.</p>
|
|
128
|
-
|
|
129
|
-
<GlassButton size="lg" onClick={() => alert('Clicked!')}>
|
|
130
|
-
Get Started
|
|
131
|
-
</GlassButton>
|
|
132
|
-
</GlassCard>
|
|
133
|
-
</main>
|
|
134
|
-
</LiquidGlassFilter>
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
---
|
|
140
|
-
|
|
141
|
-
## Shared Visual Props
|
|
142
|
-
|
|
143
|
-
Most visual components use the same glass controls:
|
|
144
|
-
|
|
145
|
-
| Prop | Type | Default | What it does |
|
|
146
|
-
|------|------|---------|--------------|
|
|
147
|
-
| `intensity` | `number` | `5` | Controls refraction and blur strength. Values are clamped from `1` to `10`. |
|
|
148
|
-
| `tint` | `string` | `undefined` | Adds a CSS color overlay such as `rgba(0, 122, 255, 0.14)` or `#ffffff22`. |
|
|
149
|
-
| `shimmer` | `boolean` | `true` | Enables animated shine/reflection effects where supported. |
|
|
150
|
-
| `thickness` | `number` | `1` | Controls bevel/border thickness in pixels where supported. |
|
|
151
|
-
|
|
152
|
-
Use low intensity for subtle UI, mid intensity for standard panels, and high intensity for strong refraction demos.
|
|
153
|
-
|
|
154
|
-
---
|
|
155
|
-
|
|
156
|
-
## GlassButton
|
|
157
|
-
|
|
158
|
-
Use `GlassButton` for primary actions, secondary actions, destructive actions, icon buttons, and pill-shaped CTA buttons. It renders a real `<button>`, so native button props like `type`, `disabled`, `aria-label`, `onClick`, and `form` work.
|
|
159
|
-
|
|
160
|
-
```tsx
|
|
161
|
-
import { GlassButton } from '@zakisheriff/liquid-glass';
|
|
162
|
-
|
|
163
|
-
function Actions() {
|
|
164
|
-
return (
|
|
165
|
-
<div style={{ display: 'flex', gap: 12 }}>
|
|
166
|
-
<GlassButton size="lg" onClick={() => console.log('Save')}>
|
|
167
|
-
Save Changes
|
|
168
|
-
</GlassButton>
|
|
169
|
-
|
|
170
|
-
<GlassButton variant="ghost" shimmer={false}>
|
|
171
|
-
Cancel
|
|
172
|
-
</GlassButton>
|
|
173
|
-
|
|
174
|
-
<GlassButton variant="destructive">
|
|
175
|
-
Delete
|
|
176
|
-
</GlassButton>
|
|
177
|
-
</div>
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
Use the `size` prop for quick sizing, and use `style` when you need a fixed width.
|
|
183
|
-
|
|
184
|
-
```tsx
|
|
185
|
-
<GlassButton
|
|
186
|
-
size="md"
|
|
187
|
-
style={{ width: '100%' }}
|
|
188
|
-
>
|
|
189
|
-
Continue
|
|
190
|
-
</GlassButton>
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
### GlassButton Props
|
|
194
|
-
|
|
195
|
-
| Prop | Type | Default | What it does |
|
|
196
|
-
|------|------|---------|--------------|
|
|
197
|
-
| `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | Changes height, font size, and minimum width. |
|
|
198
|
-
| `variant` | `'default' \| 'ghost' \| 'destructive'` | `'default'` | Sets the visual treatment. |
|
|
199
|
-
| `intensity` | `number` | `5` | Controls refraction strength. |
|
|
200
|
-
| `tint` | `string` | `undefined` | Adds a glass tint color. |
|
|
201
|
-
| `shimmer` | `boolean` | `true` | Enables the shine overlay. |
|
|
202
|
-
| `thickness` | `number` | `1` | Controls bevel thickness. |
|
|
203
|
-
| `children` | `React.ReactNode` | `undefined` | Button label or icon content. |
|
|
204
|
-
| Native button props | `ButtonHTMLAttributes<HTMLButtonElement>` | `-` | Supports `onClick`, `disabled`, `type`, `aria-*`, and more. |
|
|
205
|
-
|
|
206
|
-
---
|
|
207
|
-
|
|
208
|
-
## GlassCard
|
|
209
|
-
|
|
210
|
-
Use `GlassCard` as a glass surface for panels, forms, dashboards, settings groups, previews, and modal content. It renders a `<div>` and accepts normal div attributes.
|
|
211
|
-
|
|
212
|
-
```tsx
|
|
213
|
-
import { GlassCard } from '@zakisheriff/liquid-glass';
|
|
214
|
-
|
|
215
|
-
function ProfileCard() {
|
|
216
|
-
return (
|
|
217
|
-
<GlassCard
|
|
218
|
-
intensity={6}
|
|
219
|
-
tint="rgba(255,255,255,0.12)"
|
|
220
|
-
padding="28px"
|
|
221
|
-
radius="32px"
|
|
222
|
-
>
|
|
223
|
-
<h2>Account</h2>
|
|
224
|
-
<p>Manage your profile and preferences.</p>
|
|
225
|
-
</GlassCard>
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
Use `padding` for inner spacing and `radius` for shape. Cards are best placed over a visible background, gradient, image, or soft color field so the blur/refraction is visible.
|
|
231
|
-
|
|
232
|
-
### GlassCard Props
|
|
233
|
-
|
|
234
|
-
| Prop | Type | Default | What it does |
|
|
235
|
-
|------|------|---------|--------------|
|
|
236
|
-
| `intensity` | `number` | `5` | Controls refraction strength. |
|
|
237
|
-
| `tint` | `string` | `undefined` | Adds a glass tint color. |
|
|
238
|
-
| `shimmer` | `boolean` | `true` | Enables animated border shine. |
|
|
239
|
-
| `thickness` | `number` | `1` | Controls bevel thickness. |
|
|
240
|
-
| `padding` | `string` | `'24px'` | Sets inner content padding. |
|
|
241
|
-
| `radius` | `string` | `'20px'` | Sets border radius, for example `'24px'` or `'36px'`. |
|
|
242
|
-
| `children` | `React.ReactNode` | `undefined` | Card content. |
|
|
243
|
-
| Native div props | `HTMLAttributes<HTMLDivElement>` | `-` | Supports `className`, `style`, `id`, `role`, and more. |
|
|
244
|
-
|
|
245
|
-
---
|
|
246
|
-
|
|
247
|
-
## GlassInput
|
|
248
|
-
|
|
249
|
-
Use `GlassInput` for controlled text fields with a floating label and glass focus state.
|
|
250
|
-
|
|
251
|
-
```tsx
|
|
252
|
-
import { useState } from 'react';
|
|
253
|
-
import { GlassInput } from '@zakisheriff/liquid-glass';
|
|
254
|
-
|
|
255
|
-
function LoginForm() {
|
|
256
|
-
const [email, setEmail] = useState('');
|
|
257
|
-
|
|
258
|
-
return (
|
|
259
|
-
<GlassInput
|
|
260
|
-
label="Email"
|
|
261
|
-
placeholder="you@example.com"
|
|
262
|
-
value={email}
|
|
263
|
-
onChange={(event) => setEmail(event.target.value)}
|
|
264
|
-
autoComplete="email"
|
|
265
|
-
intensity={5}
|
|
266
|
-
/>
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
The input is controlled through `value` and `onChange`. The `label` floats when the field is focused or has a value.
|
|
272
|
-
|
|
273
|
-
### GlassInput Props
|
|
274
|
-
|
|
275
|
-
| Prop | Type | Default | What it does |
|
|
276
|
-
|------|------|---------|--------------|
|
|
277
|
-
| `label` | `string` | `undefined` | Floating label displayed inside the glass field. |
|
|
278
|
-
| `placeholder` | `string` | `undefined` | Native input placeholder. |
|
|
279
|
-
| `value` | `string` | `undefined` | Controlled input value. |
|
|
280
|
-
| `onChange` | `(event: React.ChangeEvent<HTMLInputElement>) => void` | `undefined` | Change handler for controlled state. |
|
|
281
|
-
| `intensity` | `number` | `5` | Controls refraction strength. |
|
|
282
|
-
| `tint` | `string` | `undefined` | Adds a glass tint color. |
|
|
283
|
-
| Native input props | `InputHTMLAttributes<HTMLInputElement>` | `-` | Supports `type`, `name`, `required`, `autoComplete`, `disabled`, and more. |
|
|
284
|
-
|
|
285
|
-
---
|
|
286
|
-
|
|
287
|
-
## GlassSlider
|
|
288
|
-
|
|
289
|
-
Use `GlassSlider` for range controls. It renders a native range input overlay for accessibility, while the visual layer uses liquid glass.
|
|
290
|
-
|
|
291
|
-
There are two modes:
|
|
292
|
-
|
|
293
|
-
- `showThumb={false}` creates an iOS Control Center style block slider
|
|
294
|
-
- `showThumb={true}` creates a classic track slider with a circular knob
|
|
295
|
-
|
|
296
|
-
### Control Center Block Slider
|
|
297
|
-
|
|
298
|
-
```tsx
|
|
299
|
-
import { useState } from 'react';
|
|
300
|
-
import { GlassSlider } from '@zakisheriff/liquid-glass';
|
|
301
|
-
|
|
302
|
-
function VolumeControl() {
|
|
303
|
-
const [volume, setVolume] = useState(46);
|
|
304
|
-
|
|
305
|
-
return (
|
|
306
|
-
<GlassSlider
|
|
307
|
-
min={0}
|
|
308
|
-
max={100}
|
|
309
|
-
value={volume}
|
|
310
|
-
onChange={setVolume}
|
|
311
|
-
showThumb={false}
|
|
312
|
-
label="Volume"
|
|
313
|
-
icon={<span aria-hidden>🔊</span>}
|
|
314
|
-
intensity={6}
|
|
315
|
-
/>
|
|
316
|
-
);
|
|
32
|
+
export function Settings() {
|
|
33
|
+
const [on, setOn] = useState(true);
|
|
34
|
+
return <GlassSwitch checked={on} onChange={setOn} aria-label="Wi-Fi" />;
|
|
317
35
|
}
|
|
318
36
|
```
|
|
319
37
|
|
|
320
|
-
|
|
38
|
+
Works with Next.js (the bundle is marked `"use client"`), Vite and CRA.
|
|
321
39
|
|
|
322
|
-
|
|
323
|
-
function HueControl() {
|
|
324
|
-
const [hue, setHue] = useState(180);
|
|
325
|
-
|
|
326
|
-
return (
|
|
327
|
-
<GlassSlider
|
|
328
|
-
min={0}
|
|
329
|
-
max={360}
|
|
330
|
-
value={hue}
|
|
331
|
-
onChange={setHue}
|
|
332
|
-
showThumb
|
|
333
|
-
label="Hue"
|
|
334
|
-
/>
|
|
335
|
-
);
|
|
336
|
-
}
|
|
337
|
-
```
|
|
40
|
+
## Components
|
|
338
41
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
|
342
|
-
|
|
343
|
-
| `
|
|
344
|
-
| `
|
|
345
|
-
| `
|
|
346
|
-
| `
|
|
347
|
-
| `
|
|
348
|
-
| `
|
|
349
|
-
| `label` | `string` | `undefined` | Optional label shown inside the track. |
|
|
350
|
-
| `intensity` | `number` | `5` | Controls refraction strength. |
|
|
351
|
-
| `tint` | `string` | `undefined` | Adds a glass tint color. |
|
|
352
|
-
| `shimmer` | `boolean` | `true` | Enables shine on the active fill. |
|
|
353
|
-
| `thickness` | `number` | `1` | Controls bevel thickness. |
|
|
354
|
-
| Native range props | `InputHTMLAttributes<HTMLInputElement>` | `-` | Supports `step`, `disabled`, `aria-label`, and more. |
|
|
355
|
-
|
|
356
|
-
---
|
|
357
|
-
|
|
358
|
-
## GlassNav
|
|
359
|
-
|
|
360
|
-
Use `GlassNav` for segmented controls, tab bars, and compact navigation. It manages only visuals and click events; you own the active state.
|
|
361
|
-
|
|
362
|
-
```tsx
|
|
363
|
-
import { useState } from 'react';
|
|
364
|
-
import { GlassNav } from '@zakisheriff/liquid-glass';
|
|
365
|
-
|
|
366
|
-
const tabs = [
|
|
367
|
-
{ label: 'Overview' },
|
|
368
|
-
{ label: 'Buttons' },
|
|
369
|
-
{ label: 'Inputs' },
|
|
370
|
-
];
|
|
371
|
-
|
|
372
|
-
function Tabs() {
|
|
373
|
-
const [activeTab, setActiveTab] = useState(0);
|
|
374
|
-
|
|
375
|
-
return (
|
|
376
|
-
<GlassNav
|
|
377
|
-
items={tabs}
|
|
378
|
-
activeIndex={activeTab}
|
|
379
|
-
onChange={setActiveTab}
|
|
380
|
-
intensity={5}
|
|
381
|
-
/>
|
|
382
|
-
);
|
|
383
|
-
}
|
|
384
|
-
```
|
|
385
|
-
|
|
386
|
-
Each item can include an icon.
|
|
42
|
+
| Component | What it does |
|
|
43
|
+
| --- | --- |
|
|
44
|
+
| `GlassButton` | Pill or circle (`icon` with no children). Swells, leans toward a drag, wobbles on release. Variants `default`, `clear`, `filled`, `destructive`. |
|
|
45
|
+
| `GlassSwitch` | The knob lifts into a clear lens that refracts the track. Tap, or drag with rubber-banding. |
|
|
46
|
+
| `GlassNav` | Floating tab bar. The selection inflates into a lens you can drag across tabs. |
|
|
47
|
+
| `GlassSegmented` | Segmented control. The whole control swells and the selection becomes a draggable lens. |
|
|
48
|
+
| `GlassSlider` | Thin track with a lens thumb, or `showThumb={false}` for a Control Center block that stretches past its ends. |
|
|
49
|
+
| `GlassInput` | Search / text field with icon, trailing accessory and clear button. |
|
|
50
|
+
| `GlassCard` | Refracting panel, `regular` or `clear`. |
|
|
51
|
+
| `GlassSheet` | Floating bottom sheet. Spring entrance, drag or flick to dismiss. |
|
|
387
52
|
|
|
388
53
|
```tsx
|
|
389
54
|
<GlassNav
|
|
55
|
+
activeIndex={tab}
|
|
56
|
+
onChange={setTab}
|
|
390
57
|
items={[
|
|
391
58
|
{ label: 'Home', icon: <HomeIcon /> },
|
|
392
|
-
{ label: '
|
|
59
|
+
{ label: 'Library', icon: <LibraryIcon /> },
|
|
393
60
|
]}
|
|
394
|
-
activeIndex={activeIndex}
|
|
395
|
-
onChange={setActiveIndex}
|
|
396
61
|
/>
|
|
397
|
-
```
|
|
398
|
-
|
|
399
|
-
### GlassNav Props
|
|
400
|
-
|
|
401
|
-
| Prop | Type | Default | What it does |
|
|
402
|
-
|------|------|---------|--------------|
|
|
403
|
-
| `items` | `{ label: string; icon?: React.ReactNode }[]` | Required | Items rendered as tabs. |
|
|
404
|
-
| `activeIndex` | `number` | `0` | Zero-based active item index. |
|
|
405
|
-
| `onChange` | `(index: number) => void` | `undefined` | Called when a nav item is clicked. |
|
|
406
|
-
| `intensity` | `number` | `5` | Controls refraction strength. |
|
|
407
|
-
|
|
408
|
-
---
|
|
409
|
-
|
|
410
|
-
## GlassSheet
|
|
411
|
-
|
|
412
|
-
Use `GlassSheet` for bottom sheets, action drawers, mobile menus, and lightweight modal panels. You control it with an `open` boolean.
|
|
413
|
-
|
|
414
|
-
```tsx
|
|
415
|
-
import { useState } from 'react';
|
|
416
|
-
import { GlassButton, GlassSheet } from '@zakisheriff/liquid-glass';
|
|
417
|
-
|
|
418
|
-
function SettingsSheet() {
|
|
419
|
-
const [open, setOpen] = useState(false);
|
|
420
|
-
|
|
421
|
-
return (
|
|
422
|
-
<>
|
|
423
|
-
<GlassButton onClick={() => setOpen(true)}>
|
|
424
|
-
Open Settings
|
|
425
|
-
</GlassButton>
|
|
426
|
-
|
|
427
|
-
<GlassSheet open={open} onClose={() => setOpen(false)} intensity={6}>
|
|
428
|
-
<h2>Settings</h2>
|
|
429
|
-
<p>Sheet content goes here.</p>
|
|
430
|
-
|
|
431
|
-
<GlassButton onClick={() => setOpen(false)}>
|
|
432
|
-
Done
|
|
433
|
-
</GlassButton>
|
|
434
|
-
</GlassSheet>
|
|
435
|
-
</>
|
|
436
|
-
);
|
|
437
|
-
}
|
|
438
|
-
```
|
|
439
|
-
|
|
440
|
-
The sheet closes when the backdrop is clicked or when Escape is pressed. It also locks body scrolling while mounted.
|
|
441
|
-
|
|
442
|
-
### GlassSheet Props
|
|
443
|
-
|
|
444
|
-
| Prop | Type | Default | What it does |
|
|
445
|
-
|------|------|---------|--------------|
|
|
446
|
-
| `open` | `boolean` | Required | Controls whether the sheet is visible. |
|
|
447
|
-
| `onClose` | `() => void` | `undefined` | Called by backdrop click or Escape key. |
|
|
448
|
-
| `intensity` | `number` | `5` | Controls refraction strength. |
|
|
449
|
-
| `tint` | `string` | `undefined` | Adds a glass tint color. |
|
|
450
|
-
| `children` | `React.ReactNode` | `undefined` | Sheet content. |
|
|
451
|
-
|
|
452
|
-
---
|
|
453
|
-
|
|
454
|
-
## LiquidGlassFilter
|
|
455
62
|
|
|
456
|
-
|
|
63
|
+
<GlassSegmented options={['Chat', 'Work']} value={mode} onChange={setMode} />
|
|
457
64
|
|
|
458
|
-
|
|
459
|
-
|
|
65
|
+
<GlassSlider value={volume} onChange={setVolume} />
|
|
66
|
+
<GlassSlider showThumb={false} value={brightness} onChange={setBrightness} icon={<SunIcon />} label="Display" />
|
|
460
67
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
<LiquidGlassFilter>
|
|
464
|
-
<App />
|
|
465
|
-
</LiquidGlassFilter>
|
|
466
|
-
);
|
|
467
|
-
}
|
|
68
|
+
<GlassButton icon={<PlusIcon />} aria-label="Add" />
|
|
69
|
+
<GlassButton variant="filled">Continue</GlassButton>
|
|
468
70
|
```
|
|
469
71
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
---
|
|
72
|
+
Most components accept `intensity` (1–10 refraction strength) and `tint`.
|
|
473
73
|
|
|
474
|
-
##
|
|
74
|
+
## Light and dark
|
|
475
75
|
|
|
476
|
-
|
|
76
|
+
Tokens follow `prefers-color-scheme`. To force a theme, set `data-theme="light"` or `data-theme="dark"` on any ancestor. Override any `--lg-*` variable to restyle, e.g. `--lg-accent`, `--lg-fill` or `--lg-blur`.
|
|
477
77
|
|
|
478
|
-
|
|
78
|
+
## Build your own glass
|
|
479
79
|
|
|
480
80
|
```tsx
|
|
481
|
-
import {
|
|
482
|
-
|
|
483
|
-
function CustomGlassPanel() {
|
|
484
|
-
const { style, filterId } = useGlassEffect({
|
|
485
|
-
intensity: 7,
|
|
486
|
-
tint: 'rgba(0, 122, 255, 0.14)',
|
|
487
|
-
shimmer: true,
|
|
488
|
-
thickness: 2,
|
|
489
|
-
blur: 18,
|
|
490
|
-
});
|
|
491
|
-
|
|
492
|
-
return (
|
|
493
|
-
<div data-liquid-glass style={style}>
|
|
494
|
-
Custom glass panel using {filterId}
|
|
495
|
-
</div>
|
|
496
|
-
);
|
|
497
|
-
}
|
|
498
|
-
```
|
|
499
|
-
|
|
500
|
-
### useGlassAnimation
|
|
501
|
-
|
|
502
|
-
Use `useGlassAnimation` when creating custom interactive glass elements. It gives you hover, press, and focus state plus pointer/focus handlers.
|
|
503
|
-
|
|
504
|
-
```tsx
|
|
505
|
-
import { useGlassAnimation } from '@zakisheriff/liquid-glass';
|
|
506
|
-
|
|
507
|
-
function CustomGlassButton() {
|
|
508
|
-
const { isHovered, isPressed, isFocused, handlers } = useGlassAnimation();
|
|
81
|
+
import { useRefraction, usePress } from '@zakisheriff/liquid-glass';
|
|
509
82
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
opacity: isHovered || isFocused ? 1 : 0.86,
|
|
516
|
-
}}
|
|
517
|
-
>
|
|
518
|
-
Custom
|
|
519
|
-
</button>
|
|
520
|
-
);
|
|
83
|
+
function Droplet() {
|
|
84
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
85
|
+
useRefraction(ref, { kind: 'lens', zoom: 1.3, dispersion: 1 });
|
|
86
|
+
usePress(ref);
|
|
87
|
+
return <div ref={ref} className="lg-glass" style={{ width: 240, height: 160, borderRadius: 999 }} />;
|
|
521
88
|
}
|
|
522
89
|
```
|
|
523
90
|
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
## Styling Tips
|
|
527
|
-
|
|
528
|
-
- Put glass components over a visible background, image, gradient, or soft color surface so blur/refraction has something to bend.
|
|
529
|
-
- Use `intensity={3}` to `intensity={6}` for production UI and `intensity={7}` to `intensity={10}` for dramatic demos.
|
|
530
|
-
- Use subtle tint values such as `rgba(0, 122, 255, 0.12)` instead of fully opaque colors.
|
|
531
|
-
- Keep `LiquidGlassFilter` mounted once around repeated glass components for cleaner DOM output.
|
|
532
|
-
- Import `@zakisheriff/liquid-glass/styles.css` only once.
|
|
533
|
-
|
|
534
|
-
---
|
|
535
|
-
|
|
536
|
-
## Browser Support
|
|
537
|
-
|
|
538
|
-
- Chrome 89+
|
|
539
|
-
- Edge 89+
|
|
540
|
-
- Safari 15.4+
|
|
541
|
-
- Firefox 103+
|
|
91
|
+
`createSpring`, `SPRINGS` and `haptic()` are exported too.
|
|
542
92
|
|
|
543
|
-
|
|
93
|
+
## Browser support
|
|
544
94
|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
```text
|
|
550
|
-
liquid-glass/
|
|
551
|
-
├── src/
|
|
552
|
-
│ ├── index.ts
|
|
553
|
-
│ ├── components/
|
|
554
|
-
│ │ ├── GlassButton/
|
|
555
|
-
│ │ ├── GlassCard/
|
|
556
|
-
│ │ ├── GlassInput/
|
|
557
|
-
│ │ ├── GlassNav/
|
|
558
|
-
│ │ ├── GlassSheet/
|
|
559
|
-
│ │ └── GlassSlider/
|
|
560
|
-
│ ├── filters/
|
|
561
|
-
│ │ └── LiquidGlassFilter.tsx
|
|
562
|
-
│ ├── hooks/
|
|
563
|
-
│ │ ├── useGlassAnimation.ts
|
|
564
|
-
│ │ └── useGlassEffect.ts
|
|
565
|
-
│ └── styles/
|
|
566
|
-
│ └── base.css
|
|
567
|
-
├── demo/
|
|
568
|
-
├── package.json
|
|
569
|
-
├── tsconfig.json
|
|
570
|
-
└── tsup.config.ts
|
|
571
|
-
```
|
|
572
|
-
|
|
573
|
-
---
|
|
95
|
+
- **Chrome / Edge / Arc:** full live refraction of the backdrop through `backdrop-filter: url(#svg)`.
|
|
96
|
+
- **Safari / Firefox:** the same shapes, motion, specular rims and frosting, without live backdrop displacement.
|
|
97
|
+
- Respects `prefers-reduced-motion` and `prefers-reduced-transparency`.
|
|
574
98
|
|
|
575
|
-
##
|
|
99
|
+
## Develop
|
|
576
100
|
|
|
577
101
|
```bash
|
|
578
|
-
git clone https://github.com/zakisheriff/Liquid-Glass.git
|
|
579
|
-
cd Liquid-Glass
|
|
580
102
|
npm install
|
|
103
|
+
npm run site # Next.js landing page at localhost:3000, renders straight from src/
|
|
104
|
+
npm run build # library → dist/
|
|
581
105
|
```
|
|
582
106
|
|
|
583
|
-
Run the library build:
|
|
584
|
-
|
|
585
|
-
```bash
|
|
586
|
-
npm run build
|
|
587
|
-
```
|
|
588
|
-
|
|
589
|
-
Watch the library build:
|
|
590
|
-
|
|
591
|
-
```bash
|
|
592
|
-
npm run dev
|
|
593
|
-
```
|
|
594
|
-
|
|
595
|
-
Run the demo:
|
|
596
|
-
|
|
597
|
-
```bash
|
|
598
|
-
npm run demo
|
|
599
|
-
```
|
|
600
|
-
|
|
601
|
-
---
|
|
602
|
-
|
|
603
107
|
## License
|
|
604
108
|
|
|
605
|
-
MIT
|
|
606
|
-
|
|
607
|
-
---
|
|
608
|
-
|
|
609
|
-
## Support the Project
|
|
610
|
-
|
|
611
|
-
If Liquid Glass helped you build a better interface, you can support future updates here:
|
|
612
|
-
|
|
613
|
-
<div align="center">
|
|
614
|
-
<a href="https://buymeacoffee.com/theoneatom">
|
|
615
|
-
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" height="60" width="217" alt="Buy Me A Coffee">
|
|
616
|
-
</a>
|
|
617
|
-
</div>
|
|
618
|
-
|
|
619
|
-
---
|
|
620
|
-
|
|
621
|
-
<p align="center">
|
|
622
|
-
Made by <strong>Zaki Sheriff</strong>
|
|
623
|
-
</p>
|
|
624
|
-
|
|
625
|
-
<p align="center">
|
|
626
|
-
<em>Because interfaces should feel as good as they look.</em>
|
|
627
|
-
</p>
|
|
109
|
+
MIT © Zaki Sheriff. Not affiliated with Apple Inc.
|