I am currently in the process of transitioning my design system from styled-components to emotion.
Within styled-components, the following syntax is considered valid:
export interface AvatarProps {
// ...
shape: AvatarShape;
size: AvatarSize;
}
const borderRadiusByShape = css<Pick<AvatarProps, "shape" | "size">>`
border-radius: ${(props) => {
return match(props.shape)
.with("circle", () => `${props.size}px`)
.with("square", () => "0px")
...
.exhaustive();
}}
`;
const StyledAvatar = styled.div<AvatarProps>`
/* ... */
${borderRadiusByShape};
`;
This approach allows for the reuse of borderRadius
in various styled.[x]
declarations.
Upon reviewing emotion's css
function, it appears that emotion does not support this syntax. Is there a workaround that would eliminate the need to encapsulate this functionality within a new component?