Update style of keybinds for menu items

This commit is contained in:
Andrew Kingston 2022-08-02 10:01:24 +01:00
parent 7b7075b276
commit 530b6940d4
1 changed files with 40 additions and 9 deletions

View File

@ -10,6 +10,21 @@
export let noClose = false export let noClose = false
export let keyBind = undefined export let keyBind = undefined
$: keys = getKeys(keyBind)
const getKeys = keyBind => {
let keys = keyBind?.split("+") || []
for (let i = 0; i < keys.length; i++) {
if (
keys[i].toLowerCase() === "ctrl" &&
navigator.platform.startsWith("Mac")
) {
keys[i] = "⌘"
}
}
return keys
}
const onClick = () => { const onClick = () => {
if (actionMenu && !noClose) { if (actionMenu && !noClose) {
actionMenu.hide() actionMenu.hide()
@ -37,9 +52,13 @@
</svg> </svg>
{/if} {/if}
<span class="spectrum-Menu-itemLabel"><slot /></span> <span class="spectrum-Menu-itemLabel"><slot /></span>
{#if keyBind} {#if keys?.length}
<div class="keyBind"> <div class="keys">
{keyBind} {#each keys as key}
<div class="key">
{key}
</div>
{/each}
</div> </div>
{/if} {/if}
</li> </li>
@ -48,14 +67,26 @@
.spectrum-Menu-itemIcon { .spectrum-Menu-itemIcon {
align-self: center; align-self: center;
} }
.keyBind { .keys {
margin-left: var(--spacing-xl); margin-left: 30px;
color: var(--spectrum-global-color-gray-600); display: flex;
text-transform: uppercase; flex-direction: row;
justify-content: flex-end;
align-items: center;
gap: 4px;
}
.key {
color: var(--spectrum-global-color-gray-900);
padding: 2px 4px;
font-size: 12px; font-size: 12px;
font-weight: 600; font-weight: 600;
background-color: var(--spectrum-global-color-gray-300);
border-radius: 4px;
min-width: 12px;
text-align: center;
margin: -1px 0;
} }
.is-disabled .keyBind { .is-disabled .key {
color: var(--spectrum-global-color-gray-300); color: var(--spectrum-global-color-gray-600);
} }
</style> </style>