Skip to content
This repository was archived by the owner on Jan 21, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e0b458f
IW-1244 | Extending DropdownToggle capabilities
bkoval Nov 19, 2018
9f8ef50
IW-1244 | Tests
bkoval Nov 19, 2018
921dc60
IW-1244 | Fixing className for toggle
bkoval Nov 19, 2018
a3aeab7
IW-1244 | Removing obsolete test, regenerating snapshots
bkoval Nov 19, 2018
57cab8a
IW-1244 | Build
bkoval Nov 19, 2018
e393c88
IW-1244 | Adding possibility to define custom icon in dropdown toggle
bkoval Nov 19, 2018
a247b1e
IW-1244 | Dropdowns updated
bkoval Nov 20, 2018
1de3d46
IW-1244 | Linter
bkoval Nov 20, 2018
11ae2ec
IW-1244 build
rybmat Nov 20, 2018
e74fe8b
IW-1244: isStickedToParent prop
rybmat Nov 20, 2018
f6022a0
IW-1244 fix linter
rybmat Nov 20, 2018
56d2780
IW-1244 | Revamping DropdownToggle, rewriting tests for it
bkoval Nov 22, 2018
d93baf4
IW-1244 | Linter
bkoval Nov 22, 2018
f746243
IW-1244 | Regenerated snapshots
bkoval Nov 22, 2018
3c40605
IW-1244 | onClose, tests
bkoval Nov 22, 2018
a621145
IW-1244 | Linter
bkoval Nov 22, 2018
da3984e
IW-1244 | Addressing comments
bkoval Nov 22, 2018
01c9746
IW-1244 | Adding more tests for Dropdown component
bkoval Nov 23, 2018
dddf878
IW-1244 | Build
bkoval Nov 23, 2018
f6fcb4c
IW-1244 | Fixing unit tests
bkoval Nov 26, 2018
446bf94
IW-1244 | Linter
bkoval Nov 26, 2018
a52dc0a
IW-1244 | Addressing CR
bkoval Nov 28, 2018
36eb9dd
Merge branch 'master' into IW-1244
bkoval Nov 28, 2018
816ffea
IW-1244 | Linter, removing defaultProp
bkoval Nov 28, 2018
37d48b6
IW-1244 | Regenerating snapshots for dropdown component
bkoval Nov 28, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
237 changes: 187 additions & 50 deletions components/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,36 +285,113 @@ Icon.defaultProps = {
* Basic DropdownToggle component
*/

var DropdownToggle = function DropdownToggle(_ref) {
var isLevel2 = _ref.isLevel2,
children = _ref.children;
var className = classnames({
'wds-dropdown__toggle': true,
'wds-dropdown-level-2__toggle': isLevel2
});
var iconClassName = isLevel2 ? 'wds-dropdown-chevron' : 'wds-dropdown__toggle-chevron';
return React.createElement("div", {
className: className
}, React.createElement("span", null, children), React.createElement(Icon, {
name: "menu-control-tiny",
className: "wds-icon wds-icon-tiny ".concat(iconClassName)
}));
};
var DropdownToggle =
/*#__PURE__*/
function (_React$Component) {
_inherits(DropdownToggle, _React$Component);

function DropdownToggle() {
_classCallCheck(this, DropdownToggle);

return _possibleConstructorReturn(this, _getPrototypeOf(DropdownToggle).apply(this, arguments));
}

_createClass(DropdownToggle, [{
key: "getToggleContentComponent",
value: function getToggleContentComponent() {
var _this$props = this.props,
toggleContent = _this$props.toggleContent,
isLevel2 = _this$props.isLevel2;
var iconClassName = isLevel2 ? 'wds-dropdown-chevron' : 'wds-dropdown__toggle-chevron';
var icon = React.createElement(Icon, {
name: "menu-control-tiny",
className: "wds-icon wds-icon-tiny ".concat(iconClassName)
});
var toggleContentComponent;

if (typeof toggleContent === 'function') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to support jsx toggle content as well?

<Dropdown toggle={<div>my toggle</div>}>

Or function and string is enough? :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

JSX is the else in this case :)

toggleContentComponent = toggleContent(icon);
} else if (typeof toggleContent === 'string') {
toggleContentComponent = React.createElement(React.Fragment, null, React.createElement("span", null, toggleContent), icon);
} else {
toggleContentComponent = toggleContent;
}

return toggleContentComponent;
}
}, {
key: "render",
value: function render() {
var _this$props2 = this.props,
isLevel2 = _this$props2.isLevel2,
className = _this$props2.className,
attrs = _this$props2.attrs,
onClick = _this$props2.onClick;
var fullClassName = classnames([{
'wds-dropdown__toggle': !isLevel2,
'wds-dropdown-level-2__toggle': isLevel2
}, className]);
var toggleContentComponent = this.getToggleContentComponent();
var Component = attrs.href ? 'a' : 'div';
return (// TODO: Fix a11y
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
React.createElement(Component, _extends({
onClick: onClick,
className: fullClassName
}, attrs, {
role: "button"
}), toggleContentComponent)
);
}
}]);

return DropdownToggle;
}(React.Component);

DropdownToggle.propTypes = {
/**
* HTML attributes
*/
attrs: PropTypes.shape({
href: PropTypes.string
}),

/**
* Dropdown toggle content
*/
children: PropTypes.node,

/**
* HTML classes
*/
className: PropTypes.string,

/**
* Is it a nested dropdown
*/
isLevel2: PropTypes.bool
isLevel2: PropTypes.bool,

/**
* Whether or not the dropdown is displayed on touch device
*/
isTouchDevice: PropTypes.bool,

/**
* Callback when toggle is clicked
*/
onClick: PropTypes.func.isRequired,

/**
* Content of the toggle
*/
toggleContent: PropTypes.oneOfType([PropTypes.func, PropTypes.string, PropTypes.node]).isRequired
};
DropdownToggle.defaultProps = {
children: null,
isLevel2: false
isLevel2: false,
className: '',
attrs: {},
isTouchDevice: false
};

/**
Expand All @@ -337,31 +414,53 @@ function (_React$Component) {
isTouchDevice: typeof window !== 'undefined' && 'ontouchstart' in window
};
_this.onClick = _this.onClick.bind(_assertThisInitialized(_assertThisInitialized(_this)));
_this.onToggleClicked = _this.onToggleClicked.bind(_assertThisInitialized(_assertThisInitialized(_this)));
_this.onMouseLeave = _this.onMouseLeave.bind(_assertThisInitialized(_assertThisInitialized(_this)));
return _this;
}

_createClass(Dropdown, [{
key: "onClick",
value: function onClick(e) {
value: function onClick() {
this.handleClick(false);
}
}, {
key: "onToggleClicked",
value: function onToggleClicked(event) {
this.handleClick(true, event);
}
}, {
key: "onMouseLeave",
value: function onMouseLeave() {
var isTouchDevice = this.state.isTouchDevice;

if (isTouchDevice) {
this.setState({
isClicked: !this.isClicked
isClicked: false
});
e.preventDefault();
}
}
}, {
key: "onMouseLeave",
value: function onMouseLeave() {
var isTouchDevice = this.state.isTouchDevice;
key: "handleClick",
value: function handleClick(shouldPreventDefault, event) {
var _this$state = this.state,
isTouchDevice = _this$state.isTouchDevice,
isClicked = _this$state.isClicked;
var onClose = this.props.onClose;

if (isTouchDevice) {
this.setState({
isClicked: false
isClicked: !isClicked
});

if (shouldPreventDefault) {
event.preventDefault();
event.stopPropagation();
}

if (isClicked === true && typeof onClose === 'function') {
onClose();
}
}
}
}, {
Expand All @@ -377,33 +476,43 @@ function (_React$Component) {
noChevron = _this$props.noChevron,
hasDarkShadow = _this$props.hasDarkShadow,
isActive = _this$props.isActive,
contentScrollable = _this$props.contentScrollable;
var _this$state = this.state,
isClicked = _this$state.isClicked,
isTouchDevice = _this$state.isTouchDevice;
contentScrollable = _this$props.contentScrollable,
toggleAttrs = _this$props.toggleAttrs,
isStickedToParent = _this$props.isStickedToParent,
toggleClassName = _this$props.toggleClassName;
var _this$state2 = this.state,
isClicked = _this$state2.isClicked,
isTouchDevice = _this$state2.isTouchDevice;
var className = classnames({
'wds-dropdown': true,
'wds-dropdown': !isLevel2,
'wds-is-active': isClicked || isActive,
'wds-has-shadow': hasShadow,
'wds-no-chevron': noChevron,
'wds-has-dark-shadow': hasDarkShadow,
'wds-dropdown-level-2': isLevel2,
'wds-is-touch-device': isTouchDevice
'wds-is-touch-device': isTouchDevice,
'wds-is-sticked-to-parent': isStickedToParent
});
return (// TODO: Fix a11y
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
React.createElement("div", {
var dropdownBody = React.createElement(React.Fragment, null, React.createElement(DropdownToggle, {
isLevel2: isLevel2,
attrs: toggleAttrs,
className: toggleClassName,
isTouchDevice: isTouchDevice,
toggleContent: toggle,
onClick: this.onToggleClicked
}), React.createElement(DropdownContent, {
dropdownLeftAligned: dropdownLeftAligned,
dropdownRightAligned: dropdownRightAligned,
isLevel2: isLevel2,
scrollable: contentScrollable
}, children));
var Component = isLevel2 ? 'li' : 'div';
return (// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
React.createElement(Component, {
className: className,
onClick: this.onClick,
onMouseLeave: this.onMouseLeave
}, React.createElement(DropdownToggle, {
isLevel2: isLevel2
}, toggle), React.createElement(DropdownContent, {
dropdownLeftAligned: dropdownLeftAligned,
dropdownRightAligned: dropdownRightAligned,
isLevel2: isLevel2,
scrollable: contentScrollable
}, children))
}, dropdownBody)
);
}
}]);
Expand All @@ -418,27 +527,27 @@ Dropdown.propTypes = {
children: PropTypes.node,

/**
* Whether or not dropdown should have a slight drop shadow
* Should dropdown content be scrollable
*/
contentScrollable: PropTypes.bool,

/**
* Hides chevron in dropdown toggle
* Should dropdown content be left-aligned with the dropdown toggle
*/
dropdownLeftAligned: PropTypes.bool,

/**
* Whether or not dropdown should have a drop shadow (darker than the one produced by hasShadow)
* Should dropdown content be right-aligned with the dropdown toggle
*/
dropdownRightAligned: PropTypes.bool,

/**
* Is it a nested dropdown
* Whether or not dropdown should have a drop shadow (darker than the one produced by hasShadow)
*/
hasDarkShadow: PropTypes.bool,

/**
* Should dropdown content be left-aligned with the dropdown toggle
* Whether or not dropdown should have a slight drop shadow
*/
hasShadow: PropTypes.bool,

Expand All @@ -448,19 +557,41 @@ Dropdown.propTypes = {
isActive: PropTypes.bool,

/**
* Should dropdown content be right-aligned with the dropdown toggle
* Is it a nested dropdown
*/
isLevel2: PropTypes.bool,

/**
* Should dropdown content be scrollable
* if the top of nested dropdown content should be positioned at the same height as toggle
*/
isStickedToParent: PropTypes.bool,

/**
* Should chevron on the top of dropdown content be hidden
*/
noChevron: PropTypes.bool,

/**
* HTML classes to add to toggle
*/
onClose: PropTypes.func,

/**
* React Component to display as a dropdown toggle
*/
toggle: PropTypes.node.isRequired
toggle: PropTypes.node.isRequired,

/**
* HTML attributes to add to toggle
*/
toggleAttrs: PropTypes.shape({
href: PropTypes.string
}),

/**
* HTML classes to add to toggle
*/
toggleClassName: PropTypes.string
};
Dropdown.defaultProps = {
children: null,
Expand All @@ -471,7 +602,13 @@ Dropdown.defaultProps = {
dropdownRightAligned: false,
contentScrollable: false,
isLevel2: false,
isActive: false
isActive: false,
toggleClassName: '',
toggleAttrs: {
href: ''
},
isStickedToParent: false,
onClose: null
};

module.exports = Dropdown;
63 changes: 0 additions & 63 deletions docs/build/bundle.3adf5f6e.js

This file was deleted.

2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>react-design-system</title><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Rubik:400,700"></head><body><div id="rsg-root"></div><div id="app"></div><script src="build/bundle.3adf5f6e.js"></script></body></html>
<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>react-design-system</title><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Rubik:400,700"></head><body><div id="rsg-root"></div><div id="app"></div><script src="build/bundle.46116394.js"></script></body></html>
Loading