@treely/strapi-slices 5.2.0 → 5.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@treely/strapi-slices",
3
- "version": "5.2.0",
3
+ "version": "5.2.2",
4
4
  "license": "MIT",
5
5
  "author": "Tree.ly GmbH",
6
6
  "description": "@treely/strapi-slices is a open source library maintained by Tree.ly.",
@@ -126,7 +126,7 @@
126
126
  "dependencies": {
127
127
  "@phosphor-icons/react": "^2.0.15",
128
128
  "adblock-detect-react": "^1.1.0",
129
- "boemly": "^5.7.2",
129
+ "boemly": "^5.7.3",
130
130
  "formik": "^2.4.5",
131
131
  "framer-motion": "^10.16.5",
132
132
  "mapbox-gl": "^2.15.0"
@@ -11,6 +11,7 @@ import portfolioProjectInfoMessagesDe from './components/portfolio/ProjectInfo/m
11
11
  import portfolioProjectCardMessagesDe from './components/portfolio/PortfolioProjectCard/messages.de';
12
12
  import portfolioSmallCheckoutMessagesDe from './components/portfolio/SmallCheckout/messages.de';
13
13
  import shopCheckoutMessagesDe from './slices/ShopCheckout/messages.de';
14
+ import textCarouselMessagesDe from './slices/TextCarousel/messages.de';
14
15
  import timelineMessagesDe from './slices/Timeline/messages.de';
15
16
 
16
17
  import unitMessagesDe from './unit.messages.de';
@@ -36,6 +37,7 @@ const rootMessagesDe = {
36
37
  ...projectFactsMessagesDe,
37
38
  ...projectsMapMessagesDe,
38
39
  ...shopCheckoutMessagesDe,
40
+ ...textCarouselMessagesDe,
39
41
  ...timelineMessagesDe,
40
42
 
41
43
  //
@@ -11,6 +11,7 @@ import portfolioProjectInfoMessagesEn from './components/portfolio/ProjectInfo/m
11
11
  import portfolioProjectCardMessagesEn from './components/portfolio/PortfolioProjectCard/messages.en';
12
12
  import portfolioSmallCheckoutMessagesEn from './components/portfolio/SmallCheckout/messages.en';
13
13
  import shopCheckoutMessagesEn from './slices/ShopCheckout/messages.en';
14
+ import textCarouselMessagesEn from './slices/TextCarousel/messages.en';
14
15
  import timelineMessagesEn from './slices/Timeline/messages.en';
15
16
 
16
17
  import unitMessagesEn from './unit.messages.en';
@@ -36,6 +37,7 @@ const rootMessagesEn = {
36
37
  ...projectFactsMessagesEn,
37
38
  ...projectsMapMessagesEn,
38
39
  ...shopCheckoutMessagesEn,
40
+ ...textCarouselMessagesEn,
39
41
  ...timelineMessagesEn,
40
42
 
41
43
  //
@@ -187,6 +187,7 @@ export const Cta: React.FC<CtaProps> = ({ slice }: CtaProps) => {
187
187
  return (
188
188
  <DefaultSectionContainer
189
189
  backgroundColor={VARIANTS[slice.variant].backgroundColor.left}
190
+ title={slice.title}
190
191
  >
191
192
  <Wrapper>
192
193
  {slice.title ? (
@@ -47,6 +47,7 @@ WithMultipleCards.args = {
47
47
  strapiCustomerStoryMock,
48
48
  strapiCustomerStoryWithCustomerQuoteCardMock,
49
49
  strapiCustomerStoryWithLogoCardMock,
50
+ strapiCustomerStoryWithLogoCardMock,
50
51
  strapiCustomerStoryMock,
51
52
  strapiCustomerStoryWithCustomerQuoteCardMock,
52
53
  ],
@@ -55,6 +56,7 @@ WithMultipleCards.args = {
55
56
  strapiCustomerStoryMock,
56
57
  strapiCustomerStoryWithCustomerQuoteCardMock,
57
58
  strapiCustomerStoryWithLogoCardMock,
59
+ strapiCustomerStoryWithLogoCardMock,
58
60
  strapiCustomerStoryMock,
59
61
  strapiCustomerStoryWithCustomerQuoteCardMock,
60
62
  ],
@@ -53,9 +53,9 @@ export const IconGrid: React.FC<IconGridProps> = ({ slice }: IconGridProps) => (
53
53
  )}
54
54
 
55
55
  <SimpleGrid
56
- columns={[1, null, null, 2]}
57
- gap="32"
58
- rowGap={['16', null, null, '28']}
56
+ columns={[1, null, null, 2, 3]}
57
+ gap="16"
58
+ rowGap={['16', null, null, '20']}
59
59
  >
60
60
  {slice.iconsWithTextAndButton.map((iconWithTextAndButton) => (
61
61
  <Box key={iconWithTextAndButton.id}>
@@ -1,8 +1,10 @@
1
- import React, { useRef } from 'react';
1
+ import React, { useContext, useRef, useState } from 'react';
2
2
  import {
3
+ Box,
3
4
  Center,
4
5
  DefaultSectionContainer,
5
6
  DefaultSectionHeader,
7
+ IconButton,
6
8
  TextCardWithIcon,
7
9
  useToken,
8
10
  Wrapper,
@@ -18,6 +20,10 @@ import {
18
20
  CarouselContainer,
19
21
  CarouselInnerContainer,
20
22
  } from './styles';
23
+ import { useMeasure, useWindowSize } from 'react-use';
24
+ import { AnimatePresence, motion } from 'framer-motion';
25
+ import { ArrowLeft, ArrowRight } from '@phosphor-icons/react';
26
+ import { IntlContext } from '../../components/ContextProvider';
21
27
 
22
28
  interface TextCarouselSlice extends StrapiDefaultHeader {
23
29
  slides: StrapiTextCardWithIcon[];
@@ -31,9 +37,18 @@ export const TextCarousel: React.FC<TextCarouselProps> = ({
31
37
  slice,
32
38
  }: TextCarouselProps) => {
33
39
  const [primary50] = useToken('colors', ['primary.50']);
40
+ const [slideRef, { width: slideWidth }] = useMeasure<HTMLDivElement>();
41
+ const { formatMessage } = useContext(IntlContext);
34
42
 
35
43
  const containerRef = useRef(null);
36
44
 
45
+ const { width: windowWidth } = useWindowSize();
46
+
47
+ const [sliderIndex, setSliderIndex] = useState(0);
48
+
49
+ const allowScroll = windowWidth / 2 / slideWidth < slice.slides.length;
50
+ const canMoveRight = sliderIndex < slice.slides.length - 1;
51
+ const canMoveLeft = sliderIndex !== 0;
37
52
  return (
38
53
  <DefaultSectionContainer backgroundColor={primary50} title={slice.title}>
39
54
  <Wrapper>
@@ -48,29 +63,96 @@ export const TextCarousel: React.FC<TextCarouselProps> = ({
48
63
  </Wrapper>
49
64
 
50
65
  <CarouselContainer ref={containerRef}>
51
- <CarouselInnerContainer
52
- drag="x"
53
- dragConstraints={containerRef}
54
- numberofitems={slice.slides.length}
55
- >
56
- {slice.slides.map(({ id, title, text, icon }) => (
57
- <CardContainer key={id} numberofitems={slice.slides.length}>
58
- <TextCardWithIcon
59
- title={title}
60
- text={text}
61
- icon={
62
- <Image
63
- src={strapiMediaUrl(icon.img, 'small')}
64
- alt={icon.alt}
65
- fill
66
- style={{ objectFit: icon.objectFit || 'contain' }}
66
+ <Box position="relative" width="full">
67
+ <CarouselInnerContainer
68
+ numberofitems={slice.slides.length}
69
+ animate={{
70
+ x: slideWidth * -sliderIndex,
71
+ }}
72
+ transition={{
73
+ duration: 0.3,
74
+ ease: 'easeInOut',
75
+ }}
76
+ >
77
+ {slice.slides.map(({ id, title, text, icon }) => (
78
+ <CardContainer
79
+ key={id}
80
+ ref={slideRef}
81
+ numberofitems={slice.slides.length}
82
+ >
83
+ <TextCardWithIcon
84
+ title={title}
85
+ text={text}
86
+ icon={
87
+ <Image
88
+ src={strapiMediaUrl(icon.img, 'small')}
89
+ alt={icon.alt}
90
+ fill
91
+ style={{ objectFit: icon.objectFit || 'contain' }}
92
+ />
93
+ }
94
+ displayAs="column"
95
+ />
96
+ </CardContainer>
97
+ ))}
98
+ </CarouselInnerContainer>
99
+ <Box
100
+ display={['none', null, null, !!allowScroll ? 'flex' : 'none']}
101
+ pointerEvents="none"
102
+ position="absolute"
103
+ top="40%"
104
+ left="0"
105
+ width="full"
106
+ py="0"
107
+ px="32"
108
+ justifyContent="space-between"
109
+ >
110
+ <Box>
111
+ <AnimatePresence>
112
+ {canMoveLeft && (
113
+ <IconButton
114
+ key="leftButton"
115
+ as={motion.button}
116
+ initial={{ opacity: 0 }}
117
+ animate={{ opacity: 1 }}
118
+ exit={{ opacity: 0 }}
119
+ size="lg"
120
+ variant="outline"
121
+ onClick={() => setSliderIndex(sliderIndex - 1)}
122
+ aria-label={formatMessage({
123
+ id: 'sections.textCarousel.moveLeft',
124
+ })}
125
+ icon={<ArrowLeft size={16} />}
126
+ pointerEvents="auto"
127
+ boxShadow="sm"
67
128
  />
68
- }
69
- displayAs="column"
70
- />
71
- </CardContainer>
72
- ))}
73
- </CarouselInnerContainer>
129
+ )}
130
+ </AnimatePresence>
131
+ </Box>
132
+ <Box>
133
+ <AnimatePresence>
134
+ {canMoveRight && (
135
+ <IconButton
136
+ key="rightButton"
137
+ as={motion.button}
138
+ initial={{ opacity: 0 }}
139
+ animate={{ opacity: 1 }}
140
+ exit={{ opacity: 0 }}
141
+ size="lg"
142
+ variant="outline"
143
+ onClick={() => setSliderIndex(sliderIndex + 1)}
144
+ aria-label={formatMessage({
145
+ id: 'sections.textCarousel.moveRight',
146
+ })}
147
+ icon={<ArrowRight size={16} />}
148
+ pointerEvents="auto"
149
+ boxShadow="md"
150
+ />
151
+ )}
152
+ </AnimatePresence>
153
+ </Box>
154
+ </Box>
155
+ </Box>
74
156
  </CarouselContainer>
75
157
 
76
158
  <>
@@ -0,0 +1,5 @@
1
+ const messagesDe = {
2
+ 'sections.textCarousel.moveRight': 'Nach rechts bewegen',
3
+ 'sections.textCarousel.moveLeft': 'Nach links bewegen',
4
+ };
5
+ export default messagesDe;
@@ -0,0 +1,5 @@
1
+ const messagesDe = {
2
+ 'sections.textCarousel.moveRight': 'Move right',
3
+ 'sections.textCarousel.moveLeft': 'Move left',
4
+ };
5
+ export default messagesDe;
@@ -4,18 +4,20 @@ import { BREAKPOINT_MD } from '../../constants/breakpoints';
4
4
  import { Box } from 'boemly';
5
5
 
6
6
  export const CarouselContainer = styled(Box)`
7
- overflow-x: scroll;
8
-
9
7
  margin-top: var(--boemly-space-6);
10
8
  padding: var(--boemly-space-8) 0;
11
9
 
12
- scrollbar-width: none;
13
-
14
- &::-webkit-scrollbar {
15
- display: none;
16
- }
17
10
  @media screen and (max-width: ${BREAKPOINT_MD}) {
18
11
  margin-top: var(--boemly-space-4);
12
+ width: var(--boemly-size-full);
13
+ }
14
+
15
+ width: var(--boemly-size-full);
16
+
17
+ overflow-x: hidden;
18
+
19
+ @media screen and (max-width: ${BREAKPOINT_MD}) {
20
+ overflow-x: scroll;
19
21
  }
20
22
  `;
21
23
 
@@ -35,8 +37,9 @@ export const CarouselInnerContainer = styled(
35
37
  min-width: var(--boemly-sizes-full);
36
38
 
37
39
  @media screen and (max-width: ${BREAKPOINT_MD}) {
40
+ justify-content: flex-start;
38
41
  width: calc(
39
- (var(--boemly-sizes-xs) + var(--boemly-space-4)) *
42
+ (var(--boemly-sizes-2xs) + var(--boemly-space-4)) *
40
43
  ${({ numberofitems }: CarouselInnerContainerProps) => numberofitems} +
41
44
  var(--boemly-space-6)
42
45
  );
@@ -50,14 +53,14 @@ export const CardContainer = styled(Box)<CardContainerProps>`
50
53
  width: ${({ numberofitems }: CardContainerProps) =>
51
54
  numberofitems === 3 ? 'var(--boemly-sizes-xl)' : 'var(--boemly-sizes-sm)'};
52
55
 
53
- margin-right: var(--boemly-space-16);
56
+ margin-right: var(--boemly-space-6);
54
57
 
55
58
  &:first-of-type {
56
- margin-left: var(--boemly-space-16);
59
+ margin-left: var(--boemly-space-6);
57
60
  }
58
61
 
59
62
  @media screen and (max-width: ${BREAKPOINT_MD}) {
60
- width: var(--boemly-sizes-xs);
63
+ width: var(--boemly-sizes-2xs);
61
64
 
62
65
  margin-right: var(--boemly-space-4);
63
66
 
@@ -24,6 +24,7 @@ export const strapiCustomerStoryMock: IStrapiData<StrapiCustomerStory> = {
24
24
  id: 1,
25
25
  alt: 'Icon alt text',
26
26
  img: { data: storybookStrapiTreeIconMock },
27
+ objectFit: 'contain',
27
28
  },
28
29
  img: {
29
30
  id: 1,