Skip to content

Commit

Permalink
aspect ratio component
Browse files Browse the repository at this point in the history
  • Loading branch information
GoldGroove06 committed Dec 19, 2024
1 parent a0efb52 commit da5472f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/components/ui/AspectRatio/AspectRatio.tsx
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 src/components/ui/AspectRatio/stories/AspectRatio.stories.js
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"
}
};
4 changes: 4 additions & 0 deletions src/components/ui/AspectRatio/tests/AspectRatio.test.js
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';

6 changes: 6 additions & 0 deletions styles/themes/components/aspectratio.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.rad-ui-aspect-ratio{
img{
width: 100%;
height: 100%;
}
}
1 change: 1 addition & 0 deletions styles/themes/default.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import "./components/accordion.scss";
@import "./components/alert-dialog.scss";
@import "./components/aspectratio.scss";
@import "./components/avatar.scss";
@import "./components/avatar-group.scss";
@import "./components/badge.scss";
Expand Down

0 comments on commit da5472f

Please sign in to comment.