mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-24 19:10:24 +00:00
Add toggle.ts and interactive.ts
This commit is contained in:
parent
b9959ffdc0
commit
c47d1e9f51
2 changed files with 43 additions and 0 deletions
26
styles/src/styleTree/interactive.ts
Normal file
26
styles/src/styleTree/interactive.ts
Normal 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;
|
||||
}
|
17
styles/src/styleTree/toggle.ts
Normal file
17
styles/src/styleTree/toggle.ts
Normal 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
|
||||
}
|
Loading…
Reference in a new issue