4

Is there a way to use external css (i.e bootstrap, semantic-ui, foundation, etc) while still getting the base64 class names? This could be possible if there was a way to use multiple class names.

Currently you can only use one class name like this

import React, {Component} from 'react';
import style from './App.scss';
import styles from '../semantic/dist/components/button.min.css'

  render() {
    return (
      <div className="App">
        <div className={style.button}>Hello Webpack!!!</div>
    );
  }
}

I need to be able to use multiple class names like this:

<div className={style.btn} + {style.red}>Hello Webpack!!!</div>

in order to use css frameworks and get the base64 class names. Is there a way to do this?

TL;DR: I want to have multiple class names from a file that doesn't have :local(...) for each of the class names (semantic-ui) and get the base64 random class names. Using them. If I import ../semantic/dist/components/button.min.css I can use className="ui red button" fine, but if I import Semantic from '../semantic/dist/components/button.min.css', I can't use className={Semantic.ui + " " + Semantic.button}

9
  • 1
    I'm not sure what your question is. className accepts a string, so you can easily use multiple values: className={`${class1} ${class2}`}. But I'm not sure what you mean when you refer to the "base64 class names" of the frameworks. Why wouldn't you use classes like normal? Commented Jan 12, 2016 at 1:15
  • @JoshDavidMiller I want to have multiple class names from a file that doesn't have :local(...) for each of the class names (semantic-ui) and get the base64 random class names. Commented Jan 12, 2016 at 2:12
  • Right, but what's the problem? Are you having trouble importing them or using them? Commented Jan 12, 2016 at 2:52
  • Using them. If I import ../semantic/dist/components/button.min.css I can use className="ui red button" fine, but if I import Semantic from '../semantic/dist/components/button.min.css', I can't use className={Semantic.ui + " " + Semantic.button} most likely because the semantic-ui css files don't have the :local(...) prefix. Commented Jan 12, 2016 at 15:58
  • I guess I'm a little confused. If they don't use :local, why would they have random class names? Back to my original comment, why can't you do className="ui red button"? Commented Jan 12, 2016 at 19:58

3 Answers 3

4

use classnames npm module

import classNames from 'classnames'

render: <div className={classNames(style.red,style.btn)}>Hello Webpack!!!</div>
Sign up to request clarification or add additional context in comments.

Comments

2

See this for using bootstrap along with your css styles.. Webpack Multiple CSS Loaders

And to use multiple classnames you can simply write like this in place of

{style1} + {style2}: 
   className={
       styles.button + " " + styles.red
   }

Comments

0

or: className={ [styles.button, styles.red].join(' ') }

3 Comments

This is basically the same answer as this just concatenates strings in other way
Yes, I know . So one can choose which one works the best :-)
There are also other ways to concatenate string but it's not subject of this question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.