-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
45 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,32 @@ | ||
import * as React from 'react' | ||
import { cn } from '@/lib/utils' | ||
import { getShortcutKeys } from '../utils' | ||
import { getShortcutKey } from '../utils' | ||
|
||
interface ShortcutKeyProps extends React.HTMLAttributes<HTMLSpanElement> { | ||
export interface ShortcutKeyProps extends React.HTMLAttributes<HTMLSpanElement> { | ||
keys: string[] | ||
} | ||
|
||
export const ShortcutKey = ({ className, keys, ...props }: ShortcutKeyProps) => { | ||
export const ShortcutKey = React.forwardRef<HTMLSpanElement, ShortcutKeyProps>(({ className, keys, ...props }, ref) => { | ||
const modifiedKeys = keys.map(key => getShortcutKey(key)) | ||
const ariaLabel = modifiedKeys.map(shortcut => shortcut.readable).join(' + ') | ||
|
||
return ( | ||
<span className={cn('text-xs tracking-widest opacity-60', className)} {...props}> | ||
<span className={cn('ml-4')}>{getShortcutKeys(keys)}</span> | ||
<span aria-label={ariaLabel} className={cn('inline-flex items-center gap-0.5', className)} {...props} ref={ref}> | ||
{modifiedKeys.map(shortcut => ( | ||
<kbd | ||
className={cn( | ||
'inline-block min-w-2.5 text-center align-baseline font-sans text-xs font-medium capitalize text-[rgb(156,157,160)]', | ||
|
||
className | ||
)} | ||
{...props} | ||
ref={ref} | ||
> | ||
{shortcut.symbol} | ||
</kbd> | ||
))} | ||
</span> | ||
) | ||
} | ||
}) | ||
|
||
ShortcutKey.displayName = 'ShortcutKey' | ||
|
||
export default ShortcutKey |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters