@bitrise/bitkit 12.44.2 → 12.45.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,7 +1,7 @@
1
1
  {
2
2
  "name": "@bitrise/bitkit",
3
3
  "description": "Bitrise React component library",
4
- "version": "12.44.2",
4
+ "version": "12.45.0",
5
5
  "repository": "git@github.com:bitrise-io/bitkit.git",
6
6
  "main": "src/index.ts",
7
7
  "license": "UNLICENSED",
@@ -0,0 +1,34 @@
1
+ import { defineStyle, defineStyleConfig } from '@chakra-ui/styled-system';
2
+
3
+ const baseStyle = defineStyle(({ isCopiable }) => {
4
+ const style = {
5
+ fontFamily: 'mono',
6
+ py: '4',
7
+ px: '8',
8
+ borderRadius: '2',
9
+ bg: 'neutral.95',
10
+ width: 'fit-content',
11
+ };
12
+
13
+ if (isCopiable) {
14
+ return {
15
+ ...style,
16
+ cursor: 'pointer',
17
+ _hover: {
18
+ background: 'neutral.93',
19
+ },
20
+ _active: {
21
+ background: 'neutral.90',
22
+ },
23
+ _focusVisible: {
24
+ boxShadow: 'outline',
25
+ },
26
+ };
27
+ }
28
+
29
+ return style;
30
+ });
31
+
32
+ export default defineStyleConfig({
33
+ baseStyle,
34
+ });
@@ -0,0 +1,34 @@
1
+ import { useState } from 'react';
2
+ import { useClipboard, useStyleConfig } from '@chakra-ui/react';
3
+ import Box from '../Box/Box';
4
+ import Tooltip from '../Tooltip/Tooltip';
5
+
6
+ export interface CodeSnippetProps {
7
+ children: string;
8
+ isCopiable?: boolean;
9
+ }
10
+
11
+ const CodeSnippet = (props: CodeSnippetProps) => {
12
+ const { children, isCopiable } = props;
13
+ const css = useStyleConfig('CodeSnippet', { isCopiable });
14
+ const { onCopy, hasCopied } = useClipboard(children);
15
+
16
+ const [isTooltipOpen, setTooltipOpen] = useState(false);
17
+
18
+ return (
19
+ <Tooltip isOpen={isTooltipOpen} label={hasCopied ? 'Copied to clipboard' : 'Copy to clipboard'}>
20
+ <Box
21
+ __css={css}
22
+ as="code"
23
+ tabIndex={0}
24
+ onClick={isCopiable ? onCopy : undefined}
25
+ onMouseEnter={() => (isCopiable ? setTooltipOpen(true) : undefined)}
26
+ onMouseLeave={() => (isCopiable ? setTooltipOpen(false) : undefined)}
27
+ >
28
+ {children}
29
+ </Box>
30
+ </Tooltip>
31
+ );
32
+ };
33
+
34
+ export default CodeSnippet;
package/src/index.ts CHANGED
@@ -286,6 +286,7 @@ export { default as Tag } from './Components/Tag/Tag';
286
286
  export { default as Note } from './Components/Note/Note';
287
287
  export { default as MarkdownContent } from './Components/Note/NoteMarkdownContent';
288
288
  export { default as CodeBlock } from './Components/CodeBlock/CodeBlock';
289
+ export { default as CodeSnippet } from './Components/CodeSnippet/CodeSnippet';
289
290
 
290
291
  export type { DefinitionTooltipProps } from './Components/DefinitionTooltip/DefinitionTooltip';
291
292
  export { default as DefinitionTooltip } from './Components/DefinitionTooltip/DefinitionTooltip';
package/src/theme.ts CHANGED
@@ -38,6 +38,7 @@ import SegmentedControl from './Components/SegmentedControl/SegmentedControl.the
38
38
  import Tag from './Components/Tag/Tag.theme';
39
39
  import Note from './Components/Note/Note.theme';
40
40
  import CodeBlock from './Components/CodeBlock/CodeBlock.theme';
41
+ import CodeSnippet from './Components/CodeSnippet/CodeSnippet.theme';
41
42
  import DefinitionTooltip from './Components/DefinitionTooltip/DefinitionTooltip.theme';
42
43
  import ExpandableCard from './Components/ExpandableCard/ExpandableCard.theme';
43
44
  import FileInput from './Components/Form/FileInput/FileInput.theme';
@@ -127,6 +128,7 @@ const theme = {
127
128
  Tag,
128
129
  Note,
129
130
  CodeBlock,
131
+ CodeSnippet,
130
132
  DefinitionTooltip,
131
133
  Toggletip,
132
134
  ExpandableCard,