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

Added additional CSS classes without angle brackets to avoid SASS iss… #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ The above component will:

* be able to be customised when *its* width is 400 or smaller (`"<"` is a synonym for `max-width`, not “less than”).
* be able to be customised when *its* width is 700 or greater (`">"` is a synonym for `min-width`, not “greater than”).
* apply the following classes `media-object-eqio-<400` and `media-object-eqio->700` as appropriate. If `data-eqio-prefix` had not been specified, the applied classes would be `eqio-<400` and `eqio->700`.
* apply the following classes `media-object-eqio-lt-400` and `media-object-eqio-gt-700` as appropriate. If `data-eqio-prefix` had not been specified, the applied classes would be `eqio-lt-400` and `eqio-gt-700`.

*Note: Multiple classes can be applied at once.*

Expand All @@ -78,17 +78,16 @@ The above component will:
In your CSS, write class names that match those applied to the HTML.

```scss
.media-object-eqio-\<400 {
.media-object-eqio-lt-400 {
/* customizations when less than or equal to 400px */
}

.media-object-eqio-\>700 {
.media-object-eqio-gt-700 {
/* customizations when greater than or equal to 700px */
}
```

*Note:*
* *eqio classes include the special characters `<` & `>`, so they must be escaped with a `\` in your CSS.*
* *eqio elements are `position: relative` by default, but your component can override that to `absolute`/`fixed` etc as required.*
* *eqio elements can't be anything but `overflow: visible`.*

Expand Down
15 changes: 11 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,21 @@ class Eqio {
entries.forEach((entry) => {
if (entry.isIntersecting) {
const size = entry.target.dataset.eqioSize;
const cssSafeSize = this.replaceOperators(size);

if (size.indexOf('>') === 0) {
if (entry.intersectionRatio === 1) {
this.el.classList.add(`${className}${size}`);
this.el.classList.add(`${className}${cssSafeSize}`, `${className}${size}`);
}
else {
this.el.classList.remove(`${className}${size}`);
this.el.classList.remove(`${className}${cssSafeSize}`, `${className}${size}`);
}
}
else if (entry.intersectionRatio === 1) {
this.el.classList.remove(`${className}${size}`);
this.el.classList.remove(`${className}${cssSafeSize}`, `${className}${size}`);
}
else {
this.el.classList.add(`${className}${size}`);
this.el.classList.add(`${className}${cssSafeSize}`, `${className}${size}`);
}
}
});
Expand Down Expand Up @@ -113,6 +114,12 @@ class Eqio {
delete this.sizesArray;
delete this.triggerEls;
}

replaceOperators(string) {
string = string.replace('>', 'gt-');
string = string.replace('<', 'lt-');
return string;
}
}

module.exports = Eqio;