@bitrise/bitkit 13.66.1-alpha.1 → 13.67.1-alpha.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 +17 -17
- package/src/Components/CodeSnippet/CodeSnippet.theme.ts +129 -34
- package/src/Components/CodeSnippet/CodeSnippet.tsx +86 -22
- package/src/Components/Note/NoteMarkdownContent.tsx +6 -3
- package/src/Components/components.theme.ts +0 -2
- package/src/index.ts +0 -1
- package/src/Components/CodeBlock/CodeBlock.theme.ts +0 -51
- package/src/Components/CodeBlock/CodeBlock.tsx +0 -37
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bitrise/bitkit",
|
|
3
3
|
"description": "Bitrise React component library",
|
|
4
|
-
"version": "13.
|
|
4
|
+
"version": "13.67.1-alpha.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+ssh://git@github.com/bitrise-io/bitkit.git"
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"@floating-ui/react-dom-interactions": "^0.8.1",
|
|
39
39
|
"@fontsource/figtree": "^5.0.20",
|
|
40
40
|
"@fontsource/source-code-pro": "^5.0.18",
|
|
41
|
-
"framer-motion": "^11.
|
|
41
|
+
"framer-motion": "^11.1.8",
|
|
42
42
|
"luxon": "^3.4.4",
|
|
43
43
|
"react": "^18.3.1",
|
|
44
44
|
"react-dom": "^18.3.1",
|
|
45
|
-
"react-focus-lock": "2.
|
|
45
|
+
"react-focus-lock": "^2.12.1",
|
|
46
46
|
"react-imask": "^7.6.0",
|
|
47
47
|
"react-markdown": "^9.0.1"
|
|
48
48
|
},
|
|
@@ -58,35 +58,35 @@
|
|
|
58
58
|
"@bitrise/eslint-plugin": "^2.10.2",
|
|
59
59
|
"@chakra-ui/cli": "^2.4.1",
|
|
60
60
|
"@google-cloud/storage": "^7.11.0",
|
|
61
|
-
"@storybook/addon-actions": "^8.
|
|
62
|
-
"@storybook/addon-essentials": "^8.
|
|
63
|
-
"@storybook/addon-interactions": "^8.
|
|
64
|
-
"@storybook/addon-links": "^8.
|
|
61
|
+
"@storybook/addon-actions": "^8.0.10",
|
|
62
|
+
"@storybook/addon-essentials": "^8.0.10",
|
|
63
|
+
"@storybook/addon-interactions": "^8.0.10",
|
|
64
|
+
"@storybook/addon-links": "^8.0.10",
|
|
65
65
|
"@storybook/addon-webpack5-compiler-swc": "^1.0.2",
|
|
66
|
-
"@storybook/blocks": "^8.
|
|
67
|
-
"@storybook/react": "^8.
|
|
68
|
-
"@storybook/react-webpack5": "^8.
|
|
69
|
-
"@storybook/theming": "^8.
|
|
66
|
+
"@storybook/blocks": "^8.0.10",
|
|
67
|
+
"@storybook/react": "^8.0.10",
|
|
68
|
+
"@storybook/react-webpack5": "^8.0.10",
|
|
69
|
+
"@storybook/theming": "^8.0.10",
|
|
70
70
|
"@testing-library/dom": "^10.1.0",
|
|
71
71
|
"@testing-library/jest-dom": "^6.4.5",
|
|
72
|
-
"@testing-library/react": "^15.0.
|
|
72
|
+
"@testing-library/react": "^15.0.6",
|
|
73
73
|
"@testing-library/user-event": "^14.5.2",
|
|
74
74
|
"@types/jest": "^29.5.12",
|
|
75
75
|
"@types/luxon": "^3.4.2",
|
|
76
|
-
"@types/react": "^18.3.
|
|
76
|
+
"@types/react": "^18.3.1",
|
|
77
77
|
"@types/react-dom": "^18.3.0",
|
|
78
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
|
79
|
-
"@typescript-eslint/parser": "^7.
|
|
78
|
+
"@typescript-eslint/eslint-plugin": "^7.8.0",
|
|
79
|
+
"@typescript-eslint/parser": "^7.8.0",
|
|
80
80
|
"axios": "^1.6.8",
|
|
81
81
|
"eslint": "^8.57.0",
|
|
82
|
-
"glob": "^10.3.
|
|
82
|
+
"glob": "^10.3.12",
|
|
83
83
|
"jest": "^29.7.0",
|
|
84
84
|
"jest-environment-jsdom": "^29.7.0",
|
|
85
85
|
"jsdom": "^24.0.0",
|
|
86
86
|
"prettier": "^3.2.5",
|
|
87
87
|
"react-hook-form": "^7.51.4",
|
|
88
88
|
"release-it": "^17.2.1",
|
|
89
|
-
"storybook": "^8.
|
|
89
|
+
"storybook": "^8.0.10",
|
|
90
90
|
"ts-jest": "^29.1.2",
|
|
91
91
|
"typescript": "^5.4.5"
|
|
92
92
|
},
|
|
@@ -1,45 +1,140 @@
|
|
|
1
|
-
import { defineStyle, defineStyleConfig } from '@chakra-ui/styled-system';
|
|
1
|
+
import { defineStyle, defineStyleConfig, SystemStyleObject } from '@chakra-ui/styled-system';
|
|
2
|
+
import { CodeSnippetProps } from './CodeSnippet';
|
|
2
3
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
const contentPadding = (variant: CodeSnippetProps['variant']) => {
|
|
5
|
+
switch (variant) {
|
|
6
|
+
case 'single':
|
|
7
|
+
return {
|
|
8
|
+
padding: '.75rem',
|
|
9
|
+
paddingLeft: '1rem',
|
|
10
|
+
paddingRight: '0',
|
|
11
|
+
};
|
|
12
|
+
case 'multi':
|
|
13
|
+
return {
|
|
14
|
+
padding: '1rem',
|
|
15
|
+
};
|
|
16
|
+
default:
|
|
17
|
+
return {
|
|
18
|
+
paddingX: '.375rem',
|
|
19
|
+
paddingY: '.125rem',
|
|
20
|
+
};
|
|
21
|
+
}
|
|
10
22
|
};
|
|
11
23
|
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
const baseStyle = defineStyle(({ variant, size, isExpanded }): SystemStyleObject => {
|
|
25
|
+
return {
|
|
26
|
+
wrapper: {
|
|
27
|
+
display: 'flex',
|
|
28
|
+
position: 'relative',
|
|
29
|
+
width: 'fit-content',
|
|
30
|
+
borderRadius: '2',
|
|
31
|
+
},
|
|
32
|
+
copyContainer: {
|
|
33
|
+
_after:
|
|
34
|
+
variant === 'single'
|
|
35
|
+
? {
|
|
36
|
+
content: `""`,
|
|
37
|
+
position: 'absolute',
|
|
38
|
+
width: '8',
|
|
39
|
+
top: '0',
|
|
40
|
+
bottom: '0',
|
|
41
|
+
right: '0',
|
|
42
|
+
bgGradient: `linear(to-l, transparent, background/secondary)`,
|
|
43
|
+
}
|
|
44
|
+
: 'none',
|
|
45
|
+
_focusVisible: {
|
|
46
|
+
boxShadow: 'outline',
|
|
47
|
+
zIndex: 1,
|
|
48
|
+
},
|
|
49
|
+
bg: 'background/secondary',
|
|
50
|
+
borderRadius: '2',
|
|
51
|
+
borderTopRightRadius: variant === 'single' ? '0' : '2',
|
|
52
|
+
borderBottomRightRadius: variant === 'single' ? '0' : '2',
|
|
53
|
+
cursor: 'pointer',
|
|
54
|
+
'.chakra-collapse': {
|
|
55
|
+
overflow: 'auto !important',
|
|
56
|
+
},
|
|
57
|
+
minHeight: variant === 'inline' ? '1.5rem' : '2.5rem',
|
|
58
|
+
overflow: 'auto',
|
|
59
|
+
scrollbarHeight: variant === 'single' ? 'none' : undefined,
|
|
60
|
+
'::-webkit-scrollbar': {
|
|
61
|
+
height: variant === 'single' ? 0 : undefined,
|
|
62
|
+
},
|
|
63
|
+
position: variant === 'single' ? 'relative' : 'static',
|
|
64
|
+
textColor: 'text/body',
|
|
65
|
+
textStyle: size === 'md' ? 'code/md' : 'code/lg',
|
|
66
|
+
lineHeight: '1rem',
|
|
67
|
+
width: '100%',
|
|
68
|
+
whiteSpace: variant === 'single' ? 'nowrap' : 'pre',
|
|
69
|
+
...contentPadding(variant),
|
|
70
|
+
},
|
|
71
|
+
copyIcon: {
|
|
72
|
+
bg: 'background/secondary',
|
|
73
|
+
border: 'none',
|
|
74
|
+
borderRadius: variant === 'multi' ? '2' : 'unset',
|
|
75
|
+
borderTopRightRadius: '2',
|
|
76
|
+
borderBottomRightRadius: '2',
|
|
77
|
+
position: variant === 'multi' ? 'absolute' : 'relative',
|
|
78
|
+
px: variant === 'multi' ? '4' : '12',
|
|
79
|
+
py: variant === 'multi' ? '4' : '8',
|
|
80
|
+
right: variant === 'multi' ? '4' : '0',
|
|
81
|
+
svg: {
|
|
82
|
+
color: 'icon/secondary',
|
|
83
|
+
},
|
|
84
|
+
top: variant === 'multi' ? '4' : '0',
|
|
85
|
+
_hover: {
|
|
86
|
+
bg: 'background/hover',
|
|
87
|
+
svg: {
|
|
88
|
+
color: 'text/primary',
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
_active: {
|
|
92
|
+
bg: 'background/active',
|
|
93
|
+
svg: {
|
|
94
|
+
color: 'text/primary',
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
_focusVisible: {
|
|
98
|
+
boxShadow: 'outline',
|
|
99
|
+
zIndex: 1,
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
showMoreButtonContainer: {
|
|
103
|
+
background: 'background/secondary',
|
|
104
|
+
borderRadius: 4,
|
|
105
|
+
bottom: 4,
|
|
106
|
+
button: {
|
|
107
|
+
color: 'text/secondary',
|
|
108
|
+
},
|
|
109
|
+
padding: 4,
|
|
110
|
+
position: 'absolute',
|
|
111
|
+
right: 4,
|
|
112
|
+
svg: {
|
|
113
|
+
transform: isExpanded ? 'rotate(180deg)' : 'rotate(0deg)',
|
|
114
|
+
transition: '300ms',
|
|
115
|
+
},
|
|
116
|
+
textAlign: 'right',
|
|
117
|
+
_hover: {
|
|
118
|
+
bg: 'background/hover',
|
|
119
|
+
button: {
|
|
120
|
+
color: 'text/primary',
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
_active: {
|
|
124
|
+
bg: 'background/active',
|
|
125
|
+
button: {
|
|
126
|
+
color: 'text/primary',
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
_focusVisible: {
|
|
130
|
+
boxShadow: 'outline',
|
|
131
|
+
},
|
|
132
|
+
},
|
|
32
133
|
};
|
|
33
|
-
|
|
34
|
-
return { ...style, ...(isCopiable ? copiableStyle : {}) };
|
|
35
134
|
});
|
|
36
135
|
|
|
37
136
|
const CodeSnippetTheme = defineStyleConfig({
|
|
38
137
|
baseStyle,
|
|
39
|
-
defaultProps: {
|
|
40
|
-
size: 'lg',
|
|
41
|
-
},
|
|
42
|
-
sizes,
|
|
43
138
|
});
|
|
44
139
|
|
|
45
140
|
export default CodeSnippetTheme;
|
|
@@ -1,37 +1,101 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
|
-
import { useClipboard,
|
|
2
|
+
import { useClipboard, useMultiStyleConfig } from '@chakra-ui/react';
|
|
3
3
|
import Box, { BoxProps } from '../Box/Box';
|
|
4
4
|
import Tooltip from '../Tooltip/Tooltip';
|
|
5
|
+
import Button from '../Button/Button';
|
|
6
|
+
import Collapse from '../Collapse/Collapse';
|
|
7
|
+
import IconButton from '../IconButton/IconButton';
|
|
5
8
|
|
|
6
9
|
export interface CodeSnippetProps extends Omit<BoxProps, 'children'> {
|
|
7
10
|
children: string;
|
|
8
|
-
isCopiable?: boolean;
|
|
9
|
-
textToCopy?: string;
|
|
10
11
|
size?: 'md' | 'lg';
|
|
12
|
+
startingHeight?: number;
|
|
13
|
+
textToCopy?: string;
|
|
14
|
+
variant: 'inline' | 'single' | 'multi';
|
|
11
15
|
}
|
|
12
16
|
|
|
13
17
|
const CodeSnippet = (props: CodeSnippetProps) => {
|
|
14
|
-
const { children,
|
|
15
|
-
|
|
18
|
+
const { children, variant, textToCopy, size = 'lg', startingHeight, ...rest } = props;
|
|
19
|
+
|
|
20
|
+
const [isExpanded, setExpanded] = useState(false);
|
|
21
|
+
|
|
22
|
+
const styles = useMultiStyleConfig('CodeSnippet', { variant, size, isExpanded });
|
|
23
|
+
|
|
16
24
|
const { hasCopied, onCopy } = useClipboard(textToCopy || children);
|
|
17
25
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
const tooltipLabel = hasCopied ? 'Copied to clipboard' : 'Copy to clipboard';
|
|
27
|
+
const isShowMoreButtonVisible = variant === 'multi' && startingHeight;
|
|
28
|
+
const showMoreButtonText = isExpanded ? 'Show less' : 'Show more';
|
|
29
|
+
|
|
30
|
+
switch (variant) {
|
|
31
|
+
case 'inline':
|
|
32
|
+
return (
|
|
33
|
+
<Tooltip label={tooltipLabel} closeDelay={500}>
|
|
34
|
+
<Box as="code" onClick={onCopy} sx={styles.copyContainer} {...rest}>
|
|
35
|
+
{children}
|
|
36
|
+
</Box>
|
|
37
|
+
</Tooltip>
|
|
38
|
+
);
|
|
39
|
+
case 'single':
|
|
40
|
+
return (
|
|
41
|
+
<Box __css={styles.wrapper} {...rest}>
|
|
42
|
+
<Box as="code" sx={styles.copyContainer}>
|
|
43
|
+
{children}
|
|
44
|
+
</Box>
|
|
45
|
+
<IconButton
|
|
46
|
+
aria-label={tooltipLabel}
|
|
47
|
+
iconName="Duplicate"
|
|
48
|
+
onClick={onCopy}
|
|
49
|
+
size="md"
|
|
50
|
+
tooltipCloseDelay={500}
|
|
51
|
+
variant="secondary"
|
|
52
|
+
sx={styles.copyIcon}
|
|
53
|
+
/>
|
|
54
|
+
</Box>
|
|
55
|
+
);
|
|
56
|
+
case 'multi':
|
|
57
|
+
return (
|
|
58
|
+
<Box __css={styles.wrapper} {...rest}>
|
|
59
|
+
<Box as="code" sx={styles.copyContainer}>
|
|
60
|
+
{startingHeight ? (
|
|
61
|
+
<Collapse
|
|
62
|
+
in={isExpanded}
|
|
63
|
+
startingHeight={startingHeight}
|
|
64
|
+
endingHeight="100vh"
|
|
65
|
+
transition={{ enter: { duration: 0.5 }, exit: { duration: 0.5 } }}
|
|
66
|
+
>
|
|
67
|
+
{children}
|
|
68
|
+
</Collapse>
|
|
69
|
+
) : (
|
|
70
|
+
children
|
|
71
|
+
)}
|
|
72
|
+
</Box>
|
|
73
|
+
<IconButton
|
|
74
|
+
aria-label={tooltipLabel}
|
|
75
|
+
iconName="Duplicate"
|
|
76
|
+
iconSize="24"
|
|
77
|
+
onClick={onCopy}
|
|
78
|
+
size="md"
|
|
79
|
+
tooltipCloseDelay={500}
|
|
80
|
+
variant="secondary"
|
|
81
|
+
sx={styles.copyIcon}
|
|
82
|
+
/>
|
|
83
|
+
{isShowMoreButtonVisible && (
|
|
84
|
+
<Box __css={styles.showMoreButtonContainer}>
|
|
85
|
+
<Button
|
|
86
|
+
aria-label={showMoreButtonText}
|
|
87
|
+
rightIconName="ChevronDown"
|
|
88
|
+
onClick={() => setExpanded(!isExpanded)}
|
|
89
|
+
size="sm"
|
|
90
|
+
variant="tertiary"
|
|
91
|
+
>
|
|
92
|
+
{showMoreButtonText}
|
|
93
|
+
</Button>
|
|
94
|
+
</Box>
|
|
95
|
+
)}
|
|
96
|
+
</Box>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
35
99
|
};
|
|
36
100
|
|
|
37
101
|
export default CodeSnippet;
|
|
@@ -7,7 +7,6 @@ import ListItem from '../List/ListItem';
|
|
|
7
7
|
import Box, { BoxProps } from '../Box/Box';
|
|
8
8
|
import Divider from '../Divider/Divider';
|
|
9
9
|
import Text from '../Text/Text';
|
|
10
|
-
import CodeBlock from '../CodeBlock/CodeBlock';
|
|
11
10
|
import CodeSnippet from '../CodeSnippet/CodeSnippet';
|
|
12
11
|
|
|
13
12
|
type GapType = Exclude<BoxProps['gap'], undefined>;
|
|
@@ -31,7 +30,7 @@ const defaultComponents = (size: 'sm' | 'md' | 'lg', gap: GapType = '16'): Compo
|
|
|
31
30
|
</Box>
|
|
32
31
|
),
|
|
33
32
|
code: ({ node, ...props }) => (
|
|
34
|
-
<CodeSnippet
|
|
33
|
+
<CodeSnippet variant="multi" {...props}>
|
|
35
34
|
{props.children as string}
|
|
36
35
|
</CodeSnippet>
|
|
37
36
|
),
|
|
@@ -45,7 +44,11 @@ const defaultComponents = (size: 'sm' | 'md' | 'lg', gap: GapType = '16'): Compo
|
|
|
45
44
|
li: ({ node, ...props }) => <ListItem {...props} />,
|
|
46
45
|
ol: ({ node, ...props }) => <List isOrdered {...props} />,
|
|
47
46
|
p: ({ node, ...props }) => <Text {...props} />,
|
|
48
|
-
pre: ({ node, ...props }) =>
|
|
47
|
+
pre: ({ node, ...props }) => (
|
|
48
|
+
<CodeSnippet variant="multi" size={codeSize}>
|
|
49
|
+
{props.children as string}
|
|
50
|
+
</CodeSnippet>
|
|
51
|
+
),
|
|
49
52
|
ul: ({ node, ...props }) => <List {...props} />,
|
|
50
53
|
};
|
|
51
54
|
};
|
|
@@ -38,7 +38,6 @@ import SidebarItem from './Sidebar/SidebarItem.theme';
|
|
|
38
38
|
import SegmentedControl from './SegmentedControl/SegmentedControl.theme';
|
|
39
39
|
import Tag from './Tag/Tag.theme';
|
|
40
40
|
import Note from './Note/Note.theme';
|
|
41
|
-
import CodeBlock from './CodeBlock/CodeBlock.theme';
|
|
42
41
|
import CodeSnippet from './CodeSnippet/CodeSnippet.theme';
|
|
43
42
|
import DefinitionTooltip from './DefinitionTooltip/DefinitionTooltip.theme';
|
|
44
43
|
import ExpandableCard from './ExpandableCard/ExpandableCard.theme';
|
|
@@ -66,7 +65,6 @@ const components = {
|
|
|
66
65
|
...Form,
|
|
67
66
|
Alert,
|
|
68
67
|
CloseButton,
|
|
69
|
-
CodeBlock,
|
|
70
68
|
CodeSnippet,
|
|
71
69
|
DatePickerDay,
|
|
72
70
|
DefinitionTooltip,
|
package/src/index.ts
CHANGED
|
@@ -283,7 +283,6 @@ export { default as Tag } from './Components/Tag/Tag';
|
|
|
283
283
|
export type { NoteProps } from './Components/Note/Note';
|
|
284
284
|
export { default as Note } from './Components/Note/Note';
|
|
285
285
|
export { default as MarkdownContent } from './Components/Note/NoteMarkdownContent';
|
|
286
|
-
export { default as CodeBlock } from './Components/CodeBlock/CodeBlock';
|
|
287
286
|
export { default as CodeSnippet } from './Components/CodeSnippet/CodeSnippet';
|
|
288
287
|
|
|
289
288
|
export type { DefinitionTooltipProps } from './Components/DefinitionTooltip/DefinitionTooltip';
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { createMultiStyleConfigHelpers } from '@chakra-ui/styled-system';
|
|
2
|
-
|
|
3
|
-
const { definePartsStyle, defineMultiStyleConfig } = createMultiStyleConfigHelpers([
|
|
4
|
-
'container',
|
|
5
|
-
'codeBox',
|
|
6
|
-
'copyIcon',
|
|
7
|
-
]);
|
|
8
|
-
|
|
9
|
-
const sizes = {
|
|
10
|
-
lg: definePartsStyle({
|
|
11
|
-
codeBox: {
|
|
12
|
-
textStyle: 'code/lg',
|
|
13
|
-
},
|
|
14
|
-
}),
|
|
15
|
-
md: definePartsStyle({
|
|
16
|
-
codeBox: {
|
|
17
|
-
textStyle: 'code/md',
|
|
18
|
-
},
|
|
19
|
-
}),
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const CodeBlockTheme = defineMultiStyleConfig({
|
|
23
|
-
baseStyle: {
|
|
24
|
-
codeBox: {
|
|
25
|
-
bg: 'neutral.95',
|
|
26
|
-
border: '1px solid',
|
|
27
|
-
borderColor: 'separator.primary',
|
|
28
|
-
borderRadius: '8',
|
|
29
|
-
minHeight: '4rem',
|
|
30
|
-
overflowY: 'auto',
|
|
31
|
-
px: '12',
|
|
32
|
-
py: '8',
|
|
33
|
-
textWrap: 'wrap',
|
|
34
|
-
wordBreak: 'break-all',
|
|
35
|
-
},
|
|
36
|
-
container: {
|
|
37
|
-
position: 'relative',
|
|
38
|
-
},
|
|
39
|
-
copyIcon: {
|
|
40
|
-
position: 'absolute',
|
|
41
|
-
right: '1rem',
|
|
42
|
-
top: '1rem',
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
defaultProps: {
|
|
46
|
-
size: 'lg',
|
|
47
|
-
},
|
|
48
|
-
sizes,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
export default CodeBlockTheme;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { BoxProps, useClipboard, useMultiStyleConfig } from '@chakra-ui/react';
|
|
2
|
-
import Box from '../Box/Box';
|
|
3
|
-
import IconButton from '../IconButton/IconButton';
|
|
4
|
-
|
|
5
|
-
interface CodeBlockProps extends BoxProps {
|
|
6
|
-
children: string;
|
|
7
|
-
isCopiable?: boolean;
|
|
8
|
-
size?: 'md' | 'lg';
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const CodeBlock = ({ children, isCopiable, ...props }: CodeBlockProps) => {
|
|
12
|
-
const style = useMultiStyleConfig('CodeBlock', props);
|
|
13
|
-
|
|
14
|
-
const { onCopy } = useClipboard(children);
|
|
15
|
-
|
|
16
|
-
const { maxHeight, ...otherProps } = props;
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<Box sx={style.container} {...otherProps}>
|
|
20
|
-
<Box as="pre" maxHeight={maxHeight} sx={style.codeBox}>
|
|
21
|
-
{children}
|
|
22
|
-
</Box>
|
|
23
|
-
{isCopiable && (
|
|
24
|
-
<IconButton
|
|
25
|
-
aria-label="Copy to clipboard"
|
|
26
|
-
iconName="Duplicate"
|
|
27
|
-
onClick={onCopy}
|
|
28
|
-
size="sm"
|
|
29
|
-
sx={style.copyIcon}
|
|
30
|
-
variant="secondary"
|
|
31
|
-
/>
|
|
32
|
-
)}
|
|
33
|
-
</Box>
|
|
34
|
-
);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export default CodeBlock;
|