All Projects → tomhodgins → Cssplus

tomhodgins / Cssplus

Licence: mit
CSSplus is a collection of CSS Reprocessor plugins that dynamically update CSS variables

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Cssplus

Nanostyled
A <1kB library for styling React components as if with CSS-in-JS, without CSS-in-JS
Stars: ✭ 104 (-26.24%)
Mutual labels:  css-in-js
Css In Js
A thorough analysis of all the current CSS-in-JS solutions with SSR & TypeScript support for Next.js
Stars: ✭ 127 (-9.93%)
Mutual labels:  css-in-js
Harser
Easy way for HTML parsing and building XPath
Stars: ✭ 135 (-4.26%)
Mutual labels:  xpath
Styled Typography
Typograpy components for react and styled-components
Stars: ✭ 113 (-19.86%)
Mutual labels:  css-in-js
Xstyled
A utility-first CSS-in-JS framework built for React. 💅👩‍🎤⚡️
Stars: ✭ 1,835 (+1201.42%)
Mutual labels:  css-in-js
React Next Boilerplate
🚀 A basis for reducing the configuration of your projects with nextJS, best development practices and popular libraries in the developer community.
Stars: ✭ 129 (-8.51%)
Mutual labels:  css-in-js
Css In React
🍭 CSS in React - Learn the best CSS in JS frameworks by example
Stars: ✭ 101 (-28.37%)
Mutual labels:  css-in-js
Expo Dark Mode Switch
A beautiful React dark mode switch component for iOS, Android, and Web
Stars: ✭ 137 (-2.84%)
Mutual labels:  css-in-js
Frontend Bootcamp
Frontend Workshop from HTML/CSS/JS to TypeScript/React/Redux
Stars: ✭ 10,506 (+7351.06%)
Mutual labels:  css-in-js
Jsonquery
jsonq package for Go. Golang XPath query for JSON query.
Stars: ✭ 134 (-4.96%)
Mutual labels:  xpath
Styled Jsx Plugin Sass
Plugin to add Sass support to styled-jsx. Warning this is a Proof Of Concept plugin.
Stars: ✭ 115 (-18.44%)
Mutual labels:  css-in-js
Styled By
Simple and powerful lib to handle styled props in your components
Stars: ✭ 122 (-13.48%)
Mutual labels:  css-in-js
Figma Theme
Generate development-ready theme JSON files from Figma Styles
Stars: ✭ 130 (-7.8%)
Mutual labels:  css-in-js
Graphquery
GraphQuery is a query language and execution engine tied to any backend service.
Stars: ✭ 112 (-20.57%)
Mutual labels:  xpath
React Free Style
Make React components easier and more maintainable by using inline style objects
Stars: ✭ 135 (-4.26%)
Mutual labels:  css-in-js
Pythonstudy
Python related technologies used in work: crawler, data analysis, timing tasks, RPC, page parsing, decorator, built-in functions, Python objects, multi-threading, multi-process, asynchronous, redis, mongodb, mysql, openstack, etc.
Stars: ✭ 103 (-26.95%)
Mutual labels:  xpath
Scoped Style
A tiny css in js library 🚀
Stars: ✭ 129 (-8.51%)
Mutual labels:  css-in-js
Torus
Torus is an event-driven model-view UI framework for the web, focused on being tiny, efficient, and free of dependencies.
Stars: ✭ 136 (-3.55%)
Mutual labels:  css-in-js
Next Dark Mode
🌑 Enable dark mode for Next.js apps
Stars: ✭ 133 (-5.67%)
Mutual labels:  css-in-js
React With Styles
Use CSS-in-JavaScript with themes for React without being tightly coupled to one implementation
Stars: ✭ 1,673 (+1086.52%)
Mutual labels:  css-in-js

CSSplus

CSSplus is a collection of CSS Reprocessor plugins that dynamically update CSS variables.

The plugins are designed to be used in tandem, though it's possible to pick and choose which plugins you want to include in each project.

Included are the following plugins:

Usage

NPM

If you are using NPM you can include all CSSplus plugins by including the entire package:

const cssplus = require('cssplus')

This will import all CSSplus plugins and make them available to be used in your own code as:

  • cssplus.aspecty
  • cssplus.cursory
  • cssplus.scrollery
  • cssplus.selectory
  • cssplus.varsity
  • cssplus.xpathy

But if you want to include the plugins individually, you can use the module/submodule syntax:

const selectory = require('cssplus/selectory')

And this means the Selectory plugin is available to be used in your code as:

selectory.load()

Global JavaScript

To include CSSplus plugins globally (outside of a bundler like Webpack or Browserify) you must include a <script> tag to each plugin you want to use. If you want to include just Selectory for example you would include just the one file like this:

<script src=cssplus/selectory.js></script>

To include all CSSplus plugins, you'll need to include links to the following files:

<script src=cssplus/aspecty.js></script>
<script src=cssplus/cursory.js></script>
<script src=cssplus/scrollery.js></script>
<script src=cssplus/selectory.js></script>
<script src=cssplus/varsity.js></script>
<script src=cssplus/xpathy.js></script>

Aspecty: an aspect ratio property

Aspecty is a CSS reprocessor that adds support for an aspect-ratio property using JS. This plugin allows you to define a desired aspect-ratio for an element, based on its rendered width on the page.

For any element with an aspect ratio defined, event listeners will be added to reprocess the styles on the following events:

  • mouseenter
  • mouseleave
  • mousedown
  • mouseup
  • focus
  • blur

By default, Aspecty will reprocess aspect ratios by watching the following events:

  • load
  • resize
  • input
  • click

To run Aspecty whenever you want, use the aspecty.load() function in JS.

The aspect ratio property can be used in CSS with the property name --aspect-ratio and a ratio, expressed as width and height as unitless numbers, separated by a slash /:

--aspect-ratio: width/height;

You can use it in CSS like this:

div {
  background: lime;
  --aspect-ratio: 16/9;
}

Aspecty will look through the document for any element matching the selector (in this case div) and create a new rule with a height value calculated based on each matching element's offsetWidth divided by the aspect ratio defined in CSS. To animate the effect of the --aspect-ratio property, which is actually applying via height, it is necessary to set a transition on the height property like this:

transition: height .2s ease-in-out;

Test available at: test/aspecty.html

Cursory: mouse/touch cursor variables

Cursory is a CSS reprocessor that makes the following JS values available as CSS variables:

  • cursorX
  • cursorY
  • innerWidth
  • innerHeight
  • clicked

These can be used as CSS variables with the following names:

  • --cursorX
  • --cursorY
  • --innerWidth
  • --innerHeight
  • --clicked

These variables are updated at the following events:

  • mousemove
  • touchmove

In addition, the --clicked variable is changed from 0 to 1 between the mousedown and touchstart events and the corresponding mouseup or touchend events. This allows you to use the var(--clicked) ratio as a 1 or 0 in your CSS calc() functions, or as a value for opacity:; fairly easily.

To run Cursory whenever you want, use the cursory.load() function in JS.

To make an element like div follow the cursor position when using cursory, use CSS with variables like this:

div {
  width: 10px;
  height: 10px;
  position: fixed;
  background: black;
  top: calc(var(--cursorY) * 1px);
  left: calc(var(--cursorX) * 1px);
}

Test available at: test/cursory.html

Scrollery: scroll position variables

Scrollery is a CSS reprocessor that makes the following JS values available as CSS variables for any element you tell the plugin to watch:

  • scrollWidth
  • scrollHeight
  • scrollLeft
  • scrollTop

To have scrollery watch an element, you need to give that element a unique identifier, as well as add the data-scrollery attribute. The plugin will use either the value of the data-scrollery attribute, or else the value of the id (if defined) for an element.

By default, Scrollery will watch 0 elements. If you add a data-scrollery attribute to either the <html> or <body> element it will attach an event listener for the scroll event on the window, otherwise if you add the data-scrollery attribute to other elements it will add a scroll listener to that element.

To run Scrollery whenever you want, use the scrollery.load() function in JS.

<div id=example data-scrollery></div>

And the following example are both equivalent, and resolve to a name of example:

<div data-scrollery=example></div>

Once the plugin is aware of an element to watch, and the unique name of that element, it will make the above values available in the following format: --name-value, for example:

  • --example-scrollWidth
  • --example-scrollHeight
  • --example-scrollTop
  • --example-scrollLeft

Test available at: test/scrollery.html

Selectory: a selector resolver

Selectory is a CSS reprocessor that resolves selectors using JS. This plugin will read CSS selectors that end with a [test] attribute and use JavaScript to determine whether or not to apply that style to elements matching the other part of that selector. For example, the JS test 1 == 1 will always resolve to true, so a selector written for div[test="1 == 1"] {} will always apply to each div element.

By default, Selectory will reprocess selectors by watching the following events:

  • load
  • resize
  • input
  • click

To run Selectory whenever you want, use the selectory.load() function in JS.

Other things you can do with Selectory include:

Apply a rule to a div when it is wider than 300px:

div[test="this.offsetWidth > 300"] {
  background: orange;
}

Apply a rule to an input when its value="" attribute is greater than 30:

input[test="this.value > 30"] {
  background: lime;
}

Apply a rule to an input when it has a value="" attribute zero characters long:

input[test="this.value.length == 0"] {
  background: purple;
}

Apply a rule to an input when its value="" attribute is more than 5 characters long:

input[test="5 < this.value.length"] {
  background: turquoise;
}

Apply a rule to an h3 element when it contains at least one span element:

h3[test="(this.querySelector('span'))"] {
  color: red;
}

It is limited what selectors you can use with Selectory, things like :hover and pseudo-classes tend not to work as well. As well the parsing only allows for 1 test per selector, and complex selectors may not work as intended. Using selector[test=""] {} with a simple selector is best.

Test available at: test/selectory.html

Varsity: scoped variables

Varsity is a CSS reprocessor that makes the following JS values available as CSS variables for any element you tell the plugin to watch:

  • offsetWidth
  • offsetHeight
  • offsetLeft
  • offsetTop
  • aspect-ratio
  • characters
  • children
  • value

By default, Varsity will reprocess selectors by watching the following events:

  • load
  • resize
  • input
  • click

To run Varsity whenever you want, use the varsity.load() function in JS.

To have varsity watch an element, you need to give that element a unique identifier, as well as add the data-varsity attribute. The plugin will use either the value of the data-varsity attribute, or else the value of the id (if defined) for an element.

<div id=example data-varsity></div>

And the following example are both equivalent, and resolve to a name of example:

<div data-varsity=example></div>

Once the plugin is aware of an element to watch, and the unique name of that element, it will make the above values available in the following format: --name-value, for example:

  • --example-offsetWidth
  • --example-offsetHeight
  • --example-offsetLeft
  • --example-offsetTop
  • --example-aspect-ratio
  • --example-characters
  • --example-children
  • --example-value

Test available at: test/varsity.html

XPathy: XPath selectors in CSS

XPathy is a CSS reprocessor that resolves selectors using XPath. This plugin will read CSS selectors that end with a [xpath] attribute and use JavaScript and XPath to determine whether or not to apply that style to elements matching the other part of that selector. For example, the XPath selector //div will always resolve to div, so a selector written for div [xpath="//div"] {} will always apply to each div div {} element.

By default, XPathy will reprocess selectors by watching the following events:

  • load
  • resize
  • input
  • click

To run XPathy whenever you want, use the xpathy.load() function in JS.

Other things you can do with XPathy include:

Select all span tags with the XPath //span:

[xpath="//span"] {
  color: violet;
}

Select all elements with a class name of demo-class with the XPath //*[@class='demo-class']:

[xpath="//*[@class='demo-class']"] {
  color: lime;
}

Select an element with a text content of 'Demo Content' with the XPath //*[text()='Demo Content']:

[xpath="//*[text()='Demo Content']"] {
  color: violet;
}

Select the parent element of another element with the XPath /..:

[xpath="//*[@class='child']/.."] {
  border: 1px solid lime;
}

Compare attribute values as numbers with operators like > and &lt;:

[xpath="//*[@data-price > 3]"] {
  color: violet;
}

Select elements based on the number of children they contain with an XPath like //ul[li[4]]:

[xpath="//ul[li[4]]"] {
  color: lime;
}

Test available at: test/xpathy.html

Browser support

These plugins are written in ES6, and intended to be used in modern browsers (Chrome, Safari, Firefox, Edge) without transpilation. Many of these plugins make use of CSS Custom Properties (CSS variables) for functionality, so any browser that doesn't support these features will have trouble with.

As far as I am aware, the only browser that supports CSS Custom Properties but not the ES6 features used (where transpiling to ES5 might improve support) is for Mobile Safari (iOS) support.

Currently all of these plugins are under active development and things are shifting around quite a bit so browser support may change with each release.

Demos

For 20+ CSSplus demos, check out the CSSPlus demos collection on Codepen.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].