Skip to content

Expose StarlightIcon type#2805

Merged
delucis merged 3 commits intowithastro:mainfrom
HiDeoo:hd-feat-icons-type
Jan 17, 2025
Merged

Expose StarlightIcon type#2805
delucis merged 3 commits intowithastro:mainfrom
HiDeoo:hd-feat-icons-type

Conversation

@HiDeoo
Copy link
Copy Markdown
Member

@HiDeoo HiDeoo commented Jan 14, 2025

Description

As discussed on Discord, this PR exposes a new TypeScript type for built-in icon names: StarlightIcon. This type is a union of all built-in icon names.

When building an Astro component accepting an icon name, you could already use the ComponentProps<typeof Icon>['name'] approach, but importing the Astro component in a TypeScript file, which could also use ESLint with TypeScript type-aware rules, is not trivial.

A common use case is for example a plugin defining its configuration through a Zod schema where an icon name is required. This can now be validated as a string but still provide autocompletion and type checking for the end user using icon: z.string() as z.Schema<StarlightIcon>.

Regarding the documentation change, I think I did the maximum number of changes so it's easy to remove some of them if there are not judged required or good.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Jan 14, 2025

🦋 Changeset detected

Latest commit: e8634e3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/starlight Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added 📚 docs Documentation website changes 🌟 core Changes to Starlight’s main package labels Jan 14, 2025
@netlify
Copy link
Copy Markdown

netlify bot commented Jan 14, 2025

Deploy Preview for astro-starlight ready!

Name Link
🔨 Latest commit e8634e3
🔍 Latest deploy log https://app.netlify.com/sites/astro-starlight/deploys/678a180fab3c9d0008c1bfa5
😎 Deploy Preview https://deploy-preview-2805--astro-starlight.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 100 (no change from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@astrobot-houston
Copy link
Copy Markdown
Contributor

astrobot-houston commented Jan 14, 2025

Lunaria Status Overview

🌕 This pull request will trigger status changes.

Learn more

By default, every PR changing files present in the Lunaria configuration's files property will be considered and trigger status changes accordingly.

You can change this by adding one of the keywords present in the ignoreKeywords property in your Lunaria configuration file in the PR's title (ignoring all files) or by including a tracker directive in the merged commit's description.

Tracked Files

Locale File Note
en components/icons.mdx Source changed, localizations will be marked as outdated.
en components/using-components.mdx Source changed, localizations will be marked as outdated.
en reference/icons.mdx Source changed, localizations will be marked as outdated.
Warnings reference
Icon Description
🔄️ The source for this localization has been updated since the creation of this pull request, make sure all changes in the source have been applied.

@trueberryless
Copy link
Copy Markdown
Contributor

I like that the documentation is changed this way. Also nice catch with the changes from Icon to Badge 👌

Copy link
Copy Markdown
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

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

I think this all looks great and very thorough — I had no idea how often we used keyof typeof Icons 😅 — thank you @HiDeoo!

Had one microscopic query but this PR looks good to go!

Icons can be displayed using the [`<Icon>`](/components/icons/) component.
They are also often used in other components, such as [cards](/components/cards/) or settings like [hero actions](/reference/frontmatter/#hero).

## Icon type
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this maybe be this? Not 100% sure, but “Icon type” suggests overlap with the component itself. I also considered a heading that used “name” somehow, but didn’t come up with a wording I was satisfied with.

Suggested change
## Icon type
## `StarlightIcon` type

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good call, just updated the heading and its associated links 👍

Co-authored-by: Chris Swithinbank <357379+delucis@users.noreply.github.com>
@delucis delucis merged commit ed6f9fd into withastro:main Jan 17, 2025
@delucis
Copy link
Copy Markdown
Member

delucis commented Jan 17, 2025

Oops, should have checked first that this was a patch — I thought it was 😅

I think it’s OK if I make it one? I know it’s technically a “feature”, but do you think there’s a risk in releasing it in a patch @HiDeoo?

@astrobot-houston astrobot-houston mentioned this pull request Jan 17, 2025
@HiDeoo
Copy link
Copy Markdown
Member Author

HiDeoo commented Jan 17, 2025

I think it’s OK if I make it one? I know it’s technically a “feature”, but do you think there’s a risk in releasing it in a patch @HiDeoo?

Definitely, go ahead, I went by the definition of semver but I cannot see a risk so I think it should be fine.

delucis added a commit that referenced this pull request Jan 17, 2025
@delucis
Copy link
Copy Markdown
Member

delucis commented Jan 17, 2025

Done in bb8e631 — apologies for not being more attentive.

trueberryless added a commit to trueberryless/withastro-starlight that referenced this pull request Jan 17, 2025
Yoxnear pushed a commit to Yoxnear/starlight-custom that referenced this pull request Jul 23, 2025
Co-authored-by: Chris Swithinbank <357379+delucis@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🌟 core Changes to Starlight’s main package 📚 docs Documentation website changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants