-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
515 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { Suspense, lazy } from 'react' | ||
import { codeToHtml } from 'shiki' | ||
import githubDarkDimmed from 'shiki/themes/github-dark-dimmed.mjs' | ||
|
||
const exampleComponents = import.meta.glob('../examples/**/*.tsx') as { | ||
[key: string]: () => Promise<{ | ||
default: React.ComponentType | ||
}> | ||
} | ||
|
||
const exampleCodes = import.meta.glob('../examples/**/*.tsx', { | ||
query: '?raw', | ||
import: 'default', | ||
}) as { | ||
[key: string]: () => Promise<string> | ||
} | ||
|
||
export function Example({ path }: { path: string }) { | ||
const fullPath = `../examples/${path}.tsx` | ||
|
||
return ( | ||
<div> | ||
<ExamplePreview fullPath={fullPath} /> | ||
<ExampleCode fullPath={fullPath} /> | ||
</div> | ||
) | ||
} | ||
|
||
function ExamplePreview(props: { fullPath: string }) { | ||
const loadComponent = exampleComponents[props.fullPath] | ||
|
||
if (!loadComponent) { | ||
throw new Error(`Component does not exists on [${props.fullPath}]`) | ||
} | ||
|
||
const Component = lazy(loadComponent) | ||
|
||
return ( | ||
// TODO | ||
<Suspense fallback="loading..."> | ||
<Component /> | ||
</Suspense> | ||
) | ||
} | ||
|
||
function ExampleCode(props: { fullPath: string }) { | ||
const loadCode = exampleCodes[props.fullPath] | ||
|
||
if (!loadCode) { | ||
throw new Error(`Component does not exists on [${props.fullPath}]`) | ||
} | ||
|
||
const Code = lazy(async () => { | ||
const code = await loadCode() | ||
const html = await codeToHtml(code, { | ||
lang: 'tsx', | ||
theme: 'github-light', | ||
themes: { | ||
light: 'github-light', | ||
dark: githubDarkDimmed, | ||
// dim: 'github-dimmed', | ||
}, | ||
transformers: [ | ||
{ | ||
pre: (el) => { | ||
el.properties.class += ' vocs_Pre' | ||
return el | ||
}, | ||
code: (el) => { | ||
el.properties.class += ' vocs_Code' | ||
return el | ||
}, | ||
span: (el) => { | ||
el.properties.class += ' vocs_Span' | ||
return el | ||
}, | ||
}, | ||
], | ||
}) | ||
return { | ||
default: () => { | ||
return ( | ||
<div className="vocs_CodeBlock"> | ||
<div className="vocs_Pre_wrapper" dangerouslySetInnerHTML={{ __html: html }} /> | ||
</div> | ||
) | ||
}, | ||
} | ||
}) | ||
|
||
return ( | ||
// TODO | ||
<Suspense fallback="loading..."> | ||
<Code /> | ||
</Suspense> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { | ||
Accordion, | ||
AccordionContent, | ||
AccordionItem, | ||
AccordionTrigger, | ||
} from '@dinui/react/accordion' | ||
|
||
export default function AccordionDemo() { | ||
return ( | ||
<Accordion type="single" collapsible className="w-full"> | ||
<AccordionItem value="item-1"> | ||
<AccordionTrigger>Is it accessible?</AccordionTrigger> | ||
<AccordionContent>Yes. It adheres to the WAI-ARIA design pattern.</AccordionContent> | ||
</AccordionItem> | ||
<AccordionItem value="item-2"> | ||
<AccordionTrigger>Is it styled?</AccordionTrigger> | ||
<AccordionContent> | ||
Yes. It comes with default styles that matches the other components' aesthetic. | ||
</AccordionContent> | ||
</AccordionItem> | ||
<AccordionItem value="item-3"> | ||
<AccordionTrigger>Is it animated?</AccordionTrigger> | ||
<AccordionContent> | ||
Yes. It's animated by default, but you can disable it if you prefer. | ||
</AccordionContent> | ||
</AccordionItem> | ||
</Accordion> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,28 @@ | ||
--- | ||
title: Accordion | ||
description: A vertically stacked set of interactive headings that each reveal a section of content. | ||
--- | ||
|
||
# Accordion | ||
import { Example } from '@web/components/example' | ||
|
||
<Example path="accordion-demo" /> | ||
|
||
## Usage | ||
|
||
```tsx | ||
import { | ||
Accordion, | ||
AccordionContent, | ||
AccordionItem, | ||
AccordionTrigger, | ||
} from '@dinui/react/accordion' | ||
``` | ||
|
||
```tsx | ||
<Accordion type="single" collapsible> | ||
<AccordionItem value="item-1"> | ||
<AccordionTrigger>Is it accessible?</AccordionTrigger> | ||
<AccordionContent>Yes. It adheres to the WAI-ARIA design pattern.</AccordionContent> | ||
</AccordionItem> | ||
</Accordion> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use client' | ||
|
||
import { cx } from '../utils' | ||
import * as AccordionPrimitive from '@radix-ui/react-accordion' | ||
import { ChevronDownIcon } from '@radix-ui/react-icons' | ||
import * as React from 'react' | ||
|
||
const Accordion = AccordionPrimitive.Root | ||
|
||
const AccordionItem = React.forwardRef< | ||
React.ElementRef<typeof AccordionPrimitive.Item>, | ||
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item> | ||
>(({ className, ...props }, ref) => ( | ||
<AccordionPrimitive.Item ref={ref} className={cx('border-b', className)} {...props} /> | ||
)) | ||
AccordionItem.displayName = 'AccordionItem' | ||
|
||
const AccordionTrigger = React.forwardRef< | ||
React.ElementRef<typeof AccordionPrimitive.Trigger>, | ||
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger> | ||
>(({ className, children, ...props }, ref) => ( | ||
<AccordionPrimitive.Header className="flex"> | ||
<AccordionPrimitive.Trigger | ||
ref={ref} | ||
className={cx( | ||
'flex flex-1 items-center justify-between py-4 text-sm font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180', | ||
className, | ||
)} | ||
{...props} | ||
> | ||
{children} | ||
<ChevronDownIcon className="h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-200" /> | ||
</AccordionPrimitive.Trigger> | ||
</AccordionPrimitive.Header> | ||
)) | ||
AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName | ||
|
||
const AccordionContent = React.forwardRef< | ||
React.ElementRef<typeof AccordionPrimitive.Content>, | ||
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Content> | ||
>(({ className, children, ...props }, ref) => ( | ||
<AccordionPrimitive.Content | ||
ref={ref} | ||
className="overflow-hidden text-sm data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down" | ||
{...props} | ||
> | ||
<div className={cx('pb-4 pt-0', className)}>{children}</div> | ||
</AccordionPrimitive.Content> | ||
)) | ||
AccordionContent.displayName = AccordionPrimitive.Content.displayName | ||
|
||
export { Accordion, AccordionItem, AccordionTrigger, AccordionContent } |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import clsx, { type ClassValue } from 'clsx' | ||
import { twMerge } from 'tailwind-merge' | ||
|
||
export function cx(...args: ClassValue[]) { | ||
return twMerge(clsx(...args)) | ||
} |
Oops, something went wrong.