Show your utils #799
Replies: 2 comments 5 replies
-
We have a textStyle: (style: keyof typeof textStyles) => {
return textStyles[style];
} So now I can use |
Beta Was this translation helpful? Give feedback.
-
Sharing a few thoughts... At work, I decided to prefix all of our utils with Here are our most popular utils: const stitches = createStitches({
utils: {
// Nudge an element by a certain number of pixels
_nudgeX: (x: number) => ({ transform: `translateX(${ x }px)` }),
_nudgeY: (y: number) => ({ transform: `translateY(${ y }px)` }),
_nudge: ([x, y]: [number, number]) => ({ transform: `translate(${ x }px, ${y}px)` }),
// Clamp a line of text to a certain number of rows
_lineClamp: (value: number) => ({
display: "-webkit-box",
WebkitLineClamp: value,
WebkitBoxOrient: "vertical",
overflow: "hidden"
}),
// Truncate a line of text with an ellipsis
_truncate: () => ({
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap"
})
}
}) When I first started the project I added a const typographicStyles = {
display: { fontSize: 50, fontFamily: "fantasy" },
heading: { fontSize: 25, fontFamily: "cursive" }
}
const stitches = createStitches({
utils: {
_typography: (style: keyof typeof typographicStyles) => (typographicStyles[style])
}
}) But eventually I replaced it in favor of a const typography = css({
variants: {
typeStyle: {
display: { fontSize: 50, fontFamily: "fantasy" },
heading: { fontSize: 25, fontFamily: "cursive" }
}
}
}) I prefer the latter since it is already used as the basis for a reusable |
Beta Was this translation helpful? Give feedback.
-
I think one of the greatest things is the possibility to create theme utils that make our lives easier. How about we use this discussion to showcase and list what the users have created?
Beta Was this translation helpful? Give feedback.
All reactions