Skip to content

Commit

Permalink
Merge pull request #62 from MacPaw/feat/icon_for_input
Browse files Browse the repository at this point in the history
add icon to Input component
  • Loading branch information
BZahorodnii authored May 17, 2022
2 parents a930088 + 679ca13 commit e4a182f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@macpaw/macpaw-ui",
"version": "3.9.7",
"version": "3.10.0",
"main": "lib/ui.js",
"scripts": {
"dev": "next -p 1234",
Expand Down
19 changes: 18 additions & 1 deletion pages/input.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Input, FormRow, Button, Password } from '../src/ui';
import { SearchIcon } from '../src/Icons/jsx';

# Input

Expand Down Expand Up @@ -269,4 +270,20 @@ const [value, setValue] = React.useState(10);
/>
</FormRow>
</div>
```
```

# Input with icon

<div style={{ width: 300 }}>
<FormRow>
<Input type="text" name="name" placeholder="Name" onChange={() => {}} label="Default" icon={<SearchIcon />} />
</FormRow>
</div>

```
<div style={{ width: 300 }}>
<FormRow>
<Input type="text" name="name" placeholder="Name" onChange={() => {}} label="Default" icon={<SearchIcon />} />
</FormRow>
</div>
```
12 changes: 12 additions & 0 deletions src/Input/Input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
right: 18px;
}

&-icon {
position: absolute;
top: 50%;
transform: translateY(-50%);
left: 15px;
line-height: 1;
}

&-currency {
position: absolute;
top: 50%;
Expand Down Expand Up @@ -96,6 +104,10 @@
&.-with-currency {
padding-right: 60px;
}

&.-with-icon {
padding-left: 44px;
}
}

textarea {
Expand Down
6 changes: 5 additions & 1 deletion src/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface InputProps extends Omit<InputHTMLAttributes<HTMLInputElement>,
action?: ReactNode;
multiline?: boolean;
label?: string | ReactNode;
icon?: ReactNode;
rows?: number;
currency?: string;
formatOnEvent?: 'blur' | 'input';
Expand All @@ -37,6 +38,7 @@ const Input = forwardRef<HTMLInputElement, InputProps>((props, ref) => {
label,
currency,
className,
icon,
value,
onChange,
formatOnEvent = '',
Expand All @@ -59,7 +61,8 @@ const Input = forwardRef<HTMLInputElement, InputProps>((props, ref) => {
const inputValue = !isDirtyRef.current ? (format?.(value ?? '') ?? value) : value;
const inputClassNames = cx(className, {
'-with-action': action,
'-with-currency': currency
'-with-currency': currency,
'-with-icon': icon
});

const componentProps: any = {
Expand Down Expand Up @@ -110,6 +113,7 @@ const Input = forwardRef<HTMLInputElement, InputProps>((props, ref) => {
<label className={classNames} style={style}>
{label && <span className="input-label h6">{label}{`${other.required ? ' *' : ''}`}</span>}
<span className="input-field">
{icon && <span className="input-icon">{icon}</span>}
<Component
{...componentProps}
{...other}
Expand Down

0 comments on commit e4a182f

Please sign in to comment.