@happeouikit/form-elements 1.1.2 → 2.2.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/CHANGELOG.md +20 -0
- package/dist/Checkbox.js +8 -1
- package/dist/CheckboxGroup.js +150 -0
- package/dist/DatePicker.js +1 -1
- package/dist/Input.js +24 -21
- package/dist/index.js +1 -0
- package/dist/utils.js +21 -0
- package/package.json +17 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.2.0
|
|
4
|
+
|
|
5
|
+
- [Fixed] DatePicker. inability to control component by value prop
|
|
6
|
+
- [Fixed] DatePicker. focus loss on edit
|
|
7
|
+
- [Fixed] DatePicker. selected date highlight in the UI
|
|
8
|
+
- [Fixed] DatePicker. PropTypes
|
|
9
|
+
- [Fixed] DatePicker. disabled `react/jsx-props-no-spreading eslint rule`
|
|
10
|
+
|
|
11
|
+
## 2.1.0
|
|
12
|
+
|
|
13
|
+
- [Added] CheckboxGroup component
|
|
14
|
+
|
|
15
|
+
## 2.0.1
|
|
16
|
+
|
|
17
|
+
- [Fixed] InputNumber will only accept numerical value
|
|
18
|
+
|
|
19
|
+
## 2.0.0
|
|
20
|
+
|
|
21
|
+
- [Fixed] updated versions for react, styled-components and other dependencies
|
|
22
|
+
|
|
3
23
|
## 1.1.2
|
|
4
24
|
|
|
5
25
|
- [Fixed] build dist for DatePicker
|
package/dist/Checkbox.js
CHANGED
|
@@ -34,7 +34,14 @@ var Checkbox = function Checkbox(_ref) {
|
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
Checkbox.propTypes = {
|
|
37
|
-
label: PropTypes.node
|
|
37
|
+
label: PropTypes.node,
|
|
38
|
+
value: PropTypes.string,
|
|
39
|
+
background: PropTypes.string
|
|
40
|
+
};
|
|
41
|
+
Checkbox.defaultProps = {
|
|
42
|
+
label: null,
|
|
43
|
+
value: undefined,
|
|
44
|
+
background: null
|
|
38
45
|
};
|
|
39
46
|
var StyledCheckbox = styled.span.withConfig({
|
|
40
47
|
displayName: "Checkbox__StyledCheckbox",
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import React, { useEffect, useMemo, useState } from "react";
|
|
4
|
+
import PropTypes from "prop-types";
|
|
5
|
+
import Checkbox from "./Checkbox";
|
|
6
|
+
import { devWarning, getValidChildrenArray, isString, useDevWarningOnce } from "./utils";
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
|
|
9
|
+
var getOptions = function getOptions(options) {
|
|
10
|
+
return options.map(function (option) {
|
|
11
|
+
return isString(option) ? {
|
|
12
|
+
label: option,
|
|
13
|
+
value: option
|
|
14
|
+
} : option;
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
var sortValuesByOrderInOptions = function sortValuesByOrderInOptions(options) {
|
|
19
|
+
return function (a, b) {
|
|
20
|
+
var indexA = options.findIndex(function (opt) {
|
|
21
|
+
return opt.value === a;
|
|
22
|
+
});
|
|
23
|
+
var indexB = options.findIndex(function (opt) {
|
|
24
|
+
return opt.value === b;
|
|
25
|
+
});
|
|
26
|
+
return indexA - indexB;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
var getOptionsFromChildren = function getOptionsFromChildren(children) {
|
|
31
|
+
return getValidChildrenArray(children).map(function (_ref) {
|
|
32
|
+
var option = _ref.props;
|
|
33
|
+
return option;
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
var getChildrenDefaultValue = function getChildrenDefaultValue(options) {
|
|
38
|
+
return options.filter(function (_ref2) {
|
|
39
|
+
var defaultChecked = _ref2.defaultChecked;
|
|
40
|
+
return defaultChecked;
|
|
41
|
+
}).map(function (_ref3) {
|
|
42
|
+
var value = _ref3.value;
|
|
43
|
+
return value;
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
var optionsWarning = "[CheckboxGroup] Both the `children` and `options` props have been used.\n The `options` prop will be ignored. To get rid of this warning, remove one of these props.";
|
|
48
|
+
var defaultValueWarning = "[CheckboxGroup] Both the `defaultChecked` and `defaultValue` props have been used.\n The `defaultValue` prop will be ignored. To get rid of this warning, remove one of these props.";
|
|
49
|
+
|
|
50
|
+
var CheckboxGroup = function CheckboxGroup(_ref4) {
|
|
51
|
+
var value = _ref4.value,
|
|
52
|
+
disabled = _ref4.disabled,
|
|
53
|
+
name = _ref4.name,
|
|
54
|
+
children = _ref4.children,
|
|
55
|
+
className = _ref4.className,
|
|
56
|
+
rawOptions = _ref4.options,
|
|
57
|
+
onGroupChange = _ref4.onChange,
|
|
58
|
+
groupDefaultValue = _ref4.defaultValue;
|
|
59
|
+
useDevWarningOnce(children && rawOptions, optionsWarning);
|
|
60
|
+
var options = useMemo(function () {
|
|
61
|
+
return children ? getOptionsFromChildren(children) : getOptions(rawOptions);
|
|
62
|
+
}, [children, rawOptions]);
|
|
63
|
+
var defaultValue = useMemo(function () {
|
|
64
|
+
var childrenDefaultValue = getChildrenDefaultValue(options);
|
|
65
|
+
var hasChildrenDefaultValue = Boolean(childrenDefaultValue.length);
|
|
66
|
+
|
|
67
|
+
if (hasChildrenDefaultValue && groupDefaultValue) {
|
|
68
|
+
devWarning(defaultValueWarning);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return hasChildrenDefaultValue ? childrenDefaultValue : groupDefaultValue;
|
|
72
|
+
}, [options, groupDefaultValue]);
|
|
73
|
+
|
|
74
|
+
var _useState = useState(value || defaultValue || []),
|
|
75
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
76
|
+
groupValue = _useState2[0],
|
|
77
|
+
setGroupValue = _useState2[1];
|
|
78
|
+
|
|
79
|
+
useEffect(function () {
|
|
80
|
+
if (value) {
|
|
81
|
+
setGroupValue(value);
|
|
82
|
+
}
|
|
83
|
+
}, [value]);
|
|
84
|
+
|
|
85
|
+
var isChecked = function isChecked(optionValue) {
|
|
86
|
+
return groupValue.includes(optionValue);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
var handleChange = function handleChange(option, event) {
|
|
90
|
+
if (option.onChange) {
|
|
91
|
+
option.onChange(event);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
var newValue = event.target.checked ? [].concat(_toConsumableArray(groupValue), [option.value]) : groupValue.filter(function (val) {
|
|
95
|
+
return val !== option.value;
|
|
96
|
+
});
|
|
97
|
+
var newSortedValue = newValue.sort(sortValuesByOrderInOptions(options));
|
|
98
|
+
setGroupValue(newSortedValue);
|
|
99
|
+
|
|
100
|
+
if (onGroupChange) {
|
|
101
|
+
onGroupChange(newSortedValue);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
return /*#__PURE__*/_jsx("div", {
|
|
106
|
+
className: className,
|
|
107
|
+
children: options.map(function (option) {
|
|
108
|
+
return /*#__PURE__*/_jsx(Checkbox, {
|
|
109
|
+
label: option.label,
|
|
110
|
+
name: name,
|
|
111
|
+
disabled: option.disabled || disabled,
|
|
112
|
+
checked: isChecked(option.value),
|
|
113
|
+
onChange: function onChange(event) {
|
|
114
|
+
return handleChange(option, event);
|
|
115
|
+
}
|
|
116
|
+
}, option.value);
|
|
117
|
+
})
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
var optionPropType = PropTypes.oneOfType([PropTypes.shape({
|
|
122
|
+
label: PropTypes.string,
|
|
123
|
+
value: PropTypes.string.isRequired,
|
|
124
|
+
onChange: PropTypes.func
|
|
125
|
+
}), PropTypes.string]);
|
|
126
|
+
CheckboxGroup.propTypes = {
|
|
127
|
+
className: PropTypes.string,
|
|
128
|
+
options: PropTypes.arrayOf(optionPropType),
|
|
129
|
+
onChange: PropTypes.func,
|
|
130
|
+
value: PropTypes.arrayOf(PropTypes.string),
|
|
131
|
+
defaultValue: PropTypes.arrayOf(PropTypes.string),
|
|
132
|
+
disabled: PropTypes.bool,
|
|
133
|
+
name: PropTypes.string,
|
|
134
|
+
children: PropTypes.oneOfType([PropTypes.shape({
|
|
135
|
+
type: PropTypes.oneOf([Checkbox])
|
|
136
|
+
}), PropTypes.arrayOf(PropTypes.shape({
|
|
137
|
+
type: PropTypes.oneOf([Checkbox])
|
|
138
|
+
}))])
|
|
139
|
+
};
|
|
140
|
+
CheckboxGroup.defaultProps = {
|
|
141
|
+
className: "",
|
|
142
|
+
options: null,
|
|
143
|
+
onChange: null,
|
|
144
|
+
value: null,
|
|
145
|
+
defaultValue: null,
|
|
146
|
+
disabled: false,
|
|
147
|
+
name: "",
|
|
148
|
+
children: null
|
|
149
|
+
};
|
|
150
|
+
export default CheckboxGroup;
|
package/dist/DatePicker.js
CHANGED
|
@@ -381,4 +381,4 @@ var NavBarContainer = styled.div.withConfig({
|
|
|
381
381
|
displayName: "DatePicker__NavBarContainer",
|
|
382
382
|
componentId: "sc-ce3xgi-6"
|
|
383
383
|
})(["display:flex;align-items:center;justify-content:space-between;padding:16px 14px 0px 14px;"]);
|
|
384
|
-
export default DatePicker;
|
|
384
|
+
export default DatePicker;
|
package/dist/Input.js
CHANGED
|
@@ -88,8 +88,11 @@ var InputLabel = styled.div.withConfig({
|
|
|
88
88
|
displayName: "Input__InputLabel",
|
|
89
89
|
componentId: "sc-1izazxd-2"
|
|
90
90
|
})(["margin:4px 0;"]);
|
|
91
|
-
export var StyledInput = styled.input.attrs({
|
|
92
|
-
type
|
|
91
|
+
export var StyledInput = styled.input.attrs(function (_ref2) {
|
|
92
|
+
var type = _ref2.type;
|
|
93
|
+
return {
|
|
94
|
+
type: type || "text"
|
|
95
|
+
};
|
|
93
96
|
}).withConfig({
|
|
94
97
|
displayName: "Input__StyledInput",
|
|
95
98
|
componentId: "sc-1izazxd-3"
|
|
@@ -99,26 +102,26 @@ export var StyledInput = styled.input.attrs({
|
|
|
99
102
|
"letter-spacing": "-0.3px",
|
|
100
103
|
"font-size": "14px",
|
|
101
104
|
"font-weight": "normal"
|
|
102
|
-
}), sansFamily, gray06, function (
|
|
103
|
-
var hasIcon =
|
|
105
|
+
}), sansFamily, gray06, function (_ref3) {
|
|
106
|
+
var hasIcon = _ref3.hasIcon;
|
|
104
107
|
return hasIcon ? "10px 12px 10px 38px" : "10px 12px";
|
|
105
|
-
}, black, function (
|
|
106
|
-
var _ref3$state = _ref3.state,
|
|
107
|
-
state = _ref3$state === void 0 ? "default" : _ref3$state;
|
|
108
|
-
return state === "default" ? gray04 : inputStates[state];
|
|
109
|
-
}, function (_ref4) {
|
|
108
|
+
}, black, function (_ref4) {
|
|
110
109
|
var _ref4$state = _ref4.state,
|
|
111
110
|
state = _ref4$state === void 0 ? "default" : _ref4$state;
|
|
112
|
-
return state === "default" ?
|
|
111
|
+
return state === "default" ? gray04 : inputStates[state];
|
|
113
112
|
}, function (_ref5) {
|
|
114
113
|
var _ref5$state = _ref5.state,
|
|
115
114
|
state = _ref5$state === void 0 ? "default" : _ref5$state;
|
|
116
115
|
return state === "default" ? active : inputStates[state];
|
|
117
|
-
},
|
|
118
|
-
color: gray05
|
|
119
|
-
}), function (_ref6) {
|
|
116
|
+
}, function (_ref6) {
|
|
120
117
|
var _ref6$state = _ref6.state,
|
|
121
118
|
state = _ref6$state === void 0 ? "default" : _ref6$state;
|
|
119
|
+
return state === "default" ? active : inputStates[state];
|
|
120
|
+
}, gray08, gray05, placeholder({
|
|
121
|
+
color: gray05
|
|
122
|
+
}), function (_ref7) {
|
|
123
|
+
var _ref7$state = _ref7.state,
|
|
124
|
+
state = _ref7$state === void 0 ? "default" : _ref7$state;
|
|
122
125
|
return inputStates[state];
|
|
123
126
|
});
|
|
124
127
|
var InputIconWrapper = styled.span.withConfig({
|
|
@@ -129,22 +132,22 @@ var InputIconWrapper = styled.span.withConfig({
|
|
|
129
132
|
* Number Input
|
|
130
133
|
*/
|
|
131
134
|
|
|
132
|
-
export var InputNumber = function InputNumber(
|
|
133
|
-
var label =
|
|
134
|
-
props = _objectWithoutProperties(
|
|
135
|
+
export var InputNumber = function InputNumber(_ref8) {
|
|
136
|
+
var label = _ref8.label,
|
|
137
|
+
props = _objectWithoutProperties(_ref8, _excluded2);
|
|
135
138
|
|
|
136
139
|
return /*#__PURE__*/_jsxs(InputNumberContainer, {
|
|
137
|
-
children: [/*#__PURE__*/_jsx(StyledInputNumber, _objectSpread({}, props)
|
|
140
|
+
children: [/*#__PURE__*/_jsx(StyledInputNumber, _objectSpread(_objectSpread({}, props), {}, {
|
|
141
|
+
type: "number"
|
|
142
|
+
})), label && /*#__PURE__*/_jsx(InputNumberLabel, {
|
|
138
143
|
children: label
|
|
139
144
|
})]
|
|
140
145
|
});
|
|
141
146
|
};
|
|
142
|
-
var StyledInputNumber = styled(Input).
|
|
143
|
-
pattern: "[0-9.]+"
|
|
144
|
-
}).withConfig({
|
|
147
|
+
var StyledInputNumber = styled(Input).withConfig({
|
|
145
148
|
displayName: "Input__StyledInputNumber",
|
|
146
149
|
componentId: "sc-1izazxd-5"
|
|
147
|
-
})(["width:
|
|
150
|
+
})(["width:60px;text-align:center;font-size:14px;"]);
|
|
148
151
|
var InputNumberContainer = styled.div.withConfig({
|
|
149
152
|
displayName: "Input__InputNumberContainer",
|
|
150
153
|
componentId: "sc-1izazxd-6"
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { default as Dropdown, dropdownStyles } from "./Dropdown";
|
|
|
3
3
|
export * from "./Link";
|
|
4
4
|
export { default as Switch } from "./Switch";
|
|
5
5
|
export { default as Checkbox } from "./Checkbox";
|
|
6
|
+
export { default as CheckboxGroup } from "./CheckboxGroup";
|
|
6
7
|
export { default as RadioButton } from "./RadioButton";
|
|
7
8
|
export { default as Textarea } from "./Textarea";
|
|
8
9
|
export { default as Tag } from "./Tag";
|
package/dist/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import React, { useEffect } from "react";
|
|
1
2
|
export var toCamelCase = function toCamelCase(str) {
|
|
2
3
|
return str.replace(/(_|-|,|\.)(.)/g, function (match) {
|
|
3
4
|
return match[1].toUpperCase();
|
|
@@ -24,4 +25,24 @@ export var sanitiseHashtag = function sanitiseHashtag(hashtag) {
|
|
|
24
25
|
export var addHashSign = function addHashSign(input) {
|
|
25
26
|
if (input.startsWith("#")) return input;
|
|
26
27
|
return "#" + input;
|
|
28
|
+
};
|
|
29
|
+
export var isString = function isString(value) {
|
|
30
|
+
return typeof value === "string";
|
|
31
|
+
};
|
|
32
|
+
export var getValidChildrenArray = function getValidChildrenArray(children) {
|
|
33
|
+
return React.Children.toArray(children).filter(React.isValidElement);
|
|
34
|
+
};
|
|
35
|
+
export var devWarning = function devWarning(message) {
|
|
36
|
+
if (process.env.NODE_ENV !== "production") {
|
|
37
|
+
// eslint-disable-next-line no-console
|
|
38
|
+
console.warn("HappeoUiKit/form-elements: ".concat(message));
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
export var useDevWarningOnce = function useDevWarningOnce(shouldWarn, message) {
|
|
42
|
+
useEffect(function () {
|
|
43
|
+
if (shouldWarn) {
|
|
44
|
+
devWarning(message);
|
|
45
|
+
} // eslint-disable-next-line
|
|
46
|
+
|
|
47
|
+
}, []);
|
|
27
48
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@happeouikit/form-elements",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -15,28 +15,30 @@
|
|
|
15
15
|
"author": "Happeo Oy",
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@happeouikit/buttons": "^1.0.
|
|
18
|
+
"@happeouikit/buttons": "^1.0.15",
|
|
19
19
|
"@happeouikit/colors": "^1.0.4",
|
|
20
|
-
"@happeouikit/icons": "^
|
|
20
|
+
"@happeouikit/icons": "^2.0.1",
|
|
21
21
|
"@happeouikit/layout": "^1.1.11",
|
|
22
22
|
"@happeouikit/theme": "^1.0.4",
|
|
23
|
-
"@happeouikit/tooltip": "^1.0.
|
|
24
|
-
"@happeouikit/typography": "^1.0.
|
|
23
|
+
"@happeouikit/tooltip": "^1.0.11",
|
|
24
|
+
"@happeouikit/typography": "^1.0.10",
|
|
25
25
|
"lodash.debounce": "^4.0.8",
|
|
26
|
-
"moment": "^2.
|
|
27
|
-
"polished": "^2.3.
|
|
28
|
-
"react-day-picker": "^7.4.
|
|
29
|
-
"react-intl": "^3.12.
|
|
30
|
-
"react-select": "^
|
|
31
|
-
"react-switch": "^
|
|
26
|
+
"moment": "^2.29.1",
|
|
27
|
+
"polished": "^2.3.3",
|
|
28
|
+
"react-day-picker": "^7.4.10",
|
|
29
|
+
"react-intl": "^3.12.1",
|
|
30
|
+
"react-select": "^5.2.1",
|
|
31
|
+
"react-switch": "^6.0.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@babel/plugin-proposal-unicode-property-regex": "^7.
|
|
34
|
+
"@babel/plugin-proposal-unicode-property-regex": "^7.16.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"
|
|
38
|
-
"react": "^
|
|
39
|
-
"
|
|
37
|
+
"@testing-library/jest-dom": "^5.14.1",
|
|
38
|
+
"@testing-library/react": "^10.2.1",
|
|
39
|
+
"prop-types": "^15.7.2",
|
|
40
|
+
"react": "^17.0.2",
|
|
41
|
+
"styled-components": "^5.3.3"
|
|
40
42
|
},
|
|
41
43
|
"publishConfig": {
|
|
42
44
|
"access": "public"
|