Last active
July 5, 2025 15:21
-
-
Save mvyasu/6d306d0c8a2daa33c53df9f254dcdec9 to your computer and use it in GitHub Desktop.
A variant of my studio theme provider that uses a contextual
This file contains hidden or 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
| --!strict | |
| local Studio = settings().Studio | |
| local Packages = script.Parent.Parent.Packages | |
| local Fusion = require(Packages.Fusion) | |
| local Contextual = Fusion.Contextual | |
| local Computed = Fusion.Computed | |
| local Value = Fusion.Value | |
| local dynamicFont = Value("rbxasset://fonts/families/GothamSSm.json") | |
| local dynamicTheme = Value(Studio.Theme :: StudioTheme) | |
| local fontContext = Contextual(dynamicFont :: Fusion.CanBeState<string>) | |
| local themeContext = Contextual(dynamicTheme :: Fusion.CanBeState<StudioTheme>) | |
| local themeProvider = {} | |
| themeProvider.ThemeContext = themeContext | |
| themeProvider.FontContext = fontContext | |
| type studioStyleGuideColor = Fusion.CanBeState<Enum.StudioStyleGuideColor> | |
| type studioStyleGuideModifier = Fusion.CanBeState<Enum.StudioStyleGuideModifier> | |
| function themeProvider:GetColor(providedColor: studioStyleGuideColor, providedModifier: studioStyleGuideModifier?): Fusion.Computed<Color3> | |
| local currentThemeContext = themeContext:now() | |
| return Computed(function(use) | |
| local currentTheme = use(currentThemeContext) | |
| local currentColor = use(providedColor) | |
| local currentModifier = use(providedModifier) | |
| return currentTheme:GetColor(currentColor, currentModifier) | |
| end) | |
| end | |
| type fontWeight = Fusion.CanBeState<Enum.FontWeight> | |
| type fontStyle = Fusion.CanBeState<Enum.FontStyle> | |
| function themeProvider:GetFont(providedWeight: fontWeight?, providedStyle: fontStyle?): Fusion.Computed<Font> | |
| local currentFontContext = fontContext:now() | |
| return Computed(function(use) | |
| local currentFont = use(currentFontContext) | |
| local currentFontWeight = use(providedWeight) or Enum.FontWeight.Regular | |
| local currentFontStyle = use(providedStyle) or Enum.FontStyle.Normal | |
| return Font.new(currentFont, currentFontWeight, currentFontStyle) | |
| end) | |
| end | |
| function themeProvider:GetDark(): Fusion.Computed<boolean> | |
| local currentThemeContext = themeContext:now() | |
| return Computed(function(use) | |
| local currentTheme = use(currentThemeContext) | |
| local _, _, value = currentTheme:GetColor(Enum.StudioStyleGuideColor.MainBackground):ToHSV() | |
| return value <= 0.6 | |
| end) | |
| end | |
| do --updates the dynamic theme to match studio's theme | |
| local function updateTheme() | |
| dynamicTheme:set(Studio.Theme) | |
| end | |
| local themeChangedConnection = Studio.ThemeChanged:Connect(updateTheme) | |
| local currentPlugin = script:FindFirstAncestorWhichIsA("Plugin") | |
| if currentPlugin then | |
| currentPlugin.Unloading:Once(function() | |
| themeChangedConnection:Disconnect() | |
| end) | |
| end | |
| end | |
| return themeProvider |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment