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 specificity to css selectors #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nvanselow
Copy link
Collaborator

Allows the specificity of the css selector for a styled component to be modified through the options.

It passes through the options to the BaseStyledComponent so that it can call the css generateAndInjectStyles with the options. The specificityClass is set in options and used to increase the specificity of all classes.

This works with QuickBase/babel-plugin-styled-components#1 to apply the options through babel.

*/
export default function getComponentCssSelector(componentName: string, options: Object) {
if (options && options.specificityClass) {
return `.${options.specificityClass} .${componentName}`
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd like to see us support more than one specificityClass... can we support an array here? While we think one level of increased specificity is enough for our purposes now, we don't know for certain and other consumers of the framework may need it as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

As mentioned in the related PR, these are usually called "namespace classes". 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

The linter...maybe they updated the linting rule at some point but it only runs against staged files.
Also I'm disappointed in git for these poor diffs, it looks like a bigger change than it actually is.

@harrismd
Copy link
Collaborator

Yeah, when we open a PR on the real repository, we need to make certain we aren't pushing lint-induced changes.

unsubscribeFromContext() {
if (this.unsubscribeId !== -1) {
this.context[CHANNEL_NEXT].unsubscribe(this.unsubscribeId)
const createBaseStyledComponent = (options: Object) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This diff is still really bad. I tried a second time.

let namespaceClass = options.namespaceClasses
if (Array.isArray(options.namespaceClasses)) {
namespaceClass = options.namespaceClasses.join(' .')
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@nvanselow nvanselow force-pushed the Add_specificity_to_css_selectors branch from 4fdffa6 to 6c21bb9 Compare October 23, 2017 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants