Debian Codegraph @

node/@patternfly/react-core/src/components/Progress/examples/ProgressHelperText.tsx

raw
1 import { useState } from 'react';
2 import { Progress, ProgressProps, HelperText, HelperTextItem, Radio } from '@patternfly/react-core';
3
4 export const ProgressHelperText: React.FunctionComponent = () => {
5 type ProgressVariant = ProgressProps['variant'];
6
7 const [selectedVariant, setSelectedVariant] = useState<ProgressVariant>(undefined);
8
9 const progressVariants: ProgressVariant[] = [undefined, 'success', 'warning', 'danger'];
10
11 const capitalize = (input: string) => input[0].toUpperCase() + input.substring(1);
12 const formatVariantName = (variant: ProgressVariant) => (variant ? capitalize(variant) : 'Default');
13
14 const variantOptions = progressVariants.map((variant) => (
15 <Radio
16 id={`progress-helper-text-${variant}-selector`}
17 label={`${formatVariantName(variant)} variant`}
18 isChecked={variant === selectedVariant}
19 onChange={() => setSelectedVariant(variant)}
20 key={formatVariantName(variant)}
21 name="Progress variant options"
22 />
23 ));
24
25 const helperTextVariant = selectedVariant === 'danger' ? 'error' : selectedVariant;
26
27 const helperText = (
28 <HelperText id="progress-helper-text-example-help-text">
29 <HelperTextItem variant={helperTextVariant}>
30 {`${formatVariantName(selectedVariant)} variant is being displayed`}
31 </HelperTextItem>
32 </HelperText>
33 );
34
35 return (
36 <>
37 {variantOptions}
38 <br />
39 <Progress
40 aria-describedby="progress-helper-text-example-help-text"
41 value={33}
42 title="Title"
43 helperText={helperText}
44 variant={selectedVariant}
45 />
46 </>
47 );
48 };