Skip to content

Commit

Permalink
feat(searchbar): add SearchBar component
Browse files Browse the repository at this point in the history
  • Loading branch information
jinlee93 authored Aug 31, 2022
2 parents 7d3fb43 + 033c282 commit 70457d8
Show file tree
Hide file tree
Showing 16 changed files with 504 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/components/SearchBar/SearchBar.module.css
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);
}
78 changes: 78 additions & 0 deletions src/components/SearchBar/SearchBar.stories.tsx
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} />,
};
6 changes: 6 additions & 0 deletions src/components/SearchBar/SearchBar.test.tsx
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);
});
34 changes: 34 additions & 0 deletions src/components/SearchBar/SearchBar.tsx
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 src/components/SearchBar/__snapshots__/SearchBar.test.tsx.snap
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>
`;
1 change: 1 addition & 0 deletions src/components/SearchBar/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { SearchBar as default } from './SearchBar';
14 changes: 14 additions & 0 deletions src/components/SearchButton/SearchButton.module.css
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;
}
Loading

0 comments on commit 70457d8

Please sign in to comment.