Skip to content

Commit 79e729f

Browse files
authored
feat: Add className props to ImageWithZoom (#257)
* Add className prop to ImageWithZoom * Add imageClassName prop to ImageWithZoom * Add overlayClassName prop to ImageWithZoom
1 parent 5b8f8af commit 79e729f

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/ImageWithZoom/ImageWithZoom.jsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ const ImageWithZoom = class ImageWithZoom extends React.Component {
1313
static propTypes = {
1414
// alt: PropTypes.string,
1515
carouselStore: PropTypes.object.isRequired,
16+
className: PropTypes.string,
17+
imageClassName: PropTypes.string,
18+
overlayClassName: PropTypes.string,
1619
spinner: PropTypes.func,
1720
src: PropTypes.string.isRequired,
1821
srcZoomed: PropTypes.string,
@@ -21,6 +24,9 @@ const ImageWithZoom = class ImageWithZoom extends React.Component {
2124
}
2225

2326
static defaultProps = {
27+
className: null,
28+
imageClassName: null,
29+
overlayClassName: null,
2430
isPinchZoomEnabled: true,
2531
spinner: null,
2632
srcZoomed: null,
@@ -264,6 +270,9 @@ const ImageWithZoom = class ImageWithZoom extends React.Component {
264270
render() {
265271
const {
266272
carouselStore,
273+
className,
274+
imageClassName,
275+
overlayClassName,
267276
isPinchZoomEnabled,
268277
spinner,
269278
src,
@@ -272,18 +281,25 @@ const ImageWithZoom = class ImageWithZoom extends React.Component {
272281
...filteredProps
273282
} = this.props;
274283

275-
const imageClassName = cn([
284+
const newClassName = cn([
285+
s.container,
286+
className,
287+
]);
288+
289+
const newImageClassName = cn([
276290
s.image,
277291
'carousel__zoom-image',
292+
imageClassName,
278293
]);
279294

280-
const overlayClassName = cn([
295+
const newOverlayClassName = cn([
281296
s.overlay,
282297
'carousel__zoom-image-overlay',
283298
this.state.isHovering && s.hover,
284299
this.state.isZooming && s.zoom,
285300
this.state.isHovering && 'carousel__zoom-image-overlay--hovering',
286301
this.state.isZooming && 'carousel__zoom-image-overlay--zooming',
302+
overlayClassName,
287303
]);
288304

289305
const overlayStyle = {};
@@ -293,17 +309,17 @@ const ImageWithZoom = class ImageWithZoom extends React.Component {
293309
}
294310

295311
return (
296-
<Tag className={s.container} {...filteredProps}>
312+
<Tag className={newClassName} {...filteredProps}>
297313
<Image
298-
className={imageClassName}
314+
className={newImageClassName}
299315
tag="div"
300316
src={src}
301317
isBgImage
302318
onLoad={this.handleImageComplete}
303319
onError={this.handleImageComplete}
304320
/>
305321
<Image
306-
className={overlayClassName}
322+
className={newOverlayClassName}
307323
tag="div"
308324
src={srcZoomed || src}
309325
style={overlayStyle}

typings/carouselElements.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ declare const Slide: SlideInterface
4747

4848

4949
interface ImageWithZoomProps {
50+
readonly className?: string
51+
readonly imageClassName?: string
52+
readonly overlayClassName?: string
5053
readonly src: string
5154
readonly srcZoomed?: string
5255
readonly tag?: string
56+
readonly isPinchZoomEnabled?: boolean
5357
}
5458
type ImageWithZoomInterface = React.ComponentClass<ImageWithZoomProps>
5559
declare const ImageWithZoom: ImageWithZoomInterface

0 commit comments

Comments
 (0)