Replies: 2 comments 1 reply
-
yeah the creator of StyleX mentioned he was interested in doing this. although it's a huge task |
Beta Was this translation helpful? Give feedback.
-
Did some testing with react, vue, qwik, angular and solidjs. I used vite to setup the SPAs with the vite-plugin-stylex Mitosis CodeThe code looks like this in the button.lite.tsx import { Show } from '@builder.io/mitosis';
import * as stylex from '@stylexjs/stylex';
export interface ButtonProps {
attributes?: any;
text?: string;
link?: string;
openLinkInNewTab?: boolean;
}
const styles = stylex.create({
base: {
fontSize: 16,
lineHeight: 1.5,
color: 'white',
background: 'yellow'
},
highlighted: {
color: 'black',
},
});
export default function Button(props: ButtonProps) {
return (
<Show
when={props.link}
else={<span {...props.attributes}>{props.text}</span>}
>
<a
{...props.attributes}
{...stylex.props(styles.base, styles.highlighted)}
role="button"
href={props.link}
target={props.openLinkInNewTab ? '_blank' : undefined}
>
{props.text}
</a>
</Show>
);
} LinterThe linter in the component complains.
ReactWorks already out of the box. Only one minor issue:
SolidJSWorks out of the box. Expect the same minor issue as in react. VueOnly tried with compsition API, as I am not sure if styleX works with options api in any way. The following changes needs to be made to fix stylex
Current output<template>
<template v-if="link">
<a
role="button"
:href="link"
:target="openLinkInNewTab ? '_blank' : undefined"
v-bind="{
...attributes,
...stylex.props(styles.base, styles.highlighted),
}"
>{{ text }}</a
>
</template>
<template v-else>
<span v-bind="attributes">{{ text }}</span>
</template>
</template>
<script setup lang="ts">
import * as stylex from "@stylexjs/stylex";
const styles = stylex.create({
base: {
fontSize: 16,
lineHeight: 1.5,
color: "white",
background: "yellow",
},
highlighted: {
color: "black",
},
});
export interface ButtonProps {
attributes?: any;
text?: string;
link?: string;
openLinkInNewTab?: boolean;
}
const props = defineProps<ButtonProps>();
</script> Expected output<template>
<template v-if="link">
<a
role="button"
:href="link"
:target="openLinkInNewTab ? '_blank' : undefined"
v-bind="{
...attributes,
...stylex.props(styles.base, styles.highlighted),
}"
>{{ text }}</a
>
</template>
<template v-else>
<span v-bind="attributes">{{ text }}</span>
</template>
</template>
<script setup lang="ts">
import stylex from "@stylexjs/stylex";
export interface ButtonProps {
attributes?: any;
text?: string;
link?: string;
openLinkInNewTab?: boolean;
}
const props = defineProps<ButtonProps>();
</script>
<script lang="ts">
const styles = stylex.create({
base: {
fontSize: 16,
lineHeight: 1.5,
color: "white",
background: "yellow",
},
highlighted: {
color: "black",
},
});
</script> AngularThere is no optimal way on how to use StyleX with Angular yet. Some disscussions here facebook/stylex#97 QwikOutput was completely broken. Did not investigate into the expected output. Current OutputError: SyntaxError: Identifier expected. (3:8)
1 | import{Fragment,component$,h}from"@builder.io/qwik";
2 |
> 3 | import{* as stylex}from"@stylexjs/stylex";
| ^
4 |
5 | export interface ButtonProps {
6 | attributes?: any;
========================================================================
import{Fragment,component$,h}from"@builder.io/qwik";
import{* as stylex}from"@stylexjs/stylex";
export interface ButtonProps {
attributes?: any;
text?: string;
link?: string;
openLinkInNewTab?: boolean;
}
export const styles = stylex.create({
base: {
fontSize: 16,
lineHeight: 1.5,
color: 'white',
background: 'yellow'
},
highlighted: {
color: 'black'
}
});export const Button=component$((props:ButtonProps)=>{
return (<>{props.link?<a role="button"{...props.attributes}{...stylex.props(styles.base, styles.highlighted)} href={props.link} target={props.openLinkInNewTab ? '_blank' : undefined}>{props.text}</a>:<span{...props.attributes}>{props.text}</span>}</>)});
export default Button;
========================================================================
at File.toString (C:\Users\username\mitosis-ds\basic\node_modules\.pnpm\@builder.io+mitosis@0.1.0\node_modules\@builder.io\mitosis\dist\src\generators\qwik\src-generator.js:96:23)
at C:\Users\username\mitosis-ds\basic\node_modules\.pnpm\@builder.io+mitosis@0.1.0\node_modules\@builder.io\mitosis\dist\src\generators\qwik\component-generator.js:137:35
at C:\Users\username\mitosis-ds\basic\node_modules\.pnpm\@builder.io+mitosis-cli@0.1.0\node_modules\@builder.io\mitosis-cli\dist\build\build.js:432:158
at step (C:\Users\username\mitosis-ds\basic\node_modules\.pnpm\@builder.io+mitosis-cli@0.1.0\node_modules\@builder.io\mitosis-cli\dist\build\build.js:44:23)
at Object.next (C:\Users\username\mitosis-ds\basic\node_modules\.pnpm\@builder.io+mitosis-cli@0.1.0\node_modules\@builder.io\mitosis-cli\dist\build\build.js:25:53)
at fulfilled (C:\Users\username\mitosis-ds\basic\node_modules\.pnpm\@builder.io+mitosis-cli@0.1.0\node_modules\@builder.io\mitosis-cli\dist\build\build.js:16:58) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Anyone tried using Mitosis together with StyleX?
StyleX combines static css styling with the dynamic of JS style.
Currently I see the following benefits using stylex over using the CSS property in mitosis.
TypeSafe and auto completionEDIT: This is possible with Mitosis out of the boxI think that those two things are currently not possible with css property in mitosis. Please correct me if I am wrong.
Beta Was this translation helpful? Give feedback.
All reactions