@happeouikit/form-elements 2.3.0 → 2.3.5

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.3.5
4
+
5
+ - [Added] Added the option to pass dayPickerProps
6
+
7
+ ## 2.3.4
8
+
9
+ - [Fixed] DatePicker. Added htmlFor to the label and input ID autogeneration. Accessibility issue.
10
+
11
+ ## 2.3.1
12
+
13
+ - [Fixed] remove role from span, keep role on input only
14
+
3
15
  ## 2.3.0
4
16
 
5
17
  - [Added] Typeahead component
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 React, { useRef } from "react";
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
- props = _objectWithoutProperties(_ref, ["label", "background"]);
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 props.onChange === "function") {
30
- props.onChange(event);
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: props.disabled,
38
+ disabled: rest.disabled,
38
39
  children: [/*#__PURE__*/_jsx("input", _objectSpread({
39
40
  ref: checkboxRef,
40
41
  type: "checkbox",
41
- tabIndex: "-1"
42
- }, props)), /*#__PURE__*/_jsx(StyledCheckbox, _objectSpread({
42
+ tabIndex: "-1",
43
+ role: role
44
+ }, rest)), /*#__PURE__*/_jsx(StyledCheckbox, _objectSpread({
43
45
  onKeyDown: onKeyDown,
44
46
  tabIndex: 0
45
- }, props, {
47
+ }, rest, {
46
48
  children: /*#__PURE__*/_jsx(Checkmark, {})
47
49
  })), label && /*#__PURE__*/_jsx(Label, {
48
50
  children: label
@@ -6,7 +6,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
6
6
 
7
7
  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; }
8
8
 
9
- import React, { useState } from "react";
9
+ import React, { useState, useRef } from "react";
10
10
  import PropTypes from "prop-types";
11
11
  import styled, { css } from "styled-components";
12
12
  import DayPickerInput from "react-day-picker/DayPickerInput";
@@ -26,7 +26,7 @@ import Dropdown from "./Dropdown"; // CSS
26
26
 
27
27
  import "react-day-picker/lib/style.css";
28
28
  import messages from "./messages";
29
- import { useDevWarningOnce } from "./utils";
29
+ import { useDevWarningOnce, uuidv4 } from "./utils";
30
30
  import { jsx as _jsx } from "react/jsx-runtime";
31
31
  import { jsxs as _jsxs } from "react/jsx-runtime";
32
32
  import { Fragment as _Fragment } from "react/jsx-runtime";
@@ -68,7 +68,16 @@ var DatePicker = function DatePicker(_ref) {
68
68
  disabledDays = _ref.disabledDays,
69
69
  value = _ref.value,
70
70
  pickerRef = _ref.pickerRef,
71
- props = _objectWithoutProperties(_ref, ["label", "locale", "width", "date", "type", "fromMonth", "disabledDays", "value", "pickerRef"]);
71
+ _ref$inputProps = _ref.inputProps,
72
+ inputProps = _ref$inputProps === void 0 ? {} : _ref$inputProps,
73
+ _ref$dayPickerProps = _ref.dayPickerProps,
74
+ dayPickerProps = _ref$dayPickerProps === void 0 ? {} : _ref$dayPickerProps,
75
+ props = _objectWithoutProperties(_ref, ["label", "locale", "width", "date", "type", "fromMonth", "disabledDays", "value", "pickerRef", "inputProps", "dayPickerProps"]);
76
+
77
+ // Stores the ID of the input field. If "id" isn't provided, it will be generated
78
+ // to improve accessibility by linking label to the input field.
79
+ var _useRef = useRef(inputProps.id || uuidv4()),
80
+ datePickerId = _useRef.current;
72
81
 
73
82
  var _useState = useState(fromMonth),
74
83
  _useState2 = _slicedToArray(_useState, 2),
@@ -90,11 +99,14 @@ var DatePicker = function DatePicker(_ref) {
90
99
  return /*#__PURE__*/_jsxs(Wrapper, {
91
100
  width: width,
92
101
  hasRange: isRangeMode,
93
- children: [label && /*#__PURE__*/_jsx("div", {
102
+ children: [label && /*#__PURE__*/_jsx("label", {
103
+ htmlFor: datePickerId,
104
+ "aria-label": label,
94
105
  style: {
95
106
  margin: "4px 0"
96
107
  },
97
108
  children: /*#__PURE__*/_jsx(BodyUI, {
109
+ as: "span",
98
110
  color: gray01,
99
111
  children: label
100
112
  })
@@ -104,7 +116,7 @@ var DatePicker = function DatePicker(_ref) {
104
116
  formatDate: formatDate,
105
117
  parseDate: parseDate,
106
118
  placeholder: formatValue(new Date(), locale),
107
- dayPickerProps: {
119
+ dayPickerProps: _objectSpread({
108
120
  locale: locale,
109
121
  localeUtils: MomentLocaleUtils,
110
122
  className: "Range",
@@ -125,8 +137,11 @@ var DatePicker = function DatePicker(_ref) {
125
137
  }),
126
138
  showOutsideDays: true,
127
139
  month: month
128
- },
129
- ref: pickerRef
140
+ }, dayPickerProps),
141
+ ref: pickerRef,
142
+ inputProps: _objectSpread({
143
+ id: datePickerId
144
+ }, inputProps)
130
145
  }, props), date[type])]
131
146
  });
132
147
  };
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 iconWrapper(icon, iconProps)(), /*#__PURE__*/_jsx(StyledInput, _objectSpread({
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 iconWrapper(IconComponent, iconProps) {
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
- var props = Object.assign({}, iconDefaults, iconProps);
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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@happeouikit/form-elements",
3
- "version": "2.3.0",
3
+ "version": "2.3.5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "src/index.js",