aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/Selection.js
blob: d6e62ab4443afa1e938b2502d62e0b70c9186525 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { h } from 'preact';
import { useState, useEffect } from 'preact/hooks';
import cn from 'classnames';
import css from './css';
import { Note } from './Note';

css`
.drawer {
	background: var(--theme-note-fg);

	flex: 0 0 auto;

	/* wtf webkit */
  -webkit-backface-visibility: hidden;
}

.drawer .handle {
	height: 2rem;
	margin-bottom: 1rem;
}

.drawer .handle button {
	display: block;

	height: 2rem;
	line-height: 2rem;
	margin: -1rem auto 0;
	padding: 0.25rem;
	background: var(--theme-note-bg);
	border-radius: 0.4rem;
}

.drawer .scroller {
	display: flex;
	overflow: auto;
	width: 100%;

	transition: max-height 0.3s;
}

.drawer .contents {
	display: flex;

	align-items: flex-start;

	gap: 1rem;
	padding: 0 2rem;
}

.drawer .contents > * {
	flex: 0 0 auto;
}
`;

export const Drawer = ({ height, children }) => {
	const [ hidden, setHidden ] = useState(true);

	return (
		<div class="drawer">
			<div class="handle">
				<button onClick={() => setHidden(!hidden)}>
					###
				</button>
			</div>
			<div
				class="scroller"
				style={{
					height,
					'max-height': hidden ? '0' : height,
				}}
			>
				<div class="contents">
					{children}
				</div>
			</div>
		</div>
	);
};

export const Selection = ({ items, toggleSelected }) => (
	<Drawer height="12rem" style={{ }} >
		{items.map((item) => (
			<Note
				{...item}
				ellipsis
				onSelect={toggleSelected}
			/>
		))}
	</Drawer>
);