action-sheet.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { Component, h } from '@stencil/core';
  2. import { actionSheetController, getMode } from '@ionic/core';
  3. @Component({
  4. tag: 'component-action-sheet',
  5. styleUrl: 'action-sheet.css'
  6. })
  7. export class ActionSheet {
  8. mode!: string;
  9. open = async () => {
  10. const mode = getMode();
  11. const actionSheet = await actionSheetController.create({
  12. header: 'Albums',
  13. buttons: [{
  14. text: 'Delete',
  15. role: 'destructive',
  16. icon: mode !== 'ios' ? 'trash-outline' : null,
  17. handler: () => {
  18. console.log('Delete clicked');
  19. }
  20. }, {
  21. text: 'Share',
  22. icon: mode !== 'ios' ? 'share-outline' : null,
  23. handler: () => {
  24. console.log('Share clicked');
  25. }
  26. }, {
  27. text: 'Play (open modal)',
  28. icon: mode !== 'ios' ? 'play-circle-outline' : null,
  29. handler: () => {
  30. console.log('Play clicked');
  31. }
  32. }, {
  33. text: 'Favorite',
  34. icon: mode !== 'ios' ? 'heart-outline' : null,
  35. handler: () => {
  36. console.log('Favorite clicked');
  37. }
  38. }, {
  39. text: 'Cancel',
  40. icon: mode !== 'ios' ? 'close' : null,
  41. role: 'cancel',
  42. handler: () => {
  43. console.log('Cancel clicked');
  44. }
  45. }]
  46. });
  47. await actionSheet.present();
  48. }
  49. render() {
  50. const description = `The <b>Action Sheet</b> is a dialog that displays a set of options. It appears on
  51. top of the app’s content, and must be manually dismissed by the user before they can
  52. resume interaction with the app. There are multiple ways to dismiss the action sheet,
  53. including tapping the backdrop or hitting the escape key.`;
  54. const url = 'action-sheet';
  55. return [
  56. <ion-header translucent={true}>
  57. <ion-toolbar>
  58. <ion-buttons slot="start">
  59. <ion-back-button defaultHref="/"></ion-back-button>
  60. </ion-buttons>
  61. <ion-title>Action Sheet</ion-title>
  62. </ion-toolbar>
  63. </ion-header>,
  64. <ion-content fullscreen class="component-content">
  65. <component-details description={description} url={url}></component-details>
  66. <div class="ion-padding-start ion-padding-end">
  67. <ion-button class="ion-text-wrap" expand="block" onClick={this.open}>Open Action Sheet</ion-button>
  68. </div>
  69. </ion-content>
  70. ];
  71. }
  72. }