Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore(web): Add ImageBlock #511

Closed
wants to merge 10 commits into from
15 changes: 15 additions & 0 deletions web/src/beta/components/Blocks/ImageBlock/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Meta, StoryObj } from "@storybook/react";

import ImageBlock from ".";

export default {
component: ImageBlock,
} as Meta;

type Story = StoryObj<typeof ImageBlock>;

export const Default: Story = {
args: {
src: "http://placehold.it/150X150",
},
};
49 changes: 49 additions & 0 deletions web/src/beta/components/Blocks/ImageBlock/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { CSSProperties, FC, ImgHTMLAttributes } from "react";

import { styled } from "@reearth/services/theme";

type Props = {
src: NonNullable<ImgHTMLAttributes<HTMLImageElement>["src"]>;
align?: "left" | "center" | "right"; // default center
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't need the comments here in the props.
Can you

  • remove the comments
  • Inside the props destructuring(line 15) assign defaults (ie. ({src, align="center", fit="cover", .. .. . .. })
  • Lastly update the styled component's props to expect a value for fit and align always and remove the fallbacks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code has changed.
�Above code no longer exists.

fit?: "contain" | "cover"; // default cover
maxHeight?: CSSProperties["maxHeight"];
alt?: ImgHTMLAttributes<HTMLImageElement>["alt"];
height?: CSSProperties["width"];
width?: CSSProperties["height"];
};

const ImageBlock: FC<Props> = ({ src, align, fit, maxHeight, alt, width, height }) => {
return (
<Wrapper>
<ImageBox
src={src}
fit={fit}
alt={alt}
maxHeight={maxHeight}
width={width}
height={height}
align={align}
/>
</Wrapper>
);
};

const Wrapper = styled.div`
position: absolute;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think you need this

display: flex;
`;

const ImageBox = styled.img<{
fit?: "contain" | "cover";
maxHeight?: CSSProperties["maxHeight"];
align?: "left" | "center" | "right";
}>`
display: flex;
object-fit: ${props => (props.fit ? props.fit : "cover")};
width: ${props => (props.width ? props.width : undefined)};
height: ${props => (props.height ? props.height : undefined)};
max-height: ${props => (props.maxHeight ? props.maxHeight : undefined)};
object-position: ${props => (props.align ? props.align : "center")};
`;

export default ImageBlock;