I really like how you can quickly add and style buttons in Hype but for some reason the buttons cannot have attributes and I desperately need to be able to enable/disable them.
So, I started experimenting with creating and styling custom buttons with CSS. When the button is disabled it is greyed out and displays a small padlock icon. Also, it cannot be clicked so any actions assigned to it will not work unless it is enabled again. The button can have hover over effects and also include custom symbols as text.
Have a look yourself and let me know how this can be improved
Note, Hype elements have class names that you do not see in the UI.
So if you use set attrib class on for example a Hype button or any other Hype element, you will overwrite all its classes.
If working on a Hype element use the classList and its add/remove commands.
Here is a quick edited example.
<style>
.button_enabled{
background-size: 0px 0px;/* not a inheritance for a hype button */
}
.button_disabled{
background-position: 55px 55px;
background-size: 20px 20px;
background-repeat: no-repeat;
border: 0px;
cursor: not-allowed;
pointer-events: none!important;
}
.button_enabled:hover {
color: #26B9FF!important;
}
</style>
Notice that we do not need to do all the reverse changes in the css ( above ) and the code ( below ).
When the class changes the inheritance takes over in some cases.
disabled code
var bt1 = hypeDocument.getElementById('button_1')
bt1.classList.add("button_disabled");
bt1.classList.remove("button_enabled");
hypeDocument.setElementProperty(bt1, 'background-image', "${resourcesFolderName}/padlock.svg")
enabled code
var bt1 = hypeDocument.getElementById('button_1')
bt1.classList.add("button_enabled");
bt1.classList.remove("button_disabled");
( note I am trying to keep you logic close to what it was rather than do a whole sale refactor. Which with things like this there will be many ways to do so )