Skip to content

Commit 603ec95

Browse files
committed
Add button, select and combobox scale.
Remove custom element manifest build (issue with circular ref)
1 parent 7b55d5f commit 603ec95

File tree

15 files changed

+1436
-598
lines changed

15 files changed

+1436
-598
lines changed

packages/components/docs/api-report.md

Lines changed: 1288 additions & 571 deletions
Large diffs are not rendered by default.

packages/components/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
"scripts": {
2626
"start": "storybook dev -p 6006",
2727
"start:ci": "storybook dev -p 6006 --ci --quiet",
28-
"build": "rollup -c && tsc -p ./tsconfig.json && custom-elements-manifest analyze",
28+
"build": "rollup -c && tsc -p ./tsconfig.json",
29+
"build:cem": "custom-elements-manifest analyze",
2930
"build:docs": "storybook build",
30-
"build:react": "BUILD_REACT=1 custom-elements-manifest analyze",
31+
"build:react": "BUILD_REACT=1 yarn run build:cem",
3132
"clean": "yarn clean:lib && yarn clean:test",
3233
"clean:lib": "rimraf dist",
3334
"clean:test": "rimraf test-results tests-out/**/*.js tests-out/**/*.js.map tsconfig.playwright.tsbuildinfo",

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: 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 ButtonScale = '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 scale} `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 theme size.
57+
*/
58+
@attr
59+
public scale?: ButtonScale;
60+
4861
/**
4962
* Applies 'icon-only' class when there is only an SVG in the default slot
5063
*

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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import {
1111
import { heightNumberAsToken } from '../design-tokens.js';
1212
import { comboboxStyles as styles } from './combobox.styles.js';
1313

14+
/**
15+
* Scale locally an element.
16+
*/
17+
export type ComboboxScale = 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge';
18+
1419
/**
1520
* Combobox class
1621
*
@@ -35,11 +40,20 @@ class JupyterCombobox extends Combobox {
3540
*
3641
* @public
3742
* @remarks
43+
*
44+
* @deprecated Use {@link scale} `xsmall` instead
45+
*
3846
* HTML Attribute: minimal
3947
*/
4048
@attr({ attribute: 'minimal', mode: 'boolean' })
4149
public minimal: boolean;
4250

51+
/**
52+
* Scale the element compared to the theme size.
53+
*/
54+
@attr
55+
public scale?: ComboboxScale;
56+
4357
/**
4458
* The connected callback for this FASTElement.
4559
*

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 elementScale = create<number>('element-scale').withDefault(0);
101107
/** @public */
102108
export const direction = create<Direction>('direction').withDefault(
103109
Direction.ltr

packages/components/src/select/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import {
1515
} from '../design-tokens.js';
1616
import { selectStyles as styles } from './select.styles.js';
1717

18+
/**
19+
* Scale locally an element.
20+
*/
21+
export type SelectScale = 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge';
22+
1823
/**
1924
* Select class
2025
* @public
@@ -73,11 +78,20 @@ class JupyterSelect extends Select {
7378
*
7479
* @public
7580
* @remarks
81+
*
82+
* @deprecated Use {@link scale} `xsmall` instead
83+
*
7684
* HTML Attribute: minimal
7785
*/
7886
@attr({ attribute: 'minimal', mode: 'boolean' })
7987
public minimal: boolean;
8088

89+
/**
90+
* Scale the element compared to the theme size.
91+
*/
92+
@attr
93+
public scale?: SelectScale;
94+
8195
/**
8296
* An internal stylesheet to hold calculated CSS custom properties.
8397
*

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: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
controlCornerRadius,
2222
density,
2323
designUnit,
24+
elementScale,
2425
errorFillActive,
2526
errorFillFocus,
2627
errorFillHover,
@@ -75,7 +76,11 @@ 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+
max(
81+
1px,
82+
calc((10 + (${designUnit} * 2 * (${density} + ${elementScale})))) * 1px
83+
);
7984
white-space: nowrap;
8085
outline: none;
8186
text-decoration: none;
@@ -101,12 +106,25 @@ export const BaseButtonStyles = css`
101106
box-shadow: inset 0px 0px 2px 2px ${neutralFillStrongActive};
102107
}
103108
104-
:host([minimal]) {
105-
--density: -4;
109+
:host([minimal]),
110+
:host([scale='xsmall']) {
111+
--element-scale: -4;
106112
}
107113
108-
:host([minimal]) .control {
109-
padding: 1px;
114+
:host([scale='small']) {
115+
--element-scale: -2;
116+
}
117+
118+
:host([scale='medium']) {
119+
--element-scale: 1;
120+
}
121+
122+
:host([scale='large']) {
123+
--element-scale: 2;
124+
}
125+
126+
:host([scale='xlarge']) {
127+
--element-scale: 4;
110128
}
111129
112130
/* prettier-ignore */

packages/components/src/styles/size.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
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';
712

813
/**
914
* A formula to retrieve the control height.
1015
* Use this as the value of any CSS property that
1116
* accepts a pixel size.
1217
*/
13-
export const heightNumber = cssPartial`(${baseHeightMultiplier} + ${density}) * ${designUnit}`;
18+
export const heightNumber = cssPartial`(${baseHeightMultiplier} + ${density} + ${elementScale}) * ${designUnit}`;

packages/react-components/lib/Button.d.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Button as ButtonElement } from '@jupyter/web-components';
1+
import { Button as ButtonElement, type ButtonScale } from '@jupyter/web-components';
22

33
export type { ButtonElement };
44

@@ -9,9 +9,16 @@ export interface ButtonProps
99
*/
1010
ref?: React.Ref<ButtonElement>;
1111

12-
/** Whether the button has a compact layout or not. */
12+
/** Whether the button has a compact layout or not.
13+
* @deprecated Use {@link scale} equals to `xsmall` instead.
14+
*/
1315
minimal?: boolean;
1416

17+
/**
18+
* Scale the element compared to the theme size.
19+
*/
20+
scale?: ButtonScale;
21+
1522
/** The appearance the button should have. */
1623
appearance?: ButtonElement['appearance'];
1724

packages/react-components/lib/Combobox.d.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Combobox as ComboboxElement } from '@jupyter/web-components';
1+
import { Combobox as ComboboxElement, type ComboboxScale } from '@jupyter/web-components';
22

33
export type { ComboboxElement };
44

@@ -12,9 +12,16 @@ export interface ComboboxProps
1212
/** Whether the combobox has a compact layout or not. */
1313
autowidth?: boolean;
1414

15-
/** Whether the combobox has a compact layout or not. */
15+
/** Whether the combobox has a compact layout or not.
16+
* @deprecated Use {@link scale} equals to `xsmall` instead.
17+
*/
1618
minimal?: boolean;
1719

20+
/**
21+
* Scale the element compared to the theme size.
22+
*/
23+
scale?: ComboboxScale;
24+
1825
/** The open attribute. */
1926
open?: boolean;
2027

packages/react-components/lib/Select.d.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Select as SelectElement } from '@jupyter/web-components';
1+
import { Select as SelectElement, type SelectScale } from '@jupyter/web-components';
22

33
export type { SelectElement };
44

@@ -15,9 +15,16 @@ export interface SelectProps
1515
/** Whether the select has a compact layout or not. */
1616
autowidth?: boolean;
1717

18-
/** Whether the select has a compact layout or not. */
18+
/** Whether the select has a compact layout or not.
19+
* @deprecated Use {@link scale} equals to `xsmall` instead.
20+
*/
1921
minimal?: boolean;
2022

23+
/**
24+
* Scale the element compared to the theme size.
25+
*/
26+
scale?: SelectScale;
27+
2128
/** The open attribute. */
2229
open?: boolean;
2330

0 commit comments

Comments
 (0)