Skip to content

Commit

Permalink
Simplify site title styling and logic (withastro#5741)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Swithinbank <[email protected]>
  • Loading branch information
natemoo-re and delucis authored Dec 13, 2023
1 parent 874a750 commit 2c7cf93
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 163 deletions.
5 changes: 0 additions & 5 deletions astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ export default defineConfig({
starlight({
title: 'Docs',
customCss: ['./src/styles/custom.css'],
logo: {
light: './src/assets/astro-logo-light.svg',
dark: './src/assets/astro-logo-dark.svg',
alt: 'Astro',
},
components: {
EditLink: './src/components/starlight/EditLink.astro',
Head: './src/components/starlight/Head.astro',
Expand Down
34 changes: 0 additions & 34 deletions src/assets/astro-logo-dark.svg

This file was deleted.

24 changes: 0 additions & 24 deletions src/assets/astro-logo-light.svg

This file was deleted.

15 changes: 15 additions & 0 deletions src/assets/astro-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/assets/docs.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
126 changes: 28 additions & 98 deletions src/components/starlight/SiteTitle.astro
Original file line number Diff line number Diff line change
@@ -1,121 +1,51 @@
---
import logo from '~/assets/astro-logo.svg?raw';
import docs from '~/assets/docs.svg?raw';
import { logos } from 'virtual:starlight/user-images';
import config from 'virtual:starlight/user-config';
import { pathWithBase } from '../../../node_modules/@astrojs/starlight/utils/base';
import type { Props } from '@astrojs/starlight/props';
const href = pathWithBase((Astro.props.locale || '') + '/getting-started/');
const main = 'https://astro.build/';
const self = '/' + (Astro.props.locale || 'en') + '/getting-started/';
---

<span class="site-title sl-flex">
{
config.logo && logos.dark && (
<a href="https://astro.build/">
<img
class:list={{ 'dark-only': !('src' in config.logo) }}
alt={config.logo.alt}
src={logos.dark.src}
width={logos.dark.width}
height={logos.dark.height}
/>
{/* Show light alternate if a user configure both light and dark logos. */}
{!('src' in config.logo) && (
<img
class="light-only"
alt={config.logo.alt}
src={logos.light?.src}
width={logos.light?.width}
height={logos.light?.height}
/>
)}
</a>
)
}
<a {href} class="docs" set:html={docs} aria-label="Astro Docs" />
<a class="astro-logo" href={main} set:html={logo} aria-label="Astro" />
<a class="docs-logo" href={self} set:html={docs} aria-label="Docs" />
</span>

<style>
.site-title {
--hover-offset: 0.15em;
justify-self: flex-start;
max-width: 100%;
overflow: hidden;
align-items: center;
gap: 0.25rem;
font-size: var(--sl-text-h4);
font-weight: 600;
color: var(--sl-color-text-accent);
text-decoration: none;
white-space: nowrap;
}
.site-title:focus-within {
overflow: visible;
}
.site-title a:first-child {
padding-top: 0.8rem;
gap: 1rem;
}
.site-title a {
position: relative;
margin-top: calc(var(--hover-offset) * -1);
margin-bottom: calc(var(--hover-offset) * -1);
transition: transform 0.18s cubic-bezier(0.23, 1, 0.32, 1);
display: flex;
}
.site-title a:hover {
transform: translateY(calc(var(--hover-offset) * -1));
.astro-logo {
color: var(--sl-color-white);
}
.docs-logo {
color: var(--sl-color-text-accent);
}

/* On focus, outline <img> and <svg> rather than <a> */
.site-title a:focus-visible {
outline: 0;
}
.site-title a:focus-visible::after {
content: '';
position: absolute;
top: var(--sl-nav-pad-y);
right: 0;
bottom: var(--sl-nav-pad-y);
left: 0;
outline: var(--sl-color-text-accent) auto 2px;
}
.site-title a:first-child:focus-visible::after {
left: -0.5em;
right: 0.25em;
.site-title a:focus-visible > :global(*) {
outline: auto;
outline-offset: 0.33rem;
border-radius: 1px;
}
img {
height: calc(var(--sl-nav-height) - 2 * var(--sl-nav-pad-y));
/* Adjust svg sizes to full nav height */
.site-title :global(svg) {
--display-height: 1.75rem;
/* `auto` ensures the `<svg>` scales down on really narrow viewports */
width: auto;
max-width: 100%;
object-fit: contain;
object-position: 0 50%;
}
:global([data-theme='light']) .dark-only {
display: none;
}
:global([data-theme='dark']) .light-only {
display: none;
}
.vertical-line {
height: 66%;
border-left: 2px solid var(--sl-color-gray-5);
}

.docs {
--padding: 0.5em;
display: flex;
height: calc(100% + 0.5em);
width: auto;
padding-left: var(--padding);
padding-right: var(--padding);
margin-left: calc(var(--padding) * -1);
object-fit: contain;
object-position: 0 50%;
color: var(--sl-color-text-accent);
height: auto;
margin-block: calc((var(--sl-nav-height) - var(--display-height)) / 2);
transition: transform 0.18s cubic-bezier(0.23, 1, 0.32, 1);
}

.docs :global(svg) {
margin: auto;
height: calc(var(--sl-nav-height) - 2 * var(--sl-nav-pad-y) - 0.25rem);
width: auto;
object-fit: contain;
object-position: 0 50%;
.site-title a:hover :global(svg) {
--hover-offset: 0.15rem;
transform: translateY(calc(var(--hover-offset) * -1));
}
</style>

0 comments on commit 2c7cf93

Please sign in to comment.