Support a styled API same as the one found styled-components or @emotion/styled #882
Replies: 2 comments 3 replies
-
Heyo! That's actually a good question, I might add this to the FAQ page. On the other hand, Fela shipped with pretty much the same API long before styled-components was even a thing: createComponent The only difference is that it's a generic function with the order of arguments switched. e.g. const Button = createComponent({
appearance: "none",
border: 0,
backgroundColor: "blue",
fontSize: 16,
padding: 10,
textAlign: "center",
color: "white",
":hover": {
backgroundColor: "lightblue"
}
}, "button")
It also accepts a function of const style = ({ size, theme }) => ({
appearance: "none",
border: 0,
backgroundColor: theme.colors.primary,
fontSize: size,
padding: 10,
textAlign: "center",
color: "white",
":hover": {
backgroundColor: theme.colors.primaryDark
}
})
const Button = createComponent(style, "button") But, as mentioned in the docs I actually recommend |
Beta Was this translation helpful? Give feedback.
-
You are right styled-component API is complex and it includes some overhead but what I meant is to provide a simple styled API like this one, interface INameProps { $name: string; }
const Box1 = styled("div")<INameProps>(
// the type of props will be INameProps and div element props
{},
props => ({})
);
interface IAgeProps { $age: number; }
const Box2 = styled.extend(Box2)<IAgeProps>(
// The type of props will be INameProps, IAgeProps and div element props
props => ({})
);
const test = (
<Box2
as="button"
type="submit"
// css prop for arbitrary styles
css={{
margin: "20px"
}}/>
) Also, a responsive variant API (like the one found in stitches) can be built on top of the fela styled API, but I will write it on my own, and if you become interested in the future I can contribute to this project. |
Beta Was this translation helpful? Give feedback.
-
It would be nice if react-fela did support a styled API same as the one found styled-components or @emotion/styled, it could use the useFela hook under the hood if you don't intend to support the feature could you please explain why?
Beta Was this translation helpful? Give feedback.
All reactions