Skip to content

Instantly share code, notes, and snippets.

@codebender828
Last active September 20, 2022 18:38
Show Gist options
  • Save codebender828/fdb0ab845b4c78ac6e4d05fed3d7b26a to your computer and use it in GitHub Desktop.
Save codebender828/fdb0ab845b4c78ac6e4d05fed3d7b26a to your computer and use it in GitHub Desktop.
Panda TSX Vue
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