@comicrelief/component-library 6.9.1 → 7.0.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/cypress/integration/components/Organisms/EmailSignUp.spec.js +47 -132
- package/dist/components/Molecules/Box/Box.js +6 -6
- package/dist/components/Molecules/Card/Card.js +5 -5
- package/dist/components/Organisms/EmailSignUp/EmailSignUp.md +8 -123
- package/dist/components/Organisms/EmailSignUp/EmailSignUp.style.js +46 -29
- package/dist/components/Organisms/EmailSignUp/EmailSignUp.test.js +24 -69
- package/dist/components/Organisms/EmailSignUp/EmailSignUpForm.js +92 -0
- package/dist/components/Organisms/EmailSignUp/_Confetti.js +116 -0
- package/dist/components/Organisms/EmailSignUp/_EmailSignUp.js +107 -0
- package/dist/components/Organisms/EmailSignUp/_EmailSignUpConfig.js +51 -0
- package/dist/components/Organisms/EmailSignUp/_TextInput.js +51 -0
- package/dist/components/Organisms/EmailSignUp/__snapshots__/EmailSignUp.test.js.snap +249 -406
- package/dist/components/Organisms/Header/Header.md +1 -13
- package/dist/components/Organisms/Membership/Membership.test.js +1 -1
- package/dist/index.js +14 -10
- package/package.json +2 -1
- package/src/components/Molecules/Box/Box.js +6 -6
- package/src/components/Molecules/Card/Card.js +5 -5
- package/src/components/Organisms/EmailSignUp/EmailSignUp.md +8 -123
- package/src/components/Organisms/EmailSignUp/EmailSignUp.style.js +33 -13
- package/src/components/Organisms/EmailSignUp/EmailSignUp.test.js +35 -69
- package/src/components/Organisms/EmailSignUp/EmailSignUpForm.js +60 -0
- package/src/components/Organisms/EmailSignUp/_Confetti.js +106 -0
- package/src/components/Organisms/EmailSignUp/_EmailSignUp.js +138 -0
- package/src/components/Organisms/EmailSignUp/_EmailSignUpConfig.js +54 -0
- package/src/components/Organisms/EmailSignUp/_TextInput.js +45 -0
- package/src/components/Organisms/EmailSignUp/__snapshots__/EmailSignUp.test.js.snap +249 -406
- package/src/components/Organisms/Header/Header.md +1 -13
- package/src/components/Organisms/Membership/Membership.test.js +33 -33
- package/src/index.js +10 -4
- package/cypress/integration/components/Molecules/HeaderEsuWithIcon.spec.js +0 -69
- package/dist/components/Molecules/HeaderEsuWithIcon/HeaderEsuWithIcon.js +0 -136
- package/dist/components/Molecules/HeaderEsuWithIcon/HeaderEsuWithIcon.md +0 -47
- package/dist/components/Molecules/HeaderEsuWithIcon/HeaderEsuWithIcon.style.js +0 -52
- package/dist/components/Molecules/HeaderEsuWithIcon/HeaderEsuWithIcon.test.js +0 -99
- package/dist/components/Molecules/HeaderEsuWithIcon/__snapshots__/HeaderEsuWithIcon.test.js.snap +0 -1211
- package/dist/components/Molecules/HeaderEsuWithIcon/assets/HeaderIcons.js +0 -25
- package/dist/components/Molecules/HeaderEsuWithIcon/assets/icon--close.svg +0 -5
- package/dist/components/Molecules/HeaderEsuWithIcon/assets/icon--email.svg +0 -5
- package/dist/components/Organisms/EmailSignUp/EmailSignUp.js +0 -182
- package/src/components/Molecules/HeaderEsuWithIcon/HeaderEsuWithIcon.js +0 -135
- package/src/components/Molecules/HeaderEsuWithIcon/HeaderEsuWithIcon.md +0 -47
- package/src/components/Molecules/HeaderEsuWithIcon/HeaderEsuWithIcon.style.js +0 -60
- package/src/components/Molecules/HeaderEsuWithIcon/HeaderEsuWithIcon.test.js +0 -103
- package/src/components/Molecules/HeaderEsuWithIcon/__snapshots__/HeaderEsuWithIcon.test.js.snap +0 -1211
- package/src/components/Molecules/HeaderEsuWithIcon/assets/HeaderIcons.js +0 -15
- package/src/components/Molecules/HeaderEsuWithIcon/assets/icon--close.svg +0 -5
- package/src/components/Molecules/HeaderEsuWithIcon/assets/icon--email.svg +0 -5
- package/src/components/Organisms/EmailSignUp/EmailSignUp.js +0 -197
|
@@ -0,0 +1,92 @@
|
|
|
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 _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
+
|
|
12
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/asyncToGenerator"));
|
|
13
|
+
|
|
14
|
+
var _react = _interopRequireDefault(require("react"));
|
|
15
|
+
|
|
16
|
+
var _reactHookForm = require("react-hook-form");
|
|
17
|
+
|
|
18
|
+
var _yup = require("@hookform/resolvers/yup");
|
|
19
|
+
|
|
20
|
+
var _RichText = _interopRequireDefault(require("../../Atoms/RichText/RichText"));
|
|
21
|
+
|
|
22
|
+
var _EmailSignUp = require("./_EmailSignUp");
|
|
23
|
+
|
|
24
|
+
var EmailSignUpForm = function EmailSignUpForm() {
|
|
25
|
+
var validationSchema = (0, _EmailSignUp.buildEsuValidationSchema)({});
|
|
26
|
+
var formMethods = (0, _reactHookForm.useForm)({
|
|
27
|
+
mode: 'onBlur',
|
|
28
|
+
resolver: (0, _yup.yupResolver)(validationSchema)
|
|
29
|
+
});
|
|
30
|
+
var handleSubmit = formMethods.handleSubmit,
|
|
31
|
+
trigger = formMethods.trigger;
|
|
32
|
+
|
|
33
|
+
function handleSubscribe(_x) {
|
|
34
|
+
return _handleSubscribe.apply(this, arguments);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function _handleSubscribe() {
|
|
38
|
+
_handleSubscribe = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(data) {
|
|
39
|
+
var valid;
|
|
40
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
41
|
+
while (1) {
|
|
42
|
+
switch (_context.prev = _context.next) {
|
|
43
|
+
case 0:
|
|
44
|
+
_context.next = 2;
|
|
45
|
+
return trigger([_EmailSignUp.ESU_FIELDS.EMAIL, _EmailSignUp.ESU_FIELDS.FIRST_NAME, _EmailSignUp.ESU_FIELDS.LAST_NAME]);
|
|
46
|
+
|
|
47
|
+
case 2:
|
|
48
|
+
valid = _context.sent;
|
|
49
|
+
|
|
50
|
+
if (valid) {
|
|
51
|
+
console.log(data);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
case 4:
|
|
55
|
+
case "end":
|
|
56
|
+
return _context.stop();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}, _callee);
|
|
60
|
+
}));
|
|
61
|
+
return _handleSubscribe.apply(this, arguments);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
var title = 'Stay in the know!';
|
|
65
|
+
|
|
66
|
+
var topCopy = /*#__PURE__*/_react.default.createElement(_RichText.default, {
|
|
67
|
+
markup: "<p>Get regular email updates and info on what we're up to!</p>"
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
var privacyCopy = /*#__PURE__*/_react.default.createElement(_RichText.default, {
|
|
71
|
+
markup: '<p>Our <a class="link link--white inline" href="/privacy-notice">Privacy Policy</a> describes how we handle and protect your information.<br><br>If you are under 18, please make sure you have your parents’ permission before providing us with any personal details.</p>'
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
var successCopy = /*#__PURE__*/_react.default.createElement(_RichText.default, {
|
|
75
|
+
markup: "<p>Thanks! Your first email will be with you shortly</p>"
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
return /*#__PURE__*/_react.default.createElement(_reactHookForm.FormProvider, formMethods, /*#__PURE__*/_react.default.createElement("form", {
|
|
79
|
+
onSubmit: handleSubmit(handleSubscribe),
|
|
80
|
+
noValidate: true
|
|
81
|
+
}, /*#__PURE__*/_react.default.createElement(_EmailSignUp.EmailSignUp, {
|
|
82
|
+
id: "default",
|
|
83
|
+
title: title,
|
|
84
|
+
topCopy: topCopy,
|
|
85
|
+
successCopy: successCopy,
|
|
86
|
+
privacyCopy: privacyCopy,
|
|
87
|
+
formContext: formMethods
|
|
88
|
+
})));
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
var _default = EmailSignUpForm;
|
|
92
|
+
exports.default = _default;
|
|
@@ -0,0 +1,116 @@
|
|
|
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 = Confetti;
|
|
9
|
+
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
|
|
11
|
+
|
|
12
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
+
|
|
14
|
+
var _reactCanvasConfetti = _interopRequireDefault(require("react-canvas-confetti"));
|
|
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
|
+
function randomInRange(min, max) {
|
|
21
|
+
return Math.random() * (max - min) + min;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var canvasStyles = {
|
|
25
|
+
position: 'fixed',
|
|
26
|
+
pointerEvents: 'none',
|
|
27
|
+
width: '100%',
|
|
28
|
+
height: '100%',
|
|
29
|
+
top: 0,
|
|
30
|
+
left: 0
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function getAnimationSettings(originXA, originXB) {
|
|
34
|
+
return {
|
|
35
|
+
startVelocity: 30,
|
|
36
|
+
spread: 360,
|
|
37
|
+
ticks: 60,
|
|
38
|
+
zIndex: 0,
|
|
39
|
+
particleCount: 150,
|
|
40
|
+
origin: {
|
|
41
|
+
x: randomInRange(originXA, originXB),
|
|
42
|
+
y: Math.random() - 0.2
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
} // TODO: Refactor this into an atom
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
function Confetti(_ref) {
|
|
49
|
+
var trigger = _ref.trigger,
|
|
50
|
+
duration = _ref.duration;
|
|
51
|
+
var refAnimationInstance = (0, _react.useRef)(null);
|
|
52
|
+
|
|
53
|
+
var _useState = (0, _react.useState)(),
|
|
54
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
55
|
+
intervalId = _useState2[0],
|
|
56
|
+
setIntervalId = _useState2[1];
|
|
57
|
+
|
|
58
|
+
var getInstance = (0, _react.useCallback)(function (instance) {
|
|
59
|
+
refAnimationInstance.current = instance;
|
|
60
|
+
}, []);
|
|
61
|
+
var nextTickAnimation = (0, _react.useCallback)(function () {
|
|
62
|
+
if (refAnimationInstance.current) {
|
|
63
|
+
refAnimationInstance.current(getAnimationSettings(0.1, 0.3));
|
|
64
|
+
refAnimationInstance.current(getAnimationSettings(0.7, 0.9));
|
|
65
|
+
}
|
|
66
|
+
}, []);
|
|
67
|
+
var startAnimation = (0, _react.useCallback)(function () {
|
|
68
|
+
if (!intervalId) {
|
|
69
|
+
setIntervalId(setInterval(nextTickAnimation, 400));
|
|
70
|
+
}
|
|
71
|
+
}, [intervalId, nextTickAnimation]);
|
|
72
|
+
var pauseAnimation = (0, _react.useCallback)(function () {
|
|
73
|
+
clearInterval(intervalId);
|
|
74
|
+
setIntervalId(null);
|
|
75
|
+
}, [intervalId]);
|
|
76
|
+
var stopAnimation = (0, _react.useCallback)(function () {
|
|
77
|
+
clearInterval(intervalId);
|
|
78
|
+
setIntervalId(null);
|
|
79
|
+
|
|
80
|
+
if (refAnimationInstance.current) {
|
|
81
|
+
refAnimationInstance.current.reset();
|
|
82
|
+
}
|
|
83
|
+
}, [intervalId]); // eslint-disable-next-line
|
|
84
|
+
|
|
85
|
+
(0, _react.useEffect)(function () {
|
|
86
|
+
return function () {
|
|
87
|
+
clearInterval(intervalId);
|
|
88
|
+
};
|
|
89
|
+
}, [intervalId]);
|
|
90
|
+
(0, _react.useEffect)(function () {
|
|
91
|
+
var timeOut;
|
|
92
|
+
|
|
93
|
+
if (trigger) {
|
|
94
|
+
startAnimation();
|
|
95
|
+
timeOut = setTimeout(function () {
|
|
96
|
+
// This gracefully ends the animation
|
|
97
|
+
pauseAnimation();
|
|
98
|
+
}, duration);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return function () {
|
|
102
|
+
if (timeOut) {
|
|
103
|
+
// this clears up the animation
|
|
104
|
+
stopAnimation();
|
|
105
|
+
}
|
|
106
|
+
}; // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
107
|
+
}, [trigger, duration]);
|
|
108
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_reactCanvasConfetti.default, {
|
|
109
|
+
refConfetti: getInstance,
|
|
110
|
+
style: canvasStyles
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
Confetti.defaultProps = {
|
|
115
|
+
duration: 3000
|
|
116
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports, "buildEsuValidationSchema", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function get() {
|
|
11
|
+
return _EmailSignUpConfig.buildEsuValidationSchema;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(exports, "ESU_FIELDS", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function get() {
|
|
17
|
+
return _EmailSignUpConfig.ESU_FIELDS;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
exports.EmailSignUp = void 0;
|
|
21
|
+
|
|
22
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectWithoutProperties"));
|
|
23
|
+
|
|
24
|
+
var _react = _interopRequireDefault(require("react"));
|
|
25
|
+
|
|
26
|
+
var _EmailSignUp = require("./EmailSignUp.style");
|
|
27
|
+
|
|
28
|
+
var _ButtonWithStates = _interopRequireDefault(require("../../Atoms/ButtonWithStates/ButtonWithStates"));
|
|
29
|
+
|
|
30
|
+
var _Text = _interopRequireDefault(require("../../Atoms/Text/Text"));
|
|
31
|
+
|
|
32
|
+
var _EmailSignUpConfig = require("./_EmailSignUpConfig");
|
|
33
|
+
|
|
34
|
+
var _ErrorText = _interopRequireDefault(require("../../Atoms/ErrorText/ErrorText"));
|
|
35
|
+
|
|
36
|
+
var _Confetti = _interopRequireDefault(require("./_Confetti"));
|
|
37
|
+
|
|
38
|
+
var _excluded = ["title", "topCopy", "successCopy", "privacyCopy", "backgroundColour", "buttonColour", "formContext", "columnLayout"];
|
|
39
|
+
|
|
40
|
+
var EmailSignUp = function EmailSignUp(_ref) {
|
|
41
|
+
var title = _ref.title,
|
|
42
|
+
topCopy = _ref.topCopy,
|
|
43
|
+
successCopy = _ref.successCopy,
|
|
44
|
+
privacyCopy = _ref.privacyCopy,
|
|
45
|
+
backgroundColour = _ref.backgroundColour,
|
|
46
|
+
buttonColour = _ref.buttonColour,
|
|
47
|
+
formContext = _ref.formContext,
|
|
48
|
+
columnLayout = _ref.columnLayout,
|
|
49
|
+
rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
|
|
50
|
+
var _formContext$formStat = formContext.formState,
|
|
51
|
+
isValid = _formContext$formStat.isValid,
|
|
52
|
+
isSubmitting = _formContext$formStat.isSubmitting,
|
|
53
|
+
isSubmitted = _formContext$formStat.isSubmitted,
|
|
54
|
+
isSubmitSuccessful = _formContext$formStat.isSubmitSuccessful,
|
|
55
|
+
errors = _formContext$formStat.errors;
|
|
56
|
+
return /*#__PURE__*/_react.default.createElement(_EmailSignUp.ESUWrapper, Object.assign({
|
|
57
|
+
backgroundColour: backgroundColour
|
|
58
|
+
}, rest), /*#__PURE__*/_react.default.createElement(_EmailSignUp.Title, {
|
|
59
|
+
tag: "h2",
|
|
60
|
+
size: "xxl",
|
|
61
|
+
weight: "400",
|
|
62
|
+
family: "Anton",
|
|
63
|
+
uppercase: true
|
|
64
|
+
}, title), !isSubmitted ? /*#__PURE__*/_react.default.createElement(_EmailSignUp.TopCopyWrapper, null, /*#__PURE__*/_react.default.createElement(_Text.default, null, topCopy)) : isSubmitSuccessful && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Confetti.default, {
|
|
65
|
+
trigger: isSubmitSuccessful
|
|
66
|
+
}), /*#__PURE__*/_react.default.createElement(_EmailSignUp.TopCopyWrapper, null, /*#__PURE__*/_react.default.createElement(_Text.default, null, successCopy))), !isSubmitSuccessful && /*#__PURE__*/_react.default.createElement(_EmailSignUp.FormInner, null, /*#__PURE__*/_react.default.createElement(_EmailSignUp.NameWrapper, {
|
|
67
|
+
columnLayout: columnLayout
|
|
68
|
+
}, /*#__PURE__*/_react.default.createElement(_EmailSignUp.InputField, {
|
|
69
|
+
fieldName: _EmailSignUpConfig.ESU_FIELDS.FIRST_NAME,
|
|
70
|
+
id: "first-name",
|
|
71
|
+
type: "text",
|
|
72
|
+
label: "First Name",
|
|
73
|
+
placeholder: "Enter your first name",
|
|
74
|
+
formContext: formContext
|
|
75
|
+
}), /*#__PURE__*/_react.default.createElement(_EmailSignUp.InputField, {
|
|
76
|
+
fieldName: _EmailSignUpConfig.ESU_FIELDS.LAST_NAME,
|
|
77
|
+
id: "last-name",
|
|
78
|
+
type: "text",
|
|
79
|
+
label: "Last Name",
|
|
80
|
+
placeholder: "Enter your last name",
|
|
81
|
+
formContext: formContext
|
|
82
|
+
})), /*#__PURE__*/_react.default.createElement(_EmailSignUp.InputField, {
|
|
83
|
+
fieldName: _EmailSignUpConfig.ESU_FIELDS.EMAIL,
|
|
84
|
+
id: "email",
|
|
85
|
+
type: "email",
|
|
86
|
+
label: "Email Address",
|
|
87
|
+
placeholder: "example@youremail.com",
|
|
88
|
+
formContext: formContext
|
|
89
|
+
}), /*#__PURE__*/_react.default.createElement(_EmailSignUp.ButtonWrapper, {
|
|
90
|
+
buttonColour: buttonColour
|
|
91
|
+
}, /*#__PURE__*/_react.default.createElement(_ButtonWithStates.default, {
|
|
92
|
+
type: "submit",
|
|
93
|
+
disabled: !isValid || isSubmitting,
|
|
94
|
+
loading: isSubmitting,
|
|
95
|
+
loadingText: "Submitting...",
|
|
96
|
+
"data-test": "subscribe-button"
|
|
97
|
+
}, /*#__PURE__*/_react.default.createElement(_Text.default, null, "Subscribe")))), isSubmitted && !isSubmitSuccessful && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, Object.values(errors).map(function (error) {
|
|
98
|
+
return /*#__PURE__*/_react.default.createElement(_ErrorText.default, null, error.message);
|
|
99
|
+
})), /*#__PURE__*/_react.default.createElement(_EmailSignUp.PrivacyCopyWrapper, null, /*#__PURE__*/_react.default.createElement(_Text.default, null, privacyCopy)));
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
exports.EmailSignUp = EmailSignUp;
|
|
103
|
+
EmailSignUp.defaultProps = {
|
|
104
|
+
backgroundColour: 'deep_violet_dark',
|
|
105
|
+
buttonColour: 'red',
|
|
106
|
+
columnLayout: false
|
|
107
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.buildEsuValidationSchema = exports.ESU_FIELDS = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _lodash = require("lodash");
|
|
13
|
+
|
|
14
|
+
var yup = _interopRequireWildcard(require("yup"));
|
|
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
|
+
/**
|
|
21
|
+
* ESU_FIELDS
|
|
22
|
+
*
|
|
23
|
+
* Exposes an enum to consumer of the component, to accurately access the underlying field names.
|
|
24
|
+
* can be used in conjunction with RHF or buildEsuValidationSchema
|
|
25
|
+
* to customise form validation or behaviour, as the fields are handled within the CL
|
|
26
|
+
* we just make this read-only to prevent any external changes of this object.
|
|
27
|
+
*/
|
|
28
|
+
var ESU_FIELDS = Object.freeze({
|
|
29
|
+
FIRST_NAME: 'firstName',
|
|
30
|
+
LAST_NAME: 'lastName',
|
|
31
|
+
EMAIL: 'email'
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* buildEsuValidationSchema
|
|
35
|
+
*
|
|
36
|
+
* Exposes a function that can be passed a partial or complete yup schema
|
|
37
|
+
* to extend or override the default buildEsuValidationSchema
|
|
38
|
+
*
|
|
39
|
+
* @param overrides {Object} - A yup schema object (or an empty object)
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
exports.ESU_FIELDS = ESU_FIELDS;
|
|
43
|
+
|
|
44
|
+
var buildEsuValidationSchema = function buildEsuValidationSchema(overrides) {
|
|
45
|
+
var _yup$object;
|
|
46
|
+
|
|
47
|
+
var defaultSchema = yup.object((_yup$object = {}, (0, _defineProperty2.default)(_yup$object, ESU_FIELDS.FIRST_NAME, yup.string().required('Please enter your first name').matches(/^[A-Za-z][A-Za-z' -]*$/, "This field only accepts letters and ' - and must start with a letter").max(25, 'Your first name must be between 1 and 25 characters')), (0, _defineProperty2.default)(_yup$object, ESU_FIELDS.LAST_NAME, yup.string().required('Please enter your last name').matches(/^[A-Za-z][A-Za-z' -]*$/, "This field only accepts letters and ' - and must start with a letter").max(50, 'Your first name must be between 1 and 50 characters')), (0, _defineProperty2.default)(_yup$object, ESU_FIELDS.EMAIL, yup.string().required('Please enter your email address').email('Please enter a valid email address').max(100, 'Your email address must be between 1 and 100 characters long')), _yup$object));
|
|
48
|
+
return (0, _lodash.merge)(defaultSchema, overrides);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
exports.buildEsuValidationSchema = buildEsuValidationSchema;
|
|
@@ -0,0 +1,51 @@
|
|
|
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 _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
|
|
11
|
+
|
|
12
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectWithoutProperties"));
|
|
13
|
+
|
|
14
|
+
var _react = _interopRequireDefault(require("react"));
|
|
15
|
+
|
|
16
|
+
var _Input = _interopRequireDefault(require("../../Atoms/Input/Input"));
|
|
17
|
+
|
|
18
|
+
var _excluded = ["fieldName", "label", "optional", "fieldType", "formContext"];
|
|
19
|
+
|
|
20
|
+
// TODO: This is a copy paste of the RHF friendly `TextInput` from Marketing Prefs.
|
|
21
|
+
// Perhaps it would be worthwhile refactoring this into a new `Atom` as a seperate PR.
|
|
22
|
+
var TextInput = function TextInput(_ref) {
|
|
23
|
+
var fieldName = _ref.fieldName,
|
|
24
|
+
label = _ref.label,
|
|
25
|
+
optional = _ref.optional,
|
|
26
|
+
fieldType = _ref.fieldType,
|
|
27
|
+
formContext = _ref.formContext,
|
|
28
|
+
rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
|
|
29
|
+
var errors = formContext.errors,
|
|
30
|
+
register = formContext.register;
|
|
31
|
+
var props = (0, _objectSpread2.default)({
|
|
32
|
+
name: fieldName,
|
|
33
|
+
type: fieldType,
|
|
34
|
+
label: label,
|
|
35
|
+
placeholder: label,
|
|
36
|
+
errorMsg: errors && errors[fieldName] && errors[fieldName].message,
|
|
37
|
+
optional: optional,
|
|
38
|
+
'aria-required': !optional
|
|
39
|
+
}, rest);
|
|
40
|
+
return /*#__PURE__*/_react.default.createElement(_Input.default, Object.assign({}, props, {
|
|
41
|
+
ref: register
|
|
42
|
+
}));
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
TextInput.defaultProps = {
|
|
46
|
+
optional: null,
|
|
47
|
+
fieldType: 'text',
|
|
48
|
+
formContext: null
|
|
49
|
+
};
|
|
50
|
+
var _default = TextInput;
|
|
51
|
+
exports.default = _default;
|