Skip to content

Commit

Permalink
fix: merge className prop instead of overriding
Browse files Browse the repository at this point in the history
  • Loading branch information
igordanchenko committed May 10, 2023
1 parent 4876ba3 commit adc8c3f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/components/renderers/ColumnContainerRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from "react";

import clsx from "../../utils/clsx";
import round from "../../utils/round";
import { Optional, Photo, RenderColumnContainer, RenderColumnContainerProps } from "../../types";

Expand Down Expand Up @@ -40,12 +41,12 @@ export default function ColumnContainerRenderer<T extends Photo = Photo>(props:
layoutOptions,
renderColumnContainer,
children,
columnContainerProps: { style, ...restColumnContainerProps } = {},
columnContainerProps: { style, className, ...restColumnContainerProps } = {},
...rest
} = props;

const columnContainerProps = {
className: "react-photo-album--column",
className: clsx("react-photo-album--column", className),
style: {
display: "flex",
flexDirection: "column",
Expand Down
5 changes: 3 additions & 2 deletions src/components/renderers/ContainerRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from "react";

import clsx from "../../utils/clsx";
import { Optional, RenderContainer, RenderContainerProps } from "../../types";

function defaultRenderContainer({ containerProps, children, containerRef }: RenderContainerProps) {
Expand All @@ -20,11 +21,11 @@ export default function ContainerRenderer(props: ContainerRendererProps) {
renderContainer,
children,
containerRef,
containerProps: { style, ...restContainerProps } = {},
containerProps: { style, className, ...restContainerProps } = {},
} = props;

const containerProps = {
className: `react-photo-album react-photo-album--${layout}`,
className: clsx("react-photo-album", `react-photo-album--${layout}`, className),
style: {
display: "flex",
flexWrap: "nowrap",
Expand Down
11 changes: 9 additions & 2 deletions src/components/renderers/PhotoRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from "react";

import clsx from "../../utils/clsx";
import round from "../../utils/round";
import { ImageElementAttributes, LayoutOptions, Photo, PhotoLayout, RenderPhoto, RenderPhotoProps } from "../../types";

Expand Down Expand Up @@ -65,7 +66,13 @@ export type PhotoRendererProps<T extends Photo = Photo> = Omit<
};

export default function PhotoRenderer<T extends Photo = Photo>(props: PhotoRendererProps<T>) {
const { photo, layout, layoutOptions, imageProps: { style, ...restImageProps } = {}, renderPhoto } = props;
const {
photo,
layout,
layoutOptions,
imageProps: { style, className, ...restImageProps } = {},
renderPhoto,
} = props;
const { onClick } = layoutOptions;

const imageStyle = {
Expand Down Expand Up @@ -95,7 +102,7 @@ export default function PhotoRenderer<T extends Photo = Photo>(props: PhotoRende
title: photo.title,
onClick: handleClick,
style: imageStyle,
className: "react-photo-album--photo",
className: clsx("react-photo-album--photo", className),
loading: "lazy" as const,
decoding: "async" as const,
...srcSetAndSizes(photo, layout, layoutOptions),
Expand Down
5 changes: 3 additions & 2 deletions src/components/renderers/RowContainerRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from "react";

import clsx from "../../utils/clsx";
import { Optional, Photo, RenderRowContainer, RenderRowContainerProps } from "../../types";

function defaultRenderRowContainer<T extends Photo = Photo>({
Expand All @@ -22,12 +23,12 @@ export default function RowContainerRenderer<T extends Photo = Photo>(props: Row
rowIndex,
rowsCount,
renderRowContainer,
rowContainerProps: { style, ...restRowContainerProps } = {},
rowContainerProps: { style, className, ...restRowContainerProps } = {},
children,
} = props;

const rowContainerProps = {
className: "react-photo-album--row",
className: clsx("react-photo-album--row", className),
style: {
display: "flex",
flexDirection: "row",
Expand Down
3 changes: 3 additions & 0 deletions src/utils/clsx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function clsx(...classes: (string | boolean | undefined)[]) {
return [...classes].filter((cls) => Boolean(cls)).join(" ");
}

0 comments on commit adc8c3f

Please sign in to comment.