@mrpelz/uikit-ish 0.0.0-stage → 7.8.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/dist/components/action-sheet/main.d.ts +39 -0
- package/dist/components/action-sheet/main.d.ts.map +1 -0
- package/dist/components/action-sheet/main.js +35 -0
- package/dist/components/action-sheet/main.js.map +1 -0
- package/dist/components/action-sheet/props.d.ts +10 -0
- package/dist/components/action-sheet/props.d.ts.map +1 -0
- package/dist/components/action-sheet/props.js +2 -0
- package/dist/components/action-sheet/props.js.map +1 -0
- package/dist/components/action-sheet/style.css +8 -0
- package/dist/components/activity-view/main.d.ts +45 -0
- package/dist/components/activity-view/main.d.ts.map +1 -0
- package/dist/components/activity-view/main.js +64 -0
- package/dist/components/activity-view/main.js.map +1 -0
- package/dist/components/activity-view/props.d.ts +12 -0
- package/dist/components/activity-view/props.d.ts.map +1 -0
- package/dist/components/activity-view/props.js +2 -0
- package/dist/components/activity-view/props.js.map +1 -0
- package/dist/components/activity-view/style.css +209 -0
- package/dist/components/alert/main.d.ts +53 -0
- package/dist/components/alert/main.d.ts.map +1 -0
- package/dist/components/alert/main.js +57 -0
- package/dist/components/alert/main.js.map +1 -0
- package/dist/components/alert/props.d.ts +18 -0
- package/dist/components/alert/props.d.ts.map +1 -0
- package/dist/components/alert/props.js +2 -0
- package/dist/components/alert/props.js.map +1 -0
- package/dist/components/alert/style.css +205 -0
- package/dist/components/avatar/main.d.ts +20 -0
- package/dist/components/avatar/main.d.ts.map +1 -0
- package/dist/components/avatar/main.js +42 -0
- package/dist/components/avatar/main.js.map +1 -0
- package/dist/components/avatar/props.d.ts +18 -0
- package/dist/components/avatar/props.d.ts.map +1 -0
- package/dist/components/avatar/props.js +2 -0
- package/dist/components/avatar/props.js.map +1 -0
- package/dist/components/avatar/style.css +83 -0
- package/dist/components/badge/main.d.ts +12 -0
- package/dist/components/badge/main.d.ts.map +1 -0
- package/dist/components/badge/main.js +33 -0
- package/dist/components/badge/main.js.map +1 -0
- package/dist/components/badge/props.d.ts +20 -0
- package/dist/components/badge/props.d.ts.map +1 -0
- package/dist/components/badge/props.js +2 -0
- package/dist/components/badge/props.js.map +1 -0
- package/dist/components/badge/style.css +71 -0
- package/dist/components/button/main.d.ts +16 -0
- package/dist/components/button/main.d.ts.map +1 -0
- package/dist/components/button/main.js +64 -0
- package/dist/components/button/main.js.map +1 -0
- package/dist/components/button/props.d.ts +45 -0
- package/dist/components/button/props.d.ts.map +1 -0
- package/dist/components/button/props.js +2 -0
- package/dist/components/button/props.js.map +1 -0
- package/dist/components/button/style.css +338 -0
- package/dist/components/checkbox/main.d.ts +23 -0
- package/dist/components/checkbox/main.d.ts.map +1 -0
- package/dist/components/checkbox/main.js +43 -0
- package/dist/components/checkbox/main.js.map +1 -0
- package/dist/components/checkbox/props.d.ts +14 -0
- package/dist/components/checkbox/props.d.ts.map +1 -0
- package/dist/components/checkbox/props.js +2 -0
- package/dist/components/checkbox/props.js.map +1 -0
- package/dist/components/checkbox/style.css +73 -0
- package/dist/components/color-picker/main.d.ts +31 -0
- package/dist/components/color-picker/main.d.ts.map +1 -0
- package/dist/components/color-picker/main.js +356 -0
- package/dist/components/color-picker/main.js.map +1 -0
- package/dist/components/color-picker/props.d.ts +61 -0
- package/dist/components/color-picker/props.d.ts.map +1 -0
- package/dist/components/color-picker/props.js +2 -0
- package/dist/components/color-picker/props.js.map +1 -0
- package/dist/components/color-picker/style.css +374 -0
- package/dist/components/contextual-menu/main.d.ts +84 -0
- package/dist/components/contextual-menu/main.d.ts.map +1 -0
- package/dist/components/contextual-menu/main.js +255 -0
- package/dist/components/contextual-menu/main.js.map +1 -0
- package/dist/components/contextual-menu/props.d.ts +44 -0
- package/dist/components/contextual-menu/props.d.ts.map +1 -0
- package/dist/components/contextual-menu/props.js +2 -0
- package/dist/components/contextual-menu/props.js.map +1 -0
- package/dist/components/contextual-menu/style.css +80 -0
- package/dist/components/date-picker/main.d.ts +57 -0
- package/dist/components/date-picker/main.d.ts.map +1 -0
- package/dist/components/date-picker/main.js +770 -0
- package/dist/components/date-picker/main.js.map +1 -0
- package/dist/components/date-picker/props.d.ts +220 -0
- package/dist/components/date-picker/props.d.ts.map +1 -0
- package/dist/components/date-picker/props.js +2 -0
- package/dist/components/date-picker/props.js.map +1 -0
- package/dist/components/date-picker/style.css +446 -0
- package/dist/components/edit-menu/main.d.ts +71 -0
- package/dist/components/edit-menu/main.d.ts.map +1 -0
- package/dist/components/edit-menu/main.js +317 -0
- package/dist/components/edit-menu/main.js.map +1 -0
- package/dist/components/edit-menu/props.d.ts +21 -0
- package/dist/components/edit-menu/props.d.ts.map +1 -0
- package/dist/components/edit-menu/props.js +2 -0
- package/dist/components/edit-menu/props.js.map +1 -0
- package/dist/components/edit-menu/style.css +189 -0
- package/dist/components/form/main.d.ts +21 -0
- package/dist/components/form/main.d.ts.map +1 -0
- package/dist/components/form/main.js +32 -0
- package/dist/components/form/main.js.map +1 -0
- package/dist/components/form/props.d.ts +4 -0
- package/dist/components/form/props.d.ts.map +1 -0
- package/dist/components/form/props.js +2 -0
- package/dist/components/form/props.js.map +1 -0
- package/dist/components/form/style.css +9 -0
- package/dist/components/glass/main.d.ts +34 -0
- package/dist/components/glass/main.d.ts.map +1 -0
- package/dist/components/glass/main.js +157 -0
- package/dist/components/glass/main.js.map +1 -0
- package/dist/components/glass/props.d.ts +22 -0
- package/dist/components/glass/props.d.ts.map +1 -0
- package/dist/components/glass/props.js +2 -0
- package/dist/components/glass/props.js.map +1 -0
- package/dist/components/glass/style.css +488 -0
- package/dist/components/header/main.d.ts +15 -0
- package/dist/components/header/main.d.ts.map +1 -0
- package/dist/components/header/main.js +78 -0
- package/dist/components/header/main.js.map +1 -0
- package/dist/components/header/props.d.ts +16 -0
- package/dist/components/header/props.d.ts.map +1 -0
- package/dist/components/header/props.js +2 -0
- package/dist/components/header/props.js.map +1 -0
- package/dist/components/header/style.css +119 -0
- package/dist/components/index.d.ts +38 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +45 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/layout/main.d.ts +15 -0
- package/dist/components/layout/main.d.ts.map +1 -0
- package/dist/components/layout/main.js +241 -0
- package/dist/components/layout/main.js.map +1 -0
- package/dist/components/layout/props.d.ts +52 -0
- package/dist/components/layout/props.d.ts.map +1 -0
- package/dist/components/layout/props.js +2 -0
- package/dist/components/layout/props.js.map +1 -0
- package/dist/components/layout/style.css +208 -0
- package/dist/components/list/main.d.ts +104 -0
- package/dist/components/list/main.d.ts.map +1 -0
- package/dist/components/list/main.js +1553 -0
- package/dist/components/list/main.js.map +1 -0
- package/dist/components/list/props.d.ts +178 -0
- package/dist/components/list/props.d.ts.map +1 -0
- package/dist/components/list/props.js +2 -0
- package/dist/components/list/props.js.map +1 -0
- package/dist/components/list/style.css +1689 -0
- package/dist/components/menu/main.d.ts +119 -0
- package/dist/components/menu/main.d.ts.map +1 -0
- package/dist/components/menu/main.js +487 -0
- package/dist/components/menu/main.js.map +1 -0
- package/dist/components/menu/props.d.ts +54 -0
- package/dist/components/menu/props.d.ts.map +1 -0
- package/dist/components/menu/props.js +2 -0
- package/dist/components/menu/props.js.map +1 -0
- package/dist/components/menu/style.css +446 -0
- package/dist/components/navigation/main.d.ts +9 -0
- package/dist/components/navigation/main.d.ts.map +1 -0
- package/dist/components/navigation/main.js +201 -0
- package/dist/components/navigation/main.js.map +1 -0
- package/dist/components/navigation/props.d.ts +16 -0
- package/dist/components/navigation/props.d.ts.map +1 -0
- package/dist/components/navigation/props.js +2 -0
- package/dist/components/navigation/props.js.map +1 -0
- package/dist/components/navigation/style.css +83 -0
- package/dist/components/page/main.d.ts +9 -0
- package/dist/components/page/main.d.ts.map +1 -0
- package/dist/components/page/main.js +20 -0
- package/dist/components/page/main.js.map +1 -0
- package/dist/components/page/props.d.ts +10 -0
- package/dist/components/page/props.d.ts.map +1 -0
- package/dist/components/page/props.js +2 -0
- package/dist/components/page/props.js.map +1 -0
- package/dist/components/page/style.css +19 -0
- package/dist/components/page-control/main.d.ts +13 -0
- package/dist/components/page-control/main.d.ts.map +1 -0
- package/dist/components/page-control/main.js +138 -0
- package/dist/components/page-control/main.js.map +1 -0
- package/dist/components/page-control/props.d.ts +36 -0
- package/dist/components/page-control/props.d.ts.map +1 -0
- package/dist/components/page-control/props.js +2 -0
- package/dist/components/page-control/props.js.map +1 -0
- package/dist/components/page-control/style.css +111 -0
- package/dist/components/popover/main.d.ts +34 -0
- package/dist/components/popover/main.d.ts.map +1 -0
- package/dist/components/popover/main.js +232 -0
- package/dist/components/popover/main.js.map +1 -0
- package/dist/components/popover/props.d.ts +23 -0
- package/dist/components/popover/props.d.ts.map +1 -0
- package/dist/components/popover/props.js +2 -0
- package/dist/components/popover/props.js.map +1 -0
- package/dist/components/popover/style.css +160 -0
- package/dist/components/progress/main.d.ts +31 -0
- package/dist/components/progress/main.d.ts.map +1 -0
- package/dist/components/progress/main.js +77 -0
- package/dist/components/progress/main.js.map +1 -0
- package/dist/components/progress/props.d.ts +56 -0
- package/dist/components/progress/props.d.ts.map +1 -0
- package/dist/components/progress/props.js +2 -0
- package/dist/components/progress/props.js.map +1 -0
- package/dist/components/progress/style.css +264 -0
- package/dist/components/roll/main.d.ts +18 -0
- package/dist/components/roll/main.d.ts.map +1 -0
- package/dist/components/roll/main.js +463 -0
- package/dist/components/roll/main.js.map +1 -0
- package/dist/components/roll/props.d.ts +58 -0
- package/dist/components/roll/props.d.ts.map +1 -0
- package/dist/components/roll/props.js +2 -0
- package/dist/components/roll/props.js.map +1 -0
- package/dist/components/roll/style.css +173 -0
- package/dist/components/segmented/main.d.ts +17 -0
- package/dist/components/segmented/main.d.ts.map +1 -0
- package/dist/components/segmented/main.js +151 -0
- package/dist/components/segmented/main.js.map +1 -0
- package/dist/components/segmented/props.d.ts +16 -0
- package/dist/components/segmented/props.d.ts.map +1 -0
- package/dist/components/segmented/props.js +2 -0
- package/dist/components/segmented/props.js.map +1 -0
- package/dist/components/segmented/style.css +428 -0
- package/dist/components/sheet/main.d.ts +32 -0
- package/dist/components/sheet/main.d.ts.map +1 -0
- package/dist/components/sheet/main.js +101 -0
- package/dist/components/sheet/main.js.map +1 -0
- package/dist/components/sheet/props.d.ts +11 -0
- package/dist/components/sheet/props.d.ts.map +1 -0
- package/dist/components/sheet/props.js +2 -0
- package/dist/components/sheet/props.js.map +1 -0
- package/dist/components/sheet/style.css +125 -0
- package/dist/components/sidebar/main.d.ts +15 -0
- package/dist/components/sidebar/main.d.ts.map +1 -0
- package/dist/components/sidebar/main.js +42 -0
- package/dist/components/sidebar/main.js.map +1 -0
- package/dist/components/sidebar/props.d.ts +5 -0
- package/dist/components/sidebar/props.d.ts.map +1 -0
- package/dist/components/sidebar/props.js +2 -0
- package/dist/components/sidebar/props.js.map +1 -0
- package/dist/components/sidebar/style.css +94 -0
- package/dist/components/slider/main.d.ts +35 -0
- package/dist/components/slider/main.d.ts.map +1 -0
- package/dist/components/slider/main.js +153 -0
- package/dist/components/slider/main.js.map +1 -0
- package/dist/components/slider/props.d.ts +56 -0
- package/dist/components/slider/props.d.ts.map +1 -0
- package/dist/components/slider/props.js +2 -0
- package/dist/components/slider/props.js.map +1 -0
- package/dist/components/slider/style.css +345 -0
- package/dist/components/stepper/main.d.ts +22 -0
- package/dist/components/stepper/main.d.ts.map +1 -0
- package/dist/components/stepper/main.js +56 -0
- package/dist/components/stepper/main.js.map +1 -0
- package/dist/components/stepper/props.d.ts +10 -0
- package/dist/components/stepper/props.d.ts.map +1 -0
- package/dist/components/stepper/props.js +2 -0
- package/dist/components/stepper/props.js.map +1 -0
- package/dist/components/stepper/style.css +115 -0
- package/dist/components/switch/main.d.ts +14 -0
- package/dist/components/switch/main.d.ts.map +1 -0
- package/dist/components/switch/main.js +143 -0
- package/dist/components/switch/main.js.map +1 -0
- package/dist/components/switch/props.d.ts +34 -0
- package/dist/components/switch/props.d.ts.map +1 -0
- package/dist/components/switch/props.js +2 -0
- package/dist/components/switch/props.js.map +1 -0
- package/dist/components/switch/style.css +168 -0
- package/dist/components/symbol/main.d.ts +8 -0
- package/dist/components/symbol/main.d.ts.map +1 -0
- package/dist/components/symbol/main.js +32 -0
- package/dist/components/symbol/main.js.map +1 -0
- package/dist/components/symbol/props.d.ts +10 -0
- package/dist/components/symbol/props.d.ts.map +1 -0
- package/dist/components/symbol/props.js +2 -0
- package/dist/components/symbol/props.js.map +1 -0
- package/dist/components/symbol/style.css +26 -0
- package/dist/components/tab-bar/main.d.ts +39 -0
- package/dist/components/tab-bar/main.d.ts.map +1 -0
- package/dist/components/tab-bar/main.js +1133 -0
- package/dist/components/tab-bar/main.js.map +1 -0
- package/dist/components/tab-bar/props.d.ts +152 -0
- package/dist/components/tab-bar/props.d.ts.map +1 -0
- package/dist/components/tab-bar/props.js +2 -0
- package/dist/components/tab-bar/props.js.map +1 -0
- package/dist/components/tab-bar/style.css +936 -0
- package/dist/components/text-field/main.d.ts +28 -0
- package/dist/components/text-field/main.d.ts.map +1 -0
- package/dist/components/text-field/main.js +105 -0
- package/dist/components/text-field/main.js.map +1 -0
- package/dist/components/text-field/props.d.ts +3 -0
- package/dist/components/text-field/props.d.ts.map +1 -0
- package/dist/components/text-field/props.js +2 -0
- package/dist/components/text-field/props.js.map +1 -0
- package/dist/components/text-field/style.css +230 -0
- package/dist/components/toolbar/main.d.ts +37 -0
- package/dist/components/toolbar/main.d.ts.map +1 -0
- package/dist/components/toolbar/main.js +142 -0
- package/dist/components/toolbar/main.js.map +1 -0
- package/dist/components/toolbar/props.d.ts +46 -0
- package/dist/components/toolbar/props.d.ts.map +1 -0
- package/dist/components/toolbar/props.js +2 -0
- package/dist/components/toolbar/props.js.map +1 -0
- package/dist/components/toolbar/style.css +210 -0
- package/dist/components/tooltip/main.d.ts +29 -0
- package/dist/components/tooltip/main.d.ts.map +1 -0
- package/dist/components/tooltip/main.js +37 -0
- package/dist/components/tooltip/main.js.map +1 -0
- package/dist/components/tooltip/props.d.ts +11 -0
- package/dist/components/tooltip/props.d.ts.map +1 -0
- package/dist/components/tooltip/props.js +2 -0
- package/dist/components/tooltip/props.js.map +1 -0
- package/dist/components/tooltip/style.css +29 -0
- package/dist/components/typography/main.d.ts +8 -0
- package/dist/components/typography/main.d.ts.map +1 -0
- package/dist/components/typography/main.js +21 -0
- package/dist/components/typography/main.js.map +1 -0
- package/dist/components/typography/props.d.ts +35 -0
- package/dist/components/typography/props.d.ts.map +1 -0
- package/dist/components/typography/props.js +2 -0
- package/dist/components/typography/props.js.map +1 -0
- package/dist/components/typography/style.css +719 -0
- package/dist/components/utils/main.d.ts +114 -0
- package/dist/components/utils/main.d.ts.map +1 -0
- package/dist/components/utils/main.js +431 -0
- package/dist/components/utils/main.js.map +1 -0
- package/dist/components/utils/props.d.ts +52 -0
- package/dist/components/utils/props.d.ts.map +1 -0
- package/dist/components/utils/props.js +2 -0
- package/dist/components/utils/props.js.map +1 -0
- package/dist/components/utils/style.css +77 -0
- package/dist/components/viewport/main.d.ts +32 -0
- package/dist/components/viewport/main.d.ts.map +1 -0
- package/dist/components/viewport/main.js +197 -0
- package/dist/components/viewport/main.js.map +1 -0
- package/dist/components/viewport/props.d.ts +71 -0
- package/dist/components/viewport/props.d.ts.map +1 -0
- package/dist/components/viewport/props.js +2 -0
- package/dist/components/viewport/props.js.map +1 -0
- package/dist/components/viewport/style.css +112 -0
- package/dist/main.d.ts +4 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +3 -0
- package/dist/main.js.map +1 -0
- package/dist/styles.css +567 -0
- package/dist/styles.d.ts +25 -0
- package/dist/styles.d.ts.map +1 -0
- package/dist/styles.js +39 -0
- package/dist/styles.js.map +1 -0
- package/package.json +55 -4
- package/README.md +0 -3
|
@@ -0,0 +1,1133 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import '../glass/style.css';
|
|
3
|
+
import './style.css';
|
|
4
|
+
import { Tabs as BaseTabs } from '@base-ui/react/tabs';
|
|
5
|
+
import { createContext, forwardRef, useCallback, useContext, useId, useLayoutEffect, useMemo, useRef, useState, } from 'react';
|
|
6
|
+
import { GlassBackground } from '../glass/main.js';
|
|
7
|
+
import { cn, edgeScrollDelta, frameElapsed, useForwardedRef, usePointerDrag, useSecondaryClick, withStyle, } from '../utils/main.js';
|
|
8
|
+
// Source: Apple iOS 26 Figma (“Tab Bar - iPhone”, BG Context Dim/Bright), with
|
|
9
|
+
// the selected content color mapped to the app tint (`--color-ios-primary`,
|
|
10
|
+
// i.e. `systemBlue`); glass materials, vibrant content and selection colors are
|
|
11
|
+
// tokens in `styles.css`, used via `glass/main.tsx`. The selection's transition
|
|
12
|
+
// duration comes from Framework7 `components/toolbar/toolbar-ios.less`
|
|
13
|
+
// (`.tab-link-highlight`), disabled opacity from Framework7 `less/mixins.less`
|
|
14
|
+
// (`.disabled()`).
|
|
15
|
+
//
|
|
16
|
+
// In the regular size, symbols and labels are in the Subheadline text style
|
|
17
|
+
// (selected labels: 17px, bold); the compact size's (17/28px, 10/12px) are in
|
|
18
|
+
// none.
|
|
19
|
+
//
|
|
20
|
+
// Deviations:
|
|
21
|
+
// - The list's `size` (UIKit size class) switches between the iPhone and the
|
|
22
|
+
// iPad tab bar, for all its groups; tabs hold a symbol, a label or both in
|
|
23
|
+
// either: - `compact` (Figma “Tab Bar - iPhone”): content stacked, 54px high,
|
|
24
|
+
// with a preferred (shrinkable, not fixed) width of 102px, down to a minimum
|
|
25
|
+
// of 54px (Figma: 102px, or filling the bar with 4+ tabs); `width` is used as
|
|
26
|
+
// `flex-basis` is ignored for the group's intrinsic size. A single tab next
|
|
27
|
+
// to the search tab is 102px (Figma: 110px). Neighbors overlap. - `regular`
|
|
28
|
+
// (Figma “Tab Bar - iPad”): content in a row, 36px high, hugging it (Figma:
|
|
29
|
+
// stretching to the bar's width), with larger labels that grow when selected
|
|
30
|
+
// and smaller symbols; white selected content on dim glass (iPhone: the
|
|
31
|
+
// tint). The selection is the same token as the iPhone's (Figma: #EDEDED for
|
|
32
|
+
// symbol tabs, rgb(118 118 128 / 12%) for text tabs in the bright context,
|
|
33
|
+
// one or two levels apart). Symbol-only tabs are circles in the compact size
|
|
34
|
+
// (Figma: iPhone search) and capsules hugging the symbol in the regular size
|
|
35
|
+
// (Figma: iPad sidebar and search, 50×36), but circles alone in a group;
|
|
36
|
+
// others capsules; a tab's (or its group's) `shape` overrides this (`circle`:
|
|
37
|
+
// a circle in both sizes). Labels reserve their selected width, so selecting
|
|
38
|
+
// a tab doesn't shift the tabs.
|
|
39
|
+
// - The bar's inline padding is always 32px (Figma: 28px with up to 3 tabs).
|
|
40
|
+
// - In a bar wider than its groups, the space between them widens (Figma:
|
|
41
|
+
// groups centered), the first at the bar's start, as when collapsed.
|
|
42
|
+
// - Nothing isolates blending (Figma: each group), as that would cut the glass
|
|
43
|
+
// blur off from the content behind the bar; glass, indicator and tabs stack
|
|
44
|
+
// by document order instead.
|
|
45
|
+
// - Each group positions its own selection (the indicator) on its active tab.
|
|
46
|
+
// When the active tab leaves a group, its selection fades out in place; a
|
|
47
|
+
// group gaining the active tab fades its selection in, so the selection never
|
|
48
|
+
// travels between groups.
|
|
49
|
+
// - Figma's fill blend modes are applied as `mix-blend-mode` of separate layers
|
|
50
|
+
// (blending with the blurred backdrop), each carrying the fill's opacity.
|
|
51
|
+
// - The blur layer's own `filter: blur(10px)` and masking are omitted.
|
|
52
|
+
// - Figma's glass effect (a layer effect, missing from the CSS export) is
|
|
53
|
+
// emulated as in Framework7 `less/mixins.less` (`.ios-glass()`: backdrop
|
|
54
|
+
// `saturate(180%)` and `--f7-glass-shadow`, see `styles.css`).
|
|
55
|
+
// - Pressing a tab turns the selection into a glass lens that follows the
|
|
56
|
+
// pointer and activates the closest tab on release, as in Framework7
|
|
57
|
+
// `components/toolbar/tabbar-highlight.js` and `toolbar-ios.less`
|
|
58
|
+
// (`.tab-link-highlight-pressed`); unlike Framework7 for all pointer types,
|
|
59
|
+
// not only touch. The lens belongs to the list, so it moves (and can be
|
|
60
|
+
// dragged) between groups, and is drawn above the tabs, as it has to be above
|
|
61
|
+
// the groups' glass. While dragging, it follows the pointer without a
|
|
62
|
+
// transition (Framework7: 300ms ease-out).
|
|
63
|
+
// - The browser's default focus ring is kept.
|
|
64
|
+
// Metrics of tabs and their content per size, inherited from the list. Tabs
|
|
65
|
+
// of the compact size shrink to fit their group, down to their content's
|
|
66
|
+
// width; those of the regular size keep it. Beyond that, the group scrolls
|
|
67
|
+
// (see `StyledTabs`).
|
|
68
|
+
// (See style.css.)
|
|
69
|
+
// Marks a tab's symbol and label, so a tab can lay out by its content, and
|
|
70
|
+
const setProperties = (element, properties) => {
|
|
71
|
+
for (const [property, value] of Object.entries(properties)) {
|
|
72
|
+
element.style.setProperty(property, value);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const isTab = (element) => element instanceof HTMLElement && element.getAttribute('role') === 'tab';
|
|
76
|
+
const isActive = (element) => Object.hasOwn(element.dataset, 'active');
|
|
77
|
+
// A group's tabs (and its selection) are in its scroller, inside its glass.
|
|
78
|
+
const scrollerOf = (group) => group.querySelector(':scope > [data-tab-bar-part=tabs]');
|
|
79
|
+
const groupOf = (tab) => tab.parentElement?.parentElement ?? null;
|
|
80
|
+
const tabsOf = (group) => [...(scrollerOf(group)?.children ?? [])].filter(isTab);
|
|
81
|
+
// The position of an element in the layout of the scroller containing it
|
|
82
|
+
// (unaffected by scrolling and transforms).
|
|
83
|
+
const offsetIn = (element, scroller) => {
|
|
84
|
+
let x = 0;
|
|
85
|
+
let y = 0;
|
|
86
|
+
for (let current = element; current instanceof HTMLElement && current !== scroller; current = current.offsetParent) {
|
|
87
|
+
x += current.offsetLeft;
|
|
88
|
+
y += current.offsetTop;
|
|
89
|
+
}
|
|
90
|
+
return { x, y };
|
|
91
|
+
};
|
|
92
|
+
// How far a group's scroller scrolls by its tabs' layout (not by their
|
|
93
|
+
// content, which grows beyond while pressed, see `pressGroup`). By their
|
|
94
|
+
// boxes (tabs aren't transformed, only their content), as `offsetLeft` and
|
|
95
|
+
// `offsetWidth` round, together off by up to a pixel.
|
|
96
|
+
const scrollRange = (scroller) => {
|
|
97
|
+
const origin = scroller.getBoundingClientRect().left +
|
|
98
|
+
scroller.clientLeft -
|
|
99
|
+
scroller.scrollLeft;
|
|
100
|
+
return (Math.max(0, ...[...scroller.children]
|
|
101
|
+
.filter(isTab)
|
|
102
|
+
.map((tab) => tab.getBoundingClientRect().right - origin)) - scroller.clientWidth);
|
|
103
|
+
};
|
|
104
|
+
// Only a group too narrow for its tabs clips them: others show their
|
|
105
|
+
// content growing beyond while pressed.
|
|
106
|
+
const updateOverflow = (group) => {
|
|
107
|
+
const scroller = scrollerOf(group);
|
|
108
|
+
scroller?.toggleAttribute('data-overflowing', scrollRange(scroller) > 1);
|
|
109
|
+
};
|
|
110
|
+
// A tab's box as far as its group shows it, or `undefined` if scrolled out
|
|
111
|
+
// of view.
|
|
112
|
+
const visibleRect = (tab) => {
|
|
113
|
+
const rect = tab.getBoundingClientRect();
|
|
114
|
+
const { parentElement: scroller } = tab;
|
|
115
|
+
if (!scroller)
|
|
116
|
+
return rect;
|
|
117
|
+
const clip = scroller.getBoundingClientRect();
|
|
118
|
+
const left = Math.max(rect.left, clip.left);
|
|
119
|
+
const right = Math.min(rect.right, clip.right);
|
|
120
|
+
return right - left > 1
|
|
121
|
+
? new DOMRect(left, rect.top, right - left, rect.height)
|
|
122
|
+
: undefined;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Scrolls a group to show `tab` entirely, if it doesn't. Scrolls to a
|
|
126
|
+
* position rather than by a distance, so repeating it while scrolling
|
|
127
|
+
* doesn't scroll further.
|
|
128
|
+
*/
|
|
129
|
+
const reveal = (tab, behavior = 'smooth') => {
|
|
130
|
+
const { parentElement: scroller } = tab;
|
|
131
|
+
if (!scroller)
|
|
132
|
+
return;
|
|
133
|
+
const { x } = offsetIn(tab, scroller);
|
|
134
|
+
const left = Math.min(x, scroller.scrollLeft);
|
|
135
|
+
const target = Math.max(left, x + tab.offsetWidth - scroller.clientWidth);
|
|
136
|
+
if (Math.abs(target - scroller.scrollLeft) < 1)
|
|
137
|
+
return;
|
|
138
|
+
scroller.scrollTo({ behavior, left: target });
|
|
139
|
+
};
|
|
140
|
+
// Groups that had an active tab when their selection was last positioned.
|
|
141
|
+
const hadActiveTab = new WeakMap();
|
|
142
|
+
const setSelection = (group, rect, { instant = false, left = rect.left } = {}) => {
|
|
143
|
+
// Positioned in its scroller's content, so it scrolls with the tabs.
|
|
144
|
+
const scroller = scrollerOf(group);
|
|
145
|
+
if (!scroller)
|
|
146
|
+
return;
|
|
147
|
+
const scrollerRect = scroller.getBoundingClientRect();
|
|
148
|
+
const originX = scrollerRect.left + scroller.clientLeft - scroller.scrollLeft;
|
|
149
|
+
const originY = scrollerRect.top + scroller.clientTop - scroller.scrollTop;
|
|
150
|
+
if (instant) {
|
|
151
|
+
group.style.setProperty('--uikit-tab-bar-selection-duration', '0s');
|
|
152
|
+
}
|
|
153
|
+
setProperties(group, {
|
|
154
|
+
'--uikit-tab-bar-selection-height': `${rect.height}px`,
|
|
155
|
+
'--uikit-tab-bar-selection-left': `${left - originX}px`,
|
|
156
|
+
'--uikit-tab-bar-selection-top': `${rect.top - originY}px`,
|
|
157
|
+
'--uikit-tab-bar-selection-width': `${rect.width}px`,
|
|
158
|
+
});
|
|
159
|
+
if (instant) {
|
|
160
|
+
group.getBoundingClientRect();
|
|
161
|
+
group.style.removeProperty('--uikit-tab-bar-selection-duration');
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
// Positions a group's selection on its active tab and shows it; without an
|
|
165
|
+
// active tab, the selection fades out in place. A selection appearing in a
|
|
166
|
+
// group is placed instantly, so it does not travel in from elsewhere.
|
|
167
|
+
const updateSelection = (group, { instant = false } = {}) => {
|
|
168
|
+
const tab = tabsOf(group).find((child) => isActive(child));
|
|
169
|
+
const hadActive = hadActiveTab.get(group) ?? false;
|
|
170
|
+
hadActiveTab.set(group, Boolean(tab));
|
|
171
|
+
group.style.setProperty('--uikit-tab-bar-selection-opacity', tab ? '1' : '0');
|
|
172
|
+
if (!tab)
|
|
173
|
+
return;
|
|
174
|
+
group.style.removeProperty('--uikit-tab-bar-pressed');
|
|
175
|
+
setSelection(group, tab.getBoundingClientRect(), {
|
|
176
|
+
instant: instant || !hadActive,
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
// Collapsed (measured on iOS 26, iPhone): the bar is 48pt high instead of
|
|
180
|
+
// 62pt around the same center line, 7pt further in from the edges. The
|
|
181
|
+
// groups and tabs marked `visibleWhenCollapsed` remain (and only those: what
|
|
182
|
+
// remains is the app's to decide, e.g. by `collapsedSelection`), the others
|
|
183
|
+
// collapse away; each group at its `collapsedPosition` (or the list's),
|
|
184
|
+
// groups at the same one side by side: ordered by position between two
|
|
185
|
+
// spacers, the list's pseudo-elements, which take up the free space. Tabs
|
|
186
|
+
// show `collapsedContent`, in the content color, the selection faded out
|
|
187
|
+
// (with several remaining tabs, on the active one, if it's among them): a
|
|
188
|
+
// symbol in a 40pt circle, or a label (and symbol, side by side, in the
|
|
189
|
+
// regular size's metrics) in a capsule. The bar keeps its size (see `List`).
|
|
190
|
+
// The regular size (iPad doesn't minimize its tab bar) keeps its height.
|
|
191
|
+
/**
|
|
192
|
+
* A choice of what remains while collapsed (for `visibleWhenCollapsed`), as
|
|
193
|
+
* iOS's: the active tab (by its value, among the groups' tab values) and its
|
|
194
|
+
* group; without one, the first group's first tab. Every group's `tab` is
|
|
195
|
+
* its active tab, or its first (for groups the app keeps, too).
|
|
196
|
+
*/
|
|
197
|
+
export const collapsedSelection = (groups, value) => {
|
|
198
|
+
const active = groups.findIndex((tabs) => tabs.includes(value));
|
|
199
|
+
const remaining = Math.max(active, 0);
|
|
200
|
+
return groups.map((tabs, index) => ({
|
|
201
|
+
remains: index === remaining,
|
|
202
|
+
tab: Math.max(tabs.indexOf(value), 0),
|
|
203
|
+
}));
|
|
204
|
+
};
|
|
205
|
+
// The order of groups by their position, around the spacers (1 and 3).
|
|
206
|
+
const collapsedOrder = {
|
|
207
|
+
center: 2,
|
|
208
|
+
'inline-end': 4,
|
|
209
|
+
'inline-start': 0,
|
|
210
|
+
};
|
|
211
|
+
// What a collapsed tab shows, as custom properties used by the list's styles
|
|
212
|
+
// (`collapsedList`): set on the list (its `collapsedContent`), or on a tab
|
|
213
|
+
// (its own, which wins). Symbols in a capsule take the regular size's
|
|
214
|
+
// metrics; `initial` leaves a tab's own.
|
|
215
|
+
// (See style.css.)
|
|
216
|
+
// A hidden tab: no size, so neither its width nor its aspect ratio (circles)
|
|
217
|
+
// takes up space while it collapses.
|
|
218
|
+
// A remaining tab, as the list's styles show the active one.
|
|
219
|
+
// With several groups marked to remain, they are spaced by transparent
|
|
220
|
+
// borders (see `StyledGroup`), as the list has no gap while collapsed: the
|
|
221
|
+
// groups collapsing away would take it up.
|
|
222
|
+
// (See style.css.)
|
|
223
|
+
// The accessory's height and gap above the groups (see `Accessory`).
|
|
224
|
+
const accessoryHeight = 40;
|
|
225
|
+
const accessoryGap = 16;
|
|
226
|
+
// Enabled tabs, but those a collapsed bar hides (see `collapsedList`).
|
|
227
|
+
const getTabs = (list) => [...list.querySelectorAll('[role="tab"]')].filter((tab) => tab instanceof HTMLElement &&
|
|
228
|
+
!Object.hasOwn(tab.dataset, 'disabled') &&
|
|
229
|
+
getComputedStyle(tab).pointerEvents !== 'none');
|
|
230
|
+
const getGroups = (list) => new Set(getTabs(list)
|
|
231
|
+
.map((tab) => groupOf(tab))
|
|
232
|
+
.filter((group) => group !== null));
|
|
233
|
+
// Places the lens on `rect`, centered at `centerX`, its left and right edges
|
|
234
|
+
// within `bounds` (default: those it has, e.g. settling from a press: the
|
|
235
|
+
// rect's own would pin an edge of the still larger lens).
|
|
236
|
+
const setLens = (list, rect, centerX, bounds) => {
|
|
237
|
+
const listRect = list.getBoundingClientRect();
|
|
238
|
+
const originX = listRect.left + list.clientLeft - list.scrollLeft;
|
|
239
|
+
const originY = listRect.top + list.clientTop - list.scrollTop;
|
|
240
|
+
if (bounds) {
|
|
241
|
+
setProperties(list, {
|
|
242
|
+
'--uikit-tab-bar-lens-max': `${bounds.right - originX}px`,
|
|
243
|
+
'--uikit-tab-bar-lens-min': `${bounds.left - originX}px`,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
setProperties(list, {
|
|
247
|
+
'--uikit-tab-bar-lens-height': `${rect.height}px`,
|
|
248
|
+
'--uikit-tab-bar-lens-width': `${rect.width}px`,
|
|
249
|
+
'--uikit-tab-bar-lens-x': `${centerX - originX}px`,
|
|
250
|
+
'--uikit-tab-bar-lens-y': `${rect.top + rect.height / 2 - originY}px`,
|
|
251
|
+
});
|
|
252
|
+
};
|
|
253
|
+
// Grows the group under the lens (or, with `pressed` false, back): its
|
|
254
|
+
// glass layers scale around their (the group's) center by themselves; its
|
|
255
|
+
// tabs' symbols and labels scale around the group's center too, set as their
|
|
256
|
+
// transform origin. Scaling the group itself would isolate its layers'
|
|
257
|
+
// blending (rendering the glass gray). Called again while the group scrolls,
|
|
258
|
+
// as its center moves over its tabs.
|
|
259
|
+
const pressGroup = (group, pressed) => {
|
|
260
|
+
if (!pressed) {
|
|
261
|
+
delete group.dataset.pressed;
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const scroller = scrollerOf(group);
|
|
265
|
+
if (!scroller)
|
|
266
|
+
return;
|
|
267
|
+
// The group's center in the layout of its scroller (filling the group).
|
|
268
|
+
const centerX = scroller.scrollLeft + scroller.clientWidth / 2;
|
|
269
|
+
const centerY = scroller.scrollTop + scroller.clientHeight / 2;
|
|
270
|
+
// (Symbols scale their glyphs, see `Symbol`.)
|
|
271
|
+
const content = scroller.querySelectorAll('[data-tab-bar-part=icon], [data-tab-bar-part=label], .uikit-symbol-glyph');
|
|
272
|
+
for (const element of content) {
|
|
273
|
+
if (!(element instanceof HTMLElement))
|
|
274
|
+
continue;
|
|
275
|
+
const { x, y } = offsetIn(element, scroller);
|
|
276
|
+
element.style.transformOrigin = `${centerX - x}px ${centerY - y}px`;
|
|
277
|
+
}
|
|
278
|
+
group.dataset.pressed = '';
|
|
279
|
+
};
|
|
280
|
+
/** The index of the rectangle centered closest to `x`. */
|
|
281
|
+
const closest = (rects, x) => {
|
|
282
|
+
const distances = rects.map(({ left, width }) => Math.abs(left + width / 2 - x));
|
|
283
|
+
return distances.indexOf(Math.min(...distances));
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* How a group grows while pressed (see `pressGroup`): its scale, around its
|
|
287
|
+
* center. Its tabs keep their (unscaled) boxes; their content scales.
|
|
288
|
+
*/
|
|
289
|
+
const growth = (group) => {
|
|
290
|
+
const { height, left, top, width } = group.getBoundingClientRect();
|
|
291
|
+
const scale = Number.parseFloat(getComputedStyle(group).getPropertyValue('--uikit-tab-bar-pressed-group-scale'));
|
|
292
|
+
return {
|
|
293
|
+
scale: Number.isFinite(scale) ? scale : 1,
|
|
294
|
+
x: left + width / 2,
|
|
295
|
+
y: top + height / 2,
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
// Moves the lens to the pointer, clamped to the list's tabs, and returns the
|
|
299
|
+
// closest tab (Framework7 `tabbar-highlight.js`, `setHighlightOnTouch`), of
|
|
300
|
+
// those its group shows (not scrolled out of view). The (hidden) selection of
|
|
301
|
+
// the closest tab's group follows the lens, so it settles from there on
|
|
302
|
+
// release. The lens and the pointer are where the pressed group shows its
|
|
303
|
+
// (scaled) content.
|
|
304
|
+
const press = (list, clientX) => {
|
|
305
|
+
const tabs = [];
|
|
306
|
+
const visible = [];
|
|
307
|
+
for (const tab of getTabs(list)) {
|
|
308
|
+
const rect = visibleRect(tab);
|
|
309
|
+
if (!rect)
|
|
310
|
+
continue;
|
|
311
|
+
tabs.push(tab);
|
|
312
|
+
visible.push(rect);
|
|
313
|
+
}
|
|
314
|
+
// The pointer in the tabs' unscaled layout, as the group under it grows.
|
|
315
|
+
const overTab = tabs[closest(visible, clientX)];
|
|
316
|
+
const over = overTab ? groupOf(overTab) : undefined;
|
|
317
|
+
const overGrowth = over ? growth(over) : undefined;
|
|
318
|
+
const x = overGrowth
|
|
319
|
+
? overGrowth.x + (clientX - overGrowth.x) / overGrowth.scale
|
|
320
|
+
: clientX;
|
|
321
|
+
const index = closest(visible, x);
|
|
322
|
+
const tab = tabs[index];
|
|
323
|
+
const pressedGroup = tab ? groupOf(tab) : undefined;
|
|
324
|
+
if (!tab || !pressedGroup)
|
|
325
|
+
return undefined;
|
|
326
|
+
const rect = tab.getBoundingClientRect();
|
|
327
|
+
const left = Math.min(...visible.map((visibleTab) => visibleTab.left));
|
|
328
|
+
const right = Math.max(...visible.map((visibleTab) => visibleTab.right));
|
|
329
|
+
const centerX = Math.max(left + rect.width / 2, Math.min(x, right - rect.width / 2));
|
|
330
|
+
// The lens is on the tab as its grown group shows it.
|
|
331
|
+
const { scale, x: originX, y: originY } = growth(pressedGroup);
|
|
332
|
+
setLens(list, new DOMRect(originX + (rect.left - originX) * scale, originY + (rect.top - originY) * scale, rect.width * scale, rect.height * scale), originX + (centerX - originX) * scale, {
|
|
333
|
+
left: originX + (left - originX) * scale,
|
|
334
|
+
right: originX + (right - originX) * scale,
|
|
335
|
+
});
|
|
336
|
+
for (const group of getGroups(list)) {
|
|
337
|
+
pressGroup(group, group === pressedGroup);
|
|
338
|
+
if (group === pressedGroup) {
|
|
339
|
+
// Only a group holding the active tab moves its selection; others place
|
|
340
|
+
// it instantly, so it never travels in from a stale position.
|
|
341
|
+
setSelection(group, rect, {
|
|
342
|
+
instant: !hadActiveTab.get(group),
|
|
343
|
+
left: centerX - rect.width / 2,
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
updateSelection(group);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return tab;
|
|
351
|
+
};
|
|
352
|
+
// Settles the lens on the chosen tab (if any) while it fades out. Groups take
|
|
353
|
+
// their final state right away, so the selection of a group losing the active
|
|
354
|
+
// tab does not reappear while the press ends: the chosen tab's group settles
|
|
355
|
+
// its selection from the lens position, all others fade out. They are
|
|
356
|
+
// reconciled on the next frame, in case the chosen tab is not activated.
|
|
357
|
+
const release = (list, tab) => {
|
|
358
|
+
list.style.removeProperty('--uikit-tab-bar-lens-move-duration');
|
|
359
|
+
list.style.removeProperty('--uikit-tab-bar-pressed');
|
|
360
|
+
const groups = getGroups(list);
|
|
361
|
+
for (const group of groups)
|
|
362
|
+
pressGroup(group, false);
|
|
363
|
+
if (!tab) {
|
|
364
|
+
for (const group of groups)
|
|
365
|
+
updateSelection(group);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
const rect = tab.getBoundingClientRect();
|
|
369
|
+
setLens(list, rect, rect.left + rect.width / 2);
|
|
370
|
+
for (const group of groups) {
|
|
371
|
+
const chosen = group === groupOf(tab);
|
|
372
|
+
const hadActive = hadActiveTab.get(group) ?? false;
|
|
373
|
+
hadActiveTab.set(group, chosen);
|
|
374
|
+
group.style.setProperty('--uikit-tab-bar-selection-opacity', chosen ? '1' : '0');
|
|
375
|
+
if (chosen) {
|
|
376
|
+
// A group gaining the active tab only fades its selection in.
|
|
377
|
+
setSelection(group, rect, { instant: !hadActive });
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
// Keep the selection hidden like while pressed, so it only fades out.
|
|
381
|
+
group.style.setProperty('--uikit-tab-bar-pressed', '1');
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
requestAnimationFrame(() => {
|
|
385
|
+
for (const group of groups)
|
|
386
|
+
updateSelection(group);
|
|
387
|
+
});
|
|
388
|
+
};
|
|
389
|
+
/**
|
|
390
|
+
* Scrolls the group of the lens' tab, if too narrow for its tabs, in every
|
|
391
|
+
* frame the lens' pointer is near one of the group's ends, faster closer to
|
|
392
|
+
* it (as text selections scroll). Returns a function stopping it.
|
|
393
|
+
*/
|
|
394
|
+
const autoScroll = (pointer) => {
|
|
395
|
+
const elapsedOf = frameElapsed();
|
|
396
|
+
let frame = requestAnimationFrame(function step(time) {
|
|
397
|
+
frame = requestAnimationFrame(step);
|
|
398
|
+
const elapsed = elapsedOf(time);
|
|
399
|
+
const { current } = pointer;
|
|
400
|
+
const scroller = current?.state.tab?.parentElement;
|
|
401
|
+
if (!current || !scroller)
|
|
402
|
+
return;
|
|
403
|
+
const range = scrollRange(scroller);
|
|
404
|
+
if (range <= 1)
|
|
405
|
+
return;
|
|
406
|
+
const { left, right } = scroller.getBoundingClientRect();
|
|
407
|
+
const delta = edgeScrollDelta(current.clientX, left, right, elapsed);
|
|
408
|
+
if (delta === 0)
|
|
409
|
+
return;
|
|
410
|
+
// Within the tabs' layout (see `scrollRange`).
|
|
411
|
+
scroller.scrollLeft = Math.max(0, Math.min(range, scroller.scrollLeft + delta));
|
|
412
|
+
});
|
|
413
|
+
return () => cancelAnimationFrame(frame);
|
|
414
|
+
};
|
|
415
|
+
/**
|
|
416
|
+
* Calls `done` once the transitions of `element` and its descendants have
|
|
417
|
+
* finished (also when slowed down, e.g. in the browser's developer tools, or
|
|
418
|
+
* restarted), starting from the next frame, when they have begun. Returns a
|
|
419
|
+
* function cancelling it.
|
|
420
|
+
*/
|
|
421
|
+
const afterTransitions = (element, done) => {
|
|
422
|
+
let cancelled = false;
|
|
423
|
+
const check = () => {
|
|
424
|
+
if (cancelled)
|
|
425
|
+
return;
|
|
426
|
+
const running = element
|
|
427
|
+
.getAnimations({ subtree: true })
|
|
428
|
+
.filter(({ playState }) => playState === 'running');
|
|
429
|
+
if (running.length === 0) {
|
|
430
|
+
done();
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
Promise.allSettled(running.map(({ finished }) => finished))
|
|
434
|
+
.then(() => requestAnimationFrame(check))
|
|
435
|
+
.catch(() => undefined);
|
|
436
|
+
};
|
|
437
|
+
requestAnimationFrame(check);
|
|
438
|
+
return () => {
|
|
439
|
+
cancelled = true;
|
|
440
|
+
};
|
|
441
|
+
};
|
|
442
|
+
/**
|
|
443
|
+
* Counts the elements marked by a context's children: `mark` counts one
|
|
444
|
+
* until the returned function is called.
|
|
445
|
+
*/
|
|
446
|
+
const useMarks = () => {
|
|
447
|
+
const [count, setCount] = useState(0);
|
|
448
|
+
const mark = useCallback(() => {
|
|
449
|
+
setCount((current) => current + 1);
|
|
450
|
+
return () => setCount((current) => current - 1);
|
|
451
|
+
}, []);
|
|
452
|
+
return [count, mark];
|
|
453
|
+
};
|
|
454
|
+
// The accessory (UIKit `bottomAccessory`, e.g. Music's mini player), from
|
|
455
|
+
// iOS 26: expanded, a capsule as wide as the bar's groups, its glass 48pt
|
|
456
|
+
// high and 8pt above theirs; collapsed, it moves into their row, filling the
|
|
457
|
+
// space after the remaining groups at the start (spaced as groups are), at
|
|
458
|
+
// the height of their tabs. Sizes are of its box: the glass extends beyond
|
|
459
|
+
// (see `GlassBackground`). It's a sibling of the list (not in the tab list,
|
|
460
|
+
// for its content's semantics), positioned absolutely at it by CSS anchor
|
|
461
|
+
// positioning (see `Root`), so it never changes the bar's layout and moves
|
|
462
|
+
// with it. Both places follow the groups in every frame; while the bar
|
|
463
|
+
// collapses or expands, it morphs from one to the other. Shown in one state
|
|
464
|
+
// only (`visibleIn`), it stays at its place there, fading in and out as the
|
|
465
|
+
// bar collapses and expands.
|
|
466
|
+
const accessorySpacing = 16;
|
|
467
|
+
// The accessory of a list (see `Accessory`).
|
|
468
|
+
const accessories = new WeakMap();
|
|
469
|
+
/** Boxes mixed, `fraction` of the way from `from` to `to`. */
|
|
470
|
+
const mixBoxes = (from, to, fraction) => {
|
|
471
|
+
const mix = (key) => from[key] + (to[key] - from[key]) * fraction;
|
|
472
|
+
return {
|
|
473
|
+
height: mix('height'),
|
|
474
|
+
left: mix('left'),
|
|
475
|
+
right: mix('right'),
|
|
476
|
+
top: mix('top'),
|
|
477
|
+
};
|
|
478
|
+
};
|
|
479
|
+
const accessoryMorphs = new WeakMap();
|
|
480
|
+
/** The running CSS transitions of `element` and its descendants. */
|
|
481
|
+
const runningTransitions = (element) => element
|
|
482
|
+
.getAnimations({ subtree: true })
|
|
483
|
+
.filter((animation) => animation instanceof CSSTransition && animation.playState === 'running');
|
|
484
|
+
// Properties not affecting layout: their transitions aren't sought (see
|
|
485
|
+
// `atTransitionsEnd`).
|
|
486
|
+
const paintOnly = /^(?:opacity|visibility|transform|translate|scale|rotate|filter|backdrop-filter|box-shadow|color|background.*|border-.*-color|outline.*|fill|stroke)$/u;
|
|
487
|
+
// Just before their end (ms): still running (ended, they'd be removed),
|
|
488
|
+
// their values all but their targets.
|
|
489
|
+
const beforeEnd = 0.01;
|
|
490
|
+
/**
|
|
491
|
+
* `measure`'s result as `transitions` will have ended: sought to just
|
|
492
|
+
* before their end, and back (synchronously: nothing renders in between, and
|
|
493
|
+
* they don't end).
|
|
494
|
+
*/
|
|
495
|
+
const atTransitionsEnd = (transitions, measure) => {
|
|
496
|
+
const layout = transitions.filter((transition) => !paintOnly.test(transition.transitionProperty));
|
|
497
|
+
const times = layout.map((transition) => transition.currentTime);
|
|
498
|
+
for (const transition of layout) {
|
|
499
|
+
const end = Number(transition.effect?.getComputedTiming().endTime);
|
|
500
|
+
if (Number.isFinite(end)) {
|
|
501
|
+
transition.currentTime = Math.max(0, end - beforeEnd);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
try {
|
|
505
|
+
return measure();
|
|
506
|
+
}
|
|
507
|
+
finally {
|
|
508
|
+
for (const [index, transition] of layout.entries()) {
|
|
509
|
+
transition.currentTime = times[index] ?? null;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
// CSS `ease`, as the groups' transitions (approximately).
|
|
514
|
+
const ease = (progress) => {
|
|
515
|
+
const inOut = progress * progress * (3 - 2 * progress);
|
|
516
|
+
return inOut + (1 - inOut) * progress * (1 - progress) * 0.5;
|
|
517
|
+
};
|
|
518
|
+
// The accessory's box, relative to the list.
|
|
519
|
+
const accessoryBox = (list, accessory) => {
|
|
520
|
+
const listRect = list.getBoundingClientRect();
|
|
521
|
+
const { height, left, right, top } = accessory.getBoundingClientRect();
|
|
522
|
+
return {
|
|
523
|
+
height,
|
|
524
|
+
left: left - listRect.left,
|
|
525
|
+
right: right - listRect.left,
|
|
526
|
+
top: top - listRect.top,
|
|
527
|
+
};
|
|
528
|
+
};
|
|
529
|
+
/**
|
|
530
|
+
* How far `transitions` have got (0 to 1, eased): the one ending last, by
|
|
531
|
+
* its own time (so slowed down with it, e.g. in the browser's developer
|
|
532
|
+
* tools).
|
|
533
|
+
*/
|
|
534
|
+
const transitionsProgress = (transitions) => {
|
|
535
|
+
let latest = Number.NEGATIVE_INFINITY;
|
|
536
|
+
let progress = 1;
|
|
537
|
+
for (const transition of transitions) {
|
|
538
|
+
const timing = transition.effect?.getComputedTiming();
|
|
539
|
+
const end = Number(timing?.endTime);
|
|
540
|
+
if (!(end > latest))
|
|
541
|
+
continue;
|
|
542
|
+
latest = end;
|
|
543
|
+
const delay = Number(timing?.delay ?? 0);
|
|
544
|
+
const duration = Number(timing?.duration);
|
|
545
|
+
const time = Number(transition.currentTime);
|
|
546
|
+
progress =
|
|
547
|
+
duration > 0 ? Math.min(1, Math.max(0, (time - delay) / duration)) : 1;
|
|
548
|
+
}
|
|
549
|
+
return ease(progress);
|
|
550
|
+
};
|
|
551
|
+
/**
|
|
552
|
+
* The free space of an expanded list (the space between its groups, or
|
|
553
|
+
* after its only group): while it collapses or expands, a length for its
|
|
554
|
+
* groups' margins, so they transition (from or to `auto` they couldn't).
|
|
555
|
+
*/
|
|
556
|
+
const measureFreeSpace = (list) => {
|
|
557
|
+
const groups = [...list.querySelectorAll(':scope > div')];
|
|
558
|
+
const last = groups.at(-1);
|
|
559
|
+
if (!last)
|
|
560
|
+
return 0;
|
|
561
|
+
const style = getComputedStyle(list);
|
|
562
|
+
const rtl = style.direction === 'rtl';
|
|
563
|
+
const box = list.getBoundingClientRect();
|
|
564
|
+
const rect = last.getBoundingClientRect();
|
|
565
|
+
const rest = rtl
|
|
566
|
+
? rect.left - (box.left + Number.parseFloat(style.paddingLeft))
|
|
567
|
+
: box.right - Number.parseFloat(style.paddingRight) - rect.right;
|
|
568
|
+
if (groups.length < 2)
|
|
569
|
+
return Math.max(0, rest);
|
|
570
|
+
// The space between: the second group's margin (auto, or the length).
|
|
571
|
+
const [, second] = groups;
|
|
572
|
+
const margin = second
|
|
573
|
+
? Number.parseFloat(getComputedStyle(second)[rtl ? 'marginRight' : 'marginLeft'])
|
|
574
|
+
: 0;
|
|
575
|
+
const free = Math.max(0, margin + rest);
|
|
576
|
+
return free;
|
|
577
|
+
};
|
|
578
|
+
/** Starts the accessory's morph to the collapsed (or expanded) place. */
|
|
579
|
+
const morphAccessory = (list, collapsed) => {
|
|
580
|
+
const morph = accessoryMorphs.get(list);
|
|
581
|
+
if (morph?.collapsed === collapsed)
|
|
582
|
+
return;
|
|
583
|
+
const accessory = accessories.get(list);
|
|
584
|
+
accessoryMorphs.set(list, {
|
|
585
|
+
collapsed,
|
|
586
|
+
// From where it is (also mid-morph); placed right away the first time.
|
|
587
|
+
from: morph && accessory ? accessoryBox(list, accessory) : undefined,
|
|
588
|
+
remaining: morph?.remaining ?? [],
|
|
589
|
+
});
|
|
590
|
+
};
|
|
591
|
+
// A group's box without its spacing (see `StyledGroup`): its scroller's.
|
|
592
|
+
const contentRect = (group) => (scrollerOf(group) ?? group).getBoundingClientRect();
|
|
593
|
+
// The accessory's place above the groups (all of them).
|
|
594
|
+
const aboveGroups = (rects) => ({
|
|
595
|
+
height: accessoryHeight,
|
|
596
|
+
left: Math.min(...rects.map((rect) => rect.left)),
|
|
597
|
+
right: Math.max(...rects.map((rect) => rect.right)),
|
|
598
|
+
top: Math.min(...rects.map((rect) => rect.top)) - accessoryGap - accessoryHeight,
|
|
599
|
+
});
|
|
600
|
+
// The accessory's place between the remaining groups, in the order they're
|
|
601
|
+
// placed in (see `collapsedOrder`): after those at the start, where the free
|
|
602
|
+
// space is, at the height of a collapsed tab, centered with them.
|
|
603
|
+
const betweenGroups = (list, groups) => {
|
|
604
|
+
const listRect = list.getBoundingClientRect();
|
|
605
|
+
const style = getComputedStyle(list);
|
|
606
|
+
const sorted = groups
|
|
607
|
+
.map((group) => ({
|
|
608
|
+
order: Number.parseFloat(getComputedStyle(group).order) || 0,
|
|
609
|
+
rect: contentRect(group),
|
|
610
|
+
}))
|
|
611
|
+
.toSorted((a, b) => a.order - b.order);
|
|
612
|
+
const startCount = sorted.filter(({ order }) => order === 0).length;
|
|
613
|
+
const before = sorted[startCount - 1]?.rect;
|
|
614
|
+
const after = sorted[startCount]?.rect;
|
|
615
|
+
const row = before ?? after ?? listRect;
|
|
616
|
+
const height = Number.parseFloat(style.getPropertyValue('--uikit-tab-bar-collapsed-tab-height')) || accessoryHeight;
|
|
617
|
+
return {
|
|
618
|
+
height,
|
|
619
|
+
left: before
|
|
620
|
+
? before.right + accessorySpacing
|
|
621
|
+
: listRect.left + Number.parseFloat(style.paddingLeft),
|
|
622
|
+
right: after
|
|
623
|
+
? after.left - accessorySpacing
|
|
624
|
+
: listRect.right - Number.parseFloat(style.paddingRight),
|
|
625
|
+
top: row.top + row.height / 2 - height / 2,
|
|
626
|
+
};
|
|
627
|
+
};
|
|
628
|
+
/** A box (in the viewport) relative to the list's `rect`. */
|
|
629
|
+
const relativeTo = (box, rect) => ({
|
|
630
|
+
height: box.height,
|
|
631
|
+
left: box.left - rect.left,
|
|
632
|
+
right: box.right - rect.left,
|
|
633
|
+
top: box.top - rect.top,
|
|
634
|
+
});
|
|
635
|
+
const placeAccessory = (list) => {
|
|
636
|
+
const accessory = accessories.get(list);
|
|
637
|
+
const morph = accessoryMorphs.get(list) ?? {
|
|
638
|
+
collapsed: false,
|
|
639
|
+
remaining: [],
|
|
640
|
+
};
|
|
641
|
+
if (!accessory)
|
|
642
|
+
return;
|
|
643
|
+
const groups = [...list.querySelectorAll(':scope > div')];
|
|
644
|
+
if (groups.length === 0)
|
|
645
|
+
return;
|
|
646
|
+
if (morph.collapsed) {
|
|
647
|
+
// Groups collapsing away stop taking pointer events right away.
|
|
648
|
+
morph.remaining = groups.filter((group) => getComputedStyle(group).pointerEvents !== 'none');
|
|
649
|
+
}
|
|
650
|
+
// State for its styles (see `StyledAccessory`).
|
|
651
|
+
accessory.toggleAttribute('data-collapsed', morph.collapsed);
|
|
652
|
+
const visibleIn = getComputedStyle(accessory)
|
|
653
|
+
.getPropertyValue('--uikit-tab-bar-accessory-visible-in')
|
|
654
|
+
.trim();
|
|
655
|
+
// Its place as the groups are; shown in one state only, at its place
|
|
656
|
+
// there.
|
|
657
|
+
const collapsedPlace = visibleIn === 'both' ? morph.collapsed : visibleIn === 'collapsed';
|
|
658
|
+
const measure = () => {
|
|
659
|
+
const box = collapsedPlace
|
|
660
|
+
? betweenGroups(list, morph.remaining.length > 0 ? morph.remaining : groups)
|
|
661
|
+
: aboveGroups(groups.map((group) => contentRect(group)));
|
|
662
|
+
return relativeTo(box, list.getBoundingClientRect());
|
|
663
|
+
};
|
|
664
|
+
// Morphing: from where it was, to its place as the groups will be, as far
|
|
665
|
+
// as their transitions have got; once they've ended, done.
|
|
666
|
+
const running = morph.from && visibleIn === 'both' ? runningTransitions(list) : [];
|
|
667
|
+
morph.transitions ??= running;
|
|
668
|
+
const transitions = morph.transitions.filter((transition) => running.includes(transition));
|
|
669
|
+
if (transitions.length === 0) {
|
|
670
|
+
delete morph.from;
|
|
671
|
+
delete morph.target;
|
|
672
|
+
delete morph.transitions;
|
|
673
|
+
}
|
|
674
|
+
let place;
|
|
675
|
+
if (morph.from) {
|
|
676
|
+
const time = document.timeline.currentTime;
|
|
677
|
+
if (morph.target?.time !== time) {
|
|
678
|
+
morph.target = { box: atTransitionsEnd(running, measure), time };
|
|
679
|
+
}
|
|
680
|
+
place = mixBoxes(morph.from, morph.target.box, transitionsProgress(transitions));
|
|
681
|
+
}
|
|
682
|
+
else {
|
|
683
|
+
place = measure();
|
|
684
|
+
}
|
|
685
|
+
const done = !morph.from;
|
|
686
|
+
// Room above the list for its place above the groups (see StyledList).
|
|
687
|
+
list.toggleAttribute('data-accessory-above', visibleIn !== 'collapsed');
|
|
688
|
+
setProperties(accessory, {
|
|
689
|
+
'--uikit-tab-bar-accessory-height': `${place.height}px`,
|
|
690
|
+
'--uikit-tab-bar-accessory-left': `${place.left}px`,
|
|
691
|
+
'--uikit-tab-bar-accessory-top': `${place.top}px`,
|
|
692
|
+
'--uikit-tab-bar-accessory-width': `${Math.max(0, place.right - place.left)}px`,
|
|
693
|
+
});
|
|
694
|
+
// Morphing on by itself, also once the groups have settled.
|
|
695
|
+
if (!done && morph.frame === undefined && accessoryMorphs.has(list)) {
|
|
696
|
+
morph.frame = requestAnimationFrame(() => {
|
|
697
|
+
morph.frame = undefined;
|
|
698
|
+
placeAccessory(list);
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
/**
|
|
703
|
+
* Links a bar's list and accessory, as they're added and removed (in any
|
|
704
|
+
* order).
|
|
705
|
+
*/
|
|
706
|
+
const createAccessoryLink = () => {
|
|
707
|
+
let list = null;
|
|
708
|
+
let accessory = null;
|
|
709
|
+
const sync = () => {
|
|
710
|
+
if (!list)
|
|
711
|
+
return;
|
|
712
|
+
if (!accessory) {
|
|
713
|
+
accessories.delete(list);
|
|
714
|
+
delete list.dataset.accessoryAbove;
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
717
|
+
accessories.set(list, accessory);
|
|
718
|
+
placeAccessory(list);
|
|
719
|
+
};
|
|
720
|
+
return {
|
|
721
|
+
setAccessory: (element) => {
|
|
722
|
+
accessory = element;
|
|
723
|
+
sync();
|
|
724
|
+
},
|
|
725
|
+
setList: (element) => {
|
|
726
|
+
if (list)
|
|
727
|
+
accessories.delete(list);
|
|
728
|
+
list = element;
|
|
729
|
+
sync();
|
|
730
|
+
},
|
|
731
|
+
};
|
|
732
|
+
};
|
|
733
|
+
const RootContext = createContext({});
|
|
734
|
+
/**
|
|
735
|
+
* Base UI's `Tabs.Root`, also providing the anchor its `TabBar.Accessory`
|
|
736
|
+
* is positioned at (the `TabBar.List`).
|
|
737
|
+
*/
|
|
738
|
+
const Root = forwardRef((props, ref) => {
|
|
739
|
+
const id = useId();
|
|
740
|
+
const [link] = useState(createAccessoryLink);
|
|
741
|
+
const context = useMemo(() => ({
|
|
742
|
+
...link,
|
|
743
|
+
anchor: `--uikit-tab-bar-${id.replaceAll(/[^\w-]/gu, '')}`,
|
|
744
|
+
}), [id, link]);
|
|
745
|
+
return (_jsx(RootContext.Provider, { value: context, children: _jsx(BaseTabs.Root, { ref: ref, ...props }) }));
|
|
746
|
+
});
|
|
747
|
+
const ListContext = createContext({
|
|
748
|
+
collapsed: false,
|
|
749
|
+
collapsedPosition: 'inline-start',
|
|
750
|
+
markedGroups: 0,
|
|
751
|
+
});
|
|
752
|
+
/**
|
|
753
|
+
* The tab bar, containing `TabBar.Group`s. Renders the glass lens shown
|
|
754
|
+
* while a tab is pressed.
|
|
755
|
+
*/
|
|
756
|
+
const List = forwardRef(({ className, children, collapsed = false, collapsedContent, collapsedPosition = 'inline-start', context: glassContext = 'auto', onClickCapture, onLostPointerCapture, onPointerCancel, onPointerDown, onPointerMove, onPointerUp, size = 'compact', style, ...props }, ref) => {
|
|
757
|
+
const listRef = useForwardedRef(ref);
|
|
758
|
+
const root = useContext(RootContext);
|
|
759
|
+
// For its accessory (see `Accessory`).
|
|
760
|
+
const { setList } = root;
|
|
761
|
+
useLayoutEffect(() => {
|
|
762
|
+
setList?.(listRef.current);
|
|
763
|
+
return () => setList?.(null);
|
|
764
|
+
}, [listRef, setList]);
|
|
765
|
+
const expandedWidthRef = useRef(undefined);
|
|
766
|
+
const resizingRef = useRef(collapsed);
|
|
767
|
+
const wasCollapsedRef = useRef(collapsed);
|
|
768
|
+
// Expanding (from collapsed, until settled): set while rendering, so
|
|
769
|
+
// the transitions start with its easing (see `StyledList`).
|
|
770
|
+
const [expanding, setExpanding] = useState(false);
|
|
771
|
+
// Wider than its groups (expanded): the space between them as a length
|
|
772
|
+
// (see `freeSpace`), so it transitions as the bar collapses.
|
|
773
|
+
const [wide, setWide] = useState(false);
|
|
774
|
+
const freeRef = useRef(0);
|
|
775
|
+
const [renderedCollapsed, setRenderedCollapsed] = useState(collapsed);
|
|
776
|
+
if (collapsed !== renderedCollapsed) {
|
|
777
|
+
setRenderedCollapsed(collapsed);
|
|
778
|
+
setExpanding(!collapsed);
|
|
779
|
+
}
|
|
780
|
+
// The width while expanded, kept while collapsed (and until it has
|
|
781
|
+
// expanded again), so the bar doesn't change size.
|
|
782
|
+
useLayoutEffect(() => {
|
|
783
|
+
const { current: list } = listRef;
|
|
784
|
+
if (!list)
|
|
785
|
+
return undefined;
|
|
786
|
+
const observer = new ResizeObserver(() => {
|
|
787
|
+
placeAccessory(list);
|
|
788
|
+
if (resizingRef.current)
|
|
789
|
+
return;
|
|
790
|
+
expandedWidthRef.current = list.getBoundingClientRect().width;
|
|
791
|
+
freeRef.current = measureFreeSpace(list);
|
|
792
|
+
setWide(freeRef.current > 0.5);
|
|
793
|
+
});
|
|
794
|
+
observer.observe(list);
|
|
795
|
+
return () => observer.disconnect();
|
|
796
|
+
}, [listRef]);
|
|
797
|
+
useLayoutEffect(() => {
|
|
798
|
+
const { current: list } = listRef;
|
|
799
|
+
if (!list)
|
|
800
|
+
return undefined;
|
|
801
|
+
const wasCollapsed = wasCollapsedRef.current;
|
|
802
|
+
wasCollapsedRef.current = collapsed;
|
|
803
|
+
morphAccessory(list, collapsed);
|
|
804
|
+
// While collapsing or expanding, the selections follow their active
|
|
805
|
+
// tabs in every frame (resize observers lag a frame behind, and miss
|
|
806
|
+
// tabs that only move), which their groups keep in view.
|
|
807
|
+
let frame;
|
|
808
|
+
const follow = () => {
|
|
809
|
+
for (const group of list.querySelectorAll(':scope > div')) {
|
|
810
|
+
if (!(group instanceof HTMLElement))
|
|
811
|
+
continue;
|
|
812
|
+
const active = tabsOf(group).find((tab) => isActive(tab));
|
|
813
|
+
if (active)
|
|
814
|
+
reveal(active, 'instant');
|
|
815
|
+
updateSelection(group, { instant: true });
|
|
816
|
+
}
|
|
817
|
+
placeAccessory(list);
|
|
818
|
+
frame = requestAnimationFrame(follow);
|
|
819
|
+
};
|
|
820
|
+
const stopFollowing = () => {
|
|
821
|
+
if (frame !== undefined)
|
|
822
|
+
cancelAnimationFrame(frame);
|
|
823
|
+
frame = undefined;
|
|
824
|
+
};
|
|
825
|
+
// While expanding, the groups grow from the collapsed tabs' positions
|
|
826
|
+
// until they fill the bar, their labels clipped meanwhile. Set from
|
|
827
|
+
// collapsing on, so they're in place as soon as the collapsed styles
|
|
828
|
+
// go: layout read in between (e.g. by Base UI's indicator) would start
|
|
829
|
+
// transitions from the expanded styles (or not at all, from `auto`).
|
|
830
|
+
const holdCollapsedLayout = () => {
|
|
831
|
+
list.style.setProperty('--uikit-tab-bar-collapsed-layout', '1');
|
|
832
|
+
list.style.setProperty('--uikit-tab-bar-group-margin', '0');
|
|
833
|
+
list.style.setProperty('--uikit-tab-bar-label-overflow', 'clip');
|
|
834
|
+
list.style.setProperty('--uikit-tab-bar-label-min-width', '0');
|
|
835
|
+
};
|
|
836
|
+
if (collapsed) {
|
|
837
|
+
resizingRef.current = true;
|
|
838
|
+
list.style.removeProperty('--uikit-tab-bar-spacer-grow');
|
|
839
|
+
if (expandedWidthRef.current !== undefined) {
|
|
840
|
+
list.style.minWidth = `${expandedWidthRef.current}px`;
|
|
841
|
+
}
|
|
842
|
+
holdCollapsedLayout();
|
|
843
|
+
// Wider than its groups: the space between them shrinks from its
|
|
844
|
+
// length (a frame later: from it, not from auto).
|
|
845
|
+
let shrink;
|
|
846
|
+
if (Object.hasOwn(list.dataset, 'wide')) {
|
|
847
|
+
list.style.setProperty('--uikit-tab-bar-group-margin', `${String(freeRef.current)}px`);
|
|
848
|
+
shrink = requestAnimationFrame(() => list.style.setProperty('--uikit-tab-bar-group-margin', '0'));
|
|
849
|
+
}
|
|
850
|
+
follow();
|
|
851
|
+
const cancel = afterTransitions(list, stopFollowing);
|
|
852
|
+
return () => {
|
|
853
|
+
if (shrink !== undefined)
|
|
854
|
+
cancelAnimationFrame(shrink);
|
|
855
|
+
cancel();
|
|
856
|
+
stopFollowing();
|
|
857
|
+
};
|
|
858
|
+
}
|
|
859
|
+
const settle = () => {
|
|
860
|
+
resizingRef.current = false;
|
|
861
|
+
list.style.removeProperty('min-width');
|
|
862
|
+
list.style.removeProperty('--uikit-tab-bar-collapsed-layout');
|
|
863
|
+
list.style.removeProperty('--uikit-tab-bar-group-margin');
|
|
864
|
+
list.style.removeProperty('--uikit-tab-bar-label-overflow');
|
|
865
|
+
list.style.removeProperty('--uikit-tab-bar-label-min-width');
|
|
866
|
+
list.style.removeProperty('--uikit-tab-bar-spacer-grow');
|
|
867
|
+
expandedWidthRef.current = list.getBoundingClientRect().width;
|
|
868
|
+
placeAccessory(list);
|
|
869
|
+
setExpanding(false);
|
|
870
|
+
freeRef.current = measureFreeSpace(list);
|
|
871
|
+
setWide(freeRef.current > 0.5);
|
|
872
|
+
};
|
|
873
|
+
if (!wasCollapsed) {
|
|
874
|
+
settle();
|
|
875
|
+
return undefined;
|
|
876
|
+
}
|
|
877
|
+
holdCollapsedLayout();
|
|
878
|
+
// Wider than its groups: the space between them grows back, the
|
|
879
|
+
// spacers shrink, all in step (the groups' order still held).
|
|
880
|
+
if (Object.hasOwn(list.dataset, 'wide')) {
|
|
881
|
+
list.style.setProperty('--uikit-tab-bar-group-margin', `${String(freeRef.current)}px`);
|
|
882
|
+
list.style.setProperty('--uikit-tab-bar-spacer-grow', '0');
|
|
883
|
+
}
|
|
884
|
+
follow();
|
|
885
|
+
const cancel = afterTransitions(list, () => {
|
|
886
|
+
stopFollowing();
|
|
887
|
+
settle();
|
|
888
|
+
});
|
|
889
|
+
return () => {
|
|
890
|
+
cancel();
|
|
891
|
+
stopFollowing();
|
|
892
|
+
};
|
|
893
|
+
}, [collapsed, listRef]);
|
|
894
|
+
// The accessory follows the groups while any of their transitions run
|
|
895
|
+
// (e.g. groups marked to remain while collapsed).
|
|
896
|
+
useLayoutEffect(() => {
|
|
897
|
+
const { current: list } = listRef;
|
|
898
|
+
if (!list)
|
|
899
|
+
return undefined;
|
|
900
|
+
let frame;
|
|
901
|
+
let cancel;
|
|
902
|
+
const stop = () => {
|
|
903
|
+
if (frame !== undefined)
|
|
904
|
+
cancelAnimationFrame(frame);
|
|
905
|
+
frame = undefined;
|
|
906
|
+
cancel?.();
|
|
907
|
+
cancel = undefined;
|
|
908
|
+
};
|
|
909
|
+
const onTransitionRun = () => {
|
|
910
|
+
if (frame !== undefined || !accessories.has(list))
|
|
911
|
+
return;
|
|
912
|
+
const step = () => {
|
|
913
|
+
placeAccessory(list);
|
|
914
|
+
frame = requestAnimationFrame(step);
|
|
915
|
+
};
|
|
916
|
+
step();
|
|
917
|
+
cancel = afterTransitions(list, () => {
|
|
918
|
+
stop();
|
|
919
|
+
placeAccessory(list);
|
|
920
|
+
});
|
|
921
|
+
};
|
|
922
|
+
list.addEventListener('transitionrun', onTransitionRun);
|
|
923
|
+
return () => {
|
|
924
|
+
list.removeEventListener('transitionrun', onTransitionRun);
|
|
925
|
+
stop();
|
|
926
|
+
};
|
|
927
|
+
}, [listRef]);
|
|
928
|
+
// The pointer of the lens, so it follows the tabs under it while a
|
|
929
|
+
// group scrolls.
|
|
930
|
+
const dragRef = useRef(undefined);
|
|
931
|
+
const stopScrollingRef = useRef(undefined);
|
|
932
|
+
// A press releases on its tab by clicking it (see `end`); the browser's
|
|
933
|
+
// own click that may follow (WebKit: on the tab, despite the capture)
|
|
934
|
+
// would reach the tab and its group a second time (e.g. collapsing the
|
|
935
|
+
// bar its first click expanded).
|
|
936
|
+
const pressClickedRef = useRef(false);
|
|
937
|
+
// A group too narrow for its tabs scrolls (by wheel, or by touches on
|
|
938
|
+
// the lens, which scroll it while near its ends). Scroll events don't
|
|
939
|
+
// bubble, but are captured.
|
|
940
|
+
useLayoutEffect(() => {
|
|
941
|
+
const { current: list } = listRef;
|
|
942
|
+
if (!list)
|
|
943
|
+
return undefined;
|
|
944
|
+
const onScroll = () => {
|
|
945
|
+
const { current: drag } = dragRef;
|
|
946
|
+
if (drag)
|
|
947
|
+
drag.state.tab = press(list, drag.clientX);
|
|
948
|
+
};
|
|
949
|
+
list.addEventListener('scroll', onScroll, {
|
|
950
|
+
capture: true,
|
|
951
|
+
passive: true,
|
|
952
|
+
});
|
|
953
|
+
return () => {
|
|
954
|
+
list.removeEventListener('scroll', onScroll, { capture: true });
|
|
955
|
+
stopScrollingRef.current?.();
|
|
956
|
+
};
|
|
957
|
+
}, [listRef]);
|
|
958
|
+
const [markedGroups, markGroup] = useMarks();
|
|
959
|
+
const context = useMemo(() => ({ collapsed, collapsedPosition, markGroup, markedGroups }), [collapsed, collapsedPosition, markGroup, markedGroups]);
|
|
960
|
+
const handlers = usePointerDrag({
|
|
961
|
+
end: (list, state, cancelled) => {
|
|
962
|
+
dragRef.current = undefined;
|
|
963
|
+
stopScrollingRef.current?.();
|
|
964
|
+
if (cancelled) {
|
|
965
|
+
release(list);
|
|
966
|
+
return;
|
|
967
|
+
}
|
|
968
|
+
release(list, state.tab);
|
|
969
|
+
if (!state.tab)
|
|
970
|
+
return;
|
|
971
|
+
// Also the active tab: the click reaches it and its group (e.g. to
|
|
972
|
+
// expand a collapsed bar), the press having captured the pointer.
|
|
973
|
+
state.tab.click();
|
|
974
|
+
pressClickedRef.current = true;
|
|
975
|
+
setTimeout(() => {
|
|
976
|
+
pressClickedRef.current = false;
|
|
977
|
+
}, 300);
|
|
978
|
+
reveal(state.tab);
|
|
979
|
+
},
|
|
980
|
+
move: (list, state, event) => {
|
|
981
|
+
state.tab = press(list, event.clientX);
|
|
982
|
+
dragRef.current = { clientX: event.clientX, state };
|
|
983
|
+
},
|
|
984
|
+
start: (list, event) => {
|
|
985
|
+
if (!(event.target instanceof Element))
|
|
986
|
+
return undefined;
|
|
987
|
+
if (!event.target.closest('[role="tab"]'))
|
|
988
|
+
return undefined;
|
|
989
|
+
// Place (and size) the lens at the pointer without a transition,
|
|
990
|
+
// then let it follow without delay; only opacity and scale animate.
|
|
991
|
+
list.style.setProperty('--uikit-tab-bar-lens-move-duration', '0s');
|
|
992
|
+
list.style.setProperty('--uikit-tab-bar-lens-size-duration', '0s');
|
|
993
|
+
const tab = press(list, event.clientX);
|
|
994
|
+
list.getBoundingClientRect();
|
|
995
|
+
list.style.removeProperty('--uikit-tab-bar-lens-size-duration');
|
|
996
|
+
list.style.setProperty('--uikit-tab-bar-pressed', '1');
|
|
997
|
+
const state = { tab };
|
|
998
|
+
dragRef.current = { clientX: event.clientX, state };
|
|
999
|
+
stopScrollingRef.current = autoScroll(dragRef);
|
|
1000
|
+
return state;
|
|
1001
|
+
},
|
|
1002
|
+
}, {
|
|
1003
|
+
onLostPointerCapture,
|
|
1004
|
+
onPointerCancel,
|
|
1005
|
+
onPointerDown,
|
|
1006
|
+
onPointerMove,
|
|
1007
|
+
onPointerUp,
|
|
1008
|
+
});
|
|
1009
|
+
return (_jsx(ListContext.Provider, { value: context, children: _jsxs(BaseTabs.List, { ref: listRef, "data-collapsed": collapsed ? '' : undefined, "data-collapsed-content": collapsed ? collapsedContent : undefined, "data-expanding": expanding ? '' : undefined, "data-glass-context": glassContext, "data-size": size, "data-spaced": markedGroups > 1 ? '' : undefined, "data-wide": wide ? '' : undefined, style: withStyle({ 'anchor-name': root.anchor }, style), ...props, ...handlers, className: cn('uikit-tab-bar-list', className), "data-tab-bar-part": "list", onClickCapture: (event) => {
|
|
1010
|
+
onClickCapture?.(event);
|
|
1011
|
+
if (!event.isTrusted || !pressClickedRef.current)
|
|
1012
|
+
return;
|
|
1013
|
+
pressClickedRef.current = false;
|
|
1014
|
+
event.preventDefault();
|
|
1015
|
+
event.stopPropagation();
|
|
1016
|
+
}, children: [children, _jsx("span", { "aria-hidden": "true", className: "uikit-tab-bar-lens", "data-tab-bar-part": "lens" })] }) }));
|
|
1017
|
+
});
|
|
1018
|
+
const GroupContext = createContext({ away: false, markedTabs: 0 });
|
|
1019
|
+
/**
|
|
1020
|
+
* A glass capsule of tabs, to be rendered inside `TabBar.List`. Its
|
|
1021
|
+
* `TabBar.Indicator` has to precede its tabs.
|
|
1022
|
+
*/
|
|
1023
|
+
const Group = forwardRef(({ className, children, collapsedContent, collapsedPosition, shape, visibleWhenCollapsed, ...props }, forwardedRef) => {
|
|
1024
|
+
const ref = useForwardedRef(forwardedRef);
|
|
1025
|
+
const list = useContext(ListContext);
|
|
1026
|
+
const { markGroup } = list;
|
|
1027
|
+
const [markedTabs, markTab] = useMarks();
|
|
1028
|
+
// Counted, for the layout of several remaining groups.
|
|
1029
|
+
useLayoutEffect(() => (visibleWhenCollapsed ? markGroup?.() : undefined), [markGroup, visibleWhenCollapsed]);
|
|
1030
|
+
let collapsedVisibility;
|
|
1031
|
+
if (list.collapsed) {
|
|
1032
|
+
collapsedVisibility = visibleWhenCollapsed ? 'shown' : 'away';
|
|
1033
|
+
}
|
|
1034
|
+
const away = collapsedVisibility === 'away';
|
|
1035
|
+
useLayoutEffect(() => {
|
|
1036
|
+
const { current: group } = ref;
|
|
1037
|
+
if (!group)
|
|
1038
|
+
return undefined;
|
|
1039
|
+
// Only the group and its tabs: the selection resizes itself while
|
|
1040
|
+
// following the lens, which must not snap it back to the active tab.
|
|
1041
|
+
// It follows changes of their size right away (e.g. collapsing).
|
|
1042
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
1043
|
+
updateOverflow(group);
|
|
1044
|
+
updateSelection(group, { instant: true });
|
|
1045
|
+
if (group.parentElement)
|
|
1046
|
+
placeAccessory(group.parentElement);
|
|
1047
|
+
});
|
|
1048
|
+
const observe = () => {
|
|
1049
|
+
resizeObserver.observe(group);
|
|
1050
|
+
for (const tab of tabsOf(group))
|
|
1051
|
+
resizeObserver.observe(tab);
|
|
1052
|
+
};
|
|
1053
|
+
const update = (behavior) => {
|
|
1054
|
+
observe();
|
|
1055
|
+
updateOverflow(group);
|
|
1056
|
+
const active = tabsOf(group).find((tab) => isActive(tab));
|
|
1057
|
+
if (active)
|
|
1058
|
+
reveal(active, behavior);
|
|
1059
|
+
updateSelection(group);
|
|
1060
|
+
};
|
|
1061
|
+
update('instant');
|
|
1062
|
+
const mutationObserver = new MutationObserver(() => update('smooth'));
|
|
1063
|
+
mutationObserver.observe(group, {
|
|
1064
|
+
attributeFilter: ['data-active'],
|
|
1065
|
+
childList: true,
|
|
1066
|
+
subtree: true,
|
|
1067
|
+
});
|
|
1068
|
+
return () => {
|
|
1069
|
+
resizeObserver.disconnect();
|
|
1070
|
+
mutationObserver.disconnect();
|
|
1071
|
+
};
|
|
1072
|
+
}, [ref]);
|
|
1073
|
+
const context = useMemo(() => ({ away, markTab, markedTabs, shape }), [away, markTab, markedTabs, shape]);
|
|
1074
|
+
return (_jsx(GroupContext.Provider, { value: context, children: _jsxs("div", { ref: ref, "data-collapsed-content": list.collapsed ? collapsedContent : undefined, "data-collapsed-visibility": collapsedVisibility, "data-spaced": list.markedGroups > 1 ? '' : undefined, "data-selection-shown": list.collapsed && !away && (markedTabs > 1 || list.markedGroups > 1)
|
|
1075
|
+
? ''
|
|
1076
|
+
: undefined, ...props, className: cn('uikit-tab-bar-group', className), "data-tab-bar-part": "group", style: withStyle({
|
|
1077
|
+
'--uikit-tab-bar-collapsed-order': String(collapsedOrder[collapsedPosition ?? list.collapsedPosition]),
|
|
1078
|
+
}, props.style), children: [_jsx(GlassBackground, {}), _jsx("div", { className: "uikit-tab-bar-tabs", "data-tab-bar-part": "tabs", children: children })] }) }));
|
|
1079
|
+
});
|
|
1080
|
+
/**
|
|
1081
|
+
* The selection, to be rendered first inside each `TabBar.Group`, which
|
|
1082
|
+
* positions it on its active tab; hidden while pressed, when the list's lens
|
|
1083
|
+
* takes over (Framework7 `toolbar-ios.less`, `.tab-link-highlight`).
|
|
1084
|
+
*/
|
|
1085
|
+
const Indicator = forwardRef(({ className, ...props }, ref) => (_jsx(BaseTabs.Indicator, { ref: ref, className: cn('uikit-tab-bar-indicator', className), "data-tab-bar-part": "indicator", ...props })));
|
|
1086
|
+
const Tab = forwardRef((tabProps, ref) => {
|
|
1087
|
+
const { className, collapsedContent, shape, visibleWhenCollapsed, ...props } = useSecondaryClick(tabProps);
|
|
1088
|
+
const group = useContext(GroupContext);
|
|
1089
|
+
const { markTab } = group;
|
|
1090
|
+
const { collapsed } = useContext(ListContext);
|
|
1091
|
+
useLayoutEffect(() => (visibleWhenCollapsed ? markTab?.() : undefined), [markTab, visibleWhenCollapsed]);
|
|
1092
|
+
// Only while collapsed, in a remaining group.
|
|
1093
|
+
let collapsedVisibility;
|
|
1094
|
+
if (collapsed && !group.away) {
|
|
1095
|
+
collapsedVisibility = visibleWhenCollapsed ? 'shown' : 'away';
|
|
1096
|
+
}
|
|
1097
|
+
return (_jsx(BaseTabs.Tab, { ref: ref, ...props, className: cn('uikit-tab-bar-tab', className), "data-collapsed-content": collapsed ? collapsedContent : undefined, "data-collapsed-visibility": collapsedVisibility, "data-shape": shape ?? group.shape, "data-tab-bar-part": "tab" }));
|
|
1098
|
+
});
|
|
1099
|
+
const Icon = forwardRef(({ className, ...props }, ref) => (_jsx("span", { ref: ref, "data-tab-bar-part": "icon", ...props, className: cn('uikit-tab-bar-icon', className) })));
|
|
1100
|
+
const Label = forwardRef(({ className, children, ...props }, ref) => (_jsxs("span", { ref: ref, "data-tab-bar-part": "label", ...props, className: cn('uikit-tab-bar-label', className), children: [_jsx("span", { className: "uikit-tab-bar-label-text", "data-tab-bar-part": "label-text", children: children }), _jsx("span", { "aria-hidden": "true", className: "uikit-tab-bar-label-reserve", "data-tab-bar-part": "label-reserve", children: children })] })));
|
|
1101
|
+
/**
|
|
1102
|
+
* A glass capsule of arbitrary content attached to the bar (UIKit
|
|
1103
|
+
* `bottomAccessory`, e.g. a mini player), to be rendered inside
|
|
1104
|
+
* `TabBar.Root`, after `TabBar.List`: above its groups, or, while the bar is
|
|
1105
|
+
* collapsed, between them. Positioned at the list, it doesn't take up space
|
|
1106
|
+
* in the layout.
|
|
1107
|
+
*/
|
|
1108
|
+
const Accessory = forwardRef(({ className, children, context = 'auto', style, visibleIn = 'both', ...props }, forwardedRef) => {
|
|
1109
|
+
const ref = useForwardedRef(forwardedRef);
|
|
1110
|
+
const { anchor, setAccessory } = useContext(RootContext);
|
|
1111
|
+
// Placed by its list, as its groups change, and when added (or shown in
|
|
1112
|
+
// other states).
|
|
1113
|
+
useLayoutEffect(() => {
|
|
1114
|
+
setAccessory?.(ref.current);
|
|
1115
|
+
return () => setAccessory?.(null);
|
|
1116
|
+
}, [ref, setAccessory, visibleIn]);
|
|
1117
|
+
return (_jsxs("div", { ref: ref, "data-glass-context": context, "data-tab-bar-part": "accessory", "data-visible-in": visibleIn, ...props, className: cn('uikit-tab-bar-accessory', className), style: withStyle({
|
|
1118
|
+
'--uikit-tab-bar-accessory-visible-in': visibleIn,
|
|
1119
|
+
'position-anchor': anchor,
|
|
1120
|
+
}, style), children: [_jsx(GlassBackground, {}), _jsx("span", { className: "uikit-tab-bar-accessory-content", "data-tab-bar-part": "accessory-content", children: children })] }));
|
|
1121
|
+
});
|
|
1122
|
+
export const TabBar = {
|
|
1123
|
+
...BaseTabs,
|
|
1124
|
+
Accessory,
|
|
1125
|
+
Root,
|
|
1126
|
+
List,
|
|
1127
|
+
Group,
|
|
1128
|
+
Indicator,
|
|
1129
|
+
Tab,
|
|
1130
|
+
Icon,
|
|
1131
|
+
Label,
|
|
1132
|
+
};
|
|
1133
|
+
//# sourceMappingURL=main.js.map
|