@redocly/theme 0.7.4 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Catalog/Catalog.d.ts +8 -0
- package/lib/Catalog/Catalog.js +167 -0
- package/lib/Catalog/CatalogCard.d.ts +5 -0
- package/lib/Catalog/CatalogCard.js +113 -0
- package/lib/Catalog/Filter.d.ts +5 -0
- package/lib/Catalog/Filter.js +88 -0
- package/lib/Catalog/Tags.d.ts +4 -0
- package/lib/Catalog/Tags.js +32 -0
- package/lib/Feedback/ReportDialog.d.ts +3 -0
- package/lib/Feedback/ReportDialog.js +66 -0
- package/lib/Feedback/index.d.ts +2 -0
- package/lib/Feedback/index.js +5 -1
- package/lib/Feedback/types.d.ts +5 -3
- package/lib/Feedback/useReportDialog.d.ts +7 -0
- package/lib/Feedback/useReportDialog.js +28 -0
- package/lib/Markdown/CodeSample/CodeSample.js +5 -38
- package/lib/Sidebar/ArrowBack.js +2 -2
- package/lib/Sidebar/MenuGroup.js +1 -1
- package/lib/Sidebar/Sidebar.d.ts +1 -0
- package/lib/Sidebar/Sidebar.js +5 -2
- package/lib/Sidebar/SidebarLayout.d.ts +6 -1
- package/lib/Sidebar/SidebarLayout.js +27 -2
- package/lib/TableOfContent/TableOfContent.js +1 -1
- package/lib/config.js +2 -2
- package/lib/globalStyle.js +13 -11
- package/lib/hooks/useActiveHeading.js +2 -7
- package/lib/hooks/useActiveSectionId.js +1 -1
- package/lib/hooks/useMobileMenu.js +1 -1
- package/lib/mocks/hooks/index.d.ts +4 -0
- package/lib/mocks/hooks/index.js +9 -1
- package/lib/ui/Checkbox.d.ts +1 -0
- package/lib/ui/Checkbox.js +70 -0
- package/lib/ui/Highlight.d.ts +5 -0
- package/lib/ui/Highlight.js +63 -0
- package/lib/ui/Jumbotron.js +2 -2
- package/lib/ui/darkColors.js +4 -2
- package/package.json +6 -8
- package/src/Catalog/Catalog.tsx +198 -0
- package/src/Catalog/CatalogCard.tsx +95 -0
- package/src/Catalog/Filter.tsx +103 -0
- package/src/Catalog/Tags.tsx +36 -0
- package/src/Feedback/ReportDialog.tsx +51 -0
- package/src/Feedback/index.ts +2 -0
- package/src/Feedback/types.ts +5 -3
- package/src/Feedback/useReportDialog.ts +34 -0
- package/src/Markdown/CodeSample/CodeSample.tsx +7 -50
- package/src/Sidebar/ArrowBack.tsx +2 -2
- package/src/Sidebar/MenuGroup.tsx +1 -1
- package/src/Sidebar/Sidebar.tsx +6 -2
- package/src/Sidebar/SidebarLayout.tsx +41 -2
- package/src/TableOfContent/TableOfContent.tsx +1 -1
- package/src/config.ts +2 -2
- package/src/globalStyle.ts +13 -11
- package/src/hooks/useActiveHeading.ts +3 -12
- package/src/hooks/useActiveSectionId.ts +1 -1
- package/src/hooks/useMobileMenu.ts +2 -2
- package/src/mocks/hooks/index.ts +10 -1
- package/src/types/portal/src/shared/types/catalog.d.ts +55 -0
- package/src/ui/Checkbox.tsx +64 -0
- package/src/ui/Highlight.tsx +48 -0
- package/src/ui/Jumbotron.tsx +2 -2
- package/src/ui/darkColors.tsx +4 -2
- package/lib/hooks/useReportDialog.d.ts +0 -1
- package/lib/hooks/useReportDialog.js +0 -16
- package/src/hooks/useReportDialog.ts +0 -14
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
|
|
4
|
+
import type { ResolvedNavItem } from '@redocly/theme/src/types/portal';
|
|
5
|
+
|
|
6
|
+
import type { CatalogConfig } from '@theme/types/portal/src/shared/types/catalog';
|
|
7
|
+
import { usePageSharedData } from '@portal/hooks/index.js';
|
|
8
|
+
import { H2 } from '@theme/Typography/H2';
|
|
9
|
+
import { H3 } from '@theme/Typography/H3';
|
|
10
|
+
import { Button } from '@theme/Button/Button';
|
|
11
|
+
import { HighlightContext } from '@theme/ui/Highlight';
|
|
12
|
+
import { CatalogCard } from '@theme/Catalog/CatalogCard';
|
|
13
|
+
import { Filter } from '@theme/Catalog/Filter';
|
|
14
|
+
import { useCatalog } from '@portal/hooks/index';
|
|
15
|
+
|
|
16
|
+
export default function Catalog(props: {
|
|
17
|
+
pageProps: {
|
|
18
|
+
catalogId: string;
|
|
19
|
+
catalogConfig: CatalogConfig;
|
|
20
|
+
};
|
|
21
|
+
}) {
|
|
22
|
+
const { catalogConfig } = props.pageProps;
|
|
23
|
+
const items = usePageSharedData('catalog') as ResolvedNavItem[];
|
|
24
|
+
|
|
25
|
+
const { filterTerm, setFilterTerm, groups, filters } = useCatalog(items, catalogConfig);
|
|
26
|
+
const [isFilterPanelFocused, setIsFilterPanelFocused] = React.useState(false);
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<HighlightContext.Provider value={[filterTerm]}>
|
|
30
|
+
<CatalogPageWrapper>
|
|
31
|
+
<CatalogPageSidebar isActiveInMobileMode={isFilterPanelFocused}>
|
|
32
|
+
<StyledInput
|
|
33
|
+
placeholder="Filter..."
|
|
34
|
+
value={filterTerm}
|
|
35
|
+
onFocus={() => setIsFilterPanelFocused(true)}
|
|
36
|
+
onChange={(e) => setFilterTerm(e.target.value)}
|
|
37
|
+
/>
|
|
38
|
+
{filters.map((filter, idx) => (
|
|
39
|
+
<Filter filter={filter} key={filter.property + '-' + idx} />
|
|
40
|
+
))}
|
|
41
|
+
<MobileStickyApplyFilters>
|
|
42
|
+
<Button color="secondary" onClick={() => setIsFilterPanelFocused(false)}>
|
|
43
|
+
Apply filters
|
|
44
|
+
</Button>
|
|
45
|
+
</MobileStickyApplyFilters>
|
|
46
|
+
</CatalogPageSidebar>
|
|
47
|
+
<CatalogPageContent>
|
|
48
|
+
{catalogConfig.title ? <CatalogTitle> {catalogConfig.title} </CatalogTitle> : null}
|
|
49
|
+
{catalogConfig.description ? (
|
|
50
|
+
<CatalogDescription> {catalogConfig.description} </CatalogDescription>
|
|
51
|
+
) : null}
|
|
52
|
+
{groups.map((group) => (
|
|
53
|
+
<React.Fragment key={group.title}>
|
|
54
|
+
<H3>
|
|
55
|
+
{group.title} ({group.items.length})
|
|
56
|
+
</H3>
|
|
57
|
+
<CatalogCards>
|
|
58
|
+
{group.items.map((item) => (
|
|
59
|
+
<CatalogCard item={item} key={item.link} />
|
|
60
|
+
))}
|
|
61
|
+
</CatalogCards>
|
|
62
|
+
</React.Fragment>
|
|
63
|
+
))}
|
|
64
|
+
</CatalogPageContent>
|
|
65
|
+
</CatalogPageWrapper>
|
|
66
|
+
</HighlightContext.Provider>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const MobileStickyApplyFilters = styled.div`
|
|
71
|
+
position: fixed;
|
|
72
|
+
display: none;
|
|
73
|
+
background-color: var(--sidebar-background-color);
|
|
74
|
+
bottom: 0;
|
|
75
|
+
padding: 16px 30px;
|
|
76
|
+
left: 0px;
|
|
77
|
+
right: 0px;
|
|
78
|
+
|
|
79
|
+
${Button} {
|
|
80
|
+
width: 100%;
|
|
81
|
+
margin: 0;
|
|
82
|
+
}
|
|
83
|
+
`;
|
|
84
|
+
|
|
85
|
+
const CatalogPageSidebar = styled.aside<{ isActiveInMobileMode?: boolean }>`
|
|
86
|
+
width: var(--sidebar-width);
|
|
87
|
+
border-right: 1px solid var(--sidebar-border-color);
|
|
88
|
+
padding: 20px 30px;
|
|
89
|
+
position: sticky;
|
|
90
|
+
top: var(--navbar-height);
|
|
91
|
+
height: calc(100vh - var(--navbar-height));
|
|
92
|
+
overflow: auto;
|
|
93
|
+
|
|
94
|
+
@media screen and (max-width: 767px) {
|
|
95
|
+
transition: height 0.2s ease-in-out;
|
|
96
|
+
width: 100%;
|
|
97
|
+
${({ isActiveInMobileMode }) =>
|
|
98
|
+
isActiveInMobileMode ? 'padding-bottom: 66px;' : 'height: 76px;'};
|
|
99
|
+
background-color: var(--sidebar-background-color);
|
|
100
|
+
border-bottom: 1px solid var(--sidebar-border-color);
|
|
101
|
+
z-index: 100;
|
|
102
|
+
|
|
103
|
+
${MobileStickyApplyFilters} {
|
|
104
|
+
display: ${({ isActiveInMobileMode }) => (isActiveInMobileMode ? 'block' : 'none')};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
`;
|
|
108
|
+
|
|
109
|
+
const CatalogPageContent = styled.main`
|
|
110
|
+
flex: 1;
|
|
111
|
+
padding: 32px;
|
|
112
|
+
`;
|
|
113
|
+
|
|
114
|
+
const CatalogCards = styled.div`
|
|
115
|
+
display: grid;
|
|
116
|
+
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
|
|
117
|
+
gap: 32px;
|
|
118
|
+
`;
|
|
119
|
+
|
|
120
|
+
const CatalogTitle = styled(H2)`
|
|
121
|
+
&& {
|
|
122
|
+
margin: 0;
|
|
123
|
+
}
|
|
124
|
+
`;
|
|
125
|
+
|
|
126
|
+
const CatalogDescription = styled.p`
|
|
127
|
+
margin: 16px 0 32px 0;
|
|
128
|
+
font-size: 16px;
|
|
129
|
+
color: var(--text-color-secondary);
|
|
130
|
+
`;
|
|
131
|
+
|
|
132
|
+
const CatalogPageWrapper = styled.div`
|
|
133
|
+
--sidebar-width: var(--catalog-sidebar-width, 300px);
|
|
134
|
+
|
|
135
|
+
display: flex;
|
|
136
|
+
flex-direction: row;
|
|
137
|
+
|
|
138
|
+
font-weight: var(--font-weight-regular);
|
|
139
|
+
padding: 0;
|
|
140
|
+
|
|
141
|
+
color: var(--text-color);
|
|
142
|
+
font-size: var(--font-size-base);
|
|
143
|
+
font-family: var(--font-family-base);
|
|
144
|
+
line-height: var(--line-height-base);
|
|
145
|
+
|
|
146
|
+
hr {
|
|
147
|
+
border: 0;
|
|
148
|
+
width: calc(100% + 48px);
|
|
149
|
+
margin: auto -24px 0 -24px;
|
|
150
|
+
border-top: 1px solid var(--border-color);
|
|
151
|
+
}
|
|
152
|
+
a:not([role='button']) {
|
|
153
|
+
text-decoration: none;
|
|
154
|
+
color: var(--link-text-color);
|
|
155
|
+
font-weight: var(--link-font-weight);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
@media screen and (max-width: 767px) {
|
|
159
|
+
flex-direction: column;
|
|
160
|
+
}
|
|
161
|
+
`;
|
|
162
|
+
|
|
163
|
+
// TODO: merge this input with the input from reference docs
|
|
164
|
+
// the on in ref docs is dark, needs separate variables most likely
|
|
165
|
+
const StyledInput = styled.input`
|
|
166
|
+
border: 1px solid rgba(0, 0, 0, 0.23);
|
|
167
|
+
min-width: 200px;
|
|
168
|
+
outline-color: var(--color-primary-500);
|
|
169
|
+
width: 100%;
|
|
170
|
+
|
|
171
|
+
outline: none;
|
|
172
|
+
padding: var(--input-padding);
|
|
173
|
+
border-radius: var(--input-border-radius);
|
|
174
|
+
background-color: var(--input-background-color);
|
|
175
|
+
color: var(--text-color);
|
|
176
|
+
font-family: var(--input-font-family);
|
|
177
|
+
font-size: var(--input-font-size);
|
|
178
|
+
line-height: var(--input-line-height);
|
|
179
|
+
|
|
180
|
+
&::placeholder {
|
|
181
|
+
opacity: 0.6;
|
|
182
|
+
color: var(--text-color);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
&:hover {
|
|
186
|
+
color: var(--text-color);
|
|
187
|
+
border: 1px solid rgba(0, 0, 0, 0.23);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
&:focus {
|
|
191
|
+
color: var(--text-color);
|
|
192
|
+
border: 1px solid rgba(0, 0, 0, 0.23);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
&:-webkit-autofill {
|
|
196
|
+
background-color: var(--input-background-color);
|
|
197
|
+
}
|
|
198
|
+
`;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
|
|
4
|
+
import type { CatalogItem } from '@theme/types/portal/src/shared/types/catalog';
|
|
5
|
+
import { Link } from '@portal/Link';
|
|
6
|
+
import { Highlight } from '@theme/ui/Highlight';
|
|
7
|
+
import { Tags } from '@theme/Catalog/Tags';
|
|
8
|
+
|
|
9
|
+
export function CatalogCard({ item }: { item: CatalogItem }): JSX.Element {
|
|
10
|
+
return (
|
|
11
|
+
<Link key={item.docsLink || item.link} to={item.docsLink || item.link}>
|
|
12
|
+
<StyledCard>
|
|
13
|
+
<CardTitle>
|
|
14
|
+
<Highlight>{item.title}</Highlight>
|
|
15
|
+
</CardTitle>
|
|
16
|
+
{/* <div>{item.image}</div> */}
|
|
17
|
+
<CardDescription>
|
|
18
|
+
<Highlight>{item.description ?? ''}</Highlight>
|
|
19
|
+
</CardDescription>
|
|
20
|
+
{item.tags ? <Tags tags={item.tags as string[]} /> : null}
|
|
21
|
+
<hr />
|
|
22
|
+
<CardFooter>View documentation</CardFooter>
|
|
23
|
+
</StyledCard>
|
|
24
|
+
</Link>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const StyledCard = styled.div`
|
|
29
|
+
min-height: 268px;
|
|
30
|
+
height: 100%;
|
|
31
|
+
box-shadow: var(--box-shadow);
|
|
32
|
+
|
|
33
|
+
display: flex;
|
|
34
|
+
flex-direction: column;
|
|
35
|
+
|
|
36
|
+
color: var(--text-color);
|
|
37
|
+
background-color: var(--thin-tile-background-color);
|
|
38
|
+
border-radius: 4px;
|
|
39
|
+
|
|
40
|
+
border: 1px solid var(--border-color);
|
|
41
|
+
box-shadow: 0px 0px 10px 0px rgba(35, 35, 35, 0.05);
|
|
42
|
+
transition: all 0.2s ease-in-out;
|
|
43
|
+
|
|
44
|
+
&:hover {
|
|
45
|
+
/* box-shadow: 0px 12px 30px 0px rgba(35, 35, 35, 0.2); */
|
|
46
|
+
box-shadow: 0px 10px 30px 0px rgba(35, 35, 35, 0.1);
|
|
47
|
+
border: 1px solid var(--border-color);
|
|
48
|
+
transform: translateY(-2px);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
border-radius: 8px;
|
|
52
|
+
width: 100%;
|
|
53
|
+
padding: 24px 24px 0;
|
|
54
|
+
display: flex;
|
|
55
|
+
flex-direction: column;
|
|
56
|
+
cursor: pointer;
|
|
57
|
+
`;
|
|
58
|
+
|
|
59
|
+
const CardTitle = styled.h4`
|
|
60
|
+
line-height: 26px;
|
|
61
|
+
letter-spacing: 0.8px;
|
|
62
|
+
font-size: 20px;
|
|
63
|
+
font-weight: var(--font-weight-bold);
|
|
64
|
+
margin: 0;
|
|
65
|
+
margin-bottom: 16px;
|
|
66
|
+
`;
|
|
67
|
+
|
|
68
|
+
const CardDescription = styled.div`
|
|
69
|
+
display: -webkit-box;
|
|
70
|
+
-webkit-line-clamp: 3;
|
|
71
|
+
-webkit-box-orient: vertical;
|
|
72
|
+
overflow: hidden;
|
|
73
|
+
text-overflow: ellipsis;
|
|
74
|
+
line-height: var(--line-height);
|
|
75
|
+
letter-spacing: 0px;
|
|
76
|
+
font-size: 16px;
|
|
77
|
+
color: var(--text-color-secondary);
|
|
78
|
+
text-align: inherit;
|
|
79
|
+
font-weight: 400;
|
|
80
|
+
`;
|
|
81
|
+
|
|
82
|
+
const CardFooter = styled.div`
|
|
83
|
+
height: 46px;
|
|
84
|
+
display: flex;
|
|
85
|
+
align-items: flex-start;
|
|
86
|
+
justify-content: center;
|
|
87
|
+
flex-direction: column;
|
|
88
|
+
font-size: 16px;
|
|
89
|
+
font-weight: var(--font-weight-bold);
|
|
90
|
+
|
|
91
|
+
a:hover & {
|
|
92
|
+
text-decoration: var(--link-hover-text-decoration);
|
|
93
|
+
color: var(--link-hover-text-color);
|
|
94
|
+
}
|
|
95
|
+
`;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
|
|
4
|
+
import type { ResolvedFilter } from '@theme/types/portal/src/shared/types/catalog';
|
|
5
|
+
import { Checkbox } from '@theme/ui/Checkbox';
|
|
6
|
+
|
|
7
|
+
export function Filter({ filter }: { filter: ResolvedFilter }) {
|
|
8
|
+
if (!filter.parentUsed) return null;
|
|
9
|
+
return (
|
|
10
|
+
<FilterGroup key={filter.property + filter.title}>
|
|
11
|
+
<FilterTitle>{filter.title} filter</FilterTitle>
|
|
12
|
+
{filter.type === 'select' ? (
|
|
13
|
+
<StyledSelect
|
|
14
|
+
onChange={(e) => filter.selectOption(e.target.value)}
|
|
15
|
+
value={filter.selectedOptions.values().next()?.value || ''}
|
|
16
|
+
>
|
|
17
|
+
<option key="none" value="">
|
|
18
|
+
All
|
|
19
|
+
</option>
|
|
20
|
+
{filter.filteredOptions.map((value: any) => (
|
|
21
|
+
<option key={value.value} value={value.value}>
|
|
22
|
+
{value.value} ({value.count})
|
|
23
|
+
</option>
|
|
24
|
+
))}
|
|
25
|
+
</StyledSelect>
|
|
26
|
+
) : (
|
|
27
|
+
filter.filteredOptions.map((value: any) => {
|
|
28
|
+
const id = 'filter--' + filter.property + '--' + slug(value.value);
|
|
29
|
+
return (
|
|
30
|
+
<FilterValue key={id}>
|
|
31
|
+
<Checkbox
|
|
32
|
+
type="checkbox"
|
|
33
|
+
id={id}
|
|
34
|
+
checked={filter.selectedOptions.has(value.value)}
|
|
35
|
+
onChange={() => filter.toggleOption(value.value)}
|
|
36
|
+
/>
|
|
37
|
+
<label htmlFor={id}>
|
|
38
|
+
{value.value} ({value.count})
|
|
39
|
+
</label>
|
|
40
|
+
</FilterValue>
|
|
41
|
+
);
|
|
42
|
+
})
|
|
43
|
+
)}
|
|
44
|
+
</FilterGroup>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const FilterGroup = styled.div`
|
|
49
|
+
padding: 16px 0;
|
|
50
|
+
border-bottom: 1px solid var(--border-color);
|
|
51
|
+
|
|
52
|
+
&:last-of-type {
|
|
53
|
+
border-bottom: none;
|
|
54
|
+
}
|
|
55
|
+
`;
|
|
56
|
+
|
|
57
|
+
const FilterTitle = styled.h4`
|
|
58
|
+
font-size: 18px;
|
|
59
|
+
font-weight: var(--font-weight-bold);
|
|
60
|
+
margin: 0;
|
|
61
|
+
margin-bottom: 16px;
|
|
62
|
+
`;
|
|
63
|
+
|
|
64
|
+
const FilterValue = styled.label`
|
|
65
|
+
display: block;
|
|
66
|
+
cursor: pointer;
|
|
67
|
+
font-size: 16px;
|
|
68
|
+
margin: 8px 0;
|
|
69
|
+
|
|
70
|
+
input {
|
|
71
|
+
cursor: pointer;
|
|
72
|
+
}
|
|
73
|
+
`;
|
|
74
|
+
|
|
75
|
+
const StyledSelect = styled.select`
|
|
76
|
+
border: 1px solid rgba(0, 0, 0, 0.23);
|
|
77
|
+
|
|
78
|
+
padding: var(--input-padding);
|
|
79
|
+
border-radius: var(--input-border-radius);
|
|
80
|
+
background-color: var(--input-background-color);
|
|
81
|
+
color: var(--text-color);
|
|
82
|
+
font-family: var(--input-font-family);
|
|
83
|
+
font-size: var(--input-font-size);
|
|
84
|
+
line-height: var(--input-line-height);
|
|
85
|
+
|
|
86
|
+
min-width: 200px;
|
|
87
|
+
outline-color: var(--color-primary-500);
|
|
88
|
+
transition: outline 0.25s ease;
|
|
89
|
+
display: inline-block;
|
|
90
|
+
text-align: left;
|
|
91
|
+
appearance: none;
|
|
92
|
+
|
|
93
|
+
background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
|
|
94
|
+
background-repeat: no-repeat;
|
|
95
|
+
background-position: right 10px center;
|
|
96
|
+
background-size: 1em;
|
|
97
|
+
width: 100%;
|
|
98
|
+
`;
|
|
99
|
+
|
|
100
|
+
// TODO: import from portal
|
|
101
|
+
function slug(str: string): string {
|
|
102
|
+
return str.replace(/\s/g, '-').toLowerCase();
|
|
103
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
|
|
4
|
+
import { Highlight } from '@theme/ui/Highlight';
|
|
5
|
+
|
|
6
|
+
export function Tags({ tags }: { tags: string[] }) {
|
|
7
|
+
return (
|
|
8
|
+
<TagsWrapper>
|
|
9
|
+
{tags.map((tag) => (
|
|
10
|
+
<Tag key={tag} className={'tag-' + slug(tag)}>
|
|
11
|
+
<Highlight>{tag}</Highlight>
|
|
12
|
+
</Tag>
|
|
13
|
+
))}
|
|
14
|
+
</TagsWrapper>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const TagsWrapper = styled.div`
|
|
19
|
+
margin-top: 16px;
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
const Tag = styled.div`
|
|
23
|
+
display: inline-block;
|
|
24
|
+
background-color: #d3f4ef;
|
|
25
|
+
color: #000;
|
|
26
|
+
padding: 2px 5px;
|
|
27
|
+
border-radius: var(--border-radius);
|
|
28
|
+
margin-right: 5px;
|
|
29
|
+
margin-bottom: 5px;
|
|
30
|
+
font-size: 0.8em;
|
|
31
|
+
`;
|
|
32
|
+
|
|
33
|
+
// TODO: import from portal
|
|
34
|
+
function slug(str: string): string {
|
|
35
|
+
return str.replace(/\s/g, '-').toLowerCase();
|
|
36
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
|
|
4
|
+
import { Comment } from '@theme/Feedback/Comment';
|
|
5
|
+
import type { ReportDialogProps } from '@theme/Feedback';
|
|
6
|
+
import { useSubmitFeedback } from '@portal/Feedback/useSubmitFeedback';
|
|
7
|
+
|
|
8
|
+
export const ReportDialog = ({
|
|
9
|
+
location,
|
|
10
|
+
settings,
|
|
11
|
+
onSubmit,
|
|
12
|
+
onCancel,
|
|
13
|
+
}: ReportDialogProps): JSX.Element => {
|
|
14
|
+
const { label } = settings;
|
|
15
|
+
const { submitFeedback } = useSubmitFeedback();
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<Wrapper className="modal">
|
|
19
|
+
<Comment
|
|
20
|
+
settings={{ label, onCancel }}
|
|
21
|
+
onSubmit={(value) => {
|
|
22
|
+
submitFeedback('problem', { ...value, location });
|
|
23
|
+
onSubmit();
|
|
24
|
+
}}
|
|
25
|
+
/>
|
|
26
|
+
</Wrapper>
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const Wrapper = styled.div`
|
|
31
|
+
font-family: var(--font-family-base);
|
|
32
|
+
position: fixed;
|
|
33
|
+
top: 0;
|
|
34
|
+
left: 0;
|
|
35
|
+
width: 100vw;
|
|
36
|
+
height: 100vh;
|
|
37
|
+
background: var(--modal-overlay-background-color);
|
|
38
|
+
z-index: 10000;
|
|
39
|
+
display: flex;
|
|
40
|
+
align-items: center;
|
|
41
|
+
justify-content: center;
|
|
42
|
+
|
|
43
|
+
& > * {
|
|
44
|
+
background: var(--modal-background-color);
|
|
45
|
+
box-shadow: var(--modal-box-shadow);
|
|
46
|
+
padding: 15px;
|
|
47
|
+
margin: 15px;
|
|
48
|
+
max-width: 500px;
|
|
49
|
+
max-height: 300px;
|
|
50
|
+
}
|
|
51
|
+
`;
|
package/src/Feedback/index.ts
CHANGED
|
@@ -2,4 +2,6 @@ export { Rating } from '@theme/Feedback/Rating';
|
|
|
2
2
|
export { Sentiment } from '@theme/Feedback/Sentiment';
|
|
3
3
|
export { Comment } from '@theme/Feedback/Comment';
|
|
4
4
|
export { Reasons } from '@theme/Feedback/Reasons';
|
|
5
|
+
export { ReportDialog } from '@theme/Feedback/ReportDialog';
|
|
6
|
+
export { useReportDialog } from '@theme/Feedback/useReportDialog';
|
|
5
7
|
export * from './types';
|
package/src/Feedback/types.ts
CHANGED
|
@@ -56,9 +56,11 @@ export type ReasonsProps = {
|
|
|
56
56
|
};
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
export type
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
export type ReportDialogProps = {
|
|
60
|
+
location: string;
|
|
61
|
+
onSubmit: () => void;
|
|
62
|
+
onCancel: () => void;
|
|
63
|
+
settings: {
|
|
62
64
|
label?: string;
|
|
63
65
|
};
|
|
64
66
|
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { ReportDialogProps } from '@theme/Feedback/types';
|
|
4
|
+
|
|
5
|
+
type ReportSettings = {
|
|
6
|
+
hide?: boolean;
|
|
7
|
+
label?: string;
|
|
8
|
+
tooltipText?: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function useReportDialog(reportSettings: ReportSettings): Record<string, any> {
|
|
12
|
+
const [isReportDialogShown, setIsReportDialogShown] = useState(false);
|
|
13
|
+
const isReportButtonShown = reportSettings.hide === false; // TODO: report temporary disabled by default
|
|
14
|
+
|
|
15
|
+
const showReportDialog = () => {
|
|
16
|
+
setIsReportDialogShown(true);
|
|
17
|
+
};
|
|
18
|
+
const hideReportDialog = () => {
|
|
19
|
+
setIsReportDialogShown(false);
|
|
20
|
+
};
|
|
21
|
+
const reportButtonProps = {
|
|
22
|
+
onClick: showReportDialog,
|
|
23
|
+
title: reportSettings.tooltipText || 'Report a problem',
|
|
24
|
+
};
|
|
25
|
+
const reportDialogProps: Partial<ReportDialogProps> = {
|
|
26
|
+
settings: {
|
|
27
|
+
label: reportSettings.label || 'What is wrong with a code?',
|
|
28
|
+
},
|
|
29
|
+
onSubmit: hideReportDialog,
|
|
30
|
+
onCancel: hideReportDialog,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return { isReportDialogShown, isReportButtonShown, reportButtonProps, reportDialogProps };
|
|
34
|
+
}
|
|
@@ -3,9 +3,7 @@ import styled, { css } from 'styled-components';
|
|
|
3
3
|
|
|
4
4
|
import { ClipboardService } from '@theme/utils/ClipboardService';
|
|
5
5
|
import { useThemeConfig } from '@theme/hooks/useThemeConfig';
|
|
6
|
-
import {
|
|
7
|
-
import { useSubmitFeedback } from '@portal/Feedback/useSubmitFeedback';
|
|
8
|
-
import { useReportDialog } from '@theme/hooks/useReportDialog';
|
|
6
|
+
import { ReportDialog, useReportDialog } from '@theme/Feedback';
|
|
9
7
|
|
|
10
8
|
export type CodeSampleProps = {
|
|
11
9
|
language: string;
|
|
@@ -15,16 +13,16 @@ export type CodeSampleProps = {
|
|
|
15
13
|
|
|
16
14
|
export function CodeSample({ rawContent, highlighted, language }: CodeSampleProps): JSX.Element {
|
|
17
15
|
const langClassName = language ? `language-${language}` : '';
|
|
18
|
-
const { codeSnippet: { copy = {}, report = {
|
|
19
|
-
const { submitFeedback } = useSubmitFeedback();
|
|
16
|
+
const { codeSnippet: { copy = {}, report = {} } = {} } = useThemeConfig();
|
|
20
17
|
|
|
21
18
|
const [isCopied, setIsCopied] = useState(false);
|
|
22
|
-
const
|
|
19
|
+
const { isReportDialogShown, isReportButtonShown, reportButtonProps, reportDialogProps } =
|
|
20
|
+
useReportDialog(report);
|
|
23
21
|
|
|
24
22
|
const copyCode = (code: string) => {
|
|
25
23
|
ClipboardService.copyCustom(code);
|
|
26
24
|
setIsCopied(true);
|
|
27
|
-
setTimeout(() => setIsCopied(false), copy.toasterDuration ||
|
|
25
|
+
setTimeout(() => setIsCopied(false), copy.toasterDuration || 1500);
|
|
28
26
|
};
|
|
29
27
|
|
|
30
28
|
return (
|
|
@@ -44,28 +42,9 @@ export function CodeSample({ rawContent, highlighted, language }: CodeSampleProp
|
|
|
44
42
|
</>
|
|
45
43
|
)}
|
|
46
44
|
|
|
47
|
-
{
|
|
48
|
-
<Button onClick={() => showDialog()} title={report.tooltipText || 'Report a problem'}>
|
|
49
|
-
Report
|
|
50
|
-
</Button>
|
|
51
|
-
)}
|
|
45
|
+
{isReportButtonShown && <Button {...reportButtonProps}>Report</Button>}
|
|
52
46
|
|
|
53
|
-
{
|
|
54
|
-
<ReportDialog id="modal">
|
|
55
|
-
<Comment
|
|
56
|
-
settings={{
|
|
57
|
-
label: report.label || 'What is wrong with a code?',
|
|
58
|
-
onCancel: () => {
|
|
59
|
-
hideDialog();
|
|
60
|
-
},
|
|
61
|
-
}}
|
|
62
|
-
onSubmit={(value) => {
|
|
63
|
-
submitFeedback('problem', { ...value, location: rawContent });
|
|
64
|
-
hideDialog();
|
|
65
|
-
}}
|
|
66
|
-
/>
|
|
67
|
-
</ReportDialog>
|
|
68
|
-
)}
|
|
47
|
+
{isReportDialogShown && <ReportDialog {...reportDialogProps} location={rawContent} />}
|
|
69
48
|
</CodeSampleButtonContainer>
|
|
70
49
|
<pre className={langClassName}>
|
|
71
50
|
<code className={langClassName} dangerouslySetInnerHTML={{ __html: highlighted }} />
|
|
@@ -242,25 +221,3 @@ const Wrapper = styled.div`
|
|
|
242
221
|
${darkStyleTokens};
|
|
243
222
|
}
|
|
244
223
|
`;
|
|
245
|
-
|
|
246
|
-
const ReportDialog = styled.div`
|
|
247
|
-
position: fixed;
|
|
248
|
-
top: 0;
|
|
249
|
-
left: 0;
|
|
250
|
-
width: 100vw;
|
|
251
|
-
height: 100vh;
|
|
252
|
-
background: var(--modal-overlay-background-color);
|
|
253
|
-
z-index: 10000;
|
|
254
|
-
display: flex;
|
|
255
|
-
align-items: center;
|
|
256
|
-
justify-content: center;
|
|
257
|
-
|
|
258
|
-
& > * {
|
|
259
|
-
background: var(--modal-background-color);
|
|
260
|
-
box-shadow: var(--modal-box-shadow);
|
|
261
|
-
padding: 15px;
|
|
262
|
-
margin: 15px;
|
|
263
|
-
max-width: 500px;
|
|
264
|
-
max-height: 300px;
|
|
265
|
-
}
|
|
266
|
-
`;
|
|
@@ -7,7 +7,7 @@ const Arrow = ({ className }: { className?: string }): JSX.Element => (
|
|
|
7
7
|
fill="none"
|
|
8
8
|
xmlns="http://www.w3.org/2000/svg"
|
|
9
9
|
viewBox="0 0 12 10"
|
|
10
|
-
width="
|
|
10
|
+
width="10px"
|
|
11
11
|
height="10px"
|
|
12
12
|
className={className}
|
|
13
13
|
>
|
|
@@ -19,7 +19,7 @@ const Arrow = ({ className }: { className?: string }): JSX.Element => (
|
|
|
19
19
|
|
|
20
20
|
export const ArrowBack = styled(Arrow)`
|
|
21
21
|
fill: var(--sidebar-back-button-icon-color);
|
|
22
|
-
margin-right: calc(var(--sidebar-spacing-unit)
|
|
22
|
+
margin-right: calc(var(--sidebar-spacing-unit));
|
|
23
23
|
|
|
24
24
|
background-image: var(--sidebar-back-button-icon);
|
|
25
25
|
background-repeat: no-repeat;
|
|
@@ -62,7 +62,7 @@ const MenuWrapper = styled.div<{ isExpanded?: boolean }>`
|
|
|
62
62
|
overflow: hidden;
|
|
63
63
|
${(props) =>
|
|
64
64
|
props.isExpanded
|
|
65
|
-
? `max-height:
|
|
65
|
+
? `max-height: 99999px;
|
|
66
66
|
transition: max-height .8s cubic-bezier(0.5, 0, 1, 0) 0s;`
|
|
67
67
|
: `max-height: 0px;
|
|
68
68
|
transition: max-height .8s cubic-bezier(0, 1, 0, 1) -.1s;`};
|
package/src/Sidebar/Sidebar.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import styled from 'styled-components';
|
|
2
2
|
|
|
3
3
|
interface SidebarProps {
|
|
4
|
+
isNavbar: boolean;
|
|
4
5
|
opened?: boolean;
|
|
5
6
|
animate?: boolean;
|
|
6
7
|
}
|
|
@@ -18,13 +19,16 @@ export const Sidebar = styled.aside.attrs(() => ({
|
|
|
18
19
|
font-size: var(--sidebar-item-font-size);
|
|
19
20
|
font-family: var(--sidebar-item-font-family);
|
|
20
21
|
color: var(--sidebar-item-text-color);
|
|
21
|
-
top: var(--navbar-height);
|
|
22
|
-
height: calc(100vh - var(--navbar-height));
|
|
23
22
|
display: flex;
|
|
24
23
|
flex-direction: column;
|
|
25
24
|
width: 100%;
|
|
26
25
|
-webkit-font-smoothing: antialiased;
|
|
27
26
|
|
|
27
|
+
${({ isNavbar }) => `
|
|
28
|
+
top: ${isNavbar ? 'var(--navbar-height)' : '0'};
|
|
29
|
+
height: calc(100vh ${isNavbar ? '- var(--navbar-height)' : ''});
|
|
30
|
+
`};
|
|
31
|
+
|
|
28
32
|
${({ opened, animate }) => `
|
|
29
33
|
opacity: ${opened ? '1' : '0'};
|
|
30
34
|
pointer-events: ${opened ? 'auto' : 'none'};
|