import type { FunctionComponent } from 'react'; import { MouseIcon } from '@patternfly/react-icons'; import { Label } from '@patternfly/react-core'; import { createUseStyles } from 'react-jss'; import { css } from '@patternfly/react-styles'; export interface ShortcutProps { /** Array of shortcut keys */ keys: string[]; /** Shortcut description */ description?: React.ReactNode; /** Indicates whether symbols should be displayed for certain keys */ showSymbols?: boolean; /** Show hover in the shortcut */ hover?: boolean; /** Show click in the shortcut */ click?: boolean; /** Show right click in the shortcut */ rightClick?: boolean; /** Show drag in the shortcut */ drag?: boolean; /** Show drag and drop in the shortcut */ dragAndDrop?: boolean; /** Custom label for the "Hover" mouse action. Defaults to "Hover" */ hoverLabel?: string; /** Custom label for the "Click" mouse action. Defaults to "Click" */ clickLabel?: string; /** Custom label for the "Right click" mouse action. Defaults to "Right click" */ rightClickLabel?: string; /** Custom label for the "Drag" mouse action. Defaults to "Drag" */ dragLabel?: string; /** Custom label for the "Drag + Drop" mouse action. Defaults to "Drag + Drop" */ dragAndDropLabel?: string; /** Shortcut className */ className?: string; /** Custom OUIA ID */ ouiaId?: string | number; } const symbols = { 'shift': '⇧', 'opt': '⌥', 'cmd': '⌘', 'enter': '↵', 'ctrl': '^', 'caps lock': '⇪', 'tab': '↹', 'win': '⊞', 'backspace': '⌫' } const useStyles = createUseStyles({ shortcut: { marginRight: 'var(--pf-t--global--spacer--400)' } }) const Shortcut: FunctionComponent = ({ keys = [], description = null, showSymbols = true, hover, click, drag, rightClick, dragAndDrop, hoverLabel = 'Hover', clickLabel = 'Click', rightClickLabel = 'Right click', dragLabel = 'Drag', dragAndDropLabel = 'Drag + Drop', className, ouiaId = 'Shortcut', ...props }: ShortcutProps) => { const classes = useStyles(); const badges = [ ...(hover ? [ ] : []), ...keys.map((key) => { const trimmedKey = key.trim().toLowerCase(); return( )}), ...(click ? [ ] : []), ...(rightClick ? [ ] : []), ...(drag ? [ ] : []), ...(dragAndDrop ? [ ] : []) ] return ( <> {badges.length > 0 && badges.reduce((prev, curr, idx) => ( {[ prev, ' + ', curr ]} ))} {description} );} export default Shortcut;