@spothero/ui 15.0.0-beta.4 → 15.1.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,6 +1,6 @@
1
1
  {
2
2
  "name": "@spothero/ui",
3
- "version": "15.0.0-beta.4",
3
+ "version": "15.1.0",
4
4
  "description": "SpotHero's React component UI library.",
5
5
  "main": "v2/index.js",
6
6
  "repository": "https://github.com/spothero/fe-monorepo",
@@ -8,8 +8,24 @@ import {
8
8
  } from '@chakra-ui/react';
9
9
 
10
10
  const FormControl = forwardRef(
11
- ({children, label, inputId, helperText, errorMessage, ...props}, ref) => (
12
- <ChakraFormControl {...props} ref={ref}>
11
+ (
12
+ {
13
+ children,
14
+ label,
15
+ inputId,
16
+ helperText,
17
+ errorMessage,
18
+ isFieldset,
19
+ ...props
20
+ },
21
+ ref
22
+ ) => (
23
+ <ChakraFormControl
24
+ {...props}
25
+ ref={ref}
26
+ as={isFieldset ? 'fieldset' : 'div'}
27
+ borderWidth="0"
28
+ >
13
29
  {label && (
14
30
  <FormLabel
15
31
  color="gray.600"
@@ -17,6 +33,7 @@ const FormControl = forwardRef(
17
33
  mb={2}
18
34
  fontSize="sm"
19
35
  htmlFor={inputId}
36
+ as={isFieldset ? 'legend' : 'label'}
20
37
  >
21
38
  {label}
22
39
  </FormLabel>
@@ -40,6 +57,7 @@ FormControl.propTypes = {
40
57
  helperText: PropTypes.string,
41
58
  errorMessage: PropTypes.string,
42
59
  children: PropTypes.element,
60
+ isFieldset: PropTypes.bool,
43
61
  };
44
62
 
45
63
  export default FormControl;
@@ -0,0 +1,50 @@
1
+ import React, {forwardRef} from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import {Box, Radio as ChakraRadio} from '@chakra-ui/react';
4
+
5
+ const Radio = forwardRef(
6
+ (
7
+ {
8
+ defaultChecked,
9
+ isChecked,
10
+ isDisabled,
11
+ value,
12
+ helperText,
13
+ children,
14
+ ...props
15
+ },
16
+ ref
17
+ ) => {
18
+ return (
19
+ <ChakraRadio
20
+ ref={ref}
21
+ defaultChecked={defaultChecked}
22
+ isChecked={isChecked}
23
+ isDisabled={isDisabled}
24
+ isFocusable={!isDisabled}
25
+ value={value}
26
+ {...props}
27
+ alignItems="start"
28
+ >
29
+ {children}
30
+ {helperText && (
31
+ <Box color="gray.600" fontSize="xs">
32
+ {helperText}
33
+ </Box>
34
+ )}
35
+ </ChakraRadio>
36
+ );
37
+ }
38
+ );
39
+
40
+ Radio.propTypes = {
41
+ children: PropTypes.oneOfType([PropTypes.string, PropTypes.element])
42
+ .isRequired,
43
+ defaultChecked: PropTypes.bool,
44
+ isChecked: PropTypes.bool,
45
+ isDisabled: PropTypes.bool,
46
+ value: PropTypes.string.isRequired,
47
+ helperText: PropTypes.string,
48
+ };
49
+
50
+ export default Radio;
@@ -0,0 +1,155 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import Radio from './Radio';
4
+ import RadioGroup from './RadioGroup';
5
+
6
+ export default {
7
+ title: 'v2/Radio',
8
+ component: Radio,
9
+ parameters: {
10
+ importBy: 'Radio',
11
+ removeBaseHtmlClass: true,
12
+ chakraLink: 'https://chakra-ui.com/docs/components/radio',
13
+ },
14
+ };
15
+
16
+ export const Individual = props => {
17
+ return (
18
+ <Radio value="1" {...props}>
19
+ Option 1
20
+ </Radio>
21
+ );
22
+ };
23
+
24
+ Individual.argTypes = {
25
+ helperText: {
26
+ control: {type: 'text'},
27
+ },
28
+ isDisabled: {
29
+ control: {
30
+ type: 'boolean',
31
+ },
32
+ },
33
+ isChecked: {
34
+ control: {
35
+ type: 'boolean',
36
+ },
37
+ },
38
+ children: {
39
+ table: {
40
+ disable: true,
41
+ },
42
+ },
43
+ defaultChecked: {
44
+ table: {
45
+ disable: true,
46
+ },
47
+ },
48
+ value: {
49
+ table: {
50
+ disable: true,
51
+ },
52
+ },
53
+ };
54
+
55
+ Individual.args = {
56
+ helperText: 'Helper text',
57
+ isDisabled: false,
58
+ isChecked: false,
59
+ };
60
+
61
+ Individual.propTypes = {
62
+ children: PropTypes.oneOfType([PropTypes.string, PropTypes.element])
63
+ .isRequired,
64
+ defaultChecked: PropTypes.bool,
65
+ isChecked: PropTypes.bool,
66
+ isDisabled: PropTypes.bool,
67
+ value: PropTypes.string.isRequired,
68
+ helperText: PropTypes.string,
69
+ };
70
+
71
+ export const Group = props => {
72
+ return (
73
+ <RadioGroup
74
+ name="example1"
75
+ defaultValue="3"
76
+ id="example1"
77
+ label="Which option?"
78
+ {...props}
79
+ >
80
+ <Radio value="1">Option 1</Radio>
81
+ <Radio value="2">Option 2</Radio>
82
+ <Radio value="3">Option 3</Radio>
83
+ <Radio value="4">Option 4</Radio>
84
+ </RadioGroup>
85
+ );
86
+ };
87
+
88
+ Group.title = 'v2/RadioGroup';
89
+ Group.component = RadioGroup;
90
+ Group.parameters = {
91
+ importBy: 'RadioGroup',
92
+ };
93
+
94
+ Group.argTypes = {
95
+ direction: {
96
+ options: ['column', 'row'],
97
+ control: {
98
+ type: 'radio',
99
+ },
100
+ },
101
+ isDisabled: {
102
+ control: {
103
+ type: 'boolean',
104
+ },
105
+ },
106
+ children: {
107
+ table: {
108
+ disable: true,
109
+ },
110
+ },
111
+ defaultChecked: {
112
+ table: {
113
+ disable: true,
114
+ },
115
+ },
116
+ value: {
117
+ table: {
118
+ disable: true,
119
+ },
120
+ },
121
+ isChecked: {
122
+ table: {
123
+ disable: true,
124
+ },
125
+ },
126
+ helperText: {
127
+ table: {
128
+ disable: true,
129
+ },
130
+ },
131
+ };
132
+
133
+ Group.args = {
134
+ direction: 'column',
135
+ isDisabled: false,
136
+ isInvalid: false,
137
+ isRequired: false,
138
+ label: 'Label',
139
+ errorMessage: 'Error message',
140
+ };
141
+
142
+ Group.propTypes = {
143
+ children: PropTypes.node,
144
+ defaultValue: PropTypes.string,
145
+ id: PropTypes.string.isRequired,
146
+ label: PropTypes.string,
147
+ errorMessage: PropTypes.string,
148
+ isDisabled: PropTypes.bool,
149
+ isInvalid: PropTypes.bool,
150
+ isRequired: PropTypes.bool,
151
+ name: PropTypes.string,
152
+ onChange: PropTypes.func,
153
+ value: PropTypes.string,
154
+ direction: PropTypes.oneOf(['row', 'column']),
155
+ };
@@ -0,0 +1,69 @@
1
+ import React, {forwardRef} from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import {RadioGroup as ChakraRadioGroup, Stack} from '@chakra-ui/react';
4
+ import FormControl from '../FormControl/FormControl';
5
+
6
+ const RadioGroup = forwardRef(
7
+ (
8
+ {
9
+ label,
10
+ errorMessage,
11
+ defaultValue,
12
+ isDisabled,
13
+ isInvalid,
14
+ isRequired,
15
+ name,
16
+ onChange,
17
+ value,
18
+ children,
19
+ direction,
20
+ ...props
21
+ },
22
+ ref
23
+ ) => {
24
+ return (
25
+ <FormControl
26
+ isInvalid={isInvalid}
27
+ isDisabled={isDisabled}
28
+ isRequired={isRequired}
29
+ errorMessage={errorMessage}
30
+ label={label}
31
+ inputId={props.id}
32
+ isRadio
33
+ >
34
+ <ChakraRadioGroup
35
+ ref={ref}
36
+ defaultValue={defaultValue}
37
+ name={name}
38
+ onChange={onChange}
39
+ value={value}
40
+ {...props}
41
+ >
42
+ <Stack
43
+ direction={direction ? direction : 'column'}
44
+ spacing={direction === 'row' ? 8 : 4}
45
+ >
46
+ {children}
47
+ </Stack>
48
+ </ChakraRadioGroup>
49
+ </FormControl>
50
+ );
51
+ }
52
+ );
53
+
54
+ RadioGroup.propTypes = {
55
+ children: PropTypes.node,
56
+ defaultValue: PropTypes.string,
57
+ id: PropTypes.string.isRequired,
58
+ label: PropTypes.string,
59
+ errorMessage: PropTypes.string,
60
+ isDisabled: PropTypes.bool,
61
+ isInvalid: PropTypes.bool,
62
+ isRequired: PropTypes.bool,
63
+ name: PropTypes.string,
64
+ onChange: PropTypes.func,
65
+ value: PropTypes.string,
66
+ direction: PropTypes.oneOf(['row', 'column']),
67
+ };
68
+
69
+ export default RadioGroup;
@@ -0,0 +1,2 @@
1
+ export {default as Radio} from './Radio';
2
+ export {default as RadioGroup} from './RadioGroup';
@@ -0,0 +1,52 @@
1
+ import merge from 'lodash/merge';
2
+ import chakraDefaultTheme from '@chakra-ui/theme';
3
+
4
+ const parts = ['control', 'label'];
5
+
6
+ const baseStyle = {
7
+ control: {
8
+ borderRadius: '50%',
9
+ borderWidth: '1px',
10
+ borderColor: 'gray.dark',
11
+ backgroundColor: 'white',
12
+ minWidth: 5,
13
+ minHeight: 5,
14
+ marginTop: 1,
15
+ _checked: {
16
+ borderWidth: 0,
17
+ color: 'white',
18
+ backgroundColor: 'primary.default',
19
+ _before: {
20
+ content: '""',
21
+ display: 'inline-block',
22
+ position: 'relative',
23
+ width: 2,
24
+ height: 2,
25
+ borderRadius: '50%',
26
+ background: 'currentcolor',
27
+ },
28
+ },
29
+ _focus: {
30
+ boxShadow: t => `0 0 1px 2px ${t.colors.primary['300']}`,
31
+ },
32
+ _disabled: {
33
+ borderColor: 'gray.200',
34
+ _checked: {
35
+ backgroundColor: 'gray.200',
36
+ },
37
+ },
38
+ },
39
+ label: {
40
+ fontSize: 'base',
41
+ color: 'black',
42
+ marginLeft: 3,
43
+ _disabled: {
44
+ color: 'gray.200',
45
+ },
46
+ },
47
+ };
48
+
49
+ export default merge(chakraDefaultTheme.components.Radio, {
50
+ parts,
51
+ baseStyle,
52
+ });
@@ -25,6 +25,7 @@ export {default as Checkbox} from './Checkbox';
25
25
  export {default as Input} from './Input';
26
26
  export {Popover, PopoverTrigger, PopoverContent} from './Popover';
27
27
  export {Modal} from './Modal';
28
+ export {Radio, RadioGroup} from './Radio';
28
29
 
29
30
  // generic chakra reexports
30
31
  export {
@@ -13,3 +13,4 @@ export {default as Checkbox} from './Checkbox/styles';
13
13
  export {default as Popover} from './Popover/styles';
14
14
  export {default as Input} from './Input/styles';
15
15
  export {default as Modal} from './Modal/styles';
16
+ export {default as Radio} from './Radio/styles';