Skip to content

Commit aebedff

Browse files
committed
Merged text-input-icon into text-input component
1 parent a18ec78 commit aebedff

8 files changed

Lines changed: 61 additions & 122 deletions

src/atoms/forms/text-input-icon.scss

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/atoms/forms/text-input-icon.stories.tsx

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/atoms/forms/text-input-icon.test.tsx

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/atoms/forms/text-input-icon.tsx

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/atoms/forms/text-input.scss

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@import "../../assets/scss/6-components/_component-base";
2+
3+
.c-text-input {
4+
display: flex;
5+
align-items: center;
6+
7+
input {
8+
width: 100%;
9+
position: relative;
10+
z-index: 1;
11+
}
12+
13+
.c-icon {
14+
position: relative;
15+
width: 48px;
16+
margin-right: -48px;
17+
z-index: 2;
18+
}
19+
20+
&.-icon {
21+
input {
22+
padding-left: 48px;
23+
}
24+
}
25+
26+
}

src/atoms/forms/text-input.stories.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from "react";
2-
import { text, boolean, number } from "@storybook/addon-knobs";
2+
import { text, boolean, number, select } from "@storybook/addon-knobs";
3+
import { Icons } from "../constants/icons";
34
import { TextInput } from "./text-input";
45
import Faker from "faker";
56

@@ -11,6 +12,7 @@ export default {
1112
export const textInputKnobs = () => (
1213
<TextInput
1314
disabled={boolean("Disabled", false)}
15+
icon={select("Icon", Icons, undefined)}
1416
id={Faker.random.uuid()}
1517
maxLength={number("Max Length", 30)}
1618
onChange={() => {}}

src/atoms/forms/text-input.tsx

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import { InputTypes } from "../constants/input-types";
22
import { InputProperties } from "../interfaces/input-properties";
3+
import { Icons } from "../constants/icons";
4+
import { IconSizes } from "../constants/icon-sizes";
5+
import { Icon } from "../icons/icon";
36
import React from "react";
7+
import "./text-input.scss";
48

59
// -----------------------------------------------------------------------------------------
610
// #region Interfaces
711
// -----------------------------------------------------------------------------------------
812

913
export interface TextInputProps extends InputProperties {
14+
icon?: Icons;
15+
iconSize?: IconSizes;
1016
id: string;
1117
maxLength?: number;
1218
name?: string;
@@ -24,9 +30,13 @@ export interface TextInputProps extends InputProperties {
2430
// -----------------------------------------------------------------------------------------
2531

2632
const TextInput: React.FC<TextInputProps> = (props: TextInputProps) => {
33+
let classNames: string[] = ["c-text-input"];
34+
2735
const {
2836
ariaLabelledBy,
2937
disabled,
38+
icon,
39+
iconSize,
3040
id,
3141
name,
3242
onChange,
@@ -37,19 +47,29 @@ const TextInput: React.FC<TextInputProps> = (props: TextInputProps) => {
3747

3848
const maxLength = props.maxLength != null ? props.maxLength : 20;
3949

50+
if (icon) {
51+
classNames.push("-icon");
52+
}
53+
4054
return (
41-
<input
42-
aria-labelledby={ariaLabelledBy}
43-
data-testid={testId}
44-
disabled={disabled}
45-
id={id}
46-
placeholder={placeholder}
47-
maxLength={maxLength}
48-
name={name}
49-
onChange={onChange}
50-
type={InputTypes.Text}
51-
value={value}
52-
/>
55+
<div className={classNames.join(" ")}>
56+
{// if
57+
icon &&
58+
<Icon type={icon} size={iconSize ?? IconSizes.Large} />
59+
}
60+
<input
61+
aria-labelledby={ariaLabelledBy}
62+
data-testid={testId}
63+
disabled={disabled}
64+
id={id}
65+
placeholder={placeholder}
66+
maxLength={maxLength}
67+
name={name}
68+
onChange={onChange}
69+
type={InputTypes.Text}
70+
value={value}
71+
/>
72+
</div>
5373
);
5474
};
5575

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export { PasswordInput } from "./atoms/forms/password-input";
1414
export { SubmitButton } from "./atoms/forms/submit-button";
1515
export { TextArea } from "./atoms/forms/text-area";
1616
export { TextInput } from "./atoms/forms/text-input";
17-
export { TextInputIcon } from "./atoms/forms/text-input-icon";
1817

1918
// Typography
2019
export { Heading } from "./atoms/typography/heading";

0 commit comments

Comments
 (0)