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

[Draft]: Composable classnames #47 #48

Closed
wants to merge 7 commits into from

Conversation

eddyw
Copy link

@eddyw eddyw commented Jul 28, 2020

Description (see: #47)

This PR is a draft (and PoC) of a new API for otion inspired by React stylex. The implementation is a bit different from what was mentioned in #47

  • No toString() added
  • No breaking changes

Details

It add 3 methods:

  • stylesCreate – Allows to create style objects. This is basically just an object with string keys that can contain CSS properties (as in css(...)). This is partially implemented and it only runs hash(value) instead of calling css(...)
const styles = css.create({
	blue: { color: "blue", border: "1px solid" },
	green: { color: "green" },
	hotpink: { color: "hotpink", selectors: { "&:hover": { color: "pink" } } },
});
styles.blue // { color: [classname], border: [classname] }
styles.blue.color // [classname]
  • stylesCompose – Allows to compose two or more style objects into a single one. Right side argument overrides left side argument styles
const styles = css.create({
	blue: { color: "blue", border: "1px solid" },
	green: { color: "green" },
	hotpink: { color: "hotpink", selectors: { "&:hover": { color: "pink" } } },
});
const combined = css.compose(styles.blue, styles.green, styles.hotpink);
combined.color // [classname] for "hotpink" (right-side overrides left side)
combined.border // [classname] for "1px solid"
combined.selectors["&:hover"].color // [classname] for "pink"
  • stylesClassnames – Calls stylesCompose if more than one style object is passed & combines all classnames into a single string (as what css(...) does but for style objects)
const styles = css.create({
	blue: { color: "blue", border: "1px solid" },
	hotpink: { color: "hotpink", selectors: { "&:hover": { color: "pink" } } },
});
const className = css.cls(styles.blue, styles.hotpink) // "3sn2xs 147pvhj 1666u7v"

A new page was added to gatsby example, called rfc.tsx. Visit locally http://localhost:8000/rfc to see how it behaves.

The gatsby page creates a mock or would-be API that would be backwards compatible with what css is now:

css(...) // As it is now
css.create(...)
css.compose(...)
css.cls(...)

Soo .. thoughts? 😅
There are some bothering eslint rules that I ignored that are up for discussion too 😆

- GroupScopedCSSRules defines the structure of a style object
- UnionToIntersection as name suggests
PoC - create style objects
PoC - composes two or more style objects into a single one
PoC - composes a style objects into a single one and
returns all class names
exports:
- stylesCompose
- stylesCreate
- stylesClassnames
@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit f992d1d:

Sandbox Source
kripod/otion: example-cra Configuration
kripod/otion: example-gatsby Configuration
kripod/otion: example-nextjs Configuration

@lgtm-com
Copy link

lgtm-com bot commented Jul 28, 2020

This pull request introduces 1 alert when merging f992d1d into 0c888d9 - view on LGTM.com

new alerts:

  • 1 for Comparison between inconvertible types

@eddyw eddyw closed this Feb 15, 2022
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.

1 participant