Skip to content

Commit

Permalink
Merge pull request #54 from deriv-com/aizad/storybook-input
Browse files Browse the repository at this point in the history
Aizad/ Adding Storybook to Input component
  • Loading branch information
shayan-deriv authored Feb 2, 2024
2 parents 7ca4fee + fd763aa commit f757f4e
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 2 deletions.
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)}
/>
);
},
};

0 comments on commit f757f4e

Please sign in to comment.