@thecb/components 8.4.8 → 8.4.9

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": "@thecb/components",
3
- "version": "8.4.8",
3
+ "version": "8.4.9",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "typings": "dist/index.d.ts",
@@ -57,30 +57,45 @@ const RadioButtonWithLabel = ({
57
57
  ariaInvalid,
58
58
  themeValues,
59
59
  index,
60
- handleChange = noop // optional, for custom event handling in ingesting app
61
- }) => (
62
- <InputAndLabelContainer
63
- align="center"
64
- childGap="0.5rem"
65
- activeColor={themeValues.activeColor}
66
- >
67
- <HiddenRadioInput
68
- aria-invalid={ariaInvalid}
69
- style={{ marginTop: 0 }}
70
- type="radio"
71
- name={groupName}
72
- id={id}
73
- value={value}
74
- onChange={e => {
75
- setValue(e.target.value);
76
- handleChange(e);
77
- }}
78
- defaultChecked={index === 0}
79
- />
80
- <Text
81
- as="label"
82
- htmlFor={id}
83
- extraStyles={`
60
+ handleChange = noop, // optional, for custom event handling in ingesting app
61
+ field,
62
+ config
63
+ }) => {
64
+ const getDefaultChecked = (value, idx) => {
65
+ const selectionExistsInConfig = config
66
+ .map(c => c.value)
67
+ .includes(field.rawValue);
68
+
69
+ if (selectionExistsInConfig) {
70
+ // if exists, selection comes from the redux-freeform state
71
+ return field.rawValue === value;
72
+ }
73
+ // fallback to first option as default selection
74
+ return idx === 0;
75
+ };
76
+ return (
77
+ <InputAndLabelContainer
78
+ align="center"
79
+ childGap="0.5rem"
80
+ activeColor={themeValues.activeColor}
81
+ >
82
+ <HiddenRadioInput
83
+ aria-invalid={ariaInvalid}
84
+ style={{ marginTop: 0 }}
85
+ type="radio"
86
+ name={groupName}
87
+ id={id}
88
+ value={value}
89
+ onChange={e => {
90
+ setValue(e.target.value);
91
+ handleChange(e);
92
+ }}
93
+ defaultChecked={getDefaultChecked(value, index)}
94
+ />
95
+ <Text
96
+ as="label"
97
+ htmlFor={id}
98
+ extraStyles={`
84
99
  font-size: 1rem;
85
100
  display: flex;
86
101
  width: 100%;
@@ -88,15 +103,16 @@ const RadioButtonWithLabel = ({
88
103
  cursor: pointer;
89
104
  }
90
105
  `}
91
- >
92
- <Circle
93
- activeColor={themeValues.activeColor}
94
- inactiveBorderColor={themeValues.inactiveBorderColor}
95
- />
96
- {labelText}
97
- </Text>
98
- </InputAndLabelContainer>
99
- );
106
+ >
107
+ <Circle
108
+ activeColor={themeValues.activeColor}
109
+ inactiveBorderColor={themeValues.inactiveBorderColor}
110
+ />
111
+ {labelText}
112
+ </Text>
113
+ </InputAndLabelContainer>
114
+ );
115
+ };
100
116
 
101
117
  export default themeComponent(
102
118
  RadioButtonWithLabel,
@@ -48,6 +48,8 @@ const RadioGroup = ({
48
48
  groupName={groupName}
49
49
  setValue={setValue}
50
50
  handleChange={handleChange}
51
+ field={field}
52
+ config={config}
51
53
  aria-invalid={field.dirty && field.hasErrors}
52
54
  />
53
55
  ))}
@@ -27,7 +27,7 @@ export const radioGroup = () => (
27
27
  config={config}
28
28
  groupName="radio-button-group"
29
29
  field={{
30
- rawValue: "Hello World",
30
+ rawValue: "bar",
31
31
  dirty: false
32
32
  }}
33
33
  fieldActions={{
@@ -1,5 +1,5 @@
1
1
  export default interface Field {
2
- hasErrors?: boolean;
3
- dirty?: boolean;
4
- rawValue?: string;
2
+ hasErrors: boolean;
3
+ dirty: boolean;
4
+ rawValue: string;
5
5
  }