DocsComponentsTemplatesThemesGitHub

AspectRatio

Keeps media at a fixed ratio (16:9 default).

Code

import * as React from 'react';
import { AspectRatio } from '@fruit-labs/design';

export default function Demo() {
  return (
    <div
      style={{
        maxWidth: 280,
      }}
    >
      <AspectRatio ratio={16 / 9}>
        <div
          style={{
            background: 'var(--fruit-grape)',
          }}
        />
      </AspectRatio>
    </div>
  );
}

Install

From npm:

npm install @fruit-labs/design

import { AspectRatio } from '@fruit-labs/design';

Or copy the TypeScript source into your project:

npx shadcn@latest add https://design.fruitlabs.online/r/aspect-ratio.json

Guidelines

  • Children (img/video) fill and crop.

Props

PropTypeRequired
rationumberNo
classNamestringNo
styleReact.CSSPropertiesNo
childrenReact.ReactNodeNo

Edit this example on GitHub