Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vwc-surface): viv-510 iss-859 complex menu surface #863

Merged
merged 35 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9960eb3
issue #859 initial commit
gullerya May 26, 2021
4ec9f57
issue #859: initial content
gullerya May 26, 2021
cedea0c
fixing depcheck
gullerya May 26, 2021
3ada760
merging with master
gullerya May 27, 2021
b671823
merging with remote
gullerya May 30, 2021
7684e48
wip
gullerya May 31, 2021
3707a37
wip
gullerya May 31, 2021
56de34f
wip
gullerya May 31, 2021
0074c32
issue #859: refactored surface to use our own wrapper
gullerya May 31, 2021
4fa625e
issue #859: fixing the tests
gullerya May 31, 2021
e95b14a
issue #859: added complex drop down
gullerya May 31, 2021
c9bdca4
issue #859: added complex drop down
gullerya May 31, 2021
ec0fdb6
fixing dependencies
gullerya May 31, 2021
4eaac7e
fixing Sonar issues
gullerya May 31, 2021
58e0b28
Merge branch 'master' into viv-510/iss-859-complex-menu-surface
yinonov May 31, 2021
82dd6c3
issue #859: replaces mwc-list with vwc-list in menu
gullerya May 31, 2021
0f999f6
merging with remote
gullerya May 31, 2021
8e49813
issue #859: additional cleanups
gullerya May 31, 2021
e5025db
fix tests
gullerya May 31, 2021
d475535
fixing CR remarks
gullerya May 31, 2021
8375b78
fixing CR remarks
gullerya May 31, 2021
27a1c4f
merge with master
gullerya Jun 1, 2021
29faa24
issue #859: fixed as per CR remarks
gullerya Jun 1, 2021
c26ee81
issue #859: fixing CR remarks
gullerya Jun 1, 2021
13fbddb
issue #859: fixing the dark theme
gullerya Jun 1, 2021
02b0fc1
issue #859: removing unneeded variables
gullerya Jun 1, 2021
ebec32f
issue #859: removing unneeded variables
gullerya Jun 1, 2021
8cb11c2
issue #859: removing unneeded variables
gullerya Jun 1, 2021
66bf336
fixed a story: added dense and opening the dropdown on the start
gullerya Jun 2, 2021
6391848
adding chevron icon to the dropper
gullerya Jun 2, 2021
06d7003
refine story
yinonov Jun 2, 2021
7d8f153
issue #859: fixing CR remarks
gullerya Jun 2, 2021
e8febbe
merged with remote
gullerya Jun 2, 2021
914bc7e
issue #859: refactored surface styles
gullerya Jun 3, 2021
d93c6a7
issue #859: refactored surface styles
gullerya Jun 3, 2021
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
31 changes: 31 additions & 0 deletions __snapshots__/dropdown.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# `dropdown`

#### `should have internal contents`

```html
<vwc-surface
class="mdc-menu mdc-menu-surface"
hidden=""
>
<div class="dropdown-content">
<div class="header section">
<slot name="header">
</slot>
</div>
<div class="body section">
<slot>
</slot>
</div>
<div class="actions section">
<slot name="actions">
</slot>
</div>
<div class="footer section">
<slot name="footer">
</slot>
</div>
</div>
</vwc-surface>

```

10 changes: 5 additions & 5 deletions __snapshots__/vwc-menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
#### `should have internal contents`

```html
<mwc-menu-surface
<vwc-surface
class="mdc-menu mdc-menu-surface"
hidden=""
>
<mwc-list
class="mdc-deprecated-list"
<vwc-list
class="mdc-deprecated-list vwc-menu-list"
roottabbable=""
>
<slot>
</slot>
</mwc-list>
</mwc-menu-surface>
</vwc-list>
</vwc-surface>

```

11 changes: 2 additions & 9 deletions components/datepicker/test/datepicker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ describe('datepicker', () => {
);
});

// it('should have internal contents', async () => {
// const [actualElement] = addElement(
// textToDomToParent(`<${COMPONENT_NAME}></${COMPONENT_NAME}>`)
// );
// await actualElement.onReady;
// expect(actualElement.shadowRoot.innerHTML).to.equalSnapshot();
// });

it('should have lit-flatpickr instance in DOM', async () => {
const [actualElement] = addElement(
textToDomToParent(`<${COMPONENT_NAME}></${COMPONENT_NAME}>`)
Expand Down Expand Up @@ -75,7 +67,8 @@ describe('datepicker', () => {
await waitNextTask();

const vwcMenu = actualElement.shadowRoot.querySelector('vwc-menu');
const mwcMenuSurface = vwcMenu.shadowRoot.querySelector('mwc-menu-surface');
console.log(vwcMenu.shadowRoot);
const mwcMenuSurface = vwcMenu.shadowRoot.querySelector('vwc-surface');
const menuSurface = mwcMenuSurface.shadowRoot.querySelector('.mdc-menu-surface');

assertComputedStyle(menuSurface, { position: 'fixed' });
Expand Down
Empty file.
39 changes: 39 additions & 0 deletions components/dropdown/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@vonage/vwc-dropdown",
"version": "2.9.1",
"description": "dropdown component",
"homepage": "https://github.com/Vonage/vivid/tree/master/components/dropdown#readme",
"license": "ISC",
"main": "vwc-dropdown.js",
"module": "vwc-dropdown.js",
"files": [
"*.js",
"*.ts",
"*.map"
],
"repository": {
"type": "git",
"url": "https://github.com/vonage/vivid.git",
"directory": "components/dropdown"
},
"scripts": {
"test": "echo \"Error: run tests from root\" && exit 1",
"build:typescript": "tsc -b",
"build:styles": "umbrella-style-modules",
"build": "yarn run build:styles && yarn run build:typescript"
},
"bugs": {
"url": "https://github.com/Vonage/vivid/issues"
},
"dependencies": {
"@vonage/vvd-core": "2.9.1",
"@vonage/vwc-menu": "2.9.1",
"@vonage/vwc-surface": "2.9.1",
"lit-element": "^2.4.0",
"tslib": "^2.0.3"
},
"devDependencies": {
"@vonage/vvd-umbrella": "2.9.1",
"typescript": "^4.1.3"
}
}
75 changes: 75 additions & 0 deletions components/dropdown/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
### `vwc-dropdown`

`vwc-dropdown` is a surfacing content component, dropdown, showing up on demand, eg upon user action.
`vwc-dropdown`, in contrast to `vwc-menu`, allows a free content provided by consumer, while structuring the internal body with slots: `header`, `footer` and the default content.

### Usage

Usage example:
```html
<vwc-menu>
<vwc-textfield slot="header">Item 1</vwc-textfield>
<div>
any HTML content can go here as main body
</div>
<vwc-button slot="footer">Done</vwc-button>
</vwc-menu>
```

Initiate `vwc-dropdown` to be available in your component/application:
```javascript
import '@vonage/vwc-dropdown';

// or, to be able to use casting in TypeScript, do

import { VWCDropdown } from '@vonage/vwc-dropdown';
```

### API

`vwc-dropdown` exposes several APIs to provide its fuctionality, namely properties, methods and events.

#### Properties

| Property | Modifiers | Type | Description |
|---------------------------|-----------|--------------------------------------------------|--------------------------------------------------|
| `absolute` | | `boolean` | |
| `activatable` | | `boolean` | |
| `anchor` | | `HTMLElement \| null` | |
| `corner` | | `"TOP_LEFT" \| "TOP_RIGHT" \| "BOTTOM_LEFT" \| "BOTTOM_RIGHT" \| "TOP_START" \| "TOP_END" \| "BOTTOM_START" \| "BOTTOM_END"` | |
| `defaultFocus` | | `"NONE" \| "LIST_ROOT" \| "FIRST_ITEM" \| "LAST_ITEM"` | |
| `fixed` | | `boolean` | |
| `forceGroupSelection` | | `boolean` | |
| `fullwidth` | | `boolean` | |
| `index` | readonly | `MWCListIndex` | |
| `innerRole` | | `"menu" \| "listbox"` | |
| `items` | readonly | `ListItemBase[]` | |
| `menuCorner` | | `MenuCorner` | |
| `multi` | | `boolean` | |
| `open` | | `boolean` | |
| `quick` | | `boolean` | |
| `selected` | readonly | `ListItemBase \| ListItemBase[] \| null` | |
| `slotElement` | | `HTMLSlotElement \| null` | |
| `wrapFocus` | | `boolean` | |
| `x` | | `number \| null` | |
| `y` | | `number \| null` | |

#### Methods

| Method | Type |
|-----------------------|----------------------------------------------|
| `close` | `(): void` |
| `focusItemAtIndex` | `(index: number): void` |
| `getFocusedItemIndex` | `(): number` |
| `layout` | `(updateItems?: boolean \| undefined): void` |
| `select` | `(index: MWCListIndex): void` |
| `show` | `(): void` |

#### Events

| Event | Description |
|-----------------|------------------|
| `action` | {ActionDetail} |
| `closed` | |
| `opened` | |
| `selected` | {SelectedDetail} |
23 changes: 23 additions & 0 deletions components/dropdown/src/vwc-dropdown.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.dropdown-content {
padding: 24px;
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest defining a variable as we discussed for each of the sections

:host {
  --vvd-dropdown-padding-inline: 24px;
  --vvd-dropdown-body-padding-inline: var(--vvd-dropdown-padding-inline); // or 0 as default?
  --vvd-dropdown-actions-padding-inline: var(--vvd-dropdown-padding-inline);
}

that way we have full control. what do you say?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implemented!

}

.section {
display: flex;
}

.section.body {
display: block;
width: calc(100% + 48px);
margin-inline-start: -24px;
}

// actions
.section.actions {
display: flex;
justify-content: flex-end;

::slotted(vwc-button) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
::slotted(vwc-button) {
::slotted(.vwc-button + .vwc-button) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tried several syntaxes, nothing worked to me...

margin-inline-start: 8px;
}
}
63 changes: 63 additions & 0 deletions components/dropdown/src/vwc-dropdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import '@vonage/vvd-core';
import '@vonage/vwc-surface';
import { VWCMenu } from '@vonage/vwc-menu';
import { customElement, html } from 'lit-element';
import { style as vwcDropdownStyle } from './vwc-dropdown.css';

export const COMPONENT_NAME = 'vwc-dropdown';

declare global {
interface HTMLElementTagNameMap {
[COMPONENT_NAME]: VWCDropdown;
}
}

/**
* This component is an extension of [<vwc-menu>](https://github.com/Vonage/vivid/tree/master/components/menu)
*/
@customElement('vwc-dropdown')
export class VWCDropdown extends VWCMenu {
static styles = [vwcDropdownStyle];

constructor() {
super();
this.multi = true;
}

render() {
return html`
<vwc-surface
?hidden=${!this.open}
.anchor=${this.anchor}
.open=${this.open}
.quick=${this.quick}
.corner=${this.corner}
.x=${this.x}
.y=${this.y}
.absolute=${this.absolute}
.fixed=${this.fixed}
.fullwidth=${this.fullwidth}
.menuCorner=${this.menuCorner}
?stayOpenOnBodyClick=${this.stayOpenOnBodyClick}
class="mdc-menu mdc-menu-surface"
@closed=${this.onClosed}
@opened=${this.onOpened}
@keydown=${this.onKeydown}>
<div class="dropdown-content">
<div class="section header">
<slot name="header"></slot>
</div>
<div class="section body">
<slot></slot>
</div>
<div class="section actions">
<slot name="actions"></slot>
</div>
<div class="section footer">
<slot name="footer"></slot>
</div>
</div>
</vwc-surface>
`;
}
}
1 change: 1 addition & 0 deletions components/dropdown/stories/arg-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { argTypes } from '@vonage/vwc-menu/stories/arg-types.js';
9 changes: 9 additions & 0 deletions components/dropdown/stories/dropdown-all.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { argTypes } from './arg-types.js';

export default {
title: 'Alpha/Components/Dropdown',
component: 'vwc-dropdown',
argTypes
}

export { ComplexContent } from './dropdown-basic.js';
53 changes: 53 additions & 0 deletions components/dropdown/stories/dropdown-basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import '@vonage/vwc-dropdown';
import '@vonage/vwc-button';
import '@vonage/vwc-list/vwc-list-item.js';
import '@vonage/vwc-list/vwc-check-list-item.js';
import { html } from 'lit-element';
import { spread } from '@open-wc/lit-helpers';

const TemplateA = args => html`
<style>
html, body {
height: 100%;
}
</style>
<div style="position: relative">
<vwc-button id="button" label="Open dropdown" @click="${anchorClickHandler}"></vwc-button>
<vwc-dropdown id="dropdown" ...=${spread(args)}>
<vwc-textfield slot="header" label="Do something..."></vwc-textfield>
<vwc-list multi>
<vwc-check-list-item left>
Basic item 1
</vwc-check-list-item>
<vwc-check-list-item left>
Basic item 2
</vwc-check-list-item>
<vwc-check-list-item left>
Basic item 3
</vwc-check-list-item>
<vwc-check-list-item left>
Basic item 4
</vwc-check-list-item>
</vwc-list>
<vwc-button slot="actions" @click="${actionClickHandler}">Cancel</vwc-button>
<vwc-button slot="actions" layout="filled" @click="${actionClickHandler}">Done</vwc-button>
</vwc-dropdown>
</div>
`;

export const ComplexContent = TemplateA.bind({});
ComplexContent.args = {
corner: 'BOTTOM_START'
}

function anchorClickHandler() {
const anchor = document.querySelector('#button');
const dropdown = document.querySelector('#dropdown');
dropdown.anchor = anchor;
dropdown.open = true;
}

function actionClickHandler() {
const dropdown = document.querySelector('#dropdown');
dropdown.open = false;
}
14 changes: 14 additions & 0 deletions components/dropdown/stories/dropdown-introduction.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default {
sourcePath: '../readme.md',
outputName: 'dropdown-introduction',
story: {
title: 'Alpha/Components/Dropdown/Introduction',
name: 'Introduction',
parameters: {
options: {
showPanel: false,
isToolshown: false
}
}
}
};
29 changes: 29 additions & 0 deletions components/dropdown/test/dropdown.a11y.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import '@vonage/vwc-list/vwc-list-item';
import { COMPONENT_NAME } from '../vwc-dropdown.js';
import {
isolatedElementsCreation,
waitNextTask,
textToDomToParent
} from '../../../test/test-helpers.js';
import { chaiA11yAxe } from 'chai-a11y-axe';

chai.use(chaiA11yAxe);

describe('menu a11y', () => {
const addElement = isolatedElementsCreation();

it('should have 0 accessibility violations', async () => {
const [actualElement] = addElement(
textToDomToParent(`
<${COMPONENT_NAME}>
<vwc-list-item>Item 0</vwc-list-item>
<vwc-list-item>Item 1</vwc-list-item>
<vwc-list-item>Item 2</vwc-list-item>
</${COMPONENT_NAME}>
`)
);
await waitNextTask();

await expect(actualElement).shadowDom.to.be.accessible();
});
});
Loading