Skip to content

Commit 47199ad

Browse files
authored
Add support for split buttons
1 parent 84f6ad6 commit 47199ad

7 files changed

Lines changed: 132 additions & 4 deletions

File tree

src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export {VscodeRadio} from './vscode-radio/index.js';
1818
export {VscodeRadioGroup} from './vscode-radio-group/index.js';
1919
export {VscodeSingleSelect} from './vscode-single-select/index.js';
2020
export {VscodeScrollable} from './vscode-scrollable/index.js';
21+
export {VscodeSplitButton} from './vscode-split-button/index.js';
22+
export {VscodeSplitButtonDivider} from './vscode-split-button-divider/index.js';
2123
export {VscodeSplitLayout} from './vscode-split-layout/index.js';
2224
export {VscodeTabHeader} from './vscode-tab-header/index.js';
2325
export {VscodeTabPanel} from './vscode-tab-panel/index.js';

src/vscode-button/vscode-button.styles.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ const styles: CSSResultGroup = [
2626
white-space: nowrap;
2727
}
2828
29+
:host(:empty) {
30+
padding: 1px 5px;
31+
}
32+
2933
:host([secondary]) {
3034
color: var(--vscode-button-secondaryForeground, #cccccc);
3135
background-color: var(--vscode-button-secondaryBackground, #313131);
@@ -91,6 +95,10 @@ const styles: CSSResultGroup = [
9195
margin-left: 0;
9296
}
9397
98+
::slotted(*:last-child) {
99+
margin-right: 0;
100+
}
101+
94102
::slotted(vscode-icon) {
95103
color: inherit;
96104
}
@@ -102,6 +110,7 @@ const styles: CSSResultGroup = [
102110
justify-content: center;
103111
position: relative;
104112
width: 100%;
113+
height: 100%;
105114
}
106115
107116
slot {
@@ -110,15 +119,16 @@ const styles: CSSResultGroup = [
110119
height: 100%;
111120
}
112121
113-
.icon {
122+
.icon, .icon-after {
114123
color: inherit;
115124
display: block;
125+
}
126+
127+
:host(:not(:empty)) .icon {
116128
margin-right: 3px;
117129
}
118130
119-
.icon-after {
120-
color: inherit;
121-
display: block;
131+
:host(:not(:empty)) .icon-after, :host([icon]) .icon-after {
122132
margin-left: 3px;
123133
}
124134
`,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {VscodeSplitButtonDivider} from './vscode-split-button-divider.js';
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import {css, html, TemplateResult} from 'lit';
2+
import {customElement, property} from 'lit/decorators.js';
3+
import {VscElement} from '../includes/VscElement.js';
4+
5+
/**
6+
* A divider to show between two buttons in a split button.
7+
*
8+
* @tag vscode-split-button-divider
9+
*/
10+
@customElement('vscode-split-button-divider')
11+
export class VscodeSplitButtonDivider extends VscElement {
12+
static override get styles() {
13+
return css`
14+
:host {
15+
background-color: var(--vscode-button-background, #0078d4);
16+
padding: 4px 0;
17+
display: flex;
18+
box-sizing: border-box;
19+
}
20+
:host([secondary]) {
21+
background-color: var(--vscode-button-secondaryBackground, #313131);
22+
}
23+
div {
24+
background-color: var(--vscode-button-separator);
25+
width: 1px;
26+
margin: 0;
27+
}
28+
`;
29+
}
30+
31+
/**
32+
* Button has a less prominent style.
33+
*/
34+
@property({type: Boolean, reflect: true})
35+
secondary = false;
36+
37+
override render() {
38+
return html`<div></div> `;
39+
}
40+
}
41+
42+
declare global {
43+
interface HTMLElementTagNameMap {
44+
'vscode-split-button-divider': VscodeSplitButtonDivider;
45+
}
46+
}

src/vscode-split-button/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {VscodeSplitButton} from './vscode-split-button.js';
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import {css, CSSResultGroup} from 'lit';
2+
3+
import defaultStyles from '../includes/default.styles.js';
4+
import {getDefaultFontStack} from '../includes/helpers.js';
5+
6+
const defaultFontStack = getDefaultFontStack();
7+
8+
const styles: CSSResultGroup = [
9+
defaultStyles,
10+
css`
11+
:host {
12+
display: flex;
13+
align-items: stretch;
14+
padding: 0;
15+
border: none;
16+
}
17+
18+
::slotted(vscode-button:not(:first-child)) {
19+
border-top-left-radius: 0;
20+
border-bottom-left-radius: 0;
21+
border-left-width: 0;
22+
}
23+
24+
::slotted(vscode-button:not(:last-child)) {
25+
border-top-right-radius: 0;
26+
border-bottom-right-radius: 0;
27+
border-right-width: 0;
28+
}
29+
`,
30+
];
31+
32+
export default styles;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import {html, TemplateResult} from 'lit';
2+
import {customElement, property} from 'lit/decorators.js';
3+
import {VscElement} from '../includes/VscElement.js';
4+
import styles from './vscode-split-button.styles.js';
5+
6+
/**
7+
* Shows a split button, including several components in a single button. Commonly used to show a button with a dropdown to the right.
8+
*
9+
* @tag vscode-split-button
10+
*
11+
* @cssprop [--vscode-button-background=#0078d4]
12+
* @cssprop [--vscode-button-foreground=#ffffff]
13+
* @cssprop [--vscode-button-border=var(--vscode-button-background, rgba(255, 255, 255, 0.07))]
14+
* @cssprop [--vscode-button-hoverBackground=#026ec1]
15+
* @cssprop [--vscode-font-family=sans-serif] - A sans-serif font type depends on the host OS.
16+
* @cssprop [--vscode-font-size=13px]
17+
* @cssprop [--vscode-font-weight=normal]
18+
* @cssprop [--vscode-button-secondaryForeground=#cccccc]
19+
* @cssprop [--vscode-button-secondaryBackground=#313131]
20+
* @cssprop [--vscode-button-secondaryHoverBackground=#3c3c3c]
21+
* @cssprop [--vscode-focusBorder=#0078d4]
22+
*/
23+
@customElement('vscode-split-button')
24+
export class VscodeSplitButton extends VscElement {
25+
static override styles = styles;
26+
27+
override render(): TemplateResult {
28+
return html` <slot></slot> `;
29+
}
30+
}
31+
32+
declare global {
33+
interface HTMLElementTagNameMap {
34+
'vscode-split-button': VscodeSplitButton;
35+
}
36+
}

0 commit comments

Comments
 (0)