This repository has been archived by the owner on Jan 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ui-components: Input component with Icon
It has to be possible to prefix Icon component at the beginning of Input element. Current changes introduce some code refactoring where Input element is always wrapped with outer container. And `prefix` prop is added to consume Icon component with correct positioning and coloring. Helpers module is supposed to contain small components like InputWrapper.
- Loading branch information
Showing
9 changed files
with
129 additions
and
48 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
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
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
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,18 +1,15 @@ | ||
import React from "react"; | ||
import { BaseInput, InputProps } from "./BaseInput"; | ||
import classNames from "classnames/bind"; | ||
import styles from "./styles.module.scss"; | ||
import { InputPrefix, InputWrapper } from "./helpers"; | ||
|
||
export type TextInputProps = Omit<InputProps<string>, "type">; | ||
|
||
const cx = classNames.bind(styles); | ||
|
||
export const TextInput: React.FC<TextInputProps> = props => { | ||
const { prefix, disabled, invalid } = props; | ||
return ( | ||
<BaseInput | ||
{...props} | ||
type="text" | ||
className={cx("container", props.className)} | ||
/> | ||
<InputWrapper disabled={disabled} invalid={invalid}> | ||
<InputPrefix>{prefix}</InputPrefix> | ||
<BaseInput {...props} type="text" /> | ||
</InputWrapper> | ||
); | ||
}; |
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
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,44 @@ | ||
import React from "react"; | ||
import classNames from "classnames/bind"; | ||
import styles from "./styles.module.scss"; | ||
import { InputProps } from "./BaseInput"; | ||
|
||
const cx = classNames.bind(styles); | ||
|
||
export type InputWrapperProps = Pick< | ||
InputProps, | ||
"disabled" | "invalid" | "className" | ||
>; | ||
|
||
export interface InputPrefixProps { | ||
className?: string; | ||
} | ||
|
||
export const InputPrefix: React.FC<InputPrefixProps> = ({ | ||
children, | ||
className, | ||
}) => { | ||
if (!children) { | ||
return null; | ||
} | ||
const classes = cx("prefix", className); | ||
return <div className={classes}>{children}</div>; | ||
}; | ||
|
||
export const InputWrapper: React.FC<InputWrapperProps> = ({ | ||
children, | ||
className, | ||
invalid, | ||
disabled, | ||
}) => { | ||
const wrapperClassName = cx( | ||
"container", | ||
{ | ||
active: !invalid && !disabled, | ||
disabled: disabled, | ||
invalid: invalid, | ||
}, | ||
className, | ||
); | ||
return <div className={wrapperClassName}>{children}</div>; | ||
}; |
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
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
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