2024-02-19 16:48:49 +00:00
const buttonInsetFakeBorders = [ '$borderSide(#FFFFFF, top, 0.2)' , '$borderSide(#000000, bottom, 0.2)' ]
const inputInsetFakeBorders = [ '$borderSide(#FFFFFF, bottom, 0.2)' , '$borderSide(#000000, top, 0.2)' ]
2024-02-12 15:26:08 +00:00
const buttonOuterShadow = {
x : 0 ,
y : 0 ,
blur : 2 ,
spread : 0 ,
color : '#000000' ,
alpha : 1
}
2024-02-07 13:53:34 +00:00
const hoverGlow = {
x : 0 ,
y : 0 ,
blur : 4 ,
spread : 0 ,
color : '--text' ,
alpha : 1
}
2024-01-18 12:35:25 +00:00
export default {
2024-02-09 17:37:22 +00:00
name : 'Button' , // Name of the component
2024-02-12 15:26:08 +00:00
selector : '.button-default' , // CSS selector/prefix
2024-02-11 21:11:28 +00:00
// outOfTreeSelector: '' // out-of-tree selector is used when other components are laid over it but it's not part of the tree, see Underlay component
// States, system witll calculate ALL possible combinations of those and prepend "normal" to them + standalone "normal" state
2024-01-18 12:35:25 +00:00
states : {
2024-02-11 21:11:28 +00:00
// States are a bit expensive - the amount of combinations generated is about (1/6)n^3+n, so adding more state increased number of combination by an order of magnitude!
// All states inherit from "normal" state, there is no other inheirtance, i.e. hover+disabled only inherits from "normal", not from hover nor disabled.
// However, cascading still works, so resulting state will be result of merging of all relevant states/variants
// normal: '' // normal state is implicitly added, it is always included
2024-01-23 17:18:55 +00:00
toggled : '.toggled' ,
2024-01-18 12:35:25 +00:00
pressed : ':active' ,
2024-02-18 16:40:14 +00:00
hover : ':hover:not(:disabled)' ,
2024-02-15 18:20:27 +00:00
focused : ':focus-within' ,
disabled : ':disabled'
2024-01-18 12:35:25 +00:00
} ,
2024-02-11 21:11:28 +00:00
// Variants are mutually exclusive, each component implicitly has "normal" variant, and all other variants inherit from it.
2024-01-18 12:35:25 +00:00
variants : {
2024-02-11 21:11:28 +00:00
// Variants save on computation time since adding new variant just adds one more "set".
2024-02-12 15:26:08 +00:00
// normal: '', // you can override normal variant, it will be appenended to the main class
danger : '.danger'
2024-02-11 21:11:28 +00:00
// Overall the compuation difficulty is N*((1/6)M^3+M) where M is number of distinct states and N is number of variants.
// This (currently) is further multipled by number of places where component can exist.
2024-01-18 12:35:25 +00:00
} ,
2024-02-11 21:11:28 +00:00
// This lists all other components that can possibly exist within one. Recursion is currently not supported (and probably won't be supported ever).
2024-01-18 12:35:25 +00:00
validInnerComponents : [
'Text' ,
'Icon'
2024-01-31 23:27:30 +00:00
] ,
2024-02-11 21:11:28 +00:00
// Default rules, used as "default theme", essentially.
2024-01-31 23:27:30 +00:00
defaultRules : [
{
2024-02-11 21:11:28 +00:00
// component: 'Button', // no need to specify components every time unless you're specifying how other component should look
// like within it
2024-01-31 23:27:30 +00:00
directives : {
2024-02-07 13:53:34 +00:00
background : '--fg' ,
2024-02-13 00:09:43 +00:00
shadow : [ buttonOuterShadow , ... buttonInsetFakeBorders ] ,
roundness : 3
2024-02-08 16:18:01 +00:00
}
} ,
2024-01-31 23:27:30 +00:00
{
state : [ 'hover' ] ,
directives : {
2024-02-07 13:53:34 +00:00
shadow : [ hoverGlow , ... buttonInsetFakeBorders ]
}
} ,
2024-02-12 01:46:40 +00:00
{
state : [ 'pressed' ] ,
directives : {
2024-02-12 15:26:08 +00:00
shadow : [ buttonOuterShadow , ... inputInsetFakeBorders ]
2024-02-12 01:46:40 +00:00
}
} ,
2024-02-07 13:53:34 +00:00
{
state : [ 'hover' , 'pressed' ] ,
2024-02-12 01:46:40 +00:00
directives : {
shadow : [ hoverGlow , ... inputInsetFakeBorders ]
}
} ,
{
state : [ 'toggled' ] ,
directives : {
background : '--accent,-24.2' ,
2024-02-12 15:26:08 +00:00
shadow : [ buttonOuterShadow , ... inputInsetFakeBorders ]
2024-02-12 01:46:40 +00:00
}
} ,
{
state : [ 'toggled' , 'hover' ] ,
2024-02-07 13:53:34 +00:00
directives : {
background : '--accent,-24.2' ,
shadow : [ hoverGlow , ... inputInsetFakeBorders ]
}
} ,
{
state : [ 'disabled' ] ,
directives : {
2024-02-18 18:11:06 +00:00
background : '$blend(--inheritedBackground, 0.25, --parent)' ,
2024-02-07 13:53:34 +00:00
shadow : [ ... buttonInsetFakeBorders ]
}
} ,
{
component : 'Text' ,
parent : {
component : 'Button' ,
state : [ 'disabled' ]
} ,
directives : {
textOpacity : 0.25 ,
textOpacityMode : 'blend'
2024-01-31 23:27:30 +00:00
}
}
2024-01-18 12:35:25 +00:00
]
}