Skip to content

Commit

Permalink
Merge pull request #672 from Atom-Learning/fix/input-types-do-not-use…
Browse files Browse the repository at this point in the history
…-override

fix: do not use Override in Input types
  • Loading branch information
LimeWub authored Aug 7, 2024
2 parents b97b4b1 + 0d65f59 commit 09b8a8f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -510,14 +510,14 @@ exports[`DateInput component renders lg size 1`] = `
display: table;
}
.c-nNuCY-hztIub-isToday-true {
background: var(--colors-tonal100);
}
.c-nNuCY-huXVXM-isOutsideMonth-true {
color: var(--colors-tonal200);
}
.c-nNuCY-hztIub-isToday-true {
background: var(--colors-tonal100);
}
.c-iKnjyA-kUaMfZ-size-md {
max-width: 400px;
}
Expand Down
37 changes: 19 additions & 18 deletions lib/src/components/input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as React from 'react'
import { styled } from '~/stitches'
import { disabledStyle } from '~/utilities'
import { overrideStitchesVariantValue } from '~/utilities/override-stitches-variant-value/overrideStitchesVariantValue'
import { Override } from '~/utilities/types'

import { Flex } from '../flex'
import { Text } from '../text'
Expand Down Expand Up @@ -44,6 +43,8 @@ export const InputBackground = styled(Flex, {
}
})

InputBackground.displayName = 'InputBackground'

const StyledInputText = styled.withConfig({
shouldForwardStitchesProp: (propName) => ['as'].includes(propName)
})(Text as unknown as 'input', {
Expand All @@ -63,16 +64,15 @@ const StyledInputText = styled.withConfig({
size: '100%'
})

export type InputTextProps = Override<
React.ComponentProps<typeof StyledInputText>,
{
size: React.ComponentProps<typeof Text>['size']
// override default 'type' property to prevent Input from being used to render
// checkboxes, radios etc — we have dedicated components for them
type?: 'text' | 'number' | 'email' | 'password' | 'tel' | 'url' | 'search'
as?: never
}
>
export type InputTextProps = Omit<
React.ComponentProps<typeof StyledInputText>, 'size' | 'type' | 'as'> &
{
size: React.ComponentProps<typeof Text>['size']
// override default 'type' property to prevent Input from being used to render
// checkboxes, radios etc — we have dedicated components for them
type?: 'text' | 'number' | 'email' | 'password' | 'tel' | 'url' | 'search'
as?: never
}

const toTextSize = {
sm: 'sm',
Expand Down Expand Up @@ -105,14 +105,15 @@ export const InputText = React.forwardRef(
}
)

InputText.displayName = 'InputText'

type InputBackgroundProps = React.ComponentProps<typeof InputBackground>
export type InputProps = Override<
React.ComponentProps<typeof InputText>,
{
size?: InputBackgroundProps['size']
state?: InputBackgroundProps['state']
}
>
export type InputProps = Omit<
React.ComponentProps<typeof InputText>, 'size' | 'state'> &
{
size?: InputBackgroundProps['size']
state?: InputBackgroundProps['state']
}

export const Input = React.forwardRef(
(
Expand Down

0 comments on commit 09b8a8f

Please sign in to comment.