dibk-design 0.4.54 → 1.0.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.
@@ -11,12 +11,6 @@ var _react = _interopRequireDefault(require("react"));
11
11
 
12
12
  var _propTypes = _interopRequireDefault(require("prop-types"));
13
13
 
14
- var _reactDatepicker = _interopRequireWildcard(require("react-datepicker"));
15
-
16
- var _dateFns = require("date-fns");
17
-
18
- var _nb = _interopRequireDefault(require("date-fns/locale/nb"));
19
-
20
14
  var _Button = _interopRequireDefault(require("./Button"));
21
15
 
22
16
  var _Label = _interopRequireDefault(require("./Label"));
@@ -27,22 +21,14 @@ var _theme = require("../functions/theme");
27
21
 
28
22
  var _generators = require("../functions/generators");
29
23
 
30
- require("react-datepicker/dist/react-datepicker.css");
31
-
32
24
  var _InputFieldModule = _interopRequireDefault(require("./InputField.module.scss"));
33
25
 
34
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
35
-
36
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
37
-
38
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
39
27
 
40
28
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
41
29
 
42
30
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
43
31
 
44
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
45
-
46
32
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
47
33
 
48
34
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
@@ -63,7 +49,7 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
63
49
 
64
50
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
65
51
 
66
- (0, _reactDatepicker.registerLocale)('nb', _nb.default);
52
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
67
53
 
68
54
  var InputField = /*#__PURE__*/function (_React$Component) {
69
55
  _inherits(InputField, _React$Component);
@@ -71,30 +57,43 @@ var InputField = /*#__PURE__*/function (_React$Component) {
71
57
  var _super = _createSuper(InputField);
72
58
 
73
59
  function InputField() {
60
+ var _this;
61
+
74
62
  _classCallCheck(this, InputField);
75
63
 
76
- return _super.apply(this, arguments);
64
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
65
+ args[_key] = arguments[_key];
66
+ }
67
+
68
+ _this = _super.call.apply(_super, [this].concat(args));
69
+
70
+ _defineProperty(_assertThisInitialized(_this), "formatDate", function (inputDate) {
71
+ if (!inputDate) {
72
+ return null;
73
+ }
74
+
75
+ var date = new Date(inputDate);
76
+ var year = date.getFullYear();
77
+ var month = date.getMonth() + 1 < 10 ? "0".concat(date.getMonth() + 1) : date.getMonth() + 1;
78
+ var day = date.getDate() < 10 ? "0".concat(date.getDate()) : date.getDate();
79
+ return "".concat(day, ".").concat(month, ".").concat(year);
80
+ });
81
+
82
+ return _this;
77
83
  }
78
84
 
79
85
  _createClass(InputField, [{
80
86
  key: "getThemeErrorInputStyle",
81
87
  value: function getThemeErrorInputStyle(theme) {
82
88
  return {
83
- boxShadow: "0 0 3px ".concat((0, _theme.getThemePaletteBackgroundColor)(theme, 'warning')),
84
- borderColor: (0, _theme.getThemePaletteBackgroundColor)(theme, 'warning')
89
+ boxShadow: "0 0 3px ".concat((0, _theme.getThemePaletteBackgroundColor)(theme, "warning")),
90
+ borderColor: (0, _theme.getThemePaletteBackgroundColor)(theme, "warning")
85
91
  };
86
92
  }
87
- }, {
88
- key: "convertDateToString",
89
- value: function convertDateToString(date) {
90
- return date ? (0, _dateFns.format)(new Date(date), this.props.dateFormat, {
91
- locale: _nb.default
92
- }) : '';
93
- }
94
93
  }, {
95
94
  key: "renderValueAsText",
96
95
  value: function renderValueAsText(value, defaultContent) {
97
- return this.props.type === 'date' ? value ? this.convertDateToString(value) : defaultContent : value ? value : defaultContent;
96
+ return this.props.type === "date" ? value ? this.formatDate(value) : defaultContent : value ? value : defaultContent;
98
97
  }
99
98
  }, {
100
99
  key: "getInputElementProps",
@@ -108,39 +107,11 @@ var InputField = /*#__PURE__*/function (_React$Component) {
108
107
  type: this.props.type,
109
108
  id: this.props.id,
110
109
  key: defaultKey || "".concat(this.props.id, "-").concat((0, _generators.generateRandomString)(6)),
110
+ min: this.props.min || null,
111
+ max: this.props.max || null,
111
112
  onChange: this.props.onChange,
112
113
  onBlur: this.props.onBlur
113
- }, _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;
114
- }
115
- }, {
116
- key: "getDatePickerElementProps",
117
- value: function getDatePickerElementProps(defaultValue, defaultKey) {
118
- var _this = this;
119
-
120
- return {
121
- name: this.props.name,
122
- readOnly: this.props.readOnly,
123
- disabled: this.props.disabled,
124
- id: this.props.id,
125
- key: defaultKey || "".concat(this.props.id, "-").concat((0, _generators.generateRandomString)(6)),
126
- dateFormat: this.props.dateFormat,
127
- locale: 'nb',
128
- selectsStart: this.props.selectsStart,
129
- selectsEnd: this.props.selectsEnd,
130
- startDate: this.props.startDate ? new Date(this.props.startDate) : null,
131
- endDate: this.props.endDate ? new Date(this.props.endDate) : null,
132
- minDate: this.props.minDate || null,
133
- maxDate: this.props.maxDate || null,
134
- onChange: this.props.onChange ? function (date) {
135
- return _this.props.onChange(date);
136
- } : console.log("Missing onChange handler for date picker with id: ".concat(this.props.id)),
137
- onBlur: this.props.onBlur ? function (date) {
138
- return _this.props.onBlur(date);
139
- } : null,
140
- selected: defaultValue ? new Date(defaultValue) : null,
141
- placeholderText: this.props.placeholder,
142
- className: this.props.hasErrors ? _InputFieldModule.default.hasErrors : ''
143
- };
114
+ }, _defineProperty(_ref, defaultValue ? "defaultValue" : "value", defaultValue || this.props.value), _defineProperty(_ref, "placeholder", this.props.placeholder || null), _defineProperty(_ref, "className", this.props.hasErrors ? _InputFieldModule.default.hasErrors : ""), _defineProperty(_ref, "aria-required", this.props.mandatory), _defineProperty(_ref, "style", styleRules), _ref;
144
115
  }
145
116
  }, {
146
117
  key: "render",
@@ -159,7 +130,7 @@ var InputField = /*#__PURE__*/function (_React$Component) {
159
130
  className: "".concat(_InputFieldModule.default.inputField, " ").concat(_InputFieldModule.default[this.props.type])
160
131
  }, /*#__PURE__*/_react.default.createElement(_Label.default, {
161
132
  htmlFor: this.props.id
162
- }, this.props.label, this.props.type === 'file' ? /*#__PURE__*/_react.default.createElement("div", {
133
+ }, this.props.label, this.props.type === "file" ? /*#__PURE__*/_react.default.createElement("div", {
163
134
  className: _InputFieldModule.default.fileInputContainer
164
135
  }, /*#__PURE__*/_react.default.createElement("span", {
165
136
  className: _InputFieldModule.default.input
@@ -170,9 +141,7 @@ var InputField = /*#__PURE__*/function (_React$Component) {
170
141
  },
171
142
  content: this.props.buttonContent,
172
143
  theme: this.props.theme
173
- }) : '') : ''), !this.props.contentOnly ? this.props.type === 'date' ? /*#__PURE__*/_react.default.createElement("div", {
174
- style: styleRules
175
- }, /*#__PURE__*/_react.default.createElement(_reactDatepicker.default, this.getDatePickerElementProps(defaultValue, defaultKey))) : /*#__PURE__*/_react.default.createElement("input", this.getInputElementProps(defaultValue, defaultKey, styleRules)) : /*#__PURE__*/_react.default.createElement("span", null, this.renderValueAsText(this.props.value || this.props.defaultValue, this.props.defaultContent)), /*#__PURE__*/_react.default.createElement(_ErrorMessage.default, {
144
+ }) : null) : null), !this.props.contentOnly ? /*#__PURE__*/_react.default.createElement("input", this.getInputElementProps(defaultValue, defaultKey, styleRules)) : /*#__PURE__*/_react.default.createElement("span", null, this.renderValueAsText(this.props.value || this.props.defaultValue, this.props.defaultContent)), /*#__PURE__*/_react.default.createElement(_ErrorMessage.default, {
176
145
  content: this.props.errorMessage,
177
146
  theme: this.props.theme
178
147
  }));
@@ -198,7 +167,6 @@ InputField.propTypes = {
198
167
  buttonColor: _propTypes.default.string,
199
168
  buttonContent: _propTypes.default.string,
200
169
  selectedFileName: _propTypes.default.string,
201
- dateFormat: _propTypes.default.string,
202
170
  placeholder: _propTypes.default.string,
203
171
  defaultContent: _propTypes.default.string,
204
172
  hasErrors: _propTypes.default.bool,
@@ -207,16 +175,16 @@ InputField.propTypes = {
207
175
  theme: _propTypes.default.object
208
176
  };
209
177
  InputField.defaultProps = {
210
- name: '',
211
- type: 'text',
212
- label: '',
178
+ name: "",
179
+ type: "text",
180
+ label: "",
213
181
  contentOnly: false,
214
- buttonColor: 'default',
215
- dateFormat: 'd. MMMM, yyyy',
216
- placeholder: '',
217
- defaultContent: '',
182
+ buttonColor: "default",
183
+ dateFormat: "d. MMMM, yyyy",
184
+ placeholder: "",
185
+ defaultContent: "",
218
186
  hasErrors: false,
219
- errorMessage: '',
187
+ errorMessage: "",
220
188
  mandatory: false,
221
189
  onChange: function onChange() {
222
190
  return false;
@@ -15,13 +15,12 @@ Input field example:
15
15
  <InputField id="textInput10" onChange={() => {console.log('onChange')}} label="InputField without value, contentOnly set to true and defaultContent" contentOnly={true} defaultContent="Please insert a value" />
16
16
  <InputField id="fileInput1" onChange={()=>{console.log('onchange')}} type="file" label="InputField with label, value and type set to file" />
17
17
  <InputField id="fileInput1" onChange={()=>{console.log('onchange')}} type="file" label="InputField with label, value, fileName, buttonContent and type set to file" selectedFileName="file.txt" buttonContent="Legg til fil" />
18
- <InputField id="dateInput1" onChange={(date) => console.log("date", date)} type="date" label="Datepicker without value" value="" />
19
- <InputField id="dateInput2" onChange={(date) => console.log("date", date)} type="date" label="Datepicker with value" value="2020-05-10T13:12:04" />
20
- <InputField id="dateInput3" onChange={(date) => console.log("date", date)} type="date" label="Datepicker with value, errors and error message" value="2020-05-10T13:12:04" hasErrors={true} errorMessage="Wrong date value" />
21
- <InputField id="dateInput4" onChange={(date) => console.log("date", date)} type="date" label="Datepicker with value and contentOnly set to true" value="2020-05-10T13:12:04" contentOnly={true} />
22
- <InputField id="dateInput5" onChange={(date) => console.log("date", date)} type="date" label="Datepicker with value for start date" value="2020-05-10T13:12:04" selectsStart startDate="2020-05-10T13:12:04" endDate="2020-05-19T13:12:04" />
23
- <InputField id="dateInput6" onChange={(date) => console.log("date", date)} type="date" label="Datepicker with value for end date" value="2020-05-19T13:12:04" selectsEnd startDate="2020-05-10T13:12:04" endDate="2020-05-19T13:12:04" />
24
- <InputField id="dateInput7" onChange={(date) => console.log("date", date)} type="date" label="Datepicker with defaultContent and contentOnly set to true" contentOnly={true} defaultContent="Please insert a value" />
18
+ <InputField id="dateInput1" onChange={(date) => console.log("date", date)} type="date" label="Date input without value" value="" />
19
+ <InputField id="dateInput2" onChange={(date) => console.log("date", date)} type="date" label="Date input with value" value="2020-05-10" />
20
+ <InputField id="dateInput3" onChange={(date) => console.log("date", date)} type="date" label="Date input with value, errors and error message" value="2020-05-10" hasErrors={true} errorMessage="Wrong date value" />
21
+ <InputField id="dateInput4" onChange={(date) => console.log("date", date)} type="date" label="Date input with value and contentOnly set to true" value="2020-05-10" contentOnly={true} />
22
+ <InputField id="dateInput5" onChange={(date) => console.log("date", date)} type="date" label="Date input with min and max date" value="2020-05-10" selectsStart min="2020-05-04" max="2020-05-19" />
23
+ <InputField id="dateInput6" onChange={(date) => console.log("date", date)} type="date" label="Date input with defaultContent and contentOnly set to true" contentOnly={true} defaultContent="Please insert a value" />
25
24
  <InputField id="textInput9" value="InputField with value and custom width" width="400px" />
26
25
  <InputField id="textInput10" value="InputField with a not auto generated key" elementKey="inputKeyHere" />
27
26
  ```
@@ -34,7 +33,7 @@ import customTheme from 'data/customTheme';
34
33
  <InputField id="themedTextInput4" onChange={()=>{console.log('onchange')}} value="InputField with link in label" label={['InputField with ', <a key="labelLink" href="#">link</a>, ' in label']} theme={customTheme} />
35
34
  <InputField id="themedTextInput5" onChange={()=>{console.log('onchange')}} value="InputField with label, value, errors and error message" label="InputField with label, value, errors and error message" hasErrors={true} errorMessage="Wrong value" theme={customTheme} />
36
35
  <InputField id="themedFileInput1" onChange={()=>{console.log('onchange')}} type="file" label="InputField with label, value, fileName, buttonContent and type set to file" selectedFileName="file.txt" buttonContent="Legg til fil" theme={customTheme} />
37
- <InputField id="themedDateInput3" onChange={(date) => console.log("date", date)} type="date" label="Datepicker with value, errors and error message" value="2020-05-10T13:12:04" hasErrors={true} errorMessage="Wrong date value" theme={customTheme} />
36
+ <InputField id="themedDateInput3" onChange={(date) => console.log("date", date)} type="date" label="Date input with value, errors and error message" value="2020-05-10" hasErrors={true} errorMessage="Wrong date value" theme={customTheme} />
38
37
  <InputField id="themedDateInput4" value="InputField with value, error and custom width" width="420px" hasErrors={true} theme={customTheme} errorMessage="Wrong value" />
39
38
 
40
39
  </React.Fragment>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dibk-design",
3
- "version": "0.4.54",
3
+ "version": "1.0.0",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -11,7 +11,6 @@
11
11
  "dependencies": {
12
12
  "prop-types": "^15.6.2",
13
13
  "react": "^17.0.1",
14
- "react-datepicker": "^4.1.1",
15
14
  "react-dom": "^17.0.1",
16
15
  "react-router-dom": "^6.2.2",
17
16
  "react-scripts": "^4.0.0"