Skip to content

Instantly share code, notes, and snippets.

@EHF32
Created April 21, 2022 07:22
Show Gist options
  • Save EHF32/b9d492448525c967ad9f82dba56957de to your computer and use it in GitHub Desktop.
Save EHF32/b9d492448525c967ad9f82dba56957de to your computer and use it in GitHub Desktop.
react-admin ImageField compoment with custom width
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