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 20, 2024
1 parent da5472f commit 08e638b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/components/ui/AspectRatio/AspectRatio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export type AspectRatioProps = {
}

const AspectRatio = ({ children, customRootClass, className, ratio="1", ...props }: AspectRatioProps) => {


if (isNaN(Number(ratio)) && !ratio.match(/^(\d+)\/(\d+)$/)) ratio = "1"

const rootClass = customClassSwitcher(customRootClass, COMPONENT_NAME);
return <div style={{aspectRatio:ratio}} className={clsx(rootClass, className)} {...props}>{children} </div>
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/ui/AspectRatio/stories/AspectRatio.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ export default {
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"
alt="Landscape photograph"
/>
</AspectRatio>
</SandboxEditor>
Expand All @@ -20,6 +19,7 @@ export default {
// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
export const Default = {
args: {
className:"",
ratio: "16/9"
}
};
18 changes: 18 additions & 0 deletions src/components/ui/AspectRatio/tests/AspectRatio.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,21 @@ import React from 'react';
import { render, screen } from '@testing-library/react';
import AspectRatio from '../AspectRatio';

describe('AspectRatio', () => {
test('renders AspectRatio component', () => {
render(<AspectRatio>Content</AspectRatio>);
expect(screen.getByText('Content')).toBeInTheDocument();
});

test('applies custom classes correctly', () => {
render(<AspectRatio className="additional-class">Content</AspectRatio>);
const divElement = screen.getByText('Content');
expect(divElement).toHaveClass('additional-class');
});

test('applies correct aspect ratio', () => {
render(<AspectRatio ratio="16/9">Content</AspectRatio>);
expect(screen.getByText('Content')).toHaveStyle( "aspect-ratio: 16/9");
});

});
6 changes: 0 additions & 6 deletions styles/themes/components/aspectratio.scss

This file was deleted.

1 change: 0 additions & 1 deletion styles/themes/default.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@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 08e638b

Please sign in to comment.