Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a widget that injects a function to enable consumers to change theme #256

Closed
agubler opened this issue Feb 15, 2019 · 3 comments
Closed
Labels
enhancement New feature or request next Issue/Pull Request for the next major version

Comments

@agubler
Copy link
Member

agubler commented Feb 15, 2019

Enhancement

Currently it takes a significant amount of boilerplate to inject a function that can be used to change the current theme into the widget tree:

// main.ts
import renderer from "@dojo/framework/widget-core/vdom";
import { w } from "@dojo/framework/widget-core/d";
import App from "./widgets/App";
import { Registry } from "@dojo/framework/widget-core/Registry";
import { registerThemeInjector, Theme } from "@dojo/framework/widget-core/mixins/Themed";
import myTheme from './my-theme';

const registry = new Registry();
const injector = registerThemeInjector(myTheme, registry);

registry.defineInjector("update-theme", invalidator => {
  function themeSwitcher(theme: Theme) {
    injector.set({ theme });
  }
  return () => themeSwitcher;
});

const r = renderer(() => w(App, {}));
r.mount({ registry });

// ThemeSwitcherContainer.ts
// Used in the application somewhere to inject the theme switcher function

import Container from "@dojo/framework/widget-core/Container";
import ThemeSwitcher from "./ThemeSwitcher";

export default Container(ThemeSwitcher, "update-theme", {
  getProperties(injector) {
    return {
      themeSwitcher: injector
    };
  }
});

It would be helpful if Dojo could provide a customised widget that injects a function that can be to switch themes into an application widget tree.

The widget should be virtual and have no visual output, but provide an API to for the user to render widgets and nodes with access to the update theme function. This would remove the need for a user to register a new injector or create a custom container to get access to the update theme function.

@agubler agubler added enhancement New feature or request next Issue/Pull Request for the next major version labels Feb 15, 2019
@matt-gadd
Copy link
Contributor

@agubler do we think this is true for everything we currently have injectors for? ie i18n too?

@agubler
Copy link
Member Author

agubler commented Feb 15, 2019

@matt-gadd indeed! I was going to raise a separate issue for i18n and then also a generic Provider widget

@agubler
Copy link
Member Author

agubler commented Feb 15, 2019

@matt-gadd Issues raised #257 and #258 - WIP PR raised here #259

@agubler agubler closed this as completed May 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request next Issue/Pull Request for the next major version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants