@happeouikit/form-elements 2.3.0 → 2.3.1
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 +4 -0
- package/dist/Checkbox.js +10 -8
- package/dist/Input.js +14 -5
- package/dist/utils.js +9 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/Checkbox.js
CHANGED
|
@@ -5,7 +5,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
5
5
|
|
|
6
6
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
7
7
|
|
|
8
|
-
import
|
|
8
|
+
import { useRef } from "react";
|
|
9
9
|
import styled from "styled-components";
|
|
10
10
|
import PropTypes from "prop-types";
|
|
11
11
|
import { white, active, gray01, gray06, gray08 } from "@happeouikit/colors";
|
|
@@ -17,7 +17,8 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
17
17
|
var Checkbox = function Checkbox(_ref) {
|
|
18
18
|
var label = _ref.label,
|
|
19
19
|
background = _ref.background,
|
|
20
|
-
|
|
20
|
+
role = _ref.role,
|
|
21
|
+
rest = _objectWithoutProperties(_ref, ["label", "background", "role"]);
|
|
21
22
|
|
|
22
23
|
var checkboxRef = useRef();
|
|
23
24
|
|
|
@@ -26,23 +27,24 @@ var Checkbox = function Checkbox(_ref) {
|
|
|
26
27
|
event.preventDefault();
|
|
27
28
|
checkboxRef.current.checked = !checkboxRef.current.checked;
|
|
28
29
|
|
|
29
|
-
if (typeof
|
|
30
|
-
|
|
30
|
+
if (typeof rest.onChange === "function") {
|
|
31
|
+
rest.onChange(event);
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
};
|
|
34
35
|
|
|
35
36
|
return /*#__PURE__*/_jsxs(CheckboxWrapper, {
|
|
36
37
|
background: background,
|
|
37
|
-
disabled:
|
|
38
|
+
disabled: rest.disabled,
|
|
38
39
|
children: [/*#__PURE__*/_jsx("input", _objectSpread({
|
|
39
40
|
ref: checkboxRef,
|
|
40
41
|
type: "checkbox",
|
|
41
|
-
tabIndex: "-1"
|
|
42
|
-
|
|
42
|
+
tabIndex: "-1",
|
|
43
|
+
role: role
|
|
44
|
+
}, rest)), /*#__PURE__*/_jsx(StyledCheckbox, _objectSpread({
|
|
43
45
|
onKeyDown: onKeyDown,
|
|
44
46
|
tabIndex: 0
|
|
45
|
-
},
|
|
47
|
+
}, rest, {
|
|
46
48
|
children: /*#__PURE__*/_jsx(Checkmark, {})
|
|
47
49
|
})), label && /*#__PURE__*/_jsx(Label, {
|
|
48
50
|
children: label
|
package/dist/Input.js
CHANGED
|
@@ -10,6 +10,7 @@ import styled from "styled-components";
|
|
|
10
10
|
import { placeholder } from "polished";
|
|
11
11
|
import { gray01, gray04, gray08, gray05, gray06, active, black, success, alert } from "@happeouikit/colors";
|
|
12
12
|
import { TinyText, sansFamily, BodyUI } from "@happeouikit/typography";
|
|
13
|
+
import { uuidv4 } from "./utils";
|
|
13
14
|
/**
|
|
14
15
|
* Map input states to colors
|
|
15
16
|
* @type {{default: string, success: string, error: string}}
|
|
@@ -30,16 +31,22 @@ export var Input = function Input(_ref) {
|
|
|
30
31
|
errorMessage = _ref.errorMessage,
|
|
31
32
|
rest = _objectWithoutProperties(_ref, ["label", "icon", "iconProps", "state", "errorMessage"]);
|
|
32
33
|
|
|
34
|
+
var id = React.useMemo(uuidv4, []);
|
|
35
|
+
var accessibility = label ? {
|
|
36
|
+
"aria-labelledby": id
|
|
37
|
+
} : {};
|
|
33
38
|
return /*#__PURE__*/_jsxs(Container, {
|
|
34
39
|
children: [!!label && /*#__PURE__*/_jsx(InputLabel, {
|
|
40
|
+
id: id,
|
|
35
41
|
children: /*#__PURE__*/_jsx(BodyUI, {
|
|
36
42
|
color: gray01,
|
|
37
43
|
children: label
|
|
38
44
|
})
|
|
39
|
-
}), icon && new
|
|
45
|
+
}), icon && new IconWrapper(icon, iconProps)(), /*#__PURE__*/_jsx(StyledInput, _objectSpread({
|
|
46
|
+
title: label || "Styled input",
|
|
40
47
|
hasIcon: (icon || "").toString(),
|
|
41
48
|
state: state || "default"
|
|
42
|
-
}, rest)), state === "error" && errorMessage && /*#__PURE__*/_jsx(ErrorMessage, {
|
|
49
|
+
}, accessibility, {}, rest)), state === "error" && errorMessage && /*#__PURE__*/_jsx(ErrorMessage, {
|
|
43
50
|
color: alert,
|
|
44
51
|
children: errorMessage
|
|
45
52
|
})]
|
|
@@ -52,7 +59,7 @@ export var Input = function Input(_ref) {
|
|
|
52
59
|
* @returns {function(): *}
|
|
53
60
|
*/
|
|
54
61
|
|
|
55
|
-
function
|
|
62
|
+
var IconWrapper = function IconWrapper(IconComponent, iconProps) {
|
|
56
63
|
var iconDefaults = {
|
|
57
64
|
width: "20px",
|
|
58
65
|
height: "20px",
|
|
@@ -64,7 +71,9 @@ function iconWrapper(IconComponent, iconProps) {
|
|
|
64
71
|
left: "10px",
|
|
65
72
|
fontSize: "18px"
|
|
66
73
|
};
|
|
67
|
-
|
|
74
|
+
|
|
75
|
+
var props = _objectSpread({}, iconDefaults, {}, iconProps);
|
|
76
|
+
|
|
68
77
|
return function () {
|
|
69
78
|
return /*#__PURE__*/_jsx(InputIconWrapper, {
|
|
70
79
|
children: /*#__PURE__*/_jsx(IconComponent, _objectSpread({}, props, {
|
|
@@ -72,7 +81,7 @@ function iconWrapper(IconComponent, iconProps) {
|
|
|
72
81
|
}))
|
|
73
82
|
});
|
|
74
83
|
};
|
|
75
|
-
}
|
|
84
|
+
};
|
|
76
85
|
|
|
77
86
|
var ErrorMessage = styled(TinyText).withConfig({
|
|
78
87
|
displayName: "Input__ErrorMessage",
|
package/dist/utils.js
CHANGED
|
@@ -45,4 +45,13 @@ export var useDevWarningOnce = function useDevWarningOnce(shouldWarn, message) {
|
|
|
45
45
|
} // eslint-disable-next-line
|
|
46
46
|
|
|
47
47
|
}, []);
|
|
48
|
+
};
|
|
49
|
+
export var uuidv4 = function uuidv4() {
|
|
50
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
51
|
+
// eslint-disable-next-line no-bitwise
|
|
52
|
+
var r = Math.random() * 16 | 0; // eslint-disable-next-line no-bitwise
|
|
53
|
+
|
|
54
|
+
var v = c === "x" ? r : r & 0x3 | 0x8;
|
|
55
|
+
return v.toString(16);
|
|
56
|
+
});
|
|
48
57
|
};
|