Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Svelte: implement keyboard shortcut design#63253

Merged
camdencheek merged 2 commits intomainfrom
cc/kbd-design
Jun 14, 2024
Merged

Svelte: implement keyboard shortcut design#63253
camdencheek merged 2 commits intomainfrom
cc/kbd-design

Conversation

@camdencheek
Copy link
Member

@camdencheek camdencheek commented Jun 13, 2024

The current keyboard shortcuts look pretty funky against the sleek new design IMO, so I took a few minutes (that turned into a couple hours) to implement the keyboard shortcut design from Figma.

Test plan

I manually checked every place we add keyboard shortcuts. Screenshots below.

screenshot-2024-06-13_15-52-06@2x

screenshot-2024-06-13_15-50-49@2x

screenshot-2024-06-13_15-49-42@2x
screenshot-2024-06-13_15-49-29@2x

screenshot-2024-06-13_15-49-24@2x

import { formatShortcutParts, type Keys } from '$lib/Hotkey'

export let shorcut: Keys
export let shortcut: Keys
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to fix typo

Comment on lines +40 to +45
// NOTE: the height of the kdb element is based on the base
// line height. There is no way to query the line height of the
// parent, so we assume that the container has the standard
// line height. In the case the parent has a line height of 1,
// this will grow the container slightly. This can be overridden
// by setting `--line-height-base` if overriding it in the parent.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit of a gotcha, but the shortcuts look pretty bad if we constrain them to fit inside a line-height: 1.

Comment on lines +57 to +61
// When inside a selected container, show the selected variant
:global([aria-selected='true']) & {
color: white;
background-color: var(--primary);
}
Copy link
Member Author

@camdencheek camdencheek Jun 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do we think about this pattern? Rather than overriding from the container that is selected with something like :global(kbd), the KeyboardShortcut component controls its styling and variants are activated by selectors on parent components. This effectively makes aria-selected='true' part of fthe public API of this component, which we would probably want to document loudly. But, I like that this is a pure-CSS solution that doesn't require prop-drilling variables through components.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I like this. I aligns with my expectation that components should be self contained and in control over their style. It also makes things consistent because you can't forget to style it differently or pass a prop.
It might not work in all situations though. E.g. maybe we'll have a selected element with multiple shortcuts in it and we don't want to style them differently. But I'm sure we find a solution should that be the case.

@camdencheek camdencheek requested a review from a team June 13, 2024 21:53
@camdencheek camdencheek marked this pull request as ready for review June 13, 2024 21:53
Copy link
Contributor

@fkling fkling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for cleaning up all the other keyboard shortcut instances!

Comment on lines +57 to +61
// When inside a selected container, show the selected variant
:global([aria-selected='true']) & {
color: white;
background-color: var(--primary);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I like this. I aligns with my expectation that components should be self contained and in control over their style. It also makes things consistent because you can't forget to style it differently or pass a prop.
It might not work in all situations though. E.g. maybe we'll have a selected element with multiple shortcuts in it and we don't want to style them differently. But I'm sure we find a solution should that be the case.

@camdencheek camdencheek merged commit bb359cd into main Jun 14, 2024
@camdencheek camdencheek deleted the cc/kbd-design branch June 14, 2024 06:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants