@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.
@@ -21,6 +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
+
25
+ import React from 'react'
26
+ import type { InputHTMLAttributes } from 'react'
24
27
  import PropTypes from 'prop-types'
25
28
 
26
29
  import { FormPropTypes } from '@instructure/ui-form-field'
@@ -30,150 +33,184 @@ import type {
30
33
  NumberInputTheme,
31
34
  OtherHTMLAttributes
32
35
  } from '@instructure/shared-types'
33
- import type { FormMessage } from '@instructure/ui-form-field'
36
+ import type { FormFieldOwnProps, FormMessage } from '@instructure/ui-form-field'
34
37
  import type { InteractionType } from '@instructure/ui-react-utils'
35
38
  import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
36
- import { InputHTMLAttributes } from 'react'
37
39
 
38
40
  type NumberInputOwnProps = {
39
- renderLabel: React.ReactNode | ((...args: any[]) => any)
40
- id?: string
41
- interaction?: InteractionType
42
- messages?: FormMessage[]
43
- placeholder?: string
44
- isRequired?: boolean
45
- showArrows?: boolean
46
- size?: 'medium' | 'large'
47
- value?: string | number
48
- width?: string
49
- display?: 'inline-block' | 'block'
50
- inputRef?: (...args: any[]) => any
51
- onFocus?: (...args: any[]) => any
52
- onBlur?: (...args: any[]) => any
53
- onChange?: (...args: any[]) => any
54
- onDecrement?: (...args: any[]) => any
55
- onIncrement?: (...args: any[]) => any
56
- onKeyDown?: (...args: any[]) => any
57
- inputMode?: 'numeric' | 'decimal' | 'tel'
58
- }
59
-
60
- type NumberInputState = {
61
- hasFocus: boolean
62
- }
63
-
64
- type NumberInputStyleProps = NumberInputState & {
65
- interaction: InteractionType
66
- invalid: boolean
67
- }
68
-
69
- type PropKeys = keyof NumberInputOwnProps
70
-
71
- type AllowedPropKeys = Readonly<Array<PropKeys>>
72
-
73
- type NumberInputProps = NumberInputOwnProps &
74
- WithStyleProps<NumberInputTheme, NumberInputStyle> &
75
- OtherHTMLAttributes<
76
- NumberInputOwnProps,
77
- InputHTMLAttributes<NumberInputOwnProps>
78
- >
79
-
80
- type NumberInputStyle = ComponentStyle<
81
- | 'numberInput'
82
- | 'arrowContainer'
83
- | 'arrow'
84
- | 'inputWidth'
85
- | 'inputContainer'
86
- | 'input'
87
- >
88
-
89
- const propTypes: PropValidators<PropKeys> = {
90
41
  /**
91
42
  * The form field label.
92
43
  */
93
- renderLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired,
44
+ renderLabel: React.ReactNode | (() => React.ReactNode)
45
+
94
46
  /**
95
47
  * The id of the input. One is generated if not supplied.
96
48
  */
97
- id: PropTypes.string,
49
+ id?: string
50
+
98
51
  /**
99
52
  * Specifies if interaction with the input is enabled, disabled, or readonly.
100
53
  * When "disabled", the input changes visibly to indicate that it cannot
101
54
  * receive user interactions. When "readonly" the input still cannot receive
102
55
  * user interactions but it keeps the same styles as if it were enabled.
103
56
  */
104
- interaction: PropTypes.oneOf(['enabled', 'disabled', 'readonly']),
57
+ interaction?: InteractionType
58
+
105
59
  /**
106
- * Object with shape: `{
107
- * text: PropTypes.node,
108
- * type: PropTypes.oneOf(['error', 'hint', 'success', 'screenreader-only'])
60
+ * Array of objects with shape: `{
61
+ * text: ReactNode,
62
+ * type: One of: ['error', 'hint', 'success', 'screenreader-only']
109
63
  * }`
110
64
  */
111
- messages: PropTypes.arrayOf(FormPropTypes.message),
65
+ messages?: FormMessage[]
66
+
112
67
  /**
113
68
  * Html placeholder text to display when the input has no value. This
114
69
  * should be hint text, not a label replacement.
115
70
  */
116
- placeholder: PropTypes.string,
71
+ placeholder?: string
72
+
117
73
  /**
118
74
  * Whether or not the text input is required.
119
75
  */
120
- isRequired: PropTypes.bool,
76
+ isRequired?: boolean
77
+
121
78
  /**
122
79
  * Whether or not to display the up/down arrow buttons.
123
80
  */
124
- showArrows: PropTypes.bool,
81
+ showArrows?: boolean
82
+
125
83
  /**
126
84
  * The size of the input.
127
85
  */
128
- size: PropTypes.oneOf(['medium', 'large']),
86
+ size?: 'medium' | 'large'
87
+
129
88
  /**
130
89
  * The value of the input (should be accompanied by an `onChange` prop).
131
90
  */
132
- value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
91
+ value?: string | number
92
+
133
93
  /**
134
94
  * The width of the input.
135
95
  */
136
- width: PropTypes.string,
96
+ width?: string
97
+
137
98
  /**
138
99
  * The display of the root element.
139
100
  */
140
- display: PropTypes.oneOf(['inline-block', 'block']),
101
+ display?: 'inline-block' | 'block'
102
+
141
103
  /**
142
104
  * A function that provides a reference to the actual input element.
143
105
  */
144
- inputRef: PropTypes.func,
106
+ inputRef?: (element: HTMLInputElement | null) => void
107
+
145
108
  /**
146
109
  * Callback fired when input receives focus.
147
110
  */
148
- onFocus: PropTypes.func,
111
+ onFocus?: (event: React.FocusEvent<HTMLInputElement>) => void
112
+
149
113
  /**
150
114
  * Callback fired when the input loses focus.
151
115
  */
152
- onBlur: PropTypes.func,
116
+ onBlur?: (event: React.FocusEvent<HTMLInputElement>) => void
117
+
153
118
  /**
154
119
  * Callback executed when the input fires a change event.
155
120
  * @param {Object} event - the event object
156
- * @param {Object} value - the string value of the input
121
+ * @param {string} value - the string value of the input
157
122
  */
158
- onChange: PropTypes.func,
123
+ onChange?: (event: React.ChangeEvent<HTMLInputElement>, value: string) => void
124
+
159
125
  /**
160
126
  * Called when the down arrow button is clicked, or the down arrow key is
161
127
  * pressed.
162
128
  */
163
- onDecrement: PropTypes.func,
129
+ onDecrement?: (
130
+ event:
131
+ | React.KeyboardEvent<HTMLInputElement>
132
+ | React.MouseEvent<HTMLButtonElement>
133
+ ) => void
134
+
164
135
  /**
165
136
  * Called when the up arrow button is clicked, or the up arrow key is
166
137
  * pressed.
167
138
  */
168
- onIncrement: PropTypes.func,
139
+ onIncrement?: (
140
+ event:
141
+ | React.KeyboardEvent<HTMLInputElement>
142
+ | React.MouseEvent<HTMLButtonElement>
143
+ ) => void
144
+
169
145
  /**
170
146
  * Callback fired when a key is pressed.
171
147
  */
172
- onKeyDown: PropTypes.func,
148
+ onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => void
149
+
173
150
  /**
174
151
  * The inputMode attribute of the underlying `input` element can be one of ['numeric', 'decimal', 'tel']
175
152
  */
176
- inputMode: PropTypes.oneOf(['numeric', 'decimal', 'tel'])
153
+ inputMode?: 'numeric' | 'decimal' | 'tel'
154
+
155
+ /**
156
+ * The text alignment of the input.
157
+ */
158
+ textAlign?: 'start' | 'center'
159
+ }
160
+
161
+ type NumberInputState = {
162
+ hasFocus: boolean
163
+ }
164
+
165
+ type NumberInputStyleProps = NumberInputState & {
166
+ interaction: InteractionType
167
+ invalid: boolean
168
+ }
169
+
170
+ type PropKeys = keyof NumberInputOwnProps
171
+
172
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
173
+
174
+ type NumberInputProps =
175
+ // pickProps passes through FormField.allowedProps, except the ones set manually
176
+ Omit<FormFieldOwnProps, 'label' | 'inline' | 'id' | 'elementRef'> &
177
+ NumberInputOwnProps &
178
+ WithStyleProps<NumberInputTheme, NumberInputStyle> &
179
+ OtherHTMLAttributes<
180
+ NumberInputOwnProps,
181
+ InputHTMLAttributes<NumberInputOwnProps>
182
+ >
183
+
184
+ type NumberInputStyle = ComponentStyle<
185
+ | 'numberInput'
186
+ | 'arrowContainer'
187
+ | 'arrow'
188
+ | 'inputWidth'
189
+ | 'inputContainer'
190
+ | 'input'
191
+ >
192
+
193
+ const propTypes: PropValidators<PropKeys> = {
194
+ renderLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired,
195
+ id: PropTypes.string,
196
+ interaction: PropTypes.oneOf(['enabled', 'disabled', 'readonly']),
197
+ messages: PropTypes.arrayOf(FormPropTypes.message),
198
+ placeholder: PropTypes.string,
199
+ isRequired: PropTypes.bool,
200
+ showArrows: PropTypes.bool,
201
+ size: PropTypes.oneOf(['medium', 'large']),
202
+ value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
203
+ width: PropTypes.string,
204
+ display: PropTypes.oneOf(['inline-block', 'block']),
205
+ inputRef: PropTypes.func,
206
+ onFocus: PropTypes.func,
207
+ onBlur: PropTypes.func,
208
+ onChange: PropTypes.func,
209
+ onDecrement: PropTypes.func,
210
+ onIncrement: PropTypes.func,
211
+ onKeyDown: PropTypes.func,
212
+ inputMode: PropTypes.oneOf(['numeric', 'decimal', 'tel']),
213
+ textAlign: PropTypes.oneOf(['start', 'center'])
177
214
  }
178
215
 
179
216
  const allowedProps: AllowedPropKeys = [
@@ -195,7 +232,8 @@ const allowedProps: AllowedPropKeys = [
195
232
  'onDecrement',
196
233
  'onIncrement',
197
234
  'onKeyDown',
198
- 'inputMode'
235
+ 'inputMode',
236
+ 'textAlign'
199
237
  ]
200
238
 
201
239
  export type {
@@ -44,7 +44,7 @@ const generateStyle = (
44
44
  props: NumberInputProps,
45
45
  state: NumberInputStyleProps
46
46
  ): NumberInputStyle => {
47
- const { size } = props
47
+ const { size, textAlign } = props
48
48
  const { interaction, hasFocus, invalid } = state
49
49
 
50
50
  const disabledStyles =
@@ -153,7 +153,7 @@ const generateStyle = (
153
153
  input: {
154
154
  label: 'numberInput_input',
155
155
  all: 'initial',
156
- textAlign: 'start',
156
+ textAlign: textAlign,
157
157
  direction: 'inherit',
158
158
  WebkitFontSmoothing: 'antialiased',
159
159
  MozOsxFontSmoothing: 'grayscale',
@@ -169,6 +169,7 @@ const generateStyle = (
169
169
  color: componentTheme.color,
170
170
  background: componentTheme.background,
171
171
  padding: componentTheme.padding,
172
+ textyAlign: textAlign,
172
173
  '&::placeholder': { color: componentTheme.placeholderColor }
173
174
  }
174
175
  }
@@ -1,7 +1,23 @@
1
1
  {
2
2
  "extends": "../../tsconfig.build.json",
3
3
  "compilerOptions": {
4
- "outDir": "./types"
4
+ "outDir": "./types",
5
+ "rootDir": "./src",
6
+ "composite": true
5
7
  },
6
- "include": ["src/**/*"]
8
+ "include": ["src"],
9
+ "references": [
10
+ { "path": "../ui-babel-preset/tsconfig.build.json" },
11
+ { "path": "../ui-test-locator/tsconfig.build.json" },
12
+ { "path": "../ui-test-utils/tsconfig.build.json" },
13
+ { "path": "../ui-themes/tsconfig.build.json" },
14
+ { "path": "../emotion/tsconfig.build.json" },
15
+ { "path": "../shared-types/tsconfig.build.json" },
16
+ { "path": "../ui-form-field/tsconfig.build.json" },
17
+ { "path": "../ui-icons/tsconfig.build.json" },
18
+ { "path": "../ui-react-utils/tsconfig.build.json" },
19
+ { "path": "../ui-testable/tsconfig.build.json" },
20
+ { "path": "../ui-utils/tsconfig.build.json" },
21
+ { "path": "../uid/tsconfig.build.json" }
22
+ ]
7
23
  }