JetBrains / kotlin-playground

Self-contained component to embed in websites for running Kotlin code
https://jetbrains.github.io/kotlin-playground/examples/
Apache License 2.0
448 stars 80 forks source link

Changing theme dynamically #131

Open MarcinAman opened 3 years ago

MarcinAman commented 3 years ago

Hi, is it possible to change the theme of sample dynamically (in JS). I have a theme toggler on my page therefore i'd like to also adjust the sample theme from idea to darcula. I've tried to just change the parameter manually but it doesn't seem to update anything (probably the change is not propagated)

Technically i could just render 2 versions and hide one but this results in super bad user experience

nikpachoo commented 3 years ago

Hi, @MarcinAman! Thank you for your feedback. Unfortunately, now the widget does not support changing the theme dynamically. As a workaround, instead of render 2 versions, you can try to recreate the widget with new parameters. Something like that:

let instance;

  initPlayground(element, theme) {
    if (instance) {
      instance.destroy();
    }

    playground(element, {
      getInstance: playgroundInstance => instance = playgroundInstance,
      theme: theme
    });
  } 

Most likely, we will add a possibility to change the theme dynamically, but it will take us some time to do this.