File size: 1,006 Bytes
cf86710 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | import type { CSSProperties } from "react";
import type { Modifiers, ModifiersStyles, Styles } from "../types/index.js";
import { UI } from "../UI.js";
/**
* Returns the computed style for a day based on its modifiers.
*
* This function merges the base styles for the day with any styles associated
* with active modifiers.
*
* @param dayModifiers The modifiers applied to the day.
* @param styles The base styles for the calendar elements.
* @param modifiersStyles The styles associated with specific modifiers.
* @returns The computed style for the day.
*/
export function getStyleForModifiers(
dayModifiers: Modifiers,
styles: Partial<Styles> = {},
modifiersStyles: Partial<ModifiersStyles> = {},
): CSSProperties {
let style: CSSProperties = { ...styles?.[UI.Day] };
Object.entries(dayModifiers)
.filter(([, active]) => active === true)
.forEach(([modifier]) => {
style = {
...style,
...modifiersStyles?.[modifier],
};
});
return style;
}
|