From 662a7760183499d860ff9d2060007eaf9710ab32 Mon Sep 17 00:00:00 2001 From: Heitor Carvalho Date: Tue, 1 Feb 2022 23:47:59 -0300 Subject: [PATCH 1/8] Extract UISelect from Sort to its own component --- src/components/search/Sort/Sort.tsx | 31 ++++------- src/components/ui/Select/Select.tsx | 54 +++++++++++++++++++ src/components/ui/Select/index.tsx | 1 + .../Sort/sort.scss => ui/Select/select.scss} | 2 +- 4 files changed, 66 insertions(+), 22 deletions(-) create mode 100644 src/components/ui/Select/Select.tsx create mode 100644 src/components/ui/Select/index.tsx rename src/components/{search/Sort/sort.scss => ui/Select/select.scss} (98%) diff --git a/src/components/search/Sort/Sort.tsx b/src/components/search/Sort/Sort.tsx index 9c228fbbf..50420a3b7 100644 --- a/src/components/search/Sort/Sort.tsx +++ b/src/components/search/Sort/Sort.tsx @@ -1,9 +1,6 @@ import { useSearch } from '@faststore/sdk' import React from 'react' -import { Select as UISelect } from '@faststore/ui' -import { CaretDown as CaretDownIcon } from 'phosphor-react' - -import './sort.scss' +import Select from 'src/components/ui/Select' const OptionsMap = { price_desc: 'Price, descending', @@ -25,23 +22,15 @@ function Sort() { } = useSearch() return ( -
- - setSort(keys[e.target.selectedIndex])} - value={sort} - aria-label="Product Sort" - id="select-sort" - > - {keys.map((key) => ( - - ))} - - -
+ setSort(keys[e.target.selectedIndex])} diff --git a/src/components/ui/Select/Select.tsx b/src/components/ui/Select/Select.tsx index e433e9c63..316529a75 100644 --- a/src/components/ui/Select/Select.tsx +++ b/src/components/ui/Select/Select.tsx @@ -10,6 +10,10 @@ type SelectOptions = { } interface UISelectProps extends SelectProps { + /* + * Defines the CSS class string that will be forwarded to the wrapping div "className" prop. + */ + classes?: string /* * Defines the options available in the select. The SelectOptions object * keys are the property names, while the values correspond to the text that @@ -29,11 +33,11 @@ export default function Select({ labelText, value, 'aria-label': ariaLabel, - className, + classes, testId, }: UISelectProps) { return ( -
+
{labelText && } Date: Wed, 2 Feb 2022 19:17:29 -0300 Subject: [PATCH 4/8] Remove whitespace Co-authored-by: Fanny Chien --- src/components/ui/Select/Select.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ui/Select/Select.tsx b/src/components/ui/Select/Select.tsx index 316529a75..389c36400 100644 --- a/src/components/ui/Select/Select.tsx +++ b/src/components/ui/Select/Select.tsx @@ -16,7 +16,7 @@ interface UISelectProps extends SelectProps { classes?: string /* * Defines the options available in the select. The SelectOptions object - * keys are the property names, while the values correspond to the text that + * keys are the property names, while the values correspond to the text that * will be displayed in the UI */ options: SelectOptions From 409b847bad3b27bbdb33cedc127364aea7f6a54f Mon Sep 17 00:00:00 2001 From: Heitor Carvalho Date: Thu, 3 Feb 2022 12:55:01 -0300 Subject: [PATCH 5/8] Remove aria-label property from Sort --- src/components/search/Sort/Sort.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/search/Sort/Sort.tsx b/src/components/search/Sort/Sort.tsx index 2dea85f94..02c22999b 100644 --- a/src/components/search/Sort/Sort.tsx +++ b/src/components/search/Sort/Sort.tsx @@ -28,7 +28,6 @@ function Sort() { options={OptionsMap} onChange={(e) => setSort(keys[e.target.selectedIndex])} value={sort} - aria-label="Product Sort" testId="search-sort" /> ) From 590cac3e51c7360eaf698352855abd5764f8083b Mon Sep 17 00:00:00 2001 From: Heitor Carvalho Date: Thu, 3 Feb 2022 14:42:39 -0300 Subject: [PATCH 6/8] Make 'id' a required attribute for Select --- src/components/search/Sort/Sort.tsx | 1 + src/components/ui/Select/Select.tsx | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/search/Sort/Sort.tsx b/src/components/search/Sort/Sort.tsx index 02c22999b..659ad3e50 100644 --- a/src/components/search/Sort/Sort.tsx +++ b/src/components/search/Sort/Sort.tsx @@ -23,6 +23,7 @@ function Sort() { return ( setSort(keys[e.target.selectedIndex])} diff --git a/src/components/ui/Select/Select.tsx b/src/components/ui/Select/Select.tsx index 0940b20e2..ed11d82fd 100644 --- a/src/components/ui/Select/Select.tsx +++ b/src/components/ui/Select/Select.tsx @@ -11,10 +11,6 @@ interface UISelectProps extends SelectProps { * id will be used to link the UISelect component and its label. */ id: string - /* - * Defines the CSS class string that will be forwarded to the wrapping div "className" prop. - */ - classes?: string /* * Defines the options available in the select. The SelectOptions object * keys are the property names, while the values correspond to the text that @@ -30,16 +26,16 @@ interface UISelectProps extends SelectProps { export default function Select({ id, + className, options, onChange, labelText, value, 'aria-label': ariaLabel, - classes, testId, }: UISelectProps) { return ( -
+
{labelText && }