@bitrise/bitkit 12.44.1 → 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.1",
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;
@@ -33,7 +33,7 @@ const ToggleTheme: ComponentStyleConfig = {
33
33
  },
34
34
  _before: {
35
35
  content: '""',
36
- backgroundImage: `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M10.213 13.915 17.234 7l1.49 1.49L10.212 17 5 11.68l1.49-1.489 3.723 3.724Z' fill='white' /%3E%3C/svg%3E")`,
36
+ backgroundImage: `/**/url(...), url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M10.213 13.915 17.234 7l1.49 1.49L10.212 17 5 11.68l1.49-1.489 3.723 3.724Z' fill='white' /%3E%3C/svg%3E")`,
37
37
  backgroundPositionX: '0.125rem',
38
38
  position: 'absolute',
39
39
  left: 0,
@@ -43,7 +43,7 @@ const ToggleTheme: ComponentStyleConfig = {
43
43
  },
44
44
  _after: {
45
45
  content: '""',
46
- backgroundImage: `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12.01 10.608 16.618 6l1.402 1.402-4.608 4.608 4.608 4.608-1.402 1.402-4.608-4.608-4.608 4.608L6 16.618l4.608-4.608L6 7.402 7.402 6l4.608 4.608Z' fill='white' /%3E%3C/svg%3E")`,
46
+ backgroundImage: `/**/url(...), url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12.01 10.608 16.618 6l1.402 1.402-4.608 4.608 4.608 4.608-1.402 1.402-4.608-4.608-4.608 4.608L6 16.618l4.608-4.608L6 7.402 7.402 6l4.608 4.608Z' fill='white' /%3E%3C/svg%3E")`,
47
47
  backgroundPositionX: '-0.125rem',
48
48
  position: 'absolute',
49
49
  left: '50%',
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,