diff --git a/package.json b/package.json index dc9ee7f..101c00c 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "sideEffects": false, "scripts": { "prepublishOnly": "npm run build", - "clean": "rimraf dist", + "clean": "rimraf dist && rimraf node_modules/.cache", "rollup:build": "rollup -c", "watch": "rollup -c -w", "build": "npm run clean && npm run rollup:build", diff --git a/src/CheckButton.tsx b/src/CheckButton.tsx index 08b5fb7..3a5de79 100755 --- a/src/CheckButton.tsx +++ b/src/CheckButton.tsx @@ -2,10 +2,14 @@ import { useState } from "react"; import * as styles from "./styles"; import { CheckButtonProps } from "./types"; -export const CheckButton = (props: CheckButtonProps): JSX.Element => { - const { isSelected, isVisible, onClick } = props; - const { selectedColor, hoverColor, color } = props; - +export const CheckButton = ({ + isSelected = false, + isVisible = true, + onClick, + color = "#FFFFFFB2", + selectedColor = "#4285F4FF", + hoverColor = "#FFFFFFFF", +}: CheckButtonProps): JSX.Element => { const [hover, setHover] = useState(false); const circleStyle = { display: isSelected ? "block" : "none" }; @@ -57,11 +61,3 @@ export const CheckButton = (props: CheckButtonProps): JSX.Element => { ); }; - -CheckButton.defaultProps = { - isSelected: false, - isVisible: true, - color: "#FFFFFFB2", - selectedColor: "#4285F4FF", - hoverColor: "#FFFFFFFF", -}; diff --git a/src/Gallery.tsx b/src/Gallery.tsx index 5c4c1b1..793d543 100755 --- a/src/Gallery.tsx +++ b/src/Gallery.tsx @@ -5,14 +5,23 @@ import { buildLayoutFlat } from "./buildLayout"; import { Image as ImageInterface, GalleryProps } from "./types"; import * as styles from "./styles"; -export const Gallery = ( - props: GalleryProps -): JSX.Element => { +export const Gallery = ({ + images, + id = "ReactGridGallery", + enableImageSelection = true, + onSelect = () => {}, + rowHeight = 180, + maxRows, + margin = 2, + defaultContainerWidth = 0, + onClick = () => {}, + tileViewportStyle, + thumbnailStyle, + tagStyle, + thumbnailImageComponent, +}: GalleryProps): JSX.Element => { const galleryRef = useRef(null); - const { maxRows, rowHeight, margin, enableImageSelection } = props; - const { defaultContainerWidth, images } = props; - const [containerWidth, setContainerWidth] = useState(defaultContainerWidth); const handleResize = useCallback(() => { @@ -39,15 +48,15 @@ export const Gallery = ( const handleSelect = (index: number, event: MouseEvent) => { event.preventDefault(); - props.onSelect(index, images[index], event); + onSelect(index, images[index], event); }; const handleClick = (index: number, event: MouseEvent) => { - props.onClick(index, images[index], event); + onClick(index, images[index], event); }; return ( -
+
{thumbnails.map((item, index) => ( @@ -60,10 +69,10 @@ export const Gallery = ( isSelectable={enableImageSelection} onClick={handleClick} onSelect={handleSelect} - tagStyle={props.tagStyle} - tileViewportStyle={props.tileViewportStyle} - thumbnailStyle={props.thumbnailStyle} - thumbnailImageComponent={props.thumbnailImageComponent} + tagStyle={tagStyle} + tileViewportStyle={tileViewportStyle} + thumbnailStyle={thumbnailStyle} + thumbnailImageComponent={thumbnailImageComponent} /> ))}
@@ -72,13 +81,3 @@ export const Gallery = ( }; Gallery.displayName = "Gallery"; - -Gallery.defaultProps = { - id: "ReactGridGallery", - enableImageSelection: true, - rowHeight: 180, - margin: 2, - defaultContainerWidth: 0, - onClick: () => {}, - onSelect: () => {}, -}; diff --git a/src/Image.tsx b/src/Image.tsx index db036ac..99f229a 100755 --- a/src/Image.tsx +++ b/src/Image.tsx @@ -4,32 +4,52 @@ import { ImageExtended, ImageProps } from "./types"; import * as styles from "./styles"; import { getStyle } from "./styles"; -export const Image = ( - props: ImageProps -): JSX.Element => { - const { item, thumbnailImageComponent: ThumbnailImageComponent } = props; +export const Image = ({ + item, + thumbnailImageComponent: ThumbnailImageComponent, + isSelectable = true, + thumbnailStyle, + tagStyle, + tileViewportStyle, + margin, + index, + onSelect, + onClick, +}: ImageProps): JSX.Element => { const styleContext = { item }; const [hover, setHover] = useState(false); const thumbnailProps = { - key: props.index, + key: index, "data-testid": "grid-gallery-item_thumbnail", src: item.src, alt: item.alt ? item.alt : "", title: typeof item.caption === "string" ? item.caption : null, - style: getStyle(props.thumbnailStyle, styles.thumbnail, styleContext), + style: getStyle(thumbnailStyle, styles.thumbnail, styleContext), }; const handleCheckButtonClick = (event: MouseEvent) => { - if (!props.isSelectable) { + if (!isSelectable) { return; } - props.onSelect(props.index, event); + onSelect(index, event); }; const handleViewportClick = (event: MouseEvent) => { - props.onClick(props.index, event); + onClick(index, event); + }; + + const thumbnailImageProps = { + item, + index, + margin, + onSelect, + onClick, + isSelectable, + tileViewportStyle, + thumbnailStyle, + tagStyle, }; return ( @@ -38,7 +58,7 @@ export const Image = ( data-testid="grid-gallery-item" onMouseEnter={() => setHover(true)} onMouseLeave={() => setHover(false)} - style={styles.galleryItem({ margin: props.margin })} + style={styles.galleryItem({ margin })} >
( >
@@ -62,9 +82,7 @@ export const Image = ( title={tag.title} style={styles.tagItemBlock} > - + {tag.value}
@@ -84,22 +102,21 @@ export const Image = (
{ThumbnailImageComponent ? ( - + ) : ( )} @@ -115,7 +132,3 @@ export const Image = (
); }; - -Image.defaultProps = { - isSelectable: true, -}; diff --git a/src/types.ts b/src/types.ts index 4444d3b..4559cba 100644 --- a/src/types.ts +++ b/src/types.ts @@ -61,14 +61,14 @@ export interface ImageProps { item: T; index: number; margin: number; - height: number; isSelectable: boolean; onClick: (index: number, event: MouseEvent) => void; onSelect: (index: number, event: MouseEvent) => void; tileViewportStyle: StyleProp; thumbnailStyle: StyleProp; tagStyle: StyleProp; - thumbnailImageComponent: ComponentType; + height?: number; + thumbnailImageComponent?: ComponentType; } export interface ThumbnailImageComponentImageProps { @@ -104,7 +104,7 @@ export interface CheckButtonProps { isSelected: boolean; isVisible: boolean; onClick: (event: MouseEvent) => void; - color: string; - selectedColor: string; - hoverColor: string; + color?: string; + selectedColor?: string; + hoverColor?: string; }