0.3.0 • Published 2 years ago

@code-hike/classer v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Classer is a tool from Code Hike

A little package to make React component libraries interoperable with most styling solutions. (See this twitter thread explaining why this is useful)

You write your library code like this:

// foo-library code
import { useClasser } from "@code-hike/classer"

export function Foo({ classes }) {
  const c = useClasser("foo", classes)
  return (
    <div className={c("container")}>
      <h1 className={c("title")}>Hello</h1>
      <p className={c("description")}>World</p>
      <img
        className={c("img")}
        src="https://placekitten.com/200/200"
      />
    </div>
  )
}

And the library consumers use it like this in their apps:

import { Foo } from "foo-library"

const classes = {
  "foo-title": "my-app-blue",
  "foo-img": "rounded-corners some-border",
}

function MyApp() {
  return <Foo classes={classes} />
}

MyApp renders this HTML:

<div class="foo-container">
  <h1 class="foo-title my-app-blue">Hello</h1>
  <p class="foo-description">World</p>
  <img
    class="foo-img rounded-corners some-border"
    src="https://placekitten.com/200/200"
  />
</div>

Examples:

Context

You can also do this (to avoid passing classes to nested components):

// foo-library code
import {
  useClasser,
  ClasserProvider,
} from "@code-hike/classer"

export function Foo({ classes }) {
  return (
    <ClasserProvider classes={classes}>
      <FirstChild />
      <SecondChild />
    </ClasserProvider>
  )
}

function FirstChild() {
  const c = useClasser("foo-first")
  return <h1 className={c("title")}>Hi</h1>
}

function SecondChild() {
  const c = useClasser("foo-second")
  return <h1 className={c("title")}>Ho</h1>
}
import { Foo } from "./foo-library"
import styles from "./app.module.css"

const classes = {
  "foo-title": styles.myTitle,
  "foo-img": styles.myImage,
}

function MyApp() {
  return <Foo classes={classes} />
}

License

MIT

0.3.0

2 years ago

0.3.0-next.28

2 years ago

0.3.0-next.29

2 years ago

0.3.0-next.20

2 years ago

0.3.0-next.21

2 years ago

0.3.0-next.22

2 years ago

0.3.0-next.23

2 years ago

0.3.0-next.24

2 years ago

0.3.0-next.25

2 years ago

0.3.0-next.26

2 years ago

0.3.0-next.27

2 years ago

0.3.0-next.14

2 years ago

0.3.0-next.15

2 years ago

0.3.0-next.16

2 years ago

0.3.0-next.17

2 years ago

0.3.0-next.18

2 years ago

0.3.0-next.19

2 years ago

0.3.0-next.12

2 years ago

0.3.0-next.13

2 years ago

0.3.0-next.11

3 years ago

0.3.0-next.10

3 years ago

0.3.0-next.9

3 years ago

0.3.0-next.8

3 years ago

0.3.0-next.7

3 years ago

0.3.0-next.6

3 years ago

0.3.0-next.5

3 years ago

0.3.0-next.4

3 years ago

0.3.0-next.3

3 years ago

0.3.0-next.2

3 years ago

0.3.0-next.1

3 years ago

0.3.0-next.0

3 years ago

0.0.0-4333a8b

3 years ago

0.0.0-2c9642f

3 years ago

0.0.0-6a4ea1c

3 years ago

0.0.0-e48fa74

3 years ago

0.0.0-1f0ad83

3 years ago

0.0.0-cde697c

3 years ago

0.0.0-aa6efee

3 years ago