@redocly/theme 0.48.0 → 0.48.2

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 (98) hide show
  1. package/lib/components/DatePicker/variables.js +1 -1
  2. package/lib/components/Feedback/Mood.js +14 -9
  3. package/lib/components/Search/SearchDialog.js +9 -3
  4. package/lib/components/Search/variables.js +4 -0
  5. package/lib/components/Segmented/Segmented.d.ts +4 -4
  6. package/lib/components/Segmented/Segmented.js +4 -7
  7. package/lib/components/Tag/Tag.d.ts +1 -0
  8. package/lib/components/Tag/Tag.js +3 -2
  9. package/lib/core/contexts/CodeWalkthrough/CodeWalkthroughControlsContext.js +2 -6
  10. package/lib/core/hooks/code-walkthrough/use-code-walkthrough-controls.d.ts +7 -10
  11. package/lib/core/hooks/code-walkthrough/use-code-walkthrough-controls.js +63 -97
  12. package/lib/core/hooks/code-walkthrough/use-code-walkthrough-steps.d.ts +1 -2
  13. package/lib/core/hooks/code-walkthrough/use-code-walkthrough-steps.js +20 -15
  14. package/lib/core/hooks/code-walkthrough/use-code-walkthrough.d.ts +2 -7
  15. package/lib/core/hooks/code-walkthrough/use-code-walkthrough.js +10 -3
  16. package/lib/core/hooks/code-walkthrough/use-renderable-files.d.ts +9 -0
  17. package/lib/core/hooks/code-walkthrough/use-renderable-files.js +28 -0
  18. package/lib/core/hooks/index.d.ts +1 -0
  19. package/lib/core/hooks/index.js +1 -0
  20. package/lib/core/styles/global.js +18 -0
  21. package/lib/core/types/l10n.d.ts +1 -1
  22. package/lib/core/utils/download-code-walkthrough.d.ts +4 -2
  23. package/lib/core/utils/download-code-walkthrough.js +9 -1
  24. package/lib/core/utils/find-closest-common-directory.d.ts +6 -0
  25. package/lib/core/utils/find-closest-common-directory.js +51 -0
  26. package/lib/core/utils/get-code-walkthrough-file-text.d.ts +4 -2
  27. package/lib/core/utils/get-file-icon.js +6 -0
  28. package/lib/core/utils/index.d.ts +1 -0
  29. package/lib/core/utils/index.js +1 -0
  30. package/lib/core/utils/replace-inputs-with-value.d.ts +1 -1
  31. package/lib/core/utils/replace-inputs-with-value.js +9 -10
  32. package/lib/icons/DocumentJavaIcon/DocumentJavaIcon.d.ts +9 -0
  33. package/lib/icons/DocumentJavaIcon/DocumentJavaIcon.js +22 -0
  34. package/lib/icons/DocumentJavaIcon/index.d.ts +1 -0
  35. package/lib/icons/DocumentJavaIcon/index.js +6 -0
  36. package/lib/icons/DocumentPythonIcon/DocumentPythonIcon.d.ts +9 -0
  37. package/lib/icons/DocumentPythonIcon/DocumentPythonIcon.js +23 -0
  38. package/lib/icons/DocumentPythonIcon/index.d.ts +1 -0
  39. package/lib/icons/DocumentPythonIcon/index.js +6 -0
  40. package/lib/icons/DocumentShellIcon/DocumentShellIcon.d.ts +9 -0
  41. package/lib/icons/DocumentShellIcon/DocumentShellIcon.js +22 -0
  42. package/lib/icons/DocumentShellIcon/index.d.ts +1 -0
  43. package/lib/icons/DocumentShellIcon/index.js +6 -0
  44. package/lib/icons/__tests__/IconTestUtils.d.ts +7 -0
  45. package/lib/icons/__tests__/IconTestUtils.js +33 -0
  46. package/lib/layouts/CodeWalkthroughLayout.js +4 -1
  47. package/lib/markdoc/components/CodeWalkthrough/CodeContainer.js +25 -4
  48. package/lib/markdoc/components/CodeWalkthrough/CodeFilters.d.ts +5 -4
  49. package/lib/markdoc/components/CodeWalkthrough/CodeFilters.js +15 -2
  50. package/lib/markdoc/components/CodeWalkthrough/CodePanel.js +1 -1
  51. package/lib/markdoc/components/CodeWalkthrough/CodePanelHeader.js +29 -23
  52. package/lib/markdoc/components/CodeWalkthrough/CodePanelPreview.js +1 -1
  53. package/lib/markdoc/components/CodeWalkthrough/CodePanelToolbar.js +1 -1
  54. package/lib/markdoc/components/CodeWalkthrough/CodeStep.js +5 -2
  55. package/lib/markdoc/components/CodeWalkthrough/CodeToggle.js +5 -5
  56. package/lib/markdoc/components/CodeWalkthrough/CodeWalkthrough.js +3 -3
  57. package/lib/markdoc/components/CodeWalkthrough/Input.js +7 -5
  58. package/lib/markdoc/tags/code-walkthrough.js +5 -0
  59. package/package.json +3 -3
  60. package/src/components/DatePicker/variables.ts +1 -1
  61. package/src/components/Feedback/Mood.tsx +16 -7
  62. package/src/components/Search/SearchDialog.tsx +52 -36
  63. package/src/components/Search/variables.ts +4 -0
  64. package/src/components/Segmented/Segmented.tsx +10 -10
  65. package/src/components/Tag/Tag.tsx +1 -1
  66. package/src/core/contexts/CodeWalkthrough/CodeWalkthroughControlsContext.tsx +2 -8
  67. package/src/core/hooks/code-walkthrough/use-code-walkthrough-controls.ts +90 -142
  68. package/src/core/hooks/code-walkthrough/use-code-walkthrough-steps.ts +30 -18
  69. package/src/core/hooks/code-walkthrough/use-code-walkthrough.ts +13 -13
  70. package/src/core/hooks/code-walkthrough/use-renderable-files.ts +51 -0
  71. package/src/core/hooks/index.ts +1 -0
  72. package/src/core/styles/global.ts +18 -0
  73. package/src/core/types/l10n.ts +3 -1
  74. package/src/core/utils/download-code-walkthrough.ts +16 -4
  75. package/src/core/utils/find-closest-common-directory.ts +51 -0
  76. package/src/core/utils/get-code-walkthrough-file-text.ts +3 -3
  77. package/src/core/utils/get-file-icon.ts +7 -0
  78. package/src/core/utils/index.ts +1 -0
  79. package/src/core/utils/replace-inputs-with-value.ts +12 -9
  80. package/src/icons/DocumentJavaIcon/DocumentJavaIcon.tsx +33 -0
  81. package/src/icons/DocumentJavaIcon/index.ts +1 -0
  82. package/src/icons/DocumentPythonIcon/DocumentPythonIcon.tsx +37 -0
  83. package/src/icons/DocumentPythonIcon/index.ts +1 -0
  84. package/src/icons/DocumentShellIcon/DocumentShellIcon.tsx +33 -0
  85. package/src/icons/DocumentShellIcon/index.ts +1 -0
  86. package/src/icons/__tests__/IconTestUtils.tsx +31 -0
  87. package/src/layouts/CodeWalkthroughLayout.tsx +5 -1
  88. package/src/markdoc/components/CodeWalkthrough/CodeContainer.tsx +28 -3
  89. package/src/markdoc/components/CodeWalkthrough/CodeFilters.tsx +21 -4
  90. package/src/markdoc/components/CodeWalkthrough/CodePanel.tsx +1 -1
  91. package/src/markdoc/components/CodeWalkthrough/CodePanelHeader.tsx +64 -47
  92. package/src/markdoc/components/CodeWalkthrough/CodePanelPreview.tsx +1 -1
  93. package/src/markdoc/components/CodeWalkthrough/CodePanelToolbar.tsx +1 -1
  94. package/src/markdoc/components/CodeWalkthrough/CodeStep.tsx +5 -1
  95. package/src/markdoc/components/CodeWalkthrough/CodeToggle.tsx +5 -5
  96. package/src/markdoc/components/CodeWalkthrough/CodeWalkthrough.tsx +11 -5
  97. package/src/markdoc/components/CodeWalkthrough/Input.tsx +8 -6
  98. package/src/markdoc/tags/code-walkthrough.ts +5 -0
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Splits a file path into its directory components, removing the file name.
3
+ * @param path - The full file path.
4
+ * @returns An array of directories.
5
+ */
6
+ function splitPath(path: string): string[] {
7
+ const parts = path.split('/').filter(Boolean);
8
+ parts.pop();
9
+ return parts;
10
+ }
11
+
12
+ /**
13
+ * Finds the longest common prefix between two paths.
14
+ * @param path1 - The first path as an array of directories.
15
+ * @param path2 - The second path as an array of directories.
16
+ * @returns An array representing the common prefix.
17
+ */
18
+ function findCommonPrefix(path1: string[], path2: string[]): string[] {
19
+ const common: string[] = [];
20
+ for (let i = 0; i < Math.min(path1.length, path2.length); i++) {
21
+ if (path1[i] === path2[i]) {
22
+ common.push(path1[i]);
23
+ } else {
24
+ break;
25
+ }
26
+ }
27
+ return common;
28
+ }
29
+
30
+ /**
31
+ * Finds the closest common directory for a set of file paths.
32
+ * @param paths - An array of absolute file paths.
33
+ * @returns The closest common directory as a string.
34
+ */
35
+ export function findClosestCommonDirectory(paths: string[]): string {
36
+ if (paths.length === 0) {
37
+ return '/';
38
+ }
39
+
40
+ const splitPaths = paths.map(splitPath);
41
+ let commonPrefix = splitPaths[0];
42
+
43
+ for (let i = 1; i < splitPaths.length; i++) {
44
+ commonPrefix = findCommonPrefix(commonPrefix, splitPaths[i]);
45
+ if (commonPrefix.length === 0) {
46
+ return '/';
47
+ }
48
+ }
49
+
50
+ return '/' + commonPrefix.join('/');
51
+ }
@@ -1,11 +1,11 @@
1
- import type { CodeWalkthroughFile, CodeWalkthroughNode, InputsState } from '@redocly/config';
1
+ import type { CodeWalkthroughFile, CodeWalkthroughNode } from '@redocly/config';
2
2
 
3
3
  import { matchCodeWalkthroughConditions, replaceInputsWithValue } from '@redocly/theme/core/utils';
4
4
 
5
5
  export function getCodeWalkthroughFileText(
6
6
  file: CodeWalkthroughFile,
7
7
  state: Record<string, { value: string | boolean }>,
8
- inputsState: InputsState,
8
+ inputsState: Record<string, { value: string }>,
9
9
  ) {
10
10
  const contentChunks: string[] =
11
11
  file?.content.flatMap((node) => getChunkText(node, state, inputsState)) ?? [];
@@ -16,7 +16,7 @@ export function getCodeWalkthroughFileText(
16
16
  function getChunkText(
17
17
  node: CodeWalkthroughNode,
18
18
  state: Record<string, { value: string | boolean }>,
19
- inputsState: InputsState,
19
+ inputsState: Record<string, { value: string }>,
20
20
  ): string[] {
21
21
  if (typeof node === 'string') {
22
22
  const replacedNode = replaceInputsWithValue(node, inputsState);
@@ -10,6 +10,9 @@ import { DocumentHtmlIcon } from '@redocly/theme/icons/DocumentHtmlIcon/Document
10
10
  import { DocumentReactIcon } from '@redocly/theme/icons/DocumentReactIcon/DocumentReactIcon';
11
11
  import { DocumentMarkdownIcon } from '@redocly/theme/icons/DocumentMarkdownIcon/DocumentMarkdownIcon';
12
12
  import { DocumentGraphqlIcon } from '@redocly/theme/icons/DocumentGraphqlIcon/DocumentGraphqlIcon';
13
+ import { DocumentPythonIcon } from '@redocly/theme/icons/DocumentPythonIcon/DocumentPythonIcon';
14
+ import { DocumentShellIcon } from '@redocly/theme/icons/DocumentShellIcon/DocumentShellIcon';
15
+ import { DocumentJavaIcon } from '@redocly/theme/icons/DocumentJavaIcon/DocumentJavaIcon';
13
16
 
14
17
  const fileIconMap: Record<string, React.FunctionComponent<IconProps>> = {
15
18
  yaml: DocumentYamlIcon,
@@ -28,6 +31,10 @@ const fileIconMap: Record<string, React.FunctionComponent<IconProps>> = {
28
31
 
29
32
  graphql: DocumentGraphqlIcon,
30
33
  gql: DocumentGraphqlIcon,
34
+
35
+ py: DocumentPythonIcon,
36
+ sh: DocumentShellIcon,
37
+ java: DocumentJavaIcon,
31
38
  };
32
39
 
33
40
  export function getFileIconByExt(ext: string) {
@@ -30,3 +30,4 @@ export * from '@redocly/theme/core/utils/download-code-walkthrough';
30
30
  export * from '@redocly/theme/core/utils/get-file-icon';
31
31
  export * from '@redocly/theme/core/utils/match-code-walkthrough-conditions';
32
32
  export * from '@redocly/theme/core/utils/replace-inputs-with-value';
33
+ export * from '@redocly/theme/core/utils/find-closest-common-directory';
@@ -1,11 +1,14 @@
1
- const inputRegex = /(?:\/\*|<!--|#|\/\/)\s*@redocly-input\s*\{"id":\s*"(.*?)"\}\s*(?:\*\/|-->)?/g;
1
+ export function replaceInputsWithValue(node: string, inputs: Record<string, { value?: string }>) {
2
+ const validKeys = Object.entries(inputs)
3
+ .filter(([_, input]) => input.value)
4
+ .map(([key]) => key)
5
+ .join('|');
2
6
 
3
- export function replaceInputsWithValue(node: string, inputs: Record<string, { value: string }>) {
4
- return node.replace(inputRegex, (match, inputKey) => {
5
- if (Object.prototype.hasOwnProperty.call(inputs, inputKey)) {
6
- return inputs[inputKey]?.value;
7
- } else {
8
- return match;
9
- }
10
- });
7
+ if (!validKeys) {
8
+ return node;
9
+ }
10
+
11
+ const inputRegex = new RegExp(`\\{\\{\\s*(${validKeys})\\s*\\}\\}`, 'g');
12
+
13
+ return node.replace(inputRegex, (_, inputKey) => inputs[inputKey]?.value as string);
11
14
  }
@@ -0,0 +1,33 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+
4
+ import type { IconProps } from '@redocly/theme/icons/types';
5
+
6
+ import { getCssColorVariable } from '@redocly/theme/core/utils';
7
+
8
+ const Icon = (props: IconProps) => (
9
+ <svg
10
+ width="16"
11
+ height="16"
12
+ viewBox="0 0 16 16"
13
+ fill="none"
14
+ xmlns="http://www.w3.org/2000/svg"
15
+ {...props}
16
+ >
17
+ <path
18
+ d="M2 13H14V14H2V13ZM14 2H3.5C3.36739 2 3.24021 2.05268 3.14645 2.14645C3.05268 2.24021 3 2.36739 3 2.5V9C3 9.53043 3.21071 10.0391 3.58579 10.4142C3.96086 10.7893 4.46957 11 5 11H10C10.5304 11 11.0391 10.7893 11.4142 10.4142C11.7893 10.0391 12 9.53043 12 9V7H14C14.2652 7 14.5196 6.89464 14.7071 6.70711C14.8946 6.51957 15 6.26522 15 6V3C15 2.73478 14.8946 2.48043 14.7071 2.29289C14.5196 2.10536 14.2652 2 14 2ZM14 6H12V3H14V6Z"
19
+ fill="#3B3C45"
20
+ />
21
+ </svg>
22
+ );
23
+
24
+ export const DocumentJavaIcon = styled(Icon).attrs(() => ({
25
+ 'data-component-name': 'icons/DocumentJavaIcon/DocumentJavaIcon',
26
+ }))<IconProps>`
27
+ path {
28
+ fill: ${({ color }) => getCssColorVariable(color)};
29
+ }
30
+
31
+ height: ${({ size }) => size || '16px'};
32
+ width: ${({ size }) => size || '16px'};
33
+ `;
@@ -0,0 +1 @@
1
+ export { DocumentJavaIcon } from '@redocly/theme/icons/DocumentJavaIcon/DocumentJavaIcon';
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+
4
+ import type { IconProps } from '@redocly/theme/icons/types';
5
+
6
+ import { getCssColorVariable } from '@redocly/theme/core/utils';
7
+
8
+ const Icon = (props: IconProps) => (
9
+ <svg
10
+ width="16"
11
+ height="16"
12
+ viewBox="0 0 16 16"
13
+ fill="none"
14
+ xmlns="http://www.w3.org/2000/svg"
15
+ {...props}
16
+ >
17
+ <path
18
+ d="M6.57325 1.33301C6.06757 1.33301 5.5826 1.53389 5.22504 1.89146C4.86747 2.24903 4.66659 2.734 4.66659 3.23967V4.35967H7.52659C7.78659 4.35967 7.99992 4.73967 7.99992 4.99967H3.23992C2.73424 4.99967 2.24927 5.20055 1.8917 5.55812C1.53413 5.91569 1.33325 6.40066 1.33325 6.90634V9.42701C1.33325 9.93269 1.53413 10.4177 1.8917 10.7752C2.24927 11.1328 2.73424 11.3337 3.23992 11.3337H4.02659V9.54701C4.02571 9.29694 4.07421 9.04915 4.1693 8.81786C4.26439 8.58657 4.4042 8.37633 4.58072 8.19919C4.75724 8.02206 4.96699 7.88151 5.19794 7.78561C5.4289 7.6897 5.67651 7.64034 5.92659 7.64034H9.42659C10.4799 7.64034 11.3333 6.79301 11.3333 5.73967V3.23967C11.3333 2.734 11.1324 2.24903 10.7748 1.89146C10.4172 1.53389 9.93227 1.33301 9.42659 1.33301H6.57325ZM6.09325 2.40634C6.35992 2.40634 6.57325 2.48634 6.57325 2.87967C6.57325 3.27301 6.35992 3.47367 6.09325 3.47367C5.83325 3.47367 5.61992 3.27367 5.61992 2.88034C5.61992 2.48701 5.83325 2.40634 6.09325 2.40634Z"
19
+ fill="#3B3C45"
20
+ />
21
+ <path
22
+ d="M11.9727 4.66699V6.45366C11.9735 6.70367 11.925 6.95139 11.8298 7.1826C11.7347 7.41381 11.5949 7.62397 11.4184 7.80104C11.2419 7.97811 11.0321 8.1186 10.8012 8.21446C10.5703 8.31032 10.3228 8.35966 10.0727 8.35966H6.57341C6.32334 8.35878 6.07556 8.40728 5.84427 8.50237C5.61298 8.59746 5.40274 8.73727 5.2256 8.91379C5.04846 9.09031 4.90791 9.30006 4.81201 9.53102C4.71611 9.76197 4.66675 10.0096 4.66675 10.2597V12.7597C4.66675 13.2653 4.86763 13.7503 5.2252 14.1079C5.58277 14.4654 6.06774 14.6663 6.57341 14.6663H9.42675C9.93231 14.6663 10.4172 14.4655 10.7747 14.1081C11.1323 13.7507 11.3332 13.2659 11.3334 12.7603V11.6403H8.47275C8.21275 11.6403 8.00008 11.2603 8.00008 11.0003H12.7601C13.2658 11.0003 13.7507 10.7994 14.1083 10.4419C14.4659 10.0843 14.6667 9.59934 14.6667 9.09366V6.57366C14.6667 6.06798 14.4659 5.58301 14.1083 5.22544C13.7507 4.86787 13.2658 4.66699 12.7601 4.66699H11.9727ZM5.54675 7.67566L5.54408 7.67833L5.56941 7.67566H5.54675ZM9.90675 12.5263C10.1667 12.5263 10.3801 12.7263 10.3801 13.1197C10.3801 13.1818 10.3678 13.2434 10.3441 13.3008C10.3203 13.3582 10.2854 13.4104 10.2414 13.4544C10.1975 13.4983 10.1453 13.5332 10.0879 13.557C10.0305 13.5807 9.96891 13.593 9.90675 13.593C9.64008 13.593 9.42675 13.513 9.42675 13.1197C9.42675 12.7263 9.64008 12.5263 9.90675 12.5263Z"
23
+ fill="#3B3C45"
24
+ />
25
+ </svg>
26
+ );
27
+
28
+ export const DocumentPythonIcon = styled(Icon).attrs(() => ({
29
+ 'data-component-name': 'icons/DocumentPythonIcon/DocumentPythonIcon',
30
+ }))<IconProps>`
31
+ path {
32
+ fill: ${({ color }) => getCssColorVariable(color)};
33
+ }
34
+
35
+ height: ${({ size }) => size || '16px'};
36
+ width: ${({ size }) => size || '16px'};
37
+ `;
@@ -0,0 +1 @@
1
+ export { DocumentPythonIcon } from '@redocly/theme/icons/DocumentPythonIcon/DocumentPythonIcon';
@@ -0,0 +1,33 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+
4
+ import type { IconProps } from '@redocly/theme/icons/types';
5
+
6
+ import { getCssColorVariable } from '@redocly/theme/core/utils';
7
+
8
+ const Icon = (props: IconProps) => (
9
+ <svg
10
+ width="16"
11
+ height="16"
12
+ viewBox="0 0 16 16"
13
+ fill="none"
14
+ xmlns="http://www.w3.org/2000/svg"
15
+ {...props}
16
+ >
17
+ <path
18
+ d="M14.5351 2.99992H3.83862C3.6752 3.00407 3.51738 3.06029 3.38814 3.16039C3.25891 3.26049 3.16501 3.39924 3.12012 3.55642L1.02012 12.4434C0.998149 12.5106 0.993246 12.5822 1.00585 12.6518C1.01845 12.7213 1.04817 12.7867 1.09232 12.8419C1.13646 12.8971 1.19365 12.9404 1.25874 12.968C1.32382 12.9956 1.39474 13.0066 1.46512 12.9999H12.1616C12.3249 12.9957 12.4827 12.9394 12.6118 12.8393C12.7409 12.7392 12.8348 12.6005 12.8796 12.4434L14.9801 3.55592C15.002 3.48876 15.0068 3.41722 14.9942 3.34773C14.9815 3.27825 14.9518 3.213 14.9076 3.15785C14.8635 3.10271 14.8064 3.05941 14.7413 3.03184C14.6763 3.00427 14.6054 2.9933 14.5351 2.99992ZM4.31312 11.8984C4.16872 11.9865 3.99731 12.0194 3.83057 11.9909C3.66383 11.9624 3.51306 11.8745 3.40612 11.7434L3.40262 11.7389C3.35483 11.6781 3.32075 11.6076 3.30269 11.5324C3.28463 11.4572 3.28302 11.3789 3.29797 11.303C3.31292 11.2271 3.34409 11.1554 3.38933 11.0926C3.43457 11.0298 3.49283 10.9776 3.56012 10.9394L8.36012 7.90892L5.30912 4.98292L5.30412 4.97792C5.24784 4.92482 5.20377 4.86011 5.17497 4.78829C5.14616 4.71647 5.13332 4.63924 5.13731 4.56196C5.14131 4.48469 5.16205 4.4092 5.1981 4.34073C5.23416 4.27226 5.28466 4.21244 5.34612 4.16542L5.36462 4.15042C5.49395 4.04749 5.65594 3.9944 5.82112 4.00082C5.98629 4.00725 6.14367 4.07275 6.26462 4.18542L9.88112 7.66392C9.96402 7.76867 10.006 7.90001 9.99912 8.03342C9.99485 8.11013 9.97427 8.18504 9.93875 8.25316C9.90323 8.32127 9.85358 8.38102 9.79312 8.42842C9.75612 8.44842 9.72012 8.48792 4.31762 11.8959L4.31312 11.8984ZM12.0001 11.4699C11.9905 11.6194 11.9221 11.7589 11.81 11.8582C11.6979 11.9575 11.5511 12.0084 11.4016 11.9999H8.58462C8.51096 12.0071 8.43662 11.9987 8.36638 11.9754C8.29614 11.9521 8.23156 11.9144 8.17677 11.8646C8.12199 11.8149 8.07822 11.7542 8.04828 11.6865C8.01834 11.6188 8.00289 11.5457 8.00293 11.4716C8.00296 11.3976 8.01848 11.3245 8.04848 11.2568C8.07849 11.1892 8.12231 11.1285 8.17714 11.0788C8.23197 11.0291 8.2966 10.9915 8.36686 10.9682C8.43712 10.945 8.51147 10.9367 8.58512 10.9439H11.4016C11.5503 10.9353 11.6965 10.9855 11.8085 11.0837C11.9205 11.182 11.9893 11.3203 12.0001 11.4689V11.4699Z"
19
+ fill="#3B3C45"
20
+ />
21
+ </svg>
22
+ );
23
+
24
+ export const DocumentShellIcon = styled(Icon).attrs(() => ({
25
+ 'data-component-name': 'icons/DocumentShellIcon/DocumentShellIcon',
26
+ }))<IconProps>`
27
+ path {
28
+ fill: ${({ color }) => getCssColorVariable(color)};
29
+ }
30
+
31
+ height: ${({ size }) => size || '16px'};
32
+ width: ${({ size }) => size || '16px'};
33
+ `;
@@ -0,0 +1 @@
1
+ export { DocumentShellIcon } from '@redocly/theme/icons/DocumentShellIcon/DocumentShellIcon';
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
+ import '@testing-library/jest-dom';
4
+
5
+ export function testIconComponent(IconComponent: React.ComponentType<any>, componentName: string) {
6
+ const dataName = `icons/${componentName}/${componentName}`;
7
+
8
+ return {
9
+ rendersCorrectlyWithDefaultProps: () => {
10
+ const { container } = render(<IconComponent />);
11
+ const svgElement = container.querySelector('svg');
12
+ expect(svgElement).toBeInTheDocument();
13
+ expect(container.firstChild).toHaveStyle('height: 16px; width: 16px;');
14
+ },
15
+
16
+ appliesCustomSizeAndColor: () => {
17
+ const { container } = render(<IconComponent size="24px" color="--color-primary" />);
18
+
19
+ const svgElement = container.querySelector('svg');
20
+ expect(svgElement).toBeInTheDocument();
21
+ expect(container.firstChild).toHaveStyle('height: 24px; width: 24px;');
22
+ const pathElement = container.querySelector('path');
23
+ expect(pathElement).toHaveStyle('fill: var(--color-primary);');
24
+ },
25
+
26
+ hasCorrectDataComponentName: () => {
27
+ const { container } = render(<IconComponent />);
28
+ expect(container.firstChild).toHaveAttribute('data-component-name', dataName);
29
+ },
30
+ };
31
+ }
@@ -1,6 +1,8 @@
1
1
  import React from 'react';
2
2
  import styled from 'styled-components';
3
3
 
4
+ import { breakpoints } from '@redocly/theme/core';
5
+
4
6
  export type CodeWalkthroughLayoutProps = React.PropsWithChildren<{
5
7
  className?: string;
6
8
  }>;
@@ -66,8 +68,10 @@ const ContentWrapper = styled.section`
66
68
 
67
69
  /* Full-width styling for all .code-walkthroughs */
68
70
  .code-walkthrough {
69
- max-width: none;
70
71
  width: 100%;
72
+ max-width: ${breakpoints.max};
73
+ margin-left: auto;
74
+ margin-right: auto;
71
75
  }
72
76
 
73
77
  &:first-child > h1:first-child {
@@ -21,9 +21,33 @@ export function CodeContainer({
21
21
  // useEffect executed before DOM is updated due to re-render called before "painting" phase.
22
22
  setTimeout(() => {
23
23
  if (compRef.current) {
24
- const element = compRef.current.querySelector('span.line.highlighted');
25
- if (element) {
26
- element.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'start' });
24
+ const highlightedLines = Array.from(
25
+ compRef.current.querySelectorAll('span.line.highlighted'),
26
+ );
27
+ const { bottom: panelBottom, top: panelTop } = compRef.current.getBoundingClientRect();
28
+
29
+ const linesBelow: Element[] = [];
30
+ const linesAbove: Element[] = [];
31
+ for (const highlightedLine of highlightedLines) {
32
+ const { bottom: lineBottom, top: lineTop } = highlightedLine.getBoundingClientRect();
33
+ const below = lineBottom > panelBottom;
34
+ const above = lineTop < panelTop;
35
+
36
+ if (below) {
37
+ linesBelow.push(highlightedLine);
38
+ } else if (above) {
39
+ linesAbove.push(highlightedLine);
40
+ }
41
+ }
42
+
43
+ if ((linesBelow.length && linesAbove.length) || linesAbove.length) {
44
+ linesAbove[0].scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'start' });
45
+ } else if (linesBelow.length) {
46
+ linesBelow[linesBelow.length - 1].scrollIntoView({
47
+ behavior: 'smooth',
48
+ block: 'nearest',
49
+ inline: 'start',
50
+ });
27
51
  }
28
52
  }
29
53
  }, 200);
@@ -31,6 +55,7 @@ export function CodeContainer({
31
55
 
32
56
  return (
33
57
  <CodeContainerWrapper
58
+ data-component-name="Markdoc/CodeWalkthrough/CodeContainer"
34
59
  ref={compRef}
35
60
  hideCodeColors={!isHovered}
36
61
  onMouseEnter={() => setIsHovered(true)}
@@ -3,11 +3,12 @@ import styled from 'styled-components';
3
3
 
4
4
  import type { CodeWalkthroughFilter } from '@redocly/config';
5
5
 
6
- import { Tag } from '@redocly/theme/components/Tag/Tag';
6
+ import { Tag, ContentWrapper as TagContentWrapper } from '@redocly/theme/components/Tag/Tag';
7
7
 
8
+ export type GetFilterState = (groupId: string) => { value: string; render: boolean } | null;
8
9
  export type CodeFilterProps = {
9
10
  filters: CodeWalkthroughFilter[];
10
- getFilterState: (groupId: string) => { value: string; render: boolean } | null;
11
+ getFilterState: GetFilterState;
11
12
  handleFilterSelect: (groupId: string, id: string) => void;
12
13
  filtersElementRef?: React.RefObject<HTMLDivElement>;
13
14
  };
@@ -23,7 +24,10 @@ export function CodeFilters({
23
24
  }
24
25
 
25
26
  return (
26
- <FilterWrapper ref={filtersElementRef}>
27
+ <FilterWrapper
28
+ ref={filtersElementRef}
29
+ data-component-name="Markdoc/CodeWalkthrough/CodeFilters"
30
+ >
27
31
  {filters.map(({ label, items, id }) => {
28
32
  return (
29
33
  <Filter key={id}>
@@ -50,8 +54,9 @@ export function CodeFilters({
50
54
 
51
55
  const Filter = styled.div`
52
56
  display: flex;
53
- align-items: center;
57
+ align-items: flex-start;
54
58
  gap: var(--spacing-xs);
59
+ max-width: 100%;
55
60
  `;
56
61
 
57
62
  const FilterName = styled.div`
@@ -74,14 +79,26 @@ const FilterWrapper = styled.div`
74
79
  top: calc(var(--navbar-height));
75
80
  background-color: var(--bg-color);
76
81
  z-index: 1;
82
+ max-width: var(--md-content-max-width);
77
83
  `;
78
84
 
79
85
  const ButtonsWrapper = styled.div`
80
86
  display: flex;
87
+ min-width: 0;
88
+ flex-wrap: wrap;
81
89
  `;
82
90
 
83
91
  const TagButton = styled(Tag)`
84
92
  cursor: pointer;
85
93
  padding: 0px var(--spacing-xs);
86
94
  margin-right: var(--spacing-xs);
95
+ max-width: 100%;
96
+ margin-bottom: var(--spacing-xs);
97
+
98
+ ${TagContentWrapper} {
99
+ display: inline-block;
100
+ text-overflow: ellipsis;
101
+ white-space: nowrap;
102
+ overflow: hidden;
103
+ }
87
104
  `;
@@ -25,7 +25,7 @@ export function CodePanel({
25
25
  const { handleDownloadCode } = useContext(CodeWalkthroughControlsStateContext);
26
26
 
27
27
  return (
28
- <CodePanelWrapper>
28
+ <CodePanelWrapper data-component-name="Markdoc/CodeWalkthrough/CodePanel">
29
29
  {preview ? (
30
30
  <CodePanelPreview>
31
31
  {preview.map((element, idx) => (
@@ -1,10 +1,9 @@
1
- import React, { useCallback, useEffect, useRef, useState } from 'react';
1
+ import React, { useEffect, useRef, useState } from 'react';
2
2
  import styled, { css } from 'styled-components';
3
3
 
4
4
  import type { CodeWalkthroughFile } from '@redocly/config';
5
5
 
6
- import { useThemeHooks } from '@redocly/theme/core/hooks';
7
- import { getFileIconByExt } from '@redocly/theme/core/utils';
6
+ import { useThemeHooks, useRenderableFiles, type RenderableFile } from '@redocly/theme/core/hooks';
8
7
  import { OverflowMenuVerticalIcon } from '@redocly/theme/icons/OverflowMenuVerticalIcon/OverflowMenuVerticalIcon';
9
8
  import { Dropdown } from '@redocly/theme/components/Dropdown/Dropdown';
10
9
  import { DropdownMenu } from '@redocly/theme/components/Dropdown/DropdownMenu';
@@ -25,32 +24,45 @@ export function CodePanelHeader({
25
24
  activeTabName,
26
25
  onDownloadCode,
27
26
  }: CodePanelHeaderProps): JSX.Element {
27
+ const renderableFiles = useRenderableFiles(files);
28
28
  const { useTranslate } = useThemeHooks();
29
29
  const { translate } = useTranslate();
30
30
  const tabRefs = useRef<HTMLButtonElement[]>([]);
31
31
  const tabsWrapperRef = useRef<HTMLDivElement>(null);
32
- const [hiddenFiles, setHiddenFiles] = useState<CodeWalkthroughFile[]>([]);
32
+ const [hiddenFiles, setHiddenFiles] = useState<RenderableFile[]>([]);
33
33
 
34
34
  useEffect(() => {
35
35
  const activeTab = tabRefs.current.find((tab) => tab?.dataset.name === activeTabName);
36
- if (activeTab) {
37
- activeTab.scrollIntoView({ block: 'nearest', inline: 'center' });
36
+ const tabsWrapper = tabsWrapperRef.current;
37
+
38
+ if (activeTab && tabsWrapper) {
39
+ const { left: wrapperLeft, right: wrapperRight } = tabsWrapper.getBoundingClientRect();
40
+ const { left: tabLeft, right: tabRight } = activeTab.getBoundingClientRect();
41
+ const tabHidden = tabLeft < wrapperLeft || tabRight > wrapperRight;
42
+
43
+ if (tabHidden) {
44
+ activeTab.scrollIntoView({ block: 'nearest', inline: 'nearest' });
45
+ }
38
46
  }
39
- }, [activeTabName]);
40
47
 
41
- useEffect(() => {
42
48
  const calculateHiddenFiles = () => {
43
49
  if (!tabsWrapperRef.current) return;
44
50
  const { left: wrapperLeft, right: wrapperRight } =
45
51
  tabsWrapperRef.current.getBoundingClientRect();
46
52
 
47
- const hidden = files.filter((_, i) => {
53
+ const hidden: RenderableFile[] = [];
54
+
55
+ for (let i = 0; i < renderableFiles.length; i++) {
48
56
  const tab = tabRefs.current[i];
49
- if (!tab) return false;
57
+ if (!tab) continue;
58
+
50
59
  const { left: tabLeft, right: tabRight } = tab.getBoundingClientRect();
60
+ const visible = tabLeft > wrapperLeft && tabRight < wrapperRight;
51
61
 
52
- return tabLeft < wrapperLeft || tabRight > wrapperRight;
53
- });
62
+ if (!visible) {
63
+ hidden.push(renderableFiles[i]);
64
+ }
65
+ }
54
66
 
55
67
  setHiddenFiles(hidden);
56
68
  };
@@ -58,32 +70,29 @@ export function CodePanelHeader({
58
70
  calculateHiddenFiles();
59
71
  window.addEventListener('resize', calculateHiddenFiles);
60
72
  return () => window.removeEventListener('resize', calculateHiddenFiles);
61
- }, [files]);
62
-
63
- const getFileTypeIcon = useCallback((basename: string) => {
64
- const extension = basename.split('.').pop()?.toLowerCase() || '';
65
- return getFileIconByExt(extension);
66
- }, []);
73
+ }, [activeTabName, files, renderableFiles]);
67
74
 
68
75
  return (
69
76
  <CodePanelHeaderWrapper data-component-name="Markdoc/CodeWalkthrough/CodePanelHeader">
70
77
  <TabsWrapper ref={tabsWrapperRef}>
71
78
  <Tabs>
72
- {files.map(({ path, basename }, i) => {
73
- const FileIcon = getFileTypeIcon(basename);
74
- return (
75
- <Tab
76
- ref={(el: HTMLButtonElement) => (tabRefs.current[i] = el)}
77
- data-name={path}
78
- active={path === activeTabName}
79
- key={i}
80
- onClick={() => handleTabSwitch(path)}
81
- >
82
- <FileIcon />
83
- {basename}
84
- </Tab>
85
- );
86
- })}
79
+ {renderableFiles.map(
80
+ ({ path, basename, FileIcon, parentFolder, isNameDuplicate, inRootDir }, i) => {
81
+ return (
82
+ <Tab
83
+ ref={(el: HTMLButtonElement) => (tabRefs.current[i] = el)}
84
+ data-name={path}
85
+ active={path === activeTabName}
86
+ key={i}
87
+ onClick={() => handleTabSwitch(path)}
88
+ >
89
+ <FileIcon />
90
+ {basename}
91
+ {isNameDuplicate && !inRootDir ? <Dirname>{parentFolder}</Dirname> : null}
92
+ </Tab>
93
+ );
94
+ },
95
+ )}
87
96
  </Tabs>
88
97
  <Gradient />
89
98
  </TabsWrapper>
@@ -92,18 +101,21 @@ export function CodePanelHeader({
92
101
  {hiddenFiles.length ? (
93
102
  <Dropdown trigger={<StyledOverflowMenuVerticalIcon size="14px" />} alignment="end">
94
103
  <StyledDropdownMenu>
95
- {hiddenFiles.map(({ path, basename }, i) => {
96
- const FileIcon = getFileTypeIcon(basename);
97
- return (
98
- <DropdownMenuItem
99
- active={path === activeTabName}
100
- key={i}
101
- onAction={() => handleTabSwitch(path)}
102
- prefix={<FileIcon />}
103
- content={basename}
104
- />
105
- );
106
- })}
104
+ {hiddenFiles.map(
105
+ ({ path, basename, FileIcon, isNameDuplicate, inRootDir, parentFolder }, i) => {
106
+ return (
107
+ <DropdownMenuItem
108
+ active={path === activeTabName}
109
+ key={i}
110
+ onAction={() => handleTabSwitch(path)}
111
+ prefix={<FileIcon />}
112
+ content={
113
+ isNameDuplicate && !inRootDir ? `${parentFolder}/${basename}` : basename
114
+ }
115
+ />
116
+ );
117
+ },
118
+ )}
107
119
  </StyledDropdownMenu>
108
120
  </Dropdown>
109
121
  ) : null}
@@ -141,7 +153,7 @@ const Gradient = styled.div`
141
153
 
142
154
  const Tabs = styled.div`
143
155
  display: flex;
144
- overflow-x: auto;
156
+ overflow-x: hidden;
145
157
  padding-right: var(--spacing-base);
146
158
 
147
159
  &::-webkit-scrollbar {
@@ -149,6 +161,11 @@ const Tabs = styled.div`
149
161
  }
150
162
  `;
151
163
 
164
+ const Dirname = styled.span`
165
+ font-size: var(--font-size-sm);
166
+ color: var(--text-color-description);
167
+ `;
168
+
152
169
  const ActionBar = styled.div`
153
170
  display: flex;
154
171
  `;
@@ -164,7 +181,7 @@ const Tab = styled.button<{ active: boolean }>`
164
181
  gap: var(--spacing-xs);
165
182
  color: var(--text-color-secondary);
166
183
  white-space: nowrap;
167
-
184
+ scroll-margin-right: var(--spacing-base);
168
185
  ${({ active }) =>
169
186
  active
170
187
  ? css`
@@ -11,7 +11,7 @@ export function CodePanelPreview({ children }: PropsWithChildren): JSX.Element {
11
11
  const { translate } = useTranslate();
12
12
 
13
13
  return (
14
- <CodePanelPreviewWrapper>
14
+ <CodePanelPreviewWrapper data-component-name="Markdoc/CodeWalkthrough/CodePanelPreview">
15
15
  <PreviewDropdown onClick={() => setIsOpen(!isOpen)}>
16
16
  {translate('codeWalkthrough.preview', 'Preview')}
17
17
  {isOpen ? <ChevronUpIcon /> : <ChevronDownIcon />}
@@ -16,7 +16,7 @@ export function CodePanelToolbar({ file }: CodeToolbarProps): JSX.Element {
16
16
  const fileContent = getFileText(file);
17
17
 
18
18
  return (
19
- <CodeToolbarWrapper>
19
+ <CodeToolbarWrapper data-component-name="Markdoc/CodeWalkthrough/CodePanelToolbar">
20
20
  <CopyButton data={fileContent} type="compound" variant="secondary" size="medium" />
21
21
  </CodeToolbarWrapper>
22
22
  );
@@ -70,7 +70,7 @@ export function CodeStep({
70
70
 
71
71
  const filtersElementHeight = filtersElementRef?.current?.clientHeight || 0;
72
72
  const navbarHeight = document.querySelector('nav')?.clientHeight || 0;
73
- setScrollMarginTop(filtersElementHeight + navbarHeight);
73
+ setScrollMarginTop(filtersElementHeight + navbarHeight + 10);
74
74
 
75
75
  return () => {
76
76
  if (currentCompRef) {
@@ -80,11 +80,15 @@ export function CodeStep({
80
80
  }, [activeStep, register, unregister, filtersElementRef]);
81
81
 
82
82
  if (!areConditionsMet({ when, unless })) {
83
+ if (isActive) {
84
+ setActiveStep(null);
85
+ }
83
86
  return null;
84
87
  }
85
88
 
86
89
  return (
87
90
  <StepWrapper
91
+ data-component-name="Markdoc/CodeWalkthrough/CodeStep"
88
92
  ref={compRef}
89
93
  isActive={isActive}
90
94
  scrollMarginTop={scrollMarginTop}