dibk-design 0.4.31 → 0.4.35

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.
@@ -11,18 +11,20 @@ var _react = _interopRequireDefault(require("react"));
11
11
 
12
12
  var _propTypes = _interopRequireDefault(require("prop-types"));
13
13
 
14
- var _Button = _interopRequireDefault(require("./Button"));
15
-
16
- var _Label = _interopRequireDefault(require("./Label"));
17
-
18
14
  var _reactDatepicker = _interopRequireWildcard(require("react-datepicker"));
19
15
 
20
16
  var _dateFns = require("date-fns");
21
17
 
22
18
  var _nb = _interopRequireDefault(require("date-fns/locale/nb"));
23
19
 
20
+ var _Button = _interopRequireDefault(require("./Button"));
21
+
22
+ var _Label = _interopRequireDefault(require("./Label"));
23
+
24
24
  var _theme = require("../functions/theme");
25
25
 
26
+ var _generators = require("../functions/generators");
27
+
26
28
  require("react-datepicker/dist/react-datepicker.css");
27
29
 
28
30
  var _InputFieldModule = _interopRequireDefault(require("./InputField.module.scss"));
@@ -100,65 +102,62 @@ var InputField = /*#__PURE__*/function (_React$Component) {
100
102
  return this.props.type === 'date' ? value ? this.convertDateToString(value) : defaultContent : value ? value : defaultContent;
101
103
  }
102
104
  }, {
103
- key: "renderInputField",
104
- value: function renderInputField() {
105
- var _this$props$width,
106
- _this = this;
107
-
108
- var styleRules = _objectSpread(_objectSpread({}, this.props.hasErrors ? this.getThemeErrorInputStyle(this.props.theme) : null), ((_this$props$width = this.props.width) === null || _this$props$width === void 0 ? void 0 : _this$props$width.length) && {
109
- maxWidth: this.props.width
110
- });
105
+ key: "getInputElementProps",
106
+ value: function getInputElementProps(defaultValue, styleRules) {
107
+ var _ref;
108
+
109
+ return _ref = {
110
+ name: this.props.name,
111
+ readOnly: this.props.readOnly,
112
+ disabled: this.props.disabled,
113
+ type: this.props.type,
114
+ id: this.props.id,
115
+ key: "".concat(this.props.id, "-").concat((0, _generators.generateRandomString)(6)),
116
+ onChange: this.props.onChange,
117
+ onBlur: this.props.onBlur
118
+ }, _defineProperty(_ref, defaultValue ? 'defaultValue' : 'value', defaultValue || this.props.value), _defineProperty(_ref, "placeholder", this.props.placeholder), _defineProperty(_ref, "className", this.props.hasErrors ? _InputFieldModule.default.hasErrors : ''), _defineProperty(_ref, 'aria-required', this.props.mandatory), _defineProperty(_ref, "style", styleRules), _ref;
119
+ }
120
+ }, {
121
+ key: "getDatePickerElementProps",
122
+ value: function getDatePickerElementProps(defaultValue) {
123
+ var _this = this;
111
124
 
112
- if (this.props.type === 'date') {
113
- var value = this.props.defaultValue ? this.props.defaultValue : this.props.value || null;
114
- var props = {
115
- name: this.props.name,
116
- readOnly: this.props.readOnly,
117
- disabled: this.props.disabled,
118
- id: this.props.id,
119
- dateFormat: this.props.dateFormat,
120
- locale: 'nb',
121
- selectsStart: this.props.selectsStart,
122
- selectsEnd: this.props.selectsEnd,
123
- startDate: this.props.startDate ? new Date(this.props.startDate) : null,
124
- endDate: this.props.endDate ? new Date(this.props.endDate) : null,
125
- minDate: this.props.minDate || null,
126
- maxDate: this.props.maxDate || null,
127
- onChange: this.props.onChange ? function (date) {
128
- return _this.props.onChange(date);
129
- } : console.log("Missing onChange handler for date picker with id: ".concat(this.props.id)),
130
- onBlur: this.props.onBlur ? function (date) {
131
- return _this.props.onBlur(date);
132
- } : null,
133
- selected: value ? new Date(value) : null,
134
- placeholderText: this.props.placeholder,
135
- className: this.props.hasErrors ? _InputFieldModule.default.hasErrors : ''
136
- };
137
- return /*#__PURE__*/_react.default.createElement("div", {
138
- style: styleRules
139
- }, /*#__PURE__*/_react.default.createElement(_reactDatepicker.default, props));
140
- } else {
141
- var _props2;
142
-
143
- var defaultValue = !this.props.value && this.props.defaultValue ? this.props.defaultValue : false;
144
-
145
- var _props = (_props2 = {
146
- name: this.props.name,
147
- readOnly: this.props.readOnly,
148
- disabled: this.props.disabled,
149
- type: this.props.type,
150
- id: this.props.id,
151
- onChange: this.props.onChange,
152
- onBlur: this.props.onBlur
153
- }, _defineProperty(_props2, defaultValue ? 'defaultValue' : 'value', defaultValue || this.props.value), _defineProperty(_props2, "placeholder", this.props.placeholder), _defineProperty(_props2, "className", this.props.hasErrors ? _InputFieldModule.default.hasErrors : ''), _defineProperty(_props2, 'aria-required', this.props.mandatory), _defineProperty(_props2, "style", styleRules), _props2);
154
-
155
- return /*#__PURE__*/_react.default.createElement("input", _props);
156
- }
125
+ return {
126
+ name: this.props.name,
127
+ readOnly: this.props.readOnly,
128
+ disabled: this.props.disabled,
129
+ id: this.props.id,
130
+ key: "".concat(this.props.id, "-").concat((0, _generators.generateRandomString)(6)),
131
+ dateFormat: this.props.dateFormat,
132
+ locale: 'nb',
133
+ selectsStart: this.props.selectsStart,
134
+ selectsEnd: this.props.selectsEnd,
135
+ startDate: this.props.startDate ? new Date(this.props.startDate) : null,
136
+ endDate: this.props.endDate ? new Date(this.props.endDate) : null,
137
+ minDate: this.props.minDate || null,
138
+ maxDate: this.props.maxDate || null,
139
+ onChange: this.props.onChange ? function (date) {
140
+ return _this.props.onChange(date);
141
+ } : console.log("Missing onChange handler for date picker with id: ".concat(this.props.id)),
142
+ onBlur: this.props.onBlur ? function (date) {
143
+ return _this.props.onBlur(date);
144
+ } : null,
145
+ selected: defaultValue ? new Date(defaultValue) : null,
146
+ placeholderText: this.props.placeholder,
147
+ className: this.props.hasErrors ? _InputFieldModule.default.hasErrors : ''
148
+ };
157
149
  }
158
150
  }, {
159
151
  key: "render",
160
152
  value: function render() {
161
- var _this2 = this;
153
+ var _this$props$width,
154
+ _this2 = this;
155
+
156
+ var defaultValue = this.props.defaultValue ? this.props.defaultValue : this.props.value || null;
157
+
158
+ var styleRules = _objectSpread(_objectSpread({}, this.props.hasErrors ? this.getThemeErrorInputStyle(this.props.theme) : null), ((_this$props$width = this.props.width) === null || _this$props$width === void 0 ? void 0 : _this$props$width.length) && {
159
+ maxWidth: this.props.width
160
+ });
162
161
 
163
162
  return /*#__PURE__*/_react.default.createElement("div", {
164
163
  className: "".concat(_InputFieldModule.default.inputField, " ").concat(_InputFieldModule.default[this.props.type])
@@ -175,7 +174,9 @@ var InputField = /*#__PURE__*/function (_React$Component) {
175
174
  },
176
175
  content: this.props.buttonContent,
177
176
  theme: this.props.theme
178
- }) : '') : ''), !this.props.contentOnly ? this.renderInputField() : /*#__PURE__*/_react.default.createElement("span", null, this.renderValueAsText(this.props.value || this.props.defaultValue, this.props.defaultContent)), /*#__PURE__*/_react.default.createElement("span", {
177
+ }) : '') : ''), !this.props.contentOnly ? this.props.type === 'date' ? /*#__PURE__*/_react.default.createElement("div", {
178
+ style: styleRules
179
+ }, /*#__PURE__*/_react.default.createElement(_reactDatepicker.default, this.getDatePickerElementProps(defaultValue))) : /*#__PURE__*/_react.default.createElement("input", this.getInputElementProps(defaultValue, styleRules)) : /*#__PURE__*/_react.default.createElement("span", null, this.renderValueAsText(this.props.value || this.props.defaultValue, this.props.defaultContent)), /*#__PURE__*/_react.default.createElement("span", {
179
180
  className: _InputFieldModule.default.errorMessage,
180
181
  style: this.getThemeErrorMessageStyle(this.props.theme)
181
182
  }, this.props.errorMessage ? this.props.errorMessage : ''));
@@ -13,6 +13,8 @@ var _Label = _interopRequireDefault(require("./Label"));
13
13
 
14
14
  var _theme = require("../functions/theme");
15
15
 
16
+ var _generators = require("../functions/generators");
17
+
16
18
  var _SelectModule = _interopRequireDefault(require("./Select.module.scss"));
17
19
 
18
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -151,7 +153,7 @@ var Select = /*#__PURE__*/function (_React$Component) {
151
153
  var props = (_props = {
152
154
  name: this.props.name,
153
155
  multiple: this.props.multiple
154
- }, _defineProperty(_props, defaultValue ? 'defaultValue' : 'value', defaultValue || this.props.value), _defineProperty(_props, "onChange", this.props.onChange), _defineProperty(_props, "id", this.props.id), _defineProperty(_props, "className", this.props.hasErrors ? _SelectModule.default.hasErrors : ''), _defineProperty(_props, "style", styleRules), _props);
156
+ }, _defineProperty(_props, defaultValue ? 'defaultValue' : 'value', defaultValue || this.props.value), _defineProperty(_props, "onChange", this.props.onChange), _defineProperty(_props, "id", this.props.id), _defineProperty(_props, "key", "".concat(this.props.id, "-").concat((0, _generators.generateRandomString)(6))), _defineProperty(_props, "className", this.props.hasErrors ? _SelectModule.default.hasErrors : ''), _defineProperty(_props, "style", styleRules), _props);
155
157
  return /*#__PURE__*/_react.default.createElement("div", {
156
158
  className: _SelectModule.default.select
157
159
  }, /*#__PURE__*/_react.default.createElement(_Label.default, {
@@ -15,6 +15,8 @@ var _Label = _interopRequireDefault(require("./Label"));
15
15
 
16
16
  var _theme = require("../functions/theme");
17
17
 
18
+ var _generators = require("../functions/generators");
19
+
18
20
  var _TextareaModule = _interopRequireDefault(require("./Textarea.module.scss"));
19
21
 
20
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -95,6 +97,7 @@ var Textarea = /*#__PURE__*/function (_React$Component) {
95
97
  disabled: this.props.disabled,
96
98
  type: this.props.type,
97
99
  id: this.props.id,
100
+ key: "".concat(this.props.id, "-").concat((0, _generators.generateRandomString)(6)),
98
101
  onChange: this.props.onChange,
99
102
  onBlur: this.props.onBlur
100
103
  }, _defineProperty(_props, defaultValue ? 'defaultValue' : 'value', defaultValue || this.props.value), _defineProperty(_props, "placeholder", this.props.placeholder), _defineProperty(_props, "rows", this.props.rows), _defineProperty(_props, "className", this.props.hasErrors ? _TextareaModule.default.hasErrors : ''), _defineProperty(_props, 'aria-required', this.props.mandatory), _defineProperty(_props, "style", styleRules), _props);
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.generateRandomString = void 0;
7
+
8
+ var generateRandomString = function generateRandomString(length) {
9
+ var result = '';
10
+ var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
11
+ var charactersLength = characters.length;
12
+
13
+ for (var i = 0; i < length; i++) {
14
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
15
+ }
16
+
17
+ return result;
18
+ };
19
+
20
+ exports.generateRandomString = generateRandomString;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dibk-design",
3
- "version": "0.4.31",
3
+ "version": "0.4.35",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",