Skip to content

Commit

Permalink
Make expand glyph size changing with density (#104)
Browse files Browse the repository at this point in the history
Co-authored-by: Frédéric Collonval <[email protected]>
  • Loading branch information
fcollonval and fcollonval authored Jun 16, 2024
1 parent 23ffa2e commit b4fdf7a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
23 changes: 21 additions & 2 deletions packages/components/.storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,36 @@ const parameters = {

const globalTypes = {
accent: {
name: 'Accent',
name: 'Accent color',
description: 'Theme accent color for components',
defaultValue: '#006CBE',
toolbar: {
title: 'Accent color',
icon: 'paintbrush',
// Array of plain string values or MenuItem shape (see below)
items: [
{ value: '#006CBE', right: '🔵', title: 'blue' },
{ value: '#DA1A5F', title: 'pink' },
{ value: '#f2c812', title: 'yellow' }
]
],
dynamicTitle: true
}
},
density: {
name: 'Density',
description: 'UI element density',
defaultValue: 0,
toolbar: {
title: 'Density',
icon: 'grow',
items: [
{ value: -4, title: 'xsmall' },
{ value: -2, title: 'small' },
{ value: 0, title: 'medium' },
{ value: 2, title: 'large' },
{ value: 4, title: 'xlarge' }
],
dynamicTitle: true
}
}
};
Expand Down
14 changes: 11 additions & 3 deletions packages/components/src/menu-item/menu-item.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
accentFillRest,
bodyFont,
controlCornerRadius,
density,
designUnit,
disabledOpacity,
focusStrokeWidth,
Expand All @@ -30,7 +31,8 @@ import {
neutralForegroundRest,
strokeWidth,
typeRampBaseFontSize,
typeRampBaseLineHeight
typeRampBaseLineHeight,
typeRampPlus1FontSize
} from '../design-tokens.js';
import {
DirectionalStyleSheetBehavior,
Expand Down Expand Up @@ -148,8 +150,8 @@ export const menuItemStyles: FoundationElementTemplate<
.expand-collapse-glyph {
/* TODO: adaptive typography https://github.com/microsoft/fast/issues/2432 */
width: 16px;
height: 16px;
width: calc((16 + ${density}) * 1px);
height: calc((16 + ${density}) * 1px);
fill: currentcolor;
}
Expand All @@ -170,6 +172,12 @@ export const menuItemStyles: FoundationElementTemplate<
/* TODO: adaptive typography https://github.com/microsoft/fast/issues/2432 */
width: 16px;
height: 16px;
/* Something like that would do if the typography is adaptive
font-size: inherit;
width: ${typeRampPlus1FontSize};
height: ${typeRampPlus1FontSize};
*/
}
:host(:hover) .start,
Expand Down
13 changes: 10 additions & 3 deletions packages/components/src/tree-item/tree-item.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import {
neutralForegroundRest,
strokeWidth,
typeRampBaseFontSize,
typeRampBaseLineHeight
typeRampBaseLineHeight,
typeRampPlus1FontSize
} from '../design-tokens.js';
import {
DirectionalStyleSheetBehavior,
Expand Down Expand Up @@ -211,8 +212,8 @@ export const treeItemStyles: FoundationElementTemplate<
.expand-collapse-glyph {
/* TODO: adaptive typography https://github.com/microsoft/fast/issues/2432 */
width: 16px;
height: 16px;
width: calc((16 + ${density}) * 1px);
height: calc((16 + ${density}) * 1px);
transition: transform 0.1s linear;
pointer-events: none;
Expand All @@ -229,6 +230,12 @@ export const treeItemStyles: FoundationElementTemplate<
/* TODO: adaptive typography https://github.com/microsoft/fast/issues/2432 */
width: 16px;
height: 16px;
/* Something like that would do if the typography is adaptive
font-size: inherit;
width: ${typeRampPlus1FontSize};
height: ${typeRampPlus1FontSize};
*/
}
.start {
Expand Down
3 changes: 3 additions & 0 deletions packages/components/src/utilities/storybook/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ export function withTheme(story: any, context: StoryContext): HTMLElement {
? StandardLuminance.DarkMode
: StandardLuminance.LightMode;

const density = context.globals.density;
theme.density = density;

const children = story();
if (typeof children === 'string') {
theme.insertAdjacentHTML('afterbegin', children);
Expand Down

0 comments on commit b4fdf7a

Please sign in to comment.