@justanarthur/modo-ui-notch 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +75 -2
- package/blocks/activities/agenda/examples.mdx +74 -0
- package/blocks/activities/agenda/index.tsx +441 -0
- package/blocks/activities/clock/examples.mdx +73 -0
- package/blocks/activities/clock/index.tsx +619 -0
- package/blocks/activities/now-playing/examples.mdx +68 -0
- package/blocks/activities/now-playing/index.tsx +411 -0
- package/blocks/activities/weather/examples.mdx +115 -0
- package/blocks/activities/weather/index.tsx +634 -0
- package/blocks/app/expanded-island/examples.mdx +46 -0
- package/blocks/app/expanded-island/index.tsx +143 -0
- package/blocks/app/settings-window/examples.mdx +34 -0
- package/blocks/app/settings-window/index.tsx +375 -0
- package/blocks/system/clipboard/examples.mdx +83 -0
- package/blocks/system/clipboard/index.tsx +563 -0
- package/blocks/system/recent-files/examples.mdx +66 -0
- package/blocks/system/recent-files/index.tsx +542 -0
- package/blocks/system/system-stats/examples.mdx +52 -0
- package/blocks/system/system-stats/index.tsx +312 -0
- package/components/indicators/countdown/examples.mdx +25 -0
- package/components/indicators/countdown/index.tsx +83 -0
- package/components/indicators/equalizer/examples.mdx +20 -0
- package/components/indicators/equalizer/index.tsx +116 -0
- package/components/indicators/media-scrubber/examples.mdx +29 -0
- package/components/indicators/media-scrubber/index.tsx +122 -0
- package/components/island/island/examples.mdx +57 -0
- package/components/island/island/index.tsx +415 -0
- package/components/island/island-flash/examples.mdx +52 -0
- package/components/island/island-flash/index.tsx +79 -0
- package/components/island/island-tabs/examples.mdx +53 -0
- package/components/island/island-tabs/index.tsx +285 -0
- package/components/island/widget/examples.mdx +76 -0
- package/components/island/widget/index.tsx +431 -0
- package/dist/blocks/activities/agenda/index.d.ts +2 -0
- package/dist/blocks/activities/agenda/index.js +21 -0
- package/dist/blocks/activities/clock/index.d.ts +2 -0
- package/dist/blocks/activities/clock/index.js +25 -0
- package/dist/blocks/activities/now-playing/index.d.ts +3 -0
- package/dist/blocks/activities/now-playing/index.js +24 -0
- package/dist/blocks/activities/weather/index.d.ts +2 -0
- package/dist/blocks/activities/weather/index.js +21 -0
- package/dist/blocks/app/expanded-island/index.d.ts +3 -0
- package/dist/blocks/app/expanded-island/index.js +11 -0
- package/dist/blocks/app/settings-window/index.d.ts +2 -0
- package/dist/blocks/app/settings-window/index.js +7 -0
- package/dist/blocks/system/clipboard/index.d.ts +2 -0
- package/dist/blocks/system/clipboard/index.js +17 -0
- package/dist/blocks/system/recent-files/index.d.ts +2 -0
- package/dist/blocks/system/recent-files/index.js +19 -0
- package/dist/blocks/system/system-stats/index.d.ts +2 -0
- package/dist/blocks/system/system-stats/index.js +15 -0
- package/dist/components/indicators/countdown/index.d.ts +2 -0
- package/dist/components/indicators/countdown/index.js +8 -0
- package/dist/components/indicators/equalizer/index.d.ts +2 -0
- package/dist/components/indicators/equalizer/index.js +7 -0
- package/dist/components/indicators/media-scrubber/index.d.ts +2 -0
- package/dist/components/indicators/media-scrubber/index.js +8 -0
- package/dist/components/island/island/index.d.ts +3 -0
- package/dist/components/island/island/index.js +10 -0
- package/dist/components/island/island-flash/index.d.ts +2 -0
- package/dist/components/island/island-flash/index.js +7 -0
- package/dist/components/island/island-tabs/index.d.ts +2 -0
- package/dist/components/island/island-tabs/index.js +9 -0
- package/dist/components/island/widget/index.d.ts +2 -0
- package/dist/components/island/widget/index.js +30 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +195 -0
- package/dist/lib/artwork.d.ts +2 -0
- package/dist/lib/artwork.js +8 -0
- package/dist/lib/clock.d.ts +2 -0
- package/dist/lib/clock.js +14 -0
- package/dist/lib/geometry.d.ts +2 -0
- package/dist/lib/geometry.js +24 -0
- package/dist/lib/island-context.d.ts +3 -0
- package/dist/lib/island-context.js +8 -0
- package/dist/lib/motion.d.ts +21 -0
- package/dist/lib/motion.js +16 -0
- package/dist/shared/chunk-152gpyq3.d.ts +13 -0
- package/dist/shared/chunk-2818esrq.d.ts +140 -0
- package/dist/shared/chunk-2f7zxrbk.js +65 -0
- package/dist/shared/chunk-2m5dz8nf.d.ts +88 -0
- package/dist/shared/chunk-2s4q6mt0.js +27 -0
- package/dist/shared/chunk-3thgcfcq.d.ts +151 -0
- package/dist/shared/chunk-416tsgbc.d.ts +175 -0
- package/dist/shared/chunk-502rmtap.js +54 -0
- package/dist/shared/chunk-52gb3g6r.d.ts +12 -0
- package/dist/shared/chunk-5en5aaj1.d.ts +33 -0
- package/dist/shared/chunk-61t2dfte.js +63 -0
- package/dist/shared/chunk-7fvnrtz4.d.ts +105 -0
- package/dist/shared/chunk-81fpptwp.d.ts +75 -0
- package/dist/shared/chunk-9c7ewvkk.js +381 -0
- package/dist/shared/chunk-9m0xbg5v.js +112 -0
- package/dist/shared/chunk-9xtcv3sy.js +88 -0
- package/dist/shared/chunk-bvtyjcce.d.ts +123 -0
- package/dist/shared/chunk-cc9nwbtf.js +315 -0
- package/dist/shared/chunk-cfzmfnyh.d.ts +63 -0
- package/dist/shared/chunk-d5qm9cps.js +10 -0
- package/dist/shared/chunk-da177e8r.d.ts +114 -0
- package/dist/shared/chunk-fexwzycv.d.ts +36 -0
- package/dist/shared/chunk-gb56m10p.js +39 -0
- package/dist/shared/chunk-gejenfap.d.ts +25 -0
- package/dist/shared/chunk-hrpxbqmx.d.ts +28 -0
- package/dist/shared/chunk-j755a1a5.d.ts +41 -0
- package/dist/shared/chunk-j77cx8dp.js +498 -0
- package/dist/shared/chunk-mt0k6v8x.js +474 -0
- package/dist/shared/chunk-ndf79pv5.js +58 -0
- package/dist/shared/chunk-pfhy5e4q.d.ts +53 -0
- package/dist/shared/chunk-qdzemt2v.js +477 -0
- package/dist/shared/chunk-r471sknr.js +209 -0
- package/dist/shared/chunk-s2jeqqan.js +243 -0
- package/dist/shared/chunk-t0hcxh89.d.ts +124 -0
- package/dist/shared/chunk-w48eyvfr.d.ts +56 -0
- package/dist/shared/chunk-w5h6ay93.js +72 -0
- package/dist/shared/chunk-wkg17nxs.d.ts +101 -0
- package/dist/shared/chunk-x7f3g82r.js +285 -0
- package/dist/shared/chunk-xq5hc5gv.js +333 -0
- package/dist/shared/chunk-y0188bbn.js +331 -0
- package/dist/shared/chunk-ym0xbses.js +518 -0
- package/dist/styles.css +264 -0
- package/index.ts +22 -0
- package/lib/artwork.ts +112 -0
- package/lib/clock.ts +53 -0
- package/lib/geometry.ts +130 -0
- package/lib/island-context.tsx +24 -0
- package/lib/motion.ts +42 -0
- package/mock/activities.tsx +77 -0
- package/mock/artwork.tsx +37 -0
- package/mock/clipboard.tsx +79 -0
- package/mock/clock.tsx +77 -0
- package/mock/data.ts +139 -0
- package/mock/desktop.tsx +83 -0
- package/mock/files.tsx +70 -0
- package/mock/fit.ts +26 -0
- package/mock/island-content.tsx +142 -0
- package/mock/scene.tsx +52 -0
- package/mock/screen.tsx +76 -0
- package/mock/settings.tsx +489 -0
- package/mock/system.ts +46 -0
- package/mock/weather.tsx +105 -0
- package/package.json +122 -4
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Local addition: the layout of a notch app's transient alert, the island's
|
|
3
|
+
* `flash` content. Generalised from Just Notch's power, HUD and now-playing
|
|
4
|
+
* flashes; the kit's blocks build their own on it.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { cn } from '@justanarthur/modo-ui/lib/utils'
|
|
8
|
+
import type { ReactNode } from 'react'
|
|
9
|
+
|
|
10
|
+
type IslandFlashTone = 'default' | 'success' | 'warning' | 'error' | 'info'
|
|
11
|
+
|
|
12
|
+
// Literal table: UnoCSS only generates the classes it can read whole.
|
|
13
|
+
const TONE: Record<IslandFlashTone, string> = {
|
|
14
|
+
default: 'text-foreground',
|
|
15
|
+
success: 'text-status-success',
|
|
16
|
+
warning: 'text-status-warning',
|
|
17
|
+
error: 'text-status-error',
|
|
18
|
+
info: 'text-status-info',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface IslandFlashProps {
|
|
22
|
+
/** What happened, in a few words. */
|
|
23
|
+
title: ReactNode
|
|
24
|
+
/** One line more: how long, what to do. */
|
|
25
|
+
caption?: ReactNode
|
|
26
|
+
/** The glyph at the start: an icon, an artwork tile. It takes the tone's hue. */
|
|
27
|
+
icon?: ReactNode
|
|
28
|
+
/** The hue of the icon and the `value`. Defaults to `'default'`. */
|
|
29
|
+
tone?: IslandFlashTone
|
|
30
|
+
/** A figure at the end, in the tone's hue: `15 min`, a level. */
|
|
31
|
+
value?: ReactNode
|
|
32
|
+
/** Content after it, such as an Equalizer. */
|
|
33
|
+
trailing?: ReactNode
|
|
34
|
+
/** One control at the far end, such as a ghost Button. */
|
|
35
|
+
action?: ReactNode
|
|
36
|
+
/** Classes for the row. */
|
|
37
|
+
className?: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A moment's alert in the island: an icon, what happened, a line more, and
|
|
42
|
+
* the figure or control it's about.
|
|
43
|
+
*
|
|
44
|
+
* It lays out one row the height of the island's flash: the icon in a fixed
|
|
45
|
+
* square, the title and caption truncating beside it, then the `value`, any
|
|
46
|
+
* `trailing` glyph and an `action`. The icon and the value take the tone's
|
|
47
|
+
* status hue (a focus round done in success, rain coming in warning); everything else
|
|
48
|
+
* keeps the two text colors. Pass it as the Island's `flash`.
|
|
49
|
+
*
|
|
50
|
+
* @example {@include ./examples.mdx}
|
|
51
|
+
*/
|
|
52
|
+
export default function IslandFlash({
|
|
53
|
+
title,
|
|
54
|
+
caption,
|
|
55
|
+
icon,
|
|
56
|
+
tone = 'default',
|
|
57
|
+
value,
|
|
58
|
+
trailing,
|
|
59
|
+
action,
|
|
60
|
+
className,
|
|
61
|
+
}: IslandFlashProps) {
|
|
62
|
+
return (
|
|
63
|
+
<div className={cn('flex min-w-0 items-center gap-3', className)}>
|
|
64
|
+
{icon && <span className={cn('flex size-8 shrink-0 items-center justify-center', TONE[tone])}>{icon}</span>}
|
|
65
|
+
<div className="flex min-w-0 flex-1 flex-col">
|
|
66
|
+
<span className="truncate text-body weight-semibold text-foreground">{title}</span>
|
|
67
|
+
{caption && <span className="truncate text-caption text-muted-foreground">{caption}</span>}
|
|
68
|
+
</div>
|
|
69
|
+
{value !== undefined && (
|
|
70
|
+
<span className={cn('shrink-0 text-subtitle weight-semibold tabular-nums', TONE[tone])}>{value}</span>
|
|
71
|
+
)}
|
|
72
|
+
{trailing}
|
|
73
|
+
{action && <span className="flex shrink-0 items-center">{action}</span>}
|
|
74
|
+
</div>
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type { IslandFlashProps, IslandFlashTone }
|
|
79
|
+
export { IslandFlash }
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import IslandTabs from './index'
|
|
2
|
+
import Button from '@justanarthur/modo-ui/components/actions/button'
|
|
3
|
+
import { CalendarDays, CloudSun, Music, Settings } from 'lucide-react'
|
|
4
|
+
import { TABS } from '../../../mock/data'
|
|
5
|
+
import { Fit } from '../../../mock/island-content'
|
|
6
|
+
|
|
7
|
+
# Both wings
|
|
8
|
+
|
|
9
|
+
Seven tabs balance across the wings, the left one taking the odd one; the pill melts across the gap.
|
|
10
|
+
|
|
11
|
+
<Fit width={720}>
|
|
12
|
+
<div className="dark w-full rounded-box bg-ink px-5 text-foreground">
|
|
13
|
+
<IslandTabs tabs={TABS} size="compact" trailing={<Button variant="ghost" size="icon-compact" aria-label="Settings"><Settings size={14} strokeWidth={1.5} /></Button>} />
|
|
14
|
+
</div>
|
|
15
|
+
</Fit>
|
|
16
|
+
|
|
17
|
+
# Few tabs
|
|
18
|
+
|
|
19
|
+
Three tabs balance too, the left wing taking the odd one.
|
|
20
|
+
|
|
21
|
+
<Fit width={720}>
|
|
22
|
+
<div className="dark w-full rounded-box bg-ink px-5 text-foreground">
|
|
23
|
+
<IslandTabs
|
|
24
|
+
size="compact"
|
|
25
|
+
defaultValue="calendar"
|
|
26
|
+
tabs={[
|
|
27
|
+
{ value: 'now-playing', label: 'Now Playing', icon: Music },
|
|
28
|
+
{ value: 'calendar', label: 'Calendar', icon: CalendarDays },
|
|
29
|
+
{ value: 'weather', label: 'Weather', icon: CloudSun },
|
|
30
|
+
]}
|
|
31
|
+
/>
|
|
32
|
+
</div>
|
|
33
|
+
</Fit>
|
|
34
|
+
|
|
35
|
+
# Overflow
|
|
36
|
+
|
|
37
|
+
Past what both wings hold, the strip scrolls behind the notch; its edges fade and a vertical wheel scrolls it sideways.
|
|
38
|
+
|
|
39
|
+
<Fit width={420}>
|
|
40
|
+
<div className="dark w-full rounded-box bg-ink px-5 text-foreground">
|
|
41
|
+
<IslandTabs tabs={[...TABS, ...TABS.map(t => ({ ...t, value: t.value + '-2' }))]} size="compact" />
|
|
42
|
+
</div>
|
|
43
|
+
</Fit>
|
|
44
|
+
|
|
45
|
+
# Default size
|
|
46
|
+
|
|
47
|
+
The default step: 36px tabs for a roomier panel.
|
|
48
|
+
|
|
49
|
+
<Fit width={720}>
|
|
50
|
+
<div className="dark w-full rounded-box bg-ink px-5 text-foreground">
|
|
51
|
+
<IslandTabs tabs={TABS} defaultValue="system" />
|
|
52
|
+
</div>
|
|
53
|
+
</Fit>
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Local addition: the open island's icon tabs, split across the two wings
|
|
3
|
+
* around the notch. Rebuilt from Just Notch's runtime (`island/tabs.tsx`) on
|
|
4
|
+
* modo-ui's fluid hover, liquid indicator and focus ring.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use client'
|
|
8
|
+
|
|
9
|
+
import { FocusRing } from '@justanarthur/modo-ui/lib/focus-ring'
|
|
10
|
+
import { GooIndicator } from '@justanarthur/modo-ui/lib/goo-indicator'
|
|
11
|
+
import type { IconComponent } from '@justanarthur/modo-ui/lib/icon-context'
|
|
12
|
+
import { useRowFocus } from '@justanarthur/modo-ui/lib/row-group'
|
|
13
|
+
import { useShape } from '@justanarthur/modo-ui/lib/shape-context'
|
|
14
|
+
import { type SizeVariant, useSize } from '@justanarthur/modo-ui/lib/size-context'
|
|
15
|
+
import { useControllableState } from '@justanarthur/modo-ui/lib/use-controllable-state'
|
|
16
|
+
import { useFluidHover, useRegisterFluidHoverItem } from '@justanarthur/modo-ui/lib/use-fluid-hover'
|
|
17
|
+
import { cn } from '@justanarthur/modo-ui/lib/utils'
|
|
18
|
+
import { FluidHoverHighlight } from '@justanarthur/modo-ui/primitives/systems/fluid-hover'
|
|
19
|
+
import {
|
|
20
|
+
type CSSProperties,
|
|
21
|
+
type KeyboardEvent,
|
|
22
|
+
type ReactNode,
|
|
23
|
+
useEffect,
|
|
24
|
+
useLayoutEffect,
|
|
25
|
+
useRef,
|
|
26
|
+
useState,
|
|
27
|
+
} from 'react'
|
|
28
|
+
import { DEFAULT_NOTCH, stripLayout } from '../../../lib/geometry'
|
|
29
|
+
import { useIsland } from '../../../lib/island-context'
|
|
30
|
+
|
|
31
|
+
interface IslandTab {
|
|
32
|
+
/** What selecting it reports. */
|
|
33
|
+
value: string
|
|
34
|
+
/** Its name: the tab's accessible name, and the title a consumer shows for it. */
|
|
35
|
+
label: string
|
|
36
|
+
/** Its glyph. */
|
|
37
|
+
icon: IconComponent
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface IslandTabsProps {
|
|
41
|
+
/** The tabs, in order: they fill the left wing, then the right one. */
|
|
42
|
+
tabs: IslandTab[]
|
|
43
|
+
/** The selected tab's value (controlled). */
|
|
44
|
+
value?: string
|
|
45
|
+
/** The tab selected at first (uncontrolled). Defaults to the first tab. */
|
|
46
|
+
defaultValue?: string
|
|
47
|
+
/** Called with the value of the tab a press or an arrow key selects. */
|
|
48
|
+
onValueChange?: (value: string) => void
|
|
49
|
+
/** Called with the value of the tab under the pointer, or `null`, so a title can preview it. */
|
|
50
|
+
onHoverChange?: (value: string | null) => void
|
|
51
|
+
/** Step on the size ladder. Defaults to the surrounding SizeProvider, else `'default'`. */
|
|
52
|
+
size?: SizeVariant
|
|
53
|
+
/** The notch the strip leaves free, centered. Defaults to the enclosing Island's, else `185`. */
|
|
54
|
+
notchWidth?: number
|
|
55
|
+
/** Content at the far right of the right wing, such as a settings button; the tabs keep clear of it. */
|
|
56
|
+
trailing?: ReactNode
|
|
57
|
+
/** The tab list's accessible name. Defaults to `'Widgets'`. */
|
|
58
|
+
label?: string
|
|
59
|
+
/** Classes for the root, which spans its container's width. */
|
|
60
|
+
className?: string
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Literal tables: UnoCSS only generates the classes it can read whole.
|
|
64
|
+
const TAB_WIDTH: Record<SizeVariant, number> = { default: 40, compact: 30 }
|
|
65
|
+
const TAB_CLASS: Record<SizeVariant, string> = { default: 'w-10', compact: 'w-7.5' }
|
|
66
|
+
const FADE = 16
|
|
67
|
+
const NOTCH_FADE = 8
|
|
68
|
+
|
|
69
|
+
interface TabButtonProps {
|
|
70
|
+
tab: IslandTab
|
|
71
|
+
index: number
|
|
72
|
+
selected: boolean
|
|
73
|
+
lit: boolean
|
|
74
|
+
size: SizeVariant
|
|
75
|
+
register: (index: number, element: HTMLElement | null) => void
|
|
76
|
+
onSelect: (index: number) => void
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function TabButton({ tab, index, selected, lit, size: sizeProp, register, onSelect }: TabButtonProps) {
|
|
80
|
+
const ref = useRef<HTMLButtonElement>(null)
|
|
81
|
+
const size = useSize(sizeProp)
|
|
82
|
+
const shape = useShape()
|
|
83
|
+
useRegisterFluidHoverItem(register, index, ref)
|
|
84
|
+
const Icon = tab.icon
|
|
85
|
+
return (
|
|
86
|
+
<button
|
|
87
|
+
ref={ref}
|
|
88
|
+
type="button"
|
|
89
|
+
role="tab"
|
|
90
|
+
aria-selected={selected}
|
|
91
|
+
aria-label={tab.label}
|
|
92
|
+
tabIndex={selected ? 0 : -1}
|
|
93
|
+
data-fluid-hover-index={index}
|
|
94
|
+
className={cn(
|
|
95
|
+
'relative z-10 flex shrink-0 cursor-pointer items-center justify-center bg-transparent outline-none transition-[color] duration-fast',
|
|
96
|
+
size.control,
|
|
97
|
+
TAB_CLASS[size.variant],
|
|
98
|
+
shape.bg,
|
|
99
|
+
lit ? 'text-foreground' : 'text-muted-foreground',
|
|
100
|
+
)}
|
|
101
|
+
onClick={() => onSelect(index)}
|
|
102
|
+
>
|
|
103
|
+
<Icon size={size.icon} strokeWidth={lit ? 2 : 1.5} className="transition-[stroke-width] duration-fast" />
|
|
104
|
+
</button>
|
|
105
|
+
)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function useWidth(ref: React.RefObject<HTMLElement | null>) {
|
|
109
|
+
const [width, setWidth] = useState(0)
|
|
110
|
+
useLayoutEffect(() => {
|
|
111
|
+
const el = ref.current
|
|
112
|
+
if (!el) return
|
|
113
|
+
setWidth(el.offsetWidth)
|
|
114
|
+
const observer = new ResizeObserver(() => setWidth(el.offsetWidth))
|
|
115
|
+
observer.observe(el)
|
|
116
|
+
return () => observer.disconnect()
|
|
117
|
+
}, [ref])
|
|
118
|
+
return width
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The open island's icon tabs, in both wings around the notch: the left
|
|
123
|
+
* wing's, a gap the width of the notch, then the right wing's.
|
|
124
|
+
*
|
|
125
|
+
* The tabs fill the left wing first and balance into the right one, keeping
|
|
126
|
+
* clear of the `trailing` content at its far end. The selected tab's pill is
|
|
127
|
+
* modo-ui's liquid indicator: it melts from tab to tab, across the notch too;
|
|
128
|
+
* a fluid hover highlight lights the tab under the pointer and the keyboard
|
|
129
|
+
* gets a focus ring that springs between tabs. Past what both wings hold the
|
|
130
|
+
* strip scrolls behind the notch, which hides the tabs passing under it; its
|
|
131
|
+
* outer edges fade with `scroll-fade-x` and a vertical wheel scrolls it
|
|
132
|
+
* sideways.
|
|
133
|
+
*
|
|
134
|
+
* The strip shows icons only. Show the selected tab's title yourself, or the
|
|
135
|
+
* hovered one's as a preview through `onHoverChange`. Arrow keys, Home and End
|
|
136
|
+
* move the selection. Inside an Island it reads the notch's width from it.
|
|
137
|
+
*
|
|
138
|
+
* @example {@include ./examples.mdx}
|
|
139
|
+
*/
|
|
140
|
+
export default function IslandTabs({
|
|
141
|
+
tabs,
|
|
142
|
+
value: valueProp,
|
|
143
|
+
defaultValue,
|
|
144
|
+
onValueChange,
|
|
145
|
+
onHoverChange,
|
|
146
|
+
size: sizeProp,
|
|
147
|
+
notchWidth,
|
|
148
|
+
trailing,
|
|
149
|
+
label = 'Widgets',
|
|
150
|
+
className,
|
|
151
|
+
}: IslandTabsProps) {
|
|
152
|
+
const [value, setValue] = useControllableState(valueProp, defaultValue ?? tabs[0]?.value, onValueChange)
|
|
153
|
+
const size = useSize(sizeProp)
|
|
154
|
+
const shape = useShape()
|
|
155
|
+
const island = useIsland()
|
|
156
|
+
const notch = notchWidth ?? island?.geometry.notch.width ?? DEFAULT_NOTCH.width
|
|
157
|
+
|
|
158
|
+
const root = useRef<HTMLDivElement>(null)
|
|
159
|
+
const viewport = useRef<HTMLDivElement>(null)
|
|
160
|
+
const strip = useRef<HTMLDivElement>(null)
|
|
161
|
+
const end = useRef<HTMLDivElement>(null)
|
|
162
|
+
const width = useWidth(root)
|
|
163
|
+
const reserve = useWidth(end)
|
|
164
|
+
const hover = useFluidHover(strip, { axis: 'x' })
|
|
165
|
+
const focus = useRowFocus(hover)
|
|
166
|
+
|
|
167
|
+
const selected = Math.max(
|
|
168
|
+
0,
|
|
169
|
+
tabs.findIndex(tab => tab.value === value),
|
|
170
|
+
)
|
|
171
|
+
const layout = stripLayout(tabs.length, width, notch, TAB_WIDTH[size.variant], reserve)
|
|
172
|
+
const hovered = hover.activeIndex === null ? null : (tabs[hover.activeIndex]?.value ?? null)
|
|
173
|
+
|
|
174
|
+
const report = useRef(onHoverChange)
|
|
175
|
+
report.current = onHoverChange
|
|
176
|
+
useEffect(() => report.current?.(hovered), [hovered])
|
|
177
|
+
|
|
178
|
+
// Scrolls only the strip (scrollIntoView would scroll the page too), and moves keyboard focus along.
|
|
179
|
+
useEffect(() => {
|
|
180
|
+
const el = viewport.current
|
|
181
|
+
const active = el?.querySelector<HTMLElement>('[role=tab][aria-selected=true]')
|
|
182
|
+
if (!el || !active) return
|
|
183
|
+
if (el.contains(document.activeElement) && document.activeElement !== active) active.focus({ preventScroll: true })
|
|
184
|
+
const left = active.offsetLeft - el.scrollLeft
|
|
185
|
+
const right = left + active.offsetWidth - el.clientWidth
|
|
186
|
+
if (left < 0) el.scrollBy({ left: left - FADE })
|
|
187
|
+
else if (right > 0) el.scrollBy({ left: right + FADE })
|
|
188
|
+
}, [selected])
|
|
189
|
+
|
|
190
|
+
useEffect(() => {
|
|
191
|
+
const el = viewport.current
|
|
192
|
+
if (!el || !layout.overflow) return
|
|
193
|
+
const onWheel = (event: WheelEvent) => {
|
|
194
|
+
if (Math.abs(event.deltaY) <= Math.abs(event.deltaX)) return
|
|
195
|
+
event.preventDefault()
|
|
196
|
+
el.scrollLeft += event.deltaY
|
|
197
|
+
}
|
|
198
|
+
el.addEventListener('wheel', onWheel, { passive: false })
|
|
199
|
+
return () => el.removeEventListener('wheel', onWheel)
|
|
200
|
+
}, [layout.overflow])
|
|
201
|
+
|
|
202
|
+
const select = (index: number) => {
|
|
203
|
+
const tab = tabs[index]
|
|
204
|
+
if (tab) setValue(tab.value)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
208
|
+
const next =
|
|
209
|
+
event.key === 'ArrowRight'
|
|
210
|
+
? selected + 1
|
|
211
|
+
: event.key === 'ArrowLeft'
|
|
212
|
+
? selected - 1
|
|
213
|
+
: event.key === 'Home'
|
|
214
|
+
? 0
|
|
215
|
+
: event.key === 'End'
|
|
216
|
+
? tabs.length - 1
|
|
217
|
+
: null
|
|
218
|
+
if (next === null || !tabs[next]) return
|
|
219
|
+
event.preventDefault()
|
|
220
|
+
select(next)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// The notch cut out of the strip while it scrolls behind it: a mask's alpha, not a color.
|
|
224
|
+
const hole: CSSProperties | undefined = layout.overflow
|
|
225
|
+
? {
|
|
226
|
+
maskImage: `linear-gradient(to right, black ${layout.hole.start - NOTCH_FADE}px, transparent ${layout.hole.start}px, transparent ${layout.hole.end}px, black ${layout.hole.end + NOTCH_FADE}px)`,
|
|
227
|
+
}
|
|
228
|
+
: undefined
|
|
229
|
+
|
|
230
|
+
const rect = hover.isMeasured ? hover.itemRects[selected] : undefined
|
|
231
|
+
const button = (tab: IslandTab, index: number) => (
|
|
232
|
+
<TabButton
|
|
233
|
+
key={tab.value}
|
|
234
|
+
tab={tab}
|
|
235
|
+
index={index}
|
|
236
|
+
selected={index === selected}
|
|
237
|
+
lit={index === selected || index === hover.activeIndex}
|
|
238
|
+
size={size.variant}
|
|
239
|
+
register={hover.registerItem}
|
|
240
|
+
onSelect={select}
|
|
241
|
+
/>
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
return (
|
|
245
|
+
<div ref={root} className={cn('relative flex w-full min-w-0 items-center', size.control, className)}>
|
|
246
|
+
<div className="relative h-full min-w-0 flex-1" style={hole}>
|
|
247
|
+
<div
|
|
248
|
+
ref={viewport}
|
|
249
|
+
className={cn(
|
|
250
|
+
'h-full overflow-x-auto overflow-y-hidden scrollbar-hide',
|
|
251
|
+
layout.overflow && 'scroll-fade-x [--scroll-fade-size:16px]',
|
|
252
|
+
)}
|
|
253
|
+
>
|
|
254
|
+
<div
|
|
255
|
+
ref={strip}
|
|
256
|
+
role="tablist"
|
|
257
|
+
aria-label={label}
|
|
258
|
+
className="relative flex h-full w-max min-w-full items-center"
|
|
259
|
+
onKeyDown={onKeyDown}
|
|
260
|
+
onMouseMove={hover.handlers.onMouseMove}
|
|
261
|
+
onMouseEnter={hover.handlers.onMouseEnter}
|
|
262
|
+
onMouseLeave={hover.handlers.onMouseLeave}
|
|
263
|
+
onFocus={focus.handlers.onFocus}
|
|
264
|
+
onBlur={focus.handlers.onBlur}
|
|
265
|
+
>
|
|
266
|
+
{rect && <GooIndicator rect={rect} className={cn('bg-active', shape.bg)} />}
|
|
267
|
+
<FluidHoverHighlight hover={hover} hidden={hover.activeIndex === selected} className={shape.bg} />
|
|
268
|
+
<FocusRing rect={focus.focusRect} />
|
|
269
|
+
{tabs.slice(0, layout.before).map(button)}
|
|
270
|
+
<div aria-hidden className="h-full shrink-0 grow" style={{ minWidth: layout.spacer }} />
|
|
271
|
+
{tabs.slice(layout.before).map((tab, i) => button(tab, layout.before + i))}
|
|
272
|
+
</div>
|
|
273
|
+
</div>
|
|
274
|
+
</div>
|
|
275
|
+
{trailing && (
|
|
276
|
+
<div ref={end} className="flex shrink-0 items-center">
|
|
277
|
+
{trailing}
|
|
278
|
+
</div>
|
|
279
|
+
)}
|
|
280
|
+
</div>
|
|
281
|
+
)
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export type { IslandTab, IslandTabsProps }
|
|
285
|
+
export { IslandTabs }
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import Widget from './index'
|
|
2
|
+
import Button from '@justanarthur/modo-ui/components/actions/button'
|
|
3
|
+
import { WidgetIsland } from '../../../mock/island-content'
|
|
4
|
+
import { BatteryCharging, Bell, CalendarDays, Clock, MapPin, Pause, Play, Plug, Sparkles, Zap } from 'lucide-react'
|
|
5
|
+
|
|
6
|
+
# Anatomy
|
|
7
|
+
|
|
8
|
+
A context line, the hero (a number on the display role, a name on the title role), its supporting facts, quiet actions, and a supporting column past the hairline.
|
|
9
|
+
|
|
10
|
+
<WidgetIsland tab="system">
|
|
11
|
+
<Widget
|
|
12
|
+
aside={
|
|
13
|
+
<Widget.Section label="Recent">
|
|
14
|
+
<Widget.Row leading="9:12" color="var(--badge-green)">Plugged in at 41%</Widget.Row>
|
|
15
|
+
<Widget.Row leading="8:03" color="var(--badge-amber)" trailing="Low power">Dropped to 20%</Widget.Row>
|
|
16
|
+
<Widget.Row leading="Yesterday">Fully charged</Widget.Row>
|
|
17
|
+
</Widget.Section>
|
|
18
|
+
}
|
|
19
|
+
>
|
|
20
|
+
<Widget.Header icon={BatteryCharging} trailing={<Widget.Action icon={Bell} label="Notify when full" pressed />}>
|
|
21
|
+
MacBook Pro
|
|
22
|
+
</Widget.Header>
|
|
23
|
+
<Widget.Figure value="82" unit="%" color="var(--badge-green)" />
|
|
24
|
+
<Widget.Title>Charging</Widget.Title>
|
|
25
|
+
<Widget.Meta>
|
|
26
|
+
<Widget.MetaItem icon={Clock}>38 min until full</Widget.MetaItem>
|
|
27
|
+
<Widget.MetaItem icon={Plug}>96 W adapter</Widget.MetaItem>
|
|
28
|
+
</Widget.Meta>
|
|
29
|
+
</Widget>
|
|
30
|
+
</WidgetIsland>
|
|
31
|
+
|
|
32
|
+
# Figure
|
|
33
|
+
|
|
34
|
+
`Widget.Figure` sets a number on the display role with its unit (or a word before it) on the title role, digits tabular; `color` takes a data color.
|
|
35
|
+
|
|
36
|
+
<div className="dark flex flex-wrap items-baseline gap-8 rounded-xl bg-ink p-5 text-foreground">
|
|
37
|
+
<Widget.Figure prefix="in" value="12" unit="min" />
|
|
38
|
+
<Widget.Figure value="Now" unit="35 min left" />
|
|
39
|
+
<Widget.Figure value="4:00" unit="PM" />
|
|
40
|
+
<Widget.Figure value="82" unit="%" color="var(--badge-green)" />
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
# Actions
|
|
44
|
+
|
|
45
|
+
`Widget.Action` is a ghost icon button with a tooltip; `pressed` lights a toggle (in a data `color` if given), `emphasis="primary"` is the widget's main action.
|
|
46
|
+
|
|
47
|
+
<div className="dark flex items-center gap-1 rounded-xl bg-ink p-4 text-foreground">
|
|
48
|
+
<Widget.Action icon={Play} label="Play" emphasis="primary" filled />
|
|
49
|
+
<Widget.Action icon={Pause} label="Pause" />
|
|
50
|
+
<Widget.Action icon={Sparkles} label="Enhance" pressed color="var(--badge-violet)" />
|
|
51
|
+
<Widget.Action icon={Zap} label="Low power" disabled />
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
# Rows and chips
|
|
55
|
+
|
|
56
|
+
`Widget.Row` is the island's list row: a muted figure, a color mark, the title and a muted end; `Widget.Chip` a small label one surface up.
|
|
57
|
+
|
|
58
|
+
<div className="dark flex w-full max-w-90 flex-col rounded-xl bg-ink p-4 text-foreground">
|
|
59
|
+
<Widget.Section label="Later today" trailing={<Widget.Chip color="var(--badge-green)">Team offsite</Widget.Chip>}>
|
|
60
|
+
<Widget.Row leading="12:45" color="var(--badge-orange)">Lunch with Ana</Widget.Row>
|
|
61
|
+
<Widget.Row leading="16:00" color="var(--badge-violet)" trailing={<MapPin size={12} strokeWidth={1.5} />}>Ship the island kit</Widget.Row>
|
|
62
|
+
</Widget.Section>
|
|
63
|
+
</div>
|
|
64
|
+
|
|
65
|
+
# Message
|
|
66
|
+
|
|
67
|
+
The empty, permission and error state, across the wide, short island.
|
|
68
|
+
|
|
69
|
+
<WidgetIsland tab="calendar">
|
|
70
|
+
<Widget.Message
|
|
71
|
+
icon={CalendarDays}
|
|
72
|
+
title="See what's next"
|
|
73
|
+
description="Your next event with a countdown, and the rest of today and tomorrow."
|
|
74
|
+
actions={<Button size="compact">Connect calendar</Button>}
|
|
75
|
+
/>
|
|
76
|
+
</WidgetIsland>
|