/** * @license * Copyright 2021 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import {FunctionComponent, JSX} from 'preact'; import {useState} from 'preact/hooks'; import {HelpDialog} from './help-dialog'; import {getFlowResultFilenamePrefix} from '../../report/generator/file-namer'; import {useLocalizedStrings} from './i18n/i18n'; import {HamburgerIcon, InfoIcon} from './icons'; import {useFlowResult, useOptions} from './util'; import {saveFile} from '../../report/renderer/api'; function saveHtml(flowResult: LH.FlowResult, htmlStr: string) { const blob = new Blob([htmlStr], {type: 'text/html'}); const filename = getFlowResultFilenamePrefix(flowResult) + '.html'; saveHtml.saveFile(blob, filename); } // Store `saveFile` here so we can do dependency injection. saveHtml.saveFile = saveFile; /* eslint-disable max-len */ const Logo: FunctionComponent = () => { return ( ); }; /* eslint-enable max-len */ const TopbarButton: FunctionComponent<{ onClick: JSX.MouseEventHandler, label: string, }> = ({onClick, label, children}) => { return ( ); }; const Topbar: FunctionComponent<{onMenuClick: JSX.MouseEventHandler}> = ({onMenuClick}) => { const flowResult = useFlowResult(); const strings = useLocalizedStrings(); const [showHelpDialog, setShowHelpDialog] = useState(false); const {getReportHtml, saveAsGist} = useOptions(); return (
{strings.title}
{ getReportHtml && { const htmlStr = getReportHtml(flowResult); saveHtml(flowResult, htmlStr); }} label="Button that saves the report as HTML" >{strings.save} } { saveAsGist && saveAsGist(flowResult)} label="Button that saves the report to a gist" >{strings.dropdownSaveGist} }
setShowHelpDialog(previous => !previous)} label="Button that toggles the help dialog" >
{strings.helpLabel}
{showHelpDialog ? setShowHelpDialog(false)} /> : null }
); }; export { Topbar, saveHtml, };