@bbki.ng/components 1.5.20 → 1.5.23

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,27 @@ 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
+ declare type ImageRenderer = (Img: ReactElement, index: number, col: number, randBool: boolean) => ReactNode;
259
+ interface GalleryProps extends Omit<RandomRowsLayoutProps, "classNames" | "cellsCount" | "cellRenderer"> {
260
+ images: ImgProps[];
261
+ children?: ReactNode;
262
+ imageRenderer?: ImageRenderer;
263
+ }
264
+ declare const Gallery: (props: GalleryProps) => JSX.Element;
265
+
266
+ export { Article, ArticleProps, ArticleSkeleton, ArticleSkeletonProps, BLinkDotProps, BlinkDot, Breadcrumb, BreadcrumbProps, Button, ButtonProps, ButtonType, DropImage, Error, ErrorBoundary, Gallery, GalleryProps, ImageDropProps, ImagePreviewerProps, ImageRenderer, 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,
@@ -97,10 +98,8 @@ var Article = (props) => {
97
98
  return /* @__PURE__ */ import_react.default.createElement("div", {
98
99
  className: (0, import_classnames.default)("article", className)
99
100
  }, /* @__PURE__ */ import_react.default.createElement("div", {
100
- className: "text-[2.25rem] leading-none"
101
- }, title), /* @__PURE__ */ import_react.default.createElement("hr", {
102
- className: "my-64 border-gray-200"
103
- }), description && /* @__PURE__ */ import_react.default.createElement("div", {
101
+ className: "text-[2.25rem] mb-128 leading-none"
102
+ }, title), description && /* @__PURE__ */ import_react.default.createElement("div", {
104
103
  className: "mb-128"
105
104
  }, description), /* @__PURE__ */ import_react.default.createElement("div", {
106
105
  className: "text-gray-700"
@@ -935,6 +934,109 @@ var Img = (props) => {
935
934
  style: { top: 0, left: 0 }
936
935
  }));
937
936
  };
937
+
938
+ // src/img/Gallery.tsx
939
+ var import_classnames12 = __toESM(require("classnames"));
940
+ var import_react21 = __toESM(require("react"));
941
+
942
+ // src/img/RandomRowsLayout.tsx
943
+ var import_classnames11 = __toESM(require("classnames"));
944
+ var import_react20 = __toESM(require("react"));
945
+ var last = (arr) => {
946
+ if (arr.length < 2) {
947
+ return arr[0];
948
+ }
949
+ return arr[arr.length - 1];
950
+ };
951
+ var defaultCellClsGenerator = (colNum, isCenterSingleCell) => {
952
+ const isSingleCell = colNum === 1;
953
+ const singleCellWidth = isCenterSingleCell ? "full" : "1/2";
954
+ const cellWidth = isSingleCell ? singleCellWidth : "1/2";
955
+ return `md:basis-${cellWidth}`;
956
+ };
957
+ var generateRandomBoolean = (p = 0.5) => Math.random() < p;
958
+ var generateRandomColNum = (total) => {
959
+ const colNumArr = [];
960
+ if (total <= 2) {
961
+ return [total];
962
+ }
963
+ let colSum = 0;
964
+ while (colSum < total) {
965
+ const p = last(colNumArr) === 2 ? 0.9 : 0.5;
966
+ const num = generateRandomBoolean(p) ? 1 : 2;
967
+ colNumArr.push(num);
968
+ colSum += num;
969
+ }
970
+ return colNumArr;
971
+ };
972
+ var RandomRowsLayout = (props) => {
973
+ const {
974
+ cellsCount,
975
+ cellRenderer,
976
+ classNames: classNames7 = "",
977
+ cellWrapperClsGenerator = defaultCellClsGenerator
978
+ } = props;
979
+ const colNums = generateRandomColNum(cellsCount);
980
+ const indexRef = import_react20.default.useRef(0);
981
+ import_react20.default.useEffect(() => {
982
+ indexRef.current = 0;
983
+ });
984
+ return /* @__PURE__ */ import_react20.default.createElement("div", {
985
+ className: classNames7
986
+ }, colNums.map((colNum, row) => {
987
+ const randBool = generateRandomBoolean(colNum < 2 ? 0.6 : 0.5);
988
+ const randBoolArr = [randBool, !randBool];
989
+ return /* @__PURE__ */ import_react20.default.createElement("div", {
990
+ className: "flex items-center flex-wrap",
991
+ key: row
992
+ }, new Array(colNum).fill(null).map((_, col) => {
993
+ indexRef.current += 1;
994
+ const generatedCls = cellWrapperClsGenerator(colNum, generateRandomBoolean());
995
+ const cls4 = (0, import_classnames11.default)("flex items-center justify-center flex-shrink-0 flex-grow-0", "basis-full", generatedCls);
996
+ return /* @__PURE__ */ import_react20.default.createElement("div", {
997
+ className: cls4,
998
+ key: col
999
+ }, cellRenderer(indexRef.current - 1, randBoolArr[col], col));
1000
+ }));
1001
+ }));
1002
+ };
1003
+
1004
+ // src/img/Gallery.tsx
1005
+ var defaultImageRenderer = (img, index, col) => {
1006
+ return /* @__PURE__ */ import_react21.default.createElement("div", {
1007
+ className: (0, import_classnames12.default)("mb-256", {
1008
+ "md:mr-64": col === 0,
1009
+ "md:ml-64": col !== 0
1010
+ })
1011
+ }, img);
1012
+ };
1013
+ var Gallery = (props) => {
1014
+ const _a = props, {
1015
+ images,
1016
+ children,
1017
+ imageRenderer = defaultImageRenderer
1018
+ } = _a, rest = __objRest(_a, [
1019
+ "images",
1020
+ "children",
1021
+ "imageRenderer"
1022
+ ]);
1023
+ const renderImage = (index, isLargeImage, col) => {
1024
+ const image = images[index];
1025
+ if (!image) {
1026
+ return null;
1027
+ }
1028
+ return imageRenderer(/* @__PURE__ */ import_react21.default.createElement(Img, __spreadProps(__spreadValues({}, image), {
1029
+ size: isLargeImage ? "large" : "normal"
1030
+ })), index, col, isLargeImage);
1031
+ };
1032
+ return /* @__PURE__ */ import_react21.default.createElement("div", {
1033
+ className: "w-full flex justify-center"
1034
+ }, /* @__PURE__ */ import_react21.default.createElement(RandomRowsLayout, __spreadValues({
1035
+ classNames: "mx-32 mt-128 max-w-screen-xl",
1036
+ cellsCount: images.length,
1037
+ cellRenderer: renderImage
1038
+ }, rest)), children);
1039
+ };
938
1040
  module.exports = __toCommonJS(src_exports);
939
1041
  // Annotate the CommonJS export names for ESM import in node:
940
1042
  0 && (module.exports = {
@@ -947,6 +1049,7 @@ module.exports = __toCommonJS(src_exports);
947
1049
  DropImage,
948
1050
  Error,
949
1051
  ErrorBoundary,
1052
+ Gallery,
950
1053
  Img,
951
1054
  Link,
952
1055
  LinkColor,
package/dist/index.mjs CHANGED
@@ -38,10 +38,8 @@ var Article = (props) => {
38
38
  return /* @__PURE__ */ React.createElement("div", {
39
39
  className: classNames("article", className)
40
40
  }, /* @__PURE__ */ React.createElement("div", {
41
- className: "text-[2.25rem] leading-none"
42
- }, title), /* @__PURE__ */ React.createElement("hr", {
43
- className: "my-64 border-gray-200"
44
- }), description && /* @__PURE__ */ React.createElement("div", {
41
+ className: "text-[2.25rem] mb-128 leading-none"
42
+ }, title), description && /* @__PURE__ */ React.createElement("div", {
45
43
  className: "mb-128"
46
44
  }, description), /* @__PURE__ */ React.createElement("div", {
47
45
  className: "text-gray-700"
@@ -879,6 +877,109 @@ var Img = (props) => {
879
877
  style: { top: 0, left: 0 }
880
878
  }));
881
879
  };
880
+
881
+ // src/img/Gallery.tsx
882
+ import classnames3 from "classnames";
883
+ import React20 from "react";
884
+
885
+ // src/img/RandomRowsLayout.tsx
886
+ import classnames2 from "classnames";
887
+ import React19 from "react";
888
+ var last = (arr) => {
889
+ if (arr.length < 2) {
890
+ return arr[0];
891
+ }
892
+ return arr[arr.length - 1];
893
+ };
894
+ var defaultCellClsGenerator = (colNum, isCenterSingleCell) => {
895
+ const isSingleCell = colNum === 1;
896
+ const singleCellWidth = isCenterSingleCell ? "full" : "1/2";
897
+ const cellWidth = isSingleCell ? singleCellWidth : "1/2";
898
+ return `md:basis-${cellWidth}`;
899
+ };
900
+ var generateRandomBoolean = (p = 0.5) => Math.random() < p;
901
+ var generateRandomColNum = (total) => {
902
+ const colNumArr = [];
903
+ if (total <= 2) {
904
+ return [total];
905
+ }
906
+ let colSum = 0;
907
+ while (colSum < total) {
908
+ const p = last(colNumArr) === 2 ? 0.9 : 0.5;
909
+ const num = generateRandomBoolean(p) ? 1 : 2;
910
+ colNumArr.push(num);
911
+ colSum += num;
912
+ }
913
+ return colNumArr;
914
+ };
915
+ var RandomRowsLayout = (props) => {
916
+ const {
917
+ cellsCount,
918
+ cellRenderer,
919
+ classNames: classNames7 = "",
920
+ cellWrapperClsGenerator = defaultCellClsGenerator
921
+ } = props;
922
+ const colNums = generateRandomColNum(cellsCount);
923
+ const indexRef = React19.useRef(0);
924
+ React19.useEffect(() => {
925
+ indexRef.current = 0;
926
+ });
927
+ return /* @__PURE__ */ React19.createElement("div", {
928
+ className: classNames7
929
+ }, colNums.map((colNum, row) => {
930
+ const randBool = generateRandomBoolean(colNum < 2 ? 0.6 : 0.5);
931
+ const randBoolArr = [randBool, !randBool];
932
+ return /* @__PURE__ */ React19.createElement("div", {
933
+ className: "flex items-center flex-wrap",
934
+ key: row
935
+ }, new Array(colNum).fill(null).map((_, col) => {
936
+ indexRef.current += 1;
937
+ const generatedCls = cellWrapperClsGenerator(colNum, generateRandomBoolean());
938
+ const cls4 = classnames2("flex items-center justify-center flex-shrink-0 flex-grow-0", "basis-full", generatedCls);
939
+ return /* @__PURE__ */ React19.createElement("div", {
940
+ className: cls4,
941
+ key: col
942
+ }, cellRenderer(indexRef.current - 1, randBoolArr[col], col));
943
+ }));
944
+ }));
945
+ };
946
+
947
+ // src/img/Gallery.tsx
948
+ var defaultImageRenderer = (img, index, col) => {
949
+ return /* @__PURE__ */ React20.createElement("div", {
950
+ className: classnames3("mb-256", {
951
+ "md:mr-64": col === 0,
952
+ "md:ml-64": col !== 0
953
+ })
954
+ }, img);
955
+ };
956
+ var Gallery = (props) => {
957
+ const _a = props, {
958
+ images,
959
+ children,
960
+ imageRenderer = defaultImageRenderer
961
+ } = _a, rest = __objRest(_a, [
962
+ "images",
963
+ "children",
964
+ "imageRenderer"
965
+ ]);
966
+ const renderImage = (index, isLargeImage, col) => {
967
+ const image = images[index];
968
+ if (!image) {
969
+ return null;
970
+ }
971
+ return imageRenderer(/* @__PURE__ */ React20.createElement(Img, __spreadProps(__spreadValues({}, image), {
972
+ size: isLargeImage ? "large" : "normal"
973
+ })), index, col, isLargeImage);
974
+ };
975
+ return /* @__PURE__ */ React20.createElement("div", {
976
+ className: "w-full flex justify-center"
977
+ }, /* @__PURE__ */ React20.createElement(RandomRowsLayout, __spreadValues({
978
+ classNames: "mx-32 mt-128 max-w-screen-xl",
979
+ cellsCount: images.length,
980
+ cellRenderer: renderImage
981
+ }, rest)), children);
982
+ };
882
983
  export {
883
984
  Article,
884
985
  ArticleSkeleton,
@@ -889,6 +990,7 @@ export {
889
990
  DropImage,
890
991
  Error2 as Error,
891
992
  ErrorBoundary,
993
+ Gallery,
892
994
  Img,
893
995
  Link,
894
996
  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.23",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",