Skip to content

Commit

Permalink
Input css 관련 수정했다
Browse files Browse the repository at this point in the history
  • Loading branch information
healtheloper committed Dec 14, 2023
1 parent e3ed7db commit 198f411
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 18 deletions.
11 changes: 8 additions & 3 deletions packages/co-design-core/src/components/Input/Input.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default createStyles(
};

return {
root: {},
wrapper: {
position: 'relative',
},
Expand Down Expand Up @@ -90,13 +91,14 @@ export default createStyles(
backgroundColor: theme.foundations.tokens.color.bg.bg_surface_01,
// transition: 'border-color 100ms ease',

'&:not(:disabled):hover': {
'&:not(:disabled):not(:focus):hover': {
borderColor: invalid ? invalidColor : theme.foundations.tokens.color.border.border_strong,
},

'&:focus, &:focus-within': {
width: 'calc(100% - 2px)',
border: `2px solid ${theme.foundations.tokens.color.border.border_primary}`,
borderColor: theme.foundations.tokens.color.border.border_primary,
outline: `1px solid ${theme.foundations.tokens.color.border.border_primary}`,
},

'&::placeholder': {
Expand Down Expand Up @@ -132,7 +134,8 @@ export default createStyles(
},

invalid: {
border: `2px solid ${invalidColor}`,
outline: `1px solid ${invalidColor}`,
borderColor: invalidColor,

'&::placeholder': {
opacity: 1,
Expand Down Expand Up @@ -188,6 +191,7 @@ export default createStyles(
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
margin: 1,
},

leftSection: {
Expand All @@ -198,6 +202,7 @@ export default createStyles(
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
margin: 1,
},

helperText: {
Expand Down
28 changes: 14 additions & 14 deletions packages/co-design-core/src/components/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ export const Input: InputComponent & { displayName?: string } = forwardRef(
const Element: any = component || 'input';
const [currentLength, setCurrentLength] = useState(0);

const Wrapper = label ? View : React.Fragment;

const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
if (maximumLength) {
setCurrentLength(e.target.value.length);
Expand All @@ -154,17 +152,19 @@ export const Input: InputComponent & { displayName?: string } = forwardRef(
};

return (
<Wrapper>
<Group className={classes.labelWrapper} position={label ? 'apart' : 'right'}>
{label ? (
<label htmlFor={inputId + name}>
<Typography variant={labelVariants[size]} className={classes.labelText} {...labelTextProps}>
{label}
</Typography>
</label>
) : null}
{maximumLength ? <Text className={classes.maximumLength}>{`${currentLength} / ${maximumLength}`}</Text> : null}
</Group>
<View className={classes.root}>
{(label || maximumLength) && (
<Group className={classes.labelWrapper} position={label ? 'apart' : 'right'}>
{label ? (
<label htmlFor={inputId + name}>
<Typography variant={labelVariants[size]} className={classes.labelText} {...labelTextProps}>
{label}
</Typography>
</label>
) : null}
{maximumLength ? <Text className={classes.maximumLength}>{`${currentLength} / ${maximumLength}`}</Text> : null}
</Group>
)}
<View className={cx(classes.wrapper, className)} co={co} style={style} {...wrapperProps}>
{leftSection && (
<div
Expand Down Expand Up @@ -206,7 +206,7 @@ export const Input: InputComponent & { displayName?: string } = forwardRef(
</Typography>
)}
</View>
</Wrapper>
</View>
);
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,17 @@ export const WithLeftSection = {

return (
<div style={{ width: 400, padding: 24 }}>
<Input icon={<Icon />} leftSection={withTooltip} leftSectionWidth={50} {...props} />
<Input
icon={<Icon />}
leftSection={withTooltip}
leftSectionWidth={50}
overrideStyles={{
leftSection: {
backgroundColor: 'gray',
},
}}
{...props}
/>
</div>
);
},
Expand All @@ -107,6 +117,18 @@ export const WithLabel = {
},
};

export const MultiInput = {
render: (props) => {
return (
<div style={{ width: 400, padding: 24, display: 'flex', flexDirection: 'column', gap: '32px' }}>
<Input {...props} />
<Input {...props} helperText="something wrong" />
<Input {...props} />
</div>
);
},
};

// Storybook Context 변경으로 인한 리렌더링으로 focus 풀림
export const AutoFocus = {
render: (props) => {
Expand Down

0 comments on commit 198f411

Please sign in to comment.