Skip to content

Commit 27648ca

Browse files
committed
Add size attribute to the button
1 parent 7b55d5f commit 27648ca

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

packages/components/src/button/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import { attr } from '@microsoft/fast-element';
66
import { Button, buttonTemplate as template } from '@microsoft/fast-foundation';
77
import { buttonStyles as styles } from './button.styles.js';
88

9+
/**
10+
* Scale locally an element.
11+
*/
12+
export type ElementSize = 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge';
13+
914
/**
1015
* Types of button appearance.
1116
* @public
@@ -40,11 +45,19 @@ class JupyterButton extends Button {
4045
*
4146
* @public
4247
* @remarks
48+
*
49+
* @deprecated Use {@link size} `xsmall` instead
4350
* HTML Attribute: minimal
4451
*/
4552
@attr({ attribute: 'minimal', mode: 'boolean' })
4653
public minimal: boolean;
4754

55+
/**
56+
* Scale the element compared to the general size.
57+
*/
58+
@attr
59+
public size?: ElementSize;
60+
4861
/**
4962
* Applies 'icon-only' class when there is only an SVG in the default slot
5063
*

packages/components/src/design-tokens.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ export const controlCornerRadius = create<number>(
9898
export const density = create<number>('density').withDefault(0);
9999
/** @public */
100100
export const designUnit = create<number>('design-unit').withDefault(4);
101+
/**
102+
* Adds to the density on specified element.
103+
*
104+
* @private
105+
*/
106+
export const elementSize = create<number>('element-size').withDefault(0);
101107
/** @public */
102108
export const direction = create<Direction>('direction').withDefault(
103109
Direction.ltr

packages/components/src/styles/patterns/button.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
controlCornerRadius,
2222
density,
2323
designUnit,
24+
elementSize,
2425
errorFillActive,
2526
errorFillFocus,
2627
errorFillHover,
@@ -75,7 +76,8 @@ export const BaseButtonStyles = css`
7576
display: inline-flex;
7677
justify-content: center;
7778
align-items: center;
78-
padding: 0 calc((10 + (${designUnit} * 2 * ${density})) * 1px);
79+
padding: 0
80+
calc((10 + (${designUnit} * 2 * (${density} + ${elementSize}))) * 1px);
7981
white-space: nowrap;
8082
outline: none;
8183
text-decoration: none;
@@ -101,14 +103,32 @@ export const BaseButtonStyles = css`
101103
box-shadow: inset 0px 0px 2px 2px ${neutralFillStrongActive};
102104
}
103105
104-
:host([minimal]) {
105-
--density: -4;
106+
:host([minimal]),
107+
:host([size='xsmall']) {
108+
--element-size: -4;
106109
}
107110
108-
:host([minimal]) .control {
111+
:host([minimal]) .control,
112+
:host([size='xsmall']) .control {
109113
padding: 1px;
110114
}
111115
116+
:host([size='small']) {
117+
--element-size: -2;
118+
}
119+
120+
:host([size='medium']) {
121+
--element-size: 1;
122+
}
123+
124+
:host([size='large']) {
125+
--element-size: 2;
126+
}
127+
128+
:host([size='xlarge']) {
129+
--element-size: 4;
130+
}
131+
112132
/* prettier-ignore */
113133
.control:${focusVisible} {
114134
outline: calc(${focusStrokeWidth} * 1px) solid ${neutralFillStrongFocus};

0 commit comments

Comments
 (0)