@edifice.io/react 2.6.5-develop-pedago.20260922145203 → 2.6.5-develop-pedago.20260922150541

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.
@@ -1,21 +1,24 @@
1
1
  import { jsxs, jsx } from "react/jsx-runtime";
2
2
  import illuCommunities from "@edifice.io/bootstrap/dist/images/homepage/illu-communities.svg";
3
+ import { useMeasure } from "@uidotdev/usehooks";
3
4
  import { useTranslation } from "react-i18next";
4
5
  import SvgIconArrowRight from "../../../icons/components/IconArrowRight.js";
5
6
  import CommunityItem from "./CommunityItem.js";
6
7
  import HomeCard from "../HomeCard/HomeCard.js";
7
8
  import Flex from "../../../../components/Flex/Flex.js";
8
9
  import Image from "../../../../components/Image/Image.js";
9
- const Communities = ({
10
+ const NARROW_CONTAINER_WIDTH = 800, MAX_ITEMS = 4, MAX_ITEMS_NARROW = 3, Communities = ({
10
11
  communitiesList = [],
11
12
  handleActionClick
12
13
  }) => {
13
14
  const {
14
15
  t
15
- } = useTranslation();
16
+ } = useTranslation(), [containerRef, {
17
+ width
18
+ }] = useMeasure(), maxItems = width !== null && width < NARROW_CONTAINER_WIDTH ? MAX_ITEMS_NARROW : MAX_ITEMS, visibleCommunities = communitiesList.slice(0, maxItems), itemWidth = `${100 / maxItems}%`;
16
19
  return /* @__PURE__ */ jsxs(HomeCard, { variant: "primary", children: [
17
20
  /* @__PURE__ */ jsx(HomeCard.Header, { actionLabel: communitiesList.length > 0 ? t("homepage.communities.actionLabel.seeMore") : t("homepage.communities.actionLabel.create"), actionRightIcon: /* @__PURE__ */ jsx(SvgIconArrowRight, {}), onActionClick: handleActionClick, title: t("homepage.communities.title") }),
18
- /* @__PURE__ */ jsx(HomeCard.Content, { children: /* @__PURE__ */ jsx(Flex, { gap: "16", children: communitiesList.length > 0 ? communitiesList.map((community, index) => /* @__PURE__ */ jsx(CommunityItem, { title: community.title, communityImage: community.communityImage, onActionClick: community.onActionClick, nbNotifications: community.nbNotifications }, index)) : /* @__PURE__ */ jsxs("div", { className: "communities-empty", children: [
21
+ /* @__PURE__ */ jsx(HomeCard.Content, { children: /* @__PURE__ */ jsx(Flex, { ref: containerRef, gap: "16", children: visibleCommunities.length > 0 ? visibleCommunities.map((community, index) => /* @__PURE__ */ jsx(CommunityItem, { title: community.title, communityImage: community.communityImage, onActionClick: community.onActionClick, nbNotifications: community.nbNotifications, width: itemWidth }, index)) : /* @__PURE__ */ jsxs("div", { className: "communities-empty", children: [
19
22
  /* @__PURE__ */ jsx(Image, { src: illuCommunities, alt: "", "aria-hidden": "true", style: {
20
23
  width: 80,
21
24
  height: 80
@@ -1,9 +1,11 @@
1
1
  import { CommunitiesModel } from './useCommunities';
2
2
  export type CommunitiesContainerProps = {
3
+ /** Handle a click on a community. If undefined, the community's home page will be opened. */
3
4
  onCommunityClick?: (community: CommunitiesModel) => void;
4
- onHeaderActionClick: () => void;
5
+ /** Handle a click on the header action button. If undefined, communities (or the community creation flow) will be opened. */
6
+ onHeaderActionClick?: () => void;
5
7
  };
6
- export declare function CommunitiesContainer({ onCommunityClick, onHeaderActionClick, }: CommunitiesContainerProps): import("react/jsx-runtime").JSX.Element | "An error occurred while loading communities.";
8
+ export declare function CommunitiesContainer({ onCommunityClick: handleCommunityClick, onHeaderActionClick: handleHeaderActionClick, }: CommunitiesContainerProps): import("react/jsx-runtime").JSX.Element | "An error occurred while loading communities.";
7
9
  export declare namespace CommunitiesContainer {
8
10
  var displayName: string;
9
11
  }
@@ -1,22 +1,30 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { useMemo } from "react";
2
+ import { useCallback, useMemo } from "react";
3
3
  import Communities from "./Communities.js";
4
4
  import CommunitiesSkeleton from "./CommunitiesSkeleton.js";
5
5
  import { useCommunities } from "./useCommunities.js";
6
6
  function CommunitiesContainer({
7
- onCommunityClick,
8
- onHeaderActionClick
7
+ onCommunityClick: handleCommunityClick = (community) => {
8
+ window.open(`/communities/id/${community.id}/home`, "_self");
9
+ },
10
+ onHeaderActionClick: handleHeaderActionClick
9
11
  }) {
10
12
  const {
11
13
  communities,
12
14
  isLoading,
13
15
  error
14
- } = useCommunities(), mappedCommunities = useMemo(() => communities.map((community) => ({
16
+ } = useCommunities(), handleActionClick = useCallback(() => {
17
+ if (handleHeaderActionClick) {
18
+ handleHeaderActionClick();
19
+ return;
20
+ }
21
+ window.open(communities.length > 0 ? "/communities" : "/communities/create/step-type", "_self");
22
+ }, [handleHeaderActionClick, communities.length]), mappedCommunities = useMemo(() => communities.map((community) => ({
15
23
  title: community.title,
16
24
  communityImage: community.image ?? "",
17
- onActionClick: () => onCommunityClick == null ? void 0 : onCommunityClick(community)
18
- })), [communities, onCommunityClick]);
19
- return isLoading ? /* @__PURE__ */ jsx(CommunitiesSkeleton, {}) : error ? "An error occurred while loading communities." : /* @__PURE__ */ jsx(Communities, { communitiesList: mappedCommunities, handleActionClick: onHeaderActionClick });
25
+ onActionClick: () => handleCommunityClick(community)
26
+ })), [communities, handleCommunityClick]);
27
+ return isLoading ? /* @__PURE__ */ jsx(CommunitiesSkeleton, {}) : error ? "An error occurred while loading communities." : /* @__PURE__ */ jsx(Communities, { communitiesList: mappedCommunities, handleActionClick });
20
28
  }
21
29
  export {
22
30
  CommunitiesContainer
@@ -3,9 +3,10 @@ export interface CommunityItemProps {
3
3
  communityImage: string;
4
4
  onActionClick: () => void;
5
5
  nbNotifications?: number;
6
+ width?: string;
6
7
  }
7
8
  declare const CommunityItem: {
8
- ({ title, communityImage, nbNotifications, onActionClick, }: CommunityItemProps): import("react/jsx-runtime").JSX.Element;
9
+ ({ title, communityImage, nbNotifications, onActionClick, width, }: CommunityItemProps): import("react/jsx-runtime").JSX.Element;
9
10
  displayName: string;
10
11
  };
11
12
  export default CommunityItem;
@@ -6,13 +6,14 @@ const CommunityItem = ({
6
6
  title,
7
7
  communityImage,
8
8
  nbNotifications,
9
- onActionClick
9
+ onActionClick,
10
+ width = "25%"
10
11
  }) => {
11
12
  const hasNotifications = (nbNotifications ?? 0) > 0;
12
13
  return /* @__PURE__ */ jsxs("div", { role: "button", tabIndex: 0, onClick: onActionClick, className: clsx("communities-item", {
13
14
  "communities-item-has-notifications": hasNotifications
14
15
  }), style: {
15
- width: "25%"
16
+ width
16
17
  }, children: [
17
18
  hasNotifications && /* @__PURE__ */ jsx(Badge, { className: "communities-item-badge", variant: {
18
19
  level: "danger",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edifice.io/react",
3
- "version": "2.6.5-develop-pedago.20260922145203",
3
+ "version": "2.6.5-develop-pedago.20260922150541",
4
4
  "description": "Edifice React Library",
5
5
  "keywords": [
6
6
  "react",
@@ -140,9 +140,9 @@
140
140
  "swiper": "10.1.0",
141
141
  "ua-parser-js": "1.0.36",
142
142
  "zustand": "4.5.7",
143
- "@edifice.io/utilities": "2.6.5-develop-pedago.20260922145203",
144
- "@edifice.io/tiptap-extensions": "2.6.5-develop-pedago.20260922145203",
145
- "@edifice.io/bootstrap": "2.6.5-develop-pedago.20260922145203"
143
+ "@edifice.io/tiptap-extensions": "2.6.5-develop-pedago.20260922150541",
144
+ "@edifice.io/utilities": "2.6.5-develop-pedago.20260922150541",
145
+ "@edifice.io/bootstrap": "2.6.5-develop-pedago.20260922150541"
146
146
  },
147
147
  "devDependencies": {
148
148
  "@babel/plugin-transform-react-pure-annotations": "7.27.1",
@@ -173,8 +173,8 @@
173
173
  "vite": "5.4.14",
174
174
  "vite-plugin-dts": "4.5.4",
175
175
  "vite-tsconfig-paths": "5.1.4",
176
- "@edifice.io/client": "2.6.5-develop-pedago.20260922145203",
177
- "@edifice.io/config": "2.6.5-develop-pedago.20260922145203"
176
+ "@edifice.io/client": "2.6.5-develop-pedago.20260922150541",
177
+ "@edifice.io/config": "2.6.5-develop-pedago.20260922150541"
178
178
  },
179
179
  "peerDependencies": {
180
180
  "@react-spring/web": "9.7.5",