Skip to content
This repository has been archived by the owner on Nov 10, 2020. It is now read-only.

feat(tag flyout menu): flyout menu implementation with the shortcuts #8

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3137575
feat: create initial flyout component
AAPK-code Sep 8, 2020
c943a31
feat(create basic styles and option component): created basic styles
AAPK-code Sep 8, 2020
58f8516
feat(flyout-menu): flyout-menu
AAPK-code Sep 10, 2020
d8e66e3
feat(add icons): add icons to the flyout component
AAPK-code Sep 10, 2020
830e3d0
feat(add secondary menu): added the secondary menu for the flyout com…
AAPK-code Sep 10, 2020
4ed6752
feat(refactoring flyout): did refactoring whole component
AAPK-code Sep 13, 2020
997cdad
feat(fix styles): fixed styles
AAPK-code Sep 13, 2020
b8e4267
feat(add hover behavior): added hover behavior for the flyout options
AAPK-code Sep 13, 2020
8aceea5
feat(add short cuts): added short cuts support
AAPK-code Sep 13, 2020
3e78376
feat(fix example): fixed example displaying
AAPK-code Sep 13, 2020
44954b5
feat(gux-flyout-menu): add tests
AAPK-code Sep 14, 2020
1c908df
fix(fix prev test): fix test
AAPK-code Sep 14, 2020
9e8b51f
fix(flyout-menu): refactoring
AAPK-code Sep 14, 2020
54403c9
feat(flyout-menu): add logic
AAPK-code Sep 15, 2020
25a6071
feat(add shot cuts): added short cuts with unit test
AAPK-code Sep 18, 2020
89585ac
fix(flyout-menu): fix slot markup and styles regarding comments
dmitryueno Oct 1, 2020
2dfb759
fix(flyout-menu): conflicts resolved
dmitryueno Oct 1, 2020
7099325
fix(flyout-menu): shortcuts functionality, ability to get selected op…
dmitryueno Oct 1, 2020
7400ee8
fix(flyout-menu): fix test
dmitryueno Oct 1, 2020
5cbeae5
Merge branch 'master' of https://github.com/ueno-llc/genesys-webcompo…
dmitryueno Oct 2, 2020
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
6 changes: 6 additions & 0 deletions docs/src/components-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,12 @@
"submit": "Standard Event"
}
},
"gux-flyout-menu-beta": {
"attributes": {},
"events": {
"menuOptionSelected": "Fired when option in flyout menu being selected"
}
},
"gux-table-beta": {
"attributes": {
"compact": "checkbox",
Expand Down
86 changes: 86 additions & 0 deletions src/components/beta/gux-flyout-menu-beta/example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<div style="display: flex;">
<div style="margin-left: 20px; min-width: 200px;">
<gux-button
accent="primary"
onClick='(function() {
const html = window.toHTML(`
<gux-flyout-menu-beta>
<gux-flyout-option-beta
short-cut="Crl+Alt+A"
key-code="17"
second-key-code="18"
third-key-code="65"
>
<div slot="title">Option One</div>
</gux-flyout-option-beta>
<gux-flyout-option-beta short-cut="Crl+Alt+C">
<div slot="title">Option Two</div>
</gux-flyout-option-beta>
<gux-flyout-option-beta short-cut="Shift+A">
<div slot="title">Option Three</div>
</gux-flyout-option-beta>
<gux-flyout-option-beta short-cut="⌘A">
<div slot="title">Option Four</div>
</gux-flyout-option-beta>
<gux-flyout-option-beta short-cut="⌘⇧A">
<div slot="title">Option Five</div>
</gux-flyout-option-beta>
</gux-flyout-menu-beta>
`);

document.getElementById("flyout-menu-first-container").appendChild(html);
})()'
>
Flyout example 1
</gux-button>
<div id="flyout-menu-first-container"></div>
</div>

<div style="margin-left: 20px; min-width: 200px;">
<gux-button
accent="primary"
onClick='(function() {
const html = window.toHTML(`
<gux-flyout-menu-beta>
<gux-flyout-option-beta with-icon>
<div slot="title">Option One</div>
<gux-flyout-submenu-beta slot="submenu">
<gux-flyout-option-beta>
<div slot="title">Option One</div>
</gux-flyout-option-beta>
<gux-flyout-option-beta>
<div slot="title">Option Two</div>
</gux-flyout-option-beta>
<gux-flyout-option-beta with-icon>
<div slot="title">Option Three</div>
<gux-flyout-submenu-beta slot="submenu">
<gux-flyout-option-beta short-cut="⌘A">
<div slot="title">Option One</div>
</gux-flyout-option-beta>
<gux-flyout-option-beta short-cut="⌘⇧A">
<div slot="title">Option Two</div>
</gux-flyout-option-beta>
</gux-flyout-submenu-beta>
</gux-flyout-option-beta>
<gux-flyout-option-beta>
<div slot="title">Option Four</div>
</gux-flyout-option-beta>
</gux-flyout-submenu-beta>
</gux-flyout-option-beta>
<gux-flyout-option-beta>
<div slot="title">Option Two</div>
</gux-flyout-option-beta>
<gux-flyout-option-beta>
<div slot="title">Option Three</div>
</gux-flyout-option-beta>
</gux-flyout-menu-beta>
`);

document.getElementById("flyout-menu-second-container").appendChild(html);
})()'
>
Flyout example 2
</gux-button>
<div id="flyout-menu-second-container"></div>
</div>
</div>
41 changes: 41 additions & 0 deletions src/components/beta/gux-flyout-menu-beta/gux-flyout-menu.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Style
gux-flyout-menu-beta {
background-color: #fdfdfd;
box-shadow: 0 0 5px 0 rgba(218, 225, 232, 1);
display: block;
margin-top: 12px;
min-width: 185px;
padding: 10px 0;
position: relative;

&::after,
&::before {
content: '';
height: 0;
position: absolute;
width: 0;
}

&::after {
border-bottom: 11px solid #fff;
border-left: 13px solid transparent;
border-right: 13px solid transparent;
left: 10px;
top: -11px;
}

&::before {
border-bottom: 12px solid rgba(218, 225, 232, 0.8);
border-left: 14px solid transparent;
border-right: 14px solid transparent;
left: 9px;
top: -12px;
}

.gux-flyout {
&-content {
display: flex;
flex-direction: column;
}
}
}
35 changes: 35 additions & 0 deletions src/components/beta/gux-flyout-menu-beta/gux-flyout-menu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Component, Element, Event, EventEmitter, h } from '@stencil/core';

@Component({
styleUrl: 'gux-flyout-menu.less',
tag: 'gux-flyout-menu-beta'
})
export class GuxFlyoutMenu {
@Element()
root: HTMLElement;

@Event()
menuOptionSelected: EventEmitter;

private optionSelectedHandler(ev: MouseEvent): void {
this.menuOptionSelected.emit(ev.detail);
}

componentDidLoad(): void {
this.root.addEventListener(
'optionSelected',
this.optionSelectedHandler.bind(this)
);
}

componentDidUnload(): void {
this.root.removeEventListener(
'optionSelected',
this.optionSelectedHandler.bind(this)
);
}

render() {
return <slot />;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Style
gux-flyout-option-beta {
box-sizing: border-box;
color: #000;
display: flex;
font-size: 12px;
height: auto;
justify-content: space-between;
line-height: 32px;
padding: 0 16px;
position: relative;
width: 100%;

.gux-flyout-option-container {
width: 100%;

> gux-flyout-submenu-beta {
display: none;
}

.gux-flyout-option-container-item {
align-items: center;
display: flex;
justify-content: space-between;
}
}

&:hover,
&:active,
&:focus {
background: #2a60c8;
color: #fff;
cursor: pointer;
outline: none;

> .gux-flyout-option-container > gux-flyout-submenu-beta {
display: block;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import {
Component,
Element,
h,
Listen,
Event,
Prop,
EventEmitter
} from '@stencil/core';

@Component({
styleUrl: 'gux-flyout-option.less',
tag: 'gux-flyout-option-beta'
})
export class GuxFlyoutOption {
@Element()
root: HTMLElement;

@Prop() withIcon: boolean;
@Prop() shortCut: string;
@Prop() keyCode?: string;
@Prop() secondKeyCode?: string;
@Prop() thirdKeyCode?: string;

private keycodes: string[] = [];

@Event()
optionSelected: EventEmitter;

@Listen('keydown', { target: 'window' })
keyDownHandler(ev: KeyboardEvent) {
if (this.keycodes.length === 3) {
this.keycodes.shift();
}

this.keycodes.push(ev.keyCode.toString());

if (this.shortCut) {
this.checkForShortcut();
}
}

@Listen('keyup', { target: 'window' })
keyUpHandler() {
this.keycodes = [];
}

private checkForShortcut(): void {
const optionShortcut = [
this.keyCode,
this.secondKeyCode,
this.thirdKeyCode
].filter((keyCode: string) => !!keyCode);

if (optionShortcut.length === 0) {
return;
}

const isShortCutPressed = optionShortcut.every(
(keycode: string, index: number) => {
return keycode === this.keycodes[index];
}
);

if (isShortCutPressed) {
this.handleOptionSelected();
}
}

private isIcon(): HTMLElement {
return this.withIcon ? (
<gux-icon screenreaderText="angle-right" icon-name="angle-right" />
) : (
<span> {this.shortCut} </span>
);
}

private handleOptionSelected(): void {
const isSubmenu = !!this.root.querySelector('[slot="submenu"]');

if (!isSubmenu) {
this.optionSelected.emit(
this.root.querySelector('[slot="title"]').innerHTML
);
}
}

render() {
return (
<div class="gux-flyout-option-container">
<div
class="gux-flyout-option-container-item"
onClick={this.handleOptionSelected.bind(this)}
>
<div>
<slot name="title" />
</div>
{this.isIcon()}
</div>
<slot name="submenu" />
</div>
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# gux-flyout-option



<!-- Auto Generated Below -->


## Properties

| Property | Attribute | Description | Type | Default |
| --------------- | ----------------- | ----------- | --------- | ----------- |
| `keyCode` | `key-code` | | `string` | `undefined` |
| `secondKeyCode` | `second-key-code` | | `string` | `undefined` |
| `shortCut` | `short-cut` | | `string` | `undefined` |
| `thirdKeyCode` | `third-key-code` | | `string` | `undefined` |
| `withIcon` | `with-icon` | | `boolean` | `undefined` |


## Events

| Event | Description | Type |
| ---------------- | ----------- | ------------------ |
| `optionSelected` | | `CustomEvent<any>` |


## Dependencies

### Depends on

- [gux-icon](../../../stable/gux-icon)

### Graph
```mermaid
graph TD;
gux-flyout-option-beta --> gux-icon
style gux-flyout-option-beta fill:#f9f,stroke:#333,stroke-width:4px
```

----------------------------------------------

*Built with [StencilJS](https://stenciljs.com/)*
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { newSpecPage } from '@stencil/core/testing';
import { GuxFlyoutOption } from '../gux-flyout-option';

describe('GuxFlyoutOption', () => {
let component: GuxFlyoutOption;

beforeEach(async () => {
const page = await newSpecPage({
components: [GuxFlyoutOption],
html: `
<gux-flyout-option-beta
short-cut="Crl+Alt+A"
key-code="19"
second-key-code="34"
third-key-code="11"
>
<div slot="title">Option One</div>
</gux-flyout-option-beta>
`,
language: 'en'
});

component = page.rootInstance;
});

it('should build', async () => {
expect(component).toBeInstanceOf(GuxFlyoutOption);
});
});
Loading