Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/components/Width.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
import { z } from "astro:schema";

type Props = z.infer<typeof props>;

const props = z.object({
size: z.enum(["large", "medium", "small"]),
center: z.boolean().default(false),
});

const { size, center } = props.parse(Astro.props);

const widthClasses = {
large: "w-3/4",
medium: "w-1/2",
small: "w-1/4",
};
---

<div class:list={[widthClasses[size], center ? "mx-auto" : ""]}>
<slot />
</div>
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export { default as Type } from "./Type.astro";
export { default as TypeScriptExample } from "./TypeScriptExample.astro";
export { default as WranglerConfig } from "./WranglerConfig.astro";
export { default as WARPReleases } from "./WARPReleases.astro";
export { default as Width } from "./Width.astro";
export { default as WorkersArchitectureDiagram } from "./WorkersArchitectureDiagram.astro";
export { default as WorkersIsolateDiagram } from "./WorkersIsolateDiagram.astro";
export { default as WorkerStarter } from "./WorkerStarter.astro";
Expand Down
51 changes: 51 additions & 0 deletions src/content/docs/style-guide/components/width.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
title: Width
styleGuide:
component: Width
---

This component can be used to constrain the width of content, such as text or images.

## Import

```mdx
import { Width } from "~/components";
```

## Usage

```mdx live
import { Width } from "~/components";

<Width size="large">This content will take up 75% of the container width</Width>

<Width size="medium">
This content will take up 50% of the container width
</Width>

<Width size="small">This content will take up 25% of the container width</Width>

<Width size="small" center>
This content will take up 25% of the container width and be centered
</Width>
```

## `<Width>` Props

### `size`

**required**

**type:** `"large" | "medium" | "small"`

Controls the width of the container:

- `large`: 75% of container width
- `medium`: 50% of container width
- `small`: 25% of container width

### `center`

**type:** `boolean`

Whether to horizontally center the content.