-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(searchbar): add SearchBar component
- Loading branch information
Showing
16 changed files
with
504 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/*------------------------------------*\ | ||
# SEARCH FIELD | ||
\*------------------------------------*/ | ||
|
||
/** | ||
* Search bar wrapper for the SearchField and SearchButton | ||
*/ | ||
.search-bar { | ||
display: flex; | ||
gap: var(--eds-size-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,78 @@ | ||
import { BADGE } from '@geometricpanda/storybook-addon-badges'; | ||
import { StoryObj, Meta } from '@storybook/react'; | ||
import React from 'react'; | ||
|
||
import { SearchBar } from '../SearchBar/SearchBar'; | ||
|
||
export default { | ||
title: 'Organisms/Interactive/SearchBar', | ||
component: SearchBar, | ||
parameters: { | ||
badges: [BADGE.BETA], | ||
}, | ||
decorators: [ | ||
(Story) => ( | ||
<div style={{ padding: '0.5rem', backgroundColor: 'white' }}> | ||
<Story /> | ||
</div> | ||
), | ||
], | ||
} as Meta<Args>; | ||
|
||
type Args = React.ComponentProps<typeof SearchBar>; | ||
|
||
export const Default: StoryObj<Args> = { | ||
args: { | ||
children: ( | ||
<> | ||
<SearchBar.InputField /> | ||
<SearchBar.Button /> | ||
</> | ||
), | ||
}, | ||
}; | ||
|
||
export const Disabled: StoryObj<Args> = { | ||
args: { | ||
children: ( | ||
<> | ||
<SearchBar.InputField disabled /> | ||
<SearchBar.Button disabled /> | ||
</> | ||
), | ||
}, | ||
parameters: { | ||
axe: { | ||
disabledRules: ['color-contrast'], | ||
}, | ||
}, | ||
}; | ||
|
||
export const Custom: StoryObj<Args> = { | ||
render: () => ( | ||
<> | ||
<div style={{ marginBottom: '1rem' }}> | ||
<SearchBar.Button /> | ||
<SearchBar.InputField /> | ||
</div> | ||
<div> | ||
<SearchBar.InputField /> | ||
<SearchBar.Button /> | ||
</div> | ||
</> | ||
), | ||
}; | ||
|
||
export const SearchField: StoryObj< | ||
React.ComponentProps<typeof SearchBar.InputField> | ||
> = { | ||
argTypes: { onChange: { action: 'onChange' } }, | ||
render: (args) => <SearchBar.InputField {...args} />, | ||
}; | ||
|
||
export const SearchButton: StoryObj< | ||
React.ComponentProps<typeof SearchBar.Button> | ||
> = { | ||
argTypes: { onClick: { action: 'onClick' } }, | ||
render: (args) => <SearchBar.Button {...args} />, | ||
}; |
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,6 @@ | ||
import { generateSnapshots } from '@chanzuckerberg/story-utils'; | ||
import * as stories from './SearchBar.stories'; | ||
|
||
describe('<SearchField />', () => { | ||
generateSnapshots(stories); | ||
}); |
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,34 @@ | ||
import clsx from 'clsx'; | ||
import React, { ReactNode } from 'react'; | ||
import styles from './SearchBar.module.css'; | ||
import SearchButton from '../SearchButton'; | ||
import SearchField from '../SearchField'; | ||
|
||
export type Props = { | ||
/** | ||
* SearchBar subcomponents to be wrapped. | ||
*/ | ||
children: ReactNode; | ||
/** | ||
* CSS class names that can be appended to the component. | ||
*/ | ||
className?: string; | ||
}; | ||
|
||
/** | ||
* BETA: This component is still a work in progress and is subject to change. | ||
* | ||
* ```ts | ||
* import {SearchBar} from "@chanzuckerberg/eds"; | ||
* ``` | ||
* | ||
* Input field and button used for searching through various data fields. | ||
*/ | ||
export const SearchBar = ({ children, className }: Props) => { | ||
const componentClassName = clsx(styles['search-bar'], className); | ||
|
||
return <div className={componentClassName}>{children}</div>; | ||
}; | ||
|
||
SearchBar.InputField = SearchField; | ||
SearchBar.Button = SearchButton; |
223 changes: 223 additions & 0 deletions
223
src/components/SearchBar/__snapshots__/SearchBar.test.tsx.snap
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,223 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<SearchField /> Custom story renders snapshot 1`] = ` | ||
<div | ||
style="padding: 0.5rem; background-color: white;" | ||
> | ||
<div | ||
style="margin-bottom: 1rem;" | ||
> | ||
<button | ||
class="clickable-style clickable-style--lg clickable-style--primary clickable-style--brand button button--primary search-button" | ||
data-bootstrap-override="clickable-style-primary" | ||
type="button" | ||
> | ||
Search | ||
</button> | ||
<div | ||
class="search-field" | ||
> | ||
<input | ||
class="text-input search-field__input" | ||
placeholder="Search" | ||
type="search" | ||
/> | ||
<svg | ||
class="icon search-field__icon" | ||
fill="currentColor" | ||
height="1.25rem" | ||
role="img" | ||
style="--icon-size: 1.25rem;" | ||
width="1.25rem" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<title | ||
id="3" | ||
> | ||
search | ||
</title> | ||
<use | ||
xlink:href="test-file-stub#search" | ||
/> | ||
</svg> | ||
</div> | ||
</div> | ||
<div> | ||
<div | ||
class="search-field" | ||
> | ||
<input | ||
class="text-input search-field__input" | ||
placeholder="Search" | ||
type="search" | ||
/> | ||
<svg | ||
class="icon search-field__icon" | ||
fill="currentColor" | ||
height="1.25rem" | ||
role="img" | ||
style="--icon-size: 1.25rem;" | ||
width="1.25rem" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<title | ||
id="4" | ||
> | ||
search | ||
</title> | ||
<use | ||
xlink:href="test-file-stub#search" | ||
/> | ||
</svg> | ||
</div> | ||
<button | ||
class="clickable-style clickable-style--lg clickable-style--primary clickable-style--brand button button--primary search-button" | ||
data-bootstrap-override="clickable-style-primary" | ||
type="button" | ||
> | ||
Search | ||
</button> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`<SearchField /> Default story renders snapshot 1`] = ` | ||
<div | ||
style="padding: 0.5rem; background-color: white;" | ||
> | ||
<div | ||
class="search-bar" | ||
> | ||
<div | ||
class="search-field" | ||
> | ||
<input | ||
class="text-input search-field__input" | ||
placeholder="Search" | ||
type="search" | ||
/> | ||
<svg | ||
class="icon search-field__icon" | ||
fill="currentColor" | ||
height="1.25rem" | ||
role="img" | ||
style="--icon-size: 1.25rem;" | ||
width="1.25rem" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<title | ||
id="1" | ||
> | ||
search | ||
</title> | ||
<use | ||
xlink:href="test-file-stub#search" | ||
/> | ||
</svg> | ||
</div> | ||
<button | ||
class="clickable-style clickable-style--lg clickable-style--primary clickable-style--brand button button--primary search-button" | ||
data-bootstrap-override="clickable-style-primary" | ||
type="button" | ||
> | ||
Search | ||
</button> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`<SearchField /> Disabled story renders snapshot 1`] = ` | ||
<div | ||
style="padding: 0.5rem; background-color: white;" | ||
> | ||
<div | ||
class="search-bar" | ||
> | ||
<div | ||
class="search-field" | ||
> | ||
<input | ||
class="text-input search-field__input" | ||
disabled="" | ||
placeholder="Search" | ||
type="search" | ||
/> | ||
<svg | ||
class="icon search-field__icon search-field__icon--disabled" | ||
fill="currentColor" | ||
height="1.25rem" | ||
role="img" | ||
style="--icon-size: 1.25rem;" | ||
width="1.25rem" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<title | ||
id="2" | ||
> | ||
search | ||
</title> | ||
<use | ||
xlink:href="test-file-stub#search" | ||
/> | ||
</svg> | ||
</div> | ||
<button | ||
class="clickable-style clickable-style--lg clickable-style--primary clickable-style--brand button button--primary button--disabled search-button" | ||
data-bootstrap-override="clickable-style-primary" | ||
disabled="" | ||
tabindex="-1" | ||
type="button" | ||
> | ||
Search | ||
</button> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`<SearchField /> SearchButton story renders snapshot 1`] = ` | ||
<div | ||
style="padding: 0.5rem; background-color: white;" | ||
> | ||
<button | ||
class="clickable-style clickable-style--lg clickable-style--primary clickable-style--brand button button--primary search-button" | ||
data-bootstrap-override="clickable-style-primary" | ||
type="button" | ||
> | ||
Search | ||
</button> | ||
</div> | ||
`; | ||
|
||
exports[`<SearchField /> SearchField story renders snapshot 1`] = ` | ||
<div | ||
style="padding: 0.5rem; background-color: white;" | ||
> | ||
<div | ||
class="search-field" | ||
> | ||
<input | ||
class="text-input search-field__input" | ||
placeholder="Search" | ||
type="search" | ||
/> | ||
<svg | ||
class="icon search-field__icon" | ||
fill="currentColor" | ||
height="1.25rem" | ||
role="img" | ||
style="--icon-size: 1.25rem;" | ||
width="1.25rem" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<title | ||
id="5" | ||
> | ||
search | ||
</title> | ||
<use | ||
xlink:href="test-file-stub#search" | ||
/> | ||
</svg> | ||
</div> | ||
</div> | ||
`; |
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 @@ | ||
export { SearchBar as default } from './SearchBar'; |
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,14 @@ | ||
/*------------------------------------*\ | ||
# SEARCH BUTTON | ||
\*------------------------------------*/ | ||
|
||
/** | ||
* Button to trigger search in a Search Bar. | ||
*/ | ||
.search-button { | ||
padding-top: 1px; | ||
padding-bottom: 1px; | ||
height: var(--eds-size-5); | ||
box-sizing: content-box; | ||
border: 0; | ||
} |
Oops, something went wrong.