JSFiddle - React, Tailwind, and code Playground
CSS
.button {
max-width: 200px;
text-align: center;
position: relative;
height: 50px;
line-height: 50px;
}
.wrapper {
max-width:100%;
}
.wrapper.bottom {
position: relative;
top: -52px;
}
.wrapper > * {
vertical-align: bottom;
}
.label {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
.hidden {
opacity:0;
}
JavaScript
enyo.kind({
name: "ToggleButton",
classes: "button",
kind:"enyo.Button",
published: {
value: false,
onContent: "On",
offContent: "Off"
},
components: [
{kind:"FittableColumns", classes:"wrapper", name:"off", components: [
{classes:"label", name:"offLabel", fit:true},
{content:": ", allowHtml:true},
{name:"offContent"}
]},
{tag:"br"},
{kind:"FittableColumns", classes:"wrapper bottom hidden", name:"on", components: [
{classes:"label", name:"onLabel", fit:true},
{content:": ", allowHtml:true},
{name:"onContent", content:"foo"}
]}
],
contentChanged: function() {
this.$.onLabel.setContent(this.content);
this.$.offLabel.setContent(this.content);
this.$.onContent.setContent(this.onContent);
this.$.offContent.setContent(this.offContent);
this.resized();
},
valueChanged: function() {
this.$.off.addRemoveClass("hidden", this.value);
this.$.on.addRemoveClass("hidden", !this.value);
},
tap: function() {
this.setValue(!this.value);
}
});
enyo.kind({
name: "MySample",
components: [
{kind:"ToggleButton", content:"Short"},
{kind:"ToggleButton", content:"Really really really long"},
{tag: "br"},
{kind:"ToggleButton", content:"Short", onContent:"Awesome", offContent:"Sad"},
{kind:"ToggleButton", content:"Really really really long", onContent:"Awesome", offContent:"Sad"},
]
});
new MySample().write();