-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathindex.js
More file actions
154 lines (145 loc) · 4.78 KB
/
index.js
File metadata and controls
154 lines (145 loc) · 4.78 KB
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
146
147
148
149
150
151
152
153
154
import React, { Fragment, useCallback, useState } from "react"
import styled from "styled-components"
import useToggle from "@/hooks/useToggle"
import { H5 } from "@/components/typography"
import { Icon } from "@/components/icon"
import { Button } from "@/components/button"
import Flex from "@/components/templates/flex"
import Layer from "@/components/templates/layer"
import General from "./general"
import Dashboard from "./dashboard"
import SearchProvider, { SearchInput, SearchResults } from "./search"
const Container = styled(Flex).attrs({
padding: [6],
background: "dropdown",
gap: 6,
column: true,
round: true,
overflow: { vertical: "auto" },
})`
box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
`
const Header = ({ children, onClose }) => {
return (
<Flex
width="100%"
alignItems="center"
justifyContent="between"
padding={[0, 0, 4]}
border={{ side: "bottom", color: "disabled" }}
>
<Flex gap={2} alignItems="center">
{children}
</Flex>
<Button
icon="x"
neutral
small
onClick={onClose}
flavour="borderless"
data-testid="documentation-help-close"
/>
</Flex>
)
}
const views = { general: "general", dashboard: "dashboard", search: "search" }
const titles = { general: "Need help?", dashboard: "Need help?" }
const Documentation = ({
app = "cloud",
onCloseClick,
onVisitDocumentClick,
onOpenIssueClick,
onOpenBugClick,
onContributeClick,
onSupportClick,
onGoToDemoClick,
children,
demoUrl,
modalProps = {},
}) => {
const [isOpen, toggle] = useToggle()
const [view, setView] = useState(views.general)
const isGeneral = view === views.general
const setDashboardView = useCallback(() => setView(views.dashboard), [])
const setGeneralView = useCallback(() => setView(views.general), [])
const setSearchView = useCallback(() => setView(views.search), [])
const closeClicked = useCallback(() => {
toggle()
if (onCloseClick) onCloseClick()
}, [])
return (
<Fragment>
{children(toggle, isOpen)}
{isOpen && (
<Layer
position="bottom-left"
backdrop
margin={[5, 17]}
onClickOutside={toggle}
onEsc={toggle}
>
<SearchProvider>
{({ searchTerm, setSearchTerm, results, reset }) => {
return (
<Fragment>
<Container
width={{
max: isGeneral ? "325px" : view === views.dashboard ? "600px" : "100%",
}}
data-testid="documentation-layer"
{...modalProps}
>
<Header onClose={closeClicked}>
{isGeneral && (
<Icon color="text" name="questionFilled" width="18px" height="18px" />
)}
{!isGeneral && (
<Button
icon="arrow_left"
neutral
small
onClick={() => {
setGeneralView()
reset()
}}
flavour="borderless"
data-testid="dashboard-back"
/>
)}
<H5 margin={[0]}>{titles[view] || titles.general}</H5>
</Header>
{view !== views.dashboard && (
<SearchInput
value={searchTerm}
setSearchTerm={setSearchTerm}
setSearchView={setSearchView}
/>
)}
{isGeneral && (
<Flex gap={6} overflow={{ vertical: "auto" }} column padding={[1]}>
<General
app={app}
onDashboardClick={setDashboardView}
onVisitDocumentClick={onVisitDocumentClick}
onOpenIssueClick={onOpenIssueClick}
onOpenBugClick={onOpenBugClick}
onContributeClick={onContributeClick}
onSupportClick={onSupportClick}
onGoToDemoClick={onGoToDemoClick}
demoUrl={demoUrl}
/>
</Flex>
)}
{view === views.dashboard && <Dashboard />}
{view === views.search && <SearchResults results={results} />}
</Container>
</Fragment>
)
}}
</SearchProvider>
</Layer>
)}
</Fragment>
)
}
export default Documentation