@axa-fr/canopee-react 1.7.1-alpha.29 → 1.7.1-alpha.30

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.
@@ -0,0 +1,26 @@
1
+ import "@axa-fr/canopee-css/distributeur/Timeline/Timeline.css";
2
+ import type { ComponentPropsWithoutRef, ReactNode } from "react";
3
+ type TimelineBaseItem = {
4
+ header: ReactNode;
5
+ date?: Date;
6
+ };
7
+ export type TimelineItem = TimelineBaseItem & {
8
+ details: ReactNode;
9
+ };
10
+ export type TimelineItemWithoutDetails = TimelineBaseItem & {
11
+ details?: ReactNode;
12
+ };
13
+ export type TimelineListItem = TimelineItem | TimelineItemWithoutDetails;
14
+ export type TimelineVariants = "default" | "withoutDetails";
15
+ type TimelineBaseProps = Omit<ComponentPropsWithoutRef<"ol">, "children">;
16
+ type TimelineDefaultProps = TimelineBaseProps & {
17
+ items: TimelineItem[];
18
+ variant?: "default";
19
+ };
20
+ type TimelineWithoutDetailsProps = TimelineBaseProps & {
21
+ items: TimelineItemWithoutDetails[];
22
+ variant: "withoutDetails";
23
+ };
24
+ export type TimelineProps = TimelineDefaultProps | TimelineWithoutDetailsProps;
25
+ export declare const Timeline: ({ items, variant, className, ...otherProps }: TimelineProps) => import("react/jsx-runtime").JSX.Element;
26
+ export {};
@@ -0,0 +1,4 @@
1
+ import type { TimelineListItem } from "./Timeline";
2
+ export declare const formatDate: (date?: Date) => string;
3
+ export declare const isDateInFuture: (date?: Date) => boolean;
4
+ export declare const getTimelineItemKey: (item: TimelineListItem) => string;
@@ -0,0 +1,21 @@
1
+ export const formatDate = (date) => {
2
+ if (!date) {
3
+ return "";
4
+ }
5
+ const day = String(date.getUTCDate()).padStart(2, "0");
6
+ const month = String(date.getUTCMonth() + 1).padStart(2, "0");
7
+ const year = date.getUTCFullYear();
8
+ return `${day}/${month}/${year}`;
9
+ };
10
+ export const isDateInFuture = (date) => {
11
+ if (!date) {
12
+ return true;
13
+ }
14
+ return date > new Date();
15
+ };
16
+ export const getTimelineItemKey = (item) => {
17
+ const dateKey = item.date ? item.date.toISOString() : "without-date";
18
+ const headerKey = typeof item.header === "string" ? item.header : "header";
19
+ const detailsKey = typeof item.details === "string" ? item.details : "details";
20
+ return `timeline-item-${dateKey}-${headerKey}-${detailsKey}`;
21
+ };
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import classNames from "classnames";
3
+ import "@axa-fr/canopee-css/distributeur/Timeline/Timeline.css";
4
+ import { getTimelineItemKey } from "./Timeline.helpers";
5
+ import { TimelineDetails } from "./TimelineDetails";
6
+ import { TimelineCircle } from "./TimelineCircle";
7
+ export const Timeline = ({ items, variant = "default", className, ...otherProps }) => {
8
+ const isWithoutDetails = variant === "withoutDetails";
9
+ return (_jsx("ol", { className: classNames("af-timeline", {
10
+ "af-timeline--single-item": items.length === 1,
11
+ "af-timeline--without-details": isWithoutDetails,
12
+ }, className), ...otherProps, children: items.map((item) => (_jsx("li", { className: "af-timeline__item", children: isWithoutDetails ? (_jsxs("div", { className: "af-timeline__without-details", children: [_jsx(TimelineCircle, { date: item.date }), _jsx("div", { className: "af-timeline__without-details-content", children: item.header })] })) : (_jsx(TimelineDetails, { date: item.date, details: item.details, header: item.header })) }, getTimelineItemKey(item)))) }));
13
+ };
@@ -0,0 +1,5 @@
1
+ type TimelineCircleProps = {
2
+ date?: Date;
3
+ };
4
+ export declare const TimelineCircle: ({ date }: TimelineCircleProps) => import("react/jsx-runtime").JSX.Element;
5
+ export {};
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import classNames from "classnames";
3
+ import { isDateInFuture } from "./Timeline.helpers";
4
+ export const TimelineCircle = ({ date }) => {
5
+ return (_jsx("span", { className: classNames("af-timeline__circle", {
6
+ "af-timeline__circle--half": isDateInFuture(date),
7
+ }), role: "presentation" }));
8
+ };
@@ -0,0 +1,2 @@
1
+ import type { TimelineItem } from "./Timeline";
2
+ export declare const TimelineDetails: ({ header, details, date }: TimelineItem) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import keyboardArrowDownIcon from "@material-symbols/svg-400/outlined/keyboard_arrow_down.svg";
3
+ import { useState } from "react";
4
+ import { Svg } from "../Svg";
5
+ import { formatDate } from "./Timeline.helpers";
6
+ import { TimelineCircle } from "./TimelineCircle";
7
+ export const TimelineDetails = ({ header, details, date }) => {
8
+ const [detailOpen, setDetailOpen] = useState(false);
9
+ return (_jsxs("details", { className: "af-timeline__details", onToggle: (event) => setDetailOpen(event.currentTarget.open), children: [_jsxs("summary", { className: "af-timeline__summary", children: [_jsx(TimelineCircle, { date: date }), header, _jsx(Svg, { src: keyboardArrowDownIcon, width: 20, height: 20, className: "af-timeline__show-and-hide-icon", "aria-label": `${detailOpen ? "Masquer" : "Devoiler"} le detail de la date ${formatDate(date)}`, role: "img" })] }), _jsxs("div", { className: "af-timeline__results", children: [_jsx("span", { className: "af-timeline__vertical-line" }), _jsx("div", { className: "af-timeline__content", children: details })] })] }));
10
+ };
@@ -63,3 +63,4 @@ export { Loader } from "./distributeur/Loader/Loader";
63
63
  export { CardData } from "./distributeur/CardData/CardData";
64
64
  export type { CardDataVariant } from "./distributeur/CardData/CardData";
65
65
  export { EditorialMessage, type EditorialMessageProps, type EditorialMessageType, } from "./distributeur/EditorialMessage/EditorialMessage";
66
+ export { Timeline, type TimelineProps, type TimelineVariants, } from "./distributeur/Timeline/Timeline";
@@ -55,3 +55,4 @@ export { HelpButton } from "./distributeur/HelpButton";
55
55
  export { Loader } from "./distributeur/Loader/Loader";
56
56
  export { CardData } from "./distributeur/CardData/CardData";
57
57
  export { EditorialMessage, } from "./distributeur/EditorialMessage/EditorialMessage";
58
+ export { Timeline, } from "./distributeur/Timeline/Timeline";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axa-fr/canopee-react",
3
- "version": "1.7.1-alpha.29",
3
+ "version": "1.7.1-alpha.30",
4
4
  "description": "Package React - Design System Canopée",
5
5
  "exports": {
6
6
  "./distributeur": {
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "homepage": "https://github.com/AxaFrance/design-system#readme",
51
51
  "peerDependencies": {
52
- "@axa-fr/canopee-css": "1.7.1-alpha.29",
52
+ "@axa-fr/canopee-css": "1.7.1-alpha.30",
53
53
  "@material-symbols/svg-400": ">= 0.19.0",
54
54
  "@material-symbols/svg-700": ">= 0.19.0",
55
55
  "react": ">= 18"