@redocly/theme 0.1.1 → 0.1.4

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 (203) hide show
  1. package/Button/Button.d.ts +17 -0
  2. package/Button/Button.js +34 -0
  3. package/Button/index.d.ts +1 -0
  4. package/Button/index.js +1 -0
  5. package/CodeBlock/CodeBlock.d.ts +1 -0
  6. package/CodeBlock/CodeBlock.js +7 -0
  7. package/CodeBlock/index.d.ts +1 -0
  8. package/CodeBlock/index.js +1 -0
  9. package/CopyButton/CopyButton.d.ts +6 -0
  10. package/CopyButton/CopyButton.js +69 -0
  11. package/CopyButton/CopyButtonWrapper.d.ts +9 -0
  12. package/CopyButton/CopyButtonWrapper.js +37 -0
  13. package/CopyButton/index.d.ts +2 -0
  14. package/CopyButton/index.js +2 -0
  15. package/Headings/Headings.d.ts +3 -0
  16. package/Headings/Headings.js +10 -0
  17. package/Headings/index.d.ts +1 -0
  18. package/Headings/index.js +1 -0
  19. package/JsonViewer/JsonViewer.d.ts +10 -0
  20. package/JsonViewer/JsonViewer.js +92 -0
  21. package/JsonViewer/index.d.ts +1 -0
  22. package/JsonViewer/index.js +1 -0
  23. package/JsonViewer/styled.d.ts +1 -0
  24. package/JsonViewer/styled.js +7 -0
  25. package/Logo/Logo.d.ts +10 -0
  26. package/Logo/Logo.js +25 -0
  27. package/Navbar/Navbar.d.ts +9 -0
  28. package/Navbar/Navbar.js +23 -0
  29. package/Navbar/NavbarItem.d.ts +40 -0
  30. package/Navbar/NavbarItem.js +43 -0
  31. package/Navbar/NavbarMenu.d.ts +4 -0
  32. package/Navbar/NavbarMenu.js +29 -0
  33. package/Panel/CodePanel.d.ts +1 -0
  34. package/Panel/CodePanel.js +13 -0
  35. package/Panel/ContentPanel.d.ts +1 -0
  36. package/Panel/ContentPanel.js +12 -0
  37. package/Panel/DarkHeader.d.ts +1 -0
  38. package/Panel/DarkHeader.js +7 -0
  39. package/Panel/Panel.d.ts +2 -0
  40. package/Panel/Panel.js +10 -0
  41. package/Panel/PanelBody.d.ts +6 -0
  42. package/Panel/PanelBody.js +15 -0
  43. package/Panel/PanelComponent.d.ts +10 -0
  44. package/Panel/PanelComponent.js +40 -0
  45. package/Panel/PanelHeader.d.ts +7 -0
  46. package/Panel/PanelHeader.js +16 -0
  47. package/Panel/PanelHeaderTitle.d.ts +1 -0
  48. package/Panel/PanelHeaderTitle.js +7 -0
  49. package/Panel/index.d.ts +7 -0
  50. package/Panel/index.js +7 -0
  51. package/SamplesPanelControls/SamplesPanelControls.d.ts +4 -0
  52. package/SamplesPanelControls/SamplesPanelControls.js +17 -0
  53. package/SamplesPanelControls/index.d.ts +1 -0
  54. package/SamplesPanelControls/index.js +1 -0
  55. package/SidebarLogo/SidebarLogo.d.ts +9 -0
  56. package/SidebarLogo/SidebarLogo.js +29 -0
  57. package/SidebarLogo/index.d.ts +1 -0
  58. package/SidebarLogo/index.js +1 -0
  59. package/SourceCode/SourceCode.d.ts +24 -0
  60. package/SourceCode/SourceCode.js +31 -0
  61. package/SourceCode/index.d.ts +1 -0
  62. package/SourceCode/index.js +1 -0
  63. package/Tooltip/Tooltip.d.ts +12 -0
  64. package/Tooltip/Tooltip.js +57 -0
  65. package/Tooltip/index.d.ts +1 -0
  66. package/Tooltip/index.js +1 -0
  67. package/globalStyle.d.ts +1 -0
  68. package/globalStyle.js +7 -0
  69. package/hooks/index.d.ts +3 -0
  70. package/hooks/index.js +3 -0
  71. package/hooks/useControl.d.ts +6 -0
  72. package/hooks/useControl.js +12 -0
  73. package/hooks/useMount.d.ts +1 -0
  74. package/hooks/useMount.js +7 -0
  75. package/hooks/useUnmount.d.ts +1 -0
  76. package/hooks/useUnmount.js +9 -0
  77. package/icons/ShelfIcon/ShelfIcon.d.ts +10 -0
  78. package/icons/ShelfIcon/ShelfIcon.js +33 -0
  79. package/icons/ShelfIcon/index.d.ts +2 -0
  80. package/icons/ShelfIcon/index.js +1 -0
  81. package/icons/index.d.ts +1 -0
  82. package/icons/index.js +1 -0
  83. package/index.d.ts +14 -0
  84. package/mocks/Link.d.ts +2 -0
  85. package/mocks/Link.js +17 -0
  86. package/mocks/utils.d.ts +1 -0
  87. package/mocks/utils.js +3 -0
  88. package/package.json +2 -78
  89. package/src/Button/Button.stories.tsx +74 -0
  90. package/src/Button/Button.tsx +122 -0
  91. package/src/Button/__tests__/Button.test.tsx +42 -0
  92. package/src/Button/__tests__/__snapshots__/Button.test.tsx.snap +274 -0
  93. package/src/Button/index.ts +1 -0
  94. package/src/CodeBlock/CodeBlock.ts +125 -0
  95. package/src/CodeBlock/__tests__/CodeBlock.test.tsx +12 -0
  96. package/src/CodeBlock/__tests__/__snapshots__/CodeBlock.test.tsx.snap +140 -0
  97. package/src/CodeBlock/index.ts +1 -0
  98. package/src/CopyButton/CopyButton.stories.tsx +18 -0
  99. package/src/CopyButton/CopyButton.tsx +26 -0
  100. package/src/CopyButton/CopyButtonWrapper.tsx +52 -0
  101. package/src/CopyButton/__tests__/CopyButton.test.tsx +35 -0
  102. package/src/CopyButton/__tests__/CopyButtonWrapper.test.tsx +16 -0
  103. package/src/CopyButton/__tests__/__snapshots__/CopyButton.test.tsx.snap +55 -0
  104. package/src/CopyButton/__tests__/__snapshots__/CopyButtonWrapper.test.tsx.snap +46 -0
  105. package/src/CopyButton/index.ts +2 -0
  106. package/src/Headings/Headings.stories.tsx +36 -0
  107. package/src/Headings/Headings.ts +23 -0
  108. package/src/Headings/__tests__/Headings.test.tsx +24 -0
  109. package/src/Headings/__tests__/__snapshots__/Headings.test.tsx.snap +57 -0
  110. package/src/Headings/index.ts +1 -0
  111. package/src/Introduction.stories.mdx +7 -0
  112. package/src/JsonViewer/JsonViewer.stories.tsx +57 -0
  113. package/src/JsonViewer/JsonViewer.tsx +130 -0
  114. package/src/JsonViewer/__tests__/JsonViewer.test.tsx +82 -0
  115. package/src/JsonViewer/__tests__/__snapshots__/JsonViewer.test.tsx.snap +2728 -0
  116. package/src/JsonViewer/index.ts +1 -0
  117. package/src/JsonViewer/styled.ts +103 -0
  118. package/src/Logo/Logo.tsx +23 -0
  119. package/src/Navbar/Navbar.stories.tsx +38 -0
  120. package/src/Navbar/Navbar.tsx +60 -0
  121. package/src/Navbar/NavbarItem.tsx +90 -0
  122. package/src/Navbar/NavbarMenu.tsx +29 -0
  123. package/src/Panel/CodePanel.stories.tsx +27 -0
  124. package/src/Panel/CodePanel.ts +31 -0
  125. package/src/Panel/ContentPanel.stories.tsx +27 -0
  126. package/src/Panel/ContentPanel.ts +43 -0
  127. package/src/Panel/DarkHeader.ts +8 -0
  128. package/src/Panel/Panel.stories.tsx +58 -0
  129. package/src/Panel/Panel.ts +18 -0
  130. package/src/Panel/PanelBody.ts +30 -0
  131. package/src/Panel/PanelComponent.tsx +73 -0
  132. package/src/Panel/PanelHeader.ts +25 -0
  133. package/src/Panel/PanelHeaderTitle.ts +11 -0
  134. package/src/Panel/__tests__/CodePanel.test.tsx +26 -0
  135. package/src/Panel/__tests__/ContentPanel.test.tsx +26 -0
  136. package/src/Panel/__tests__/Panel.test.tsx +54 -0
  137. package/src/Panel/__tests__/__snapshots__/CodePanel.test.tsx.snap +258 -0
  138. package/src/Panel/__tests__/__snapshots__/ContentPanel.test.tsx.snap +278 -0
  139. package/src/Panel/__tests__/__snapshots__/Panel.test.tsx.snap +398 -0
  140. package/src/Panel/index.ts +7 -0
  141. package/src/SamplesPanelControls/SamplesControlButton.stories.tsx +18 -0
  142. package/src/SamplesPanelControls/SamplesPanelControls.ts +70 -0
  143. package/src/SamplesPanelControls/__tests__/SamplesPanelControls.test.tsx +36 -0
  144. package/src/SamplesPanelControls/__tests__/__snapshots__/SamplesPanelControls.test.tsx.snap +228 -0
  145. package/src/SamplesPanelControls/index.ts +1 -0
  146. package/src/SidebarLogo/SidebarLogo.stories.tsx +21 -0
  147. package/src/SidebarLogo/SidebarLogo.tsx +47 -0
  148. package/src/SidebarLogo/__tests__/SidebarLogo.test.tsx +32 -0
  149. package/src/SidebarLogo/__tests__/__snapshots__/SidebarLogo.test.tsx.snap +62 -0
  150. package/src/SidebarLogo/index.ts +1 -0
  151. package/src/SourceCode/SourceCode.stories.tsx +29 -0
  152. package/src/SourceCode/SourceCode.tsx +67 -0
  153. package/src/SourceCode/__tests__/SourceCode.test.tsx +47 -0
  154. package/src/SourceCode/__tests__/__snapshots__/SourceCode.test.tsx.snap +786 -0
  155. package/src/SourceCode/index.ts +1 -0
  156. package/src/Tooltip/Tooltip.stories.tsx +27 -0
  157. package/src/Tooltip/Tooltip.tsx +171 -0
  158. package/src/Tooltip/__tests__/Tooltip.test.tsx +41 -0
  159. package/src/Tooltip/__tests__/__snapshots__/Tooltip.test.tsx.snap +83 -0
  160. package/src/Tooltip/index.ts +1 -0
  161. package/src/globalStyle.ts +512 -0
  162. package/src/hooks/index.ts +3 -0
  163. package/src/hooks/useControl.ts +20 -0
  164. package/src/hooks/useMount.ts +8 -0
  165. package/src/hooks/useUnmount.ts +10 -0
  166. package/src/icons/ShelfIcon/ShelfIcon.stories.tsx +36 -0
  167. package/src/icons/ShelfIcon/ShelfIcon.tsx +45 -0
  168. package/src/icons/ShelfIcon/__tests__/ShelfIcon.test.tsx +54 -0
  169. package/src/icons/ShelfIcon/__tests__/__snapshots__/ShelfIcon.test.tsx.snap +235 -0
  170. package/src/icons/ShelfIcon/index.ts +2 -0
  171. package/src/icons/index.ts +1 -0
  172. package/src/index.ts +14 -0
  173. package/src/mocks/Link.tsx +7 -0
  174. package/src/mocks/utils.ts +3 -0
  175. package/src/utils/ClipboardService.ts +92 -0
  176. package/src/utils/__tests__/ClipboardService.test.ts +24 -0
  177. package/src/utils/__tests__/__snapshots__/highlight.test.ts.snap +5 -0
  178. package/src/utils/__tests__/__snapshots__/jsonToHtml.test.ts.snap +5 -0
  179. package/src/utils/__tests__/css-variables.test.ts +20 -0
  180. package/src/utils/__tests__/highlight.test.ts +51 -0
  181. package/src/utils/__tests__/jsonToHtml.test.ts +40 -0
  182. package/src/utils/__tests__/media-css.test.ts +20 -0
  183. package/src/utils/__tests__/theme-helpers.test.ts +25 -0
  184. package/src/utils/css-variables.ts +2 -0
  185. package/src/utils/highlight.ts +81 -0
  186. package/src/utils/index.ts +6 -0
  187. package/src/utils/jsonToHtml.ts +122 -0
  188. package/src/utils/media-css.ts +16 -0
  189. package/src/utils/theme-helpers.ts +34 -0
  190. package/utils/ClipboardService.d.ts +8 -0
  191. package/utils/ClipboardService.js +83 -0
  192. package/utils/css-variables.d.ts +1 -0
  193. package/utils/css-variables.js +4 -0
  194. package/utils/highlight.d.ts +32 -0
  195. package/utils/highlight.js +65 -0
  196. package/utils/index.d.ts +6 -0
  197. package/utils/index.js +6 -0
  198. package/utils/jsonToHtml.d.ts +1 -0
  199. package/utils/jsonToHtml.js +116 -0
  200. package/utils/media-css.d.ts +12 -0
  201. package/utils/media-css.js +9 -0
  202. package/utils/theme-helpers.d.ts +3 -0
  203. package/utils/theme-helpers.js +27 -0
@@ -0,0 +1,228 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`SampleControls & SamplesControlButton renders 1`] = `
4
+ .c2 {
5
+ background-color: var(--samples-panel-controls-background-color);
6
+ border: 0;
7
+ outline: 0;
8
+ border-radius: var(--global-border-radius);
9
+ height: 20px;
10
+ color: var(--color-content-inverse);
11
+ font-size: 12px;
12
+ line-height: 12px;
13
+ cursor: pointer;
14
+ padding: 1px 6px;
15
+ min-width: 90px;
16
+ }
17
+
18
+ .c2:hover,
19
+ .c2:focus {
20
+ background-color: var(--samples-panel-controls-hover-background-color);
21
+ }
22
+
23
+ .c0 {
24
+ padding: 10px 0;
25
+ opacity: 0.7;
26
+ -webkit-transition: opacity 0.3s ease;
27
+ transition: opacity 0.3s ease;
28
+ text-align: right;
29
+ }
30
+
31
+ .c0:focus-within {
32
+ opacity: 1;
33
+ }
34
+
35
+ .c0 > div,
36
+ .c0 > .c1 {
37
+ margin-top: 5px;
38
+ margin-left: 10px;
39
+ }
40
+
41
+ .c0 > div:first-child,
42
+ .c0 > .c1:first-child {
43
+ margin-left: 0;
44
+ }
45
+
46
+ @media screen and (min-width:50rem) {
47
+ .c2 {
48
+ padding: 2px 20px;
49
+ }
50
+ }
51
+
52
+ @media screen and (min-width:50rem) {
53
+ .c0 > div,
54
+ .c0 > .c1 {
55
+ margin-top: 0;
56
+ }
57
+ }
58
+
59
+ <div
60
+ class="c0"
61
+ >
62
+ <button
63
+ class="c1 c2"
64
+ >
65
+ Copy
66
+ </button>
67
+ </div>
68
+ `;
69
+
70
+ exports[`StyledPre renders 1`] = `
71
+ .c0 {
72
+ max-height: var(--code-block-max-height,600px);
73
+ word-break: var(--code-block-word-break,initial);
74
+ }
75
+
76
+ .c0 code[class*='language-'],
77
+ .c0 pre[class*='language-'] {
78
+ text-shadow: 0 -0.1em 0.2em black;
79
+ text-align: left;
80
+ white-space: pre;
81
+ word-spacing: normal;
82
+ word-break: normal;
83
+ word-wrap: normal;
84
+ line-height: 1.5;
85
+ -moz-tab-size: 4;
86
+ -o-tab-size: 4;
87
+ tab-size: 4;
88
+ -webkit-hyphens: none;
89
+ -moz-hyphens: none;
90
+ -ms-hyphens: none;
91
+ -webkit-hyphens: none;
92
+ -moz-hyphens: none;
93
+ -ms-hyphens: none;
94
+ hyphens: none;
95
+ }
96
+
97
+ .c0 pre[class*='language-'] {
98
+ padding: 1em;
99
+ margin: 0.5em 0;
100
+ overflow: auto;
101
+ }
102
+
103
+ .c0 .token.comment,
104
+ .c0 .token.prolog,
105
+ .c0 .token.doctype,
106
+ .c0 .token.cdata {
107
+ color: hsl(30,20%,50%);
108
+ }
109
+
110
+ .c0 .token.punctuation {
111
+ opacity: 1;
112
+ }
113
+
114
+ .c0 .namespace {
115
+ opacity: 0.7;
116
+ }
117
+
118
+ .c0 .token.property,
119
+ .c0 .token.tag,
120
+ .c0 .token.number,
121
+ .c0 .token.constant,
122
+ .c0 .token.symbol {
123
+ color: var(--color-content-inverse);
124
+ }
125
+
126
+ .c0 .token.boolean {
127
+ color: var(--color-error-500);
128
+ }
129
+
130
+ .c0 .token.selector,
131
+ .c0 .token.attr-name,
132
+ .c0 .token.string,
133
+ .c0 .token.char,
134
+ .c0 .token.builtin,
135
+ .c0 .token.inserted {
136
+ color: #fee39e;
137
+ }
138
+
139
+ .c0 .token.selector + a,
140
+ .c0 .token.attr-name + a,
141
+ .c0 .token.string + a,
142
+ .c0 .token.char + a,
143
+ .c0 .token.builtin + a,
144
+ .c0 .token.inserted + a,
145
+ .c0 .token.selector + a:visited,
146
+ .c0 .token.attr-name + a:visited,
147
+ .c0 .token.string + a:visited,
148
+ .c0 .token.char + a:visited,
149
+ .c0 .token.builtin + a:visited,
150
+ .c0 .token.inserted + a:visited {
151
+ color: #4ed2ba;
152
+ -webkit-text-decoration: underline;
153
+ text-decoration: underline;
154
+ }
155
+
156
+ .c0 .token.property.string {
157
+ color: #9efaa7;
158
+ }
159
+
160
+ .c0 .token.operator,
161
+ .c0 .token.entity,
162
+ .c0 .token.url,
163
+ .c0 .token.variable {
164
+ color: #f5b83d;
165
+ }
166
+
167
+ .c0 .token.atrule,
168
+ .c0 .token.attr-value,
169
+ .c0 .token.keyword {
170
+ color: #ffdbf4;
171
+ }
172
+
173
+ .c0 .token.regex,
174
+ .c0 .token.important {
175
+ color: #e90;
176
+ }
177
+
178
+ .c0 .token.important,
179
+ .c0 .token.bold {
180
+ font-weight: bold;
181
+ }
182
+
183
+ .c0 .token.italic {
184
+ font-style: italic;
185
+ }
186
+
187
+ .c0 .token.entity {
188
+ cursor: help;
189
+ }
190
+
191
+ .c0 .token.deleted {
192
+ color: red;
193
+ }
194
+
195
+ .c1 {
196
+ overflow-x: auto;
197
+ margin: 0;
198
+ font-family: var(--code-font-family);
199
+ padding: 20px;
200
+ border-radius: var(--global-border-radius);
201
+ background-color: var(--samples-panel-controls-background-color);
202
+ color: var(--color-content-inverse);
203
+ font-size: var(--code-font-size);
204
+ white-space: var(--code-wrap,pre);
205
+ }
206
+
207
+ @media print {
208
+ .c0 code[class*='language-'],
209
+ .c0 pre[class*='language-'] {
210
+ text-shadow: none;
211
+ }
212
+ }
213
+
214
+ <pre
215
+ class="c0 c1"
216
+ >
217
+ Test:
218
+ <br />
219
+ <a
220
+ class="token string"
221
+ href="#"
222
+ rel="noopener noreferrer"
223
+ target="_blank"
224
+ >
225
+ Click
226
+ </a>
227
+ </pre>
228
+ `;
@@ -0,0 +1 @@
1
+ export * from './SamplesPanelControls';
@@ -0,0 +1,21 @@
1
+ import React from 'react';
2
+ import { ComponentStory, ComponentMeta } from '@storybook/react';
3
+
4
+ import { SidebarLogo } from './SidebarLogo';
5
+
6
+ export default {
7
+ title: 'SidebarLogo',
8
+ component: SidebarLogo,
9
+ argTypes: {
10
+ backgroundColor: { control: 'color' },
11
+ },
12
+ } as ComponentMeta<typeof SidebarLogo>;
13
+
14
+ const Template: ComponentStory<typeof SidebarLogo> = (args) => <SidebarLogo {...args} />;
15
+
16
+ export const Default = Template.bind({});
17
+ Default.args = {
18
+ imageUrl: 'https://redocly.github.io/redoc/petstore-logo.png',
19
+ altText: 'Pet Store',
20
+ href: 'http://redocly.com/',
21
+ };
@@ -0,0 +1,47 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+
4
+ export interface LogoProps {
5
+ imageUrl?: string;
6
+ href?: string;
7
+ altText?: string;
8
+ dataTestId?: string;
9
+ backgroundColor?: string;
10
+ }
11
+
12
+ export function SidebarLogo({
13
+ imageUrl,
14
+ href,
15
+ altText,
16
+ backgroundColor,
17
+ dataTestId,
18
+ }: LogoProps = {}): JSX.Element | null {
19
+ if (!imageUrl) {
20
+ return null;
21
+ }
22
+
23
+ const logo = <LogoImgEl src={imageUrl} alt={altText || 'logo'} />;
24
+
25
+ return (
26
+ <LogoWrap data-cy={dataTestId} style={{ backgroundColor }}>
27
+ {href ? <Link href={href}>{logo}</Link> : logo}
28
+ </LogoWrap>
29
+ );
30
+ }
31
+
32
+ const LogoImgEl = styled.img`
33
+ max-height: var(--logo-max-height);
34
+ max-width: var(--logo-max-width);
35
+ padding: var(--logo-padding);
36
+ width: 100%;
37
+ display: block;
38
+ `;
39
+
40
+ const LogoWrap = styled.div`
41
+ text-align: center;
42
+ line-height: 0;
43
+ `;
44
+
45
+ const Link = styled.a`
46
+ display: inline-block;
47
+ `;
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
+
4
+ import { SidebarLogo } from '../SidebarLogo';
5
+
6
+ describe('SidebarLogo', () => {
7
+ it('renders', () => {
8
+ const { container } = render(
9
+ <SidebarLogo
10
+ imageUrl="https://test.com/logo.png"
11
+ href="https://test.com"
12
+ dataTestId="test"
13
+ />,
14
+ );
15
+
16
+ expect(container.firstChild).toMatchSnapshot();
17
+ });
18
+
19
+ it('renders without href', () => {
20
+ const { container } = render(
21
+ <SidebarLogo imageUrl="https://test.com/logo.png" dataTestId="test" />,
22
+ );
23
+
24
+ expect(container.firstChild).toMatchSnapshot();
25
+ });
26
+
27
+ it('renders nothing, if imageUrl not provided', () => {
28
+ const { container } = render(<SidebarLogo href="https://test.com" />);
29
+
30
+ expect(container.firstChild).toBeNull();
31
+ });
32
+ });
@@ -0,0 +1,62 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`SidebarLogo renders 1`] = `
4
+ .c2 {
5
+ max-height: var(--logo-max-height);
6
+ max-width: var(--logo-max-width);
7
+ padding: var(--logo-padding);
8
+ width: 100%;
9
+ display: block;
10
+ }
11
+
12
+ .c0 {
13
+ text-align: center;
14
+ line-height: 0;
15
+ }
16
+
17
+ .c1 {
18
+ display: inline-block;
19
+ }
20
+
21
+ <div
22
+ class="c0"
23
+ data-cy="test"
24
+ >
25
+ <a
26
+ class="c1"
27
+ href="https://test.com"
28
+ >
29
+ <img
30
+ alt="logo"
31
+ class="c2"
32
+ src="https://test.com/logo.png"
33
+ />
34
+ </a>
35
+ </div>
36
+ `;
37
+
38
+ exports[`SidebarLogo renders without href 1`] = `
39
+ .c1 {
40
+ max-height: var(--logo-max-height);
41
+ max-width: var(--logo-max-width);
42
+ padding: var(--logo-padding);
43
+ width: 100%;
44
+ display: block;
45
+ }
46
+
47
+ .c0 {
48
+ text-align: center;
49
+ line-height: 0;
50
+ }
51
+
52
+ <div
53
+ class="c0"
54
+ data-cy="test"
55
+ >
56
+ <img
57
+ alt="logo"
58
+ class="c1"
59
+ src="https://test.com/logo.png"
60
+ />
61
+ </div>
62
+ `;
@@ -0,0 +1 @@
1
+ export * from './SidebarLogo';
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+ import { ComponentStory, ComponentMeta } from '@storybook/react';
3
+
4
+ import { SourceCode } from './SourceCode';
5
+
6
+ export default {
7
+ title: 'SourceCode',
8
+ component: SourceCode,
9
+ } as ComponentMeta<typeof SourceCode>;
10
+
11
+ const Template: ComponentStory<typeof SourceCode> = (args) => <SourceCode {...args} />;
12
+
13
+ export const WithoutCopyButton = Template.bind({});
14
+ WithoutCopyButton.args = {
15
+ lang: 'php',
16
+ source: `$client = new Rebilly\\Client([
17
+ 'apiKey' => 'YourApiKeyHere',
18
+ 'baseUrl' => 'https://api.rebilly.com',
19
+ ]);`,
20
+ };
21
+ export const WithCopyButton = Template.bind({});
22
+ WithCopyButton.args = {
23
+ lang: 'php',
24
+ withCopyButton: true,
25
+ source: `$client = new Rebilly\\Client([
26
+ 'apiKey' => 'YourApiKeyHere',
27
+ 'baseUrl' => 'https://api.rebilly.com',
28
+ ]);`,
29
+ };
@@ -0,0 +1,67 @@
1
+ import React from 'react';
2
+
3
+ import { highlight } from '../utils/highlight';
4
+ import { SampleControls, SampleControlsWrap, PreformattedCodeBlock } from '../SamplesPanelControls';
5
+ import { CopyButtonWrapper } from '../CopyButton';
6
+
7
+ export interface SourceCodeProps {
8
+ lang: string;
9
+ source?: string;
10
+ externalSource?: ExternalSource;
11
+ withCopyButton?: boolean;
12
+ dataTestId?: string;
13
+ }
14
+
15
+ export interface Sample {
16
+ lang: string;
17
+ label?: string;
18
+ }
19
+
20
+ export type UnstableExternalCodeSample = Sample & {
21
+ get: (source: ExternalSource) => string;
22
+ };
23
+
24
+ export interface ExternalSource {
25
+ sample: UnstableExternalCodeSample;
26
+ exampleName?: string;
27
+ pathParams?: any;
28
+ properties?: any;
29
+ operation?: any;
30
+ }
31
+
32
+ export function Code({
33
+ source,
34
+ lang,
35
+ dataTestId,
36
+ }: Required<Omit<SourceCodeProps, 'externalSource' | 'withCopyButton'>>): JSX.Element {
37
+ return (
38
+ <PreformattedCodeBlock
39
+ dangerouslySetInnerHTML={{ __html: highlight(source, lang) }}
40
+ data-cy={dataTestId}
41
+ />
42
+ );
43
+ }
44
+
45
+ export function SourceCode({
46
+ lang,
47
+ source,
48
+ externalSource,
49
+ withCopyButton,
50
+ dataTestId = 'source-code',
51
+ }: SourceCodeProps): JSX.Element {
52
+ const _source = source || externalSource?.sample?.get?.(externalSource) || '';
53
+ if (withCopyButton) {
54
+ return (
55
+ <CopyButtonWrapper data={source}>
56
+ {({ renderCopyButton }) => (
57
+ <SampleControlsWrap>
58
+ <SampleControls data-cy="copy-button">{renderCopyButton()}</SampleControls>
59
+ <Code lang={lang} source={_source} dataTestId={dataTestId} />
60
+ </SampleControlsWrap>
61
+ )}
62
+ </CopyButtonWrapper>
63
+ );
64
+ }
65
+
66
+ return <Code dataTestId={dataTestId} lang={lang} source={_source} />;
67
+ }
@@ -0,0 +1,47 @@
1
+ import React from 'react';
2
+
3
+ import { SourceCode } from '../SourceCode';
4
+ import { renderWithTheme } from '../../../tests/utils';
5
+
6
+ describe('SourceCode', () => {
7
+ it('renders without copy button', () => {
8
+ const { container } = renderWithTheme(
9
+ <SourceCode source={`let count = 1; count++;`} lang="js" dataTestId="without-copy-button" />,
10
+ );
11
+
12
+ expect(container.firstChild).toMatchSnapshot();
13
+ });
14
+
15
+ it('renders with copy button', () => {
16
+ const { container } = renderWithTheme(
17
+ <SourceCode
18
+ source={`let count = 1; count++;`}
19
+ lang="js"
20
+ withCopyButton
21
+ dataTestId="with-copy-button"
22
+ />,
23
+ );
24
+
25
+ expect(container.firstChild).toMatchSnapshot();
26
+ });
27
+
28
+ it('renders with external source', () => {
29
+ const { container } = renderWithTheme(
30
+ <SourceCode
31
+ externalSource={{ sample: { get: () => `let count = 1; count++;`, lang: 'js' } }}
32
+ lang="js"
33
+ dataTestId="with-external-source"
34
+ />,
35
+ );
36
+
37
+ expect(container.firstChild).toMatchSnapshot();
38
+ });
39
+
40
+ it('renders with external source when it returns null', () => {
41
+ const { container } = renderWithTheme(
42
+ <SourceCode externalSource={{ sample: { get: () => '', lang: 'js' } }} lang="js" />,
43
+ );
44
+
45
+ expect(container.firstChild).toMatchSnapshot();
46
+ });
47
+ });