Skip to content

Commit

Permalink
feat: added types for the AspectRatio component (#13753)
Browse files Browse the repository at this point in the history
* feat: added types for the AspectRatio component

* refactor: removed @description jsdoc annotations

---------

Co-authored-by: Sunny.Johal <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 7, 2023
1 parent 57decc1 commit c5e4bcc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,58 @@

import cx from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import React, { PropsWithChildren, ReactHTML } from 'react';
import { usePrefix } from '../../internal/usePrefix';

interface AspectRatioProps {
/**
* Provide a custom component or string to be rendered as
* the outermost node of the component. This is useful if you want
* to deviate from the default `div` tag, where you could specify
* `section` or `article` instead.
*
* ```jsx
* <AspectRatio as="article">My content</AspectRatio>
* ```
*/
as?: keyof ReactHTML;

/**
* Specify a class name for the outermost node
* of the component.
*/
className?: string;

/**
* Specify the ratio to be used by the aspect ratio
* container. This will determine what aspect ratio your content
* will be displayed in.
*/
ratio?:
| '1x1'
| '2x3'
| '3x2'
| '3x4'
| '4x3'
| '1x2'
| '2x1'
| '9x16'
| '16x9';
}

/**
* The AspectRatio component provides a `ratio` prop that will be used to
* specify the aspect ratio that the children you provide will be displayed in.
* This is often useful alongside our grid components, or for media assets like
* images or videos.
*/
function AspectRatio({
const AspectRatio = ({
as: BaseComponent = 'div',
className: containerClassName,
children,
ratio = '1x1',
...rest
}) {
}: PropsWithChildren<AspectRatioProps>) => {
const prefix = usePrefix();
const className = cx(
containerClassName,
Expand All @@ -34,7 +70,7 @@ function AspectRatio({
{children}
</BaseComponent>
);
}
};

AspectRatio.propTypes = {
/**
Expand Down

0 comments on commit c5e4bcc

Please sign in to comment.