-
Notifications
You must be signed in to change notification settings - Fork 69
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
39af6af
commit 91b7a8e
Showing
8 changed files
with
332 additions
and
46 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,59 @@ | ||
'use client'; | ||
|
||
import React, { FC } from 'react'; | ||
import { | ||
AutocompleteFilter, | ||
AutocompleteFilterItem, | ||
} from './AutoCompleteVariants'; | ||
|
||
type AutocompleteProps = { | ||
display: string; | ||
options: string[]; | ||
limitType: string; | ||
selectedRange: string | React.ChangeEvent<HTMLSelectElement>; | ||
setSelectedRange: (prev: any) => void; | ||
aria_describedby_label?: string; | ||
handleSelectionChange: (selection: string, limitType: string) => void; | ||
}; | ||
|
||
export const Autocomplete: FC<AutocompleteProps> = ({ | ||
options, | ||
limitType, | ||
selectedRange, | ||
setSelectedRange, | ||
aria_describedby_label, | ||
handleSelectionChange, | ||
}) => { | ||
const selectedKey = options.indexOf(selectedRange as string).toString(); | ||
|
||
const onEnter = (key: string) => { | ||
setSelectedRange((prev: any) => ({ | ||
...prev, | ||
[limitType]: key, | ||
})); | ||
handleSelectionChange(key, limitType); | ||
}; | ||
return ( | ||
<div className="space-x-2 min-h-[33.5px]"> | ||
<AutocompleteFilter | ||
aria-describedby={aria_describedby_label} | ||
defaultSelectedKey={selectedKey} | ||
variant="flat" | ||
size="md" | ||
radius="md" | ||
onKeyUp={(key) => | ||
key.key === 'Enter' && onEnter(key.currentTarget.value) | ||
} | ||
placeholder="Select options..." | ||
> | ||
{options.map((option: string, index: number) => ( | ||
<AutocompleteFilterItem key={index} shouldHighlightOnFocus={false}> | ||
{option} | ||
</AutocompleteFilterItem> | ||
))} | ||
</AutocompleteFilter> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Autocomplete; |
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,43 @@ | ||
import { | ||
Autocomplete, | ||
AutocompleteItem, | ||
extendVariants, | ||
} from '@nextui-org/react'; | ||
|
||
export const AutocompleteFilterItem = extendVariants(AutocompleteItem, { | ||
variants: { | ||
color: { | ||
gray: { | ||
title: ['text-gray-900'], | ||
}, | ||
}, | ||
size: { | ||
md: { | ||
wrapper: 'm-12', | ||
}, | ||
}, | ||
}, | ||
defaultVariants: { | ||
color: 'gray', | ||
size: 'md', | ||
}, | ||
}); | ||
|
||
export const AutocompleteFilter = extendVariants(Autocomplete, { | ||
variants: { | ||
color: { | ||
gray: { | ||
base: 'text-gray-900', | ||
}, | ||
}, | ||
size: { | ||
md: { | ||
base: 'py-2', | ||
}, | ||
}, | ||
}, | ||
defaultVariants: { | ||
color: 'gray', | ||
size: 'md', | ||
}, | ||
}); |
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,71 @@ | ||
'use client'; | ||
|
||
import React, { FC } from 'react'; | ||
import Autocomplete from './AutoComplete'; | ||
|
||
type RangedInputsProps = { | ||
display: string; | ||
options: string[]; | ||
selectedRanges: | ||
| { | ||
min: string | React.ChangeEvent<HTMLSelectElement>; | ||
max: string | React.ChangeEvent<HTMLSelectElement>; | ||
} | ||
| undefined; | ||
setSelectedRanges: (prev: any) => void; | ||
aria_describedby_label?: string; | ||
handleSelectionChange: (selection: string) => void; | ||
}; | ||
|
||
const RangedInputs: FC<RangedInputsProps> = ({ | ||
display, | ||
options, | ||
selectedRanges, | ||
setSelectedRanges, | ||
aria_describedby_label, | ||
handleSelectionChange, | ||
}) => { | ||
return ( | ||
<div className="flex items-center min-h-[40px]"> | ||
<div className="flex flex-col"> | ||
<label | ||
htmlFor="max" | ||
className="body-sm font-medium text-gray-700" | ||
aria-describedby={aria_describedby_label} | ||
> | ||
Min | ||
</label> | ||
<Autocomplete | ||
display={display} | ||
limitType={'min'} | ||
selectedRange={selectedRanges?.min ?? ''} | ||
setSelectedRange={setSelectedRanges} | ||
options={options} | ||
aria_describedby_label="" | ||
handleSelectionChange={handleSelectionChange} | ||
/> | ||
</div> | ||
<div className="flex items-center justify-center mt-6 h-0.5 w-5 bg-gray-400"></div> | ||
<div className="flex flex-col"> | ||
<label | ||
htmlFor="max" | ||
className="body-sm font-medium text-gray-700" | ||
aria-describedby={aria_describedby_label} | ||
> | ||
Max | ||
</label> | ||
<Autocomplete | ||
display={display} | ||
limitType={'max'} | ||
selectedRange={selectedRanges?.max ?? ''} | ||
setSelectedRange={setSelectedRanges} | ||
options={options} | ||
aria_describedby_label="" | ||
handleSelectionChange={handleSelectionChange} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default RangedInputs; |
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.