From c47d1e9f5178d1a14122405f0872e305c6da562e Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Wed, 14 Jun 2023 17:26:58 +0200 Subject: [PATCH] Add toggle.ts and interactive.ts --- styles/src/styleTree/interactive.ts | 26 ++++++++++++++++++++++++++ styles/src/styleTree/toggle.ts | 17 +++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 styles/src/styleTree/interactive.ts create mode 100644 styles/src/styleTree/toggle.ts diff --git a/styles/src/styleTree/interactive.ts b/styles/src/styleTree/interactive.ts new file mode 100644 index 0000000000..2f7181900c --- /dev/null +++ b/styles/src/styleTree/interactive.ts @@ -0,0 +1,26 @@ +interface Interactive { + default: T, + hover?: T, + clicked?: T, + disabled?: T, +} + +export function interactive(base: T, modifications: Partial>): Interactive { + const interactiveObj: Interactive = { + 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; +} diff --git a/styles/src/styleTree/toggle.ts b/styles/src/styleTree/toggle.ts new file mode 100644 index 0000000000..0602ae6b59 --- /dev/null +++ b/styles/src/styleTree/toggle.ts @@ -0,0 +1,17 @@ +interface Toggleable { + inactive: T + active: T, +} + +export function toggleable(inactive: T, modifications: Partial>): Toggleable { + let active: T = inactive; + if (modifications.active !== undefined) { + active = { ...inactive, ...modifications.active }; + } + return { + inactive: inactive, + active: active + }; + + d +}