| 31 | }; |
| 32 | |
| 33 | export class FullscreenWidget extends Widget<FullscreenWidgetProps> { |
| 34 | static defaultProps: Required<FullscreenWidgetProps> = { |
| 35 | ...Widget.defaultProps, |
| 36 | id: 'fullscreen', |
| 37 | placement: 'top-left', |
| 38 | viewId: null, |
| 39 | enterLabel: 'Enter Fullscreen', |
| 40 | exitLabel: 'Exit Fullscreen', |
| 41 | container: undefined!, |
| 42 | onFullscreenChange: () => {} |
| 43 | }; |
| 44 | |
| 45 | className = 'deck-widget-fullscreen'; |
| 46 | placement: WidgetPlacement = 'top-left'; |
| 47 | fullscreen: boolean = false; |
| 48 | |
| 49 | constructor(props: FullscreenWidgetProps = {}) { |
| 50 | super(props); |
| 51 | this.setProps(this.props); |
| 52 | } |
| 53 | |
| 54 | onAdd(): void { |
| 55 | document.addEventListener('fullscreenchange', this.onFullscreenChange.bind(this)); |
| 56 | } |
| 57 | |
| 58 | onRemove() { |
| 59 | document.removeEventListener('fullscreenchange', this.onFullscreenChange.bind(this)); |
| 60 | } |
| 61 | |
| 62 | onRenderHTML(rootElement: HTMLElement): void { |
| 63 | const isFullscreen = this.getFullscreen(); |
| 64 | render( |
| 65 | <IconButton |
| 66 | onClick={() => { |
| 67 | this.handleClick().catch(err => log.error(err)()); |
| 68 | }} |
| 69 | label={isFullscreen ? this.props.exitLabel : this.props.enterLabel} |
| 70 | className={isFullscreen ? 'deck-widget-fullscreen-exit' : 'deck-widget-fullscreen-enter'} |
| 71 | />, |
| 72 | rootElement |
| 73 | ); |
| 74 | } |
| 75 | |
| 76 | setProps(props: Partial<FullscreenWidgetProps>) { |
| 77 | this.placement = props.placement ?? this.placement; |
| 78 | this.viewId = props.viewId ?? this.viewId; |
| 79 | super.setProps(props); |
| 80 | } |
| 81 | |
| 82 | getContainer() { |
| 83 | return this.props.container || this.deck?.props.parent || this.deck?.getCanvas()?.parentElement; |
| 84 | } |
| 85 | |
| 86 | getFullscreen(): boolean { |
| 87 | return this.fullscreen; |
| 88 | } |
| 89 | |
| 90 | onFullscreenChange() { |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…