Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Conversation

nvanselow
Copy link
Collaborator

@nvanselow nvanselow commented Oct 20, 2017

This PR works with QuickBase/styled-components#3

It allows the specificity class to be set through a babel plugin configuration.

{
  "plugins": [
    ["babel-plugin-styled-components", {
      "namespaceClasses": 'moreSpecific'
    }]
  ]
}

or for a list of classes

{
  "plugins": [
    ["babel-plugin-styled-components", {
      "namespaceClasses": ["moreSpecific", "verySpecific"]
    }]
  ]
}

Results in classes to be pre-prended with the specificity class.

E.g.,

.moreSpecific .mx12n49 {
  background-color: yellow;
}

export const useMinify = (state) => getOption(state, 'minify')
export const useCSSPreprocessor = (state) => getOption(state, 'preprocess', false) // EXPERIMENTAL
export const useTranspileTemplateLiterals = (state) => getOption(state, 'transpileTemplateLiterals')
export const useIncreaseSpecificityClass = state => getOption(state, 'specificityClass', null);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually these are called "namespace classes" (not to be confused with CSS namespaces which serve a different purpose). Perhaps that terminology would be more clear.

Copy link

@genedwards genedwards left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@nvanselow
Copy link
Collaborator Author

Great name suggestion @harrismd! Fixed.

const namespaceClassOption = Array.isArray(namespaceClasses) ?
t.arrayExpression(namespaceClasses)
: t.stringLiteral(namespaceClass);
withConfigProps.push(t.objectProperty(t.identifier('namespaceClass'), namespaceClassOption))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be: t.identifier('namespaceClasses')

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is accessing the value in the config...

Copy link
Collaborator

@harrismd harrismd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved pending double-check of that one constant.

@nvanselow
Copy link
Collaborator Author

@harrismd - Fixed. Apologies that was a bit of a work in progress when you saw it. Had to make some other changes due to how babel-types work.

@nvanselow nvanselow force-pushed the Add_option_to_increase_specificity_in_styled_components branch from 2915b8d to cd97215 Compare October 23, 2017 19:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants