`;
-exports[`Frame incorrect usage renders ratio of 1:1 with error if ratio is not an array 1`] = `
+exports[`Frame incorrect usage renders without ratio with error if ratio string is not correct format 1`] = `
.c0 {
- --n: 16;
- --d: 9;
box-sizing: border-box;
display: block;
inline-size: 100%;
position: relative;
overflow: hidden;
- aspect-ratio: var(--n) / var(--d);
+}
+
+.c0[style*="--ratio"] {
+ aspect-ratio: var(--ratio);
}
.c0 > * {
@@ -463,6 +637,11 @@ exports[`Frame incorrect usage renders ratio of 1:1 with error if ratio is not a
![random thing]()
{
expect(Frame).toBeTruthy();
});
- it("renders with ratio", () => {
+ it("renders with ratio as an array", () => {
const frame = create(
![random thing](https://picsum.photos/5000)
@@ -18,6 +18,15 @@ describe("Frame", () => {
expect(frame.toJSON()).toMatchSnapshot();
});
+ it("renders with ratio as a string", () => {
+ const frame = create(
+
+
![random thing](https://picsum.photos/5000)
+
+ );
+ expect(frame.toJSON()).toMatchSnapshot();
+ });
+
it("renders without ratio", () => {
const frame = create(
@@ -59,7 +68,7 @@ describe("Frame", () => {
expect(errorStack.toJSON()).toMatchSnapshot();
});
- it("renders ratio of 1:1 with error if ratio is not an array", () => {
+ it("renders without ratio if ratio is not correct type", () => {
expect(console.error).not.toBeCalled();
const errorStack = create(
@@ -72,7 +81,7 @@ describe("Frame", () => {
expect(errorStack.toJSON()).toMatchSnapshot();
});
- it("falls back to 1 with error if array of length <1 provided", () => {
+ it("renders without ratio with error if array of length <1 provided", () => {
expect(console.error).not.toBeCalled();
const errorStack = create(
@@ -85,7 +94,7 @@ describe("Frame", () => {
expect(errorStack.toJSON()).toMatchSnapshot();
});
- it("falls back to 1 with error if array of length >2 provided", () => {
+ it("renders without ratio with error if array of length >2 provided", () => {
expect(console.error).not.toBeCalled();
const errorStack = create(
@@ -98,7 +107,7 @@ describe("Frame", () => {
expect(errorStack.toJSON()).toMatchSnapshot();
});
- it("falls back to 1 with error if array of not numbers provided", () => {
+ it("renders without ratio with error if array of not numbers provided", () => {
expect(console.error).not.toBeCalled();
const errorStack = create(
@@ -110,5 +119,18 @@ describe("Frame", () => {
expect(console.error).toBeCalled();
expect(errorStack.toJSON()).toMatchSnapshot();
});
+
+ it("renders without ratio with error if ratio string is not correct format", () => {
+ expect(console.error).not.toBeCalled();
+
+ const errorStack = create(
+
+
![random thing](https://picsum.photos/5000)
+
+ );
+
+ expect(console.error).toBeCalled();
+ expect(errorStack.toJSON()).toMatchSnapshot();
+ });
});
});
diff --git a/packages/frame/examples/Frame.stories.mdx b/packages/frame/examples/Frame.stories.mdx
index 0307b3ce95..dd9eb33c5b 100644
--- a/packages/frame/examples/Frame.stories.mdx
+++ b/packages/frame/examples/Frame.stories.mdx
@@ -25,14 +25,28 @@ yarn add @bedrock-layout/frame
-## ratio
+## ratio as string
-The `ratio` prop takes an array of two numbers, which prepresent the ratio of width to height of the desired aspect ratio.
+The `ratio` prop takes a string the is in the format of `${number}/${number}`, which represents the ratio of width to height of the desired aspect ratio.
+
+In the example below, the frame will maintain a 16:9 aspect ratio and will crop the image to fit.
+
+
+
+## ratio as array
+
+The `ratio` prop can also take an array of two numbers, which represent the ratio of width to height of the desired aspect ratio.
In the example below, the frame will maintain a 4:3 aspect ratio and will crop the image to fit.