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-button): improve styling #654

Closed
wants to merge 6 commits into from
Closed
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
7 changes: 4 additions & 3 deletions packages/main/src/Button.hbs
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
<button
type="button"
class="{{classes.main}}"
class="ui5-button-inner"
?disabled="{{disabled}}"
data-sap-focus-ref
{{> ariaPressed}}
dir="{{rtl}}"
@focusout={{_onfocusout}}
@focusin={{_onfocusin}}
@click={{_onclick}}
@mousedown={{_onmousedown}}
>
{{#if icon}}
<ui5-icon
class="{{classes.icon}}"
class="ui5-button-icon"
src="{{icon}}"
></ui5-icon>
{{/if}}

{{#if textContent}}
<span id="{{_id}}-content" class="{{classes.text}}">
<span id="{{_id}}-content" class="ui5-button-text">
<bdi>
<slot></slot>
</bdi>
Expand Down
65 changes: 38 additions & 27 deletions packages/main/src/Button.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
import { isSpace, isEnter } from "@ui5/webcomponents-base/dist/events/PseudoEvents.js";
import { getCompactSize } from "@ui5/webcomponents-base/dist/config/CompactSize.js";
import { getRTL } from "@ui5/webcomponents-base/dist/config/RTL.js";
import { getFeature } from "@ui5/webcomponents-base/dist/FeaturesRegistry.js";
import { fetchResourceBundle, getResourceBundle } from "@ui5/webcomponents-base/dist/ResourceBundle.js";
Expand Down Expand Up @@ -96,8 +95,33 @@ const metadata = {

/**
* Used to switch the active state (pressed or not) of the <code>ui5-button</code>.
* @private
*/
_active: {
active: {
type: Boolean,
},

/**
* Defines if a content has been added to the default slot
* @private
*/
iconOnly: {
type: Boolean,
},

/**
* Indicates if the elements is on focus
* @private
*/
focused: {
type: Boolean,
},

/**
* Indicates if the elements has a slotted icon
* @private
*/
hasIcon: {
type: Boolean,
},

Expand Down Expand Up @@ -189,8 +213,8 @@ class Button extends UI5Element {
super();

this._deactivate = () => {
if (this._active) {
this._active = false;
if (this.active) {
this.active = false;
}
};

Expand All @@ -202,6 +226,9 @@ class Button extends UI5Element {
if (this.submits && !FormSupport) {
console.warn(`In order for the "submits" property to have effect, you should also: import "@ui5/webcomponents/dist/features/InputElementsFormSupport.js";`); // eslint-disable-line
}

this.iconOnly = !this.childNodes.length;
this.hasIcon = !!this.icon;
}

onEnterDOM() {
Expand All @@ -223,7 +250,7 @@ class Button extends UI5Element {

_onmousedown(event) {
event.isMarked = "button";
this._active = true;
this.active = true;
}

onmouseup(event) {
Expand All @@ -232,39 +259,23 @@ class Button extends UI5Element {

onkeydown(event) {
if (isSpace(event) || isEnter(event)) {
this._active = true;
this.active = true;
}
}

onkeyup(event) {
if (isSpace(event) || isEnter(event)) {
this._active = false;
this.active = false;
}
}

_onfocusout(_event) {
this._active = false;
this.active = false;
this.focused = false;
}

get classes() {
return {
main: {
sapMBtn: true,
sapMBtnActive: this._active,
sapMBtnWithIcon: this.icon,
sapMBtnNoText: !this.textContent.length,
sapMBtnDisabled: this.disabled,
sapMBtnIconEnd: this.iconEnd,
[`sapMBtn${this.design}`]: true,
sapUiSizeCompact: getCompactSize(),
},
icon: {
sapWCIconInButton: true,
},
text: {
sapMBtnText: true,
},
};
_onfocusin() {
this.focused = true;
}

get rtl() {
Expand Down
6 changes: 0 additions & 6 deletions packages/main/src/ToggleButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ class ToggleButton extends Button {
this.pressed = !this.pressed;
this.fireEvent("press", { pressed: this.pressed });
}

get classes() {
const result = super.classes;
result.main.sapMToggleBtnPressed = this.pressed;
return result;
}
}

ToggleButton.define();
Expand Down
Loading