Skip to content

Commit

Permalink
Fix import
Browse files Browse the repository at this point in the history
  • Loading branch information
miina committed Nov 18, 2022
1 parent bb45f35 commit 9f9f11f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 28 deletions.
17 changes: 17 additions & 0 deletions packages/design-system/src/components/keyboard/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './keyboard';
export * from './utils';
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ import {
resolveKeySpec,
createKeyHandler,
createShortcutAriaLabel,
isPlatformMacOS,
getKeyForOS,
prettifyShortcut,
} from './utils';

const globalRef: { current: null | HTMLElement } = { current: null };
Expand Down Expand Up @@ -210,32 +209,6 @@ export function useEscapeToBlurEffect(
);
}

/**
* Prettifies keyboard shortcuts in a platform-agnostic way.
*/
export function prettifyShortcut(shortcut: string) {
const isMacOS = isPlatformMacOS();

const delimiter = isMacOS ? '' : '+';

return shortcut
.toLowerCase()
.replace('alt', getKeyForOS('alt'))
.replace('ctrl', getKeyForOS('ctrl'))
.replace('mod', getKeyForOS('mod'))
.replace('cmd', getKeyForOS('cmd'))
.replace('shift', getKeyForOS('shift'))
.replace('left', '←')
.replace('up', '↑')
.replace('right', '→')
.replace('down', '↓')
.replace('delete', '⌫')
.replace('enter', '⏎')
.split('+')
.map((s) => s.charAt(0).toUpperCase() + s.slice(1))
.join(delimiter);
}

interface ShortcutProps {
component: React.FC;
shortcut?: string;
Expand Down
26 changes: 26 additions & 0 deletions packages/design-system/src/components/keyboard/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,29 @@ export function createShortcutAriaLabel(shortcut: string) {
.map((s) => s.charAt(0).toUpperCase() + s.slice(1))
.join(delimiter);
}

/**
* Prettifies keyboard shortcuts in a platform-agnostic way.
*/
export function prettifyShortcut(shortcut: string) {
const isMacOS = isPlatformMacOS();

const delimiter = isMacOS ? '' : '+';

return shortcut
.toLowerCase()
.replace('alt', getKeyForOS('alt'))
.replace('ctrl', getKeyForOS('ctrl'))
.replace('mod', getKeyForOS('mod'))
.replace('cmd', getKeyForOS('cmd'))
.replace('shift', getKeyForOS('shift'))
.replace('left', '←')
.replace('up', '↑')
.replace('right', '→')
.replace('down', '↓')
.replace('delete', '⌫')
.replace('enter', '⏎')
.split('+')
.map((s) => s.charAt(0).toUpperCase() + s.slice(1))
.join(delimiter);
}

0 comments on commit 9f9f11f

Please sign in to comment.