Skip to content

Commit

Permalink
Merge pull request #172 from neplextech/next
Browse files Browse the repository at this point in the history
fix(JSX): monkey patch layout issues
  • Loading branch information
twlite committed Sep 23, 2023
2 parents d414be0 + 55670f7 commit 4762bcf
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/helpers/jsx.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type * as React from 'react';
import { Node } from '../fabric';
import { performObjectCleanup } from './StyleSheet';
import { performObjectCleanup, StyleSheet } from './StyleSheet';

export type ElementInit = {
type: string;
Expand Down Expand Up @@ -32,6 +32,21 @@ export const JSX = {
Element,
createElement(type: string | Element, props: Record<string, unknown>, ...children: Element[]): Element {
if (type instanceof Element) return type;

// monkey-patch layout issues
if ('className' in props) props.tw ??= props.className;

if (type === 'div') {
if ('tw' in props) {
props.tw = StyleSheet.cn('flex flex-col content-start shrink-0', props.tw as string);
} else if ('style' in props) {
props.style = StyleSheet.compose(
{ display: 'flex', flexDirection: 'column', alignContent: 'flex-start', flexShrink: 0 },
props.style as Record<string, unknown>
);
}
}

return new Element({
type,
props: {
Expand Down

0 comments on commit 4762bcf

Please sign in to comment.