Skip to content

Commit a0db8bc

Browse files
committed
reduced width layouts
1 parent 657c6a5 commit a0db8bc

File tree

6 files changed

+45
-4
lines changed

6 files changed

+45
-4
lines changed

special-pages/pages/history/app/components/App.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ import { useURLReflection } from '../global/hooks/useURLReflection.js';
1818
import { useSearchCommit } from '../global/hooks/useSearchCommit.js';
1919
import { useRangesData } from '../global/Providers/HistoryServiceProvider.js';
2020
import { usePlatformName } from '../types.js';
21+
import { useLayoutMode } from '../global/hooks/useLayoutMode.js';
2122

2223
export function App() {
2324
const platformName = usePlatformName();
2425
const mainRef = useRef(/** @type {HTMLElement|null} */ (null));
2526
const { isDarkMode } = useEnv();
2627
const ranges = useRangesData();
2728
const query = useQueryContext();
29+
const mode = useLayoutMode();
2830

2931
/**
3032
* Handlers that are global in nature
@@ -60,7 +62,7 @@ export function App() {
6062
}, [onKeyDown, query]);
6163

6264
return (
63-
<div class={styles.layout} data-theme={isDarkMode ? 'dark' : 'light'} data-platform={platformName}>
65+
<div class={styles.layout} data-theme={isDarkMode ? 'dark' : 'light'} data-platform={platformName} data-layout-mode={mode}>
6466
<aside class={styles.aside}>
6567
<Sidebar ranges={ranges} />
6668
</aside>

special-pages/pages/history/app/components/App.module.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ body {
1515
--main-padding-right: 76px;
1616
--windows-scrollbar: 15px;
1717

18+
&[data-layout-mode="reduced"] {
19+
--sidebar-width: 230px;
20+
--main-padding-left: 28px;
21+
--main-padding-right: 56px;
22+
}
23+
1824
display: grid;
1925
grid-template-columns: var(--sidebar-width) 1fr;
2026
grid-template-rows: max-content 1fr;

special-pages/pages/history/app/components/Header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function Controls({ term, range, domain }) {
8484

8585
return (
8686
<div class={styles.controls}>
87-
<button class={styles.largeButton} onClick={onClick} aria-disabled={ariaDisabled} title={title}>
87+
<button class={styles.largeButton} onClick={onClick} aria-disabled={ariaDisabled} title={title} tabindex={0}>
8888
<Trash />
8989
<span>{buttonTxt}</span>
9090
</button>

special-pages/pages/history/app/components/Item.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const Item = memo(
5353
<a href={props.url} data-url={props.url} class={styles.entryLink} tabindex={0}>
5454
{title}
5555
</a>
56-
<span class={styles.domain} data-testid="Item.domain">
56+
<span class={styles.domain} data-testid="Item.domain" title={props.domain}>
5757
{props.domain}
5858
</span>
5959
<span class={styles.time}>{dateTimeOfDay}</span>

special-pages/pages/history/app/components/Item.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
overflow: hidden;
111111
text-overflow: ellipsis;
112112

113-
@media screen and (min-width: 800px) {
113+
[data-layout-mode="normal"] & {
114114
flex-shrink: 0;
115115
}
116116

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { useSignal } from '@preact/signals';
2+
import { useLayoutEffect } from 'preact/hooks';
3+
4+
/**
5+
* This hook listens to changes in the viewport width and provides a
6+
* reactive signal indicating whether the layout mode should be 'reduced'
7+
* or 'normal'.
8+
*
9+
* - 'reduced': For narrow viewports (width <= 799px).
10+
* - 'normal': For wider viewports (width > 799px).
11+
*
12+
* @returns {import('@preact/signals').ReadonlySignal<'reduced' | 'normal'>}
13+
* A signal representing the current layout mode ('reduced' or 'normal').
14+
*/
15+
export function useLayoutMode() {
16+
const mode = useSignal(/** @type {'reduced' | 'normal'} */ (window.matchMedia('(max-width: 799px)').matches ? 'reduced' : 'normal'));
17+
18+
useLayoutEffect(() => {
19+
const mediaQuery = window.matchMedia('(max-width: 799px)');
20+
const handleChange = () => {
21+
mode.value = mediaQuery.matches ? 'reduced' : 'normal';
22+
};
23+
24+
handleChange();
25+
mediaQuery.addEventListener('change', handleChange);
26+
27+
return () => {
28+
mediaQuery.removeEventListener('change', handleChange);
29+
};
30+
}, []);
31+
32+
return mode;
33+
}

0 commit comments

Comments
 (0)