Skip to content

Commit

Permalink
docs: document specifying props
Browse files Browse the repository at this point in the history
Closes #24
  • Loading branch information
gregberge committed Dec 25, 2023
1 parent 0383b5d commit d9be6b1
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions website/pages/docs/guides/styling-any-component.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,25 @@ const HoverCardContent = twc(HoverCard.Content).attrs({
sideOffset: 5,
})`data-[side=bottom]:animate-slideUpAndFade data-[side=right]:animate-slideLeftAndFade data-[side=left]:animate-slideRightAndFade data-[side=top]:animate-slideDownAndFade w-[300px] rounded-md bg-white p-5 shadow-[hsl(206_22%_7%_/_35%)_0px_10px_38px_-10px,hsl(206_22%_7%_/_20%)_0px_10px_20px_-15px] data-[state=open]:transition-all`;
```

## Specify props

When you wrap a component with `twc`, it infers the component's props automatically. However, this can sometimes result in unpredictable behavior. In such scenarios, it's better to define the props manually.

For example, with the [`@radix-ui/react-accordion`](https://www.radix-ui.com/primitives/docs/components/accordion#accordion) component, its complex props like `type` and `collapsible` might not be inferred correctly by twc. To prevent issues, explicitly declare these props when using `twc`. This explicit declaration ensures accurate prop handling, avoiding potential problems.

```tsx
import * as React from 'react'
import * as AccordionPrimitive from "@radix-ui/react-accordion";
import { twc } from "react-twc";

const Accordion = twc(AccordionPrimitive.Root)<React.ComponentProps<typeof AccordionPrimitive.Root>>`py-2`;

export default () => {
return (
{/* This work without any type error, `collapsible` is authorized when `type="single"` */}
<Accordion type="single" collapsible>
</Accordion>
);
}
```

0 comments on commit d9be6b1

Please sign in to comment.