@financial-times/n-conversion-forms 40.0.2 → 41.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.
@@ -1,84 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import classNames from 'classnames';
4
- import { canadianProvinces } from 'n-common-static-data';
5
- const defaultProvinces = canadianProvinces.provinces;
6
-
7
- export function Province({
8
- value,
9
- fieldId = 'provinceField',
10
- selectId = 'province',
11
- hasError = false,
12
- isHidden = false,
13
- isBillingProvince = false,
14
- isDisabled = false,
15
- provinces = defaultProvinces,
16
- }) {
17
- const fieldClassNames = classNames([
18
- 'o-forms-field',
19
- { ncf__hidden: isHidden },
20
- ]);
21
-
22
- const inputWrapperClassNames = classNames([
23
- 'o-forms-input',
24
- 'o-forms-input--select',
25
- { 'o-forms-input--invalid': hasError },
26
- ]);
27
-
28
- return (
29
- <label
30
- id={fieldId}
31
- className={fieldClassNames}
32
- data-validate="required"
33
- htmlFor={selectId}
34
- >
35
- <span className="o-forms-title">
36
- <span className="o-forms-title__main">
37
- {isBillingProvince ? 'Billing ' : ''}Province
38
- </span>
39
- </span>
40
- <span className={inputWrapperClassNames}>
41
- <select
42
- id={selectId}
43
- aria-required="true"
44
- required
45
- name={isBillingProvince ? 'billingProvince' : 'province'}
46
- data-trackable="field-province"
47
- disabled={isDisabled}
48
- defaultValue={value}
49
- >
50
- <option disabled value="">
51
- Please select a province
52
- </option>
53
-
54
- {provinces.map(({ code, name }) => {
55
- return (
56
- <option key={code} value={code}>
57
- {name}
58
- </option>
59
- );
60
- })}
61
- </select>
62
- <span className="o-forms-input__error">
63
- Please select your province.
64
- </span>
65
- </span>
66
- </label>
67
- );
68
- }
69
-
70
- Province.propTypes = {
71
- value: PropTypes.string,
72
- fieldId: PropTypes.string,
73
- selectId: PropTypes.string,
74
- hasError: PropTypes.bool,
75
- isHidden: PropTypes.bool,
76
- isBillingProvince: PropTypes.bool,
77
- isDisabled: PropTypes.bool,
78
- provinces: PropTypes.arrayOf(
79
- PropTypes.shape({
80
- code: PropTypes.string,
81
- name: PropTypes.string,
82
- })
83
- ),
84
- };
@@ -1,96 +0,0 @@
1
- import { Province } from './index';
2
- import { expectToRenderCorrectly } from '../test-jest/helpers/expect-to-render-correctly';
3
- import { canadianProvinces } from 'n-common-static-data';
4
- const defaultProvinces = canadianProvinces.provinces;
5
-
6
- import Enzyme, { mount } from 'enzyme';
7
- import Adapter from 'enzyme-adapter-react-16';
8
- Enzyme.configure({ adapter: new Adapter() });
9
-
10
- expect.extend(expectToRenderCorrectly);
11
-
12
- describe('Province', () => {
13
- it('render a select with a label', () => {
14
- const props = {
15
- provinces: defaultProvinces,
16
- };
17
-
18
- expect(Province).toRenderCorrectly(props);
19
- });
20
-
21
- it('can render an initial selected value', () => {
22
- const props = {
23
- provinces: defaultProvinces,
24
- value: 'AB',
25
- };
26
-
27
- expect(Province).toRenderCorrectly(props);
28
- });
29
-
30
- it('can render a disabled select', () => {
31
- const props = {
32
- provinces: defaultProvinces,
33
- isDisabled: true,
34
- };
35
-
36
- expect(Province).toRenderCorrectly(props);
37
- });
38
-
39
- it('can render an error message', () => {
40
- const props = {
41
- provinces: defaultProvinces,
42
- hasError: true,
43
- };
44
-
45
- expect(Province).toRenderCorrectly(props);
46
- });
47
-
48
- it('can apply class to hide the component', () => {
49
- const props = {
50
- provinces: defaultProvinces,
51
- isHidden: true,
52
- };
53
-
54
- expect(Province).toRenderCorrectly(props);
55
- });
56
-
57
- it('can override ID for field', () => {
58
- const props = {
59
- fieldId: 'fieldID',
60
- };
61
- const component = mount(Province(props));
62
- const field = component.find('#fieldID');
63
-
64
- expect(field.exists()).toBe(true);
65
- });
66
-
67
- it('can override ID for select', () => {
68
- const props = {
69
- selectId: 'selectId',
70
- };
71
- const component = mount(Province(props));
72
- const select = component.find('select#selectId');
73
-
74
- expect(select.exists()).toBe(true);
75
- });
76
-
77
- it('applies context-specific name if is billing province', () => {
78
- const props = {
79
- isBillingProvince: true,
80
- };
81
- const component = mount(Province(props));
82
- const selectElementName = component.find('select#province').prop('name');
83
-
84
- expect(selectElementName).toBe('billingProvince');
85
- });
86
-
87
- it('applies context-specific name if is not billing province', () => {
88
- const props = {
89
- isBillingProvince: false,
90
- };
91
- const component = mount(Province(props));
92
- const selectElementName = component.find('select#province').prop('name');
93
-
94
- expect(selectElementName).toBe('province');
95
- });
96
- });
@@ -1,21 +0,0 @@
1
- import React from 'react';
2
- import { Province } from './province';
3
-
4
- export default {
5
- title: 'Province',
6
- component: Province,
7
- };
8
-
9
- export const Basic = (args) => <Province {...args} />;
10
- Basic.args = {
11
- provinces: [
12
- {
13
- code: 'AB',
14
- name: 'Alberta',
15
- },
16
- {
17
- code: 'BC',
18
- name: 'British Columbia',
19
- },
20
- ],
21
- };
@@ -1,83 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import classNames from 'classnames';
4
- import { americanStates } from 'n-common-static-data';
5
- const defaultStates = americanStates.states;
6
-
7
- export function State({
8
- value,
9
- fieldId = 'stateField',
10
- selectId = 'state',
11
- hasError = false,
12
- isHidden = false,
13
- isBillingState = false,
14
- isDisabled = false,
15
- states = defaultStates,
16
- }) {
17
- const fieldClassNames = classNames([
18
- 'o-forms-field',
19
- { ncf__hidden: isHidden },
20
- ]);
21
-
22
- const inputWrapperClassNames = classNames([
23
- 'o-forms-input',
24
- 'o-forms-input--select',
25
- { 'o-forms-input--invalid': hasError },
26
- ]);
27
-
28
- return (
29
- <label
30
- id={fieldId}
31
- className={fieldClassNames}
32
- data-validate="required"
33
- htmlFor={selectId}
34
- >
35
- <span className="o-forms-title">
36
- <span className="o-forms-title__main">
37
- {isBillingState ? 'Billing ' : ''}State
38
- </span>
39
- </span>
40
-
41
- <span className={inputWrapperClassNames}>
42
- <select
43
- id={selectId}
44
- aria-required="true"
45
- required
46
- name={isBillingState ? 'billingState' : 'state'}
47
- data-trackable="field-state"
48
- disabled={isDisabled}
49
- defaultValue={value}
50
- >
51
- <option disabled value="">
52
- Please select a state
53
- </option>
54
-
55
- {states.map(({ code, name }) => {
56
- return (
57
- <option key={code} value={code}>
58
- {name}
59
- </option>
60
- );
61
- })}
62
- </select>
63
- <span className="o-forms-input__error">Please select your state</span>
64
- </span>
65
- </label>
66
- );
67
- }
68
-
69
- State.propTypes = {
70
- value: PropTypes.string,
71
- fieldId: PropTypes.string,
72
- selectId: PropTypes.string,
73
- hasError: PropTypes.bool,
74
- isHidden: PropTypes.bool,
75
- isBillingState: PropTypes.bool,
76
- isDisabled: PropTypes.bool,
77
- states: PropTypes.arrayOf(
78
- PropTypes.shape({
79
- code: PropTypes.string,
80
- name: PropTypes.string,
81
- })
82
- ),
83
- };
@@ -1,96 +0,0 @@
1
- import { State } from './index';
2
- import { expectToRenderCorrectly } from '../test-jest/helpers/expect-to-render-correctly';
3
- import { americanStates } from 'n-common-static-data';
4
- const defaultStates = americanStates.states;
5
-
6
- import Enzyme, { mount } from 'enzyme';
7
- import Adapter from 'enzyme-adapter-react-16';
8
- Enzyme.configure({ adapter: new Adapter() });
9
-
10
- expect.extend(expectToRenderCorrectly);
11
-
12
- describe('State', () => {
13
- it('render a select with a label', () => {
14
- const props = {
15
- states: defaultStates,
16
- };
17
-
18
- expect(State).toRenderCorrectly(props);
19
- });
20
-
21
- it('can render an initial selected value', () => {
22
- const props = {
23
- states: defaultStates,
24
- value: 'AL',
25
- };
26
-
27
- expect(State).toRenderCorrectly(props);
28
- });
29
-
30
- it('can render a disabled select', () => {
31
- const props = {
32
- states: defaultStates,
33
- isDisabled: true,
34
- };
35
-
36
- expect(State).toRenderCorrectly(props);
37
- });
38
-
39
- it('can render an error message', () => {
40
- const props = {
41
- states: defaultStates,
42
- hasError: true,
43
- };
44
-
45
- expect(State).toRenderCorrectly(props);
46
- });
47
-
48
- it('can apply class to hide the component', () => {
49
- const props = {
50
- states: defaultStates,
51
- isHidden: true,
52
- };
53
-
54
- expect(State).toRenderCorrectly(props);
55
- });
56
-
57
- it('can override ID for field', () => {
58
- const props = {
59
- fieldId: 'fieldID',
60
- };
61
- const component = mount(State(props));
62
- const field = component.find('#fieldID');
63
-
64
- expect(field.exists()).toBe(true);
65
- });
66
-
67
- it('can override ID for select', () => {
68
- const props = {
69
- selectId: 'selectId',
70
- };
71
- const component = mount(State(props));
72
- const select = component.find('select#selectId');
73
-
74
- expect(select.exists()).toBe(true);
75
- });
76
-
77
- it('applies context-specific name if is billing state', () => {
78
- const props = {
79
- isBillingState: true,
80
- };
81
- const component = mount(State(props));
82
- const selectElementName = component.find('select#state').prop('name');
83
-
84
- expect(selectElementName).toBe('billingState');
85
- });
86
-
87
- it('applies context-specific name if is not billing state', () => {
88
- const props = {
89
- isBillingState: false,
90
- };
91
- const component = mount(State(props));
92
- const selectElementName = component.find('select#state').prop('name');
93
-
94
- expect(selectElementName).toBe('state');
95
- });
96
- });
@@ -1,25 +0,0 @@
1
- import React from 'react';
2
- import { State } from './state';
3
-
4
- export default {
5
- title: 'State',
6
- component: State,
7
- };
8
-
9
- export const Basic = (args) => <State {...args} />;
10
- Basic.args = {
11
- states: [
12
- {
13
- code: 'AL',
14
- name: 'Alabama',
15
- },
16
- {
17
- code: 'AK',
18
- name: 'Alaska',
19
- },
20
- {
21
- code: 'AZ',
22
- name: 'Arizona',
23
- },
24
- ],
25
- };
package/dist/state.jsx DELETED
@@ -1,80 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.State = State;
8
- var _react = _interopRequireDefault(require("react"));
9
- var _propTypes = _interopRequireDefault(require("prop-types"));
10
- var _classnames = _interopRequireDefault(require("classnames"));
11
- var _nCommonStaticData = require("n-common-static-data");
12
- var defaultStates = _nCommonStaticData.americanStates.states;
13
- function State(_ref) {
14
- var value = _ref.value,
15
- _ref$fieldId = _ref.fieldId,
16
- fieldId = _ref$fieldId === void 0 ? 'stateField' : _ref$fieldId,
17
- _ref$selectId = _ref.selectId,
18
- selectId = _ref$selectId === void 0 ? 'state' : _ref$selectId,
19
- _ref$hasError = _ref.hasError,
20
- hasError = _ref$hasError === void 0 ? false : _ref$hasError,
21
- _ref$isHidden = _ref.isHidden,
22
- isHidden = _ref$isHidden === void 0 ? false : _ref$isHidden,
23
- _ref$isBillingState = _ref.isBillingState,
24
- isBillingState = _ref$isBillingState === void 0 ? false : _ref$isBillingState,
25
- _ref$isDisabled = _ref.isDisabled,
26
- isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
27
- _ref$states = _ref.states,
28
- states = _ref$states === void 0 ? defaultStates : _ref$states;
29
- var fieldClassNames = (0, _classnames["default"])(['o-forms-field', {
30
- ncf__hidden: isHidden
31
- }]);
32
- var inputWrapperClassNames = (0, _classnames["default"])(['o-forms-input', 'o-forms-input--select', {
33
- 'o-forms-input--invalid': hasError
34
- }]);
35
- return /*#__PURE__*/_react["default"].createElement("label", {
36
- id: fieldId,
37
- className: fieldClassNames,
38
- "data-validate": "required",
39
- htmlFor: selectId
40
- }, /*#__PURE__*/_react["default"].createElement("span", {
41
- className: "o-forms-title"
42
- }, /*#__PURE__*/_react["default"].createElement("span", {
43
- className: "o-forms-title__main"
44
- }, isBillingState ? 'Billing ' : '', "State")), /*#__PURE__*/_react["default"].createElement("span", {
45
- className: inputWrapperClassNames
46
- }, /*#__PURE__*/_react["default"].createElement("select", {
47
- id: selectId,
48
- "aria-required": "true",
49
- required: true,
50
- name: isBillingState ? 'billingState' : 'state',
51
- "data-trackable": "field-state",
52
- disabled: isDisabled,
53
- defaultValue: value
54
- }, /*#__PURE__*/_react["default"].createElement("option", {
55
- disabled: true,
56
- value: ""
57
- }, "Please select a state"), states.map(function (_ref2) {
58
- var code = _ref2.code,
59
- name = _ref2.name;
60
- return /*#__PURE__*/_react["default"].createElement("option", {
61
- key: code,
62
- value: code
63
- }, name);
64
- })), /*#__PURE__*/_react["default"].createElement("span", {
65
- className: "o-forms-input__error"
66
- }, "Please select your state")));
67
- }
68
- State.propTypes = {
69
- value: _propTypes["default"].string,
70
- fieldId: _propTypes["default"].string,
71
- selectId: _propTypes["default"].string,
72
- hasError: _propTypes["default"].bool,
73
- isHidden: _propTypes["default"].bool,
74
- isBillingState: _propTypes["default"].bool,
75
- isDisabled: _propTypes["default"].bool,
76
- states: _propTypes["default"].arrayOf(_propTypes["default"].shape({
77
- code: _propTypes["default"].string,
78
- name: _propTypes["default"].string
79
- }))
80
- };
package/utils/province.js DELETED
@@ -1,9 +0,0 @@
1
- const FormElement = require('./form-element');
2
-
3
- class Province extends FormElement {
4
- constructor(document) {
5
- super(document, '.ncf #provinceField');
6
- }
7
- }
8
-
9
- module.exports = Province;
package/utils/state.js DELETED
@@ -1,9 +0,0 @@
1
- const FormElement = require('./form-element');
2
-
3
- class State extends FormElement {
4
- constructor(document) {
5
- super(document, '.ncf #stateField');
6
- }
7
- }
8
-
9
- module.exports = State;