Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Component: Tooltips #164

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
97645c4
tooltip start
driskull Oct 3, 2019
0aa2c43
tooltip progress
driskull Oct 3, 2019
f391f0b
progress
driskull Oct 3, 2019
d52c99e
arrow setup
driskull Oct 3, 2019
9b62f48
tests
driskull Oct 3, 2019
96948b8
cleanup
driskull Oct 3, 2019
6aef4f8
ready for styling
driskull Oct 3, 2019
28ef028
update demo
driskull Oct 3, 2019
17c2111
review fix
driskull Oct 4, 2019
ac750bc
use slot for image
driskull Oct 4, 2019
746d71c
update readme/test
driskull Oct 4, 2019
3b9b89c
add slot doc
driskull Oct 4, 2019
591e72c
image demo
driskull Oct 4, 2019
aa665bb
some styling updates
Oct 4, 2019
5e6d9e7
Added dark theme
Oct 4, 2019
8f746ec
updated background var
Oct 4, 2019
688638d
presentation cleanup
Oct 4, 2019
28ef8ea
fit kitty.
driskull Oct 4, 2019
53df32d
get arrow showing
driskull Oct 4, 2019
7066381
arrow variable
driskull Oct 4, 2019
07785ae
fix BG var
driskull Oct 4, 2019
44325a6
margin for pointer.
driskull Oct 4, 2019
999bd34
placement options
driskull Oct 4, 2019
ad88e74
fix test.
driskull Oct 4, 2019
0d539f6
popover arrow styles.
driskull Oct 5, 2019
abe8004
DRY css
driskull Oct 7, 2019
0e1b1dd
Update readme.md
driskull Oct 7, 2019
dd46d07
2px border radius
driskull Oct 7, 2019
c794d03
simplify tooltip to just hover
driskull Oct 9, 2019
c2b30db
Merge branch 'master' into dris0000/calcite-tooltip
driskull Oct 9, 2019
eb6b2a4
remove module
driskull Oct 9, 2019
5d22e3d
Updates css, removes stale classes
macandcheese Oct 10, 2019
20544b7
Removed unused CSS variable
Oct 10, 2019
1bd92b6
Removed hover and pressed states
Oct 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/calcite-popover/calcite-popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class CalcitePopover {
}

/**
* Determines where the element will be positioned.
* Determines where the component will be positioned relative to the referenceElement.
* horizontal: Positioned to the left or right of the referenceElement.
* vertical: Positioned above or below the referenceElement.
*/
Expand Down
14 changes: 7 additions & 7 deletions src/components/calcite-popover/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

## Properties

| Property | Attribute | Description | Type | Default |
| ------------------ | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------- | -------------- |
| `open` | `open` | Display and position the component. | `boolean` | `false` |
| `placement` | `placement` | Determines where the element will be positioned. horizontal: Positioned to the left or right of the referenceElement. vertical: Positioned above or below the referenceElement. | `"horizontal" \| "vertical"` | `"horizontal"` |
| `referenceElement` | `reference-element` | Reference HTMLElement used to position this component according to the placement property. | `HTMLElement \| string` | `undefined` |
| `xOffset` | `x-offset` | Offset the position of the popover in the horizontal direction. | `number` | `0` |
| `yOffset` | `y-offset` | Offset the position of the popover in the vertical direction. | `number` | `0` |
| Property | Attribute | Description | Type | Default |
| ------------------ | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------- | -------------- |
| `open` | `open` | Display and position the component. | `boolean` | `false` |
| `placement` | `placement` | Determines where the component will be positioned relative to the referenceElement. horizontal: Positioned to the left or right of the referenceElement. vertical: Positioned above or below the referenceElement. | `"horizontal" \| "vertical"` | `"horizontal"` |
| `referenceElement` | `reference-element` | Reference HTMLElement used to position this component according to the placement property. | `HTMLElement \| string` | `undefined` |
| `xOffset` | `x-offset` | Offset the position of the popover in the horizontal direction. | `number` | `0` |
| `yOffset` | `y-offset` | Offset the position of the popover in the vertical direction. | `number` | `0` |


## Methods
Expand Down
195 changes: 195 additions & 0 deletions src/components/calcite-tooltip/calcite-tooltip.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
import { newE2EPage } from "@stencil/core/testing";

import { defaults, hidden, renders } from "../../tests/commonTests";

import { CSS } from "./resources";

describe("calcite-tooltip", () => {
it("renders", async () => renders("calcite-tooltip"));

it("honors hidden attribute", async () => hidden("calcite-tooltip"));

it("has property defaults", async () =>
defaults("calcite-tooltip", [
{
propertyName: "image",
defaultValue: undefined
},
{
propertyName: "imageLabel",
defaultValue: undefined
},
{
propertyName: "interaction",
defaultValue: "hover"
},
{
propertyName: "open",
defaultValue: false
},
{
propertyName: "placement",
defaultValue: "auto"
},
{
propertyName: "referenceElement",
defaultValue: undefined
},
{
propertyName: "text",
defaultValue: undefined
},
{
propertyName: "theme",
defaultValue: "light"
}
]));

it("popover positions when referenceElement is set", async () => {
const page = await newE2EPage();

await page.setContent(
`<calcite-tooltip open></calcite-tooltip><div>referenceElement</div>`
);

const element = await page.find("calcite-tooltip");

await page.$eval("calcite-tooltip", (elm: any) => {
const referenceElement = document.createElement("div");
document.body.appendChild(referenceElement);
elm.referenceElement = referenceElement;
});

await page.waitForChanges();

const computedStyle = await element.getComputedStyle();

expect(computedStyle.transform).not.toBe("none");
});

it("open popover should be visible", async () => {
const page = await newE2EPage();

await page.setContent(
`<calcite-tooltip></calcite-tooltip><div>referenceElement</div>`
);

const element = await page.find("calcite-tooltip");

await page.$eval("calcite-tooltip", (elm: any) => {
const referenceElement = document.createElement("div");
document.body.appendChild(referenceElement);
elm.referenceElement = referenceElement;
});

await page.waitForChanges();

const container = await page.find(`calcite-tooltip >>> .${CSS.container}`);

expect(await container.isVisible()).toBe(false);

element.setProperty("open", true);

await page.waitForChanges();

expect(await container.isVisible()).toBe(true);
});

it("should accept referenceElement as string id", async () => {
const page = await newE2EPage();

await page.setContent(
`<calcite-tooltip reference-element="ref" open>content</calcite-tooltip><div id="ref">referenceElement</div>`
);

await page.waitForChanges();

const container = await page.find(`calcite-tooltip >>> .${CSS.container}`);

await page.waitForChanges();

expect(await container.isVisible()).toBe(true);

const element = await page.find("calcite-tooltip");

const computedStyle = await element.getComputedStyle();

expect(computedStyle.transform).not.toBe("none");
});

it("should honor hover interaction", async () => {
const page = await newE2EPage();

await page.setContent(
`<calcite-tooltip reference-element="ref" interaction="hover">content</calcite-tooltip><div id="ref">referenceElement</div>`
);

await page.waitForChanges();

const container = await page.find(`calcite-tooltip >>> .${CSS.container}`);

expect(await container.isVisible()).toBe(false);

const ref = await page.find("#ref");

await ref.hover();

expect(await container.isVisible()).toBe(true);
});

it("should honor click interaction", async () => {
const page = await newE2EPage();

await page.setContent(
`<calcite-tooltip reference-element="ref" interaction="click">content</calcite-tooltip><div id="ref">referenceElement</div>`
);

await page.waitForChanges();

const container = await page.find(`calcite-tooltip >>> .${CSS.container}`);

expect(await container.isVisible()).toBe(false);

const ref = await page.find("#ref");

await ref.click();

expect(await container.isVisible()).toBe(true);

await ref.click();

expect(await container.isVisible()).toBe(false);
});

it("should honor image & imageLabel", async () => {
const page = await newE2EPage();

await page.setContent(
`<calcite-tooltip reference-element="ref" image="http://placekitten.com/200/300" image-label="hi" open>content</calcite-tooltip><div id="ref">referenceElement</div>`
);

await page.waitForChanges();

const image = await page.find(`calcite-tooltip >>> .${CSS.image}`);

expect(await image.isVisible()).toBe(true);

expect(image.getAttribute("alt")).toBe("hi");
});

it("should honor text", async () => {
const page = await newE2EPage();

await page.setContent(
`<calcite-tooltip reference-element="ref" text="hi" open>content</calcite-tooltip><div id="ref">referenceElement</div>`
);

await page.waitForChanges();

const content = await page.find(`calcite-tooltip >>> .${CSS.content}`);

expect(await content.isVisible()).toBe(true);

expect(content.textContent).toBe("hi");
});
});
96 changes: 96 additions & 0 deletions src/components/calcite-tooltip/calcite-tooltip.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
:host {
display: block;
position: absolute;
z-index: 999;
top: -999999px;
left: -999999px;
}

.container {
visibility: hidden;
background-color: #fff;
padding: 5px 10px;
box-shadow: $shadow-2;
border-radius: 2px;
max-width: 200px;
max-height: 200px;
display: flex;
flex-direction: column;
}

.container--open {
visibility: visible;
}

.image {
flex: 1;
overflow: hidden;
}

.content {
position: relative;
flex: 1;
}

.close-button {
Copy link
Contributor

@macandcheese macandcheese Oct 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use 2px border-radius where this is adjacent to the container top corner / bottom corner (depending on type)

position: absolute;
top: 0;
z-index: 1;
right: 0;
background: transparent;
padding: 5px;
border: none;
display: block;
}

.arrow {
display: block;
}

:host([x-placement="top"]) .arrow {
display: block;
}

:host([x-placement="top-end"]) .arrow {
display: block;
}

:host([x-placement="right"]) .arrow {
display: block;
}

:host([x-placement="right-start"]) .arrow {
display: block;
}

:host([x-placement="right-end"]) .arrow {
display: block;
}

:host([x-placement="bottom-end"]) .arrow {
display: block;
}

:host([x-placement="right-end"]) .arrow {
display: block;
}

:host([x-placement="bottom"]) .arrow {
display: block;
}

:host([x-placement="bottom-start"]) .arrow {
display: block;
}

:host([x-placement="left-end"]) .arrow {
display: block;
}

:host([x-placement="left"]) .arrow {
display: block;
}

:host([x-placement="left-start"]) .arrow {
display: block;
}
Loading