Add toggle.ts and interactive.ts

This commit is contained in:
Piotr Osiewicz 2023-06-14 17:26:58 +02:00 committed by Mikayla Maki
parent b9959ffdc0
commit c47d1e9f51
No known key found for this signature in database
2 changed files with 43 additions and 0 deletions

View file

@ -0,0 +1,26 @@
interface Interactive<T> {
default: T,
hover?: T,
clicked?: T,
disabled?: T,
}
export function interactive<T>(base: T, modifications: Partial<Interactive<T>>): Interactive<T> {
const interactiveObj: Interactive<T> = {
default: base,
};
if (modifications.hover !== undefined) {
interactiveObj.hover = { ...base, ...modifications.hover };
}
if (modifications.clicked !== undefined) {
interactiveObj.clicked = { ...base, ...modifications.clicked };
}
if (modifications.disabled !== undefined) {
interactiveObj.disabled = { ...base, ...modifications.disabled };
}
return interactiveObj;
}

View file

@ -0,0 +1,17 @@
interface Toggleable<T> {
inactive: T
active: T,
}
export function toggleable<T>(inactive: T, modifications: Partial<Toggleable<T>>): Toggleable<T> {
let active: T = inactive;
if (modifications.active !== undefined) {
active = { ...inactive, ...modifications.active };
}
return {
inactive: inactive,
active: active
};
d
}