mirror of
https://github.com/zhigang1992/react.git
synced 2026-04-28 20:25:29 +08:00
feat(image): add scale prop to image container
This commit is contained in:
@@ -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>
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user