Skip to content

Commit c41b71f

Browse files
committed
update keyboardKey component
1 parent 6ca931c commit c41b71f

File tree

4 files changed

+38
-13
lines changed

4 files changed

+38
-13
lines changed
Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
1-
$key-base-height: 24px;
1+
$key-base-height: 28px;
2+
$medium-side-padding: 9.5px;
23

34
.KeyboardKey {
45
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
56
display: inline-block;
67
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
78
height: $key-base-height;
89
margin: 0 var(--p-space-05) var(--p-space-05);
9-
padding: 0 var(--p-space-1);
10-
background-color: var(--p-surface);
11-
box-shadow: 0 0 0 var(--p-space-025) var(--p-border-subdued),
12-
0 var(--p-space-05) 0 0 var(--p-surface),
13-
0 var(--p-space-05) 0 var(--p-space-025) var(--p-border-subdued);
14-
border-radius: var(--p-border-radius-1);
10+
padding: 0 $medium-side-padding;
11+
background: var(--p-surface-depressed);
12+
box-shadow: 0px var(--p-space-025) 0px rgb(0 0 0 / 15%);
13+
border-radius: var(--p-space-1);
14+
color: var(--p-text);
1515
font-family: var(--p-font-family-sans);
1616
font-size: var(--p-font-size-75);
1717
font-weight: var(--p-font-weight-medium);
1818
line-height: $key-base-height;
19-
color: var(--p-text-subdued);
2019
text-align: center;
2120
min-width: $key-base-height;
2221
user-select: none;
2322
}
23+
24+
.small {
25+
color: var(--p-text-subdued);
26+
border-radius: var(--p-space-05);
27+
box-shadow: none;
28+
max-height: var(--p-space-5);
29+
display: inline;
30+
font-size: var(--p-space-3);
31+
padding: var(--p-space-05) var(--p-space-1);
32+
}

polaris-react/src/components/KeyboardKey/KeyboardKey.stories.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,9 @@ export default {
77
} as ComponentMeta<typeof KeyboardKey>;
88

99
export function Default() {
10-
return <KeyboardKey>Ctrl</KeyboardKey>;
10+
return <KeyboardKey></KeyboardKey>;
11+
}
12+
13+
export function Small() {
14+
return <KeyboardKey variant="small"></KeyboardKey>;
1115
}
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import React from 'react';
22

3+
import {classNames} from '../../utilities/css';
4+
35
import styles from './KeyboardKey.scss';
46

7+
type Variant = 'small';
8+
59
export interface KeyboardKeyProps {
6-
/** The content to display inside the key */
710
children?: string;
11+
variant?: Variant;
812
}
9-
10-
export function KeyboardKey({children}: KeyboardKeyProps) {
13+
export function KeyboardKey({children, variant}: KeyboardKeyProps) {
1114
let key = children || '';
1215
key = key.length > 1 ? key.toLowerCase() : key.toUpperCase();
1316

14-
return <kbd className={styles.KeyboardKey}>{key}</kbd>;
17+
const className = classNames(styles.KeyboardKey, variant && styles[variant]);
18+
19+
return <kbd className={className}>{key}</kbd>;
1520
}

polaris-react/src/components/KeyboardKey/tests/KeyboardKey.test.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,11 @@ describe('<KeyboardKey />', () => {
2323
const keyboardKey = mountWithApp(<KeyboardKey />);
2424
expect(keyboardKey).toContainReactText('');
2525
});
26+
27+
it("renders small icon when variant is set to 'small'", () => {
28+
const keyboardKey = mountWithApp(<KeyboardKey variant="small" />);
29+
expect(keyboardKey).toContainReactComponent('kbd', {
30+
className: 'KeyboardKey small',
31+
});
32+
});
2633
});

0 commit comments

Comments
 (0)