@redocly/theme 0.1.27 → 0.1.30

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 (132) hide show
  1. package/Button/Button.js +3 -3
  2. package/CodeBlock/CodeBlock.js +1 -1
  3. package/CopyButton/CopyButton.js +17 -1
  4. package/CopyButton/CopyButtonWrapper.js +1 -1
  5. package/Footer/Footer.js +2 -1
  6. package/Footer/FooterColumn.js +1 -1
  7. package/Footer/FooterColumns.d.ts +2 -2
  8. package/Footer/FooterColumns.js +1 -1
  9. package/JsonViewer/JsonViewer.d.ts +2 -0
  10. package/JsonViewer/JsonViewer.js +53 -22
  11. package/Markdown/Admonition.js +1 -1
  12. package/Markdown/CodeSample/CodeSample.js +17 -1
  13. package/Markdown/Heading.js +1 -1
  14. package/Markdown/Mermaid.js +1 -1
  15. package/Markdown/Sup.d.ts +2 -0
  16. package/Markdown/Sup.js +19 -0
  17. package/Markdown/Tabs/Tabs.js +17 -1
  18. package/Markdown/index.d.ts +4 -3
  19. package/Markdown/index.js +4 -3
  20. package/Navbar/MobileNavbarDropdown.d.ts +8 -0
  21. package/Navbar/MobileNavbarDropdown.js +21 -0
  22. package/Navbar/MobileNavbarItem.d.ts +15 -0
  23. package/Navbar/MobileNavbarItem.js +102 -0
  24. package/Navbar/MobileNavbarMenu.d.ts +6 -0
  25. package/Navbar/MobileNavbarMenu.js +32 -0
  26. package/Navbar/MobileNavbarMenuButton.d.ts +4 -0
  27. package/Navbar/MobileNavbarMenuButton.js +19 -0
  28. package/Navbar/Navbar.js +26 -4
  29. package/Navbar/NavbarDropdown.js +1 -1
  30. package/Navbar/NavbarItem.d.ts +9 -3
  31. package/Navbar/NavbarItem.js +9 -9
  32. package/Navbar/NavbarMenu.js +3 -2
  33. package/PageNavigation/NextPageLink.js +4 -4
  34. package/PageNavigation/PreviousPageLink.js +4 -4
  35. package/Panel/PanelComponent.js +18 -2
  36. package/Profile/Profile.d.ts +8 -0
  37. package/Profile/Profile.js +60 -0
  38. package/Profile/index.d.ts +2 -0
  39. package/Profile/index.js +5 -0
  40. package/Search/Autocomplete.js +18 -2
  41. package/Search/utils.js +17 -1
  42. package/Sidebar/SidebarLayout.js +17 -1
  43. package/SourceCode/SourceCode.d.ts +10 -3
  44. package/SourceCode/SourceCode.js +10 -5
  45. package/TableOfContent/TableOfContent.js +13 -5
  46. package/Tooltip/Tooltip.d.ts +5 -4
  47. package/Tooltip/Tooltip.js +43 -21
  48. package/globalStyle.js +2 -2
  49. package/hooks/__tests__/mocks/MockIntersectionObserver.d.ts +15 -0
  50. package/hooks/__tests__/mocks/MockIntersectionObserver.js +39 -0
  51. package/hooks/useActiveHeading.d.ts +1 -1
  52. package/hooks/useActiveHeading.js +86 -21
  53. package/hooks/useActiveSectionId.js +17 -1
  54. package/hooks/useControl.js +17 -1
  55. package/hooks/useMobileMenu.js +17 -1
  56. package/hooks/useNavbarHeight.js +17 -1
  57. package/index.d.ts +1 -0
  58. package/index.js +1 -0
  59. package/package.json +1 -1
  60. package/src/Button/Button.tsx +5 -1
  61. package/src/CodeBlock/CodeBlock.ts +12 -0
  62. package/src/CopyButton/CopyButtonWrapper.tsx +1 -1
  63. package/src/Footer/Footer.tsx +4 -3
  64. package/src/Footer/FooterColumn.tsx +3 -1
  65. package/src/Footer/FooterColumns.tsx +3 -3
  66. package/src/JsonViewer/JsonViewer.tsx +55 -40
  67. package/src/Markdown/Admonition.tsx +1 -1
  68. package/src/Markdown/Heading.tsx +1 -1
  69. package/src/Markdown/Mermaid.tsx +1 -1
  70. package/src/Markdown/Sup.tsx +8 -0
  71. package/src/Markdown/index.ts +4 -3
  72. package/src/Navbar/MobileNavbarDropdown.tsx +37 -0
  73. package/src/Navbar/MobileNavbarItem.tsx +116 -0
  74. package/src/Navbar/MobileNavbarMenu.tsx +106 -0
  75. package/src/Navbar/MobileNavbarMenuButton.tsx +13 -0
  76. package/src/Navbar/Navbar.tsx +11 -3
  77. package/src/Navbar/NavbarDropdown.tsx +1 -1
  78. package/src/Navbar/NavbarItem.tsx +9 -8
  79. package/src/Navbar/NavbarMenu.tsx +9 -4
  80. package/src/PageNavigation/NextPageLink.tsx +3 -3
  81. package/src/PageNavigation/PreviousPageLink.tsx +3 -3
  82. package/src/Profile/Profile.tsx +91 -0
  83. package/src/Profile/index.ts +2 -0
  84. package/src/SourceCode/SourceCode.tsx +32 -5
  85. package/src/TableOfContent/TableOfContent.tsx +14 -4
  86. package/src/Tooltip/Tooltip.tsx +87 -63
  87. package/src/globalStyle.ts +2 -0
  88. package/src/hooks/useActiveHeading.ts +92 -28
  89. package/src/index.ts +1 -0
  90. package/src/types/portal/src/client/app/Sidebar/types.d.ts +2 -1
  91. package/src/types/portal/src/server/constants.d.ts +2 -0
  92. package/src/types/portal/src/server/dev-server/types.d.ts +22 -0
  93. package/src/types/portal/src/server/plugins/markdown/types.d.ts +15 -5
  94. package/src/types/portal/src/server/plugins/portal-config/get-frontmatter-keys-to-resolve.d.ts +2 -0
  95. package/src/types/portal/src/server/plugins/portal-config/types.d.ts +6 -2
  96. package/src/types/portal/src/server/plugins/reference-docs/utils.d.ts +26 -0
  97. package/src/types/portal/src/server/plugins/types.d.ts +29 -12
  98. package/src/types/portal/src/server/store.d.ts +16 -16
  99. package/src/types/portal/src/server/utils/fs.d.ts +2 -1
  100. package/src/types/portal/src/server/utils/index.d.ts +1 -0
  101. package/src/types/portal/src/server/utils/paths.d.ts +4 -0
  102. package/src/types/portal/src/server/utils/rbac.d.ts +15 -0
  103. package/src/types/portal/src/shared/constants.d.ts +7 -0
  104. package/src/types/portal/src/shared/models/config.d.ts +24 -12
  105. package/src/types/portal/src/shared/types.d.ts +17 -4
  106. package/src/types/portal/src/shared/urls.d.ts +1 -1
  107. package/src/types/portal/src/shared/utils.d.ts +2 -0
  108. package/src/ui/Burger.tsx +36 -0
  109. package/src/ui/Flex.tsx +1 -0
  110. package/src/utils/args-typecheck.ts +9 -0
  111. package/src/utils/color.ts +9 -0
  112. package/src/utils/highlight.ts +11 -0
  113. package/src/utils/index.ts +2 -0
  114. package/src/utils/jsonToHtml.ts +171 -59
  115. package/src/utils/theme-helpers.ts +3 -1
  116. package/ui/Burger.d.ts +8 -0
  117. package/ui/Burger.js +23 -0
  118. package/ui/Dropdown.js +17 -1
  119. package/ui/Flex.js +1 -1
  120. package/ui/UniversalLink.js +17 -1
  121. package/utils/args-typecheck.d.ts +2 -0
  122. package/utils/args-typecheck.js +13 -0
  123. package/utils/color.d.ts +2 -0
  124. package/utils/color.js +12 -0
  125. package/utils/highlight.d.ts +1 -0
  126. package/utils/highlight.js +12 -1
  127. package/utils/index.d.ts +2 -0
  128. package/utils/index.js +2 -0
  129. package/utils/jsonToHtml.d.ts +4 -1
  130. package/utils/jsonToHtml.js +287 -83
  131. package/utils/media-css.js +40 -3
  132. package/utils/theme-helpers.js +59 -10
@@ -3,9 +3,10 @@ import styled from 'styled-components';
3
3
 
4
4
  import { FooterColumns } from '@theme/Footer/FooterColumns';
5
5
  import { FooterCopyright } from '@theme/Footer/FooterCopyright';
6
- import type { NavGroupRecord } from '@theme/types/portal';
6
+ import type { NavGroupRecord, ResolvedNavItem } from '@theme/types/portal';
7
7
  import { useThemeSettings } from '@portal/hooks';
8
8
  import { DEFAULT_THEME_NAME } from '@portal/constants';
9
+ import { isEmptyArray } from '@theme/utils';
9
10
 
10
11
  interface FooterProps {
11
12
  data: NavGroupRecord;
@@ -14,13 +15,13 @@ interface FooterProps {
14
15
  export function Footer({ data: { columns, copyrightText } }: FooterProps): JSX.Element | null {
15
16
  const { footer } = useThemeSettings(DEFAULT_THEME_NAME);
16
17
 
17
- if (!(columns?.length || copyrightText) || footer?.hide) {
18
+ if (isEmptyArray(columns) || !copyrightText || footer?.hide) {
18
19
  return null;
19
20
  }
20
21
 
21
22
  return (
22
23
  <FooterContainer data-component-name="Footer/Footer">
23
- <FooterColumns columns={columns} />
24
+ <FooterColumns columns={columns as ResolvedNavItem[]} />
24
25
  <FooterCopyright copyrightText={copyrightText} />
25
26
  </FooterContainer>
26
27
  );
@@ -51,7 +51,9 @@ const FooterColumnContainer = styled.div`
51
51
  display: flex;
52
52
  flex-direction: column;
53
53
  text-align: left;
54
- margin: 0 30px;
54
+ margin: 0 20px;
55
+ width: 20%;
56
+ word-break: break-word;
55
57
  `;
56
58
 
57
59
  const FooterLink = styled(Link)`
@@ -2,14 +2,14 @@ import React from 'react';
2
2
  import styled from 'styled-components';
3
3
 
4
4
  import { FooterColumn } from '@theme/Footer/FooterColumn';
5
- import type { NavGroup } from '@theme/types/portal';
5
+ import type { ResolvedNavItem } from '@theme/types/portal';
6
6
 
7
7
  interface FooterColumnsProps {
8
- columns: NavGroup;
8
+ columns: ResolvedNavItem[];
9
9
  }
10
10
 
11
11
  export function FooterColumns({ columns }: FooterColumnsProps): JSX.Element | null {
12
- if (typeof columns === 'string' || typeof columns === 'undefined' || !columns?.length) {
12
+ if (!columns?.length) {
13
13
  return null;
14
14
  }
15
15
 
@@ -11,9 +11,17 @@ export interface JsonProps {
11
11
  data: any;
12
12
  className?: string;
13
13
  jsonSampleExpandLevel: number;
14
+ withLineNumbers?: boolean;
15
+ startLineNumber?: number;
14
16
  }
15
17
 
16
- function JsonComponent({ data, jsonSampleExpandLevel, className }: JsonProps): JSX.Element {
18
+ function JsonComponent({
19
+ data,
20
+ jsonSampleExpandLevel,
21
+ className,
22
+ withLineNumbers,
23
+ startLineNumber,
24
+ }: JsonProps): JSX.Element {
17
25
  const node = useRef<HTMLDivElement | null>(null);
18
26
 
19
27
  useMount(() => {
@@ -84,10 +92,10 @@ function JsonComponent({ data, jsonSampleExpandLevel, className }: JsonProps): J
84
92
  )}
85
93
  </SampleControls>
86
94
  <StyledCodeBlock
87
- className={className}
95
+ className={withLineNumbers ? `${className} line-numbers` : className}
88
96
  ref={node}
89
97
  dangerouslySetInnerHTML={{
90
- __html: jsonToHTML(data, jsonSampleExpandLevel),
98
+ __html: jsonToHTML(data, jsonSampleExpandLevel, startLineNumber),
91
99
  }}
92
100
  />
93
101
  </JsonViewerWrap>
@@ -111,15 +119,11 @@ export const JsonViewer = styled(Json).attrs(() => ({
111
119
  color: var(--color-content-inverse);
112
120
  padding: inherit;
113
121
  border: none;
114
-
115
- & > .collapser {
116
- display: none;
117
- pointer-events: none;
118
- }
119
122
  }
120
123
 
121
124
  contain: content;
122
125
  overflow-x: auto;
126
+ position: relative;
123
127
  padding: 10px;
124
128
  border-radius: var(--global-border-radius);
125
129
  background-color: var(--samples-panel-controls-background-color);
@@ -128,13 +132,26 @@ export const JsonViewer = styled(Json).attrs(() => ({
128
132
  font-family: var(--code-font-family);
129
133
  white-space: var(--code-wrap, pre);
130
134
 
131
- .callback-function {
132
- color: gray;
135
+ &.line-numbers {
136
+ padding: 20px 20px 20px 3em;
137
+
138
+ *[data-line]:not(.collapsed *[data-line]) {
139
+ &:before {
140
+ content: attr(data-line);
141
+ position: absolute;
142
+ left: 0;
143
+ min-width: 2em;
144
+ text-align: right;
145
+ pointer-events: none;
146
+ user-select: none;
147
+ padding: 0 0.5em;
148
+ font-size: 13px;
149
+ }
150
+ }
133
151
  }
134
152
 
135
- .collapser:after {
136
- content: '-';
137
- cursor: pointer;
153
+ .callback-function {
154
+ color: gray;
138
155
  }
139
156
 
140
157
  .collapsed > .collapser:after {
@@ -147,11 +164,17 @@ export const JsonViewer = styled(Json).attrs(() => ({
147
164
  }
148
165
 
149
166
  .collapsible {
150
- margin-left: 2ch;
167
+ padding-left: 2ch;
168
+ display: inline-block;
151
169
  }
152
170
 
153
171
  .hoverable {
154
172
  padding: 1px 2px;
173
+ display: inline-block;
174
+ }
175
+
176
+ .collapsed {
177
+ display: inline-flex;
155
178
  }
156
179
 
157
180
  .hovered {
@@ -161,39 +184,31 @@ export const JsonViewer = styled(Json).attrs(() => ({
161
184
  .collapser {
162
185
  background-color: transparent;
163
186
  border: 0;
187
+ padding: 0;
164
188
  color: #fff;
165
- display: flex;
166
- align-items: center;
167
- justify-content: center;
168
- width: 15px;
189
+ width: 0;
169
190
  height: 15px;
170
- position: absolute;
171
- top: 4px;
172
- left: -1.5em;
173
191
  cursor: default;
174
192
  user-select: none;
175
193
  -webkit-user-select: none;
176
- padding: 2px;
177
194
  font-family: var(--code-font-family);
178
195
  font-size: var(--code-font-size);
179
- &:focus {
180
- outline: #fff dotted 1px;
181
- }
182
- }
183
-
184
- ul {
185
- list-style-type: none;
186
- padding: 0;
187
- margin: 0 0 0 26px;
188
- }
189
196
 
190
- li {
191
- position: relative;
192
- display: block;
193
- }
194
-
195
- .hoverable {
196
- display: inline-block;
197
+ &:after {
198
+ content: '-';
199
+ cursor: pointer;
200
+ display: flex;
201
+ align-items: center;
202
+ justify-content: center;
203
+ width: 15px;
204
+ height: 100%;
205
+ padding: 2px 5px 2px 2px;
206
+ transform: translateX(-100%);
207
+
208
+ &:focus {
209
+ outline: #fff dotted 1px;
210
+ }
211
+ }
197
212
  }
198
213
 
199
214
  .selected {
@@ -210,7 +225,7 @@ export const JsonViewer = styled(Json).attrs(() => ({
210
225
  }
211
226
 
212
227
  .collapsed > .ellipsis {
213
- display: inherit;
228
+ display: inline;
214
229
  }
215
230
  `;
216
231
 
@@ -17,7 +17,7 @@ export function Admonition({
17
17
  children,
18
18
  }: React.PropsWithChildren<AdmonitionProps>): JSX.Element {
19
19
  return (
20
- <Wrapper type={type} data-component-name="Markdown/Admonition/Admonition">
20
+ <Wrapper type={type} data-component-name="Markdown/Admonition">
21
21
  <AlertIcon type={type} />
22
22
  {name ? <Heading type={type}>{name}</Heading> : null}
23
23
  <Content>{children}</Content>
@@ -39,7 +39,7 @@ export function Heading({
39
39
  {
40
40
  id,
41
41
  className: concatClassNames('heading-anchor', mdClassName),
42
- 'data-component-name': 'Markdown/Heading/Heading',
42
+ 'data-component-name': 'Markdown/Heading',
43
43
  },
44
44
  <>
45
45
  {linkEl}
@@ -10,7 +10,7 @@ export function Mermaid({ diagramHtml }: MermaidProps): JSX.Element {
10
10
  <Wrapper
11
11
  className="mermaid-wrapper"
12
12
  dangerouslySetInnerHTML={{ __html: diagramHtml }}
13
- data-component-name="Markdown/Mermaid/Mermaid"
13
+ data-component-name="Markdown/Mermaid"
14
14
  />
15
15
  );
16
16
  }
@@ -0,0 +1,8 @@
1
+ import React, { PropsWithChildren } from 'react';
2
+ import styled from 'styled-components';
3
+
4
+ export function Sup({ children }: PropsWithChildren<unknown>): JSX.Element {
5
+ return <Wrapper data-component-name="Markdown/Sup">{children}</Wrapper>;
6
+ }
7
+
8
+ const Wrapper = styled.sup``;
@@ -1,9 +1,10 @@
1
- export * from '@theme/Markdown/CodeSample';
2
- export * from '@theme/Markdown/Tabs';
3
1
  export * from '@theme/Markdown/Admonition';
2
+ export * from '@theme/Markdown/CodeSample';
4
3
  export * from '@theme/Markdown/ContentWrapper';
5
4
  export * from '@theme/Markdown/Heading';
6
5
  export * from '@theme/Markdown/MarkdownLayout';
6
+ export * from '@theme/Markdown/MarkdownWrapper';
7
7
  export * from '@theme/Markdown/Mermaid';
8
8
  export * from '@theme/Markdown/PageWrapper';
9
- export * from '@theme/Markdown/MarkdownWrapper';
9
+ export * from '@theme/Markdown/Sup';
10
+ export * from '@theme/Markdown/Tabs';
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+
4
+ import type { ResolvedNavLinkItem } from '@theme/types/portal';
5
+ import { Link } from '@portal/Link';
6
+
7
+ interface NavbarDropdownProps {
8
+ items: ResolvedNavLinkItem[];
9
+ }
10
+
11
+ export function MobileNavbarDropdown({ items }: NavbarDropdownProps): JSX.Element {
12
+ return (
13
+ <MobileDropdownWrapper data-component-name="Navbar/MobileNavbarDropdown">
14
+ {items.map((item, index) => (
15
+ <div key={`${item.label}_${index}`}>
16
+ <Link to={item.link}>{item.label}</Link>
17
+ </div>
18
+ ))}
19
+ </MobileDropdownWrapper>
20
+ );
21
+ }
22
+
23
+ export const MobileDropdownWrapper = styled.div`
24
+ padding: 0 15px;
25
+ width: max-content;
26
+ transition: all 0.2s ease-in-out;
27
+ overflow: hidden;
28
+ box-shadow: var(--navbar-dropdown-shadow);
29
+ & > div {
30
+ padding: 10px 0;
31
+ cursor: pointer;
32
+ a {
33
+ color: var(--navbar-text-color);
34
+ text-decoration: none;
35
+ }
36
+ }
37
+ `;
@@ -0,0 +1,116 @@
1
+ import React, { useState } from 'react';
2
+ import styled from 'styled-components';
3
+ import { useLocation } from 'react-router-dom';
4
+
5
+ import type {
6
+ ResolvedNavItem,
7
+ ResolvedNavLinkItem,
8
+ ResolvedNavGroupItem,
9
+ } from '@theme/types/portal';
10
+ import { Link } from '@portal/Link';
11
+ import { withPathPrefix } from '@portal/utils';
12
+ import { MobileDropdownWrapper, MobileNavbarDropdown } from '@theme/Navbar/MobileNavbarDropdown';
13
+
14
+ export interface NavbarItemProps {
15
+ navItem: ResolvedNavItem;
16
+ className?: string;
17
+ }
18
+
19
+ export function MobileNavbarItem({ navItem, className }: NavbarItemProps): JSX.Element | null {
20
+ const { pathname } = useLocation();
21
+ const [expandedDropdown, setExpandedDropdown] = useState(false);
22
+ const toggleDropdown = () => setExpandedDropdown(!expandedDropdown);
23
+
24
+ if ((navItem as ResolvedNavLinkItem).link) {
25
+ const item = navItem as ResolvedNavLinkItem;
26
+ const isActive = pathname === withPathPrefix(item.link);
27
+ return (
28
+ <NavMenuItem
29
+ active={isActive}
30
+ data-component-name="Navbar/MobileNavbarItem"
31
+ className={className}
32
+ >
33
+ <NavLink to={item.link} active={isActive}>
34
+ <NavLabel>{item.label}</NavLabel>
35
+ </NavLink>
36
+ </NavMenuItem>
37
+ );
38
+ }
39
+
40
+ if ((navItem as ResolvedNavGroupItem).items) {
41
+ const item = navItem as ResolvedNavGroupItem;
42
+ return (
43
+ <NavMenuItemWithDropdownWrapper expanded={expandedDropdown}>
44
+ <NavMenuItem
45
+ active={false}
46
+ onClick={toggleDropdown}
47
+ data-component-name="Navbar/MobileNavbarItem"
48
+ className={className}
49
+ >
50
+ <NavLabel>{item.label}</NavLabel>
51
+ <ExpandedArrow />
52
+ </NavMenuItem>
53
+ <MobileNavbarDropdown items={item.items as ResolvedNavLinkItem[]} />
54
+ </NavMenuItemWithDropdownWrapper>
55
+ );
56
+ }
57
+
58
+ return null;
59
+ }
60
+
61
+ const ExpandedArrow = styled.div`
62
+ width: 5px;
63
+ height: 5px;
64
+ border: 1px solid;
65
+ border-left: none;
66
+ border-top: none;
67
+ transition: all 0.3s ease-out;
68
+ `;
69
+
70
+ export const NavMenuItem = styled.li<{ active?: boolean }>`
71
+ display: flex;
72
+ justify-content: space-between;
73
+ align-items: center;
74
+ padding: calc(var(--sidebar-spacing-horizontal) * 2);
75
+ text-align: left;
76
+ line-height: 1;
77
+ font-size: var(--navbar-item-font-size);
78
+ margin-left: var(--navbar-item-margin-horizontal);
79
+ margin-right: var(--navbar-item-margin-horizontal);
80
+ font-weight: var(--navbar-item-font-weight);
81
+ background: ${({ active }) => (active ? 'var(--navbar-item-active-background-color)' : 'none')};
82
+ &:not(:last-child) {
83
+ border-bottom: 1px solid var(--navbar-item-separator-line-color, #dadada);
84
+ }
85
+ `;
86
+
87
+ export const NavMenuItemWithDropdownWrapper = styled.div<{ expanded: boolean }>`
88
+ display: inline-block;
89
+ position: relative;
90
+ border-bottom: 1px solid var(--navbar-item-separator-line-color, #dadada);
91
+
92
+ ${ExpandedArrow} {
93
+ transform: rotate(${({ expanded }) => (expanded ? '' : '-')}45deg);
94
+ }
95
+
96
+ ${MobileDropdownWrapper} {
97
+ height: ${({ expanded }) => (expanded ? '100%' : '0')};
98
+ opacity: ${({ expanded }) => (expanded ? '1' : '0')};
99
+ }
100
+
101
+ ${NavMenuItem} {
102
+ border-bottom: none;
103
+ }
104
+ `;
105
+
106
+ export const NavLink = styled(Link)`
107
+ color: ${({ active }) =>
108
+ active ? 'var(--navbar-item-active-text-color)' : 'var(--navbar-text-color)'};
109
+ text-decoration: ${({ active }) =>
110
+ active ? 'var(--navbar-item-active-text-decoration)' : 'none'};
111
+ `;
112
+
113
+ const NavLabel = styled.span`
114
+ cursor: pointer;
115
+ vertical-align: middle;
116
+ `;
@@ -0,0 +1,106 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+
4
+ import { NavMenuItem, NavMenuItemWithDropdownWrapper } from '@theme/Navbar/NavbarItem';
5
+ import { MobileNavbarItem } from '@theme/Navbar/MobileNavbarItem';
6
+ import { DropdownWrapper } from '@theme/Navbar/NavbarDropdown';
7
+ import type { ResolvedConfigLinks, ResolvedNavItem } from '@theme/types/portal';
8
+ import { isPrimitive, isEmptyArray } from '@theme/utils';
9
+
10
+ export function MobileNavbarMenu({
11
+ menuItems,
12
+ closeMenu,
13
+ }: {
14
+ menuItems: ResolvedConfigLinks;
15
+ closeMenu: () => void;
16
+ }): JSX.Element | null {
17
+ if (isPrimitive(menuItems) || isEmptyArray(menuItems)) {
18
+ return null;
19
+ }
20
+
21
+ return (
22
+ <NavItemsWrapper data-component-name="Navbar/MobileNavbarMenu">
23
+ <NavItemsContainer>
24
+ {(menuItems as ResolvedNavItem[]).map((navItem, index) => {
25
+ return (
26
+ <MobileNavbarItem
27
+ key={`${navItem.label}_${index}`}
28
+ data-cy={navItem.label}
29
+ navItem={navItem}
30
+ />
31
+ );
32
+ })}
33
+ </NavItemsContainer>
34
+ <NavItemsClosableArea onClick={closeMenu} />
35
+ </NavItemsWrapper>
36
+ );
37
+ }
38
+
39
+ const NavItemsWrapper = styled.div`
40
+ height: 100%;
41
+ width: 100%;
42
+ position: fixed;
43
+ z-index: 201; //more than Search
44
+ left: 0;
45
+ top: 0;
46
+ overflow-x: hidden;
47
+ transition: 0.5s;
48
+ display: flex;
49
+ ${DropdownWrapper} {
50
+ & > div {
51
+ text-align: center;
52
+ padding: 10px 0;
53
+ cursor: pointer;
54
+ a {
55
+ color: var(--navbar-text-color);
56
+ text-decoration: none;
57
+ }
58
+ :hover {
59
+ text-decoration: underline;
60
+ }
61
+ }
62
+ }
63
+ `;
64
+
65
+ const NavItemsClosableArea = styled.div`
66
+ display: flex;
67
+ flex: 1;
68
+ min-width: 50px;
69
+ height: 100%;
70
+ background-color: rgba(255, 255, 255, 0.4);
71
+ `;
72
+
73
+ const NavItemsContainer = styled.ul`
74
+ width: 70%;
75
+ list-style: none;
76
+ margin: 0;
77
+ padding: 0;
78
+ display: flex;
79
+ flex-direction: column;
80
+ background: var(--navbar-background-color);
81
+
82
+ ${NavMenuItem} {
83
+ &:not(:last-child){
84
+ border-bottom: 1px solid var(--navbar-item-separator-line-color, #dadada);
85
+ }
86
+ border-radius: 0;
87
+ padding: 1em 0;
88
+ width: 100%;
89
+ }
90
+
91
+ ${NavMenuItemWithDropdownWrapper} {
92
+ display: block;
93
+ &:not(:last-child){
94
+ border-bottom: 1px solid var(--navbar-item-separator-line-color, #dadada);
95
+ border-radius: 0;
96
+ }
97
+ ${NavMenuItem} {
98
+ border-bottom: none;
99
+ }
100
+ ${DropdownWrapper} {
101
+ background-color: var(--navbar-background-color);
102
+ width: 100%;
103
+ padding: 0;
104
+ position: relative;
105
+ }
106
+ `;
@@ -0,0 +1,13 @@
1
+ import styled from 'styled-components';
2
+
3
+ import { Burger } from '@theme/ui/Burger';
4
+
5
+ export const MobileNavbarMenuButton = styled(Burger).attrs(() => ({
6
+ 'data-component-name': 'Navbar/MobileNavbarMenuButton',
7
+ }))`
8
+ display: block;
9
+
10
+ ${({ theme }) => theme.mediaQueries.medium} {
11
+ display: none;
12
+ }
13
+ `;
@@ -5,6 +5,9 @@ import { useThemeSettings } from '@portal/hooks';
5
5
  import { DEFAULT_THEME_NAME } from '@portal/constants';
6
6
  import { ResolvedConfigLinks } from '@theme/types/portal';
7
7
  import { NavbarMenu } from '@theme/Navbar';
8
+ import { useMobileMenu } from '@theme/hooks/useMobileMenu';
9
+ import { MobileNavbarMenuButton } from '@theme/Navbar/MobileNavbarMenuButton';
10
+ import { MobileNavbarMenu } from '@theme/Navbar/MobileNavbarMenu';
8
11
 
9
12
  interface NavbarProps {
10
13
  menu: ResolvedConfigLinks;
@@ -13,17 +16,22 @@ interface NavbarProps {
13
16
  }
14
17
 
15
18
  export function Navbar({ menu, logo, search }: NavbarProps): JSX.Element | null {
16
- const settings = useThemeSettings(DEFAULT_THEME_NAME);
17
- const searchSettings = settings.search;
19
+ const [isOpen, setIsOpen] = useMobileMenu(false);
20
+ const { search: searchSettings, navbar } = useThemeSettings(DEFAULT_THEME_NAME);
18
21
  const hideSearch =
19
22
  searchSettings?.hide || (searchSettings?.placement && searchSettings?.placement !== 'navbar');
20
23
 
21
- if (settings?.navbar?.hide) {
24
+ if (navbar?.hide) {
22
25
  return null;
23
26
  }
24
27
 
28
+ const openMobileMenu = () => setIsOpen(true);
29
+ const closeMobileMenu = () => setIsOpen(false);
30
+
25
31
  return (
26
32
  <NavbarContainer data-component-name="Navbar/Navbar">
33
+ <MobileNavbarMenuButton onClick={openMobileMenu} />
34
+ {isOpen && <MobileNavbarMenu closeMenu={closeMobileMenu} menuItems={menu} />}
27
35
  {logo}
28
36
  <NavbarMenu menuItems={menu} />
29
37
  {hideSearch ? null : search}
@@ -31,7 +31,7 @@ export const DropdownWrapper = styled.div`
31
31
  box-shadow: var(--navbar-dropdown-shadow);
32
32
  & > div {
33
33
  text-align: left;
34
- padding: 10px 0px;
34
+ padding: 10px 0;
35
35
  cursor: pointer;
36
36
  a {
37
37
  color: var(--navbar-text-color);
@@ -11,18 +11,19 @@ import { Link } from '@portal/Link';
11
11
  import { withPathPrefix } from '@portal/utils';
12
12
  import { NavbarDropdown, DropdownWrapper } from '@theme/Navbar/NavbarDropdown';
13
13
 
14
- interface NavbarItemProps {
14
+ export interface NavbarItemProps {
15
15
  navItem: ResolvedNavItem;
16
+ className?: string;
16
17
  }
17
18
 
18
- export function NavbarItem({ navItem }: NavbarItemProps): JSX.Element | null {
19
+ export function NavbarItem({ navItem, className }: NavbarItemProps): JSX.Element | null {
19
20
  const { pathname } = useLocation();
20
21
 
21
22
  if ((navItem as ResolvedNavLinkItem).link) {
22
23
  const item = navItem as ResolvedNavLinkItem;
23
24
  const isActive = pathname === withPathPrefix(item.link);
24
25
  return (
25
- <NavMenuItem active={isActive} data-component-name="Navbar/NavbarItem">
26
+ <NavMenuItem active={isActive} data-component-name="Navbar/NavbarItem" className={className}>
26
27
  <NavLink to={item.link} active={isActive}>
27
28
  <NavLabel>{item.label}</NavLabel>
28
29
  </NavLink>
@@ -34,7 +35,7 @@ export function NavbarItem({ navItem }: NavbarItemProps): JSX.Element | null {
34
35
  const item = navItem as ResolvedNavGroupItem;
35
36
  return (
36
37
  <NavMenuItemWithDropdownWrapper>
37
- <NavMenuItem active={false} data-component-name="Navbar/NavbarItem">
38
+ <NavMenuItem active={false} data-component-name="Navbar/NavbarItem" className={className}>
38
39
  <NavLabel>{item.label}</NavLabel>
39
40
  </NavMenuItem>
40
41
  <NavbarDropdown items={item.items as ResolvedNavLinkItem[]} />
@@ -45,7 +46,7 @@ export function NavbarItem({ navItem }: NavbarItemProps): JSX.Element | null {
45
46
  return null;
46
47
  }
47
48
 
48
- const NavMenuItemWithDropdownWrapper = styled.div`
49
+ export const NavMenuItemWithDropdownWrapper = styled.div`
49
50
  display: inline-block;
50
51
  position: relative;
51
52
  border-radius: var(--navbar-item-border-radius);
@@ -57,9 +58,9 @@ const NavMenuItemWithDropdownWrapper = styled.div`
57
58
  }
58
59
  `;
59
60
 
60
- const NavMenuItem = styled.li<{ active?: boolean }>`
61
+ export const NavMenuItem = styled.li<{ active?: boolean }>`
61
62
  display: inline-block;
62
- padding: 20px calc(var(--sidebar-spacing-horizontal) * 2);
63
+ padding: 8px calc(var(--sidebar-spacing-horizontal) * 2);
63
64
  text-align: center;
64
65
  line-height: 1;
65
66
  font-size: var(--navbar-item-font-size);
@@ -70,7 +71,7 @@ const NavMenuItem = styled.li<{ active?: boolean }>`
70
71
  background: ${({ active }) => (active ? 'var(--navbar-item-active-background-color)' : 'none')};
71
72
  `;
72
73
 
73
- const NavLink = styled(Link)`
74
+ export const NavLink = styled(Link)`
74
75
  color: ${({ active }) =>
75
76
  active ? 'var(--navbar-item-active-text-color)' : 'var(--navbar-text-color)'};
76
77
  text-decoration: ${({ active }) =>