-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0efb52
commit da5472f
Showing
5 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use client'; | ||
import React from 'react'; | ||
import { customClassSwitcher } from '~/core'; | ||
import { clsx } from 'clsx'; | ||
const COMPONENT_NAME = 'AspectRatio'; | ||
|
||
export type AspectRatioProps = { | ||
children: React.ReactNode; | ||
customRootClass?: string; | ||
className?: string; | ||
ratio?: string; | ||
props: Record<string, any>[]; | ||
} | ||
|
||
const AspectRatio = ({ children, customRootClass, className, ratio="1", ...props }: AspectRatioProps) => { | ||
|
||
const rootClass = customClassSwitcher(customRootClass, COMPONENT_NAME); | ||
return <div style={{aspectRatio:ratio}} className={clsx(rootClass, className)} {...props}>{children} </div> | ||
} | ||
AspectRatio.displayName = COMPONENT_NAME; | ||
|
||
export default AspectRatio; |
25 changes: 25 additions & 0 deletions
25
src/components/ui/AspectRatio/stories/AspectRatio.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import AspectRatio from '../AspectRatio'; | ||
import SandboxEditor from '~/components/tools/SandboxEditor/SandboxEditor'; | ||
|
||
// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export | ||
export default { | ||
title: 'Components/AspectRatio', | ||
component: AspectRatio, | ||
render: (args) => <SandboxEditor> | ||
<AspectRatio {...args} > | ||
<img | ||
|
||
className="Image" | ||
src="https://images.pexels.com/photos/346529/pexels-photo-346529.jpeg?cs=srgb&dl=pexels-bri-schneiter-28802-346529.jpg&fm=jpg" | ||
alt="Landscape photograph by Tobias Tullius" | ||
/> | ||
</AspectRatio> | ||
</SandboxEditor> | ||
}; | ||
|
||
// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args | ||
export const Default = { | ||
args: { | ||
ratio: "16/9" | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import AspectRatio from '../AspectRatio'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.rad-ui-aspect-ratio{ | ||
img{ | ||
width: 100%; | ||
height: 100%; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters