From 4a2eeb85b6d480da5f9b96305465e26d91c3a1aa Mon Sep 17 00:00:00 2001 From: Revanshu Paliwal Date: Tue, 6 Feb 2024 10:26:10 +0100 Subject: SONAR-21566 Migrate keyboard shortcut modal to new UI --- .../src/components/KeyboardHintKeys.tsx | 15 +++++++-- .../__snapshots__/KeyboardHint-test.tsx.snap | 36 ++++++++++++++++---- .../__snapshots__/KeyboardHintKeys-test.tsx.snap | 38 ++++++++++++---------- 3 files changed, 62 insertions(+), 27 deletions(-) (limited to 'server/sonar-web/design-system/src/components') diff --git a/server/sonar-web/design-system/src/components/KeyboardHintKeys.tsx b/server/sonar-web/design-system/src/components/KeyboardHintKeys.tsx index 84cf5e12a5e..44ac3e6c4ba 100644 --- a/server/sonar-web/design-system/src/components/KeyboardHintKeys.tsx +++ b/server/sonar-web/design-system/src/components/KeyboardHintKeys.tsx @@ -18,6 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import styled from '@emotion/styled'; +import classNames from 'classnames'; import tw from 'twin.macro'; import { themeColor, themeContrast } from '../helpers'; import { Key } from '../helpers/keyboard'; @@ -35,6 +36,8 @@ export const mappedKeys = { [Key.Click]: 'click', }; +const NON_KEY_SYMBOLS = ['+', ' ']; + export function KeyboardHintKeys({ command }: { command: string }) { const keys = command .trim() @@ -42,11 +45,19 @@ export function KeyboardHintKeys({ command }: { command: string }) { .map((key, index) => { const uniqueKey = `${key}-${index}`; - if (!(Object.keys(mappedKeys).includes(key) || Object.values(mappedKeys).includes(key))) { + if (NON_KEY_SYMBOLS.includes(key)) { return {key}; } - return {mappedKeys[key as keyof typeof mappedKeys] || key}; + const isNonMappedKey = !( + Object.keys(mappedKeys).includes(key) || Object.values(mappedKeys).includes(key) + ); + + return ( + + {Object.keys(mappedKeys).includes(key) ? mappedKeys[key as keyof typeof mappedKeys] : key} + + ); }); return
{keys}
; diff --git a/server/sonar-web/design-system/src/components/__tests__/__snapshots__/KeyboardHint-test.tsx.snap b/server/sonar-web/design-system/src/components/__tests__/__snapshots__/KeyboardHint-test.tsx.snap index 798c34a273f..a45b1d68bd8 100644 --- a/server/sonar-web/design-system/src/components/__tests__/__snapshots__/KeyboardHint-test.tsx.snap +++ b/server/sonar-web/design-system/src/components/__tests__/__snapshots__/KeyboardHint-test.tsx.snap @@ -46,12 +46,12 @@ exports[`renders on mac 1`] = ` class="sw-flex sw-gap-1" > @@ -106,12 +106,12 @@ exports[`renders on windows 1`] = ` class="sw-flex sw-gap-1" > Ctrl Alt @@ -138,6 +138,26 @@ exports[`renders with command 1`] = ` color: rgb(106,117,144); } +.emotion-2 { + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + -webkit-box-pack: center; + -ms-flex-pack: center; + -webkit-justify-content: center; + justify-content: center; + padding-left: 0.125rem; + padding-right: 0.125rem; + border-radius: 0.125rem; + background-color: rgb(225,230,243); + color: rgb(62,67,87); +} +
- + command
@@ -204,7 +226,7 @@ exports[`renders with title 1`] = ` class="sw-flex sw-gap-1" > click @@ -259,7 +281,7 @@ exports[`renders without title 1`] = ` class="sw-flex sw-gap-1" > click diff --git a/server/sonar-web/design-system/src/components/__tests__/__snapshots__/KeyboardHintKeys-test.tsx.snap b/server/sonar-web/design-system/src/components/__tests__/__snapshots__/KeyboardHintKeys-test.tsx.snap index 337d1b9b385..d1ec21d7864 100644 --- a/server/sonar-web/design-system/src/components/__tests__/__snapshots__/KeyboardHintKeys-test.tsx.snap +++ b/server/sonar-web/design-system/src/components/__tests__/__snapshots__/KeyboardHintKeys-test.tsx.snap @@ -26,7 +26,7 @@ exports[`should render Alt 1`] = ` class="sw-flex sw-gap-1" > Alt @@ -60,7 +60,7 @@ exports[`should render ArrowDown 1`] = ` class="sw-flex sw-gap-1" > click @@ -286,7 +286,7 @@ exports[`should render Command 1`] = ` class="sw-flex sw-gap-1" > @@ -320,7 +320,7 @@ exports[`should render Control 1`] = ` class="sw-flex sw-gap-1" > Ctrl @@ -354,7 +354,7 @@ exports[`should render Option 1`] = ` class="sw-flex sw-gap-1" > @@ -388,7 +388,7 @@ exports[`should render a default text if no keys match 1`] = ` class="sw-flex sw-gap-1" > Ctrl @@ -396,7 +396,7 @@ exports[`should render a default text if no keys match 1`] = ` + click @@ -429,11 +429,13 @@ exports[`should render multiple keys 1`] = `
- + Use Ctrl @@ -441,7 +443,7 @@ exports[`should render multiple keys 1`] = ` + Ctrl @@ -516,7 +518,7 @@ exports[`should render multiple keys with non-key symbols 1`] = ` +