@apify/ui-library 0.63.2-featcodeblockwithtabs-5a4360.36 → 0.64.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apify/ui-library",
3
- "version": "0.63.2-featcodeblockwithtabs-5a4360.36+a49029a0694",
3
+ "version": "0.64.0",
4
4
  "description": "React UI library used by apify.com",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -26,7 +26,6 @@
26
26
  "It's not nice, but helps us to get around the problem of multiple react instances."
27
27
  ],
28
28
  "dependencies": {
29
- "@apify/log": "^2.5.11",
30
29
  "@apify/ui-icons": "^0.9.0",
31
30
  "@floating-ui/react": "^0.26.2",
32
31
  "clsx": "^2.0.0",
@@ -66,5 +65,5 @@
66
65
  "typescript": "^5.1.6",
67
66
  "typescript-eslint": "^8.24.0"
68
67
  },
69
- "gitHead": "a49029a0694005e89b5f38ad452a1d490d138d99"
68
+ "gitHead": "7fb7b476bfa81ad05a3a830b91a85abcec7a6a63"
70
69
  }
@@ -32,7 +32,7 @@ type HeaderProps = {
32
32
 
33
33
  const LANGUAGES_WITHOUT_LINE_NUMBERS = ['json', 'jsonp', 'jsonp', 'rss', 'yaml', 'xml', 'html', 'bash', 'text', 'dockerfile', 'http'];
34
34
 
35
- const HeaderDots = () => {
35
+ function HeaderDots() {
36
36
  return (
37
37
  <div className="CodeBlock-HederDotsWrapper">
38
38
  <div className="CodeBlock-HeaderDot" />
@@ -40,15 +40,15 @@ const HeaderDots = () => {
40
40
  <div className="CodeBlock-HeaderDot" />
41
41
  </div>
42
42
  );
43
- };
43
+ }
44
44
 
45
- const Header = ({
45
+ function Header({
46
46
  tabs,
47
47
  currentTab,
48
48
  showBashHeader,
49
49
  onTabChange,
50
50
  title,
51
- }: HeaderProps) => {
51
+ }: HeaderProps) {
52
52
  return (
53
53
  <div className="CodeBlock-Header">
54
54
  {showBashHeader && <HeaderDots />}
@@ -87,9 +87,9 @@ const Header = ({
87
87
  </div>
88
88
  </div>
89
89
  );
90
- };
90
+ }
91
91
 
92
- export type CodeBlockProps = RegularBoxProps & {
92
+ type CodeBlockProps = RegularBoxProps & {
93
93
  content: string | CodeTab[]; // TODO: Try to make it work with children props
94
94
  size?: SharedTextSize;
95
95
  language?: string | undefined;
@@ -112,7 +112,7 @@ export type CodeBlockProps = RegularBoxProps & {
112
112
  hideLineNumbers?: boolean | undefined;
113
113
  }
114
114
 
115
- export const CodeBlock = ({
115
+ export function CodeBlock({
116
116
  content,
117
117
  size,
118
118
  language,
@@ -133,7 +133,7 @@ export const CodeBlock = ({
133
133
  hideBashPromptPrefixes,
134
134
  onActionButtonClick,
135
135
  ...rest
136
- }: CodeBlockProps) => {
136
+ }: CodeBlockProps) {
137
137
  const isMultiTab = content instanceof Array;
138
138
  const defaultTab = isMultiTab
139
139
  ? content.find((tab) => tab.key === defaultTabKey) ?? content[0]
@@ -232,4 +232,4 @@ export const CodeBlock = ({
232
232
  )}
233
233
  </CodeBlockWrapper >
234
234
  );
235
- };
235
+ }
@@ -1,4 +1,3 @@
1
1
  export * from './code_block/code_block.js';
2
- export * from './code_block/code_block_with_tabs.js';
3
2
  export * from './one_line_code/one_line_code.js';
4
3
  export * from './inline_code/inline_code.js';
@@ -3,8 +3,6 @@ import { FastAverageColor } from 'fast-average-color';
3
3
  import type { RefCallback } from 'react';
4
4
  import { useCallback, useState } from 'react';
5
5
 
6
- import log from '@apify/log';
7
-
8
6
  // Uses Luma (Y component of YIQ) computed from RGB to determine whether the color is dark.
9
7
  // See https://en.wikipedia.org/wiki/YIQ
10
8
  const isDark = (rgb: number[]): boolean => {
@@ -33,7 +31,7 @@ export const useImageColor = () => {
33
31
  try {
34
32
  setColor(patchDarknessInfo(await fac.getColorAsync(element)));
35
33
  } catch (error) {
36
- log.error('Failed to determine the image color.', { error });
34
+ console.error('Failed to determine the image color.', { error });
37
35
  }
38
36
  };
39
37
 
@@ -1,28 +0,0 @@
1
- import React from 'react';
2
- import { type MarginSpacingProps, type RegularBoxProps } from '../../box.js';
3
- import { type RegularLinkProps } from '../../link.js';
4
- import { type CodeBlockProps } from './code_block.js';
5
- export type CodeBlockTabKey = 'cli' | 'http' | 'javascript' | 'mcp' | 'openapi' | 'python' | 'typescript';
6
- type SharedBoxProps = Omit<RegularBoxProps, 'as' | 'children' | 'onClick'> & MarginSpacingProps;
7
- type SharedCodeBlockProps = Omit<CodeBlockProps, 'bashCommandsStart' | 'content' | 'language' | 'defaultTabKey' | 'onTabChange'>;
8
- type SharedLinkProps = Pick<RegularLinkProps, 'to' | 'rel' | 'target'>;
9
- export type CodeBlockTabProps = {
10
- key: CodeBlockTabKey;
11
- bashCommandsStart?: number[];
12
- content: string;
13
- onClick?: (e: React.MouseEvent) => void;
14
- } & Partial<SharedLinkProps>;
15
- type CodeBlockWithTabsProps = SharedBoxProps & {
16
- codeBlockProps: SharedCodeBlockProps;
17
- currentTabKey: CodeBlockTabKey;
18
- tabs: CodeBlockTabProps[];
19
- };
20
- export declare const CODE_BLOCK_WITH_TABS_CLASSNAMES: {
21
- WRAPPER: string;
22
- TABS: string;
23
- TAB: string;
24
- CONTENT: string;
25
- };
26
- export declare const CodeBlockWithTabs: ({ className, codeBlockProps, currentTabKey, tabs, ...props }: CodeBlockWithTabsProps) => import("react/jsx-runtime").JSX.Element;
27
- export {};
28
- //# sourceMappingURL=code_block_with_tabs.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"code_block_with_tabs.d.ts","sourceRoot":"","sources":["../../../../../src/components/code/code_block/code_block_with_tabs.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,OAAO,EAAO,KAAK,kBAAkB,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,EAAQ,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAE5D,OAAO,EAAa,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjE,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,MAAM,GAAG,YAAY,GAAG,KAAK,GAAG,SAAS,GAAG,QAAQ,GAAG,YAAY,CAAC;AAgD1G,KAAK,cAAc,GAAG,IAAI,CAAC,eAAe,EAAE,IAAI,GAAG,UAAU,GAAG,SAAS,CAAC,GAAG,kBAAkB,CAAC;AAEhG,KAAK,oBAAoB,GAAG,IAAI,CAAC,cAAc,EAAE,mBAAmB,GAAG,SAAS,GAAG,UAAU,GAAG,eAAe,GAAG,aAAa,CAAC,CAAC;AACjI,KAAK,eAAe,GAAG,IAAI,CAAC,gBAAgB,EAAE,IAAI,GAAG,KAAK,GAAG,QAAQ,CAAC,CAAC;AAEvE,MAAM,MAAM,iBAAiB,GAAG;IAC5B,GAAG,EAAE,eAAe,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,KAAK,IAAI,CAAC;CAC3C,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;AAE7B,KAAK,sBAAsB,GAAG,cAAc,GAAG;IAC3C,cAAc,EAAE,oBAAoB,CAAC;IACrC,aAAa,EAAE,eAAe,CAAC;IAC/B,IAAI,EAAE,iBAAiB,EAAE,CAAC;CAC7B,CAAC;AAEF,eAAO,MAAM,+BAA+B;;;;;CAK3C,CAAC;AAgFF,eAAO,MAAM,iBAAiB,iEAAkE,sBAAsB,4CA6DrH,CAAC"}
@@ -1,152 +0,0 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import clsx from 'clsx';
3
- import styled from 'styled-components';
4
- import { theme } from '../../../design_system/theme.js';
5
- import { useSharedUiDependencies } from '../../../ui_dependency_provider.js';
6
- import { Box } from '../../box.js';
7
- import { Link } from '../../link.js';
8
- import { HeadingShared } from '../../text/heading_shared.js';
9
- import { CodeBlock } from './code_block.js';
10
- const CODE_BLOCK_TAB_CATALOG = {
11
- cli: {
12
- label: 'CLI',
13
- language: 'bash',
14
- src: 'https://apify.com/img/icons/code.svg',
15
- },
16
- http: {
17
- label: 'HTTP',
18
- language: 'bash',
19
- src: 'https://apify.com/img/icons/http.svg',
20
- },
21
- javascript: {
22
- label: 'JavaScript',
23
- language: 'javascript',
24
- // TODO: duplicate icon from 'template-icons' to 'icons' folder on the web
25
- src: 'https://apify.com/img/template-icons/javascript.svg',
26
- },
27
- mcp: {
28
- label: 'MCP',
29
- language: 'bash',
30
- src: 'https://apify.com/img/icons/mcp.svg',
31
- },
32
- openapi: {
33
- label: 'OpenAPI',
34
- language: 'json',
35
- src: 'https://apify.com/img/icons/openapi.svg',
36
- },
37
- python: {
38
- label: 'Python',
39
- language: 'python',
40
- // TODO: duplicate icon from 'template-icons' to 'icons' folder on the web
41
- src: 'https://apify.com/img/template-icons/python.svg',
42
- },
43
- typescript: {
44
- label: 'TypeScript',
45
- language: 'typescript',
46
- // TODO: duplicate icon from 'template-icons' to 'icons' folder on the web
47
- src: 'https://apify.com/img/template-icons/typescript.svg',
48
- },
49
- };
50
- export const CODE_BLOCK_WITH_TABS_CLASSNAMES = {
51
- WRAPPER: 'CodeBlockWithTabsWrapper',
52
- TABS: 'CodeBlockWithTabsTabs',
53
- TAB: 'CodeBlockWithTabsTab',
54
- CONTENT: 'CodeBlockWithTabsContent',
55
- };
56
- const CodeBlockWithTabsWrapper = styled(Box) `
57
- .${CODE_BLOCK_WITH_TABS_CLASSNAMES.TABS} {
58
- min-width: 266px;
59
- height: 72px;
60
- padding-inline: ${theme.space.space8};
61
- display: flex;
62
- gap: ${theme.space.space4};
63
- overflow-x: auto;
64
- background-color: ${theme.color.neutral.backgroundSubtle};
65
- border: 1px solid ${theme.color.neutral.border};
66
- border-bottom: none;
67
- border-top-right-radius: ${theme.radius.radius12};
68
- border-top-left-radius: ${theme.radius.radius12};
69
-
70
- @media ${theme.device.tablet} {
71
- height: 88px;
72
- justify-content: center;
73
- gap: ${theme.space.space24};
74
- padding-inline: ${theme.space.space24};
75
- }
76
- }
77
-
78
- .${CODE_BLOCK_WITH_TABS_CLASSNAMES.TAB} {
79
- min-width: 64px;
80
- position: relative;
81
- padding: ${theme.space.space12} ${theme.space.space8};
82
- color: ${theme.color.neutral.textMuted};
83
- display: flex;
84
- flex-direction: column;
85
- flex-shrink: 0;
86
- align-items: center;
87
- justify-content: flex-end;
88
- gap: ${theme.space.space4};
89
- cursor: pointer;
90
-
91
- img {
92
- width: 20px;
93
- height: 20px;
94
- }
95
-
96
- [role="tabpanel"] {
97
- bottom: 0;
98
- width: 100%;
99
- height: 2px;
100
- color: ${theme.color.neutral.text};
101
- background-color: ${theme.color.primaryBlack.action};
102
- border-radius: ${theme.radius.radiusFull};
103
- display: none;
104
- position: absolute;
105
- z-index: 2;
106
- }
107
-
108
- &.selected {
109
- color: ${theme.color.neutral.text};
110
-
111
- [role="tabpanel"] {
112
- display: block;
113
- }
114
- }
115
-
116
- &:hover {
117
- color: ${theme.color.neutral.text};
118
- text-decoration: none;
119
- }
120
- }
121
-
122
- .${CODE_BLOCK_WITH_TABS_CLASSNAMES.CONTENT} {
123
- max-width: initial;
124
- border-top-left-radius: 0;
125
- border-top-right-radius: 0;
126
- }
127
- `;
128
- const IMG_RESIZE = {
129
- width: 20,
130
- height: 20,
131
- };
132
- export const CodeBlockWithTabs = ({ className, codeBlockProps, currentTabKey, tabs, ...props }) => {
133
- const { generateProxyImageUrl } = useSharedUiDependencies();
134
- const currentTab = tabs.find((tab) => tab.key === currentTabKey) ?? tabs[0];
135
- return (_jsxs(CodeBlockWithTabsWrapper, { className: clsx(CODE_BLOCK_WITH_TABS_CLASSNAMES.WRAPPER, className), ...props, children: [_jsx("div", { className: CODE_BLOCK_WITH_TABS_CLASSNAMES.TABS, children: tabs.map((tab) => {
136
- const { label, src } = CODE_BLOCK_TAB_CATALOG[tab.key];
137
- const selected = tab.key === currentTab?.key;
138
- const commonProps = {
139
- key: tab.key,
140
- className: clsx(CODE_BLOCK_WITH_TABS_CLASSNAMES.TAB, { selected }),
141
- 'data-test': `code-block-tab-${tab.key}`,
142
- onClick: tab.onClick,
143
- };
144
- const children = (_jsxs(_Fragment, { children: [_jsx("img", { src: generateProxyImageUrl?.(src, { resize: IMG_RESIZE }) ?? src, alt: label }), _jsx(HeadingShared, { type: "titleS", as: "p", children: label }), _jsx("div", { role: "tabpanel" })] }));
145
- // if the tab has a 'to' prop, render a Link component
146
- if (tab.to) {
147
- return (_jsx(Link, { ...commonProps, to: tab.to, rel: tab.rel, target: tab.target, children: children }));
148
- }
149
- return (_jsx("div", { ...commonProps, role: "button", children: children }));
150
- }) }), _jsx(CodeBlock, { bashCommandsStart: currentTab?.bashCommandsStart, content: currentTab?.content ?? '', language: CODE_BLOCK_TAB_CATALOG[currentTab?.key]?.language, className: CODE_BLOCK_WITH_TABS_CLASSNAMES.CONTENT, hideBashHeader: true, ...codeBlockProps })] }));
151
- };
152
- //# sourceMappingURL=code_block_with_tabs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"code_block_with_tabs.js","sourceRoot":"","sources":["../../../../../src/components/code/code_block/code_block_with_tabs.tsx"],"names":[],"mappings":";AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EAAE,GAAG,EAAiD,MAAM,cAAc,CAAC;AAClF,OAAO,EAAE,IAAI,EAAyB,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAuB,MAAM,iBAAiB,CAAC;AASjE,MAAM,sBAAsB,GAAgD;IACxE,GAAG,EAAE;QACD,KAAK,EAAE,KAAK;QACZ,Q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AE,GAAG,CAAC,EAAE,QAAQ,EAC3D,SAAS,EAAE,+BAA+B,CAAC,OAAO,EAClD,cAAc,WACV,cAAc,GACpB,IACqB,CAC9B,CAAC;AACN,CAAC,CAAC"}
@@ -1,224 +0,0 @@
1
- import clsx from 'clsx';
2
- import React from 'react';
3
- import styled from 'styled-components';
4
-
5
- import { theme } from '../../../design_system/theme.js';
6
- import { useSharedUiDependencies } from '../../../ui_dependency_provider.js';
7
- import { Box, type MarginSpacingProps, type RegularBoxProps } from '../../box.js';
8
- import { Link, type RegularLinkProps } from '../../link.js';
9
- import { HeadingShared } from '../../text/heading_shared.js';
10
- import { CodeBlock, type CodeBlockProps } from './code_block.js';
11
-
12
- export type CodeBlockTabKey = 'cli' | 'http' | 'javascript' | 'mcp' | 'openapi' | 'python' | 'typescript';
13
- type CodeBlockTabConfig = {
14
- label: string;
15
- language: string;
16
- src: string;
17
- };
18
-
19
- const CODE_BLOCK_TAB_CATALOG: Record<CodeBlockTabKey, CodeBlockTabConfig> = {
20
- cli: {
21
- label: 'CLI',
22
- language: 'bash',
23
- src: 'https://apify.com/img/icons/code.svg',
24
- },
25
- http: {
26
- label: 'HTTP',
27
- language: 'bash',
28
- src: 'https://apify.com/img/icons/http.svg',
29
- },
30
- javascript: {
31
- label: 'JavaScript',
32
- language: 'javascript',
33
- // TODO: duplicate icon from 'template-icons' to 'icons' folder on the web
34
- src: 'https://apify.com/img/template-icons/javascript.svg',
35
- },
36
- mcp: {
37
- label: 'MCP',
38
- language: 'bash',
39
- src: 'https://apify.com/img/icons/mcp.svg',
40
- },
41
- openapi: {
42
- label: 'OpenAPI',
43
- language: 'json',
44
- src: 'https://apify.com/img/icons/openapi.svg',
45
- },
46
- python: {
47
- label: 'Python',
48
- language: 'python',
49
- // TODO: duplicate icon from 'template-icons' to 'icons' folder on the web
50
- src: 'https://apify.com/img/template-icons/python.svg',
51
- },
52
- typescript: {
53
- label: 'TypeScript',
54
- language: 'typescript',
55
- // TODO: duplicate icon from 'template-icons' to 'icons' folder on the web
56
- src: 'https://apify.com/img/template-icons/typescript.svg',
57
- },
58
- };
59
-
60
- type SharedBoxProps = Omit<RegularBoxProps, 'as' | 'children' | 'onClick'> & MarginSpacingProps;
61
-
62
- type SharedCodeBlockProps = Omit<CodeBlockProps, 'bashCommandsStart' | 'content' | 'language' | 'defaultTabKey' | 'onTabChange'>;
63
- type SharedLinkProps = Pick<RegularLinkProps, 'to' | 'rel' | 'target'>;
64
-
65
- export type CodeBlockTabProps = {
66
- key: CodeBlockTabKey;
67
- bashCommandsStart?: number[];
68
- content: string;
69
- onClick?: (e: React.MouseEvent) => void;
70
- } & Partial<SharedLinkProps>;
71
-
72
- type CodeBlockWithTabsProps = SharedBoxProps & {
73
- codeBlockProps: SharedCodeBlockProps;
74
- currentTabKey: CodeBlockTabKey;
75
- tabs: CodeBlockTabProps[];
76
- };
77
-
78
- export const CODE_BLOCK_WITH_TABS_CLASSNAMES = {
79
- WRAPPER: 'CodeBlockWithTabsWrapper',
80
- TABS: 'CodeBlockWithTabsTabs',
81
- TAB: 'CodeBlockWithTabsTab',
82
- CONTENT: 'CodeBlockWithTabsContent',
83
- };
84
-
85
- const CodeBlockWithTabsWrapper = styled(Box)`
86
- .${CODE_BLOCK_WITH_TABS_CLASSNAMES.TABS} {
87
- min-width: 266px;
88
- height: 72px;
89
- padding-inline: ${theme.space.space8};
90
- display: flex;
91
- gap: ${theme.space.space4};
92
- overflow-x: auto;
93
- background-color: ${theme.color.neutral.backgroundSubtle};
94
- border: 1px solid ${theme.color.neutral.border};
95
- border-bottom: none;
96
- border-top-right-radius: ${theme.radius.radius12};
97
- border-top-left-radius: ${theme.radius.radius12};
98
-
99
- @media ${theme.device.tablet} {
100
- height: 88px;
101
- justify-content: center;
102
- gap: ${theme.space.space24};
103
- padding-inline: ${theme.space.space24};
104
- }
105
- }
106
-
107
- .${CODE_BLOCK_WITH_TABS_CLASSNAMES.TAB} {
108
- min-width: 64px;
109
- position: relative;
110
- padding: ${theme.space.space12} ${theme.space.space8};
111
- color: ${theme.color.neutral.textMuted};
112
- display: flex;
113
- flex-direction: column;
114
- flex-shrink: 0;
115
- align-items: center;
116
- justify-content: flex-end;
117
- gap: ${theme.space.space4};
118
- cursor: pointer;
119
-
120
- img {
121
- width: 20px;
122
- height: 20px;
123
- }
124
-
125
- [role="tabpanel"] {
126
- bottom: 0;
127
- width: 100%;
128
- height: 2px;
129
- color: ${theme.color.neutral.text};
130
- background-color: ${theme.color.primaryBlack.action};
131
- border-radius: ${theme.radius.radiusFull};
132
- display: none;
133
- position: absolute;
134
- z-index: 2;
135
- }
136
-
137
- &.selected {
138
- color: ${theme.color.neutral.text};
139
-
140
- [role="tabpanel"] {
141
- display: block;
142
- }
143
- }
144
-
145
- &:hover {
146
- color: ${theme.color.neutral.text};
147
- text-decoration: none;
148
- }
149
- }
150
-
151
- .${CODE_BLOCK_WITH_TABS_CLASSNAMES.CONTENT} {
152
- max-width: initial;
153
- border-top-left-radius: 0;
154
- border-top-right-radius: 0;
155
- }
156
- `;
157
-
158
- const IMG_RESIZE = {
159
- width: 20,
160
- height: 20,
161
- };
162
-
163
- export const CodeBlockWithTabs = ({ className, codeBlockProps, currentTabKey, tabs, ...props }: CodeBlockWithTabsProps) => {
164
- const { generateProxyImageUrl } = useSharedUiDependencies();
165
- const currentTab = tabs.find((tab) => tab.key === currentTabKey) ?? tabs[0];
166
-
167
- return (
168
- <CodeBlockWithTabsWrapper className={clsx(CODE_BLOCK_WITH_TABS_CLASSNAMES.WRAPPER, className)} {...props}>
169
- <div className={CODE_BLOCK_WITH_TABS_CLASSNAMES.TABS}>
170
- {tabs.map((tab) => {
171
- const { label, src } = CODE_BLOCK_TAB_CATALOG[tab.key];
172
- const selected = tab.key === currentTab?.key;
173
-
174
- const commonProps = {
175
- key: tab.key,
176
- className: clsx(CODE_BLOCK_WITH_TABS_CLASSNAMES.TAB, { selected }),
177
- 'data-test': `code-block-tab-${tab.key}`,
178
- onClick: tab.onClick,
179
- };
180
- const children = (
181
- <>
182
- <img src={generateProxyImageUrl?.(src, { resize: IMG_RESIZE }) ?? src} alt={label} />
183
- <HeadingShared type="titleS" as="p">
184
- {label}
185
- </HeadingShared>
186
- <div role="tabpanel" />
187
- </>
188
- );
189
-
190
- // if the tab has a 'to' prop, render a Link component
191
- if (tab.to) {
192
- return (
193
- <Link
194
- {...commonProps}
195
- to={tab.to}
196
- rel={tab.rel}
197
- target={tab.target}
198
- >
199
- {children}
200
- </Link>
201
- );
202
- }
203
-
204
- return (
205
- <div
206
- {...commonProps}
207
- role="button"
208
- >
209
- {children}
210
- </div>
211
- );
212
- })}
213
- </div>
214
- <CodeBlock
215
- bashCommandsStart={currentTab?.bashCommandsStart}
216
- content={currentTab?.content ?? ''}
217
- language={CODE_BLOCK_TAB_CATALOG[currentTab?.key]?.language}
218
- className={CODE_BLOCK_WITH_TABS_CLASSNAMES.CONTENT}
219
- hideBashHeader
220
- {...codeBlockProps}
221
- />
222
- </CodeBlockWithTabsWrapper>
223
- );
224
- };