Skip to content
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

Add <Badge> component #1530

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c63a6c3
Move <Badge> to user components
kevinzunigacuellar Feb 18, 2024
41dad00
testing page
kevinzunigacuellar Feb 18, 2024
a1761f5
add changeset
kevinzunigacuellar Feb 18, 2024
80ad0ae
copilot bad!
kevinzunigacuellar Feb 18, 2024
cf8a9a6
new light themes, expose css variables, override themes for md content
kevinzunigacuellar Feb 22, 2024
480b08b
more examples
kevinzunigacuellar Feb 22, 2024
9383dce
add `class` for defining custom badges
kevinzunigacuellar Feb 22, 2024
7e726d7
switch set:html for slot
kevinzunigacuellar Feb 22, 2024
22a517e
add class to badge schema and sidebar
kevinzunigacuellar Feb 22, 2024
d915e4f
add docs!
kevinzunigacuellar Feb 26, 2024
14d84cf
Merge branch 'main' into kevin/badge
kevinzunigacuellar Apr 15, 2024
9a64a0f
Wip: badge
kevinzunigacuellar Apr 16, 2024
7c98bad
Update badge component and related schemas
kevinzunigacuellar Apr 16, 2024
94c6d8e
remove unused exports
kevinzunigacuellar Apr 16, 2024
4e9256d
docs: add class override
kevinzunigacuellar Apr 16, 2024
d2e05f1
Merge branch 'main' into kevin/badge
kevinzunigacuellar Apr 16, 2024
ec2afcc
Remove test file
kevinzunigacuellar Apr 16, 2024
a62ead3
move badge docs before icon section
kevinzunigacuellar Apr 16, 2024
263f0cc
feat: tweak badge appearance in headings
HiDeoo Apr 29, 2024
3926ac4
export and use BadgeComponent type for badge component
kevinzunigacuellar May 1, 2024
b77871d
update docs 💜
kevinzunigacuellar May 1, 2024
474395b
rfc: BadgeComponent to support `attrs`
kevinzunigacuellar May 7, 2024
7acfb8e
chore: Update badge component documentation
kevinzunigacuellar May 7, 2024
d1ce134
remove attrs from schema
kevinzunigacuellar May 7, 2024
9bce965
update docs
kevinzunigacuellar May 7, 2024
de49e5c
remove comma
kevinzunigacuellar May 7, 2024
4cbf409
Apply suggestions from code review
kevinzunigacuellar May 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/wicked-melons-study.md
@@ -0,0 +1,6 @@
---
'@astrojs/starlight': minor
---

Adds the `<Badge>` component

57 changes: 57 additions & 0 deletions docs/src/content/docs/guides/components.mdx
Expand Up @@ -296,3 +296,60 @@ The code above generates the following on the page:
import importedCode from '/src/env.d.ts?raw';

<Code code={importedCode} lang="ts" title="src/env.d.ts" />

### Badge

import { Badge } from '@astrojs/starlight/components';

Use the `<Badge>` component to display small pieces of information, such as status or labels.

Place the content you want to display inside the `<Badge>` component. Optionally, you can specify a `variant` attribute with values like `tip`, `note`, `caution`, `danger`, `success`, or `default` to adjust the badge's color.
kevinzunigacuellar marked this conversation as resolved.
Show resolved Hide resolved

```mdx
kevinzunigacuellar marked this conversation as resolved.
Show resolved Hide resolved

import { Badge } from '@astrojs/starlight/components';

- <Badge variant="note">Note</Badge>
- <Badge variant="tip">Tip</Badge>
- <Badge variant="success">Success</Badge>
- <Badge variant="danger">Danger</Badge>
- <Badge variant="caution">Caution</Badge>
- <Badge variant="default">Default</Badge>

```
- <Badge variant="note">Note</Badge>
kevinzunigacuellar marked this conversation as resolved.
Show resolved Hide resolved
- <Badge variant="tip">Tip</Badge>
- <Badge variant="success">Success</Badge>
- <Badge variant="danger">Danger</Badge>
- <Badge variant="caution">Caution</Badge>
- <Badge variant="default">Default</Badge>

You can customize the badge variants colors by setting the CSS variables.

```css
:root {
--sl-badge-default-bg: var(--sl-color-accent-low);
--sl-badge-default-border: var(--sl-color-accent);
--sl-badge-default-text: var(--sl-color-accent-high);

--sl-badge-note-bg: var(--sl-color-blue-low);
--sl-badge-note-border: var(--sl-color-blue);
--sl-badge-note-text: var(--sl-color-blue-high);

--sl-badge-danger-bg: var(--sl-color-red-low);
--sl-badge-danger-border: var(--sl-color-red);
--sl-badge-danger-text: var(--sl-color-red-high);

--sl-badge-success-bg: var(--sl-color-green-low);
--sl-badge-success-border: var(--sl-color-green);
--sl-badge-success-text: var(--sl-color-green-high);

--sl-badge-caution-bg: var(--sl-color-orange-low);
--sl-badge-caution-border: var(--sl-color-orange);
--sl-badge-caution-text: var(--sl-color-orange-high);

--sl-badge-tip-bg: var(--sl-color-purple-low);
--sl-badge-tip-border: var(--sl-color-purple);
--sl-badge-tip-text: var(--sl-color-purple-high);
}
```
kevinzunigacuellar marked this conversation as resolved.
Show resolved Hide resolved
72 changes: 72 additions & 0 deletions docs/src/content/docs/reference/test.mdx
@@ -0,0 +1,72 @@
---
title: Testing badges
description: Learn how to start building your next documentation site with Starlight by Astro.
sidebar:
badge: Test
---

import { Tabs, TabItem, Badge } from '@astrojs/starlight/components';

## APIs

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

### <Badge variant="success">POST</Badge> `/api/users`

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

#### <Badge variant="tip">PUT</Badge> `/api/users`

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

##### <Badge variant="danger">DELETE</Badge> `/api/users`

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

### Lists

- *Italic <Badge variant="caution">caution</Badge>* lorem ipsum
- **Bold <Badge variant="tip">caution</Badge>** lorem ipsum
- ***Bold Italic <Badge variant="note">caution</Badge>*** lorem ipsum
- Custom <Badge class="custom-badge">Custom</Badge> lorem ipsum

### Asides

:::danger
<Badge variant="note">note</Badge> <Badge variant="caution">caution</Badge> <Badge variant="danger">danger</Badge> <Badge variant="success">sucess</Badge> <Badge variant="tip">tip</Badge> <Badge variant="default">default</Badge>
:::


:::note
<Badge variant="note">note</Badge> <Badge variant="caution">caution</Badge> <Badge variant="danger">danger</Badge> <Badge variant="success">sucess</Badge> <Badge variant="tip">tip</Badge> <Badge variant="default">default</Badge>
:::

### Tabs

<Tabs>
<TabItem label="Tab 1">
This API is <Badge variant="caution">caution</Badge> and should be avoided.

```js
const foo = 'bar';
```

</TabItem>
<TabItem label="Tab 2">
This API is <Badge variant="danger">danger</Badge> and should be avoided.

```js
const foo = 'bar';
```
</TabItem>
</Tabs>


### Tables

| Method | Endpoint | Description |
| ------ | -------- | ----------- |
| <Badge variant="success">GET</Badge> | `/api/users` | Get all users |
| <Badge variant="tip">POST</Badge> | `/api/users` | Create a new user |
| <Badge variant="note">PUT</Badge> | `/api/users` | Update a user |
| <Badge variant="danger">DELETE</Badge> | `/api/users` | Delete a user |
1 change: 1 addition & 0 deletions packages/starlight/components.ts
@@ -1,4 +1,5 @@
export { default as Aside } from './user-components/Aside.astro';
export { default as Badge } from './user-components/Badge.astro';
export { default as Card } from './user-components/Card.astro';
export { default as CardGrid } from './user-components/CardGrid.astro';
export { default as Icon } from './user-components/Icon.astro';
Expand Down
87 changes: 0 additions & 87 deletions packages/starlight/components/Badge.astro

This file was deleted.

13 changes: 7 additions & 6 deletions packages/starlight/components/SidebarSublist.astro
@@ -1,7 +1,7 @@
---
import { flattenSidebar, type SidebarEntry } from '../utils/navigation';
import Icon from '../user-components/Icon.astro';
import Badge from './Badge.astro';
import Badge from '../user-components/Badge.astro';

interface Props {
sublist: SidebarEntry[];
Expand All @@ -26,10 +26,9 @@ const { sublist, nested } = Astro.props;
{entry.badge && (
<>
{' '}
<Badge
text={entry.badge.text}
variant={entry.isCurrent ? 'outline' : entry.badge.variant}
/>
<Badge variant={entry.badge.variant} class={entry.badge.class}>
{entry.badge.text}
</Badge>
</>
)}
</a>
Expand All @@ -43,7 +42,9 @@ const { sublist, nested } = Astro.props;
{entry.badge && (
<>
{' '}
<Badge text={entry.badge.text} variant={entry.badge.variant} />
<Badge variant={entry.badge.variant} class={entry.badge.class}>
{entry.badge.text}
</Badge>
</>
)}
</div>
Expand Down
5 changes: 4 additions & 1 deletion packages/starlight/schemas/badge.ts
@@ -1,9 +1,12 @@
import { z } from 'astro/zod';

export const badgeVariants = ['note', 'danger', 'success', 'caution', 'tip', 'default'] as const;

const badgeSchema = () =>
z.object({
variant: z.enum(['note', 'danger', 'success', 'caution', 'tip', 'default']).default('default'),
variant: z.enum(badgeVariants).default('default'),
text: z.string(),
class: z.string().optional(),
kevinzunigacuellar marked this conversation as resolved.
Show resolved Hide resolved
});

export const BadgeConfigSchema = () =>
Expand Down