mirror of
https://github.com/nexu-io/open-design.git
synced 2026-10-27 09:51:12 +01:00
feat(landing): add locale-aware community entry (#7120)
* feat(landing): surface localized community benefits * feat(landing): localize community benefits * fix(landing): keep community entry inside mobile nav * fix(landing): cover compact header transition band --------- Co-authored-by: 徐燕来 <xuyanlai@refly.ai>
This commit is contained in:
co-authored by
徐燕来
parent
f6331fb33a
commit
645aace758
@@ -195,7 +195,7 @@ const directAssets = {
|
||||
}
|
||||
|
||||
// Hamburger menu toggle. Active only at narrow viewports (CSS hides
|
||||
// the toggle button at ≥1100px). Click toggles `.is-open` on the
|
||||
// the toggle button at ≥1367px). Click toggles `.is-open` on the
|
||||
// header; outside-click, Escape, and clicking any link inside the
|
||||
// menu close it again. Keeps `aria-expanded` in sync.
|
||||
const toggle = document.querySelector('[data-nav-toggle]');
|
||||
|
||||
@@ -22,15 +22,168 @@ import type { SolutionPageKey } from '../solution-pages-i18n/types';
|
||||
const REPO = 'https://github.com/nexu-io/open-design';
|
||||
const REPO_DISCUSSIONS = `${REPO}/discussions`;
|
||||
const DISCORD = 'https://discord.gg/mHAjSMV6gz';
|
||||
const FEISHU = 'https://od.kokiai.net/community/website';
|
||||
const X_PROFILE = 'https://x.com/OpenDesignHQ';
|
||||
|
||||
type CommunityEntryCopy = {
|
||||
cta: string;
|
||||
benefits: readonly [string, string, string];
|
||||
};
|
||||
|
||||
const COMMUNITY_ENTRY_COPY = {
|
||||
en: {
|
||||
cta: 'Join Discord',
|
||||
benefits: [
|
||||
'Model × design scenario arenas',
|
||||
'Weekly Hackathon: credits + promotion',
|
||||
'Super Thursday: weekly prize draws',
|
||||
],
|
||||
},
|
||||
zh: {
|
||||
cta: '加入飞书社群',
|
||||
benefits: [
|
||||
'模型 × 设计场景竞技场',
|
||||
'Weekly Hackathon:Credits + 流量扶持',
|
||||
'Super Thursday:每周抽奖',
|
||||
],
|
||||
},
|
||||
'zh-tw': {
|
||||
cta: '加入飛書社群',
|
||||
benefits: [
|
||||
'模型 × 設計場景競技場',
|
||||
'Weekly Hackathon:Credits + 流量扶持',
|
||||
'Super Thursday:每週抽獎',
|
||||
],
|
||||
},
|
||||
ja: {
|
||||
cta: 'Discordに参加',
|
||||
benefits: [
|
||||
'モデル × デザインシーンのアリーナ',
|
||||
'Weekly Hackathon:クレジット+露出支援',
|
||||
'Super Thursday:毎週抽選',
|
||||
],
|
||||
},
|
||||
ko: {
|
||||
cta: 'Discord 참여',
|
||||
benefits: [
|
||||
'모델 × 디자인 시나리오 아레나',
|
||||
'Weekly Hackathon: 크레딧 + 홍보 지원',
|
||||
'Super Thursday: 매주 추첨',
|
||||
],
|
||||
},
|
||||
de: {
|
||||
cta: 'Discord beitreten',
|
||||
benefits: [
|
||||
'Arenen für Modelle × Designszenarien',
|
||||
'Weekly Hackathon: Credits + Reichweite',
|
||||
'Super Thursday: wöchentliche Verlosung',
|
||||
],
|
||||
},
|
||||
fr: {
|
||||
cta: 'Rejoindre Discord',
|
||||
benefits: [
|
||||
'Arènes modèles × scénarios de design',
|
||||
'Weekly Hackathon : crédits + mise en avant',
|
||||
'Super Thursday : tirage hebdomadaire',
|
||||
],
|
||||
},
|
||||
ru: {
|
||||
cta: 'Вступить в Discord',
|
||||
benefits: [
|
||||
'Арены: модели × дизайн-сценарии',
|
||||
'Weekly Hackathon: кредиты + продвижение',
|
||||
'Super Thursday: еженедельный розыгрыш',
|
||||
],
|
||||
},
|
||||
es: {
|
||||
cta: 'Unirse a Discord',
|
||||
benefits: [
|
||||
'Arenas de modelos × escenarios de diseño',
|
||||
'Weekly Hackathon: créditos + promoción',
|
||||
'Super Thursday: sorteo semanal',
|
||||
],
|
||||
},
|
||||
'pt-br': {
|
||||
cta: 'Entrar no Discord',
|
||||
benefits: [
|
||||
'Arenas de modelos × cenários de design',
|
||||
'Weekly Hackathon: créditos + divulgação',
|
||||
'Super Thursday: sorteio semanal',
|
||||
],
|
||||
},
|
||||
it: {
|
||||
cta: 'Unisciti a Discord',
|
||||
benefits: [
|
||||
'Arene modelli × scenari di design',
|
||||
'Weekly Hackathon: crediti + promozione',
|
||||
'Super Thursday: estrazione settimanale',
|
||||
],
|
||||
},
|
||||
vi: {
|
||||
cta: 'Tham gia Discord',
|
||||
benefits: [
|
||||
'Đấu trường mô hình × bối cảnh thiết kế',
|
||||
'Weekly Hackathon: credit + hỗ trợ quảng bá',
|
||||
'Super Thursday: quay thưởng hằng tuần',
|
||||
],
|
||||
},
|
||||
pl: {
|
||||
cta: 'Dołącz do Discorda',
|
||||
benefits: [
|
||||
'Areny modeli × scenariuszy projektowych',
|
||||
'Weekly Hackathon: kredyty + promocja',
|
||||
'Super Thursday: cotygodniowe losowanie',
|
||||
],
|
||||
},
|
||||
id: {
|
||||
cta: 'Gabung Discord',
|
||||
benefits: [
|
||||
'Arena model × skenario desain',
|
||||
'Weekly Hackathon: kredit + dukungan promosi',
|
||||
'Super Thursday: undian mingguan',
|
||||
],
|
||||
},
|
||||
nl: {
|
||||
cta: 'Word lid van Discord',
|
||||
benefits: [
|
||||
'Arena’s voor modellen × ontwerpscenario’s',
|
||||
'Weekly Hackathon: credits + promotie',
|
||||
'Super Thursday: wekelijkse loting',
|
||||
],
|
||||
},
|
||||
ar: {
|
||||
cta: 'انضم إلى Discord',
|
||||
benefits: [
|
||||
'ساحات النماذج × سيناريوهات التصميم',
|
||||
'Weekly Hackathon: أرصدة + دعم الترويج',
|
||||
'Super Thursday: سحب أسبوعي',
|
||||
],
|
||||
},
|
||||
tr: {
|
||||
cta: "Discord'a katıl",
|
||||
benefits: [
|
||||
'Model × tasarım senaryosu arenaları',
|
||||
'Weekly Hackathon: kredi + tanıtım desteği',
|
||||
'Super Thursday: haftalık çekiliş',
|
||||
],
|
||||
},
|
||||
uk: {
|
||||
cta: 'Приєднатися до Discord',
|
||||
benefits: [
|
||||
'Арени: моделі × дизайн-сценарії',
|
||||
'Weekly Hackathon: кредити + промопідтримка',
|
||||
'Super Thursday: щотижневий розіграш',
|
||||
],
|
||||
},
|
||||
} as const satisfies Record<LandingLocaleCode, CommunityEntryCopy>;
|
||||
|
||||
// OpenDesign Cloud endpoints for the header account module.
|
||||
// Production defaults; overridable at build time via PUBLIC_* env so a
|
||||
// preview/staging build can point at a non-prod cloud. These are surfaced to
|
||||
// the runtime via `data-*` on `.nav-account` because the auth logic lives in
|
||||
// `header-enhancer.astro`'s `<script is:inline>` (NOT processed by Vite, so it
|
||||
// cannot read `import.meta.env` itself).
|
||||
const env = import.meta.env as Record<string, string | undefined>;
|
||||
const env = (import.meta.env ?? {}) as Record<string, string | undefined>;
|
||||
const CLOUD_API_BASE =
|
||||
env.PUBLIC_CLOUD_API_BASE ?? env.PUBLIC_AMR_API_BASE ?? 'https://amr-api.open-design.ai';
|
||||
const CLOUD_CONSOLE_URL =
|
||||
@@ -179,6 +332,8 @@ export function Header({
|
||||
const href = (path: string) => localizedHref(path, locale);
|
||||
const homeBrandHref = brandHref === '/' ? href('/') : brandHref;
|
||||
const productMenuCopy = getHeaderProductMenuCopy(locale);
|
||||
const usesFeishuCommunity = locale === 'zh' || locale === 'zh-tw';
|
||||
const communityCopy = COMMUNITY_ENTRY_COPY[locale];
|
||||
|
||||
return (
|
||||
<header className='nav' data-od-id='nav'>
|
||||
@@ -193,7 +348,7 @@ export function Header({
|
||||
/>
|
||||
</a>
|
||||
{/*
|
||||
Mobile / tablet hamburger. Hidden by CSS at ≥1100px (the desktop
|
||||
Mobile / tablet hamburger. Hidden by CSS at ≥1367px (the desktop
|
||||
breakpoint where the full nav fits). At narrower widths it toggles
|
||||
`.is-open` on the parent <header> via a small handler in
|
||||
`header-enhancer.astro` — when open, the `<nav>` element below
|
||||
@@ -461,7 +616,8 @@ export function Header({
|
||||
|
||||
{/* Community — Contributors / Ambassadors / Moderators / Events. These
|
||||
pages are now localized Astro routes, so link through `href()`
|
||||
to keep visitors on their language variant. */}
|
||||
to keep visitors on their language variant. Discord and Feishu
|
||||
open their respective community spaces in a new tab. */}
|
||||
<li className='has-dropdown'>
|
||||
<a
|
||||
href={href('/community/')}
|
||||
@@ -502,6 +658,11 @@ export function Header({
|
||||
<span className='dropdown-name'>Discord</span>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href={FEISHU} {...ext}>
|
||||
<span className='dropdown-name'>Feishu</span>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href={REPO_DISCUSSIONS} {...ext}>
|
||||
<span className='dropdown-name'>
|
||||
@@ -517,9 +678,69 @@ export function Header({
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
{/* Compact navigation keeps the community action inside the
|
||||
hamburger panel so long localized labels cannot crowd the
|
||||
fixed header row. The desktop counterpart stays in nav-side. */}
|
||||
<li className='nav-community-mobile-entry'>
|
||||
<a
|
||||
className='nav-community-mobile-cta'
|
||||
href={usesFeishuCommunity ? FEISHU : DISCORD}
|
||||
{...ext}
|
||||
data-community-cta
|
||||
data-community-platform={usesFeishuCommunity ? 'feishu' : 'discord'}
|
||||
>
|
||||
<svg
|
||||
className='nav-community-cta-icon'
|
||||
viewBox='0 0 20 20'
|
||||
aria-hidden='true'
|
||||
>
|
||||
<path d='M4 4.75h12v8.5H9l-3.8 2.5v-2.5H4z' />
|
||||
<path d='M7 8h6M7 10.5h4' />
|
||||
</svg>
|
||||
<span>{communityCopy.cta}</span>
|
||||
</a>
|
||||
<div className='nav-community-mobile-benefits'>
|
||||
{communityCopy.benefits.map((benefit) => (
|
||||
<div className='nav-community-mobile-benefit' key={benefit}>
|
||||
<span className='nav-community-benefits-dot' aria-hidden='true' />
|
||||
<span>{benefit}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
<div className='nav-side'>
|
||||
<div className='nav-community-entry'>
|
||||
<a
|
||||
className='nav-community-cta'
|
||||
href={usesFeishuCommunity ? FEISHU : DISCORD}
|
||||
{...ext}
|
||||
data-community-cta
|
||||
data-community-platform={usesFeishuCommunity ? 'feishu' : 'discord'}
|
||||
>
|
||||
<svg
|
||||
className='nav-community-cta-icon'
|
||||
viewBox='0 0 20 20'
|
||||
aria-hidden='true'
|
||||
>
|
||||
<path d='M4 4.75h12v8.5H9l-3.8 2.5v-2.5H4z' />
|
||||
<path d='M7 8h6M7 10.5h4' />
|
||||
</svg>
|
||||
{communityCopy.cta}
|
||||
</a>
|
||||
<div className='nav-community-benefits-card'>
|
||||
<ul>
|
||||
{communityCopy.benefits.map((benefit) => (
|
||||
<li key={benefit}>
|
||||
<span className='nav-community-benefits-dot' aria-hidden='true' />
|
||||
<span>{benefit}</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
{localeSwitcher ? (
|
||||
<details className='locale-switch nav-locale-switch' data-locale-switch>
|
||||
<summary
|
||||
|
||||
@@ -684,14 +684,14 @@ body::before {
|
||||
gap: 24px;
|
||||
}
|
||||
/*
|
||||
* Desktop bar layout (≥1081px, above the hamburger breakpoint): three
|
||||
* Desktop bar layout (≥1367px, above the hamburger breakpoint): three
|
||||
* equal-flanked columns — brand logo pinned flush-left, the nav links
|
||||
* centred, and the action cluster (download / star / locale) flush-right.
|
||||
* The two 1fr side tracks are symmetric, which keeps the centre column
|
||||
* optically centred regardless of how wide either side gets. Mobile keeps
|
||||
* the base flex layout untouched.
|
||||
*/
|
||||
@media (min-width: 1081px) {
|
||||
@media (min-width: 1367px) {
|
||||
.nav-inner {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr auto 1fr;
|
||||
@@ -716,13 +716,6 @@ body::before {
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
/* Mid-band desktop (hamburger ends at 1081px): the longest locales need
|
||||
* tighter link spacing to hold a single row. The hover bridge width must
|
||||
* track the gap so sweeping between triggers keeps a dropdown open. */
|
||||
@media (min-width: 1081px) and (max-width: 1366px) {
|
||||
.nav-links { gap: 22px; }
|
||||
.nav-links li.has-dropdown:not(:last-child)::after { width: 22px; }
|
||||
}
|
||||
.brand {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
@@ -917,7 +910,7 @@ body::before {
|
||||
* hides the frost behind itself, so the bar still reads as a clean bar.
|
||||
* Desktop only: the mobile nav is a vertical drawer, not a hover panel.
|
||||
*/
|
||||
@media (min-width: 1081px) {
|
||||
@media (min-width: 1367px) {
|
||||
.site-chrome::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
@@ -1028,7 +1021,7 @@ body::before {
|
||||
where a centering transform would shift them sideways. The Product li goes
|
||||
static so the wide panel positions against `.container` and centers on it —
|
||||
anchored to the li it overflows narrow desktops. */
|
||||
@media (min-width: 1081px) {
|
||||
@media (min-width: 1367px) {
|
||||
.nav-links li.nav-item-mega { position: static; }
|
||||
/* With the li static, absolutely-positioned descendants resolve against
|
||||
`.container` (the nearest positioned ancestor), so the shared
|
||||
@@ -1128,7 +1121,7 @@ a.nav-mega-col-head.is-active {
|
||||
}
|
||||
|
||||
/*
|
||||
* Hamburger toggle. Hidden at desktop widths (≥1080px). At narrower
|
||||
* Hamburger toggle. Hidden at desktop widths (≥1367px). At narrower
|
||||
* viewports it replaces the inline nav-links and toggles a panel
|
||||
* underneath the header bar via a small handler in `header-enhancer`.
|
||||
*/
|
||||
@@ -1195,6 +1188,106 @@ a.nav-mega-col-head.is-active {
|
||||
top: calc(100% + var(--nav-flyout-gap, 12px));
|
||||
right: 0;
|
||||
}
|
||||
.nav-community-entry {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.nav-community-mobile-entry {
|
||||
display: none;
|
||||
}
|
||||
.nav-community-cta {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 7px;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid rgba(26, 26, 26, 0.16);
|
||||
border-radius: 999px;
|
||||
background: rgba(255, 255, 255, 0.88);
|
||||
box-shadow: 0 2px 7px rgba(17, 17, 26, 0.06);
|
||||
color: var(--ink);
|
||||
font-family: var(--sans);
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
line-height: 1;
|
||||
text-decoration: none;
|
||||
white-space: nowrap;
|
||||
flex-shrink: 0;
|
||||
transition: background 160ms ease, box-shadow 160ms ease, transform 160ms ease;
|
||||
}
|
||||
.nav-community-cta:hover {
|
||||
border-color: rgba(26, 26, 26, 0.3);
|
||||
background: #fff;
|
||||
box-shadow: 0 4px 11px rgba(17, 17, 26, 0.09);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
.nav-community-cta:focus-visible {
|
||||
outline: 2px solid var(--ink);
|
||||
outline-offset: 3px;
|
||||
}
|
||||
.nav-community-cta-icon {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
flex: 0 0 16px;
|
||||
color: #3370ff;
|
||||
}
|
||||
.nav-community-cta-icon path:first-child {
|
||||
fill: color-mix(in srgb, currentColor 10%, transparent);
|
||||
stroke: currentColor;
|
||||
stroke-width: 1.5;
|
||||
stroke-linejoin: round;
|
||||
}
|
||||
.nav-community-cta-icon path:last-child {
|
||||
fill: none;
|
||||
stroke: currentColor;
|
||||
stroke-width: 1.5;
|
||||
stroke-linecap: round;
|
||||
}
|
||||
.nav-community-benefits-card {
|
||||
position: absolute;
|
||||
z-index: 60;
|
||||
top: calc(100% + 11px);
|
||||
right: 0;
|
||||
width: 278px;
|
||||
max-width: calc(100vw - 24px);
|
||||
padding: 12px 14px;
|
||||
border: 1px solid rgba(26, 26, 26, 0.11);
|
||||
border-radius: 14px;
|
||||
background: rgba(255, 255, 255, 0.94);
|
||||
box-shadow:
|
||||
0 8px 24px rgba(17, 17, 26, 0.08),
|
||||
0 2px 5px rgba(17, 17, 26, 0.04);
|
||||
-webkit-backdrop-filter: blur(12px);
|
||||
backdrop-filter: blur(12px);
|
||||
color: var(--ink);
|
||||
font-family: var(--sans);
|
||||
font-size: 11.5px;
|
||||
font-weight: 550;
|
||||
line-height: 1.35;
|
||||
}
|
||||
.nav-community-benefits-card ul {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
}
|
||||
.nav-community-benefits-card li {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 9px;
|
||||
}
|
||||
.nav-community-benefits-dot {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
flex: 0 0 6px;
|
||||
margin-top: 4.5px;
|
||||
border-radius: 50%;
|
||||
background: var(--coral);
|
||||
box-shadow: 0 0 0 2px color-mix(in srgb, var(--coral) 16%, transparent);
|
||||
}
|
||||
.nav-cta {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
@@ -5572,6 +5665,7 @@ footer .container {
|
||||
/* ---------- responsive ----------
|
||||
*
|
||||
* Breakpoint ladder:
|
||||
* 1366 — crowded translated headers use the compact hamburger drawer.
|
||||
* 1280 — desktop chrome shrinks (drop side rails, slimmer container).
|
||||
* 1200 — topbar mid label crowds first, hide it.
|
||||
* 1080 — small desktop / large laptop. Smaller hero/section heads.
|
||||
@@ -5591,25 +5685,22 @@ footer .container {
|
||||
@media (max-width: 1200px) {
|
||||
.topbar-inner .mid { display: none; }
|
||||
}
|
||||
/* nav: between 1080 and 1180 the brand tail + nav links + 2 CTAs + dot
|
||||
* crowd the row. Drop the brand sub-meta first, then tighten link spacing,
|
||||
* so the Star CTA never has to compress. */
|
||||
@media (max-width: 1180px) {
|
||||
/* The full translated navigation plus community, locale, Star, and Download
|
||||
* actions does not fit safely in the condensed 1280px capsule. Keep a compact
|
||||
* row through 1366px and resume the complete desktop header at 1367px. */
|
||||
@media (max-width: 1366px) {
|
||||
.nav-inner { gap: 18px; }
|
||||
.brand-meta { display: none; }
|
||||
/* Link gap for this band already comes from the 1081–1366px rule next to
|
||||
the desktop grid layout (22px — translated labels need the tighter
|
||||
spacing); restating a larger gap here would override it. */
|
||||
}
|
||||
|
||||
/* nav: at ≤1080px there's no clean way to fit Product · Skills · Systems ·
|
||||
/* nav: at ≤1366px there's no clean way to fit Product · Skills · Systems ·
|
||||
* Templates · Craft · Blog · Contact + Download + Star + dot in one row,
|
||||
* so swap to a hamburger panel. Star CTA stays visible in the bar (it's
|
||||
* the social-proof CTA); Download moves into the panel. The Product
|
||||
* submenu flattens from a hover-popup to an always-expanded inline list,
|
||||
* since hover doesn't translate to touch.
|
||||
*/
|
||||
@media (max-width: 1080px) {
|
||||
@media (max-width: 1366px) {
|
||||
.nav-toggle { display: inline-flex; }
|
||||
.brand { white-space: nowrap; }
|
||||
/* Hide Download from the bar (Star stays). */
|
||||
@@ -5686,6 +5777,61 @@ footer .container {
|
||||
padding: 14px 0;
|
||||
font-size: 16px;
|
||||
}
|
||||
/* The persistent community entry moves out of the fixed bar and into the
|
||||
drawer. This keeps brand, hamburger, locale, and the remaining actions
|
||||
within one compact row even with long Russian/Ukrainian labels. */
|
||||
.nav-side .nav-community-entry {
|
||||
display: none;
|
||||
}
|
||||
.nav-links .nav-community-mobile-entry {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
padding: 14px 0 18px;
|
||||
}
|
||||
.nav-links .nav-community-mobile-cta {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
width: fit-content;
|
||||
max-width: 100%;
|
||||
gap: 8px;
|
||||
padding: 10px 14px;
|
||||
border: 1px solid rgba(26, 26, 26, 0.16);
|
||||
border-radius: 999px;
|
||||
background: #fff;
|
||||
box-shadow: 0 2px 7px rgba(17, 17, 26, 0.06);
|
||||
color: var(--ink);
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
line-height: 1.3;
|
||||
white-space: normal;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.nav-links .nav-community-mobile-cta:hover {
|
||||
border-color: rgba(26, 26, 26, 0.3);
|
||||
background: rgba(26, 26, 26, 0.025);
|
||||
}
|
||||
.nav-community-mobile-benefits {
|
||||
display: grid;
|
||||
gap: 9px;
|
||||
min-width: 0;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid rgba(26, 26, 26, 0.09);
|
||||
border-radius: 14px;
|
||||
background: rgba(26, 26, 26, 0.025);
|
||||
}
|
||||
.nav-community-mobile-benefit {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
min-width: 0;
|
||||
gap: 9px;
|
||||
color: var(--ink);
|
||||
font-family: var(--sans);
|
||||
font-size: 13px;
|
||||
font-weight: 550;
|
||||
line-height: 1.4;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.nav-links a .num {
|
||||
position: static;
|
||||
margin-left: 6px;
|
||||
@@ -5878,7 +6024,7 @@ footer .container {
|
||||
.foot-bottom { flex-direction: column; align-items: flex-start; gap: 12px; }
|
||||
.foot-bottom .right { flex-wrap: wrap; gap: 12px 20px; }
|
||||
/* nav — at ≤880px tighten padding; nav-links stay reachable through
|
||||
* the hamburger panel introduced at ≤1080px. Brand meta and Download
|
||||
* the hamburger panel introduced at ≤1366px. Brand meta and Download
|
||||
* stay hidden; Star CTA still pings in the bar. */
|
||||
.nav { padding: 16px 0; }
|
||||
.brand-meta { display: none; }
|
||||
@@ -6823,4 +6969,3 @@ footer .container {
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.hm-dl-hero, .hm-dl-hero .hm-sheen { animation: none; }
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { existsSync, readFileSync } from 'node:fs';
|
||||
import { test } from 'node:test';
|
||||
import { chromium } from 'playwright';
|
||||
import { createElement } from 'react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
|
||||
import { Header } from '../app/_components/header.tsx';
|
||||
|
||||
const headerSource = readFileSync(
|
||||
new URL('../app/_components/header.tsx', import.meta.url),
|
||||
'utf8',
|
||||
);
|
||||
const stylesSource = readFileSync(new URL('../app/globals.css', import.meta.url), 'utf8');
|
||||
|
||||
const ukrainianHeader = renderToStaticMarkup(
|
||||
createElement(Header, {
|
||||
counts: { skills: 100, systems: 10, templates: 20, craft: 5 },
|
||||
github: { starsLabel: '83K+' },
|
||||
locale: 'uk',
|
||||
localeSwitcher: {
|
||||
label: 'Змінити мову',
|
||||
prefix: '',
|
||||
shortLabel: 'UK',
|
||||
options: [
|
||||
{
|
||||
code: 'uk',
|
||||
href: '/uk/',
|
||||
htmlLang: 'uk',
|
||||
label: 'Українська',
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
test('community entry moves into the drawer without overflowing long localized labels', () => {
|
||||
assert.match(
|
||||
headerSource,
|
||||
/<li className='nav-community-mobile-entry'>[\s\S]*?className='nav-community-mobile-cta'[\s\S]*?className='nav-community-mobile-benefits'/,
|
||||
);
|
||||
assert.match(headerSource, /cta: 'Приєднатися до Discord'/);
|
||||
assert.match(stylesSource, /\.nav-community-mobile-entry\s*\{\s*display:\s*none;/);
|
||||
assert.match(
|
||||
stylesSource,
|
||||
/@media \(max-width: 1366px\)[\s\S]*?\.nav-side \.nav-community-entry\s*\{\s*display:\s*none;\s*\}[\s\S]*?\.nav-links \.nav-community-mobile-entry\s*\{[^}]*display:\s*grid;/,
|
||||
);
|
||||
assert.match(
|
||||
stylesSource,
|
||||
/\.nav-links \.nav-community-mobile-cta\s*\{[^}]*max-width:\s*100%;[^}]*white-space:\s*normal;[^}]*overflow-wrap:\s*anywhere;/s,
|
||||
);
|
||||
});
|
||||
|
||||
test('longest-label community entry stays inside the rendered header at its boundary widths', async (t) => {
|
||||
const localChrome = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
|
||||
const browser = await chromium.launch({
|
||||
headless: true,
|
||||
...(existsSync(localChrome) ? { executablePath: localChrome } : {}),
|
||||
});
|
||||
t.after(() => browser.close());
|
||||
|
||||
const context = await browser.newContext({ viewport: { width: 1081, height: 900 } });
|
||||
const page = await context.newPage();
|
||||
await page.setContent(
|
||||
`<!doctype html><html lang="uk"><head><style>${stylesSource}</style></head><body><div class="site-chrome is-condensed">${ukrainianHeader}</div></body></html>`,
|
||||
);
|
||||
|
||||
const readLayout = async (width: number) => {
|
||||
await page.setViewportSize({ width, height: 900 });
|
||||
await page.evaluate(`document.querySelector('header.nav').classList.add('is-open')`);
|
||||
await page.waitForTimeout(250);
|
||||
return page.evaluate(`(() => {
|
||||
const nav = document.querySelector('header.nav');
|
||||
const inner = document.querySelector('.nav-inner');
|
||||
const toggle = document.querySelector('.nav-toggle');
|
||||
const desktopEntry = document.querySelector('.nav-side .nav-community-entry');
|
||||
const drawerEntry = document.querySelector('.nav-community-mobile-entry');
|
||||
if (!nav || !inner || !toggle || !desktopEntry || !drawerEntry) {
|
||||
throw new Error('header layout fixture is incomplete');
|
||||
}
|
||||
|
||||
const isVisible = (element) => {
|
||||
const style = getComputedStyle(element);
|
||||
const rect = element.getBoundingClientRect();
|
||||
return style.display !== 'none' && style.visibility !== 'hidden' && rect.width > 0;
|
||||
};
|
||||
const innerRect = inner.getBoundingClientRect();
|
||||
const rowChildren = Array.from(inner.children).filter((element) => {
|
||||
return isVisible(element) && getComputedStyle(element).position !== 'absolute';
|
||||
});
|
||||
const rowRects = rowChildren
|
||||
.map((element) => element.getBoundingClientRect())
|
||||
.sort((a, b) => a.left - b.left);
|
||||
const rowFits =
|
||||
rowRects.every((rect) => rect.left >= innerRect.left - 1 && rect.right <= innerRect.right + 1) &&
|
||||
rowRects.every((rect, index) => index === 0 || rowRects[index - 1].right <= rect.left + 1);
|
||||
|
||||
return {
|
||||
desktopEntryVisible: isVisible(desktopEntry),
|
||||
drawerEntryText: drawerEntry.innerText,
|
||||
drawerEntryVisible: isVisible(drawerEntry),
|
||||
rowFits,
|
||||
toggleVisible: isVisible(toggle),
|
||||
};
|
||||
})()`);
|
||||
};
|
||||
|
||||
const compact = await readLayout(1081);
|
||||
assert.equal(compact.toggleVisible, true);
|
||||
assert.equal(compact.desktopEntryVisible, false);
|
||||
assert.equal(compact.drawerEntryVisible, true);
|
||||
assert.match(compact.drawerEntryText, /Приєднатися до Discord/);
|
||||
assert.equal(compact.rowFits, true);
|
||||
|
||||
const desktop = await readLayout(1367);
|
||||
assert.equal(desktop.toggleVisible, false);
|
||||
assert.equal(desktop.desktopEntryVisible, true);
|
||||
assert.equal(desktop.drawerEntryVisible, false);
|
||||
assert.equal(desktop.rowFits, true);
|
||||
});
|
||||
Reference in New Issue
Block a user