@popsure/dirty-swan 0.41.14 → 0.41.15

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.
@@ -1,4 +1,3 @@
1
-
2
1
  import { useState } from 'react';
3
2
  import { Radio, RadioProps } from '.';
4
3
  import { images } from '../../../util/images';
@@ -8,21 +7,22 @@ const story = {
8
7
  component: Radio,
9
8
  argTypes: {
10
9
  options: {
11
- description: 'Object that contains the possible options for rendering in the input.',
10
+ description:
11
+ 'Object that contains the possible options for rendering in the input.',
12
12
  defaultValue: {
13
- CAT:{
13
+ CAT: {
14
14
  title: 'Cat',
15
- description: 'At least 1'
15
+ description: 'At least 1',
16
16
  },
17
- DOG:{
17
+ DOG: {
18
18
  title: 'Dog',
19
- description: 'At least 2'
19
+ description: 'At least 2',
20
20
  },
21
- NONE:{
21
+ NONE: {
22
22
  title: 'None',
23
- description: 'No pets'
24
- }
25
- }
23
+ description: 'No pets',
24
+ },
25
+ },
26
26
  },
27
27
  value: {
28
28
  description: 'Current checked values.',
@@ -31,122 +31,137 @@ const story = {
31
31
  description: 'Function called everytime a value changes.',
32
32
  action: true,
33
33
  table: {
34
- category: "Callbacks",
34
+ category: 'Callbacks',
35
35
  },
36
36
  },
37
37
  wide: {
38
- description: 'Property that defines if options should fill 100% of available horizontal space',
39
- defaultValue: false
38
+ description:
39
+ 'Property that defines if options should fill 100% of available horizontal space',
40
+ defaultValue: false,
40
41
  },
41
42
  inlineLayout: {
42
- description: 'Property that defines if options should show inline instead of block. Check inline radio options story for examples.',
43
- defaultValue: false
43
+ description:
44
+ 'Property that defines if options should show inline instead of block. Check inline radio options story for examples.',
45
+ defaultValue: false,
44
46
  },
45
47
  classNames: {
46
48
  description: 'ClassNames for custom styling',
47
49
  defaultValue: {
48
50
  container: '',
49
51
  label: '',
50
- option: ''
51
- }
52
+ option: '',
53
+ },
52
54
  },
53
55
  bordered: {
54
56
  description: 'Property that defines if option should show with border',
55
- defaultValue: true
57
+ defaultValue: true,
56
58
  },
57
- }
59
+ disabled: {
60
+ description:
61
+ 'Property that defines if the input and corresponding label are disabled and not clickable',
62
+ defaultValue: false,
63
+ },
64
+ },
58
65
  };
59
66
 
60
- export const RadioStory = ({
67
+ export const RadioStory = ({
61
68
  onChange,
62
69
  options,
63
70
  wide,
64
71
  classNames,
65
72
  inlineLayout,
66
73
  bordered,
74
+ disabled,
67
75
  }: RadioProps<string>) => {
68
76
  const [checkedValues, setCheckedValues] = useState<string>();
69
77
 
70
78
  const handleOnChange = (newValue: string) => {
71
79
  setCheckedValues(newValue);
72
80
  onChange(newValue);
73
- }
81
+ };
74
82
 
75
83
  return (
76
- <Radio
84
+ <Radio
77
85
  wide={wide}
78
- options={options}
86
+ options={options}
79
87
  onChange={handleOnChange}
80
88
  value={checkedValues}
81
89
  classNames={classNames}
82
90
  inlineLayout={inlineLayout}
83
91
  bordered={bordered}
92
+ disabled={disabled}
84
93
  />
85
94
  );
86
- }
95
+ };
87
96
 
88
- export const RadioWithCustomWrapperStyles = ({ onChange }: RadioProps<string>) => {
97
+ export const RadioWithCustomWrapperStyles = ({
98
+ onChange,
99
+ }: RadioProps<string>) => {
89
100
  const [checkedValues, setCheckedValues] = useState<string>();
90
101
 
91
102
  const handleOnChange = (newValue: string) => {
92
103
  setCheckedValues(newValue);
93
104
  onChange(newValue);
94
- }
105
+ };
95
106
 
96
107
  return (
97
- <Radio
108
+ <Radio
98
109
  onChange={handleOnChange}
99
110
  value={checkedValues}
100
111
  options={{
101
112
  CAT1: 'Cat',
102
113
  DOG1: 'Dog',
103
- }}
104
- classNames={{ container: "p32 bg-primary-300 br24 bs-lg" }}
114
+ }}
115
+ classNames={{ container: 'p32 bg-primary-300 br24 bs-lg' }}
105
116
  />
106
117
  );
107
- }
118
+ };
108
119
 
109
- export const RadioWithCustomOptionStyles = ({ onChange }: RadioProps<string>) => {
120
+ export const RadioWithCustomOptionStyles = ({
121
+ onChange,
122
+ }: RadioProps<string>) => {
110
123
  const [checkedValues, setCheckedValues] = useState<string>();
111
124
 
112
125
  const handleOnChange = (newValue: string) => {
113
126
  setCheckedValues(newValue);
114
127
  onChange(newValue);
115
- }
128
+ };
116
129
 
117
130
  return (
118
- <Radio
131
+ <Radio
119
132
  onChange={handleOnChange}
120
133
  value={checkedValues}
121
134
  options={{
122
135
  CAT2: 'Cat',
123
136
  DOG2: 'Dog',
124
- }}
125
- classNames={{ option: "mb32 p24 bg-green-100 br12 bs-lg" }}
137
+ }}
138
+ classNames={{ option: 'mb32 p24 bg-green-100 br12 bs-lg' }}
126
139
  />
127
140
  );
128
- }
141
+ };
129
142
 
130
- export const RadioWithCustomLabelStyles = ({ onChange }: RadioProps<string>) => {
143
+ export const RadioWithCustomLabelStyles = ({
144
+ onChange,
145
+ }: RadioProps<string>) => {
131
146
  const [checkedValues, setCheckedValues] = useState<string>();
132
147
 
133
- const handleOnChange = (newValue: string ) => {
148
+ const handleOnChange = (newValue: string) => {
134
149
  setCheckedValues(newValue);
135
150
  onChange(newValue);
136
- }
151
+ };
137
152
 
138
153
  return (
139
- <Radio
154
+ <Radio
140
155
  onChange={handleOnChange}
141
156
  value={checkedValues}
142
157
  options={{
143
158
  CAT3: 'Cat',
144
159
  DOG3: 'Dog',
145
- }}
146
- classNames={{ label: "bg-grey-900 tc-white" }}
160
+ }}
161
+ classNames={{ label: 'bg-grey-900 tc-white' }}
147
162
  />
148
163
  );
149
- }
164
+ };
150
165
 
151
166
  export const RadioWithInlineLayout = ({ onChange }: RadioProps<string>) => {
152
167
  const [checkedValues, setCheckedValues] = useState<string>();
@@ -154,10 +169,10 @@ export const RadioWithInlineLayout = ({ onChange }: RadioProps<string>) => {
154
169
  const handleOnChange = (newValue: string) => {
155
170
  setCheckedValues(newValue);
156
171
  onChange(newValue);
157
- }
172
+ };
158
173
 
159
174
  return (
160
- <Radio
175
+ <Radio
161
176
  onChange={handleOnChange}
162
177
  value={checkedValues}
163
178
  options={{
@@ -167,78 +182,88 @@ export const RadioWithInlineLayout = ({ onChange }: RadioProps<string>) => {
167
182
  RABBIT: 'Rabbit',
168
183
  RAT: 'Rat',
169
184
  ANOTHER: 'Other',
170
- }}
171
- classNames={{ option: "w30" }}
185
+ }}
186
+ classNames={{ option: 'w30' }}
172
187
  inlineLayout
173
188
  wide
174
189
  />
175
190
  );
176
- }
191
+ };
177
192
 
178
- export const RadioWithCustomLabel = ({ onChange, wide, classNames, inlineLayout }: RadioProps<string>) => {
193
+ export const RadioWithCustomLabel = ({
194
+ onChange,
195
+ wide,
196
+ classNames,
197
+ inlineLayout,
198
+ }: RadioProps<string>) => {
179
199
  const [checkedValues, setCheckedValues] = useState<string>();
180
200
 
181
201
  const handleOnChange = (newValue: string) => {
182
202
  setCheckedValues(newValue);
183
203
  onChange(newValue);
184
- }
204
+ };
185
205
 
186
206
  return (
187
- <Radio
207
+ <Radio
188
208
  options={{
189
209
  BIGDOG: {
190
- icon: () => <img src={images.bigDog} alt='' />,
210
+ icon: () => <img src={images.bigDog} alt="" />,
191
211
  title: 'Dog',
192
212
  },
193
- FISH:{
194
- icon: () => <img src={images.brokenAquarium} alt='' />,
213
+ FISH: {
214
+ icon: () => <img src={images.brokenAquarium} alt="" />,
195
215
  title: 'Fish',
196
216
  },
197
- OTHER:{
198
- icon: () => <img src={images.brokenGlass} alt='' />,
217
+ OTHER: {
218
+ icon: () => <img src={images.brokenGlass} alt="" />,
199
219
  title: 'Other',
200
- }
201
- }}
220
+ },
221
+ }}
202
222
  onChange={handleOnChange}
203
223
  value={checkedValues}
204
- classNames={{ option: "w30" }}
224
+ classNames={{ option: 'w30' }}
205
225
  inlineLayout
206
226
  />
207
227
  );
208
- }
228
+ };
209
229
 
210
- export const RadioWithCustomLabelInline = ({ onChange, wide, classNames, inlineLayout }: RadioProps<string>) => {
230
+ export const RadioWithCustomLabelInline = ({
231
+ onChange,
232
+ wide,
233
+ classNames,
234
+ inlineLayout,
235
+ }: RadioProps<string>) => {
211
236
  const [checkedValues, setCheckedValues] = useState<string>();
212
237
 
213
238
  const handleOnChange = (newValue: string) => {
214
239
  setCheckedValues(newValue);
215
240
  onChange(newValue);
216
- }
241
+ };
217
242
 
218
243
  return (
219
- <Radio
244
+ <Radio
220
245
  options={{
221
246
  BIGDOG: {
222
- icon: () => <img src={images.bigDog} alt='' />,
247
+ icon: () => <img src={images.bigDog} alt="" />,
223
248
  title: 'Dog',
224
249
  },
225
- FISH:{
226
- icon: () => <img src={images.brokenAquarium} alt='' />,
250
+ FISH: {
251
+ icon: () => <img src={images.brokenAquarium} alt="" />,
227
252
  title: 'Fish',
228
253
  },
229
- OTHER:{
230
- icon: () => <img src={images.brokenGlass} alt='' />,
254
+ OTHER: {
255
+ icon: () => <img src={images.brokenGlass} alt="" />,
231
256
  title: 'Other',
232
- }
233
- }}
257
+ },
258
+ }}
234
259
  onChange={handleOnChange}
235
260
  inlineIcon
236
261
  value={checkedValues}
237
- classNames={{ option: "w30" }}
262
+ classNames={{ option: 'w30' }}
238
263
  inlineLayout
239
264
  />
240
265
  );
241
- }
266
+ };
242
267
 
243
268
  RadioStory.storyName = 'Radio';
244
269
 
@@ -248,18 +273,18 @@ export const RadioIconOnly = ({ onChange }: RadioProps<string>) => {
248
273
  const handleOnChange = (newValue: string) => {
249
274
  setCheckedValues(newValue);
250
275
  onChange(newValue);
251
- }
276
+ };
252
277
 
253
278
  return (
254
- <Radio
255
- options={{ NOTHING: '' }}
279
+ <Radio
280
+ options={{ NOTHING: '' }}
256
281
  onChange={handleOnChange}
257
282
  classNames={{ label: 'jc-start' }}
258
283
  value={checkedValues}
259
284
  bordered={false}
260
285
  />
261
286
  );
262
- }
287
+ };
263
288
 
264
289
  RadioStory.storyName = 'Radio';
265
290
 
@@ -107,4 +107,23 @@ describe('Radio component', () => {
107
107
 
108
108
  expect(getByText('Cat')).toBeInTheDocument();
109
109
  });
110
+
111
+ it('Should disable the input', async () => {
112
+ const { getByTestId } = render(
113
+ <Radio
114
+ options={{
115
+ CAT: {
116
+ title: 'Cat',
117
+ description: 'Cat description',
118
+ },
119
+ }}
120
+ onChange={mockOnChange}
121
+ disabled
122
+ />
123
+ );
124
+
125
+ const radioInput = getByTestId('radio-input-CAT');
126
+
127
+ expect(radioInput).toBeDisabled();
128
+ });
110
129
  });
@@ -22,6 +22,7 @@ export interface RadioProps<ValueType extends string> {
22
22
  option?: string;
23
23
  };
24
24
  bordered?: boolean;
25
+ disabled?: boolean;
25
26
  }
26
27
 
27
28
  export const Radio = <ValueType extends string>({
@@ -33,6 +34,7 @@ export const Radio = <ValueType extends string>({
33
34
  inlineIcon = false,
34
35
  classNames: classNamesObj,
35
36
  bordered = true,
37
+ disabled = false,
36
38
  }: RadioProps<ValueType>) => {
37
39
  const entries = Object.entries(options) as [
38
40
  ValueType,
@@ -78,6 +80,7 @@ export const Radio = <ValueType extends string>({
78
80
  onChange={() => onChange(currentValue)}
79
81
  checked={checked}
80
82
  data-testid={`radio-input-${currentValue}`}
83
+ disabled={disabled}
81
84
  />
82
85
 
83
86
  <label
@@ -91,10 +94,10 @@ export const Radio = <ValueType extends string>({
91
94
  data-testid={`radio-${currentValue}`}
92
95
  >
93
96
  {customIcon && (
94
- <div
97
+ <div
95
98
  className={classNames(
96
- "d-inline-flex ai-center jc-center",
97
- inlineIcon ? "mr8" : "mt8"
99
+ 'd-inline-flex ai-center jc-center',
100
+ inlineIcon ? 'mr8' : 'mt8'
98
101
  )}
99
102
  >
100
103
  {customIcon?.(checked)}
@@ -96,7 +96,7 @@
96
96
  }
97
97
 
98
98
  .p-radio--no-icon + label::before {
99
- display: none!important;
99
+ display: none !important;
100
100
  }
101
101
  .p-radio:checked {
102
102
  & + label::before {
@@ -105,6 +105,17 @@
105
105
  }
106
106
  }
107
107
 
108
+ .p-radio:disabled {
109
+ + .p-label {
110
+ cursor: not-allowed;
111
+ opacity: 0.6;
112
+ }
113
+
114
+ + .p-label--bordered:hover {
115
+ border-color: $ds-grey-400;
116
+ }
117
+ }
118
+
108
119
  .p-checkbox {
109
120
  & + label {
110
121
  &::before {