Skip to content

Commit

Permalink
fix(web-components): add expand collapse hover state to tree view (#1…
Browse files Browse the repository at this point in the history
…6375)

* fix: add hover state for expand collapse button in tree-item

* Change files
  • Loading branch information
eljefe223 authored Jan 14, 2021
1 parent 326fa5b commit c641f03
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "patch",
"comment": "fix: add hover state for expand collapse button in tree-item",
"packageName": "@fluentui/web-components",
"email": "jes@microsoft.com",
"dependentChangeType": "patch",
"date": "2021-01-05T20:23:56.895Z"
}
72 changes: 57 additions & 15 deletions packages/web-components/src/tree-item/tree-item.styles.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { css } from '@microsoft/fast-element';
import {
cssCustomPropertyBehaviorFactory,
DirectionalStyleSheetBehavior,
disabledCursor,
display,
focusVisible,
forcedColorsStylesheetBehavior,
} from '@microsoft/fast-foundation';
import { SystemColors } from '@microsoft/fast-web-utilities';
import { neutralFillStealthHover, neutralFillStealthSelected } from '@microsoft/fast-components-styles-msft';
import {
accentForegroundRestBehavior,
heightNumber,
Expand All @@ -20,6 +22,8 @@ import {
neutralForegroundRestBehavior,
} from '../styles/index';

import { FluentDesignSystemProvider } from '../design-system-provider/index';

const ltr = css`
.expand-collapse-glyph {
transform: rotate(-45deg);
Expand Down Expand Up @@ -50,6 +54,21 @@ const rtl = css`
}
`;

export const expandCollapseButtonSize =
'((var(--base-height-multiplier) / 2) * var(--design-unit)) + ((var(--design-unit) * var(--density)) / 2)';

const expandCollapseHoverBehavior = cssCustomPropertyBehaviorFactory(
'neutral-stealth-hover-over-hover',
x => neutralFillStealthHover(neutralFillStealthHover)(x),
FluentDesignSystemProvider.findProvider,
);

const selectedExpandCollapseHoverBehavior = cssCustomPropertyBehaviorFactory(
'neutral-stealth-hover-over-selected',
x => neutralFillStealthHover(neutralFillStealthSelected)(x),
FluentDesignSystemProvider.findProvider,
);

export const TreeItemStyles = css`
${display('block')} :host {
contain: content;
Expand Down Expand Up @@ -82,7 +101,7 @@ export const TreeItemStyles = css`
position: relative;
box-sizing: border-box;
border: transparent calc(var(--outline-width) * 1px) solid;
height: calc(${heightNumber} * 1px);
height: calc((${heightNumber} + 1) * 1px);
}
.positioning-region::before {
Expand All @@ -101,12 +120,12 @@ export const TreeItemStyles = css`
}
.content-region {
display: flex;
display: inline-flex;
align-items: center;
white-space: nowrap;
width: 100%;
height: calc(${heightNumber} * 1px);
margin-inline-start: calc(var(--design-unit) * 2px + 2px);
margin-inline-start: calc(var(--design-unit) * 2px + 8px);
font-size: var(--type-ramp-base-font-size);
line-height: var(--type-ramp-base-line-height);
font-weight: 400;
Expand All @@ -127,13 +146,14 @@ export const TreeItemStyles = css`
${
/* Width and Height should be based off calc(glyph-size-number + (design-unit * 4) * 1px) -
update when density story is figured out */ ''
} width: var(--expand-collapse-button-size);
height: var(--expand-collapse-button-size);
} width: calc((${expandCollapseButtonSize} + (var(--design-unit) * 2)) * 1px);
height: calc((${expandCollapseButtonSize} + (var(--design-unit) * 2)) * 1px);
padding: 0;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
margin: 0 6px;
}
.expand-collapse-glyph {
Expand Down Expand Up @@ -182,10 +202,27 @@ export const TreeItemStyles = css`
cursor: ${disabledCursor};
}
:host(.nested) .content-region {
position: relative;
margin-inline-start: var(--expand-collapse-button-size);
}
:host(.nested) .expand-collapse-button {
position: absolute;
}
:host(.nested) .expand-collapse-button:hover {
background: ${expandCollapseHoverBehavior.var};
}
:host([selected]) .positioning-region {
background: ${neutralFillStealthSelectedBehavior.var};
}
:host([selected]) .expand-collapse-button:hover {
background: ${selectedExpandCollapseHoverBehavior.var};
}
:host([selected])::after {
content: "";
display: block;
Expand All @@ -200,22 +237,13 @@ export const TreeItemStyles = css`
border-radius: calc(var(--corner-radius) * 1px);
}
:host(.nested) .content-region {
position: relative;
margin-inline-start: var(--expand-collapse-button-size);
}
:host(.nested) .expand-collapse-button {
position: absolute;
left: var(--expand-collapse-button-nested-width, calc(${heightNumber} * -1px));
}
::slotted(fluent-tree-item) {
--tree-item-nested-width: 1em;
--expand-collapse-button-nested-width: calc(${heightNumber} * -1px);
}
`.withBehaviors(
accentForegroundRestBehavior,
expandCollapseHoverBehavior,
neutralFillStealthSelectedBehavior,
neutralFillStealthActiveBehavior,
neutralFillStealthHoverBehavior,
Expand All @@ -224,13 +252,15 @@ export const TreeItemStyles = css`
neutralFocusInnerAccentBehavior,
neutralForegroundActiveBehavior,
neutralForegroundRestBehavior,
selectedExpandCollapseHoverBehavior,
new DirectionalStyleSheetBehavior(ltr, rtl),
forcedColorsStylesheetBehavior(
css`
:host {
forced-color-adjust: none;
border-color: transparent;
background: ${SystemColors.Field};
color: ${SystemColors.FieldText};
}
:host .content-region {
color: ${SystemColors.FieldText};
Expand Down Expand Up @@ -262,6 +292,7 @@ export const TreeItemStyles = css`
:host(:${focusVisible}) .positioning-region {
border-color: ${SystemColors.FieldText};
box-shadow: 0 0 0 2px inset ${SystemColors.Field};
color: ${SystemColors.FieldText};
}
:host([disabled]) .content-region,
:host([disabled]) .positioning-region:hover .content-region {
Expand All @@ -279,6 +310,17 @@ export const TreeItemStyles = css`
:host([disabled]) .positioning-region:hover {
background: ${SystemColors.Field};
}
.expand-collapse-glyph,
.start,
.end {
fill: ${SystemColors.FieldText};
}
:host(.nested) .expand-collapse-button:hover {
background: ${SystemColors.Field};
}
:host(.nested) .expand-collapse-button:hover .expand-collapse-glyph {
fill: ${SystemColors.FieldText};
}
`,
),
);

0 comments on commit c641f03

Please sign in to comment.