@sofyan/glass 0.1.6 → 0.3.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 +225 -12
- package/dist/dark.css +5 -2
- package/dist/dark.unlayered.css +102 -0
- package/dist/glass.css +397 -7
- package/dist/glass.unlayered.css +1117 -0
- package/dist/react/index.d.ts +184 -5
- package/dist/react/index.js +635 -60
- package/dist/react/index.js.map +1 -1
- package/package.json +12 -11
package/dist/react/index.d.ts
CHANGED
|
@@ -38,6 +38,85 @@ interface GlassButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
|
38
38
|
/** A glass button with a 44px touch target. Defaults to `type="button"`. */
|
|
39
39
|
declare const GlassButton: react.ForwardRefExoticComponent<GlassButtonProps & react.RefAttributes<HTMLButtonElement>>;
|
|
40
40
|
|
|
41
|
+
type GlassConfirmTone = 'neutral' | 'danger';
|
|
42
|
+
interface GlassConfirmProps {
|
|
43
|
+
open: boolean;
|
|
44
|
+
/** The confirm button. */
|
|
45
|
+
onConfirm: () => void;
|
|
46
|
+
/** The cancel button, Esc, or any other way the dialog is closed without confirming. */
|
|
47
|
+
onCancel: () => void;
|
|
48
|
+
/** The question. Names the dialog (aria-labelledby). */
|
|
49
|
+
title: ReactNode;
|
|
50
|
+
/** What happens if they confirm. Describes the dialog (aria-describedby). */
|
|
51
|
+
message?: ReactNode;
|
|
52
|
+
confirmLabel?: string;
|
|
53
|
+
cancelLabel?: string;
|
|
54
|
+
/** `danger` for what is hard to undo: a red confirm button, and focus starts on Cancel. */
|
|
55
|
+
tone?: GlassConfirmTone;
|
|
56
|
+
confirmDisabled?: boolean;
|
|
57
|
+
/** Shown between the message and the buttons: more details, or an input. */
|
|
58
|
+
children?: ReactNode;
|
|
59
|
+
className?: string;
|
|
60
|
+
}
|
|
61
|
+
/** What `confirm()` of `useGlassConfirm` takes: the dialog's text and tone, and `details`. */
|
|
62
|
+
interface GlassConfirmOptions extends Pick<GlassConfirmProps, 'title' | 'message' | 'confirmLabel' | 'cancelLabel' | 'tone'> {
|
|
63
|
+
/** Shown between the message and the buttons, like `children` of <GlassConfirm>. */
|
|
64
|
+
details?: ReactNode;
|
|
65
|
+
}
|
|
66
|
+
interface GlassConfirmHook {
|
|
67
|
+
/** Asks, and resolves with the answer: true for confirm, false for anything else. */
|
|
68
|
+
confirm: (options: GlassConfirmOptions) => Promise<boolean>;
|
|
69
|
+
/** Render it once, anywhere in the component. */
|
|
70
|
+
dialog: ReactNode;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* A confirmation on a native <dialog> (APG alertdialog): the page goes inert, focus stays
|
|
74
|
+
* inside and returns to the opener on close. It must be answered: Esc cancels, a tap on the
|
|
75
|
+
* backdrop does nothing.
|
|
76
|
+
*
|
|
77
|
+
* Focus starts on the confirm button, or on Cancel when `tone` is `danger` (or confirm is
|
|
78
|
+
* disabled), so a stray Enter never does the irreversible thing. An element in `children`
|
|
79
|
+
* with `autoFocus` (or `autofocus`) keeps focus instead.
|
|
80
|
+
*/
|
|
81
|
+
declare function GlassConfirm({ open, onConfirm, onCancel, title, message, confirmLabel, cancelLabel, tone, confirmDisabled, children, className, }: GlassConfirmProps): react.JSX.Element;
|
|
82
|
+
/**
|
|
83
|
+
* `await confirm({ title })` instead of wiring `open` state. Render `dialog` once.
|
|
84
|
+
*
|
|
85
|
+
* Each promise resolves exactly once: true on confirm, false on cancel, when a newer
|
|
86
|
+
* `confirm()` replaces it, or when the component unmounts.
|
|
87
|
+
*/
|
|
88
|
+
declare function useGlassConfirm(): GlassConfirmHook;
|
|
89
|
+
|
|
90
|
+
interface GlassFieldProps {
|
|
91
|
+
/** Names the control (a <label for>). Shown above it unless `hideLabel`. */
|
|
92
|
+
label: ReactNode;
|
|
93
|
+
/** Help under the control, read with it (aria-describedby). */
|
|
94
|
+
hint?: ReactNode;
|
|
95
|
+
/** What is wrong. Marks the control invalid and is read with it (aria-describedby). */
|
|
96
|
+
error?: ReactNode;
|
|
97
|
+
/** Hide the label visually; screen readers still read it. */
|
|
98
|
+
hideLabel?: boolean;
|
|
99
|
+
/** On the wrapper. */
|
|
100
|
+
className?: string;
|
|
101
|
+
/** On the control. */
|
|
102
|
+
inputClassName?: string;
|
|
103
|
+
}
|
|
104
|
+
interface GlassInputProps extends GlassFieldProps, Omit<ComponentPropsWithoutRef<'input'>, 'className'> {
|
|
105
|
+
}
|
|
106
|
+
interface GlassTextareaProps extends GlassFieldProps, Omit<ComponentPropsWithoutRef<'textarea'>, 'className'> {
|
|
107
|
+
}
|
|
108
|
+
interface GlassSelectProps extends GlassFieldProps, Omit<ComponentPropsWithoutRef<'select'>, 'className'> {
|
|
109
|
+
}
|
|
110
|
+
/** A labelled text input with an optional hint and error. Takes every <input> prop. */
|
|
111
|
+
declare const GlassInput: react.ForwardRefExoticComponent<GlassInputProps & react.RefAttributes<HTMLInputElement>>;
|
|
112
|
+
/** A labelled <textarea> with an optional hint and error. Takes every <textarea> prop. */
|
|
113
|
+
declare const GlassTextarea: react.ForwardRefExoticComponent<GlassTextareaProps & react.RefAttributes<HTMLTextAreaElement>>;
|
|
114
|
+
/**
|
|
115
|
+
* A labelled <select> with an optional hint and error. Takes every <select> prop. A
|
|
116
|
+
* drop-down gets a chevron (`glass-select`); a list box (`multiple`, `size` > 1) shows none.
|
|
117
|
+
*/
|
|
118
|
+
declare const GlassSelect: react.ForwardRefExoticComponent<GlassSelectProps & react.RefAttributes<HTMLSelectElement>>;
|
|
119
|
+
|
|
41
120
|
/**
|
|
42
121
|
* True when the browser renders SVG filters inside `backdrop-filter`
|
|
43
122
|
* (currently Chromium only). Safari and Firefox accept the syntax but either
|
|
@@ -80,6 +159,92 @@ interface GlassSheetProps {
|
|
|
80
159
|
*/
|
|
81
160
|
declare function GlassSheet({ open, onClose, title, eyebrow, closeLabel, swipeToClose, footer, children, className, bodyClassName, }: GlassSheetProps): react.JSX.Element;
|
|
82
161
|
|
|
162
|
+
type GlassTabsOrientation = 'horizontal' | 'vertical';
|
|
163
|
+
interface GlassTabsProps {
|
|
164
|
+
/** The selected tab's `value`. */
|
|
165
|
+
value: string;
|
|
166
|
+
onChange: (value: string) => void;
|
|
167
|
+
/** Names the tab list (aria-label). Translate it. */
|
|
168
|
+
label: string;
|
|
169
|
+
/** Default `horizontal`: Left and Right move between tabs. `vertical`: Up and Down. */
|
|
170
|
+
orientation?: GlassTabsOrientation;
|
|
171
|
+
children?: ReactNode;
|
|
172
|
+
}
|
|
173
|
+
interface GlassTabListProps {
|
|
174
|
+
children?: ReactNode;
|
|
175
|
+
className?: string;
|
|
176
|
+
}
|
|
177
|
+
interface GlassTabProps {
|
|
178
|
+
/** Matches the `value` of its <GlassTabPanel>. */
|
|
179
|
+
value: string;
|
|
180
|
+
disabled?: boolean;
|
|
181
|
+
children?: ReactNode;
|
|
182
|
+
className?: string;
|
|
183
|
+
}
|
|
184
|
+
interface GlassTabPanelProps {
|
|
185
|
+
/** Matches the `value` of its <GlassTab>. */
|
|
186
|
+
value: string;
|
|
187
|
+
children?: ReactNode;
|
|
188
|
+
className?: string;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Tabs (APG tabs pattern, automatic activation): the arrow keys move focus along the tabs
|
|
192
|
+
* and select the tab they land on, wrapping at the ends and skipping disabled tabs. Home and
|
|
193
|
+
* End go to the first and last. Only the selected tab is in the Tab order.
|
|
194
|
+
*
|
|
195
|
+
* Holds the state for <GlassTabList>, <GlassTab> and <GlassTabPanel>, and renders only its
|
|
196
|
+
* children, so the layout around them is yours.
|
|
197
|
+
*/
|
|
198
|
+
declare function GlassTabs({ value, onChange, label, orientation, children, }: GlassTabsProps): react.JSX.Element;
|
|
199
|
+
/**
|
|
200
|
+
* The row (or column) of tabs: a glass track that scrolls sideways when the tabs do not fit.
|
|
201
|
+
* Marked `data-glass-no-drag`, so in a sheet a sideways swipe along it never pulls the sheet.
|
|
202
|
+
*/
|
|
203
|
+
declare function GlassTabList({ children, className }: GlassTabListProps): react.JSX.Element;
|
|
204
|
+
/** One tab. Selected when its `value` is the value of <GlassTabs>. */
|
|
205
|
+
declare function GlassTab({ value, disabled, children, className }: GlassTabProps): react.JSX.Element;
|
|
206
|
+
/**
|
|
207
|
+
* The content of one tab. Hidden (not unmounted) while its tab is not selected, so its state
|
|
208
|
+
* and scroll position survive a switch. Focusable, so keyboard users can reach content that
|
|
209
|
+
* has nothing focusable in it.
|
|
210
|
+
*/
|
|
211
|
+
declare function GlassTabPanel({ value, children, className }: GlassTabPanelProps): react.JSX.Element;
|
|
212
|
+
|
|
213
|
+
type GlassToastTone = 'neutral' | 'danger';
|
|
214
|
+
interface GlassToastOptions {
|
|
215
|
+
/** `danger` is announced at once (role="alert") and stays until dismissed. */
|
|
216
|
+
tone?: GlassToastTone;
|
|
217
|
+
/**
|
|
218
|
+
* How long a neutral toast stays (ms). Default 5000. `Infinity` or 0 keeps it until it is
|
|
219
|
+
* dismissed. Ignored for `danger`, which always stays.
|
|
220
|
+
*/
|
|
221
|
+
duration?: number;
|
|
222
|
+
}
|
|
223
|
+
interface GlassToastsProps {
|
|
224
|
+
/** Accessible name of the dismiss button. Translate it. */
|
|
225
|
+
dismissLabel?: string;
|
|
226
|
+
/** Where the stack sits. Default `top`. */
|
|
227
|
+
position?: 'top' | 'bottom';
|
|
228
|
+
className?: string;
|
|
229
|
+
}
|
|
230
|
+
/** Shows a toast in the mounted <GlassToasts />. Returns its id, for `dismissToast(id)`. */
|
|
231
|
+
declare function toast(message: ReactNode, options?: GlassToastOptions): number;
|
|
232
|
+
/** Removes the toast with this id, or every toast when called without one. */
|
|
233
|
+
declare function dismissToast(id?: number): void;
|
|
234
|
+
/**
|
|
235
|
+
* Where `toast()` shows up. Mount it once, near the root of the app.
|
|
236
|
+
*
|
|
237
|
+
* Two live regions are always in the page, so assistive tech is already listening when a
|
|
238
|
+
* toast arrives: neutral toasts go in `role="status"` (read when the person is idle), danger
|
|
239
|
+
* toasts in `role="alert"` (read at once). `aria-atomic="false"` overrides the roles' default,
|
|
240
|
+
* so a new toast is read on its own rather than with the ones already showing.
|
|
241
|
+
*
|
|
242
|
+
* Toasts never take focus. Neutral ones leave after `duration`, pausing while hovered or
|
|
243
|
+
* focused; danger ones stay until dismissed. Rendered into <body> after mount, so the server
|
|
244
|
+
* render and hydration match.
|
|
245
|
+
*/
|
|
246
|
+
declare function GlassToasts({ dismissLabel, position, className, }: GlassToastsProps): react.ReactPortal | null;
|
|
247
|
+
|
|
83
248
|
interface ReleaseState {
|
|
84
249
|
/** How far the sheet is pulled down (px). */
|
|
85
250
|
offset: number;
|
|
@@ -93,7 +258,13 @@ declare function shouldClose({ offset, height, velocity }: ReleaseState): boolea
|
|
|
93
258
|
interface SwipeToCloseOptions {
|
|
94
259
|
/** Turn the gesture on or off (e.g. only while open, only in the bottom-sheet layout). */
|
|
95
260
|
enabled: boolean;
|
|
96
|
-
/**
|
|
261
|
+
/**
|
|
262
|
+
* Optional. The scrolling areas under the finger are found by themselves: every element
|
|
263
|
+
* from the press up to the sheet (itself included) with `overflow-y` auto, scroll or
|
|
264
|
+
* overlay and more content than fits. A press inside one drags only while all of them are
|
|
265
|
+
* scrolled to the top. Pass a scroller here only when that test misses it, e.g. one with
|
|
266
|
+
* `overflow-y: hidden` that a script scrolls; it then counts whenever it holds the press.
|
|
267
|
+
*/
|
|
97
268
|
scrollRef?: RefObject<HTMLElement | null>;
|
|
98
269
|
/**
|
|
99
270
|
* Called once the sheet has slid away. The sheet stays off-screen until `enabled` turns
|
|
@@ -113,10 +284,18 @@ interface SwipeToCloseOptions {
|
|
|
113
284
|
* follows the finger via an inline transform and either slides away (then `onClose`) or
|
|
114
285
|
* settles back.
|
|
115
286
|
*
|
|
287
|
+
* The scrolling areas need no wiring: at each press the hook walks from the element under
|
|
288
|
+
* the finger up to the sheet and takes every element a person can scroll vertically. If any
|
|
289
|
+
* of them is scrolled down, the gesture is theirs (a pull down scrolls back up) and no drag
|
|
290
|
+
* starts. A sideways scroller does not block a drag (only vertical scrolling counts), and a
|
|
291
|
+
* sideways move lets go of one. Outside every vertical scroller the page is held (below),
|
|
292
|
+
* which stops a sideways scroller there too: mark it `data-glass-no-drag`.
|
|
293
|
+
*
|
|
116
294
|
* iOS Safari decides at the first touchmove of a gesture whether the page pans, and later
|
|
117
295
|
* moves can no longer stop it. So wherever nothing in the sheet would scroll for that touch
|
|
118
|
-
* (the header, grabber and backdrop
|
|
119
|
-
* nothing to scroll), touchmoves are cancelled from the
|
|
296
|
+
* (outside every scroller, such as the header, grabber and backdrop; a downward pull at the
|
|
297
|
+
* top of a scroller; a scroller with nothing to scroll), touchmoves are cancelled from the
|
|
298
|
+
* first one; taps still click.
|
|
120
299
|
*
|
|
121
300
|
* After a slide-away the inline transform is kept until the effect is torn down (the owner
|
|
122
301
|
* closed the sheet and `enabled` turned false). Clearing it earlier would show the sheet at
|
|
@@ -128,5 +307,5 @@ interface SwipeToCloseOptions {
|
|
|
128
307
|
*/
|
|
129
308
|
declare function useSwipeToClose(sheetRef: RefObject<HTMLElement | null>, { enabled, scrollRef, onClose, media }: SwipeToCloseOptions): void;
|
|
130
309
|
|
|
131
|
-
export { Glass, GlassButton, GlassFilter, GlassSheet, glassClasses, shouldClose, supportsBackdropRefraction, useSwipeToClose };
|
|
132
|
-
export type { GlassButtonProps, GlassButtonSize, GlassButtonVariant, GlassOptions, GlassProps, GlassShape, GlassSheetProps, GlassThickness, GlassTone, ReleaseState, SwipeToCloseOptions };
|
|
310
|
+
export { Glass, GlassButton, GlassConfirm, GlassFilter, GlassInput, GlassSelect, GlassSheet, GlassTab, GlassTabList, GlassTabPanel, GlassTabs, GlassTextarea, GlassToasts, dismissToast, glassClasses, shouldClose, supportsBackdropRefraction, toast, useGlassConfirm, useSwipeToClose };
|
|
311
|
+
export type { GlassButtonProps, GlassButtonSize, GlassButtonVariant, GlassConfirmHook, GlassConfirmOptions, GlassConfirmProps, GlassConfirmTone, GlassFieldProps, GlassInputProps, GlassOptions, GlassProps, GlassSelectProps, GlassShape, GlassSheetProps, GlassTabListProps, GlassTabPanelProps, GlassTabProps, GlassTabsOrientation, GlassTabsProps, GlassTextareaProps, GlassThickness, GlassToastOptions, GlassToastTone, GlassToastsProps, GlassTone, ReleaseState, SwipeToCloseOptions };
|