[BUG] Alpha modifier/transformer not working
LegendAF opened this issue · comments
Alex Fernandez commented
ℹ️ Info
Version: figma2flutter: ^0.2.0-alpha
💬 Description
While attempting to use the alpha modifier, the hex output always seems to be the same. However when I use lighten, the end hex value always changes.
📜 tokens file you tried to import
"low2": {
"value": "#000000",
"type": "color",
"$extensions": {
"studio.tokens": {
"modify": {
"type": "alpha",
"value": "0.5",
"space": "srgb"
}
}
}
},
vs
"low2": {
"value": "#000000",
"type": "color",
"$extensions": {
"studio.tokens": {
"modify": {
"type": "alpha",
"value": "1",
"space": "srgb"
}
}
}
},
The output is always the same. Is it user error?
Joe Freeman commented
I wrote a unit test that shows this doesn't work.
It looks like the only modification type currently supported are lighten, darken, mix if I'm reading color_transformer.dart correctly
`
@OverRide
String transform(Token token) {
final value = token.value;
ColorValue? colorValue = ColorValue.maybeParse(value);
if (colorValue == null) {
throw Exception('Invalid color value: $value');
}
if (token.hasExtensions) {
final modify = token.extensions?['studio.tokens']?['modify'];
if (modify != null) {
final type = modify['type'];
final value = double.tryParse(modify['value'] as String? ?? '0');
final color = modify['color'] as String?;
if (value != null && value != 0) {
if (type == 'lighten') {
colorValue = colorValue.lighten(value / 2);
} else if (type == 'darken') {
colorValue = colorValue.darken(value / 2);
} else if (color != null && type == 'mix' && color.startsWith('#')) {
colorValue = colorValue.mix(color, value);
}
}
}
}
return colorValue.declaration();
}
`
Joe Freeman commented
This is fixed on main and in the next release whenever that is.