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

Changeable breakpoint class (\@) #3

Merged
merged 3 commits into from
Aug 15, 2017

Conversation

palmenhq
Copy link
Contributor

@palmenhq palmenhq commented Aug 15, 2017

It's not possible to escape some characters (among them @) with css module's composes:. I like the @ but it's just not possible to use in some setups which makes the framework unusable. I've replaced the hard-coded @ for responsive classes with a changeable setting that defaults to @.

@rbrtsmith
Copy link
Collaborator

Hi Johan thanks for your contribution!

I like the fact that you have put it into a variable to give the users more choice.

Could you show me an example Webpack config where this does not work? I've ran this on many Webpack projects without issue using Sass / Post-CSS loaders etc.
Example: https://github.com/rbrtsmith/nebula WIP project

@@ -6,6 +6,7 @@ $nb-spacing-unit: 1rem !default;
$nb-spacing-unit-half: ($nb-spacing-unit / 2) !default;
$nb-spacing-unit-double: ($nb-spacing-unit * 2) !default;

$nb-breakpoint-class: '\\@' !default;
Copy link
Collaborator

@rbrtsmith rbrtsmith Aug 15, 2017

Choose a reason for hiding this comment

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

Shouldn't the value of this be \@?

Copy link
Contributor Author

@palmenhq palmenhq Aug 15, 2017

Choose a reason for hiding this comment

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

I don't think so, since the first \ is escaping the "actual" \ from the string (so the actual string value is \@), otherwise we'd try to escape the @ itself which is not what we want.

Also inlines with this which was here before :)

@palmenhq
Copy link
Contributor Author

This one doesn't work (webpack 2.4): https://gist.github.com/palmfjord/e0d48aacb5e9ca5c2fdb8f234526ebe0

However, just to be clear, the CSS itself works perfectly, but when using the composes magic like so:

.my-class {
  composes: o-grid__item u-1/2@sm;
}

it breaks and gives this error:

Module build failed:
  composes: o-grid__item u-1/2@sm;
                             ^
      Invalid CSS after "...rid__item u-1/2": expected expression (e.g. 1px, bold), was "@sm;"

@rbrtsmith
Copy link
Collaborator

rbrtsmith commented Aug 15, 2017

Oh you are using CSS-Modules then? (That's where the composes syntax comes from I believe) I had never tested with that as I don't really have much use for them with ITCSS managing the architecture.

I don't think I've put it in the docs though but you shouldn't be composing grid / layout objects (anything in the objects layer) with other classes that are going to risk breaking the grid via property overrides (padding, margins, width etc). Better to just nest elements within and add classes to those and keep anything in the object layer single purpose. (I gather this was just an example bit of code)

I actually have a bunch of React components that have been 'Nebularised' over at https://github.com/rbrtsmith/nebula-react so consumers don't have to worry about adding classes or composing them, they can just augment the components with props and use their own classNames or something like the Styled Components package.

README.md Outdated
@@ -266,6 +266,10 @@ Base font-sizing for body copy.
```sass
$nb-base-font-size: 1rem !default;
```
The delimiter to use for responsive variations of classes (default `@`, but could be changed to i.e. `-bp-` to allow `composes:` as that doesn't work with `@` in class names)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should mention that this is for use with CSS-Modules. If the consumer isn't using them then everything should compile down fine.

@palmenhq
Copy link
Contributor Author

Right! Css Modules.. Temporary confusion over here haha. I'll update the readme and pr description accordingly.

Awesome stuff with nebula react, I'll take a look!

I usually just compose the grid into empty classes like so:

.container {
  composes: o-grid;
}
.inner-container {
  composes: o-grid__item u-1/2;
}

.something {
  color: red;
  font-family: "Comic Sans";
}
<div className={styles.container}>
  <div className={styles.containerInner}>
    <div className={styles.something}>
      hello world
    </div>
  </div>
</div>

@rbrtsmith rbrtsmith merged commit 43d9f48 into NebulaUI:master Aug 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants