Skip to content

Commit 4b97881

Browse files
authored
[Docs Site] Add Width component (#21415)
* [Docs Site] Add Width component * use zod * add centering * add centering example
1 parent 6796708 commit 4b97881

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

src/components/Width.astro

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
import { z } from "astro:schema";
3+
4+
type Props = z.infer<typeof props>;
5+
6+
const props = z.object({
7+
size: z.enum(["large", "medium", "small"]),
8+
center: z.boolean().default(false),
9+
});
10+
11+
const { size, center } = props.parse(Astro.props);
12+
13+
const widthClasses = {
14+
large: "w-3/4",
15+
medium: "w-1/2",
16+
small: "w-1/4",
17+
};
18+
---
19+
20+
<div class:list={[widthClasses[size], center ? "mx-auto" : ""]}>
21+
<slot />
22+
</div>

src/components/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export { default as Type } from "./Type.astro";
5959
export { default as TypeScriptExample } from "./TypeScriptExample.astro";
6060
export { default as WranglerConfig } from "./WranglerConfig.astro";
6161
export { default as WARPReleases } from "./WARPReleases.astro";
62+
export { default as Width } from "./Width.astro";
6263
export { default as WorkersArchitectureDiagram } from "./WorkersArchitectureDiagram.astro";
6364
export { default as WorkersIsolateDiagram } from "./WorkersIsolateDiagram.astro";
6465
export { default as WorkerStarter } from "./WorkerStarter.astro";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
title: Width
3+
styleGuide:
4+
component: Width
5+
---
6+
7+
This component can be used to constrain the width of content, such as text or images.
8+
9+
## Import
10+
11+
```mdx
12+
import { Width } from "~/components";
13+
```
14+
15+
## Usage
16+
17+
```mdx live
18+
import { Width } from "~/components";
19+
20+
<Width size="large">This content will take up 75% of the container width</Width>
21+
22+
<Width size="medium">
23+
This content will take up 50% of the container width
24+
</Width>
25+
26+
<Width size="small">This content will take up 25% of the container width</Width>
27+
28+
<Width size="small" center>
29+
This content will take up 25% of the container width and be centered
30+
</Width>
31+
```
32+
33+
## `<Width>` Props
34+
35+
### `size`
36+
37+
**required**
38+
39+
**type:** `"large" | "medium" | "small"`
40+
41+
Controls the width of the container:
42+
43+
- `large`: 75% of container width
44+
- `medium`: 50% of container width
45+
- `small`: 25% of container width
46+
47+
### `center`
48+
49+
**type:** `boolean`
50+
51+
Whether to horizontally center the content.

0 commit comments

Comments
 (0)