@sb1/ffe-form-react 8.1.2 → 9.0.2

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/es/Input.js CHANGED
@@ -1,4 +1,4 @@
1
- var _excluded = ["className", "inline", "textLike"];
1
+ var _excluded = ["className", "inline", "textLike", "textRightAlign"];
2
2
 
3
3
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
4
 
@@ -13,6 +13,7 @@ var Input = /*#__PURE__*/React.forwardRef(function (props, ref) {
13
13
  var className = props.className,
14
14
  inline = props.inline,
15
15
  textLike = props.textLike,
16
+ textRightAlign = props.textRightAlign,
16
17
  rest = _objectWithoutProperties(props, _excluded);
17
18
 
18
19
  return /*#__PURE__*/React.createElement("input", _extends({
@@ -20,6 +21,8 @@ var Input = /*#__PURE__*/React.forwardRef(function (props, ref) {
20
21
  'ffe-input-field--inline': inline
21
22
  }, {
22
23
  'ffe-input-field--text-like': textLike
24
+ }, {
25
+ 'ffe-input-field--text-right-align': textRightAlign
23
26
  }, className),
24
27
  ref: ref
25
28
  }, rest));
@@ -31,6 +34,9 @@ Input.propTypes = {
31
34
  inline: bool,
32
35
 
33
36
  /** Apply the text-like modifier by setting this to `true`. */
34
- textLike: bool
37
+ textLike: bool,
38
+
39
+ /** Make the text right aligned */
40
+ textRightAlign: bool
35
41
  };
36
42
  export default Input;
@@ -104,8 +104,8 @@ RadioButtonInputGroup.propTypes = {
104
104
  */
105
105
  label: oneOfType([node, string]),
106
106
 
107
- /** The name of the radio button */
108
- name: string,
107
+ /** The name of the radio button, required to avoid missing name */
108
+ name: string.isRequired,
109
109
 
110
110
  /** Change handler, receives value of selected radio button */
111
111
  onChange: func,
package/lib/Input.js CHANGED
@@ -11,7 +11,7 @@ var _propTypes = require("prop-types");
11
11
 
12
12
  var _classnames = _interopRequireDefault(require("classnames"));
13
13
 
14
- var _excluded = ["className", "inline", "textLike"];
14
+ var _excluded = ["className", "inline", "textLike", "textRightAlign"];
15
15
 
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
17
 
@@ -25,6 +25,7 @@ var Input = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
25
25
  var className = props.className,
26
26
  inline = props.inline,
27
27
  textLike = props.textLike,
28
+ textRightAlign = props.textRightAlign,
28
29
  rest = _objectWithoutProperties(props, _excluded);
29
30
 
30
31
  return /*#__PURE__*/_react.default.createElement("input", _extends({
@@ -32,6 +33,8 @@ var Input = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
32
33
  'ffe-input-field--inline': inline
33
34
  }, {
34
35
  'ffe-input-field--text-like': textLike
36
+ }, {
37
+ 'ffe-input-field--text-right-align': textRightAlign
35
38
  }, className),
36
39
  ref: ref
37
40
  }, rest));
@@ -44,7 +47,10 @@ Input.propTypes = {
44
47
  inline: _propTypes.bool,
45
48
 
46
49
  /** Apply the text-like modifier by setting this to `true`. */
47
- textLike: _propTypes.bool
50
+ textLike: _propTypes.bool,
51
+
52
+ /** Make the text right aligned */
53
+ textRightAlign: _propTypes.bool
48
54
  };
49
55
  var _default = Input;
50
56
  exports.default = _default;
@@ -117,8 +117,8 @@ RadioButtonInputGroup.propTypes = {
117
117
  */
118
118
  label: (0, _propTypes.oneOfType)([_propTypes.node, _propTypes.string]),
119
119
 
120
- /** The name of the radio button */
121
- name: _propTypes.string,
120
+ /** The name of the radio button, required to avoid missing name */
121
+ name: _propTypes.string.isRequired,
122
122
 
123
123
  /** Change handler, receives value of selected radio button */
124
124
  onChange: _propTypes.func,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sb1/ffe-form-react",
3
- "version": "8.1.2",
3
+ "version": "9.0.2",
4
4
  "description": "React component for form elements in ffe",
5
5
  "license": "MIT",
6
6
  "author": "SpareBank 1",
@@ -18,11 +18,8 @@
18
18
  "url": "ssh://git@github.com:SpareBank1/designsystem.git"
19
19
  },
20
20
  "scripts": {
21
- "build": "npm run build:cjs && npm run build:es && npm run build:types",
22
- "build:cjs": "babel -d lib/. --root-mode=upward --env-name=cjs --ignore=*.spec.js src/.",
23
- "build:es": "babel -d es/. --root-mode=upward --env-name=es --ignore=*.spec.js src/.",
24
- "build:types": "copyfiles -f src/index.d.ts types/",
25
- "lint": "eslint src/.",
21
+ "build": "ffe-buildtool babel",
22
+ "lint": "eslint src",
26
23
  "test": "jest",
27
24
  "test:watch": "jest --watch"
28
25
  },
@@ -30,16 +27,17 @@
30
27
  "setupTestFrameworkScriptFile": "../../test-setup.js"
31
28
  },
32
29
  "dependencies": {
33
- "@sb1/ffe-collapse-react": "^1.1.6",
34
- "classnames": "^2.2.5",
35
- "uuid": "^8.0.0"
30
+ "@sb1/ffe-collapse-react": "^1.1.7",
31
+ "classnames": "^2.3.1",
32
+ "uuid": "^8.3.2"
36
33
  },
37
34
  "devDependencies": {
35
+ "@sb1/ffe-buildtool": "^0.1.0",
38
36
  "enzyme": "^3.7.0",
39
37
  "enzyme-adapter-react-16": "^1.7.0",
40
38
  "eslint": "^5.9.0",
41
39
  "jest": "^26.0.0",
42
- "prop-types": "^15.6.0",
40
+ "prop-types": "^15.7.2",
43
41
  "react": "^16.9.0",
44
42
  "react-dom": "^16.9.0",
45
43
  "react-motion": "^0.5.2",
@@ -54,5 +52,5 @@
54
52
  "publishConfig": {
55
53
  "access": "public"
56
54
  },
57
- "gitHead": "10d5866ee997def57f017c3580bf5da32f1132c3"
55
+ "gitHead": "59eb2e12625e744f1a116c14a40cf69f1bbecdc6"
58
56
  }
package/types/index.d.ts CHANGED
@@ -120,7 +120,7 @@ export interface RadioButtonInputGroupProps extends WeakFieldSetAttributes {
120
120
  fieldMessage?: string | React.ReactNode;
121
121
  inline?: boolean;
122
122
  label?: string | React.ReactNode;
123
- name?: string;
123
+ name: string;
124
124
  onChange?: React.ChangeEventHandler<HTMLInputElement>;
125
125
  selectedValue?: string | boolean | number;
126
126
  tooltip?: string | React.ReactNode;
@@ -1,31 +0,0 @@
1
- import React from 'react';
2
- import { shallow } from 'enzyme';
3
- import BaseFieldMessage from './BaseFieldMessage';
4
-
5
- var getWrapper = function getWrapper(props) {
6
- return shallow( /*#__PURE__*/React.createElement(BaseFieldMessage, props, "Field message"));
7
- };
8
-
9
- describe('<BaseFieldMessage>', function () {
10
- it('renders the correct class name based on type prop', function () {
11
- var wrapper = getWrapper({
12
- type: 'error'
13
- });
14
- expect(wrapper.exists()).toBe(true);
15
- expect(wrapper.hasClass('ffe-field-error-message')).toBe(true);
16
- });
17
- it('renders the correct class name based on type prop', function () {
18
- var wrapper = getWrapper({
19
- type: 'info'
20
- });
21
- expect(wrapper.exists()).toBe(true);
22
- expect(wrapper.hasClass('ffe-field-info-message')).toBe(true);
23
- });
24
- it('renders the correct class name based on type prop', function () {
25
- var wrapper = getWrapper({
26
- type: 'success'
27
- });
28
- expect(wrapper.exists()).toBe(true);
29
- expect(wrapper.hasClass('ffe-field-success-message')).toBe(true);
30
- });
31
- });
@@ -1,136 +0,0 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
3
- import React from 'react';
4
- import { shallow } from 'enzyme';
5
- import BaseRadioButton from './BaseRadioButton';
6
- var defaultProps = {
7
- children: 'Some choice',
8
- name: 'choice',
9
- value: 'value'
10
- };
11
-
12
- var getWrapper = function getWrapper(props) {
13
- return shallow( /*#__PURE__*/React.createElement(BaseRadioButton, _extends({}, defaultProps, props)));
14
- };
15
-
16
- describe('<BaseRadioButton />', function () {
17
- it('renders without exploding', function () {
18
- var wrapper = getWrapper();
19
- expect(wrapper.exists()).toBe(true);
20
- });
21
- it('is checked undefined if checked prop is undefined and selectedValue is undefined', function () {
22
- var wrapper = getWrapper({});
23
- expect(wrapper.find('input').props()).toHaveProperty('checked', undefined);
24
- wrapper.setProps({
25
- checked: true
26
- });
27
- expect(wrapper.find('input').props()).toHaveProperty('checked', true);
28
- });
29
- it('is checked if checked prop is true', function () {
30
- var wrapper = getWrapper({
31
- checked: false
32
- });
33
- expect(wrapper.find('input').props()).toHaveProperty('checked', false);
34
- wrapper.setProps({
35
- checked: true
36
- });
37
- expect(wrapper.find('input').props()).toHaveProperty('checked', true);
38
- });
39
- it('is checked if selectedValue equals value', function () {
40
- var wrapper = getWrapper({
41
- selectedValue: 'other_value'
42
- });
43
- expect(wrapper.find('input').props()).toHaveProperty('checked', false);
44
- wrapper.setProps({
45
- selectedValue: 'value'
46
- });
47
- expect(wrapper.find('input').props()).toHaveProperty('checked', true);
48
- });
49
- it('is not checked if not checked and selectedValue !== value', function () {
50
- var wrapper = getWrapper({
51
- checked: false,
52
- selectedValue: 'nope'
53
- });
54
- expect(wrapper.find('input').props()).toHaveProperty('checked', false);
55
- });
56
- it('is not checked if checked === undefined and selectedValue is falsy, but not undefined', function () {
57
- var wrapperWithNull = getWrapper({
58
- selectedValue: null
59
- });
60
- expect(wrapperWithNull.find('input').props()).toHaveProperty('checked', false);
61
- var wrapperWithEmptyString = getWrapper({
62
- selectedValue: ''
63
- });
64
- expect(wrapperWithEmptyString.find('input').props()).toHaveProperty('checked', false);
65
- });
66
- it('accepts boolean values and checks the input if it is selected', function () {
67
- var wrapper = getWrapper({
68
- selectedValue: true,
69
- value: true
70
- });
71
- expect(wrapper.find('input').props()).toHaveProperty('checked', true);
72
- });
73
- it('accepts boolean values and does not check the input if it is not selected', function () {
74
- var wrapper = getWrapper({
75
- selectedValue: 'false',
76
- value: true
77
- });
78
- expect(wrapper.find('input').props()).toHaveProperty('checked', false);
79
- });
80
- describe('id', function () {
81
- it('is unique across instances', function () {
82
- var oneId = getWrapper().find('input').prop('id');
83
- var anotherId = getWrapper().find('input').prop('id');
84
- expect(oneId).not.toBe(anotherId);
85
- });
86
- it('is stable per instance', function () {
87
- var wrapper = getWrapper();
88
- var idBeforeUpdate = wrapper.find('input').prop('id');
89
- wrapper.setProps({
90
- selectedValue: 'red'
91
- });
92
- var idAfterUpdate = wrapper.find('input').prop('id');
93
- expect(idBeforeUpdate).toBe(idAfterUpdate);
94
- });
95
- });
96
- describe('tooltip', function () {
97
- it('does not render if not present', function () {
98
- var wrapper = getWrapper({
99
- tooltip: undefined
100
- });
101
- expect(wrapper.find('Tooltip').exists()).toBe(false);
102
- });
103
- it('renders if present', function () {
104
- var wrapper = getWrapper({
105
- tooltip: 'Tip generously'
106
- });
107
- expect(wrapper.find('Tooltip').exists()).toBe(true);
108
- });
109
- it('does not add the correct class if not present', function () {
110
- var wrapper = getWrapper({
111
- tooltip: undefined
112
- });
113
- expect(wrapper.find('.ffe-radio-button--with-tooltip').exists()).toBe(false);
114
- });
115
- it('adds the correct class if present', function () {
116
- var wrapper = getWrapper({
117
- tooltip: 'Tip generously'
118
- });
119
- expect(wrapper.find('.ffe-radio-button--with-tooltip').exists()).toBe(true);
120
- });
121
- });
122
- describe('aria-invalid', function () {
123
- it('does not add the class if false', function () {
124
- var wrapper = getWrapper({
125
- 'aria-invalid': 'false'
126
- });
127
- expect(wrapper.find('.ffe-radio-button--invalid').exists()).toBe(false);
128
- });
129
- it('adds the correct class if true', function () {
130
- var wrapper = getWrapper({
131
- 'aria-invalid': 'true'
132
- });
133
- expect(wrapper.find('.ffe-radio-button--invalid').exists()).toBe(true);
134
- });
135
- });
136
- });
@@ -1,109 +0,0 @@
1
- import React from 'react';
2
- import { shallow } from 'enzyme';
3
- import Checkbox from './Checkbox';
4
-
5
- var getWrapper = function getWrapper(props) {
6
- return shallow( /*#__PURE__*/React.createElement(Checkbox, props));
7
- };
8
-
9
- describe('<Checkbox />', function () {
10
- it('should render a input', function () {
11
- var wrapper = getWrapper();
12
- expect(wrapper.find('input').exists()).toBe(true);
13
- });
14
- it('should call onChange when clicked', function () {
15
- var spy = jest.fn();
16
- var wrapper = getWrapper({
17
- onChange: spy
18
- });
19
- wrapper.find('input').simulate('change');
20
- expect(spy).toHaveBeenCalledTimes(1);
21
- });
22
- it('should call onChange with the correct parameter', function () {
23
- var mockEvent = {
24
- target: {
25
- value: true
26
- }
27
- };
28
- var spy = jest.fn();
29
- var wrapper = getWrapper({
30
- onChange: spy
31
- });
32
- wrapper.find('input').simulate('change', mockEvent);
33
- expect(spy.mock.calls[0][0]).toBe(mockEvent);
34
- });
35
- it('should render a default value if passed', function () {
36
- var wrapper = getWrapper();
37
- expect(wrapper.find('input').prop('checked')).toBe(undefined);
38
- wrapper = getWrapper({
39
- checked: true
40
- });
41
- expect(wrapper.find('input').prop('checked')).toBe(true);
42
- });
43
- it('should apply the same id to <label> and <input>', function () {
44
- var wrapper = getWrapper({
45
- name: 'Some text goes here'
46
- });
47
- expect(wrapper.find('label').prop('htmlFor')).toBe(wrapper.find('input').prop('id'));
48
- });
49
- it('should support noMargins', function () {
50
- var wrapper = getWrapper({
51
- noMargins: false
52
- });
53
- expect(wrapper.find('.ffe-checkbox--no-margin').exists()).toBe(false);
54
- wrapper.setProps({
55
- noMargins: true
56
- });
57
- expect(wrapper.find('.ffe-checkbox--no-margin').exists()).toBe(true);
58
- });
59
- it('should support inline', function () {
60
- var wrapper = getWrapper();
61
- expect(wrapper.find('.ffe-checkbox--inline').exists()).toBe(true);
62
- wrapper.setProps({
63
- inline: false
64
- });
65
- expect(wrapper.find('.ffe-checkbox--inline').exists()).toBe(false);
66
- wrapper.setProps({
67
- inline: true
68
- });
69
- expect(wrapper.find('.ffe-checkbox--inline').exists()).toBe(true);
70
- });
71
- it('should support aria-invalid', function () {
72
- var wrapper = getWrapper({
73
- 'aria-invalid': 'false'
74
- });
75
- expect(wrapper.find('input').prop('aria-invalid')).toBe('false');
76
- });
77
- it('should set arbitrary props (rest) on input', function () {
78
- var wrapper = getWrapper({
79
- name: 'checkbox',
80
- iDontReallyDoAnything: 'false',
81
- tabIndex: -1
82
- });
83
- expect(wrapper.find('input').prop('name')).toBe('checkbox');
84
- expect(wrapper.find('input').prop('iDontReallyDoAnything')).toBe('false');
85
- expect(wrapper.find('input').prop('tabIndex')).toBe(-1);
86
- });
87
- it('should render children if it is a function', function () {
88
- var wrapper = shallow( /*#__PURE__*/React.createElement(Checkbox, null, function (labelProps) {
89
- return (
90
- /*#__PURE__*/
91
- // eslint-disable-next-line jsx-a11y/label-has-for
92
- React.createElement("label", labelProps, "Hello world")
93
- );
94
- }));
95
- expect(wrapper.find('label').prop('children')).toBe('Hello world');
96
- });
97
- it('should render with a hidden label', function () {
98
- var wrapper = getWrapper({
99
- 'aria-label': 'I am label',
100
- hiddenLabel: true
101
- });
102
- var label = wrapper.find('.ffe-checkbox--hidden-label');
103
- var input = wrapper.find('.ffe-hidden-checkbox');
104
- expect(label.exists()).toBe(true);
105
- expect(label.children()).toHaveLength(0);
106
- expect(input.exists()).toBe(true);
107
- expect(input.prop('aria-label')).toBe('I am label');
108
- });
109
- });
@@ -1,15 +0,0 @@
1
- import React from 'react';
2
- import { mount } from 'enzyme';
3
- import ErrorFieldMessage from './ErrorFieldMessage';
4
-
5
- var getWrapper = function getWrapper() {
6
- return mount( /*#__PURE__*/React.createElement(ErrorFieldMessage, null, "Field message"));
7
- };
8
-
9
- describe('<ErrorFieldMessage>', function () {
10
- it('renders the correct class name based on type prop', function () {
11
- var wrapper = getWrapper();
12
- expect(wrapper.exists()).toBe(true);
13
- expect(wrapper.find('div').hasClass('ffe-field-error-message')).toBe(true);
14
- });
15
- });
@@ -1,15 +0,0 @@
1
- import React from 'react';
2
- import { mount } from 'enzyme';
3
- import InfoFieldMessage from './InfoFieldMessage';
4
-
5
- var getWrapper = function getWrapper() {
6
- return mount( /*#__PURE__*/React.createElement(InfoFieldMessage, null, "Field message"));
7
- };
8
-
9
- describe('<InfoFieldMessage>', function () {
10
- it('renders the correct class name based on type prop', function () {
11
- var wrapper = getWrapper();
12
- expect(wrapper.exists()).toBe(true);
13
- expect(wrapper.find('div').hasClass('ffe-field-info-message')).toBe(true);
14
- });
15
- });
package/es/Input.spec.js DELETED
@@ -1,41 +0,0 @@
1
- import React from 'react';
2
- import { shallow } from 'enzyme';
3
- import Input from './Input';
4
-
5
- var getWrapper = function getWrapper(props) {
6
- return shallow( /*#__PURE__*/React.createElement(Input, props));
7
- };
8
-
9
- describe('<Input />', function () {
10
- it('renders an input element', function () {
11
- var wrapper = getWrapper();
12
- expect(wrapper.exists()).toBe(true);
13
- expect(wrapper.is('input')).toBe(true);
14
- expect(wrapper.hasClass('ffe-input-field')).toBe(true);
15
- });
16
- it('passes props', function () {
17
- var wrapper = getWrapper({
18
- autoComplete: true,
19
- className: 'app-input'
20
- });
21
- expect(wrapper.prop('autoComplete')).toBe(true);
22
- expect(wrapper.hasClass('app-input')).toBe(true);
23
- expect(wrapper.hasClass('ffe-input-field')).toBe(true);
24
- });
25
- it('sets the correct class for inline-modifer', function () {
26
- var wrapper = getWrapper();
27
- expect(wrapper.hasClass('ffe-input-field--inline')).toBe(false);
28
- wrapper.setProps({
29
- inline: true
30
- });
31
- expect(wrapper.hasClass('ffe-input-field--inline')).toBe(true);
32
- });
33
- it('sets the correct class for textLike-modifer', function () {
34
- var wrapper = getWrapper();
35
- expect(wrapper.hasClass('ffe-input-field--text-like')).toBe(false);
36
- wrapper.setProps({
37
- textLike: true
38
- });
39
- expect(wrapper.hasClass('ffe-input-field--text-like')).toBe(true);
40
- });
41
- });