@financial-times/n-conversion-forms 28.2.0 → 28.3.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.
@@ -1,7 +1,6 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import classNames from 'classnames';
4
- import { getCountries } from '../utils/countries';
3
+ import { Country } from './country';
5
4
 
6
5
  export function BillingCountry({
7
6
  fieldId = 'billingCountryField',
@@ -11,58 +10,19 @@ export function BillingCountry({
11
10
  isDisabled = false,
12
11
  value,
13
12
  }) {
14
- const selectWrapperClassName = classNames([
15
- 'o-forms-input',
16
- 'o-forms-input--select',
17
- { 'o-forms-input--invalid': hasError },
18
- ]);
19
- const props = {
20
- id: inputId,
21
- className: 'js-field__input js-item__value',
22
- 'aria-required': true,
23
- required: true,
24
- name: inputId,
25
- 'data-trackable': 'field-billing-country',
26
- disabled: isDisabled,
27
- };
28
- const countries = getCountries({ filter: filterList, value });
29
-
30
- const createOption = (country) => (
31
- <option key={country.code} value={country.code} selected={country.selected}>
32
- {country.name}
33
- </option>
34
- );
35
- const createOptGroup = (country) => (
36
- <optgroup key={country.label} label={country.label}>
37
- {country.countries.map((country) => createOption(country))}
38
- </optgroup>
39
- );
40
- const createSelect = (countries) => (
41
- <select {...props}>
42
- <option value="" disabled>
43
- Please select a country
44
- </option>
45
- {countries.map((country) =>
46
- country.label ? createOptGroup(country) : createOption(country)
47
- )}
48
- </select>
49
- );
50
-
51
13
  return (
52
- <label
53
- id={fieldId}
54
- className="o-forms-field"
55
- data-validate="required"
56
- htmlFor={inputId}
57
- >
58
- <span className="o-forms-title">
59
- <span className="o-forms-title__main">Billing Country</span>
60
- </span>
61
- <span className={selectWrapperClassName}>
62
- {createSelect(countries)}
63
- <span className="o-forms-input__error">Please select your country</span>
64
- </span>
65
- </label>
14
+ <Country
15
+ dataTrackable="field-billing-country"
16
+ fieldId={fieldId}
17
+ filterList={filterList}
18
+ hasError={hasError}
19
+ inputId={inputId}
20
+ isB2b={false}
21
+ isDisabled={isDisabled}
22
+ isPlaceholderDisabled={true}
23
+ label="Billing Country"
24
+ value={value}
25
+ />
66
26
  );
67
27
  }
68
28
 
@@ -3,7 +3,7 @@ import { expectToRenderCorrectly } from '../test-jest/helpers/expect-to-render-c
3
3
 
4
4
  expect.extend(expectToRenderCorrectly);
5
5
 
6
- describe('Country', () => {
6
+ describe('BillingCountry', () => {
7
7
  it('renders with default props', () => {
8
8
  const props = {};
9
9
 
@@ -4,28 +4,30 @@ import classNames from 'classnames';
4
4
  import { getCountries } from '../utils/countries';
5
5
 
6
6
  export function Country({
7
+ additionalFieldInformation,
8
+ dataTrackable = 'field-country',
7
9
  fieldId = 'countryField',
8
10
  filterList = [],
9
11
  hasError = false,
10
12
  inputId = 'country',
11
13
  isB2b = false,
12
14
  isDisabled = false,
15
+ isPlaceholderDisabled = false,
13
16
  value,
14
- additionalFieldInformation,
17
+ label = `Country${isB2b ? '/Region' : ''}`,
18
+ errorText = `Please select your country${isB2b ? '/region' : ''}`,
15
19
  }) {
16
20
  const selectWrapperClassName = classNames([
17
21
  'o-forms-input',
18
22
  'o-forms-input--select',
19
23
  { 'o-forms-input--invalid': hasError },
20
24
  ]);
21
- const label = `Country${isB2b ? '/Region' : ''}`;
22
- const error = `Please select your country${isB2b ? '/region' : ''}`;
23
25
  const selectProps = {
24
26
  id: inputId,
25
27
  'aria-required': true,
26
28
  required: true,
27
- name: 'country',
28
- 'data-trackable': 'field-country',
29
+ name: inputId,
30
+ 'data-trackable': dataTrackable,
29
31
  disabled: isDisabled,
30
32
  };
31
33
  const countries = getCountries({ filter: filterList, value });
@@ -42,7 +44,9 @@ export function Country({
42
44
  );
43
45
  const createSelect = (countries) => (
44
46
  <select {...selectProps}>
45
- <option value="">Please select a country{isB2b ? '/region' : ''}</option>
47
+ <option value="" disabled={isPlaceholderDisabled}>
48
+ Please select a country{isB2b ? '/region' : ''}
49
+ </option>
46
50
  {countries.map((country) =>
47
51
  country.label ? createOptGroup(country) : createOption(country)
48
52
  )}
@@ -60,7 +64,7 @@ export function Country({
60
64
  return (
61
65
  <label
62
66
  id={fieldId}
63
- className="o-forms-field js-unknown-user-field ncf__validation-error"
67
+ className="o-forms-field ncf__validation-error"
64
68
  data-validate="required"
65
69
  htmlFor={selectProps.id}
66
70
  >
@@ -69,7 +73,7 @@ export function Country({
69
73
  </span>
70
74
  <span className={selectWrapperClassName}>
71
75
  {createSelect(countries)}
72
- <span className={fieldErrorClassNames}>{error}</span>
76
+ <span className={fieldErrorClassNames}>{errorText}</span>
73
77
  {additionalFieldInformation ? (
74
78
  <p className="additional-field-information">
75
79
  {additionalFieldInformation}
@@ -81,12 +85,16 @@ export function Country({
81
85
  }
82
86
 
83
87
  Country.propTypes = {
88
+ additionalFieldInformation: PropTypes.node,
89
+ dataTrackable: PropTypes.string,
90
+ errorText: PropTypes.string,
84
91
  fieldId: PropTypes.string,
85
92
  filterList: PropTypes.arrayOf(PropTypes.string),
86
93
  hasError: PropTypes.bool,
87
94
  inputId: PropTypes.string,
88
95
  isB2b: PropTypes.bool,
89
96
  isDisabled: PropTypes.bool,
97
+ isPlaceholderDisabled: PropTypes.bool,
98
+ label: PropTypes.string,
90
99
  value: PropTypes.string,
91
- additionalFieldInformation: PropTypes.node,
92
100
  };
@@ -18,6 +18,14 @@ describe('Country', () => {
18
18
  expect(Country).toRenderCorrectly(props);
19
19
  });
20
20
 
21
+ it('renders with dataTrackable', () => {
22
+ const props = {
23
+ dataTrackable: 'some-trackable',
24
+ };
25
+
26
+ expect(Country).toRenderCorrectly(props);
27
+ });
28
+
21
29
  it('renders with large filterList', () => {
22
30
  const props = {
23
31
  filterList: [
@@ -78,4 +86,28 @@ describe('Country', () => {
78
86
 
79
87
  expect(Country).toRenderCorrectly(props);
80
88
  });
89
+
90
+ it('renders with inputId', () => {
91
+ const props = {
92
+ inputId: 'some-other-name',
93
+ };
94
+
95
+ expect(Country).toRenderCorrectly(props);
96
+ });
97
+
98
+ it('renders with label', () => {
99
+ const props = {
100
+ label: 'Some Label',
101
+ };
102
+
103
+ expect(Country).toRenderCorrectly(props);
104
+ });
105
+
106
+ it('renders with errorText', () => {
107
+ const props = {
108
+ errorText: 'Some Error Text',
109
+ };
110
+
111
+ expect(Country).toRenderCorrectly(props);
112
+ });
81
113
  });
@@ -7,8 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.BillingCountry = BillingCountry;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _propTypes = _interopRequireDefault(require("prop-types"));
10
- var _classnames = _interopRequireDefault(require("classnames"));
11
- var _countries = require("../utils/countries");
10
+ var _country = require("./country");
12
11
  function BillingCountry(_ref) {
13
12
  var _ref$fieldId = _ref.fieldId,
14
13
  fieldId = _ref$fieldId === void 0 ? 'billingCountryField' : _ref$fieldId,
@@ -21,59 +20,18 @@ function BillingCountry(_ref) {
21
20
  _ref$isDisabled = _ref.isDisabled,
22
21
  isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
23
22
  value = _ref.value;
24
- var selectWrapperClassName = (0, _classnames["default"])(['o-forms-input', 'o-forms-input--select', {
25
- 'o-forms-input--invalid': hasError
26
- }]);
27
- var props = {
28
- id: inputId,
29
- className: 'js-field__input js-item__value',
30
- 'aria-required': true,
31
- required: true,
32
- name: inputId,
33
- 'data-trackable': 'field-billing-country',
34
- disabled: isDisabled
35
- };
36
- var countries = (0, _countries.getCountries)({
37
- filter: filterList,
23
+ return /*#__PURE__*/_react["default"].createElement(_country.Country, {
24
+ dataTrackable: "field-billing-country",
25
+ fieldId: fieldId,
26
+ filterList: filterList,
27
+ hasError: hasError,
28
+ inputId: inputId,
29
+ isB2b: false,
30
+ isDisabled: isDisabled,
31
+ isPlaceholderDisabled: true,
32
+ label: "Billing Country",
38
33
  value: value
39
34
  });
40
- var createOption = function createOption(country) {
41
- return /*#__PURE__*/_react["default"].createElement("option", {
42
- key: country.code,
43
- value: country.code,
44
- selected: country.selected
45
- }, country.name);
46
- };
47
- var createOptGroup = function createOptGroup(country) {
48
- return /*#__PURE__*/_react["default"].createElement("optgroup", {
49
- key: country.label,
50
- label: country.label
51
- }, country.countries.map(function (country) {
52
- return createOption(country);
53
- }));
54
- };
55
- var createSelect = function createSelect(countries) {
56
- return /*#__PURE__*/_react["default"].createElement("select", props, /*#__PURE__*/_react["default"].createElement("option", {
57
- value: "",
58
- disabled: true
59
- }, "Please select a country"), countries.map(function (country) {
60
- return country.label ? createOptGroup(country) : createOption(country);
61
- }));
62
- };
63
- return /*#__PURE__*/_react["default"].createElement("label", {
64
- id: fieldId,
65
- className: "o-forms-field",
66
- "data-validate": "required",
67
- htmlFor: inputId
68
- }, /*#__PURE__*/_react["default"].createElement("span", {
69
- className: "o-forms-title"
70
- }, /*#__PURE__*/_react["default"].createElement("span", {
71
- className: "o-forms-title__main"
72
- }, "Billing Country")), /*#__PURE__*/_react["default"].createElement("span", {
73
- className: selectWrapperClassName
74
- }, createSelect(countries), /*#__PURE__*/_react["default"].createElement("span", {
75
- className: "o-forms-input__error"
76
- }, "Please select your country")));
77
35
  }
78
36
  BillingCountry.propTypes = {
79
37
  fieldId: _propTypes["default"].string,
package/dist/country.js CHANGED
@@ -10,7 +10,10 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
10
10
  var _classnames = _interopRequireDefault(require("classnames"));
11
11
  var _countries = require("../utils/countries");
12
12
  function Country(_ref) {
13
- var _ref$fieldId = _ref.fieldId,
13
+ var additionalFieldInformation = _ref.additionalFieldInformation,
14
+ _ref$dataTrackable = _ref.dataTrackable,
15
+ dataTrackable = _ref$dataTrackable === void 0 ? 'field-country' : _ref$dataTrackable,
16
+ _ref$fieldId = _ref.fieldId,
14
17
  fieldId = _ref$fieldId === void 0 ? 'countryField' : _ref$fieldId,
15
18
  _ref$filterList = _ref.filterList,
16
19
  filterList = _ref$filterList === void 0 ? [] : _ref$filterList,
@@ -22,19 +25,22 @@ function Country(_ref) {
22
25
  isB2b = _ref$isB2b === void 0 ? false : _ref$isB2b,
23
26
  _ref$isDisabled = _ref.isDisabled,
24
27
  isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
28
+ _ref$isPlaceholderDis = _ref.isPlaceholderDisabled,
29
+ isPlaceholderDisabled = _ref$isPlaceholderDis === void 0 ? false : _ref$isPlaceholderDis,
25
30
  value = _ref.value,
26
- additionalFieldInformation = _ref.additionalFieldInformation;
31
+ _ref$label = _ref.label,
32
+ label = _ref$label === void 0 ? "Country".concat(isB2b ? '/Region' : '') : _ref$label,
33
+ _ref$errorText = _ref.errorText,
34
+ errorText = _ref$errorText === void 0 ? "Please select your country".concat(isB2b ? '/region' : '') : _ref$errorText;
27
35
  var selectWrapperClassName = (0, _classnames["default"])(['o-forms-input', 'o-forms-input--select', {
28
36
  'o-forms-input--invalid': hasError
29
37
  }]);
30
- var label = "Country".concat(isB2b ? '/Region' : '');
31
- var error = "Please select your country".concat(isB2b ? '/region' : '');
32
38
  var selectProps = {
33
39
  id: inputId,
34
40
  'aria-required': true,
35
41
  required: true,
36
- name: 'country',
37
- 'data-trackable': 'field-country',
42
+ name: inputId,
43
+ 'data-trackable': dataTrackable,
38
44
  disabled: isDisabled
39
45
  };
40
46
  var countries = (0, _countries.getCountries)({
@@ -58,7 +64,8 @@ function Country(_ref) {
58
64
  };
59
65
  var createSelect = function createSelect(countries) {
60
66
  return /*#__PURE__*/_react["default"].createElement("select", selectProps, /*#__PURE__*/_react["default"].createElement("option", {
61
- value: ""
67
+ value: "",
68
+ disabled: isPlaceholderDisabled
62
69
  }, "Please select a country", isB2b ? '/region' : ''), countries.map(function (country) {
63
70
  return country.label ? createOptGroup(country) : createOption(country);
64
71
  }));
@@ -68,7 +75,7 @@ function Country(_ref) {
68
75
  }]);
69
76
  return /*#__PURE__*/_react["default"].createElement("label", {
70
77
  id: fieldId,
71
- className: "o-forms-field js-unknown-user-field ncf__validation-error",
78
+ className: "o-forms-field ncf__validation-error",
72
79
  "data-validate": "required",
73
80
  htmlFor: selectProps.id
74
81
  }, /*#__PURE__*/_react["default"].createElement("span", {
@@ -79,17 +86,21 @@ function Country(_ref) {
79
86
  className: selectWrapperClassName
80
87
  }, createSelect(countries), /*#__PURE__*/_react["default"].createElement("span", {
81
88
  className: fieldErrorClassNames
82
- }, error), additionalFieldInformation ? /*#__PURE__*/_react["default"].createElement("p", {
89
+ }, errorText), additionalFieldInformation ? /*#__PURE__*/_react["default"].createElement("p", {
83
90
  className: "additional-field-information"
84
91
  }, additionalFieldInformation) : null));
85
92
  }
86
93
  Country.propTypes = {
94
+ additionalFieldInformation: _propTypes["default"].node,
95
+ dataTrackable: _propTypes["default"].string,
96
+ errorText: _propTypes["default"].string,
87
97
  fieldId: _propTypes["default"].string,
88
98
  filterList: _propTypes["default"].arrayOf(_propTypes["default"].string),
89
99
  hasError: _propTypes["default"].bool,
90
100
  inputId: _propTypes["default"].string,
91
101
  isB2b: _propTypes["default"].bool,
92
102
  isDisabled: _propTypes["default"].bool,
93
- value: _propTypes["default"].string,
94
- additionalFieldInformation: _propTypes["default"].node
103
+ isPlaceholderDisabled: _propTypes["default"].bool,
104
+ label: _propTypes["default"].string,
105
+ value: _propTypes["default"].string
95
106
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@financial-times/n-conversion-forms",
3
- "version": "28.2.0",
3
+ "version": "28.3.0",
4
4
  "description": "Containing jsx components and styles for forms included on Accounts and Acqusition apps (next-signup, next-profile, next-retention, etc).",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {