trousers
trousers copied to clipboard
V4!
Main branch for all changes related to Trousers v4 π
Original issue: #83 Closes: #83 #80 #79 #74 #67 #13
In a nutshell π°
Trousers in its current form solves a lot of problems for me, but it's becoming clear that it needs to be rearchitected in order to solve some of its the short-comings and modernize it a bit.
V4 has a large focus on:
- Providing a build-time alternative to avoid runtime as much as possible
- Utilise css variables for theming to improve runtime
- Lean into the CSS prop as an API to help us achieve the above
Features
- π Build-time, near-zero runtime via babel marco! π
- CSS-var based theming
- Leaning into the CSS prop
- Zero config SSR
- Modifier predicates are passed into the underlying element via modifier props
$primary - Less dependency on React
- No longer dependant on hooks
- Dynamic properties can be applied to css vars to avoid remounting styles
- Runtime version of the library is faster
- Smaller overall
- New package structure
- Collector API improved
- Styled API
Examples
React
/** @jsx jsx */
import { css, jsx } from '@trousers/react';
const styles = css('button', { backgroundColor: 'var(--theme-background-color)' })
.modifier('primary', { backgroundColor: '#f95b5b' })
.modifier('disabled', { backgroundColor: 'red' });
const Button = props =>
<button css={styles} $primary={props.primary} $disabled={props.disabled}>
{props.children}
</button>;
export default Button;
Macro (build-time only)
import { css } from '@trousers/macro';
const styles = css('button', { backgroundColor: 'var(--theme-background-color)' })
.modifier('primary', { backgroundColor: '#f95b5b' })
.modifier('disabled', { backgroundColor: 'red' });
const Button = props =>
<button css={styles} $primary={props.primary} $disabled={props.disabled}>
{props.children}
</button>;
export default Button;
β οΈ No Changeset found
Latest commit: ded6c10b0016d2b276dcdff1f771dd2afa75f46c
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
Daniel will you ever come back to finish this?
Hey @MrBirb , i definitely want to come back to this and get it over the line. I think this is already very close I just need to do some more thorough testing :)
Thank you! Canβt wait for this to land!
Hey @MrBirb , it would be sweet if you could help me dogfood the current alpha version and LMK what you think!
this should be available in 4.0.0-alpha6
Sure thing! I will try this in the weekend!