• Stars
    star
    104
  • Rank 330,604 (Top 7 %)
  • Language
    CSS
  • Created over 9 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

evil micro-classes

minions

Evil micro-classes.

WIP

This project is undergoing a pretty big transition. I've removed the aspirational documentation to prevent confusion.

If for some reason your using this, you're likely on v0.0.3 and it's very different. I recommend looking at the documentation for that tag.

What is This?

This library is the practice of a naming convention I've been working out for human readable, low-conlfict micro-class.

I think that the naming conventions are solid. They're intended to be very literal. So, the practice is repeatable, library on not.

The library exists mostly to suss out shortcomings and areas of conflict.

A Simple Example

<div class="p-1r bw-1p bc-cC mx-2r ff-sans">
  This element has 1rem of padding, a 1px border (set to currentColor), a top/bottom margin of 2rem, and the font-family is sans.
</div>

Prior Art

  • tachyons - This is the first library I'd seen that went completely down the rabbit-hole of micro-classes with media-queries.
  • gravitons - Brent's projects are some of my favorite on the internet. Gravitons and basscss make an elegant and minimal framework.

Experimentation

There are a few guiding principles that I find absent from those other libraries. This isn't a problem; they're not omissions. But I find in my work, with my team, I wanted a more literal translation between classname and rule.

Guiding Principles

"Guessable," highly Literal Class Names

I want class names that are internally consistent and very literal. I want virtually 0 abstraction between a rule I'd type in CSS and a micro-class selector.

Whatever-first: mobile, wearable, mega-widescreen, appliance, who cares?

Support for legacy apps - "Mobile first" isn't possible in 10-year old app. It's already been "firsted." I want media-query classes that aren't opinionated about the starting line.

Why?

That's a great question.

I've come to believe that the biggest problem with CSS is that you have to name selectors to do anything. People suck at naming things and only the best people go back to reconsider.

This approach allows you to defer naming thing…maybe indefinitely.

Syntax

{property-shortand}-{value-shorthand}

Property shorthand

In the majority of cases, properties get shortened to a single character per word.

display  = d
overflow = o
margin   = m
padding  = p

Properties with two words (separated by a dash) will have two characters.

border-color = bc
border-width = bw

Likewise specific properties get a character for each dash-delimited word.

border-top-width    = btw
border-right-width  = brw
border-bottom-width = bbw
border-left-width   = blw

x and y have been added as aliases for right & left and top & bottom, respectively, for box-model properties.

border-top-width && border-bottom-width = byw
border-right-width && border-left-width = bxw

Value shorthand

Value shorthand follows the same rules as Property shortand. Values get shortened to a single character per word. This includes measurement values.

4px = 4p
1rem = 1r
hidden = h
inline-block = ib

measurements

There is no additional abstraction between measurement values and class selectors:

1em = 1e
.5em = .5e
.25em = .25e

1rem = 1r
.5rem = .5r
.25rem = .25r

Conflicts

There will be conflicts; I have two methods for resolving them.

Verbosity

Where two classes share the same selector, but one is less likely to be used, I attempt to make a more verbose version available.

.o-1 is a problematic selector. It can mean {opacity: 1} or {order: 1}.

I use opacity more than order and therefor use the verbose version of order to resolve the conflict:

.order-1

Alternate

Where two classes share might share the same selector and they are both popular, I chose a second character.

This isn't very common but the conflict exists in a pretty big way: background-color and border-color.

I've used gc for background-color.

bc = border-color
gc = background-color

Sadly, this exceptions is one that needs to be memorized and internalized.

Negative

There is only one number prefix. n may be used to prefix a number as negative. I'm avoiding the use of - to prevent confusion with OOCSS-style classes that use the -- (double-dash) delimiter as a modifier.

.order-1  { order: 1 }
.order-n1 { order: -1 }

Theming

The ability to theme minions is important. There's a simple convention for theme-able values. If the value side of the - isn't abbreviated, it's theme-able. Everything else is static. Here's an example:

.c-r   /* static, don't touch this */
.c-red /* variable. theme the shit out of it */

Property lexicon

ac  = align-content
ai  = align-items
as  = align-self
ad  = animation-delay *
      animation-direction
      animation-duration *
aic = animation-iteration-count

aps = animation-play-state
atf = animation-timing-function
ba  = background-attachment
bbw = border-bottom-width
b   = bottom
bc  = background-clip
      border-collapse
blw = border-left-width
bo  = background-origin
bp  = background-position
br  = background-repeat
brw = border-right-width
bs  = background-size
      border-style
btw = border-top-width
bw  = border-width
bxw = border-x-width
byw = border-y-width
bs  = box-sizing

c   = clear
      cursor
cc  = column-count

d   = display

f   = flex
      float
fb  = flex-basis
fd  = flex-direction
ff  = flex-flow
      font-family
fg  = flex-grow
fs  = flex-shrink
      flex-size
      font-style
fv  = font-variant
fw  = flex-wrap
      font-weight

h   = height

jc  = justify-content

l   = left
lh  = line-height
ls  = letter-spacing
lsp = list-style-position
lst = list-style-type

nh  = min-height *
nw  = min-width *

m   = margin
mb  = margin-bottom
ml  = margin-left
mr  = margin-right
mt  = margin-top
mx  = margin-x
my  = margin-y
mbm = mix-blend-mode

o   = opacity
      order
      overflow
os  = outline-style
ow  = outline-width
      outline-wrap
ox  = outline-x
oy  = outline-y

p   = padding
      position
pe  = pointer-events

r   = resize
      right

t   = top
ta  = text-align
td  = text-decoration
      transition-duration *
      transition-delay *
ti  = text-indent
to  = text-overflow
tp  = transition-property
tt  = text-transform
ttf = transition-timing-function

v   = visibility
va  = vertical-align

w   = width
wb  = word-break
wc  = will-change
ws  = white-space
      word-spacing

xh  = max-height *
xw  = max-width *

zi  = z-index

* indicates alternative naming do to conflict

Measurement

In cases of measurements, 0, 1, 2, 3, and 4 are available.

There em and rem and additional values for 1/2 and 1/4.

/* 0 */
p-0 { padding: 0 }

/* px */
p-1p { padding: 1px }
p-2p { padding: 2px }
p-3p { padding: 3px }
p-4p { padding: 4px }

/* em */
p-\.25e { padding: .25em }
p-\.5e  { padding: .5em }
p-1e   { padding: 1em }
p-2e   { padding: 2em }
p-3e   { padding: 3em }

/* rem */
p-\.25r { padding: .25rem }
p-\.5r  { padding: .5rem }
p-1r   { padding: 1rem }
p-2r   { padding: 2rem }
p-3r   { padding: 3rem }

Coming Eventually

THIS SECTION IS THE EXPERIMENTAL BIT THAT IS ONLY PARTIALLY IMPLEMENTED

_ Delimiter

The _ delimiter indicates that the selector enacts on all direct children, not the element the selector is on.

<div class="p-1r">This element has 1rem padding.</div>

<div class="p_1r">
  <div>These elements</div>
  <div>have 1rem padding.</div>
</div>

! Suffix

The ! suffix forces a rule by appending !important.

<ul class="p_1">
  <li>all direct children have 1em padding</li>
  <li>this one two</li>
  <li class="p-0!">this one has reset to 0</li>
</ul>

:h, :a Suffixes and Others

The :h and :a suffix can be applied to classes to apply their styles on browser events.

<a href="#" class="bw-1p bw-2p:h bw-3p:a">hover me</a>

Any other pseudo classes and elements can be written this way as well, e.g., :fc, :lc, :b, :a, :n(even) etc.

^ Selector

The ^ is a way for denoting an ancestor as the event target. It's like a look-back selector.

<div class="^">
  <div>
    <div>
      <div class="bw-2p:^h">This element will get hover-effect on great-grandparent hover</div>
    </div>
  </div>
</div>

Media Queries

The primary advantage that these classes provide over inline-styles is there ability to leverage media-queries.

Breakpoint-specific classes are suffixed with an @-symbol, followed by the two-character shorthand for the breakpoint (i.e., mn, sm, md, lg, xl).

<p class="w-10%@mn w-20%@xs w-40%@sm w-60%@md w-80%@lg w-100%@xl">
  The wider the screen gets, the wider I get.
</p>

Matching Logic

With the right matching logic, this library can support legacy apps with a "whatever-first" approach.

Overriding (up)

@media (min-width: 768px) {
  .p-1r\@md {}
}

Overriding (down)

@media (max-width: 767px) {
  .p-1r\@\!md {}
}

/*
 * alternatively,
 * not could be used to use the same value and be measurement agnostic
 */
@media not all and (max-width: 768px) {}

Exact Match (and)

@media (min-width: 768px) and (max-width: 991px) {
  .p-1r\@\=md {}
}

/*
 * alternatively,
 * not could be used to use the same value and be measurement agnostic
 */

Exact Exclude (or)

@media (max-width: 767px), (min-width: 992px){
  .p-1r@!=sm {}
}

More Repositories

1

reactpatterns

Patterns for React Developers
HTML
1,724
star
2

react-patterns

moved to to https://github.com/chantastic/sites/tree/master/reactpatterns.com
1,698
star
3

sites

JavaScript
1,032
star
4

react-cheat-sheet

A filterable React.js reference site
JavaScript
181
star
5

react-suspense-course

JavaScript
73
star
6

react-svg-spinner

An SVG spinner component
JavaScript
52
star
7

react-media-object

A media-object implementation in React.js
JavaScript
36
star
8

react-testing-patterns

Mostly reasonable patterns for testing React on Rails
34
star
9

practical-bem

The TL;DR on BEM IRL
34
star
10

8-point

A set of 8 point grid classes
CSS
28
star
11

commit-guidelines

How we commit code
23
star
12

react-rails-alt

A sample Rails application with React.js and Alt(Flux)
Ruby
22
star
13

react.holiday

A React advent for nerds and n00bs.
Astro
21
star
14

tip.css

A CSS tooltip.
CSS
16
star
15

css4-to-css3

An in-browser transformer for cssnext, in React. Just for funsies.
JavaScript
14
star
16

one-million-ui-states

A demonstration of how I test one million UI states every merge
JavaScript
13
star
17

use-lodash

A really terrible React Hook that is illustrative in other ways
JavaScript
11
star
18

reactcontext.com

a gentle intro to the what, where, when, why, and how of React Context
JavaScript
9
star
19

dt-service-calculator

A sample component with step-able history for training with Digital Telepathy — June 17, 2015
JavaScript
9
star
20

compare-words

A wordle guess-validation functions
JavaScript
8
star
21

btn.css

A scalable, style-able button.
HTML
7
star
22

prompt-guidelines

How to write user-friendly prompts
6
star
23

react-europa-inline-styles

My Keynote slide deck from React Europe 2015
6
star
24

react-flag-object

WIP React Flag Object implementation with inline-styles
JavaScript
5
star
25

react-disposition

Reusable, transportable, display and position React components.
JavaScript
5
star
26

updown

WORK IN PROGRESS!!!!!: A recursive README.md to index.html converter
JavaScript
5
star
27

react-card-object

A React card implementation with inline styles
JavaScript
5
star
28

rocss

Resource Oriented CSS
4
star
29

vite-react-jest-testing-library-axe

TypeScript
4
star
30

css-patterns

A mostly reasonable approach to naming things in CSS
4
star
31

style-components.com

HTML
4
star
32

myopic

A function for crafting thoughts that don't age well 🤓
JavaScript
4
star
33

ease.css

transition-timing functions as css classes
CSS
4
star
34

pseudo-class

JavaScript
4
star
35

select.css

HTML
3
star
36

legacy-dotfiles

Local extensions to Thoughtbot/dotfiles
Emacs Lisp
3
star
37

next-pokedex

A sample Next 13 app for react.holiday 2022
CSS
3
star
38

learnreactin30days

3
star
39

react-18-migration

WIP: Migrate a Client-Side React Apps to 18 Beta
JavaScript
3
star
40

worst

WIP
CSS
3
star
41

minions_rails

minions.css for Rails
CSS
3
star
42

react-minions

WIP. Don't use.
JavaScript
3
star
43

2016-reactjs-conf-faq

ARCHIVED: Things to know about getting a 2016 React.js Conf ticket
3
star
44

component-driven-avatar

JavaScript
2
star
45

circum

A positive array index for any number.
JavaScript
2
star
46

swifty.js

Better DevTools console
JavaScript
2
star
47

concurrent-mode-in-30

JavaScript
2
star
48

map-pseudo-classes

Using JS map() to implement CSS psuedo-classes
JavaScript
2
star
49

dotfiles

Shell
2
star
50

popover.css

popover styles
CSS
2
star
51

font-scale.css

CSS
2
star
52

frontend-guide

A Guide to PCO Frontend Tools
2
star
53

instruction.css

Exposable bits of UI clarification
JavaScript
2
star
54

rem-point

Soft-grid classes using rem
CSS
2
star
55

fullstack-react-todo

JavaScript
2
star
56

reactpatterns-book

2
star
57

dropdown.css

css dropdown WIP
JavaScript
2
star
58

storybook-nextjs

A setup run-thru of Storybook in a stock NextJS app
TypeScript
2
star
59

table.css

Responsive Table CSS
HTML
2
star
60

react-blox

Reusable, transportable components with box-model style props.
JavaScript
2
star
61

react_component_rails

A React component generator with love for tests and the Asset Pipeline
Ruby
2
star
62

react-aria-dropdown

WIP
2
star
63

react-basics

React Basics Book
2
star
64

aria-live-storybook-addon

Observe and log aria-live region changes in the addon panel
JavaScript
2
star
65

storybook-automated-tests-with-coverage

JavaScript
2
star
66

til

stuff i just learned
2
star
67

reactholiday22

A 25 day celebration of React at react.holiday
JavaScript
2
star
68

compare-words-worker

A Cloudflare Worker that compares words a la Wordle
JavaScript
2
star
69

react-starter

I've done this like 500 times...
JavaScript
2
star
70

birdcallreview.com

HTML
2
star
71

react-prompt

WIP
JavaScript
2
star
72

chantastic.org

JavaScript
2
star
73

chansolo.com

i picture of me superimposed on han solo
HTML
2
star
74

system-ui.css

An opinionated system-ui fallback, exposed as a class
CSS
2
star
75

planningcenter-minions.css

A minions.css extensions for Planning Center app colors.
HTML
2
star
76

point.css

WIP: relative point layout system in CSS
CSS
1
star
77

minionize_ruby

media-query helper for minions.css
Ruby
1
star
78

immutable-react

Immutable React Playground
JavaScript
1
star
79

reactbasics.com

A gentle introduction to React
1
star
80

use-aria-live

JavaScript
1
star
81

open-color.css

CSS
1
star
82

esmodule-reference-course

A short but thorough introduction to ES Modules
JavaScript
1
star
83

supabase-nextjs

JavaScript
1
star
84

storybook-react-portals-demo

Stories showcasing React Portals and how to interact with them declaratively
TypeScript
1
star
85

es-react-snippets.el

WIP
Emacs Lisp
1
star
86

batman-touch

jQuery Mobile touch-events extension for Batman.js
CoffeeScript
1
star
87

restated

JavaScript
1
star
88

elements

Created with CodeSandbox
JavaScript
1
star
89

instruct

JavaScript
1
star
90

wordle-words

The dictionary of words used in Wordle the word game
JavaScript
1
star
91

chantastic

My contact, on the NPM registry
JavaScript
1
star
92

givingashit.com

Personal Droning
CSS
1
star
93

button.css

A mostly reasonable button
CSS
1
star
94

chantastic.io

CSS
1
star
95

emacs

Learning emacs and shit
CSS
1
star
96

doxy

Cross-platform Church Center Components
JavaScript
1
star
97

pages-playground

playing with gh-pages features
HTML
1
star
98

stack.css

A WIP mobile-first grid concept
CSS
1
star
99

dialog.css

CSS Dialog
CSS
1
star
100

snippets-sublime-toolkitv5

Emporium Plus TOOL KIT v5 Snippet Library for Sublime Text
1
star