@apify/ui-library 0.63.2-featcodeblockwithtabs-5a4360.31 → 0.63.2-featcodeblockwithtabs-5a4360.35
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/dist/src/components/code/code_block/code_block_with_tabs.d.ts +9 -4
- package/dist/src/components/code/code_block/code_block_with_tabs.d.ts.map +1 -1
- package/dist/src/components/code/code_block/code_block_with_tabs.js +82 -69
- package/dist/src/components/code/code_block/code_block_with_tabs.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/components/code/code_block/code_block_with_tabs.tsx +105 -89
|
@@ -1,14 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type MarginSpacingProps, type RegularBoxProps } from '../../box.js';
|
|
1
3
|
import { type RegularLinkProps } from '../../link.js';
|
|
2
4
|
import { type CodeBlockProps } from './code_block.js';
|
|
3
5
|
export type CodeBlockTabKey = 'cli' | 'http' | 'javascript' | 'mcp' | 'openapi' | 'python' | 'typescript';
|
|
4
|
-
type
|
|
6
|
+
type SharedBoxProps = Omit<RegularBoxProps, 'as' | 'children' | 'onClick'> & MarginSpacingProps;
|
|
7
|
+
type SharedCodeBlockProps = Omit<CodeBlockProps, 'bashCommandsStart' | 'content' | 'language' | 'defaultTabKey' | 'onTabChange'>;
|
|
5
8
|
type SharedLinkProps = Pick<RegularLinkProps, 'to' | 'rel' | 'target'>;
|
|
6
|
-
type CodeBlockTabProps = {
|
|
9
|
+
export type CodeBlockTabProps = {
|
|
7
10
|
key: CodeBlockTabKey;
|
|
11
|
+
bashCommandsStart?: number[];
|
|
8
12
|
content: string;
|
|
9
13
|
onClick?: (e: React.MouseEvent) => void;
|
|
10
14
|
} & Partial<SharedLinkProps>;
|
|
11
|
-
type CodeBlockWithTabsProps =
|
|
15
|
+
type CodeBlockWithTabsProps = SharedBoxProps & {
|
|
16
|
+
codeBlockProps: SharedCodeBlockProps;
|
|
12
17
|
currentTabKey: CodeBlockTabKey;
|
|
13
18
|
tabs: CodeBlockTabProps[];
|
|
14
19
|
};
|
|
@@ -18,6 +23,6 @@ export declare const CODE_BLOCK_WITH_TABS_CLASSNAMES: {
|
|
|
18
23
|
TAB: string;
|
|
19
24
|
CONTENT: string;
|
|
20
25
|
};
|
|
21
|
-
export declare const CodeBlockWithTabs: ({
|
|
26
|
+
export declare const CodeBlockWithTabs: ({ className, codeBlockProps, currentTabKey, tabs, ...props }: CodeBlockWithTabsProps) => import("react/jsx-runtime").JSX.Element;
|
|
22
27
|
export {};
|
|
23
28
|
//# sourceMappingURL=code_block_with_tabs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code_block_with_tabs.d.ts","sourceRoot":"","sources":["../../../../../src/components/code/code_block/code_block_with_tabs.tsx"],"names":[],"mappings":"
|
|
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"}
|
|
@@ -2,6 +2,8 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
import styled from 'styled-components';
|
|
4
4
|
import { theme } from '../../../design_system/theme.js';
|
|
5
|
+
import { useSharedUiDependencies } from '../../../ui_dependency_provider.js';
|
|
6
|
+
import { Box } from '../../box.js';
|
|
5
7
|
import { Link } from '../../link.js';
|
|
6
8
|
import { HeadingShared } from '../../text/heading_shared.js';
|
|
7
9
|
import { CodeBlock } from './code_block.js';
|
|
@@ -51,89 +53,100 @@ export const CODE_BLOCK_WITH_TABS_CLASSNAMES = {
|
|
|
51
53
|
TAB: 'CodeBlockWithTabsTab',
|
|
52
54
|
CONTENT: 'CodeBlockWithTabsContent',
|
|
53
55
|
};
|
|
54
|
-
const CodeBlockWithTabsWrapper = styled
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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};
|
|
67
69
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
@media ${theme.device.tablet} {
|
|
71
|
+
height: 88px;
|
|
72
|
+
justify-content: center;
|
|
73
|
+
gap: ${theme.space.space24};
|
|
74
|
+
padding-inline: ${theme.space.space24};
|
|
75
|
+
}
|
|
73
76
|
}
|
|
74
|
-
}
|
|
75
77
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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;
|
|
88
90
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
img {
|
|
92
|
+
width: 20px;
|
|
93
|
+
height: 20px;
|
|
94
|
+
}
|
|
93
95
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
+
}
|
|
105
107
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
display: block;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
108
|
+
&.selected {
|
|
109
|
+
color: ${theme.color.neutral.text};
|
|
111
110
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
[role="tabpanel"] {
|
|
112
|
+
display: block;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
&:hover {
|
|
117
|
+
color: ${theme.color.neutral.text};
|
|
118
|
+
text-decoration: none;
|
|
119
|
+
}
|
|
115
120
|
}
|
|
116
|
-
}
|
|
117
121
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
122
|
+
.${CODE_BLOCK_WITH_TABS_CLASSNAMES.CONTENT} {
|
|
123
|
+
max-width: initial;
|
|
124
|
+
border-top-left-radius: 0;
|
|
125
|
+
border-top-right-radius: 0;
|
|
126
|
+
}
|
|
123
127
|
`;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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) => {
|
|
129
136
|
const { label, src } = CODE_BLOCK_TAB_CATALOG[tab.key];
|
|
130
137
|
const selected = tab.key === currentTab?.key;
|
|
131
|
-
const
|
|
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" })] }));
|
|
132
145
|
// if the tab has a 'to' prop, render a Link component
|
|
133
146
|
if (tab.to) {
|
|
134
|
-
return (_jsx(Link, {
|
|
147
|
+
return (_jsx(Link, { ...commonProps, to: tab.to, rel: tab.rel, target: tab.target, children: children }));
|
|
135
148
|
}
|
|
136
|
-
return (_jsx("div", {
|
|
137
|
-
}) }), _jsx(CodeBlock, { content: currentTab?.content ?? '', language: CODE_BLOCK_TAB_CATALOG[currentTab?.key]?.language, className: CODE_BLOCK_WITH_TABS_CLASSNAMES.CONTENT, hideBashHeader:
|
|
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 })] }));
|
|
138
151
|
};
|
|
139
152
|
//# sourceMappingURL=code_block_with_tabs.js.map
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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,QAAQ,EAAE,MAAM;QAChB,GAAG,EAAE,sCAAsC;KAC9C;IACD,IAAI,EAAE;QACF,KAAK,EAAE,MAAM;QACb,QAAQ,EAAE,MAAM;QAChB,GAAG,EAAE,sCAAsC;KAC9C;IACD,UAAU,EAAE;QACR,KAAK,EAAE,YAAY;QACnB,QAAQ,EAAE,YAAY;QACtB,0EAA0E;QAC1E,GAAG,EAAE,qDAAqD;KAC7D;IAC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