Reputation: 575
I'm working within a very atomised structure using @emotion/react
that splits components into several different files:
types.ts
- for types (shared between web and native)styles.ts
- for styling (shared between web and native)logic.ts
- any applicable logic (shared between web and native)web.tsx
- the web componentnative.tsx
- the React native componentIn the styles.ts file, I'd have something like the below:
export const ElementWrapper = css`
border: 1px solid red
`
In the web.tsx
file, I'll compile the component in a way such as below:
import { ElementProps } from './types'
import { ElementWrapper } from './styles'
export const Element = ({ children, ...rest}: PropsWithChildren<ElementProps>) => {
return (
<SOME_ELEMENT css={ElementWrapper} {...rest}>
{children}
</SOME_ELEMENT>
)
}
Is there any way to pass styling props to the ElementWrapper
component in the current setup? For example, a marginRight=false
style of prop that I could access in the styles.ts
file?
I attempted to pass props to the SOME_ELEMENT
component, but obviously they can't be passed through. It also appears there's no way to add further props to the css property of SOME_ELEMENT
.
Upvotes: 0
Views: 685
Reputation: 1118
I suppose you could make a wrapper function.
export const ElementWrapper = ({marginRight}) => css`
border: 1px solid red;
margin-right: ${marginRight};
`
// ...
return (
<SOME_ELEMENT css={ElementWrapper({marginRight: '5px'})} {...rest}>
{children}
</SOME_ELEMENT>
)
Upvotes: 1