Hulian UIv0.93.5413 components0 components
  • Start
  • Components
  • Blocks
  • Pages
  • Demos
  • Changelog
ChineseEnglish
  • ComponentsComponents
  • ThemeTheme

Containers

  • Layout
  • AdminLayout
  • SettingsLayout
  • ScrollArea
  • Viewport
  • Resizable
  • AspectRatio
  • FitScreen
  • PreviewSandbox
  • Masonry
  • Container
  • AccentScope

Arrangement

  • Stack
  • Grid
  • Spacer
  • Divider
  • Separator

FitScreen

fit-screen

Scales a fixed design canvas to fit, cover, or stretch within its container.

Usage

Basic usage

Scale the large-screen content with a fixed design size (default 1920×1080) into any parent container and center it proportionally.

1920×1080
Basic usage
tsx
<div className="h-56 w-full overflow-hidden rounded-lg border">
  <FitScreen designWidth={1920} designHeight={1080}>
    {/* Your 1920×1080 large screen content */}
  </FitScreen>
</div>

fit · No cutting to the same ratio

Default mode: Use min zoom, the content is completely visible, and edges may be left around.

1920×1080
mode = fit
tsx
<FitScreen mode="fit">
  {/* Large screen content */}
</FitScreen>

cover · Fully covered and can be cut

Take max and scale it to fill the container in equal proportions, and the excess part will be cut off.

1920×1080
mode = cover
tsx
<FitScreen mode="cover">
  {/* Large screen content */}
</FitScreen>

stretch · Non-equal ratio

Independent horizontal and vertical scaling fills the container, and the content may be deformed.

1920×1080
mode = stretch
tsx
<FitScreen mode="stretch">
  {/* Large screen content */}
</FitScreen>

When to use

Use FitScreen when content has been laid out against a fixed design canvas, such as a 1920×1080 dashboard or presentation slide, and the entire canvas must scale within an arbitrary parent. Set interactive={false} for live slide thumbnails, or use fullscreen / apiRef for presentation fullscreen mode. Use Viewport when content should reflow at container breakpoints instead of scaling, or AspectRatio when a single element only needs a fixed ratio.

Import

ts
import { FitScreen, computeFit } from "@hulianui/ui"

Props

NameTypeDefaultDescription
designWidthnumber1920Design-canvas width.
designHeightnumber1080Design-canvas height.
mode"fit" | "cover" | "stretch""fit"fit preserves the full canvas and may letterbox; cover fills the parent and may crop edges; stretch fills both axes and may distort content.
interactivebooleantrueWhether inner content is interactive. When false, applies inert, pointer-events-none, and select-none for static thumbnail previews without focus leaks.
onScaleChange(scale: FitScale) => void-Called whenever { scaleX, scaleY } changes so overlays such as drawing layers stay aligned.
fullscreenboolean-Controlled fullscreen state; requests Fullscreen on the outer container when true and exits when false.
onFullscreenChange(fullscreen: boolean) => void-Fired when browser fullscreen state changes (including exiting via Esc).
backgroundstring-Optional outer container background color (e.g., letterbox background in fullscreen mode).
apiRefMutableRefObject<FitScreenApi | null>-Imperative handle (enterFullscreen / exitFullscreen / toggleFullscreen / isFullscreen / getScale / element).
classNamestring-The outer container class name.
styleCSSProperties-Inline style applied to the outer container.
FitScreen forwards ref to its outer <div> container via forwardRef.

computeFit(input: FitInput) is the pure scaling function used after ResizeObserver measures the parent. It accepts { outerW, outerH, designW, designH, mode } and can be tested independently.

Slots

SlotTypeDescription
children*ReactNodeContent laid out at the fixed design dimensions.

Usage guidelines

  • Scaling uses transform: scale. Headless/CDP screenshot coordinates may not align with real click geometry. Account for this in visual and interaction tests; see [[recharts-headless-screenshot-blank-clippath-animation-starved]] and [[turbopack-dev-cold-route-blank-cdp-screenshot-warm-first]]. Use dispatchEvent if coordinate clicks are inaccurate.
  • Guard detached refs before writing styles. During StrictMode remounts, <Activity>, or Offscreen reconnection, ref.current can remain truthy after its style target is detached. See [[react-offscreen-reconnect-detached-ref-style-crash]]; check if (!el?.style) return before writing.
  • Keep designWidth and designHeight consistent with the dimensions used to lay out the children. A mismatch produces the wrong scale and can cause clipping or unexpected empty space.
  • Browser Fullscreen requests require a user gesture; non-gesture calls degrade gracefully without throwing.

Related

SlideDeck · Layout · AdminLayout · ScrollArea · Viewport · Resizable · AspectRatio

Playground

1920×1080
mode = fit
<FitScreen designWidth={1920} designHeight={1080} mode="fit">
  {/* Your 1920×1080 large screen content */}
</FitScreen>
PreviousAspectRatioLayoutNextPreviewSandbox

On this page

  • Usage
  • Documentation
    • When to use
    • Import
    • Props
    • Slots
    • Usage guidelines
    • Related
  • Playground