You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Created a ComboBox component to add diverse usage than our current select component
Why?
There are other functionalities such as being able to page the results in a selection or adding the ability to first search through a set to then provide the combobox options that shouldn't be added to the current select component.
Screenshots/Screen Recordings
Testing/Proof
dev.tsx code
import{ComboBox,Form,FormGroup,Box}from'@bigcommerce/big-design';importReact,{FunctionComponent,useState}from'react';constallCountries=["Afghanistan","Albania","Algeria","Andorra","Angola","Antigua and Barbuda","Argentina","Armenia","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bhutan","Bolivia","Bosnia and Herzegovina","Botswana","Brazil","Brunei","Bulgaria","Burkina Faso","Burundi","Cabo Verde","Cambodia","Cameroon","Canada","Central African Republic","Chad","Chile","China","Colombia","Comoros","Congo (Congo-Brazzaville)","Costa Rica","Croatia","Cuba","Cyprus","Czechia (Czech Republic)","Democratic Republic of the Congo","Denmark","Djibouti","Dominica","Dominican Republic","Ecuador","Egypt","El Salvador","Equatorial Guinea","Eritrea","Estonia","Eswatini (fmr. "+"Swaziland)","Ethiopia","Fiji","Finland","France","Gabon","Gambia","Georgia","Germany","Ghana","Greece","Grenada","Guatemala","Guinea","Guinea-Bissau","Guyana","Haiti","Holy See","Honduras","Hungary","Iceland","India","Indonesia","Iran","Iraq","Ireland","Israel","Italy","Jamaica","Japan","Jordan","Kazakhstan","Kenya","Kiribati","Kuwait","Kyrgyzstan","Laos","Latvia","Lebanon","Lesotho","Liberia","Libya","Liechtenstein","Lithuania","Luxembourg","Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Marshall Islands","Mauritania","Mauritius","Mexico","Micronesia","Moldova","Monaco","Mongolia","Montenegro","Morocco","Mozambique","Myanmar (formerly Burma)","Namibia","Nauru","Nepal","Netherlands","New Zealand","Nicaragua","Niger","Nigeria","North Korea","North Macedonia","Norway","Oman","Pakistan","Palau","Palestine State","Panama","Papua New Guinea","Paraguay","Peru","Philippines","Poland","Portugal","Qatar","Romania","Russia","Rwanda","Saint Kitts and Nevis","Saint Lucia","Saint Vincent and the Grenadines","Samoa","San Marino","Sao Tome and Principe","Saudi Arabia","Senegal","Serbia","Seychelles","Sierra Leone","Singapore","Slovakia","Slovenia","Solomon Islands","Somalia","South Africa","South Korea","South Sudan","Spain","Sri Lanka","Sudan","Suriname","Sweden","Switzerland","Syria","Tajikistan","Tanzania","Thailand","Timor-Leste","Togo","Tonga","Trinidad and Tobago","Tunisia","Turkey","Turkmenistan","Tuvalu","Uganda","Ukraine","United Arab Emirates","United Kingdom","United States of America","Uruguay","Uzbekistan","Vanuatu","Venezuela","Vietnam","Yemen","Zambia","Zimbabwe"];constComboBoxTest: FunctionComponent=()=>{// First ComboBox (paged)const[value,setValue]=useState('mx');consthandleChange=(val)=>setValue(val);const[optionsLoading,setOptionsLoading]=useState(false);typeOption={value: string;content: string};constgenerateOptions=(start: number,num: number): Option[]=>{returnallCountries.slice(start,start+num).map((country)=>({value: country.toLowerCase().replace(/[^a-z]/g,'-'),content: country,}));};const[selectOptions,setSelectOptions]=useState<Option[]>(generateOptions(0,9));constexpandOptions=async()=>{setOptionsLoading(true);// Simulate async option fetchawaitnewPromise((resolve)=>setTimeout(resolve,1000));setSelectOptions((prevOptions)=>{conststart=prevOptions.length;constnewOptions=generateOptions(start,9);return[...prevOptions, ...newOptions];});setOptionsLoading(false);};consthasMoreOptions=selectOptions.length<allCountries.length;// Second ComboBox (search after 3 letters)const[searchValue,setSearchValue]=useState('');const[searchOptions,setSearchOptions]=useState<Option[]>([]);const[searchLoading,setSearchLoading]=useState(false);consthandleSearchInputChange=async(input: string)=>{setSearchValue(input);if(input.length<2){setSearchOptions([]);return;}setSearchLoading(true);// Simulate async fetchawaitnewPromise((resolve)=>setTimeout(resolve,500));constfiltered=allCountries.filter((country)=>country.toLowerCase().includes(input.toLowerCase())).map((country)=>({value: country.toLowerCase().replace(/[^a-z]/g,'-'),content: country,}));setSearchOptions(filtered);setSearchLoading(false);};consthandleSearchOptionChange=(val)=>setSearchValue(val);return(<Boxpadding={'xxLarge'}><Form><FormGroup><ComboBoxfilterable={true}label="Countries (Paged)"maxHeight={300}onOptionChange={handleChange}options={selectOptions}placeholder="Choose country"placement="bottom-start"requiredvalue={value}onScrollToBottom={hasMoreOptions ? expandOptions : undefined}optionsLoading={optionsLoading}/></FormGroup><FormGroup><ComboBoxfilterable={true}label="Countries (Search after 2 letters)"maxHeight={300}onOptionChange={handleSearchOptionChange}options={searchOptions}placeholder="Type at least 2 letters"placement="bottom-start"requiredvalue={searchValue}optionsLoading={searchLoading}onInputChange={handleSearchInputChange}/></FormGroup></Form></Box>);};exportdefaultComboBoxTest;
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Created a ComboBox component to add diverse usage than our current select component
Why?
There are other functionalities such as being able to page the results in a selection or adding the ability to first search through a set to then provide the combobox options that shouldn't be added to the current select component.
Screenshots/Screen Recordings
Testing/Proof
dev.tsxcode