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

Support component customisation #709

Merged
merged 80 commits into from
Oct 6, 2023
Merged

Conversation

delucis
Copy link
Member

@delucis delucis commented Sep 11, 2023

What kind of changes does this PR include?

  • Changes to Starlight code

Description

  • Closes Ability to customise Starlight’s components #415
  • Refactors Starlight’s internal components to use a standardised prop type. Does this by pulling up some logic to a top-level “route data” object.
  • Minimises the amount of data manipulation done in component code. This should hopefully help ensure user components receive data in a format they can use directly relatively easily without needing to duplicate any of our code.
  • Support overriding default components via Starlight config (will use a Vite virtual module to do this — still in progress on my local branch)
  • Support “slots” — spaces in the layout where no default component is rendered but users can add custom UI Cancelled for now after some discussion — let’s see if we can make an override-only system as nice as possible!
  • Refactor a couple of our components so that the boundaries lie where users most likely will want/expect them.
  • Docs!

Docs preview →

How will this feature work?

  • There’s a new components option in Starlight config where users can provide a component to override one of Starlight’s built-in components in astro.config.mjs:

    starlight({
      title: 'Docs with component overrides',
      components: {
        SocialIcons: './src/overrides/MySocialLinks.astro',
      },
    })
  • Components used to override a built-in component can import types to get type-safe props. These are consistent across all components available to override:

    ---
    import type { Props } from '@astrojs/starlight/props';
    
    const { editUrl } = Astro.props;
         // ^ (property) StarlightRouteData.editUrl: URL | undefined
    ---
  • Components can import the default implementation if they want to just add some DOM alongside the existing UI:

    ---
    // src/overrides/MySocialLinks.astro
    import Default from '@astrojs/starlight/components/SocialIcons.astro';
    import type { Props } from '@astrojs/starlight/props';
    ---
    
    <Default {...Astro.props}><slot /></Default>
    <a href="mailto:santa@north.pole">E-mail</a>

    Most components don’t require <slot />, but some do, so I’m thinking this pattern should be what we document for consistency. <PageFrame /> uses named slots, which might need extra documentation. Looked at refactoring it to avoid using them, but I think it would lead to worse code structure.

@changeset-bot
Copy link

changeset-bot bot commented Sep 11, 2023

🦋 Changeset detected

Latest commit: 98b80e0

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

@netlify
Copy link

netlify bot commented Sep 11, 2023

Deploy Preview for astro-starlight ready!

Name Link
🔨 Latest commit 98b80e0
🔍 Latest deploy log https://app.netlify.com/sites/astro-starlight/deploys/65203a766f500d000899c396
😎 Deploy Preview https://deploy-preview-709--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.

@delucis delucis marked this pull request as draft September 11, 2023 22:39
@github-actions github-actions bot added the 🌟 core Changes to Starlight’s main package label Sep 11, 2023
@astrobot-houston
Copy link
Collaborator

astrobot-houston commented Sep 11, 2023

size-limit report 📦

Path Size
/index.html 9.51 KB (+1.02% 🔺)
/_astro/*.js 19.27 KB (+0.08% 🔺)
/_astro/*.css 9.63 KB (+0.77% 🔺)

@delucis delucis added the 🌟 minor Change that triggers a minor release label Sep 19, 2023
Copy link
Member

@TheOtterlord TheOtterlord left a comment

Choose a reason for hiding this comment

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

can't wait to use this 🥳

@adambraimbridge
Copy link

uses named slots, which might need extra documentation.

Starlight is awesome, I'm rather enjoying it but still learning.

I'd love to see the documentation for overriding the PageFrame.astro component, specifically how to preserve the named header slot.

@adambraimbridge
Copy link

adambraimbridge commented Oct 20, 2023

Update: I think I figured it out. Really loving Starlight :) <3

---
import type { Props } from '@astrojs/starlight/props';
import Default from '@astrojs/starlight/components/PageFrame.astro';
import { Header } from 'virtual:starlight/components';
import { Sidebar } from 'virtual:starlight/components';
---

<Default {...Astro.props}>
  <Header slot="header" {...Astro.props} />
  <Sidebar slot="sidebar" {...Astro.props} />
  <slot />
</Default>

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 🌟 minor Change that triggers a minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to customise Starlight’s components
8 participants