-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into em-create-header-component-#83
- Loading branch information
Showing
6 changed files
with
124 additions
and
6 deletions.
There are no files selected for viewing
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
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,29 @@ | ||
import React from 'react' | ||
import { Search } from './Search' | ||
|
||
export default { | ||
title: 'Search', | ||
parameters: { | ||
info: ` | ||
USWDS 2.0 Search component | ||
Source: https://designsystem.digital.gov/components/header/ | ||
`, | ||
}, | ||
} | ||
|
||
const mockSubmit = (): void => { | ||
/* mock submit fn */ | ||
} | ||
|
||
export const defaultSearch = (): React.ReactElement => ( | ||
<Search onSubmit={mockSubmit} /> | ||
) | ||
|
||
export const bigSearch = (): React.ReactElement => ( | ||
<Search big onSubmit={mockSubmit} /> | ||
) | ||
|
||
export const smallSearch = (): React.ReactElement => ( | ||
<Search small onSubmit={mockSubmit} /> | ||
) |
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,20 @@ | ||
import React from 'react' | ||
import { render, fireEvent } from '@testing-library/react' | ||
|
||
import { Search } from './Search' | ||
|
||
describe('Search component', () => { | ||
it('renders without errors', () => { | ||
const mockSubmit = jest.fn() | ||
const { queryByTestId } = render(<Search onSubmit={mockSubmit}></Search>) | ||
expect(queryByTestId('textInput')).toBeInTheDocument() | ||
}) | ||
|
||
it('implements an onSubmit handler', () => { | ||
const mockSubmit = jest.fn() | ||
const { getByTestId } = render(<Search onSubmit={mockSubmit}></Search>) | ||
|
||
fireEvent.submit(getByTestId('textInput')) | ||
expect(mockSubmit).toHaveBeenCalledTimes(1) | ||
}) | ||
}) |
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,57 @@ | ||
import React from 'react' | ||
import classnames from 'classnames' | ||
|
||
import { Button } from '../Button/Button' | ||
import { Form } from '../forms/Form/Form' | ||
import { Label } from '../forms/Label/Label' | ||
import { TextInput } from '../forms/TextInput/TextInput' | ||
|
||
interface SearchInputProps { | ||
onSubmit: (event: React.FormEvent<HTMLFormElement>) => void | ||
big?: boolean | ||
small?: boolean | ||
label?: React.ReactNode | ||
className?: string | ||
} | ||
|
||
export const Search = ( | ||
props: SearchInputProps & React.FormHTMLAttributes<HTMLFormElement> | ||
): React.ReactElement => { | ||
const { | ||
onSubmit, | ||
big, | ||
small, | ||
label = 'Search', | ||
className, | ||
...formProps | ||
} = props | ||
const classes = classnames( | ||
'usa-search', | ||
{ | ||
'usa-search--small': small, | ||
'usa-search--big': big, | ||
}, | ||
className | ||
) | ||
|
||
return ( | ||
<Form | ||
onSubmit={onSubmit} | ||
className={classes} | ||
role="search" | ||
search={true} | ||
{...formProps}> | ||
<Label srOnly={true} htmlFor="search-field"> | ||
{label} | ||
</Label> | ||
<TextInput id="search-field" type="search" name="search" /> | ||
<Button type="submit"> | ||
<span className={small ? 'usa-sr-only' : 'usa-search__submit-text'}> | ||
Search | ||
</span> | ||
</Button> | ||
</Form> | ||
) | ||
} | ||
|
||
export default Search |
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
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