|
| 1 | +import { Card, CardContent } from "@/components/ui/card"; |
| 2 | +import { Code } from "@/components/ui/code"; |
| 3 | +import { Squircle } from "@squircle-js/react"; |
| 4 | + |
| 5 | +import Prism from "prismjs"; |
| 6 | +import "prismjs/components/prism-jsx"; |
| 7 | +import type { PropsWithChildren } from "react"; |
| 8 | + |
| 9 | +const usage = `<Squircle |
| 10 | + asChild |
| 11 | + cornerRadius={10} |
| 12 | + cornerSmoothing={1} |
| 13 | + className="bg-black text-white px-2 py-1" |
| 14 | +> |
| 15 | + <span>Inline Squircle</span> |
| 16 | +</Squircle>`; |
| 17 | + |
| 18 | +const highlightedUsage = Prism.highlight( |
| 19 | + ["...", usage, "..."].join("\n"), |
| 20 | + Prism.languages.jsx, |
| 21 | + "jsx" |
| 22 | +); |
| 23 | + |
| 24 | +export const ExamplesSectionAsChildExample = () => { |
| 25 | + return ( |
| 26 | + <Card className="w-full max-w-[480px] sm:max-w-[508px]"> |
| 27 | + <CardContent className="py-6 w-full space-y-4"> |
| 28 | + <h3 className="font-semibold text-lg">Code:</h3> |
| 29 | + <p> |
| 30 | + You can use <Kode>asChild</Kode> prop to squircle any element. This is |
| 31 | + useful when you want to squircle some element that might change size. |
| 32 | + By default <Kode>Squircle</Kode> is a <Kode>div</Kode> element, but |
| 33 | + you can change it to any other element by nesting that element inside |
| 34 | + of <Kode>Squircle</Kode> component and adding <Kode>asChild</Kode>{" "} |
| 35 | + prop. |
| 36 | + </p> |
| 37 | + |
| 38 | + <Code dangerousHTML={highlightedUsage} raw={usage} /> |
| 39 | + <h3 className="font-semibold text-lg">Result:</h3> |
| 40 | + |
| 41 | + <Squircle |
| 42 | + cornerRadius={10} |
| 43 | + cornerSmoothing={1} |
| 44 | + asChild |
| 45 | + className="bg-black text-white px-2 py-1" |
| 46 | + > |
| 47 | + <span>Inline Squircle</span> |
| 48 | + </Squircle> |
| 49 | + </CardContent> |
| 50 | + </Card> |
| 51 | + ); |
| 52 | +}; |
| 53 | + |
| 54 | +const Kode = ({ children }: PropsWithChildren) => ( |
| 55 | + <code className="bg-slate-200/50 px-1.5 text-sm py-0.5 rounded-md"> |
| 56 | + {children} |
| 57 | + </code> |
| 58 | +); |
0 commit comments