Skip to content

Commit

Permalink
feat: add tooltip and anchor region web component (#16399)
Browse files Browse the repository at this point in the history
* add tail on top and bottom tooltip

* update fixture, storybook and styles for tooltip and anchor region

* Change files

* fixed import order in stories

* export anchor region and removed TODO comment

* update anchor region example

* updated the fixture base file to use fluent components

* combined selector creating the the bubble tail

* generate and add api report

* added elevation

* update background and color to use neutral contrast recipe

* update FAST to Fluent and bump fast-foundation version to 1.16.1

* revert version and opt into semver on fast-foundation
  • Loading branch information
khamudom authored Mar 18, 2021
1 parent 2738fd6 commit a7f14f4
Show file tree
Hide file tree
Showing 14 changed files with 1,562 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "minor",
"comment": "update fixture, storybook and styles for tooltip and anchor region",
"packageName": "@fluentui/web-components",
"email": "khamu@microsoft.com",
"dependentChangeType": "patch",
"date": "2021-01-06T23:15:48.875Z"
}
16 changes: 16 additions & 0 deletions packages/web-components/docs/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { Accordion } from '@microsoft/fast-foundation';
import { AccordionItem } from '@microsoft/fast-foundation';
import { Anchor } from '@microsoft/fast-foundation';
import { AnchoredRegion } from '@microsoft/fast-foundation';
import { Badge } from '@microsoft/fast-foundation';
import { BaseProgress } from '@microsoft/fast-foundation';
import { Breadcrumb } from '@microsoft/fast-foundation';
Expand Down Expand Up @@ -42,6 +43,7 @@ import { TabPanel } from '@microsoft/fast-foundation';
import { Tabs } from '@microsoft/fast-foundation';
import { TextArea } from '@microsoft/fast-foundation';
import { TextField } from '@microsoft/fast-foundation';
import { Tooltip } from '@microsoft/fast-foundation';
import { TreeItem } from '@microsoft/fast-foundation';
import { TreeView } from '@microsoft/fast-foundation';

Expand Down Expand Up @@ -224,6 +226,9 @@ export const ambientShadow = "0 0 calc((var(--elevation) * 0.225px) + 2px) rgba(
// @public
export type AnchorAppearance = ButtonAppearance | 'hypertext';

// @public
export const AnchoredRegionStyles: import("@microsoft/fast-element").ElementStyles;

// @public
export const AnchorStyles: import("@microsoft/fast-element").ElementStyles;

Expand Down Expand Up @@ -439,6 +444,10 @@ export class FluentAnchor extends Anchor {
defaultSlottedContentChanged(): void;
}

// @beta
export class FluentAnchoredRegion extends AnchoredRegion {
}

// @public
export class FluentBadge extends Badge {
// (undocumented)
Expand Down Expand Up @@ -762,6 +771,10 @@ export class FluentTextField extends TextField {
connectedCallback(): void;
}

// @public
export class FluentTooltip extends Tooltip {
}

// @public
export class FluentTreeItem extends TreeItem {
}
Expand Down Expand Up @@ -1300,6 +1313,9 @@ export type TextFieldAppearance = 'filled' | 'outline';
// @public
export const TextFieldStyles: import("@microsoft/fast-element").ElementStyles;

// @public
export const TooltipStyles: import("@microsoft/fast-element").ElementStyles;

// @public
export const TreeItemStyles: import("@microsoft/fast-element").ElementStyles;

Expand Down
2 changes: 1 addition & 1 deletion packages/web-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"dependencies": {
"@microsoft/fast-colors": "^5.1.0",
"@microsoft/fast-element": "^1.0.0",
"@microsoft/fast-foundation": "1.16.0",
"@microsoft/fast-foundation": "^1.16.0",
"lodash-es": "^4.17.20",
"tslib": "^1.13.0"
}
Expand Down
162 changes: 162 additions & 0 deletions packages/web-components/src/anchored-region/anchored-region.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import { STORY_RENDERED } from '@storybook/core-events';
import addons from '@storybook/addons';
import { Direction, RtlScrollConverter } from '@microsoft/fast-web-utilities';
import { FluentDesignSystemProvider } from '../design-system-provider';
import { FluentAnchoredRegion } from '../anchored-region';
import AnchoreRegionTemplate from './fixtures/base.html';

// Prevent tree-shaking
FluentAnchoredRegion;
FluentDesignSystemProvider;

let scalingViewportPreviousXValue: number = 250;
let scalingViewportPreviousYValue: number = 250;

addons.getChannel().addListener(STORY_RENDERED, (name: string) => {
if (name.toLowerCase().startsWith('anchored-region')) {
scrollViewports();
setButtonActions();

const scalingViewportUpdate: HTMLElement | null = document.getElementById('viewport-scaling-update');
if (scalingViewportUpdate !== null) {
scalingViewportUpdate.addEventListener('scroll', handleScrollViaUpdate);
}

const scalingViewportOffset: HTMLElement | null = document.getElementById('viewport-scaling-offset');
if (scalingViewportOffset !== null) {
scalingViewportOffset.addEventListener('scroll', handleScrollViaOffset);
}
}
});

function scrollViewports(): void {
document.querySelectorAll("div[id^='viewport']").forEach(el => {
if (el instanceof HTMLDivElement) {
el.scrollTop = 280;
RtlScrollConverter.setScrollLeft(
el,
el.dir === Direction.rtl ? -250 : 250,
el.dir === Direction.rtl ? Direction.rtl : Direction.ltr,
);
}
});
}

function handleScrollViaUpdate(ev: Event): void {
if (ev.target instanceof HTMLElement) {
const scalingRegionUpdate: HTMLElement | null = document.getElementById('region-scaling-update');
if (scalingRegionUpdate instanceof FluentAnchoredRegion) {
(scalingRegionUpdate as any).update();
}
}
}

function handleScrollViaOffset(ev: Event): void {
if (ev.target instanceof HTMLElement) {
const scroller: HTMLElement = ev.target as HTMLElement;

const scalingRegionOffset: HTMLElement | null = document.getElementById('region-scaling-offset');
if (scalingRegionOffset instanceof FluentAnchoredRegion) {
(scalingRegionOffset as any).updateAnchorOffset(
scalingViewportPreviousXValue - scroller.scrollLeft,
scalingViewportPreviousYValue - scroller.scrollTop,
);
}

scalingViewportPreviousXValue = scroller.scrollLeft;
scalingViewportPreviousYValue = scroller.scrollTop;
}
}

function setButtonActions(): void {
document.querySelectorAll('button').forEach(el => {
if (el instanceof HTMLButtonElement) {
switch (el.id) {
case 'toggle-anchor-anchor1':
el.onclick = event => {
const region: HTMLElement | null = document.getElementById('toggle-anchor-region');
if (region === null) {
return;
}
region.setAttribute('anchor', 'toggle-anchor-anchor1');
};
break;

case 'toggle-anchor-anchor2':
el.onclick = event => {
const region: HTMLElement | null = document.getElementById('toggle-anchor-region');
if (region === null) {
return;
}
region.setAttribute('anchor', 'toggle-anchor-anchor2');
};
break;

case 'toggle-positions-horizontal':
el.onclick = event => {
const region: HTMLElement | null = document.getElementById('toggle-positions-region');
if (region === null) {
return;
}
const currentPosition: string | null = region.getAttribute('horizontal-default-position');
if (currentPosition === 'left') {
region.setAttribute('horizontal-default-position', 'right');
} else {
region.setAttribute('horizontal-default-position', 'left');
}
};
break;

case 'toggle-positions-vertical':
el.onclick = event => {
const region: HTMLElement | null = document.getElementById('toggle-positions-region');
if (region === null) {
return;
}
const currentPosition: string | null = region.getAttribute('vertical-default-position');
if (currentPosition === 'top') {
region.setAttribute('vertical-default-position', 'bottom');
} else {
region.setAttribute('vertical-default-position', 'top');
}
};
break;

case 'toggle-positions-small':
el.onclick = event => {
const smallContent: HTMLElement | null = document.getElementById('toggle-positions-small');
const largeContent: HTMLElement | null = document.getElementById('toggle-positions-large');
if (smallContent === null || largeContent === null) {
return;
}

smallContent.hidden = false;
largeContent.hidden = true;
};
break;

case 'toggle-positions-large':
el.onclick = event => {
const smallContent: HTMLElement | null = document.getElementById('toggle-positions-small');
const largeContent: HTMLElement | null = document.getElementById('toggle-positions-large');
if (smallContent === null || largeContent === null) {
return;
}

smallContent.hidden = true;
largeContent.hidden = false;
};
break;

default:
el.onclick;
}
}
});
}

export default {
title: 'Anchored region',
};

export const base = () => AnchoreRegionTemplate;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { css } from '@microsoft/fast-element';

export const AnchoredRegionStyles = css`
:host {
contain: layout;
display: block;
}
`;
Loading

0 comments on commit a7f14f4

Please sign in to comment.