Skip to content

Commit 353fcfc

Browse files
committed
Aside: Add support for icons attribute.
Only built-icons will be supported for now. This commit does not add support for the `:::` markdown shorthand for defining an aside, that will be done in the next commit.
1 parent fc6f311 commit 353fcfc

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

docs/src/content/docs/components/asides.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ Other content is also supported in asides.
4949
</Aside>
5050

5151
<Aside type="danger">Do not give your password to anyone.</Aside>
52+
53+
<Aside icon="heart">
54+
Aside with a custom icon. The icon must be part of starlight's icon list.
55+
</Aside>
5256
````
5357

5458
<Fragment slot="markdoc">
@@ -73,6 +77,10 @@ Other content is also supported in asides.
7377
{% aside type="danger" %}
7478
Do not give your password to anyone.
7579
{% /aside %}
80+
81+
{% aside icon="heart" %}
82+
Aside with a custom icon. The icon must be part of starlight's icon list.
83+
{% /aside %}
7684
````
7785

7886
</Fragment>
@@ -95,6 +103,10 @@ Do not give your password to anyone.
95103

96104
<Aside type="danger">Do not give your password to anyone.</Aside>
97105

106+
<Aside icon="heart">
107+
Aside with a custom icon. The icon must be part of starlight's icon list.
108+
</Aside>
109+
98110
</Fragment>
99111

100112
</Preview>

packages/markdoc/index.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ export const StarlightMarkdocPreset = {
6767
aside: {
6868
render: component('@astrojs/starlight/components', 'Aside'),
6969
attributes: {
70+
icon: {
71+
type: String,
72+
required: false,
73+
},
7074
title: {
7175
type: String,
7276
required: false,

packages/starlight/user-components/Aside.astro

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
---
22
import { AstroError } from 'astro/errors';
33
import Icon from './Icon.astro';
4+
import type { StarlightIcon } from '../components/Icons';
45
56
const asideVariants = ['note', 'tip', 'caution', 'danger'] as const;
67
const icons = { note: 'information', tip: 'rocket', caution: 'warning', danger: 'error' } as const;
78
89
interface Props {
910
type?: (typeof asideVariants)[number];
1011
title?: string;
12+
icon?: StarlightIcon;
1113
}
1214
13-
let { type = 'note', title } = Astro.props;
15+
let { type = 'note', title, icon } = Astro.props;
1416
1517
if (!asideVariants.includes(type)) {
1618
throw new AstroError(
@@ -27,7 +29,7 @@ if (!title) {
2729

2830
<aside aria-label={title} class={`starlight-aside starlight-aside--${type}`}>
2931
<p class="starlight-aside__title" aria-hidden="true">
30-
<Icon name={icons[type]} class="starlight-aside__icon" />{title}
32+
<Icon name={icon || icons[type]} class="starlight-aside__icon" />{title}
3133
</p>
3234
<div class="starlight-aside__content">
3335
<slot />

0 commit comments

Comments
 (0)