@instructure/ui-number-input 8.13.1-snapshot.9 → 8.14.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.
@@ -35,112 +35,27 @@ var _FormPropTypes = require("@instructure/ui-form-field/lib/FormPropTypes.js");
35
35
  * SOFTWARE.
36
36
  */
37
37
  const propTypes = {
38
- /**
39
- * The form field label.
40
- */
41
38
  renderLabel: _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.func]).isRequired,
42
-
43
- /**
44
- * The id of the input. One is generated if not supplied.
45
- */
46
39
  id: _propTypes.default.string,
47
-
48
- /**
49
- * Specifies if interaction with the input is enabled, disabled, or readonly.
50
- * When "disabled", the input changes visibly to indicate that it cannot
51
- * receive user interactions. When "readonly" the input still cannot receive
52
- * user interactions but it keeps the same styles as if it were enabled.
53
- */
54
40
  interaction: _propTypes.default.oneOf(['enabled', 'disabled', 'readonly']),
55
-
56
- /**
57
- * Object with shape: `{
58
- * text: PropTypes.node,
59
- * type: PropTypes.oneOf(['error', 'hint', 'success', 'screenreader-only'])
60
- * }`
61
- */
62
41
  messages: _propTypes.default.arrayOf(_FormPropTypes.FormPropTypes.message),
63
-
64
- /**
65
- * Html placeholder text to display when the input has no value. This
66
- * should be hint text, not a label replacement.
67
- */
68
42
  placeholder: _propTypes.default.string,
69
-
70
- /**
71
- * Whether or not the text input is required.
72
- */
73
43
  isRequired: _propTypes.default.bool,
74
-
75
- /**
76
- * Whether or not to display the up/down arrow buttons.
77
- */
78
44
  showArrows: _propTypes.default.bool,
79
-
80
- /**
81
- * The size of the input.
82
- */
83
45
  size: _propTypes.default.oneOf(['medium', 'large']),
84
-
85
- /**
86
- * The value of the input (should be accompanied by an `onChange` prop).
87
- */
88
46
  value: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
89
-
90
- /**
91
- * The width of the input.
92
- */
93
47
  width: _propTypes.default.string,
94
-
95
- /**
96
- * The display of the root element.
97
- */
98
48
  display: _propTypes.default.oneOf(['inline-block', 'block']),
99
-
100
- /**
101
- * A function that provides a reference to the actual input element.
102
- */
103
49
  inputRef: _propTypes.default.func,
104
-
105
- /**
106
- * Callback fired when input receives focus.
107
- */
108
50
  onFocus: _propTypes.default.func,
109
-
110
- /**
111
- * Callback fired when the input loses focus.
112
- */
113
51
  onBlur: _propTypes.default.func,
114
-
115
- /**
116
- * Callback executed when the input fires a change event.
117
- * @param {Object} event - the event object
118
- * @param {Object} value - the string value of the input
119
- */
120
52
  onChange: _propTypes.default.func,
121
-
122
- /**
123
- * Called when the down arrow button is clicked, or the down arrow key is
124
- * pressed.
125
- */
126
53
  onDecrement: _propTypes.default.func,
127
-
128
- /**
129
- * Called when the up arrow button is clicked, or the up arrow key is
130
- * pressed.
131
- */
132
54
  onIncrement: _propTypes.default.func,
133
-
134
- /**
135
- * Callback fired when a key is pressed.
136
- */
137
55
  onKeyDown: _propTypes.default.func,
138
-
139
- /**
140
- * The inputMode attribute of the underlying `input` element can be one of ['numeric', 'decimal', 'tel']
141
- */
142
- inputMode: _propTypes.default.oneOf(['numeric', 'decimal', 'tel'])
56
+ inputMode: _propTypes.default.oneOf(['numeric', 'decimal', 'tel']),
57
+ textAlign: _propTypes.default.oneOf(['start', 'center'])
143
58
  };
144
59
  exports.propTypes = propTypes;
145
- const allowedProps = ['renderLabel', 'id', 'interaction', 'messages', 'placeholder', 'isRequired', 'showArrows', 'size', 'value', 'width', 'display', 'inputRef', 'onFocus', 'onBlur', 'onChange', 'onDecrement', 'onIncrement', 'onKeyDown', 'inputMode'];
60
+ const allowedProps = ['renderLabel', 'id', 'interaction', 'messages', 'placeholder', 'isRequired', 'showArrows', 'size', 'value', 'width', 'display', 'inputRef', 'onFocus', 'onBlur', 'onChange', 'onDecrement', 'onIncrement', 'onKeyDown', 'inputMode', 'textAlign'];
146
61
  exports.allowedProps = allowedProps;
@@ -40,7 +40,8 @@ exports.default = void 0;
40
40
  * @return {Object} The final style object, which will be used in the component
41
41
  */
42
42
  const generateStyle = (componentTheme, props, state) => {
43
- const size = props.size;
43
+ const size = props.size,
44
+ textAlign = props.textAlign;
44
45
  const interaction = state.interaction,
45
46
  hasFocus = state.hasFocus,
46
47
  invalid = state.invalid;
@@ -141,7 +142,7 @@ const generateStyle = (componentTheme, props, state) => {
141
142
  input: {
142
143
  label: 'numberInput_input',
143
144
  all: 'initial',
144
- textAlign: 'start',
145
+ textAlign: textAlign,
145
146
  direction: 'inherit',
146
147
  WebkitFontSmoothing: 'antialiased',
147
148
  MozOsxFontSmoothing: 'grayscale',
@@ -157,6 +158,7 @@ const generateStyle = (componentTheme, props, state) => {
157
158
  color: componentTheme.color,
158
159
  background: componentTheme.background,
159
160
  padding: componentTheme.padding,
161
+ textyAlign: textAlign,
160
162
  '&::placeholder': {
161
163
  color: componentTheme.placeholderColor
162
164
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-number-input",
3
- "version": "8.13.1-snapshot.9+f32ba918e",
3
+ "version": "8.14.0",
4
4
  "description": "A UI component library made by Instructure Inc.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "homepage": "https://instructure.github.io/instructure-ui/",
@@ -24,21 +24,21 @@
24
24
  "ts:check": "tsc -p tsconfig.build.json --noEmit --emitDeclarationOnly false"
25
25
  },
26
26
  "devDependencies": {
27
- "@instructure/ui-babel-preset": "8.13.1-snapshot.9+f32ba918e",
28
- "@instructure/ui-test-locator": "8.13.1-snapshot.9+f32ba918e",
29
- "@instructure/ui-test-utils": "8.13.1-snapshot.9+f32ba918e",
30
- "@instructure/ui-themes": "8.13.1-snapshot.9+f32ba918e"
27
+ "@instructure/ui-babel-preset": "8.14.0",
28
+ "@instructure/ui-test-locator": "8.14.0",
29
+ "@instructure/ui-test-utils": "8.14.0",
30
+ "@instructure/ui-themes": "8.14.0"
31
31
  },
32
32
  "dependencies": {
33
33
  "@babel/runtime": "^7.13.10",
34
- "@instructure/emotion": "8.13.1-snapshot.9+f32ba918e",
35
- "@instructure/shared-types": "8.13.1-snapshot.9+f32ba918e",
36
- "@instructure/ui-form-field": "8.13.1-snapshot.9+f32ba918e",
37
- "@instructure/ui-icons": "8.13.1-snapshot.9+f32ba918e",
38
- "@instructure/ui-react-utils": "8.13.1-snapshot.9+f32ba918e",
39
- "@instructure/ui-testable": "8.13.1-snapshot.9+f32ba918e",
40
- "@instructure/ui-utils": "8.13.1-snapshot.9+f32ba918e",
41
- "@instructure/uid": "8.13.1-snapshot.9+f32ba918e",
34
+ "@instructure/emotion": "8.14.0",
35
+ "@instructure/shared-types": "8.14.0",
36
+ "@instructure/ui-form-field": "8.14.0",
37
+ "@instructure/ui-icons": "8.14.0",
38
+ "@instructure/ui-react-utils": "8.14.0",
39
+ "@instructure/ui-testable": "8.14.0",
40
+ "@instructure/ui-utils": "8.14.0",
41
+ "@instructure/uid": "8.14.0",
42
42
  "keycode": "^2",
43
43
  "prop-types": "^15"
44
44
  },
@@ -48,6 +48,5 @@
48
48
  "publishConfig": {
49
49
  "access": "public"
50
50
  },
51
- "sideEffects": false,
52
- "gitHead": "f32ba918e4d3ce76c6ee95c856584d00a9d80958"
51
+ "sideEffects": false
53
52
  }
@@ -21,8 +21,9 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
+
24
25
  /** @jsx jsx */
25
- import { Component } from 'react'
26
+ import React, { Component } from 'react'
26
27
  import keycode from 'keycode'
27
28
 
28
29
  import { FormField } from '@instructure/ui-form-field'
@@ -43,18 +44,20 @@ import { withStyle, jsx } from '@instructure/emotion'
43
44
 
44
45
  import generateStyle from './styles'
45
46
  import generateComponentTheme from './theme'
47
+
48
+ import { allowedProps, propTypes } from './props'
46
49
  import type {
47
50
  NumberInputProps,
48
51
  NumberInputState,
49
52
  NumberInputStyleProps
50
53
  } from './props'
51
- import { allowedProps, propTypes } from './props'
52
54
 
53
55
  /**
54
56
  ---
55
57
  category: components
56
58
  id: NumberInput
57
59
  ---
60
+ @tsProps
58
61
  **/
59
62
  @withStyle(generateStyle, generateComponentTheme)
60
63
  @testable()
@@ -63,36 +66,24 @@ class NumberInput extends Component<NumberInputProps, NumberInputState> {
63
66
  static allowedProps = allowedProps
64
67
  static propTypes = propTypes
65
68
  static defaultProps = {
66
- id: null,
67
69
  // Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
68
70
  interaction: undefined,
69
71
  messages: [],
70
- placeholder: null,
71
72
  isRequired: false,
72
73
  showArrows: true,
73
74
  size: 'medium',
74
75
  display: 'block',
75
- // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
76
- inputRef: (event) => {},
77
- // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
78
- onFocus: (event) => {},
79
- // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
80
- onBlur: (event) => {},
81
- // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
82
- onChange: (event, value) => {},
83
- // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
84
- onDecrement: (event) => {},
85
- // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
86
- onIncrement: (event) => {},
87
- // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
88
- onKeyDown: (event) => {},
76
+ textAlign: 'start',
89
77
  inputMode: 'numeric'
90
78
  }
91
79
 
92
80
  state: NumberInputState = { hasFocus: false }
93
- _input = null
81
+
94
82
  ref: Element | null = null
95
83
 
84
+ private _input: HTMLInputElement | null = null
85
+ private _id?: string
86
+
96
87
  handleRef = (el: Element | null) => {
97
88
  this.ref = el
98
89
  }
@@ -101,12 +92,9 @@ class NumberInput extends Component<NumberInputProps, NumberInputState> {
101
92
  if (this.props.id) {
102
93
  return this.props.id
103
94
  }
104
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_id' does not exist on type 'NumberInput... Remove this comment to see the full error message
105
95
  if (!this._id) {
106
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_id' does not exist on type 'NumberInput... Remove this comment to see the full error message
107
96
  this._id = uid('NumberInput')
108
97
  }
109
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_id' does not exist on type 'NumberInput... Remove this comment to see the full error message
110
98
  return this._id
111
99
  }
112
100
 
@@ -137,68 +125,77 @@ class NumberInput extends Component<NumberInputProps, NumberInputState> {
137
125
  }
138
126
  }
139
127
 
140
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'element' implicitly has an 'any' type.
141
- handleInputRef = (element) => {
128
+ handleInputRef = (element: HTMLInputElement | null) => {
142
129
  this._input = element
143
- // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
144
- this.props.inputRef(element)
130
+
131
+ if (typeof this.props.inputRef === 'function') {
132
+ this.props.inputRef(element)
133
+ }
145
134
  }
146
135
 
147
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'event' implicitly has an 'any' type.
148
- handleFocus = (event) => {
136
+ handleFocus = (event: React.FocusEvent<HTMLInputElement>) => {
149
137
  this.setState({ hasFocus: true })
150
- // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
151
- this.props.onFocus(event)
138
+
139
+ if (typeof this.props.onFocus === 'function') {
140
+ this.props.onFocus(event)
141
+ }
152
142
  }
153
143
 
154
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'event' implicitly has an 'any' type.
155
- handleBlur = (event) => {
144
+ handleBlur = (event: React.FocusEvent<HTMLInputElement>) => {
156
145
  this.setState({ hasFocus: false })
157
- // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
158
- this.props.onBlur(event)
146
+
147
+ if (typeof this.props.onBlur === 'function') {
148
+ this.props.onBlur(event)
149
+ }
159
150
  }
160
151
 
161
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'event' implicitly has an 'any' type.
162
- handleChange = (event) => {
163
- // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
164
- this.props.onChange(event, event.target.value)
152
+ handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
153
+ if (typeof this.props.onChange === 'function') {
154
+ this.props.onChange(event, event.target.value)
155
+ }
165
156
  }
166
157
 
167
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'event' implicitly has an 'any' type.
168
- handleKeyDown = (event) => {
169
- // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
170
- this.props.onKeyDown(event)
158
+ handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
159
+ const { onKeyDown, onDecrement, onIncrement } = this.props
160
+
161
+ if (typeof onKeyDown === 'function') {
162
+ onKeyDown(event)
163
+ }
171
164
 
172
165
  if (event.keyCode === keycode.codes.down) {
173
166
  event.preventDefault()
174
- // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
175
- this.props.onDecrement(event)
167
+ if (typeof onDecrement === 'function') {
168
+ onDecrement(event)
169
+ }
176
170
  } else if (event.keyCode === keycode.codes.up) {
177
171
  event.preventDefault()
178
- // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
179
- this.props.onIncrement(event)
172
+ if (typeof onIncrement === 'function') {
173
+ onIncrement(event)
174
+ }
180
175
  }
181
176
  }
182
177
 
183
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'event' implicitly has an 'any' type.
184
- handleClickUpArrow = (event) => {
178
+ handleClickUpArrow = (event: React.MouseEvent<HTMLButtonElement>) => {
185
179
  this.arrowClicked(event, this.props.onIncrement)
186
180
  }
187
181
 
188
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'event' implicitly has an 'any' type.
189
- handleClickDownArrow = (event) => {
182
+ handleClickDownArrow = (event: React.MouseEvent<HTMLButtonElement>) => {
190
183
  this.arrowClicked(event, this.props.onDecrement)
191
184
  }
192
185
 
193
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'event' implicitly has an 'any' type.
194
- arrowClicked(event, callback) {
186
+ arrowClicked(
187
+ event: React.MouseEvent<HTMLButtonElement>,
188
+ callback: NumberInputProps['onIncrement'] | NumberInputProps['onDecrement']
189
+ ) {
195
190
  const { interaction } = this
196
191
 
197
192
  event.preventDefault()
198
193
  if (interaction === 'enabled') {
199
- // @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
200
- this._input.focus()
201
- callback(event)
194
+ this._input?.focus()
195
+
196
+ if (typeof callback === 'function') {
197
+ callback(event)
198
+ }
202
199
  }
203
200
  }
204
201
 
@@ -209,8 +206,7 @@ class NumberInput extends Component<NumberInputProps, NumberInputState> {
209
206
  aria-hidden
210
207
  css={this.props.styles?.arrow}
211
208
  onMouseDown={this.handleClickUpArrow}
212
- // @ts-expect-error ts-migrate(2322) FIXME: Type 'string' is not assignable to type 'number | ... Remove this comment to see the full error message
213
- tabIndex="-1"
209
+ tabIndex={-1}
214
210
  type="button"
215
211
  >
216
212
  <IconArrowOpenUpLine />
@@ -219,8 +215,7 @@ class NumberInput extends Component<NumberInputProps, NumberInputState> {
219
215
  aria-hidden
220
216
  css={this.props.styles?.arrow}
221
217
  onMouseDown={this.handleClickDownArrow}
222
- // @ts-expect-error ts-migrate(2322) FIXME: Type 'string' is not assignable to type 'number | ... Remove this comment to see the full error message
223
- tabIndex="-1"
218
+ tabIndex={-1}
224
219
  type="button"
225
220
  >
226
221
  <IconArrowOpenDownLine />