question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Are BEM-style class names possible?

See original GitHub issue

Hi. I want to get classes like Card and Card--large. In the documentation I found an example like this:

const Card = styled('form')`
width: 150px;
height: 120px;
&.large {
  width: 300px;
  height: 240px;
}
`;
// …
return (<Card large />);

It will generate somethins like this:

<form class="UserCard-Card--3mYhX UserCard-Card--2O_am"></form>

with webpack config

    module: {
      rules: [
        {
          test: /\.css$/,
          use: [
            { 
              loader: "style-loader",
            },
            { 
              loader: "astroturf/css-loader",
              options: {
                modules: true,
                localIdentName: '[name]--[hash:base64:5]',
              },
            }
          ],
        },
        {
          test: /\.jsx?$/,
          exclude: /node_modules/,
          use: ['babel-loader', 'astroturf/loader'],
        }
      ]
    },

But is there any way to get canonical BEM .Card and .Card--large classes?

<form class="Card__3mYhX Card--large__3mYhX"></form>

Regards. Anton.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
SilentImpcommented, Dec 24, 2018

@taion Actually, no, sir. I think you got the problem wrong. How I should set modifier class?

const Card = styled('form')`
width: 150px;
&--large {
  width: 300px;
}
`;
// …
return (<Card --large />);

Just wouldn’t work. As you may see in the config example — I am aware of localIdentName property. But if I am wrong and I may somehow configure it to get what i need — please, show me how.

Regards.

1reaction
SilentImpcommented, Dec 25, 2018

@jquense css`` with localIdentName: ‘[local]’, is totally the solution. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Naming
Block names may consist of Latin letters, digits, and dashes. To form a CSS class, add a short prefix for namespacing: .block, Any...
Read more >
BEM by Example: Best Practices for BEM CSS Naming
BEM (which stands for Block-Element-Modifier) is a naming convention standard for CSS class names. It has fairly wide adoption and is immensely ...
Read more >
Class naming 101: BEM
Naming elements is just as easy as naming blocks. We create element class names by starting with the block, then adding two underscores, ......
Read more >
Naming convention / Methodology / BEM
The primary purpose of the naming convention is to give names meaning so that they are as informative as possible for the developer....
Read more >
BEM 101
The Block, Element, Modifier methodology (commonly referred to as BEM) is a popular naming convention for classes in HTML and CSS.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found