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-title): clean up styles #662

Merged
merged 3 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
12 changes: 6 additions & 6 deletions packages/main/src/Title.hbs
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
{{#if h1}}
<h1
class="{{classes.main}}">
class="ui5-title-root">
{{> titleInner}}
</h1>
{{/if}}

{{#if h2}}
<h2
class="{{classes.main}}">
class="ui5-title-root">
{{> titleInner}}
</h2>
{{/if}}

{{#if h3}}
<h3
class="{{classes.main}}">
class="ui5-title-root">
{{> titleInner}}
</h3>
{{/if}}

{{#if h4}}
<h4
class="{{classes.main}}">
class="ui5-title-root">
{{> titleInner}}
</h4>
{{/if}}

{{#if h5}}
<h5
class="{{classes.main}}">
class="ui5-title-root">
{{> titleInner}}
</h5>
{{/if}}

{{#if h6}}
<h6
class="{{classes.main}}">
class="ui5-title-root">
{{> titleInner}}
</h6>
{{/if}}
Expand Down
13 changes: 2 additions & 11 deletions packages/main/src/Title.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
import TitleLevel from "./types/TitleLevel.js";

// Template
import TitleTemplate from "./generated/templates/TitleTemplate.lit.js";

// Styles
Expand Down Expand Up @@ -115,17 +117,6 @@ class Title extends UI5Element {
get h6() {
return this.normalizedLevel === "h6";
}

get classes() {
return {
main: {
sapMTitle: true,
sapMTitleWrap: this.wrap,
sapUiSelectable: true,
[`sapMTitleStyle${this.level}`]: true,
},
};
}
}

Title.define();
Expand Down
78 changes: 61 additions & 17 deletions packages/main/src/themes/Title.css
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
:host(ui5-title:not([hidden])) {
:host(:not([hidden])) {
display: block;
max-width: 100%;
color: var(--sapUiGroupTitleTextColor);
font-family: var(--sapUiFontHeaderFamily);
text-shadow: var(--sapUiShadowText);
}

ui5-title:not([hidden]) {
display: block;
overflow: hidden;
:host {
max-width: 100%;
color: var(--sapUiGroupTitleTextColor);
font-family: var(--sapUiFontHeaderFamily);
text-shadow: var(--sapUiShadowText);
max-width: 100%;
}

.sapMTitle {
.ui5-title-root {
display: inline-block;
position: relative;
font-weight: var(--sapUiFontHeaderWeight);
Expand All @@ -33,36 +27,86 @@ ui5-title:not([hidden]) {
cursor: text;
}

.sapMTitle.sapMTitleWrap {
:host([wrap]) .ui5-title-root {
white-space: pre-line;
}

/* Level H1 */
:host([level="H1"]) .ui5-title-root {
font-size: var(--sapMFontHeader1Size);
}

/* Level H2 */
:host([level="H2"]) .ui5-title-root {
font-size: var(--sapMFontHeader2Size);
}

/* Level H3 */
:host([level="H3"]) .ui5-title-root {
font-size: var(--sapMFontHeader3Size);
}

/* Level H4 */
:host([level="H4"]) .ui5-title-root {
font-size: var(--sapMFontHeader4Size);
}

/* Level H5 */
:host([level="H5"]) .ui5-title-root {
font-size: var(--sapMFontHeader5Size);
}

/* Level H6 */
:host([level="H6"]) .ui5-title-root {
font-size: var(--sapMFontHeader6Size);
}

/*
* IE pair of styles
*
*/
ui5-title:not([hidden]) {
display: block;
}

ui5-title {
overflow: hidden;
color: var(--sapUiGroupTitleTextColor);
font-family: var(--sapUiFontHeaderFamily);
text-shadow: var(--sapUiShadowText);
max-width: 100%;
}

ui5-title[wrap] .ui5-title-root {
white-space: pre-line;
}

/* Level H1 */
.sapMTitleStyleH1 {
ui5-title[level="H1"] .ui5-title-root {
font-size: var(--sapMFontHeader1Size);
}

/* Level H2 */
.sapMTitleStyleH2 {
ui5-title[level="H2"] .ui5-title-root {
font-size: var(--sapMFontHeader2Size);
}

/* Level H3 */
.sapMTitleStyleH3 {
ui5-title[level="H3"] .ui5-title-root {
font-size: var(--sapMFontHeader3Size);
}

/* Level H4 */
.sapMTitleStyleH4 {
ui5-title[level="H4"] .ui5-title-root {
font-size: var(--sapMFontHeader4Size);
}

/* Level H5 */
.sapMTitleStyleH5 {
ui5-title[level="H5"] .ui5-title-root {
font-size: var(--sapMFontHeader5Size);
}

/* Level H6 */
.sapMTitleStyleH6 {
ui5-title[level="H6"] .ui5-title-root {
font-size: var(--sapMFontHeader6Size);
}
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.getTitleRoot = function() {
return this.title.shadowRoot.querySelector(".sapMTitle");
return this.title.shadowRoot.querySelector(".ui5-title-root");
};
});
hooks.beforeEach(function () {
Expand All @@ -28,70 +28,5 @@ TestHelper.ready(function() {

assert.ok(titleRoot, "root element is in the DOM");
});

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

var titleRoot = this.getTitleRoot(),
existingClasses = ["sapMTitle", "sapUiSelectable", "sapMTitleStyleH2"];

existingClasses.forEach(function(className) {
assert.ok(titleRoot.classList.contains(className), "root element does contain " + className);
});
});
});

QUnit.module("API", function (hooks) {
hooks.before(function() {
this.getTitleRoot = function() {
return this.title.shadowRoot.querySelector(".sapMTitle");
};
});
hooks.beforeEach(function () {
var html = '<ui5-title id="myTitle">label</ui5-title>';
fixture.innerHTML = html;

this.title = document.getElementById("myTitle");

return RenderScheduler.whenFinished();
});
hooks.afterEach(function () {
fixture.innerHTML = "";
this.title = null;
});

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

var done = assert.async(),
title = this.title,
titleRoot = this.getTitleRoot(),
expectedLevel = 'H2',
expectedClass1 = "sapMTitleStyleH2",
expectedClass2 = "sapMTitleWrap",
expectedWrap = true;

var props = [{
prop: "level",
value: expectedLevel
}, {
prop: "wrap",
value: expectedWrap
}];

props.forEach(function(propInfo) {
// act
title[propInfo.prop] = propInfo.value;
});

RenderScheduler.whenFinished().then(function () {
// assert
// assert
assert.ok(titleRoot.classList.contains(expectedClass1), "root element does contain " + expectedClass1);
assert.ok(titleRoot.classList.contains(expectedClass2), "root element does contain " + expectedClass2);

done();
});
});
});
});