Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 79 additions & 31 deletions docs-overrides/assets/stylesheets/components/_lang-switch.scss
Original file line number Diff line number Diff line change
@@ -1,50 +1,98 @@
.sd-lang-switch {
position: relative;
display: inline-flex;
align-items: stretch;
margin: 0 0.4rem;
padding: 2px;
border: 1px solid rgba(255, 255, 255, 0.45);
border-radius: 999px;
background: rgba(255, 255, 255, 0.08);
font-size: 0.72rem;
line-height: 1;

&__item {
align-items: center;
margin: 0 0.2rem;

// Hide the default disclosure marker on summary
&__trigger::-webkit-details-marker { display: none; }
&__trigger { list-style: none; }

&__trigger {
display: inline-flex;
align-items: center;
padding: 0.28rem 0.7rem;
color: rgba(255, 255, 255, 0.85);
text-decoration: none;
justify-content: center;
min-width: 1.7rem;
height: 1.7rem;
padding: 0 0.32rem;
border-radius: 999px;
font-weight: 600;
letter-spacing: 0.02em;
color: rgba(255, 255, 255, 0.85);
cursor: pointer;
transition: background-color 120ms ease, color 120ms ease;

&:hover,
&:focus {
&:focus-visible {
color: #ffffff;
background-color: rgba(255, 255, 255, 0.18);
outline: none;
}
}

&--active {
color: #ca463a;
background-color: #ffffff;
&__glyph {
display: inline-flex;
align-items: baseline;
font-family: -apple-system, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
font-weight: 600;
line-height: 1;
letter-spacing: -0.02em;
}

&:hover,
&:focus {
color: #ca463a;
background-color: #ffffff;
}
}
&__glyph-cn {
font-size: 0.95rem;
margin-right: 0.05rem;
}
}

@media (max-width: 600px) {
.sd-lang-switch {
font-size: 0.68rem;
&__glyph-en {
font-size: 0.7rem;
transform: translateY(-0.18rem);
font-weight: 700;
}

&__item {
padding: 0.22rem 0.55rem;
&[open] &__trigger {
color: #ffffff;
background-color: rgba(255, 255, 255, 0.22);
}

&__menu {
position: absolute;
top: calc(100% + 0.35rem);
right: 0;
min-width: 8rem;
margin: 0;
padding: 0.3rem 0;
list-style: none;
background: #ffffff;
border-radius: 4px;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
z-index: 100;

li { margin: 0; padding: 0; }
}

&__link {
display: block;
padding: 0.4rem 0.9rem;
color: rgba(0, 0, 0, 0.78);
text-decoration: none;
font-size: 0.72rem;
font-weight: 500;
line-height: 1.3;
white-space: nowrap;

&:hover,
&:focus {
color: #ca463a;
background-color: rgba(202, 70, 58, 0.08);
outline: none;
}

&--active {
color: #ca463a;
font-weight: 700;
}
}
}

// Close the dropdown when clicking outside — relies on the click-away
// hint via `tabindex` on the body and `:focus-within`. Native <details>
// stays open until summary is clicked again, which is acceptable.
34 changes: 21 additions & 13 deletions docs-overrides/partials/alternate.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
{% if config.extra.alternate and config.extra.alternate | length > 1 %}
<nav class="sd-lang-switch" aria-label="{{ lang.t('select.language') }}">
{% for alt in config.extra.alternate %}
{%- set is_active = (alt.lang == config.theme.language) -%}
<a
href="{{ alt.link | url }}"
hreflang="{{ alt.lang }}"
lang="{{ alt.lang }}"
target="_self"
class="sd-lang-switch__item{% if is_active %} sd-lang-switch__item--active{% endif %}"
{% if is_active %}aria-current="true"{% endif %}
>{{ alt.name }}</a>
{% endfor %}
</nav>
<details class="sd-lang-switch">
<summary class="sd-lang-switch__trigger" aria-label="{{ lang.t('select.language') }}" title="{{ lang.t('select.language') }}">
<span class="sd-lang-switch__glyph" aria-hidden="true"><span class="sd-lang-switch__glyph-cn">文</span><span class="sd-lang-switch__glyph-en">A</span></span>
</summary>
<ul class="sd-lang-switch__menu" role="menu">
{% for alt in config.extra.alternate %}
{%- set is_active = (alt.lang == config.theme.language) -%}
<li role="none">
<a
href="{{ alt.link | url }}"
hreflang="{{ alt.lang }}"
lang="{{ alt.lang }}"
target="_self"
role="menuitem"
class="sd-lang-switch__link{% if is_active %} sd-lang-switch__link--active{% endif %}"
{% if is_active %}aria-current="true"{% endif %}
>{{ alt.name }}</a>
</li>
{% endfor %}
</ul>
</details>
{% endif %}
4 changes: 2 additions & 2 deletions docs-overrides/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@
{% if not config.theme.palette is mapping %}
{% include "partials/javascripts/palette.html" %}
{% endif %}
</div>
<div class="right-part">

<!-- Site language selector -->
{% if config.extra.alternate %}
{% include "partials/alternate.html" %}
{% endif %}
</div>
<div class="right-part">

<!-- Button to open search modal -->
{% if "material/search" in config.plugins %}
Expand Down
Loading