-
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.
Merge pull request #66 from complexdatacollective/feature/node-panel-…
…accordion WIP implementation of panels using radix accordion for a11y
- Loading branch information
Showing
6 changed files
with
183 additions
and
82 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
52 changes: 44 additions & 8 deletions
52
components/interview/interfaces/name-generator/NodePanel.tsx
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,16 +1,52 @@ | ||
import Panel from './Panel'; | ||
import NodeList, { type Node } from '../../NodeList'; | ||
import * as Accordion from '@radix-ui/react-accordion'; | ||
import { motion } from 'framer-motion'; | ||
import { MotionSurface } from '~/components/layout/Surface'; | ||
import Heading from '~/components/typography/Heading'; | ||
import { cn } from '~/lib/utils'; | ||
|
||
export default function NodePanel({ | ||
nodes, | ||
// incompatibility between framer-motion 12.x and new react types | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
const MotionTrigger = motion(Accordion.Trigger); | ||
|
||
export default function Panel({ | ||
id, | ||
title, | ||
expanded, | ||
children, | ||
noHighlight, | ||
}: { | ||
nodes: Node[]; | ||
id: string; | ||
title: string; | ||
expanded: boolean; | ||
children: React.ReactNode; | ||
noHighlight?: boolean; | ||
}) { | ||
const panelClasses = cn( | ||
'flex flex-1 flex-col rounded-small border-b border-b-4 border-panel-1 shadow-xl', | ||
{ | ||
'border-b-0': noHighlight, | ||
}, | ||
); | ||
|
||
const contentClasses = cn( | ||
'h-auto flex-grow border-t border-background flex flex-col overflow-hidden items-center', | ||
); | ||
|
||
return ( | ||
<Panel title={title}> | ||
<NodeList items={nodes} nodeSize="sm" /> | ||
</Panel> | ||
<Accordion.Item value={id} asChild> | ||
<MotionSurface layout level={1} spacing="none" className={panelClasses}> | ||
<MotionTrigger | ||
layout | ||
className="flex cursor-pointer items-center justify-center p-4" | ||
> | ||
<Heading variant="h3" className="mb-0"> | ||
{title} | ||
</Heading> | ||
</MotionTrigger> | ||
<Accordion.Content className={contentClasses}> | ||
{expanded ? children : null} | ||
</Accordion.Content> | ||
</MotionSurface> | ||
</Accordion.Item> | ||
); | ||
} |
49 changes: 34 additions & 15 deletions
49
components/interview/interfaces/name-generator/NodePanels.tsx
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,27 +1,46 @@ | ||
'use client'; | ||
|
||
import type { Node } from '~/components/interview/NodeList'; | ||
import * as Accordion from '@radix-ui/react-accordion'; | ||
import { useState } from 'react'; | ||
import NodeList from '~/components/interview/NodeList'; | ||
import NodePanel from './NodePanel'; | ||
import { forwardRef, type ForwardedRef } from 'react'; | ||
import { useTranslations } from 'next-intl'; | ||
|
||
// TODO: Remove once connected to state | ||
type Panel = { | ||
id: string; | ||
title: string; | ||
nodes: Node[]; | ||
}; | ||
|
||
export default forwardRef(function NodePanels( | ||
{ panels }: { panels: Panel[] }, | ||
ref: ForwardedRef<HTMLDivElement>, | ||
) { | ||
const t = useTranslations(`Protocol.Panels`); | ||
type NodePanels = { | ||
panels: Panel[]; | ||
} & React.ComponentProps<'div'>; | ||
|
||
export default function NodePanels({ panels, ...rest }: NodePanels) { | ||
const [values, setValues] = useState<string[]>( | ||
panels.map((panel) => panel.id), | ||
); | ||
|
||
return ( | ||
<div id="data-wizard-task-step-2" ref={ref} className="flex flex-col gap-4"> | ||
{panels.map((panel) => { | ||
return ( | ||
<NodePanel key={panel.id} {...panel} title={t(`${panel.id}.Title`)} /> | ||
); | ||
})} | ||
</div> | ||
<Accordion.Root | ||
value={values} | ||
onValueChange={setValues} | ||
asChild | ||
type="multiple" | ||
> | ||
<div className="flex flex-col gap-4" {...rest}> | ||
{panels.map((panel) => ( | ||
<NodePanel | ||
key={panel.id} | ||
id={panel.id} | ||
title={panel.title} | ||
expanded={values.includes(panel.id)} | ||
> | ||
<NodeList items={panel.nodes} nodeSize="sm" /> | ||
</NodePanel> | ||
))} | ||
</div> | ||
</Accordion.Root> | ||
); | ||
}); | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.