Skip to content

Commit 83cda98

Browse files
committed
Mobile fixes
1 parent 52cc234 commit 83cda98

7 files changed

Lines changed: 112 additions & 32 deletions

File tree

src/components/DeclarationsPage.tsx

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useMemo, useState } from "react";
1+
import React, { useCallback, useMemo, useState } from "react";
22
import { styled } from "@linaria/react";
33
import {
44
DeclarationsContext,
@@ -83,6 +83,7 @@ export default function DeclarationsPage({
8383
}) {
8484
const [filter, setFilter] = useState("");
8585
const [search, setSearch] = useState("");
86+
const [sidebarOpen, setSidebarOpen] = useState(false);
8687

8788
const references = useMemo(() => buildReferences(context.declarations), [context.declarations]);
8889

@@ -104,14 +105,20 @@ export default function DeclarationsPage({
104105
const searchCtx = useMemo(() => ({ search, setSearch }), [search, setSearch]);
105106
const filterCtx = useMemo(() => ({ filter, setFilter }), [filter, setFilter]);
106107

108+
const closeSidebar = useCallback(() => setSidebarOpen(false), []);
109+
const openSidebar = useCallback(() => setSidebarOpen(true), []);
110+
107111
return (
108112
<DeclarationsContext.Provider value={fullContext}>
109113
<SearchContext.Provider value={searchCtx}>
110114
<SidebarFilterContext.Provider value={filterCtx}>
111115
<PageGrid>
112-
<DeclarationsSidebar />
116+
<MobileSidebarOverlay data-open={sidebarOpen || undefined} onClick={closeSidebar} />
117+
<SidebarPanel data-open={sidebarOpen || undefined}>
118+
<DeclarationsSidebar onNavigate={closeSidebar} />
119+
</SidebarPanel>
113120
<ContentColumn>
114-
<NavBar baseUrl={context.root} />
121+
<NavBar baseUrl={context.root} onMenuClick={openSidebar} />
115122
<ContentList />
116123
</ContentColumn>
117124
</PageGrid>
@@ -127,15 +134,49 @@ const ContentColumn = styled.div`
127134
overflow: hidden;
128135
`;
129136

137+
const MobileSidebarOverlay = styled.div`
138+
display: none;
139+
140+
@media (max-width: 768px) {
141+
&[data-open] {
142+
display: block;
143+
position: fixed;
144+
inset: 0;
145+
background: rgba(0, 0, 0, 0.5);
146+
z-index: 300;
147+
}
148+
}
149+
`;
150+
151+
const SidebarPanel = styled.div`
152+
display: contents;
153+
154+
@media (max-width: 768px) {
155+
display: none;
156+
position: fixed;
157+
top: 0;
158+
left: 0;
159+
bottom: 0;
160+
width: 300px;
161+
z-index: 301;
162+
background: var(--sidebar);
163+
164+
&[data-open] {
165+
display: flex;
166+
}
167+
168+
> * {
169+
flex: 1;
170+
min-height: 0;
171+
}
172+
}
173+
`;
174+
130175
const PageGrid = styled.div`
131176
display: grid;
132177
grid-template-columns: 340px 1fr;
133178
height: 100dvh;
134179
135-
@media (max-width: 1100px) {
136-
grid-template-columns: 200px 1fr;
137-
}
138-
139180
@media (max-width: 768px) {
140181
grid-template-columns: 1fr;
141182
}

src/components/DeclarationsSidebar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const HEADER_HEIGHT = 28;
3838
const HEADER_GAP = 8;
3939
const ITEM_HEIGHT = 28;
4040

41-
export const DeclarationsSidebar = () => {
41+
export const DeclarationsSidebar = ({ onNavigate }: { onNavigate?: () => void }) => {
4242
const { declarations } = useContext(DeclarationsContext);
4343
const { filter, setFilter } = useContext(SidebarFilterContext);
4444
const { module: activeModule = "", scope = "" } = useParams();
@@ -205,7 +205,7 @@ export const DeclarationsSidebar = () => {
205205
</SidebarGroupHeader>
206206
</div>
207207
) : (
208-
<DeclarationSidebarElement declaration={row.declaration} />
208+
<DeclarationSidebarElement declaration={row.declaration} onClick={onNavigate} />
209209
)}
210210
</div>
211211
);

src/components/Docs/ContentList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ const OffsetsNote = styled.div`
142142
font-size: 14px;
143143
color: var(--text-dim);
144144
text-align: center;
145-
padding: 8px 4px 0;
145+
padding: 8px 4px;
146146
`;
147147

148148
function renderItem(declaration: Declaration) {

src/components/Docs/SchemaClass.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const FieldRow = styled.div`
4444
background-color: var(--group);
4545
border: 1px solid var(--group-border);
4646
border-radius: 8px;
47+
overflow: hidden;
4748
4849
&[data-highlighted] {
4950
background-color: var(--search-highlight);
@@ -55,6 +56,7 @@ const FieldSignature = styled.div`
5556
font-size: 16px;
5657
display: flex;
5758
align-items: baseline;
59+
flex-wrap: wrap;
5860
gap: 6px;
5961
`;
6062

src/components/layout/Content.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { styled } from "@linaria/react";
22

33
export const ContentWrapper = styled.main`
44
flex: 1;
5-
padding: 0 0 0 24px;
5+
padding: 0 24px 24px 24px;
66
min-width: 0;
77
overflow-y: auto;
88
99
@media (max-width: 768px) {
1010
grid-column: 1;
11-
padding: 0;
11+
padding: 0 8px 16px;
1212
}
1313
`;
1414

@@ -27,5 +27,5 @@ export const TextMessage = styled.div`
2727
`;
2828

2929
export const ListItem = styled.div`
30-
padding: 5px 14px 5px 0;
30+
padding: 5px 0;
3131
`;

src/components/layout/NavBar.tsx

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import { AppContext } from "../AppContext";
55
import { SearchBox } from "../Search";
66
import { GAMES, GameId, getGame } from "../../games";
77

8-
export const NavBar = ({ baseUrl }: { baseUrl?: string }) => {
8+
export const NavBar = ({
9+
baseUrl,
10+
onMenuClick,
11+
}: {
12+
baseUrl?: string;
13+
onMenuClick?: () => void;
14+
}) => {
915
if (!baseUrl) {
1016
return (
1117
<NavBarSimple>
@@ -16,6 +22,23 @@ export const NavBar = ({ baseUrl }: { baseUrl?: string }) => {
1622

1723
return (
1824
<NavBarContentCell>
25+
{onMenuClick && (
26+
<MenuButton onClick={onMenuClick} aria-label="Open sidebar">
27+
<svg
28+
viewBox="0 0 24 24"
29+
width="22"
30+
height="22"
31+
fill="none"
32+
stroke="currentColor"
33+
strokeWidth="2"
34+
strokeLinecap="round"
35+
>
36+
<line x1="3" y1="6" x2="21" y2="6" />
37+
<line x1="3" y1="12" x2="21" y2="12" />
38+
<line x1="3" y1="18" x2="21" y2="18" />
39+
</svg>
40+
</MenuButton>
41+
)}
1942
<NavBarSearchBox baseUrl={baseUrl} placeholder="Search... (module: or offset: to filter)" />
2043
<NavBarThemeSwitcher />
2144
</NavBarContentCell>
@@ -168,6 +191,21 @@ const SwitcherOption = styled.button`
168191
}
169192
`;
170193

194+
const MenuButton = styled.button`
195+
display: none;
196+
background: none;
197+
border: none;
198+
padding: 4px;
199+
color: var(--text);
200+
cursor: pointer;
201+
flex-shrink: 0;
202+
203+
@media (max-width: 768px) {
204+
display: flex;
205+
align-items: center;
206+
}
207+
`;
208+
171209
const NavBarContentCell = styled.div`
172210
display: flex;
173211
align-items: center;

src/components/layout/Sidebar.tsx

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,28 @@ export const SidebarElement: React.FC<{
4747
to: string;
4848
icon: IconKind;
4949
text: string;
50-
}> = React.memo(({ to, icon, text }) => (
51-
<SidebarLink to={to} prefetch="none">
50+
onClick?: () => void;
51+
}> = React.memo(({ to, icon, text, onClick }) => (
52+
<SidebarLink to={to} prefetch="none" onClick={onClick}>
5253
<KindIcon kind={icon} size="small" />
5354
<span>{text}</span>
5455
</SidebarLink>
5556
));
5657

57-
export const DeclarationSidebarElement: React.FC<{ declaration: Declaration }> = React.memo(
58-
({ declaration }) => {
59-
const { root } = useContext(DeclarationsContext);
60-
return (
61-
<SidebarElement
62-
to={`${root}/${declaration.module}/${declaration.name}`}
63-
icon={declaration.kind}
64-
text={declaration.name}
65-
/>
66-
);
67-
},
68-
);
58+
export const DeclarationSidebarElement: React.FC<{
59+
declaration: Declaration;
60+
onClick?: () => void;
61+
}> = React.memo(({ declaration, onClick }) => {
62+
const { root } = useContext(DeclarationsContext);
63+
return (
64+
<SidebarElement
65+
to={`${root}/${declaration.module}/${declaration.name}`}
66+
icon={declaration.kind}
67+
text={declaration.name}
68+
onClick={onClick}
69+
/>
70+
);
71+
});
6972

7073
export const SidebarGroupHeader = styled.button`
7174
background: var(--sidebar);
@@ -112,8 +115,4 @@ export const SidebarWrapper = styled.div`
112115
min-width: 0;
113116
padding: 6px 8px 4px 10px;
114117
background-color: var(--sidebar);
115-
116-
@media (max-width: 768px) {
117-
display: none;
118-
}
119118
`;

0 commit comments

Comments
 (0)