Check this out
Components
Цей контент ще не доступний вашою мовою.
Components let you easily reuse a piece of UI or styling consistently. Examples might include a link card or a YouTube embed. Starlight supports the use of components in MDX files and provides some common components for you to use.
Learn more about building components in the Astro Docs.
Using a component
You can use a component by importing it into your MDX file and then rendering it as a JSX tag.
These look like HTML tags but start with an uppercase letter matching the name in your import
statement:
Because Starlight is powered by Astro, you can add support for components built with any supported UI framework (React, Preact, Svelte, Vue, Solid, Lit, and Alpine) in your MDX files. Learn more about using components in MDX in the Astro docs.
Compatibility with Starlight’s styles
Starlight applies default styling to your Markdown content, for example adding margin between elements.
If these styles conflict with your component’s appearance, set the not-content
class on your component to disable them.
Built-in components
Starlight provides some built-in components for common documentation use cases.
These components are available from the @astrojs/starlight/components
package.
Tabs
You can display a tabbed interface using the <Tabs>
and <TabItem>
components.
Each <TabItem>
must have a label
to display to users.
Use the optional icon
attribute to include one of Starlight’s built-in icons next to the label.
The code above generates the following tabs on the page:
Sirius, Vega, Betelgeuse
Io, Europa, Ganymede
Synced tabs
Keep multiple tab groups synchronized by adding the syncKey
attribute.
All <Tabs>
with the same syncKey
value will display the same active label. This allows your reader to choose once (e.g. their operating system or package manager), and see their choice persisted using localStorage
and reflected throughout the entire website.
To synchronize related tabs, add an identical syncKey
property to each <Tabs>
component and ensure that they all use the same <TabItem>
labels:
The code above generates the following on the page:
Some stars:
Some exoplanets:
Cards
You can display content in a box matching Starlight’s styles using the <Card>
component.
Wrap multiple cards in the <CardGrid>
component to display cards side-by-side when there’s enough space.
A <Card>
requires a title
and can optionally include an icon
attribute set to the name of one of Starlight’s built-in icons.
The code above generates the following on the page:
Stars
Sirius, Vega, Betelgeuse
Moons
Io, Europa, Ganymede
Link Cards
Use the <LinkCard>
component to link prominently to different pages.
A <LinkCard>
requires a title
and an href
attribute. You can optionally include a short description
or other link attributes such as target
.
Group multiple <LinkCard>
components in <CardGrid>
to display cards side-by-side when there’s enough space.
The above code generates the following on the page:
Asides
Asides (also known as “admonitions” or “callouts”) are useful for displaying secondary information alongside a page’s main content.
An <Aside>
can have an optional type
of note
(the default), tip
, caution
or danger
. Setting a title
attribute overrides the default aside title.
The above code generates the following on the page:
Starlight also provides a custom syntax for rendering asides in Markdown and MDX as an alternative to the <Aside>
component.
See the “Authoring Content in Markdown” guide for details of the custom syntax.
Code
Use the <Code>
component to render syntax highlighted code when using a Markdown code block is not possible, for example, to render data coming from external sources like files, databases, or APIs.
See the Expressive Code “Code Component” docs for full details of the props <Code>
supports.
The code above generates the following on the page:
Imported Code
Use Vite’s ?raw
import suffix to import any code file as a string.
You can then pass this imported string to the <Code>
component to include it on your page.
The code above generates the following on the page:
File Tree
Use the <FileTree>
component to display the structure of a directory with file icons and collapsible sub-directories.
Specify the structure of your files and directories with an unordered Markdown list inside <FileTree>
.
Create a sub-directory using a nested list or add a /
to the end of a list item to render it as a directory without specific content.
The following syntax can be used to customize the appearance of the file tree:
- Highlight a file or directory by making its name bold, e.g.
**README.md**
. - Add a comment to a file or directory by adding more text after the name.
- Add placeholder files and directories by using either
...
or…
as the name.
The above code generates the following on the page:
- astro.config.mjs an important file
- package.json
- README.md
Directorysrc
Directorycomponents
- Header.astro
- …
Directorypages/
- …
Steps
Use the <Steps>
component to style numbered lists of tasks.
This is useful for more complex step-by-step guides where each step needs to be clearly highlighted.
Wrap <Steps>
around a standard Markdown ordered list.
All the usual Markdown syntax is applicable inside <Steps>
.
The code above generates the following on the page:
-
Import the component into your MDX file:
-
Wrap
<Steps>
around your ordered list items.
Badges
Use the <Badge>
component to display small pieces of information, such as status or labels.
Pass the content you want to display to the text
attribute of the <Badge>
component.
By default, the badge will use the theme accent color of your site. To use a built-in badge color, set the variant
attribute to one of the following values: note
(blue), tip
(purple), danger
(red), caution
(orange), or success
(green).
The size
attribute (default: small
) controls the size of the badge text. medium
and large
are also available options for displaying a larger badge.
For further customization, use other <span>
attributes such as class
or style
with custom CSS.
The code above generates the following on the page:
New Deprecated Starlight CustomIcon
Starlight provides a set of common icons that you can display in your content using the <Icon>
component.
Each <Icon>
requires a name
and can optionally include a label
to provide context for screen readers.
The size
and color
attributes can be used to adjust the icon’s appearance using CSS units and color values.
The code above generates the following on the page:
All icons
A list of all available icons is shown below with their associated names. Click an icon to copy the component code for it.