-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
31fc7ff
commit c02e145
Showing
15 changed files
with
218 additions
and
105 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 |
---|---|---|
@@ -1,82 +1,11 @@ | ||
import React from 'react'; | ||
import {PlusCircleIcon} from '@shopify/polaris-icons'; | ||
|
||
import {BlockStack, Card, Layout, Page, Picker, Text} from '../src'; | ||
import {Page} from '../src'; | ||
|
||
export function Playground() { | ||
const [selected, setSelected] = React.useState(''); | ||
const options = [ | ||
{ | ||
value: '012345678', | ||
children: 'Burberry', | ||
}, | ||
{ | ||
value: '123456789', | ||
children: 'Chanel', | ||
}, | ||
{ | ||
value: '234567890', | ||
children: 'Dior', | ||
}, | ||
{ | ||
value: '345678901', | ||
children: 'Gucci', | ||
}, | ||
{ | ||
value: '456789012', | ||
children: 'Hermès', | ||
}, | ||
{ | ||
value: '567890123', | ||
children: 'Louis Vuitton', | ||
}, | ||
{ | ||
value: '678901234', | ||
children: <span>Prada</span>, | ||
}, | ||
{ | ||
value: '789012345', | ||
children: <div>Versace</div>, | ||
}, | ||
]; | ||
|
||
return ( | ||
<Page title="Playground"> | ||
{/* Add the code you want to test in here */} | ||
<Layout> | ||
<Layout.Section> | ||
<h1>Playground</h1> | ||
</Layout.Section> | ||
<Layout.Section variant="oneThird"> | ||
<Card> | ||
<BlockStack gap="200"> | ||
<Text as="h3">Organization</Text> | ||
<Picker | ||
searchField={{ | ||
label: 'Search for a product', | ||
placeholder: 'Search for a product', | ||
autoComplete: 'off', | ||
onChange: (value) => console.log(value), | ||
}} | ||
activator={{ | ||
label: 'Product', | ||
placeholder: 'Select a product', | ||
}} | ||
options={options} | ||
onSelect={setSelected} | ||
addAction={{ | ||
value: 'addy', | ||
children: 'Add product', | ||
icon: PlusCircleIcon, | ||
}} | ||
/> | ||
<ul> | ||
<li>Selected: {selected}</li> | ||
</ul> | ||
</BlockStack> | ||
</Card> | ||
</Layout.Section> | ||
</Layout> | ||
</Page> | ||
); | ||
} |
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
25 changes: 25 additions & 0 deletions
25
polaris-react/src/components/Picker/components/Activator/tests/Activator.test.tsx
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,25 @@ | ||
import React from 'react'; | ||
import {mountWithApp} from 'tests/utilities'; | ||
|
||
import {Activator} from '../Activator'; | ||
import {UnstyledButton} from '../../../../UnstyledButton'; | ||
|
||
describe('<Activator />', () => { | ||
it('renders a label', () => { | ||
const activator = mountWithApp(<Activator label="label" />); | ||
|
||
expect(activator).toContainReactText('label'); | ||
}); | ||
|
||
it('renders a placeholder', () => { | ||
const activator = mountWithApp(<Activator placeholder="placeholder" />); | ||
|
||
expect(activator).toContainReactText('placeholder'); | ||
}); | ||
|
||
it('renders a disabled activator', () => { | ||
const activator = mountWithApp(<Activator disabled />); | ||
|
||
expect(activator).toContainReactComponent(UnstyledButton, {disabled: true}); | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
...components/TextField/TextField.module.css → ...onents/SearchField/SearchField.module.css
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.TextField { | ||
.SearchField { | ||
flex-grow: 1; | ||
padding: var(--p-space-100) 0; | ||
outline: none; | ||
|
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
1 change: 1 addition & 0 deletions
1
polaris-react/src/components/Picker/components/SearchField/index.ts
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 {SearchField} from './SearchField'; |
73 changes: 73 additions & 0 deletions
73
polaris-react/src/components/Picker/components/SearchField/tests/SearchField.test.tsx
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,73 @@ | ||
import React from 'react'; | ||
import {mountWithApp} from 'tests/utilities'; | ||
|
||
import {SearchField} from '../SearchField'; | ||
import {Label} from '../../../../Label'; | ||
import type {ComboboxTextFieldType} from '../../../../../utilities/combobox'; | ||
import {ComboboxTextFieldContext} from '../../../../../utilities/combobox'; | ||
import type {TextFieldProps} from '../../../../TextField'; | ||
|
||
function mountWithProvider( | ||
props: { | ||
textFieldProps?: Partial<TextFieldProps>; | ||
textFieldProviderValue?: Partial<ComboboxTextFieldType>; | ||
} = {}, | ||
) { | ||
const textField = mountWithApp( | ||
<ComboboxTextFieldContext.Provider | ||
value={{...props.textFieldProviderValue}} | ||
> | ||
<SearchField | ||
label="label" | ||
onChange={noop} | ||
autoComplete="off" | ||
{...props.textFieldProps} | ||
/> | ||
</ComboboxTextFieldContext.Provider>, | ||
); | ||
|
||
return textField; | ||
} | ||
|
||
describe('<TextField />', () => { | ||
it('renders a label', () => { | ||
const picker = mountWithProvider({ | ||
textFieldProps: { | ||
label: 'Field', | ||
}, | ||
}); | ||
|
||
expect(picker).toContainReactComponent(Label, {children: 'Field'}); | ||
}); | ||
|
||
it('renders a prefix', () => { | ||
const picker = mountWithProvider({ | ||
textFieldProps: { | ||
prefix: <div>Prefix</div>, | ||
}, | ||
}); | ||
|
||
expect(picker).toContainReactComponent('div', {children: 'Prefix'}); | ||
}); | ||
|
||
it('renders accessibility attributes', () => { | ||
const picker = mountWithProvider({ | ||
textFieldProviderValue: { | ||
activeOptionId: 'option1', | ||
listboxId: 'listbox1', | ||
setTextFieldLabelId: () => 'TextFieldLabel', | ||
}, | ||
}); | ||
|
||
expect(picker).toContainReactComponent('input', { | ||
role: 'combobox', | ||
'aria-activedescendant': 'option1', | ||
'aria-haspopup': 'listbox', | ||
'aria-autocomplete': 'list', | ||
'aria-expanded': 'true', | ||
'aria-controls': 'listbox1', | ||
}); | ||
}); | ||
}); | ||
|
||
function noop() {} |
1 change: 0 additions & 1 deletion
1
polaris-react/src/components/Picker/components/TextField/index.ts
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export {TextField} from './TextField'; | ||
export {SearchField} from './SearchField'; | ||
export * from './Activator'; |
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 |
---|---|---|
@@ -1,2 +1 @@ | ||
export * from './Picker'; | ||
export {TextField as PickerTextField} from './components'; |
Oops, something went wrong.