Skip to content

Commit 2d3eae3

Browse files
authored
Merge pull request #29 from josevictorferreira/bugfix/fix-css-properties-generation
Bugfix - Fixes in CSS generation - "sketch_css"
2 parents f1b492f + b108390 commit 2d3eae3

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

sketch_css/src/sketch/css.gleam

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ fn compute_css_property(name, param) {
420420

421421
fn css_property(name, param) {
422422
let prop =
423-
string.split(name, "-")
423+
string.split(name, "_")
424424
|> list.filter(fn(a) { a != "" })
425425
|> string.join("-")
426426
let body = property_body(param)
@@ -452,6 +452,8 @@ fn template_areas_to_string(param) {
452452
fn string_to_string(param) {
453453
case param {
454454
glance.String(m) -> m
455+
glance.Int(i) -> i
456+
glance.Float(f) -> f
455457
glance.Variable(v) ->
456458
"var(--" <> string.replace(v, each: "_", with: "-") <> ")"
457459
_ -> ""
@@ -463,17 +465,24 @@ fn property_body(param) {
463465
[Field(None, p)] -> {
464466
case rewrite_pipe(p) {
465467
Call(FieldAccess(Variable(_), size), [Field(None, value)]) ->
466-
size_to_string(value) <> size
468+
size_value_to_string(value) <> size_to_string(size)
467469
Call(Variable(size), [Field(None, value)]) ->
468-
size_to_string(value) <> size
470+
size_value_to_string(value) <> size_to_string(size)
469471
p -> string_to_string(p)
470472
}
471473
}
472474
_ -> string.inspect(param)
473475
}
474476
}
475477

476-
fn size_to_string(value) {
478+
fn size_to_string(size: String) -> String {
479+
case size {
480+
"percent" -> "%"
481+
_ -> size
482+
}
483+
}
484+
485+
fn size_value_to_string(value) {
477486
case rewrite_pipe(value) {
478487
glance.Int(i) -> i
479488
glance.Float(f) -> f

sketch_css/test/main_css.gleam

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sketch
22
import sketch.{background, class as t} as s
33
import sketch/media
4-
import sketch/size.{px}
4+
import sketch/size.{percent, px}
55

66
fn custom_color(custom) {
77
sketch.color(custom)
@@ -10,6 +10,9 @@ fn custom_color(custom) {
1010
pub fn card(custom) {
1111
sketch.class([
1212
sketch.background("#ddd"),
13+
sketch.z_index(100),
14+
sketch.opacity(1.0),
15+
sketch.width(percent(100)),
1316
background("red"),
1417
s.display("block"),
1518
s.padding(size.pt(12)),

sketch_css/test/sketch/constants.gleam

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ pub const card = \"card\""
1010

1111
pub const css = ".card {
1212
background: #ddd;
13+
z-index: 100;
14+
opacity: 1.0;
15+
width: 100%;
1316
background: red;
1417
display: block;
1518
padding: 12pt;

0 commit comments

Comments
 (0)