DEV Community

Cover image for Lean, Simple Tab Component in Juris. In pure Javascript without any fancies abstractions.
ArtyProg
ArtyProg

Posted on

Lean, Simple Tab Component in Juris. In pure Javascript without any fancies abstractions.

Resti, Juris author, posted a nice video on creating a simple tab component : SimpleTab-Video

You an test it here : SimpleTab

Here is his code :

const juris = new Juris();

const SimpleTab = (props, { getState, setState }) => ({
  div: {
    children: [
      {
        div: {
          children: [
            { button: { text: "Tab 1", onclick: () => setState("activeTab", 0) } },
            { button: { text: "Tab 2", onclick: () => setState("activeTab", 1) } },
            { button: { text: "Tab 3", onclick: () => setState("activeTab", 2) } },
            { button: { text: "Tab 4", onclick: () => setState("activeTab", 3) } }
          ]
        }
      },
      {
        div: {
          children: () => {
            const active = getState("activeTab", 0);
            const contents = [
              { p: { text: "Tab 1 content" } },
              { p: { text: "Tab 2 content" } },
              { p: { text: "Tab 3 content" } },
              { p: { text: "Tab 4 content" } }
            ];
            return [ contents[active] ];
          }
        }
      }
    ]
  }
});

juris.registerComponent("SimpleTab", SimpleTab);
juris.layout = { SimpleTab: {} };
juris.render('#app');


Enter fullscreen mode Exit fullscreen mode

I sincerely hope you can achieve the same simplicity with you favorite framework.

Remember, that this code does not need any NodeJS environment, and run as is in the browser (of course linking Juris library directly via CDN).

Top comments (0)