-
-
Notifications
You must be signed in to change notification settings - Fork 738
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(chore) Rename getClassNamesForModifiers → getDayCellClassNames, add …
…tests
- Loading branch information
Showing
4 changed files
with
96 additions
and
31 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
This file was deleted.
Oops, something went wrong.
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,64 @@ | ||
import { DayFlag, SelectionState } from "../UI.js"; | ||
import type { ModifiersClassNames, ClassNames } from "../types/index.js"; | ||
|
||
import { getDayCellClassNames } from "./getDayCellClassNames.js"; | ||
import { getDefaultClassNames } from "./getDefaultClassNames.js"; | ||
|
||
describe("getDayCellClassNames", () => { | ||
const baseClass = "day"; | ||
const classNames: ClassNames = { | ||
...getDefaultClassNames(), | ||
[DayFlag.disabled]: "disabled", | ||
[SelectionState.selected]: "selected-style" | ||
}; | ||
const modifiersClassNames: ModifiersClassNames = { | ||
today: "today-class", | ||
weekend: "weekend-class" | ||
}; | ||
|
||
it("should return base class when no modifiers are active", () => { | ||
const modifiers = { today: false, weekend: false }; | ||
const result = getDayCellClassNames( | ||
modifiers, | ||
classNames, | ||
modifiersClassNames | ||
); | ||
expect(result).toEqual([baseClass]); | ||
}); | ||
|
||
it("should return class names for active modifiers", () => { | ||
const modifiers = { today: true, weekend: false }; | ||
const result = getDayCellClassNames( | ||
modifiers, | ||
classNames, | ||
modifiersClassNames | ||
); | ||
expect(result).toEqual([baseClass, "today-class"]); | ||
}); | ||
|
||
it("should return class names for active day flags", () => { | ||
const modifiers = { selected: true }; | ||
const result = getDayCellClassNames( | ||
modifiers, | ||
classNames, | ||
modifiersClassNames | ||
); | ||
expect(result).toEqual([baseClass, "selected-style"]); | ||
}); | ||
|
||
it("should return class names for active selection states", () => { | ||
const modifiers = { selected: true }; | ||
const result = getDayCellClassNames(modifiers, classNames); | ||
expect(result).toEqual([baseClass, "selected-style"]); | ||
}); | ||
|
||
it("should prioritize modifiersClassNames over classNames", () => { | ||
const modifiers = { today: true, selected: true }; | ||
const result = getDayCellClassNames( | ||
modifiers, | ||
classNames, | ||
modifiersClassNames | ||
); | ||
expect(result).toEqual([baseClass, "today-class", "selected-style"]); | ||
}); | ||
}); |
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,27 @@ | ||
import { DayFlag, SelectionState, UI } from "../UI.js"; | ||
import type { ModifiersClassNames, ClassNames } from "../types/index.js"; | ||
|
||
export function getDayCellClassNames( | ||
modifiers: Record<string, boolean>, | ||
classNames: ClassNames, | ||
modifiersClassNames: ModifiersClassNames = {} | ||
) { | ||
const result = Object.entries(modifiers) | ||
.filter(([, active]) => active === true) | ||
.reduce( | ||
(val, [modifier]) => { | ||
val.push(`${classNames[UI.Day]}-${modifier}`); | ||
if (modifiersClassNames[modifier]) { | ||
val.push(modifiersClassNames[modifier as string]); | ||
} else if (classNames[DayFlag[modifier as DayFlag]]) { | ||
val.push(classNames[DayFlag[modifier as DayFlag]]); | ||
} else if (classNames[SelectionState[modifier as SelectionState]]) { | ||
val.push(classNames[SelectionState[modifier as SelectionState]]); | ||
} | ||
return val; | ||
}, | ||
[classNames[UI.Day]] as string[] | ||
); | ||
|
||
return result; | ||
} |