This repository has been archived by the owner on Jun 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FSSS-164] Extract UISelect from Sort to its own component (#299)
* Extract UISelect from Sort to its own component * Rename data-ui-select to data-select * Change attribute className to classes * Remove whitespace * Remove aria-label property from Sort * Make 'id' a required attribute for Select * Change 'SelectOptions' type to Record * Use className attribute instead of classes Co-authored-by: Fanny Chien <fannychienn@gmail.com>
- Loading branch information
1 parent
b866a61
commit 5158652
Showing
4 changed files
with
68 additions
and
22 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,56 @@ | ||
import React from 'react' | ||
import { Select as UISelect } from '@faststore/ui' | ||
import type { SelectProps } from '@faststore/ui' | ||
import { CaretDown as CaretDownIcon } from 'phosphor-react' | ||
|
||
import './select.scss' | ||
|
||
interface UISelectProps extends SelectProps { | ||
/* | ||
* Redefines the id property to be required when using the Select component. The | ||
* id will be used to link the UISelect component and its label. | ||
*/ | ||
id: string | ||
/* | ||
* Defines the options available in the select. The SelectOptions object | ||
* keys are the property names, while the values correspond to the text that | ||
* will be displayed in the UI | ||
*/ | ||
options: Record<string, string> | ||
/* | ||
* Specifies the text that will be displayed in the label right next to the Select. | ||
* If omitted, the label will not be rendered. | ||
*/ | ||
labelText?: string | ||
} | ||
|
||
export default function Select({ | ||
id, | ||
className, | ||
options, | ||
onChange, | ||
labelText, | ||
value, | ||
'aria-label': ariaLabel, | ||
testId, | ||
}: UISelectProps) { | ||
return ( | ||
<div data-select className={className}> | ||
{labelText && <label htmlFor={id}>{labelText}</label>} | ||
<UISelect | ||
data-testid={testId} | ||
onChange={onChange} | ||
value={value} | ||
aria-label={ariaLabel} | ||
id={id} | ||
> | ||
{Object.keys(options).map((key) => ( | ||
<option key={key} value={key}> | ||
{options[key]} | ||
</option> | ||
))} | ||
</UISelect> | ||
<CaretDownIcon size={18} weight="bold" /> | ||
</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 { default } from './Select' |
2 changes: 1 addition & 1 deletion
2
src/components/search/Sort/sort.scss → src/components/ui/Select/select.scss
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