-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat : implemented typographyWithTextField
- Loading branch information
1 parent
da41413
commit c5d1c73
Showing
4 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
36 changes: 36 additions & 0 deletions
36
frontend/src/components/molecules/TypographyWithTextField/index.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
44 changes: 44 additions & 0 deletions
44
frontend/src/components/molecules/TypographyWithTextField/index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
|
||
}); |
55 changes: 55 additions & 0 deletions
55
frontend/src/components/molecules/TypographyWithTextField/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React from "react"; | ||
import MuiTypography from "../../atoms/typography"; | ||
import CustomTextField from "../../atoms/textfield"; | ||
|
||
|
||
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 | ||
} | ||
|
||
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; |