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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(side-drawer): add end and start positions #1146

Merged
merged 17 commits into from
Dec 14, 2021
4 changes: 2 additions & 2 deletions __snapshots__/Side-drawer.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
#### `should internal contents`

```html
<aside class="side-drawer">
<aside class="side-drawer side-drawer--start">
rinaok marked this conversation as resolved.
Show resolved Hide resolved
<div class="side-drawer--content">
<slot>
</slot>
</div>
</aside>
<div class="side-drawer--app-content">
<div class="side-drawer--app-content side-drawer--start">
rinaok marked this conversation as resolved.
Show resolved Hide resolved
<slot name="app-content">
</slot>
</div>
Expand Down
29 changes: 17 additions & 12 deletions components/side-drawer/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ Represents a side drawer custom element.

## Properties

| Property | Attribute | Type | Default |
| ----------- | ----------- | ---------------------- | ------- |
| `alternate` | `alternate` | `boolean` | false |
| `hasTopBar` | `hasTopBar` | `boolean \| undefined` | |
| `open` | `open` | `boolean` | false |
| `type` | `type` | `string` | "" |
| Property | Attribute | Type | Default | Description |
| ----------- | ----------- | --------------------------------------- | ------- | ----------- |
| `alternate` | `alternate` | `boolean` | false | |
| `hasTopBar` | `hasTopBar` | `boolean \| undefined` | | |
| `open` | `open` | `boolean` | false | |
| `position` | `position` | `"start" \| "end" \| undefined` | "start" | |
| `type` | `type` | `"modal" \| "dismissible" \| undefined` | | |

## Methods

Expand All @@ -19,9 +20,13 @@ Represents a side drawer custom element.
| `show` | `(): void` | Opens the side drawer from the closed state. |


| Property | Default | Description |
| ------------------------------ | ----------------------------------------------- | ------------------------------------------- |
| `side-drawer-background-color` | "The current theme's canvas (background) color" | Controls the background of the side drawer |
| `side-drawer-inline-size` | "280px" | Controls the inline size of the side drawer |
| `side-drawer-padding` | "16px" | Controls the padding of the side drawer |
| `side-drawer-z-index` | 6 | Controls the z-index of the side drawer |
## CSS Custom Properties

| Property | Default | Description |
| ------------------------------ | ------------------------------------------- | ------------------------------------------------- |
| `side-drawer-background-color` | "Current theme's canvas (background) color" | Controls the background of the side drawer |
| `side-drawer-color` | "Current theme's on-canvas (text) color" | Controls the color of the side drawer |
| `side-drawer-inline-size` | "280px" | Controls the inline size of the side drawer |
| `side-drawer-padding-body` | "16px" | Controls the padding of the side drawer's body |
| `side-drawer-padding-top-bar` | "16px" | Controls the padding of the side drawer's top bar |
| `side-drawer-z-index` | 6 | Controls the z-index of the side drawer |
45 changes: 31 additions & 14 deletions components/side-drawer/src/vwc-side-drawer-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,27 @@ export class VWCSideDrawerBase extends LitElement {
})
type?: 'modal' | 'dismissible';

/**
* @prop open - indicates whether the side drawer is open
* accepts boolean value
* */
@property({
type: Boolean,
reflect: true
})
open = false;

/**
* @prop side - sets the side of the side drawer
* accepts "start" | "end"
* @public
* */
@property({
type: String,
reflect: true
})
position?: 'start' | 'end' = 'start';
rinaok marked this conversation as resolved.
Show resolved Hide resolved

/**
* Opens the side drawer from the closed state.
* @public
Expand Down Expand Up @@ -93,32 +108,38 @@ export class VWCSideDrawerBase extends LitElement {
const topBar = this.hasTopBar ? this.renderTopBar() : '';
const scrim = (this.type === 'modal' && this.open) ? this.renderScrim() : '';
const alternate = this.alternate ? 'vvd-scheme-alternate' : undefined;
const start = this.position === 'start';
const end = this.position === 'end';

const classes = {
'side-drawer--alternate': this.alternate,
'side-drawer--dismissible': dismissible,
'side-drawer--modal': modal,
'side-drawer--open': this.open,
'side-drawer--start': start,
'side-drawer--end': end,
};

const contentClassed = {
'side-drawer--start': start,
rinaok marked this conversation as resolved.
Show resolved Hide resolved
'side-drawer--end': end,
};

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

${topBar}

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

</aside>

<div class="side-drawer--app-content">
<div class="side-drawer--app-content ${classMap(contentClassed)}">
<slot name="app-content"></slot>
</div>

${scrim}
`;
}
Expand All @@ -132,11 +153,7 @@ export class VWCSideDrawerBase extends LitElement {

private renderScrim(): TemplateResult {
return html`
<div
class="side-drawer--scrim"
@click="${this.#handleScrimClick}"
@keydown="${this.#handleScrimClick}"
></div>`;
<div class="side-drawer--scrim" @click="${this.#handleScrimClick}" @keydown="${this.#handleScrimClick}"></div>`;
}

#handleScrimClick(): void {
Expand Down
27 changes: 21 additions & 6 deletions components/side-drawer/src/vwc-side-drawer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ $inline-size: var(#{variables.$side-drawer-inline-size}, 280px);
block-size: 100vh;
}

:host([position='end']) {
flex-direction: row-reverse;
}

.side-drawer {
position: fixed;
z-index: var(#{variables.$side-drawer-z-index}, #{$z-index-default});
Expand All @@ -32,9 +36,14 @@ $inline-size: var(#{variables.$side-drawer-inline-size}, 280px);

&.side-drawer--modal,
&.side-drawer--dismissible {

transform: translateX(0%);
rinaok marked this conversation as resolved.
Show resolved Hide resolved
&:not(.side-drawer--open) {
transform: translateX(-100%);
&.side-drawer--end {
transform: translateX(100%);
}
&:not(.side-drawer--end) {
transform: translateX(-100%);
}
}
@media (prefers-reduced-motion: no-preference) {
transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
Expand All @@ -46,6 +55,10 @@ $inline-size: var(#{variables.$side-drawer-inline-size}, 280px);
+ .side-drawer--app-content {
@include typography.typography-cat-shorthand(body-1);
margin-inline-start: #{$inline-size};
&.side-drawer--end {
margin-inline-end: var(--side-drawer-inline-size, 280px);
margin-inline-start: 0;
}
::slotted(vwc-top-app-bar),
::slotted(vwc-top-app-bar-fixed) {
--mdc-top-app-bar-width: calc(100% - #{$inline-size});
Expand Down Expand Up @@ -75,10 +88,12 @@ $inline-size: var(#{variables.$side-drawer-inline-size}, 280px);

.side-drawer--modal {
position: fixed;
top: 0;
rinaok marked this conversation as resolved.
Show resolved Hide resolved
right: initial;
bottom: 0;
left: 0;
&:not(.side-drawer--end) {
inset-inline-start: 0;
}
&.side-drawer--end {
inset-inline-end: 0;
}
}

.side-drawer--scrim {
Expand Down
7 changes: 7 additions & 0 deletions components/side-drawer/stories/arg-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ export const argTypes = {
open: {
control: booleanControl
},
position: {
defaultValue: 'start',
control: {
type: 'select',
options: ['start', 'end'],
}
},
type: {
control: {
type: 'select',
Expand Down
3 changes: 3 additions & 0 deletions components/side-drawer/stories/side-drawer-basic.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ Alternate.args = { alternate: true };
export const TopBar = Template.bind({});
TopBar.args = { hasTopBar: true };

export const PositionEnd = Template.bind({});
PositionEnd.args = { position: 'end' };

let prevActivatedItem;
function onClick(e) {
// only list items can be activated
Expand Down
16 changes: 16 additions & 0 deletions components/side-drawer/test/side-drawer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ describe('side-drawer', () => {
expect(actualElement.hasTopBar, 'hasTopBar should be undefined')
.to
.equal(undefined);
expect(actualElement.position, 'position should be start')
.to
.equal('start');
});
});

Expand Down Expand Up @@ -82,6 +85,19 @@ describe('side-drawer', () => {
.equal(type);
}
});

it('should reflect (position) from attribute to property', async () => {
const COMPONENT_POSITIONS = ['start', 'end'];
for await (const position of COMPONENT_POSITIONS) {
const [actualElement] = addElement(
textToDomToParent(`<${COMPONENT_NAME} position=${position}></${COMPONENT_NAME}>`)
);
await actualElement.updateComplete;
expect(actualElement.position)
.to
.equal(position);
}
});
});

describe('Modal side drawer events', () => {
Expand Down
Binary file modified ui-tests/snapshots/vwc-side-drawer.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion ui-tests/tests/vwc-side-drawer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function createElementVariations(wrapper) {

<div>
<div id="demo">
<vwc-side-drawer id="side-drawer">
<vwc-side-drawer id="side-drawer" position="end">
<span slot="top-bar">
<vwc-icon type="vonage-mono"></vwc-icon> VONAGE
</span>
Expand Down