-
Notifications
You must be signed in to change notification settings - Fork 172
/
Docs.tsx
145 lines (135 loc) · 5.4 KB
/
Docs.tsx
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import {
Component,
For,
Show,
Switch,
Match,
createEffect,
createSignal,
onMount,
on,
} from 'solid-js';
import { createStore } from 'solid-js/store';
import Nav from '../components/Nav';
import Header from '../components/Header';
import { Section } from '../../scripts/types';
import { Icon } from '@amoutonbrady/solid-heroicons';
import { chevronDown, chevronRight } from '@amoutonbrady/solid-heroicons/solid';
import Footer from '../components/Footer';
import createIntersectionObserver from '../utils/createIntersectionObserver';
const Docs: Component<{
doc: { content: string; sections: Section[] };
hash: string;
loading: boolean;
version: string;
}> = (props) => {
const [current, setCurrent] = createSignal<string | null>(null);
const [section, setSection] = createStore<Record<string, boolean>>({});
const [toggleSections, setToggleSections] = createSignal(false);
onMount(() => {
props.doc.sections.forEach((section) => {
const obs = createIntersectionObserver(document.getElementById(section.slug)!, false);
createEffect(
on(obs, (entry) => current() !== null && entry !== null && setCurrent(section.slug)),
);
});
setCurrent(props.doc.sections[0].slug);
});
return (
<div class="flex flex-col relative">
<Nav showLogo />
<Header title="Documentation" />
<Show when={!props.loading}>
<div class="lg:px-12 container my-5 lg:grid lg:grid-cols-12 gap-4">
<button
class="fixed lg:hidden top-20 right-3 text-white rounded-lg pl-1 pt-1 transition duration-500 bg-solid-medium"
classList={{
'rotate-90': toggleSections(),
}}
onClick={() => setToggleSections(!toggleSections())}
>
<Icon class="h-7 w-7" path={chevronRight} />
</button>
<div class="col-span-4 lg:col-span-3 relative">
<div
class={
'py-5 h-5/6 w-5/6 rounded-r-lg rounded-br-lg overflow-auto z-20 p-10 md:p-0 shadow-2xl border-2 border-gray-100 bg-white fixed top-12 duration-300 transform ' +
'md:border-0 md:shadow-none md:p-0 md:flex-col ' +
'lg:sticky lg:flex'
}
classList={{
'-left-full': !toggleSections(),
'left-0': toggleSections(),
}}
style={{ height: 'calc(100vh - 5rem)', top: '4rem' }}
>
<ul class="overflow-auto flex flex-col flex-1">
<For each={props.doc.sections}>
{(firstLevel: Section) => (
<li>
<button
type="button"
class="text-left w-full text-solid-medium border-b hover:text-gray-400 transition flex flex-wrap content-center justify-between space-x-2 text-sm p-2 py-4"
onClick={() => setSection(firstLevel.title, (prev) => !prev)}
>
<span
class="flex-1"
classList={{
'font-semibold': current() == firstLevel.slug,
}}
>
{firstLevel.title}
</span>
<Icon
class="opacity-50 h-5 w-7 transform transition origin-center"
classList={{
'rotate-180 opacity-100': !!section[firstLevel.title],
hidden: !firstLevel.children!.length,
}}
path={chevronDown}
/>
</button>
<ul
class="overflow-hidden transition"
classList={{
'h-0': section[firstLevel.title] !== true,
}}
>
<For each={firstLevel.children!}>
{(secondLevel) => (
<li onClick={() => setToggleSections(false)}>
<a
class="block px-5 border-b border-gray-100 pb-3 text-sm my-4 break-words"
classList={{
'text-solid hover:text-solid-dark':
`#${secondLevel.slug}` === props.hash,
'hover:text-gray-400': `#${secondLevel.slug}` !== props.hash,
}}
href={`#${secondLevel.slug}`}
children={secondLevel.title}
/>
</li>
)}
</For>
</ul>
</li>
)}
</For>
</ul>
</div>
</div>
<div class="col-span-8 lg:col-span-9 px-10 lg:px-0">
<Switch fallback={'Failed to load markdown...'}>
<Match when={props.loading}>Loading documentation...</Match>
<Match when={props.doc}>
<div class="prose prose-solid max-w-full" innerHTML={props.doc.content} />
</Match>
</Switch>
</div>
</div>
</Show>
<Footer />
</div>
);
};
export default Docs;