@spothero/ui 15.6.0 → 15.7.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 +1 -1
- package/styles/v2/components/Switch/Switch.jsx +52 -0
- package/styles/v2/components/Switch/Switch.stories.js +88 -0
- package/styles/v2/components/Switch/index.js +1 -0
- package/styles/v2/components/Switch/styles/index.js +17 -0
- package/styles/v2/components/index.js +1 -0
- package/styles/v2/components/styles.js +1 -0
- package/v2/index.js +1 -1
- package/v2/index.js.map +1 -1
package/package.json
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React, {forwardRef} from 'react';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
|
|
5
|
+
import {Switch as ChakraSwitch} from '@chakra-ui/react';
|
|
6
|
+
|
|
7
|
+
import FormControl from '../FormControl/FormControl';
|
|
8
|
+
|
|
9
|
+
const Switch = forwardRef(
|
|
10
|
+
(
|
|
11
|
+
{
|
|
12
|
+
label,
|
|
13
|
+
helperText,
|
|
14
|
+
errorMessage,
|
|
15
|
+
isInvalid,
|
|
16
|
+
isDisabled,
|
|
17
|
+
isRequired,
|
|
18
|
+
...props
|
|
19
|
+
},
|
|
20
|
+
ref
|
|
21
|
+
) => {
|
|
22
|
+
const classes = cn({'FormElement-contains-error': isInvalid});
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<FormControl
|
|
26
|
+
isInvalid={isInvalid}
|
|
27
|
+
isDisabled={isDisabled}
|
|
28
|
+
isRequired={isRequired}
|
|
29
|
+
errorMessage={errorMessage}
|
|
30
|
+
helperText={helperText}
|
|
31
|
+
label={label}
|
|
32
|
+
inputId={props.id}
|
|
33
|
+
>
|
|
34
|
+
<ChakraSwitch ref={ref} className={classes} {...props} />
|
|
35
|
+
</FormControl>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
Switch.propTypes = {
|
|
41
|
+
isChecked: PropTypes.bool,
|
|
42
|
+
defaultChecked: PropTypes.bool,
|
|
43
|
+
id: PropTypes.string.isRequired,
|
|
44
|
+
label: PropTypes.string,
|
|
45
|
+
helperText: PropTypes.string,
|
|
46
|
+
errorMessage: PropTypes.string,
|
|
47
|
+
isInvalid: PropTypes.bool,
|
|
48
|
+
isDisabled: PropTypes.bool,
|
|
49
|
+
isRequired: PropTypes.bool,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default Switch;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
|
|
4
|
+
import Component from './Switch';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: 'v2/Switch',
|
|
8
|
+
component: Component,
|
|
9
|
+
parameters: {
|
|
10
|
+
removeBaseHtmlClass: true,
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const SwitchTemplate = props => <Component {...props} />;
|
|
15
|
+
|
|
16
|
+
SwitchTemplate.propTypes = {
|
|
17
|
+
isChecked: PropTypes.bool,
|
|
18
|
+
defaultChecked: PropTypes.bool,
|
|
19
|
+
id: PropTypes.string.isRequired,
|
|
20
|
+
label: PropTypes.string,
|
|
21
|
+
helperText: PropTypes.string,
|
|
22
|
+
errorMessage: PropTypes.string,
|
|
23
|
+
isInvalid: PropTypes.bool,
|
|
24
|
+
isDisabled: PropTypes.bool,
|
|
25
|
+
isRequired: PropTypes.bool,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const Switch = SwitchTemplate.bind({});
|
|
29
|
+
|
|
30
|
+
Switch.argTypes = {
|
|
31
|
+
isChecked: {
|
|
32
|
+
control: {
|
|
33
|
+
type: 'boolean',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
defaultChecked: {
|
|
37
|
+
control: {
|
|
38
|
+
type: 'boolean',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
id: {
|
|
42
|
+
control: {
|
|
43
|
+
type: 'text',
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
label: {
|
|
47
|
+
control: {
|
|
48
|
+
type: 'text',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
helperText: {
|
|
52
|
+
control: {
|
|
53
|
+
type: 'text',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
errorMessage: {
|
|
57
|
+
control: {
|
|
58
|
+
type: 'text',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
isInvalid: {
|
|
62
|
+
control: {
|
|
63
|
+
type: 'boolean',
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
isDisabled: {
|
|
67
|
+
control: {
|
|
68
|
+
type: 'boolean',
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
isRequired: {
|
|
72
|
+
control: {
|
|
73
|
+
type: 'boolean',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
Switch.args = {
|
|
79
|
+
isChecked: true,
|
|
80
|
+
defaultChecked: false,
|
|
81
|
+
id: 'Switch_Id',
|
|
82
|
+
label: 'Label',
|
|
83
|
+
helperText: 'Helper Text',
|
|
84
|
+
errorMessage: 'Error Message',
|
|
85
|
+
isInvalid: false,
|
|
86
|
+
isDisabled: false,
|
|
87
|
+
isRequired: false,
|
|
88
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {default} from './Switch';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import merge from 'lodash/merge';
|
|
2
|
+
import chakraDefaultTheme from '@chakra-ui/theme';
|
|
3
|
+
|
|
4
|
+
const overrides = {
|
|
5
|
+
defaultProps: {
|
|
6
|
+
colorScheme: 'primary',
|
|
7
|
+
size: 'lg',
|
|
8
|
+
},
|
|
9
|
+
baseStyle: props =>
|
|
10
|
+
merge(chakraDefaultTheme.components.Switch.baseStyle(props), {
|
|
11
|
+
track: {
|
|
12
|
+
bg: 'gray.medium',
|
|
13
|
+
},
|
|
14
|
+
}),
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default {...chakraDefaultTheme.components.Switch, ...overrides};
|
|
@@ -9,6 +9,7 @@ export * from './Button';
|
|
|
9
9
|
export * from './Table';
|
|
10
10
|
export {TabList, TabPanels, Tab, TabPanel, default as Tabs} from './Tabs';
|
|
11
11
|
export {default as Select} from './Select';
|
|
12
|
+
export {default as Switch} from './Switch';
|
|
12
13
|
export {default as Link} from './Link/Link';
|
|
13
14
|
export {default as Text} from './Text/Text';
|
|
14
15
|
export {default as Grid, GridItem} from './Grid';
|
|
@@ -10,6 +10,7 @@ export {default as Heading} from './Heading/Heading.styles';
|
|
|
10
10
|
export {default as Tabs} from './Tabs/styles';
|
|
11
11
|
export {default as Select} from './Select/styles';
|
|
12
12
|
export {default as Checkbox} from './Checkbox/styles';
|
|
13
|
+
export {default as Switch} from './Switch/styles';
|
|
13
14
|
export {default as Popover} from './Popover/styles';
|
|
14
15
|
export {default as Input} from './Input/styles';
|
|
15
16
|
export {default as Modal} from './Modal/styles';
|