Last active
September 20, 2022 18:38
-
-
Save codebender828/fdb0ab845b4c78ac6e4d05fed3d7b26a to your computer and use it in GitHub Desktop.
Panda TSX Vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { DOMElements } from "@chakra-ui/vue-system" | |
import { computed, defineComponent } from "vue" | |
function cx(...args: any[]) { | |
return args.filter(Boolean).join(" ") | |
} | |
function splitProps(props: any) { | |
const styleProps = {} | |
const elementProps = {} | |
for (const [key, value] of Object.entries(props)) { | |
if (isCssProperty(key)) { | |
styleProps[key] = value | |
} else { | |
elementProps[key] = value | |
} | |
} | |
return [styleProps, elementProps] | |
} | |
function css(props: any) { | |
return "class" | |
} | |
function styled(Dynamic: DOMElements) { | |
const PandaComponent = defineComponent((_, { attrs, slots }) => { | |
const [styleProps, elementProps] = splitProps(attrs) | |
const classes = computed(() => { | |
const { css: cssStyles, ...otherStyles } = styleProps | |
const atomicClass = css({ ...otherStyles, ...cssStyles }) | |
return cx(atomicClass, elementProps.class) | |
}) | |
return () => ( | |
<Dynamic {...elementProps} class={classes.value}> | |
{slots} | |
</Dynamic> | |
) | |
}) | |
PandaComponent.name = `chakra.${Dynamic}` | |
return PandaComponent | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment