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(dialog): add vwc-dialog #580

Merged
merged 28 commits into from
Jan 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3979d2a
Add the dialog component skeleton
YonatanKra Jan 10, 2021
1714a03
Merge remote-tracking branch 'upstream/master' into mwc-modal-window
YonatanKra Jan 10, 2021
172b853
Merge remote-tracking branch 'upstream/master' into mwc-modal-window
YonatanKra Jan 13, 2021
ab8cc8b
the dialog + prettier
YonatanKra Jan 13, 2021
8d5b70b
Dialog now extends mwc-dialog
YonatanKra Jan 17, 2021
4270372
Add headless dev command
YonatanKra Jan 17, 2021
8c9cbfe
Fix headless dev mode
YonatanKra Jan 17, 2021
099472c
Merge remote-tracking branch 'upstream/master' into mwc-modal-window
YonatanKra Jan 17, 2021
8a77fda
Depcheck issues fixed
YonatanKra Jan 17, 2021
ae3c366
Fix stupid typo :)
YonatanKra Jan 17, 2021
db7c4cf
Prettier
YonatanKra Jan 17, 2021
0c1ed04
Setup the dialog in the storybook
YonatanKra Jan 17, 2021
b34e663
Merge remote-tracking branch 'upstream/master' into mwc-modal-window
YonatanKra Jan 17, 2021
cfe68db
Conform to new tsconfig settings
YonatanKra Jan 17, 2021
620543f
Apply suggestions from code review
YonatanKra Jan 17, 2021
cd7d797
updating the dependencies to the rest of the repo
gullerya Jan 17, 2021
9226d9e
Updated yarn.lock
YonatanKra Jan 17, 2021
c3d69df
Merge remote-tracking branch 'upstream/mwc-modal-window' into mwc-mod…
YonatanKra Jan 17, 2021
3078cff
Dep cleanup
YonatanKra Jan 17, 2021
f52d058
Prettier
YonatanKra Jan 17, 2021
ca6c040
Change naming conventions
YonatanKra Jan 17, 2021
636d8ac
Fix
YonatanKra Jan 17, 2021
443706d
Update components/dialog/stories/dialog.stories.js
yinonov Jan 17, 2021
863b57b
Update components/dialog/package.json
yinonov Jan 17, 2021
d971b1e
Update components/dialog/stories/dialog.stories.js
yinonov Jan 17, 2021
0ccf0b0
Update package.json
yinonov Jan 17, 2021
1ca215d
Add stories to SB
YonatanKra Jan 18, 2021
ff84424
Merge remote-tracking branch 'upstream/master' into mwc-modal-window
YonatanKra Jan 18, 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
42 changes: 42 additions & 0 deletions __snapshots__/Dialog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# `Dialog`

#### `should internal contents`

```html
<div
aria-describedby="content"
aria-labelledby="title"
aria-modal="true"
class="mdc-dialog"
role="alertdialog"
>
<div class="mdc-dialog__container">
<div class="mdc-dialog__surface">
<div
class="mdc-dialog__content"
id="content"
>
<slot id="contentSlot">
</slot>
</div>
<footer
class="mdc-dialog__actions"
id="actions"
>
<span>
<slot name="secondaryAction">
</slot>
</span>
<span>
<slot name="primaryAction">
</slot>
</span>
</footer>
</div>
</div>
<div class="mdc-dialog__scrim">
</div>
</div>

```

24 changes: 12 additions & 12 deletions common/foundation/src/form-association/submit-on-enter-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import { requestSubmit } from '../form-association';
import { getFormByIdOrClosest } from './common';

export function submitOnEnter(element: HTMLInputElement): void {
element.addEventListener('keydown', function (
this: HTMLInputElement,
event: KeyboardEvent
) {
const form = getFormByIdOrClosest(this);
if (!form) {
return;
}
element.addEventListener(
'keydown',
function (this: HTMLInputElement, event: KeyboardEvent) {
const form = getFormByIdOrClosest(this);
if (!form) {
return;
}

if (event.key === 'Enter') {
event.preventDefault();
requestSubmit(form);
if (event.key === 'Enter') {
event.preventDefault();
requestSubmit(form);
}
}
});
);
}
32 changes: 32 additions & 0 deletions components/dialog/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@vonage/vwc-dialog",
"version": "1.0.2",
"description": "dialog component",
"homepage": "https://github.com/Vonage/vivid/tree/master/components/dialog#readme",
"license": "ISC",
"main": "vwc-dialog.js",
"module": "vwc-dialog.js",
"files": [
"*.js",
"*.ts",
"*.map"
],
"repository": {
"type": "git",
"url": "https://github.com/vonage/vivid.git",
"directory": "components/dialog"
},
"scripts": {
"test": "echo \"Error: run tests from root\" && exit 1"
},
"bugs": {
"url": "https://github.com/Vonage/vivid/issues"
},
"dependencies": {
"@material/mwc-dialog": "^0.20.0",
"@vonage/vvd-style-coupling": "1.0.2",
"@vonage/vvd-foundation": "1.0.2",
"lit-element": "^2.4.0",
"tslib": "^2.0.3"
}
}
15 changes: 15 additions & 0 deletions components/dialog/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# vwc-dialog
gullerya marked this conversation as resolved.
Show resolved Hide resolved

Add a description of vwc-dialog.

## Properties

| Property | Type |
|---------------------------|-------------------------------------------|
| `prop ` | `propType` |

## Methods

| Method | Type |
|---------|------------|
| `method`| `(): void` |
6 changes: 6 additions & 0 deletions components/dialog/src/vwc-dialog.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@use '@vonage/vvd-foundation/scss/variable-names/color-semantic-variable-names' as color-semantic;
@use '@vonage/vvd-foundation/scss/mixins/color-connotation-mixins';

:host {

}
Comment on lines +1 to +6
Copy link
Contributor

Choose a reason for hiding this comment

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

remove the file if unnecessary. it also requires a package implicitly

26 changes: 26 additions & 0 deletions components/dialog/src/vwc-dialog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { customElement } from 'lit-element';
import { style } from './vwc-dialog.css';
import { Dialog as MWCDialog } from '@material/mwc-dialog';
import { style as mwcDialogStyle } from '@material/mwc-dialog/mwc-dialog-css';
import { style as styleCoupling } from '@vonage/vvd-style-coupling';

declare global {
interface HTMLElementTagNameMap {
'vwc-dialog': VWCDialog;
}
}

/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-ignore
MWCDialog.styles = [styleCoupling, mwcDialogStyle, style];

@customElement('vwc-dialog')
export class VWCDialog extends MWCDialog {
connectedCallback(): void {
super.connectedCallback();
}

disconnectedCallback(): void {
super.disconnectedCallback();
}
}
15 changes: 15 additions & 0 deletions components/dialog/stories/arg-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const argTypes = {
connotation: {
control: {
type: 'select',
options: ['primary', 'cta', 'success', 'error', 'info', 'announcement'],
}
},
disabled: {
control: {
type: 'inline-radio',
options: { 'true': '', 'false': undefined }
}
},
styles: { table: { disable: true } },
}
41 changes: 41 additions & 0 deletions components/dialog/stories/dialog.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import '@vonage/vwc-dialog/vwc-dialog.js';
import '@vonage/vwc-button';
import { html } from 'lit-element';
import { spread } from '@open-wc/lit-helpers';
import { argTypes } from './arg-types.js';

export default {
title: 'Components/Atoms/Dialog',
component: 'vwc-dialog',
argTypes
};

const Template = args => html`
<vwc-button @click="${handleOpenDialogClick}">Open dialog</vwc-button>
<vwc-dialog ...=${spread(args)}>
<div>This is the modal's content.</div>
<vwc-button
slot="primaryAction"
dialogAction="discard">
Discard
</vwc-button>
<vwc-button
slot="secondaryAction"
dialogAction="cancel">
Cancel
</vwc-button>
</vwc-dialog>
`;

export const Basic = Template.bind({});
Basic.args = { id: 'dialog-a' };

export const Heading = Template.bind({});
Heading.args = { id: 'dialog-a', heading: 'Hello Modal!'};

export const Stacked = Template.bind({});
Stacked.args = { id: 'dialog-a', stacked: ''};

function handleOpenDialogClick(e) {
e.target.parentNode.querySelector('#dialog-a').show();
}
28 changes: 28 additions & 0 deletions components/dialog/test/dialog.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import '../vwc-dialog.js';
import {
waitNextTask,
textToDomToParent,
isolatedElementsCreation,
} from '../../../test/test-helpers.js';
import { chaiDomDiff } from '@open-wc/semantic-dom-diff';

chai.use(chaiDomDiff);

const COMPONENT_NAME = 'vwc-dialog';

describe('Dialog', () => {
let addElement = isolatedElementsCreation();

it(`${COMPONENT_NAME} is defined as a custom element`, async () => {
assert.exists(customElements.get(COMPONENT_NAME));
});

it('should internal contents', async () => {
const addedElements = addElement(
textToDomToParent(`<${COMPONENT_NAME}>Button Text</${COMPONENT_NAME}>`)
);
const actualElement = addedElements[0];
await waitNextTask();
expect(actualElement.shadowRoot.innerHTML).to.equalSnapshot();
});
});
26 changes: 26 additions & 0 deletions components/dialog/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"extends": "../../tsconfig.settings.json",
"compilerOptions": {
"composite": true,
"rootDir": "src",
"outDir": "./",
"tsBuildInfoFile": ".tsbuildinfo"
},
"include": [
"src/*.ts"
],
"exclude": [
"src/test/*.ts"
],
"references": [
{
"path": "../../common/core"
},
{
"path": "../../common/foundation"
},
{
"path": "../../common/style-coupling"
}
]
}
10 changes: 10 additions & 0 deletions karma.conf.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const fetchOriginalConfig = require('./karma.conf');
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to split this change (and the relevant package.json mods) into a different PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dunno - does this disturb you? Can look at it as refactor...

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it specific to add vwc-dialog, or does it affect other components?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It affects nothing. Just a utility that helps me speed up development using TDD.


const browsers = [process.env.RUN === 'CI' ? 'ChromeHeadless' : 'Chrome'];
module.exports = config => {
const originalConfig = fetchOriginalConfig(config);
originalConfig.browsers = browsers;
originalConfig.autoWatch = true;
originalConfig.singleRun = false;
return originalConfig;
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"test:chrome": "karma start --coverage --browsers=ChromeHeadless",
"test:firefox": "karma start --coverage --browsers=FirefoxHeadless",
"test:safari": "karma start --coverage --browsers=SafariNative",
"test:dev": "yarn compile && concurrently \"yarn tsc:watch\" \"karma start --auto-watch=true --single-run=false --browsers=Chrome\"",
"test:dev": "yarn compile && concurrently \"yarn tsc:watch\" \"karma start karma.conf.spec.js\"",
"test:dev:ci": "yarn compile && concurrently \"yarn tsc:watch\" \"RUN=CI karma start karma.conf.spec.js\"",
"test:update-snapshots": "karma start --update-snapshots",
"test:prune-snapshots": "karma start --prune-snapshots",
"test:bs": "karma start karma.bs.config.js --coverage",
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
{ "path": "components/checkbox" },
{ "path": "components/chips" },
{ "path": "components/circular-progress" },
{ "path": "components/dialog" },
{ "path": "components/drawer" },
{ "path": "components/expansion-panel" },
{ "path": "components/fab" },
Expand Down
Loading