Skip to content

Commit 6fdaad7

Browse files
committed
fix: change css for input
1 parent c262641 commit 6fdaad7

File tree

3 files changed

+72
-58
lines changed

3 files changed

+72
-58
lines changed

lib/components/Input/HelperMessage.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export interface HelperMessageProps {
99
variant?: InputVariants;
1010
disabled?: boolean;
1111
}
12-
13-
const MessageVariant: Record<InputVariants, string> = {
12+
type TMessageVariant = Exclude<InputVariants, "disabled">;
13+
const MessageVariant: Record<TMessageVariant, string> = {
1414
general: "deriv-helper-message__general",
1515
success: "deriv-helper-message__success",
1616
warning: "deriv-helper-message__warning",
@@ -26,7 +26,8 @@ const HelperMessage = ({
2626
<p
2727
className={clsx("deriv-helper-message", {
2828
[MessageVariant["general"]]: disabled,
29-
[MessageVariant[error ? "error" : variant]]: !disabled,
29+
[MessageVariant[error ? "error" : (variant as TMessageVariant)]]:
30+
!disabled,
3031
})}
3132
>
3233
{message}

lib/components/Input/Input.scss

+40-43
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,39 @@ $inactive_color: #999999;
88
$border: 1px solid;
99

1010
.deriv-input {
11-
display: inline-block;
11+
display: inline-flex;
1212
position: relative;
13+
border-radius: 4px;
14+
width: 328px;
15+
box-sizing: border-box;
16+
text-align: left;
17+
padding: 10px 16px;
18+
border: $border;
19+
20+
&__general {
21+
border-color: $inactive_color;
22+
&:focus-within {
23+
border-color: $active_color;
24+
}
25+
}
26+
&__error {
27+
border-color: $error_field;
28+
}
29+
&__success {
30+
border-color: $success_color;
31+
}
32+
33+
&__active {
34+
border-color: $active_color;
35+
}
36+
37+
&__disabled {
38+
border-color: $disabled_color;
39+
}
1340

1441
&--field {
1542
width: 100%;
16-
padding: 10px 16px;
1743
outline: none;
18-
border-radius: 4px;
19-
width: 328px;
20-
box-sizing: border-box;
21-
outline: none;
22-
text-align: left;
23-
&:disabled {
24-
border: $border $disabled_color;
25-
color: $inactive_color;
26-
}
2744
&::placeholder {
2845
visibility: hidden;
2946
}
@@ -37,24 +54,6 @@ $border: 1px solid;
3754
height: fit-content;
3855
}
3956
}
40-
&__general {
41-
border: $border $inactive_color;
42-
&:focus {
43-
border: $border $active_color;
44-
}
45-
}
46-
&__error {
47-
border: $border $error_field;
48-
&:focus {
49-
border: $border $error_field;
50-
}
51-
}
52-
&__success {
53-
border: $border $success_color;
54-
&:focus {
55-
border: $border $success_color;
56-
}
57-
}
5857
}
5958

6059
&--label {
@@ -78,38 +77,36 @@ $border: 1px solid;
7877
&__success {
7978
color: $success_color;
8079
}
80+
&__active {
81+
color: $active_color;
82+
}
83+
84+
&__disabled {
85+
color: $disabled_color;
86+
}
8187
}
8288

8389
&--helper-message {
90+
top: 100%;
8491
position: absolute;
8592
left: 16px;
86-
margin-top: 2px;
8793
line-height: 1;
8894
}
8995

9096
&--right-content {
91-
position: absolute;
92-
right: 16px;
93-
bottom: 25%;
97+
margin-left: 16px;
9498
}
9599
}
96100

97-
.deriv-input--field__general:disabled + .deriv-input--label,
98-
.deriv-input--field__error:disabled + .deriv-input--label,
99-
.deriv-input--field__success:disabled + .deriv-input--label {
100-
color: $inactive_color;
101-
cursor: not-allowed;
102-
}
103-
104-
.deriv-input--field:focus + .deriv-input--label {
101+
.deriv-input__general .deriv-input--field:focus + .deriv-input--label {
105102
color: $active_color;
106103
}
107104

108-
.deriv-input--field__error:focus + .deriv-input--label {
105+
.deriv-input__error .deriv-input--field:focus + .deriv-input--label {
109106
color: $error_field;
110107
}
111108

112-
.deriv-input--field__success:focus + .deriv-input--label {
109+
.deriv-input__success .deriv-input--field:focus + .deriv-input--label {
113110
color: $success_color;
114111
}
115112

lib/components/Input/index.tsx

+28-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import clsx from "clsx";
33
import HelperMessage from "./HelperMessage";
44
import "./Input.scss";
55

6-
export type InputVariants = "general" | "success" | "error" | "warning";
6+
export type InputVariants =
7+
| "general"
8+
| "success"
9+
| "error"
10+
| "warning"
11+
| "disabled";
712
interface InputProps
813
extends Omit<ComponentProps<"input">, "style" | "placeholder"> {
914
label?: string;
@@ -15,17 +20,19 @@ interface InputProps
1520
}
1621

1722
const InputVariant: Record<InputVariants, string> = {
18-
general: "deriv-input--field__general",
19-
success: "deriv-input--field__success",
20-
warning: "deriv-input--field__general",
21-
error: "deriv-input--field__error",
23+
general: "deriv-input__general",
24+
success: "deriv-input__success",
25+
warning: "deriv-input__general",
26+
error: "deriv-input__error",
27+
disabled: "deriv-input__disabled",
2228
};
2329

2430
const LabelVariant: Record<InputVariants, string> = {
2531
general: "deriv-input--label__general",
2632
success: "deriv-input--label__success",
2733
warning: "deriv-input--label__general",
2834
error: "deriv-input--label__error",
35+
disabled: "deriv-input--label__disabled",
2936
};
3037

3138
export const Input = ({
@@ -41,24 +48,33 @@ export const Input = ({
4148
...rest
4249
}: InputProps) => {
4350
return (
44-
<div className="deriv-input">
51+
<div
52+
className={clsx(
53+
"deriv-input",
54+
className,
55+
InputVariant[error ? "error" : variant],
56+
{
57+
"deriv-input__disabled": disabled,
58+
}
59+
)}
60+
>
4561
{leftPlaceholder && (
4662
<div className="deriv-input--left-content">{leftPlaceholder}</div>
4763
)}
4864
<input
4965
placeholder={label}
50-
className={clsx(
51-
"deriv-input--field",
52-
className,
53-
InputVariant[error ? "error" : variant]
54-
)}
66+
className="deriv-input--field"
5567
id={id}
68+
disabled={disabled}
5669
{...rest}
5770
/>
5871
<label
5972
className={clsx(
6073
"deriv-input--label",
61-
LabelVariant[error ? "error" : variant]
74+
LabelVariant[error ? "error" : variant],
75+
{
76+
"deriv-input--label__disabled": disabled,
77+
}
6278
)}
6379
htmlFor={id}
6480
>

0 commit comments

Comments
 (0)