Skip to content

Commit 29ac016

Browse files
support proper layout grow as expanded - flex: n for every elements
1 parent 72d09f6 commit 29ac016

9 files changed

Lines changed: 59 additions & 9 deletions

File tree

externals/design-sdk

externals/reflect-core

packages/builder-css-styles/tricks/trick-flex-sizing/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function flexsizing({
3737
case Axis.horizontal:
3838
case Axis.vertical:
3939
return {
40-
flex: "none",
40+
flex: flex > 0 ? flex : "none", // 1+
4141
width: width && length(width),
4242
height: height && length(height),
4343
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { ReflectSceneNode } from "@design-sdk/figma-node";
2+
3+
export function hasFlexible(node: ReflectSceneNode) {
4+
return node.layoutGrow >= 1;
5+
}

packages/designto-token/detection/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from "./do-have-flex";
12
export * from "./do-contains-masking";
23
export * from "./do-have-dimmed-opacity";
34
export * from "./do-have-stretching";

packages/designto-token/main.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { nodes } from "@design-sdk/core";
2-
import { Widget } from "@reflect-ui/core";
2+
import { Expanded, Widget } from "@reflect-ui/core";
33
import type { Blurred, Opacity, Rotation } from "@reflect-ui/core";
44
import type { Stretched } from "./tokens";
55
import { tokenizeText } from "./token-text";
@@ -21,13 +21,15 @@ import {
2121
hasLayerBlurType,
2222
hasRotation,
2323
hasStretching,
24+
hasFlexible,
2425
} from "./detection";
2526
import { MaskingItemContainingNode, tokenizeMasking } from "./token-masking";
2627
import { wrap_with_opacity } from "./token-opacity";
2728
import { wrap_with_stretched } from "./token-stretch";
2829
import { wrap_with_layer_blur } from "./token-effect/layer-blur";
2930
import { wrap_with_background_blur } from "./token-effect/background-blur";
3031
import { wrap_with_rotation } from "./token-rotation";
32+
import { wrap_with_expanded } from "./token-expanded";
3133
import flags_handling_gate from "./support-flags";
3234

3335
export type { Widget };
@@ -239,12 +241,15 @@ function handleNode(
239241
export function post_wrap(
240242
node: nodes.ReflectSceneNode,
241243
tokenizedTarget: Widget
242-
): Widget | Stretched | Opacity | Blurred | Rotation {
244+
): Widget | Stretched | Opacity | Blurred | Rotation | Expanded {
243245
let wrapped = tokenizedTarget;
244-
if (wrapped) {
245-
if (hasStretching(node)) {
246-
wrapped = wrap_with_stretched(node, wrapped);
247-
}
246+
247+
if (hasStretching(node)) {
248+
wrapped = wrap_with_stretched(node, wrapped);
249+
}
250+
251+
if (hasFlexible(node)) {
252+
wrapped = wrap_with_expanded(node, wrapped);
248253
}
249254

250255
if (hasDimmedOpacity(node)) {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { nodes } from "@design-sdk/core";
2+
import { Expanded, WidgetKey } from "@reflect-ui/core";
3+
import type { Widget } from "@reflect-ui/core";
4+
import assert from "assert";
5+
6+
export function wrap_with_expanded(
7+
node: nodes.ReflectSceneNode,
8+
widget: Widget
9+
): Expanded {
10+
assert(
11+
node.layoutGrow >= 1,
12+
"layoug grow must be >= 1 to be wrapped with Expanded"
13+
);
14+
15+
return new Expanded({
16+
key: new WidgetKey({
17+
...widget.key,
18+
id: widget.key.id + "_opacity",
19+
}),
20+
child: widget,
21+
flex: node.layoutGrow,
22+
});
23+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { Composer } from ".";
2+
import { Expanded } from "@reflect-ui/core";
3+
4+
export function compose_wrapped_with_expanded(
5+
widget: Expanded,
6+
child_composer: Composer
7+
) {
8+
const child = child_composer(widget.child);
9+
child.extendStyle({
10+
flex: widget.flex,
11+
});
12+
return child;
13+
}

packages/designto-web/tokens-to-web-widget/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { compose_wrapped_with_positioned } from "./compose-wrapped-with-position
1414
import { compose_wrapped_with_clip_stretched } from "./compose-wrapped-with-stretched";
1515
import { compose_wrapped_with_sized_box } from "./compose-wrapped-with-sized-box";
1616
import { compose_wrapped_with_overflow_box } from "./compose-wrapped-with-overflow-box";
17+
import { compose_wrapped_with_expanded } from "./compose-wrapped-with-expanded";
1718
import { compose_unwrapped_text_input } from "./compose-unwrapped-text-field";
1819
import { compose_unwrapped_button } from "./compose-unwrapped-button";
1920
import { compose_unwrapped_slider } from "./compose-unwrapped-slider";
@@ -144,6 +145,8 @@ function compose<T extends JsxWidget>(
144145
thisWebWidget = compose_wrapped_with_blurred(widget, handleChild);
145146
} else if (widget instanceof core.Rotation) {
146147
thisWebWidget = compose_wrapped_with_rotation(widget, handleChild);
148+
} else if (widget instanceof core.Expanded) {
149+
thisWebWidget = compose_wrapped_with_expanded(widget, handleChild);
147150
}
148151
// ----- region clip path ------
149152
else if (widget instanceof core.ClipRRect) {

0 commit comments

Comments
 (0)