-
Notifications
You must be signed in to change notification settings - Fork 44
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
Changes from 9 commits
cf0b930
1b61090
af5f733
c8dcf8a
0b87da1
6fbb88a
b6192df
867c535
f7534d4
e914ffe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> | ||
); | ||
}, | ||
}; |
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"]; | ||
}; | ||
|
||
const ImageBlock: React.FC<Props> = ({ src, alt }) => { | ||
if (src) { | ||
return ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't need { } for strings |
||
</BlankImageBox> | ||
); | ||
}; | ||
|
||
const Wrapper = styled.div` | ||
position: absolute; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; |
There was a problem hiding this comment.
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