@instructure/ui-number-input 8.13.1-snapshot.9 → 8.14.1-snapshot.6

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