From a414ac32ce964459b4aae4f901065a9a1cbd5ed2 Mon Sep 17 00:00:00 2001 From: Anand Bhupathi Medarametla Date: Mon, 30 Sep 2024 15:05:43 +1000 Subject: [PATCH] signup component --- src/components/Signup/Signup.stories.ts | 37 ++++++++++ src/components/Signup/Signup.style.ts | 53 ++++++++++++++ src/components/Signup/Signup.test.tsx | 13 ++++ src/components/Signup/Signup.tsx | 95 +++++++++++++++++++++++++ 4 files changed, 198 insertions(+) create mode 100644 src/components/Signup/Signup.stories.ts create mode 100644 src/components/Signup/Signup.style.ts create mode 100644 src/components/Signup/Signup.test.tsx create mode 100644 src/components/Signup/Signup.tsx diff --git a/src/components/Signup/Signup.stories.ts b/src/components/Signup/Signup.stories.ts new file mode 100644 index 0000000..08a5927 --- /dev/null +++ b/src/components/Signup/Signup.stories.ts @@ -0,0 +1,37 @@ +import { Signup } from './Signup'; +import type { Meta, StoryObj } from '@storybook/react'; + +const meta = { + title: 'Components/Signup', + component: Signup, +} satisfies Meta; + +export default meta; +type Story = StoryObj; + +const defaultProps = {}; + +const disableControls = { + parameters: { + controls: { + disable: true, + }, + actions: { + disable: true, + }, + }, +}; + +export const Demo: Story = { + args: { + ...defaultProps, + }, + tags: ['excludeFromSidebar'], +}; + +export const Default: Story = { + args: { + ...defaultProps, + }, + ...disableControls, +}; diff --git a/src/components/Signup/Signup.style.ts b/src/components/Signup/Signup.style.ts new file mode 100644 index 0000000..2623889 --- /dev/null +++ b/src/components/Signup/Signup.style.ts @@ -0,0 +1,53 @@ +import styled from 'styled-components'; + +export const StyledSignup = styled.div` + display: flex; + flex-direction: column; + align-items: center; +`; + +export const ModalOverlay = styled.div` + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; + background: rgba(0, 0, 0, 0.5); + display: flex; + justify-content: center; + align-items: center; +`; + +export const StyledModal = styled.div` + background: white; + padding: 20px; + border-radius: 8px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); +`; + +export const CloseButton = styled.button` + margin-top: 10px; + padding: 5px 10px; + background-color: #007bff; + color: white; + border: none; + border-radius: 5px; + cursor: pointer; + + &:hover { + background-color: #0056b3; + } +`; + +export const Form = styled.form` + display: flex; + flex-direction: column; + gap: 10px; +`; + +export const Input = styled.input` + padding: 8px; + border: 1px solid #ccc; + border-radius: 4px; + width: 300px; +`; diff --git a/src/components/Signup/Signup.test.tsx b/src/components/Signup/Signup.test.tsx new file mode 100644 index 0000000..834a3b4 --- /dev/null +++ b/src/components/Signup/Signup.test.tsx @@ -0,0 +1,13 @@ +import { screen } from '@testing-library/react'; +import { renderWithDeps } from '../../../jest.utils.tsx'; +import Signup from './Signup'; + +describe('', () => { + it('renders', () => { + renderWithDeps(); + + const signup = screen.getByTestId('Signup'); + + expect(signup).toBeInTheDocument(); + }); +}); diff --git a/src/components/Signup/Signup.tsx b/src/components/Signup/Signup.tsx new file mode 100644 index 0000000..0735908 --- /dev/null +++ b/src/components/Signup/Signup.tsx @@ -0,0 +1,95 @@ +import { FC, useState } from 'react'; +import { + StyledSignup, + ModalOverlay, + StyledModal, + CloseButton, + Form, + Input, +} from './Signup.style'; + +type SignupProps = {}; + +export const Signup: FC = () => { + const [isModalOpen, setModalOpen] = useState(false); + const [formData, setFormData] = useState({ + username: '', + email: '', + phone: '', + password: '', + }); + + const handleChange = (e: React.ChangeEvent) => { + const { name, value } = e.target; + setFormData((prevData) => ({ + ...prevData, + [name]: value, + })); + }; + + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault(); + setModalOpen(true); + }; + + const handleCloseModal = () => { + setModalOpen(false); + setFormData({ + username: '', + email: '', + phone: '', + password: '', + }); + }; + + return ( + +

Sign Up

+
+ + + + + +
+ + {isModalOpen && ( + + +

Signup Successful

+

Thank you for signing up!

+ Close +
+
+ )} +
+ ); +};