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

Brainstorm how to abstract utils #383

Closed
peduarte opened this issue Feb 15, 2021 · 2 comments
Closed

Brainstorm how to abstract utils #383

peduarte opened this issue Feb 15, 2021 · 2 comments
Assignees
Labels

Comments

@peduarte
Copy link
Contributor

peduarte commented Feb 15, 2021

With types

Related: #129

@jonathantneal
Copy link
Contributor

We have a proposal in #659 that adds ScaleValue and PropertyValue utilities.

The ScaleValue utility types a value to accept any token value from a given scale.

The PropertyValue utility types a value to accept any token or css value from a given property.

import * as Stitches from '@stitches/react'

export const c = (value: Stitches.ScaleValue<'colors'>) => ({
	color: value,
})

export const mx = (value: Stitches.PropertyValue<'marginLeft'> | Stitches.PropertyValue<'marginLeft'>[]) => Array.isArray(value) ? {
	marginLeft: value[0],
	marginRight: value[1] || value[0]
} : {
	marginLeft: value,
	marginRight: value
}
import { createCss } from '@stitches/react'
import * as utils from './utils'

const { styled } = createCss({
	theme: {
		colors: {
			red: '#ff0000',
		},
	},
	utils,
})

const Button1 = styled('button', {
	c: '$red',
	mx: 'auto'
})

const Button2 = styled('button', {
	c: '$red',
	mx: ['auto', 0]
})

screenshot from the above code suggesting the c property

screenshot from the above code suggesting values for the c property

@peduarte
Copy link
Contributor Author

Fixed in V1. Please refer to migration guide and changelog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants