@bitrise/bitkit 10.17.1 → 10.18.0-alpha-chakra.1

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": "10.17.1",
4
+ "version": "10.18.0-alpha-chakra.1",
5
5
  "repository": "git@github.com:bitrise-io/bitkit.git",
6
6
  "main": "src/index.ts",
7
7
  "license": "UNLICENSED",
@@ -0,0 +1,18 @@
1
+ import { ComponentMeta } from '@storybook/react';
2
+ import Toggle from './Toggle';
3
+
4
+ export default {
5
+ title: 'Components/Toggle',
6
+ component: Toggle,
7
+ } as ComponentMeta<typeof Toggle>;
8
+
9
+ export const WithProps = {
10
+ args: {
11
+ children: 'Toggle the toggle',
12
+ defaultChecked: false,
13
+ helpherText:
14
+ 'Inline help. Maecenas a turpis tortor. Nunc vitae libero tempor, ullamcorper purus quis, mattis tellus.',
15
+ isDisabled: false,
16
+ isLoading: false,
17
+ },
18
+ };
@@ -0,0 +1,77 @@
1
+ import type { ComponentStyleConfig } from '@chakra-ui/theme';
2
+
3
+ const ToggleTheme: ComponentStyleConfig = {
4
+ baseStyle: {
5
+ formControl: {
6
+ display: 'flex',
7
+ alignItems: 'center',
8
+ flexWrap: 'wrap',
9
+ gap: '8',
10
+ },
11
+ track: {
12
+ boxSizing: 'border-box',
13
+ width: '48',
14
+ height: '24',
15
+ padding: '0.125rem',
16
+ backgroundColor: 'neutral.50',
17
+ borderRadius: '12',
18
+ transition: '100ms',
19
+ _disabled: {
20
+ backgroundColor: 'neutral.93',
21
+ cursor: 'not-allowed',
22
+ },
23
+ _checked: {
24
+ backgroundColor: 'turquoise.70',
25
+ _disabled: {
26
+ backgroundColor: 'turquoise.80',
27
+ },
28
+ },
29
+ _before: {
30
+ content: '""',
31
+ 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")`,
32
+ backgroundPositionX: '0.125rem',
33
+ position: 'absolute',
34
+ left: 0,
35
+ right: '50%',
36
+ top: 0,
37
+ bottom: 0,
38
+ },
39
+ _after: {
40
+ content: '""',
41
+ 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")`,
42
+ backgroundPositionX: '-0.125rem',
43
+ position: 'absolute',
44
+ left: '50%',
45
+ right: 0,
46
+ top: 0,
47
+ bottom: 0,
48
+ },
49
+ },
50
+ thumb: {
51
+ position: 'relative',
52
+ zIndex: '1',
53
+ width: '1.25rem',
54
+ height: '1.25rem',
55
+ borderRadius: '24',
56
+ bgGradient: 'linear(to-b, neutral.93 3.43%, neutral.100 100%)',
57
+ transition: '100ms',
58
+ _checked: {
59
+ transform: 'translate(24px)',
60
+ },
61
+ },
62
+ spinner: {
63
+ width: '16',
64
+ height: '16',
65
+ color: 'neutral.70',
66
+ },
67
+ helpherText: {
68
+ fontSize: '2',
69
+ lineHeight: '2',
70
+ width: '100%',
71
+ marginTop: '-4px',
72
+ color: 'neutral.40',
73
+ },
74
+ },
75
+ };
76
+
77
+ export default ToggleTheme;
@@ -0,0 +1,51 @@
1
+ import { ReactNode } from 'react';
2
+ import {
3
+ FormControl,
4
+ FormControlProps,
5
+ FormLabel,
6
+ Spinner,
7
+ Switch,
8
+ SwitchProps,
9
+ forwardRef,
10
+ useMultiStyleConfig,
11
+ } from '@chakra-ui/react';
12
+ import Text from '../Text/Text';
13
+
14
+ export interface ToggleProps extends FormControlProps {
15
+ children?: ReactNode;
16
+ defaultChecked?: SwitchProps['defaultChecked'];
17
+ id?: SwitchProps['id'];
18
+ isChecked?: SwitchProps['isChecked'];
19
+ isDisabled?: SwitchProps['isDisabled'];
20
+ isLoading?: boolean;
21
+ helpherText?: string;
22
+ onChange?: SwitchProps['onChange'];
23
+ value?: SwitchProps['value'];
24
+ }
25
+
26
+ /**
27
+ * The Toggle component is used as an alternative for the checkbox component.
28
+ */
29
+ const Toggle = forwardRef<ToggleProps, 'div'>((props, ref) => {
30
+ const { children, defaultChecked, helpherText, id, isChecked, isDisabled, isLoading, onChange, value, ...rest } =
31
+ props;
32
+ const switchProps = {
33
+ defaultChecked,
34
+ id,
35
+ isChecked,
36
+ isDisabled: isDisabled || isLoading,
37
+ onChange,
38
+ value,
39
+ };
40
+ const css = useMultiStyleConfig('Switch');
41
+ return (
42
+ <FormControl sx={css.formControl} {...rest} ref={ref}>
43
+ <Switch {...switchProps} />
44
+ <FormLabel htmlFor={id}>{children}</FormLabel>
45
+ {isLoading && <Spinner sx={css.spinner} />}
46
+ {helpherText && <Text sx={css.helpherText}>{helpherText}</Text>}
47
+ </FormControl>
48
+ );
49
+ });
50
+
51
+ export default Toggle;
package/src/index.ts CHANGED
@@ -192,3 +192,6 @@ export { default as Thead } from './Components/Table/Thead';
192
192
 
193
193
  export type { TableRowProps } from './Components/Table/Tr';
194
194
  export { default as Tr } from './Components/Table/Tr';
195
+
196
+ export type { ToggleProps } from './Components/Toggle/Toggle';
197
+ export { default as Toggle } from './Components/Toggle/Toggle';
package/src/old.ts CHANGED
@@ -94,9 +94,6 @@ export { default as OldTableRow } from './Old/Table/TableRow';
94
94
  export type { Props as TextareaProps } from './Old/Textarea/Textarea';
95
95
  export { default as Textarea } from './Old/Textarea/Textarea';
96
96
 
97
- export type { Props as ToggleProps } from './Old/Toggle/Toggle';
98
- export { default as Toggle } from './Old/Toggle/Toggle';
99
-
100
97
  export type { Props as VisibilityProps } from './Old/Visibility/Visibility';
101
98
  export { default as Visibility } from './Old/Visibility/Visibility';
102
99
 
package/src/theme.ts CHANGED
@@ -23,6 +23,7 @@ import Alert from './Foundations/Themes/Alert.theme';
23
23
  import Tooltip from './Components/Tooltip/Tooltip.theme';
24
24
  import CloseButton from './Components/CloseButton/CloseButton.theme';
25
25
  import Popover from './Components/Popover/Popover.theme';
26
+ import Toggle from './Components/Toggle/Toggle.theme';
26
27
 
27
28
  import breakpoints from './Foundations/Breakpoints/Breakpoints';
28
29
  import colors from './Foundations/Colors/Colors';
@@ -93,6 +94,7 @@ const theme = {
93
94
  CloseButton,
94
95
  Input,
95
96
  Popover,
97
+ Switch: Toggle,
96
98
  },
97
99
  };
98
100