@apify/ui-library 1.109.0 → 1.109.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.
- package/dist/src/components/code/action_button.d.ts +6 -1
- package/dist/src/components/code/action_button.d.ts.map +1 -1
- package/dist/src/components/code/action_button.js +10 -2
- package/dist/src/components/code/action_button.js.map +1 -1
- package/dist/src/components/code/one_line_code/one_line_code.d.ts +7 -1
- package/dist/src/components/code/one_line_code/one_line_code.d.ts.map +1 -1
- package/dist/src/components/code/one_line_code/one_line_code.js +2 -2
- package/dist/src/components/code/one_line_code/one_line_code.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/components/code/action_button.tsx +22 -1
- package/src/components/code/one_line_code/one_line_code.tsx +26 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apify/ui-library",
|
|
3
|
-
"version": "1.109.
|
|
3
|
+
"version": "1.109.2",
|
|
4
4
|
"description": "React UI library used by apify.com",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"src",
|
|
65
65
|
"style"
|
|
66
66
|
],
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "a7edf97e472d4cf7b799c8d2e1d6e15d2a613599"
|
|
68
68
|
}
|
|
@@ -4,6 +4,7 @@ import styled, { css } from 'styled-components';
|
|
|
4
4
|
import { CheckIcon, CopyIcon } from '@apify/ui-icons';
|
|
5
5
|
|
|
6
6
|
import { theme } from '../../design_system/theme.js';
|
|
7
|
+
import { useSharedUiDependencies } from '../../ui_dependency_provider.js';
|
|
7
8
|
import { useCopyToClipboard } from '../../utils/index.js';
|
|
8
9
|
import { Text } from '../text/index.js';
|
|
9
10
|
|
|
@@ -62,19 +63,33 @@ const StyledButton = styled.button<StyledButtonProps>`
|
|
|
62
63
|
|
|
63
64
|
interface ActionButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
64
65
|
successStyle?: boolean;
|
|
66
|
+
trackingId?: string;
|
|
67
|
+
trackingData?: Record<string, unknown>;
|
|
68
|
+
onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void;
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
export const ActionButton = ({
|
|
68
72
|
successStyle,
|
|
69
73
|
children,
|
|
74
|
+
trackingId,
|
|
75
|
+
trackingData,
|
|
76
|
+
onClick,
|
|
70
77
|
...props
|
|
71
78
|
}: ActionButtonProps) => {
|
|
72
79
|
const hasText = typeof children === 'string';
|
|
73
80
|
|
|
81
|
+
const { trackClick } = useSharedUiDependencies();
|
|
82
|
+
|
|
83
|
+
const trackedOnClick = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
84
|
+
if (trackClick && trackingId) trackClick(trackingId, trackingData);
|
|
85
|
+
if (onClick) onClick(e);
|
|
86
|
+
};
|
|
87
|
+
|
|
74
88
|
return (
|
|
75
89
|
<StyledButton
|
|
76
90
|
$successStyle={successStyle}
|
|
77
91
|
$hasText={hasText}
|
|
92
|
+
onClick={trackedOnClick}
|
|
78
93
|
{...props}
|
|
79
94
|
>
|
|
80
95
|
{hasText ? <Text weight="bold">{children}</Text> : children}
|
|
@@ -84,12 +99,18 @@ export const ActionButton = ({
|
|
|
84
99
|
|
|
85
100
|
interface CopyButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
86
101
|
code: string;
|
|
102
|
+
trackingId?: string;
|
|
103
|
+
trackingData?: Record<string, unknown>;
|
|
87
104
|
}
|
|
88
105
|
|
|
89
106
|
export const CopyButton = ({ code, ...props }: CopyButtonProps) => {
|
|
90
107
|
const { isCopied, copyToClipboard } = useCopyToClipboard();
|
|
91
108
|
return (
|
|
92
|
-
<ActionButton
|
|
109
|
+
<ActionButton
|
|
110
|
+
onClick={async () => copyToClipboard(code)}
|
|
111
|
+
data-test='copy_to_clipboard'
|
|
112
|
+
aria-label="Copy to clipboard"
|
|
113
|
+
{...props}>
|
|
93
114
|
{isCopied ? <CheckIcon size="16" /> : <CopyIcon size="16" />}
|
|
94
115
|
</ActionButton>
|
|
95
116
|
);
|
|
@@ -137,6 +137,16 @@ const OneLineCodeWrapper = styled(SyntaxHighlighterBaseStylesWrapper)<OneLineCod
|
|
|
137
137
|
}
|
|
138
138
|
`;
|
|
139
139
|
|
|
140
|
+
export type TrackingBundleDataObject = {
|
|
141
|
+
trackingId: string;
|
|
142
|
+
trackingData?: Record<string, unknown>;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export type OneLineCodeTrackingBundle = Record<
|
|
146
|
+
'secret' | 'copy' | 'action',
|
|
147
|
+
TrackingBundleDataObject
|
|
148
|
+
>;
|
|
149
|
+
|
|
140
150
|
export type OneLineCodeProps = BoxProps & {
|
|
141
151
|
children: string;
|
|
142
152
|
language?: string;
|
|
@@ -149,6 +159,7 @@ export type OneLineCodeProps = BoxProps & {
|
|
|
149
159
|
secret?: string;
|
|
150
160
|
disabled?: boolean;
|
|
151
161
|
hideCopyButton?: boolean;
|
|
162
|
+
trackingBundle?: OneLineCodeTrackingBundle;
|
|
152
163
|
}
|
|
153
164
|
|
|
154
165
|
export function OneLineCode({
|
|
@@ -163,6 +174,7 @@ export function OneLineCode({
|
|
|
163
174
|
secret,
|
|
164
175
|
disabled,
|
|
165
176
|
hideCopyButton,
|
|
177
|
+
trackingBundle,
|
|
166
178
|
...rest
|
|
167
179
|
}: OneLineCodeProps) {
|
|
168
180
|
const hasSecret = secret !== undefined;
|
|
@@ -209,6 +221,8 @@ export function OneLineCode({
|
|
|
209
221
|
{hasSecret && (
|
|
210
222
|
<ActionButton
|
|
211
223
|
onClick={() => setShowSecret((prev) => !prev)}
|
|
224
|
+
trackingId={trackingBundle?.secret?.trackingId}
|
|
225
|
+
trackingData={trackingBundle?.secret?.trackingData}
|
|
212
226
|
data-test='toggle-visibility-button'
|
|
213
227
|
>
|
|
214
228
|
{showSecret ? (
|
|
@@ -218,9 +232,19 @@ export function OneLineCode({
|
|
|
218
232
|
)}
|
|
219
233
|
</ActionButton>
|
|
220
234
|
)}
|
|
221
|
-
{!hideCopyButton &&
|
|
235
|
+
{!hideCopyButton && (
|
|
236
|
+
<CopyButton
|
|
237
|
+
code={codeWithSecret}
|
|
238
|
+
trackingId={trackingBundle?.copy?.trackingId}
|
|
239
|
+
trackingData={trackingBundle?.copy?.trackingData}
|
|
240
|
+
/>
|
|
241
|
+
)}
|
|
222
242
|
{!!onActionButtonClick && (
|
|
223
|
-
<ActionButton
|
|
243
|
+
<ActionButton
|
|
244
|
+
onClick={onActionButtonClick}
|
|
245
|
+
trackingId={trackingBundle?.action?.trackingId}
|
|
246
|
+
trackingData={trackingBundle?.action?.trackingData}
|
|
247
|
+
>
|
|
224
248
|
{actionButtonLabel}
|
|
225
249
|
</ActionButton>
|
|
226
250
|
)}
|