• Drawer抽屉
    • 规则
  • 代码演示
  • API

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

    嵌入文档模式

    嵌入到文档流中

    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 class="my-drawer"
    8. [ngStyle]="{minHeight: this.height+'px'}"
    9. [contentStyle]="{ color: '#A6A6A6', textAlign: 'center', paddingTop: '42px' }"
    10. [sidebarStyle]="{ border: '1px solid #ddd' }"
    11. [sidebar]="sidebar"
    12. [enableDragHandle]="false"
    13. [docked]="this.state.docked"
    14. (onOpenChange)="onDockedChange($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"
    25. [thumb]="'https://zos.alipayobjects.com/rmsportal/eOZidTabPoEbPeU.png'">
    26. Category
    27. </ListItem>
    28. <ListItem *ngFor="let num of this.nums ; let i = index"
    29. [thumb]="'https://zos.alipayobjects.com/rmsportal/eOZidTabPoEbPeU.png'">
    30. Category{{i + 1}}
    31. </ListItem>
    32. </List>
    33. </ng-template>
    34. `,
    35. styles: [
    36. `
    37. /deep/ .my-drawer {
    38. position: relative;
    39. overflow: auto;
    40. -webkit-overflow-scrolling: touch;
    41. }
    42. /deep/ .my-drawer .am-drawer-sidebar {
    43. background-color: #fff;
    44. overflow: auto;
    45. -webkit-overflow-scrolling: touch;
    46. }
    47. /deep/ .my-drawer .am-drawer-sidebar .am-list {
    48. width: 300px;
    49. padding: 0;
    50. }
    51. `
    52. ]
    53. })
    54. export class DemoDrawerDockComponent {
    55. height: number = document.documentElement.clientHeight;
    56. nums: Array<number> = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
    57. state = {
    58. docked: false
    59. };
    60. constructor() {}
    61. onDockedChange = event => {
    62. console.log('dockedChanged', event);
    63. this.state.docked = !this.state.docked;
    64. };
    65. }

    Drawer 抽屉 - 图1

    API

    属性说明类型默认值
    sidebar抽屉里的内容ng-template-
    onOpenChangeopen 状态切换时调用(open: bool): void-
    open开关状态Booleanfalse
    position抽屉所在位置String'left', enum{'left', 'right', 'top', 'bottom'}
    sidebarStyle-Object{}
    contentStyle-Object{}
    overlayStyle-Object{}
    dragHandleStyle-Object{}
    touch是否开启触摸手势Booleantrue
    transitions是否开启动画Booleantrue
    docked是否嵌入到正常文档流里Booleanfalse
    enableDragHandle是否启用 dragHandleBooleanfalse
    dragToggleDistance打开关闭抽屉时距 sidebar 的拖动距离Number30