From f4e1de6dbe9d20dfcf2144d879294d189433a810 Mon Sep 17 00:00:00 2001 From: Jonathan Fuchs Date: Thu, 9 Sep 2021 15:34:20 -0700 Subject: [PATCH] Remove system props from TextInput & fix prop types (#1414) --- .changeset/cuddly-rice-march.md | 5 +++ docs/content/TextInput.md | 12 +----- src/TextInput.tsx | 56 +++++++++++++++++++--------- src/stories/DropdownMenu.stories.tsx | 2 +- 4 files changed, 45 insertions(+), 30 deletions(-) create mode 100644 .changeset/cuddly-rice-march.md diff --git a/.changeset/cuddly-rice-march.md b/.changeset/cuddly-rice-march.md new file mode 100644 index 00000000000..83b181c7c59 --- /dev/null +++ b/.changeset/cuddly-rice-march.md @@ -0,0 +1,5 @@ +--- +'@primer/components': major +--- + +Removed system props support from `` and fixed its type definition. diff --git a/docs/content/TextInput.md b/docs/content/TextInput.md index 83d557f59fa..230c00877f9 100644 --- a/docs/content/TextInput.md +++ b/docs/content/TextInput.md @@ -11,21 +11,11 @@ TextInput is a form component to add default styling to the native text input. ```jsx live - + ``` -## System props - - - -System props are deprecated in all components except [Box](/Box). Please use the [`sx` prop](/overriding-styles) instead. - - - -TextInput components get `COMMON` system props. Read our [System Props](/system-props) doc page for a full list of available props. - ## Component props Native `` attributes are forwarded to the underlying React `input` component and are not listed below. diff --git a/src/TextInput.tsx b/src/TextInput.tsx index a8c77488bd3..45cc2460a77 100644 --- a/src/TextInput.tsx +++ b/src/TextInput.tsx @@ -1,9 +1,8 @@ -import {omit, pick} from '@styled-system/props' import classnames from 'classnames' import React from 'react' import styled, {css} from 'styled-components' import {maxWidth, MaxWidthProps, minWidth, MinWidthProps, variant, width, WidthProps} from 'styled-system' -import {COMMON, get, SystemCommonProps} from './constants' +import {get} from './constants' import sx, {SxProp} from './sx' import {ComponentProps} from './utils/types' @@ -43,8 +42,7 @@ type StyledWrapperProps = { block?: boolean contrast?: boolean variant?: 'small' | 'large' -} & SystemCommonProps & - WidthProps & +} & WidthProps & MinWidthProps & MaxWidthProps & SxProp @@ -113,7 +111,6 @@ const Wrapper = styled.span` @media (min-width: ${get('breakpoints.1')}) { font-size: ${get('fontSizes.1')}; } - ${COMMON} ${width} ${minWidth} ${maxWidth} @@ -121,30 +118,53 @@ const Wrapper = styled.span` ${sx}; ` -type TextInputInternalProps = { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - as?: any // This is a band-aid fix until we have better type support for the `as` prop +// Props that are not passed through to Input: +type NonPassthroughProps = { + className?: string icon?: React.ComponentType<{className?: string}> -} & ComponentProps & - ComponentProps +} & Pick< + ComponentProps, + 'block' | 'contrast' | 'disabled' | 'sx' | 'theme' | 'width' | 'maxWidth' | 'minWidth' | 'variant' +> + +type TextInputInternalProps = NonPassthroughProps & + // Note: using ComponentProps instead of ComponentPropsWithoutRef here would cause a type issue where `css` is a required prop. + Omit, keyof NonPassthroughProps> // using forwardRef is important so that other components (ex. SelectMenu) can autofocus the input const TextInput = React.forwardRef( - ({icon: IconComponent, contrast, className, block, disabled, theme, sx: sxProp, ...rest}, ref) => { + ( + { + icon: IconComponent, + block, + className, + contrast, + disabled, + sx: sxProp, + theme, + width: widthProp, + minWidth: minWidthProp, + maxWidth: maxWidthProp, + variant: variantProp, + ...inputProps + }, + ref + ) => { // this class is necessary to style FilterSearch, plz no touchy! const wrapperClasses = classnames(className, 'TextInput-wrapper') - const wrapperProps = pick(rest) - const inputProps = omit(rest) return ( {IconComponent && } diff --git a/src/stories/DropdownMenu.stories.tsx b/src/stories/DropdownMenu.stories.tsx index 09deabcca93..1f524c0de8d 100644 --- a/src/stories/DropdownMenu.stories.tsx +++ b/src/stories/DropdownMenu.stories.tsx @@ -36,7 +36,7 @@ export function FavoriteColorStory(): JSX.Element { return ( <>

Favorite Color

- +
Please select your favorite color:
(