Skip to content
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

Headless UI v2 #3085

Merged
merged 15 commits into from
Jun 24, 2024
610 changes: 305 additions & 305 deletions .yarn/releases/yarn-4.3.0.cjs → .yarn/releases/yarn-4.2.2.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ enableGlobalCache: false

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.3.0.cjs
yarnPath: .yarn/releases/yarn-4.2.2.cjs
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we got many peer deps warning due to rework shipped in 4.3.0

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"last 1 safari version"
]
},
"packageManager": "yarn@4.3.0",
"packageManager": "yarn@4.2.2",
"engines": {
"node": "18.16.1"
},
Expand All @@ -35,7 +35,7 @@
"@ethersproject/abi": "5.7.0",
"@ethersproject/bignumber": "5.7.0",
"@gsap/react": "2.1.1",
"@headlessui/react": "1.7.19",
"@headlessui/react": "2.0.4",
"@hookform/error-message": "2.0.1",
"@hookform/resolvers": "3.3.4",
"@keplr-wallet/proto-types": "0.12.83",
Expand Down
3 changes: 2 additions & 1 deletion src/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default function App() {
return (
<ModalContext>
<SentryRoutes>
<Route path={`${appRoutes.donate}/:id`} element={<Donate />} />
Copy link
Collaborator Author

@ap-justin ap-justin Jun 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move /Donate to it's own layout instead of it just covering header | main | footer this prevents z-index clashes with the floating header and header dropdowns

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea!

<Route path={appRoutes.donate_widget}>
<Route path=":id" element={<DonateWidget />} />
<Route
Expand Down Expand Up @@ -82,7 +83,7 @@ export default function App() {
path={appRoutes.applications + "/:id"}
element={<Application />}
/>
<Route path={`${appRoutes.donate}/:id`} element={<Donate />} />

<Route path={appRoutes.donate_thanks} element={<DonateThanks />} />
<Route
path={appRoutes.stripe_payment_status}
Expand Down
15 changes: 10 additions & 5 deletions src/App/Header/NavDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Popover, Transition } from "@headlessui/react";
import {
Popover,
PopoverButton,
PopoverPanel,
Transition,
} from "@headlessui/react";
import ExtLink from "components/ExtLink";
import Icon from "components/Icon";
import LoaderRing from "components/LoaderRing";
Expand All @@ -20,7 +25,7 @@ export default function NavDropdown({ links }: Props) {
<Popover className="relative">
{({ open }) => (
<>
<Popover.Button
<PopoverButton
data-testid="nav_dropdown"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most of the changes are of this nature

Suggested change
<PopoverButton
<Popover.Button

className={`${
open ? "text-white" : "text-white/90"
Expand All @@ -42,7 +47,7 @@ export default function NavDropdown({ links }: Props) {
} max-sm:hidden transition duration-150 ease-in-out group-hover:text-blue-d7/80`}
aria-hidden="true"
/>
</Popover.Button>
</PopoverButton>
<Transition
as={Fragment}
enter="transition ease-out duration-200"
Expand All @@ -52,7 +57,7 @@ export default function NavDropdown({ links }: Props) {
leaveFrom="opacity-100 translate-y-0"
leaveTo="opacity-0 translate-y-1"
>
<Popover.Panel className="absolute right-0 z-10 mt-3 sm:w-screen max-w-80 shadow-[0px_8px_20px] shadow-gray-d1 rounded-lg bg-gray-l6 dark:bg-blue-d6 transform">
<PopoverPanel className="absolute right-0 z-10 mt-3 sm:w-screen max-w-80 shadow-[0px_8px_20px] shadow-gray-d1 rounded-lg bg-gray-l6 dark:bg-blue-d6 transform">
{({ close }) => (
<nav className="overflow-hidden grid gap-y-2 w-full p-6">
{links.map((link) =>
Expand Down Expand Up @@ -88,7 +93,7 @@ export default function NavDropdown({ links }: Props) {
)}
</nav>
)}
</Popover.Panel>
</PopoverPanel>
</Transition>
</>
)}
Expand Down
8 changes: 4 additions & 4 deletions src/components/CountrySelector/CountrySelector.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Combobox } from "@headlessui/react";
import { Combobox, ComboboxButton, ComboboxInput } from "@headlessui/react";
import { ErrorMessage } from "@hookform/error-message";
import { useState } from "react";
import {
Expand Down Expand Up @@ -57,11 +57,11 @@ export default function CountrySelector<
{country.flag || null}
</span>

<Combobox.Button>
<ComboboxButton>
{({ open }) => <DrawerIcon isOpen={open} size={25} className="mr-1" />}
</Combobox.Button>
</ComboboxButton>

<Combobox.Input
<ComboboxInput
ref={ref}
placeholder={props.placeholder}
onChange={(event) => setQuery(event.target.value as any)}
Expand Down
25 changes: 8 additions & 17 deletions src/components/CountrySelector/Options.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Combobox } from "@headlessui/react";
import { ComboboxOption, ComboboxOptions } from "@headlessui/react";
import { isEmpty } from "helpers";
import React from "react";
import type { Country } from "types/components";

const containerStyle =
Expand All @@ -16,29 +15,21 @@ export default function Options({ query, options }: Props) {
o.name.toLocaleLowerCase().includes(query.toLocaleLowerCase())
);
return (
<Combobox.Options
<ComboboxOptions
className={containerStyle}
style={{ height: options.length <= 10 ? "auto" : "10rem" }}
>
{(!isEmpty(options) &&
filtered.map((country) => (
<Combobox.Option
as={React.Fragment}
<ComboboxOption
className="data-[selected]:bg-blue-l2 hover:bg-blue-l2 flex items-center gap-2 p-2 text-sm font-heading"
key={country.name}
value={country}
>
{({ active }) => (
<li
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

active is depracated

className={`${
active ? "bg-blue-l2 dark:bg-blue-d1" : ""
} flex items-center gap-2 p-2 text-sm font-heading`}
>
<span className="text-2xl">{country.flag}</span>
<span>{country.name}</span>
</li>
)}
</Combobox.Option>
<span className="text-2xl">{country.flag}</span>
<span>{country.name}</span>
</ComboboxOption>
))) || <div className="p-2 text-sm">{query} not found</div>}
</Combobox.Options>
</ComboboxOptions>
);
}
29 changes: 12 additions & 17 deletions src/components/CurrencySelector/CurrencyOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Combobox } from "@headlessui/react";
import { ComboboxOption, ComboboxOptions } from "@headlessui/react";
import QueryLoader from "components/QueryLoader";
import type { CurrencyOption } from "types/components";
import type { QueryState } from "types/third-party/redux";
Expand Down Expand Up @@ -48,25 +48,20 @@ export default function CurrencyOptions({
}}
>
{(currencies) => (
<Combobox.Options
className={`${classes} w-full bg-white dark:bg-blue-d6 shadow-lg rounded max-h-52 overflow-y-auto scroller text-base ring-1 ring-black ring-opacity-5 focus:outline-none`}
<ComboboxOptions
anchor="bottom"
className={`${classes} w-[var(--input-width)] bg-white dark:bg-blue-d6 shadow-lg rounded [--anchor-max-height:13rem] overflow-y-auto scroller text-base ring-1 ring-black ring-opacity-5 focus:outline-none`}
>
{currencies.map(({ code, name, min, rate }) => (
<Combobox.Option key={code} value={{ code, name, min, rate }}>
{({ active, selected }) => (
<div
className={`${active ? "bg-[--accent-secondary]" : ""} ${
selected ? "font-semibold" : "font-normal"
} flex items-center gap-2 p-2 cursor-pointer truncate`}
>
{!!name
? `${code.toUpperCase()} - ${name}`
: code.toUpperCase()}
</div>
)}
</Combobox.Option>
<ComboboxOption
key={code}
value={{ code, name, min, rate }}
className="flex items-center gap-2 p-2 cursor-pointer truncate data-[selected]:bg-[--accent-secondary] hover:bg-[--accent-secondary]"
>
{!!name ? `${code.toUpperCase()} - ${name}` : code.toUpperCase()}
</ComboboxOption>
))}
</Combobox.Options>
</ComboboxOptions>
)}
</QueryLoader>
);
Expand Down
12 changes: 6 additions & 6 deletions src/components/CurrencySelector/CurrencySelector.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Combobox } from "@headlessui/react";
import { Combobox, ComboboxButton, ComboboxInput } from "@headlessui/react";
import Icon from "components/Icon/Icon";
import { unpack } from "helpers";
import { useState } from "react";
Expand Down Expand Up @@ -54,9 +54,9 @@ export default function CurrencySelector<T extends CurrencyOption>({
as="div"
className={`relative items-center grid grid-cols-[1fr_auto] field-container ${style.combobox}`}
>
<Combobox.Input
<ComboboxInput
id="wise__currency"
className="w-full border-r border-gray-l3 dark:border-navy px-4 py-3.5 text-sm leading-5 focus:ring-0"
className="w-full dark:border-navy px-4 py-3.5 text-sm leading-5 focus:ring-0"
displayValue={(currency: T) =>
!!currency.name
? `${currency.code.toUpperCase()} - ${currency.name}`
Expand All @@ -65,7 +65,7 @@ export default function CurrencySelector<T extends CurrencyOption>({
onChange={(event) => setQuery(event.target.value)}
spellCheck={false}
/>
<Combobox.Button className="flex items-center px-2">
<ComboboxButton className="flex items-center absolute inset-y-0 right-2">
{({ open }) =>
isCurrencyLoading ? (
<Icon
Expand All @@ -77,12 +77,12 @@ export default function CurrencySelector<T extends CurrencyOption>({
<DrawerIcon
isOpen={open}
size={25}
className={`h-full w-full ${isCurrencyError ? "text-red" : ""}`}
className={`${isCurrencyError ? "text-red" : ""}`}
aria-hidden
/>
)
}
</Combobox.Button>
</ComboboxButton>

<CurrencyOptions
query={query}
Expand Down
14 changes: 7 additions & 7 deletions src/components/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Dialog, Transition } from "@headlessui/react";
import { DialogPanel, DialogTitle, TransitionChild } from "@headlessui/react";
import React, { type FC } from "react";

const ModalFn: FC<any> = (props) => (
<Transition.Child
<TransitionChild
as={React.Fragment}
enter="transform ease-out duration-300"
enterFrom="opacity-0"
Expand All @@ -11,14 +11,14 @@ const ModalFn: FC<any> = (props) => (
leaveFrom="opacity-100"
leaveTo="opacity-0"
>
<Dialog.Panel {...props} />
</Transition.Child>
<DialogPanel {...props} />
</TransitionChild>
);

const TitleFn: FC<any> = (props) => <Dialog.Title {...props} />;
const TitleFn: FC<any> = (props) => <DialogTitle {...props} />;

const ModalFnRoot = ModalFn as typeof Dialog.Panel;
const Title = TitleFn as typeof Dialog.Title;
const ModalFnRoot = ModalFn as typeof DialogPanel;
const Title = TitleFn as typeof DialogTitle;

const Modal = Object.assign(ModalFnRoot, { Title });

Expand Down
28 changes: 14 additions & 14 deletions src/components/Selector/MultiSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Combobox } from "@headlessui/react";
import {
Combobox,
ComboboxButton,
ComboboxInput,
ComboboxOption,
ComboboxOptions,
} from "@headlessui/react";
import { ErrorMessage } from "@hookform/error-message";
import Icon, { DrawerIcon } from "components/Icon";
import { isEmpty } from "helpers";
Expand Down Expand Up @@ -64,7 +70,7 @@ export function MultiSelector<
multiple
>
<FocusableInput ref={ref} />
<Combobox.Button
<ComboboxButton
aria-invalid={invalid}
aria-disabled={isDisabled}
as="div"
Expand All @@ -84,7 +90,7 @@ export function MultiSelector<
{searchable ? (
<div className="inline-flex items-center gap-2 text-navy-l1 dark:text-navy-l2 pl-3 bg-white/5 rounded">
<Icon type="Search" size={20} />
<Combobox.Input
<ComboboxInput
className="appearance-none bg-transparent first:pl-3 focus:outline-none h-10"
value={searchText}
onChange={(e) => setSearchText(e.target.value)}
Expand All @@ -105,8 +111,8 @@ export function MultiSelector<
/>
</>
)}
</Combobox.Button>
<Combobox.Options className={`${styles.options} ${cls.options}`}>
</ComboboxButton>
<ComboboxOptions className={`${styles.options} ${cls.options}`}>
{optionsAvailable && (
<div className="flex justify-between p-4">
{isAllSelected ? (
Expand All @@ -125,22 +131,16 @@ export function MultiSelector<

{optionsAvailable &&
filteredOptions.map((o) => (
<Combobox.Option
key={o.value}
value={o}
className={({ active, selected }) =>
styles.option(selected, active)
}
>
<ComboboxOption key={o.value} value={o} className={styles.option}>
{o.label}
</Combobox.Option>
</ComboboxOption>
))}
{!optionsAvailable && (
<p className="text-navy-l1 dark:text-navy-l2 text-sm px-4 py-2">
No options found
</p>
)}
</Combobox.Options>
</ComboboxOptions>
<ErrorMessage
name={name}
errors={errors}
Expand Down
23 changes: 13 additions & 10 deletions src/components/Selector/NativeSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Listbox } from "@headlessui/react";
import {
Listbox,
ListboxButton,
ListboxOption,
ListboxOptions,
} from "@headlessui/react";
import { DrawerIcon } from "components/Icon";
import { unpack } from "helpers";
import { type AriaAttributes, forwardRef } from "react";
Expand Down Expand Up @@ -31,7 +36,7 @@ export const NativeSelect = forwardRef(function Select<V extends ValKey>(
className="relative"
>
<FocusableInput ref={ref} />
<Listbox.Button
<ListboxButton
aria-invalid={props["aria-invalid"]}
aria-disabled={props.disabled}
id={props.id}
Expand All @@ -48,20 +53,18 @@ export const NativeSelect = forwardRef(function Select<V extends ValKey>(
/>
</>
)}
</Listbox.Button>
<Listbox.Options className={`${styles.options} ${cls.options}`}>
</ListboxButton>
<ListboxOptions className={`${styles.options} ${cls.options}`}>
{(props.options ?? []).map((o) => (
<Listbox.Option
<ListboxOption
key={o.value}
value={o.value}
className={({ active, selected }) =>
styles.option(selected, active)
}
className={styles.option}
>
{o.label}
</Listbox.Option>
</ListboxOption>
))}
</Listbox.Options>
</ListboxOptions>
</Listbox>
);
});
Loading
Loading