Skip to content

Commit

Permalink
refactor(ui5-switch): rename type property to graphical (#506)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: type property is renamed to boolean property graphical
  • Loading branch information
fifoosid authored Jun 19, 2019
1 parent 9d81d32 commit 0040e85
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 53 deletions.
24 changes: 9 additions & 15 deletions packages/main/src/Switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import getEffectiveRTL from "@ui5/webcomponents-base/src/util/getEffectiveRTL.js

// Template
import SwitchTemplate from "./build/compiled/SwitchTemplate.lit.js";
import SwitchType from "./types/SwitchType.js";


// Styles
import switchCss from "./themes/Switch.css.js";
Expand Down Expand Up @@ -77,18 +77,15 @@ const metadata = {
/**
* Defines the <code>ui5-switch</code> type.
* <br>
* Available options are <code>Textual</code> and <code>Graphical</code>.
*
* <br><br>
* <b>Note:</b> If <code>Graphical</code> type is set,
* <b>Note:</b> If <code>graphical</code> type is set,
* positive and negative icons will replace the <code>textOn</code> and <code>textOff</code>.
* @type {string}
* @defaultvalue "Textual"
* @defaultvalue false
* @public
*/
type: {
type: String,
defaultValue: SwitchType.Textual,
graphical: {
type: Boolean,
},
},
events: /** @lends sap.ui.webcomponents.main.Switch.prototype */ {
Expand Down Expand Up @@ -176,30 +173,27 @@ class Switch extends UI5Element {
}

get textOn() {
const graphical = this.type === SwitchType.Graphical;
return graphical ? "" : this.textOn;
return this.graphical ? "" : this.textOn;
}

get textOff() {
const graphical = this.type === SwitchType.Graphical;
return graphical ? "" : this.textOff;
return this.graphical ? "" : this.textOff;
}

get tabIndex() {
return this.disabled ? undefined : "0";
}

get classes() {
const graphical = this.type === SwitchType.Graphical;
const hasLabel = graphical || this.textOn || this.textOff;
const hasLabel = this.graphical || this.textOn || this.textOff;

return {
main: {
"ui5-switch-wrapper": true,
"ui5-switch-desktop": isDesktop(),
"ui5-switch--disabled": this.disabled,
"ui5-switch--checked": this.checked,
"ui5-switch--semantic": graphical,
"ui5-switch--semantic": this.graphical,
"ui5-switch--no-label": !hasLabel,
"sapUiSizeCompact": getCompactSize(),
},
Expand Down
26 changes: 0 additions & 26 deletions packages/main/src/types/SwitchType.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ <h3>Default Switch</h3>

<h3>Graphical Switch</h3>
<div style="display: flex">
<ui5-switch type="Graphical" text-on="On" text-off="Off"></ui5-switch>
<ui5-switch type="Graphical" checked text-on="Yes" text-off="No"></ui5-switch>
<ui5-switch type="Graphical" text-on="On" text-off="Off" disabled></ui5-switch>
<ui5-switch type="Graphical" checked text-on="Yes" text-off="No" disabled></ui5-switch>
<ui5-switch graphical text-on="On" text-off="Off"></ui5-switch>
<ui5-switch graphical checked text-on="Yes" text-off="No"></ui5-switch>
<ui5-switch graphical text-on="On" text-off="Off" disabled></ui5-switch>
<ui5-switch graphical checked text-on="Yes" text-off="No" disabled></ui5-switch>
</div>

<h3>Custom Switch</h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ <h3>Basic Switch</h3>
<section>
<h3>Graphical Switch</h3>
<div class="snippet">
<ui5-switch type="Graphical"></ui5-switch>
<ui5-switch type="Graphical" checked></ui5-switch>
<ui5-switch type="Graphical" disabled></ui5-switch>
<ui5-switch type="Graphical" checked disabled></ui5-switch>
<ui5-switch graphical></ui5-switch>
<ui5-switch graphical checked></ui5-switch>
<ui5-switch graphical disabled></ui5-switch>
<ui5-switch graphical checked disabled></ui5-switch>
</div>
<pre class="prettyprint lang-html"><xmp>
<ui5-switch type="Graphical"></ui5-switch>
<ui5-switch type="Graphical" checked></ui5-switch>
<ui5-switch type="Graphical" disabled></ui5-switch>
<ui5-switch type="Graphical" checked disabled></ui5-switch>
<ui5-switch graphical></ui5-switch>
<ui5-switch graphical checked></ui5-switch>
<ui5-switch graphical disabled></ui5-switch>
<ui5-switch graphical checked disabled></ui5-switch>
</xmp></pre>
</section>

Expand Down

0 comments on commit 0040e85

Please sign in to comment.