feat(image): add scale prop to image container

This commit is contained in:
unix
2020-03-23 08:46:48 +08:00
parent 67a135c01e
commit 2d2d9d33de
2 changed files with 7 additions and 3 deletions

View File

@@ -9,17 +9,19 @@ interface Props {
width?: number
height?: number
className?: string
scale?: string
}
const defaultProps = {
animation: true,
className: '',
scale: '100%',
}
export type ImageProps = Props & typeof defaultProps & React.ImgHTMLAttributes<any>
const Image: React.FC<ImageProps> = React.memo(({
src, width, height, animation, className, ...props
src, width, height, animation, className, scale, ...props
}) => {
const showAnimation = animation && width && height
const theme = useTheme()
@@ -67,8 +69,9 @@ const Image: React.FC<ImageProps> = React.memo(({
}
img {
width: 100%;
height: 100%;
width: ${scale};
height: ${scale};
object-fit: scale-down;
}
`}</style>
</div>

View File

@@ -44,6 +44,7 @@ Display image content.
| **animation** | display animation when loading | `boolean` | - | `true` |
| **width** | width | `number` | - | - |
| **height** | height | `number` | - | - |
| **scale** | scale value | `string` | - | `100%` |
| ... | native props | `ImgHTMLAttributes` | `'alt', 'className', ...` | - |
</Attributes>