Skip to content

[Docs Site] Add Width component #21415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 7, 2025
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.