ParentComponent equivalent of SolidJs in TSRX #1150
|
SolidJs has a // Regular SolidJS TSX
type RootProps = ComponentProps<typeof KTabs>
const Root: ParentComponent<RootProps> = (props) => {
const [local, others] = splitProps(props, ['class', 'children', 'orientation'])
return (
<KTabs
class={cn(
'flex gap-3',
local.orientation === 'vertical' ? 'flex-row items-start' : 'flex-col',
'data-disabled:opacity-60',
local.class
)}
orientation={local.orientation}
{...others}
>
{local.children}
</KTabs>
)
}Here, the type RootProps = ComponentProps<typeof KTabs> & { children?: JSX.Element }
component Root(&{ class: className, children, orientation, ...others }: RootProps) {
<KTabs
class={cn(
'flex gap-3',
orientation === 'vertical' ? 'flex-row items-start' : 'flex-col',
'data-disabled:opacity-60',
className
)}
{orientation}
{...others}
>
{children}
</KTabs>
}Now children is properly typed as |
Replies: 2 comments 1 reply
|
Ripple doesn't have a dedicated 1.
|
|
@Borderliner If you're using TSRX with Solid 2.0 as the target framework, you should be able to just use the Solid types. The syntax that you used for TSRX is no longer correct though as it's just functions now, no component. And to use statements (no return) you need to also have the @{} block. // TSRX using Solid 2.0
import type { ParentProps, ParentComponent, ComponentProps } from 'solid-js';
type KTabsOwnProps = {
class?: string;
orientation?: "horizontal" | "vertical";
disabled?: boolean;
};
const KTabs: ParentComponent<KTabsOwnProps> = (props) => {
return (
<div class={props.class} data-orientation={props.orientation}>
{props.children}
</div>
);
};
type RootProps = ComponentProps<typeof KTabs>;
function Root({
class: className,
children,
orientation = 'horizontal',
...others
}: ParentProps<RootProps>) @{
<KTabs
class={cn(
'flex gap-3',
orientation === 'vertical' ? 'flex-row items-start' : 'flex-col',
'data-disabled:opacity-60',
className,
)}
orientation={orientation}
{...others}
>{children}</KTabs>
}Regarding the Ripple types. They were only created for Ripple and in some frameworks they may not work properly, like React with className. I'm not sure if we should create these types specifically for TSRX since every framework covers them and you'd be using the framework's api to do your development so I don't think it makes sense to have TSRX specific types. Happy to reconsider if we get valid reasons for them. |
Ripple doesn't have a dedicated
ParentComponentalias, but you don't need to spell outchildren?: JSX.Elementby hand either. The built-in helper you want isPropsWithChildrenOptional, and the child type should be Ripple'sChildren, notJSX.Element.1.
PropsWithChildrenOptional<T>is the closestParentComponent<T>equivalentRipple exports these from the
rippleentry: