From 9825908217a313a7c1016067d1522be418b8a87c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guszt=C3=A1v=20Szikszai?= Date: Sat, 19 Jun 2021 08:47:29 +0200 Subject: [PATCH] Added `setToken` and `getName` functions to `Ui.Token`. --- source/Enums/Token.mint | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/source/Enums/Token.mint b/source/Enums/Token.mint index 6f32e28..bebb406 100644 --- a/source/Enums/Token.mint +++ b/source/Enums/Token.mint @@ -35,6 +35,26 @@ module Ui.Token { } } + /* Sets a given token. */ + fun setToken (token : Ui.Token, tokens : Array(Ui.Token)) : Array(Ui.Token) { + try { + name = + getName(token) + + tokens + |> Array.reject((item : Ui.Token) { getName(item) == name }) + |> Array.push(token) + } + } + + /* Gets the name of the token. */ + fun getName (token : Ui.Token) : String { + case (token) { + Ui.Token::Schemed(name) => name + Ui.Token::Simple(name) => name + } + } + /* Resolves many tokens using the dark mode param. */ fun resolveMany (darkMode : Bool, tokens : Array(Ui.Token)) : String { tokens