@planningcenter/tapestry-react 2.9.2 → 2.10.0-rc.1

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.
Files changed (64) hide show
  1. package/dist/cjs/Badge/Badge.js +19 -7
  2. package/dist/cjs/Badge/Status.js +52 -77
  3. package/dist/cjs/Button/Button.js +1 -1
  4. package/dist/cjs/Calendar/Day.js +5 -2
  5. package/dist/cjs/Combobox/ComboboxPopover.js +20 -6
  6. package/dist/cjs/Input/Inline.js +1 -1
  7. package/dist/cjs/Input/InputBox.js +1 -1
  8. package/dist/cjs/Menu/Item.js +47 -25
  9. package/dist/cjs/Modal/Modal.js +4 -3
  10. package/dist/cjs/NumberField/NumberField.js +112 -31
  11. package/dist/cjs/NumberField/NumberField.test.js +8 -2
  12. package/dist/cjs/Portal/Portal.js +2 -1
  13. package/dist/cjs/Progress/Progress.js +2 -2
  14. package/dist/cjs/Radio/Radio.js +12 -8
  15. package/dist/cjs/Toolbar/Toolbar.js +1 -0
  16. package/dist/cjs/Tooltip/Tooltip.js +4 -2
  17. package/dist/cjs/Wizard/Wizard.js +4 -4
  18. package/dist/cjs/system/utils.js +2 -0
  19. package/dist/esm/Badge/Badge.js +19 -7
  20. package/dist/esm/Badge/Status.js +52 -77
  21. package/dist/esm/Button/Button.js +1 -1
  22. package/dist/esm/Calendar/Day.js +5 -2
  23. package/dist/esm/Combobox/ComboboxPopover.js +20 -6
  24. package/dist/esm/Input/Inline.js +1 -1
  25. package/dist/esm/Input/InputBox.js +1 -1
  26. package/dist/esm/Menu/Item.js +47 -25
  27. package/dist/esm/Modal/Modal.js +4 -3
  28. package/dist/esm/NumberField/NumberField.js +112 -32
  29. package/dist/esm/NumberField/NumberField.test.js +8 -2
  30. package/dist/esm/Portal/Portal.js +2 -1
  31. package/dist/esm/Progress/Progress.js +2 -2
  32. package/dist/esm/Radio/Radio.js +12 -8
  33. package/dist/esm/Toolbar/Toolbar.js +2 -1
  34. package/dist/esm/Tooltip/Tooltip.js +4 -2
  35. package/dist/esm/Wizard/Wizard.js +4 -4
  36. package/dist/esm/system/utils.js +2 -0
  37. package/dist/types/Badge/Status.d.ts +27 -0
  38. package/dist/types/Button/Button.d.ts +4 -2
  39. package/dist/types/Modal/Modal.d.ts +23 -0
  40. package/dist/types/NumberField/NumberField.d.ts +89 -0
  41. package/dist/types/Progress/Progress.d.ts +12 -0
  42. package/dist/types/Radio/Radio.d.ts +44 -0
  43. package/dist/types/Wizard/Wizard.d.ts +63 -0
  44. package/package.json +3 -1
  45. package/src/Badge/Badge.js +8 -0
  46. package/src/Badge/Status.tsx +90 -0
  47. package/src/Button/Button.tsx +2 -2
  48. package/src/Calendar/Day.js +11 -0
  49. package/src/Combobox/ComboboxPopover.js +30 -0
  50. package/src/Input/Inline.js +1 -1
  51. package/src/Input/InputBox.js +1 -1
  52. package/src/Menu/Item.js +15 -0
  53. package/src/Modal/{Modal.js → Modal.tsx} +8 -9
  54. package/src/NumberField/NumberField.mdx +13 -0
  55. package/src/NumberField/NumberField.test.tsx +38 -11
  56. package/src/NumberField/{NumberField.js → NumberField.tsx} +124 -48
  57. package/src/Portal/Portal.tsx +1 -0
  58. package/src/Progress/{Progress.js → Progress.tsx} +3 -4
  59. package/src/Radio/{Radio.js → Radio.tsx} +21 -15
  60. package/src/Toolbar/Toolbar.js +1 -0
  61. package/src/Tooltip/Tooltip.js +8 -1
  62. package/src/Wizard/{Wizard.js → Wizard.tsx} +42 -35
  63. package/src/system/utils.js +2 -0
  64. package/src/Badge/Status.js +0 -101
package/src/Menu/Item.js CHANGED
@@ -38,10 +38,12 @@ function Item({
38
38
  }
39
39
 
40
40
  if (renderLeft) {
41
+ // @ts-ignore error TS2339: Property 'paddingLeft' does not exist on type
41
42
  css.paddingLeft = 5
42
43
  }
43
44
 
44
45
  if (renderRight) {
46
+ // @ts-ignore error TS2339: Property 'paddingRight' does not exist on type
45
47
  css.paddingRight = 5
46
48
  }
47
49
 
@@ -50,18 +52,26 @@ function Item({
50
52
  }
51
53
 
52
54
  if (disabled) {
55
+ // @ts-ignore error TS2339: Property 'cursor' does not exist on type ...
53
56
  css.cursor = 'not-allowed'
57
+ // @ts-ignore error TS2339: Property 'opacity' does not exist on type ...
54
58
  css.opacity = 0.65
55
59
  } else if (
60
+ // @ts-ignore error TS2339: Property 'onClick' does not exist on type '{}'.
56
61
  props.onClick ||
62
+ // @ts-ignore error TS2339: Property 'onDoubleClick' does not exist on type '{}'.
57
63
  props.onDoubleClick ||
64
+ // @ts-ignore error TS2339: Property 'onMouseDown' does not exist on type '{}'.
58
65
  props.onMouseDown ||
66
+ // @ts-ignore error TS2339: Property 'onMouseUp' does not exist on type '{}'.
59
67
  props.onMouseUp
60
68
  ) {
69
+ // @ts-ignore error TS2339: Property 'cursor' does not exist on type ...
61
70
  css.cursor = 'pointer'
62
71
  }
63
72
 
64
73
  return (
74
+ // @ts-ignore error TS2322: Type '{ ... }' is not assignable to type ...
65
75
  <StackView {...css} {...props}>
66
76
  {renderLeft && (
67
77
  <Box
@@ -75,8 +85,11 @@ function Item({
75
85
  left={0.5}
76
86
  >
77
87
  {typeof renderLeft === 'function'
88
+ // @ts-ignore error TS2349: This expression is not callable.
78
89
  ? renderRight()
90
+ // @ts-ignore error TS2769: No overload matches this call.
79
91
  : cloneElement(renderLeft, {
92
+ // @ts-ignore error TS2339: Property 'props' does not exist on type ...
80
93
  size: (renderLeft.props && renderLeft.props.size) || 'md',
81
94
  })}
82
95
  </Box>
@@ -97,7 +110,9 @@ function Item({
97
110
  >
98
111
  {typeof renderRight === 'function'
99
112
  ? renderRight()
113
+ // @ts-ignore error TS2769: No overload matches this call.
100
114
  : cloneElement(renderRight, {
115
+ // @ts-ignore error TS2339: Property 'props' does not exist on type ...
101
116
  size: (renderRight.props && renderRight.props.size) || 'md',
102
117
  })}
103
118
  </Box>
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import React, { useLayoutEffect, useRef } from 'react'
3
2
 
4
3
  import Box from '../Box'
@@ -8,36 +7,36 @@ import { trapFocus } from '../utils'
8
7
  import { useThemeProps } from '../system'
9
8
 
10
9
  export type ModalProps = {
11
- children?: any,
10
+ children?: React.ReactNode
12
11
  /**
13
12
  * Close the modal when clicking outside of it.
14
13
  */
15
- closeOnOutsideClick: boolean,
14
+ closeOnOutsideClick?: boolean
16
15
 
17
16
  /**
18
17
  * Called by either clicking on the internal [`<Scrim/>`](/scrim) component or
19
18
  * by pressing the `Escape` key.
20
19
  */
21
- onRequestClose: () => null,
20
+ onRequestClose?: () => null
22
21
 
23
22
  /**
24
23
  * Determines whether the modal is open or not.
25
24
  */
26
- open: boolean,
25
+ open: boolean
27
26
 
28
27
  /**
29
28
  * Props passed to the internal [`<Scrim/>`](/scrim) component.
30
29
  */
31
- scrimProps?: object,
30
+ scrimProps?: Record<string, any>
32
31
  }
33
32
 
34
- function Modal({
33
+ const Modal = ({
35
34
  children,
36
- closeOnOutsideClick,
35
+ closeOnOutsideClick = false,
37
36
  onRequestClose,
38
37
  open,
39
38
  ...restProps
40
- }: ModalProps) {
39
+ }: ModalProps): JSX.Element => {
41
40
  const { scrimProps = {}, ...themeProps } = useThemeProps('modal', restProps)
42
41
  const modalRef = useRef(null)
43
42
 
@@ -15,6 +15,19 @@ render(() => {
15
15
  })
16
16
  ```
17
17
 
18
+ ### With Controls
19
+ ```jsx live
20
+ render(() => {
21
+ const [value, setValue] = React.useState(0)
22
+ return (
23
+ <Input.InputBox>
24
+ <NumberField value={value} onChange={(value) => setValue(value)} hasControls={true} />
25
+ </Input.InputBox>
26
+ )
27
+ })
28
+ ```
29
+
30
+ ### Inline
18
31
  ```jsx live
19
32
  render(() => {
20
33
  const [month, setMonth] = React.useState(4)
@@ -7,10 +7,23 @@ import NumberField from './NumberField'
7
7
  describe('value', () => {
8
8
  const TestApp = ({ value: initialValue, ...props }) => {
9
9
  const [value, setValue] = useState(initialValue)
10
- return <NumberField {...props } data-testid="test" value={value} onChange={setValue}/>
10
+ return (
11
+ <NumberField
12
+ {...props}
13
+ data-testid="test"
14
+ value={value}
15
+ // @ts-ignore No overload matches this call.
16
+ // Overload 1 of 2, '(props: Props | Readonly<Props>): NumberField', gave the following error.
17
+ // Type 'Dispatch<any>' is not assignable to type '(value: string) => null'.
18
+ // Type 'void' is not assignable to type 'null'.
19
+ // Overload 2 of 2, '(props: Props, context: any): NumberField', gave the following error.
20
+ // Type 'Dispatch<any>' is not assignable to type '(value: string) => null'.ts(2769)
21
+ onChange={setValue}
22
+ />
23
+ )
11
24
  }
12
- const setup = props => {
13
- const { getByTestId } = render(<TestApp {...props}/>)
25
+ const setup = (props) => {
26
+ const { getByTestId } = render(<TestApp {...props} />)
14
27
  return getByTestId('test')
15
28
  }
16
29
 
@@ -61,7 +74,7 @@ describe('value', () => {
61
74
  })
62
75
 
63
76
  describe('pad', () => {
64
- it("add appropriate pad", () => {
77
+ it('add appropriate pad', () => {
65
78
  const numberField = setup({ value: 0, pad: 2 })
66
79
  userEvent.type(numberField, '12{backspace}')
67
80
  expect(numberField).toHaveValue('01')
@@ -70,13 +83,20 @@ describe('value', () => {
70
83
  })
71
84
 
72
85
  describe('moveFocusOnMax', () => {
73
- const TestApp = props => {
86
+ const TestApp = (props) => {
74
87
  const [value, setValue] = useState(0)
75
88
 
76
- return <>
77
- <NumberField {...props } data-testid="test-a" value={value} onChange={setValue}/>
78
- <input data-testid="test-b"/>
79
- </>
89
+ return (
90
+ <>
91
+ <NumberField
92
+ {...props}
93
+ data-testid="test-a"
94
+ value={value}
95
+ onChange={setValue}
96
+ />
97
+ <input data-testid="test-b" />
98
+ </>
99
+ )
80
100
  }
81
101
 
82
102
  const setup = () => {
@@ -103,10 +123,17 @@ describe('moveFocusOnMax', () => {
103
123
  })
104
124
 
105
125
  describe('ignoredKeys', () => {
106
- const TestApp = props => {
126
+ const TestApp = (props) => {
107
127
  const [value, setValue] = useState(1)
108
128
 
109
- return <NumberField {...props } data-testid="test" value={value} onChange={setValue}/>
129
+ return (
130
+ <NumberField
131
+ {...props}
132
+ data-testid="test"
133
+ value={value}
134
+ onChange={setValue}
135
+ />
136
+ )
110
137
  }
111
138
 
112
139
  const setup = () => {
@@ -1,29 +1,35 @@
1
- // @flow
2
- import { createElement, Component } from 'react'
1
+ import React, { createElement, Component } from 'react'
3
2
 
4
3
  import InputField from '../Input/InputField'
4
+ import StackView from '../StackView'
5
+ import Button from '../Button'
5
6
  import { padNumber, getTabbableSiblings } from '../utils'
6
7
 
7
8
  type Props = {
8
9
  /**
9
10
  * Render custom component or HTML element tag. (Defaults to a [InputField](/input.inputfield) component.). */
10
- as?: any,
11
+ as?: any
12
+
13
+ /**
14
+ * Add controls to increment/decrement the value
15
+ */
16
+ hasControls?: boolean
11
17
 
12
18
  /**
13
19
  * An array of keys to ignore when pushed.
14
20
  * ex: ["ArrowUp", "ArrowDown"].
15
21
  */
16
- ignoredKeys: string[],
22
+ ignoredKeys: string[]
17
23
 
18
24
  /**
19
25
  * Maximum number that can be entered.
20
26
  */
21
- max: number,
27
+ max: number
22
28
 
23
29
  /**
24
30
  * Minimum number that can be entered.
25
31
  */
26
- min: number,
32
+ min: number
27
33
 
28
34
  /**
29
35
  * Called when the input's onInput is called with a valid value
@@ -31,43 +37,43 @@ type Props = {
31
37
  * Please note traditional onInput/onChange events are not supported
32
38
  * since this component takes control of them.
33
39
  */
34
- onChange: (value: string) => null,
40
+ onChange: (value: string) => null
35
41
 
36
42
  /**
37
43
  * Maps to the input's `onBlur` prop.
38
44
  */
39
- onBlur?: () => null,
45
+ onBlur?: () => null
40
46
 
41
- onKeyDown?: Function,
47
+ onKeyDown?: Function
42
48
 
43
49
  /**
44
50
  * The amount of 0s to pad the value with.
45
51
  */
46
- pad: number,
52
+ pad: number
47
53
 
48
54
  /**
49
55
  * Forces the input text to stay fully selected while interacting with it.
50
56
  */
51
- highlightOnInteraction: boolean,
57
+ highlightOnInteraction: boolean
52
58
 
53
59
  /**
54
60
  * String to display when value is empty.
55
61
  */
56
- placeholder: string,
62
+ placeholder: string
57
63
 
58
64
  /**
59
65
  * The amount to step up/down from the value when using the arrow keys
60
66
  * defaults to `1`
61
67
  */
62
- step: number,
68
+ step: number
63
69
 
64
70
  /**
65
71
  * The value of the input.
66
72
  */
67
- value: number,
73
+ value: number
68
74
 
69
- autoWidth: boolean,
70
- moveFocusOnMax: boolean,
75
+ autoWidth: boolean
76
+ moveFocusOnMax: boolean
71
77
  }
72
78
 
73
79
  const MIN_VALUE = -Infinity
@@ -105,6 +111,7 @@ function isNotAcceptedNumberKey(event) {
105
111
  class NumberField extends Component<Props> {
106
112
  static defaultProps = {
107
113
  as: InputField,
114
+ hasControls: false,
108
115
  ignoredKeys: [],
109
116
  min: MIN_VALUE,
110
117
  max: MAX_VALUE,
@@ -117,7 +124,9 @@ class NumberField extends Component<Props> {
117
124
  getParsedValues = (value) => {
118
125
  return {
119
126
  value: Number.parseFloat(value),
127
+ // @ts-ignore Argument of type 'number' is not assignable to parameter of type 'string'.ts(2345)
120
128
  minValue: Number.parseFloat(this.props.min),
129
+ // @ts-ignore Argument of type 'number' is not assignable to parameter of type 'string'.ts(2345)
121
130
  maxValue: Number.parseFloat(this.props.max),
122
131
  }
123
132
  }
@@ -143,41 +152,54 @@ class NumberField extends Component<Props> {
143
152
  event.target.value
144
153
  )
145
154
  if (value < minValue) {
155
+ // @ts-ignore Argument of type 'number' is not assignable to parameter of type 'string'.ts(2345)
146
156
  this.props.onChange(minValue)
147
157
  } else if (value > maxValue) {
158
+ // @ts-ignore Argument of type 'number' is not assignable to parameter of type 'string'.ts(2345)
148
159
  this.props.onChange(maxValue)
149
160
  } else if (isNaN(event.target.value)) {
161
+ // @ts-ignore Argument of type 'number' is not assignable to parameter of type 'string'.ts(2345)
150
162
  this.props.onChange(this.clampValue(value))
151
163
  }
152
164
  if (this.props.onBlur) {
165
+ // @ts-ignore
153
166
  this.props.onBlur(event)
154
167
  }
155
168
  this.firstTouch = true
156
169
  }
157
170
 
171
+ stepValue = (baseValue, step) => {
172
+ const nextValue = this.clampValue(baseValue + step)
173
+ const parsedValue = Number.parseFloat(
174
+ // @ts-ignore Expected 1 arguments, but got 2.ts(2554)
175
+ baseValue.toString().indexOf('.') > -1 ? nextValue.toFixed(2) : nextValue
176
+ )
177
+ if (this.isValueValid(parsedValue)) {
178
+ // @ts-ignore Argument of type 'number' is not assignable to parameter of type 'string'.ts(2345)
179
+ this.props.onChange(parsedValue)
180
+ }
181
+ }
182
+
183
+ incrementValue = () => this.stepValue(this.props.value, this.props.step)
184
+
185
+ decrementValue = () => this.stepValue(this.props.value, -this.props.step)
186
+
158
187
  handleKeyDown = (event) => {
159
188
  if (this.props.ignoredKeys.includes(event.key)) {
160
189
  return
161
190
  }
162
191
  const { pad, step } = this.props
163
- const { value, minValue, maxValue } = this.getParsedValues(
164
- event.target.value
165
- )
192
+ const { value } = this.getParsedValues(event.target.value)
166
193
  if (
167
194
  isNotAcceptedNumberKey(event) ||
168
195
  (pad && (event.key === 'ArrowLeft' || event.key === 'ArrowRight'))
169
196
  ) {
170
197
  event.preventDefault()
171
198
  }
172
- if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {
173
- const increment = (event.key === 'ArrowUp' ? 1 : -1) * step
174
- const nextValue = this.clampValue(value + increment)
175
- const parsedValue = Number.parseFloat(
176
- event.target.value.indexOf('.') > -1 ? nextValue.toFixed(2) : nextValue
177
- )
178
- if (this.isValueValid(parsedValue)) {
179
- this.props.onChange(parsedValue)
180
- }
199
+ if (event.key === 'ArrowUp') {
200
+ this.incrementValue()
201
+ } else if (event.key === 'ArrowDown') {
202
+ this.decrementValue()
181
203
  }
182
204
  if (this.props.onKeyDown) {
183
205
  this.props.onKeyDown(event)
@@ -234,40 +256,32 @@ class NumberField extends Component<Props> {
234
256
  )
235
257
  }
236
258
 
237
- render() {
238
- const {
239
- autoWidth,
240
- as,
241
- highlightOnInteraction,
242
- ignoredKeys,
243
- min,
244
- max,
245
- moveFocusOnMax,
246
- onChange,
247
- onBlur,
248
- onInput,
249
- onKeyDown,
250
- pad,
251
- value,
252
- ...restProps
253
- } = this.props
259
+ renderInput(restProps) {
260
+ const { as, highlightOnInteraction, pad, value } = this.props
254
261
  const parsed = this.getParsedValues(value)
255
262
  let numberValue = value === null ? '' : value
263
+
256
264
  if (pad && numberValue !== '') {
257
265
  numberValue = padNumber(numberValue, pad)
258
266
  }
267
+
268
+ // @ts-ignore Property 'min' does not exist on type '{ value: number; minValue: number; maxValue: number; }'.ts(2339)
259
269
  if (parsed.min !== MIN_VALUE) {
260
- restProps.min = min
270
+ restProps.min = this.props.min
261
271
  }
272
+
273
+ // @ts-ignore Property 'max' does not exist on type '{ value: number; minValue: number; maxValue: number; }'.ts(2339)
262
274
  if (parsed.max !== MAX_VALUE) {
263
- restProps.max = max
275
+ restProps.max = this.props.max
264
276
  }
265
- if (autoWidth !== false) {
277
+
278
+ if (this.props.autoWidth !== false) {
266
279
  restProps.autoWidth = this.getAutoWidthValue(numberValue)
267
280
  if (restProps.autoWidth === undefined) {
268
281
  restProps.autoWidth = true
269
282
  }
270
283
  }
284
+
271
285
  return createElement(as, {
272
286
  ...restProps,
273
287
  textOverflow: undefined,
@@ -279,6 +293,68 @@ class NumberField extends Component<Props> {
279
293
  onKeyDown: this.handleKeyDown,
280
294
  })
281
295
  }
296
+
297
+ renderInputWithControls(restProps) {
298
+ const inputElement = this.renderInput(restProps)
299
+
300
+ if (this.props.hasControls) {
301
+ return (
302
+ <>
303
+ {inputElement}
304
+ <StackView marginRight={-1} marginLeft={1}>
305
+ <Button
306
+ icon={{ name: 'general.upCaret' }}
307
+ hover={{ backgroundColor: 'grey-1' }}
308
+ minHeight={1}
309
+ onClick={() => this.incrementValue()}
310
+ paddingVertical={0.25}
311
+ // @ts-ignore Type 'string' is not assignable to type 'never'.ts(2322)
312
+ size="xs"
313
+ title={`Increment by 1`}
314
+ theme="naked"
315
+ />
316
+ <Button
317
+ icon={{ name: 'general.downCaret' }}
318
+ hover={{ backgroundColor: 'grey-1' }}
319
+ minHeight={1}
320
+ onClick={() => this.decrementValue()}
321
+ paddingVertical={0.25}
322
+ // @ts-ignore Type 'string' is not assignable to type 'never'.ts(2322)
323
+ size="xs"
324
+ title={`Decrement by 1`}
325
+ theme="naked"
326
+ />
327
+ </StackView>
328
+ </>
329
+ )
330
+ }
331
+ return inputElement
332
+ }
333
+
334
+ render() {
335
+ const {
336
+ autoWidth,
337
+ as,
338
+ hasControls,
339
+ highlightOnInteraction,
340
+ ignoredKeys,
341
+ min,
342
+ max,
343
+ moveFocusOnMax,
344
+ onChange,
345
+ onBlur,
346
+ // @ts-ignore Property 'onInput' does not exist on type 'Readonly<Props>'.ts(2339)
347
+ onInput,
348
+ onKeyDown,
349
+ pad,
350
+ value,
351
+ ...restProps
352
+ } = this.props
353
+
354
+ return this.props.hasControls
355
+ ? this.renderInputWithControls(restProps)
356
+ : this.renderInput(restProps)
357
+ }
282
358
  }
283
359
 
284
360
  export default NumberField
@@ -31,6 +31,7 @@ class Portal extends React.Component<PortalProps> {
31
31
  }
32
32
 
33
33
  static contextType = ThemeContext
34
+ // @ts-ignore error TS2612: Property 'context' will overwrite the base property in 'Component<PortalProps, {}, any>'. If this is intentional, add an initializer. Otherwise, add a 'declare' modifier or remove the redundant declaration.
34
35
  context: React.ContextType<React.Context<Theme>>
35
36
 
36
37
  _portalNode: HTMLElement = null
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import React from 'react'
3
2
 
4
3
  import Box from '../Box'
@@ -8,14 +7,14 @@ export type Props = {
8
7
  /**
9
8
  * The current value of the progress bar.
10
9
  */
11
- value?: number,
10
+ value?: number
12
11
  /**
13
12
  * Active color of the progress bar.
14
13
  */
15
- activeColor?: string,
14
+ activeColor?: string
16
15
  }
17
16
 
18
- function Progress({ value, ...restProps }: Props) {
17
+ const Progress = ({ value, ...restProps }: Props): JSX.Element => {
19
18
  const { activeColor = 'primary', ...themeProps } = useThemeProps(
20
19
  'progress',
21
20
  restProps
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import React, { useEffect, useState, useRef } from 'react'
3
2
  import mitt from 'mitt'
4
3
 
@@ -14,60 +13,62 @@ const iconPaths = {
14
13
  checked: 'tapestry.radio1',
15
14
  }
16
15
 
17
- export type Props = {
16
+ export type RadioProps = {
18
17
  /**
19
18
  * Disables the radio component.
20
19
  */
21
- disabled?: boolean,
20
+ disabled?: boolean
22
21
 
23
22
  /**
24
23
  * Determines if the radio should use an internal label or not.
25
24
  */
26
- label?: string,
25
+ label?: string
27
26
 
28
- id?: string | number,
27
+ /**
28
+ * Connects input to its corresponding label's `htmlFor`.
29
+ */
30
+ id?: string | number
29
31
 
30
32
  /**
31
33
  * Checks the radio.
32
34
  */
33
- checked?: boolean,
35
+ checked?: boolean
34
36
 
35
37
  /**
36
38
  * Maps to the internal input's `name` prop.
37
39
  */
38
- name?: string,
40
+ name?: string
39
41
 
40
42
  /**
41
43
  * Maps to the internal input's `value` prop.
42
44
  */
43
- value?: mixed,
45
+ value?: any
44
46
 
45
47
  /**
46
48
  * Determines the size of the radio based on a [scale](http://google.com).
47
49
  */
48
- size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl',
50
+ size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl'
49
51
 
50
52
  /**
51
53
  * Maps to the internal input's `onChange` prop.
52
54
  */
53
- onChange?: () => null,
55
+ onChange?: () => null
54
56
 
55
57
  /**
56
58
  * Maps to the internal input's `onFocus` prop.
57
59
  */
58
- onFocus?: () => null,
60
+ onFocus?: () => null
59
61
 
60
62
  /**
61
63
  * Maps to the internal input's `onBlur` prop.
62
64
  */
63
- onBlur?: () => null,
65
+ onBlur?: () => null
64
66
  }
65
67
 
66
68
  const radioEmitter = mitt()
67
69
 
68
- function Radio({
70
+ const Radio = ({
69
71
  checked,
70
- css,
71
72
  disabled,
72
73
  id,
73
74
  label,
@@ -78,7 +79,7 @@ function Radio({
78
79
  size = 'xs',
79
80
  value,
80
81
  ...restProps
81
- }: Props) {
82
+ }: RadioProps): JSX.Element => {
82
83
  const radioTheme = useThemeValue('radio')
83
84
  const inputRef = useRef()
84
85
  const [localChecked, setLocalChecked] = useState(false)
@@ -114,6 +115,8 @@ function Radio({
114
115
  innerRef={inputRef}
115
116
  as="input"
116
117
  type="radio"
118
+ // @ts-ignore Type 'string | number' is not assignable to type 'string'.
119
+ // Type 'number' is not assignable to type 'string'.ts(2322)
117
120
  id={id}
118
121
  name={name}
119
122
  checked={checked}
@@ -121,14 +124,17 @@ function Radio({
121
124
  disabled={disabled}
122
125
  onChange={(event) => {
123
126
  radioEmitter.emit(name, event.target)
127
+ // @ts-ignore Expected 0 arguments, but got 1.ts(2554)
124
128
  onChange && onChange(event)
125
129
  }}
126
130
  onFocus={(event) => {
127
131
  setFocus(true)
132
+ // @ts-ignore Expected 0 arguments, but got 1.ts(2554)
128
133
  onFocus && onFocus(event)
129
134
  }}
130
135
  onBlur={(event) => {
131
136
  setFocus(false)
137
+ // @ts-ignore Expected 0 arguments, but got 1.ts(2554)
132
138
  onBlur && onBlur(event)
133
139
  }}
134
140
  position="absolute"
@@ -1,4 +1,5 @@
1
1
  import React, { Component, Children, cloneElement } from 'react'
2
+ // @ts-ignore Should this be ReactNode anyway?
2
3
  import type { Node } from 'react'
3
4
 
4
5
  import Badge from '../Badge'