-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is nothing but just a wrapper component with special handling for transform sx prop.
- Loading branch information
1 parent
10230f9
commit 424a97a
Showing
8 changed files
with
86 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { PolymorphicComponent } from './base'; | ||
import type { SxProp } from './sx'; | ||
|
||
declare const Box: PolymorphicComponent<SxProp, {}>; | ||
|
||
export { Box }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as React from 'react'; | ||
|
||
// eslint-disable-next-line react/prop-types | ||
export const Box = React.forwardRef(({ as = 'div', sx, className, style, ...rest }, ref) => { | ||
const Component = as; | ||
// eslint-disable-next-line react/prop-types | ||
const sxClass = typeof sx === 'string' ? sx : sx?.className; | ||
const classes = [className, sxClass].filter(Boolean).join(' '); | ||
// eslint-disable-next-line react/prop-types | ||
const sxVars = sx && typeof sx !== 'string' ? sx?.vars : {}; | ||
const varStyles = {}; | ||
|
||
if (sxVars) { | ||
Object.entries(sxVars).forEach(([cssVariable, [value, isUnitLess]]) => { | ||
if (typeof value === 'string' || isUnitLess) { | ||
varStyles[`--${cssVariable}`] = value; | ||
} else { | ||
varStyles[`--${cssVariable}`] = `${value}px`; | ||
} | ||
}); | ||
} | ||
const styles = { | ||
...style, | ||
...varStyles, | ||
}; | ||
return <Component ref={ref} className={classes} style={styles} {...rest} />; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import * as React from 'react'; | ||
import { Box } from '@pigment-css/react/Box'; | ||
|
||
export function App() { | ||
return ( | ||
<Box as="div" sx={{ display: 'flex' }}> | ||
<Box as="p" sx={() => ({ color: 'primary' })}> | ||
Hello{' '} | ||
<Box as="a" href="https://mui.com" download> | ||
Link | ||
</Box> | ||
</Box> | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters