Replies: 2 comments 4 replies
-
My only concern with the // Text.tsx
export const Text = styled('span', {...})
// Link.tsx
import { Text } from './Text';
Text.withProps = { as: 'a' };
export const Link = Text;
// App.tsx
import { Text } from './Text';
import { Link } from './Link';
export const App = () => (
<div>
<Link href="#">Link</Link>
<Text>This will be an anchor but only because `Link` is used in the same file!!</Text>
</div>
) You can see a demonstration of this issue with our I really think both of these APIs need to happen before the component is created (much like const Title = styled.withProps({})(Text, {}); And for const Button = styled(
{
border: 0,
variants: {
color: {},
appearance: {},
}
},
// compoundVariants
{
composes: { color: 'red', appearance: 'outline' },
color: 'gray',
border: '1px solid gray',
},
{
composes: { color: 'violet', appearance: 'outline' },
color: 'violet',
border: '1px solid violet',
},
); |
Beta Was this translation helpful? Give feedback.
-
What about something like this? export const Text = styled('span', {
fontFamily: "$system",
variants: {
size: {
1: { fontSize: "$1" },
2: { fontSize: "$2" },
3: { fontSize: "$3" },
}
}
})
export const Title = styled(Text, {
textTransform: "uppercase",
lineHeight: "1.2em",
bp1: {
lineHeight: "1.3em"
}
})
Title.defaultProps = {
as: "h1",
size: {
initial: "2",
bp1: "3"
}
} |
Beta Was this translation helpful? Give feedback.
-
I'd like to open up a discussion about composing Stitches components which include pre-defined props/variants/styles.
A common example of this is to create higher-level components, which implement low-level components.
For the sake of this issue, I'll be using the following components:
Text
- contains its base styles and variantsTitle
- implementsText
with a set of opinions, eg: which variant to use.The way to do this currently, is like so:
Technically this would work, but it suffers from the following issues:
Title
component is no longer types, resulting in a poorer DXTo solve issue number 1, lack to typing, we need to do:
To solve issue number 2, merging css objects, we could introduce a
css.compose
function:To solve issue number 3, too much boilerplate, we introduce a first-class API to set default props, thinking of something along the lines of
withProps
. Similar to ReactsdefaultProps
(which is being deprecated). This solution would ensure the typings are correct and that any css passed in is properly merged:Conclusion
The idea is that we keep our options open. If someone just needs to compose a low-level component and set a few opinions, such as which variant to use, they can use the
withProps
API.If someone needs to compose a low-level component, but add extra functionality - such as a loading animation on a button - they can manually type their components with
React.ComponentProps<typeof StitchesComponent>
.Finally, if someone needs to merge css objected passed in from the outside, they can use the
css.compose
function.Beta Was this translation helpful? Give feedback.
All reactions