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

View File

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