Marigold
v18.0.0-beta.4
Marigold
v18.0.0-beta.4

Application

MarigoldProvider
RouterProvider

Layout

AppShellbeta
Aside
Aspect
Center
Columns
Container
Grid
Inline
Inset
Pagebeta
Panelbeta
Scrollable
Split
Stack
Tiles

Actions

Buttonupdated
ButtonGroupbeta
Link
LinkButton
ToggleButtonbeta

Form

Autocomplete
Calendar
Checkbox
ComboBox
DateField
DatePicker
DateRangePickerbeta
FileField
Form
NumberField
Radio
RangeCalendaralpha
SearchField
SegmentedControlbeta
Select
SelectListupdated
Slider
Switchupdated
TagFieldbeta
TextArea
TextField
TimeField

Collection

Cardupdated
Table
Tag
ActionBaralpha

Navigation

Accordion
Breadcrumbs
Pagination
Sidebarbeta
Tabs
TopNavigationbeta

Overlay

ActionMenualpha
ContextualHelp
Dialog
Drawer
Menuupdated
Toastbeta
Tooltip

Content

Badge
Descriptionalpha
Divider
EmptyStatebeta
ErrorStatebeta
Headline
Keyboardbeta
List
Loader
SectionMessage
SVG
Text
TextValuealpha
Titlealpha

Formatters

DateFormat
NumericFormat

Hooks and Utils

cn
cva
extendTheme
parseFormData
useAsyncListData
useLandmark
useListData
useTheme
VisuallyHidden
Components

Aspect

Keep media elements at a certain apsect ratio.

The <Aspect> component keeps media elements like images or videos in their correct aspect ratio, preventing them from looking stretched or squished on different screens. It is particularly useful for creating responsive layouts where consistent media dimensions are important.

Usage

When using the <Aspect> component to maintain the aspect ratio of media elements, choose an appropriate predefined ratio to ensure a consistent and visually appealing layout. The available aspect ratios include:

  • square: For media that should have equal width and height.
  • landscape: Suitable for wider-than-tall elements, commonly used for photos and videos.
  • portrait: Ideal for media taller than they are wide, like profile pictures.
  • widescreen: Useful for standard video content with a 16:9 ratio.
  • ultrawide: Best for extra-wide content, such as panoramic media.
  • golden: Reflects the golden ratio, providing a balanced and aesthetically pleasing aspect.

Select a ratio based on the type of media and the context in which it is displayed to achieve the best visual effect.

an abstract marigold flower
an abstract marigold flower
an abstract marigold flower
an abstract marigold flower
an abstract marigold flower
an abstract marigold flower
import { Aspect } from '@marigold/components';export default () => (  <div className="grid auto-rows-max grid-cols-[repeat(auto-fill,minmax(200px,1fr))] gap-x-2 gap-y-4">    <Aspect ratio="portrait">      <img        src="/marigold-abstract.webp"        className="object-cover"        alt="an abstract marigold flower"      />    </Aspect>    <Aspect ratio="square">      <img src="/marigold-abstract.webp" alt="an abstract marigold flower" />    </Aspect>    <Aspect ratio="landscape">      <img        src="/marigold-abstract.webp"        className="object-cover"        alt="an abstract marigold flower"      />    </Aspect>    <Aspect ratio="golden">      <img        src="/marigold-abstract.webp"        className="object-cover"        alt="an abstract marigold flower"      />    </Aspect>    <Aspect ratio="widescreen">      <img        src="/marigold-abstract.webp"        className="object-cover"        alt="an abstract marigold flower"      />    </Aspect>    <Aspect ratio="ultrawide">      <img        src="/marigold-abstract.webp"        className="object-cover"        alt="an abstract marigold flower"      />    </Aspect>  </div>);

Image

When using the <Aspect> component with the <Image> component, it's recommended to use the fit and position of the <Image> component properties to achieve the best results. The fit option ensures that the image is properly resized to fill the aspect container without distortion, while the position option controls how the image is aligned within the container, allowing for better visual balance.

a field of marigold flowers and a bright blue sky
a field of marigold flowers and a bright blue sky
import { Aspect, Stack } from '@marigold/components';export default () => (  <Stack space={4}>    <Aspect ratio="ultrawide">      <img        src="/marigold-field.webp"        className="object-cover object-bottom"        alt="a field of marigold flowers and a bright blue sky"      />    </Aspect>    <Aspect ratio="ultrawide">      <img        src="/marigold-field.webp"        className="object-cover object-top"        alt="a field of marigold flowers and a bright blue sky"      />    </Aspect>  </Stack>);

Iframe

When using the <Aspect> component with an <iframe>, it can help to maintain the aspect ratio of embedded content, such as videos or maps, ensuring they appear correctly across different screen sizes.

To get the best results, combine the aspect component with appropriate width and height settings on the iframe to avoid any stretching or scaling issues.

import { Aspect } from '@marigold/components';export default () => (  <Aspect ratio="landscape">    <iframe      src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d4820.000043444012!2d7.826018541821473!3d48.020383262446884!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x47911b1e29425703%3A0xbe342117a976e59!2sEuropa-Park%20Stadion!5e1!3m2!1sde!2sde!4v1647595604899!5m2!1sde!2sde"      title="Google Maps showing the SC Freiburg stadium"      width="100%"      height="100%"    />  </Aspect>);

Max Width

Setting a max width is useful when you want to prevent a media element from growing too large, especially on wider screens. It helps maintain a balanced layout by ensuring the media stays within a reasonable size.

The max width can be controlled using the maxWidth prop, allowing you to easily set a limit that fits your layout needs.

an abstract marigold flower
import { Aspect } from '@marigold/components';export default () => (  <Aspect ratio="square" maxWidth="20vw">    <img src="/marigold-abstract.webp" alt="an abstract marigold flower" />  </Aspect>);

Props

Did you know? You can explore, test, and customize props live in Marigold's storybook. Watch the effects they have in real-time!
View Aspect stories

Aspect

Prop

Type

Accessibility props (6)

Prop

Type

Related

Building layouts

Learn how to build layouts.
Last update: 5 months ago

Aside

Component to separate content from the main content.

Center

Component to center its children horizontally.

On this page

UsageImageIframeMax WidthPropsAspectRelated