diff options
| author | Adam <[email protected]> | 2025-10-24 08:26:17 -0500 |
|---|---|---|
| committer | Adam <[email protected]> | 2025-10-24 12:16:33 -0500 |
| commit | fe8f6d7a3eef34e932bd43d244460d417865de88 (patch) | |
| tree | 3129fd2072fd3fd0dd842e33c59e0f1f256c1df3 /packages/ui/src | |
| parent | 59b5f5350950e9cac81676f45eaca8611514c4d1 (diff) | |
| download | opencode-fe8f6d7a3eef34e932bd43d244460d417865de88.tar.gz opencode-fe8f6d7a3eef34e932bd43d244460d417865de88.zip | |
wip: desktop work
Diffstat (limited to 'packages/ui/src')
| -rw-r--r-- | packages/ui/src/components/collapsible.css | 46 | ||||
| -rw-r--r-- | packages/ui/src/components/collapsible.tsx | 35 | ||||
| -rw-r--r-- | packages/ui/src/components/index.ts | 1 | ||||
| -rw-r--r-- | packages/ui/src/demo.tsx | 36 |
4 files changed, 117 insertions, 1 deletions
diff --git a/packages/ui/src/components/collapsible.css b/packages/ui/src/components/collapsible.css new file mode 100644 index 000000000..441d0083f --- /dev/null +++ b/packages/ui/src/components/collapsible.css @@ -0,0 +1,46 @@ +[data-component="collapsible"] { + display: flex; + flex-direction: column; + + [data-slot="trigger"] { + cursor: pointer; + user-select: none; + + &:focus-visible { + outline: 2px solid var(--border-focus); + outline-offset: 2px; + } + + &[data-disabled] { + cursor: not-allowed; + opacity: 0.5; + } + } + + [data-slot="content"] { + overflow: hidden; + /* animation: slideUp 250ms ease-out; */ + + /* &[data-expanded] { */ + /* animation: slideDown 250ms ease-out; */ + /* } */ + } +} + +@keyframes slideDown { + from { + height: 0; + } + to { + height: var(--kb-collapsible-content-height); + } +} + +@keyframes slideUp { + from { + height: var(--kb-collapsible-content-height); + } + to { + height: 0; + } +} diff --git a/packages/ui/src/components/collapsible.tsx b/packages/ui/src/components/collapsible.tsx new file mode 100644 index 000000000..011d103c1 --- /dev/null +++ b/packages/ui/src/components/collapsible.tsx @@ -0,0 +1,35 @@ +import { Collapsible as Kobalte, CollapsibleRootProps } from "@kobalte/core/collapsible" +import { ComponentProps, ParentProps, splitProps } from "solid-js" + +export interface CollapsibleProps extends ParentProps<CollapsibleRootProps> { + class?: string + classList?: ComponentProps<"div">["classList"] +} + +function CollapsibleRoot(props: CollapsibleProps) { + const [local, others] = splitProps(props, ["class", "classList"]) + + return ( + <Kobalte + data-component="collapsible" + classList={{ + ...(local.classList ?? {}), + [local.class ?? ""]: !!local.class, + }} + {...others} + /> + ) +} + +function CollapsibleTrigger(props: ComponentProps<typeof Kobalte.Trigger>) { + return <Kobalte.Trigger data-slot="trigger" {...props} /> +} + +function CollapsibleContent(props: ComponentProps<typeof Kobalte.Content>) { + return <Kobalte.Content data-slot="content" {...props} /> +} + +export const Collapsible = Object.assign(CollapsibleRoot, { + Trigger: CollapsibleTrigger, + Content: CollapsibleContent, +}) diff --git a/packages/ui/src/components/index.ts b/packages/ui/src/components/index.ts index 71cfd3a89..3691363cd 100644 --- a/packages/ui/src/components/index.ts +++ b/packages/ui/src/components/index.ts @@ -1,4 +1,5 @@ export * from "./button" +export * from "./collapsible" export * from "./dialog" export * from "./icon" export * from "./icon-button" diff --git a/packages/ui/src/demo.tsx b/packages/ui/src/demo.tsx index 85fd20c0e..7c507d7d9 100644 --- a/packages/ui/src/demo.tsx +++ b/packages/ui/src/demo.tsx @@ -1,6 +1,19 @@ import type { Component } from "solid-js" import { createSignal } from "solid-js" -import { Button, Select, Tabs, Tooltip, Fonts, List, Dialog, Icon, IconButton, Input, SelectDialog } from "./components" +import { + Button, + Select, + Tabs, + Tooltip, + Fonts, + List, + Dialog, + Icon, + IconButton, + Input, + SelectDialog, + Collapsible, +} from "./components" import "./index.css" const Demo: Component = () => { @@ -180,6 +193,27 @@ const Demo: Component = () => { {(item) => <div>{item}</div>} </SelectDialog> </section> + <h3>Collapsible</h3> + <section> + <Collapsible> + <Collapsible.Trigger> + <Button variant="secondary">Toggle Content</Button> + </Collapsible.Trigger> + <Collapsible.Content> + <div + style={{ + padding: "16px", + "background-color": "var(--surface-base)", + "border-radius": "8px", + "margin-top": "8px", + }} + > + <p>This is collapsible content that can be toggled open and closed.</p> + <p>It animates smoothly using CSS animations.</p> + </div> + </Collapsible.Content> + </Collapsible> + </section> </div> ) |
