|
| 1 | +/* |
| 2 | + * This file is part of Cockpit. |
| 3 | + * |
| 4 | + * Copyright (C) 2016 Red Hat, Inc. |
| 5 | + * |
| 6 | + * Cockpit is free software; you can redistribute it and/or modify it |
| 7 | + * under the terms of the GNU Lesser General Public License as published by |
| 8 | + * the Free Software Foundation; either version 2.1 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * Cockpit is distributed in the hope that it will be useful, but |
| 12 | + * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | + * Lesser General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Lesser General Public License |
| 17 | + * along with Cockpit; If not, see <https://www.gnu.org/licenses/>. |
| 18 | + */ |
| 19 | + |
| 20 | +import cockpit from "cockpit"; |
| 21 | +import React from "react"; |
| 22 | +import { createRoot, Container } from 'react-dom/client'; |
| 23 | +import { usePageLocation } from "hooks"; |
| 24 | + |
| 25 | +import '../lib/patternfly/patternfly-5-cockpit.scss'; |
| 26 | + |
| 27 | +import { Page, PageSection, Bullseye, Button } from '@patternfly/react-core'; |
| 28 | + |
| 29 | +import 'cockpit-dark-theme'; // once per page |
| 30 | + |
| 31 | +const FullscreenDemo = () => { |
| 32 | + const { path } = usePageLocation(); |
| 33 | + |
| 34 | + function go_fullscreen() { |
| 35 | + cockpit.location.go("/fullscreen"); |
| 36 | + } |
| 37 | + |
| 38 | + function go_halfscreen() { |
| 39 | + cockpit.location.go("/"); |
| 40 | + } |
| 41 | + |
| 42 | + return ( |
| 43 | + <Page> |
| 44 | + <PageSection> |
| 45 | + <Bullseye> |
| 46 | + { (path[0] != "fullscreen") |
| 47 | + ? <Button onClick={go_fullscreen}>Go fullscreen</Button> |
| 48 | + : <Button onClick={go_halfscreen}>Go back</Button> |
| 49 | + } |
| 50 | + </Bullseye> |
| 51 | + </PageSection> |
| 52 | + </Page> |
| 53 | + ); |
| 54 | +}; |
| 55 | + |
| 56 | +function init_app(rootElement: Container) { |
| 57 | + const root = createRoot(rootElement); |
| 58 | + root.render(<FullscreenDemo />); |
| 59 | +} |
| 60 | + |
| 61 | +document.addEventListener("DOMContentLoaded", function() { |
| 62 | + cockpit.transport.wait(function() { |
| 63 | + init_app(document.getElementById('app')!); |
| 64 | + }); |
| 65 | +}); |
0 commit comments