Utilizing knobs to dynamically incorporate components into templates on Storybook: A guide

I am a novice in the realm of storytelling, attempting to craft tales involving a basic button and a button adorned with icons. My objective is to have the ability to switch out the icons within the button utilizing the knobs section. For example:

export const textButton = () => ({
  components: { PButton },
  template: `<p-button
      :color="color"
      :text="label"
    />`,
  props: {
    color: {
      default: select(
        "color",
        ["transparent", "black", "blue", "orange"],
        "black"
      )
    },
    label: { default: text("label", "Button") }
  }
});

The above showcases the story for a plain button where I can interchange colors from the knobs section. Likewise, I seek the correct syntax for the template to facilitate switching the icons contained within the button as individual components.


export const textWithIcon = () => ({
  components: { PButton, Arrow, Bullet, Check, Chevron, Cross, Delete, Edit, Info, Lock, Play, Plus, Search, UpDown, Upload },
  template: `<p-button
    :text="label"
    :color="color"
  >
    <template v-slot:icon>{{icon}}</template>
  </p-button>`,
  props: {
    icon: {
      default: select('icon', ['<Arrow />', '<Bullet />', '<Check />', '<Chevron />', '<Cross />', '<Delete />', '<Edit />', '<Info />', '<Lock />', '<Play />', '<Plus />', '<Search />', '<UpDown />', '<Upload />'], '<Arrow />'),
    },
    label: { default: text('label', 'Button') },
  },
});

https://i.sstatic.net/y3yX7.png

How can I accomplish this? What is the correct format? Any guidance or documentation reference would be greatly appreciated as I have been unable to find relevant information on this topic.

Answer №1

To tackle this issue, I implemented the following solution:

<component v-bind:is="selectedComponent"></component>

This involved providing the component with a name string and ensuring that all necessary components were properly imported.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Sending data from express js to a different server

Currently, I am faced with a scenario where I need to send a file from Jquery to my Express server and then transfer that request to another server without parsing the file in the Express server. Below are the code snippets I have been using so far: Jquery ...

Displaying an HTML file in a Node and Express application using JavaScript File handling

Starting my first Node, Express & Angular project has been a bit tricky due to issues with the asset pipeline. I'm not entirely sure if it's related to my folder structure, which I tried setting up based on online tutorials but am open to suggest ...

Change the runat attribute in JavaScript to execute on the server side

Is there a way to dynamically set the runat attribute using client-side JavaScript? I am facing the challenge of adding rows to a table after the page is loaded and must ensure that their cell data is accessible on the server side. While I am open to marki ...

Guide to populate Div content using JSON information

I am working with a JSON object that contains arrays, and my goal is to dynamically populate a div element. I have a dropdown menu (select option) that I want to fill with all the keys from my JSON data. Each key in my JSON has an array of data as its va ...

Preserve setTimeout() Functionality Across Page Refreshes and Navigations

I am trying to display an alert message after a 15-minute delay, but the functionality is disrupted when the page refreshes or if I navigate to a different page. This all takes place on a single web page. When a specific button is clicked, it should trig ...

Using a URL parameter inside an AJAX call

Greetings! I am looking to incorporate an ajax function for data transfer to my php page while utilizing the $_GET variable for verification purposes. This is the code snippet that I have implemented: $.ajax({ type: "POST", url: "coords ...

I encountered an issue in ReactJS where I received a TypeError stating that props.history.listen is not a function

Why is this showing up? I'm using ReactJS and can't figure out what's going wrong. Here is my history.js: import { createBrowserHistory } from 'history' export default createBrowserHistory In my App.js: import React from 'r ...

The ng-disabled directive in Angular JS is not effectively disabling a button

Why is the button not disabled? var mainApp = angular.module('mainApp', []); mainApp.controller('mainController', function ($scope) { $scope.form = { login: '' }; }); <form ng-controller="LoginAppCtrl as ...

What steps should I take to address the original tag error for Vue.js in the index.html file?

Desired Learning Interested in delving into the Vue.js framework using Vim and this helpful guide: https://cr-vue.mio3io.com/guide/chapter1.html#繰り返しの描画 Encountered Issue Difficulty in getting Vue tags to be recognized and functional i ...

Trouble arises when dealing with components beyond just the background while using jquery_interactive_bg.js

After experimenting with different plugins, I managed to achieve a parallax effect on my website's landing page by using the interactive_bg.js plugin. Following the steps outlined in a demo tutorial, I was able to attain the desired visual effect. Be ...

The @click function does not function properly when employing runtimeConfig in Nuxt 3

Here is a demonstration I created: https://stackblitz.com/edit/github-jsuxnz-rst5gg-git?file=app.vue Initially, the @click function works fine until I introduce runtimeConfig with const config = useRuntimeConfig();, after which all events cease to work. ...

Inject a directive attribute dynamically into an element using another directive, and ensure the initial directive is set to 'active.'

Let me explain in more detail. I am utilizing the tooltip directive from the UI Bootstrap suite, which allows me to attach a tooltip to an input element like this: <input type="text" ng-model="inputModel" class="form-control" placeholder=" ...

Exploring the world of Javascript: The significance of variable scope and its

Encountered a unique challenge while attempting to execute an ajax call and confine the function's actions to itself. Below is the code snippet: $(document).on('click', 'input.action', function(event) { var self = this; ...

I am attempting to link my Firebase real-time database with Cloud Firestore, but I am encountering import errors in the process

I am currently working on enhancing the online functionality of my chat app by implementing a presence system using Firebase Realtime Database. Here is the code snippet that I have created for this purpose: db refers to Firestore and dbt refers to the Rea ...

Updating the vue data map to group items by both date and employee

I am currently facing an issue with my Vue component and template where I display employees along with their hours/scans by date. The problem is that the current mapping aggregates all hours and scans based on the first record's date. The challenge a ...

Unable to dynamically update textbox with dropdown value in Internet Explorer [Using JavaScript]

I am attempting to modify the text in a textbox when a choice is made from a dropdown form element using the onchange() function. While this process works smoothly in Firefox, Safari, and Chrome, it fails to do so in Internet Explorer. Below is the simpl ...

What is the reason behind AngularJS consistently selecting the first TD cell?

I'm a beginner in AngularJS and I'm testing my skills by creating a small game. Here's the table structure I have: <table class="board"> <h1>Table</h1> <input type="number" ng-model="val"><button ng-click="ctrl.f ...

Ways to activate onChange multiple times for a single item within material ui's autocomplete feature

I am utilizing the autocomplete component in the Material UI. Upon selecting an item, the onChange props are triggered and certain actions are performed. However, I am encountering an issue where I can select the same object multiple times without the on ...

How to check off a checkbox using a jQuery function

I have a listbox displayed in my view. This listbox is using a template Listbox <div id="UsersLoad" style="width: 50%"> @Html.EditorFor(i => i.Users, "UsersForEdit") </div> UserForEdit Template (Code snippet) @model string[] @{ ...

Transferring variables from the $(document).ready(function(){}) to the $(window).load(function(){} allows for seamless and

Just think about if I successfully create percent_pass at the time of document.ready, how can I transfer that variable to window.load? $(document).ready(function() { jQuery(function() { var ques_count = $('.question-body').length; va ...