Skip to content

Commit 43afc54

Browse files
Merge pull request #123 from gridaco/staging
CSS: Flex align-items & gap fix, linear-gradient deg fix
2 parents a5424aa + fba85b5 commit 43afc54

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

editor/scaffolds/preview/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export function Preview({
167167
width: target.width,
168168
height: target.height,
169169
borderRadius: 1,
170-
backgroundColor: bg_color_str,
170+
backgroundColor: !preview && bg_color_str, // clear bg after preview is rendered.
171171
contain: "layout style paint",
172172
}}
173173
>

externals/design-sdk

packages/builder-css-styles/linear-gradient/index.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,23 @@ import { color } from "../color";
55
/**
66
* https://developer.mozilla.org/en-US/docs/Web/CSS/gradient/linear-gradient()
77
*
8+
* TODO:
9+
* - [ ] stops support (position)
10+
*
811
* @param g
912
* @returns
1013
*/
1114
export function linearGradient(g: LinearGradientManifest): CSSProperty.Color {
12-
// throw "css gradient not ready";
13-
// TODO:
14-
// 1. stops support
15-
// 2. angle support
16-
var angleDeg =
15+
const angle =
1716
(Math.atan2(g.begin.y - g.end.y, g.begin.x - g.end.x) * 180) / Math.PI;
1817

18+
const gradient_angle =
19+
angle +
20+
// when the rotation value is 0, it means the gradient direction is left to right, which in css, it is 90deg.
21+
// so we have to subtract 90.
22+
// TODO: consider: extract this outside of the styles module?
23+
-90;
24+
1925
const colors = g.colors.map(color).join(", ");
20-
return `linear-gradient(${angleDeg}deg, ${colors})`;
26+
return `linear-gradient(${gradient_angle}deg, ${colors})`;
2127
}

packages/builder-web-core/widgets-native/flex/index.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,14 @@ export class Flex extends MultiChildWidget implements CssMinHeightMixin {
123123
overflow: this.overflow,
124124
...css.justifyContent(this.mainAxisAlignment),
125125
"flex-direction": direction(this.direction),
126-
"align-items": this.crossAxisAlignment,
126+
"align-items": flex_align_items(this.crossAxisAlignment),
127127
flex: this.flex,
128128
"flex-wrap": this.flexWrap,
129-
gap: this.itemSpacing && css.px(this.itemSpacing),
129+
gap:
130+
// if justify-content is set to space-between, do not set the gap.
131+
this.mainAxisAlignment == MainAxisAlignment.spaceBetween
132+
? undefined
133+
: this.itemSpacing && css.px(this.itemSpacing),
130134
"box-shadow": css.boxshadow(...(this.boxShadow ?? [])),
131135
...css.border(this.border),
132136
...css.borderRadius(this.borderRadius),
@@ -153,3 +157,24 @@ function direction(axis: Axis): CSSProperty.FlexDirection {
153157
}
154158
throw `axis value of "${axis}" is not a valid reflect Axis value.`;
155159
}
160+
161+
/**
162+
* explicit css value with `flex-` prefix for start, end
163+
* why? - "start" and "end" also attributes to the box itself -> to be more flex-specific.
164+
* @param alignment
165+
* @returns
166+
*/
167+
function flex_align_items(alignment: CrossAxisAlignment) {
168+
switch (alignment) {
169+
case CrossAxisAlignment.start:
170+
return "flex-start";
171+
case CrossAxisAlignment.end:
172+
return "flex-end";
173+
case CrossAxisAlignment.center:
174+
return "center";
175+
case CrossAxisAlignment.stretch:
176+
return "stretch";
177+
case CrossAxisAlignment.baseline:
178+
return "baseline";
179+
}
180+
}

0 commit comments

Comments
 (0)