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

Expose StarlightIcon type #2805

Merged
merged 3 commits into from
Jan 17, 2025
Merged

Expose StarlightIcon type #2805

merged 3 commits into from
Jan 17, 2025

Conversation

HiDeoo
Copy link
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.

Copy link

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
Copy link

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
Collaborator

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
Contributor

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

Copy link
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!

@@ -10,6 +10,19 @@ Starlight provides a set of built-in icons that you can display in your content
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
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
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 <[email protected]>
@delucis delucis merged commit ed6f9fd into withastro:main Jan 17, 2025
16 checks passed
@delucis
Copy link
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
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
Member

delucis commented Jan 17, 2025

Done in bb8e631 — apologies for not being more attentive.

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