-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(TextInput): Convert UnstyledTextInput to use CSS modules behind …
…feature flag (#5254) * feat(TextInput): Convert UnstyledTextInput to use CSS modules behind feature flag * changeset * reorder props
- Loading branch information
1 parent
fca4ec9
commit ac6ddcd
Showing
5 changed files
with
66 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@primer/react": minor | ||
--- | ||
|
||
Convert UnstyledTextInput to use CSS Modules behing feature flag |
3 changes: 3 additions & 0 deletions
3
packages/react/src/TextInputWithTokens/TextInputWithTokens.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.UnstyledTextInput { | ||
height: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/react/src/internal/components/UnstyledTextInput.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.Input { | ||
width: 100%; | ||
font-family: inherit; | ||
font-size: inherit; | ||
color: inherit; | ||
background-color: transparent; | ||
border: 0; | ||
appearance: none; | ||
|
||
&:focus { | ||
outline: 0; | ||
} | ||
} |
51 changes: 37 additions & 14 deletions
51
packages/react/src/internal/components/UnstyledTextInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,42 @@ | ||
import styled from 'styled-components' | ||
import sx from '../../sx' | ||
import sx, {type SxProp} from '../../sx' | ||
import {toggleStyledComponent} from '../utils/toggleStyledComponent' | ||
import React from 'react' | ||
import {useFeatureFlag} from '../../FeatureFlags' | ||
|
||
const UnstyledTextInput = styled.input` | ||
border: 0; | ||
font-size: inherit; | ||
font-family: inherit; | ||
background-color: transparent; | ||
-webkit-appearance: none; | ||
color: inherit; | ||
width: 100%; | ||
&:focus { | ||
outline: 0; | ||
} | ||
import styles from './UnstyledTextInput.module.css' | ||
import {clsx} from 'clsx' | ||
|
||
${sx}; | ||
` | ||
export const TEXT_INPUT_CSS_MODULES_FEATURE_FLAG = 'primer_react_css_modules_team' | ||
|
||
type ToggledUnstyledTextInputProps = React.ComponentPropsWithoutRef<'input'> & SxProp | ||
|
||
const ToggledUnstyledTextInput = toggleStyledComponent( | ||
TEXT_INPUT_CSS_MODULES_FEATURE_FLAG, | ||
'input', | ||
styled.input` | ||
border: 0; | ||
font-size: inherit; | ||
font-family: inherit; | ||
background-color: transparent; | ||
-webkit-appearance: none; | ||
color: inherit; | ||
width: 100%; | ||
&:focus { | ||
outline: 0; | ||
} | ||
${sx}; | ||
`, | ||
) | ||
|
||
const UnstyledTextInput = React.forwardRef<HTMLInputElement, ToggledUnstyledTextInputProps>(function UnstyledTextInput( | ||
{className, ...rest}, | ||
forwardRef, | ||
) { | ||
const enabled = useFeatureFlag(TEXT_INPUT_CSS_MODULES_FEATURE_FLAG) | ||
return <ToggledUnstyledTextInput ref={forwardRef} {...rest} className={clsx(className, enabled && styles.Input)} /> | ||
}) | ||
UnstyledTextInput.displayName = 'UnstyledTextInput' | ||
|
||
export default UnstyledTextInput |