-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(SearchBox): Add Search Box (#863)
- Loading branch information
1 parent
f529975
commit 267a7a4
Showing
41 changed files
with
1,454 additions
and
2 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,13 @@ | ||
--- | ||
'@itwin/itwinui-react': minor | ||
--- | ||
|
||
Add `SearchBox` component for your search needs. It can be used as static or expandable version of SearchBox. | ||
|
||
```ts | ||
<SearchBox inputProps={{placeholder:'Basic search'}} /> | ||
<SearchBox expandable inputProps={{placeholder:'Expandable search'}} /> | ||
``` | ||
|
||
`SearchBox` has `SearchBox.Icon`, `SearchBox.Button`, `SearchBox.Input`, `SearchBox.CollapseButton` and `SearchBox.ExpandButton` subcomponents which can be passed as children to customise the look. | ||
|
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,8 @@ | ||
--- | ||
'@itwin/itwinui-css': minor | ||
--- | ||
|
||
- Add `iui-input-flex-container` class for inputs with icons and buttons within | ||
- Add `iui-searchbox` class for Searchbox | ||
- Add `iui-expandable-searchbox` class for Searchbox that can be expanded | ||
- Add `iui-search-icon` for styling icons within 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
Binary file added
BIN
+10.9 KB
...press-visual-screenshots/baseline/SearchBox.test.ts-Basic With Custom Items.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.01 KB
...ook/cypress-visual-screenshots/baseline/SearchBox.test.ts-Basic With Status.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.07 KB
apps/storybook/cypress-visual-screenshots/baseline/SearchBox.test.ts-Basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.42 KB
...ook/cypress-visual-screenshots/baseline/SearchBox.test.ts-Expandable (Open).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.1 KB
...-screenshots/baseline/SearchBox.test.ts-Expandable With Custom Items (Open).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.12 KB
...-visual-screenshots/baseline/SearchBox.test.ts-Expandable With Custom Items.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.12 KB
.../storybook/cypress-visual-screenshots/baseline/SearchBox.test.ts-Expandable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.33 KB
apps/storybook/cypress-visual-screenshots/baseline/SearchBox.test.ts-Small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.98 KB
...ess-visual-screenshots/baseline/SearchBox.test.ts-With Custom Action (Open).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.12 KB
...ok/cypress-visual-screenshots/baseline/SearchBox.test.ts-With Custom Action.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,129 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Bentley Systems, Incorporated. All rights reserved. | ||
* See LICENSE.md in the project root for license terms and full copyright notice. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import { Meta, StoryFn } from '@storybook/react'; | ||
import { action } from '@storybook/addon-actions'; | ||
import React from 'react'; | ||
import { SearchBox, SearchBoxProps, Text, Divider } from '@itwin/itwinui-react'; | ||
import { SvgCaretDownSmall, SvgCaretUpSmall } from '@itwin/itwinui-icons-react'; | ||
|
||
export default { | ||
component: SearchBox, | ||
argTypes: { | ||
className: { control: { disable: true } }, | ||
style: { control: { disable: true } }, | ||
}, | ||
args: { | ||
isDisabled: false, | ||
}, | ||
title: 'Input/SearchBox', | ||
} as Meta<SearchBoxProps>; | ||
|
||
export const Basic: StoryFn<SearchBoxProps> = (args) => { | ||
return <SearchBox inputProps={{ placeholder: 'Basic search' }} {...args} />; | ||
}; | ||
|
||
Basic.args = { | ||
isDisabled: false, | ||
}; | ||
|
||
export const BasicWithCustomItems: StoryFn<SearchBoxProps> = () => { | ||
return ( | ||
<SearchBox> | ||
<SearchBox.Button title='Search button' /> | ||
<SearchBox.Input placeholder='Basic search with custom interactions' /> | ||
<Text | ||
isMuted | ||
variant='body' | ||
as='p' | ||
style={{ paddingRight: 'var(--iui-size-s)', alignSelf: 'center' }} | ||
> | ||
0/3 | ||
</Text> | ||
<Divider orientation='vertical' /> | ||
<SearchBox.Button aria-label='Previous result'> | ||
<SvgCaretUpSmall /> | ||
</SearchBox.Button> | ||
<SearchBox.Button aria-label='Next result'> | ||
<SvgCaretDownSmall /> | ||
</SearchBox.Button> | ||
</SearchBox> | ||
); | ||
}; | ||
|
||
export const BasicWithStatus: StoryFn<SearchBoxProps> = () => { | ||
return ( | ||
<SearchBox | ||
inputProps={{ placeholder: 'Search with warning' }} | ||
status='warning' | ||
/> | ||
); | ||
}; | ||
|
||
export const Expandable: StoryFn<SearchBoxProps> = () => { | ||
return ( | ||
<SearchBox expandable inputProps={{ placeholder: 'Expandable search' }} /> | ||
); | ||
}; | ||
|
||
export const ExpandableWithCustomItems: StoryFn<SearchBoxProps> = () => { | ||
return ( | ||
<SearchBox expandable> | ||
<SearchBox.CollapsedState /> | ||
<SearchBox.ExpandedState> | ||
<SearchBox.Input placeholder='Expandable search with custom interactions' /> | ||
<SearchBox.Button aria-label='Previous result'> | ||
<SvgCaretUpSmall /> | ||
</SearchBox.Button> | ||
<SearchBox.Button aria-label='Next result'> | ||
<SvgCaretDownSmall /> | ||
</SearchBox.Button> | ||
<Divider orientation='vertical' /> | ||
<SearchBox.CollapseButton /> | ||
</SearchBox.ExpandedState> | ||
</SearchBox> | ||
); | ||
}; | ||
|
||
export const Small: StoryFn<SearchBoxProps> = () => { | ||
return <SearchBox size='small' inputProps={{ placeholder: 'Search...' }} />; | ||
}; | ||
|
||
export const WithCustomAction: StoryFn<SearchBoxProps> = () => { | ||
const [expanded, setExpanded] = React.useState(false); | ||
|
||
const handleExpand = () => { | ||
action('Expanding searchbox'); | ||
setExpanded(true); | ||
}; | ||
|
||
const handleCollapse = () => { | ||
action('Collapsing searchbox'); | ||
setExpanded(false); | ||
}; | ||
|
||
return ( | ||
<SearchBox | ||
expandable | ||
isExpanded={expanded} | ||
onExpand={handleExpand} | ||
onCollapse={handleCollapse} | ||
> | ||
<SearchBox.CollapsedState> | ||
<SearchBox.ExpandButton /> | ||
</SearchBox.CollapsedState> | ||
<SearchBox.ExpandedState> | ||
<SearchBox.Input placeholder='Test' /> | ||
<SearchBox.CollapseButton /> | ||
<Divider orientation='vertical' /> | ||
<SearchBox.Button aria-label='Previous result'> | ||
<SvgCaretUpSmall /> | ||
</SearchBox.Button> | ||
<SearchBox.Button aria-label='Next result'> | ||
<SvgCaretDownSmall /> | ||
</SearchBox.Button> | ||
</SearchBox.ExpandedState> | ||
</SearchBox> | ||
); | ||
}; |
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,28 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Bentley Systems, Incorporated. All rights reserved. | ||
* See LICENSE.md in the project root for license terms and full copyright notice. | ||
*--------------------------------------------------------------------------------------------*/ | ||
describe('SearchBox', () => { | ||
const storyPath = 'Input/SearchBox'; | ||
const tests = [ | ||
'Basic', | ||
'Basic With Status', | ||
'Basic With Custom Items', | ||
'Expandable', | ||
'Expandable With Custom Items', | ||
'With Custom Action', | ||
'Small', | ||
]; | ||
|
||
tests.forEach((testName) => { | ||
it(testName, function () { | ||
const id = Cypress.storyId(storyPath, testName); | ||
cy.visit('iframe', { qs: { id } }); | ||
cy.compareSnapshot(testName); | ||
if (!testName.includes('Basic') && testName !== 'Small') { | ||
cy.get('.iui-searchbox-open-button').first().click(); | ||
cy.compareSnapshot(`${testName} (Open)`); | ||
} | ||
}); | ||
}); | ||
}); |
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,46 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Bentley Systems, Incorporated. All rights reserved. | ||
* See LICENSE.md in the project root for license terms and full copyright notice. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import * as React from 'react'; | ||
import { SearchBox, Text, Divider, Flex } from '@itwin/itwinui-react'; | ||
import { SvgCaretUpSmall, SvgCaretDownSmall, SvgCloseSmall } from '@itwin/itwinui-icons-react'; | ||
|
||
export default () => { | ||
return ( | ||
<Flex style={{ width: '70%' }} justifyContent='center' flexDirection='column'> | ||
<SearchBox expandable> | ||
<SearchBox.Input placeholder='Expandable search with custom interactions' /> | ||
<SearchBox.Button label='Previous result'> | ||
<SvgCaretUpSmall /> | ||
</SearchBox.Button> | ||
<SearchBox.Button label='Next result'> | ||
<SvgCaretDownSmall /> | ||
</SearchBox.Button> | ||
<Divider orientation='vertical' /> | ||
<SearchBox.CollapseButton label='Close search' /> | ||
</SearchBox> | ||
<SearchBox> | ||
<SearchBox.Input placeholder='Basic search with custom interactions' /> | ||
<Text | ||
isMuted | ||
variant='body' | ||
as='p' | ||
style={{ paddingRight: 'var(--iui-size-s)', alignSelf: 'center' }} | ||
> | ||
0/3 | ||
</Text> | ||
<Divider orientation='vertical' /> | ||
<SearchBox.Button label='Previous result'> | ||
<SvgCaretUpSmall /> | ||
</SearchBox.Button> | ||
<SearchBox.Button label='Next result'> | ||
<SvgCaretDownSmall /> | ||
</SearchBox.Button> | ||
<SearchBox.Button label='Clear search'> | ||
<SvgCloseSmall /> | ||
</SearchBox.Button> | ||
</SearchBox> | ||
</Flex> | ||
); | ||
}; |
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,32 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Bentley Systems, Incorporated. All rights reserved. | ||
* See LICENSE.md in the project root for license terms and full copyright notice. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import * as React from 'react'; | ||
import { SearchBox, Divider, Flex } from '@itwin/itwinui-react'; | ||
import { SvgCaretUpSmall, SvgCaretDownSmall, SvgAirplane } from '@itwin/itwinui-icons-react'; | ||
|
||
export default () => { | ||
return ( | ||
<Flex style={{ width: '70%' }} justifyContent='center' flexDirection='column'> | ||
<SearchBox | ||
expandable | ||
collapsedState={ | ||
<SearchBox.ExpandButton> | ||
<SvgAirplane /> | ||
</SearchBox.ExpandButton> | ||
} | ||
> | ||
<SearchBox.Input placeholder='Expandable search with custom open icon' /> | ||
<SearchBox.Button label='Previous result'> | ||
<SvgCaretUpSmall /> | ||
</SearchBox.Button> | ||
<SearchBox.Button label='Next result'> | ||
<SvgCaretDownSmall /> | ||
</SearchBox.Button> | ||
<Divider orientation='vertical' /> | ||
<SearchBox.CollapseButton label='Close search' /> | ||
</SearchBox> | ||
</Flex> | ||
); | ||
}; |
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,18 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Bentley Systems, Incorporated. All rights reserved. | ||
* See LICENSE.md in the project root for license terms and full copyright notice. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import * as React from 'react'; | ||
import { SearchBox, Flex } from '@itwin/itwinui-react'; | ||
|
||
export default () => { | ||
return ( | ||
<Flex style={{ width: '70%' }} justifyContent='center'> | ||
<SearchBox | ||
expandable | ||
aria-label='Search input' | ||
inputProps={{ placeholder: 'Expandable search...' }} | ||
/> | ||
</Flex> | ||
); | ||
}; |
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 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Bentley Systems, Incorporated. All rights reserved. | ||
* See LICENSE.md in the project root for license terms and full copyright notice. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import * as React from 'react'; | ||
import { SearchBox, Flex } from '@itwin/itwinui-react'; | ||
|
||
export default () => { | ||
return ( | ||
<Flex style={{ width: '70%' }}> | ||
<SearchBox aria-label='Search input' inputProps={{ placeholder: 'Search...' }} /> | ||
</Flex> | ||
); | ||
}; |
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,15 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Bentley Systems, Incorporated. All rights reserved. | ||
* See LICENSE.md in the project root for license terms and full copyright notice. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import * as React from 'react'; | ||
import { SearchBox, Flex } from '@itwin/itwinui-react'; | ||
|
||
export default () => { | ||
return ( | ||
<Flex style={{ width: '70%' }} flexDirection='column'> | ||
<SearchBox size='small' inputProps={{ placeholder: 'Small search...' }} /> | ||
<SearchBox size='large' inputProps={{ placeholder: 'Large search...' }} /> | ||
</Flex> | ||
); | ||
}; |
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,16 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Bentley Systems, Incorporated. All rights reserved. | ||
* See LICENSE.md in the project root for license terms and full copyright notice. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import * as React from 'react'; | ||
import { SearchBox, Flex } from '@itwin/itwinui-react'; | ||
|
||
export default () => { | ||
return ( | ||
<Flex style={{ width: '70%' }} flexDirection='column'> | ||
<SearchBox status='positive' inputProps={{ placeholder: 'Positive search...' }} /> | ||
<SearchBox status='warning' inputProps={{ placeholder: 'Warning search...' }} /> | ||
<SearchBox status='negative' inputProps={{ placeholder: 'Negative search...' }} /> | ||
</Flex> | ||
); | ||
}; |
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
Binary file added
BIN
+18 KB
...ts/bitmaps_reference/iTwinUI_input_Type_SearchBox_dark_0_demo-search-box_0_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+18.1 KB
...bitmaps_reference/iTwinUI_input_Type_SearchBox_hc_dark_0_demo-search-box_0_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+18.3 KB
...itmaps_reference/iTwinUI_input_Type_SearchBox_hc_light_0_demo-search-box_0_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+18.2 KB
...s/bitmaps_reference/iTwinUI_input_Type_SearchBox_light_0_demo-search-box_0_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.