-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
86 additions
and
1 deletion.
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 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,42 @@ | ||
package demo.helpers | ||
|
||
import com.raquo.laminar.api.L.* | ||
import be.doeraene.webcomponents.ui5.* | ||
import be.doeraene.webcomponents.ui5.theming.Theming | ||
|
||
object ThemeSelector { | ||
|
||
/** Allows to select the theme for the web-components. | ||
* | ||
* That does not take care of the "rest" of the ui (for example, the general background colour, or text colours...) | ||
* | ||
* You would need to use the `selectedChoiceVar` current value and adjust remaining css when relevant. | ||
*/ | ||
def apply(): HtmlElement = { | ||
|
||
val themeChoices = Vector( | ||
"sap_fiori_3", | ||
"sap_fiori_3_dark" | ||
) | ||
|
||
val selectedChoiceVar = Var(themeChoices(0)) | ||
|
||
Select( | ||
themeChoices.map { theme => | ||
Select.option( | ||
theme, | ||
_.value := theme, | ||
_.selected <-- selectedChoiceVar.signal.map(_ == theme) | ||
) | ||
}, | ||
_.events.onChange.map(_.detail.selectedOption.maybeValue.getOrElse(themeChoices(0))) --> selectedChoiceVar.writer, | ||
selectedChoiceVar.signal.changes --> Observer(Theming.setTheme) | ||
) | ||
|
||
} | ||
|
||
// registering the themes | ||
Theming.WebComponentsAssets | ||
Theming.WebComponentsFioriAssets | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
web-components/src/main/scala/be/doeraene/webcomponents/ui5/theming/Theming.scala
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,41 @@ | ||
package be.doeraene.webcomponents.ui5.theming | ||
|
||
import scala.scalajs.js.annotation.JSImport | ||
|
||
import scala.scalajs.js | ||
|
||
//noinspection ScalaUnusedSymbol | ||
object Theming { | ||
|
||
@js.native | ||
@JSImport("@ui5/webcomponents-base/dist/config/Theme.js", "setTheme") | ||
def setTheme(theme: String): js.Promise[Unit] = js.native | ||
|
||
@js.native | ||
@JSImport("@ui5/webcomponents-base/dist/config/Theme.js", "getTheme") | ||
def getTheme(): String = js.native | ||
|
||
@js.native | ||
@JSImport("@ui5/webcomponents-base/dist/asset-registries/Themes.js", "registerThemePropertiesLoader") | ||
def registerThemePropertiesLoader( | ||
packageName: String, | ||
themeName: String, | ||
loader: js.Function0[js.Promise[js.Object]] | ||
): Unit = | ||
js.native | ||
|
||
@js.native | ||
@JSImport( | ||
"@ui5/webcomponents/dist/Assets.js", | ||
JSImport.Namespace | ||
) | ||
object WebComponentsAssets extends js.Object | ||
|
||
@js.native | ||
@JSImport( | ||
"@ui5/webcomponents-fiori/dist/Assets.js", | ||
JSImport.Namespace | ||
) | ||
object WebComponentsFioriAssets extends js.Object | ||
|
||
} |