@dhis2-ui/input 9.14.0 → 9.15.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.
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.Input = void 0;
7
7
  var _style = _interopRequireDefault(require("styled-jsx/style"));
8
8
  var _uiConstants = require("@dhis2/ui-constants");
9
+ var _uiIcons = require("@dhis2/ui-icons");
9
10
  var _statusIcon = require("@dhis2-ui/status-icon");
10
11
  var _classnames = _interopRequireDefault(require("classnames"));
11
12
  var _propTypes = _interopRequireDefault(require("prop-types"));
@@ -17,8 +18,8 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
17
18
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
18
19
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
19
20
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
20
- const styles = [`.input.jsx-31445346{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;gap:${_uiConstants.spacers.dp8};}`, `input.jsx-31445346{box-sizing:border-box;font-size:14px;line-height:16px;-webkit-user-select:text;-moz-user-select:text;-ms-user-select:text;user-select:text;color:${_uiConstants.colors.grey900};background-color:white;padding:11px 12px;max-height:40px;outline:0;border:1px solid ${_uiConstants.colors.grey500};border-radius:3px;box-shadow:inset 0 0 1px 0 rgba(48,54,60,0.1);text-overflow:ellipsis;}`, "input.dense.jsx-31445346{max-height:32px;padding:7px 8px;}", `input.jsx-31445346:focus{outline:none;box-shadow:inset 0 0 0 2px ${_uiConstants.theme.focus};border-color:${_uiConstants.theme.focus};}`, `input.jsx-31445346::-webkit-input-placeholder{color:${_uiConstants.colors.grey600};opacity:1;}`, `input.jsx-31445346::-moz-placeholder{color:${_uiConstants.colors.grey600};opacity:1;}`, `input.jsx-31445346:-ms-input-placeholder{color:${_uiConstants.colors.grey600};opacity:1;}`, `input.jsx-31445346::placeholder{color:${_uiConstants.colors.grey600};opacity:1;}`, "input[type='date'].jsx-31445346::-webkit-inner-spin-button,input[type='date'].jsx-31445346::-webkit-calendar-picker-indicator,input[type='time'].jsx-31445346::-webkit-inner-spin-button,input[type='time'].jsx-31445346::-webkit-calendar-picker-indicator,input[type='datetime-local'].jsx-31445346::-webkit-inner-spin-button,input[type='datetime-local'].jsx-31445346::-webkit-calendar-picker-indicator{height:14px;padding-top:1px;padding-bottom:1px;}", "input[type='date'].jsx-31445346::-webkit-datetime-edit-fields-wrapper,input[type='datetime-local'].jsx-31445346::-webkit-datetime-edit-fields-wrapper,input[type='time'].jsx-31445346::-webkit-datetime-edit-fields-wrapper{padding:0;}", `input.warning.jsx-31445346{border-color:${_uiConstants.theme.warning};}`, `input.error.jsx-31445346{border-color:${_uiConstants.theme.error};}`, `input.read-only.jsx-31445346{background-color:${_uiConstants.colors.grey050};border-color:${_uiConstants.colors.grey300};box-shadow:none;cursor:text;}`, `input.disabled.jsx-31445346{background-color:${_uiConstants.colors.grey100};border-color:${_uiConstants.colors.grey500};color:${_uiConstants.theme.disabled};cursor:not-allowed;}`];
21
- styles.__hash = "31445346";
21
+ const styles = [`.input.jsx-4253951613{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;position:relative;gap:${_uiConstants.spacers.dp8};}`, `input.jsx-4253951613{box-sizing:border-box;font-size:14px;line-height:16px;-webkit-user-select:text;-moz-user-select:text;-ms-user-select:text;user-select:text;color:${_uiConstants.colors.grey900};background-color:white;padding:11px 12px;max-height:40px;outline:0;border:1px solid ${_uiConstants.colors.grey500};border-radius:3px;box-shadow:inset 0 0 1px 0 rgba(48,54,60,0.1);text-overflow:ellipsis;}`, "input.dense.jsx-4253951613{max-height:32px;padding:7px 8px;}", `input.jsx-4253951613:focus{outline:none;box-shadow:inset 0 0 0 2px ${_uiConstants.theme.focus};border-color:${_uiConstants.theme.focus};}`, `input.jsx-4253951613::-webkit-input-placeholder{color:${_uiConstants.colors.grey600};opacity:1;}`, `input.jsx-4253951613::-moz-placeholder{color:${_uiConstants.colors.grey600};opacity:1;}`, `input.jsx-4253951613:-ms-input-placeholder{color:${_uiConstants.colors.grey600};opacity:1;}`, `input.jsx-4253951613::placeholder{color:${_uiConstants.colors.grey600};opacity:1;}`, "input[type='date'].jsx-4253951613::-webkit-inner-spin-button,input[type='date'].jsx-4253951613::-webkit-calendar-picker-indicator,input[type='time'].jsx-4253951613::-webkit-inner-spin-button,input[type='time'].jsx-4253951613::-webkit-calendar-picker-indicator,input[type='datetime-local'].jsx-4253951613::-webkit-inner-spin-button,input[type='datetime-local'].jsx-4253951613::-webkit-calendar-picker-indicator{height:14px;padding-top:1px;padding-bottom:1px;}", "input[type='date'].jsx-4253951613::-webkit-datetime-edit-fields-wrapper,input[type='datetime-local'].jsx-4253951613::-webkit-datetime-edit-fields-wrapper,input[type='time'].jsx-4253951613::-webkit-datetime-edit-fields-wrapper{padding:0;}", `input.warning.jsx-4253951613{border-color:${_uiConstants.theme.warning};}`, `input.error.jsx-4253951613{border-color:${_uiConstants.theme.error};}`, `input.read-only.jsx-4253951613{background-color:${_uiConstants.colors.grey050};border-color:${_uiConstants.colors.grey300};box-shadow:none;cursor:text;}`, `input.disabled.jsx-4253951613{background-color:${_uiConstants.colors.grey100};border-color:${_uiConstants.colors.grey500};color:${_uiConstants.theme.disabled};cursor:not-allowed;}`];
22
+ styles.__hash = "4253951613";
22
23
  class Input extends _react.Component {
23
24
  constructor() {
24
25
  super(...arguments);
@@ -43,6 +44,14 @@ class Input extends _react.Component {
43
44
  this.props.onKeyDown(this.createHandlerPayload(e), e);
44
45
  }
45
46
  });
47
+ _defineProperty(this, "handleClear", () => {
48
+ if (this.props.onChange) {
49
+ this.props.onChange({
50
+ value: '',
51
+ name: this.props.name
52
+ });
53
+ }
54
+ });
46
55
  }
47
56
  componentDidMount() {
48
57
  if (this.props.initialFocus) {
@@ -75,12 +84,21 @@ class Input extends _react.Component {
75
84
  min,
76
85
  step,
77
86
  autoComplete,
78
- dataTest = 'dhis2-uicore-input'
87
+ dataTest = 'dhis2-uicore-input',
88
+ clearable,
89
+ prefixIcon,
90
+ width
79
91
  } = this.props;
80
92
  return /*#__PURE__*/_react.default.createElement("div", {
81
93
  "data-test": dataTest,
82
- className: "jsx-3353877153 " + `jsx-${styles.__hash}` + " " + ((0, _classnames.default)('input', className) || "")
83
- }, /*#__PURE__*/_react.default.createElement("input", {
94
+ className: `jsx-${styles.__hash}` + " " + _style.default.dynamic([["3324859945", [width ? width : `100%`, _uiConstants.colors.grey600, _uiConstants.colors.grey500]]]) + " " + ((0, _classnames.default)('input', className, {
95
+ 'input-prefix-icon': prefixIcon
96
+ }, {
97
+ 'input-clearable': clearable
98
+ }) || "")
99
+ }, prefixIcon && /*#__PURE__*/_react.default.createElement("span", {
100
+ className: `jsx-${styles.__hash}` + " " + _style.default.dynamic([["3324859945", [width ? width : `100%`, _uiConstants.colors.grey600, _uiConstants.colors.grey500]]]) + " " + "prefix"
101
+ }, prefixIcon), /*#__PURE__*/_react.default.createElement("input", {
84
102
  role: role,
85
103
  id: name,
86
104
  name: name,
@@ -99,7 +117,7 @@ class Input extends _react.Component {
99
117
  onBlur: this.handleBlur,
100
118
  onChange: this.handleChange,
101
119
  onKeyDown: this.handleKeyDown,
102
- className: "jsx-3353877153 " + `jsx-${styles.__hash}` + " " + ((0, _classnames.default)({
120
+ className: `jsx-${styles.__hash}` + " " + _style.default.dynamic([["3324859945", [width ? width : `100%`, _uiConstants.colors.grey600, _uiConstants.colors.grey500]]]) + " " + ((0, _classnames.default)({
103
121
  dense,
104
122
  disabled,
105
123
  error,
@@ -107,7 +125,13 @@ class Input extends _react.Component {
107
125
  warning,
108
126
  'read-only': readOnly
109
127
  }) || "")
110
- }), /*#__PURE__*/_react.default.createElement(_statusIcon.StatusIcon, {
128
+ }), clearable && value !== null && value !== void 0 && value.length ? /*#__PURE__*/_react.default.createElement("button", {
129
+ type: "button",
130
+ onClick: this.handleClear,
131
+ className: `jsx-${styles.__hash}` + " " + _style.default.dynamic([["3324859945", [width ? width : `100%`, _uiConstants.colors.grey600, _uiConstants.colors.grey500]]]) + " " + "clear-button"
132
+ }, /*#__PURE__*/_react.default.createElement(_uiIcons.IconCross16, {
133
+ color: _uiConstants.colors.white
134
+ })) : null, /*#__PURE__*/_react.default.createElement(_statusIcon.StatusIcon, {
111
135
  error: error,
112
136
  valid: valid,
113
137
  loading: loading,
@@ -115,8 +139,9 @@ class Input extends _react.Component {
115
139
  }), /*#__PURE__*/_react.default.createElement(_style.default, {
116
140
  id: styles.__hash
117
141
  }, styles), /*#__PURE__*/_react.default.createElement(_style.default, {
118
- id: "3353877153"
119
- }, ["input.jsx-3353877153{width:100%;}"]));
142
+ id: "3324859945",
143
+ dynamic: [width ? width : `100%`, _uiConstants.colors.grey600, _uiConstants.colors.grey500]
144
+ }, [`.input.__jsx-style-dynamic-selector{width:${width ? width : `100%`};}`, "input.__jsx-style-dynamic-selector{width:100%;}", ".input-prefix-icon.__jsx-style-dynamic-selector input.__jsx-style-dynamic-selector{padding-inline-start:30px;}", ".input-clearable.__jsx-style-dynamic-selector input.__jsx-style-dynamic-selector{padding-inline-end:30px;}", `.prefix.__jsx-style-dynamic-selector{position:absolute;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;pointer-events:none;left:10px;padding:0;color:${_uiConstants.colors.grey600};}`, `.clear-button.__jsx-style-dynamic-selector{position:absolute;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;border:none;cursor:pointer;height:16px;width:16px;border-radius:50%;right:10px;background:${_uiConstants.colors.grey500};padding:1px;}`]));
120
145
  }
121
146
  }
122
147
  exports.Input = Input;
@@ -128,6 +153,8 @@ Input.propTypes = {
128
153
  /** The [native `autocomplete` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-autocomplete) */
129
154
  autoComplete: _propTypes.default.string,
130
155
  className: _propTypes.default.string,
156
+ /** Makes the input field clearable */
157
+ clearable: _propTypes.default.bool,
131
158
  dataTest: _propTypes.default.string,
132
159
  /** Makes the input smaller */
133
160
  dense: _propTypes.default.bool,
@@ -147,6 +174,8 @@ Input.propTypes = {
147
174
  name: _propTypes.default.string,
148
175
  /** Placeholder text for the input */
149
176
  placeholder: _propTypes.default.string,
177
+ /** Add prefix icon */
178
+ prefixIcon: _propTypes.default.element,
150
179
  /** Makes the input read-only */
151
180
  readOnly: _propTypes.default.bool,
152
181
  /** Sets a role attribute on the input */
@@ -162,6 +191,8 @@ Input.propTypes = {
162
191
  value: _propTypes.default.string,
163
192
  /** Applies 'warning' appearance for validation feedback. Mutually exclusive with `valid` and `error` props */
164
193
  warning: _uiConstants.sharedPropTypes.statusPropType,
194
+ /** Defines the width of the input. Can be any valid CSS measurement */
195
+ width: _propTypes.default.string,
165
196
  /** Called with signature `({ name: string, value: string }, event)` */
166
197
  onBlur: _propTypes.default.func,
167
198
  /** Called with signature `({ name: string, value: string }, event)` */
@@ -44,6 +44,8 @@ class InputField extends _react.default.Component {
44
44
  validationText,
45
45
  inputWidth,
46
46
  autoComplete,
47
+ clearable,
48
+ prefixIcon,
47
49
  dataTest = 'dhis2-uiwidgets-inputfield'
48
50
  } = this.props;
49
51
  return /*#__PURE__*/_react.default.createElement(_field.Field, {
@@ -82,7 +84,10 @@ class InputField extends _react.default.Component {
82
84
  tabIndex: tabIndex,
83
85
  initialFocus: initialFocus,
84
86
  readOnly: readOnly,
85
- autoComplete: autoComplete
87
+ autoComplete: autoComplete,
88
+ clearable: clearable,
89
+ prefixIcon: prefixIcon,
90
+ width: inputWidth
86
91
  })));
87
92
  }
88
93
  }
@@ -94,6 +99,8 @@ const InputFieldProps = exports.InputFieldProps = {
94
99
  /** The [native `autocomplete` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-autocomplete) */
95
100
  autoComplete: _propTypes.default.string,
96
101
  className: _propTypes.default.string,
102
+ /** Makes the input field clearable */
103
+ clearable: _propTypes.default.bool,
97
104
  dataTest: _propTypes.default.string,
98
105
  /** Makes the input smaller */
99
106
  dense: _propTypes.default.bool,
@@ -119,6 +126,8 @@ const InputFieldProps = exports.InputFieldProps = {
119
126
  name: _propTypes.default.string,
120
127
  /** Placeholder text for the input */
121
128
  placeholder: _propTypes.default.string,
129
+ /** Add prefix icon */
130
+ prefixIcon: _propTypes.default.element,
122
131
  /** Makes the input read-only */
123
132
  readOnly: _propTypes.default.bool,
124
133
  /** Indicates this input is required */
@@ -3,11 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.WithValue = exports.WithHelpText = exports.ValueTextOverflow = exports.StatusWarning = exports.StatusValid = exports.StatusLoading = exports.StatusError = exports.Required = exports.ReadOnly = exports.PlaceholderNoValue = exports.NoPlaceholderNoValue = exports.LabelTextOverflow = exports.InputWidth = exports.Focus = exports.Disabled = exports.Dense = exports.Default = void 0;
6
+ exports.default = exports.WithValue = exports.WithHelpText = exports.ValueTextOverflow = exports.StatusWarning = exports.StatusValid = exports.StatusLoading = exports.StatusError = exports.Required = exports.ReadOnly = exports.PlaceholderNoValue = exports.NoPlaceholderNoValue = exports.LabelTextOverflow = exports.InputWithPrefixIcon = exports.InputWidth = exports.Focus = exports.Disabled = exports.Dense = exports.Default = exports.ClearableInput = void 0;
7
7
  var _uiConstants = require("@dhis2/ui-constants");
8
- var _react = _interopRequireDefault(require("react"));
8
+ var _uiIcons = require("@dhis2/ui-icons");
9
+ var _react = _interopRequireWildcard(require("react"));
9
10
  var _index = require("./index.js");
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
12
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
13
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
12
14
  const subtitle = 'Allows a user to enter data, usually text';
13
15
  const description = `
@@ -165,4 +167,30 @@ ValueTextOverflow.args = {
165
167
  const Required = exports.Required = Template.bind({});
166
168
  Required.args = {
167
169
  required: true
168
- };
170
+ };
171
+ const InputWithPrefixIcon = args => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_index.InputField, _extends({}, args, {
172
+ name: "prefix-icon-input",
173
+ label: "Search",
174
+ placeholder: 'Search',
175
+ prefixIcon: /*#__PURE__*/_react.default.createElement(_uiIcons.IconSearch16, null)
176
+ })), /*#__PURE__*/_react.default.createElement(_index.InputField, _extends({}, args, {
177
+ name: "prefix-icon-input",
178
+ label: "Location",
179
+ placeholder: 'Enter Location',
180
+ prefixIcon: /*#__PURE__*/_react.default.createElement(_uiIcons.IconLocation16, null),
181
+ inputWidth: '200px'
182
+ })));
183
+ exports.InputWithPrefixIcon = InputWithPrefixIcon;
184
+ const ClearableInput = args => {
185
+ const [value, setValue] = (0, _react.useState)('value');
186
+ return /*#__PURE__*/_react.default.createElement(_index.InputField, _extends({}, args, {
187
+ name: "clearable-input",
188
+ label: "This field can be cleared",
189
+ placeholder: '',
190
+ onChange: e => setValue(e.value),
191
+ clearable: true,
192
+ clearText: () => setValue(''),
193
+ value: value
194
+ }));
195
+ };
196
+ exports.ClearableInput = ClearableInput;
@@ -3,13 +3,14 @@ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object
3
3
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
4
4
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
5
5
  import { theme, colors, spacers, sharedPropTypes } from '@dhis2/ui-constants';
6
+ import { IconCross16 } from '@dhis2/ui-icons';
6
7
  import { StatusIcon } from '@dhis2-ui/status-icon';
7
8
  import cx from 'classnames';
8
9
  import PropTypes from 'prop-types';
9
10
  import React, { Component } from 'react';
10
11
  import { inputTypes } from './inputTypes.js';
11
- const styles = [`.input.jsx-31445346{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;gap:${spacers.dp8};}`, `input.jsx-31445346{box-sizing:border-box;font-size:14px;line-height:16px;-webkit-user-select:text;-moz-user-select:text;-ms-user-select:text;user-select:text;color:${colors.grey900};background-color:white;padding:11px 12px;max-height:40px;outline:0;border:1px solid ${colors.grey500};border-radius:3px;box-shadow:inset 0 0 1px 0 rgba(48,54,60,0.1);text-overflow:ellipsis;}`, "input.dense.jsx-31445346{max-height:32px;padding:7px 8px;}", `input.jsx-31445346:focus{outline:none;box-shadow:inset 0 0 0 2px ${theme.focus};border-color:${theme.focus};}`, `input.jsx-31445346::-webkit-input-placeholder{color:${colors.grey600};opacity:1;}`, `input.jsx-31445346::-moz-placeholder{color:${colors.grey600};opacity:1;}`, `input.jsx-31445346:-ms-input-placeholder{color:${colors.grey600};opacity:1;}`, `input.jsx-31445346::placeholder{color:${colors.grey600};opacity:1;}`, "input[type='date'].jsx-31445346::-webkit-inner-spin-button,input[type='date'].jsx-31445346::-webkit-calendar-picker-indicator,input[type='time'].jsx-31445346::-webkit-inner-spin-button,input[type='time'].jsx-31445346::-webkit-calendar-picker-indicator,input[type='datetime-local'].jsx-31445346::-webkit-inner-spin-button,input[type='datetime-local'].jsx-31445346::-webkit-calendar-picker-indicator{height:14px;padding-top:1px;padding-bottom:1px;}", "input[type='date'].jsx-31445346::-webkit-datetime-edit-fields-wrapper,input[type='datetime-local'].jsx-31445346::-webkit-datetime-edit-fields-wrapper,input[type='time'].jsx-31445346::-webkit-datetime-edit-fields-wrapper{padding:0;}", `input.warning.jsx-31445346{border-color:${theme.warning};}`, `input.error.jsx-31445346{border-color:${theme.error};}`, `input.read-only.jsx-31445346{background-color:${colors.grey050};border-color:${colors.grey300};box-shadow:none;cursor:text;}`, `input.disabled.jsx-31445346{background-color:${colors.grey100};border-color:${colors.grey500};color:${theme.disabled};cursor:not-allowed;}`];
12
- styles.__hash = "31445346";
12
+ const styles = [`.input.jsx-4253951613{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;position:relative;gap:${spacers.dp8};}`, `input.jsx-4253951613{box-sizing:border-box;font-size:14px;line-height:16px;-webkit-user-select:text;-moz-user-select:text;-ms-user-select:text;user-select:text;color:${colors.grey900};background-color:white;padding:11px 12px;max-height:40px;outline:0;border:1px solid ${colors.grey500};border-radius:3px;box-shadow:inset 0 0 1px 0 rgba(48,54,60,0.1);text-overflow:ellipsis;}`, "input.dense.jsx-4253951613{max-height:32px;padding:7px 8px;}", `input.jsx-4253951613:focus{outline:none;box-shadow:inset 0 0 0 2px ${theme.focus};border-color:${theme.focus};}`, `input.jsx-4253951613::-webkit-input-placeholder{color:${colors.grey600};opacity:1;}`, `input.jsx-4253951613::-moz-placeholder{color:${colors.grey600};opacity:1;}`, `input.jsx-4253951613:-ms-input-placeholder{color:${colors.grey600};opacity:1;}`, `input.jsx-4253951613::placeholder{color:${colors.grey600};opacity:1;}`, "input[type='date'].jsx-4253951613::-webkit-inner-spin-button,input[type='date'].jsx-4253951613::-webkit-calendar-picker-indicator,input[type='time'].jsx-4253951613::-webkit-inner-spin-button,input[type='time'].jsx-4253951613::-webkit-calendar-picker-indicator,input[type='datetime-local'].jsx-4253951613::-webkit-inner-spin-button,input[type='datetime-local'].jsx-4253951613::-webkit-calendar-picker-indicator{height:14px;padding-top:1px;padding-bottom:1px;}", "input[type='date'].jsx-4253951613::-webkit-datetime-edit-fields-wrapper,input[type='datetime-local'].jsx-4253951613::-webkit-datetime-edit-fields-wrapper,input[type='time'].jsx-4253951613::-webkit-datetime-edit-fields-wrapper{padding:0;}", `input.warning.jsx-4253951613{border-color:${theme.warning};}`, `input.error.jsx-4253951613{border-color:${theme.error};}`, `input.read-only.jsx-4253951613{background-color:${colors.grey050};border-color:${colors.grey300};box-shadow:none;cursor:text;}`, `input.disabled.jsx-4253951613{background-color:${colors.grey100};border-color:${colors.grey500};color:${theme.disabled};cursor:not-allowed;}`];
13
+ styles.__hash = "4253951613";
13
14
  export class Input extends Component {
14
15
  constructor() {
15
16
  super(...arguments);
@@ -34,6 +35,14 @@ export class Input extends Component {
34
35
  this.props.onKeyDown(this.createHandlerPayload(e), e);
35
36
  }
36
37
  });
38
+ _defineProperty(this, "handleClear", () => {
39
+ if (this.props.onChange) {
40
+ this.props.onChange({
41
+ value: '',
42
+ name: this.props.name
43
+ });
44
+ }
45
+ });
37
46
  }
38
47
  componentDidMount() {
39
48
  if (this.props.initialFocus) {
@@ -66,12 +75,21 @@ export class Input extends Component {
66
75
  min,
67
76
  step,
68
77
  autoComplete,
69
- dataTest = 'dhis2-uicore-input'
78
+ dataTest = 'dhis2-uicore-input',
79
+ clearable,
80
+ prefixIcon,
81
+ width
70
82
  } = this.props;
71
83
  return /*#__PURE__*/React.createElement("div", {
72
84
  "data-test": dataTest,
73
- className: "jsx-3353877153 " + `jsx-${styles.__hash}` + " " + (cx('input', className) || "")
74
- }, /*#__PURE__*/React.createElement("input", {
85
+ className: `jsx-${styles.__hash}` + " " + _JSXStyle.dynamic([["3324859945", [width ? width : `100%`, colors.grey600, colors.grey500]]]) + " " + (cx('input', className, {
86
+ 'input-prefix-icon': prefixIcon
87
+ }, {
88
+ 'input-clearable': clearable
89
+ }) || "")
90
+ }, prefixIcon && /*#__PURE__*/React.createElement("span", {
91
+ className: `jsx-${styles.__hash}` + " " + _JSXStyle.dynamic([["3324859945", [width ? width : `100%`, colors.grey600, colors.grey500]]]) + " " + "prefix"
92
+ }, prefixIcon), /*#__PURE__*/React.createElement("input", {
75
93
  role: role,
76
94
  id: name,
77
95
  name: name,
@@ -90,7 +108,7 @@ export class Input extends Component {
90
108
  onBlur: this.handleBlur,
91
109
  onChange: this.handleChange,
92
110
  onKeyDown: this.handleKeyDown,
93
- className: "jsx-3353877153 " + `jsx-${styles.__hash}` + " " + (cx({
111
+ className: `jsx-${styles.__hash}` + " " + _JSXStyle.dynamic([["3324859945", [width ? width : `100%`, colors.grey600, colors.grey500]]]) + " " + (cx({
94
112
  dense,
95
113
  disabled,
96
114
  error,
@@ -98,7 +116,13 @@ export class Input extends Component {
98
116
  warning,
99
117
  'read-only': readOnly
100
118
  }) || "")
101
- }), /*#__PURE__*/React.createElement(StatusIcon, {
119
+ }), clearable && value !== null && value !== void 0 && value.length ? /*#__PURE__*/React.createElement("button", {
120
+ type: "button",
121
+ onClick: this.handleClear,
122
+ className: `jsx-${styles.__hash}` + " " + _JSXStyle.dynamic([["3324859945", [width ? width : `100%`, colors.grey600, colors.grey500]]]) + " " + "clear-button"
123
+ }, /*#__PURE__*/React.createElement(IconCross16, {
124
+ color: colors.white
125
+ })) : null, /*#__PURE__*/React.createElement(StatusIcon, {
102
126
  error: error,
103
127
  valid: valid,
104
128
  loading: loading,
@@ -106,8 +130,9 @@ export class Input extends Component {
106
130
  }), /*#__PURE__*/React.createElement(_JSXStyle, {
107
131
  id: styles.__hash
108
132
  }, styles), /*#__PURE__*/React.createElement(_JSXStyle, {
109
- id: "3353877153"
110
- }, ["input.jsx-3353877153{width:100%;}"]));
133
+ id: "3324859945",
134
+ dynamic: [width ? width : `100%`, colors.grey600, colors.grey500]
135
+ }, [`.input.__jsx-style-dynamic-selector{width:${width ? width : `100%`};}`, "input.__jsx-style-dynamic-selector{width:100%;}", ".input-prefix-icon.__jsx-style-dynamic-selector input.__jsx-style-dynamic-selector{padding-inline-start:30px;}", ".input-clearable.__jsx-style-dynamic-selector input.__jsx-style-dynamic-selector{padding-inline-end:30px;}", `.prefix.__jsx-style-dynamic-selector{position:absolute;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;pointer-events:none;left:10px;padding:0;color:${colors.grey600};}`, `.clear-button.__jsx-style-dynamic-selector{position:absolute;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;border:none;cursor:pointer;height:16px;width:16px;border-radius:50%;right:10px;background:${colors.grey500};padding:1px;}`]));
111
136
  }
112
137
  }
113
138
  _defineProperty(Input, "defaultProps", {
@@ -118,6 +143,8 @@ Input.propTypes = {
118
143
  /** The [native `autocomplete` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-autocomplete) */
119
144
  autoComplete: PropTypes.string,
120
145
  className: PropTypes.string,
146
+ /** Makes the input field clearable */
147
+ clearable: PropTypes.bool,
121
148
  dataTest: PropTypes.string,
122
149
  /** Makes the input smaller */
123
150
  dense: PropTypes.bool,
@@ -137,6 +164,8 @@ Input.propTypes = {
137
164
  name: PropTypes.string,
138
165
  /** Placeholder text for the input */
139
166
  placeholder: PropTypes.string,
167
+ /** Add prefix icon */
168
+ prefixIcon: PropTypes.element,
140
169
  /** Makes the input read-only */
141
170
  readOnly: PropTypes.bool,
142
171
  /** Sets a role attribute on the input */
@@ -152,6 +181,8 @@ Input.propTypes = {
152
181
  value: PropTypes.string,
153
182
  /** Applies 'warning' appearance for validation feedback. Mutually exclusive with `valid` and `error` props */
154
183
  warning: sharedPropTypes.statusPropType,
184
+ /** Defines the width of the input. Can be any valid CSS measurement */
185
+ width: PropTypes.string,
155
186
  /** Called with signature `({ name: string, value: string }, event)` */
156
187
  onBlur: PropTypes.func,
157
188
  /** Called with signature `({ name: string, value: string }, event)` */
@@ -37,6 +37,8 @@ class InputField extends React.Component {
37
37
  validationText,
38
38
  inputWidth,
39
39
  autoComplete,
40
+ clearable,
41
+ prefixIcon,
40
42
  dataTest = 'dhis2-uiwidgets-inputfield'
41
43
  } = this.props;
42
44
  return /*#__PURE__*/React.createElement(Field, {
@@ -75,7 +77,10 @@ class InputField extends React.Component {
75
77
  tabIndex: tabIndex,
76
78
  initialFocus: initialFocus,
77
79
  readOnly: readOnly,
78
- autoComplete: autoComplete
80
+ autoComplete: autoComplete,
81
+ clearable: clearable,
82
+ prefixIcon: prefixIcon,
83
+ width: inputWidth
79
84
  })));
80
85
  }
81
86
  }
@@ -86,6 +91,8 @@ const InputFieldProps = {
86
91
  /** The [native `autocomplete` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-autocomplete) */
87
92
  autoComplete: PropTypes.string,
88
93
  className: PropTypes.string,
94
+ /** Makes the input field clearable */
95
+ clearable: PropTypes.bool,
89
96
  dataTest: PropTypes.string,
90
97
  /** Makes the input smaller */
91
98
  dense: PropTypes.bool,
@@ -111,6 +118,8 @@ const InputFieldProps = {
111
118
  name: PropTypes.string,
112
119
  /** Placeholder text for the input */
113
120
  placeholder: PropTypes.string,
121
+ /** Add prefix icon */
122
+ prefixIcon: PropTypes.element,
114
123
  /** Makes the input read-only */
115
124
  readOnly: PropTypes.bool,
116
125
  /** Indicates this input is required */
@@ -1,6 +1,7 @@
1
1
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
2
  import { sharedPropTypes } from '@dhis2/ui-constants';
3
- import React from 'react';
3
+ import { IconLocation16, IconSearch16 } from '@dhis2/ui-icons';
4
+ import React, { useState } from 'react';
4
5
  import { InputField } from './index.js';
5
6
  const subtitle = 'Allows a user to enter data, usually text';
6
7
  const description = `
@@ -157,4 +158,28 @@ ValueTextOverflow.args = {
157
158
  export const Required = Template.bind({});
158
159
  Required.args = {
159
160
  required: true
161
+ };
162
+ export const InputWithPrefixIcon = args => /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(InputField, _extends({}, args, {
163
+ name: "prefix-icon-input",
164
+ label: "Search",
165
+ placeholder: 'Search',
166
+ prefixIcon: /*#__PURE__*/React.createElement(IconSearch16, null)
167
+ })), /*#__PURE__*/React.createElement(InputField, _extends({}, args, {
168
+ name: "prefix-icon-input",
169
+ label: "Location",
170
+ placeholder: 'Enter Location',
171
+ prefixIcon: /*#__PURE__*/React.createElement(IconLocation16, null),
172
+ inputWidth: '200px'
173
+ })));
174
+ export const ClearableInput = args => {
175
+ const [value, setValue] = useState('value');
176
+ return /*#__PURE__*/React.createElement(InputField, _extends({}, args, {
177
+ name: "clearable-input",
178
+ label: "This field can be cleared",
179
+ placeholder: '',
180
+ onChange: e => setValue(e.value),
181
+ clearable: true,
182
+ clearText: () => setValue(''),
183
+ value: value
184
+ }));
160
185
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2-ui/input",
3
- "version": "9.14.0",
3
+ "version": "9.15.0",
4
4
  "description": "UI Input",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,13 +33,13 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@dhis2/prop-types": "^3.1.2",
36
- "@dhis2-ui/box": "9.14.0",
37
- "@dhis2-ui/field": "9.14.0",
38
- "@dhis2-ui/input": "9.14.0",
39
- "@dhis2-ui/loader": "9.14.0",
40
- "@dhis2-ui/status-icon": "9.14.0",
41
- "@dhis2/ui-constants": "9.14.0",
42
- "@dhis2/ui-icons": "9.14.0",
36
+ "@dhis2-ui/box": "9.15.0",
37
+ "@dhis2-ui/field": "9.15.0",
38
+ "@dhis2-ui/input": "9.15.0",
39
+ "@dhis2-ui/loader": "9.15.0",
40
+ "@dhis2-ui/status-icon": "9.15.0",
41
+ "@dhis2/ui-constants": "9.15.0",
42
+ "@dhis2/ui-icons": "9.15.0",
43
43
  "classnames": "^2.3.1",
44
44
  "prop-types": "^15.7.2"
45
45
  },
package/types/index.d.ts CHANGED
@@ -41,6 +41,10 @@ export interface InputProps {
41
41
  */
42
42
  autoComplete?: string
43
43
  className?: string
44
+ /**
45
+ * Makes the input clearable
46
+ */
47
+ clearable?: boolean
44
48
  dataTest?: string
45
49
  /**
46
50
  * Makes the input smaller
@@ -78,6 +82,10 @@ export interface InputProps {
78
82
  * Placeholder text for the input
79
83
  */
80
84
  placeholder?: string
85
+ /**
86
+ * Add prefix icon
87
+ */
88
+ prefixIcon?: Element
81
89
  /**
82
90
  * Makes the input read-only
83
91
  */
@@ -135,6 +143,10 @@ export interface InputFieldProps {
135
143
  */
136
144
  autoComplete?: string
137
145
  className?: string
146
+ /**
147
+ * Makes the input field clearable
148
+ */
149
+ clearable?: boolean
138
150
  dataTest?: string
139
151
  /**
140
152
  * Makes the input smaller
@@ -184,6 +196,10 @@ export interface InputFieldProps {
184
196
  * Placeholder text for the input
185
197
  */
186
198
  placeholder?: string
199
+ /**
200
+ * Add prefix icon to input
201
+ */
202
+ prefixIcon?: Element
187
203
  /**
188
204
  * Makes the input read-only
189
205
  */