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

refactor(ui5-link): clean up styles #659

Merged
merged 4 commits into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 packages/main/src/Link.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<a
class="{{classes.main}}"
class="ui5-link-root"
role="link"
href="{{parsedRef}}"
target="{{target}}"
Expand Down
13 changes: 0 additions & 13 deletions packages/main/src/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,6 @@ class Link extends UI5Element {
return this.disabled ? "true" : undefined;
}

get classes() {
return {
main: {
sapMLnk: true,
sapMLnkSubtle: this.design === LinkDesign.Subtle,
sapMLnkEmphasized: this.design === LinkDesign.Emphasized,
sapMLnkWrapping: this.wrap,
sapMLnkDsbl: this.disabled,
sapMLnkMaxWidth: true,
},
};
}

get parsedRef() {
return this.href.length > 0 ? this.href : undefined;
}
Expand Down
124 changes: 85 additions & 39 deletions packages/main/src/themes/Link.css
Original file line number Diff line number Diff line change
@@ -1,79 +1,73 @@
:host(ui5-link:not([hidden])) {
:host(:not([hidden])) {
display: inline-flex;
max-width: 100%;
}

:host([disabled]) {
pointer-events: none;
}

ui5-link[disabled] {
pointer-events: none;
}

ui5-link {
display: inline-block;
:host {
max-width: 100%;
}

.sapMLnk {
color: var(--sapUiLink);
text-decoration: none;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
word-wrap: normal;
font-family: var(--sapUiFontFamily);
font-size: var(--sapMFontMediumSize);
cursor: pointer;
display: inline-block;
justify-content: center;
align-items: center;
position: relative;
outline: none;
}

.sapMLnk:not(.sapMLnkDsbl):hover,
.sapMLnk.sapMLnkSubtle:not(.sapMLnkDsbl):hover {
text-decoration: underline;
color: var(--sapUiLinkHover);
:host([disabled]) {
pointer-events: none;
}

.sapMLnk:visited {
color: var(--sapUiLinkVisited);
:host([design="Subtle"]):not([disabled]) .ui5-link-root:hover,
:host([design="Subtle"]):not([disabled]) .ui5-link-root:hover {
text-decoration: underline;
color: var(--sapUiLinkHover);
}

.sapMLnk.sapMLnkDsbl {
:host([disabled]) .ui5-link-root {
text-shadow: none;
outline: none;
cursor: default;
pointer-events: none;
opacity: var(--_ui5_link_opacity);
}

.sapMLnk.sapMLnkEmphasized {
:host([design="Emphasized"]) .ui5-link-root {
font-weight: bold;
}

.sapMLnk.sapMLnkSubtle,
.sapMLnk.sapMLnkSubtle:visited {
:host([design="Subtle"]) .ui5-link-root,
:host([design="Subtle"]) .ui5-link-root:visited {
color: var(--_ui5_link_subtle_color);
}

.sapMLnk.sapMLnkSubtle:focus {
:host([design="Subtle"]) .ui5-link-root:focus {
color: var(--sapUiLink);
}

.sapMLnk.sapMLnkWrapping {
:host([wrap]) .ui5-link-root {
white-space: normal;
word-wrap: break-word;
}

.sapMLnk:focus {
.ui5-link-root {
display: inline-block;
position: relative;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
word-wrap: normal;
text-decoration: none;
outline: none;
}

.ui5-link-root,
.ui5-link-root:visited,
.ui5-link-root:active {
color: currentColor;
}

.ui5-link-root:focus {
text-decoration: underline;
}

.sapMLnk:focus::after {
.ui5-link-root:focus::after {
content: "";
width: var(--_ui5_link_outline_element_size);
height: var(--_ui5_link_outline_element_size);
Expand All @@ -83,3 +77,55 @@ ui5-link {
top: 0;
outline: none;
}

/*
* IE pair of styles,
* to be removed later on
*/
ui5-link:not([hidden]) {
display: inline-flex;
}

ui5-link {
max-width: 100%;
color: var(--sapUiLink);
font-family: var(--sapUiFontFamily);
font-size: var(--sapMFontMediumSize);
cursor: pointer;
}

ui5-link[disabled] {
pointer-events: none;
}

ui5-link[design="Subtle"]:not([disabled]) .ui5-link-root:hover,
ui5-link[design="Subtle"]:not([disabled]) .ui5-link-root:hover {
text-decoration: underline;
color: var(--sapUiLinkHover);
}

ui5-link[disabled] .ui5-link-root {
text-shadow: none;
outline: none;
cursor: default;
pointer-events: none;
opacity: var(--_ui5_link_opacity);
}

ui5-link[design="Emphasized"] .ui5-link-root {
font-weight: bold;
}

ui5-link[design="Subtle"] .ui5-link-root,
ui5-link[design="Subtle"] .ui5-link-root:visited {
color: var(--_ui5_link_subtle_color);
}

ui5-link[design="Subtle"] .ui5-link-root:focus {
color: var(--sapUiLink);
}

ui5-link[wrap] .ui5-link-root {
white-space: normal;
word-wrap: break-word;
}
2 changes: 2 additions & 0 deletions packages/main/test/sap/ui/webcomponents/main/pages/Link.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">

<script>delete Document.prototype.adoptedStyleSheets;</script>

<script data-ui5-config type="application/json">
{
"language": "EN"
Expand Down
50 changes: 6 additions & 44 deletions packages/main/test/sap/ui/webcomponents/main/qunit/Link.qunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ TestHelper.ready(function() {
QUnit.module("Rendering", function (hooks) {
hooks.before(function() {
this.getLinkRoot = function() {
return this.link.shadowRoot.querySelector(".sapMLnk");
return this.link.shadowRoot.querySelector(".ui5-link-root");
};
});
hooks.beforeEach(function () {
Expand All @@ -30,14 +30,9 @@ TestHelper.ready(function() {
});

QUnit.test("Default settings", function (assert) {
assert.expect(6);

var link = this.getLinkRoot(),
classes = ["sapMLnkEmphasized", "sapMLnkSubtle", "sapMLnkWrapping", "sapMLnkDsbl"];
assert.expect(2);

classes.forEach(function(className) {
assert.notOk(link.classList.contains(className), "root element does not contain " + className);
});
var link = this.getLinkRoot();

assert.notOk(link.getAttribute('href'), "Rendered without 'href' by default");
assert.notOk(link.getAttribute('target'), "Rendered without 'target' by default");
Expand All @@ -51,11 +46,7 @@ TestHelper.ready(function() {
};

this.getLinkRoot = function() {
return this.link.shadowRoot.querySelector(".sapMLnk");
};

this.getLinkInternalControl = function() {
return this.link.internalControl;
return this.link.shadowRoot.querySelector(".ui5-link-root");
};
});
hooks.beforeEach(function () {
Expand All @@ -71,49 +62,21 @@ TestHelper.ready(function() {
this.link = null;
});

QUnit.test("set boolean props", function (assert) {
assert.expect(2);

var done = assert.async(),
link = this.getLink(),
linkRoot = this.getLinkRoot(),
expectedClassеs = ["sapMLnkWrapping", "sapMLnkDsbl"],
props = ["wrap", "disabled"];

// act
props.forEach(function(prop) {
link[prop] = true;
});

RenderScheduler.whenFinished().then(function () {
expectedClassеs.forEach(function(className) {
// assert
assert.ok(linkRoot.classList.contains(className), "root element contain " + className);
});

done();
});
});

QUnit.test("set string props", function (assert) {
assert.expect(3);
assert.expect(2);

var done = assert.async(),
link = this.getLink(),
linkRoot = this.getLinkRoot(),
expectedHref = "https://sap.com",
expectedTarget = '_blank',
type1 = "Emphasized";
expectedTarget = '_blank';

var props = [{
prop: 'href',
value: expectedHref
}, {
prop: 'target',
value: expectedTarget
}, {
prop: 'design',
value: type1
}];

props.forEach(function(propInfo) {
Expand All @@ -125,7 +88,6 @@ TestHelper.ready(function() {
// assert
assert.equal(linkRoot.getAttribute("href"), expectedHref, "'href' has been set");
assert.equal(linkRoot.getAttribute("target"), expectedTarget, "'target' has been set");
assert.ok(linkRoot.classList.contains("sapMLnkEmphasized"), "root element contain sapMLnkSubtle");
done();
});
});
Expand Down