Skip to content

Commit ad93873

Browse files
authored
Merge pull request #3332 from Vizzuality/feature/new-selector
Feature/new selector
2 parents 9abaa7b + 3def534 commit ad93873

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1002
-596
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ $ npm install
8484
Almost there! Final steps are to copy the `.env.sample` to `.env`, and start the server:
8585

8686
```bash
87-
$ ./bin/server
87+
$ npm start
8888
```
8989
The app should now be accessible on [http://0.0.0.0:5000](http://0.0.0.0:5000).
9090

app/javascript/assets/icons/arrow-down.svg

100644100755
File mode changed.

app/javascript/assets/icons/close.svg

+5-17
Loading

app/javascript/assets/icons/download.svg

100644100755
+4-2
Loading

app/javascript/assets/icons/facebook.svg

100644100755
+5-4
Loading

app/javascript/assets/icons/flechita.svg

100644100755
+5-1
Loading

app/javascript/assets/icons/googleplus.svg

100644100755
+5-4
Loading

app/javascript/assets/icons/info.svg

+3-3
Loading

app/javascript/assets/icons/link.svg

100644100755
+4-2
Loading
+1-1
Loading

app/javascript/assets/icons/minus.svg

100644100755
+5-1
Loading

app/javascript/assets/icons/play.svg

+1-1
Loading

app/javascript/assets/icons/plus.svg

100644100755
+5-1
Loading
+2-2
Loading

app/javascript/assets/icons/share.svg

100644100755
+5-1
Loading

app/javascript/assets/icons/twitter.svg

100644100755
+5-4
Loading

app/javascript/components/button/button-component.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ const Button = props => {
7878
arrow
7979
disabled={isDeviceTouch}
8080
html={<Tip text={tooltip.text} />}
81+
hideOnClick
8182
{...tooltip}
8283
>
8384
{button}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
import Icon from 'components/icon';
5+
import Button from 'components/button';
6+
7+
import arrowDownIcon from 'assets/icons/arrow-down.svg';
8+
import infoIcon from 'assets/icons/info.svg';
9+
10+
const Item = props => {
11+
const {
12+
index,
13+
item,
14+
showGroup,
15+
highlightedIndex,
16+
getItemProps,
17+
handleSelectGroup,
18+
optionsAction,
19+
optionsActionKey,
20+
activeValue,
21+
activeLabel
22+
} = props;
23+
const { group, groupParent, label, metaKey } = item;
24+
25+
const isActive =
26+
(!showGroup && !group) ||
27+
(group === showGroup || groupParent === showGroup);
28+
const isGroupParentActive = groupParent && showGroup === groupParent;
29+
const isHighlighted =
30+
highlightedIndex === index ||
31+
activeLabel === label ||
32+
(groupParent && groupParent === showGroup) ||
33+
(groupParent && activeValue && groupParent === activeValue.group);
34+
35+
return (
36+
<div
37+
className={`item-wrapper
38+
${isActive ? 'show' : ''}
39+
${!group ? 'base' : ''}
40+
`}
41+
>
42+
{isGroupParentActive && (
43+
<Icon
44+
icon={arrowDownIcon}
45+
className={`group-icon ${
46+
showGroup === groupParent ? 'selected' : ''
47+
}`}
48+
/>
49+
)}
50+
<div
51+
{...getItemProps({
52+
item,
53+
index,
54+
className: `item ${isHighlighted ? 'highlight' : ''}`
55+
})}
56+
{...!!groupParent && {
57+
onClick: () => handleSelectGroup(item)
58+
}}
59+
>
60+
{label}
61+
</div>
62+
{metaKey && (
63+
<Button
64+
className="theme-button-small square info-button"
65+
onClick={() => optionsAction(item[optionsActionKey])}
66+
>
67+
<Icon icon={infoIcon} className="info-icon" />
68+
</Button>
69+
)}
70+
{groupParent &&
71+
showGroup !== groupParent && (
72+
<Icon
73+
icon={arrowDownIcon}
74+
className={`group-icon ${
75+
showGroup === groupParent ? 'selected' : ''
76+
}`}
77+
/>
78+
)}
79+
</div>
80+
);
81+
};
82+
83+
Item.propTypes = {
84+
index: PropTypes.number,
85+
item: PropTypes.object,
86+
showGroup: PropTypes.string,
87+
highlightedIndex: PropTypes.number,
88+
getItemProps: PropTypes.func,
89+
handleSelectGroup: PropTypes.func,
90+
optionsAction: PropTypes.func,
91+
optionsActionKey: PropTypes.string,
92+
activeValue: PropTypes.object,
93+
activeLabel: PropTypes.string
94+
};
95+
96+
export default Item;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
import Item from './item';
5+
6+
const Menu = props => {
7+
const {
8+
isOpen,
9+
activeValue,
10+
activeLabel,
11+
items,
12+
showGroup,
13+
getItemProps,
14+
highlightedIndex,
15+
optionsAction,
16+
optionsActionKey,
17+
noItemsFound,
18+
handleSelectGroup
19+
} = props;
20+
21+
return !isOpen ? null : (
22+
<div className="menu">
23+
{items && items.length ? (
24+
items.map((item, index) => (
25+
<Item
26+
key={item.value}
27+
index={index}
28+
item={item}
29+
showGroup={showGroup}
30+
highlightedIndex={highlightedIndex}
31+
getItemProps={getItemProps}
32+
handleSelectGroup={handleSelectGroup}
33+
optionsAction={optionsAction}
34+
optionsActionKey={optionsActionKey}
35+
activeValue={activeValue}
36+
activeLabel={activeLabel}
37+
/>
38+
))
39+
) : (
40+
<div className="item not-found">
41+
{noItemsFound || 'No results found'}
42+
</div>
43+
)}
44+
</div>
45+
);
46+
};
47+
48+
Menu.propTypes = {
49+
isOpen: PropTypes.bool,
50+
activeValue: PropTypes.object,
51+
activeLabel: PropTypes.string,
52+
items: PropTypes.array,
53+
showGroup: PropTypes.string,
54+
getItemProps: PropTypes.func,
55+
highlightedIndex: PropTypes.number,
56+
optionsAction: PropTypes.func,
57+
optionsActionKey: PropTypes.string,
58+
noItemsFound: PropTypes.string,
59+
handleSelectGroup: PropTypes.func
60+
};
61+
62+
export default Menu;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
import Icon from 'components/icon';
5+
6+
import arrowDownIcon from 'assets/icons/arrow-down.svg';
7+
import closeIcon from 'assets/icons/close.svg';
8+
9+
const Selector = props => {
10+
const {
11+
isOpen,
12+
arrowPosition,
13+
onSelectorClick,
14+
clearable,
15+
activeValue,
16+
activeLabel,
17+
searchable,
18+
inputProps,
19+
handleClearSelection,
20+
children,
21+
innerRef
22+
} = props;
23+
24+
return (
25+
<div ref={innerRef} className={`container ${isOpen ? 'is-open' : ''}`}>
26+
<div className={`selector ${arrowPosition ? 'align-left' : ''}`}>
27+
{arrowPosition === 'left' && (
28+
<button className="arrow-btn" onClick={onSelectorClick}>
29+
<Icon className="arrow" icon={arrowDownIcon} />
30+
</button>
31+
)}
32+
<span
33+
className={`value ${!activeValue ? 'no-value' : ''} ${
34+
clearable && activeValue ? 'clearable' : ''
35+
}`}
36+
>
37+
{(isOpen && !searchable) || !isOpen ? activeLabel : ''}
38+
</span>
39+
<input {...inputProps()} />
40+
{clearable &&
41+
activeValue && (
42+
<button className="clear-btn" onClick={handleClearSelection}>
43+
<Icon icon={closeIcon} className="clear-icon" />
44+
</button>
45+
)}
46+
{arrowPosition !== 'left' && (
47+
<button className="arrow-btn" onClick={onSelectorClick}>
48+
<Icon className="arrow" icon={arrowDownIcon} />
49+
</button>
50+
)}
51+
</div>
52+
<div className="menu-arrow" />
53+
{children}
54+
</div>
55+
);
56+
};
57+
58+
Selector.propTypes = {
59+
children: PropTypes.node,
60+
isOpen: PropTypes.bool,
61+
arrowPosition: PropTypes.string,
62+
onSelectorClick: PropTypes.func,
63+
clearable: PropTypes.bool,
64+
activeValue: PropTypes.object,
65+
activeLabel: PropTypes.string,
66+
searchable: PropTypes.bool,
67+
inputProps: PropTypes.func,
68+
handleClearSelection: PropTypes.func,
69+
innerRef: PropTypes.func
70+
};
71+
72+
export default Selector;

0 commit comments

Comments
 (0)