Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aizad/ Adding Storybook to Input component #54

Merged
merged 3 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/components/Input/HelperMessage.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ $error_field: #ec3f3f;
font-style: normal;
font-weight: 400;
line-height: 18px;
color: $inactive_color;
&--general {
color: $inactive_color;
}
Expand Down
6 changes: 6 additions & 0 deletions lib/components/Input/Input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ $border: 1px solid;
}
}

.deriv-input--general .deriv-input__field:disabled + .deriv-input__label,
.deriv-input--error .deriv-input__field:disabled + .deriv-input__label,
.deriv-input--success .deriv-input__field:disabled + .deriv-input__label {
color: $disabled_color;
}

.deriv-input--general .deriv-input__field:focus + .deriv-input__label {
color: $active_color;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/components/Input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ export type InputVariants =
| "error"
| "warning"
| "disabled";
interface InputProps
extends Omit<ComponentProps<"input">, "style" | "placeholder"> {
interface InputProps extends Omit<ComponentProps<"input">, "placeholder"> {
label?: string;
leftPlaceholder?: ReactNode;
rightPlaceholder?: ReactNode;
Expand Down
179 changes: 179 additions & 0 deletions src/stories/Input.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
import { StoryObj, Meta } from "@storybook/react";
import { Input } from "../../lib/main";
import { useState } from "react";

const meta = {
title: "Components/Input",
component: Input,
parameters: { layout: "centered" },
tags: ["autodocs"],
args: {
label: "Enter Password",
value: "",
variant: "general",
message: "This is a helper message",
error: false,
disabled: false,
},
argTypes: {
leftPlaceholder: {
control: {
disable: true,
},
},
rightPlaceholder: {
control: {
disable: true,
},
},
value: {
control: {
disable: true,
},
},
variant: {
options: ["general", "success", "warning", "error"],
control: {
type: "select",
},
},
message: {
control: {
type: "text",
},
},
error: {
control: {
type: "boolean",
},
},
},
} satisfies Meta<typeof Input>;

export default meta;
type Story = StoryObj<typeof meta>;

export const Default: Story = {
name: "Default Input",
args: {
label: "Enter name",
value: "",
message: "This is a helper message",
},
render: (args) => {
const [value, setValue] = useState("");

return (
<Input
{...args}
value={value}
onChange={(e) => setValue(e.target.value)}
/>
);
},
};

export const Disabled: Story = {
name: "Disabled Input",
args: {
label: "Enter name",
value: "",
message: "This is a helper message",
disabled: true,
},
render: (args) => {
const [value, setValue] = useState("");

return (
<Input
{...args}
value={value}
onChange={(e) => setValue(e.target.value)}
/>
);
},
};

export const Success: Story = {
name: "Success Input",
args: {
label: "Enter name",
value: "",
message: "This is a helper message",
variant: "success",
},
render: (args) => {
const [value, setValue] = useState("");

return (
<Input
{...args}
value={value}
onChange={(e) => setValue(e.target.value)}
/>
);
},
};

export const Error: Story = {
name: "Error Input",
args: {
label: "Enter name",
value: "",
message: "This is a helper message",
variant: "error",
},
render: (args) => {
const [value, setValue] = useState("");

return (
<Input
{...args}
value={value}
onChange={(e) => setValue(e.target.value)}
/>
);
},
};

export const Warning: Story = {
name: "Error Input",
args: {
label: "Enter name",
value: "",
message: "This is a helper message",
variant: "warning",
},
render: (args) => {
const [value, setValue] = useState("");

return (
<Input
{...args}
value={value}
onChange={(e) => setValue(e.target.value)}
/>
);
},
};

export const RightPlaceholder: Story = {
name: "Input with Right Placeholder",
args: {
label: "Enter name",
value: "",
message: "This is a helper message",
rightPlaceholder: "USD",
},
render: (args) => {
const [value, setValue] = useState("");

return (
<Input
{...args}
value={value}
onChange={(e) => setValue(e.target.value)}
/>
);
},
};