Skip to content

Commit

Permalink
fix: duplicate class name in suffix icon (#97)
Browse files Browse the repository at this point in the history
* fix: duplicate class name in suffix icon

* refactor: setting default value in TextField

* refactor: modify suffix type in SuffixTextField

* fix: add suffix icon visibility

* fix: add input active property

* Update src/components/TextField/TextField.style.ts

Co-authored-by: 이유진 <[email protected]>

---------

Co-authored-by: 이유진 <[email protected]>
  • Loading branch information
Hanna922 and nijuy authored May 16, 2024
1 parent 3d0b90a commit f48f4e2
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 40 deletions.
13 changes: 9 additions & 4 deletions src/components/TextField/PasswordTextField/PasswordTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,28 @@ import { TextField } from '../TextField';
import { PasswordTextFieldProps } from './PasswordTextField.type';

export const PasswordTextField = ({ isMarked = true, ...props }: PasswordTextFieldProps) => {
const theme = useTheme();
const [isMarkedValue, setIsMarkedValue] = useState(isMarked);

const onClickEyeButton = () => {
setIsMarkedValue((prev) => !prev);
};

return (
<TextField
type={isMarkedValue ? 'password' : 'text'}
suffix={
<IconContext.Provider
value={{
color: useTheme().color.buttonNormal,
color: theme.color.buttonNormal,
size: '1.5rem',
}}
>
<div className="suffix-icon" onClick={onClickEyeButton}>
{isMarkedValue ? <IcEyeclosedLine /> : <IcEyeopenLine />}
</div>
{isMarkedValue ? (
<IcEyeclosedLine onClick={onClickEyeButton} />
) : (
<IcEyeopenLine onClick={onClickEyeButton} />
)}
</IconContext.Provider>
}
{...props}
Expand Down
4 changes: 1 addition & 3 deletions src/components/TextField/SearchTextField/SearchTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ export const SearchTextField = ({ onClickClearButton, ...props }: SearchTextFiel
size: '1rem',
}}
>
<div className="suffix-icon clear-icon" onClick={onClickClearButton}>
<IcXLine />
</div>
<IcXLine onClick={onClickClearButton} />
</IconContext.Provider>
}
searchPrefix={
Expand Down
8 changes: 4 additions & 4 deletions src/components/TextField/SimpleTextField/SimpleTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import { TextField } from '../TextField';
import { SimpleTextFieldProps } from './SimpleTextField.type';

export const SimpleTextField = ({ onClickClearButton, ...props }: SimpleTextFieldProps) => {
const theme = useTheme();

return (
<TextField
suffix={
<IconContext.Provider
value={{
color: useTheme().color.buttonNormal,
color: theme.color.buttonNormal,
size: '1rem',
}}
>
<div className="suffix-icon clear-icon" onClick={onClickClearButton}>
<IcXLine />
</div>
<IcXLine onClick={onClickClearButton} />
</IconContext.Provider>
}
{...props}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { TextFieldProps } from '../TextField.type';

export interface SuffixTextFieldProps extends Omit<TextFieldProps, 'searchPrefix'> {
/** TextField 오른쪽에 들어갈 텍스트 */
suffix?: string;
}
export interface SuffixTextFieldProps extends Omit<TextFieldProps, 'searchPrefix'> {}
28 changes: 8 additions & 20 deletions src/components/TextField/TextField.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ interface StyledTextFieldProps {
$width?: TextFieldProps['width'];
}

export const StyledSuffixIconContainer = styled.div<StyledTextFieldProps>`
display: none;
`;

export const StyledTextFieldWrapper = styled.div<StyledTextFieldProps>`
width: ${({ $width }) => $width};
height: 46px;
Expand All @@ -27,18 +31,6 @@ export const StyledTextFieldWrapper = styled.div<StyledTextFieldProps>`
padding: 12px 16px;
gap: 4px;
.suffix-icon {
visibility: hidden;
cursor: pointer;
}
input:focus + .suffix-icon,
input:active + .suffix-icon {
visibility: visible;
display: flex;
align-items: center;
}
${({ $isDisabled, $isPositive, $isNegative, theme }) =>
!$isDisabled &&
($isNegative
Expand All @@ -50,14 +42,10 @@ export const StyledTextFieldWrapper = styled.div<StyledTextFieldProps>`
border: 1px solid ${theme.color.textPointed};
`)}
${({ $isDisabled }) =>
$isDisabled &&
css`
input:focus + .suffix-icon,
input:active + .suffix-icon {
display: none;
}
`}
input:focus + ${StyledSuffixIconContainer}, input:active + ${StyledSuffixIconContainer} {
display: flex;
cursor: pointer;
}
`;

export const StyledTextField = styled.input<StyledTextFieldProps>`
Expand Down
13 changes: 8 additions & 5 deletions src/components/TextField/TextField.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import {
StyledFieldLabel,
StyledHelperLabel,
StyledSuffixIconContainer,
StyledSuffixText,
StyledTextField,
StyledTextFieldWrapper,
} from './TextField.style';
import { TextFieldProps } from './TextField.type';

export const TextField = ({
isNegative,
isPositive,
isFocused,
isTyping,
isNegative = false,
isPositive = false,
isFocused = false,
isTyping = false,
fieldLabel,
helperLabel,
suffix,
Expand All @@ -35,7 +36,9 @@ export const TextField = ({
{typeof suffix === 'string' ? (
<StyledSuffixText $isDisabled={props.disabled}>{suffix}</StyledSuffixText>
) : (
suffix
<StyledSuffixIconContainer $isDisabled={props.disabled}>
{suffix}
</StyledSuffixIconContainer>
)}
</StyledTextFieldWrapper>
{helperLabel && (
Expand Down

0 comments on commit f48f4e2

Please sign in to comment.