@bitrise/bitkit 13.123.0 → 13.125.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": "13.123.0",
4
+ "version": "13.125.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+ssh://git@github.com/bitrise-io/bitkit.git"
@@ -1,19 +1,83 @@
1
1
  import type { ComponentStyleConfig } from '@chakra-ui/theme';
2
2
 
3
3
  const ToggleTheme: ComponentStyleConfig = {
4
- baseStyle: ({ withTooltip }) => {
5
- return {
6
- label: {
7
- fontSize: '3',
8
- fontWeight: 'normal',
9
- lineHeight: '1.5rem',
10
- marginBottom: 0,
4
+ variants: {
5
+ fixed: {
6
+ form: {
7
+ display: 'flex',
8
+ flexDirection: 'row',
9
+ justifyContent: 'space-between',
10
+ gap: '24',
11
11
  },
12
- labelWrapper: {
12
+ },
13
+ dynamic: {
14
+ form: {
15
+ flexDirection: 'column',
13
16
  display: 'flex',
14
- gap: '8',
15
- paddingInlineEnd: withTooltip ? '4' : undefined,
16
- width: withTooltip ? 'fit-content' : undefined,
17
+ },
18
+ },
19
+ },
20
+ sizes: {
21
+ sm: {
22
+ container: {
23
+ width: '1.75rem',
24
+ },
25
+ skeleton: {
26
+ width: '1.75rem',
27
+ height: '16',
28
+ },
29
+ thumb: {
30
+ height: '12',
31
+ width: '12',
32
+ _checked: {
33
+ transform: 'translate(12px)',
34
+ },
35
+ },
36
+ track: {
37
+ height: '16',
38
+ width: '1.75rem',
39
+ _after: {
40
+ backgroundSize: '16px 16px',
41
+ backgroundPositionX: '-0.1rem',
42
+ },
43
+ _before: {
44
+ backgroundPositionX: '0',
45
+ backgroundSize: '16px 16px',
46
+ },
47
+ },
48
+ },
49
+ },
50
+ baseStyle: ({ isReadOnly }) => {
51
+ return {
52
+ skeleton: {
53
+ width: isReadOnly ? '40' : '3rem',
54
+ borderRadius: isReadOnly ? '4' : '12',
55
+ height: '24',
56
+ },
57
+ valueText: {
58
+ textStyle: 'body/lg/regular',
59
+ '[data-disabled] &': {
60
+ color: 'text.disabled',
61
+ cursor: 'not-allowed',
62
+ },
63
+ },
64
+ form: {
65
+ _disabled: { cursor: 'not-allowed' },
66
+ },
67
+ helperText: {
68
+ color: 'input/text/helper',
69
+ '[data-disabled] &': {
70
+ color: 'text.disabled',
71
+ cursor: 'not-allowed',
72
+ },
73
+ },
74
+ container: {
75
+ position: 'relative',
76
+ width: '3rem',
77
+ },
78
+ label: {
79
+ fontStyle: 'comp/input/label',
80
+ marginBottom: '4',
17
81
  },
18
82
  spinner: {
19
83
  color: 'neutral.70',
@@ -26,7 +90,7 @@ const ToggleTheme: ComponentStyleConfig = {
26
90
  _checked: {
27
91
  transform: 'translate(24px)',
28
92
  },
29
- bgGradient: 'linear(to-b, neutral.93 3.43%, neutral.100 100%)',
93
+ backgroundColor: 'input/toggle/slideOn',
30
94
  borderRadius: '24',
31
95
  height: '1.25rem',
32
96
  position: 'relative',
@@ -41,6 +105,7 @@ const ToggleTheme: ComponentStyleConfig = {
41
105
  `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"),` +
42
106
  `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")`,
43
107
  backgroundPositionX: '-0.125rem',
108
+ backgroundSize: '24px 24px',
44
109
  bottom: 0,
45
110
  content: '""',
46
111
  left: '50%',
@@ -51,9 +116,10 @@ const ToggleTheme: ComponentStyleConfig = {
51
116
  _before: {
52
117
  backgroundImage:
53
118
  `/* @see: https://github.com/chakra-ui/chakra-ui/issues/7548#issuecomment-1684034030 */` +
54
- `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"),` +
55
- `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")`,
119
+ `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M18.7372 7.67567L10.7502 16.3887L5.34921 11.7592L6.6508 10.2407L10.5831 13.6112L17.2628 6.32422L18.7372 7.67567Z' fill='white' /%3E%3C/svg%3E"),` +
120
+ `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M18.7372 7.67567L10.7502 16.3887L5.34921 11.7592L6.6508 10.2407L10.5831 13.6112L17.2628 6.32422L18.7372 7.67567Z' fill='white' /%3E%3C/svg%3E")`,
56
121
  backgroundPositionX: '0.125rem',
122
+ backgroundSize: '24px 24px',
57
123
  bottom: 0,
58
124
  content: '""',
59
125
  left: 0,
@@ -63,18 +129,18 @@ const ToggleTheme: ComponentStyleConfig = {
63
129
  },
64
130
  _checked: {
65
131
  _disabled: {
66
- backgroundColor: 'turquoise.80',
132
+ backgroundColor: 'input/toggle/frameOn-disabled',
67
133
  },
68
- backgroundColor: 'turquoise.70',
134
+ backgroundColor: 'input/toggle/frameOn',
69
135
  },
70
136
  _disabled: {
71
- backgroundColor: 'neutral.93',
137
+ backgroundColor: 'input/toggle/frameOff-disabled',
72
138
  cursor: 'not-allowed',
73
139
  },
74
140
  _focusVisible: {
75
141
  boxShadow: 'outline',
76
142
  },
77
- backgroundColor: 'neutral.50',
143
+ backgroundColor: 'input/toggle/frameOff',
78
144
  borderRadius: '12',
79
145
  boxSizing: 'border-box',
80
146
  height: '24',
@@ -2,33 +2,35 @@ import { ReactNode } from 'react';
2
2
  import {
3
3
  FormControl,
4
4
  FormControlProps,
5
- FormErrorMessage,
6
5
  FormHelperText,
7
6
  FormLabel,
8
7
  forwardRef,
9
- Switch,
10
8
  SwitchProps,
11
9
  useMultiStyleConfig,
12
10
  } from '@chakra-ui/react';
13
11
  import Box from '../Box/Box';
14
- import ProgressSpinner from '../ProgressSpinner/ProgressSpinner';
15
12
  import Tooltip, { TooltipProps } from '../Tooltip/Tooltip';
13
+ import Text from '../Text/Text';
14
+ import Skeleton from '../Skeleton/Skeleton';
15
+ import SkeletonBox from '../Skeleton/SkeletonBox';
16
+ import ToggleComponent from './ToggleComponent';
16
17
 
17
18
  export interface ToggleProps extends Omit<FormControlProps, 'label' | 'onBlur' | 'onChange'> {
18
19
  'data-testid'?: string;
19
20
  defaultChecked?: SwitchProps['defaultChecked'];
20
- errorText?: string;
21
21
  id?: SwitchProps['id'];
22
22
  isChecked?: SwitchProps['isChecked'];
23
23
  isDisabled?: SwitchProps['isDisabled'];
24
24
  isLoading?: boolean;
25
- helperText?: string;
26
- label?: ReactNode;
25
+ helperText?: ReactNode;
26
+ label: ReactNode;
27
27
  name?: string;
28
28
  onBlur?: SwitchProps['onBlur'];
29
29
  onChange?: SwitchProps['onChange'];
30
30
  tooltip?: Omit<TooltipProps, 'children'>;
31
31
  value?: SwitchProps['value'];
32
+ valueText?: ReactNode;
33
+ variant?: 'dynamic' | 'fixed';
32
34
  }
33
35
 
34
36
  /**
@@ -39,12 +41,12 @@ const Toggle = forwardRef<ToggleProps, 'div'>((props, ref) => {
39
41
  'aria-label': ariaLabel,
40
42
  'data-testid': dataTestid,
41
43
  defaultChecked,
42
- errorText,
43
44
  helperText,
44
45
  id,
45
46
  isChecked,
46
47
  isDisabled,
47
48
  isInvalid,
49
+ isReadOnly,
48
50
  isLoading,
49
51
  label,
50
52
  name,
@@ -52,11 +54,16 @@ const Toggle = forwardRef<ToggleProps, 'div'>((props, ref) => {
52
54
  onChange,
53
55
  tooltip,
54
56
  value,
57
+ valueText,
58
+ variant = 'dynamic',
55
59
  ...rest
56
60
  } = props;
61
+ const size: 'sm' | 'md' = variant === 'dynamic' ? 'md' : 'sm';
62
+ const css = useMultiStyleConfig('Switch', { withTooltip: !!tooltip, size, variant });
57
63
  const formControlProps = {
58
- isDisabled: isDisabled || isLoading,
59
- isInvalid: isInvalid || !!errorText,
64
+ sx: css.form,
65
+ isDisabled,
66
+ isInvalid,
60
67
  ...rest,
61
68
  ref,
62
69
  };
@@ -66,28 +73,75 @@ const Toggle = forwardRef<ToggleProps, 'div'>((props, ref) => {
66
73
  defaultChecked,
67
74
  id,
68
75
  isChecked,
69
- isDisabled: isDisabled || isLoading,
76
+ isDisabled,
77
+ isReadOnly,
78
+ isLoading,
70
79
  name,
71
80
  onBlur,
72
81
  onChange,
73
82
  value,
83
+ size,
84
+ };
85
+ const helperBlock = () => {
86
+ if (isLoading) {
87
+ return (
88
+ <Skeleton marginTop="4" maxWidth="120px" isActive paddingY="0.125rem">
89
+ <SkeletonBox height="12" />
90
+ </Skeleton>
91
+ );
92
+ }
93
+ return (
94
+ <>
95
+ {helperText && (
96
+ <FormHelperText sx={css.helperText} as="p">
97
+ {helperText}
98
+ </FormHelperText>
99
+ )}
100
+ </>
101
+ );
102
+ };
103
+ const switchComponent = () => {
104
+ if (tooltip)
105
+ return (
106
+ <Tooltip {...tooltip}>
107
+ <ToggleComponent {...switchProps} />
108
+ </Tooltip>
109
+ );
110
+ return <ToggleComponent {...switchProps} />;
74
111
  };
75
- const css = useMultiStyleConfig('Switch', { withTooltip: !!tooltip });
76
112
  return (
77
113
  <FormControl {...formControlProps}>
78
- <Tooltip isDisabled={!tooltip} {...tooltip}>
79
- <Box sx={css.labelWrapper}>
80
- <Switch {...switchProps} />
81
- {label && (
114
+ {variant === 'fixed' && (
115
+ <>
116
+ <Box>
82
117
  <FormLabel htmlFor={id} sx={css.label}>
83
118
  {label}
84
119
  </FormLabel>
85
- )}
86
- {isLoading && <ProgressSpinner sx={css.spinner} />}
87
- </Box>
88
- </Tooltip>
89
- {errorText && <FormErrorMessage as="p">{errorText}</FormErrorMessage>}
90
- {helperText && <FormHelperText as="p">{helperText}</FormHelperText>}
120
+ {helperBlock()}
121
+ </Box>
122
+ <Box display="flex" flexDirection="row" alignItems="center" gap="8">
123
+ {switchComponent()}
124
+ </Box>
125
+ </>
126
+ )}
127
+ {variant === 'dynamic' && (
128
+ <>
129
+ <FormLabel htmlFor={id} sx={css.label}>
130
+ {label}
131
+ </FormLabel>
132
+ <Box display="flex" flexDirection="row" alignItems="center" gap="8">
133
+ {switchComponent()}
134
+ {isLoading ? (
135
+ <Skeleton maxWidth="7.5rem" flex="1" isActive>
136
+ <SkeletonBox height="16" />
137
+ </Skeleton>
138
+ ) : (
139
+ <Text sx={css.valueText}>{valueText}</Text>
140
+ )}
141
+ </Box>
142
+ {helperBlock()}
143
+ </>
144
+ )}
91
145
  </FormControl>
92
146
  );
93
147
  });
@@ -0,0 +1,43 @@
1
+ import { Switch, SwitchProps, useMultiStyleConfig } from '@chakra-ui/react';
2
+ import Skeleton from '../Skeleton/Skeleton';
3
+ import SkeletonBox from '../Skeleton/SkeletonBox';
4
+ import Badge from '../Badge/Badge';
5
+
6
+ export interface ToggleComponentProps extends SwitchProps {
7
+ size?: 'md' | 'sm';
8
+ isLoading?: boolean;
9
+ }
10
+ const ToggleComponent = (props: ToggleComponentProps) => {
11
+ const { isLoading, isReadOnly, isChecked, ...rest } = props;
12
+ const { skeleton } = useMultiStyleConfig('Switch', props);
13
+ if (isLoading) {
14
+ return (
15
+ <Skeleton isActive>
16
+ <SkeletonBox __css={skeleton} />
17
+ </Skeleton>
18
+ );
19
+ }
20
+ if (isReadOnly) {
21
+ if (isChecked)
22
+ return (
23
+ <Badge
24
+ userSelect="none"
25
+ cursor="default"
26
+ w="40"
27
+ variant="subtle"
28
+ colorScheme="positive"
29
+ justifyContent="center"
30
+ >
31
+ ON
32
+ </Badge>
33
+ );
34
+ return (
35
+ <Badge userSelect="none" cursor="default" w="40" justifyContent="center">
36
+ OFF
37
+ </Badge>
38
+ );
39
+ }
40
+ return <Switch isReadOnly={isReadOnly} isChecked={isChecked} {...rest} />;
41
+ };
42
+
43
+ export default ToggleComponent;
@@ -0,0 +1,37 @@
1
+ import { ReactNode, useState } from 'react';
2
+ import { As, MergeWithAs } from '@chakra-ui/react';
3
+ import Dialog, { DialogProps } from '../Dialog/Dialog';
4
+
5
+ type ValueDialogProps<T> = { value?: T; children: (value: T) => ReactNode } & Omit<
6
+ DialogProps,
7
+ 'isOpen' | 'onCloseComplete' | 'children'
8
+ >;
9
+
10
+ type ComponentWithAs<Component extends As = 'section'> = {
11
+ <T, AsComponent extends As = Component>(
12
+ props: MergeWithAs<
13
+ React.ComponentProps<Component>,
14
+ React.ComponentProps<AsComponent>,
15
+ ValueDialogProps<T>,
16
+ AsComponent
17
+ >,
18
+ ): JSX.Element;
19
+ };
20
+ const ValueDialog: ComponentWithAs = ({ value, onClose, children, ...rest }) => {
21
+ const [closing, setClosing] = useState(false);
22
+ return (
23
+ <Dialog
24
+ isOpen={Boolean(value) || !closing}
25
+ onClose={() => setClosing(true)}
26
+ onCloseComplete={() => {
27
+ onClose();
28
+ setClosing(false);
29
+ }}
30
+ {...rest}
31
+ >
32
+ {value && children(value)}
33
+ </Dialog>
34
+ );
35
+ };
36
+
37
+ export default ValueDialog;
@@ -1,5 +1,5 @@
1
1
  import { createMultiStyleConfigHelpers } from '@chakra-ui/styled-system';
2
- import { ColorScheme } from 'src/types/bitkit';
2
+ import { ColorScheme } from '../../types/bitkit';
3
3
 
4
4
  const { defineMultiStyleConfig } = createMultiStyleConfigHelpers(['card', 'icon']);
5
5
 
package/src/index.ts CHANGED
@@ -203,6 +203,9 @@ export { default as Tr } from './Components/Table/Tr';
203
203
  export type { ToggleProps } from './Components/Toggle/Toggle';
204
204
  export { default as Toggle } from './Components/Toggle/Toggle';
205
205
 
206
+ export type { ToggleComponentProps } from './Components/Toggle/ToggleComponent';
207
+ export { default as ToggleComponent } from './Components/Toggle/ToggleComponent';
208
+
206
209
  export type { CollapseProps } from './Components/Collapse/Collapse';
207
210
  export { default as Collapse } from './Components/Collapse/Collapse';
208
211
 
@@ -289,7 +289,7 @@
289
289
  "subtle": "pal.neutral.93",
290
290
  "minimal": "pal.neutral.95",
291
291
  "disabled": "pal.neutral.95",
292
- "transparent": "pal.neutral.100 0%"
292
+ "transparent": "{color.pal.neutral.100} 0%"
293
293
  },
294
294
  "border": {
295
295
  "minimal": "pal.neutral.93",
@@ -520,9 +520,9 @@
520
520
  },
521
521
  "toggle": {
522
522
  "frameOn": "sys.success.bold",
523
- "frameOn-disabled": "rgba(sys.success.bold,0.5)",
523
+ "frameOn-disabled": "rgb(from var(--colors-sys-success-bold) r g b / 0.5)",
524
524
  "frameOff": "sys.neutral.bold",
525
- "frameOff-disabled": "rgba(sys.neutral.bold,0.5)",
525
+ "frameOff-disabled": "rgb(from var(--colors-sys-neutral-bold) r g b / 0.5)",
526
526
  "slideOn": "sys.bg.surface",
527
527
  "slideOn-disabled": "sys.bg.surface",
528
528
  "slideOff": "sys.bg.surface",
@@ -580,8 +580,8 @@
580
580
  }
581
581
  },
582
582
  "utilities": {
583
- "overlay": "rgba(sys.bg.contrast, 0.8)",
584
- "overlay-light": "rgba(sys.bg.contrast, 0.16)",
583
+ "overlay": "rgb(from var(--colors-sys-bg-contrast) r g b / 0.8)",
584
+ "overlay-light": "rgb(from var(--colors-sys-bg-contrast) r g b / 0.16)",
585
585
  "skeleton": "sys.bg.subtle",
586
586
  "skeleton-strong": "sys.fg.minimal"
587
587
  },
@@ -605,7 +605,7 @@
605
605
  "sys/bg/subtle": "pal.neutral.93",
606
606
  "sys/bg/minimal": "pal.neutral.95",
607
607
  "sys/bg/disabled": "pal.neutral.95",
608
- "sys/bg/transparent": "pal.neutral.100 0%",
608
+ "sys/bg/transparent": "{color.pal.neutral.100} 0%",
609
609
  "sys/border/minimal": "pal.neutral.93",
610
610
  "sys/border/subtle": "pal.neutral.90",
611
611
  "sys/border/strong": "pal.neutral.80",
@@ -786,9 +786,9 @@
786
786
  "input/checkbox/selection": "sys.interactive.base",
787
787
  "input/checkbox/selection-disabled": "sys.interactive.disabled",
788
788
  "input/toggle/frameOn": "sys.success.bold",
789
- "input/toggle/frameOn-disabled": "rgba(sys.success.bold,0.5)",
789
+ "input/toggle/frameOn-disabled": "rgb(from var(--colors-sys-success-bold) r g b / 0.5)",
790
790
  "input/toggle/frameOff": "sys.neutral.bold",
791
- "input/toggle/frameOff-disabled": "rgba(sys.neutral.bold,0.5)",
791
+ "input/toggle/frameOff-disabled": "rgb(from var(--colors-sys-neutral-bold) r g b / 0.5)",
792
792
  "input/toggle/slideOn": "sys.bg.surface",
793
793
  "input/toggle/slideOn-disabled": "sys.bg.surface",
794
794
  "input/toggle/slideOff": "sys.bg.surface",
@@ -829,8 +829,8 @@
829
829
  "status/neutral/border": "sys.neutral.muted",
830
830
  "status/neutral/icon": "sys.neutral.strong",
831
831
  "status/neutral/text": "sys.neutral.strong",
832
- "utilities/overlay": "rgba(sys.bg.contrast, 0.8)",
833
- "utilities/overlay-light": "rgba(sys.bg.contrast, 0.16)",
832
+ "utilities/overlay": "rgb(from var(--colors-sys-bg-contrast) r g b / 0.8)",
833
+ "utilities/overlay-light": "rgb(from var(--colors-sys-bg-contrast) r g b / 0.16)",
834
834
  "utilities/skeleton": "sys.bg.subtle",
835
835
  "utilities/skeleton-strong": "sys.fg.minimal"
836
836
  }