Drawer抽屉

用于在屏幕边缘显示应用导航等内容的面板。

规则

  • 是 Android 推荐的导航方式,常见于该平台应用。

代码演示

基本用法

遮罩层模式

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'demo-drawer-basic',
  4. template: `
  5. <div>
  6. <Navbar [icon]="icon" (onLeftClick)="onOpenChange($event)">Basic</Navbar>
  7. <Drawer
  8. class="my-drawer"
  9. [ngStyle]="{ minHeight: this.height + 'px' }"
  10. [contentStyle]="{ color: '#A6A6A6', textAlign: 'center', paddingTop: '42px' }"
  11. [enableDragHandle]="true"
  12. [sidebar]="sidebar"
  13. [open]="this.state.open"
  14. (onOpenChange)="onOpenChange($event)"
  15. >
  16. Click upper-left corner
  17. </Drawer>
  18. </div>
  19. <ng-template #icon>
  20. <Icon type="ellipsis"></Icon>
  21. </ng-template>
  22. <ng-template #sidebar>
  23. <List>
  24. <ListItem [multipleLine]="true" [thumb]="'https://zos.alipayobjects.com/rmsportal/eOZidTabPoEbPeU.png'">
  25. Category
  26. </ListItem>
  27. <ListItem
  28. *ngFor="let num of this.nums; let i = index"
  29. [thumb]="'https://zos.alipayobjects.com/rmsportal/eOZidTabPoEbPeU.png'"
  30. >
  31. Category{{ i + 1 }}
  32. </ListItem>
  33. </List>
  34. </ng-template>
  35. `,
  36. styles: [
  37. `
  38. /deep/ .my-drawer {
  39. position: relative;
  40. overflow: auto;
  41. -webkit-overflow-scrolling: touch;
  42. }
  43. /deep/ .my-drawer .am-drawer-sidebar {
  44. background-color: #fff;
  45. overflow: auto;
  46. -webkit-overflow-scrolling: touch;
  47. }
  48. /deep/ .my-drawer .am-drawer-sidebar .am-list {
  49. width: 300px;
  50. padding: 0;
  51. }
  52. `
  53. ]
  54. })
  55. export class DemoDrawerBasicComponent {
  56. height: number = document.documentElement.clientHeight;
  57. nums: Array<number> = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
  58. state = {
  59. open: true
  60. };
  61. constructor() {}
  62. onOpenChange(event) {
  63. console.log(event);
  64. this.state.open = !this.state.open;
  65. }
  66. }

嵌入文档模式

嵌入到文档流中

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'demo-drawer-dock',
  4. template: `
  5. <div>
  6. <Navbar [icon]="icon" (onLeftClick)="onDockedChange($event)">Docked in document</Navbar>
  7. <Drawer
  8. class="my-drawer"
  9. [ngStyle]="{ minHeight: this.height + 'px' }"
  10. [contentStyle]="{ color: '#A6A6A6', textAlign: 'center', paddingTop: '42px' }"
  11. [sidebarStyle]="{ border: '1px solid #ddd' }"
  12. [sidebar]="sidebar"
  13. [enableDragHandle]="false"
  14. [docked]="this.state.docked"
  15. (onOpenChange)="onDockedChange($event)"
  16. >
  17. Click upper-left corner
  18. </Drawer>
  19. </div>
  20. <ng-template #icon>
  21. <Icon type="ellipsis"></Icon>
  22. </ng-template>
  23. <ng-template #sidebar>
  24. <List>
  25. <ListItem [multipleLine]="true" [thumb]="'https://zos.alipayobjects.com/rmsportal/eOZidTabPoEbPeU.png'">
  26. Category
  27. </ListItem>
  28. <ListItem
  29. *ngFor="let num of this.nums; let i = index"
  30. [thumb]="'https://zos.alipayobjects.com/rmsportal/eOZidTabPoEbPeU.png'"
  31. >
  32. Category{{ i + 1 }}
  33. </ListItem>
  34. </List>
  35. </ng-template>
  36. `,
  37. styles: [
  38. `
  39. /deep/ .my-drawer {
  40. position: relative;
  41. overflow: auto;
  42. -webkit-overflow-scrolling: touch;
  43. }
  44. /deep/ .my-drawer .am-drawer-sidebar {
  45. background-color: #fff;
  46. overflow: auto;
  47. -webkit-overflow-scrolling: touch;
  48. }
  49. /deep/ .my-drawer .am-drawer-sidebar .am-list {
  50. width: 300px;
  51. padding: 0;
  52. }
  53. `
  54. ]
  55. })
  56. export class DemoDrawerDockComponent {
  57. height: number = document.documentElement.clientHeight;
  58. nums: Array<number> = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
  59. state = {
  60. docked: false
  61. };
  62. constructor() {}
  63. onDockedChange = event => {
  64. console.log('dockedChanged', event);
  65. this.state.docked = !this.state.docked;
  66. }
  67. }

Drawer抽屉 - 图1

API

参数说明类型默认值
[sidebar]抽屉里的内容TemplateRef-
[open]开关状态booleanfalse
[position]抽屉所在位置‘left’ | ‘right’ | ‘top’ | ‘bottom’‘left’
[sidebarStyle]-object{}
[contentStyle]-object{}
[overlayStyle]-object{}
[dragHandleStyle]-object{}
[touch]是否开启触摸手势booleantrue
[transitions]是否开启动画booleantrue
[docked]是否嵌入到正常文档流里booleanfalse
[enableDragHandle]是否启用 dragHandlebooleanfalse
[dragToggleDistance]打开/关闭抽屉时距 sidebar 的拖动距离number30
(onOpenChange)open 状态切换时调用EventEmitter<boolean>-