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

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.32+1e905b277d8",
3
+ "version": "0.63.2-featcodeblockwithtabs-5a4360.36+a49029a0694",
4
4
  "description": "React UI library used by apify.com",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -66,5 +66,5 @@
66
66
  "typescript": "^5.1.6",
67
67
  "typescript-eslint": "^8.24.0"
68
68
  },
69
- "gitHead": "1e905b277d80c7b4e02e1498fc1bd893de67a91e"
69
+ "gitHead": "a49029a0694005e89b5f38ad452a1d490d138d99"
70
70
  }
@@ -3,6 +3,8 @@ import React from 'react';
3
3
  import styled from 'styled-components';
4
4
 
5
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';
6
8
  import { Link, type RegularLinkProps } from '../../link.js';
7
9
  import { HeadingShared } from '../../text/heading_shared.js';
8
10
  import { CodeBlock, type CodeBlockProps } from './code_block.js';
@@ -55,16 +57,20 @@ const CODE_BLOCK_TAB_CATALOG: Record<CodeBlockTabKey, CodeBlockTabConfig> = {
55
57
  },
56
58
  };
57
59
 
58
- type SharedCodeBlockProps = Omit<CodeBlockProps, 'content' | 'language' | 'defaultTabKey' | 'onTabChange'>;
60
+ type SharedBoxProps = Omit<RegularBoxProps, 'as' | 'children' | 'onClick'> & MarginSpacingProps;
61
+
62
+ type SharedCodeBlockProps = Omit<CodeBlockProps, 'bashCommandsStart' | 'content' | 'language' | 'defaultTabKey' | 'onTabChange'>;
59
63
  type SharedLinkProps = Pick<RegularLinkProps, 'to' | 'rel' | 'target'>;
60
64
 
61
65
  export type CodeBlockTabProps = {
62
66
  key: CodeBlockTabKey;
67
+ bashCommandsStart?: number[];
63
68
  content: string;
64
69
  onClick?: (e: React.MouseEvent) => void;
65
70
  } & Partial<SharedLinkProps>;
66
71
 
67
- type CodeBlockWithTabsProps = SharedCodeBlockProps & {
72
+ type CodeBlockWithTabsProps = SharedBoxProps & {
73
+ codeBlockProps: SharedCodeBlockProps;
68
74
  currentTabKey: CodeBlockTabKey;
69
75
  tabs: CodeBlockTabProps[];
70
76
  };
@@ -76,7 +82,7 @@ export const CODE_BLOCK_WITH_TABS_CLASSNAMES = {
76
82
  CONTENT: 'CodeBlockWithTabsContent',
77
83
  };
78
84
 
79
- const CodeBlockWithTabsWrapper = styled.div`
85
+ const CodeBlockWithTabsWrapper = styled(Box)`
80
86
  .${CODE_BLOCK_WITH_TABS_CLASSNAMES.TABS} {
81
87
  min-width: 266px;
82
88
  height: 72px;
@@ -129,6 +135,8 @@ const CodeBlockWithTabsWrapper = styled.div`
129
135
  }
130
136
 
131
137
  &.selected {
138
+ color: ${theme.color.neutral.text};
139
+
132
140
  [role="tabpanel"] {
133
141
  display: block;
134
142
  }
@@ -147,21 +155,31 @@ const CodeBlockWithTabsWrapper = styled.div`
147
155
  }
148
156
  `;
149
157
 
150
- export const CodeBlockWithTabs = ({ currentTabKey, tabs, className, hideBashHeader = true, ...props }: CodeBlockWithTabsProps) => {
151
- // Math.Max(0, ) ensures that the index is not negative, in case the currentTabKey is not found in the tabs array
152
- const currentTabIndex = Math.max(0, tabs.findIndex((tab) => tab.key === currentTabKey));
153
- const currentTab = tabs[currentTabIndex];
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];
154
166
 
155
167
  return (
156
- <CodeBlockWithTabsWrapper className={clsx(CODE_BLOCK_WITH_TABS_CLASSNAMES.WRAPPER, className)}>
168
+ <CodeBlockWithTabsWrapper className={clsx(CODE_BLOCK_WITH_TABS_CLASSNAMES.WRAPPER, className)} {...props}>
157
169
  <div className={CODE_BLOCK_WITH_TABS_CLASSNAMES.TABS}>
158
170
  {tabs.map((tab) => {
159
171
  const { label, src } = CODE_BLOCK_TAB_CATALOG[tab.key];
160
172
  const selected = tab.key === currentTab?.key;
161
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
+ };
162
180
  const children = (
163
181
  <>
164
- <img src={src} alt={label} />
182
+ <img src={generateProxyImageUrl?.(src, { resize: IMG_RESIZE }) ?? src} alt={label} />
165
183
  <HeadingShared type="titleS" as="p">
166
184
  {label}
167
185
  </HeadingShared>
@@ -173,12 +191,10 @@ export const CodeBlockWithTabs = ({ currentTabKey, tabs, className, hideBashHead
173
191
  if (tab.to) {
174
192
  return (
175
193
  <Link
176
- key={tab.key}
177
- className={clsx(CODE_BLOCK_WITH_TABS_CLASSNAMES.TAB, { selected })}
194
+ {...commonProps}
178
195
  to={tab.to}
179
196
  rel={tab.rel}
180
197
  target={tab.target}
181
- onClick={tab.onClick}
182
198
  >
183
199
  {children}
184
200
  </Link>
@@ -187,10 +203,8 @@ export const CodeBlockWithTabs = ({ currentTabKey, tabs, className, hideBashHead
187
203
 
188
204
  return (
189
205
  <div
190
- key={tab.key}
191
- className={clsx(CODE_BLOCK_WITH_TABS_CLASSNAMES.TAB, { selected })}
206
+ {...commonProps}
192
207
  role="button"
193
- onClick={tab.onClick}
194
208
  >
195
209
  {children}
196
210
  </div>
@@ -198,11 +212,12 @@ export const CodeBlockWithTabs = ({ currentTabKey, tabs, className, hideBashHead
198
212
  })}
199
213
  </div>
200
214
  <CodeBlock
215
+ bashCommandsStart={currentTab?.bashCommandsStart}
201
216
  content={currentTab?.content ?? ''}
202
217
  language={CODE_BLOCK_TAB_CATALOG[currentTab?.key]?.language}
203
218
  className={CODE_BLOCK_WITH_TABS_CLASSNAMES.CONTENT}
204
- hideBashHeader={hideBashHeader}
205
- {...props}
219
+ hideBashHeader
220
+ {...codeBlockProps}
206
221
  />
207
222
  </CodeBlockWithTabsWrapper>
208
223
  );