-
-
Notifications
You must be signed in to change notification settings - Fork 497
feat(accordion): add slide animation. #1659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| import { Accordion, AccordionContent, AccordionPanel, AccordionTitle } from "flowbite-react"; | ||
| import type { CodeData } from "~/components/code-demo"; | ||
|
|
||
| const code = ` | ||
| import { Accordion, AccordionContent, AccordionPanel, AccordionTitle } from "flowbite-react"; | ||
|
|
||
| export function Component() { | ||
| return ( | ||
| <Accordion animate animationDuration={300}> | ||
| <AccordionPanel> | ||
| <AccordionTitle>What is Flowbite?</AccordionTitle> | ||
| <AccordionContent> | ||
| <p className="mb-2 text-gray-500 dark:text-gray-400"> | ||
| Flowbite is an open-source library of interactive components built on top of Tailwind CSS including buttons, | ||
| dropdowns, modals, navbars, and more. | ||
| </p> | ||
| <p className="text-gray-500 dark:text-gray-400"> | ||
| Check out this guide to learn how to | ||
| <a | ||
| href="https://flowbite.com/docs/getting-started/introduction/" | ||
| className="text-cyan-600 hover:underline dark:text-cyan-500" | ||
| > | ||
| get started | ||
| </a> | ||
| and start developing websites even faster with components on top of Tailwind CSS. | ||
| </p> | ||
| </AccordionContent> | ||
| </AccordionPanel> | ||
| <AccordionPanel> | ||
| <AccordionTitle>Is there a Figma file available?</AccordionTitle> | ||
| <AccordionContent> | ||
| <p className="mb-2 text-gray-500 dark:text-gray-400"> | ||
| Flowbite is first conceptualized and designed using the Figma software so everything you see in the library | ||
| has a design equivalent in our Figma file. | ||
| </p> | ||
| <p className="text-gray-500 dark:text-gray-400"> | ||
| Check out the | ||
| <a href="https://flowbite.com/figma/" className="text-cyan-600 hover:underline dark:text-cyan-500"> | ||
| Figma design system | ||
| </a> | ||
| based on the utility classes from Tailwind CSS and components from Flowbite. | ||
| </p> | ||
| </AccordionContent> | ||
| </AccordionPanel> | ||
| <AccordionPanel> | ||
| <AccordionTitle>What are the differences between Flowbite and Tailwind UI?</AccordionTitle> | ||
| <AccordionContent> | ||
| <p className="mb-2 text-gray-500 dark:text-gray-400"> | ||
| The main difference is that the core components from Flowbite are open source under the MIT license, whereas | ||
| Tailwind UI is a paid product. Another difference is that Flowbite relies on smaller and standalone | ||
| components, whereas Tailwind UI offers sections of pages. | ||
| </p> | ||
| <p className="mb-2 text-gray-500 dark:text-gray-400"> | ||
| However, we actually recommend using both Flowbite, Flowbite Pro, and even Tailwind UI as there is no | ||
| technical reason stopping you from using the best of two worlds. | ||
| </p> | ||
| <p className="mb-2 text-gray-500 dark:text-gray-400">Learn more about these technologies:</p> | ||
| <ul className="list-disc pl-5 text-gray-500 dark:text-gray-400"> | ||
| <li> | ||
| <a href="https://flowbite.com/pro/" className="text-cyan-600 hover:underline dark:text-cyan-500"> | ||
| Flowbite Pro | ||
| </a> | ||
| </li> | ||
| <li> | ||
| <a | ||
| href="https://tailwindui.com/" | ||
| rel="nofollow" | ||
| className="text-cyan-600 hover:underline dark:text-cyan-500" | ||
| > | ||
| Tailwind UI | ||
| </a> | ||
| </li> | ||
| </ul> | ||
| </AccordionContent> | ||
| </AccordionPanel> | ||
| </Accordion> | ||
| ); | ||
| } | ||
| `; | ||
|
|
||
| export function Component() { | ||
| return ( | ||
| <Accordion animate animationDuration={300}> | ||
| <AccordionPanel> | ||
| <AccordionTitle>What is Flowbite?</AccordionTitle> | ||
| <AccordionContent> | ||
| <p className="mb-2 text-gray-500 dark:text-gray-400"> | ||
| Flowbite is an open-source library of interactive components built on top of Tailwind CSS including buttons, | ||
| dropdowns, modals, navbars, and more. | ||
| </p> | ||
| <p className="text-gray-500 dark:text-gray-400"> | ||
| Check out this guide to learn how to | ||
| <a | ||
| href="https://flowbite.com/docs/getting-started/introduction/" | ||
| className="text-cyan-600 hover:underline dark:text-cyan-500" | ||
| > | ||
| get started | ||
| </a> | ||
| and start developing websites even faster with components on top of Tailwind CSS. | ||
| </p> | ||
| </AccordionContent> | ||
| </AccordionPanel> | ||
| <AccordionPanel> | ||
| <AccordionTitle>Is there a Figma file available?</AccordionTitle> | ||
| <AccordionContent> | ||
| <p className="mb-2 text-gray-500 dark:text-gray-400"> | ||
| Flowbite is first conceptualized and designed using the Figma software so everything you see in the library | ||
| has a design equivalent in our Figma file. | ||
| </p> | ||
| <p className="text-gray-500 dark:text-gray-400"> | ||
| Check out the | ||
| <a href="https://flowbite.com/figma/" className="text-cyan-600 hover:underline dark:text-cyan-500"> | ||
| Figma design system | ||
| </a> | ||
| based on the utility classes from Tailwind CSS and components from Flowbite. | ||
| </p> | ||
| </AccordionContent> | ||
| </AccordionPanel> | ||
| <AccordionPanel> | ||
| <AccordionTitle>What are the differences between Flowbite and Tailwind UI?</AccordionTitle> | ||
| <AccordionContent> | ||
| <p className="mb-2 text-gray-500 dark:text-gray-400"> | ||
| The main difference is that the core components from Flowbite are open source under the MIT license, whereas | ||
| Tailwind UI is a paid product. Another difference is that Flowbite relies on smaller and standalone | ||
| components, whereas Tailwind UI offers sections of pages. | ||
| </p> | ||
| <p className="mb-2 text-gray-500 dark:text-gray-400"> | ||
| However, we actually recommend using both Flowbite, Flowbite Pro, and even Tailwind UI as there is no | ||
| technical reason stopping you from using the best of two worlds. | ||
| </p> | ||
| <p className="mb-2 text-gray-500 dark:text-gray-400">Learn more about these technologies:</p> | ||
| <ul className="list-disc pl-5 text-gray-500 dark:text-gray-400"> | ||
| <li> | ||
| <a href="https://flowbite.com/pro/" className="text-cyan-600 hover:underline dark:text-cyan-500"> | ||
| Flowbite Pro | ||
| </a> | ||
| </li> | ||
| <li> | ||
| <a | ||
| href="https://tailwindui.com/" | ||
| rel="nofollow" | ||
| className="text-cyan-600 hover:underline dark:text-cyan-500" | ||
| > | ||
| Tailwind UI | ||
| </a> | ||
| </li> | ||
| </ul> | ||
| </AccordionContent> | ||
| </AccordionPanel> | ||
| </Accordion> | ||
| ); | ||
| } | ||
|
|
||
| export const animation: CodeData = { | ||
| type: "single", | ||
| code: { | ||
| fileName: "index", | ||
| language: "tsx", | ||
| code, | ||
| }, | ||
| githubSlug: "accordion/accordion.animation.tsx", | ||
| component: <Component />, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| export { animation } from "./accordion.animation"; | ||
| export { collapseAll } from "./accordion.collapseAll"; | ||
| export { root } from "./accordion.root"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,10 @@ export interface AccordionRootTheme { | |
|
|
||
| export interface AccordionProps extends ComponentProps<"div">, ThemingProps<AccordionRootTheme> { | ||
| alwaysOpen?: boolean; | ||
| /** Enable smooth open/close animation for panel content. */ | ||
| animate?: boolean; | ||
| /** Duration of the open/close animation in milliseconds. Only used when `animate` is true. Defaults to 300. */ | ||
| animationDuration?: number; | ||
| arrowIcon?: FC<ComponentProps<"svg">>; | ||
| children: ReactElement<AccordionPanelProps> | ReactElement<AccordionPanelProps>[]; | ||
| flush?: boolean; | ||
|
|
@@ -43,6 +47,8 @@ export function Accordion(props: AccordionProps) { | |
|
|
||
| const { | ||
| alwaysOpen = false, | ||
| animate = false, | ||
| animationDuration = 300, | ||
|
Comment on lines
+50
to
+51
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard Line 51 defaults only when the prop is Suggested fix- const {
+ const {
alwaysOpen = false,
animate = false,
- animationDuration = 300,
+ animationDuration: animationDurationProp = 300,
arrowIcon = ChevronDownIcon,
children,
flush = false,
collapseAll = false,
className,
...restProps
} = resolveProps(props, provider.props?.accordion);
+
+ const animationDuration =
+ Number.isFinite(animationDurationProp) && animationDurationProp >= 0 ? animationDurationProp : 300;🤖 Prompt for AI Agents |
||
| arrowIcon = ChevronDownIcon, | ||
| children, | ||
| flush = false, | ||
|
|
@@ -58,13 +64,15 @@ export function Accordion(props: AccordionProps) { | |
| Children.map(children, (child, i) => | ||
| cloneElement(child, { | ||
| alwaysOpen, | ||
| animate, | ||
| animationDuration, | ||
| arrowIcon, | ||
| flush, | ||
| isOpen: isOpen === i, | ||
| setOpen: () => setOpen(isOpen === i ? -1 : i), | ||
| }), | ||
| ), | ||
| [alwaysOpen, arrowIcon, children, flush, isOpen], | ||
| [alwaysOpen, animate, animationDuration, arrowIcon, children, flush, isOpen], | ||
| ); | ||
|
|
||
| return ( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.