@bitrise/bitkit 10.17.0 → 10.18.0-alpha-chakra.2
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 +1 -1
- package/src/Components/Tabs/Tabs.tsx +25 -11
- package/src/Components/Toggle/Toggle.stories.tsx +18 -0
- package/src/Components/Toggle/Toggle.theme.ts +78 -0
- package/src/Components/Toggle/Toggle.tsx +53 -0
- package/src/index.ts +3 -0
- package/src/old.ts +0 -3
- package/src/theme.ts +2 -0
- package/src/tsconfig.tsbuildinfo +1 -1
- package/src/Old/Toggle/Toggle.css +0 -84
- package/src/Old/Toggle/Toggle.tsx +0 -68
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { isValidElement, ReactElement,
|
|
1
|
+
import React, { isValidElement, ReactElement, useState } from 'react';
|
|
2
2
|
import { Tabs as ChakraTabs, TabsProps as ChakraTabsProps, forwardRef } from '@chakra-ui/react';
|
|
3
3
|
import { useHistory } from '../../hooks';
|
|
4
4
|
|
|
@@ -15,6 +15,25 @@ const getTabIds = (props: TabsProps): string[] => {
|
|
|
15
15
|
return tabs.filter((item) => isValidElement(item)).map((item) => item.props.id);
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
const getTabIndexFromSearchParams = (tabIds: string[], defaultIndex?: number) => {
|
|
19
|
+
if (typeof window === 'undefined') {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
24
|
+
const tabName = searchParams.get('tab');
|
|
25
|
+
if (!tabName) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const index = tabIds.indexOf(tabName);
|
|
30
|
+
if (index === -1) {
|
|
31
|
+
return defaultIndex;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return index;
|
|
35
|
+
};
|
|
36
|
+
|
|
18
37
|
/**
|
|
19
38
|
* An accessible tabs component that provides keyboard interactions and ARIA attributes described in the WAI-ARIA Tabs Design Pattern.
|
|
20
39
|
*/
|
|
@@ -23,21 +42,16 @@ const Tabs = forwardRef<TabsProps, 'div'>((props, ref) => {
|
|
|
23
42
|
const tabIds = getTabIds(props);
|
|
24
43
|
const defaultIndex = tabIds.indexOf(defaultTab) > -1 ? tabIds.indexOf(defaultTab) : 0;
|
|
25
44
|
|
|
26
|
-
const {
|
|
27
|
-
const [actualIndex, setActualIndex] = useState(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (withHistory && searchParams.get('tab')) {
|
|
31
|
-
const tabName = searchParams.get('tab') || '';
|
|
32
|
-
const index = tabIds.indexOf(tabName) > -1 ? tabIds.indexOf(tabName) : defaultIndex;
|
|
33
|
-
setActualIndex(index);
|
|
34
|
-
}
|
|
35
|
-
}, []);
|
|
45
|
+
const { replace } = useHistory();
|
|
46
|
+
const [actualIndex, setActualIndex] = useState(
|
|
47
|
+
withHistory ? getTabIndexFromSearchParams(tabIds, defaultIndex) : defaultIndex,
|
|
48
|
+
);
|
|
36
49
|
|
|
37
50
|
const onTabChange = (index: number) => {
|
|
38
51
|
const tabId = tabIds[index];
|
|
39
52
|
setActualIndex(index);
|
|
40
53
|
if (withHistory) {
|
|
54
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
41
55
|
if (tabId) {
|
|
42
56
|
searchParams.set('tab', tabId);
|
|
43
57
|
} else {
|
|
@@ -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,78 @@
|
|
|
1
|
+
import type { ComponentStyleConfig } from '@chakra-ui/theme';
|
|
2
|
+
|
|
3
|
+
const ToggleTheme: ComponentStyleConfig = {
|
|
4
|
+
baseStyle: {
|
|
5
|
+
formControl: {
|
|
6
|
+
display: 'flex',
|
|
7
|
+
flexWrap: 'wrap',
|
|
8
|
+
gap: '8',
|
|
9
|
+
},
|
|
10
|
+
track: {
|
|
11
|
+
boxSizing: 'border-box',
|
|
12
|
+
width: '48',
|
|
13
|
+
height: '24',
|
|
14
|
+
padding: '0.125rem',
|
|
15
|
+
backgroundColor: 'neutral.50',
|
|
16
|
+
borderRadius: '12',
|
|
17
|
+
transition: '100ms',
|
|
18
|
+
_disabled: {
|
|
19
|
+
backgroundColor: 'neutral.93',
|
|
20
|
+
cursor: 'not-allowed',
|
|
21
|
+
},
|
|
22
|
+
_checked: {
|
|
23
|
+
backgroundColor: 'turquoise.70',
|
|
24
|
+
_disabled: {
|
|
25
|
+
backgroundColor: 'turquoise.80',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
_before: {
|
|
29
|
+
content: '""',
|
|
30
|
+
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")`,
|
|
31
|
+
backgroundPositionX: '0.125rem',
|
|
32
|
+
position: 'absolute',
|
|
33
|
+
left: 0,
|
|
34
|
+
right: '50%',
|
|
35
|
+
top: 0,
|
|
36
|
+
bottom: 0,
|
|
37
|
+
},
|
|
38
|
+
_after: {
|
|
39
|
+
content: '""',
|
|
40
|
+
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")`,
|
|
41
|
+
backgroundPositionX: '-0.125rem',
|
|
42
|
+
position: 'absolute',
|
|
43
|
+
left: '50%',
|
|
44
|
+
right: 0,
|
|
45
|
+
top: 0,
|
|
46
|
+
bottom: 0,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
thumb: {
|
|
50
|
+
position: 'relative',
|
|
51
|
+
zIndex: '1',
|
|
52
|
+
width: '1.25rem',
|
|
53
|
+
height: '1.25rem',
|
|
54
|
+
borderRadius: '24',
|
|
55
|
+
bgGradient: 'linear(to-b, neutral.93 3.43%, neutral.100 100%)',
|
|
56
|
+
transition: '100ms',
|
|
57
|
+
_checked: {
|
|
58
|
+
transform: 'translate(24px)',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
label: {
|
|
62
|
+
flexBasis: 'calc(100% - 56px)',
|
|
63
|
+
},
|
|
64
|
+
spinner: {
|
|
65
|
+
width: '16',
|
|
66
|
+
height: '16',
|
|
67
|
+
color: 'neutral.70',
|
|
68
|
+
},
|
|
69
|
+
helpherText: {
|
|
70
|
+
fontSize: '2',
|
|
71
|
+
lineHeight: '2',
|
|
72
|
+
marginTop: '-4px',
|
|
73
|
+
color: 'neutral.40',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export default ToggleTheme;
|
|
@@ -0,0 +1,53 @@
|
|
|
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 sx={css.label} htmlFor={id}>
|
|
45
|
+
{children}
|
|
46
|
+
</FormLabel>
|
|
47
|
+
{isLoading && <Spinner sx={css.spinner} />}
|
|
48
|
+
{helpherText && <Text sx={css.helpherText}>{helpherText}</Text>}
|
|
49
|
+
</FormControl>
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
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
|
|