We're phasing out Box
, Flex
and Grid
in favor of our new styling API.
#2430
mannycarrera4
started this conversation in
General
Replies: 1 comment 3 replies
-
Do you think CKR will end up publishing a const BaseStyles = createStyles({
boxSizing: border-box,
});
const Base = createComponent('div')({
displayName: 'MyComponent',
Component: ({children, ...elemProps}: CSProps, ref, Element) => {
return (
<Element ref={ref} {...mergeStyles(elemProps, [BaseStyles])}>
{children}
</Element>
);
},
}); |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In Canvas Kit v10, we're introduced a new way of styling. This allows us to generate styles in a more efficient and predictable way rather than relying on Emotion's costly runtime. This also meant that we've decided as team to move away from style props and phase out our atomic level components.
Prior to v10, we heavily used our atomic level components such as
Box
,Flex
andGrid
which allowed us to use style props. The benefits where to give our consumers and ourselves a quick way to style an element.However, the biggest fallback was the lack of understanding how styles merged especially when consumers would extend a component that used styled props and styled an element using the
css
prop orstyled
components from Emotion.Why is style merging unpredictable with style props?
Style props create an unpredictable interface. A style prop is always valid according to TypeScript and JavaScript runtime, but whether that style prop actually applies the style depends on the implementation of the component you use.
If the component you use supports and only uses style props, the style prop works. If the component uses any other method of styling, like creating styled components, it will not work.
Example:
Style props employ "prop drilling" to get the style prop all the way down to the Box element while styled and the
css
prop apply styles at every render.styled
andcss
are predictable. They apply at the level you declare them. Style props drill down to the component that implements them.Example:
With
mergeStyles
, thecs
prop works the same way - at eachmergeStyles
call.mergeStyles
reduces everycs
prop toclassName
andstyle
attributes the same waystyled
and thecss
prop reduce to aclassName
. This is why you don't ever see acss
prop being passed on the prop list. It is always removed and turned into a classNameIn order for us to move forward and to provide a more predictable way of style merging, we've decided as a team to start phasing out the usage of
Box
,Flex
andGrid
within Canvas Kit.We hold the firm belief that we should not impose on our consumers a strict way of styling or how to overwrite styles, but we aim to guide you in the best approach to do so.
So what does styling look like if we don't use
Box
,Flex
andGrid
.What about creating complex styles based on props or state?
We want to introduce a simpler way to group your styles, which would look like
stencils
. Here's a great discussion by @NicholasBoll describing how stencils would work. This allows consumers and us to style more complex components.Ideally we'd also like to update
createComponent
so that it simplifies the types and usage of stencils.Beta Was this translation helpful? Give feedback.
All reactions