mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
* fix(date-picker): error state (#5317) * fix(date-range-picker): fixed the error state in preset * Update giant-sloths-shop.md * Removed if statement * chore(date-picker): prettier --------- Co-authored-by: WK Wong <wingkwong.code@gmail.com> * fix(theme): clear button in mobile (#5252) * fix(toast): fixed close button hover position * fix(input): fixed the clear button rendering on smaller devices * Delete .changeset/soft-spoons-march.md * Update input.ts * Undo unrelated toast changes * fix(toast): icons (#5246) * feat(shared-icons): add loading icon * fix(toast): icons * chore(toast): revise types for icons * chore(changeset): add changeset * refactor: migrate eslint to v9 (#5267) * refactor: migrate eslint to v9 * chore: lint * chore: update eslint command * chore: fix lint warnings * chore: separate lint and lint:fix * chore: exclude contentlayer generated code * fix(scripts): add missing await * fix(autocomplete): persist last selected item position (#5286) * refactor(select): remove unnecessary code * fix(autocomplete): persist last selected item position * chore(changeset): add changeset * chore(deps): bump framer-motion version (#5287) * chore(deps): bump framer-motion version * fix: typing issues * chore(changeset): add changeset --------- Co-authored-by: Junior Garcia <jrgarciadev@gmail.com> * chore(docs): supplement onAction & selectionBehavior (#5289) * fix(autocomplete): ensure focused item matches selected item after filter, selection (#5290) * fix(autocomplete): ensure focused item matches selected item after filter, selection * chore: apply type and default value * chore: add perpose coment in updated code * test: add focuskey management testcode * docs: add changeset * docs: update changeset * chore: remove comment * fix: broken components in stories (#5291) * chore(switch): remove xl size * chore(docs): remove xl size * chore(system-rsc): remove xl size * chore(circular-progress): remove xl size * chore: undo * chore(deps): bump RA versions (#5310) * chore(deps): ra version bump * chore(changeset): add changeset * fix(scripts): incorrect docs path --------- Co-authored-by: Junior Garcia <jrgarciadev@gmail.com> * chore(docs): update meta data (#5311) * docs(layout.tsx): added text-foreground (#5316) * feat(tabs): add click handling for tab items in tests and implementation (#3917) Co-authored-by: WK Wong <wingkwong.code@gmail.com> * fix issues in tabs examples (#2405) Co-authored-by: WK Wong <wingkwong.code@gmail.com> * chore(docs): add missing onValueChange in CheckboxGroup (#5332) * ci(changesets): version packages (#5323) Co-authored-by: Junior Garcia <jrgarciadev@gmail.com> * chore(deps): bump RA versions (#5361) * chore(deps): bump RA versions * chore(deps): bump RA versions * chore(deps): bump RA versions * chore: changeset * refactor(listbox): already extends in AriaListBoxProps * chore(docs): remove herohack announcement (#5363) * chore: remove herohack announcement * Update carbon-ad.tsx * chore(docs): fixed lint errors * chore(docs): requested changes * Update carbon-ad.tsx * Update carbon-ad.tsx * fix(theme): consistent faded styling for isInvalid in InputOtp and DateInput (#5349) * fix(input-otp): remove bg and border styles from faded variant when isInvalid * fix(date-input): remove bg styles from faded variant when isInvalid * chore(changeset): add changeset * chore: bump theme peerDependencies * chore: bump theme peerDependencies * fix: wrong version * chore: extra line --------- Co-authored-by: WK Wong <wingkwong.code@gmail.com> * fix(theme): helperWrapper padding (#5350) * fix(number-input): decreased helperWrapper padding to maintain consistency * Update beige-laws-heal.md * chore(theme): change to p-1 * chore(deps): bump peerDependencies for theme pkg * fix(number-input): incorrect versions * chore(changeset): include number input --------- Co-authored-by: WK Wong <wingkwong.code@gmail.com> * fix(autocomplete): onClear (#5365) * fix(autocomplete): add onClear * feat(autocomplete): add test case for onClear * chore(changeset): add changeset * fix(number-input): only allow number type (#5368) * refactor(number-input): avoid non number type passing to number input * chore(changeset): add changeset * refactor: optimization (#5362) * chore(deps): bump RA versions * chore(deps): bump RA versions * chore(deps): bump RA versions * chore: changeset * chore(deps): remove unnecessary dependencies * fix(calendar): typing issue * refactor(system): remove unused SupportedCalendars * refactor(system): move I18nProviderProps to type * refactor: use `spectrumCalendarProps<DateValue>["createCalendar"]` * feat: add consistent-type-imports * fix: eslint * chore: add changeset * refactor: remove unused deps * ci(changesets): version packages (#5364) Co-authored-by: Junior Garcia <jrgarciadev@gmail.com> --------- Co-authored-by: Vishv Salvi <82429084+Vishvsalvi@users.noreply.github.com> Co-authored-by: Junior Garcia <jrgarciadev@gmail.com> Co-authored-by: KumJungMin <37934668+KumJungMin@users.noreply.github.com> Co-authored-by: liaoyinglong <vigossliao@gmail.com> Co-authored-by: zhengjitf <zhengjitf@gmail.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Anuj Kuralkar <76731106+anuj-kuralkar@users.noreply.github.com>
231 lines
8.0 KiB
TypeScript
231 lines
8.0 KiB
TypeScript
import type {ColorPickerType, Config, ConfigLayout, ThemeType, ThemeColor} from "./types";
|
|
|
|
import {readableColor} from "color2k";
|
|
|
|
import {colorsId, baseColorsId, showcaseId, otherColorsId, defaultColorsId} from "./constants";
|
|
import {generateThemeColor, hexToHsl} from "./utils/colors";
|
|
import {templates} from "./templates";
|
|
|
|
export function setCssColor(
|
|
colorType: ColorPickerType,
|
|
value: string,
|
|
heroUIValue: string,
|
|
theme: ThemeType,
|
|
) {
|
|
const baseColorEl = document.getElementById(colorsId);
|
|
const commonColorsEl = document.getElementById(baseColorsId);
|
|
const showcaseEl = document.getElementById(showcaseId);
|
|
const defaultColorEl = document.getElementById(defaultColorsId);
|
|
const configurationContainer = document.getElementById("configuration-container");
|
|
|
|
const themeColor = generateThemeColor(value, colorType, theme);
|
|
const heroThemeColor = generateThemeColor(heroUIValue, colorType, theme);
|
|
|
|
if (!baseColorEl || !commonColorsEl || !showcaseEl || !defaultColorEl) {
|
|
// eslint-disable-next-line no-console
|
|
console.error("One or more required elements are missing from the DOM.");
|
|
|
|
return;
|
|
}
|
|
|
|
Object.keys(themeColor).forEach((key) => {
|
|
const value = hexToHsl(themeColor[key as keyof ThemeColor]);
|
|
const heroValue = hexToHsl(heroThemeColor[key as keyof ThemeColor]);
|
|
|
|
if (key === "DEFAULT") {
|
|
baseColorEl.style.setProperty(`--heroui-${colorType}`, value);
|
|
commonColorsEl.style.setProperty(`--heroui-${colorType}`, value);
|
|
showcaseEl.style.setProperty(`--heroui-${colorType}`, value);
|
|
defaultColorEl.style.setProperty(`--heroui-${colorType}`, value);
|
|
configurationContainer?.style.setProperty(`--heroui-${colorType}`, heroValue);
|
|
} else {
|
|
baseColorEl.style.setProperty(`--heroui-${colorType}-${key}`, value);
|
|
commonColorsEl.style.setProperty(`--heroui-${colorType}-${key}`, value);
|
|
showcaseEl.style.setProperty(`--heroui-${colorType}-${key}`, value);
|
|
defaultColorEl.style.setProperty(`--heroui-${colorType}`, value);
|
|
configurationContainer?.style.setProperty(`--heroui-${colorType}-${key}`, heroValue);
|
|
}
|
|
});
|
|
}
|
|
|
|
export function setCssBackground(value: string) {
|
|
const showcaseEl = document.getElementById(showcaseId);
|
|
const baseColor = document.getElementById(baseColorsId);
|
|
const hslValue = hexToHsl(value);
|
|
|
|
baseColor?.style.setProperty("--heroui-background", hslValue);
|
|
showcaseEl?.style.setProperty("--heroui-background", hslValue);
|
|
}
|
|
|
|
export function setCssFontSize(type: keyof ConfigLayout["fontSize"], value: string) {
|
|
const el = document.getElementById(showcaseId);
|
|
|
|
el?.style.setProperty(`--heroui-font-size-${type}`, `${value}rem`);
|
|
}
|
|
|
|
export function setCssLineHeight(type: keyof ConfigLayout["lineHeight"], value: string) {
|
|
const el = document.getElementById(showcaseId);
|
|
|
|
el?.style.setProperty(`--heroui-line-height-${type}`, `${value}rem`);
|
|
}
|
|
|
|
export function setCssRadius(type: keyof ConfigLayout["radius"], value: string) {
|
|
const el = document.getElementById(showcaseId);
|
|
|
|
el?.style.setProperty(`--heroui-radius-${type}`, `${value}rem`);
|
|
}
|
|
|
|
export function setCssBorderWidth(type: keyof ConfigLayout["borderWidth"], value: string) {
|
|
const el = document.getElementById(showcaseId);
|
|
|
|
el?.style.setProperty(`--heroui-border-width-${type}`, `${value}px`);
|
|
}
|
|
|
|
export function setCssContentColor(level: 1 | 2 | 3 | 4, value: string, heroValue: string) {
|
|
const showcaseEl = document.getElementById(showcaseId);
|
|
const baseColorEl = document.getElementById(baseColorsId);
|
|
const configurationContainer = document.getElementById("configuration-container");
|
|
|
|
const hslValue = hexToHsl(value);
|
|
const heroHslValue = hexToHsl(heroValue);
|
|
|
|
showcaseEl?.style.setProperty(`--heroui-content${level}`, hslValue);
|
|
showcaseEl?.style.setProperty(
|
|
`--heroui-content${level}-foreground`,
|
|
hexToHsl(readableColor(value)),
|
|
);
|
|
baseColorEl?.style.setProperty(`--heroui-content${level}`, hslValue);
|
|
baseColorEl?.style.setProperty(
|
|
`--heroui-content${level}-foreground`,
|
|
hexToHsl(readableColor(value)),
|
|
);
|
|
|
|
configurationContainer?.style.setProperty(`--heroui-content${level}`, heroHslValue);
|
|
configurationContainer?.style.setProperty(
|
|
`--heroui-content${level}-foreground`,
|
|
hexToHsl(readableColor(heroValue)),
|
|
);
|
|
}
|
|
|
|
export function setCssOtherColor(
|
|
type: "background" | "foreground" | "focus" | "overlay",
|
|
value: string,
|
|
) {
|
|
const showcaseEl = document.getElementById(showcaseId);
|
|
const otherColors = document.getElementById(otherColorsId);
|
|
const hslValue = hexToHsl(value);
|
|
|
|
otherColors?.style.setProperty(`--heroui-${type}`, hslValue);
|
|
showcaseEl?.style.setProperty(`--heroui-${type}`, hslValue);
|
|
}
|
|
|
|
export function setOtherCssParams(type: keyof ConfigLayout["otherParams"], value: string) {
|
|
const el = document.getElementById(showcaseId);
|
|
|
|
if (!el) return;
|
|
|
|
switch (type) {
|
|
case "disabledOpacity":
|
|
el.style.setProperty("--heroui-disabled-opacity", value);
|
|
break;
|
|
case "dividerWeight":
|
|
el.style.setProperty("--heroui-divider-weight", `${value}px`);
|
|
break;
|
|
case "hoverOpacity":
|
|
el.style.setProperty("--heroui-hover-opacity", value);
|
|
break;
|
|
}
|
|
}
|
|
|
|
export function setAllCssVars(config: Config, theme: ThemeType) {
|
|
if (!config[theme] || !config[theme].baseColor || !config[theme].layoutColor || !config.layout) {
|
|
// eslint-disable-next-line no-console
|
|
console.error("Invalid configuration or theme provided.");
|
|
|
|
return;
|
|
}
|
|
|
|
setCssColor(
|
|
"default",
|
|
config[theme].defaultColor.default,
|
|
templates[0].value[theme].defaultColor.default,
|
|
theme,
|
|
);
|
|
setCssColor(
|
|
"primary",
|
|
config[theme].baseColor.primary,
|
|
templates[0].value[theme].baseColor.primary,
|
|
theme,
|
|
);
|
|
setCssColor(
|
|
"secondary",
|
|
config[theme].baseColor.secondary,
|
|
templates[0].value[theme].baseColor.secondary,
|
|
theme,
|
|
);
|
|
setCssColor(
|
|
"success",
|
|
config[theme].baseColor.success,
|
|
templates[0].value[theme].baseColor.success,
|
|
theme,
|
|
);
|
|
setCssColor(
|
|
"warning",
|
|
config[theme].baseColor.warning,
|
|
templates[0].value[theme].baseColor.warning,
|
|
theme,
|
|
);
|
|
setCssColor(
|
|
"danger",
|
|
config[theme].baseColor.danger,
|
|
templates[0].value[theme].baseColor.danger,
|
|
theme,
|
|
);
|
|
setCssColor(
|
|
"foreground",
|
|
config[theme].layoutColor.foreground,
|
|
templates[0].value[theme].layoutColor.foreground,
|
|
theme,
|
|
);
|
|
setCssContentColor(
|
|
1,
|
|
config[theme].contentColor.content1,
|
|
templates[0].value[theme].contentColor.content1,
|
|
);
|
|
setCssContentColor(
|
|
2,
|
|
config[theme].contentColor.content2,
|
|
templates[0].value[theme].contentColor.content2,
|
|
);
|
|
setCssContentColor(
|
|
3,
|
|
config[theme].contentColor.content3,
|
|
templates[0].value[theme].contentColor.content3,
|
|
);
|
|
setCssContentColor(
|
|
4,
|
|
config[theme].contentColor.content4,
|
|
templates[0].value[theme].contentColor.content4,
|
|
);
|
|
setCssBackground(config[theme].layoutColor.background);
|
|
setCssFontSize("tiny", config.layout.fontSize.tiny);
|
|
setCssFontSize("small", config.layout.fontSize.small);
|
|
setCssFontSize("medium", config.layout.fontSize.medium);
|
|
setCssFontSize("large", config.layout.fontSize.large);
|
|
setCssLineHeight("tiny", config.layout.lineHeight.tiny);
|
|
setCssLineHeight("small", config.layout.lineHeight.small);
|
|
setCssLineHeight("medium", config.layout.lineHeight.medium);
|
|
setCssLineHeight("large", config.layout.lineHeight.large);
|
|
setCssRadius("small", config.layout.radius.small);
|
|
setCssRadius("medium", config.layout.radius.medium);
|
|
setCssRadius("large", config.layout.radius.large);
|
|
setCssBorderWidth("small", config.layout.borderWidth.small);
|
|
setCssBorderWidth("medium", config.layout.borderWidth.medium);
|
|
setCssBorderWidth("large", config.layout.borderWidth.large);
|
|
setCssOtherColor("focus", config[theme].layoutColor.focus);
|
|
setCssOtherColor("overlay", config[theme].layoutColor.overlay);
|
|
setOtherCssParams("disabledOpacity", config.layout.otherParams.disabledOpacity);
|
|
setOtherCssParams("dividerWeight", config.layout.otherParams.dividerWeight);
|
|
setOtherCssParams("hoverOpacity", config.layout.otherParams.hoverOpacity);
|
|
}
|