@justanarthur/modo-ui 2.1.0 → 2.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/blocks/desktop-shell/index.tsx +2 -1
- package/components/inputs/checkbox/index.tsx +5 -0
- package/components/inputs/combobox/index.tsx +9 -4
- package/components/inputs/radio/index.tsx +5 -0
- package/components/inputs/select/index.tsx +23 -3
- package/components/inputs/slider/comfortable.tsx +10 -4
- package/components/inputs/slider/compact.tsx +153 -71
- package/components/inputs/slider/examples.mdx +24 -0
- package/components/inputs/slider/geometry.ts +18 -6
- package/components/inputs/slider/index.tsx +30 -8
- package/components/inputs/slider/value-display.tsx +16 -9
- package/components/inputs/switch/index.tsx +5 -0
- package/components/inputs/textarea/examples.mdx +19 -0
- package/components/inputs/textarea/index.tsx +42 -5
- package/components/navigation/sidebar/sidebar-group.tsx +2 -1
- package/components/navigation/sidebar/sidebar-menu-sub.tsx +2 -1
- package/components/navigation/sidebar/sidebar-shell.tsx +2 -1
- package/components/navigation/tree/index.tsx +2 -1
- package/components/overlays/dropdown/index.tsx +50 -8
- package/components/overlays/dropdown/submenu.tsx +41 -10
- package/components/overlays/tooltip/examples.mdx +13 -0
- package/components/overlays/tooltip/index.tsx +58 -16
- package/dist/blocks/desktop-shell/index.js +10 -9
- package/dist/blocks/sidebar-app/index.js +11 -10
- package/dist/components/actions/button/index.js +2 -2
- package/dist/components/actions/copy/index.js +4 -4
- package/dist/components/containers/accordion/index.d.ts +1 -1
- package/dist/components/containers/accordion/index.js +2 -2
- package/dist/components/containers/card/index.js +3 -3
- package/dist/components/data-display/log-view/index.js +3 -3
- package/dist/components/inputs/checkbox/index.d.ts +2 -0
- package/dist/components/inputs/checkbox/index.js +1 -1
- package/dist/components/inputs/color-picker/index.js +5 -5
- package/dist/components/inputs/combobox/index.d.ts +1 -1
- package/dist/components/inputs/combobox/index.js +2 -2
- package/dist/components/inputs/date-time/date-picker/index.js +7 -7
- package/dist/components/inputs/date-time/date-range-picker/index.js +7 -7
- package/dist/components/inputs/date-time/duration-picker/index.js +7 -7
- package/dist/components/inputs/date-time/month-picker/index.js +7 -7
- package/dist/components/inputs/date-time/time-picker/index.js +7 -7
- package/dist/components/inputs/field/index.js +2 -2
- package/dist/components/inputs/file-dropzone/index.js +3 -3
- package/dist/components/inputs/key-value/index.js +3 -3
- package/dist/components/inputs/radio/index.d.ts +2 -0
- package/dist/components/inputs/radio/index.js +1 -1
- package/dist/components/inputs/search/index.js +6 -6
- package/dist/components/inputs/select/index.d.ts +22 -4
- package/dist/components/inputs/select/index.js +3 -3
- package/dist/components/inputs/slider/index.d.ts +12 -3
- package/dist/components/inputs/slider/index.js +1 -1
- package/dist/components/inputs/switch/index.d.ts +2 -0
- package/dist/components/inputs/switch/index.js +1 -1
- package/dist/components/inputs/textarea/index.d.ts +8 -1
- package/dist/components/inputs/textarea/index.js +1 -1
- package/dist/components/navigation/breadcrumb/index.js +4 -4
- package/dist/components/navigation/navigation-menu/index.js +2 -2
- package/dist/components/navigation/pagination/index.js +3 -3
- package/dist/components/navigation/sidebar/index.js +8 -7
- package/dist/components/navigation/tree/index.js +2 -1
- package/dist/components/overlays/alert-dialog/index.d.ts +3 -3
- package/dist/components/overlays/alert-dialog/index.js +5 -5
- package/dist/components/overlays/command/index.d.ts +1 -1
- package/dist/components/overlays/command/index.js +5 -5
- package/dist/components/overlays/context-menu/index.d.ts +20 -1
- package/dist/components/overlays/context-menu/index.js +4 -4
- package/dist/components/overlays/dialog/index.d.ts +3 -3
- package/dist/components/overlays/dialog/index.js +4 -4
- package/dist/components/overlays/dropdown/index.d.ts +30 -8
- package/dist/components/overlays/dropdown/index.js +3 -3
- package/dist/components/overlays/lightbox/index.js +3 -3
- package/dist/components/overlays/popover/index.d.ts +6 -6
- package/dist/components/overlays/popover/index.js +3 -3
- package/dist/components/overlays/preview-card/index.js +2 -2
- package/dist/components/overlays/sheet/index.d.ts +3 -3
- package/dist/components/overlays/sheet/index.js +5 -5
- package/dist/components/overlays/toast/index.d.ts +1 -1
- package/dist/components/overlays/toast/index.js +3 -3
- package/dist/components/overlays/tooltip/index.d.ts +35 -10
- package/dist/components/overlays/tooltip/index.js +3 -3
- package/dist/docs/index.js +9 -8
- package/dist/index.d.ts +92 -38
- package/dist/index.js +47 -46
- package/dist/lib/inert.d.ts +7 -0
- package/dist/lib/inert.js +6 -0
- package/dist/lib/overlay.d.ts +20 -13
- package/dist/lib/overlay.js +2 -1
- package/dist/lib/slot.d.ts +5 -2
- package/dist/lib/slot.js +1 -1
- package/dist/primitives/layout/resizable/index.d.ts +4 -2
- package/dist/primitives/layout/resizable/index.js +1 -1
- package/dist/primitives/systems/morph/index.js +3 -3
- package/dist/primitives/systems/motion/index.js +3 -3
- package/dist/shared/{components-s90v3jpr.js → components-01e24999.js} +60 -11
- package/dist/shared/{components-a1ms36qq.js → components-1f5624hb.js} +1 -1
- package/dist/shared/{components-9z7bq8gn.js → components-1sbnbq6a.js} +1 -1
- package/dist/shared/{components-w2at9ntm.js → components-27fatggq.js} +1 -1
- package/dist/shared/{components-fmyvz4r2.js → components-2bq4ng4d.js} +4 -4
- package/dist/shared/components-2myjk2zf.js +8 -0
- package/dist/shared/{components-hz6armxa.js → components-2tw25pk6.js} +3 -0
- package/dist/shared/{components-nhmgr5xc.js → components-2v4mmw1s.js} +10 -7
- package/dist/shared/{components-twyj2y8c.js → components-3rt5c1qt.js} +1 -1
- package/dist/shared/{components-91mmbrw3.js → components-3sb31vw5.js} +1 -1
- package/dist/shared/{components-1f3a7gmg.js → components-4fswe4kh.js} +1 -1
- package/dist/shared/{components-gsstwhtv.js → components-5vezp3e5.js} +3 -0
- package/dist/shared/{components-ee09xmkh.js → components-6g8a5nrs.js} +4 -1
- package/dist/shared/{components-h0x2pj2y.js → components-6xtntksc.js} +17 -3
- package/dist/shared/{components-1asw2ph0.js → components-7g2q2ccp.js} +1 -1
- package/dist/shared/{components-kwxye0an.js → components-7wjkag2j.js} +4 -2
- package/dist/shared/{components-vfreweq3.js → components-83jn0raj.js} +1 -1
- package/dist/shared/{components-1bnf96sr.js → components-8e0fjgm9.js} +37 -9
- package/dist/shared/{components-j79a6jqa.js → components-8ybvpebx.js} +1 -1
- package/dist/shared/{components-me742146.js → components-a3brpprb.js} +1 -1
- package/dist/shared/{components-ev0ytbqb.js → components-abqfs5fh.js} +1 -1
- package/dist/shared/{components-r5q9gdh4.js → components-agjpst9b.js} +5 -5
- package/dist/shared/{components-6rtawx8y.js → components-e52xgvd9.js} +4 -4
- package/dist/shared/{components-0cpte6s1.js → components-eebf7f9c.js} +4 -3
- package/dist/shared/{components-xa9fvd5b.js → components-etgpz4zk.js} +1 -1
- package/dist/shared/{components-b9bj65j3.js → components-ex2xtqv7.js} +6 -6
- package/dist/shared/{components-n0gbyp5a.js → components-fjg4j430.js} +5 -5
- package/dist/shared/{components-280grw6q.js → components-fxw1122w.js} +1 -1
- package/dist/shared/{components-y8m64zdw.js → components-gnsvnejm.js} +1 -1
- package/dist/shared/{components-7mj5wsv3.js → components-gr82tz50.js} +21 -3
- package/dist/shared/{components-22h8dvt1.js → components-k25zw9g8.js} +3 -3
- package/dist/shared/{components-a1mwqxsv.js → components-k2gg1agj.js} +3 -3
- package/dist/shared/{components-wx1dcp2n.js → components-kz6ak6kj.js} +1 -1
- package/dist/shared/{components-yf2gtq68.js → components-m7d7r3r8.js} +8 -5
- package/dist/shared/{components-62510420.js → components-mvwf8ckh.js} +4 -4
- package/dist/shared/{components-2m2hg11x.js → components-nh05qz8b.js} +3 -3
- package/dist/shared/{components-77gxngmc.js → components-nred2e6g.js} +5 -5
- package/dist/shared/{components-3rvrdsa9.js → components-s2pnh8h9.js} +1 -1
- package/dist/shared/{components-xnkc892z.js → components-t4j0r23n.js} +1 -1
- package/dist/shared/{components-rgng034x.js → components-tcm3k3wj.js} +24 -3
- package/dist/shared/{components-p32aqk3q.js → components-vx286kq7.js} +110 -73
- package/dist/shared/{components-b2kjsn1s.js → components-vykcfb5r.js} +1 -1
- package/dist/shared/{components-hcftn5r8.js → components-x5v7e0fz.js} +3 -0
- package/dist/shared/{components-0h2mng6m.js → components-ycwhrqe1.js} +1 -1
- package/dist/shared/{components-chda6b23.js → components-ypxst3cn.js} +33 -4
- package/dist/shared/{components-14wzcym0.js → components-z87sanbc.js} +5 -5
- package/dist/shared/{components-fqsgd07c.js → components-zv63s4fh.js} +2 -2
- package/dist/styles.css +5 -1
- package/lib/inert.ts +15 -0
- package/lib/overlay.tsx +49 -5
- package/lib/slot.tsx +9 -3
- package/package.json +6 -1
- package/primitives/layout/resizable/index.tsx +35 -7
package/dist/styles.css
CHANGED
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
}
|
|
63
63
|
/* layer: theme */
|
|
64
64
|
@layer theme{
|
|
65
|
-
:root, :host { --
|
|
65
|
+
:root, :host { --spacing: 0.25rem; --default-transition-timingFunction: cubic-bezier(0.4, 0, 0.2, 1); --default-transition-duration: 150ms; --radius-none: 0; --font-sans: 'Inter Variable', ui-sans-serif, system-ui, sans-serif; --font-mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace; --ease-DEFAULT: cubic-bezier(0.4, 0, 0.2, 1); --radius-md: 0.375rem; --radius-DEFAULT: 0.25rem; --ease-out: cubic-bezier(0, 0, 0.2, 1); --container-sm: 24rem; --leading-relaxed: 1.625; --radius-3xl: 1.5rem; --radius-xl: 0.75rem; --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1); --leading-tight: 1.25; --radius-xs: 0.125rem; --leading-snug: 1.375; --leading-normal: 1.5; --radius-sm: 0.25rem; --radius-2xl: 1rem; --radius-lg: 0.5rem; --leading-none: 1; --container-2xl: 42rem; --default-font-family: var(--font-sans); --default-monoFont-family: var(--font-mono); }
|
|
66
66
|
}
|
|
67
67
|
/* layer: base */
|
|
68
68
|
@layer base{
|
|
@@ -587,6 +587,7 @@
|
|
|
587
587
|
.h-2\.5{height:calc(var(--spacing) * 2.5);}
|
|
588
588
|
.h-24,
|
|
589
589
|
.h24{height:calc(var(--spacing) * 24);}
|
|
590
|
+
.h-40{height:calc(var(--spacing) * 40);}
|
|
590
591
|
.h-5{height:calc(var(--spacing) * 5);}
|
|
591
592
|
.h-56{height:calc(var(--spacing) * 56);}
|
|
592
593
|
.h-6{height:calc(var(--spacing) * 6);}
|
|
@@ -674,6 +675,7 @@
|
|
|
674
675
|
.w-8{width:calc(var(--spacing) * 8);}
|
|
675
676
|
.w-80{width:calc(var(--spacing) * 80);}
|
|
676
677
|
.w-9{width:calc(var(--spacing) * 9);}
|
|
678
|
+
.w-fit{width:fit-content;}
|
|
677
679
|
.w-full{width:100%;}
|
|
678
680
|
.w-max{width:max-content;}
|
|
679
681
|
.w-px{width:1px;}
|
|
@@ -705,6 +707,7 @@
|
|
|
705
707
|
.cursor-col-resize{cursor:col-resize;}
|
|
706
708
|
.cursor-row-resize{cursor:row-resize;}
|
|
707
709
|
.cursor-ew-resize{cursor:ew-resize;}
|
|
710
|
+
.cursor-ns-resize{cursor:ns-resize;}
|
|
708
711
|
.cursor-zoom-in{cursor:zoom-in;}
|
|
709
712
|
.cursor-zoom-out{cursor:zoom-out;}
|
|
710
713
|
.group\/card:focus-within .group-focus-within\/card\:pointer-events-auto,
|
|
@@ -805,6 +808,7 @@
|
|
|
805
808
|
.data-\[ending-style\]\:data-\[activation-direction\=right\]\:-translate-x-4[data-activation-direction=right][data-ending-style],
|
|
806
809
|
.data-\[starting-style\]\:data-\[activation-direction\=left\]\:-translate-x-4[data-activation-direction=left][data-starting-style]{--un-translate-x:calc(var(--spacing) * -4);translate:var(--un-translate-x) var(--un-translate-y);}
|
|
807
810
|
.translate-y-0\.5{--un-translate-y:calc(var(--spacing) * 0.5);translate:var(--un-translate-x) var(--un-translate-y);}
|
|
811
|
+
.translate-y-1\/2{--un-translate-y:50%;translate:var(--un-translate-x) var(--un-translate-y);}
|
|
808
812
|
.after\:-translate-x-1\/2::after{--un-translate-x:-50%;translate:var(--un-translate-x) var(--un-translate-y);}
|
|
809
813
|
.-rotate-45{rotate:-45deg;}
|
|
810
814
|
.-rotate-90{rotate:-90deg;}
|
package/lib/inert.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Local addition (not part of Fluid Functionalism): `inert` that holds on
|
|
3
|
+
* React 18 and 19. React 18 has no `inert` prop and passes it through as an
|
|
4
|
+
* unknown attribute, so it needs a string (`''`); React 19 reads it as a
|
|
5
|
+
* boolean and drops `''`, with a warning.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { version } from 'react'
|
|
9
|
+
|
|
10
|
+
const INERT = (Number.parseInt(version, 10) >= 19 ? true : '') as unknown as boolean
|
|
11
|
+
|
|
12
|
+
/** Spread onto an element to make it inert while `on`. */
|
|
13
|
+
export function inertProps(on: boolean) {
|
|
14
|
+
return on ? { inert: INERT } : {}
|
|
15
|
+
}
|
package/lib/overlay.tsx
CHANGED
|
@@ -10,9 +10,19 @@
|
|
|
10
10
|
|
|
11
11
|
'use client'
|
|
12
12
|
|
|
13
|
-
import
|
|
13
|
+
import type { Popover } from '@base-ui/react/popover'
|
|
14
|
+
import {
|
|
15
|
+
type ComponentProps,
|
|
16
|
+
createContext,
|
|
17
|
+
type ReactNode,
|
|
18
|
+
type RefObject,
|
|
19
|
+
useCallback,
|
|
20
|
+
useContext,
|
|
21
|
+
useMemo,
|
|
22
|
+
} from 'react'
|
|
14
23
|
import { useControllableState } from './use-controllable-state'
|
|
15
24
|
import { inPlaceOffset, type MorphOrigin, type MorphProps, opensInPlace, useMorphOrigin } from './use-morph'
|
|
25
|
+
import { cn } from './utils'
|
|
16
26
|
|
|
17
27
|
type Side = 'top' | 'right' | 'bottom' | 'left'
|
|
18
28
|
type Align = 'start' | 'center' | 'end'
|
|
@@ -32,6 +42,23 @@ interface AnchorProps {
|
|
|
32
42
|
container?: HTMLElement | null
|
|
33
43
|
}
|
|
34
44
|
|
|
45
|
+
type Positioner = ComponentProps<typeof Popover.Positioner>
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The finer positioning props a content may add to `AnchorProps`, forwarded
|
|
49
|
+
* to Base UI's `Positioner` by `positionerProps`. Documented once.
|
|
50
|
+
*/
|
|
51
|
+
interface CollisionProps {
|
|
52
|
+
/** Shift along the aligned edge in px, after `align`, or Base UI's function of side, align and sizes. Defaults to `0`. */
|
|
53
|
+
alignOffset?: Positioner['alignOffset']
|
|
54
|
+
/** Space kept between the panel and the edge of its collision boundary, in px or per side. Defaults to `5`. */
|
|
55
|
+
collisionPadding?: Positioner['collisionPadding']
|
|
56
|
+
/** The area the panel stays inside: an element, several, or a rect. Defaults to `'clipping-ancestors'`. */
|
|
57
|
+
collisionBoundary?: Positioner['collisionBoundary']
|
|
58
|
+
/** Classes for the positioner, the element that carries the panel's place and stacking (a `z-index` over a host's own layers). */
|
|
59
|
+
positionerClassName?: string
|
|
60
|
+
}
|
|
61
|
+
|
|
35
62
|
/** What an overlay's parts read from its root. */
|
|
36
63
|
interface OverlayState {
|
|
37
64
|
open: boolean
|
|
@@ -89,15 +116,32 @@ function useOverlay(part: string): OverlayState {
|
|
|
89
116
|
* when the panel opens in place. Spread them on the `Positioner`.
|
|
90
117
|
*/
|
|
91
118
|
function positionerProps(
|
|
92
|
-
{
|
|
119
|
+
{
|
|
120
|
+
side,
|
|
121
|
+
align,
|
|
122
|
+
sideOffset,
|
|
123
|
+
effect,
|
|
124
|
+
hideSource,
|
|
125
|
+
alignOffset,
|
|
126
|
+
collisionPadding,
|
|
127
|
+
collisionBoundary,
|
|
128
|
+
positionerClassName,
|
|
129
|
+
}: AnchorProps & MorphProps & CollisionProps,
|
|
93
130
|
defaults: { side: Side; align: Align; sideOffset: number },
|
|
94
|
-
) {
|
|
131
|
+
): Pick<Positioner, 'sideOffset' | 'alignOffset' | 'collisionPadding' | 'collisionBoundary'> & {
|
|
132
|
+
side: Side
|
|
133
|
+
align: Align
|
|
134
|
+
className: string
|
|
135
|
+
} {
|
|
95
136
|
const inPlace = opensInPlace({ effect, hideSource })
|
|
96
137
|
return {
|
|
97
138
|
side: side ?? defaults.side,
|
|
98
139
|
align: align ?? (inPlace ? 'start' : defaults.align),
|
|
99
140
|
sideOffset: inPlace ? inPlaceOffset : (sideOffset ?? defaults.sideOffset),
|
|
100
|
-
|
|
141
|
+
alignOffset,
|
|
142
|
+
collisionPadding,
|
|
143
|
+
collisionBoundary,
|
|
144
|
+
className: cn('z-50 outline-none', positionerClassName),
|
|
101
145
|
}
|
|
102
146
|
}
|
|
103
147
|
|
|
@@ -114,5 +158,5 @@ function usePortalContainer(container?: HTMLElement | null) {
|
|
|
114
158
|
return container ?? scoped ?? undefined
|
|
115
159
|
}
|
|
116
160
|
|
|
117
|
-
export type { Align, AnchorProps, OpenChangeDetails, OverlayRootProps, OverlayState, Side }
|
|
161
|
+
export type { Align, AnchorProps, CollisionProps, OpenChangeDetails, OverlayRootProps, OverlayState, Side }
|
|
118
162
|
export { OverlayContext, PortalContainer, positionerProps, useOverlay, useOverlayRoot, usePortalContainer }
|
package/lib/slot.tsx
CHANGED
|
@@ -25,7 +25,7 @@ import { mergeRefs } from './merge-refs'
|
|
|
25
25
|
import { cn } from './utils'
|
|
26
26
|
|
|
27
27
|
interface SlotProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
28
|
-
/** The element that becomes the control, e.g. a Button. */
|
|
28
|
+
/** The element that becomes the control, e.g. a Button. `children` fill it when it has none of its own. */
|
|
29
29
|
render?: ReactElement
|
|
30
30
|
/** Compose onto the single child instead. Defaults to `false`. */
|
|
31
31
|
asChild?: boolean
|
|
@@ -33,9 +33,15 @@ interface SlotProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
|
33
33
|
children?: ReactNode
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* The element a Base UI part renders as: `render`, else `asChild`'s child, else none. `children` fill
|
|
38
|
+
* a `render` element that has none of its own (`render={<button/>}` + children); its own children win.
|
|
39
|
+
*/
|
|
37
40
|
function slotRender(render: ReactElement | undefined, asChild: boolean | undefined, children: ReactNode) {
|
|
38
|
-
if (render)
|
|
41
|
+
if (render) {
|
|
42
|
+
const own = (render.props as { children?: ReactNode }).children
|
|
43
|
+
return children === undefined || own !== undefined ? render : cloneElement(render, undefined, children)
|
|
44
|
+
}
|
|
39
45
|
return asChild && isValidElement(children) ? children : undefined
|
|
40
46
|
}
|
|
41
47
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justanarthur/modo-ui",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.3.0",
|
|
5
5
|
"description": "Fluid Functionalism (Base UI flavor, MIT © 2026 Micka Touillaud) ported to UnoCSS: motion springs, fluid hover, a two-step size ladder and an eight-level elevated surface system. Documented with modo.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"keywords": [
|
|
@@ -118,6 +118,11 @@
|
|
|
118
118
|
"source": "./lib/icon-context.tsx",
|
|
119
119
|
"default": "./dist/lib/icon-context.js"
|
|
120
120
|
},
|
|
121
|
+
"./lib/inert": {
|
|
122
|
+
"types": "./dist/lib/inert.d.ts",
|
|
123
|
+
"source": "./lib/inert.ts",
|
|
124
|
+
"default": "./dist/lib/inert.js"
|
|
125
|
+
},
|
|
121
126
|
"./lib/merge-refs": {
|
|
122
127
|
"types": "./dist/lib/merge-refs.d.ts",
|
|
123
128
|
"source": "./lib/merge-refs.ts",
|
|
@@ -140,7 +140,14 @@ function ResizableHandle({ label = 'Resize', className }: ResizableHandleProps)
|
|
|
140
140
|
const index = useContext(ResizableIndexContext)
|
|
141
141
|
const reduced = useReduceMotion()
|
|
142
142
|
const [hovered, setHovered] = useState(false)
|
|
143
|
-
const drag = useRef<{
|
|
143
|
+
const drag = useRef<{
|
|
144
|
+
start: number
|
|
145
|
+
sizes: number[]
|
|
146
|
+
next: number[]
|
|
147
|
+
panels: HTMLElement[]
|
|
148
|
+
flex: string[]
|
|
149
|
+
pxPerPercent: number
|
|
150
|
+
} | null>(null)
|
|
144
151
|
const [dragging, setOwnDragging] = useState(false)
|
|
145
152
|
const setDragging = (next: boolean) => {
|
|
146
153
|
setOwnDragging(next)
|
|
@@ -152,15 +159,22 @@ function ResizableHandle({ label = 'Resize', className }: ResizableHandleProps)
|
|
|
152
159
|
|
|
153
160
|
const onPointerDown = (e: PointerEvent<HTMLDivElement>) => {
|
|
154
161
|
if (e.button !== 0) return
|
|
155
|
-
const panels = [...(e.currentTarget.parentElement?.children ?? [])].filter(
|
|
156
|
-
el.hasAttribute('data-resizable-panel'),
|
|
162
|
+
const panels = [...(e.currentTarget.parentElement?.children ?? [])].filter(
|
|
163
|
+
(el): el is HTMLElement => el instanceof HTMLElement && el.hasAttribute('data-resizable-panel'),
|
|
157
164
|
)
|
|
158
165
|
const px = panels.reduce((sum, el) => {
|
|
159
166
|
const rect = el.getBoundingClientRect()
|
|
160
167
|
return sum + (horizontal ? rect.width : rect.height)
|
|
161
168
|
}, 0)
|
|
162
169
|
e.currentTarget.setPointerCapture(e.pointerId)
|
|
163
|
-
drag.current = {
|
|
170
|
+
drag.current = {
|
|
171
|
+
start: horizontal ? e.clientX : e.clientY,
|
|
172
|
+
sizes: group.sizes,
|
|
173
|
+
next: group.sizes,
|
|
174
|
+
panels,
|
|
175
|
+
flex: panels.map(el => el.style.flex),
|
|
176
|
+
pxPerPercent: px / 100,
|
|
177
|
+
}
|
|
164
178
|
setDragging(true)
|
|
165
179
|
e.preventDefault()
|
|
166
180
|
}
|
|
@@ -169,12 +183,24 @@ function ResizableHandle({ label = 'Resize', className }: ResizableHandleProps)
|
|
|
169
183
|
const d = drag.current
|
|
170
184
|
if (!d?.pxPerPercent) return
|
|
171
185
|
const delta = ((horizontal ? e.clientX : e.clientY) - d.start) / d.pxPerPercent
|
|
172
|
-
|
|
186
|
+
d.next = resize(d.sizes, index, delta, group.limits)
|
|
187
|
+
// A drag step re-renders nothing: it writes the panels' flex, and the sizes commit on release.
|
|
188
|
+
d.panels.forEach((el, i) => {
|
|
189
|
+
el.style.flex = `${d.next[i] ?? 0} 1 0px`
|
|
190
|
+
})
|
|
191
|
+
e.currentTarget.setAttribute('aria-valuenow', String(Math.round(d.next[index] ?? 0)))
|
|
173
192
|
}
|
|
174
193
|
|
|
175
194
|
const onPointerUp = () => {
|
|
195
|
+
const d = drag.current
|
|
176
196
|
drag.current = null
|
|
177
197
|
setDragging(false)
|
|
198
|
+
if (!d) return
|
|
199
|
+
// Back to what React rendered, so sizes a controlled parent turns down don't stick.
|
|
200
|
+
d.panels.forEach((el, i) => {
|
|
201
|
+
el.style.flex = d.flex[i] ?? ''
|
|
202
|
+
})
|
|
203
|
+
group.setSizes(d.next)
|
|
178
204
|
}
|
|
179
205
|
|
|
180
206
|
const onKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
|
|
@@ -245,7 +271,7 @@ interface ResizableProps {
|
|
|
245
271
|
direction?: ResizableDirection
|
|
246
272
|
/** Controlled panel sizes in percent, one per panel in order. Pair with `onSizesChange`. */
|
|
247
273
|
sizes?: number[]
|
|
248
|
-
/** Called with every panel's size
|
|
274
|
+
/** Called with every panel's size when a handle moves: on a drag's release, on each key and on a double-click. */
|
|
249
275
|
onSizesChange?: (sizes: number[]) => void
|
|
250
276
|
/** Percent a handle moves per arrow key. Defaults to `5`. */
|
|
251
277
|
step?: number
|
|
@@ -267,7 +293,9 @@ interface ResizableProps {
|
|
|
267
293
|
* its starting size. A collapsible panel snaps shut when dragged below half
|
|
268
294
|
* its minimum. A drag follows the pointer; every other change of size (a
|
|
269
295
|
* key, a reset, new controlled `sizes`, such as a toggle folding a pane)
|
|
270
|
-
* glides there.
|
|
296
|
+
* glides there. A drag writes the panels' sizes to the DOM and commits them
|
|
297
|
+
* (`onSizesChange`) on release, so it re-renders nothing on the way. Sizes
|
|
298
|
+
* work uncontrolled (each panel's `defaultSize`) or
|
|
271
299
|
* controlled (`sizes` + `onSizesChange`). Groups nest: put a Resizable inside
|
|
272
300
|
* a panel to split it the other way.
|
|
273
301
|
*
|