Created
April 21, 2022 07:22
-
-
Save EHF32/b9d492448525c967ad9f82dba56957de to your computer and use it in GitHub Desktop.
react-admin ImageField compoment with custom width
This file contains hidden or 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
import { ImageField } from "react-admin"; | |
import styled from "@emotion/styled"; | |
export default function PreviewImageField({ | |
record, | |
source, | |
width = "unherit", | |
}: any & ImageStyledProps) { | |
if (typeof record == "string") { | |
record = { | |
[source]: record, | |
}; | |
} | |
return <StyledImage width={width} record={record} source={source} />; | |
} | |
const dynamicStyle = (props: ImageStyledProps) => ({ width: props.width }); | |
const StyledImage = styled(ImageField)<ImageStyledProps>` | |
& img { | |
${dynamicStyle} | |
object-fit: cover; | |
} | |
`; | |
type ImageStyledProps = { | |
width: number | string; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment