actions.d.ts 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import { Dom7Array } from 'dom7';
  2. import Framework7, {
  3. CSSSelector,
  4. Framework7EventsClass,
  5. Framework7Plugin,
  6. } from '../app/app-class.js';
  7. export namespace Actions {
  8. interface Actions extends Framework7EventsClass<Events> {
  9. /** Link to global app instance */
  10. app: Framework7;
  11. /** Action sheet HTML element */
  12. el: HTMLElement;
  13. /** Dom7 instance with action sheet HTML element */
  14. $el: Dom7Array;
  15. /** Backdrop HTML element */
  16. backdropEl: HTMLElement;
  17. /** Dom7 instance with backdrop HTML element */
  18. $backdropEl: Dom7Array;
  19. /** Action sheet instance parameters */
  20. params: Parameters;
  21. /** Boolean prop indicating whether action sheet is opened or not */
  22. opened: boolean;
  23. /** Open action sheet. Where animate - boolean (by default true) - defines whether it should be opened with animation */
  24. open(animate?: boolean): void;
  25. /** Close action sheet. Where animate - boolean (by default true) - defines whether it should be closed with animation */
  26. close(animate?: boolean): void;
  27. /** Destroy action sheet */
  28. destroy(): void;
  29. }
  30. interface Button {
  31. /** String with Button's text (could be HTML string) */
  32. text: string;
  33. /** HTML string of icon */
  34. icon?: string;
  35. /** Enables bold button text */
  36. bold?: boolean;
  37. /** Button color, one of default colors */
  38. color?: string;
  39. /** Button background color, one of default colors */
  40. bg?: string;
  41. /** If enabled then it will be rendered as label instead of button */
  42. label?: boolean;
  43. /** Defines whether the button is disabled or not. */
  44. disabled?: boolean;
  45. /** If enabled then button click will close Action Sheet */
  46. close?: boolean;
  47. /** Callback function that will be executed after click on this button */
  48. onClick?: (actions: Actions, e: unknown) => void;
  49. }
  50. interface Parameters {
  51. /** Action Sheet element. Can be useful if you already have Action Sheet element in your HTML and want to create new instance using this element*/
  52. el?: HTMLElement | CSSSelector;
  53. /** Full Action Sheet HTML content string. Can be useful if you want to create Action Sheet element with custom HTML*/
  54. content?: string;
  55. /** Enables Action Sheet backdrop (dark semi transparent layer behind)*/
  56. backdrop?: boolean;
  57. /** Backdrop element to share across instances */
  58. backdropEl?: HTMLElement | CSSSelector;
  59. /** If enabled it creates unique backdrop element exclusively for this modal (default false) */
  60. backdropUnique?: boolean;
  61. /** Custom css class added to Actions Sheet element */
  62. cssClass?: string;
  63. /** When enabled, action sheet will be closed on backdrop click*/
  64. closeByBackdropClick?: boolean;
  65. /** When enabled, action sheet will be closed on when click outside of it*/
  66. closeByOutsideClick?: boolean;
  67. /** When enabled, action sheet will be closed on ESC keyboard key press (default false) */
  68. closeOnEscape?: boolean;
  69. /** Whether the Action Sheet should be opened/closed with animation or not. Can be overwritten in .open() and .close() methods*/
  70. animate?: boolean;
  71. /** Action sheet groups/buttons. In this case Actions layout will be generated dynamically based on passed groups and buttons. In case of groups it should array where each item represent array with buttons for group.*/
  72. buttons?: Button[] | Button[][];
  73. /** Enables grid buttons layout*/
  74. grid?: boolean;
  75. /** When enabled, action sheet will be converted to Popover on large screens.*/
  76. convertToPopover?: boolean;
  77. /** When enabled, action sheet will be always converted to Popover.*/
  78. forceToPopover?: boolean;
  79. /** HTML element or string CSS selector of target element. Required when conversion to popover is in use*/
  80. targetEl?: HTMLElement | CSSSelector;
  81. /** Virtual target element horizontal offset from left side of the screen. Required when conversion to popover is in use without using real target element (targetEl)*/
  82. targetX?: number;
  83. /** Virtual target element vertical offset from top of the screen. Required when conversion to popover is in use without using real target element (targetEl)*/
  84. targetY?: number;
  85. /** Virtual target element width (in px). Required when conversion to popover is in use without using real target element (targetEl)*/
  86. targetWidth?: number;
  87. /** Virtual target element height (in px). Required when conversion to popover is in use without using real target element (targetEl)*/
  88. targetHeight?: number;
  89. /** Element to mount modal to. (default app.el) */
  90. containerEl?: HTMLElement | CSSSelector;
  91. /** Callback function that will be executed after click on the Action Sheet button*/
  92. onClick?: (actions: Actions, e: unknown) => void;
  93. /** Custom function to render Action Sheet. Must return Action Sheet html*/
  94. render?: () => string;
  95. /** Custom function to render Popover when conversion to popover is in use. Must return Popover html*/
  96. renderPopover?: () => string;
  97. /** Object with event handlers */
  98. on?: {
  99. [event in keyof Events]?: Events[event];
  100. };
  101. }
  102. interface Events {
  103. /** Event will be triggered when Action Sheet starts its opening animation. As an argument event handler receives action sheet instance */
  104. open: (actions: Actions) => void;
  105. /** Event will be triggered after Action Sheet completes its opening animation. As an argument event handler receives action sheet instance */
  106. opened: (actions: Actions) => void;
  107. /** Event will be triggered when Action Sheet starts its closing animation. As an argument event handler receives action sheet instance */
  108. close: (actions: Actions) => void;
  109. /** Event will be triggered after Action Sheet completes its closing animation. As an argument event handler receives action sheet instance */
  110. closed: (actions: Actions) => void;
  111. /** Event will be triggered right before Action Sheet instance will be destroyed. As an argument event handler receives action sheet instance */
  112. beforeDestroy: (actions: Actions) => void;
  113. }
  114. interface DomEvents {
  115. /** Event will be triggered when Action Sheet starts its opening animation */
  116. 'actions:open': (actions: Actions) => void;
  117. /** Event will be triggered after Action Sheet completes its opening animation */
  118. 'actions:opened': (actions: Actions) => void;
  119. /** Event will be triggered when Action Sheet starts its closing animation */
  120. 'actions:close': (actions: Actions) => void;
  121. /** Event will be triggered after Action Sheet completes its closing animation */
  122. 'actions:closed': (actions: Actions) => void;
  123. }
  124. interface AppMethods {
  125. actions: {
  126. /** create Action Sheet instance */
  127. create(parameters: Parameters): Actions;
  128. /** destroy Action Sheet instance */
  129. destroy(el: HTMLElement | CSSSelector | Actions): void;
  130. /** get Action Sheet instance by HTML element */
  131. get(el?: HTMLElement | CSSSelector): Actions;
  132. /** opens Action Sheet */
  133. open(el?: HTMLElement | CSSSelector, animate?: boolean): Actions;
  134. /** closes Action Sheet */
  135. close(el?: HTMLElement | CSSSelector, animate?: boolean): Actions;
  136. };
  137. }
  138. interface AppParams {
  139. actions?: Parameters | undefined;
  140. }
  141. interface AppEvents {
  142. /** Event will be triggered when Action Sheet starts its opening animation. As an argument event handler receives action sheet instance */
  143. actionsOpen: (actions: Actions) => void;
  144. /** Event will be triggered after Action Sheet completes its opening animation. As an argument event handler receives action sheet instance */
  145. actionsOpened: (actions: Actions) => void;
  146. /** Event will be triggered when Action Sheet starts its closing animation. As an argument event handler receives action sheet instance */
  147. actionsClose: (actions: Actions) => void;
  148. /** Event will be triggered after Action Sheet completes its closing animation. As an argument event handler receives action sheet instance */
  149. actionsClosed: (actions: Actions) => void;
  150. /** Event will be triggered right before Action Sheet instance will be destroyed. As an argument event handler receives action sheet instance */
  151. actionsBeforeDestroy: (actions: Actions) => void;
  152. }
  153. }
  154. declare const ActionsComponent: Framework7Plugin;
  155. export default ActionsComponent;