Skip to content

Commit c659a9a

Browse files
rishavanandAlex Pagnotta
andauthored
Add search functionality to skills (#63) (#65)
Co-authored-by: Alex Pagnotta <alex.pagnotta@outlook.it>
1 parent 5033c37 commit c659a9a

1 file changed

Lines changed: 58 additions & 26 deletions

File tree

src/components/Field/SkillsField.tsx

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import React from 'react';
2-
import { Row, Col, Button, Dropdown, Menu, Grid, Checkbox, Tooltip } from 'antd';
1+
import React, { useState } from 'react';
2+
import { Row, Col, Button, Dropdown, Menu, Grid, Checkbox, Tooltip, Input } from 'antd';
33
import { DownOutlined } from '@ant-design/icons';
44
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
55
import { faArrowsAltV } from '@fortawesome/free-solid-svg-icons';
66
import { FieldProps } from '.';
77
import { SKILLS } from '../../config/skills';
88

9+
const { Search } = Input;
10+
911
const { useBreakpoint } = Grid;
1012

1113
export enum ALIGNMENT {
@@ -63,6 +65,9 @@ export const SkillsField = ({
6365
fieldProps: SkillsFieldProps;
6466
modifyField: (filedProps: SkillsFieldProps) => void;
6567
}) => {
68+
69+
const [searchValue, setSearchValue] = useState('');
70+
6671
const screens = useBreakpoint();
6772

6873
const skillsColSpan = screens.md ? 6 : 12;
@@ -77,13 +82,31 @@ export const SkillsField = ({
7782
...fieldProps,
7883
};
7984

80-
const onChange = checkedSkills => {
81-
localSkillsFieldProps.data.list = checkedSkills as string[];
85+
const onChange = event => {
86+
87+
const name = event.target.value;
88+
const isChecked = event.target.checked;
89+
let currentSkillsList = localSkillsFieldProps.data.list;
90+
91+
if(isChecked) {
92+
currentSkillsList.push(name);
93+
}
94+
else {
95+
currentSkillsList = currentSkillsList.filter(skill => skill !== name);
96+
}
97+
98+
localSkillsFieldProps.data.list = currentSkillsList as string[];
99+
82100
modifyField({
83101
...localSkillsFieldProps,
84102
});
103+
85104
};
86105

106+
const onSearch = value => {
107+
setSearchValue(value);
108+
}
109+
87110
const changeSize = (size: typeof localSkillsFieldProps.options.size) => {
88111
const localProps = { ...localSkillsFieldProps };
89112
if (!localProps.options) localProps.options = {};
@@ -107,40 +130,49 @@ export const SkillsField = ({
107130

108131
return (
109132
<>
110-
<Row justify="space-between" style={{ marginBottom: 10 }}>
111-
<Row>
112-
<Col>
113-
<Dropdown overlay={sizeMenu}>
114-
<Tooltip placement="top" title={<span>Icon Size</span>}>
115-
<Button
116-
style={{ paddingLeft: 5, paddingRight: 5, width: 50 }}
117-
icon={
118-
<>
119-
<FontAwesomeIcon icon={faArrowsAltV} /> <DownOutlined />
120-
</>
121-
}
122-
/>
123-
</Tooltip>
124-
</Dropdown>
125-
</Col>
126-
</Row>
133+
<Row justify="space-between" style={{ marginBottom: 30 }}>
134+
<Col>
135+
<Search
136+
placeholder="Search Skills..."
137+
allowClear
138+
onSearch={onSearch}
139+
style={{ width: 180 }}
140+
/>
141+
</Col>
142+
<Col>
143+
<Dropdown overlay={sizeMenu}>
144+
<Tooltip placement="top" title={<span>Icon Size</span>}>
145+
<Button
146+
style={{ paddingLeft: 5, paddingRight: 5, width: 50 }}
147+
icon={
148+
<>
149+
<FontAwesomeIcon icon={faArrowsAltV} /> <DownOutlined />
150+
</>
151+
}
152+
/>
153+
</Tooltip>
154+
</Dropdown>
155+
</Col>
127156
</Row>
128157
<Checkbox.Group
129158
defaultValue={localSkillsFieldProps.data.list}
130159
style={{ width: '100%' }}
131-
onChange={onChange}
132160
>
133161
<Row>
134-
{Object.keys(SKILLS).map(skill => {
162+
{Object.values(SKILLS)
163+
.filter(
164+
skill => searchValue !== '' && searchValue !== undefined ?
165+
skill.label.toLowerCase().indexOf(searchValue.toLowerCase()) > -1 : true
166+
)
167+
.map(skill => {
135168
return (
136-
<Col span={skillsColSpan} key={SKILLS[skill].value}>
137-
<Checkbox value={SKILLS[skill].value}>{SKILLS[skill].label}</Checkbox>
169+
<Col span={skillsColSpan} key={skill.value}>
170+
<Checkbox onChange={onChange} value={skill.value}>{skill.label}</Checkbox>
138171
</Col>
139172
);
140173
})}
141174
</Row>
142175
</Checkbox.Group>
143-
,
144176
</>
145177
);
146178
};

0 commit comments

Comments
 (0)