Are there plans to support as
property along with asChild
?
#2899
-
Hi! I couldn't find the answer in the docs, but perhaps this topic can be unwrapped in this discussion. Yet Chakra used Here is the example, using ParkUI: import React from 'react'
import { Button, ButtonProps } from 'ui-kit/button'
import { Text } from 'ui-kit/text'
export const MySpecialButton: React.FC<ButtonProps> = ({ ...props }) => {
return (
<Button {...props} variant='subtle'>
<Text>Title</Text>
<Text>Description</Text>
</Button>
)
}
// I want this button to work as link now
const AsLink = () => {
return <MySpecialButton>???</MySpecialButton>
} I can't see a way to make it work as a link here as the direction of In Chakra I would solve this with a little effort: const AsLink = () => {
return <MySpecialButton as='a' />
} But in the ark, I have to do this sort of wrapping, resulting it way less flexibility. import React, { Children, Fragment } from 'react'
import { Button, ButtonProps } from 'ui-kit/button'
import { Text } from 'ui-kit/text'
export const MySpecialButton: React.FC<ButtonProps> = ({
children,
...props
}) => {
const hasDirectChild = Boolean(
children && Children.only(children) && React.isValidElement(children),
)
const directDescendant = hasDirectChild ? children : <Fragment />
return (
<Button {...props} variant='subtle'>
{React.cloneElement(directDescendant as React.ReactElement, {
children: (
<>
<Text>Title</Text>
<Text>Description</Text>
</>
),
})}
</Button>
)
}
const AsLink = () => {
return (
<MySpecialButton>
<a href='#' />
</MySpecialButton>
)
} Going back to the original question, are there any plans to support |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
We don’t have plans to support to the as prop due to the type complexity it introduces. It’s hard to get it right for all frameworks |
Beta Was this translation helpful? Give feedback.
We don’t have plans to support to the as prop due to the type complexity it introduces. It’s hard to get it right for all frameworks