-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: menu item classNames not work (#4156)
* fix: menu item classNames not work * feat: changeset * docs: update * feat: merge classes utility added * Update .changeset/brave-trains-wave.md --------- Co-authored-by: WK Wong <[email protected]> Co-authored-by: Junior Garcia <[email protected]>
- Loading branch information
1 parent
c8f2ec8
commit d37007c
Showing
6 changed files
with
80 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@nextui-org/menu": patch | ||
"@nextui-org/theme": patch | ||
--- | ||
|
||
Fix menu item classNames not work (#4119) |
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type {SlotsToClasses} from "./types"; | ||
|
||
import {clsx} from "@nextui-org/shared-utils"; | ||
|
||
/** | ||
* Merges two sets of class names for each slot in a component. | ||
* @param itemClasses - Base classes for each slot | ||
* @param itemPropsClasses - Additional classes from props for each slot | ||
* @returns A merged object containing the combined classes for each slot | ||
*/ | ||
export const mergeClasses = <T extends SlotsToClasses<string>, P extends SlotsToClasses<string>>( | ||
itemClasses?: T, | ||
itemPropsClasses?: P, | ||
): T => { | ||
if (!itemClasses && !itemPropsClasses) return {} as T; | ||
|
||
const keys = new Set([...Object.keys(itemClasses || {}), ...Object.keys(itemPropsClasses || {})]); | ||
|
||
return Array.from(keys).reduce( | ||
(acc, key) => ({ | ||
...acc, | ||
[key]: clsx(itemClasses?.[key], itemPropsClasses?.[key]), | ||
}), | ||
{} as T, | ||
); | ||
}; |