|
| 1 | +import { |
| 2 | + Component, |
| 3 | + type ComponentInterface, |
| 4 | + Event, |
| 5 | + type EventEmitter, |
| 6 | + h, |
| 7 | + Prop, |
| 8 | + State, |
| 9 | +} from "@stencil/core"; |
| 10 | +import { isMobile } from "../../utils/utils"; |
| 11 | + |
| 12 | +const backIcon = |
| 13 | + '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-arrow-left"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M5 12l14 0" /><path d="M5 12l6 6" /><path d="M5 12l6 -6" /></svg>'; |
| 14 | +const closeIcon = |
| 15 | + '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-x"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M18 6l-12 12" /><path d="M6 6l12 12" /></svg>'; |
| 16 | + |
| 17 | +@Component({ |
| 18 | + tag: "scout-drawer", |
| 19 | + styleUrl: "drawer.css", |
| 20 | + shadow: { |
| 21 | + delegatesFocus: true, |
| 22 | + }, |
| 23 | +}) |
| 24 | +export class ScoutDrawer implements ComponentInterface { |
| 25 | + /** |
| 26 | + * Open/closestate of the drawer. |
| 27 | + */ |
| 28 | + @Prop() open: boolean = false; |
| 29 | + /** |
| 30 | + * Open/closestate of the drawer. |
| 31 | + */ |
| 32 | + @Prop() title: string = ""; |
| 33 | + /** |
| 34 | + * Render back button. |
| 35 | + */ |
| 36 | + @Prop() backButton: boolean = false; |
| 37 | + /** |
| 38 | + * Render close button. |
| 39 | + */ |
| 40 | + @Prop() closeButton: boolean = false; |
| 41 | + /** |
| 42 | + * Backdrop for the drawer. Will also make it clickable to close the drawer. |
| 43 | + */ |
| 44 | + @Prop() backdrop: boolean = false; |
| 45 | + |
| 46 | + @State() openState: "opening" | "closing" | "open" | "close" = "close"; |
| 47 | + |
| 48 | + /** |
| 49 | + * Fired when clicking backButton (<-) |
| 50 | + */ |
| 51 | + @Event() backButtonClicked: EventEmitter<void>; |
| 52 | + /** |
| 53 | + * Fired when clicking backButton (X) |
| 54 | + */ |
| 55 | + @Event() exitButtonClicked: EventEmitter<void>; |
| 56 | + |
| 57 | + onBackButtonClick() { |
| 58 | + this.backButtonClicked.emit(); |
| 59 | + } |
| 60 | + onExitButtonClick() { |
| 61 | + this.exitButtonClicked.emit(); |
| 62 | + } |
| 63 | + |
| 64 | + render() { |
| 65 | + const shouldRenderHeader = |
| 66 | + this.title || this.backButton || this.closeButton; |
| 67 | + // const animateDrawer = (direction: "open" | "close") => {}; |
| 68 | + return ( |
| 69 | + <div> |
| 70 | + {this.backdrop && ( |
| 71 | + // biome-ignore lint/a11y/noStaticElementInteractions: <closable backdrop> |
| 72 | + <div |
| 73 | + onKeyDown={() => {}} |
| 74 | + onChange={() => this.onExitButtonClick()} |
| 75 | + class={`backdrop ${this.open ? "backdrop-visible" : "backdrop-hidden"}`} |
| 76 | + ></div> |
| 77 | + )} |
| 78 | + <div |
| 79 | + onAnimationStart={() => {}} |
| 80 | + onAnimationEnd={() => {}} |
| 81 | + class={`drawer--container-${isMobile() ? "desktop" : "desktop"} ${this.open ? "open" : "closed"}`} |
| 82 | + > |
| 83 | + {shouldRenderHeader && ( |
| 84 | + <div class="header"> |
| 85 | + {this.backButton && ( |
| 86 | + // biome-ignore lint/a11y/useButtonType: <not needed> |
| 87 | + <button |
| 88 | + class="back-button" |
| 89 | + onClick={() => this.onBackButtonClick()} |
| 90 | + > |
| 91 | + <span class="icon" innerHTML={backIcon}></span> |
| 92 | + </button> |
| 93 | + )} |
| 94 | + {this.closeButton && ( |
| 95 | + // biome-ignore lint/a11y/useButtonType: <not needed> |
| 96 | + <button |
| 97 | + class="close-button" |
| 98 | + onClick={() => this.onExitButtonClick()} |
| 99 | + > |
| 100 | + <span class="icon" innerHTML={closeIcon} /> |
| 101 | + </button> |
| 102 | + )} |
| 103 | + {this.title && <h3 class="title">{this.title}</h3>} |
| 104 | + </div> |
| 105 | + )} |
| 106 | + <slot /> |
| 107 | + </div> |
| 108 | + </div> |
| 109 | + ); |
| 110 | + } |
| 111 | +} |
0 commit comments