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

WIP: twind/styled #7

Closed
wants to merge 11 commits into from
Closed

WIP: twind/styled #7

wants to merge 11 commits into from

Conversation

sastan
Copy link
Collaborator

@sastan sastan commented Dec 21, 2020

The styled API is commonly used within the react community. Although twind is framework agnostic it may be nice to provide a styled module as well.

The API is inspired by emotion, styled-component and goober. This PR adds three new modules:

  • twind/styled - base implementation and framework agnostic
  • twind/styled/react - ready to use with react
  • twind/styled/preact - ready to use with preact

See docs/styled.md

An example is available as example/styled.tsx. After yarn start open http://localhost:8080/styled.html.

Try the Preview Package

Official releases are only available on registry.npmjs.org as twind.

This PR has been published to npm.pkg.github.com as @tw-in-js/twind@pr7.

Install/Update

Configure your NPM client (click to expand)

Adjust you .npmrc to use https://npm.pkg.github.com for @tw-in-js

@tw-in-js:registry=https://npm.pkg.github.com

Using the command line:

npm config set @tw-in-js:registry https://npm.pkg.github.com --global
# For npm
npm install --force twind@npm:@tw-in-js/twind@pr7

# For yarn - upgrade implies install
yarn upgrade twind@npm:@tw-in-js/twind@pr7

Benchmarks

# Object Styles
twind: <div color="black" class="tw-3u6ba0 tw-14ssw6o"></div>
goober: <div color="black" random="0.014518000616767335" class="go3334449672" data-reactroot=""></div>
emotion: <style data-emotion="css 14zyg7u">.css-14zyg7u{display:inline-block;border-radius:3px;padding:0.5rem 0;margin:0.5rem 1rem;width:11rem;background:transparent;color:white;border:2px solid white;font-size:0.875rem;line-height:1.25rem;}.css-14zyg7u:hover{color:black;opacity:0;}.css-14zyg7u:focus{border:2px dashed black;}@media (min-width: 768px){.css-14zyg7u{font-size:1rem;line-height:1.5rem;}}@media (min-width: 1280px){.css-14zyg7u{font-size:1.125rem;line-height:1.75rem;}}</style><div color="black" class="css-14zyg7u"></div>
styled-components: <div color="black" class="sc-bdfBwQ kIZhoG"></div>
twind x 52,441 ops/sec ±0.55% (90 runs sampled)
goober@2.0.18 x 40,491 ops/sec ±0.43% (96 runs sampled)
emotion@11.0.0 x 36,848 ops/sec ±0.69% (91 runs sampled)
styled-components@5.2.1 x 38,456 ops/sec ±0.62% (90 runs sampled)

Fastest is: twind

# Template Literal Styles
twind: <div color="black" class="tw-la1urp inline-block rounded py-2 my-2 mx-4 w-44 bg-transparent text-white border-2 border-solid border-white hover:text-black hover:opacity-100 focus:border-2 focus:border-dashed focus:border-black text-sm md:text-base lg:text-lg"></div>
goober: <div color="black" random="0.44058694455997416" class="go602841230" data-reactroot=""></div>
emotion: <style data-emotion="css 1j1rmlp">.css-1j1rmlp{display:inline-block;border-radius:3px;padding:0.5rem 0;margin:0.5rem 1rem;width:11rem;background:transparent;color:white;border:2px solid white;font-size:0.875rem;line-height:1.25rem;}.css-1j1rmlp:hover{color:black;opacity:1;}.css-1j1rmlp:focus{border:2px dashed black;}@media (min-width: 768px){.css-1j1rmlp{font-size:1rem;line-height:1.5rem;}}@media (min-width: 1280px){.css-1j1rmlp{font-size:1.125rem;line-height:1.75rem;}}</style><div color="black" class="css-1j1rmlp"></div>
styled-components: <div color="black" class="sc-gsTCUz bzdKjA"></div>
twind x 57,979 ops/sec ±0.38% (93 runs sampled)
goober@2.0.18 x 43,721 ops/sec ±0.56% (96 runs sampled)
emotion@11.0.0 x 36,768 ops/sec ±0.63% (94 runs sampled)
styled-components@5.2.1 x 57,611 ops/sec ±0.45% (94 runs sampled)

Fastest is: twind

@sastan sastan added the pr³ ✨ Feature New Feature label Dec 21, 2020
@sastan sastan force-pushed the twind-styled branch 4 times, most recently from 474a81a to 53c2c66 Compare December 21, 2020 19:29
@sastan sastan changed the title twind/styled WIP: twind/styled Dec 22, 2020
Copy link
Contributor

@lukejacksonn lukejacksonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all LGTM. The only comment I have is around the linting errors people who use styled already are going to recieve when using styled.xxx`` but I guess if we made tw.xxx`` available that might get confusing.

I don't think it's something that should prevent this from being merged but something we should think about.

@lukejacksonn
Copy link
Contributor

After looking at and playing with the awesome demo in #44 I realised that it is possible to just do:

import { styled as twind } from "twind/styled/react";

const Button = twind.button`...`

Which prevents the styled linter plugin on codesandbox from erroring. Perhaps we recommend something like this.

@sastan
Copy link
Collaborator Author

sastan commented Jan 2, 2021

That is a good idea 💡. I'll try to look through the comment to see if wee can implement some of the other ideas.

@sastan sastan linked an issue Jan 4, 2021 that may be closed by this pull request
@coveralls
Copy link

Pull Request Test Coverage Report for Build 473256276

  • -1 of 601 (99.83%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-1.6%) to 93.76%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/styled/index.ts 549 550 99.82%
Totals Coverage Status
Change from base Build 473243139: -1.6%
Covered Lines: 4559
Relevant Lines: 4846

💛 - Coveralls

@coveralls
Copy link

coveralls commented Jan 9, 2021

Pull Request Test Coverage Report for Build 473326666

  • 600 of 601 (99.83%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.3%) to 95.69%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/styled/index.ts 549 550 99.82%
Totals Coverage Status
Change from base Build 473316997: 0.3%
Covered Lines: 4649
Relevant Lines: 4846

💛 - Coveralls

@sastan sastan linked an issue Jan 10, 2021 that may be closed by this pull request
@sastan sastan removed a link to an issue Jan 10, 2021
@sastan sastan force-pushed the main branch 2 times, most recently from d3d2fb6 to a63ed92 Compare January 15, 2021 21:55
@sastan sastan mentioned this pull request Jan 29, 2021
@sastan
Copy link
Collaborator Author

sastan commented Jan 29, 2021

We will focus our efforts on a new PR once #102 is agreed on.

@sastan sastan closed this Jan 29, 2021
@sastan sastan deleted the twind-styled branch February 20, 2021 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr³ ✨ Feature New Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeScript Issues with Styled API for React
4 participants