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 <LinkButton> component #1784

Merged
merged 22 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
5 changes: 5 additions & 0 deletions .changeset/chilled-pots-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/starlight': minor
---

Adds `<LinkButton>` component for visually distinct and emphasized call to action links
14 changes: 14 additions & 0 deletions docs/src/assets/landing.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,17 @@
[data-has-hero] .hero > img {
filter: drop-shadow(0 0 3rem var(--overlay-blurple));
}

/* // TODO(HiDeoo) Remove these styles */

.sl-link-button.custom-link-button.primary {
background-color: green;
}

.sl-link-button.custom-link-button.secondary {
border-color: green;
color: green;
}
.sl-link-button.custom-link-button.minimal {
color: green;
}
41 changes: 41 additions & 0 deletions docs/src/content/docs/guides/components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,47 @@ import { LinkCard } from '@astrojs/starlight/components';
<LinkCard title="Components" href="/guides/components/" />
</CardGrid>

### Link Buttons

Use the `<LinkButton>` component for visually distinct and emphasized call to action links best suited to sparingly direct users to the most relevant or actionable content at the end of a section.
delucis marked this conversation as resolved.
Show resolved Hide resolved

A `<LinkButton>` requires an [`href`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#href) attribute and optionally accepts other link attributes such as `target`.

The `icon` attribute can optionally be set to the name of [one of Starlight's built-in icons](#all-icons) to include an icon next to the text.
The `iconPlacement` attribute can be used to place the icon before the text by setting it to `start` (defaults to `end`).

Customize the appearance of the link button using the `variant` attribute, which can be set to `primary`, `secondary`, or `minimal` (the default).

```mdx
# src/content/docs/example.mdx

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

<LinkButton href="/getting-started/" variant="primary">
Get started
</LinkButton>
<LinkButton href="https://docs.astro.build" variant="secondary" icon="external">
Related: Astro
</LinkButton>
<LinkButton href="/guides/i18n/" variant="minimal" icon="right-arrow">
More about internationalization
</LinkButton>
```

The above code generates the following on the page:

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

<LinkButton href="/getting-started/" variant="primary">
Get started
</LinkButton>
<LinkButton href="https://docs.astro.build" variant="secondary" icon="external">
Related: Astro
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noting that this renders as <a ...><p>Related: Astro</p></a>

Not sure if there’s anything we could or should do about that? It’s not invalid HTML and I guess doesn’t really have any bad side effects.

</LinkButton>
<LinkButton href="/guides/i18n/" variant="minimal" icon="right-arrow">
More about internationalization
</LinkButton>

### Asides

Asides (also known as “admonitions” or “callouts”) are useful for displaying secondary information alongside a page’s main content.
Expand Down
Loading
Loading