#Tabs in header?

49 messages · Page 1 of 1 (latest)

stone ridge
#

I really like how the swagger docs have multiple sections in the header bar on their site. Is there an easy way to copy this set up?

(I am not at all a frontend developer, have been attempting to copy and paste things from their github repo https://github.com/swagger-api/swagger.io-docs/tree/main but not having much luck so far since I don't know which bits are essential to copy across.)

GitHub

The content of swagger.io. Contribute to swagger-api/swagger.io-docs development by creating an account on GitHub.

wet sparrow
#

Hey! So they are using a custom Header.astro component: https://github.com/swagger-api/swagger.io-docs/blob/main/astro.config.mjs#L288

Inside that, they have defined their menu and then a dropdown within each list item: https://github.com/swagger-api/swagger.io-docs/blob/main/src/components/Header.astro#L274

Then in the script, they have listeners for clicks inside the .dropdown class which toggles the actual dropdown to show/hide: https://github.com/swagger-api/swagger.io-docs/blob/main/src/components/Header.astro#L1579

stone ridge
#

thanks I'll try to copy those across

stone ridge
#

but can't figure out where it is used actually

wet sparrow
#

So I probably wouldn't just copy+paste it verbatim, it's probably easier for you to work out how it's working and implement it yourself tbh! Copy and pasting directly into a different project is tricky!

grave temple
#

The labels prop was removed in newer versions of Starlight, yeah. You’d want to use Astro.locals.t() instead. So for example, if a component is doing Astro.props.labels['some.key'], you’d want to refactor that to Astro.locals.t('some.key').

#

(Basically, do what the error message tells you to do 😄)

stone ridge
#

@wet sparrow not easier to work it out because I have no idea how any of this works lol. @grave temple thanks, but I have tried searching for the key it is telling me to replace but it is not anywhere in the code

grave temple
#

Hmm, hard to say then with out more to go on. I’d recommend sharing your code if possible so folks can take a look.

stone ridge
#

Maybe I can ask a simpler question. If I am making a custom component, and I want to import other existing components , should the following import statements work? ```

#

import { Icon } from '@astrojs/starlight/components';
import { ThemeSelect } from '@astrojs/starlight/components';
import type { Props } from '@astrojs/starlight/props';
---
#

currently I get the error: Unable to render ThemeSelect because it is undefined! Did you forget to import the component or is it possible there is a typo?

grave temple
#

Are you missing the initial --- up top?

stone ridge
#

But do not at all understand why one seems to import fine, and the other doesnt

grave temple
#
---
import { Icon } from '@astrojs/starlight/components';
import { ThemeSelect } from '@astrojs/starlight/components';
import type { Props } from '@astrojs/starlight/props';
---
#

Oh wait

#

Right, ThemeSelect

#

That is not exported that way

#

There are basically two different places you can get Starlight components on depending on the kind of components:

  • @astrojs/starlight/components — contains all the components intended for use in your docs content, like Tabs, Icon, Steps etc. (the components you see in the sidebar in Starlight’s docs)
  • @astrojs/starlight/components/ComponentName.astro — directly import a component used in Starlight’s layout etc., like ThemeSelect

So the correct imports in your example would be:

---
import { Icon } from '@astrojs/starlight/components';
import ThemeSelect from '@astrojs/starlight/components/ThemeSelect.astro';
import type { Props } from '@astrojs/starlight/props';
---
stone ridge
#

I get the same error if I change it to that way of importing.

#
---

import { Icon } from '@astrojs/starlight/components';
import { ThemeSelect } from '@astrojs/starlight/components/ThemeSelect.astro';
import type { Props } from '@astrojs/starlight/props';
---
#
Error: Unable to render ThemeSelect because it is undefined!
Did you forget to import the component or is it possible there is a typo?
    at renderFrameworkComponent (/Users/marionshadbolt/Documents/GitHub/CanDIGv2/docs/node_modules/astro/dist/runtime/server/render/component.js:60:11)
    at Module.renderComponent (/Users/marionshadbolt/Documents/GitHub/CanDIGv2/docs/node_modules/astro/dist/runtime/server/render/component.js:384:16)
    at /Users/marionshadbolt/Documents/GitHub/CanDIGv2/docs/src/components/Header.astro:1:1
    at AstroComponentInstance.Header [as factory] (/Users/marionshadbolt/Documents/GitHub/CanDIGv2/docs/node_modules/astro/dist/runtime/server/astro-component.js:16:12)
    at AstroComponentInstance.init (/Users/marionshadbolt/Documents/GitHub/CanDIGv2/docs/node_modules/astro/dist/runtime/server/render/astro/instance.js:32:29)
    at AstroComponentInstance.render (/Users/marionshadbolt/Documents/GitHub/CanDIGv2/docs/node_modules/astro/dist/runtime/server/render/astro/instance.js:42:36)
    at Object.render (/Users/marionshadbolt/Documents/GitHub/CanDIGv2/docs/node_modules/astro/dist/runtime/server/render/component.js:366:22)
    at Module.renderChild (/Users/marionshadbolt/Documents/GitHub/CanDIGv2/docs/node_modules/astro/dist/runtime/server/render/any.js:31:17)
#

wait I left in the curly brackets

#

it is working now

#

thank you!

#

I will keep messing around

stone ridge
#

I think I give up on this, it would be great to see tabs in the header as a future option for navigation incorporated into Starlight/astro

grave temple
#

Just to check, have you seen some of the plugins that provide this feature?

#

Not sure if it fits your use case, but if it does, it’s probably easier to set up.

stone ridge
#

Nope I hadn't seen that. Thanks I will look into it

stone ridge
grave temple
remote scaffold
grave temple
#

Do you have any plugins? If not, try searching for Astro.props.labels in your project to see where it is being used. And if you do have plugins, you may need to check if they have newer versions and update these.

remote scaffold
grave temple
#

Oh, yeah, you can’t stringify the full props object like that. Astro.props.labels is a getter that throws when trying to read one of its values. So something that tries to enumerate like stringify() will throw the error.

remote scaffold
#

hmpf; yes, whenever I somehow call Astro.props.labels it is getting triggered. So i think this is not a nice behaviour 😄

grave temple
#

You can do this if you need to:

const { labels, ...props } = Astro.props;
JSON.stringify(props);
#

I’m guessing you’re just stringifying for debugging purposes?

remote scaffold
#

does this exclude the labels property? - yes, just for debugging. This really bugged me

grave temple
#

Yeah, the above code snippet creates a new props variable that excludes labels

#

So it’s safe to stringify

#

So you could opt to just do JSON.stringify(Astro.props.entry) or whatever you were interested in

remote scaffold
#

this unblocks me! thank you very much.
For others I think this should somewhere be documented since its not obvious at all 😅 because technically i have not set labels but it tells me i did and should not use it anymore