-
-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Temporarily copy/paste `urlToSlug()` from #1175 * Add `<Aside>` component * Document `<Aside>` component * Add changeset * Nicer formatting of multiline aside
- Loading branch information
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@astrojs/starlight': minor | ||
--- | ||
|
||
Adds a new `<Aside>` component | ||
|
||
The new component is in addition to the existing custom Markdown syntax. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
import { AstroError } from 'astro/errors'; | ||
import { slugToLocaleData, urlToSlug } from '../utils/slugs'; | ||
import { useTranslations } from '../utils/translations'; | ||
import Icon from './Icon.astro'; | ||
const asideVariants = ['note', 'tip', 'caution', 'danger'] as const; | ||
const icons = { note: 'information', tip: 'rocket', caution: 'warning', danger: 'error' } as const; | ||
interface Props { | ||
type?: (typeof asideVariants)[number]; | ||
title?: string; | ||
} | ||
let { type = 'note', title } = Astro.props; | ||
if (!asideVariants.includes(type)) { | ||
throw new AstroError( | ||
'Invalid `type` prop passed to the `<Aside>` component.\n', | ||
`Received: ${JSON.stringify(type)}\n` + | ||
`Expected one of ${asideVariants.map((i) => JSON.stringify(i)).join(', ')}` | ||
); | ||
} | ||
if (!title) { | ||
const { locale } = slugToLocaleData(urlToSlug(Astro.url)); | ||
title = useTranslations(locale)(`aside.${type}`); | ||
} | ||
--- | ||
|
||
<aside aria-label={title} class={`starlight-aside starlight-aside--${type}`}> | ||
<p class="starlight-aside__title" aria-hidden="true"> | ||
<Icon name={icons[type]} class="starlight-aside__icon" />{title} | ||
</p> | ||
<section class="starlight-aside__content"> | ||
<slot /> | ||
</section> | ||
</aside> |