@comicrelief/component-library 7.7.0 → 7.9.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.
Files changed (20) hide show
  1. package/cypress/integration/components/Atoms/MarketingPreferencesDSForm.spec.js +2 -2
  2. package/dist/components/Organisms/MarketingPreferencesDS/MarketingPreferencesDS.style.js +60 -42
  3. package/dist/components/Organisms/MarketingPreferencesDS/_AssociatedFields.js +16 -4
  4. package/dist/components/Organisms/MarketingPreferencesDS/_CheckAnswer.js +5 -15
  5. package/dist/components/Organisms/MarketingPreferencesDS/_DefaultCopy.js +6 -6
  6. package/dist/components/Organisms/MarketingPreferencesDS/_MarketingPreferencesDS.js +67 -114
  7. package/dist/components/Organisms/MarketingPreferencesDS/_MarketingPrefsConfig.js +8 -11
  8. package/dist/components/Organisms/MarketingPreferencesDS/assets/CR_Tick_black.svg +1 -0
  9. package/dist/theme/crTheme/colors.js +4 -0
  10. package/package.json +1 -1
  11. package/src/components/Organisms/MarketingPreferencesDS/MarketingPreferencesDS.style.js +78 -71
  12. package/src/components/Organisms/MarketingPreferencesDS/_AssociatedFields.js +16 -4
  13. package/src/components/Organisms/MarketingPreferencesDS/_CheckAnswer.js +9 -18
  14. package/src/components/Organisms/MarketingPreferencesDS/_DefaultCopy.js +8 -8
  15. package/src/components/Organisms/MarketingPreferencesDS/_MarketingPreferencesDS.js +105 -107
  16. package/src/components/Organisms/MarketingPreferencesDS/_MarketingPrefsConfig.js +8 -11
  17. package/src/components/Organisms/MarketingPreferencesDS/assets/CR_Tick_black.svg +1 -0
  18. package/src/theme/crTheme/colors.js +4 -0
  19. package/dist/components/Organisms/MarketingPreferencesDS/_NoMessage.js +0 -40
  20. package/src/components/Organisms/MarketingPreferencesDS/_NoMessage.js +0 -27
@@ -1,16 +1,13 @@
1
- /* eslint-disable camelcase */
2
1
  import React from 'react';
3
2
  import PropTypes from 'prop-types';
4
3
  import { useWatch } from 'react-hook-form';
5
4
  import _ from 'lodash';
6
- import Text from '../../Atoms/Text/Text';
7
- import TextInput from './_TextInput';
8
5
  import CheckAnswer from './_CheckAnswer';
9
- import NoMessage from './_NoMessage';
10
6
 
11
7
  import { defaultCopyTop, defaultCopyBottom } from './_DefaultCopy';
12
8
  import {
13
- TopCopyWrapper, BottomCopyWrapper, Head, FormField, ShowHideInputWrapper
9
+ TopCopyWrapper, BottomCopyWrapper, Head, FormField,
10
+ ShowHideInputWrapper, ExtraInfo, OuterWrapper, MPTextInput
14
11
  } from './MarketingPreferencesDS.style';
15
12
 
16
13
  import {
@@ -27,27 +24,24 @@ const MarketingPreferencesDS = ({
27
24
  const { errors, control } = formContext;
28
25
 
29
26
  // For brevity
30
- const emailChoice = useWatch({ control, name: 'mp_permissionEmail', defaultValue: [] });
31
- const postChoice = useWatch({ control, name: 'mp_permissionPost', defaultValue: [] });
32
- const phoneChoice = useWatch({ control, name: 'mp_permissionPhone', defaultValue: [] });
33
- const smsChoice = useWatch({ control, name: 'mp_permissionSMS', defaultValue: [] });
27
+ const emailChoice = useWatch({ control, name: 'mp_permissionEmail', defaultValue: null });
28
+ const postChoice = useWatch({ control, name: 'mp_permissionPost', defaultValue: null });
29
+ const phoneChoice = useWatch({ control, name: 'mp_permissionPhone', defaultValue: null });
30
+ const smsChoice = useWatch({ control, name: 'mp_permissionSMS', defaultValue: null });
34
31
 
35
32
  const {
33
+ // eslint-disable-next-line camelcase
36
34
  mp_permissionEmail, mp_permissionSMS, mp_permissionPhone, mp_permissionPost
37
35
  } = mpValidationOptions;
38
36
 
39
37
  // If the field is not required for each No/Yes choice, remove it from the DOM entirely
40
- const disableEmailInput = (mp_permissionEmail.yes === false && emailChoice.includes('yes'))
41
- || (mp_permissionEmail.no === false && emailChoice.includes('no'));
38
+ const disableEmailInput = (mp_permissionEmail.yes === false && emailChoice.includes('yes'));
42
39
 
43
- const disableSMSInput = (mp_permissionSMS.yes === false && smsChoice.includes('yes'))
44
- || (mp_permissionSMS.no === false && smsChoice.includes('no'));
40
+ const disableSMSInput = (mp_permissionSMS.yes === false && smsChoice.includes('yes'));
45
41
 
46
- const disablePhoneInput = (mp_permissionPhone.yes === false && phoneChoice.includes('yes'))
47
- || (mp_permissionPhone.no === false && phoneChoice.includes('no'));
42
+ const disablePhoneInput = (mp_permissionPhone.yes === false && phoneChoice.includes('yes'));
48
43
 
49
- const disablePostInput = (mp_permissionPost.yes === false && postChoice.includes('yes'))
50
- || (mp_permissionPost.no === false && postChoice.includes('no'));
44
+ const disablePostInput = (mp_permissionPost.yes === false && postChoice.includes('yes'));
51
45
 
52
46
  // Required to track multiple errors to determine whether to show/hide the fieldset
53
47
  const isAddressErroring = () => {
@@ -59,42 +53,43 @@ const MarketingPreferencesDS = ({
59
53
  };
60
54
  /* Only show the field if config hasn't hidden it (to pass in parent values)
61
55
  or if a choice has been made */
62
- const showEmailField = !mp_permissionEmail.hideInput && (emailChoice.length || errors.mp_email);
63
- const showSMSField = !mp_permissionSMS.hideInput && (smsChoice.length || errors.mp_mobile);
64
- const showPhoneField = !mp_permissionPhone.hideInput && (phoneChoice.length || errors.mp_phone);
65
- const showPostFields = !mp_permissionPost.hideInput && (postChoice.length || isAddressErroring());
56
+ const showEmailField = !mp_permissionEmail.hideInput && (emailChoice || errors.mp_email);
57
+ const showSMSField = !mp_permissionSMS.hideInput && (smsChoice || errors.mp_mobile);
58
+ const showPhoneField = !mp_permissionPhone.hideInput && (phoneChoice || errors.mp_phone);
59
+ const showPostFields = !mp_permissionPost.hideInput && (postChoice || isAddressErroring());
66
60
 
67
61
  const customId = id ? `marketing-preferences--${id}` : 'marketing-preferences';
68
62
 
69
63
  return (
70
- <div id={customId}>
64
+ <OuterWrapper id={customId}>
71
65
  {copyTop && <TopCopyWrapper>{copyTop}</TopCopyWrapper>}
72
66
 
73
67
  {/* Render Email checkboxes and input if not removed in config */}
74
68
  {!mp_permissionEmail.disableOption && (
75
69
  <FormField className="field-email">
76
70
  <Head>
77
- <Text tag="h3" size="l" family="Anton" uppercase weight="400" color="grey_dark">
78
- Email Me
79
- </Text>
80
71
  <CheckAnswer
81
72
  mpValidationOptions={mpValidationOptions}
82
73
  name="mp_permissionEmail"
83
74
  id="mp_permissionEmail"
84
- userSelection={emailChoice[0]}
75
+ userSelection={emailChoice}
85
76
  formContext={formContext}
86
77
  />
87
78
  </Head>
88
79
 
89
80
  <MaybeDisabled disabled={disableEmailInput}>
90
81
  <ShowHideInputWrapper show={showEmailField}>
91
- {emailChoice[0] === 'no' && <NoMessage askingFor="an email" optInType="email" /> }
92
- <TextInput
82
+ <ExtraInfo>
83
+ Please confirm the email address we will use to
84
+ <b> email </b>
85
+ you:
86
+ </ExtraInfo>
87
+ <MPTextInput
93
88
  placeholder=""
94
89
  fieldName="mp_email"
95
90
  label="Please enter your email address"
96
91
  // Dynamically update the field attr based on config for current choice
97
- optional={!mp_permissionEmail[emailChoice[0]]}
92
+ optional={!mp_permissionEmail[emailChoice]}
98
93
  type="email"
99
94
  id="mp_email"
100
95
  formContext={formContext}
@@ -104,95 +99,34 @@ const MarketingPreferencesDS = ({
104
99
  </FormField>
105
100
  )}
106
101
 
107
- {/* Render SMS checkboxes and inputs if not removed in config */}
108
- {!mp_permissionSMS.disableOption && (
109
- <FormField className="field-sms">
110
- <Head>
111
- <Text tag="h3" size="l" family="Anton" uppercase weight="400" color="grey_dark">
112
- Text me
113
- </Text>
114
- <CheckAnswer
115
- name="mp_permissionSMS"
116
- id="mp_permissionSMS"
117
- mpValidationOptions={mpValidationOptions}
118
- userSelection={smsChoice[0]}
119
- formContext={formContext}
120
- />
121
- </Head>
122
- <MaybeDisabled disabled={disableSMSInput}>
123
- <ShowHideInputWrapper show={showSMSField}>
124
- {smsChoice[0] === 'no' && <NoMessage askingFor="a mobile number" optInType="SMS" />}
125
- <TextInput
126
- placeholder=""
127
- fieldName="mp_mobile"
128
- label="Please enter your mobile no."
129
- optional={!mp_permissionSMS[smsChoice[0]]}
130
- id="mp_mobile"
131
- formContext={formContext}
132
- />
133
- </ShowHideInputWrapper>
134
- </MaybeDisabled>
135
- </FormField>
136
- )}
137
-
138
- {/* Render Phone checkboxes and input if not removed in config */}
139
- {!mp_permissionPhone.disableOption && (
140
- <FormField className="field-phone">
141
- <Head>
142
- <Text tag="h3" size="l" family="Anton" uppercase weight="400" color="grey_dark">
143
- Phone me
144
- </Text>
145
- <CheckAnswer
146
- name="mp_permissionPhone"
147
- mpValidationOptions={mpValidationOptions}
148
- id="mp_permissionPhone"
149
- userSelection={phoneChoice[0]}
150
- formContext={formContext}
151
- />
152
- </Head>
153
- <MaybeDisabled disabled={disablePhoneInput}>
154
- <ShowHideInputWrapper show={showPhoneField}>
155
- {phoneChoice[0] === 'no' ? <NoMessage askingFor="a phone number" optInType="phone" /> : ''}
156
- <TextInput
157
- placeholder=""
158
- fieldName="mp_phone"
159
- label="Please enter your phone no."
160
- optional={!mp_permissionPhone[phoneChoice[0]]}
161
- id="mp_phone"
162
- formContext={formContext}
163
- />
164
- </ShowHideInputWrapper>
165
- </MaybeDisabled>
166
- </FormField>
167
- )}
168
-
169
102
  {/* Render Post checkboxes and inputs if not removed in config */}
170
103
  {!mp_permissionPost.disableOption && (
171
104
  <FormField className="field-post">
172
105
  <Head>
173
- <Text tag="h3" size="l" family="Anton" uppercase weight="400" color="grey_dark">
174
- Send me post
175
- </Text>
176
106
  <CheckAnswer
177
107
  name="mp_permissionPost"
178
108
  mpValidationOptions={mpValidationOptions}
179
109
  id="mp_permissionPost"
180
- userSelection={postChoice[0]}
110
+ userSelection={postChoice}
181
111
  formContext={formContext}
182
112
  />
183
113
  </Head>
184
114
  <MaybeDisabled disabled={disablePostInput}>
185
115
  <ShowHideInputWrapper show={showPostFields}>
186
- {postChoice[0] === 'no' ? <NoMessage askingFor="an address" optInType="postal" /> : ''}
187
- <TextInput
116
+ <ExtraInfo>
117
+ Please confirm the address we will use to
118
+ <b> post </b>
119
+ to you:
120
+ </ExtraInfo>
121
+ <MPTextInput
188
122
  placeholder=""
189
123
  fieldName="mp_address1"
190
124
  label="Address Line 1"
191
- optional={!mp_permissionPost[postChoice[0]]}
125
+ optional={!mp_permissionPost[postChoice]}
192
126
  id="mp_address1"
193
127
  formContext={formContext}
194
128
  />
195
- <TextInput
129
+ <MPTextInput
196
130
  placeholder=""
197
131
  fieldName="mp_address2"
198
132
  label="Address Line 2"
@@ -200,7 +134,7 @@ const MarketingPreferencesDS = ({
200
134
  id="mp_address2"
201
135
  formContext={formContext}
202
136
  />
203
- <TextInput
137
+ <MPTextInput
204
138
  placeholder=""
205
139
  fieldName="mp_address3"
206
140
  label="Address Line 3"
@@ -208,27 +142,27 @@ const MarketingPreferencesDS = ({
208
142
  id="mp_address3"
209
143
  formContext={formContext}
210
144
  />
211
- <TextInput
145
+ <MPTextInput
212
146
  placeholder=""
213
147
  fieldName="mp_town"
214
148
  label="Town/City"
215
- optional={!mp_permissionPost[postChoice[0]]}
149
+ optional={!mp_permissionPost[postChoice]}
216
150
  id="mp_town"
217
151
  formContext={formContext}
218
152
  />
219
- <TextInput
153
+ <MPTextInput
220
154
  placeholder=""
221
155
  fieldName="mp_postcode"
222
156
  label="Postcode"
223
- optional={!mp_permissionPost[postChoice[0]]}
157
+ optional={!mp_permissionPost[postChoice]}
224
158
  id="mp_postcode"
225
159
  formContext={formContext}
226
160
  />
227
- <TextInput
161
+ <MPTextInput
228
162
  placeholder=""
229
163
  fieldName="mp_country"
230
164
  label="Country"
231
- optional={!mp_permissionPost[postChoice[0]]}
165
+ optional={!mp_permissionPost[postChoice]}
232
166
  id="mp_country"
233
167
  formContext={formContext}
234
168
  />
@@ -237,8 +171,72 @@ const MarketingPreferencesDS = ({
237
171
  </FormField>
238
172
  )}
239
173
 
174
+ {/* Render SMS checkboxes and inputs if not removed in config */}
175
+ {!mp_permissionSMS.disableOption && (
176
+ <FormField className="field-sms">
177
+ <Head>
178
+ <CheckAnswer
179
+ name="mp_permissionSMS"
180
+ id="mp_permissionSMS"
181
+ mpValidationOptions={mpValidationOptions}
182
+ userSelection={smsChoice}
183
+ formContext={formContext}
184
+ />
185
+ </Head>
186
+ <MaybeDisabled disabled={disableSMSInput}>
187
+ <ShowHideInputWrapper show={showSMSField}>
188
+ <ExtraInfo>
189
+ Please confirm the mobile number we will use to
190
+ <b> text </b>
191
+ you on:
192
+ </ExtraInfo>
193
+ <MPTextInput
194
+ placeholder=""
195
+ fieldName="mp_mobile"
196
+ label="Please enter your mobile no."
197
+ optional={!mp_permissionSMS[smsChoice]}
198
+ id="mp_mobile"
199
+ formContext={formContext}
200
+ />
201
+ </ShowHideInputWrapper>
202
+ </MaybeDisabled>
203
+ </FormField>
204
+ )}
205
+
206
+ {/* Render Phone checkboxes and input if not removed in config */}
207
+ {!mp_permissionPhone.disableOption && (
208
+ <FormField className="field-phone">
209
+ <Head>
210
+ <CheckAnswer
211
+ name="mp_permissionPhone"
212
+ mpValidationOptions={mpValidationOptions}
213
+ id="mp_permissionPhone"
214
+ userSelection={phoneChoice}
215
+ formContext={formContext}
216
+ />
217
+ </Head>
218
+ <MaybeDisabled disabled={disablePhoneInput}>
219
+ <ShowHideInputWrapper show={showPhoneField}>
220
+ <ExtraInfo>
221
+ Please confirm the telephone number we will use to
222
+ <b> phone </b>
223
+ you on:
224
+ </ExtraInfo>
225
+ <MPTextInput
226
+ placeholder=""
227
+ fieldName="mp_phone"
228
+ label="Please enter your phone no."
229
+ optional={!mp_permissionPhone[phoneChoice]}
230
+ id="mp_phone"
231
+ formContext={formContext}
232
+ />
233
+ </ShowHideInputWrapper>
234
+ </MaybeDisabled>
235
+ </FormField>
236
+ )}
237
+
240
238
  {copyBottom && <BottomCopyWrapper>{copyBottom}</BottomCopyWrapper>}
241
- </div>
239
+ </OuterWrapper>
242
240
  );
243
241
  };
244
242
 
@@ -12,10 +12,10 @@ const setInitialValues = overrideValues => {
12
12
  mp_town: '',
13
13
  mp_country: '',
14
14
  mp_postcode: '',
15
- mp_permissionEmail: [],
16
- mp_permissionPost: [],
17
- mp_permissionPhone: [],
18
- mp_permissionSMS: []
15
+ mp_permissionEmail: false,
16
+ mp_permissionPost: false,
17
+ mp_permissionPhone: false,
18
+ mp_permissionSMS: false
19
19
  };
20
20
 
21
21
  // Override with any custom options supplied
@@ -29,12 +29,12 @@ const buildValidationSchema = overrideOptions => {
29
29
  mp_permissionEmail: {
30
30
  /**
31
31
  * As per react-hook-form's validation requirements, sets the fields' required attribute
32
- * for each checkbox option (Yes & No), a non-required field isn't rendered or included
33
- * in the validation. As the backend *currently* needs values to formalise a user's opt-out,
34
- * we'll set all fields to 'required' by default (once the option is chosen).
32
+ * for each checkbox option (now only 'Yes' as of 2023), a non-required field isn't rendered
33
+ * or included in the validation. As the backend *currently* needs values to formalise
34
+ * a user's opt-out, we'll set all fields to 'required' by default
35
+ * (once the option is chosen).
35
36
  */
36
37
  yes: true,
37
- no: true,
38
38
  // Hide the input from user interaction, but keep it in the DOM so we can pass values to it
39
39
  hideInput: false,
40
40
  // Allows complete removal of the option (checkboxes & fields) from both render & validation.
@@ -43,19 +43,16 @@ const buildValidationSchema = overrideOptions => {
43
43
  },
44
44
  mp_permissionSMS: {
45
45
  yes: true,
46
- no: true,
47
46
  hideInput: false,
48
47
  disableOption: false
49
48
  },
50
49
  mp_permissionPhone: {
51
50
  yes: true,
52
- no: true,
53
51
  hideInput: false,
54
52
  disableOption: false
55
53
  },
56
54
  mp_permissionPost: {
57
55
  yes: true,
58
- no: true,
59
56
  hideInput: false,
60
57
  disableOption: false
61
58
  }
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48"><path d="M36.121 15.879a2.998 2.998 0 0 0-4.242 0L21 26.757l-4.879-4.878a2.998 2.998 0 0 0-4.242 0 2.998 2.998 0 0 0 0 4.242l7 7c.586.586 1.353.879 2.121.879s1.535-.293 2.121-.879l13-13a2.998 2.998 0 0 0 0-4.242z" fill="#000"/></svg>
@@ -38,6 +38,10 @@ const colors = {
38
38
  purple_light: '#DFC6F6',
39
39
  red: '#E52630',
40
40
  red_dark: '#890B11',
41
+ rnd_23_teal: '#3EB1AA',
42
+ rnd_23_yellow: '#FFE300',
43
+ rnd_23_pink: '#EDB4D3',
44
+ rnd_23_black: '#2B3737',
41
45
  teal: '#4ECDBE',
42
46
  teal_dark: '#13767C',
43
47
  teal_light: '#86E4E9',
@@ -1,40 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = void 0;
9
-
10
- var _react = _interopRequireDefault(require("react"));
11
-
12
- var _styledComponents = _interopRequireWildcard(require("styled-components"));
13
-
14
- var _Text = _interopRequireDefault(require("../../Atoms/Text/Text"));
15
-
16
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
-
18
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
-
20
- var NoMessageWrapper = _styledComponents.default.div.withConfig({
21
- displayName: "_NoMessage__NoMessageWrapper",
22
- componentId: "sc-2h3k46-0"
23
- })(["", ""], function (_ref) {
24
- var theme = _ref.theme;
25
- return (0, _styledComponents.css)(["background-color:", ";padding:15px;margin-bottom:15px;"], theme.color('red'));
26
- });
27
-
28
- var NoMessage = function NoMessage(_ref2) {
29
- var askingFor = _ref2.askingFor,
30
- optInType = _ref2.optInType;
31
- var message = "This will remove the supplied ".concat(askingFor, " from any *previous* ").concat(optInType, " opt-in from our database; otherwise, you can leave this unchecked.");
32
- return /*#__PURE__*/_react.default.createElement(NoMessageWrapper, null, /*#__PURE__*/_react.default.createElement(_Text.default, {
33
- tag: "p",
34
- size: "s",
35
- color: "white"
36
- }, message));
37
- };
38
-
39
- var _default = NoMessage;
40
- exports.default = _default;
@@ -1,27 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import styled, { css } from 'styled-components';
4
- import Text from '../../Atoms/Text/Text';
5
-
6
- const NoMessageWrapper = styled.div`${({ theme }) => css`
7
- background-color: ${theme.color('red')};
8
- padding: 15px;
9
- margin-bottom: 15px;
10
- `}`;
11
-
12
- const NoMessage = ({ askingFor, optInType }) => {
13
- const message = `This will remove the supplied ${askingFor} from any *previous* ${optInType} opt-in from our database; otherwise, you can leave this unchecked.`;
14
-
15
- return (
16
- <NoMessageWrapper>
17
- <Text tag="p" size="s" color="white">{message}</Text>
18
- </NoMessageWrapper>
19
- );
20
- };
21
-
22
- NoMessage.propTypes = {
23
- askingFor: PropTypes.string.isRequired,
24
- optInType: PropTypes.string.isRequired
25
- };
26
-
27
- export default NoMessage;