Header.astro 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. ---
  2. import config from 'virtual:starlight/user-config';
  3. import { Icon } from '@astrojs/starlight/components';
  4. import { HeaderLinks } from 'toolbeam-docs-theme/components';
  5. import Default from 'toolbeam-docs-theme/overrides/Header.astro';
  6. import SocialIcons from 'virtual:starlight/components/SocialIcons';
  7. import SiteTitle from '@astrojs/starlight/components/SiteTitle.astro';
  8. const path = Astro.url.pathname;
  9. const links = config.social || [];
  10. const { headerLinks } = globalThis.toolbeamDocsThemeConfig ?? {};
  11. ---
  12. { path.startsWith("/s")
  13. ? <div class="header sl-flex">
  14. <div class="title-wrapper sl-flex">
  15. <SiteTitle {...Astro.props} />
  16. </div>
  17. <div class="middle-group sl-flex">
  18. {
  19. headerLinks?.map(({ name, url }) => (
  20. <a class="links" href={url}>{name}</a>
  21. ))
  22. }
  23. </div>
  24. <div class="sl-hidden md:sl-flex right-group">
  25. {
  26. links.length > 0 && (
  27. <div class="sl-flex social-icons">
  28. {links.map(({ href, icon }) => (
  29. <a {href} rel="me" target="_blank">
  30. <Icon name={icon} size="1rem" />
  31. </a>
  32. ))}
  33. </div>
  34. )
  35. }
  36. </div>
  37. </div>
  38. : <Default {...Astro.props}><slot /></Default>
  39. }
  40. <style>
  41. .header {
  42. gap: var(--sl-nav-gap);
  43. justify-content: space-between;
  44. align-items: center;
  45. height: 100%;
  46. }
  47. .title-wrapper {
  48. /* Prevent long titles overflowing and covering the search and menu buttons on narrow viewports. */
  49. overflow: clip;
  50. /* Avoid clipping focus ring around link inside title wrapper. */
  51. padding: calc(0.25rem + 2px) 0.25rem calc(0.25rem - 2px);
  52. margin: -0.25rem;
  53. }
  54. .middle-group {
  55. justify-content: flex-end;
  56. gap: var(--sl-nav-gap);
  57. }
  58. @media (max-width: 50rem) {
  59. :global(:root[data-has-sidebar]) {
  60. .middle-group {
  61. display: none;
  62. }
  63. }
  64. }
  65. @media (min-width: 50rem) {
  66. .middle-group {
  67. display: flex;
  68. }
  69. }
  70. .right-group,
  71. .social-icons {
  72. gap: 1rem;
  73. align-items: center;
  74. a {
  75. line-height: 1;
  76. svg {
  77. color: var(--sl-color-text-dimmed);
  78. }
  79. }
  80. a.links {
  81. text-transform: uppercase;
  82. font-size: var(--sl-text-sm);
  83. color: var(--sl-color-text-secondary);
  84. line-height: normal;
  85. }
  86. }
  87. @media (min-width: 50rem) {
  88. :global(:root[data-has-sidebar]) {
  89. --__sidebar-pad: calc(2 * var(--sl-nav-pad-x));
  90. }
  91. :global(:root:not([data-has-toc])) {
  92. --__toc-width: 0rem;
  93. }
  94. .header {
  95. --__sidebar-width: max(0rem, var(--sl-content-inline-start, 0rem) - var(--sl-nav-pad-x));
  96. --__main-column-fr: calc(
  97. (
  98. 100% + var(--__sidebar-pad, 0rem) - var(--__toc-width, var(--sl-sidebar-width)) -
  99. (2 * var(--__toc-width, var(--sl-nav-pad-x))) - var(--sl-content-inline-start, 0rem) -
  100. var(--sl-content-width)
  101. ) / 2
  102. );
  103. display: grid;
  104. grid-template-columns:
  105. /* 1 (site title): runs up until the main content column’s left edge or the width of the title, whichever is the largest */
  106. minmax(
  107. calc(var(--__sidebar-width) + max(0rem, var(--__main-column-fr) - var(--sl-nav-gap))),
  108. auto
  109. )
  110. /* 2 (search box): all free space that is available. */
  111. 1fr
  112. /* 3 (right items): use the space that these need. */
  113. auto;
  114. align-content: center;
  115. }
  116. }
  117. </style>