Slottable pattern #3062
javialon26
started this conversation in
General
Replies: 1 comment
-
Thanks mate for reaching out - You should be able to achieve this. Here is the import type { ButtonProps as ChakraButtonProps } from '@chakra-ui/react'
import { AbsoluteCenter, Button as ChakraButton, Span, Spinner } from '@chakra-ui/react'
import { forwardRef } from 'react'
interface ButtonLoadingProps {
loading?: boolean
loadingText?: React.ReactNode
}
export interface ButtonProps extends ChakraButtonProps, ButtonLoadingProps {}
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button(props, ref) {
const { loading, disabled, loadingText, children, ...rest } = props
return (
<ChakraButton disabled={loading || disabled} ref={ref} {...rest}>
{loading && !loadingText ? (
<>
<AbsoluteCenter display="inline-flex">
<Spinner size="inherit" color="inherit" />
</AbsoluteCenter>
<Span opacity={0}>{children}</Span>
</>
) : loading && loadingText ? (
<>
<Spinner size="inherit" color="inherit" />
{loadingText}
</>
) : (
children
)}
</ChakraButton>
)
}) And later I can use it like this <Button asChild size={{ base: 'xl', md: '2xl' }}>
<NextLink href="/blocks">
View Blocks <LuArrowRight />
</NextLink>
</Button> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, is there a way to achieve the same functionality as Slottable component in Radix:
example:
I need to build a component with more elements than only a children, if I use the composition example (https://ark-ui.com/react/docs/guides/composition), I got an error, because my component have more than a children:
Thanks
Beta Was this translation helpful? Give feedback.
All reactions