Skip to content

Commit

Permalink
chore(project): update TypeScript to v4.8.3 (#2360)
Browse files Browse the repository at this point in the history
* chore(project): update TypeScript to v4.8.3

* chore: remove formatting jsx

* chore: update snapshots

* Create silver-walls-compete.md

* refactor(ts): update ts types for FormControl, InputField

* chore: address eslint violations
  • Loading branch information
joshblack committed Oct 12, 2022
1 parent 247c15c commit 0f41dfe
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 157 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-walls-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

Update types to support TypeScript v4.8.3
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
"storybook-addon-turbo-build": "1.1.0",
"styled-components": "4.4.1",
"ts-toolbelt": "9.6.0",
"typescript": "4.5.4",
"typescript": "4.8.3",
"webpack": "5.74.0"
},
"peerDependencies": {
Expand Down
18 changes: 11 additions & 7 deletions src/AvatarPair.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import styled from 'styled-components'
import Avatar from './Avatar'
import Avatar, {AvatarProps} from './Avatar'
import {get} from './constants'
import Box, {BoxProps} from './Box'

Expand All @@ -15,13 +15,17 @@ export type AvatarPairProps = BoxProps

const AvatarPair = ({children, ...rest}: AvatarPairProps) => {
const avatars = React.Children.map(children, (child, i) => {
if (!React.isValidElement(child)) return child
return i === 0 ? (
React.cloneElement(child, {size: 40})
) : (
<ChildAvatar bg="canvas.default" {...child.props} size={20} />
)
if (!React.isValidElement(child)) {
return child
}

if (i === 0) {
return React.cloneElement(child as React.ReactElement<AvatarProps>, {size: 40})
}

return <ChildAvatar bg="canvas.default" {...child.props} size={20} />
})

return (
<Box position="relative" display="inline-flex" {...rest}>
{avatars}
Expand Down
45 changes: 30 additions & 15 deletions src/FormControl/FormControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import TextInput from '../TextInput'
import TextInputWithTokens from '../TextInputWithTokens'
import {useSSRSafeId} from '../utils/ssr'
import FormControlCaption from './_FormControlCaption'
import FormControlLabel from './_FormControlLabel'
import FormControlLabel, {Props as FormControlLabelProps} from './_FormControlLabel'
import FormControlValidation from './_FormControlValidation'
import {Slots} from './slots'
import ValidationAnimationContainer from '../_ValidationAnimationContainer'
Expand Down Expand Up @@ -149,11 +149,18 @@ const FormControl = React.forwardRef<HTMLDivElement, FormControlProps>(
<Box ref={ref} display="flex" alignItems={slots.LeadingVisual ? 'center' : undefined} sx={sx}>
<Box sx={{'> input': {marginLeft: 0, marginRight: 0}}}>
{React.isValidElement(InputComponent) &&
React.cloneElement(InputComponent, {
id,
disabled,
['aria-describedby']: captionId
})}
React.cloneElement(
InputComponent as React.ReactElement<{
id: string
disabled: boolean
['aria-describedby']: string
}>,
{
id,
disabled,
['aria-describedby']: captionId as string
}
)}
{React.Children.toArray(children).filter(
child =>
React.isValidElement(child) &&
Expand All @@ -175,7 +182,10 @@ const FormControl = React.forwardRef<HTMLDivElement, FormControlProps>(
{slots.LeadingVisual}
</Box>
)}
{(React.isValidElement(slots.Label) && !slots.Label.props.visuallyHidden) || slots.Caption ? (
{(React.isValidElement(slots.Label) &&
slots.Label.type === FormControlLabel &&
!(slots.Label.props as FormControlLabelProps).visuallyHidden) ||
slots.Caption ? (
<Box display="flex" flexDirection="column" ml={2}>
{slots.Label}
{slots.Caption}
Expand All @@ -197,14 +207,19 @@ const FormControl = React.forwardRef<HTMLDivElement, FormControlProps>(
>
{slots.Label}
{React.isValidElement(InputComponent) &&
React.cloneElement(InputComponent, {
id,
required,
disabled,
validationStatus,
['aria-describedby']: [validationMessageId, captionId].filter(Boolean).join(' '),
...InputComponent.props
})}
React.cloneElement(
InputComponent,
Object.assign(
{
id,
required,
disabled,
validationStatus,
['aria-describedby']: [validationMessageId, captionId].filter(Boolean).join(' ')
},
InputComponent.props
)
)}
{React.Children.toArray(children).filter(
child =>
React.isValidElement(child) &&
Expand Down
52 changes: 13 additions & 39 deletions src/__tests__/__snapshots__/CheckboxGroup.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,12 @@ exports[`CheckboxGroup renders consistently 1`] = `
margin-right: 0;
}
.c7 {
margin-left: 8px;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
}
.c2 {
display: block;
font-size: 16px;
}
.c8 {
.c7 {
font-weight: 600;
font-size: 14px;
display: block;
Expand Down Expand Up @@ -125,17 +114,12 @@ exports[`CheckboxGroup renders consistently 1`] = `
value="one"
/>
</div>
<div
<label
className="c7"
display="flex"
htmlFor="react-aria-2"
>
<label
className="c8"
htmlFor="react-aria-2"
>
Choice one
</label>
</div>
Choice one
</label>
</div>
<div
className="c4"
Expand All @@ -157,17 +141,12 @@ exports[`CheckboxGroup renders consistently 1`] = `
value="two"
/>
</div>
<div
<label
className="c7"
display="flex"
htmlFor="react-aria-3"
>
<label
className="c8"
htmlFor="react-aria-3"
>
Choice two
</label>
</div>
Choice two
</label>
</div>
<div
className="c4"
Expand All @@ -189,17 +168,12 @@ exports[`CheckboxGroup renders consistently 1`] = `
value="three"
/>
</div>
<div
<label
className="c7"
display="flex"
htmlFor="react-aria-4"
>
<label
className="c8"
htmlFor="react-aria-4"
>
Choice three
</label>
</div>
Choice three
</label>
</div>
</div>
</fieldset>
Expand Down
52 changes: 13 additions & 39 deletions src/__tests__/__snapshots__/CheckboxOrRadioGroup.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,12 @@ exports[`CheckboxOrRadioGroup renders consistently 1`] = `
margin-right: 0;
}
.c7 {
margin-left: 8px;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
}
.c2 {
display: block;
font-size: 16px;
}
.c8 {
.c7 {
font-weight: 600;
font-size: 14px;
display: block;
Expand Down Expand Up @@ -125,17 +114,12 @@ exports[`CheckboxOrRadioGroup renders consistently 1`] = `
value="choiceOne"
/>
</div>
<div
<label
className="c7"
display="flex"
htmlFor="react-aria-2"
>
<label
className="c8"
htmlFor="react-aria-2"
>
Choice one
</label>
</div>
Choice one
</label>
</div>
<div
className="c4"
Expand All @@ -157,17 +141,12 @@ exports[`CheckboxOrRadioGroup renders consistently 1`] = `
value="choiceTwo"
/>
</div>
<div
<label
className="c7"
display="flex"
htmlFor="react-aria-3"
>
<label
className="c8"
htmlFor="react-aria-3"
>
Choice two
</label>
</div>
Choice two
</label>
</div>
<div
className="c4"
Expand All @@ -189,17 +168,12 @@ exports[`CheckboxOrRadioGroup renders consistently 1`] = `
value="choiceThree"
/>
</div>
<div
<label
className="c7"
display="flex"
htmlFor="react-aria-4"
>
<label
className="c8"
htmlFor="react-aria-4"
>
Choice three
</label>
</div>
Choice three
</label>
</div>
</div>
</fieldset>
Expand Down
Loading

0 comments on commit 0f41dfe

Please sign in to comment.