Skip to content

Commit 166c095

Browse files
committed
fix: docs layout for mobile size
1 parent a1e07bc commit 166c095

7 files changed

Lines changed: 96 additions & 8 deletions

File tree

apps/docs/src/components/doc-footer/component-page.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
&__layout {
88
padding: 30px 30px 30px 280px;
9+
10+
@media (max-width: $size-md) {
11+
padding: 20px 16px;
12+
}
913
}
1014

1115
&__divider {

apps/docs/src/components/header/header.scss

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,23 @@
5454
display: flex;
5555
list-style: none;
5656
height: 100%;
57+
min-width: 0;
58+
overflow-x: auto;
59+
-webkit-overflow-scrolling: touch;
60+
scrollbar-width: none;
61+
62+
&::-webkit-scrollbar {
63+
display: none;
64+
}
5765
}
5866

5967
&__nav-list {
6068
height: 100%;
6169
margin: 0;
70+
padding: 0;
6271
display: flex;
6372
align-items: center;
73+
white-space: nowrap;
6474
}
6575

6676
&__nav-item {
@@ -143,13 +153,15 @@
143153

144154
@media (max-width: $size-xs) {
145155
&__nav-item {
146-
margin-left: 12px;
147-
font-size: 14px;
156+
margin-left: 8px;
157+
font-size: 13px;
148158
}
149159

150160
&__version,
151161
&__locale-toggle,
152-
&__theme-toggle {
162+
&__theme-toggle,
163+
&__github-link,
164+
&__home-link {
153165
display: none;
154166
}
155167
}

apps/docs/src/components/header/index.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import './header.scss';
3-
import { NavLink } from 'react-router-dom';
3+
import { NavLink, useLocation } from 'react-router-dom';
44
import pkg from '../../../../../packages/react/package.json';
55
import { Link } from '@tiny-design/react';
66
import { IconGithub } from '@tiny-design/icons';
@@ -15,14 +15,17 @@ const { version, repository } = pkg;
1515
export const Header = (): React.ReactElement => {
1616
const { toggle } = useSidebarToggle();
1717
const { siteLocale: s } = useLocaleContext();
18+
const { pathname } = useLocation();
19+
const isHome = pathname === '/';
1820

1921
return (
2022
<header className="header">
2123
<div className="header__left">
2224
<button
2325
className="header__menu-toggle"
2426
onClick={toggle}
25-
aria-label="Toggle menu">
27+
aria-label="Toggle menu"
28+
style={isHome ? { display: 'none' } : undefined}>
2629
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
2730
<line x1="3" y1="6" x2="21" y2="6" />
2831
<line x1="3" y1="12" x2="21" y2="12" />
@@ -38,7 +41,7 @@ export const Header = (): React.ReactElement => {
3841
</div>
3942
<nav className="header__nav">
4043
<ul className="header__nav-list">
41-
<li className="header__nav-item">
44+
<li className="header__nav-item header__home-link">
4245
<NavLink end to="/" className="header__link">
4346
{s.nav.home}
4447
</NavLink>
@@ -67,7 +70,7 @@ export const Header = (): React.ReactElement => {
6770
<span className="header__version">v{version}</span>
6871
</a>
6972
</li>
70-
<li className="header__nav-item">
73+
<li className="header__nav-item header__github-link">
7174
<Link href={repository.url} underline={false} rel="noreferrer noopener">
7275
<IconGithub color="currentColor" size={19} />
7376
</Link>

apps/docs/src/components/markdown-tag/md-tag.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@
6565
}
6666
}
6767

68+
overflow-wrap: break-word;
69+
70+
@media (max-width: $size-md) {
71+
overflow-x: hidden;
72+
}
73+
6874
&__pre-container {
6975
code {
7076
line-height: 2;

apps/docs/src/components/sidebar-menu/index.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ import React from 'react';
22
import './sidebar-menu.scss';
33
import { NavLink } from 'react-router-dom';
44
import { RouterItem } from '../../routers';
5-
import { Layout } from '@tiny-design/react';
5+
import { Layout, Link } from '@tiny-design/react';
6+
import { IconGithub } from '@tiny-design/icons';
67
import { useSidebarToggle } from '../../context/sidebar-toggle-context';
8+
import { useLocaleContext } from '../../context/locale-context';
9+
import { ThemeToggle } from '../header/theme-toggle';
10+
import pkg from '../../../../../packages/react/package.json';
711

812
const { Sidebar } = Layout;
13+
const { version, repository } = pkg;
914

1015
type Props = {
1116
routers: RouterItem[];
@@ -15,6 +20,8 @@ type Props = {
1520
export const SidebarMenu = (props: Props): React.ReactElement => {
1621
const { routers, url } = props;
1722
const { isOpen, close } = useSidebarToggle();
23+
const { locale, toggle: toggleLocale } = useLocaleContext();
24+
const isZh = locale.locale === 'zh_CN';
1825

1926
return (
2027
<>
@@ -61,6 +68,19 @@ export const SidebarMenu = (props: Props): React.ReactElement => {
6168
}
6269
})}
6370
</ul>
71+
<div className="sidebar-menu__toolbar">
72+
<span className="sidebar-menu__toolbar-version">v{version}</span>
73+
<Link href={repository.url} underline={false} rel="noreferrer noopener">
74+
<IconGithub color="currentColor" size={18} />
75+
</Link>
76+
<button
77+
className="sidebar-menu__toolbar-btn"
78+
onClick={toggleLocale}
79+
aria-label={isZh ? 'Switch to English' : '切换到中文'}>
80+
{isZh ? 'EN' : '中文'}
81+
</button>
82+
<ThemeToggle />
83+
</div>
6484
</Sidebar>
6585
</>
6686
);

apps/docs/src/components/sidebar-menu/sidebar-menu.scss

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
border-right: 1px solid var(--ty-color-border);
1212
padding: 20px 0;
1313
z-index: 99;
14+
display: flex;
15+
flex-direction: column;
1416

1517
&__title {
1618
margin: 0 30px;
@@ -98,6 +100,10 @@
98100
display: none;
99101
}
100102

103+
&__toolbar {
104+
display: none;
105+
}
106+
101107
@media (max-width: $size-md) {
102108
transform: translateX(-100%);
103109
transition: transform 0.3s ease;
@@ -114,5 +120,41 @@
114120
background: rgba(0, 0, 0, 0.3);
115121
z-index: 100;
116122
}
123+
124+
&__toolbar {
125+
display: flex;
126+
align-items: center;
127+
gap: 12px;
128+
padding: 16px 30px;
129+
border-top: 1px solid var(--ty-color-border-secondary);
130+
margin-top: auto;
131+
}
132+
133+
&__toolbar-version {
134+
font-size: 12px;
135+
color: var(--ty-color-text-tertiary);
136+
background: var(--ty-color-fill);
137+
padding: 2px 10px;
138+
border-radius: 46px;
139+
}
140+
141+
&__toolbar-btn {
142+
display: inline-flex;
143+
align-items: center;
144+
justify-content: center;
145+
height: 28px;
146+
padding: 0 8px;
147+
border: 1px solid var(--ty-color-border);
148+
border-radius: 14px;
149+
background: var(--ty-color-bg-elevated);
150+
color: var(--ty-color-text-secondary);
151+
cursor: pointer;
152+
font-size: 12px;
153+
font-weight: 500;
154+
}
155+
156+
&__toolbar .header__theme-toggle {
157+
display: inline-flex;
158+
}
117159
}
118160
}

apps/docs/src/index.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ body {
2828

2929
&__layout {
3030
padding: 30px 30px 30px 280px;
31+
overflow-x: hidden;
3132

3233
@media (max-width: $size-md) {
3334
padding: 20px 16px;

0 commit comments

Comments
 (0)