feature(components): prop-type DropDown

This commit is contained in:
Alexander Klein 2021-02-16 12:57:18 +01:00
parent 303fffbc40
commit b75ad8eec5

View File

@ -1,4 +1,5 @@
import React, { useState, useRef } from 'react'; import React, { useState, useRef } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames'; import classNames from 'classnames';
import Menu from './Menu'; import Menu from './Menu';
import useDocumentClick from 'hooks/useDocumentClick'; import useDocumentClick from 'hooks/useDocumentClick';
@ -6,13 +7,7 @@ import Chevron from 'assets/chevron-down.svg';
import styles from './Dropdown.module.css'; import styles from './Dropdown.module.css';
import Icon from './Icon'; import Icon from './Icon';
export default function DropDown({ function DropDown({ value, className, menuClassName, options = [], onChange = () => {} }) {
value,
className,
menuClassName,
options = [],
onChange = () => {},
}) {
const [showMenu, setShowMenu] = useState(false); const [showMenu, setShowMenu] = useState(false);
const ref = useRef(); const ref = useRef();
const selectedOption = options.find(e => e.value === value); const selectedOption = options.find(e => e.value === value);
@ -52,3 +47,18 @@ export default function DropDown({
</div> </div>
); );
} }
DropDown.propTypes = {
value: PropTypes.any,
className: PropTypes.string,
menuClassName: PropTypes.string,
options: PropTypes.arrayOf(
PropTypes.shape({
value: PropTypes.any.isRequired,
label: PropTypes.node,
}),
),
onChange: PropTypes.func,
};
export default DropDown;