@bbki.ng/components 1.5.20 → 1.5.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -240,12 +240,26 @@ interface Photo {
240
240
  avgColor?: string;
241
241
  thumbnailSrc?: string;
242
242
  renderedWidth?: number;
243
- }
244
-
243
+ }
245
244
  interface ImgProps extends Photo {
246
245
  className?: string;
247
246
  size?: "large" | "normal";
248
- }
247
+ }
248
+
249
249
  declare const Img: (props: ImgProps) => JSX.Element;
250
250
 
251
- export { Article, ArticleProps, ArticleSkeleton, ArticleSkeletonProps, BLinkDotProps, BlinkDot, Breadcrumb, BreadcrumbProps, Button, ButtonProps, ButtonType, DropImage, Error, ErrorBoundary, ImageDropProps, ImagePreviewerProps, Img, ImgProps, Link, LinkColor, LinkList, LinkListProps, LinkListSkeleton, LinkListSkeletonProps, LinkProps, List, Logo, LogoProps, Nav, NavProps, NoiseCover, NoiseCoverProps, NotFound, Page, Panel, PanelProps, PathObj, PopConfirm, PopConfirmProps, Skeleton, SkeletonColor, SkeletonProps, Table, TableProps, Tag, TagProps, Tags, ThreeColLayout, TitledList, TitledListProps, listProps, threeColLayoutProps };
251
+ interface RandomRowsLayoutProps {
252
+ classNames?: string;
253
+ cellWrapperClsGenerator?: (colNum: number, randBoolean: boolean) => string;
254
+ cellsCount: number;
255
+ cellRenderer: (index: number, randomBool: boolean, col: number) => React.ReactNode;
256
+ }
257
+
258
+ interface GalleryProps extends Omit<RandomRowsLayoutProps, "classNames" | "cellsCount" | "cellRenderer"> {
259
+ images: ImgProps[];
260
+ children?: ReactNode;
261
+ imageRenderer?: (Img: ReactElement) => ReactNode;
262
+ }
263
+ declare const Gallery: (props: GalleryProps) => JSX.Element;
264
+
265
+ export { Article, ArticleProps, ArticleSkeleton, ArticleSkeletonProps, BLinkDotProps, BlinkDot, Breadcrumb, BreadcrumbProps, Button, ButtonProps, ButtonType, DropImage, Error, ErrorBoundary, Gallery, GalleryProps, ImageDropProps, ImagePreviewerProps, Img, Link, LinkColor, LinkList, LinkListProps, LinkListSkeleton, LinkListSkeletonProps, LinkProps, List, Logo, LogoProps, Nav, NavProps, NoiseCover, NoiseCoverProps, NotFound, Page, Panel, PanelProps, PathObj, PopConfirm, PopConfirmProps, Skeleton, SkeletonColor, SkeletonProps, Table, TableProps, Tag, TagProps, Tags, ThreeColLayout, TitledList, TitledListProps, listProps, threeColLayoutProps };
package/dist/index.js CHANGED
@@ -67,6 +67,7 @@ __export(src_exports, {
67
67
  DropImage: () => DropImage,
68
68
  Error: () => Error2,
69
69
  ErrorBoundary: () => ErrorBoundary,
70
+ Gallery: () => Gallery,
70
71
  Img: () => Img,
71
72
  Link: () => Link,
72
73
  LinkColor: () => LinkColor,
@@ -935,6 +936,98 @@ var Img = (props) => {
935
936
  style: { top: 0, left: 0 }
936
937
  }));
937
938
  };
939
+
940
+ // src/img/Gallery.tsx
941
+ var import_classnames12 = __toESM(require("classnames"));
942
+ var import_react21 = __toESM(require("react"));
943
+
944
+ // src/img/RandomRowsLayout.tsx
945
+ var import_classnames11 = __toESM(require("classnames"));
946
+ var import_react20 = __toESM(require("react"));
947
+ var last = (arr) => {
948
+ if (arr.length < 2) {
949
+ return arr[0];
950
+ }
951
+ return arr[arr.length - 1];
952
+ };
953
+ var defaultCellClsGenerator = (colNum, isCenterSingleCell) => {
954
+ const isSingleCell = colNum === 1;
955
+ const singleCellWidth = isCenterSingleCell ? "full" : "1/2";
956
+ const cellWidth = isSingleCell ? singleCellWidth : "1/2";
957
+ return `md:basis-${cellWidth}`;
958
+ };
959
+ var generateRandomBoolean = (p = 0.5) => Math.random() < p;
960
+ var generateRandomColNum = (total) => {
961
+ const colNumArr = [];
962
+ if (total <= 2) {
963
+ return [total];
964
+ }
965
+ let colSum = 0;
966
+ while (colSum < total) {
967
+ const p = last(colNumArr) === 2 ? 0.9 : 0.5;
968
+ const num = generateRandomBoolean(p) ? 1 : 2;
969
+ colNumArr.push(num);
970
+ colSum += num;
971
+ }
972
+ return colNumArr;
973
+ };
974
+ var RandomRowsLayout = (props) => {
975
+ const {
976
+ cellsCount,
977
+ cellRenderer,
978
+ classNames: classNames7 = "",
979
+ cellWrapperClsGenerator = defaultCellClsGenerator
980
+ } = props;
981
+ const colNums = generateRandomColNum(cellsCount);
982
+ const indexRef = import_react20.default.useRef(0);
983
+ import_react20.default.useEffect(() => {
984
+ indexRef.current = 0;
985
+ });
986
+ return /* @__PURE__ */ import_react20.default.createElement("div", {
987
+ className: classNames7
988
+ }, colNums.map((colNum, row) => {
989
+ const randBool = generateRandomBoolean(colNum < 2 ? 0.6 : 0.5);
990
+ const randBoolArr = [randBool, !randBool];
991
+ return /* @__PURE__ */ import_react20.default.createElement("div", {
992
+ className: "flex items-center flex-wrap",
993
+ key: row
994
+ }, new Array(colNum).fill(null).map((_, col) => {
995
+ indexRef.current += 1;
996
+ const generatedCls = cellWrapperClsGenerator(colNum, generateRandomBoolean());
997
+ const cls4 = (0, import_classnames11.default)("flex items-center justify-center flex-shrink-0 flex-grow-0", "basis-full", generatedCls);
998
+ return /* @__PURE__ */ import_react20.default.createElement("div", {
999
+ className: cls4,
1000
+ key: col
1001
+ }, cellRenderer(indexRef.current - 1, randBoolArr[col], col));
1002
+ }));
1003
+ }));
1004
+ };
1005
+
1006
+ // src/img/Gallery.tsx
1007
+ var Gallery = (props) => {
1008
+ const _a = props, { images, children, imageRenderer = (i) => i } = _a, rest = __objRest(_a, ["images", "children", "imageRenderer"]);
1009
+ const renderImage = (index, isLargeImage, col) => {
1010
+ const image = images[index];
1011
+ if (!image) {
1012
+ return null;
1013
+ }
1014
+ return /* @__PURE__ */ import_react21.default.createElement("div", {
1015
+ className: (0, import_classnames12.default)("mb-256", {
1016
+ "md:mr-64": col === 0,
1017
+ "md:ml-64": col !== 0
1018
+ })
1019
+ }, imageRenderer(/* @__PURE__ */ import_react21.default.createElement(Img, __spreadProps(__spreadValues({}, image), {
1020
+ size: isLargeImage ? "large" : "normal"
1021
+ }))));
1022
+ };
1023
+ return /* @__PURE__ */ import_react21.default.createElement("div", {
1024
+ className: "w-full flex justify-center"
1025
+ }, /* @__PURE__ */ import_react21.default.createElement(RandomRowsLayout, __spreadValues({
1026
+ classNames: "mx-32 mt-128 max-w-screen-xl",
1027
+ cellsCount: images.length,
1028
+ cellRenderer: renderImage
1029
+ }, rest)), children);
1030
+ };
938
1031
  module.exports = __toCommonJS(src_exports);
939
1032
  // Annotate the CommonJS export names for ESM import in node:
940
1033
  0 && (module.exports = {
@@ -947,6 +1040,7 @@ module.exports = __toCommonJS(src_exports);
947
1040
  DropImage,
948
1041
  Error,
949
1042
  ErrorBoundary,
1043
+ Gallery,
950
1044
  Img,
951
1045
  Link,
952
1046
  LinkColor,
package/dist/index.mjs CHANGED
@@ -879,6 +879,98 @@ var Img = (props) => {
879
879
  style: { top: 0, left: 0 }
880
880
  }));
881
881
  };
882
+
883
+ // src/img/Gallery.tsx
884
+ import classnames3 from "classnames";
885
+ import React20 from "react";
886
+
887
+ // src/img/RandomRowsLayout.tsx
888
+ import classnames2 from "classnames";
889
+ import React19 from "react";
890
+ var last = (arr) => {
891
+ if (arr.length < 2) {
892
+ return arr[0];
893
+ }
894
+ return arr[arr.length - 1];
895
+ };
896
+ var defaultCellClsGenerator = (colNum, isCenterSingleCell) => {
897
+ const isSingleCell = colNum === 1;
898
+ const singleCellWidth = isCenterSingleCell ? "full" : "1/2";
899
+ const cellWidth = isSingleCell ? singleCellWidth : "1/2";
900
+ return `md:basis-${cellWidth}`;
901
+ };
902
+ var generateRandomBoolean = (p = 0.5) => Math.random() < p;
903
+ var generateRandomColNum = (total) => {
904
+ const colNumArr = [];
905
+ if (total <= 2) {
906
+ return [total];
907
+ }
908
+ let colSum = 0;
909
+ while (colSum < total) {
910
+ const p = last(colNumArr) === 2 ? 0.9 : 0.5;
911
+ const num = generateRandomBoolean(p) ? 1 : 2;
912
+ colNumArr.push(num);
913
+ colSum += num;
914
+ }
915
+ return colNumArr;
916
+ };
917
+ var RandomRowsLayout = (props) => {
918
+ const {
919
+ cellsCount,
920
+ cellRenderer,
921
+ classNames: classNames7 = "",
922
+ cellWrapperClsGenerator = defaultCellClsGenerator
923
+ } = props;
924
+ const colNums = generateRandomColNum(cellsCount);
925
+ const indexRef = React19.useRef(0);
926
+ React19.useEffect(() => {
927
+ indexRef.current = 0;
928
+ });
929
+ return /* @__PURE__ */ React19.createElement("div", {
930
+ className: classNames7
931
+ }, colNums.map((colNum, row) => {
932
+ const randBool = generateRandomBoolean(colNum < 2 ? 0.6 : 0.5);
933
+ const randBoolArr = [randBool, !randBool];
934
+ return /* @__PURE__ */ React19.createElement("div", {
935
+ className: "flex items-center flex-wrap",
936
+ key: row
937
+ }, new Array(colNum).fill(null).map((_, col) => {
938
+ indexRef.current += 1;
939
+ const generatedCls = cellWrapperClsGenerator(colNum, generateRandomBoolean());
940
+ const cls4 = classnames2("flex items-center justify-center flex-shrink-0 flex-grow-0", "basis-full", generatedCls);
941
+ return /* @__PURE__ */ React19.createElement("div", {
942
+ className: cls4,
943
+ key: col
944
+ }, cellRenderer(indexRef.current - 1, randBoolArr[col], col));
945
+ }));
946
+ }));
947
+ };
948
+
949
+ // src/img/Gallery.tsx
950
+ var Gallery = (props) => {
951
+ const _a = props, { images, children, imageRenderer = (i) => i } = _a, rest = __objRest(_a, ["images", "children", "imageRenderer"]);
952
+ const renderImage = (index, isLargeImage, col) => {
953
+ const image = images[index];
954
+ if (!image) {
955
+ return null;
956
+ }
957
+ return /* @__PURE__ */ React20.createElement("div", {
958
+ className: classnames3("mb-256", {
959
+ "md:mr-64": col === 0,
960
+ "md:ml-64": col !== 0
961
+ })
962
+ }, imageRenderer(/* @__PURE__ */ React20.createElement(Img, __spreadProps(__spreadValues({}, image), {
963
+ size: isLargeImage ? "large" : "normal"
964
+ }))));
965
+ };
966
+ return /* @__PURE__ */ React20.createElement("div", {
967
+ className: "w-full flex justify-center"
968
+ }, /* @__PURE__ */ React20.createElement(RandomRowsLayout, __spreadValues({
969
+ classNames: "mx-32 mt-128 max-w-screen-xl",
970
+ cellsCount: images.length,
971
+ cellRenderer: renderImage
972
+ }, rest)), children);
973
+ };
882
974
  export {
883
975
  Article,
884
976
  ArticleSkeleton,
@@ -889,6 +981,7 @@ export {
889
981
  DropImage,
890
982
  Error2 as Error,
891
983
  ErrorBoundary,
984
+ Gallery,
892
985
  Img,
893
986
  Link,
894
987
  LinkColor,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbki.ng/components",
3
- "version": "1.5.20",
3
+ "version": "1.5.21",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",