File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -62,6 +62,7 @@ export { AccessibleList } from "./molecules/accessible-list/accessible-list";
6262export { Card } from "./molecules/cards/card" ;
6363export { DropdownButton } from "./molecules/dropdown-button/dropdown-button" ;
6464export { ErrorBanner } from "./molecules/errors/error-banner" ;
65+ export { Form } from "./molecules/forms/form" ;
6566
6667// Form Fields
6768
Original file line number Diff line number Diff line change 1+ import Faker from "faker" ;
2+ import { Form } from "./form" ;
3+ import React from "react" ;
4+ import { text } from "@storybook/addon-knobs" ;
5+ import { SubmitButton } from "../../atoms/forms/submit-button" ;
6+
7+ export default {
8+ component : Form ,
9+ title : "Molecules | Forms / Form" ,
10+ } ;
11+
12+ const renderChildren = ( ) => (
13+ < React . Fragment >
14+ < div className = "c-form-field" >
15+ < label >
16+ { Faker . hacker . noun ( ) }
17+ < input type = "text" > </ input >
18+ </ label >
19+ </ div >
20+
21+ < SubmitButton />
22+ </ React . Fragment >
23+ ) ;
24+
25+ export const formDefault = ( ) => (
26+ < Form onSubmit = { ( ) => alert ( "form submitted" ) } > { renderChildren ( ) } </ Form >
27+ ) ;
28+
29+ export const formKnobs = ( ) => (
30+ < Form
31+ buttonText = { text ( "buttonText" , "Submit" ) }
32+ cssClassName = { text ( "cssClassName" , "c-form" ) }
33+ onSubmit = { ( ) => alert ( "Form Submitted" ) } >
34+ { renderChildren ( ) }
35+ </ Form >
36+ ) ;
Original file line number Diff line number Diff line change 1+ import React from "react" ;
2+ import { render } from "@testing-library/react" ;
3+ import { Form } from "./form" ;
4+ import faker from "faker" ;
5+
6+ describe ( "Form" , ( ) => {
7+ test ( "when default props, renders children" , ( ) => {
8+ // Arrange
9+ const expected = faker . random . words ( ) ;
10+
11+ // Act
12+ const { getByText } = render (
13+ < Form onSubmit = { ( ) => { } } > { expected } </ Form >
14+ ) ;
15+
16+ // Assert
17+ expect ( getByText ( expected ) ) . not . toBeNull ( ) ;
18+ } ) ;
19+ } ) ;
Original file line number Diff line number Diff line change 1+ import * as React from "react" ;
2+ import { PropsWithChildren } from "react" ;
3+
4+ const COMPONENT_CLASS = "c-form" ;
5+
6+ interface FormProps {
7+ action ?: string ;
8+ buttonText ?: string ;
9+ cssClassName ?: string ;
10+ id ?: string ;
11+ method ?: string ;
12+ onSubmit : ( e : React . FormEvent < HTMLFormElement > ) => void ;
13+ }
14+
15+ const Form : React . FC < FormProps > = ( props : PropsWithChildren < FormProps > ) => (
16+ < form
17+ action = { props . action }
18+ className = { props . cssClassName ?? COMPONENT_CLASS }
19+ id = { props . id }
20+ method = { props . method }
21+ onSubmit = { props . onSubmit } >
22+ { props . children }
23+ </ form >
24+ ) ;
25+
26+ export { Form } ;
You can’t perform that action at this time.
0 commit comments