Skip to content
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
2 changes: 1 addition & 1 deletion lib/components/Dropdown/Dropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@

Copy link
Contributor

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 than rem. Let's keep it consistent throughout the whole project by using px as of now 👍🏼

Copy link
Contributor Author

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

&__items {
position: absolute;
top: 2.7rem;
top: 2.9rem;
width: 100%;
display: flex;
flex-direction: column;
Expand Down
51 changes: 31 additions & 20 deletions lib/components/Dropdown/index.tsx
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";
Expand All @@ -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'];
Expand All @@ -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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yaswanth-deriv you should fix the variants as well.prompt variation is the one where you can type in it.

};


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);
Expand Down Expand Up @@ -69,7 +73,7 @@ export const Dropdown = ({
return item ? reactNodeToString(item.text) : '';
},
onInputValueChange({ inputValue }) {
onChange?.(inputValue ?? '');
onSearch?.(inputValue ?? '');
if (shouldFilterList) {
setItems(
list.filter(item =>
Expand Down Expand Up @@ -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>
);
Expand Down
32 changes: 32 additions & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,38 @@ ReactDOM.createRoot(document.getElementById('root')!).render(
text: 'Option 2',
value: 'option2'
},
{
text: 'Option 3',
value: 'option3'
},
{
text: 'Option 4',
value: 'option4'
},
{
text: 'Option 5',
value: 'option5'
},
{
text: 'Option 6',
value: 'option6'
},
{
text: 'Option 7',
value: 'option7'
},
{
text: 'Option 8',
value: 'option8'
},
{
text: 'Option 9',
value: 'option9'
},
{
text: 'Option 10',
value: 'option10'
},
]}
dropdownIcon="down"
onSelect={(value) => console.log(value)}
Expand Down