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-side-drawer): add modal support #1002

Merged
merged 93 commits into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from 76 commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
20b9f05
feat(vwc-side-drawer): 1st draft
rinaok Jul 20, 2021
7d0d6fe
story added
rinaok Jul 25, 2021
4a0862c
story added
rinaok Jul 25, 2021
dabc12d
semi-transparent content model
yinonov Jul 25, 2021
a22dba3
alternate scheme
yinonov Jul 25, 2021
f19388c
alternate
rinaok Jul 25, 2021
4d165af
devider check
rinaok Jul 26, 2021
7f66692
working example
yinonov Jul 26, 2021
22d7599
this will break
yinonov Jul 26, 2021
e080a8c
this will not break
yinonov Jul 26, 2021
2a5ee28
slot="navigation"
rinaok Jul 26, 2021
e80c316
margin list
rinaok Jul 26, 2021
f0d12e1
side drawer bigger inline size
rinaok Jul 26, 2021
2d31f37
side drawer position
rinaok Jul 26, 2021
65cf376
appContent inlined
rinaok Jul 27, 2021
8c13aca
Merge branch 'master' into VIV-642/feature/vwc-side-drawer
tveinfeld Jul 28, 2021
cac389b
Merge branch 'master' into VIV-642/feature/vwc-side-drawer
tveinfeld Jul 28, 2021
cf6a3c6
documentation, header, image
rinaok Jul 28, 2021
e09a4c6
vvd-umbrella under devDependencies
rinaok Jul 29, 2021
3d3ac8f
@prop
rinaok Jul 29, 2021
7ff4b73
readme
rinaok Jul 29, 2021
73008d3
Update package.json
yinonov Jul 29, 2021
95f4109
Update package.json
yinonov Jul 29, 2021
0eb435f
Update package.json
yinonov Jul 29, 2021
fdc05ea
Update package.json
yinonov Jul 29, 2021
f09eb4e
Update package.json
yinonov Jul 29, 2021
51b3c8f
add border and shadow to side drawer
rinaok Jul 29, 2021
c7ed50d
activated
rinaok Jul 29, 2021
d9c5bfd
style
rinaok Jul 29, 2021
2d59c66
Extension panel should not be activated
rinaok Aug 1, 2021
913b230
wider side drawer
rinaok Aug 1, 2021
449102c
slots documentation
rinaok Aug 1, 2021
339ec8b
Merge branch 'master' into VIV-642/feature/vwc-side-drawer
yinonov Aug 2, 2021
f45ff02
restore yarn.lock
yinonov Aug 2, 2021
1c58e80
refer correct tokens
yinonov Aug 2, 2021
9cbb155
refactor
yinonov Aug 2, 2021
a182b0b
surface added
rinaok Aug 3, 2021
324d187
declartiveness
yinonov Aug 3, 2021
4186fd5
Merge branch 'VIV-642/feature/vwc-side-drawer' into vwc-side-drawer-m…
rinaok Aug 3, 2021
8e0bf63
merge
rinaok Aug 3, 2021
dd69915
Merge branch 'VIV-642/feature/vwc-side-drawer' into vwc-side-drawer-m…
yinonov Aug 3, 2021
0a04ad9
story issues
yinonov Aug 3, 2021
2e916ea
correct module import
yinonov Aug 3, 2021
80258e4
proxy props
yinonov Aug 3, 2021
f68e41a
modal support
yinonov Aug 3, 2021
39e8bef
styles
yinonov Aug 3, 2021
86cc100
Merge branch 'VIV-642/feature/vwc-side-drawer' of https://github.com/…
rinaok Aug 3, 2021
eea3de6
scrim added
yinonov Aug 3, 2021
c5ae861
run-time z-index for scrim
yinonov Aug 3, 2021
1d9ef8f
arg types
yinonov Aug 3, 2021
81a5400
open and close drawer with scrim and toggle button
rinaok Aug 3, 2021
c6e74a9
open drawer mode just in modal
rinaok Aug 4, 2021
cc4e3f6
open mode in alternate
rinaok Aug 4, 2021
847d44c
open simple naming
yinonov Aug 4, 2021
57a3281
Merge branches 'vwc-side-drawer-modal' and 'vwc-side-drawer-modal' of…
yinonov Aug 4, 2021
da2023a
removed the toggle button
rinaok Aug 4, 2021
5a344ae
scrim bug fix
rinaok Aug 4, 2021
594a8b7
refactor members
yinonov Aug 4, 2021
927f587
Merge branch 'vwc-side-drawer-modal' of https://github.com/Vonage/viv…
yinonov Aug 4, 2021
78c2ae8
open and close animations
rinaok Aug 4, 2021
5e149f6
some modifications
yinonov Aug 5, 2021
dfd799f
super.disconnectedCallback
yinonov Aug 5, 2021
b3ebb72
close on keydown
rinaok Aug 5, 2021
0703733
closing and opening
rinaok Aug 5, 2021
9e9e458
add blockingElements
yinonov Aug 8, 2021
aa98411
position absolute instead of fixed
rinaok Aug 8, 2021
2bba6c9
side drawer transition ended
rinaok Aug 8, 2021
e92b05a
opened and closed
rinaok Aug 8, 2021
84beb5e
closed and opened
rinaok Aug 8, 2021
49de5e2
modal absolute
rinaok Aug 8, 2021
0bda842
notifyClose and notifyOpen
rinaok Aug 8, 2021
dfbf9f3
UI test
rinaok Aug 10, 2021
f4f8706
on-base missing
yinonov Aug 10, 2021
ddd1b34
tests
rinaok Aug 10, 2021
e9a5553
tests
rinaok Aug 10, 2021
55004a4
Merge branch 'master' of https://github.com/Vonage/vivid into vwc-sid…
rinaok Aug 10, 2021
bb5a3eb
open and close test
rinaok Aug 11, 2021
c476e20
disfunctional test
yinonov Aug 11, 2021
e882fca
Test transitionEnd
YonatanKra Aug 12, 2021
b3be796
open and close test
rinaok Aug 14, 2021
bd5ff7d
test release and focus events
rinaok Aug 14, 2021
69bd84a
remove transitionend listener
rinaok Aug 15, 2021
61736e6
a11y test
rinaok Aug 15, 2021
8fee83f
duplications in test
rinaok Aug 15, 2021
2995fee
unite tests
rinaok Aug 15, 2021
245eb88
side-drawer snapshot
rinaok Aug 15, 2021
6e0082d
remove slots from summary
rinaok Aug 15, 2021
cef81b9
jsdocs fire
rinaok Aug 15, 2021
1b2919f
jsdoc
rinaok Aug 15, 2021
f3f6256
Merge branch 'master' into vwc-side-drawer-modal
rinaok Aug 16, 2021
8af5d01
Merge branch 'master' into vwc-side-drawer-modal
tveinfeld Aug 16, 2021
f655760
change css naming
rinaok Aug 16, 2021
af86996
jsdoc
rinaok Aug 16, 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
2 changes: 1 addition & 1 deletion __snapshots__/Side-drawer.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#### `should internal contents`

```html
<aside class="side-drawer">
<aside class="side-drawer vvd-side-drawer--open">
<div class="vvd-side-drawer--content">
<slot>
</slot>
Expand Down
9 changes: 9 additions & 0 deletions common/foundation/scss/mixins/_scrim.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$vvd-scrim--background-color: --vvd-scrim--background-color;
$vvd-scrim--opacity: --vvd-scrim--opacity;

@use '@vonage/vvd-design-tokens/build/scss/semantic-variables/scheme-variables' as scheme-variables;

@mixin scrim-variables {
#{$vvd-scrim--background-color}: var(#{scheme-variables.$vvd-color-neutral});
#{$vvd-scrim--opacity}: 0.32;
}
2 changes: 1 addition & 1 deletion components/dialog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@
"@vonage/vvd-umbrella": "2.17.0",
"typescript": "^4.3.2"
}
}
}
6 changes: 4 additions & 2 deletions components/dialog/src/vwc-dialog.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@use '@vonage/vvd-typography/scss/typography' as typography;
@use '@vonage/vvd-design-tokens/build/scss/semantic-variables/scheme-variables' as scheme-variables;
@use '@vonage/vvd-foundation/scss/mixins/scrim' as scrim-mixins;

#title,
#content,
Expand Down Expand Up @@ -47,8 +48,9 @@
}

.mdc-dialog .mdc-dialog__scrim {
--mdc-dialog-scrim-color: var(#{scheme-variables.$vvd-color-neutral});
opacity: 0.32;
--mdc-dialog-scrim-color: var(#{scrim-mixins.$vvd-scrim--background-color});
@include scrim-mixins.scrim-variables;
opacity: var(#{scrim-mixins.$vvd-scrim--opacity});
}

.dismiss-button {
Expand Down
168 changes: 157 additions & 11 deletions components/side-drawer/src/vwc-side-drawer-base.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import 'blocking-elements';
import 'wicg-inert';

import {
html, LitElement, TemplateResult, property,
} from 'lit-element';
import { nothing } from 'lit-html';
import { ifDefined } from 'lit-html/directives/if-defined';
import { classMap } from 'lit-html/directives/class-map';
import { observer } from '@material/mwc-base/observer';
import { DocumentWithBlockingElements } from 'blocking-elements';

const blockingElements =
(document as DocumentWithBlockingElements).$blockingElements;

/**
* @slot header - The content of the header.
Expand All @@ -29,43 +36,182 @@ export class VWCSideDrawerBase extends LitElement {
@property({ type: Boolean, reflect: true })
hasTopBar?: boolean;

/**
* @prop type - can be modal, dismissible or empty
* accepts String value
* @public
* */
@property({ type: String, reflect: true })
type = '';

/**
* @prop absolute - the modal can be fixed or absolute
* accepts Boolean value
* @public
* */
@property({ type: Boolean, reflect: true })
absolute = false;

@property({ type: Boolean, reflect: true })
@observer(function (
this: VWCSideDrawerBase,
isOpen: boolean,
wasOpen: boolean
) {
if (isOpen) {
this.show();
// wasOpen helps with first render (when it is `undefined`) perf
} else if (wasOpen !== undefined) {
this.close();
}
this.openChanged(isOpen);
})
open = true;
/**
* Invoked when the element open state is updated.
*
* Expressions inside this method will trigger upon open state change
*
* @param _isOpen Boolean of open state
*/ openChanged(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_isOpen: boolean
// eslint-disable-next-line @typescript-eslint/no-empty-function
): void {}

/**
* Opens the drawer from the closed state.
*/
show(): void {
this.open = true;
}

/**
* Closes the drawer from the open state.
*/
close(): void {
this.open = false;
}

/**
* Side drawer finished open animation.
*/
#opened(): void {
this.trapFocus();
this.notifyOpen();
}

/**
* Side drawer finished close animation.
*/
#closed(): void {
this.releaseFocus();
this.notifyClose();
}

notifyClose(): void {
const init: CustomEventInit = { bubbles: true, composed: true };
const ev = new CustomEvent('closed', init);
this.open = false;
this.dispatchEvent(ev);
}

notifyOpen(): void {
const init: CustomEventInit = { bubbles: true, composed: true };
const ev = new CustomEvent('opened', init);
this.open = true;
this.dispatchEvent(ev);
}

disconnectedCallback(): void {
super.disconnectedCallback();
this.releaseFocus();
}

trapFocus(): void {
blockingElements.push(this);
}

releaseFocus(): void {
blockingElements.remove(this);
}

#handleScrimClick(): void {
if (this.type === 'modal' && this.open) {
this.close();
}
}

#onKeydown({ key }: KeyboardEvent): void {
console.log(this.type, this.open, key);
if (this.type === 'modal' && this.open && key === 'Escape') {
this.close();
}
}

#onTransitionEnd(): void {
if (this.type === 'modal') {
// when side drawer finishes open animation
if (this.open) {
this.#opened();
} else {
// when side drawer finishes close animation
this.#closed();
}
}
}

private renderTopBar(): TemplateResult {
return html`<div class="vvd-side-drawer--top-bar">
<slot name="top-bar"></slot>
</div>`;
}

private renderScrim(): TemplateResult {
// eslint-disable-next-line lit-a11y/click-events-have-key-events
return html`<div
class="vvd-side-drawer--scrim ${this.absolute
? 'vvd-side-drawer--absolute'
: ''}"
@click="${this.#handleScrimClick}"
></div>`;
}

/**
* the html markup
* @internal
* */
protected render(): TemplateResult {
const topBar = this.hasTopBar
? this.renderTopBar()
: nothing;

const alternate = this.alternate
? 'vvd-scheme-alternate'
: undefined;
const dismissible = this.type === 'dismissible' || this.type === 'modal';
const modal = this.type === 'modal';
const topBar = this.hasTopBar ? this.renderTopBar() : '';
const scrim = this.type === 'modal' && this.open ? this.renderScrim() : '';
const alternate = this.alternate ? 'vvd-scheme-alternate' : undefined;
const absolute = this.type === 'modal' && this.absolute;

const classes = {
'vvd-side-drawer--alternate': this.alternate,
// 'vvd-side-drawer--modal': this.modal, // !@rinaok use with modal
'vvd-side-drawer--dismissible': dismissible,
'vvd-side-drawer--modal': modal,
'vvd-side-drawer--open': this.open,
'vvd-side-drawer--absolute': absolute,
};

return html`
<aside
part="${ifDefined(alternate)}"
class="side-drawer ${classMap(classes)}"
@keydown=${this.#onKeydown}
@transitionend=${this.#onTransitionEnd}
>

${topBar}

<div class="vvd-side-drawer--content">
<slot></slot>
</div>

</aside>

${scrim}
`;
}
}
85 changes: 73 additions & 12 deletions components/side-drawer/src/vwc-side-drawer.scss
Original file line number Diff line number Diff line change
@@ -1,38 +1,99 @@
$vvd-side-drawer--padding: --vvd-side-drawer--padding;
$vvd-side-drawer--min-inline-size: --vvd-side-drawer--min-inline-size;
$vvd-side-drawer--z-index: --vvd-side-drawer--z-index;

$z-index-default: var(#{$vvd-side-drawer--z-index}, 6);
$padding-default: var(#{$vvd-side-drawer--padding}, 16px);
$min-width: 280px;

@use '@vonage/vvd-design-tokens/build/scss/semantic-variables/scheme-variables' as scheme-variables;
@use '@vonage/vvd-typography/scss/typography' as typography;
@use '@vonage/vvd-foundation/scss/mixins/scrim' as scrim-mixins;

:host {
--vvd-side-drawer--padding: 16px;
display: flex;
min-inline-size: 280px;
block-size: 100%;
}

.side-drawer {
block-size: 100%;
inline-size: 100%;
// box-sizing: border-box;
// padding: 10px;
// margin: 0;
z-index: #{$z-index-default};
color: var(#{scheme-variables.$vvd-color-on-base});
min-inline-size: var(#{$vvd-side-drawer--min-inline-size}, $min-width);
&:not(.vvd-side-drawer--alternate):not(.vvd-side-drawer--modal) {
background-color: var(#{scheme-variables.$vvd-color-neutral-10});
}
&.vvd-side-drawer--alternate,
&.vvd-side-drawer--alternate {
background-color: var(#{scheme-variables.$vvd-color-base});
}
&.vvd-side-drawer--modal {
background-color: var(#{scheme-variables.$vvd-color-base});
@media screen and (prefers-reduced-motion: reduce) {
&.vvd-side-drawer--open {
transform: translateX(0%);
transition: none;
}
}

&.vvd-side-drawer--open {
transform: translateX(0%);
transition: transform 0.5s linear;
}@media screen and (prefers-reduced-motion: reduce) {
&:not(.vvd-side-drawer--open) {
transform: translateX(-100%);
transition: none;
}
}
&:not(.vvd-side-drawer--open) {
transform: translateX(-100%);
transition: transform 0.5s linear;
}
}
}

.vvd-side-drawer--top-bar {
display: flex;
align-items: center;
block-size: 64px;
padding-inline-end: var(#{$vvd-side-drawer--padding}--top-bar, var(#{$vvd-side-drawer--padding}));
padding-inline-start: var(#{$vvd-side-drawer--padding}--top-bar, var(#{$vvd-side-drawer--padding}));
padding-inline-end: var(#{$vvd-side-drawer--padding}--top-bar, #{$padding-default});
padding-inline-start: var(#{$vvd-side-drawer--padding}--top-bar, #{$padding-default});
}

.vvd-side-drawer--content {
padding-inline-end: var(#{$vvd-side-drawer--padding}--content, var(#{$vvd-side-drawer--padding}));
padding-inline-start: var(#{$vvd-side-drawer--padding}--content, var(#{$vvd-side-drawer--padding}));
padding-inline-end: var(#{$vvd-side-drawer--padding}--content, #{$padding-default});
padding-inline-start: var(#{$vvd-side-drawer--padding}--content, #{$padding-default});
}

.vvd-side-drawer--modal {
top: 0;
right: initial;
bottom: 0;
left: 0;

&.vvd-side-drawer--absolute {
position: absolute;
}
&:not(.vvd-side-drawer--absolute) {
position: fixed;
}
}

.vvd-side-drawer--scrim {
@include scrim-mixins.scrim-variables;
z-index: calc(#{$z-index-default} - 1);
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: var(#{scrim-mixins.$vvd-scrim--background-color});
opacity: var(#{scrim-mixins.$vvd-scrim--opacity});

&.vvd-side-drawer--absolute {
position: absolute;
}
&:not(.vvd-side-drawer--absolute) {
position: fixed;
}
}



1 change: 0 additions & 1 deletion components/side-drawer/src/vwc-side-drawer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import '@vonage/vvd-core';
import { customElement } from 'lit-element';

import { VWCSideDrawerBase } from './vwc-side-drawer-base.js';
import { style } from './vwc-side-drawer.css.js';

Expand Down
Loading