feat(ui): add docking, viewport controls and composed settings
Add shared dock layouts, navigation cube, range bands, progress actions and comparison surfaces. Extend toolbar menus and loading composition, and align tokens, registry entries, documentation and the living catalog.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
export type FloatingPlacement = "bottom-start" | "bottom-end" | "top-start" | "top-end";
|
||||
export type FloatingPlacement = "bottom-start" | "bottom-end" | "top-start" | "top-end" | "left-start" | "right-start";
|
||||
|
||||
export interface RectLike {
|
||||
top: number;
|
||||
@@ -15,6 +15,7 @@ export interface FloatingPositionOptions {
|
||||
surfaceHeight: number;
|
||||
placement?: FloatingPlacement;
|
||||
offset?: number;
|
||||
flip?: boolean;
|
||||
viewportWidth?: number;
|
||||
viewportHeight?: number;
|
||||
viewportPadding?: number;
|
||||
@@ -24,6 +25,7 @@ export interface FloatingPosition {
|
||||
top: number;
|
||||
left: number;
|
||||
maxHeight: number;
|
||||
maxWidth?: number;
|
||||
resolvedPlacement: FloatingPlacement;
|
||||
}
|
||||
|
||||
@@ -33,6 +35,7 @@ export function computeFloatingPosition({
|
||||
surfaceHeight,
|
||||
placement = "bottom-start",
|
||||
offset = 8,
|
||||
flip = true,
|
||||
viewportWidth = typeof window === "undefined" ? 1920 : window.innerWidth,
|
||||
viewportHeight = typeof window === "undefined" ? 1080 : window.innerHeight,
|
||||
viewportPadding = 8,
|
||||
@@ -41,6 +44,22 @@ export function computeFloatingPosition({
|
||||
0,
|
||||
viewportHeight - viewportPadding * 2,
|
||||
);
|
||||
if (placement.startsWith("left") || placement.startsWith("right")) {
|
||||
const roomLeft = Math.max(0, anchor.left - offset - viewportPadding);
|
||||
const roomRight = Math.max(0, viewportWidth - anchor.right - offset - viewportPadding);
|
||||
const leftRequested = placement.startsWith("left");
|
||||
const switched = flip && (leftRequested ? surfaceWidth > roomLeft && roomRight > roomLeft : surfaceWidth > roomRight && roomLeft > roomRight);
|
||||
const toLeft = switched ? !leftRequested : leftRequested;
|
||||
const maxWidth = toLeft ? roomLeft : roomRight;
|
||||
const actualWidth = Math.min(surfaceWidth, maxWidth);
|
||||
const visibleHeight = Math.min(surfaceHeight, viewportAvailableHeight);
|
||||
return {
|
||||
left: toLeft ? anchor.left - offset - actualWidth : anchor.right + offset,
|
||||
top: Math.max(viewportPadding, Math.min(anchor.top, viewportHeight - viewportPadding - visibleHeight)),
|
||||
maxHeight: viewportAvailableHeight, maxWidth,
|
||||
resolvedPlacement: toLeft ? "left-start" : "right-start",
|
||||
};
|
||||
}
|
||||
const roomBelow = Math.min(
|
||||
viewportAvailableHeight,
|
||||
Math.max(0, viewportHeight - anchor.bottom - offset - viewportPadding),
|
||||
@@ -50,9 +69,9 @@ export function computeFloatingPosition({
|
||||
Math.max(0, anchor.top - offset - viewportPadding),
|
||||
);
|
||||
const requestedTop = placement.startsWith("top");
|
||||
const shouldFlip = requestedTop
|
||||
const shouldFlip = flip && (requestedTop
|
||||
? surfaceHeight > roomAbove && roomBelow > roomAbove
|
||||
: surfaceHeight > roomBelow && roomAbove > roomBelow;
|
||||
: surfaceHeight > roomBelow && roomAbove > roomBelow);
|
||||
const resolvedPlacement = shouldFlip
|
||||
? (`${requestedTop ? "bottom" : "top"}-${placement.endsWith("end") ? "end" : "start"}` as FloatingPlacement)
|
||||
: placement;
|
||||
|
||||
Reference in New Issue
Block a user