Skip to content

Commit ce4e14d

Browse files
authored
Merge branch 'main' into hussam-i-am/dialog-v2-css-modules-
2 parents 72dc7aa + 912a0d7 commit ce4e14d

File tree

3 files changed

+75
-23
lines changed

3 files changed

+75
-23
lines changed

.changeset/dirty-fans-tap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": minor
3+
---
4+
5+
Update `Textarea` component to use CSS module
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.TextArea {
2+
width: 100%;
3+
font-family: inherit;
4+
font-size: inherit;
5+
color: inherit;
6+
resize: both;
7+
background-color: transparent;
8+
border: 0;
9+
appearance: none;
10+
}
11+
12+
.TextArea:focus {
13+
outline: 0;
14+
}
15+
16+
.TextArea[resize='none'] {
17+
resize: none;
18+
}
19+
20+
.TextArea[resize='both'] {
21+
resize: both;
22+
}
23+
24+
.TextArea[resize='horizontal'] {
25+
resize: horizontal;
26+
}
27+
28+
.TextArea[resize='vertical'] {
29+
resize: vertical;
30+
}
31+
32+
.TextArea:disabled {
33+
resize: none;
34+
}

packages/react/src/Textarea/Textarea.tsx

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import {TextInputBaseWrapper} from '../internal/components/TextInputWrapper'
55
import type {FormValidationStatus} from '../utils/types/FormValidationStatus'
66
import type {SxProp} from '../sx'
77
import sx from '../sx'
8+
import {toggleStyledComponent} from '../internal/utils/toggleStyledComponent'
9+
import {clsx} from 'clsx'
10+
import {useFeatureFlag} from '../FeatureFlags'
11+
import classes from './TextArea.module.css'
812

913
export const DEFAULT_TEXTAREA_ROWS = 7
1014
export const DEFAULT_TEXTAREA_COLS = 30
@@ -38,33 +42,39 @@ export type TextareaProps = {
3842
} & TextareaHTMLAttributes<HTMLTextAreaElement> &
3943
SxProp
4044

41-
const StyledTextarea = styled.textarea<TextareaProps>`
42-
border: 0;
43-
font-size: inherit;
44-
font-family: inherit;
45-
background-color: transparent;
46-
-webkit-appearance: none;
47-
color: inherit;
48-
width: 100%;
49-
resize: both;
45+
const CSS_MODULES_FEATURE_FLAG = 'primer_react_css_modules_team'
5046

51-
&:focus {
52-
outline: 0;
53-
}
47+
const StyledTextarea = toggleStyledComponent(
48+
CSS_MODULES_FEATURE_FLAG,
49+
'textarea',
50+
styled.textarea<TextareaProps>`
51+
border: 0;
52+
font-size: inherit;
53+
font-family: inherit;
54+
background-color: transparent;
55+
-webkit-appearance: none;
56+
color: inherit;
57+
width: 100%;
58+
resize: both;
5459
55-
${props =>
56-
props.resize &&
57-
css`
58-
resize: ${props.resize};
59-
`}
60+
&:focus {
61+
outline: 0;
62+
}
6063
61-
${props =>
62-
props.disabled &&
63-
css`
64-
resize: none;
65-
`}
64+
${props =>
65+
props.resize &&
66+
css`
67+
resize: ${props.resize};
68+
`}
69+
70+
${props =>
71+
props.disabled &&
72+
css`
73+
resize: none;
74+
`}
6675
${sx};
67-
`
76+
`,
77+
)
6878

6979
/**
7080
* An accessible, native textarea component that supports validation states.
@@ -88,6 +98,8 @@ const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
8898
}: TextareaProps,
8999
ref,
90100
): ReactElement => {
101+
const enabled = useFeatureFlag(CSS_MODULES_FEATURE_FLAG)
102+
91103
return (
92104
<TextInputBaseWrapper
93105
sx={sxProp}
@@ -106,6 +118,7 @@ const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
106118
disabled={disabled}
107119
rows={rows}
108120
cols={cols}
121+
className={clsx(enabled && classes.TextArea, className)}
109122
{...rest}
110123
/>
111124
</TextInputBaseWrapper>

0 commit comments

Comments
 (0)