@redocly/theme 0.7.3 → 0.7.5

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.
Files changed (51) hide show
  1. package/lib/Catalog/Catalog.d.ts +8 -0
  2. package/lib/Catalog/Catalog.js +167 -0
  3. package/lib/Catalog/CatalogCard.d.ts +5 -0
  4. package/lib/Catalog/CatalogCard.js +113 -0
  5. package/lib/Catalog/Filter.d.ts +5 -0
  6. package/lib/Catalog/Filter.js +88 -0
  7. package/lib/Catalog/Tags.d.ts +4 -0
  8. package/lib/Catalog/Tags.js +32 -0
  9. package/lib/Feedback/ReportDialog.d.ts +3 -0
  10. package/lib/Feedback/ReportDialog.js +66 -0
  11. package/lib/Feedback/index.d.ts +2 -0
  12. package/lib/Feedback/index.js +5 -1
  13. package/lib/Feedback/types.d.ts +5 -3
  14. package/lib/Feedback/useReportDialog.d.ts +7 -0
  15. package/lib/Feedback/useReportDialog.js +28 -0
  16. package/lib/Markdown/CodeSample/CodeSample.js +8 -41
  17. package/lib/Sidebar/ArrowBack.js +2 -2
  18. package/lib/Sidebar/SidebarLayout.d.ts +5 -1
  19. package/lib/Sidebar/SidebarLayout.js +26 -1
  20. package/lib/config.d.ts +90 -82
  21. package/lib/config.js +24 -18
  22. package/lib/globalStyle.js +12 -10
  23. package/lib/mocks/hooks/index.d.ts +4 -0
  24. package/lib/mocks/hooks/index.js +16 -6
  25. package/lib/ui/Checkbox.d.ts +1 -0
  26. package/lib/ui/Checkbox.js +70 -0
  27. package/lib/ui/Highlight.d.ts +5 -0
  28. package/lib/ui/Highlight.js +63 -0
  29. package/lib/ui/darkColors.js +4 -2
  30. package/package.json +4 -2
  31. package/src/Catalog/Catalog.tsx +198 -0
  32. package/src/Catalog/CatalogCard.tsx +95 -0
  33. package/src/Catalog/Filter.tsx +103 -0
  34. package/src/Catalog/Tags.tsx +36 -0
  35. package/src/Feedback/ReportDialog.tsx +51 -0
  36. package/src/Feedback/index.ts +2 -0
  37. package/src/Feedback/types.ts +5 -3
  38. package/src/Feedback/useReportDialog.ts +34 -0
  39. package/src/Markdown/CodeSample/CodeSample.tsx +11 -57
  40. package/src/Sidebar/ArrowBack.tsx +2 -2
  41. package/src/Sidebar/SidebarLayout.tsx +38 -1
  42. package/src/config.ts +24 -18
  43. package/src/globalStyle.ts +12 -10
  44. package/src/mocks/hooks/index.ts +17 -6
  45. package/src/types/portal/src/shared/types/catalog.d.ts +55 -0
  46. package/src/ui/Checkbox.tsx +64 -0
  47. package/src/ui/Highlight.tsx +48 -0
  48. package/src/ui/darkColors.tsx +4 -2
  49. package/lib/hooks/useReportDialog.d.ts +0 -1
  50. package/lib/hooks/useReportDialog.js +0 -16
  51. package/src/hooks/useReportDialog.ts +0 -14
@@ -7,13 +7,23 @@ import { MobileSidebarButton } from '@theme/Sidebar/MobileSidebarButton';
7
7
  import { MenuContainer } from '@theme/Sidebar/MenuContainer';
8
8
  import { SidebarSearch } from '@theme/Search/SidebarSearch';
9
9
  import { useThemeConfig } from '@theme/hooks/useThemeConfig';
10
+ import { ArrowBack } from '@theme/Sidebar/ArrowBack';
11
+ import { Link } from '@portal/Link';
10
12
 
11
13
  interface SidebarLayoutProps {
12
14
  versions: React.ReactNode;
13
15
  menu: React.ReactNode;
16
+ backLink?: {
17
+ label: string;
18
+ slug: string;
19
+ };
14
20
  }
15
21
 
16
- export function SidebarLayout({ versions, menu }: SidebarLayoutProps): JSX.Element | null {
22
+ export function SidebarLayout({
23
+ versions,
24
+ menu,
25
+ backLink,
26
+ }: SidebarLayoutProps): JSX.Element | null {
17
27
  const [isOpen, setIsOpen] = useMobileMenu();
18
28
  const toggleMenu = () => setIsOpen(!isOpen);
19
29
  const { search, sidebar } = useThemeConfig();
@@ -28,6 +38,15 @@ export function SidebarLayout({ versions, menu }: SidebarLayoutProps): JSX.Eleme
28
38
 
29
39
  {!search?.hide && search?.placement === 'sidebar' ? <SidebarSearch /> : null}
30
40
  <Sidebar animate={true} opened={isOpen}>
41
+ {(backLink && (
42
+ <BackLinkWrapper>
43
+ <Link to={backLink.slug}>
44
+ <ArrowBack />
45
+ Back to {backLink.label}
46
+ </Link>
47
+ </BackLinkWrapper>
48
+ )) ||
49
+ null}
31
50
  {versions}
32
51
  <MenuContainer>{menu}</MenuContainer>
33
52
  </Sidebar>
@@ -35,4 +54,22 @@ export function SidebarLayout({ versions, menu }: SidebarLayoutProps): JSX.Eleme
35
54
  );
36
55
  }
37
56
 
57
+ const BackLinkWrapper = styled.div`
58
+ padding: var(--sidebar-offset-top) var(--sidebar-item-padding-horizontal)
59
+ var(--sidebar-item-padding-horizontal)
60
+ calc(var(--sidebar-offset-left) + var(--sidebar-item-padding-horizontal));
61
+
62
+ a {
63
+ color: var(--sidebar-back-button-text-color);
64
+ font-size: var(--sidebar-back-button-font-size);
65
+ font-family: var(--sidebar-back-button-font-family);
66
+ text-decoration: none;
67
+ &:hover {
68
+ color: var(--sidebar-back-button-hover-text-color);
69
+ }
70
+ }
71
+
72
+ border-bottom: 1px solid var(--sidebar-border-color);
73
+ `;
74
+
38
75
  const Wrapper = styled.div``;
package/src/config.ts CHANGED
@@ -126,6 +126,30 @@ export const ThemeConfig = z
126
126
  .strict()
127
127
  .optional()
128
128
  .default({}),
129
+ codeSnippet: z
130
+ .object({
131
+ copy: z
132
+ .object({
133
+ buttonText: z.string().default('Copy').optional(),
134
+ tooltipText: z.string().default('Copy to clipboard').optional(),
135
+ toasterText: z.string().default('Copied!').optional(),
136
+ toasterDuration: z.number().default(1500).optional(),
137
+ })
138
+ .extend(HideConfig.shape)
139
+ .optional()
140
+ .default({}),
141
+ report: z
142
+ .object({
143
+ tooltipText: z.string().default('Report a problem').optional(),
144
+ label: z.string().optional(),
145
+ })
146
+ .extend(HideConfig.shape)
147
+ .optional()
148
+ .default({ hide: true }),
149
+ })
150
+ .strict()
151
+ .default({})
152
+ .optional(),
129
153
  markdown: z
130
154
  .object({
131
155
  frontMatterKeysToResolve: z.array(z.string()).default(['image', 'links']).optional(),
@@ -154,24 +178,6 @@ export const ThemeConfig = z
154
178
  .extend(HideConfig.shape)
155
179
  .default({})
156
180
  .optional(),
157
- copyCodeSnippet: z
158
- .object({
159
- buttonText: z.string().default('Copy').optional(),
160
- tooltipText: z.string().default('Copy to clipboard').optional(),
161
- toasterText: z.string().default('Copied').optional(),
162
- toasterDuration: z.number().default(1500).optional(),
163
- })
164
- .extend(HideConfig.shape)
165
- .optional()
166
- .default({}),
167
- reportCodeSnippet: z
168
- .object({
169
- tooltipText: z.string().default('Report a problem').optional(),
170
- label: z.string().optional(),
171
- })
172
- .extend(HideConfig.shape)
173
- .optional()
174
- .default({ hide: true }), // TODO: temporary disabled
175
181
  })
176
182
  .strict()
177
183
  .default({})
@@ -517,7 +517,7 @@ const sidebar = css`
517
517
  --sidebar-back-button-font-family: var(--sidebar-item-font-family);
518
518
  --sidebar-back-button-font-size: var(--sidebar-item-font-size);
519
519
  --sidebar-back-button-transform: inherit;
520
- --sidebar-back-button-text-color: var(--sidebar-item-text-color);
520
+ --sidebar-back-button-text-color: var(--link-text-color);
521
521
  --sidebar-back-button-background-color: transparent;
522
522
  --sidebar-back-button-hover-text-color: var(--sidebar-item-active-color);
523
523
  --sidebar-back-button-hover-background-color: transparent;
@@ -1706,7 +1706,7 @@ const inputs = css`
1706
1706
  --input-border: none; // @presenter Border
1707
1707
  --input-border-radius: var(--border-radius); // @presenter BorderRadius
1708
1708
  --input-font-size: var(--font-size-base); // @presenter FontSize
1709
- --input-font-family: var(--code-font-family); // @presenter FontFamily
1709
+ --input-font-family: var(--font-family-base); // @presenter FontFamily
1710
1710
  --input-line-height: 1.15em; // @presenter LineHeight
1711
1711
  --input-padding: 8px;
1712
1712
 
@@ -1716,6 +1716,8 @@ const inputs = css`
1716
1716
  --input-focus-text-color: var(--text-color-inverse); // @presenter Color
1717
1717
  --input-placeholder-text-color: var(--text-color-inverse); // @presenter Color
1718
1718
 
1719
+ --checkbox-backround-color: var(--background-color);
1720
+ --checkbox-checked-backround-color: var(--color-primary-500);
1719
1721
  // @tokens End
1720
1722
  `;
1721
1723
 
@@ -1925,7 +1927,7 @@ const pages = css`
1925
1927
 
1926
1928
  --page-404-font-family: var(--font-family-base); // @presenter FontFamily
1927
1929
 
1928
- --page-404-header-text-color: #000;
1930
+ --page-404-header-text-color: #000;
1929
1931
  --page-404-header-font-size: 14em; // @presenter FontSize
1930
1932
  --page-404-header-font-weight: 600; // @presenter FontWeight
1931
1933
  --page-404-header-line-height: 1.2; // @presenter LineHeight
@@ -1945,31 +1947,31 @@ const pages = css`
1945
1947
  * @tokens 403 Page
1946
1948
  * @presenter Color
1947
1949
  */
1948
-
1950
+
1949
1951
  --page-403-font-family: var(--font-family-base); // @presenter FontFamily
1950
-
1952
+
1951
1953
  --page-403-header-text-color: #000;
1952
1954
  --page-403-header-font-size: 14em; // @presenter FontSize
1953
1955
  --page-403-header-font-weight: 600; // @presenter FontWeight
1954
1956
  --page-403-header-line-height: 1.2; // @presenter LineHeight
1955
1957
  --page-403-header-margin: 0; // @presenter Spacing
1956
-
1958
+
1957
1959
  --page-403-description-text-color: #000;
1958
1960
  --page-403-description-font-size: 2em; // @presenter FontSize
1959
1961
  --page-403-description-font-weight: 400; // @presenter FontWeight
1960
1962
  --page-403-description-line-height: 1; // @presenter LineHeight
1961
1963
  --page-403-description-margin: 0; // @presenter Spacing
1962
-
1964
+
1963
1965
  --page-403-button-margin: 4em; // @presenter Spacing
1964
-
1966
+
1965
1967
  // @tokens End
1966
1968
  `
1967
1969
 
1968
1970
  const modal = css`
1969
- body:has([id='modal']) {
1971
+ body:has(.modal) {
1970
1972
  overflow: hidden;
1971
1973
  }
1972
-
1974
+
1973
1975
  --modal-box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.6);
1974
1976
  --modal-overlay-background-color: rgba(206, 206, 206, 0.49);
1975
1977
  --modal-background-color: var(--background-color);
@@ -1,5 +1,6 @@
1
1
  import type { ThemeUIConfig } from '@theme/config';
2
-
2
+ import type { ResolvedNavItem } from '@theme/types/portal';
3
+ import type { CatalogConfig, FilteredCatalog } from '@theme/types/portal/src/shared/types/catalog';
3
4
  interface PageLink {
4
5
  label: string;
5
6
  link: string;
@@ -13,20 +14,22 @@ export function useThemeConfig<T extends Record<string, unknown>>(): T & ThemeUI
13
14
  placement: 'navbar',
14
15
  shortcuts: ['ctrl+f', 'cmd+k', '/'],
15
16
  },
16
- markdown: {
17
- toc: { depth: 3, header: 'Table of contents', hide: false },
18
- lastUpdatedBlock: { hide: false, format: 'timeago', locale: 'en-US' },
19
- copyCodeSnippet: {
17
+ codeSnippet: {
18
+ copy: {
20
19
  hide: false,
21
20
  buttonText: 'Copy',
22
21
  tooltipText: 'Copy to clipboard',
23
22
  toasterText: 'Copied',
24
23
  toasterDuration: 1500,
25
24
  },
26
- reportCodeSnippet: {
25
+ report: {
27
26
  hide: false,
28
27
  tooltipText: 'Report a problem',
29
28
  },
29
+ },
30
+ markdown: {
31
+ toc: { depth: 3, header: 'Table of contents', hide: false },
32
+ lastUpdatedBlock: { hide: false, format: 'timeago', locale: 'en-US' },
30
33
  editPage: {
31
34
  baseUrl: '',
32
35
  text: 'Edit this page',
@@ -63,3 +66,11 @@ export function useSidebarSiblingsData(): { nextPage: PageLink | null; prevPage:
63
66
  },
64
67
  };
65
68
  }
69
+
70
+ export function usePageSharedData<T = unknown>(_id: string): T {
71
+ throw new Error('Mock not implemented yet.');
72
+ }
73
+
74
+ export function useCatalog(_items: ResolvedNavItem[], _config: CatalogConfig): FilteredCatalog {
75
+ throw new Error('Mock not implemented yet.');
76
+ }
@@ -0,0 +1,55 @@
1
+ import type { NavItem } from './nav';
2
+
3
+ export type FilteredCatalog = {
4
+ groups: { title: string; items: CatalogItem[] }[];
5
+ filters: ResolvedFilter[];
6
+ filterTerm: string;
7
+ setFilterTerm: (term: string) => void;
8
+ };
9
+
10
+ export type Filter = {
11
+ type?: 'select' | 'checkboxes';
12
+ title: string;
13
+ property: string;
14
+ parentFilter?: string;
15
+ missingCategoryName?: string;
16
+ options?: string[];
17
+ };
18
+
19
+ export type CatalogConfig = {
20
+ slug: string;
21
+ filters: Filter[];
22
+ groupByFirstFilter: boolean;
23
+ items: NavItem[];
24
+ requiredPermission?: string;
25
+ separateVersions?: boolean;
26
+ title?: string;
27
+ description?: string;
28
+ };
29
+
30
+ export type CatalogThemeConfig = {
31
+ catalog: Record<string, CatalogConfig>;
32
+ };
33
+
34
+ export type ResolvedFilter = Omit<Filter, 'options'> & {
35
+ options: {
36
+ value: string;
37
+ count: number;
38
+ }[];
39
+ filteredOptions: {
40
+ value: string;
41
+ count: number;
42
+ }[];
43
+ toggleOption: (option: string) => void;
44
+ selectOption: (option: string) => void;
45
+ parentUsed: boolean;
46
+ selectedOptions: Set<string>;
47
+ };
48
+
49
+ export type CatalogItem = {
50
+ title: string;
51
+ link: string;
52
+ description?: string;
53
+ image?: string;
54
+ [k: string]: unknown;
55
+ };
@@ -0,0 +1,64 @@
1
+ import styled from 'styled-components';
2
+
3
+ export const Checkbox = styled.input`
4
+ position: absolute;
5
+ opacity: 0;
6
+
7
+ & + label {
8
+ position: relative;
9
+ cursor: pointer;
10
+ padding: 0;
11
+ display: flex;
12
+
13
+ div {
14
+ margin-top: 1px;
15
+ }
16
+ p {
17
+ line-height: 1.2;
18
+ }
19
+
20
+ &::before {
21
+ content: '';
22
+ margin-right: 10px;
23
+ display: inline-block;
24
+ vertical-align: top;
25
+ width: 18px;
26
+ height: 18px;
27
+ background: var(--checkbox-backround-color);
28
+ border: 1px solid rgba(0, 0, 0, 0.23);
29
+ border-radius: 2px;
30
+ flex-shrink: 0;
31
+ }
32
+ }
33
+
34
+ &:focus + label:before {
35
+ box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12);
36
+ }
37
+
38
+ &:checked + label {
39
+ &::before {
40
+ background: var(--checkbox-checked-backround-color);
41
+ }
42
+ &::after {
43
+ content: '';
44
+ position: absolute;
45
+ left: 5px;
46
+ top: 10px;
47
+ background: var(--checkbox-backround-color);
48
+ width: 2px;
49
+ height: 2px;
50
+ box-shadow: 2px 0 0 white, 4px 0 0 white, 4px -2px 0 white, 4px -4px 0 white, 4px -6px 0 white,
51
+ 4px -8px 0 white;
52
+ transform: rotate(45deg);
53
+ }
54
+ }
55
+
56
+ &:disabled + label {
57
+ color: #b8b8b8;
58
+ cursor: auto;
59
+ &::before {
60
+ box-shadow: none;
61
+ background: #ddd;
62
+ }
63
+ }
64
+ `;
@@ -0,0 +1,48 @@
1
+ import * as React from 'react';
2
+ import { findAll } from 'highlight-words-core';
3
+
4
+ export const HighlightContext = React.createContext<string[]>([]);
5
+
6
+ export function Highlight(props: { children: React.ReactChildren | string }): JSX.Element {
7
+ const { children } = props;
8
+ const searchWords = React.useContext(HighlightContext);
9
+
10
+ if (!searchWords.length) {
11
+ return <>children</> || null;
12
+ }
13
+
14
+ function highlight(str: string, childIdx: number = 0) {
15
+ const chunks = findAll({
16
+ searchWords,
17
+ textToHighlight: str,
18
+ });
19
+
20
+ return (
21
+ <React.Fragment key={childIdx}>
22
+ {chunks.map((chunk, idx) => {
23
+ const { end, highlight, start } = chunk;
24
+ const text = str.substr(start, end - start);
25
+ if (highlight) {
26
+ return <mark key={idx}>{text}</mark>;
27
+ } else {
28
+ return text;
29
+ }
30
+ })}
31
+ </React.Fragment>
32
+ );
33
+ }
34
+
35
+ if (typeof children === 'string') {
36
+ return highlight(children);
37
+ } else if (Array.isArray(children)) {
38
+ return (
39
+ <>
40
+ {children.map((child, idx) =>
41
+ typeof children === 'string' ? highlight(child, idx) : child || null,
42
+ )}
43
+ </>
44
+ );
45
+ } else {
46
+ return <>children</> || null;
47
+ }
48
+ }
@@ -60,12 +60,14 @@ export const darkMode = css`
60
60
  --tooltip-text-color: #fff;
61
61
  --md-table-head-background-color: var(--color-secondary-300);
62
62
  --md-tabs-hover-tab-border-color: var(--color-secondary-500);
63
- --wide-tile-background-color: #000000;
64
- --thin-tile-background-color: #000000;
63
+ --thin-tile-background-color: #1d242d;
64
+ --wide-tile-background-color: #1d242d;
65
65
  --page-404-header-text-color: #fff;
66
66
  --page-404-description-text-color: #fff;
67
67
  --page-403-header-text-color: #fff;
68
68
  --page-403-description-text-color: #fff;
69
+ --checkbox-backround-color: var(--color-secondary-900);
70
+ --checkbox-checked-backround-color: var(--color-primary-400);
69
71
 
70
72
  background-color: var(--background-color);
71
73
  color: var(--text-color);
@@ -1 +0,0 @@
1
- export declare function useReportDialog(initialState?: boolean): [boolean, () => void, () => void];
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useReportDialog = void 0;
4
- const react_1 = require("react");
5
- function useReportDialog(initialState = false) {
6
- const [isDialogShown, setIsShown] = (0, react_1.useState)(initialState);
7
- const showDialog = () => {
8
- setIsShown(true);
9
- };
10
- const hideDialog = () => {
11
- setIsShown(false);
12
- };
13
- return [isDialogShown, showDialog, hideDialog];
14
- }
15
- exports.useReportDialog = useReportDialog;
16
- //# sourceMappingURL=useReportDialog.js.map
@@ -1,14 +0,0 @@
1
- import { useState } from 'react';
2
-
3
- export function useReportDialog(initialState = false): [boolean, () => void, () => void] {
4
- const [isDialogShown, setIsShown] = useState(initialState);
5
-
6
- const showDialog = () => {
7
- setIsShown(true);
8
- };
9
- const hideDialog = () => {
10
- setIsShown(false);
11
- };
12
-
13
- return [isDialogShown, showDialog, hideDialog];
14
- }