| 1 |
import styles from '@patternfly/react-styles/css/components/Icon/icon'; |
| 2 |
import { css } from '@patternfly/react-styles'; |
| 3 |
import { Spinner } from '../Spinner'; |
| 4 |
|
| 5 |
export type IconSize = |
| 6 |
| 'sm' |
| 7 |
| 'md' |
| 8 |
| 'lg' |
| 9 |
| 'xl' |
| 10 |
| '2xl' |
| 11 |
| '3xl' |
| 12 |
| 'headingSm' |
| 13 |
| 'headingMd' |
| 14 |
| 'headingLg' |
| 15 |
| 'headingXl' |
| 16 |
| 'heading_2xl' |
| 17 |
| 'heading_3xl' |
| 18 |
| 'bodySm' |
| 19 |
| 'bodyDefault' |
| 20 |
| 'bodyLg'; |
| 21 |
|
| 22 |
export interface IconComponentProps extends Omit<React.HTMLProps<HTMLSpanElement>, 'size'> { |
| 23 |
/** Icon content */ |
| 24 |
children?: React.ReactNode; |
| 25 |
/** Icon when isInProgress is set to true. Defaults to a 1em spinner. */ |
| 26 |
progressIcon?: React.ReactNode; |
| 27 |
/** Additional classes applied to the icon container */ |
| 28 |
className?: string; |
| 29 |
/** Size of the icon component container and icon. */ |
| 30 |
size?: IconSize; |
| 31 |
/** Size of icon. Overrides the icon size set by the size property. */ |
| 32 |
iconSize?: IconSize; |
| 33 |
/** Size of progress icon. Overrides the icon size set by the size property. */ |
| 34 |
progressIconSize?: IconSize; |
| 35 |
/** Status color of the icon */ |
| 36 |
status?: 'custom' | 'info' | 'success' | 'warning' | 'danger'; |
| 37 |
/** Indicates the icon is inline and should inherit the text font size and color. Overriden by size and iconSize properties. */ |
| 38 |
isInline?: boolean; |
| 39 |
/** Indicates the icon is in progress. Setting this property to true will swap the icon with the progressIcon. */ |
| 40 |
isInProgress?: boolean; |
| 41 |
/** Aria-label for the default progress icon */ |
| 42 |
defaultProgressArialabel?: string; |
| 43 |
/** Flag indicating whether the icon passed as children should be mirrored for |
| 44 |
* right to left (RTL) languages. This will not mirror the icon passed to progressIcon. |
| 45 |
*/ |
| 46 |
shouldMirrorRTL?: boolean; |
| 47 |
} |
| 48 |
|
| 49 |
export const Icon: React.FunctionComponent<IconComponentProps> = ({ |
| 50 |
children, |
| 51 |
className, |
| 52 |
progressIcon, |
| 53 |
size, |
| 54 |
iconSize, |
| 55 |
progressIconSize, |
| 56 |
status, |
| 57 |
isInline = false, |
| 58 |
isInProgress = false, |
| 59 |
defaultProgressArialabel = 'Loading...', |
| 60 |
shouldMirrorRTL = false, |
| 61 |
...props |
| 62 |
}: IconComponentProps) => { |
| 63 |
const _progressIcon = progressIcon ?? <Spinner diameter="1em" aria-label={defaultProgressArialabel} />; |
| 64 |
|
| 65 |
return ( |
| 66 |
<span |
| 67 |
className={css( |
| 68 |
styles.icon, |
| 69 |
isInline && styles.modifiers.inline, |
| 70 |
isInProgress && styles.modifiers.inProgress, |
| 71 |
styles.modifiers[size], |
| 72 |
className |
| 73 |
)} |
| 74 |
{...props} |
| 75 |
> |
| 76 |
<span |
| 77 |
className={css( |
| 78 |
styles.iconContent, |
| 79 |
styles.modifiers[iconSize], |
| 80 |
styles.modifiers[status], |
| 81 |
shouldMirrorRTL && 'pf-v6-m-mirror-inline-rtl' |
| 82 |
)} |
| 83 |
> |
| 84 |
{children} |
| 85 |
</span> |
| 86 |
{isInProgress && ( |
| 87 |
<span className={css(styles.iconProgress, styles.modifiers[progressIconSize], className)}>{_progressIcon}</span> |
| 88 |
)} |
| 89 |
</span> |
| 90 |
); |
| 91 |
}; |
| 92 |
Icon.displayName = 'Icon'; |