From e1b7106b3cd33d73f4167796ebeb0decd301d1b8 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Wed, 8 Mar 2023 17:47:47 +0100 Subject: [PATCH 1/5] update playground examples to use a shared `Button` --- .../playground-react/components/button.tsx | 20 ++++++ packages/playground-react/package.json | 2 +- .../pages/combinations/form.tsx | 39 +++++------ .../pages/combinations/tabs-in-dialog.tsx | 15 ++-- .../combobox/combobox-with-pure-tailwind.tsx | 3 +- .../pages/dialog/dialog-focus-issue.tsx | 14 ++-- .../dialog/dialog-with-shadow-children.tsx | 8 +-- .../playground-react/pages/dialog/dialog.tsx | 69 +++++-------------- .../pages/menu/menu-with-framer-motion.tsx | 26 ++++--- .../pages/menu/menu-with-popper.tsx | 6 +- .../menu/menu-with-transition-and-popper.tsx | 6 +- .../pages/menu/menu-with-transition.tsx | 7 +- packages/playground-react/pages/menu/menu.tsx | 3 +- .../pages/menu/multiple-elements.tsx | 3 +- .../transitions/component-examples/modal.tsx | 4 -- .../component-examples/peek-a-boo.tsx | 6 -- .../playground-vue/src/components/Button.vue | 9 +++ .../src/components/dialog/dialog.vue | 68 +++++------------- 18 files changed, 128 insertions(+), 180 deletions(-) create mode 100644 packages/playground-react/components/button.tsx create mode 100644 packages/playground-vue/src/components/Button.vue diff --git a/packages/playground-react/components/button.tsx b/packages/playground-react/components/button.tsx new file mode 100644 index 0000000000..fa9cdb5d3e --- /dev/null +++ b/packages/playground-react/components/button.tsx @@ -0,0 +1,20 @@ +import { ComponentProps, forwardRef, ReactNode } from 'react' + +function classNames(...classes: (string | false | undefined | null)[]) { + return classes.filter(Boolean).join(' ') +} + +export let Button = forwardRef< + HTMLButtonElement, + ComponentProps<'button'> & { children?: ReactNode } +>(({ className, ...props }, ref) => ( + +
+
- - Tab 1 - Tab 2 - Tab 3 + + Tab 1 + Tab 2 + Tab 3 Panel 1 @@ -26,6 +27,6 @@ export default function App() {
- +
) } diff --git a/packages/playground-react/pages/combobox/combobox-with-pure-tailwind.tsx b/packages/playground-react/pages/combobox/combobox-with-pure-tailwind.tsx index 8e76c46b3d..e97cfafd3d 100644 --- a/packages/playground-react/pages/combobox/combobox-with-pure-tailwind.tsx +++ b/packages/playground-react/pages/combobox/combobox-with-pure-tailwind.tsx @@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react' import { Combobox } from '@headlessui/react' import { classNames } from '../../utils/class-names' +import { Button } from '../../components/button' let everybody = [ 'Wade Cooper', @@ -64,7 +65,7 @@ export default function Home() { onChange={(e) => setQuery(e.target.value)} className="border-none px-3 py-1 outline-none" /> - +
- - - + + +
@@ -23,12 +24,7 @@ export default function DialogFocusIssue() { return (

Headless UI Focus Jump

- +
diff --git a/packages/playground-react/pages/dialog/dialog-with-shadow-children.tsx b/packages/playground-react/pages/dialog/dialog-with-shadow-children.tsx index 61261c564b..f37a248026 100644 --- a/packages/playground-react/pages/dialog/dialog-with-shadow-children.tsx +++ b/packages/playground-react/pages/dialog/dialog-with-shadow-children.tsx @@ -1,6 +1,7 @@ import { useEffect, useRef } from 'react' import { useState } from 'react' import { Dialog } from '@headlessui/react' +import { Button } from '../../components/button' if (typeof document !== 'undefined') { class MyCustomElement extends HTMLElement { @@ -49,12 +50,7 @@ export default function App() { return (
- + setOpen(false)}>
diff --git a/packages/playground-react/pages/dialog/dialog.tsx b/packages/playground-react/pages/dialog/dialog.tsx index b617b59bd3..64d10ec9b0 100644 --- a/packages/playground-react/pages/dialog/dialog.tsx +++ b/packages/playground-react/pages/dialog/dialog.tsx @@ -3,6 +3,7 @@ import Flatpickr from 'react-flatpickr' import { Dialog, Menu, Portal, Transition } from '@headlessui/react' import { usePopper } from '../../utils/hooks/use-popper' import { classNames } from '../../utils/class-names' +import { Button } from '../../components/button' import 'flatpickr/dist/themes/light.css' @@ -14,16 +15,6 @@ function resolveClass({ active, disabled }) { ) } -function Button(props: React.ComponentProps<'button'>) { - return ( - @@ -70,11 +61,6 @@ export default function Home() {
{nested && setNested(false)} />} -
- -
+
- - + Choose a reason + - Choose a reason - - - - - + + +
-
- - +
+ +
diff --git a/packages/playground-react/pages/menu/menu-with-framer-motion.tsx b/packages/playground-react/pages/menu/menu-with-framer-motion.tsx index e68263c6c3..c51d158390 100644 --- a/packages/playground-react/pages/menu/menu-with-framer-motion.tsx +++ b/packages/playground-react/pages/menu/menu-with-framer-motion.tsx @@ -1,9 +1,10 @@ -import React from 'react' +import React, { forwardRef } from 'react' import Link from 'next/link' -import { Menu } from '@headlessui/react' +import { Menu, MenuItemProps } from '@headlessui/react' import { AnimatePresence, motion } from 'framer-motion' import { classNames } from '../../utils/class-names' +import { Button } from '../../components/button' export default function Home() { return ( @@ -13,7 +14,7 @@ export default function Home() { {({ open }) => ( <> - + Options ) { +let NextLink = forwardRef((props: React.ComponentProps<'a'>, ref) => { let { href, children, ...rest } = props return ( - {children} + + {children} + ) -} +}) -function SignOutButton(props) { +let SignOutButton = forwardRef((props, ref) => { return (
-
) -} +}) -function Item(props) { +let Item = forwardRef>((props, ref) => { return ( classNames( @@ -108,4 +112,4 @@ function Item(props) { {...props} /> ) -} +}) diff --git a/packages/playground-react/pages/menu/menu-with-popper.tsx b/packages/playground-react/pages/menu/menu-with-popper.tsx index e8ee320c91..43bab7a917 100644 --- a/packages/playground-react/pages/menu/menu-with-popper.tsx +++ b/packages/playground-react/pages/menu/menu-with-popper.tsx @@ -4,6 +4,7 @@ import { Menu } from '@headlessui/react' import { usePopper } from '../../utils/hooks/use-popper' import { classNames } from '../../utils/class-names' +import { Button } from '../../components/button' export default function Home() { let [trigger, container] = usePopper({ @@ -25,10 +26,7 @@ export default function Home() {
- + Options - + Options
-
- + Options - + Options - + Options -
diff --git a/packages/playground-react/pages/transitions/component-examples/peek-a-boo.tsx b/packages/playground-react/pages/transitions/component-examples/peek-a-boo.tsx index 1deeee541f..149c419ff8 100644 --- a/packages/playground-react/pages/transitions/component-examples/peek-a-boo.tsx +++ b/packages/playground-react/pages/transitions/component-examples/peek-a-boo.tsx @@ -18,12 +18,6 @@ export default function Home() { -