Skip to content

Commit

Permalink
fix(drawer): add mdc-deprecated-list
Browse files Browse the repository at this point in the history
fixes #55
  • Loading branch information
MaximBalaganskiy committed Aug 31, 2021
1 parent 1de730a commit 50cab88
Show file tree
Hide file tree
Showing 20 changed files with 612 additions and 40 deletions.
1 change: 1 addition & 0 deletions packages/all/mdc-all.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@use "@material/button/mdc-button";
@use "@material/list/evolution-mixins"as list-evolution-mixins;
@use "@material/list/mdc-list";
@use "@aurelia-mdc-web/list"as auList;
@use "@material/top-app-bar/mdc-top-app-bar";
@use "@material/icon-button/mdc-icon-button";
Expand Down
10 changes: 5 additions & 5 deletions packages/app/src/views/drawer/dismissible.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<mdc-drawer type="dismissible" view-model.ref="demoDismissible">
<mdc-drawer-header title="Drawer Title" subtitle="Subtitle"></mdc-drawer-header>
<mdc-drawer-content>
<mdc-list>
<mdc-list-item repeat.for="item of destinations" activated.bind="item.activated">
<mdc-icon mdc-list-item-leading if.bind="item.icon">${item.icon}</mdc-icon>
<mdc-deprecated-list>
<mdc-deprecated-list-item repeat.for="item of destinations" activated.bind="item.activated">
<mdc-icon mdc-deprecated-list-item-graphic if.bind="item.icon">${item.icon}</mdc-icon>
<span>${item.label}</span>
</mdc-list-item>
</mdc-list>
</mdc-deprecated-list-item>
</mdc-deprecated-list>
</mdc-drawer-content>
</mdc-drawer>
<mdc-drawer-app-content style="padding: 16px; height: 400px;">
Expand Down
10 changes: 5 additions & 5 deletions packages/app/src/views/drawer/modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<mdc-drawer type="modal" view-model.ref="demoModal">
<mdc-drawer-header title="Drawer Title" subtitle="Subtitle"></mdc-drawer-header>
<mdc-drawer-content>
<mdc-list tabindex="0">
<mdc-list-item repeat.for="item of destinations" activated.bind="item.activated">
<mdc-icon mdc-list-item-leading if.bind="item.icon">${item.icon}</mdc-icon>
<mdc-deprecated-list tabindex="0">
<mdc-deprecated-list-item repeat.for="item of destinations" activated.bind="item.activated">
<mdc-icon mdc-deprecated-list-item-graphic if.bind="item.icon">${item.icon}</mdc-icon>
<span>${item.label}</span>
</mdc-list-item>
</mdc-list>
</mdc-deprecated-list-item>
</mdc-deprecated-list>
</mdc-drawer-content>
</mdc-drawer>
<div style="padding: 16px; height: 400px;">
Expand Down
10 changes: 5 additions & 5 deletions packages/app/src/views/drawer/rtl.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<mdc-drawer type="modal" view-model.ref="demoRTL" dir="rtl">
<mdc-drawer-header title="Drawer Title" subtitle="Subtitle"></mdc-drawer-header>
<mdc-drawer-content dir="rtl">
<mdc-list tabindex="0">
<mdc-list-item repeat.for="item of destinations" activated.bind="item.activated">
<mdc-icon mdc-list-item-leading if.bind="item.icon">${item.icon}</mdc-icon>
<mdc-deprecated-list tabindex="0">
<mdc-deprecated-list-item repeat.for="item of destinations" activated.bind="item.activated">
<mdc-icon mdc-deprecated-list-item-graphic if.bind="item.icon">${item.icon}</mdc-icon>
<span>${item.label}</span>
</mdc-list-item>
</mdc-list>
</mdc-deprecated-list-item>
</mdc-deprecated-list>
</mdc-drawer-content>
</mdc-drawer>
<div style="padding: 16px; height: 400px;">
Expand Down
36 changes: 18 additions & 18 deletions packages/app/src/views/drawer/standard.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,38 @@
<mdc-drawer ref="demoPermanent">
<mdc-drawer-header title="Drawer Title" subtitle="Subtitle"></mdc-drawer-header>
<mdc-drawer-content>
<mdc-list activated>
<a mdc-list-item repeat.for="item of destinations" activated.bind="item.activated"
<mdc-deprecated-list activated>
<a mdc-deprecated-list-item repeat.for="item of destinations" activated.bind="item.activated"
click.delegate="item.activated = !item.activated">
<mdc-icon mdc-list-item-leading if.bind="item.icon">${item.icon}</mdc-icon>
<mdc-icon mdc-deprecated-list-item-graphic if.bind="item.icon">${item.icon}</mdc-icon>
<span>${item.label}</span>
</a>
<mdc-list-divider></mdc-list-divider>
<mdc-list-group>
<mdc-deprecated-list-divider></mdc-deprecated-list-divider>
<mdc-deprecated-list-group>
<h6>Labels</h6>
</mdc-list-group>
<a mdc-list-item href="#/drawer-demo/examples">
<mdc-icon mdc-list-item-leading>bookmark</mdc-icon>
</mdc-deprecated-list-group>
<a mdc-deprecated-list-item href="#/drawer-demo/examples">
<mdc-icon mdc-deprecated-list-item-graphic>bookmark</mdc-icon>
<span>Family</span>
</a>
<a mdc-list-item href="#/drawer-demo/examples">
<mdc-icon mdc-list-item-leading>bookmark</mdc-icon>
<a mdc-deprecated-list-item href="#/drawer-demo/examples">
<mdc-icon mdc-deprecated-list-item-graphic>bookmark</mdc-icon>
<span>Friends</span>
</a>
<a mdc-list-item href="#/drawer-demo/examples">
<mdc-icon mdc-list-item-leading>bookmark</mdc-icon>
<a mdc-deprecated-list-item href="#/drawer-demo/examples">
<mdc-icon mdc-deprecated-list-item-graphic>bookmark</mdc-icon>
<span>Work</span>
</a>
<mdc-list-divider></mdc-list-divider>
<a mdc-list-item href="#/drawer-demo/examples">
<mdc-icon mdc-list-item-leading>settings</mdc-icon>
<mdc-deprecated-list-divider></mdc-deprecated-list-divider>
<a mdc-deprecated-list-item href="#/drawer-demo/examples">
<mdc-icon mdc-deprecated-list-item-graphic>settings</mdc-icon>
<span>Settings</span>
</a>
<a mdc-list-item href="#/drawer-demo/examples">
<mdc-icon mdc-list-item-leading>announcement</mdc-icon>
<a mdc-deprecated-list-item href="#/drawer-demo/examples">
<mdc-icon mdc-deprecated-list-item-graphic>announcement</mdc-icon>
<span>Help & feedback</span>
</a>
</mdc-list>
</mdc-deprecated-list>
</mdc-drawer-content>
</mdc-drawer>
<div style="padding: 16px; height: 400px;">
Expand Down
8 changes: 4 additions & 4 deletions packages/app/src/views/root/root.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
<mdc-drawer view-model.ref="drawer" type="dismissible" mdc-top-app-bar-fixed-adjust>
<mdc-drawer-header title="Aurelia" subtitle="Material Components Web"></mdc-drawer-header>
<mdc-drawer-content>
<mdc-list activated wrap-focus mdclist:action.delegate="navigateTo($event.detail)" tabindex="0">
<mdc-deprecated-list activated wrap-focus mdclist:action.delegate="navigateTo($event.detail)" tabindex="0">
<template repeat.for="m of navModels">
<mdc-list-item activated.bind="m.isActive" value.bind="m">${m.title}</mdc-list-item>
<mdc-list-divider if.bind="m.config.divider"></mdc-list-divider>
<mdc-deprecated-list-item activated.bind="m.isActive" value.bind="m">${m.title}</mdc-deprecated-list-item>
<mdc-deprecated-list-divider if.bind="m.config.divider"></mdc-deprecated-list-divider>
</template>
</mdc-list>
</mdc-deprecated-list>
</mdc-drawer-content>
</mdc-drawer>
<mdc-drawer-app-content mdc-top-app-bar-fixed-adjust class="demo-panel-section">
Expand Down
4 changes: 1 addition & 3 deletions packages/drawer/src/mdc-drawer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { MdcComponent, MdcFocusTrap } from '@aurelia-mdc-web/base';
import { MDCDismissibleDrawerFoundation, cssClasses, strings, MDCModalDrawerFoundation, MDCDrawerAdapter } from '@material/drawer';
import { SpecificEventListener } from '@material/base';
import { MDCListFoundation } from '@material/list';
import { inject, useView, customElement, bindable } from 'aurelia-framework';
import { PLATFORM } from 'aurelia-pal';

Expand Down Expand Up @@ -106,8 +105,7 @@ export class MdcDrawer extends MdcComponent<MDCDismissibleDrawerFoundation | MDC
}
},
focusActiveNavigationItem: () => {
const activeNavItemEl = this.root.querySelector<HTMLElement>(
`.${MDCListFoundation.cssClasses.LIST_ITEM_ACTIVATED_CLASS}`);
const activeNavItemEl = this.root.querySelector<HTMLElement>('.mdc-deprecated-list-item--activated');
if (activeNavItemEl) {
activeNavItemEl.focus();
}
Expand Down
11 changes: 11 additions & 0 deletions packages/list/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ export function configure(config: FrameworkConfiguration) {
PLATFORM.moduleName('./mdc-list-item-secondary-text'),
PLATFORM.moduleName('./mdc-list-divider/mdc-list-divider'),
PLATFORM.moduleName('./mdc-list-group'),

PLATFORM.moduleName('./mdc-deprecated-list/mdc-deprecated-list'),
PLATFORM.moduleName('./mdc-deprecated-list/mdc-deprecated-list-item/mdc-deprecated-list-item'),
PLATFORM.moduleName('./mdc-deprecated-list/mdc-deprecated-list-item/enhance-mdc-deprecated-list-item'),
PLATFORM.moduleName('./mdc-deprecated-list/mdc-deprecated-list-item-primary-text'),
PLATFORM.moduleName('./mdc-deprecated-list/mdc-deprecated-list-item-secondary-text'),
PLATFORM.moduleName('./mdc-deprecated-list/mdc-deprecated-list-item-graphic'),
PLATFORM.moduleName('./mdc-deprecated-list/mdc-deprecated-list-item-meta'),
PLATFORM.moduleName('./mdc-deprecated-list/mdc-deprecated-list-divider/mdc-deprecated-list-divider'),
PLATFORM.moduleName('./mdc-deprecated-list/mdc-deprecated-list-group'),

]);

config.aurelia.use.plugin(PLATFORM.moduleName('@aurelia-mdc-web/ripple'));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template role="separator"
class="mdc-deprecated-list-divider ${padded ? 'mdc-deprecated-list-divider--padded' : ''} ${inset ? 'mdc-deprecated-list-divider--inset' : ''}">
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { customElement, useView, PLATFORM } from 'aurelia-framework';
import { bindable } from 'aurelia-typed-observable-plugin';

/**
* Optional, for list divider element
* @selector mdc-deprecated-list-divider
*/
@useView(PLATFORM.moduleName('./mdc-deprecated-list-divider.html'))
@customElement('mdc-deprecated-list-divider')
export class MdcDeprecatedListDivider {
/** To make a divider match the padding of list items */
@bindable.booleanAttr
padded: boolean;

/** Increases the leading margin of the divider so that it does not intersect the avatar column */
@bindable.booleanAttr
inset: boolean;
}
25 changes: 25 additions & 0 deletions packages/list/src/mdc-deprecated-list/mdc-deprecated-list-group.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { inlineView, customElement, children, customAttribute, inject } from 'aurelia-framework';

/**
* Optional. Wrapper around two or more mdc-list elements to be grouped together.
* @selector mdc-deprecated-list-group
*/
@inlineView('<template class="mdc-deprecated-list-group"><slot></slot></template>')
@customElement('mdc-deprecated-list-group')
export class MdcDeprecatedListGroup {
@children('h1,h2,h3,h4,h5,h6')
headers: HTMLElement[];
headersChanged() {
this.headers.forEach(x => x.classList.add('mdc-deprecated-list-group__subheader'));
}
}

@inject(Element)
@customAttribute('mdc-deprecated-list-group-subheader')
export class MdcDeprecatedListGroupSubheader {
constructor(private root: HTMLElement) { }

attached() {
this.root.classList.add('mdc-deprecated-list-group__subheader');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { customAttribute, inject } from 'aurelia-framework';

/**
* Optional. The first tile in the row (in LTR languages, the first column of the list item). Typically an icon or image.
* @selector [mdc-deprecated-list-item-graphic]
*/
@inject(Element)
@customAttribute('mdc-deprecated-list-item-graphic')
export class MdcDeprecatedListItemGraphic {
constructor(private root: HTMLElement) { }

attached() {
this.root.classList.add('mdc-deprecated-list-item__graphic');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { customAttribute, inject } from 'aurelia-framework';

/**
* Optional. The last tile in the row (in LTR languages, the last column of the list item). Typically small text, icon. or image.
* @selector [mdc-deprecated-list-item-meta]
*/
@inject(Element)
@customAttribute('mdc-deprecated-list-item-meta')
export class MdcDeprecatedListItemMeta {
constructor(private root: HTMLElement) { }

attached() {
this.root.classList.add('mdc-deprecated-list-item__meta');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { inlineView, customElement } from 'aurelia-framework';

/**
* Optional, primary text for the list item
* @selector mdc-deprecated-list-item-primary-text
*/
@inlineView('<template class="mdc-deprecated-list-item__primary-text"><slot></slot></template>')
@customElement('mdc-deprecated-list-item-primary-text')
export class MdcDeprecatedListItemPrimaryText { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { inlineView, customElement } from 'aurelia-framework';

/**
* Optional, secondary text for the list item. Displayed below the primary text.
* @selector mdc-deprecated-list-item-secondary-text
*/
@inlineView('<template class="mdc-deprecated-list-item__secondary-text"><slot></slot></template>')
@customElement('mdc-deprecated-list-item-secondary-text')
export class MdcDeprecatedListItemPrimaryText { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { viewEngineHooks } from 'aurelia-framework';

@viewEngineHooks
export class EnhanceMdcDeprecatedListItem {
beforeCompile(template: DocumentFragment) {
const actions = template.querySelectorAll('[mdc-deprecated-list-item]');
for (const i of Array.from(actions)) {
i.setAttribute('as-element', 'mdc-deprecated-list-item');
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<template class="mdc-deprecated-list-item
${disabled ? 'mdc-deprecated-list-item--disabled' : ''}
${activated ? 'mdc-deprecated-list-item--activated' : ''}
" id="mdc-deprecated-list-item-${id}" mdc-ripple="disabled.bind: disabled || disableRipple" keydown.trigger="onKeydown($event)"
click.trigger="onClick()">
<div class="mdc-deprecated-list-item__ripple"></div>
<slot></slot>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { inject, useView, customElement, processContent, ViewCompiler, ViewResources } from 'aurelia-framework';
import { PLATFORM } from 'aurelia-pal';
import { bindable } from 'aurelia-typed-observable-plugin';

let listItemId = 0;

const ENTER = 13;
const SPACE = 32;
const LIST_ITEM_ACTION = 'mdclistitem:action';

/**
* @selector mdc-deprecated-list-item
*/
@inject(Element)
@useView(PLATFORM.moduleName('./mdc-deprecated-list-item.html'))
@customElement('mdc-deprecated-list-item')
@processContent(MdcDeprecatedListItem.processContent)
export class MdcDeprecatedListItem {
constructor(public root: HTMLElement) { }

static processContent(_viewCompiler: ViewCompiler, _resources: ViewResources, element: Element) {
const graphic = element.querySelector('mdc-checkbox:not([mdc-deprecated-list-item-meta]),[mdc-deprecated-list-item-graphic]');
if (graphic) {
element.removeChild(graphic);
}
const meta = element.querySelector('[mdc-deprecated-list-item-meta]');
if (meta) {
element.removeChild(meta);
}
const itemText = document.createElement('span');
itemText.classList.add('mdc-deprecated-list-item__text');
const children = [].slice.call(element.childNodes) as ChildNode[];
for (let i = 0; i < children.length; ++i) {
itemText.appendChild(children[i]);
}
if (graphic) {
element.appendChild(graphic);
}
element.appendChild(itemText);
if (meta) {
element.appendChild(meta);
}
return true;
}

id = ++listItemId;

/** Disables the list item */
@bindable.booleanAttr
disabled: boolean;

/** Styles the row in an activated state */
@bindable.booleanAttr
activated: boolean;

/** Random data associated with the list item. Passed in events payload. */
@bindable
value: unknown;

/** Disables ripple effect */
@bindable.booleanAttr
disableRipple: boolean;

onKeydown(evt: KeyboardEvent) {
if ((evt.keyCode === ENTER || evt.keyCode === SPACE) && !this.disabled) {
this.root.dispatchEvent(new CustomEvent(LIST_ITEM_ACTION, { detail: { item: this, data: this.value }, bubbles: true }));
}
return true;
}

onClick() {
if (!this.disabled) {
this.root.dispatchEvent(new CustomEvent(LIST_ITEM_ACTION, { detail: { item: this, data: this.value }, bubbles: true }));
}
return true;
}

}

/** @hidden */
export interface IMdcListItemElement extends HTMLElement {
au: {
controller: {
viewModel: MdcDeprecatedListItem;
};
};
}

export interface IMdcListActionEventDetail {
index: number;
data: unknown;
}

/** @hidden */
export interface IMdcListActionEvent extends Event {
detail: IMdcListActionEventDetail;
}
Loading

0 comments on commit 50cab88

Please sign in to comment.