Skip to content

✨ feat : implemented typographyWithTextField #10

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Meta, StoryObj } from '@storybook/react';
import TypographyWithTextField from "./index";

const meta: Meta<typeof TypographyWithTextField> = {
title: "molecules/TypographyWithTextField",
component: TypographyWithTextField,
argTypes: {
label: { control: 'text' },
color: { control: 'color' },
placeholder: { control: 'text' },
value: { control: 'text' },
onChange: { action: 'onChange' },
isPassword: { control: 'boolean' },
width: { control: 'text' },
height: { control: 'text' },
size: { control: 'select', options: ['small', 'medium'] },
borderRadius: { control: 'text' },
},
};

export const Default: StoryObj<typeof TypographyWithTextField> = {
args: {
label: "Password",
color: "#344054",
placeholder: "Enter your Password",
value: "",
onChange: () => console.log("onChange triggered"),
isPassword: true,
width: "50%",
height: "40px",
size: "small",
borderRadius: "8px",
},
};

export default meta;
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { render, fireEvent } from "@testing-library/react";
import TypographyWithTextField from "./index";

describe("TypographyWithTextField", () => {
const label = "Label";
const color = "red";
const placeholder = "Placeholder";
let value = "";
const onChange = jest.fn();
const isPassword = false;
const width = "200px";
const height = 40;
const size = "medium";
const borderRadius = "8px";
const variant = "body1";

beforeEach(() => {
onChange.mockClear();
value = "";
});

it("calls onChange when input value changes", () => {
const { getByPlaceholderText } = render(
<TypographyWithTextField
label={label}
color={color}
placeholder={placeholder}
value={value}
onChange={onChange}
isPassword={isPassword}
width={width}
height={height}
size={size}
borderRadius={borderRadius}
variant={variant}
/>
);
const textFieldElement = getByPlaceholderText(placeholder);
fireEvent.change(textFieldElement, { target: { value: "New Value" } });
expect(onChange).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenCalledWith("New Value");
});

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from "react";
import CustomTextField from "../../atoms/Textfield";
import MuiTypography from "../../atoms/Typography";
import { TypographyWithTextFieldProps } from "../../../utils/interfaces";

const TypographyWithTextField: React.FC<TypographyWithTextFieldProps> = ({
label,
placeholder,
value,
onChange,
isPassword,
color,
width,
height,
size,
borderRadius,
variant,
}) => {
return (
<>
<MuiTypography
variant={variant}
text={label}
color={color}
sx={{ marginBottom: "-10px" }}
/>
<CustomTextField
placeholder={placeholder}
value={value}
onChange={onChange}
isPassword={isPassword}
width={width}
height={height}
size={size}
borderRadius={borderRadius}

/>
</>
);
};

export default TypographyWithTextField;
20 changes: 17 additions & 3 deletions frontend/src/utils/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,23 @@ import { ButtonProps, TypographyProps } from "@mui/material";
import { ReactNode } from "react";

export interface SocialLoginProps {
text: string;
src: string;
}
text: string;
src: string;
}

export interface TypographyWithTextFieldProps {
label: string;
color: string;
placeholder: string;
value: string;
onChange: (value: string) => void;
isPassword: boolean;
width?: string;
height?: string | number;
size?: "small" | "medium";
borderRadius?: string | number;
variant:any
}
export interface ButtonPropsInterface extends ButtonProps { }

export interface IconComponentProps {
Expand Down