Issue with displaying PrimeVue component in Vue 3 Storybook

Currently, I am experimenting with Vue Storybook (Vue Js 3) along with the UI Framework primevue. Even though everything seems to be set up correctly without any errors, my component is not rendering in the browser as expected.

According to the guidelines, all I need to do is create a .vue file and a .stories.js file to showcase my component.

Main.js



import {createApp} from 'vue';
import App from './App.vue';
import PrimeVue from 'primevue/config';

const app = createApp(App);


app.component('Breadcrumb', Breadcrumb);
app.use(PrimeVue,{ripple: true});

List.vue


<template>
  <div>
    <Breadcrumb :home="home" :model="items" />
  </div>
</template>

<script>
import Breadcrumb from "primevue/breadcrumb";

export default {
  name: "List",
  components: {
    Breadcrumb,
  },
  data() {
    return {
      home: {
        icon: "pi pi-home",
        to: "/",
      },
      items: [
        { label: "Computer" },
        { label: "Notebook" },
        { label: "Accessories" },
        { label: "Backpacks" },
        { label: "Item" },
      ],
    };
  },
};
</script>

List.stories.js


import List from "./List.vue";

export default {
  title: "List",
  component: List,
};

// export const actionsData = {
//   onPinTask: action("pin-task"),
//   onArchiveTask: action("archiveTask"),
// };

const Template = (args, { argTypes }) => ({
    components: { List },
    props: Object.keys(argTypes),
    template:
      '<List />',
  });
export const ListDefault = Template.bind({});

Can anyone pinpoint where the problem might be occurring? It's visible in the Storybook Sidemenu. https://i.sstatic.net/ynzjU.png

Answer β„–1

Utilizing VUE3 with TypeScript and PrimeVue

In my situation, I made modifications to the preview.js file.

import { app } from '@storybook/vue3'
import { globalComponentsRegistry } from '../src/utils/globalComponentsRegistry';
import { PRIMEVUE_COMPONENTS } from '../src/utils/primevue/index';

import PrimeVue from 'primevue/config';

app.use(PrimeVue, { ripple: true });

globalComponentsRegistry(PRIMEVUE_COMPONENTS, app)

export const parameters = {
  actions: { argTypesRegex: "^on[A-Z].*" },
  controls: {
    matchers: {
      color: /(background|color)$/i,
      date: /Date$/,
    },
  },
}

I've implemented a utility function called globalComponentsRegistry() to install components in my main application. I also utilize this function for storybook integration. Here is the code snippet:

/**
 * Helper to register all Primevue components dynamically as: ...app.component('TabMenu', TabMenu);
 */
export const globalComponentsRegistry = (components: any, context: any) => {
  Object.entries(components).forEach(([keyName, definition]) => {
    const componentName = keyName;
    context.component(componentName, definition);
  });
};

This function takes an object containing all components ('PRIMEVUE_COMPONENTS') and the application instance (utilized for both storybook and the main app).

import TabMenu from 'primevue/tabmenu';
import Knob from 'primevue/knob';

export const PRIMEVUE_COMPONENTS = {
  TabMenu: TabMenu,
  Knob: Knob,
  ...
};

Now, I am able to view my custom components on storybook, including the prime knob component that was tested.

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

Answer β„–2

One major issue to address is the main.js file. I faced similar challenges with mine, but after some perseverance, I was able to get it working smoothly. The main.js serves as an entry point for the Storybook app and requires a different configuration compared to your main application. In the image provided below, you'll see that app is imported from @storybook/vue3, which often leads to confusion when integrating third-party libraries.

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

It's also crucial to pay attention to your CSS files. I made sure to import all necessary CSS files for my application. If you're using less or scss, be sure to refer to the Storybook docs for guidance on managing them effectively. Farewell.

For those who prefer copy-pasting code:

import { app } from '@storybook/vue3';
import PrimeVue from 'primevue/config';
import 'primevue/resources/primevue.min.css';
import 'primeicons/primeicons.css';
import 'primevue/resources/themes/saga-blue/theme.css';

app.use(PrimeVue, { ripple: true });

export const decorators = [(story) => ({
  components: {
    story,
  },
  template: '<story />'
})];

export const parameters = {
  actions: { argTypesRegex: "βŒƒon[A-Z].*" },
  controls: {
   matchers: {
    color: /(background|color)$/i/,
    date: /Date$/,
   }
  },
  decorators
}

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

What's the best way to show floating point numbers in a concise format while also maintaining the ability to perform calculations within this Vue app?

I'm currently developing a compact calculator application using Vue 3 and implementing some custom CSS. For the most part, everything seems to be functioning correctly, except for when the results are long numbers that extend beyond the display limit ...

Generating ranges dynamically based on the values in an array

As I receive data from a server, my goal is to categorize it into various buckets for presentation. The dataset appears in the following format: Array [ Object { "name": "1.00", "value": 17, }, Object { "name": "1.01", "value": ...

Display directional arrow on Ext.grid when the page is initially loaded

Displaying a grid with the product ID is our current setup. While the data is sorted according to the product ID, the sort arrow does not display upon page load. I have observed that clicking on the column reveals the arrow. How can we ensure that the so ...

Trouble displaying data fetched from nested Axios requests in VueJS view

I am currently working on a project where I need to display a list of posts fetched from an API onto a webpage using VueJS and Axios. However, I have encountered a challenge. One piece of crucial data (the post URL) must be obtained through a separate API ...

Exploring Keypress events with Dojo's 'on' module

Recently, I've started utilizing Dojo's latest on module for event handling. It has been working well so far, but a new issue has cropped up. Specifically, when using the keypress event, I am unable to retrieve the character value (such as "2" or ...

What is the best way to ensure Leaflet-Search functionality remains active even when a layerGroup is toggled off using L.control.layers

I am encountering challenges while using the Leaflet.Control.Search plugin by Stefano Cudini in conjunction with Leaflet's built-in function L.control.layers. When all layers are active, there are no issues with locating a specific area. However, wh ...

Unable to concatenate an array of strings using the concat method

I'm attempting to store HTML tags and a list as a string in a JavaScript variable so that I can later replace that code within an HTML document. app.use('/index', function(req, res) { var query = req.query; var searchQuery = query.searc ...

Utilizing Angular's DomSanitizer to safely bypass security scripts

Exploring the capabilities of Angular's bypassSecurityTrust* functions has been a recent focus of mine. My objective is to have a script tag successfully execute on the current page. However, I keep encountering issues where the content gets sanitized ...

The UI bootstrap dropdown toggle requires two clicks to reopen after being manually closed

Utilizing the UI Bootstrap drop-down element to display the calendar from angular-bootstrap-datetimepicker upon clicking. Additionally, a $watch has been implemented to close the dropdown once a date is chosen. Access the Plunker here <div uib-dropdow ...

Connection between overlay div and corresponding destination div address

I created a linked image with an overlay div: <div class="imageBlock"> <a href="http://www.google.com"> <img src="https://placeimg.com/640/480/any"> </a> <a href="http://www.twitter.com"> <img src="https://pl ...

Arrange the placement of a box outside of the primary DIV while maintaining a connection to it

I've encountered a hurdle that's hindering my progress. I'm attempting to shift a small box containing various options (like report, like, dislike, etc.) out from the main DIV while keeping it securely attached from the outside. Let me illus ...

Stop the flow of data in the RxJS stream depending on a specific value within the stream

I developed a straightforward component featuring a single button that initiates and halts a sequence of numbers generated by RxJS timer. import { Component, OnInit } from '@angular/core'; import { BehaviorSubject, Observable, timer, merge } fro ...

JavaScript module dependency management technique

Just starting out with JavaScript, I'm attempting to incorporate a JavaScript library/sdk. I've familiarized myself with common patterns and currently considering using the revealing module pattern. To provide a concrete example, let's imagi ...

Generating Three.js canvases dynamically based on requirements (implemented with classes)

In my scenario, I have an asset inventory containing multiple assets. I am looking to implement a feature where whenever a user hovers over the assets, it triggers rendering with an OrbitController (Trackball is preferred but not feasible due to a bug). Th ...

AngularJS- issue with button visibility on 'toolbar' widget

In my angularJS application, there is a page with multiple widgets displayed. When a user clicks on the 'Settings' button on the page (separate from the widgets), a toolbar for each widget appears showing different buttons depending on the widget ...

tips for showcasing an item in a tooltip within a data table

I am working on dynamically creating a table with data retrieved from an ajax response. My goal is to display the data stored in an object within a tooltip attached to each cell. Currently, I have successfully rendered the table, but it is displaying `[obj ...

"Classes can be successfully imported in a console environment, however, they encounter issues when

Running main.js in the console using node works perfectly fine for me. However, when I attempt to run it through a browser by implementing an HTML file, I do not see anything printed to the console. Interestingly, if I remove any mentions of Vector.ts fro ...

The getElementById method in JavaScript can result in a null return value

Why is null returned by the getElementById method in JavaScript? <html> <head> <title>test_elementObject</title> <script language="JavaScript" type="text/javascript"> <!-- var input1 = document.getElementById ( " ...

Add an item with a combination of different data types (such as objects and arrays) to a Mongo database, but encountering

I am currently working on posting an item to MongoDB using a combination of Node.js, Express, Mongoose, and Vue.js. The item I am trying to post consists of a mix of objects and arrays. Although the object post is successful in generating an ID, the data i ...

JavaScript Unit Testing seamlessly incorporated with CruiseControl.NET

Currently seeking a framework that offers unit testing for JavaScript. In the future, I will need to connect it to CruiseControl.NET. I have numerous ASP websites that utilize JavaScript, and I am looking to automate the testing process for them. Previousl ...