<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How can I configure CSS modules to style my visual with react - powerbi-visuals-api in Custom Visuals Development Discussion</title>
    <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/How-can-I-configure-CSS-modules-to-style-my-visual-with-react/m-p/4105463#M10346</link>
    <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="791161" data-lia-user-login="Túlio" class="lia-mention lia-mention-user"&gt;Túlio&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to make sure your project has the dependencies required by CSS modules installed. You may need the css-loader dependency required by Webpack. Here is the code to install the corresponding dependencies:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;npm install css-loader style-loader --save-dev
&lt;/LI-CODE&gt;
&lt;P&gt;Modify your Webpack configuration to support CSS modules:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;module.exports = {
    module: {
        rules: [
            {
                test: /\.css$/,
                use: [
                    {
                        loader: 'style-loader'
                    },
                    {
                        loader: 'css-loader',
                        options: {
                            modules: true
                        }
                    }
                ]
            }
        ]
    }
};
&lt;/LI-CODE&gt;
&lt;P&gt;Create a CSS Modules file:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;/* styles.module.css */
.title {
    color: blue;
    font-size: 24px;
    font-weight: bold;
}
&lt;/LI-CODE&gt;
&lt;P&gt;In your React component or Power BI visual, import the CSS module:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;import * as React from "react";
import styles from "./styles.module.css";

export class Visual implements IVisual {
    constructor(options: VisualConstructorOptions) {
        const element = document.createElement("div");
        element.className = styles.title;  // This accesses the .title class from your CSS module
        element.innerText = "Hello, Power BI!";
        options.element.appendChild(element);
    }
}
&lt;/LI-CODE&gt;
&lt;P&gt;When you set element.className to styles.title , it applies the styles defined in the CSS module to that element. The class name is automatically scoped to avoid conflicts with other styles.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;hackcrr&lt;/P&gt;
&lt;P&gt;If I have answered your question,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;please mark my reply as solution&lt;/STRONG&gt;&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;kudos to this post&lt;/STRONG&gt;&lt;/EM&gt;, thank you!&lt;/P&gt;</description>
    <pubDate>Sun, 18 Aug 2024 01:13:55 GMT</pubDate>
    <dc:creator>hackcrr</dc:creator>
    <dc:date>2024-08-18T01:13:55Z</dc:date>
    <item>
      <title>How can I configure CSS modules to style my visual with react - powerbi-visuals-api</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/How-can-I-configure-CSS-modules-to-style-my-visual-with-react/m-p/4098572#M10328</link>
      <description>&lt;P&gt;How can I access "&lt;STRONG&gt;styles.title" &lt;/STRONG&gt;like the example below?&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import * as React from "react"; 
import styles from "./styles.module.css"; 

export class Visual implements IVisual { 
    constructor(options: VisualConstructorOptions) { 
        const element = document.createElement("div"); 
        element.className = styles.title; 
        element.innerText = "Hello, Power BI!"; 
        options.element.appendChild(element); 
    } 
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using&amp;nbsp;"powerbi-visuals-api": "5.11.0"&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2024 21:44:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/How-can-I-configure-CSS-modules-to-style-my-visual-with-react/m-p/4098572#M10328</guid>
      <dc:creator>Túlio</dc:creator>
      <dc:date>2024-08-13T21:44:32Z</dc:date>
    </item>
    <item>
      <title>Re: How can I configure CSS modules to style my visual with react - powerbi-visuals-api</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/How-can-I-configure-CSS-modules-to-style-my-visual-with-react/m-p/4099628#M10329</link>
      <description>&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;Hi,&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="791161" data-lia-user-login="Túlio" class="lia-mention lia-mention-user"&gt;Túlio&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;Thanks for your detailed explanation, I am more than willing to help you out. &lt;BR /&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in;"&gt;&lt;SPAN&gt;As far as I understand, if you want to go through a custom CSS file, I hope you can check if it meets the requirements of the custom &lt;/SPAN&gt;&lt;SPAN&gt;visual&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;BR /&gt;&lt;BR /&gt;Here are the relevant documents I found that I hope will help you:&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;A href="https://learn.microsoft.com/en-us/power-bi/developer/visuals/create-react-visual" target="_blank"&gt;&lt;SPAN&gt;Create a React-based visual for Power . - Power BI | Microsoft Learn&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;A href="https://learn.microsoft.com/en-us/power-bi/developer/visuals/power-bi-custom-visuals-certified" target="_blank"&gt;&lt;SPAN&gt;Get your Power BI visuals certified - Power BI | Microsoft Learn&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;" lang="zh-CN"&gt;Of course, if you only want to implement custom visuals in Desktop, you can try to find out if there are similar custom visuals in your app that can run your CSS files.&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;&lt;SPAN&gt;&lt;BR /&gt;For the issue you mentioned, it would be more advisable to post your question in &lt;/SPAN&gt;&lt;SPAN&gt;Custom Visuals Development&lt;/SPAN&gt;&lt;SPAN&gt; community to get professional support in time.&lt;/SPAN&gt;&lt;SPAN&gt;We've now moved your question to that forum.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in;"&gt;&lt;SPAN&gt;Here is the link to the forum you need:&lt;BR /&gt;&lt;/SPAN&gt;&lt;A href="https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/bd-p/CustomVisualsDevelopmentDiscussion" target="_blank"&gt;&lt;SPAN&gt;Custom Visuals Development Discussion - Microsoft Fabric Community&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;Best Regards,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;Leroy Lu&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2024 08:00:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/How-can-I-configure-CSS-modules-to-style-my-visual-with-react/m-p/4099628#M10329</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-08-14T08:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: How can I configure CSS modules to style my visual with react - powerbi-visuals-api</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/How-can-I-configure-CSS-modules-to-style-my-visual-with-react/m-p/4105463#M10346</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="791161" data-lia-user-login="Túlio" class="lia-mention lia-mention-user"&gt;Túlio&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to make sure your project has the dependencies required by CSS modules installed. You may need the css-loader dependency required by Webpack. Here is the code to install the corresponding dependencies:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;npm install css-loader style-loader --save-dev
&lt;/LI-CODE&gt;
&lt;P&gt;Modify your Webpack configuration to support CSS modules:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;module.exports = {
    module: {
        rules: [
            {
                test: /\.css$/,
                use: [
                    {
                        loader: 'style-loader'
                    },
                    {
                        loader: 'css-loader',
                        options: {
                            modules: true
                        }
                    }
                ]
            }
        ]
    }
};
&lt;/LI-CODE&gt;
&lt;P&gt;Create a CSS Modules file:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;/* styles.module.css */
.title {
    color: blue;
    font-size: 24px;
    font-weight: bold;
}
&lt;/LI-CODE&gt;
&lt;P&gt;In your React component or Power BI visual, import the CSS module:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;import * as React from "react";
import styles from "./styles.module.css";

export class Visual implements IVisual {
    constructor(options: VisualConstructorOptions) {
        const element = document.createElement("div");
        element.className = styles.title;  // This accesses the .title class from your CSS module
        element.innerText = "Hello, Power BI!";
        options.element.appendChild(element);
    }
}
&lt;/LI-CODE&gt;
&lt;P&gt;When you set element.className to styles.title , it applies the styles defined in the CSS module to that element. The class name is automatically scoped to avoid conflicts with other styles.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;hackcrr&lt;/P&gt;
&lt;P&gt;If I have answered your question,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;please mark my reply as solution&lt;/STRONG&gt;&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;kudos to this post&lt;/STRONG&gt;&lt;/EM&gt;, thank you!&lt;/P&gt;</description>
      <pubDate>Sun, 18 Aug 2024 01:13:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/How-can-I-configure-CSS-modules-to-style-my-visual-with-react/m-p/4105463#M10346</guid>
      <dc:creator>hackcrr</dc:creator>
      <dc:date>2024-08-18T01:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: How can I configure CSS modules to style my visual with react - powerbi-visuals-api</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/How-can-I-configure-CSS-modules-to-style-my-visual-with-react/m-p/4109151#M10362</link>
      <description>&lt;P&gt;This is not working for me. I'm still not able to import it as&lt;/P&gt;&lt;PRE&gt;import styles from "./styles.module.css";&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Is there some other solution?&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2024 12:34:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/How-can-I-configure-CSS-modules-to-style-my-visual-with-react/m-p/4109151#M10362</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-08-20T12:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: How can I configure CSS modules to style my visual with react - powerbi-visuals-api</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/How-can-I-configure-CSS-modules-to-style-my-visual-with-react/m-p/4118362#M10392</link>
      <description>&lt;P&gt;It doesn't work for me &lt;span class="lia-unicode-emoji" title=":downcast_face_with_sweat:"&gt;😓&lt;/span&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2024 09:48:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/How-can-I-configure-CSS-modules-to-style-my-visual-with-react/m-p/4118362#M10392</guid>
      <dc:creator>Túlio</dc:creator>
      <dc:date>2024-08-26T09:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: How can I configure CSS modules to style my visual with react - powerbi-visuals-api</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/How-can-I-configure-CSS-modules-to-style-my-visual-with-react/m-p/4131567#M10474</link>
      <description>&lt;P&gt;I changed the property "&lt;STRONG&gt;esModules&lt;/STRONG&gt;" to false, which works for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
	test: /\.css$/,
	include: /\.module\.css$/,
	exclude: /node_modules/,
	use: [
	  'style-loader',
	  {
		loader: 'css-loader',
		options: {
		  esModule: false,
		  modules: {
			localIdentName: '[name]__[local]__[hash:base64:5]'
		  }
		},
	  },
	],
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2024 15:09:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/How-can-I-configure-CSS-modules-to-style-my-visual-with-react/m-p/4131567#M10474</guid>
      <dc:creator>Túlio</dc:creator>
      <dc:date>2024-09-03T15:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: How can I configure CSS modules to style my visual with react - powerbi-visuals-api</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/How-can-I-configure-CSS-modules-to-style-my-visual-with-react/m-p/4132097#M10477</link>
      <description>&lt;P style="margin-top: 0pt; margin-bottom: 6pt; font-family: Arial; font-size: 12.0pt; color: black;"&gt;&lt;SPAN&gt;Hi,&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="791161" data-lia-user-login="Túlio" class="lia-mention lia-mention-user"&gt;Túlio&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;We are very glad to know that the issue has been resolved. If you wish, consider accepting your solution as a solution that will also benefit other community members who have the same problem as you and find a solution faster.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin-top: 0pt; margin-bottom: 6pt; font-family: Arial; font-size: 12.0pt; color: black;"&gt;&lt;SPAN&gt;Of course, if there is anything else we can do for you, please do not hesitate to contact us.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin-top: 0pt; margin-bottom: 6pt; font-family: Arial; font-size: 12.0pt; color: black;"&gt;&lt;SPAN&gt;Looking forward to your reply.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin-top: 0pt; margin-bottom: 8pt; font-family: Arial; font-size: 12.0pt;"&gt;Best Regards,&lt;/P&gt;
&lt;P style="margin-top: 0pt; margin-bottom: 8pt; font-family: Arial; font-size: 12.0pt;"&gt;Leroy Lu&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2024 01:05:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/How-can-I-configure-CSS-modules-to-style-my-visual-with-react/m-p/4132097#M10477</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-09-04T01:05:37Z</dc:date>
    </item>
  </channel>
</rss>

