Skip to content
This repository has been archived by the owner on Sep 14, 2021. It is now read-only.

Commit

Permalink
Add Material Menu examples (#49)
Browse files Browse the repository at this point in the history
* Update type to avoid warning in Material Auto Suggest example.
* Update dependencies.
* Allow travis failures on stable SDK 
* Ignore screenshot file created when running tests
* Add sanity check test for Material Menu.
  • Loading branch information
nshahan committed Nov 28, 2017
1 parent e566593 commit 971b829
Show file tree
Hide file tree
Showing 11 changed files with 465 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.packages
.pub/
build/

screenshot.png
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ cache:
- $HOME/.pub-cache
matrix:
allow_failures:
- dart: dev
dart_task: dartfmt
- dart: stable
2 changes: 2 additions & 0 deletions lib/app_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'src/material_expansionpanel_demo/material_expansionpanel_demo.dart';
import 'src/material_icon_demo/material_icon_demo.dart';
import 'src/material_input_demo/material_input_demo.dart';
import 'src/material_list_demo/material_list_demo.dart';
import 'src/material_menu_demo/material_menu_demo.dart';
import 'src/material_popup_demo/material_popup_demo.dart';
import 'src/material_progress_demo/material_progress_demo.dart';
import 'src/material_radio_demo/material_radio_demo.dart';
Expand Down Expand Up @@ -45,6 +46,7 @@ import 'src/scorecard_demo/scorecard_demo.dart';
MaterialIconDemoComponent,
MaterialInputDemoComponent,
MaterialListDemoComponent,
MaterialMenuDemoComponent,
MaterialPopupDemoComponent,
MaterialProgressDemoComponent,
MaterialRadioDemoComponent,
Expand Down
20 changes: 20 additions & 0 deletions lib/app_component.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<li><a href="#Scorecards">Scorecards</a></li>
<li><a href="#Popups">Popups</a></li>
<li><a href="#Dialogs">Modal Dialogs</a></li>
<li><a href="#Menus">Menus</a></li>
<li><a href="#Tooltips">Tooltips</a></li>
<li><a href="#Lists">Lists</a></li>
<li><a href="#Selects">Selects</a></li>
Expand Down Expand Up @@ -388,6 +389,25 @@ <h2>Modal Dialogs</h2>
<material-dialog-demo></material-dialog-demo>
<hr>

<a name="Menus"></a>
<h2>Menus</h2>
<ul class="source-links">
<li>
<a href="https://github.com/dart-lang/angular_components/tree/master/lib/material_menu"
target="_blank">
Component Source
</a>
</li>
<li>
<a href="https://github.com/dart-lang/angular_components_example/tree/master/lib/src/material_menu_demo"
target="_blank">
Example Source
</a>
</li>
</ul>
<material-menu-demo></material-menu-demo>
<hr>

<a name="Tooltips"></a>
<h2>Tooltips</h2>
<ul class="source-links">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class MaterialAutoSuggestInputDemoComponent {
final ExampleSelectionOptions suggestionOptions =
new ExampleSelectionOptions.withOptionGroups(_optionGroups);
final ExampleSelectionOptions suggestionOptionsWithItemRenderer =
new ExampleSelectionOptions.withOptionGroups(_optionGroups,
new ExampleSelectionOptions<List<int>>.withOptionGroups(_optionGroups,
toFilterableString: _numberNameRenderer);

final emptySuggestionOptions =
Expand Down Expand Up @@ -126,7 +126,7 @@ class MaterialAutoSuggestInputDemoComponent {

SelectionOptions get options => suggestionOptionsWithItemRenderer;

ItemRenderer get itemRenderer => _numberNameRenderer;
ItemRenderer<List<int>> get itemRenderer => _numberNameRenderer;

ComponentRenderer get componentRenderer =>
useComponentRenderer ? (_) => ExampleRendererComponent : null;
Expand Down
278 changes: 278 additions & 0 deletions lib/src/material_menu_demo/material_menu_demo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
import 'dart:html';

import 'package:angular/angular.dart';
import 'package:observable/observable.dart';
import 'package:angular_components/laminate/overlay/zindexer.dart';
import 'package:angular_components/laminate/popup/module.dart';
import 'package:angular_components/material_menu/dropdown_menu.dart';
import 'package:angular_components/material_menu/material_fab_menu.dart';
import 'package:angular_components/material_menu/material_menu.dart';
import 'package:angular_components/model/menu/menu.dart';
import 'package:angular_components/model/menu/selectable_menu.dart';
import 'package:angular_components/model/selection/select.dart';
import 'package:angular_components/model/selection/selection_model.dart';
import 'package:angular_components/model/ui/icon.dart';
import 'package:angular_components/utils/disposer/disposer.dart';

@Component(
selector: 'material-menu-demo',
providers: const [
popupBindings,
const Provider(ZIndexer, useClass: ZIndexer)
],
directives: const [
MaterialMenuComponent,
MaterialFabMenuComponent,
DropdownMenuComponent
],
templateUrl: 'material_menu_demo.html',
styleUrls: const ['material_menu_demo.css'],
)
class MaterialMenuDemoComponent implements OnDestroy {
/// Stores the selected color, in an observable manner.
final SelectionModel<String> colorSelection;

/// Simple menu with some colors.
final MenuModel<MenuItem> menuModel;

/// The same as [menuModel], but with an icon.
final MenuModel<MenuItem> menuModelWithIcon;

/// Demonstrates the use of sub menus.
final MenuModel<MenuItem> nestedMenuModel;

/// Demonstrates the use of selectable sub menus.
final MenuModel<MenuItem> selectableMenuModel;

/// Demonstrates menu items with multiple suffixes.
final MenuModel<MenuItem> menuModelWithAffixes;

final Disposer _disposer;

final MenuItem menuItem = new MenuItem('your label',
icon: new Icon('add'),
subMenu: new MenuModel([
new MenuItemGroup([
new MenuItem('item1-1', tooltip: 'your tooltip'),
new MenuItem('item1-2', tooltip: 'your second tooltip')
], 'group1'),
new MenuItemGroup(
[new MenuItem('item2-1'), new MenuItem('item2-2')], 'group2'),
]));

MaterialMenuDemoComponent._(
this._disposer,
this.colorSelection,
this.menuModel,
this.menuModelWithIcon,
this.nestedMenuModel,
this.selectableMenuModel,
this.menuModelWithAffixes);

factory MaterialMenuDemoComponent() {
var colorSelection = new SelectionModel<String>.withList();
var makeColorMenuItem = (String color, {MenuModel<MenuItem> subMenu}) =>
new ColorMenuItem(color, colorSelection, subMenu: subMenu);
var menuModel = new MenuModel<ColorMenuItem>([
new MenuItemGroup<ColorMenuItem>([
makeColorMenuItem('red'),
makeColorMenuItem('green'),
makeColorMenuItem('yellow'),
makeColorMenuItem('black'),
])
]);

var menuModelWithIcon =
new MenuModel<MenuItem>(menuModel.itemGroups, icon: new Icon('menu'));
var nestedMenuModel = new MenuModel<MenuItem>([
new MenuItemGroup<MenuItem>([
new MenuItem('Basic Colors', subMenu: menuModel),
new MenuItem<ColorMenuItem>('Lights',
subMenu: new MenuModel<ColorMenuItem>([
new MenuItemGroup<ColorMenuItem>([
makeColorMenuItem('Blue',
subMenu: new MenuModel<ColorMenuItem>([
new MenuItemGroup<ColorMenuItem>([
makeColorMenuItem('lightsteelblue'),
makeColorMenuItem('lightblue'),
makeColorMenuItem('lightskyblue'),
])
])),
makeColorMenuItem('lightgreen'),
makeColorMenuItem('lightsalmon'),
makeColorMenuItem('lightyellow'),
])
])),
new MenuItem('Darks',
subMenu: new MenuModel<ColorMenuItem>([
new MenuItemGroup<ColorMenuItem>([
makeColorMenuItem('darkblue'),
makeColorMenuItem('darkmagenta'),
makeColorMenuItem('darkkhaki'),
makeColorMenuItem('darkolivegreen'),
])
])),
])
]);

final disposer = new Disposer.oneShot();

final metalSelection =
new SelectionModel<String>.withList(selectedValues: ['O1']);
final typeSelection = new SelectionModel<String>.withList(allowMulti: true);
final planeSelection =
new SelectionModel<String>.withList(allowMulti: true);
final toolSelection = new SelectionModel<String>.withList(allowMulti: true);

final chiselItem = new SelectableMenuItem<String>(
value: 'Chisels',
subMenu: new MenuModel<MenuItem>([
new MenuItemGroupWithSelection<String>(items: [
new SelectableMenuItem<String>(value: 'PMV-11'),
new SelectableMenuItem<String>(value: 'A2'),
new SelectableMenuItem<String>(value: 'O1'),
], selectionModel: metalSelection, label: 'Steel'),
new MenuItemGroupWithSelection<String>(items: [
new SelectableMenuItem<String>(value: 'Mortise'),
new SelectableMenuItem<String>(value: 'Bench'),
new SelectableMenuItem<String>(value: 'Paring'),
], selectionModel: typeSelection, label: 'Function'),
new MenuItemGroup<MenuItem>([
new MenuItem('Help',
itemSuffixes: new ObservableList.from([
new IconAffix(
icon: new Icon('help_outline'),
visibility: IconVisibility.hover)
]),
action: () => window.alert('halp!')),
]),
]));

final planeItem = new SelectableMenuItem<String>(
value: 'Planes',
subMenu: new MenuModel<MenuItem>([
new MenuItemGroupWithSelection<String>(items: [
new SelectableMenuItem<String>(
value: 'Bench', selectableState: SelectableOption.Disabled),
new SelectableMenuItem<String>(value: 'Smoothing'),
new SelectableMenuItem<String>(value: 'Chisel'),
new SelectableMenuItem<String>(value: 'Block'),
new SelectableMenuItem<String>(
value: 'Shoulder', selectableState: SelectableOption.Disabled),
], selectionModel: planeSelection),
]));

disposer.addStreamSubscription(typeSelection.changes.listen((_) {
if (typeSelection.isNotEmpty) {
toolSelection.select('Chisels');
} else {
toolSelection.deselect('Chisels');
}
}));

disposer.addStreamSubscription(planeSelection.changes.listen((_) {
if (planeSelection.isNotEmpty) {
toolSelection.select('Planes');
} else {
toolSelection.deselect('Planes');
}
}));

var selectableMenuModel = new MenuModel<MenuItem>([
new MenuItemGroupWithSelection<String>(items: [
chiselItem,
planeItem,
new SelectableMenuItem<String>(
value: 'Hidden item', selectableState: SelectableOption.Hidden),
new SelectableMenuItem<String>(
value: 'Sandpaper',
selectableState: SelectableOption.Disabled,
subMenu: new MenuModel<MenuItem>([
new MenuItemGroup<MenuItem>([
new SelectableMenuItem<String>(value: '320'),
new SelectableMenuItem<String>(value: '150'),
]),
])),
], selectionModel: toolSelection, label: 'Tools'),
new MenuItemGroup<MenuItem>([
new MenuItem('Buy',
subMenu: new MenuModel<MenuItem>([
new MenuItemGroup<MenuItem>([
new MenuItem('Almost new',
enabled: false, action: () => window.alert('almost new!')),
new MenuItem('Used', action: () => window.alert('used!')),
new MenuItem('New', action: () => window.alert('new!')),
])
])),
new MenuItem('Advertise',
subMenu: new MenuModel<MenuItem>([
new MenuItemGroup<MenuItem>([
new MenuItem('Google',
enabled: false, action: () => window.alert('google!')),
new MenuItem('Facebook',
enabled: false, action: () => window.alert('facebook!')),
new MenuItem('Craigslist',
enabled: false, action: () => window.alert('craigslist!')),
])
])),
new MenuItem('Sell'),
], 'Unselectable group'),
]);

final menuModelWithAffixes = new MenuModel<MenuItem>([
new MenuItemGroup<MenuItem>([
new MenuItem('With no suffixes', action: () => window.alert('1')),
new MenuItem('With an icon suffix',
action: () => window.alert('2'),
itemSuffixes: new ObservableList.from([
new IconAffix(
icon: new IconWithAction(
'delete', () => window.alert('action'), 'ariaLabel', null,
shouldCloseMenuOnTrigger: true))
])),
new MenuItem('With text suffix',
action: () => window.alert('3'),
itemSuffixes:
new ObservableList.from([new CaptionAffix(text: 'Ctrl + V')])),
new MenuItem('With multiple suffixes',
action: () => window.alert('4'),
itemSuffixes: new ObservableList.from([
new IconAffix(
icon: new IconWithAction('delete',
() => window.alert('action 1'), 'ariaLabel', null)),
new IconAffix(icon: new Icon('accessible')),
new CaptionAffix(text: 'some text'),
new IconAffix(icon: new Icon('autorenew')),
])),
]),
]);

return new MaterialMenuDemoComponent._(
disposer,
colorSelection,
menuModel,
menuModelWithIcon,
nestedMenuModel,
selectableMenuModel,
menuModelWithAffixes);
}

@override
void ngOnDestroy() {
_disposer.dispose();
}

String get selectedColor => colorSelection.selectedValues.isEmpty
? 'red'
: colorSelection.selectedValues.first;
}

class ColorMenuItem extends MenuItem<ColorMenuItem> {
ColorMenuItem(String label, SelectionModel selection,
{Icon icon, MenuModel<MenuItem> subMenu})
: super(label, icon: icon, subMenu: subMenu) {
this.action = () {
selection.select(label);
};
}
}

0 comments on commit 971b829

Please sign in to comment.