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