Skip to content

Commit 407fd00

Browse files
committed
Rename size to scale to avoid issue on select element
Add new scale attribute on combobox and select instead of minimal (deprecated)
1 parent 27648ca commit 407fd00

File tree

10 files changed

+93
-40
lines changed

10 files changed

+93
-40
lines changed

packages/components/src/button/button.stories.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ export default {
2121
},
2222
disabled: { control: 'boolean' },
2323
autofocus: { control: 'boolean' },
24-
minimal: { control: 'boolean' },
24+
scale: {
25+
control: 'select',
26+
options: ['xsmall', 'small', 'medium', 'large', 'xlarge']
27+
},
2528
startIcon: { control: 'boolean' },
2629
onClick: {
2730
action: 'clicked',
@@ -44,7 +47,7 @@ const Template: StoryFn = (args): HTMLElement => {
4447
${args.appearance ? `appearance=${args.appearance.toLowerCase()}` : ''}
4548
${args.disabled ? 'disabled' : ''}
4649
${args.autofocus ? 'autofocus' : ''}
47-
${args.minimal ? 'minimal' : ''}
50+
${args.scale ? `scale=${args.scale}` : ''}
4851
${args.ariaPressed !== 'none' ? `aria-pressed=${args.ariaPressed}` : ''}
4952
>${args.startIcon ? getFaIcon('plus', args.label ? 'start' : null) : ''}${
5053
args.label ?? ''
@@ -64,7 +67,7 @@ Accent.args = {
6467
appearance: 'Accent',
6568
disabled: false,
6669
autofocus: false,
67-
minimal: false,
70+
scale: 'medium',
6871
startIcon: false,
6972
ariaPressed: 'none',
7073
onClick: action('button-clicked')

packages/components/src/button/index.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55
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';
8-
9-
/**
10-
* Scale locally an element.
11-
*/
12-
export type ElementSize = 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge';
8+
import type { ElementScale } from '../styles/size.js';
139

1410
/**
1511
* Types of button appearance.
@@ -46,17 +42,17 @@ class JupyterButton extends Button {
4642
* @public
4743
* @remarks
4844
*
49-
* @deprecated Use {@link size} `xsmall` instead
45+
* @deprecated Use {@link scale} `xsmall` instead
5046
* HTML Attribute: minimal
5147
*/
5248
@attr({ attribute: 'minimal', mode: 'boolean' })
5349
public minimal: boolean;
5450

5551
/**
56-
* Scale the element compared to the general size.
52+
* Scale the element compared to the theme size.
5753
*/
5854
@attr
59-
public size?: ElementSize;
55+
public scale?: ElementScale;
6056

6157
/**
6258
* Applies 'icon-only' class when there is only an SVG in the default slot

packages/components/src/combobox/combobox.stories.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ export default {
1313
disabled: { control: 'boolean' },
1414
customIndicator: { control: 'boolean' },
1515
numberOfChildren: { control: 'number' },
16-
minimal: { control: 'boolean' },
16+
scale: {
17+
control: 'select',
18+
options: ['xsmall', 'small', 'medium', 'large', 'xlarge']
19+
},
1720
autowidth: { control: 'boolean' },
1821
autocomplete: {
1922
control: 'select',
@@ -58,7 +61,7 @@ const Template: StoryFn = (args): HTMLElement => {
5861
'afterbegin',
5962
`<jp-combobox
6063
${args.disabled ? 'disabled' : ''}
61-
${args.minimal ? 'minimal' : ''}
64+
${args.scale ? `scale=${args.scale}` : ''}
6265
${args.autowidth ? 'autowidth' : ''}
6366
${args.autocomplete !== 'none' ? `autocomplete=${args.autocomplete}` : ''}
6467
${args.ariaInvalid ? `aria-invalid="${args.ariaInvalid}"` : ''}
@@ -98,7 +101,7 @@ Default.args = {
98101
disabled: false,
99102
customIndicator: false,
100103
numberOfChildren: 10,
101-
minimal: false,
104+
scale: 'medium',
102105
autowidth: false,
103106
autocomplete: 'none',
104107
ariaInvalid: false,

packages/components/src/combobox/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from '@microsoft/fast-foundation';
1111
import { heightNumberAsToken } from '../design-tokens.js';
1212
import { comboboxStyles as styles } from './combobox.styles.js';
13+
import type { ElementScale } from '../styles/size.js';
1314

1415
/**
1516
* Combobox class
@@ -35,11 +36,20 @@ class JupyterCombobox extends Combobox {
3536
*
3637
* @public
3738
* @remarks
39+
*
40+
* @deprecated Use {@link scale} `xsmall` instead
41+
*
3842
* HTML Attribute: minimal
3943
*/
4044
@attr({ attribute: 'minimal', mode: 'boolean' })
4145
public minimal: boolean;
4246

47+
/**
48+
* Scale the element compared to the theme size.
49+
*/
50+
@attr
51+
public scale?: ElementScale;
52+
4353
/**
4454
* The connected callback for this FASTElement.
4555
*

packages/components/src/design-tokens.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export const designUnit = create<number>('design-unit').withDefault(4);
103103
*
104104
* @private
105105
*/
106-
export const elementSize = create<number>('element-size').withDefault(0);
106+
export const elementScale = create<number>('element-scale').withDefault(0);
107107
/** @public */
108108
export const direction = create<Direction>('direction').withDefault(
109109
Direction.ltr

packages/components/src/select/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
neutralLayerFloating
1515
} from '../design-tokens.js';
1616
import { selectStyles as styles } from './select.styles.js';
17+
import type { ElementScale } from '../styles/size.js';
1718

1819
/**
1920
* Select class
@@ -73,11 +74,20 @@ class JupyterSelect extends Select {
7374
*
7475
* @public
7576
* @remarks
77+
*
78+
* @deprecated Use {@link scale} `xsmall` instead
79+
*
7680
* HTML Attribute: minimal
7781
*/
7882
@attr({ attribute: 'minimal', mode: 'boolean' })
7983
public minimal: boolean;
8084

85+
/**
86+
* Scale the element compared to the theme size.
87+
*/
88+
@attr
89+
public scale?: ElementScale;
90+
8191
/**
8292
* An internal stylesheet to hold calculated CSS custom properties.
8393
*

packages/components/src/select/select.stories.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ export default {
1212
disabled: { control: 'boolean' },
1313
customIndicator: { control: 'boolean' },
1414
numberOfChildren: { control: 'number' },
15-
minimal: { control: 'boolean' },
15+
scale: {
16+
control: 'select',
17+
options: ['xsmall', 'small', 'medium', 'large', 'xlarge']
18+
},
19+
size: { control: 'number' },
1620
autowidth: { control: 'boolean' },
1721
ariaInvalid: { control: 'boolean' },
1822
onChange: {
@@ -39,7 +43,8 @@ const Template: StoryFn = (args, context): HTMLElement => {
3943
'afterbegin',
4044
`<jp-select
4145
${args.disabled ? 'disabled' : ''}
42-
${args.minimal ? 'minimal' : ''}
46+
${args.scale ? `scale=${args.scale}` : ''}
47+
${args.size > 0 ? `size=${args.size}` : ''}
4348
${args.autowidth ? 'autowidth' : ''}
4449
${args.ariaInvalid ? `aria-invalid="${args.ariaInvalid}"` : ''}
4550
>
@@ -79,7 +84,8 @@ Default.args = {
7984
disabled: false,
8085
customIndicator: false,
8186
numberOfChildren: 3,
82-
minimal: false,
87+
scale: 'medium',
88+
size: 0,
8389
autowidth: false,
8490
ariaInvalid: false,
8591
onChange: action('change'),

packages/components/src/select/select.styles.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,26 @@ export const selectStyles: FoundationElementTemplate<
146146
padding: 0 calc(${designUnit} * 2.25px);
147147
width: 100%;
148148
}
149-
150-
:host([minimal]) {
151-
--density: -4;
149+
150+
:host([minimal]),
151+
:host([scale='xsmall']) {
152+
--element-scale: -4;
153+
}
154+
155+
:host([scale='small']) {
156+
--element-scale: -2;
157+
}
158+
159+
:host([scale='medium']) {
160+
--element-scale: 1;
161+
}
162+
163+
:host([scale='large']) {
164+
--element-scale: 2;
165+
}
166+
167+
:host([scale='xlarge']) {
168+
--element-scale: 4;
152169
}
153170
154171
:host(:not([disabled]):hover) {

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
controlCornerRadius,
2222
density,
2323
designUnit,
24-
elementSize,
24+
elementScale,
2525
errorFillActive,
2626
errorFillFocus,
2727
errorFillHover,
@@ -77,7 +77,10 @@ export const BaseButtonStyles = css`
7777
justify-content: center;
7878
align-items: center;
7979
padding: 0
80-
calc((10 + (${designUnit} * 2 * (${density} + ${elementSize}))) * 1px);
80+
max(
81+
1px,
82+
calc((10 + (${designUnit} * 2 * (${density} + ${elementScale})))) * 1px
83+
);
8184
white-space: nowrap;
8285
outline: none;
8386
text-decoration: none;
@@ -104,29 +107,24 @@ export const BaseButtonStyles = css`
104107
}
105108
106109
:host([minimal]),
107-
:host([size='xsmall']) {
108-
--element-size: -4;
110+
:host([scale='xsmall']) {
111+
--element-scale: -4;
109112
}
110113
111-
:host([minimal]) .control,
112-
:host([size='xsmall']) .control {
113-
padding: 1px;
114+
:host([scale='small']) {
115+
--element-scale: -2;
114116
}
115117
116-
:host([size='small']) {
117-
--element-size: -2;
118+
:host([scale='medium']) {
119+
--element-scale: 1;
118120
}
119121
120-
:host([size='medium']) {
121-
--element-size: 1;
122+
:host([scale='large']) {
123+
--element-scale: 2;
122124
}
123125
124-
:host([size='large']) {
125-
--element-size: 2;
126-
}
127-
128-
:host([size='xlarge']) {
129-
--element-size: 4;
126+
:host([scale='xlarge']) {
127+
--element-scale: 4;
130128
}
131129
132130
/* prettier-ignore */

packages/components/src/styles/size.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@
33
// Distributed under the terms of the Modified BSD License.
44

55
import { cssPartial } from '@microsoft/fast-element';
6-
import { baseHeightMultiplier, density, designUnit } from '../design-tokens.js';
6+
import {
7+
baseHeightMultiplier,
8+
density,
9+
designUnit,
10+
elementScale
11+
} from '../design-tokens.js';
12+
13+
/**
14+
* Scale locally an element.
15+
*/
16+
export type ElementScale = 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge';
717

818
/**
919
* A formula to retrieve the control height.
1020
* Use this as the value of any CSS property that
1121
* accepts a pixel size.
1222
*/
13-
export const heightNumber = cssPartial`(${baseHeightMultiplier} + ${density}) * ${designUnit}`;
23+
export const heightNumber = cssPartial`(${baseHeightMultiplier} + ${density} + ${elementScale}) * ${designUnit}`;

0 commit comments

Comments
 (0)