-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Yaswanth/Added input props in dropdown component #60
Merged
shayan-deriv
merged 8 commits into
deriv-com:main
from
yaswanth-deriv:yaswanth/Added_input_props_dropdown
Feb 15, 2024
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4938b1e
Added input props to dropdown
yaswanth-deriv 697e2c5
Merge branch 'deriv-com:main' into yaswanth/Added_input_props_dropdown
yaswanth-deriv 45a2c4e
refactor: made changes in css file
yaswanth-deriv 8519176
refactor: Added max-height for dropdown list
yaswanth-deriv 9e426d5
Merge branch 'deriv-com:main' into yaswanth/Added_input_props_dropdown
yaswanth-deriv 96b5980
Merge branch 'deriv-com:main' into yaswanth/Added_input_props_dropdown
yaswanth-deriv 0e4c564
refactor: Added xs in style
yaswanth-deriv f20c9e9
Merge branch 'main' into yaswanth/Added_input_props_dropdown
yaswanth-deriv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,4 +1,4 @@ | ||
import React, { isValidElement, useCallback, useEffect, useState } from 'react'; | ||
import React, { isValidElement,HtmlHTMLAttributes ,useCallback, useEffect, useState } from 'react'; | ||
import clsx from 'clsx'; | ||
import { useCombobox } from 'downshift'; | ||
import { TGenericSizes } from "../../types"; | ||
|
@@ -7,10 +7,11 @@ import {Input } from '../Input/index'; | |
import './Dropdown.scss'; | ||
|
||
type InputProps = React.ComponentProps<typeof Input>; | ||
type TProps = { | ||
type TProps = HtmlHTMLAttributes<HTMLInputElement> & { | ||
yaswanth-deriv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
disabled?: boolean; | ||
dropdownIcon: React.ReactNode; | ||
errorMessage?: InputProps['message']; | ||
dropdownHeight?:string; | ||
icon?: React.ReactNode; | ||
isRequired?: boolean; | ||
label?: InputProps['label']; | ||
|
@@ -20,25 +21,28 @@ type TProps = { | |
}[]; | ||
listHeight?: Extract<TGenericSizes, 'lg' | 'md' | 'sm'>; | ||
yaswanth-deriv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
name: InputProps['name']; | ||
onChange?: (inputValue: string) => void; | ||
onSearch?: (inputValue: string) => void; | ||
onSelect: (value: string) => void; | ||
value?: InputProps['value']; | ||
variant?: 'comboBox' | 'prompt'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yaswanth-deriv you should fix the variants as well. |
||
}; | ||
|
||
|
||
export const Dropdown = ({ | ||
disabled, | ||
dropdownIcon, | ||
errorMessage, | ||
dropdownHeight, | ||
icon = false, | ||
label, | ||
list, | ||
listHeight = 'md', | ||
name, | ||
onChange, | ||
onSearch, | ||
onSelect, | ||
value, | ||
variant = 'prompt', | ||
...rest | ||
}:TProps) => { | ||
const [items, setItems] = useState(list); | ||
const [shouldFilterList, setShouldFilterList] = useState(false); | ||
|
@@ -69,7 +73,7 @@ export const Dropdown = ({ | |
return item ? reactNodeToString(item.text) : ''; | ||
}, | ||
onInputValueChange({ inputValue }) { | ||
onChange?.(inputValue ?? ''); | ||
onSearch?.(inputValue ?? ''); | ||
if (shouldFilterList) { | ||
setItems( | ||
list.filter(item => | ||
|
@@ -134,24 +138,31 @@ export const Dropdown = ({ | |
type='text' | ||
value={value} | ||
{...getInputProps()} | ||
{...rest} | ||
yaswanth-deriv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/> | ||
</div> | ||
<ul className={`deriv-dropdown__items deriv-dropdown__items--${listHeight}`} {...getMenuProps()}> | ||
yaswanth-deriv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{isOpen && | ||
items.map((item, index) => ( | ||
<li | ||
className={clsx('deriv-dropdown__item', { | ||
'deriv-dropdown__item--active': value === item.value, | ||
})} | ||
key={item.value} | ||
onClick={() => clearFilter()} | ||
{...getItemProps({ index, item })} | ||
> | ||
<Text size='sm' weight={value === item.value ? 'bold' : 'normal'}> | ||
{item.text} | ||
</Text> | ||
</li> | ||
))} | ||
{isOpen &&( | ||
<div style={{height:dropdownHeight?dropdownHeight:"12.5rem"}}> | ||
{ | ||
items.map((item, index) => ( | ||
<li | ||
className={clsx('deriv-dropdown__item', { | ||
'deriv-dropdown__item--active': value === item.value, | ||
})} | ||
key={item.value} | ||
onClick={() => clearFilter()} | ||
{...getItemProps({ index, item })} | ||
> | ||
<Text size='sm' weight={value === item.value ? 'bold' : 'normal'}> | ||
{item.text} | ||
</Text> | ||
</li> | ||
)) | ||
} | ||
</div> | ||
) | ||
} | ||
</ul> | ||
</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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the files currently are utilizing the
px
unit rather thanrem
. Let's keep it consistent throughout the whole project by usingpx
as of now 👍🏼There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.I am creating other PR to address these comments.Thanks