Skip to content

Commit

Permalink
feat: reorganize ContainerProps, ColumnContainerProps, RowContainerPr…
Browse files Browse the repository at this point in the history
…ops, PhotoProps

Rename PhotoDecorator to PhotoRenderer.
Remove ResponsivePhoto from named exports.
  • Loading branch information
igordanchenko committed Dec 30, 2021
1 parent ebf250c commit 657cf3b
Show file tree
Hide file tree
Showing 16 changed files with 984 additions and 276 deletions.
14 changes: 6 additions & 8 deletions src/PhotoAlbum.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import * as React from "react";
import ResizeObserver from "resize-observer-polyfill";

import Layout from "./Layout";
import RowsLayout from "./components/RowsLayout";
import ColumnsLayout from "./components/ColumnsLayout";
import MasonryLayout from "./components/MasonryLayout";
import PhotoAlbumContainer from "./components/PhotoAlbumContainer";
import RowsLayout from "./components/layouts/RowsLayout";
import ColumnsLayout from "./components/layouts/ColumnsLayout";
import MasonryLayout from "./components/layouts/MasonryLayout";
import ContainerRenderer from "./components/renderers/ContainerRenderer";
import resolveResponsiveParameter from "./utils/responsive";
import useLayoutEffect from "./utils/layoutEffect";
import { ColumnsLayoutOptions, Photo, PhotoAlbumProps, RowsLayoutOptions } from "./types";
Expand Down Expand Up @@ -105,10 +105,8 @@ const PhotoAlbum = <T extends Photo>(props: PhotoAlbumProps<T>): JSX.Element =>

const commonLayoutProps = { photos, renderPhoto, instrumentation };

const Container = renderContainer || PhotoAlbumContainer;

return (
<Container ref={setContainerRef} layoutOptions={layoutOptions}>
<ContainerRenderer ref={setContainerRef} layoutOptions={layoutOptions} renderContainer={renderContainer}>
{layout === Layout.Rows ? (
<RowsLayout<T>
layoutOptions={layoutOptions as RowsLayoutOptions}
Expand All @@ -128,7 +126,7 @@ const PhotoAlbum = <T extends Photo>(props: PhotoAlbumProps<T>): JSX.Element =>
{...commonLayoutProps}
/>
)}
</Container>
</ContainerRenderer>
);
};

Expand Down
43 changes: 0 additions & 43 deletions src/ResponsivePhoto.tsx

This file was deleted.

49 changes: 0 additions & 49 deletions src/components/ColumnContainer.tsx

This file was deleted.

32 changes: 0 additions & 32 deletions src/components/PhotoAlbumContainer.tsx

This file was deleted.

60 changes: 0 additions & 60 deletions src/components/PhotoDecorator.tsx

This file was deleted.

27 changes: 0 additions & 27 deletions src/components/RowContainer.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from "react";

import PhotoDecorator from "./PhotoDecorator";
import ColumnContainer from "./ColumnContainer";
import computeColumnsLayout from "../layouts/columns";
import { ColumnsLayoutOptions, Instrumentation, Photo, RenderColumnContainer, RenderPhoto } from "../types";
import PhotoRenderer from "../renderers/PhotoRenderer";
import ColumnContainerRenderer from "../renderers/ColumnContainerRenderer";
import computeColumnsLayout from "../../layouts/columns";
import { ColumnsLayoutOptions, Instrumentation, Photo, RenderColumnContainer, RenderPhoto } from "../../types";

type ColumnsLayoutProps<T extends Photo = Photo> = {
photos: T[];
Expand All @@ -15,9 +15,6 @@ type ColumnsLayoutProps<T extends Photo = Photo> = {

const ColumnsLayout = <T extends Photo = Photo>(props: ColumnsLayoutProps<T>): JSX.Element => {
const { photos, layoutOptions, renderPhoto, renderColumnContainer, instrumentation } = props;
const { onClick } = layoutOptions;

const Container = renderColumnContainer || ColumnContainer;

const columnsLayout = computeColumnsLayout({ photos, layoutOptions, instrumentation });

Expand All @@ -28,27 +25,25 @@ const ColumnsLayout = <T extends Photo = Photo>(props: ColumnsLayoutProps<T>): J
return (
<>
{columnsModel.map((column, columnIndex) => (
<Container
<ColumnContainerRenderer
key={`column-${columnIndex}`}
layoutOptions={layoutOptions}
columnIndex={columnIndex}
columnsCount={columnsModel.length}
columnsGaps={columnsGaps}
columnsRatios={columnsRatios}
renderColumnContainer={renderColumnContainer}
>
{column.map(({ photo, layout }) => (
<PhotoDecorator
<PhotoRenderer
key={photo.key || photo.src}
photoProps={{
photo,
layout,
onClick,
layoutOptions,
}}
photo={photo}
layout={layout}
layoutOptions={layoutOptions}
renderPhoto={renderPhoto}
/>
))}
</Container>
</ColumnContainerRenderer>
))}
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as React from "react";

import PhotoDecorator from "./PhotoDecorator";
import ColumnContainer from "./ColumnContainer";
import computeMasonryLayout from "../layouts/masonry";
import { ColumnsLayoutOptions, Instrumentation, Photo, RenderColumnContainer, RenderPhoto } from "../types";
import PhotoRenderer from "../renderers/PhotoRenderer";
import ColumnContainerRenderer from "../renderers/ColumnContainerRenderer";
import computeMasonryLayout from "../../layouts/masonry";
import { ColumnsLayoutOptions, Instrumentation, Photo, RenderColumnContainer, RenderPhoto } from "../../types";

type MasonryLayoutProps<T extends Photo = Photo> = {
photos: T[];
Expand All @@ -15,36 +15,31 @@ type MasonryLayoutProps<T extends Photo = Photo> = {

const MasonryLayout = <T extends Photo = Photo>(props: MasonryLayoutProps<T>): JSX.Element => {
const { photos, layoutOptions, renderPhoto, renderColumnContainer, instrumentation } = props;
const { onClick } = layoutOptions;

const masonryLayout = computeMasonryLayout({ photos, layoutOptions, instrumentation });

if (masonryLayout === undefined) return <></>;

const Container = renderColumnContainer || ColumnContainer;

return (
<>
{masonryLayout.map((column, columnIndex) => (
<Container
<ColumnContainerRenderer
key={`masonry-column-${columnIndex}`}
layoutOptions={layoutOptions}
columnsCount={masonryLayout.length}
columnIndex={columnIndex}
renderColumnContainer={renderColumnContainer}
>
{column.map(({ photo, layout }) => (
<PhotoDecorator
<PhotoRenderer
key={photo.key || photo.src}
photoProps={{
photo,
layout,
onClick,
layoutOptions,
}}
photo={photo}
layout={layout}
layoutOptions={layoutOptions}
renderPhoto={renderPhoto}
/>
))}
</Container>
</ColumnContainerRenderer>
))}
</>
);
Expand Down
Loading

0 comments on commit 657cf3b

Please sign in to comment.