Skip to content

Commit

Permalink
edit droplist component
Browse files Browse the repository at this point in the history
Relates #55
  • Loading branch information
Alaalser committed Feb 18, 2021
1 parent 2ddb01d commit 13ae509
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 22 deletions.
64 changes: 44 additions & 20 deletions client/src/Components/Common/DropList/index.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,60 @@
import React from 'react';
import { Select } from 'antd';
import PropTypes from 'prop-types';

import locationIcon from '../../../assets/icons/location.svg';

import './style.css';

const { Option } = Select;

const DropList = ({ options, isSearch, ...otherSelectProps }) => (
<div className="drop-list">
{isSearch ? <img src={locationIcon} alt="location" /> : null}
<Select
placeholder="المنطقة"
bordered={!isSearch}
labelInValue
className={`${isSearch ? 'search-case' : 'request-case'}`}
{...otherSelectProps}
>
{options.map((option) => (
<Option key={option.id} value={option.value} disabled={option.disabled}>
{option.value}
const { Option, OptGroup } = Select;

const DropList = ({ options, isSearch, ...otherSelectProps }) => {
const optionItem = {};

options.forEach(({ id, location_main: main, location_sub: sub }) => {
if (!optionItem[main]) optionItem[main] = [];
optionItem[main].push(
<Option key={id} value={sub}>
{sub}
</Option>
);
});

return (
<div className="drop-list">
{isSearch ? <img src={locationIcon} alt="location" /> : null}
<Select
placeholder="المنطقة"
bordered={!isSearch}
labelInValue
className={`${isSearch ? 'search-case' : 'request-case'}`}
{...otherSelectProps}
>
<Option key={0} value="كل المنطقة">
كل المنطقة
</Option>
))}
</Select>
</div>
);
{Object.keys(optionItem).map((oneKey) => (
<OptGroup key={oneKey} label={oneKey}>
{optionItem[oneKey]}
</OptGroup>
))}
</Select>
</div>
);
};

DropList.defaultProps = {
isSearch: false,
};

DropList.propTypes = {
options: PropTypes.arrayOf(PropTypes.object).isRequired,
options: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.number,
location_main: PropTypes.string,
location_sub: PropTypes.string,
})
).isRequired,
isSearch: PropTypes.bool,
};

Expand Down
3 changes: 1 addition & 2 deletions client/src/Components/Common/DropList/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
}

.search-case {
width: 110px;
height: 25px;
}
}

0 comments on commit 13ae509

Please sign in to comment.