@glassly/miniapp 0.4.3-dev.1242 → 0.4.3-dev.1259
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 +32 -2
- package/dist/theme.css +856 -0
- package/dist/ui/index.d.ts +1 -0
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +1 -0
- package/dist/ui/index.js.map +1 -1
- package/dist/ui/kit/Badge.d.ts +8 -0
- package/dist/ui/kit/Badge.d.ts.map +1 -0
- package/dist/ui/kit/Badge.js +6 -0
- package/dist/ui/kit/Badge.js.map +1 -0
- package/dist/ui/kit/Button.d.ts +9 -0
- package/dist/ui/kit/Button.d.ts.map +1 -0
- package/dist/ui/kit/Button.js +7 -0
- package/dist/ui/kit/Button.js.map +1 -0
- package/dist/ui/kit/Card.d.ts +10 -0
- package/dist/ui/kit/Card.d.ts.map +1 -0
- package/dist/ui/kit/Card.js +21 -0
- package/dist/ui/kit/Card.js.map +1 -0
- package/dist/ui/kit/Dock.d.ts +29 -0
- package/dist/ui/kit/Dock.d.ts.map +1 -0
- package/dist/ui/kit/Dock.js +34 -0
- package/dist/ui/kit/Dock.js.map +1 -0
- package/dist/ui/kit/Feedback.d.ts +37 -0
- package/dist/ui/kit/Feedback.d.ts.map +1 -0
- package/dist/ui/kit/Feedback.js +21 -0
- package/dist/ui/kit/Feedback.js.map +1 -0
- package/dist/ui/kit/Field.d.ts +8 -0
- package/dist/ui/kit/Field.d.ts.map +1 -0
- package/dist/ui/kit/Field.js +16 -0
- package/dist/ui/kit/Field.js.map +1 -0
- package/dist/ui/kit/Page.d.ts +33 -0
- package/dist/ui/kit/Page.d.ts.map +1 -0
- package/dist/ui/kit/Page.js +77 -0
- package/dist/ui/kit/Page.js.map +1 -0
- package/dist/ui/kit/Section.d.ts +17 -0
- package/dist/ui/kit/Section.d.ts.map +1 -0
- package/dist/ui/kit/Section.js +22 -0
- package/dist/ui/kit/Section.js.map +1 -0
- package/dist/ui/kit/SetupGuide.d.ts +45 -0
- package/dist/ui/kit/SetupGuide.d.ts.map +1 -0
- package/dist/ui/kit/SetupGuide.js +40 -0
- package/dist/ui/kit/SetupGuide.js.map +1 -0
- package/dist/ui/kit/Switch.d.ts +7 -0
- package/dist/ui/kit/Switch.d.ts.map +1 -0
- package/dist/ui/kit/Switch.js +11 -0
- package/dist/ui/kit/Switch.js.map +1 -0
- package/dist/ui/kit/Tabs.d.ts +20 -0
- package/dist/ui/kit/Tabs.d.ts.map +1 -0
- package/dist/ui/kit/Tabs.js +53 -0
- package/dist/ui/kit/Tabs.js.map +1 -0
- package/dist/ui/kit/cx.d.ts +2 -0
- package/dist/ui/kit/cx.d.ts.map +1 -0
- package/dist/ui/kit/cx.js +4 -0
- package/dist/ui/kit/cx.js.map +1 -0
- package/dist/ui/kit/hooks.d.ts +17 -0
- package/dist/ui/kit/hooks.d.ts.map +1 -0
- package/dist/ui/kit/hooks.js +34 -0
- package/dist/ui/kit/hooks.js.map +1 -0
- package/dist/ui/kit/index.d.ts +14 -0
- package/dist/ui/kit/index.d.ts.map +1 -0
- package/dist/ui/kit/index.js +14 -0
- package/dist/ui/kit/index.js.map +1 -0
- package/dist/ui/kit/useWide.d.ts +4 -0
- package/dist/ui/kit/useWide.d.ts.map +1 -0
- package/dist/ui/kit/useWide.js +18 -0
- package/dist/ui/kit/useWide.js.map +1 -0
- package/package.json +12 -5
- package/src/ui/index.ts +2 -0
- package/src/ui/kit/Badge.tsx +19 -0
- package/src/ui/kit/Button.tsx +27 -0
- package/src/ui/kit/Card.tsx +29 -0
- package/src/ui/kit/Dock.tsx +77 -0
- package/src/ui/kit/Feedback.tsx +101 -0
- package/src/ui/kit/Field.tsx +38 -0
- package/src/ui/kit/Page.tsx +154 -0
- package/src/ui/kit/Section.tsx +80 -0
- package/src/ui/kit/SetupGuide.tsx +153 -0
- package/src/ui/kit/Switch.tsx +28 -0
- package/src/ui/kit/Tabs.tsx +108 -0
- package/src/ui/kit/cx.ts +3 -0
- package/src/ui/kit/hooks.ts +53 -0
- package/src/ui/kit/index.ts +51 -0
- package/src/ui/kit/useWide.ts +19 -0
- package/src/ui/theme.css +856 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import {useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type ReactNode} from "react"
|
|
2
|
+
|
|
3
|
+
import {useColorScheme} from "../../react/useColorScheme"
|
|
4
|
+
import {useRailBackButton} from "../../react/useRailBackButton"
|
|
5
|
+
import {useSafeArea} from "../../react/useSafeArea"
|
|
6
|
+
import {Button} from "./Button"
|
|
7
|
+
import {cx} from "./cx"
|
|
8
|
+
import {useWide} from "./useWide"
|
|
9
|
+
|
|
10
|
+
const GUTTER = 16
|
|
11
|
+
const HINGE = 20
|
|
12
|
+
|
|
13
|
+
export interface PageProps {
|
|
14
|
+
header?: ReactNode
|
|
15
|
+
children?: ReactNode
|
|
16
|
+
aside?: ReactNode
|
|
17
|
+
footer?: ReactNode
|
|
18
|
+
fill?: boolean
|
|
19
|
+
maxWidth?: number | "none"
|
|
20
|
+
bottom?: number
|
|
21
|
+
className?: string
|
|
22
|
+
style?: CSSProperties
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The phone page shell: safe-area and Duo rail padding, the host's background
|
|
27
|
+
* colour on the native layer, and a two-column layout in wide windows.
|
|
28
|
+
*/
|
|
29
|
+
export function Page({header, children, aside, footer, fill, maxWidth = 640, bottom, className, style}: PageProps) {
|
|
30
|
+
const {insets} = useSafeArea()
|
|
31
|
+
const scheme = useColorScheme()
|
|
32
|
+
const wide = useWide() && aside != null
|
|
33
|
+
const left = Math.max(GUTTER, insets.left)
|
|
34
|
+
const right = Math.max(GUTTER, insets.right)
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
const bridge = (window as unknown as {glassly?: {setBackgroundColor?: (color: string) => void}}).glassly
|
|
38
|
+
const color = getComputedStyle(document.documentElement).getPropertyValue("--background").trim()
|
|
39
|
+
if (color) bridge?.setBackgroundColor?.(color)
|
|
40
|
+
}, [scheme])
|
|
41
|
+
|
|
42
|
+
const body: CSSProperties = wide
|
|
43
|
+
? {gridTemplateColumns: `calc(50vw - ${HINGE + left}px) ${2 * HINGE}px minmax(0, 1fr)`}
|
|
44
|
+
: {maxWidth: maxWidth === "none" ? undefined : maxWidth}
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<div
|
|
48
|
+
className={cx("gl-page", className)}
|
|
49
|
+
data-fill={fill ? "" : undefined}
|
|
50
|
+
style={{
|
|
51
|
+
paddingTop: insets.top + (header ? 0 : GUTTER),
|
|
52
|
+
paddingLeft: left,
|
|
53
|
+
paddingRight: right,
|
|
54
|
+
paddingBottom: bottom ?? insets.bottom + GUTTER,
|
|
55
|
+
...style,
|
|
56
|
+
}}>
|
|
57
|
+
{insets.top > 0 ? <div className="gl-page-statusbar" aria-hidden="true" style={{height: insets.top}} /> : null}
|
|
58
|
+
<div className="gl-page-body" data-wide={wide ? "" : undefined} style={body}>
|
|
59
|
+
{header ? <div style={wide ? {gridColumn: 1, gridRow: 1} : undefined}>{header}</div> : null}
|
|
60
|
+
<main className="gl-page-main" style={wide ? {gridColumn: 1, gridRow: 2, height: "100%"} : undefined}>
|
|
61
|
+
{children}
|
|
62
|
+
</main>
|
|
63
|
+
{aside != null ? (
|
|
64
|
+
<aside className="gl-page-aside" style={wide ? {gridColumn: 3, gridRow: 2, height: "100%"} : undefined}>
|
|
65
|
+
{aside}
|
|
66
|
+
</aside>
|
|
67
|
+
) : null}
|
|
68
|
+
</div>
|
|
69
|
+
{footer}
|
|
70
|
+
</div>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface PageHeaderProps {
|
|
75
|
+
title: ReactNode
|
|
76
|
+
onBack?: () => void
|
|
77
|
+
children?: ReactNode
|
|
78
|
+
className?: string
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** A header row aligned with the host's menu button, keeping clear of it. */
|
|
82
|
+
export function PageHeader({title, onBack, children, className}: PageHeaderProps) {
|
|
83
|
+
const {insets, capsuleMenu} = useSafeArea()
|
|
84
|
+
const backInRail = useRailBackButton(onBack)
|
|
85
|
+
const ref = useRef<HTMLElement>(null)
|
|
86
|
+
const [reserve, setReserve] = useState(0)
|
|
87
|
+
|
|
88
|
+
useLayoutEffect(() => {
|
|
89
|
+
const el = ref.current
|
|
90
|
+
if (!el || !capsuleMenu) {
|
|
91
|
+
setReserve(0)
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
const update = () => setReserve(Math.max(0, Math.round(layoutRight(el) - capsuleMenu.left + 12)))
|
|
95
|
+
update()
|
|
96
|
+
const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(update)
|
|
97
|
+
observer?.observe(el)
|
|
98
|
+
window.addEventListener("resize", update)
|
|
99
|
+
return () => {
|
|
100
|
+
observer?.disconnect()
|
|
101
|
+
window.removeEventListener("resize", update)
|
|
102
|
+
}
|
|
103
|
+
}, [capsuleMenu])
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<header
|
|
107
|
+
ref={ref}
|
|
108
|
+
className={cx("gl-header", className)}
|
|
109
|
+
style={{
|
|
110
|
+
minHeight: capsuleMenu?.height ?? 36,
|
|
111
|
+
marginTop: capsuleMenu ? Math.max(0, capsuleMenu.top - insets.top) : 12,
|
|
112
|
+
marginBottom: 4,
|
|
113
|
+
paddingRight: reserve,
|
|
114
|
+
}}>
|
|
115
|
+
{onBack && !backInRail ? (
|
|
116
|
+
<Button variant="ghost" size="icon" aria-label="Back" onClick={onBack} style={{marginLeft: -8}}>
|
|
117
|
+
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
|
|
118
|
+
<path
|
|
119
|
+
d="M15 18l-6-6 6-6"
|
|
120
|
+
stroke="currentColor"
|
|
121
|
+
strokeWidth="2"
|
|
122
|
+
strokeLinecap="round"
|
|
123
|
+
strokeLinejoin="round"
|
|
124
|
+
/>
|
|
125
|
+
</svg>
|
|
126
|
+
</Button>
|
|
127
|
+
) : null}
|
|
128
|
+
{typeof title === "string" ? <h1 className="gl-header-title">{title}</h1> : title}
|
|
129
|
+
{children ? <div className="gl-header-trailing">{children}</div> : null}
|
|
130
|
+
</header>
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function layoutRight(el: HTMLElement): number {
|
|
135
|
+
let left = el.offsetWidth
|
|
136
|
+
for (let node: HTMLElement | null = el; node; node = node.offsetParent as HTMLElement | null) left += node.offsetLeft
|
|
137
|
+
return left
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface FooterProps {
|
|
141
|
+
version?: string
|
|
142
|
+
children?: ReactNode
|
|
143
|
+
className?: string
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** The page's bottom line, where the version label goes (never the top-right). */
|
|
147
|
+
export function Footer({version, children, className}: FooterProps) {
|
|
148
|
+
return (
|
|
149
|
+
<footer className={cx("gl-footer", className)}>
|
|
150
|
+
{version ? `v${version}` : null}
|
|
151
|
+
{children}
|
|
152
|
+
</footer>
|
|
153
|
+
)
|
|
154
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {
|
|
2
|
+
cloneElement,
|
|
3
|
+
Fragment,
|
|
4
|
+
isValidElement,
|
|
5
|
+
useId,
|
|
6
|
+
type HTMLAttributes,
|
|
7
|
+
type ReactElement,
|
|
8
|
+
type ReactNode,
|
|
9
|
+
} from "react"
|
|
10
|
+
|
|
11
|
+
import {cx} from "./cx"
|
|
12
|
+
|
|
13
|
+
export interface SectionProps extends Omit<HTMLAttributes<HTMLElement>, "title"> {
|
|
14
|
+
title?: ReactNode
|
|
15
|
+
description?: ReactNode
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function Section({title, description, className, children, ...props}: SectionProps) {
|
|
19
|
+
return (
|
|
20
|
+
<section className={cx("gl-section", className)} {...props}>
|
|
21
|
+
{title ? <h2 className="gl-section-title">{title}</h2> : null}
|
|
22
|
+
<div className="gl-section-body">{children}</div>
|
|
23
|
+
{description ? <p className="gl-section-description">{description}</p> : null}
|
|
24
|
+
</section>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface SettingsRowProps {
|
|
29
|
+
label: ReactNode
|
|
30
|
+
description?: ReactNode
|
|
31
|
+
icon?: ReactNode
|
|
32
|
+
control?: ReactNode
|
|
33
|
+
onClick?: () => void
|
|
34
|
+
disabled?: boolean
|
|
35
|
+
className?: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function Chevron() {
|
|
39
|
+
return (
|
|
40
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" aria-hidden="true">
|
|
41
|
+
<path d="M9 6l6 6-6 6" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
|
|
42
|
+
</svg>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// The label names the control and forwards taps to it. Only a single labelable
|
|
47
|
+
// control (Switch, Select, Input) takes the id; a segmented control ignores it.
|
|
48
|
+
export function SettingsRow({label, description, icon, control, onClick, disabled, className}: SettingsRowProps) {
|
|
49
|
+
const id = useId()
|
|
50
|
+
const text = (labelFor?: string) => (
|
|
51
|
+
<>
|
|
52
|
+
{icon ? <span className="gl-row-icon">{icon}</span> : null}
|
|
53
|
+
<span className="gl-row-text">
|
|
54
|
+
{labelFor ? <label htmlFor={labelFor}>{label}</label> : <span>{label}</span>}
|
|
55
|
+
{description ? <span className="gl-row-description">{description}</span> : null}
|
|
56
|
+
</span>
|
|
57
|
+
</>
|
|
58
|
+
)
|
|
59
|
+
if (onClick) {
|
|
60
|
+
return (
|
|
61
|
+
<button type="button" className={cx("gl-row", className)} onClick={onClick} disabled={disabled}>
|
|
62
|
+
{text()}
|
|
63
|
+
<span className="gl-row-trailing">
|
|
64
|
+
{control}
|
|
65
|
+
<Chevron />
|
|
66
|
+
</span>
|
|
67
|
+
</button>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
const element = isValidElement(control) && control.type !== Fragment ? (control as ReactElement<{id?: string}>) : null
|
|
71
|
+
const controlId = element ? (element.props.id ?? id) : undefined
|
|
72
|
+
return (
|
|
73
|
+
<div className={cx("gl-row", className)} aria-disabled={disabled || undefined}>
|
|
74
|
+
{text(controlId)}
|
|
75
|
+
{control ? (
|
|
76
|
+
<span className="gl-row-trailing">{element ? cloneElement(element, {id: controlId}) : control}</span>
|
|
77
|
+
) : null}
|
|
78
|
+
</div>
|
|
79
|
+
)
|
|
80
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import {useEffect, useRef, useState, type CSSProperties, type ReactNode} from "react"
|
|
2
|
+
|
|
3
|
+
import {Button} from "./Button"
|
|
4
|
+
import {cx} from "./cx"
|
|
5
|
+
import {Page, PageHeader} from "./Page"
|
|
6
|
+
|
|
7
|
+
export interface SetupStep {
|
|
8
|
+
id: string
|
|
9
|
+
title: string
|
|
10
|
+
description?: ReactNode
|
|
11
|
+
content?: ReactNode
|
|
12
|
+
done?: boolean
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface SetupGuideProps {
|
|
16
|
+
appName: string
|
|
17
|
+
steps: SetupStep[]
|
|
18
|
+
onFinish: () => void
|
|
19
|
+
onSkip: () => void
|
|
20
|
+
footer?: ReactNode
|
|
21
|
+
step?: number
|
|
22
|
+
onStepChange?: (step: number) => void
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A first-run guide: "Set up <app>" with Skip, the steps with a done mark on
|
|
27
|
+
* finished ones, the current step, and Back and Next (Start on the last).
|
|
28
|
+
* The app decides its steps, when each is done, and saving that it was seen.
|
|
29
|
+
*/
|
|
30
|
+
export function SetupGuide({
|
|
31
|
+
appName,
|
|
32
|
+
steps,
|
|
33
|
+
onFinish,
|
|
34
|
+
onSkip,
|
|
35
|
+
footer,
|
|
36
|
+
step: controlled,
|
|
37
|
+
onStepChange,
|
|
38
|
+
}: SetupGuideProps) {
|
|
39
|
+
const [own, setOwn] = useState(0)
|
|
40
|
+
const index = controlled ?? own
|
|
41
|
+
const setIndex = (next: number) => {
|
|
42
|
+
if (controlled === undefined) setOwn(next)
|
|
43
|
+
onStepChange?.(next)
|
|
44
|
+
}
|
|
45
|
+
const titleRef = useRef<HTMLHeadingElement>(null)
|
|
46
|
+
const current = Math.min(index, steps.length - 1)
|
|
47
|
+
const step = steps[current]
|
|
48
|
+
const last = current === steps.length - 1
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
titleRef.current?.focus()
|
|
52
|
+
}, [current])
|
|
53
|
+
|
|
54
|
+
if (!step) return null
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<Page
|
|
58
|
+
header={
|
|
59
|
+
<PageHeader title={`Set up ${appName}`}>
|
|
60
|
+
<Button variant="ghost" size="sm" onClick={onSkip}>
|
|
61
|
+
Skip
|
|
62
|
+
</Button>
|
|
63
|
+
</PageHeader>
|
|
64
|
+
}
|
|
65
|
+
footer={footer}>
|
|
66
|
+
<ol className="gl-guide-steps" aria-label="Setup steps">
|
|
67
|
+
{steps.map((s, i) => (
|
|
68
|
+
<li
|
|
69
|
+
key={s.id}
|
|
70
|
+
data-state={i === current ? "current" : s.done ? "done" : "todo"}
|
|
71
|
+
aria-current={i === current ? "step" : undefined}>
|
|
72
|
+
<span className="gl-guide-mark" aria-hidden="true">
|
|
73
|
+
{s.done && i !== current ? "✓" : i + 1}
|
|
74
|
+
</span>
|
|
75
|
+
<span className="gl-guide-step-title">
|
|
76
|
+
{s.title}
|
|
77
|
+
{s.done ? <span className="gl-visually-hidden"> (done)</span> : null}
|
|
78
|
+
</span>
|
|
79
|
+
</li>
|
|
80
|
+
))}
|
|
81
|
+
</ol>
|
|
82
|
+
|
|
83
|
+
<section className="gl-guide-current" aria-labelledby={`guide-${step.id}`}>
|
|
84
|
+
<p className="gl-guide-progress">
|
|
85
|
+
Step {current + 1} of {steps.length}
|
|
86
|
+
</p>
|
|
87
|
+
<div className="gl-guide-heading">
|
|
88
|
+
<h2 id={`guide-${step.id}`} ref={titleRef} tabIndex={-1} className="gl-guide-title">
|
|
89
|
+
{step.title}
|
|
90
|
+
</h2>
|
|
91
|
+
{step.done ? <span className="gl-guide-done">Done</span> : null}
|
|
92
|
+
</div>
|
|
93
|
+
{step.description ? <p className="gl-guide-description">{step.description}</p> : null}
|
|
94
|
+
{step.content}
|
|
95
|
+
</section>
|
|
96
|
+
|
|
97
|
+
<div className="gl-guide-nav">
|
|
98
|
+
<Button variant="outline" disabled={current === 0} onClick={() => setIndex(current - 1)}>
|
|
99
|
+
Back
|
|
100
|
+
</Button>
|
|
101
|
+
<Button onClick={() => (last ? onFinish() : setIndex(current + 1))}>{last ? "Start" : "Next"}</Button>
|
|
102
|
+
</div>
|
|
103
|
+
</Page>
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface LensLine {
|
|
108
|
+
text: string
|
|
109
|
+
dim?: boolean
|
|
110
|
+
align?: "left" | "right"
|
|
111
|
+
marked?: boolean
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export interface LensPreviewProps {
|
|
115
|
+
lines: Array<string | LensLine>
|
|
116
|
+
status?: {left: ReactNode; right?: ReactNode}
|
|
117
|
+
label?: string
|
|
118
|
+
className?: string
|
|
119
|
+
style?: CSSProperties
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* A lens-shaped frame filled with sample lines, to show on the phone what the
|
|
124
|
+
* glasses will show. It draws on the phone only; nothing is sent to the glasses.
|
|
125
|
+
*/
|
|
126
|
+
export function LensPreview({
|
|
127
|
+
lines,
|
|
128
|
+
status,
|
|
129
|
+
label = "Preview of the glasses display",
|
|
130
|
+
className,
|
|
131
|
+
style,
|
|
132
|
+
}: LensPreviewProps) {
|
|
133
|
+
return (
|
|
134
|
+
<figure className={cx("gl-lens", className)} style={style} aria-label={label}>
|
|
135
|
+
<div className="gl-lens-lines">
|
|
136
|
+
{lines.map((line, i) => {
|
|
137
|
+
const l = typeof line === "string" ? {text: line} : line
|
|
138
|
+
return (
|
|
139
|
+
<p key={i} data-dim={l.dim ? "" : undefined} data-marked={l.marked ? "" : undefined} data-align={l.align}>
|
|
140
|
+
{l.text}
|
|
141
|
+
</p>
|
|
142
|
+
)
|
|
143
|
+
})}
|
|
144
|
+
</div>
|
|
145
|
+
{status ? (
|
|
146
|
+
<div className="gl-lens-status">
|
|
147
|
+
<span>{status.left}</span>
|
|
148
|
+
{status.right ? <span>{status.right}</span> : null}
|
|
149
|
+
</div>
|
|
150
|
+
) : null}
|
|
151
|
+
</figure>
|
|
152
|
+
)
|
|
153
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {forwardRef, type ButtonHTMLAttributes} from "react"
|
|
2
|
+
|
|
3
|
+
import {cx} from "./cx"
|
|
4
|
+
|
|
5
|
+
export interface SwitchProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "onChange" | "value"> {
|
|
6
|
+
checked: boolean
|
|
7
|
+
onCheckedChange?: (checked: boolean) => void
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const Switch = forwardRef<HTMLButtonElement, SwitchProps>(function Switch(
|
|
11
|
+
{checked, onCheckedChange, onClick, className, ...props},
|
|
12
|
+
ref,
|
|
13
|
+
) {
|
|
14
|
+
return (
|
|
15
|
+
<button
|
|
16
|
+
ref={ref}
|
|
17
|
+
type="button"
|
|
18
|
+
role="switch"
|
|
19
|
+
aria-checked={checked}
|
|
20
|
+
className={cx("gl-switch", className)}
|
|
21
|
+
onClick={(event) => {
|
|
22
|
+
onClick?.(event)
|
|
23
|
+
if (!event.defaultPrevented) onCheckedChange?.(!checked)
|
|
24
|
+
}}
|
|
25
|
+
{...props}
|
|
26
|
+
/>
|
|
27
|
+
)
|
|
28
|
+
})
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import {createContext, useContext, useId, type HTMLAttributes, type ReactNode} from "react"
|
|
2
|
+
|
|
3
|
+
import {cx} from "./cx"
|
|
4
|
+
|
|
5
|
+
interface TabsState {
|
|
6
|
+
value: string
|
|
7
|
+
onValueChange: (value: string) => void
|
|
8
|
+
id: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const TabsContext = createContext<TabsState | null>(null)
|
|
12
|
+
|
|
13
|
+
function useTabs(part: string): TabsState {
|
|
14
|
+
const state = useContext(TabsContext)
|
|
15
|
+
if (!state) throw new Error(`<${part}> must sit inside <Tabs>`)
|
|
16
|
+
return state
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface TabsProps extends Omit<HTMLAttributes<HTMLDivElement>, "onChange"> {
|
|
20
|
+
value: string
|
|
21
|
+
onValueChange: (value: string) => void
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Tabs, or a segmented control when used without TabsContent. */
|
|
25
|
+
export function Tabs({value, onValueChange, className, ...props}: TabsProps) {
|
|
26
|
+
const id = useId()
|
|
27
|
+
return (
|
|
28
|
+
<TabsContext.Provider value={{value, onValueChange, id}}>
|
|
29
|
+
<div className={cx("gl-tabs", className)} {...props} />
|
|
30
|
+
</TabsContext.Provider>
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const KEY_STEP: Record<string, number> = {ArrowRight: 1, ArrowDown: 1, ArrowLeft: -1, ArrowUp: -1}
|
|
35
|
+
|
|
36
|
+
/** Arrow keys, Home and End move between tabs and select them, per the ARIA tabs pattern. */
|
|
37
|
+
export function TabsList({className, onKeyDown, ...props}: HTMLAttributes<HTMLDivElement>) {
|
|
38
|
+
return (
|
|
39
|
+
<div
|
|
40
|
+
role="tablist"
|
|
41
|
+
className={cx("gl-tabs-list", className)}
|
|
42
|
+
onKeyDown={(event) => {
|
|
43
|
+
onKeyDown?.(event)
|
|
44
|
+
if (event.defaultPrevented) return
|
|
45
|
+
const tabs = Array.from(event.currentTarget.querySelectorAll<HTMLButtonElement>('[role="tab"]:not(:disabled)'))
|
|
46
|
+
const at = tabs.indexOf(document.activeElement as HTMLButtonElement)
|
|
47
|
+
if (at < 0) return
|
|
48
|
+
const step = KEY_STEP[event.key]
|
|
49
|
+
const next =
|
|
50
|
+
event.key === "Home"
|
|
51
|
+
? 0
|
|
52
|
+
: event.key === "End"
|
|
53
|
+
? tabs.length - 1
|
|
54
|
+
: step
|
|
55
|
+
? (at + step + tabs.length) % tabs.length
|
|
56
|
+
: -1
|
|
57
|
+
if (next < 0) return
|
|
58
|
+
event.preventDefault()
|
|
59
|
+
tabs[next].focus()
|
|
60
|
+
tabs[next].click()
|
|
61
|
+
}}
|
|
62
|
+
{...props}
|
|
63
|
+
/>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface TabsTriggerProps extends Omit<HTMLAttributes<HTMLButtonElement>, "onClick"> {
|
|
68
|
+
value: string
|
|
69
|
+
disabled?: boolean
|
|
70
|
+
children: ReactNode
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function TabsTrigger({value, disabled, className, ...props}: TabsTriggerProps) {
|
|
74
|
+
const tabs = useTabs("TabsTrigger")
|
|
75
|
+
const selected = tabs.value === value
|
|
76
|
+
return (
|
|
77
|
+
<button
|
|
78
|
+
type="button"
|
|
79
|
+
role="tab"
|
|
80
|
+
id={`${tabs.id}-tab-${value}`}
|
|
81
|
+
aria-selected={selected}
|
|
82
|
+
aria-controls={`${tabs.id}-panel-${value}`}
|
|
83
|
+
tabIndex={selected ? 0 : -1}
|
|
84
|
+
disabled={disabled}
|
|
85
|
+
className={cx("gl-tabs-trigger", className)}
|
|
86
|
+
onClick={() => tabs.onValueChange(value)}
|
|
87
|
+
{...props}
|
|
88
|
+
/>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface TabsContentProps extends HTMLAttributes<HTMLDivElement> {
|
|
93
|
+
value: string
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function TabsContent({value, className, ...props}: TabsContentProps) {
|
|
97
|
+
const tabs = useTabs("TabsContent")
|
|
98
|
+
if (tabs.value !== value) return null
|
|
99
|
+
return (
|
|
100
|
+
<div
|
|
101
|
+
role="tabpanel"
|
|
102
|
+
id={`${tabs.id}-panel-${value}`}
|
|
103
|
+
aria-labelledby={`${tabs.id}-tab-${value}`}
|
|
104
|
+
className={className}
|
|
105
|
+
{...props}
|
|
106
|
+
/>
|
|
107
|
+
)
|
|
108
|
+
}
|
package/src/ui/kit/cx.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {useCallback, useEffect, useRef, useState} from "react"
|
|
2
|
+
|
|
3
|
+
type On = (channel: string, callback: (payload: unknown) => void) => () => void
|
|
4
|
+
|
|
5
|
+
export function useChannel<TChannels extends object, C extends keyof TChannels & string>(
|
|
6
|
+
channel: C,
|
|
7
|
+
initial: TChannels[C],
|
|
8
|
+
): TChannels[C]
|
|
9
|
+
export function useChannel<TChannels extends object, C extends keyof TChannels & string>(
|
|
10
|
+
channel: C,
|
|
11
|
+
): TChannels[C] | undefined
|
|
12
|
+
export function useChannel<TChannels extends object, C extends keyof TChannels & string>(
|
|
13
|
+
channel: C,
|
|
14
|
+
initial?: TChannels[C],
|
|
15
|
+
): TChannels[C] | undefined {
|
|
16
|
+
const [value, setValue] = useState<TChannels[C] | undefined>(initial)
|
|
17
|
+
const initialRef = useRef(initial)
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
setValue(initialRef.current)
|
|
20
|
+
const on = (globalThis as unknown as {glassly?: {on?: On}}).glassly?.on
|
|
21
|
+
return on?.(channel, (payload) => setValue(payload as TChannels[C]))
|
|
22
|
+
}, [channel])
|
|
23
|
+
return value
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface HoldHandlers {
|
|
27
|
+
onPointerDown: () => void
|
|
28
|
+
onPointerUp: () => void
|
|
29
|
+
onPointerLeave: () => void
|
|
30
|
+
onPointerCancel: () => void
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A hidden developer mode, toggled by holding a control (usually the settings
|
|
35
|
+
* button) for `holdMs`. In memory only: it resets when the page reloads.
|
|
36
|
+
*/
|
|
37
|
+
export function useDeveloperMode(holdMs = 5000): {developerMode: boolean; holdHandlers: HoldHandlers} {
|
|
38
|
+
const [developerMode, setDeveloperMode] = useState(false)
|
|
39
|
+
const timer = useRef<ReturnType<typeof setTimeout> | null>(null)
|
|
40
|
+
const clear = useCallback(() => {
|
|
41
|
+
if (timer.current) clearTimeout(timer.current)
|
|
42
|
+
timer.current = null
|
|
43
|
+
}, [])
|
|
44
|
+
const onPointerDown = useCallback(() => {
|
|
45
|
+
clear()
|
|
46
|
+
timer.current = setTimeout(() => setDeveloperMode((on) => !on), holdMs)
|
|
47
|
+
}, [clear, holdMs])
|
|
48
|
+
useEffect(() => clear, [clear])
|
|
49
|
+
return {
|
|
50
|
+
developerMode,
|
|
51
|
+
holdHandlers: {onPointerDown, onPointerUp: clear, onPointerLeave: clear, onPointerCancel: clear},
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export {Badge, type BadgeProps, type BadgeVariant} from "./Badge"
|
|
2
|
+
export {Button, type ButtonProps, type ButtonSize, type ButtonVariant} from "./Button"
|
|
3
|
+
export {Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle} from "./Card"
|
|
4
|
+
export {
|
|
5
|
+
Dock,
|
|
6
|
+
dockClearance,
|
|
7
|
+
railSide,
|
|
8
|
+
useDockClearance,
|
|
9
|
+
DOCK_HEIGHT,
|
|
10
|
+
PILL_WIDTH,
|
|
11
|
+
RAIL_CENTER,
|
|
12
|
+
RAIL_MIN_WIDTH,
|
|
13
|
+
type DockItem,
|
|
14
|
+
type DockProps,
|
|
15
|
+
} from "./Dock"
|
|
16
|
+
export {
|
|
17
|
+
Banner,
|
|
18
|
+
EmptyState,
|
|
19
|
+
Separator,
|
|
20
|
+
Spinner,
|
|
21
|
+
Stat,
|
|
22
|
+
type BannerProps,
|
|
23
|
+
type BannerVariant,
|
|
24
|
+
type EmptyStateProps,
|
|
25
|
+
type SeparatorProps,
|
|
26
|
+
type SpinnerProps,
|
|
27
|
+
type StatProps,
|
|
28
|
+
} from "./Feedback"
|
|
29
|
+
export {Input, Select, Textarea, type SelectProps} from "./Field"
|
|
30
|
+
export {useChannel, useDeveloperMode, type HoldHandlers} from "./hooks"
|
|
31
|
+
export {Footer, Page, PageHeader, type FooterProps, type PageHeaderProps, type PageProps} from "./Page"
|
|
32
|
+
export {
|
|
33
|
+
LensPreview,
|
|
34
|
+
SetupGuide,
|
|
35
|
+
type LensLine,
|
|
36
|
+
type LensPreviewProps,
|
|
37
|
+
type SetupGuideProps,
|
|
38
|
+
type SetupStep,
|
|
39
|
+
} from "./SetupGuide"
|
|
40
|
+
export {Section, SettingsRow, type SectionProps, type SettingsRowProps} from "./Section"
|
|
41
|
+
export {Switch, type SwitchProps} from "./Switch"
|
|
42
|
+
export {
|
|
43
|
+
Tabs,
|
|
44
|
+
TabsContent,
|
|
45
|
+
TabsList,
|
|
46
|
+
TabsTrigger,
|
|
47
|
+
type TabsProps,
|
|
48
|
+
type TabsContentProps,
|
|
49
|
+
type TabsTriggerProps,
|
|
50
|
+
} from "./Tabs"
|
|
51
|
+
export {useWide, WIDE_QUERY} from "./useWide"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {useEffect, useState} from "react"
|
|
2
|
+
|
|
3
|
+
export const WIDE_QUERY = "(min-width: 700px) and (min-aspect-ratio: 1/1)"
|
|
4
|
+
|
|
5
|
+
const matches = () => typeof window !== "undefined" && window.matchMedia?.(WIDE_QUERY).matches === true
|
|
6
|
+
|
|
7
|
+
/** True in a landscape window at least 700 px wide: the open iPhone Duo, an iPad, a landscape phone. */
|
|
8
|
+
export function useWide(): boolean {
|
|
9
|
+
const [wide, setWide] = useState(matches)
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const query = window.matchMedia?.(WIDE_QUERY)
|
|
12
|
+
if (!query) return
|
|
13
|
+
const update = () => setWide(query.matches)
|
|
14
|
+
update()
|
|
15
|
+
query.addEventListener("change", update)
|
|
16
|
+
return () => query.removeEventListener("change", update)
|
|
17
|
+
}, [])
|
|
18
|
+
return wide
|
|
19
|
+
}
|