import React from 'react'; import { CodeBlock, CodeBlockAction, CodeBlockCode, ClipboardCopyButton, ExpandableSection, ExpandableSectionToggle, Button } from '@breakaway/preact-core'; import PlayIcon from '@patternfly/react-icons/dist/esm/icons/play-icon'; export const ExpandableCodeBlock: React.FunctionComponent = () => { const [isExpanded, setIsExpanded] = React.useState(false); const [copied, setCopied] = React.useState(false); const onToggle = (isExpanded) => { setIsExpanded(isExpanded); }; const clipboardCopyFunc = (event, text) => { navigator.clipboard.writeText(text.toString()); }; const onClick = (event, text) => { clipboardCopyFunc(event, text); setCopied(true); }; const copyBlock = `apiVersion: helm.openshift.io/v1beta1/ kind: HelmChartRepository metadata: name: azure-sample-repo spec: connectionConfig: url: https://raw.githubusercontent.com/Azure-Samples/helm-charts/master/docs`; const code = `apiVersion: helm.openshift.io/v1beta1/ kind: HelmChartRepository metadata: name: azure-sample-repo`; const expandedCode = `spec: connectionConfig: url: https://raw.githubusercontent.com/Azure-Samples/helm-charts/master/docs`; const actions = ( onClick(e, copyBlock)} exitDelay={copied ? 1500 : 600} maxWidth="110px" variant="plain" onTooltipHidden={() => setCopied(false)} > {copied ? 'Successfully copied to clipboard!' : 'Copy to clipboard'} ); return ( {code} {expandedCode} {isExpanded ? 'Show Less' : 'Show More'} ); };