1- import { isMacOS } from '@primer/behaviors/utils'
2-
31/** Converts the first character of the string to upper case and the remaining to lower case. */
42// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
53const capitalize = ( [ first , ...rest ] : string ) => ( first ?. toUpperCase ( ) ?? '' ) + rest . join ( '' ) . toLowerCase ( )
@@ -8,19 +6,16 @@ const capitalize = ([first, ...rest]: string) => (first?.toUpperCase() ?? '') +
86// would be realistically used in shortcuts. For example, the Pause/Break key is not necessary
97// because it is not found on many keyboards.
108
11- // These are methods instead of plain objects to delay calling isMacOS (which depends on
12- // `window.navigator`) and avoid SSR issues
13-
149/**
1510 * Short-form iconic versions of keys. These should be intuitive (not archaic) and match icons on keyboards.
1611 */
17- export const condensedKeyName = ( key : string ) =>
12+ export const condensedKeyName = ( key : string , isMacOS : boolean ) =>
1813 ( {
19- alt : isMacOS ( ) ? '⌥' : 'Alt' , // the alt key _is_ the option key on MacOS - in the browser there is no "option" key
14+ alt : isMacOS ? '⌥' : 'Alt' , // the alt key _is_ the option key on MacOS - in the browser there is no "option" key
2015 control : '⌃' ,
2116 shift : '⇧' ,
22- meta : isMacOS ( ) ? '⌘' : 'Win' ,
23- mod : isMacOS ( ) ? '⌘' : '⌃' ,
17+ meta : isMacOS ? '⌘' : 'Win' ,
18+ mod : isMacOS ? '⌘' : '⌃' ,
2419 pageup : 'PgUp' ,
2520 pagedown : 'PgDn' ,
2621 arrowup : '↑' ,
@@ -44,10 +39,10 @@ export const condensedKeyName = (key: string) =>
4439 * Specific key displays for 'full' format. We still do show some icons (ie punctuation)
4540 * because that's more intuitive, but for the rest of keys we show the standard key name.
4641 */
47- export const fullKeyName = ( key : string ) =>
42+ export const fullKeyName = ( key : string , isMacOS : boolean ) =>
4843 ( {
49- alt : isMacOS ( ) ? 'Option' : 'Alt' ,
50- mod : isMacOS ( ) ? 'Command' : 'Control' ,
44+ alt : isMacOS ? 'Option' : 'Alt' ,
45+ mod : isMacOS ? 'Command' : 'Control' ,
5146 '+' : 'Plus' ,
5247 pageup : 'Page Up' ,
5348 pagedown : 'Page Down' ,
@@ -64,11 +59,11 @@ export const fullKeyName = (key: string) =>
6459 * readers from expressing punctuation in speech, ie, reading a long pause instead of the
6560 * word "period".
6661 */
67- export const accessibleKeyName = ( key : string ) =>
62+ export const accessibleKeyName = ( key : string , isMacOS : boolean ) =>
6863 ( {
69- alt : isMacOS ( ) ? 'option' : 'alt' ,
70- meta : isMacOS ( ) ? 'command' : 'Windows' ,
71- mod : isMacOS ( ) ? 'command' : 'control' ,
64+ alt : isMacOS ? 'option' : 'alt' ,
65+ meta : isMacOS ? 'command' : 'Windows' ,
66+ mod : isMacOS ? 'command' : 'control' ,
7267 // Screen readers may not be able to pronounce concatenated words - this provides a better experience
7368 pageup : 'page up' ,
7469 pagedown : 'page down' ,
0 commit comments