* fix(listbox): item classNames prop, listbox wrapper export

* chore(listbox): changesets
This commit is contained in:
Junior Garcia 2023-09-14 21:53:26 -03:00 committed by GitHub
parent 59ed34b3de
commit 3aa86423aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 29 additions and 12 deletions

View File

@ -0,0 +1,5 @@
---
"@nextui-org/listbox": patch
---
Fix #1625 Listbox item classNames

View File

@ -100,7 +100,7 @@ const DeleteDocumentIcon = `export const DeleteDocumentIcon = (props) => (
</svg>
);`;
const ListboxWrapper = `const ListboxWrapper = ({children}) => (
const ListboxWrapper = `export const ListboxWrapper = ({children}) => (
<div className="w-full max-w-[260px] border-small px-1 py-2 rounded-small border-default-200 dark:border-default-100">
{children}
</div>

View File

@ -1,4 +1,4 @@
const ListboxWrapper = `const ListboxWrapper = ({children}) => (
const ListboxWrapper = `export const ListboxWrapper = ({children}) => (
<div className="w-full max-w-[260px] border-small px-1 py-2 rounded-small border-default-200 dark:border-default-100">
{children}
</div>

View File

@ -1,4 +1,4 @@
const ListboxWrapper = `const ListboxWrapper = ({children}) => (
const ListboxWrapper = `export const ListboxWrapper = ({children}) => (
<div className="w-full max-w-[260px] border-small px-1 py-2 rounded-small border-default-200 dark:border-default-100">
{children}
</div>

View File

@ -100,7 +100,7 @@ const DeleteDocumentIcon = `export const DeleteDocumentIcon = (props) => (
</svg>
);`;
const ListboxWrapper = `const ListboxWrapper = ({children}) => (
const ListboxWrapper = `export const ListboxWrapper = ({children}) => (
<div className="w-full max-w-[260px] border-small px-1 py-2 rounded-small border-default-200 dark:border-default-100">
{children}
</div>

View File

@ -1,4 +1,4 @@
const ListboxWrapper = `const ListboxWrapper = ({children}) => (
const ListboxWrapper = `export const ListboxWrapper = ({children}) => (
<div className="w-[260px] border-small px-1 py-2 rounded-small border-default-200 dark:border-default-100">
{children}
</div>

View File

@ -100,7 +100,7 @@ const DeleteDocumentIcon = `export const DeleteDocumentIcon = (props) => (
</svg>
);`;
const ListboxWrapper = `const ListboxWrapper = ({children}) => (
const ListboxWrapper = `export const ListboxWrapper = ({children}) => (
<div className="w-full max-w-[260px] border-small px-1 py-2 rounded-small border-default-200 dark:border-default-100">
{children}
</div>

View File

@ -1,4 +1,4 @@
const ListboxWrapper = `const ListboxWrapper = ({children}) => (
const ListboxWrapper = `export const ListboxWrapper = ({children}) => (
<div className="w-full max-w-[260px] border-small px-1 py-2 rounded-small border-default-200 dark:border-default-100">
{children}
</div>

View File

@ -1,4 +1,4 @@
const ListboxWrapper = `const ListboxWrapper = ({children}) => (
const ListboxWrapper = `export const ListboxWrapper = ({children}) => (
<div className="w-full max-w-[260px] border-small px-1 py-2 rounded-small border-default-200 dark:border-default-100">
{children}
</div>

View File

@ -12,8 +12,6 @@ export interface ListboxItemProps<T extends object = object> extends UseListboxI
const ListboxItem = forwardRef<"li", ListboxItemProps>((props, _) => {
const {
Component,
slots,
classNames,
rendered,
description,
isSelectable,
@ -25,6 +23,7 @@ const ListboxItem = forwardRef<"li", ListboxItemProps>((props, _) => {
disableAnimation,
getItemProps,
getLabelProps,
getWrapperProps,
getDescriptionProps,
getSelectedIconProps,
} = useListboxItem(props);
@ -47,7 +46,7 @@ const ListboxItem = forwardRef<"li", ListboxItemProps>((props, _) => {
<Component {...getItemProps()}>
{startContent}
{description ? (
<div className={slots.wrapper({class: classNames?.wrapper})}>
<div {...getWrapperProps()}>
<span {...getLabelProps()}>{rendered}</span>
<span {...getDescriptionProps()}>{description}</span>
</div>

View File

@ -1,6 +1,7 @@
import type {ForwardedRef, ReactElement, Ref} from "react";
import {forwardRef} from "@nextui-org/system";
import {mergeProps} from "@react-aria/utils";
import {UseListboxProps, useListbox} from "./use-listbox";
import ListboxSection from "./listbox-section";
@ -27,7 +28,13 @@ function Listbox<T extends object>(props: Props<T>, ref: ForwardedRef<HTMLUListE
if (item.type === "section") {
return <ListboxSection key={item.key} {...itemProps} itemClasses={itemClasses} />;
}
let listboxItem = <ListboxItem key={item.key} {...itemProps} classNames={itemClasses} />;
let listboxItem = (
<ListboxItem
key={item.key}
{...itemProps}
classNames={mergeProps(itemClasses, item.props?.classNames)}
/>
);
if (item.wrapper) {
listboxItem = item.wrapper(listboxItem);

View File

@ -132,6 +132,11 @@ export function useListboxItem<T extends object>(originalProps: UseListboxItemPr
className: slots.description({class: classNames?.description}),
});
const getWrapperProps: PropGetter = (props = {}) => ({
...mergeProps(props),
className: slots.wrapper({class: classNames?.wrapper}),
});
const getSelectedIconProps = useCallback<PropGetter>(
(props = {}) => {
return {
@ -160,6 +165,7 @@ export function useListboxItem<T extends object>(originalProps: UseListboxItemPr
disableAnimation,
getItemProps,
getLabelProps,
getWrapperProps,
getDescriptionProps,
getSelectedIconProps,
};