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
39 changes: 39 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,39 @@
import { Meta, StoryObj } from "@storybook/react";

import ImageBlock from ".";

export default {
component: ImageBlock,
} as Meta;

const Container: React.FC<{ children?: React.ReactNode }> = ({ children }) => (
<div style={{ width: "430px" }}>{children}</div>
);

type Story = StoryObj<typeof ImageBlock>;

export const Default: Story = {
args: {
src: "http://placehold.it/430X260",
},
render: args => {
return (
<Container>
<ImageBlock {...args} />
</Container>
);
},
};

export const Blank: Story = {
args: {
src: "",
},
render: args => {
return (
<Container>
<ImageBlock {...args} />
</Container>
);
},
};
43 changes: 43 additions & 0 deletions web/src/beta/components/Blocks/ImageBlock/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import Icon from "@reearth/beta/components/Icon";
import { styled } from "@reearth/services/theme";

type Props = {
src: NonNullable<React.ImgHTMLAttributes<HTMLImageElement>["src"]>;
alt?: React.ImgHTMLAttributes<HTMLImageElement>["alt"];
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to type so specifically. For some elements, where there are specific values needed, this is good.
But for something like src and alt, any string is okay, so you can just type these as string

};

const ImageBlock: React.FC<Props> = ({ src, alt }) => {
if (src) {
return (
Copy link
Member

Choose a reason for hiding this comment

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

Like the Video block , please use a ternary operator with one return 🙇🏻

<Wrapper>
<ImageBox src={src} alt={alt} />
</Wrapper>
);
}
return (
<BlankImageBox>
<Icon icon={"image"} color={"#2e2e2e"} size={32} />
Copy link
Member

@KaWaite KaWaite Jun 29, 2023

Choose a reason for hiding this comment

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

Don't need { } for strings
so icon="image" color="#2e2e2e"

</BlankImageBox>
);
};

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

width: inherit;
`;

const ImageBox = styled.img`
display: flex;
object-fit: cover;
width: 100%;
`;

const BlankImageBox = styled.div`
display: flex;
aspect-ratio: 43/26;
background: #f1f1f1;
align-items: center;
justify-content: center;
`;

export default ImageBlock;
3 changes: 3 additions & 0 deletions web/src/beta/components/Icon/Icons/image.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions web/src/beta/components/Icon/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ import TwoRectangle from "./Icons/two-rectangle.svg";
// Plus
import Plus from "./Icons/plus.svg";

// Image
import Image from "./Icons/image.svg";

export default {
file: File,
dl: InfoTable,
Expand Down Expand Up @@ -87,4 +90,5 @@ export default {
workspaceAdd: WorkspaceAdd,
workspaces: Workspaces,
checkmark: CheckMark,
image: Image,
};