Skip to content

Commit d3e5d14

Browse files
authored
Merge pull request #322 from Wikia/IW-1296
IW-1296 | reversible dropdown with canFlip property
2 parents e38ce63 + 0be4f34 commit d3e5d14

File tree

12 files changed

+1564
-1426
lines changed

12 files changed

+1564
-1426
lines changed

app/components/dropdown.js

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import Component from '@ember/component';
2+
import { computed } from '@ember/object';
23
import { or } from '@ember/object/computed';
34

5+
import getViewportSize from '../utils/viewport-size';
6+
47
const isTouchDevice = ('ontouchstart' in window);
58

69
export default Component.extend({
@@ -11,37 +14,59 @@ export default Component.extend({
1114
'hasDarkShadow:wds-has-dark-shadow',
1215
'isLevel2:wds-dropdown-level-2:wds-dropdown',
1316
'isTouchDevice:wds-is-touch-device',
17+
'isFlipped:wds-is-flipped',
1418
],
1519

1620
isClicked: false,
1721
isLevel2: false,
22+
isFlipped: false,
23+
canFlip: false,
1824
isTouchDevice: isTouchDevice,
1925

2026
isActive: or('dropdownExpanded', 'isClicked'),
2127

28+
contentElement: computed('element', function () {
29+
return this.element && this.element.querySelector('.wds-dropdown__content');
30+
}),
31+
2232
init() {
2333
this._super(...arguments);
2434

25-
if (this.mouseEnter) {
26-
this.mouseEnter = this.mouseEnter.bind(this);
27-
}
28-
this.mouseLeave = this.mouseLeave.bind(this);
35+
this._mouseEnter = this._mouseEnter.bind(this);
36+
this._mouseLeave = this._mouseLeave.bind(this);
2937
},
3038

3139
didInsertElement() {
3240
this._super(...arguments);
3341

34-
if (this.mouseEnter) {
35-
this.element.addEventListener('mouseenter', this.mouseEnter);
36-
}
37-
38-
this.element.addEventListener('mouseleave', this.mouseLeave);
42+
this.element.addEventListener('mouseenter', this._mouseEnter);
43+
this.element.addEventListener('mouseleave', this._mouseLeave);
3944
},
4045

41-
mouseLeave() {
46+
_mouseLeave() {
4247
if (this.isTouchDevice) {
4348
this.set('isClicked', false);
4449
}
50+
51+
if (this.canFlip && !this.isLevel2) {
52+
this.set('isFlipped', false);
53+
}
54+
55+
if (this.mouseLeave) {
56+
this.mouseLeave(...arguments);
57+
}
58+
},
59+
60+
_mouseEnter() {
61+
if (this.canFlip && !this.isLevel2 && this.contentElement) {
62+
const contentElementBoundingRect = this.contentElement.getBoundingClientRect();
63+
64+
this.set('isFlipped', contentElementBoundingRect.bottom > getViewportSize().height);
65+
}
66+
67+
if (this.mouseEnter) {
68+
this.mouseEnter(...arguments);
69+
}
4570
},
4671

4772
actions: {

app/utils/viewport-size.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default function getViewportSize() {
2+
return {
3+
width: Math.max(document.documentElement.clientWidth, window.innerWidth || 0),
4+
height: Math.max(document.documentElement.clientHeight, window.innerHeight || 0),
5+
};
6+
}

dist/css/styles.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/scss/wds-components/_dropdowns.scss

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,28 @@
144144
border: 0;
145145
}
146146
}
147+
148+
&.wds-is-flipped {
149+
&::before, &::after {
150+
bottom: unset;
151+
top: -$wds-dropdown-border-width;
152+
}
153+
154+
&::before {
155+
border-bottom-color: transparent;
156+
border-top-color: $wds-color-faint-gray;
157+
}
158+
159+
&::after {
160+
border-bottom-color: transparent;
161+
border-top-color: $wds-color-white;
162+
}
163+
164+
.wds-dropdown__content {
165+
bottom: 100%;
166+
top: unset;
167+
}
168+
}
147169
}
148170

149171
.wds-dropdown__content .wds-list.wds-is-linked .wds-dropdown-level-2 {

dist/scss/wds-mixins/_dropdown-theming.scss

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,25 @@
4141
}
4242
}
4343

44-
.wds-dropdown::after {
45-
border-bottom-color: $dropdown-background-color;
46-
}
44+
.wds-dropdown {
45+
&::after {
46+
border-bottom-color: $dropdown-background-color;
47+
}
48+
49+
&::before {
50+
border-bottom-color: $color-page-border;
51+
}
4752

48-
.wds-dropdown::before {
49-
border-bottom-color: $color-page-border;
53+
&.wds-is-flipped {
54+
&::after {
55+
border-bottom-color: transparent;
56+
border-top-color: $dropdown-background-color;
57+
}
58+
59+
&::before {
60+
border-bottom-color: transparent;
61+
border-top-color: $color-page-border;
62+
}
63+
}
5064
}
5165
}

docs/assets/design-system.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/assets/dummy.js

Lines changed: 30 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/assets/vendor.js

Lines changed: 1375 additions & 1383 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/assets/wds.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

style-guide/styles/wds-components/_dropdowns.scss

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,28 @@
144144
border: 0;
145145
}
146146
}
147+
148+
&.wds-is-flipped {
149+
&::before, &::after {
150+
bottom: unset;
151+
top: -$wds-dropdown-border-width;
152+
}
153+
154+
&::before {
155+
border-bottom-color: transparent;
156+
border-top-color: $wds-color-faint-gray;
157+
}
158+
159+
&::after {
160+
border-bottom-color: transparent;
161+
border-top-color: $wds-color-white;
162+
}
163+
164+
.wds-dropdown__content {
165+
bottom: 100%;
166+
top: unset;
167+
}
168+
}
147169
}
148170

149171
.wds-dropdown__content .wds-list.wds-is-linked .wds-dropdown-level-2 {

0 commit comments

Comments
 (0)