@vodafone_de/brix-components 3.0.1 → 3.0.2
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/BackgroundColor-JObp_2xA.js +14 -0
- package/dist/BorderColor-BummoQ1-.js +24 -0
- package/dist/BorderRadius-ClUShVLu.js +10 -0
- package/dist/BorderWidth-DfOlyKK7.js +16 -0
- package/dist/CornerStyle-JEbGNArR.js +6 -0
- package/dist/FontWeight-CR22KTex.js +8 -0
- package/dist/HeadingSize-CfCRn3Lh.js +12 -0
- package/dist/IconColor-CtC9WUgr.js +10 -0
- package/dist/ObjectColor-BZDBuV8H.js +22 -0
- package/dist/Opacity-smkGiwsf.js +6 -0
- package/dist/SizeTypes-Ck_RdzIf.js +8 -0
- package/dist/Spacing-D0HQH9YJ.js +16 -0
- package/dist/TextBodySize-BcZR9mh2.js +6 -0
- package/dist/TextColor-BXiR5Uq9.js +16 -0
- package/dist/colorUtils-uLZF5UIN.js +94 -0
- package/dist/components/Accordion/index.js +195 -0
- package/dist/components/AccordionGroup/index.js +59 -0
- package/dist/components/Badge/index.js +11 -0
- package/dist/components/Body/index.js +72 -6
- package/dist/components/BottomBar/index.js +79 -0
- package/dist/components/Button/index.js +24 -0
- package/dist/components/ButtonAsLink/index.js +7 -0
- package/dist/components/ButtonGroup/index.js +34 -0
- package/dist/components/Card/index.js +18 -0
- package/dist/components/Carousel/index.js +497 -0
- package/dist/components/Checkbox/index.js +218 -0
- package/dist/components/CheckboxGroup/index.js +58 -0
- package/dist/components/Collapsible/index.js +85 -0
- package/dist/components/ColorSwatch/index.js +87 -0
- package/dist/components/ColorSwatchGroup/index.js +43 -0
- package/dist/components/Container/index.js +76 -0
- package/dist/components/DateInput/index.js +86 -0
- package/dist/components/DemoBox/index.js +21 -0
- package/dist/components/Dialog/index.js +172 -0
- package/dist/components/DiscoveryCard/index.js +130 -0
- package/dist/components/DiscoveryCardGroup/index.js +53 -0
- package/dist/components/Divider/index.js +30 -0
- package/dist/components/Fieldset/index.js +41 -0
- package/dist/components/FilterGroup/index.js +148 -0
- package/dist/components/Flex/index.js +17 -0
- package/dist/components/FlexItem/index.js +41 -0
- package/dist/components/FootnoteContent/index.js +39 -0
- package/dist/components/FootnoteLink/index.js +46 -0
- package/dist/components/Form/index.js +20 -0
- package/dist/components/FormElement/index.js +31 -0
- package/dist/components/FormHelperLabel/index.js +21 -0
- package/dist/components/FormHelperMessage/index.js +47 -0
- package/dist/components/FormHelperStatusIcon/index.js +50 -0
- package/dist/components/GoogleMap/index.js +196 -0
- package/dist/components/Grid/index.js +39 -0
- package/dist/components/GridItem/index.js +12 -0
- package/dist/components/Heading/index.js +94 -0
- package/dist/components/HifiIcon/index.js +31 -0
- package/dist/components/Icon/index.js +38 -0
- package/dist/components/IconButton/index.js +85 -0
- package/dist/components/IconSnippet/index.js +112 -0
- package/dist/components/IconSnippet/styled.d.ts +1 -1
- package/dist/components/IconSnippetList/index.js +25 -0
- package/dist/components/Image/index.js +84 -0
- package/dist/components/ImageHeader/index.js +262 -0
- package/dist/components/ImageHeader/styled.d.ts +4 -4
- package/dist/components/InlineLink/index.js +43 -0
- package/dist/components/Input/index.js +55 -0
- package/dist/components/Label/index.js +22 -0
- package/dist/components/Legend/index.js +60 -0
- package/dist/components/Link/index.js +19 -0
- package/dist/components/LinkAsButton/index.js +7 -0
- package/dist/components/LinkList/index.js +64 -0
- package/dist/components/LinkListItem/index.js +316 -0
- package/dist/components/LoadingSpinner/index.js +70 -0
- package/dist/components/Notification/index.js +181 -0
- package/dist/components/Overlay/index.js +33 -0
- package/dist/components/PickerGroup/index.js +282 -0
- package/dist/components/Price/index.js +18 -0
- package/dist/components/ProductCard/index.js +81 -0
- package/dist/components/RadioGroup/index.js +197 -0
- package/dist/components/ResponsiveImage/index.js +89 -0
- package/dist/components/RichText/index.js +7 -0
- package/dist/components/ScreenreaderOnly/index.js +6 -0
- package/dist/components/SearchInput/index.js +140 -0
- package/dist/components/SelectInput/index.js +160 -0
- package/dist/components/Stepper/index.js +205 -0
- package/dist/components/SuggestInput/index.js +387 -0
- package/dist/components/Switch/index.js +169 -0
- package/dist/components/TabularPrice/index.js +8 -0
- package/dist/components/TextList/index.js +10 -0
- package/dist/components/Textarea/index.js +156 -0
- package/dist/components/Tray/index.js +218 -0
- package/dist/easing-Dm-pO8SY.js +6 -0
- package/dist/filterProps-Cewck8OH.js +13 -0
- package/dist/foundations/GlobalStyle/index.js +3 -292
- package/dist/foundations/PatternProps/index.js +1 -0
- package/dist/foundations/media-query/forcedColors/index.js +12 -0
- package/dist/foundations/media-query/reducedMotion/index.js +21 -0
- package/dist/foundations/media-query/viewport/index.js +6 -0
- package/dist/foundations/token/getBackgroundColor/index.js +5 -0
- package/dist/foundations/token/getBodySize/index.js +13 -2
- package/dist/foundations/token/getBorderColor/index.js +5 -0
- package/dist/foundations/token/getBorderRadius/index.js +15 -0
- package/dist/foundations/token/getBorderWidth/index.js +19 -0
- package/dist/foundations/token/getBottomSpacing/index.js +14 -0
- package/dist/foundations/token/getFontWeight/index.js +13 -0
- package/dist/foundations/token/getHeadingSize/index.js +27 -0
- package/dist/foundations/token/getHoverColor/index.js +7 -0
- package/dist/foundations/token/getIconColor/index.js +5 -0
- package/dist/foundations/token/getObjectColor/index.js +5 -0
- package/dist/foundations/token/getOpacity/index.js +11 -0
- package/dist/foundations/token/getPressColor/index.js +7 -0
- package/dist/foundations/token/getSpacing/index.js +5 -0
- package/dist/foundations/token/getTextColor/index.js +5 -0
- package/dist/foundations/token/getTextDecoration/index.js +13 -0
- package/dist/getCssVar-BP6T9pFM.js +6 -0
- package/dist/hooks/useFocusWithin/index.js +36 -0
- package/dist/hooks/useForcedColors/index.js +9 -0
- package/dist/hooks/useMediaQuery/index.js +19 -0
- package/dist/hooks/useReducedMotion/index.js +9 -0
- package/dist/hooks/useThirdPartyConsent/index.js +54 -0
- package/dist/hooks/useViewport/index.js +24 -0
- package/dist/index-BXLT6ke-.js +79 -0
- package/dist/index-C4XnzWFL.js +61 -0
- package/dist/index-CeJsIf3Z.js +208 -0
- package/dist/index-Ck2bCrhT.js +32 -0
- package/dist/index-CzTqNQTT.js +79 -0
- package/dist/index-D6hvbziL.js +167 -0
- package/dist/index-DQhtQZ85.js +24 -0
- package/dist/props-Czq9XX2J.js +6 -0
- package/dist/{index-BaPlSfS3.js → renderInlineRichTextFromOpenText-CA52y1-B.js} +3 -105
- package/dist/shadow-u158mzuN.js +4 -0
- package/dist/styled-BpvuD699.js +45 -0
- package/dist/styled-CDWclYAa.js +124 -0
- package/dist/styled-CXSdomF5.js +34 -0
- package/dist/styled-CpoX5USb.js +71 -0
- package/dist/styled-DZo6MwrF.js +245 -0
- package/dist/styled-FNJyDkPV.js +165 -0
- package/dist/styled-Wlt68LfQ.js +133 -0
- package/dist/styled-ZpQohvyx.js +29 -0
- package/dist/tags-DI6H1biK.js +29 -0
- package/package.json +2 -1
- package/dist/index-BoPDwZgt.js +0 -18
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useRef, useState, useEffect } from "react";
|
|
4
|
+
import { s as spacingMd, b as spacingNone } from "../../Spacing-D0HQH9YJ.js";
|
|
5
|
+
import Container from "../Container/index.js";
|
|
6
|
+
import styled from "styled-components";
|
|
7
|
+
import { C as CardStyled } from "../../styled-BpvuD699.js";
|
|
8
|
+
import { getBorderRadius } from "../../foundations/token/getBorderRadius/index.js";
|
|
9
|
+
import { getSpacing } from "../../foundations/token/getSpacing/index.js";
|
|
10
|
+
import { a as borderRadiusNone } from "../../BorderRadius-ClUShVLu.js";
|
|
11
|
+
import { f as filterProps } from "../../filterProps-Cewck8OH.js";
|
|
12
|
+
const bottomBarExtraPadding = 100;
|
|
13
|
+
const BottomBarStyled = styled(CardStyled).withConfig({
|
|
14
|
+
shouldForwardProp: filterProps(),
|
|
15
|
+
displayName: "BottomBarStyled",
|
|
16
|
+
componentId: "sc-oqw46b-0"
|
|
17
|
+
})({
|
|
18
|
+
paddingLeft: getSpacing(spacingNone),
|
|
19
|
+
paddingRight: getSpacing(spacingNone),
|
|
20
|
+
paddingBottom: `calc(${getSpacing(spacingMd)} + ${bottomBarExtraPadding}px)`,
|
|
21
|
+
position: "fixed",
|
|
22
|
+
bottom: 0,
|
|
23
|
+
width: "100%",
|
|
24
|
+
height: "auto",
|
|
25
|
+
borderBottomLeftRadius: getBorderRadius(borderRadiusNone),
|
|
26
|
+
borderBottomRightRadius: getBorderRadius(borderRadiusNone),
|
|
27
|
+
transition: "transform 400ms cubic-bezier(0.7, -0.4, 0.4, 1.4)"
|
|
28
|
+
}, ({
|
|
29
|
+
visible
|
|
30
|
+
}) => {
|
|
31
|
+
return {
|
|
32
|
+
transform: visible ? `translateY(${bottomBarExtraPadding}px)` : "translateY(100%)"
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
const BottomBar = ({
|
|
36
|
+
theme = "Light",
|
|
37
|
+
...props
|
|
38
|
+
}) => {
|
|
39
|
+
const bottomBarRef = useRef(null);
|
|
40
|
+
const [bottomBarHeight, setBottomBarHeight] = useState(0);
|
|
41
|
+
const [visible, setVisible] = useState(props.visible === true);
|
|
42
|
+
const [screenSize, setScreenSize] = useState(null);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
setVisible(true === props.visible);
|
|
45
|
+
}, [props.visible]);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (bottomBarRef.current) {
|
|
48
|
+
setBottomBarHeight(bottomBarRef.current.clientHeight - bottomBarExtraPadding);
|
|
49
|
+
}
|
|
50
|
+
const updateScreenSize = () => {
|
|
51
|
+
setScreenSize({
|
|
52
|
+
width: window.innerWidth,
|
|
53
|
+
height: window.innerHeight
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
updateScreenSize();
|
|
57
|
+
window.addEventListener("resize", updateScreenSize);
|
|
58
|
+
return () => {
|
|
59
|
+
window.removeEventListener("resize", updateScreenSize);
|
|
60
|
+
};
|
|
61
|
+
}, []);
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (screenSize) {
|
|
64
|
+
if (bottomBarHeight * 5 > screenSize.height) {
|
|
65
|
+
visible && setVisible(false);
|
|
66
|
+
} else if (props.visible) {
|
|
67
|
+
setVisible(props.visible);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}, [screenSize]);
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
document.documentElement.classList.toggle("HasObscuringBottomBar", visible);
|
|
73
|
+
document.documentElement.style.setProperty("--bottomBarHeight", `${bottomBarHeight}px`);
|
|
74
|
+
}, [bottomBarHeight, props.children]);
|
|
75
|
+
return /* @__PURE__ */ jsx(BottomBarStyled, { "aria-hidden": true, className: `${theme} ${props.className}`, ref: bottomBarRef, ...props, visible, children: /* @__PURE__ */ jsx(Container, { padding: spacingNone, children: props.children }) });
|
|
76
|
+
};
|
|
77
|
+
export {
|
|
78
|
+
BottomBar as default
|
|
79
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { r as renderInlineRichTextFromOpenText } from "../../renderInlineRichTextFromOpenText-CA52y1-B.js";
|
|
4
|
+
import { B as ButtonAsLink, g as getButtonIcon } from "../../index-C4XnzWFL.js";
|
|
5
|
+
import { B as ButtonStyled } from "../../styled-FNJyDkPV.js";
|
|
6
|
+
const buttonFullWidth = "full";
|
|
7
|
+
const buttonAutoWidth = "auto";
|
|
8
|
+
const isButtonAsLinkProp = (props) => {
|
|
9
|
+
return props.href !== void 0;
|
|
10
|
+
};
|
|
11
|
+
const Button = (props) => {
|
|
12
|
+
if (isButtonAsLinkProp(props)) {
|
|
13
|
+
return /* @__PURE__ */ jsx(ButtonAsLink, { ...props });
|
|
14
|
+
}
|
|
15
|
+
return /* @__PURE__ */ jsxs(ButtonStyled, { ...props, children: [
|
|
16
|
+
renderInlineRichTextFromOpenText(props.children),
|
|
17
|
+
getButtonIcon(props == null ? void 0 : props.icon)
|
|
18
|
+
] });
|
|
19
|
+
};
|
|
20
|
+
export {
|
|
21
|
+
buttonAutoWidth,
|
|
22
|
+
buttonFullWidth,
|
|
23
|
+
Button as default
|
|
24
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
3
|
+
import Button from "../Button/index.js";
|
|
4
|
+
import Flex from "../Flex/index.js";
|
|
5
|
+
import { f as flexOrientationHorizontal, a as flexJustifyStart } from "../../styled-CpoX5USb.js";
|
|
6
|
+
import FlexItem from "../FlexItem/index.js";
|
|
7
|
+
import { c as spacingSm, s as spacingMd } from "../../Spacing-D0HQH9YJ.js";
|
|
8
|
+
import { useViewport } from "../../hooks/useViewport/index.js";
|
|
9
|
+
const renderButtons = (buttons, isMobile, isReversed = false) => {
|
|
10
|
+
if (!isMobile && isReversed) {
|
|
11
|
+
buttons = buttons.slice().reverse();
|
|
12
|
+
}
|
|
13
|
+
return buttons.map((button) => {
|
|
14
|
+
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(FlexItem, { as: "li", grow: isMobile ? "auto" : void 0, bottomSpacing: "None", children: /* @__PURE__ */ jsx(Button, { ...button, bottomSpacing: "None", width: isMobile ? "full" : button.width, children: button.children }, button.uid) }, button.uid) });
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
const ButtonGroup = ({
|
|
18
|
+
isReversed,
|
|
19
|
+
buttons,
|
|
20
|
+
orientation = flexOrientationHorizontal,
|
|
21
|
+
justifyHorizontal = flexJustifyStart,
|
|
22
|
+
bottomSpacing = spacingMd,
|
|
23
|
+
...props
|
|
24
|
+
}) => {
|
|
25
|
+
const viewport = useViewport();
|
|
26
|
+
let justify = "start";
|
|
27
|
+
if ("sm" !== viewport) {
|
|
28
|
+
justify = "horizontal" === orientation ? justifyHorizontal : "start";
|
|
29
|
+
}
|
|
30
|
+
return /* @__PURE__ */ jsx(Flex, { className: props.className, bottomSpacing, gapSpacing: spacingSm, justify, orientation: "sm" === viewport ? "vertical" : orientation, as: "ul", children: renderButtons(buttons, "sm" === viewport, isReversed) });
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
ButtonGroup as default
|
|
34
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { d as divTagName } from "../../tags-DI6H1biK.js";
|
|
4
|
+
import { C as CardStyled } from "../../styled-BpvuD699.js";
|
|
5
|
+
import { a } from "../../styled-BpvuD699.js";
|
|
6
|
+
const Card = ({
|
|
7
|
+
children,
|
|
8
|
+
className,
|
|
9
|
+
theme,
|
|
10
|
+
tag = divTagName,
|
|
11
|
+
isMobileDark = false,
|
|
12
|
+
appearance,
|
|
13
|
+
...props
|
|
14
|
+
}) => /* @__PURE__ */ jsx(CardStyled, { ...props, className: (className ? className : "") + (isMobileDark ? " DarkMobile" : "") + ("Dark" === theme || "secondary" === appearance ? " Dark" : ""), appearance, as: tag, children });
|
|
15
|
+
export {
|
|
16
|
+
a as CardAppearanceColor,
|
|
17
|
+
Card as default
|
|
18
|
+
};
|
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
3
|
+
import "@af-utils/scrollend-polyfill";
|
|
4
|
+
import { createContext, useRef, useState, useEffect, useContext, createElement } from "react";
|
|
5
|
+
import { useFocusWithin } from "../../hooks/useFocusWithin/index.js";
|
|
6
|
+
import { l as liTagName, u as ulTagName } from "../../tags-DI6H1biK.js";
|
|
7
|
+
import { s as spacingMd } from "../../Spacing-D0HQH9YJ.js";
|
|
8
|
+
import styled from "styled-components";
|
|
9
|
+
import { C as CardStyled } from "../../styled-BpvuD699.js";
|
|
10
|
+
import { G as GridStyled } from "../../styled-ZpQohvyx.js";
|
|
11
|
+
import { G as GridItemStyled } from "../../styled-Wlt68LfQ.js";
|
|
12
|
+
import { v as viewport } from "../../index-Ck2bCrhT.js";
|
|
13
|
+
import { getBorderRadius } from "../../foundations/token/getBorderRadius/index.js";
|
|
14
|
+
import { getBottomSpacing } from "../../foundations/token/getBottomSpacing/index.js";
|
|
15
|
+
import { getObjectColor } from "../../foundations/token/getObjectColor/index.js";
|
|
16
|
+
import { getSpacing } from "../../foundations/token/getSpacing/index.js";
|
|
17
|
+
import { c as borderRadiusFull } from "../../BorderRadius-ClUShVLu.js";
|
|
18
|
+
import { c as colorObjectBrand, d as colorObjectUnselected } from "../../ObjectColor-BZDBuV8H.js";
|
|
19
|
+
import { f as filterProps } from "../../filterProps-Cewck8OH.js";
|
|
20
|
+
import IconButton from "../IconButton/index.js";
|
|
21
|
+
import { S as ScreenreaderOnly } from "../../index-DQhtQZ85.js";
|
|
22
|
+
const getItems = (items, loop) => {
|
|
23
|
+
const normalizedItems = [...items].map((item, index) => ({
|
|
24
|
+
...item,
|
|
25
|
+
index,
|
|
26
|
+
ghost: false,
|
|
27
|
+
interactive: true
|
|
28
|
+
}));
|
|
29
|
+
for (const index in normalizedItems) {
|
|
30
|
+
normalizedItems[index].index = parseInt(index, 10);
|
|
31
|
+
normalizedItems[index].ghost = false;
|
|
32
|
+
}
|
|
33
|
+
if (!loop) {
|
|
34
|
+
return normalizedItems;
|
|
35
|
+
}
|
|
36
|
+
const front = [...normalizedItems].map((item) => {
|
|
37
|
+
const ghost = {
|
|
38
|
+
...item
|
|
39
|
+
};
|
|
40
|
+
ghost.uid = `front-ghost${ghost.uid}`;
|
|
41
|
+
ghost.ghost = true;
|
|
42
|
+
return ghost;
|
|
43
|
+
});
|
|
44
|
+
const back = [...normalizedItems].map((item) => {
|
|
45
|
+
const ghost = {
|
|
46
|
+
...item
|
|
47
|
+
};
|
|
48
|
+
ghost.uid = `back-ghost${ghost.uid}`;
|
|
49
|
+
ghost.ghost = true;
|
|
50
|
+
return ghost;
|
|
51
|
+
});
|
|
52
|
+
return front.concat(normalizedItems).concat(back);
|
|
53
|
+
};
|
|
54
|
+
const getItemByScroll = (scroll, itemWidth, items) => {
|
|
55
|
+
if (0 > scroll) {
|
|
56
|
+
scroll = 0;
|
|
57
|
+
}
|
|
58
|
+
if (scroll > itemWidth * items.length) {
|
|
59
|
+
scroll = itemWidth * items.length;
|
|
60
|
+
}
|
|
61
|
+
let visibleItem = Math.ceil(scroll / itemWidth);
|
|
62
|
+
if (!visibleItem) {
|
|
63
|
+
visibleItem = 0;
|
|
64
|
+
}
|
|
65
|
+
if (visibleItem >= items.length) {
|
|
66
|
+
visibleItem = items.length - 1;
|
|
67
|
+
}
|
|
68
|
+
if (!items[visibleItem]) {
|
|
69
|
+
return 0;
|
|
70
|
+
}
|
|
71
|
+
return visibleItem;
|
|
72
|
+
};
|
|
73
|
+
const scrollTo = (element, left, behavior = "smooth") => {
|
|
74
|
+
element.scrollTo({
|
|
75
|
+
left,
|
|
76
|
+
behavior
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
const initialState = {
|
|
80
|
+
ref: void 0,
|
|
81
|
+
visibleItems: 1,
|
|
82
|
+
interactive: [0],
|
|
83
|
+
goPrev: false,
|
|
84
|
+
goNext: false,
|
|
85
|
+
numberOfIndicators: 0,
|
|
86
|
+
activeIndicator: 0
|
|
87
|
+
};
|
|
88
|
+
const CarouselContext = createContext({
|
|
89
|
+
state: initialState
|
|
90
|
+
});
|
|
91
|
+
const CarouselProvider = ({
|
|
92
|
+
children,
|
|
93
|
+
loop,
|
|
94
|
+
...props
|
|
95
|
+
}) => {
|
|
96
|
+
const ref = useRef(null);
|
|
97
|
+
const focus = useFocusWithin(ref);
|
|
98
|
+
const [activeIndex, setActiveIndex] = useState(props.activeIndex);
|
|
99
|
+
const [scrollSpyIndex, setScrollSpyIndex] = useState(void 0);
|
|
100
|
+
const [interactive, setInteractive] = useState([]);
|
|
101
|
+
const [needsFirstPosition, setNeedsFirstPosition] = useState(activeIndex !== 0);
|
|
102
|
+
const [itemWidth, setItemWidth] = useState(0);
|
|
103
|
+
const [visibleItems, setVisibleItems] = useState(1);
|
|
104
|
+
const [goPrev, setGoPrev] = useState(false);
|
|
105
|
+
const [goNext, setGoNext] = useState(false);
|
|
106
|
+
const [numberOfIndicators, setNumberOfIndicators] = useState(0);
|
|
107
|
+
const [activeIndicator, setActiveIndicator] = useState(props.items[props.activeIndex].index);
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
if (loop) {
|
|
110
|
+
const update = props.items.filter((item) => !item.ghost).length;
|
|
111
|
+
setNumberOfIndicators(update);
|
|
112
|
+
} else {
|
|
113
|
+
const update = props.items.filter((item) => !item.ghost).length - visibleItems + 1;
|
|
114
|
+
setNumberOfIndicators(update);
|
|
115
|
+
}
|
|
116
|
+
}, [loop, visibleItems, props.items]);
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
if (!(ref == null ? void 0 : ref.current)) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (!itemWidth) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const track = ref == null ? void 0 : ref.current.offsetWidth;
|
|
125
|
+
setVisibleItems(Math.floor(track / itemWidth));
|
|
126
|
+
}, [itemWidth]);
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
let updateInteractive = [...Array(visibleItems).keys()].map((i) => activeIndex + i);
|
|
129
|
+
if (focus) {
|
|
130
|
+
updateInteractive = [...Array(props.items.length).keys()];
|
|
131
|
+
}
|
|
132
|
+
setInteractive(updateInteractive);
|
|
133
|
+
}, [focus, activeIndex, visibleItems, props.items]);
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
if (!(ref == null ? void 0 : ref.current)) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const handleResize = () => {
|
|
139
|
+
if (!window) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (!(ref == null ? void 0 : ref.current)) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const itemWidth2 = ref.current.querySelector("[data-carousel-item]").offsetWidth;
|
|
146
|
+
setItemWidth(itemWidth2);
|
|
147
|
+
};
|
|
148
|
+
window.addEventListener("resize", handleResize);
|
|
149
|
+
handleResize();
|
|
150
|
+
return () => {
|
|
151
|
+
window.removeEventListener("resize", handleResize);
|
|
152
|
+
};
|
|
153
|
+
}, [ref.current]);
|
|
154
|
+
useEffect(() => {
|
|
155
|
+
var _a, _b;
|
|
156
|
+
if (!(ref == null ? void 0 : ref.current)) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (!itemWidth) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const handleScroll = (event) => {
|
|
163
|
+
const left = event.target.scrollLeft;
|
|
164
|
+
const ucurrent = getItemByScroll(left - itemWidth / 2, itemWidth, props.items);
|
|
165
|
+
setScrollSpyIndex(ucurrent);
|
|
166
|
+
};
|
|
167
|
+
const handleScrollend = (event) => {
|
|
168
|
+
const left = event.target.scrollLeft;
|
|
169
|
+
let updateActiveIndex = getItemByScroll(left - itemWidth / 2, itemWidth, props.items);
|
|
170
|
+
if (loop) {
|
|
171
|
+
const ghosts = [];
|
|
172
|
+
for (let i = 0, x = visibleItems; i < x; i += 1) {
|
|
173
|
+
ghosts.push(props.items[i + updateActiveIndex].ghost);
|
|
174
|
+
}
|
|
175
|
+
if (!ghosts.includes(false)) {
|
|
176
|
+
updateActiveIndex = props.items.findIndex((item) => item.index === props.items[updateActiveIndex].index && !item.ghost);
|
|
177
|
+
const left2 = updateActiveIndex * itemWidth;
|
|
178
|
+
const behavior = "instant";
|
|
179
|
+
scrollTo(ref.current, left2, behavior);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (needsFirstPosition) {
|
|
183
|
+
setNeedsFirstPosition(false);
|
|
184
|
+
}
|
|
185
|
+
setActiveIndex(updateActiveIndex);
|
|
186
|
+
setScrollSpyIndex(void 0);
|
|
187
|
+
};
|
|
188
|
+
(_a = ref.current) == null ? void 0 : _a.addEventListener("scroll", handleScroll);
|
|
189
|
+
(_b = ref.current) == null ? void 0 : _b.addEventListener("scrollend", handleScrollend);
|
|
190
|
+
return () => {
|
|
191
|
+
var _a2, _b2;
|
|
192
|
+
(_a2 = ref.current) == null ? void 0 : _a2.removeEventListener("scroll", handleScroll);
|
|
193
|
+
(_b2 = ref.current) == null ? void 0 : _b2.removeEventListener("scrollend", handleScrollend);
|
|
194
|
+
};
|
|
195
|
+
}, [ref.current, itemWidth, visibleItems, props.items]);
|
|
196
|
+
useEffect(() => {
|
|
197
|
+
if (!ref.current) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (scrollSpyIndex) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (activeIndex === scrollSpyIndex) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const left = activeIndex * itemWidth;
|
|
207
|
+
const behavior = needsFirstPosition ? "instant" : "smooth";
|
|
208
|
+
scrollTo(ref.current, left, behavior);
|
|
209
|
+
}, [activeIndex, scrollSpyIndex, ref.current, itemWidth]);
|
|
210
|
+
useEffect(() => {
|
|
211
|
+
if (!props.onUpdate) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
const visibleIndexes = [];
|
|
215
|
+
for (let i = 0, x = visibleItems; i < x; i += 1) {
|
|
216
|
+
visibleIndexes.push(props.items[i + activeIndex].index);
|
|
217
|
+
}
|
|
218
|
+
props.onUpdate(visibleIndexes);
|
|
219
|
+
}, [activeIndex]);
|
|
220
|
+
const movePrev = () => {
|
|
221
|
+
const prev = activeIndex > 0 ? activeIndex - 1 : props.items.length - 1;
|
|
222
|
+
setActiveIndex(prev);
|
|
223
|
+
};
|
|
224
|
+
const moveNext = () => {
|
|
225
|
+
const next = activeIndex < props.items.length ? activeIndex + 1 : 0;
|
|
226
|
+
setActiveIndex(next);
|
|
227
|
+
};
|
|
228
|
+
useEffect(() => {
|
|
229
|
+
if (loop) {
|
|
230
|
+
setGoPrev(() => movePrev);
|
|
231
|
+
setGoNext(() => moveNext);
|
|
232
|
+
} else {
|
|
233
|
+
setGoPrev(activeIndex === 0 ? false : () => movePrev);
|
|
234
|
+
setGoNext(activeIndex + 1 >= numberOfIndicators ? false : () => moveNext);
|
|
235
|
+
}
|
|
236
|
+
}, [loop, activeIndex, numberOfIndicators]);
|
|
237
|
+
useEffect(() => {
|
|
238
|
+
const index = scrollSpyIndex || activeIndex;
|
|
239
|
+
setActiveIndicator(props.items[index].index);
|
|
240
|
+
}, [activeIndex, scrollSpyIndex]);
|
|
241
|
+
return /* @__PURE__ */ jsx(CarouselContext.Provider, { value: {
|
|
242
|
+
state: {
|
|
243
|
+
ref,
|
|
244
|
+
visibleItems,
|
|
245
|
+
interactive,
|
|
246
|
+
goPrev,
|
|
247
|
+
goNext,
|
|
248
|
+
numberOfIndicators,
|
|
249
|
+
activeIndicator
|
|
250
|
+
}
|
|
251
|
+
}, children });
|
|
252
|
+
};
|
|
253
|
+
const offsetHorizontal = 8;
|
|
254
|
+
const offsetVertical = 8;
|
|
255
|
+
const CarouselStyled = styled.section.withConfig({
|
|
256
|
+
shouldForwardProp: filterProps(),
|
|
257
|
+
displayName: "CarouselStyled",
|
|
258
|
+
componentId: "sc-14nqzsr-0"
|
|
259
|
+
})({
|
|
260
|
+
paddingBottom: "44px"
|
|
261
|
+
}, getBottomSpacing);
|
|
262
|
+
const CarouselViewportStyled = styled.div.withConfig({
|
|
263
|
+
shouldForwardProp: filterProps(),
|
|
264
|
+
displayName: "CarouselViewportStyled",
|
|
265
|
+
componentId: "sc-14nqzsr-1"
|
|
266
|
+
})({
|
|
267
|
+
overflowX: "scroll",
|
|
268
|
+
scrollBehavior: "smooth",
|
|
269
|
+
scrollSnapType: "x mandatory",
|
|
270
|
+
scrollbarWidth: "none",
|
|
271
|
+
width: `calc(100% + ${2 * offsetHorizontal}px)`,
|
|
272
|
+
"&::-webkit-scrollbar": {
|
|
273
|
+
width: 0,
|
|
274
|
+
height: 0
|
|
275
|
+
}
|
|
276
|
+
}, () => {
|
|
277
|
+
const nestedStyles = {};
|
|
278
|
+
const cardSelector = `&:has(${CardStyled.toString()})`;
|
|
279
|
+
nestedStyles[cardSelector] = {
|
|
280
|
+
paddingLeft: `${offsetHorizontal}px`,
|
|
281
|
+
paddingRight: `${offsetHorizontal}px`,
|
|
282
|
+
marginLeft: `${-1 * offsetHorizontal}px`,
|
|
283
|
+
paddingTop: `${offsetVertical}px`,
|
|
284
|
+
paddingBottom: `${offsetVertical}px`,
|
|
285
|
+
width: `calc(100% + ${2 * offsetHorizontal}px)`,
|
|
286
|
+
scrollPaddingLeft: `calc(${getSpacing(spacingMd)} - 6px)`,
|
|
287
|
+
...viewport.md({
|
|
288
|
+
scrollPaddingLeft: `calc(${getSpacing(spacingMd)} - 12px)`
|
|
289
|
+
})
|
|
290
|
+
};
|
|
291
|
+
return nestedStyles;
|
|
292
|
+
});
|
|
293
|
+
const CarouselTrackStyled = styled(GridStyled).withConfig({
|
|
294
|
+
shouldForwardProp: filterProps(),
|
|
295
|
+
displayName: "CarouselTrackStyled",
|
|
296
|
+
componentId: "sc-14nqzsr-2"
|
|
297
|
+
})({
|
|
298
|
+
flexWrap: "nowrap",
|
|
299
|
+
paddingBottom: getSpacing(spacingMd)
|
|
300
|
+
}, () => {
|
|
301
|
+
const nestedStyles = {};
|
|
302
|
+
const cardSelector = `&:has(${CardStyled.toString()})`;
|
|
303
|
+
nestedStyles[cardSelector] = {
|
|
304
|
+
paddingBottom: `calc(${getSpacing(spacingMd)} - ${offsetVertical}px)`
|
|
305
|
+
};
|
|
306
|
+
return nestedStyles;
|
|
307
|
+
});
|
|
308
|
+
const CarouselItemStyled = styled(GridItemStyled).withConfig({
|
|
309
|
+
shouldForwardProp: filterProps(),
|
|
310
|
+
displayName: "CarouselItemStyled",
|
|
311
|
+
componentId: "sc-14nqzsr-3"
|
|
312
|
+
})({});
|
|
313
|
+
const CarouselTrackEndStyled = styled(GridItemStyled).withConfig({
|
|
314
|
+
shouldForwardProp: filterProps(),
|
|
315
|
+
displayName: "CarouselTrackEndStyled",
|
|
316
|
+
componentId: "sc-14nqzsr-4"
|
|
317
|
+
})({
|
|
318
|
+
flexBasis: `${getSpacing(spacingMd)}px`
|
|
319
|
+
});
|
|
320
|
+
const CarouselSnapperStyled = styled.div.withConfig({
|
|
321
|
+
displayName: "CarouselSnapperStyled",
|
|
322
|
+
componentId: "sc-14nqzsr-5"
|
|
323
|
+
})({
|
|
324
|
+
scrollSnapAlign: "start",
|
|
325
|
+
height: "100%"
|
|
326
|
+
});
|
|
327
|
+
const CarouselControlStyled = styled.aside.withConfig({
|
|
328
|
+
shouldForwardProp: filterProps(),
|
|
329
|
+
displayName: "CarouselControlStyled",
|
|
330
|
+
componentId: "sc-14nqzsr-6"
|
|
331
|
+
})({
|
|
332
|
+
position: "relative"
|
|
333
|
+
});
|
|
334
|
+
const CarouselNavigationPrevButtonStyled = styled.div.withConfig({
|
|
335
|
+
shouldForwardProp: filterProps(),
|
|
336
|
+
displayName: "CarouselNavigationPrevButtonStyled",
|
|
337
|
+
componentId: "sc-14nqzsr-7"
|
|
338
|
+
})({
|
|
339
|
+
position: "absolute",
|
|
340
|
+
top: "0px",
|
|
341
|
+
left: "0px"
|
|
342
|
+
});
|
|
343
|
+
const CarouselNavigationNextButtonStyled = styled.div.withConfig({
|
|
344
|
+
shouldForwardProp: filterProps(),
|
|
345
|
+
displayName: "CarouselNavigationNextButtonStyled",
|
|
346
|
+
componentId: "sc-14nqzsr-8"
|
|
347
|
+
})({
|
|
348
|
+
position: "absolute",
|
|
349
|
+
top: "0px",
|
|
350
|
+
right: "0px"
|
|
351
|
+
});
|
|
352
|
+
const CarouselIndicatorsStyled = styled.ol.withConfig({
|
|
353
|
+
shouldForwardProp: filterProps(),
|
|
354
|
+
displayName: "CarouselIndicatorsStyled",
|
|
355
|
+
componentId: "sc-14nqzsr-9"
|
|
356
|
+
})({
|
|
357
|
+
position: "absolute",
|
|
358
|
+
right: "0",
|
|
359
|
+
left: "0",
|
|
360
|
+
textAlign: "center",
|
|
361
|
+
height: "24px",
|
|
362
|
+
paddingTop: "10px",
|
|
363
|
+
display: "inline-block"
|
|
364
|
+
});
|
|
365
|
+
const CarouselIndicatorItemStyled = styled.li.withConfig({
|
|
366
|
+
shouldForwardProp: filterProps(),
|
|
367
|
+
displayName: "CarouselIndicatorItemStyled",
|
|
368
|
+
componentId: "sc-14nqzsr-10"
|
|
369
|
+
})({
|
|
370
|
+
display: "inline-block",
|
|
371
|
+
width: "24px",
|
|
372
|
+
height: "24px",
|
|
373
|
+
position: "relative"
|
|
374
|
+
}, {
|
|
375
|
+
"& div": {
|
|
376
|
+
position: "absolute",
|
|
377
|
+
top: "50%",
|
|
378
|
+
left: "50%",
|
|
379
|
+
transform: "translateY(-50%) translateX(-50%)"
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
const CarouselIndicatorStyled = styled.div.withConfig({
|
|
383
|
+
shouldForwardProp: filterProps(),
|
|
384
|
+
displayName: "CarouselIndicatorStyled",
|
|
385
|
+
componentId: "sc-14nqzsr-11"
|
|
386
|
+
})({
|
|
387
|
+
display: "inline-block",
|
|
388
|
+
borderRadius: getBorderRadius(borderRadiusFull),
|
|
389
|
+
transition: "background-color 0.6s ease , width 0.6s ease,height 0.6s ease"
|
|
390
|
+
}, ({
|
|
391
|
+
isActive = false
|
|
392
|
+
}) => {
|
|
393
|
+
return {
|
|
394
|
+
backgroundColor: isActive ? getObjectColor(colorObjectBrand) : getObjectColor(colorObjectUnselected),
|
|
395
|
+
width: isActive ? "16px" : "10px",
|
|
396
|
+
height: isActive ? "16px" : "10px"
|
|
397
|
+
};
|
|
398
|
+
});
|
|
399
|
+
const CarouselIndicator = () => {
|
|
400
|
+
const {
|
|
401
|
+
state: {
|
|
402
|
+
numberOfIndicators,
|
|
403
|
+
activeIndicator
|
|
404
|
+
}
|
|
405
|
+
} = useContext(CarouselContext);
|
|
406
|
+
if (!numberOfIndicators) {
|
|
407
|
+
return null;
|
|
408
|
+
}
|
|
409
|
+
const indicators = [...Array(numberOfIndicators).keys()];
|
|
410
|
+
return /* @__PURE__ */ jsx(CarouselIndicatorsStyled, { children: indicators.map((indicator) => /* @__PURE__ */ jsx(CarouselIndicatorItemStyled, { isActive: indicator === activeIndicator, children: /* @__PURE__ */ jsx(CarouselIndicatorStyled, { isActive: indicator === activeIndicator }) }, indicator)) });
|
|
411
|
+
};
|
|
412
|
+
const CarouselItem = ({
|
|
413
|
+
uid,
|
|
414
|
+
gridConfig,
|
|
415
|
+
interactive = true,
|
|
416
|
+
children,
|
|
417
|
+
...props
|
|
418
|
+
}) => {
|
|
419
|
+
return /* @__PURE__ */ createElement(CarouselItemStyled, { ...props, component: "GridItem", key: uid, uid, ...gridConfig, as: liTagName, ...{
|
|
420
|
+
inert: !interactive ? true : void 0
|
|
421
|
+
} }, children);
|
|
422
|
+
};
|
|
423
|
+
const CarouselNavigation = ({
|
|
424
|
+
uid,
|
|
425
|
+
screenReaderInstruction,
|
|
426
|
+
prevAriaLabel,
|
|
427
|
+
nextAriaLabel
|
|
428
|
+
}) => {
|
|
429
|
+
const {
|
|
430
|
+
state: {
|
|
431
|
+
goPrev,
|
|
432
|
+
goNext
|
|
433
|
+
}
|
|
434
|
+
} = useContext(CarouselContext);
|
|
435
|
+
const getPrevButton = () => {
|
|
436
|
+
if (false === goPrev) {
|
|
437
|
+
return null;
|
|
438
|
+
}
|
|
439
|
+
return /* @__PURE__ */ jsx(CarouselNavigationPrevButtonStyled, { children: /* @__PURE__ */ jsx(IconButton, { label: prevAriaLabel, iconName: "ChevronLeft", appearance: "tertiary", tabIndex: -1, "aria-disabled": "true", "aria-describedby": `${uid}-carousel-instruction`, onClick: goPrev }) });
|
|
440
|
+
};
|
|
441
|
+
const getNextButton = () => {
|
|
442
|
+
if (false === goNext) {
|
|
443
|
+
return null;
|
|
444
|
+
}
|
|
445
|
+
return /* @__PURE__ */ jsx(CarouselNavigationNextButtonStyled, { children: /* @__PURE__ */ jsx(IconButton, { label: nextAriaLabel, iconName: "ChevronRight", appearance: "tertiary", tabIndex: -1, "aria-disabled": "true", "aria-describedby": `${uid}-carousel-instruction`, onClick: goNext }) });
|
|
446
|
+
};
|
|
447
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
448
|
+
/* @__PURE__ */ jsx(ScreenreaderOnly, { id: `${uid}-carousel-instruction`, children: screenReaderInstruction }),
|
|
449
|
+
getPrevButton(),
|
|
450
|
+
getNextButton()
|
|
451
|
+
] });
|
|
452
|
+
};
|
|
453
|
+
const CarouselInner = ({
|
|
454
|
+
gridConfig,
|
|
455
|
+
items,
|
|
456
|
+
...props
|
|
457
|
+
}) => {
|
|
458
|
+
const {
|
|
459
|
+
state: {
|
|
460
|
+
ref,
|
|
461
|
+
interactive
|
|
462
|
+
}
|
|
463
|
+
} = useContext(CarouselContext);
|
|
464
|
+
return /* @__PURE__ */ jsxs(CarouselStyled, { ...props, bottomSpacing: spacingMd, children: [
|
|
465
|
+
/* @__PURE__ */ jsx(CarouselViewportStyled, { ref, children: /* @__PURE__ */ jsxs(CarouselTrackStyled, { as: ulTagName, stretch: true, children: [
|
|
466
|
+
items.map(({
|
|
467
|
+
uid,
|
|
468
|
+
...item
|
|
469
|
+
}, index) => /* @__PURE__ */ jsx(CarouselItem, { uid, gridConfig, interactive: interactive.includes(index), "data-carousel-item": item.index, "data-carousel-ghost": true === item.ghost, children: /* @__PURE__ */ jsx(CarouselSnapperStyled, { children: item.children }) }, uid)),
|
|
470
|
+
/* @__PURE__ */ jsx(CarouselTrackEndStyled, { ...gridConfig, as: liTagName })
|
|
471
|
+
] }) }),
|
|
472
|
+
/* @__PURE__ */ jsxs(CarouselControlStyled, { children: [
|
|
473
|
+
/* @__PURE__ */ jsx(CarouselIndicator, {}),
|
|
474
|
+
/* @__PURE__ */ jsx(CarouselNavigation, { uid: props.uid, screenReaderInstruction: props.screenReaderInstruction, prevAriaLabel: props.prevAriaLabel, nextAriaLabel: props.nextAriaLabel })
|
|
475
|
+
] })
|
|
476
|
+
] });
|
|
477
|
+
};
|
|
478
|
+
const carouselDefaultGridConfig = {
|
|
479
|
+
sm: 12,
|
|
480
|
+
md: 6,
|
|
481
|
+
lg: 4
|
|
482
|
+
};
|
|
483
|
+
const Carousel = ({
|
|
484
|
+
items,
|
|
485
|
+
activeIndex,
|
|
486
|
+
loop = false,
|
|
487
|
+
gridConfig = carouselDefaultGridConfig,
|
|
488
|
+
...props
|
|
489
|
+
}) => {
|
|
490
|
+
activeIndex = activeIndex ? activeIndex : 0;
|
|
491
|
+
activeIndex = loop ? activeIndex + items.length : activeIndex;
|
|
492
|
+
const loopableItems = getItems(items, loop);
|
|
493
|
+
return /* @__PURE__ */ jsx(CarouselProvider, { ...props, loop, gridConfig, items: loopableItems, activeIndex, children: /* @__PURE__ */ jsx(CarouselInner, { ...props, loop, gridConfig, items: loopableItems, activeIndex }) });
|
|
494
|
+
};
|
|
495
|
+
export {
|
|
496
|
+
Carousel as default
|
|
497
|
+
};
|