mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-07-07 22:18:39 +00:00
fix(cli): deduplicate classNames in applyColorMapping (#1089)
* fix(cli): deduplicate classNames in applyColorMapping * refactor: simplify applyColorMapping return * chore: add changeset --------- Co-authored-by: shadcn <m@shadcn.com>
This commit is contained in:
@@ -146,27 +146,27 @@ export function applyColorMapping(
|
||||
|
||||
// Build color mappings.
|
||||
const classNames = input.split(" ")
|
||||
const lightMode: string[] = []
|
||||
const darkMode: string[] = []
|
||||
const lightMode = new Set<string>()
|
||||
const darkMode = new Set<string>()
|
||||
for (let className of classNames) {
|
||||
const [variant, value, modifier] = splitClassName(className)
|
||||
const prefix = PREFIXES.find((prefix) => value?.startsWith(prefix))
|
||||
if (!prefix) {
|
||||
if (!lightMode.includes(className)) {
|
||||
lightMode.push(className)
|
||||
if (!lightMode.has(className)) {
|
||||
lightMode.add(className)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
const needle = value?.replace(prefix, "")
|
||||
if (needle && needle in mapping.light) {
|
||||
lightMode.push(
|
||||
lightMode.add(
|
||||
[variant, `${prefix}${mapping.light[needle]}`]
|
||||
.filter(Boolean)
|
||||
.join(":") + (modifier ? `/${modifier}` : "")
|
||||
)
|
||||
|
||||
darkMode.push(
|
||||
darkMode.add(
|
||||
["dark", variant, `${prefix}${mapping.dark[needle]}`]
|
||||
.filter(Boolean)
|
||||
.join(":") + (modifier ? `/${modifier}` : "")
|
||||
@@ -174,10 +174,10 @@ export function applyColorMapping(
|
||||
continue
|
||||
}
|
||||
|
||||
if (!lightMode.includes(className)) {
|
||||
lightMode.push(className)
|
||||
if (!lightMode.has(className)) {
|
||||
lightMode.add(className)
|
||||
}
|
||||
}
|
||||
|
||||
return lightMode.join(" ") + " " + darkMode.join(" ").trim()
|
||||
return [...Array.from(lightMode), ...Array.from(darkMode)].join(" ").trim()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user