Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add classnames lib #4572

Closed
Tracked by #4341
oskarleonard opened this issue Nov 8, 2022 · 0 comments
Closed
Tracked by #4341

Add classnames lib #4572

oskarleonard opened this issue Nov 8, 2022 · 0 comments

Comments

@oskarleonard
Copy link
Contributor

Description

Standardize how we code conditional classes using the classnames library

Motivation

  • Prevent us from having a growing number of undefined classes in the dom, we currently have more than 700 instances of undefined.
  • Using the classnames lib we can over time clean up the dom, send less data to the user and simplify the dev experience.

Additional Information

Some code examples of what the difference will be:

// Setup
const isUndefined = undefined;
const isFalse = false;
const isZero = 0;
const isNull = null;
let className;
let styles = {
  header: "header"
};

String literals

<div className={`${styles.header} ${className}`}/> translates to <div class="class undefined" />

Classnames lib

<div className={classNames(styles.header, className)}/> translates to <div class="class" />


[].join(" ")

        <div
          className={[
            "class",
            isFalse && "isFalse",
            isZero && "isZero",
            isNull && "isNull",
            isUndefined && "isUndefined"
          ].join(" ")}
        />

Translates to <div class="class false 0 " />

Classnames lib

        <div
          className={classNames(
            "class",
            isFalse && "isFalse",
            isZero && "isZero",
            isNull && "isNull",
            isUndefined && "isUndefined"
          )}
        />

Translates to <div class="class" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

3 participants