@salt-ds/embla-carousel 0.1.5 → 0.1.6
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/CHANGELOG.md +31 -0
- package/css/salt-embla-carousel.css +42 -22
- package/dist-cjs/Carousel.js +30 -9
- package/dist-cjs/Carousel.js.map +1 -1
- package/dist-cjs/CarouselAutoplayIndicator.js.map +1 -1
- package/dist-cjs/CarouselAutoplayIndicatorSVG.js.map +1 -1
- package/dist-cjs/CarouselCard.css.js +1 -1
- package/dist-cjs/CarouselCard.js +18 -8
- package/dist-cjs/CarouselCard.js.map +1 -1
- package/dist-cjs/CarouselContext.js.map +1 -1
- package/dist-cjs/CarouselNextButton.js +4 -1
- package/dist-cjs/CarouselNextButton.js.map +1 -1
- package/dist-cjs/CarouselPreviousButton.js +4 -1
- package/dist-cjs/CarouselPreviousButton.js.map +1 -1
- package/dist-cjs/CarouselProgressLabel.js +11 -33
- package/dist-cjs/CarouselProgressLabel.js.map +1 -1
- package/dist-cjs/CarouselSlides.css.js +1 -1
- package/dist-cjs/CarouselSlides.js +119 -23
- package/dist-cjs/CarouselSlides.js.map +1 -1
- package/dist-cjs/CarouselTab.css.js +1 -1
- package/dist-cjs/CarouselTab.js +1 -5
- package/dist-cjs/CarouselTab.js.map +1 -1
- package/dist-cjs/CarouselTabList.css.js +1 -1
- package/dist-cjs/CarouselTabList.js +41 -27
- package/dist-cjs/CarouselTabList.js.map +1 -1
- package/dist-cjs/createCustomSettle.js.map +1 -1
- package/dist-cjs/getSlideDescription.js +32 -0
- package/dist-cjs/getSlideDescription.js.map +1 -0
- package/dist-cjs/getVisibleSlideDescription.js +26 -0
- package/dist-cjs/getVisibleSlideDescription.js.map +1 -0
- package/dist-cjs/getVisibleSlideIndexes.js +33 -0
- package/dist-cjs/getVisibleSlideIndexes.js.map +1 -0
- package/dist-cjs/index.js +0 -3
- package/dist-cjs/index.js.map +1 -1
- package/dist-cjs/usePrevNextButtons.js +3 -1
- package/dist-cjs/usePrevNextButtons.js.map +1 -1
- package/dist-es/Carousel.js +32 -11
- package/dist-es/Carousel.js.map +1 -1
- package/dist-es/CarouselAutoplayIndicator.js.map +1 -1
- package/dist-es/CarouselAutoplayIndicatorSVG.js.map +1 -1
- package/dist-es/CarouselCard.css.js +1 -1
- package/dist-es/CarouselCard.js +18 -8
- package/dist-es/CarouselCard.js.map +1 -1
- package/dist-es/CarouselContext.js.map +1 -1
- package/dist-es/CarouselNextButton.js +4 -1
- package/dist-es/CarouselNextButton.js.map +1 -1
- package/dist-es/CarouselPreviousButton.js +4 -1
- package/dist-es/CarouselPreviousButton.js.map +1 -1
- package/dist-es/CarouselProgressLabel.js +12 -34
- package/dist-es/CarouselProgressLabel.js.map +1 -1
- package/dist-es/CarouselSlides.css.js +1 -1
- package/dist-es/CarouselSlides.js +121 -25
- package/dist-es/CarouselSlides.js.map +1 -1
- package/dist-es/CarouselTab.css.js +1 -1
- package/dist-es/CarouselTab.js +1 -5
- package/dist-es/CarouselTab.js.map +1 -1
- package/dist-es/CarouselTabList.css.js +1 -1
- package/dist-es/CarouselTabList.js +42 -28
- package/dist-es/CarouselTabList.js.map +1 -1
- package/dist-es/createCustomSettle.js.map +1 -1
- package/dist-es/getSlideDescription.js +30 -0
- package/dist-es/getSlideDescription.js.map +1 -0
- package/dist-es/getVisibleSlideDescription.js +24 -0
- package/dist-es/getVisibleSlideDescription.js.map +1 -0
- package/dist-es/getVisibleSlideIndexes.js +30 -0
- package/dist-es/getVisibleSlideIndexes.js.map +1 -0
- package/dist-es/index.js +0 -1
- package/dist-es/index.js.map +1 -1
- package/dist-es/usePrevNextButtons.js +3 -1
- package/dist-es/usePrevNextButtons.js.map +1 -1
- package/dist-types/Carousel.d.ts +7 -1
- package/dist-types/CarouselContext.d.ts +31 -0
- package/dist-types/CarouselTab.d.ts +0 -6
- package/dist-types/CarouselTabList.d.ts +4 -0
- package/dist-types/getSlideDescription.d.ts +7 -0
- package/dist-types/getVisibleSlideDescription.d.ts +7 -0
- package/dist-types/getVisibleSlideIndexes.d.ts +8 -0
- package/dist-types/index.d.ts +0 -1
- package/package.json +2 -2
- package/dist-cjs/CarouselAnnouncementPlugin.js +0 -52
- package/dist-cjs/CarouselAnnouncementPlugin.js.map +0 -1
- package/dist-cjs/CarouselProgressLabel.css.js +0 -6
- package/dist-cjs/CarouselProgressLabel.css.js.map +0 -1
- package/dist-es/CarouselAnnouncementPlugin.js +0 -49
- package/dist-es/CarouselAnnouncementPlugin.js.map +0 -1
- package/dist-es/CarouselProgressLabel.css.js +0 -4
- package/dist-es/CarouselProgressLabel.css.js.map +0 -1
- package/dist-types/CarouselAnnouncementPlugin.d.ts +0 -24
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# @salt-ds/embla-carousel
|
|
2
2
|
|
|
3
|
+
## 0.1.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 30fc785: Accessibility updates for Carousel
|
|
8
|
+
|
|
9
|
+
- Carousel now passes WCAG 2.1 AA requirements, if implemented as per documentation.
|
|
10
|
+
- Removed next/prev buttons from focus order, when displaying a tablist.
|
|
11
|
+
- Slides and actions within slides are now focusable.
|
|
12
|
+
|
|
13
|
+
Removed embla plugin `CarouselAnnouncementPlugin.ts` as it is no longer needed.
|
|
14
|
+
|
|
15
|
+
```diff
|
|
16
|
+
- import { CarouselAnnouncementPlugin } from "./CarouselAnnouncementPlugin";
|
|
17
|
+
<Carousel
|
|
18
|
+
aria-label="Account overview"
|
|
19
|
+
getEmblaApi={setEmblaApi}
|
|
20
|
+
- emblaPlugins={[CarouselAnnouncementPlugin()]}
|
|
21
|
+
>
|
|
22
|
+
</Carousel>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [378fc01]
|
|
26
|
+
- Updated dependencies [1f53f12]
|
|
27
|
+
- Updated dependencies [22fed0d]
|
|
28
|
+
- Updated dependencies [770bc9c]
|
|
29
|
+
- Updated dependencies [54e4b19]
|
|
30
|
+
- Updated dependencies [bbb7dba]
|
|
31
|
+
- Updated dependencies [c3df8d8]
|
|
32
|
+
- @salt-ds/core@1.49.0
|
|
33
|
+
|
|
3
34
|
## 0.1.5
|
|
4
35
|
|
|
5
36
|
### Patch Changes
|
|
@@ -56,41 +56,71 @@
|
|
|
56
56
|
gap: var(--salt-spacing-200);
|
|
57
57
|
flex-grow: 1;
|
|
58
58
|
}
|
|
59
|
+
.saltCarouselCard:focus-visible {
|
|
60
|
+
outline: none;
|
|
61
|
+
}
|
|
62
|
+
.saltCarouselCard:focus-visible::after {
|
|
63
|
+
content: "";
|
|
64
|
+
position: absolute;
|
|
65
|
+
top: 0;
|
|
66
|
+
bottom: 0;
|
|
67
|
+
left: var(--carousel-slide-spacing);
|
|
68
|
+
right: 0;
|
|
69
|
+
outline: var(--salt-focused-outline);
|
|
70
|
+
outline-offset: calc(var(--salt-focused-outlineWidth) * -1);
|
|
71
|
+
cursor: var(--salt-cursor-hover);
|
|
72
|
+
border-radius: var(--salt-palette-corner, 0);
|
|
73
|
+
}
|
|
59
74
|
.saltCarouselCard-body {
|
|
60
75
|
display: flex;
|
|
61
76
|
overflow: hidden;
|
|
62
77
|
flex-direction: column;
|
|
63
|
-
gap: var(--salt-spacing-200);
|
|
64
78
|
flex-grow: 1;
|
|
79
|
+
padding-bottom: var(--salt-spacing-200);
|
|
80
|
+
}
|
|
81
|
+
.saltCarouselCard-header {
|
|
82
|
+
padding-bottom: var(--salt-spacing-100);
|
|
83
|
+
}
|
|
84
|
+
.saltCarouselCard-actions {
|
|
85
|
+
padding-top: var(--salt-spacing-200);
|
|
86
|
+
}
|
|
87
|
+
.saltCarouselCard-body.saltCarouselCard-bordered-body {
|
|
65
88
|
padding: 0 var(--salt-spacing-200) var(--salt-spacing-200) var(--salt-spacing-200);
|
|
66
89
|
}
|
|
67
90
|
.saltCarouselCard-content h2,
|
|
68
91
|
.saltCarouselCard-content h3 {
|
|
69
92
|
margin: 0;
|
|
70
93
|
}
|
|
71
|
-
.saltCarouselCard[data-visibility=off-screen] a {
|
|
72
|
-
visibility: hidden;
|
|
73
|
-
}
|
|
74
94
|
.saltCarouselCard-bordered {
|
|
75
95
|
background: var(--salt-container-primary-background);
|
|
76
96
|
border: var(--salt-size-fixed-100) var(--salt-container-borderStyle) var(--salt-container-primary-borderColor);
|
|
77
97
|
border-radius: var(--salt-palette-corner, 0);
|
|
78
98
|
}
|
|
79
99
|
|
|
80
|
-
/* src/CarouselProgressLabel.css */
|
|
81
|
-
.saltCarouselTabList.saltText {
|
|
82
|
-
font-weight: var(--salt-text-fontWeight-strong);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
100
|
/* src/CarouselSlides.css */
|
|
86
101
|
.saltCarouselSlides {
|
|
87
102
|
overflow: hidden;
|
|
103
|
+
cursor: var(--salt-cursor-grab);
|
|
88
104
|
}
|
|
89
105
|
.saltCarouselSlides-container {
|
|
90
106
|
display: flex;
|
|
91
107
|
touch-action: pan-y pinch-zoom;
|
|
92
108
|
margin-left: calc(var(--carousel-slide-spacing) * -1);
|
|
93
109
|
}
|
|
110
|
+
.saltCarouselSlides-sr-only {
|
|
111
|
+
position: absolute;
|
|
112
|
+
height: 1px;
|
|
113
|
+
width: 1px;
|
|
114
|
+
padding: 0;
|
|
115
|
+
margin: -1px;
|
|
116
|
+
overflow: hidden;
|
|
117
|
+
clip: rect(0, 0, 0, 0);
|
|
118
|
+
white-space: nowrap;
|
|
119
|
+
border-width: 0;
|
|
120
|
+
}
|
|
121
|
+
.saltCarouselSlides-dragging {
|
|
122
|
+
cursor: var(--salt-cursor-grab-active);
|
|
123
|
+
}
|
|
94
124
|
|
|
95
125
|
/* src/CarouselTab.css */
|
|
96
126
|
.saltCarouselTab {
|
|
@@ -126,12 +156,8 @@
|
|
|
126
156
|
transform: translate(-50%, -50%);
|
|
127
157
|
}
|
|
128
158
|
.saltCarouselTab:focus-visible {
|
|
129
|
-
outline
|
|
130
|
-
outline-
|
|
131
|
-
outline-color: var(--salt-focused-outlineColor);
|
|
132
|
-
outline-offset: var(--salt-focused-outlineOffset);
|
|
133
|
-
background: var(--salt-selectable-background-hover);
|
|
134
|
-
border-color: var(--salt-selectable-borderColor-hover);
|
|
159
|
+
outline: var(--saltRadioButton-outline, var(--salt-focused-outline));
|
|
160
|
+
outline-offset: var(--salt-spacing-fixed-100);
|
|
135
161
|
}
|
|
136
162
|
.saltCarouselTab-selected {
|
|
137
163
|
box-shadow: inset 0 0 0 var(--salt-size-selectable) var(--salt-selectable-borderColor-selected);
|
|
@@ -145,11 +171,5 @@
|
|
|
145
171
|
align-items: center;
|
|
146
172
|
gap: var(--salt-spacing-200);
|
|
147
173
|
}
|
|
148
|
-
.saltCarouselTabList:focus-visible {
|
|
149
|
-
outline-style: var(--salt-focused-outlineStyle);
|
|
150
|
-
outline-width: var(--salt-focused-outlineWidth);
|
|
151
|
-
outline-offset: var(--salt-focused-outlineOffset);
|
|
152
|
-
outline-color: var(--salt-focused-outlineColor);
|
|
153
|
-
}
|
|
154
174
|
|
|
155
|
-
/* src/
|
|
175
|
+
/* src/28b4a5f8-340b-4ae4-bd4b-182f53df6997.css */
|
package/dist-cjs/Carousel.js
CHANGED
|
@@ -15,9 +15,11 @@ const Carousel = react.forwardRef(
|
|
|
15
15
|
function Carousel2({
|
|
16
16
|
children,
|
|
17
17
|
className,
|
|
18
|
+
disableSlideAnnouncements,
|
|
18
19
|
emblaOptions = {},
|
|
19
20
|
emblaPlugins = [],
|
|
20
21
|
getEmblaApi,
|
|
22
|
+
id,
|
|
21
23
|
...rest
|
|
22
24
|
}, ref) {
|
|
23
25
|
const targetWindow = window.useWindow();
|
|
@@ -29,23 +31,42 @@ const Carousel = react.forwardRef(
|
|
|
29
31
|
const [emblaRef, emblaApi] = useEmblaCarousel(emblaOptions, [
|
|
30
32
|
...emblaPlugins
|
|
31
33
|
]);
|
|
34
|
+
const carouselId = core.useId(id);
|
|
32
35
|
react.useEffect(() => {
|
|
33
36
|
if (emblaApi) {
|
|
34
37
|
getEmblaApi == null ? void 0 : getEmblaApi(emblaApi);
|
|
35
38
|
}
|
|
36
39
|
return void 0;
|
|
37
40
|
}, [emblaApi]);
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
const [ariaVariant, setAriaVariant] = react.useState("group");
|
|
42
|
+
const [announcementState, setAnnouncementState] = react.useState(void 0);
|
|
43
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
44
|
+
CarouselContext.CarouselContext.Provider,
|
|
40
45
|
{
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
value: {
|
|
47
|
+
ariaVariant,
|
|
48
|
+
disableSlideAnnouncements,
|
|
49
|
+
emblaApi,
|
|
50
|
+
emblaRef,
|
|
51
|
+
setAriaVariant,
|
|
52
|
+
announcementState,
|
|
53
|
+
setAnnouncementState,
|
|
54
|
+
carouselId
|
|
55
|
+
},
|
|
56
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
57
|
+
"section",
|
|
58
|
+
{
|
|
59
|
+
"aria-roledescription": "carousel",
|
|
60
|
+
role: "region",
|
|
61
|
+
className: clsx.clsx(withBaseName(), className),
|
|
62
|
+
ref,
|
|
63
|
+
...rest,
|
|
64
|
+
children
|
|
65
|
+
},
|
|
66
|
+
`carousel-${ariaVariant}}`
|
|
67
|
+
)
|
|
47
68
|
}
|
|
48
|
-
)
|
|
69
|
+
);
|
|
49
70
|
}
|
|
50
71
|
);
|
|
51
72
|
|
package/dist-cjs/Carousel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Carousel.js","sources":["../src/Carousel.tsx"],"sourcesContent":["import { makePrefixer } from \"@salt-ds/core\";\nimport { useComponentCssInjection } from \"@salt-ds/styles\";\nimport { useWindow } from \"@salt-ds/window\";\nimport { clsx } from \"clsx\";\nimport useEmblaCarousel, {\n type UseEmblaCarouselType,\n} from \"embla-carousel-react\";\nimport {
|
|
1
|
+
{"version":3,"file":"Carousel.js","sources":["../src/Carousel.tsx"],"sourcesContent":["import { makePrefixer, useId } from \"@salt-ds/core\";\nimport { useComponentCssInjection } from \"@salt-ds/styles\";\nimport { useWindow } from \"@salt-ds/window\";\nimport { clsx } from \"clsx\";\nimport useEmblaCarousel, {\n type UseEmblaCarouselType,\n} from \"embla-carousel-react\";\nimport {\n type ComponentPropsWithoutRef,\n forwardRef,\n useEffect,\n useState,\n} from \"react\";\nimport carouselCss from \"./Carousel.css\";\nimport {\n type CarouselAnnouncementTrigger,\n type CarouselAriaVariant,\n CarouselContext,\n} from \"./CarouselContext\";\n\nconst withBaseName = makePrefixer(\"saltCarousel\");\n\nexport type CarouselEmblaRefType = UseEmblaCarouselType[0];\nexport type CarouselEmblaApiType = UseEmblaCarouselType[1];\n\ntype UseCarouselParameters = Parameters<typeof useEmblaCarousel>;\nexport type CarouselOptions = UseCarouselParameters[0];\nexport type CarouselPlugin = UseCarouselParameters[1];\n\n/**\n * Props for the Carousel component.\n * Pass a ref to the carousel to get it to return a reference to the embla API\n */\nexport interface CarouselProps extends ComponentPropsWithoutRef<\"section\"> {\n /**\n * Options to configure the Embla Carousel.\n * These options are passed directly to the Embla Carousel instance.\n */\n emblaOptions?: CarouselOptions;\n\n /**\n * Plugins to enhance the functionality of the Embla Carousel.\n * These options are passed directly to the Embla Carousel instance.\n */\n emblaPlugins?: CarouselPlugin;\n /**\n * Get embla API instance, use this to manage the state of the Carousel\n **/\n getEmblaApi?: (embla: CarouselEmblaApiType) => void;\n /**\n * Disable screenreader announcing slide updates, defaults to false.\n */\n disableSlideAnnouncements?: boolean;\n}\n\nexport const Carousel = forwardRef<HTMLElement, CarouselProps>(\n function Carousel(\n {\n children,\n className,\n disableSlideAnnouncements,\n emblaOptions = {},\n emblaPlugins = [],\n getEmblaApi,\n id,\n ...rest\n },\n ref,\n ) {\n const targetWindow = useWindow();\n useComponentCssInjection({\n testId: \"salt-carousel\",\n css: carouselCss,\n window: targetWindow,\n });\n\n const [emblaRef, emblaApi] = useEmblaCarousel(emblaOptions, [\n ...emblaPlugins,\n ]);\n\n const carouselId = useId(id);\n\n useEffect(() => {\n if (emblaApi) {\n getEmblaApi?.(emblaApi);\n }\n return undefined;\n }, [emblaApi]);\n\n const [ariaVariant, setAriaVariant] =\n useState<CarouselAriaVariant>(\"group\");\n const [announcementState, setAnnouncementState] = useState<\n CarouselAnnouncementTrigger | undefined\n >(undefined);\n\n return (\n <CarouselContext.Provider\n value={{\n ariaVariant,\n disableSlideAnnouncements,\n emblaApi,\n emblaRef,\n setAriaVariant,\n announcementState,\n setAnnouncementState,\n carouselId,\n }}\n >\n <section\n key={`carousel-${ariaVariant}}`}\n aria-roledescription=\"carousel\"\n role=\"region\"\n className={clsx(withBaseName(), className)}\n ref={ref}\n {...rest}\n >\n {children}\n </section>\n </CarouselContext.Provider>\n );\n },\n);\n"],"names":["makePrefixer","forwardRef","Carousel","useWindow","useComponentCssInjection","carouselCss","useId","useEffect","useState","jsx","CarouselContext","clsx"],"mappings":";;;;;;;;;;;;AAoBA,MAAM,YAAA,GAAeA,kBAAa,cAAc,CAAA;AAmCzC,MAAM,QAAA,GAAWC,gBAAA;AAAA,EACtB,SAASC,SAAAA,CACP;AAAA,IACE,QAAA;AAAA,IACA,SAAA;AAAA,IACA,yBAAA;AAAA,IACA,eAAe,EAAC;AAAA,IAChB,eAAe,EAAC;AAAA,IAChB,WAAA;AAAA,IACA,EAAA;AAAA,IACA,GAAG;AAAA,KAEL,GAAA,EACA;AACA,IAAA,MAAM,eAAeC,gBAAA,EAAU;AAC/B,IAAAC,+BAAA,CAAyB;AAAA,MACvB,MAAA,EAAQ,eAAA;AAAA,MACR,GAAA,EAAKC,UAAA;AAAA,MACL,MAAA,EAAQ;AAAA,KACT,CAAA;AAED,IAAA,MAAM,CAAC,QAAA,EAAU,QAAQ,CAAA,GAAI,iBAAiB,YAAA,EAAc;AAAA,MAC1D,GAAG;AAAA,KACJ,CAAA;AAED,IAAA,MAAM,UAAA,GAAaC,WAAM,EAAE,CAAA;AAE3B,IAAAC,eAAA,CAAU,MAAM;AACd,MAAA,IAAI,QAAA,EAAU;AACZ,QAAA,WAAA,IAAA,IAAA,GAAA,MAAA,GAAA,WAAA,CAAc,QAAA,CAAA;AAAA,MAChB;AACA,MAAA,OAAO,MAAA;AAAA,IACT,CAAA,EAAG,CAAC,QAAQ,CAAC,CAAA;AAEb,IAAA,MAAM,CAAC,WAAA,EAAa,cAAc,CAAA,GAChCC,eAA8B,OAAO,CAAA;AACvC,IAAA,MAAM,CAAC,iBAAA,EAAmB,oBAAoB,CAAA,GAAIA,eAEhD,MAAS,CAAA;AAEX,IAAA,uBACEC,cAAA;AAAA,MAACC,+BAAA,CAAgB,QAAA;AAAA,MAAhB;AAAA,QACC,KAAA,EAAO;AAAA,UACL,WAAA;AAAA,UACA,yBAAA;AAAA,UACA,QAAA;AAAA,UACA,QAAA;AAAA,UACA,cAAA;AAAA,UACA,iBAAA;AAAA,UACA,oBAAA;AAAA,UACA;AAAA,SACF;AAAA,QAEA,QAAA,kBAAAD,cAAA;AAAA,UAAC,SAAA;AAAA,UAAA;AAAA,YAEC,sBAAA,EAAqB,UAAA;AAAA,YACrB,IAAA,EAAK,QAAA;AAAA,YACL,SAAA,EAAWE,SAAA,CAAK,YAAA,EAAa,EAAG,SAAS,CAAA;AAAA,YACzC,GAAA;AAAA,YACC,GAAG,IAAA;AAAA,YAEH;AAAA,WAAA;AAAA,UAPI,YAAY,WAAW,CAAA,CAAA;AAAA;AAQ9B;AAAA,KACF;AAAA,EAEJ;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CarouselAutoplayIndicator.js","sources":["../src/CarouselAutoplayIndicator.tsx"],"sourcesContent":["import { makePrefixer, useDensity } from \"@salt-ds/core\";\nimport { useComponentCssInjection } from \"@salt-ds/styles\";\nimport { useWindow } from \"@salt-ds/window\";\nimport { clsx } from \"clsx\";\nimport {\n type ComponentPropsWithoutRef,\n type CSSProperties,\n forwardRef,\n useEffect,\n useRef,\n} from \"react\";\nimport carouselAutoplayIndicator from \"./CarouselAutoplayIndicator.css\";\nimport { CarouselAutoplayIndicatorSVG } from \"./CarouselAutoplayIndicatorSVG\";\n\nexport interface CarouselAutoplayIndicatorProps\n extends ComponentPropsWithoutRef<\"div\"> {\n /**\n * Duration of each slide in milliseconds.\n */\n duration: number;\n /**\n * Index of slide currently displayed.\n */\n slideIndex: number;\n /**\n * If `true`, the indicator is animated to visualize the time until the next slide.\n */\n isPlaying: boolean;\n /**\n * If `true`, the animation is paused.\n */\n isPaused?: boolean;\n}\n\nconst withBaseName = makePrefixer(\"saltCarouselAutoplayIndicator\");\n\nconst sizeAndStrokeWidthMapping = {\n high: { size: 10, strokeWidth: 2 },\n medium: { size: 12, strokeWidth: 2 },\n low: { size: 14, strokeWidth: 2 },\n touch: { size: 16, strokeWidth: 2 },\n};\n\nexport const CarouselAutoplayIndicator = forwardRef<\n HTMLDivElement,\n CarouselAutoplayIndicatorProps\n>(\n (\n {\n className,\n duration,\n slideIndex,\n isPlaying,\n isPaused = false,\n children,\n ...props\n },\n ref,\n ) => {\n const targetWindow = useWindow();\n useComponentCssInjection({\n testId: \"salt-carousel-autoplay-indicator\",\n css: carouselAutoplayIndicator,\n window: targetWindow,\n });\n\n const barRef = useRef<SVGCircleElement>(null);\n const animationFrameId = useRef<number | null>(null);\n\n const density = useDensity();\n const { size, strokeWidth } = sizeAndStrokeWidthMapping[density];\n const radius = (size - strokeWidth) / 2;\n const circumference = 2 * Math.PI * radius;\n\n useEffect(() => {\n if (barRef.current) {\n animationFrameId.current = requestAnimationFrame(() => {\n if (!barRef.current) {\n return;\n }\n barRef.current.style.animation = \"none\"; // Reset animation\n barRef.current.style.strokeDashoffset = `${circumference}`;\n animationFrameId.current = requestAnimationFrame(() => {\n if (!barRef.current) {\n return;\n }\n barRef.current.style.animation = `indicatorAnimation ${duration}ms linear`;\n barRef.current.style.animationPlayState = isPaused\n ? \"paused\"\n : isPlaying\n ? \"running\"\n : \"paused\";\n });\n });\n }\n\n return () => {\n if (animationFrameId.current !== null) {\n cancelAnimationFrame(animationFrameId.current);\n animationFrameId.current = null;\n }\n };\n }, [circumference, duration, slideIndex, isPlaying, isPaused]);\n\n return (\n <div\n ref={ref}\n style={\n {\n width: size,\n height: size,\n \"--carousel-svg-circumference\": circumference,\n } as CSSProperties\n }\n className={clsx(withBaseName(), className)}\n {...props}\n >\n <CarouselAutoplayIndicatorSVG\n size={size}\n strokeWidth={strokeWidth}\n barRef={barRef}\n radius={radius}\n />\n </div>\n );\n },\n);\n"],"names":["makePrefixer","forwardRef","useWindow","useComponentCssInjection","carouselAutoplayIndicator","useRef","useDensity","useEffect","jsx","clsx","CarouselAutoplayIndicatorSVG"],"mappings":";;;;;;;;;;;AAkCA,MAAM,YAAA,GAAeA,kBAAa,+BAA+B,CAAA;AAEjE,MAAM,
|
|
1
|
+
{"version":3,"file":"CarouselAutoplayIndicator.js","sources":["../src/CarouselAutoplayIndicator.tsx"],"sourcesContent":["import { makePrefixer, useDensity } from \"@salt-ds/core\";\nimport { useComponentCssInjection } from \"@salt-ds/styles\";\nimport { useWindow } from \"@salt-ds/window\";\nimport { clsx } from \"clsx\";\nimport {\n type ComponentPropsWithoutRef,\n type CSSProperties,\n forwardRef,\n useEffect,\n useRef,\n} from \"react\";\nimport carouselAutoplayIndicator from \"./CarouselAutoplayIndicator.css\";\nimport { CarouselAutoplayIndicatorSVG } from \"./CarouselAutoplayIndicatorSVG\";\n\nexport interface CarouselAutoplayIndicatorProps\n extends ComponentPropsWithoutRef<\"div\"> {\n /**\n * Duration of each slide in milliseconds.\n */\n duration: number;\n /**\n * Index of slide currently displayed.\n */\n slideIndex: number;\n /**\n * If `true`, the indicator is animated to visualize the time until the next slide.\n */\n isPlaying: boolean;\n /**\n * If `true`, the animation is paused.\n */\n isPaused?: boolean;\n}\n\nconst withBaseName = makePrefixer(\"saltCarouselAutoplayIndicator\");\n\nconst sizeAndStrokeWidthMapping = {\n high: { size: 10, strokeWidth: 2 },\n medium: { size: 12, strokeWidth: 2 },\n low: { size: 14, strokeWidth: 2 },\n touch: { size: 16, strokeWidth: 2 },\n};\n\nexport const CarouselAutoplayIndicator = forwardRef<\n HTMLDivElement,\n CarouselAutoplayIndicatorProps\n>(\n (\n {\n className,\n duration,\n slideIndex,\n isPlaying,\n isPaused = false,\n children,\n ...props\n },\n ref,\n ) => {\n const targetWindow = useWindow();\n useComponentCssInjection({\n testId: \"salt-carousel-autoplay-indicator\",\n css: carouselAutoplayIndicator,\n window: targetWindow,\n });\n\n const barRef = useRef<SVGCircleElement>(null);\n const animationFrameId = useRef<number | null>(null);\n\n const density = useDensity();\n const { size, strokeWidth } = sizeAndStrokeWidthMapping[density];\n const radius = (size - strokeWidth) / 2;\n const circumference = 2 * Math.PI * radius;\n\n useEffect(() => {\n if (barRef.current) {\n animationFrameId.current = requestAnimationFrame(() => {\n if (!barRef.current) {\n return;\n }\n barRef.current.style.animation = \"none\"; // Reset animation\n barRef.current.style.strokeDashoffset = `${circumference}`;\n animationFrameId.current = requestAnimationFrame(() => {\n if (!barRef.current) {\n return;\n }\n barRef.current.style.animation = `indicatorAnimation ${duration}ms linear`;\n barRef.current.style.animationPlayState = isPaused\n ? \"paused\"\n : isPlaying\n ? \"running\"\n : \"paused\";\n });\n });\n }\n\n return () => {\n if (animationFrameId.current !== null) {\n cancelAnimationFrame(animationFrameId.current);\n animationFrameId.current = null;\n }\n };\n }, [circumference, duration, slideIndex, isPlaying, isPaused]);\n\n return (\n <div\n ref={ref}\n style={\n {\n width: size,\n height: size,\n \"--carousel-svg-circumference\": circumference,\n } as CSSProperties\n }\n className={clsx(withBaseName(), className)}\n {...props}\n >\n <CarouselAutoplayIndicatorSVG\n size={size}\n strokeWidth={strokeWidth}\n barRef={barRef}\n radius={radius}\n />\n </div>\n );\n },\n);\n"],"names":["makePrefixer","forwardRef","useWindow","useComponentCssInjection","carouselAutoplayIndic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AEJ,QAAA,kBAAAD,cAAA;AAAA,UAACE,yDAAA;AAAA,UAAA;AAAA,YACC,IAAA;AAAA,YACA,WAAA;AAAA,YACA,MAAA;AAAA,YACA;AAAA;AAAA;AACF;AAAA,KACF;AAAA,EAEJ;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CarouselAutoplayIndicatorSVG.js","sources":["../src/CarouselAutoplayIndicatorSVG.tsx"],"sourcesContent":["import { makePrefixer } from \"@salt-ds/core\";\nimport { clsx } from \"clsx\";\nimport { forwardRef, type Ref, type SVGAttributes } from \"react\";\n\nconst withBaseName = makePrefixer(\"saltCarouselAutoplayIndicatorSVG\");\n\nexport interface CarouselAutoplayIndicatorSVGProps\n extends SVGAttributes<SVGSVGElement> {\n /**\n * Class name to apply to the SVG element.\n */\n className?: string;\n /**\n * Ref to attach to progress indicator element\n */\n barRef: Ref<SVGCircleElement>;\n /**\n * Size of the SVG in pixels.\n */\n size: number;\n /**\n * Stroke width of the progress indicator in pixels.\n */\n strokeWidth: number;\n /**\n * Radius of the progress indicator circle.\n */\n radius: number;\n}\n\nexport const CarouselAutoplayIndicatorSVG = forwardRef<\n SVGSVGElement,\n CarouselAutoplayIndicatorSVGProps\n>(\n (\n {\n barRef,\n className,\n radius,\n size,\n strokeWidth,\n }: CarouselAutoplayIndicatorSVGProps,\n ref,\n ) => {\n return (\n <svg\n className={clsx(withBaseName(), className)}\n width={size}\n height={size}\n aria-hidden\n ref={ref}\n >\n <circle\n className={withBaseName(\"track\")}\n cx={size / 2}\n cy={size / 2}\n r={radius}\n strokeWidth={strokeWidth}\n />\n <circle\n ref={barRef}\n className={withBaseName(\"bar\")}\n cx={size / 2}\n cy={size / 2}\n r={radius}\n strokeWidth={strokeWidth}\n />\n </svg>\n );\n },\n);\n"],"names":["makePrefixer","forwardRef","jsxs","clsx","jsx"],"mappings":";;;;;;;AAIA,MAAM,YAAA,GAAeA,kBAAa,kCAAkC,CAAA;AA0B7D,MAAM,
|
|
1
|
+
{"version":3,"file":"CarouselAutoplayIndicatorSVG.js","sources":["../src/CarouselAutoplayIndicatorSVG.tsx"],"sourcesContent":["import { makePrefixer } from \"@salt-ds/core\";\nimport { clsx } from \"clsx\";\nimport { forwardRef, type Ref, type SVGAttributes } from \"react\";\n\nconst withBaseName = makePrefixer(\"saltCarouselAutoplayIndicatorSVG\");\n\nexport interface CarouselAutoplayIndicatorSVGProps\n extends SVGAttributes<SVGSVGElement> {\n /**\n * Class name to apply to the SVG element.\n */\n className?: string;\n /**\n * Ref to attach to progress indicator element\n */\n barRef: Ref<SVGCircleElement>;\n /**\n * Size of the SVG in pixels.\n */\n size: number;\n /**\n * Stroke width of the progress indicator in pixels.\n */\n strokeWidth: number;\n /**\n * Radius of the progress indicator circle.\n */\n radius: number;\n}\n\nexport const CarouselAutoplayIndicatorSVG = forwardRef<\n SVGSVGElement,\n CarouselAutoplayIndicatorSVGProps\n>(\n (\n {\n barRef,\n className,\n radius,\n size,\n strokeWidth,\n }: CarouselAutoplayIndicatorSVGProps,\n ref,\n ) => {\n return (\n <svg\n className={clsx(withBaseName(), className)}\n width={size}\n height={size}\n aria-hidden\n ref={ref}\n >\n <circle\n className={withBaseName(\"track\")}\n cx={size / 2}\n cy={size / 2}\n r={radius}\n strokeWidth={strokeWidth}\n />\n <circle\n ref={barRef}\n className={withBaseName(\"bar\")}\n cx={size / 2}\n cy={size / 2}\n r={radius}\n strokeWidth={strokeWidth}\n />\n </svg>\n );\n },\n);\n"],"names":["makePrefixer","forwardRef","jsxs","clsx","jsx"],"mappings":";;;;;;;AAIA,MAAM,YAAA,GAAeA,kBAAa,kCAAkC,CAAA;AA0B7D,MAAM,4BAAA,GAA+BC,gBAAA;AAAA,EAI1C,CACE;AAAA,IACE,MAAA;AAAA,IACA,SAAA;AAAA,IACA,MAAA;AAAA,IACA,IAAA;AAAA,IACA;AAAA,KAEF,GAAA,KACG;AACH,IAAA,uBACEC,eAAA;AAAA,MAAC,KAAA;AAAA,MAAA;AAAA,QACC,SAAA,EAAWC,SAAA,CAAK,YAAA,EAAa,EAAG,SAAS,CAAA;AAAA,QACzC,KAAA,EAAO,IAAA;AAAA,QACP,MAAA,EAAQ,IAAA;AAAA,QACR,aAAA,EAAW,IAAA;AAAA,QACX,GAAA;AAAA,QAEA,QAAA,EAAA;AAAA,0BAAAC,cAAA;AAAA,YAAC,QAAA;AAAA,YAAA;AAAA,cACC,SAAA,EAAW,aAAa,OAAO,CAAA;AAAA,cAC/B,IAAI,IAAA,GAAO,CAAA;AAAA,cACX,IAAI,IAAA,GAAO,CAAA;AAAA,cACX,CAAA,EAAG,MAAA;AAAA,cACH;AAAA;AAAA,WACF;AAAA,0BACAA,cAAA;AAAA,YAAC,QAAA;AAAA,YAAA;AAAA,cACC,GAAA,EAAK,MAAA;AAAA,cACL,SAAA,EAAW,aAAa,KAAK,CAAA;AAAA,cAC7B,IAAI,IAAA,GAAO,CAAA;AAAA,cACX,IAAI,IAAA,GAAO,CAAA;AAAA,cACX,CAAA,EAAG,MAAA;AAAA,cACH;AAAA;AAAA;AACF;AAAA;AAAA,KACF;AAAA,EAEJ;AACF;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var css_248z = ".saltCarouselCard {\n display: flex;\n transform: translate3d(0, 0, 0);\n flex: 0 0 var(--carousel-slide-size);\n min-width: 0;\n padding-left: var(--carousel-slide-spacing);\n box-sizing: border-box;\n}\n\n.saltCarouselCard-content {\n display: flex;\n user-select: none;\n overflow: hidden;\n flex-direction: column;\n gap: var(--salt-spacing-200);\n flex-grow: 1;\n}\n\n.saltCarouselCard-body {\n display: flex;\n overflow: hidden;\n flex-direction: column;\n
|
|
3
|
+
var css_248z = ".saltCarouselCard {\n display: flex;\n transform: translate3d(0, 0, 0);\n flex: 0 0 var(--carousel-slide-size);\n min-width: 0;\n padding-left: var(--carousel-slide-spacing);\n box-sizing: border-box;\n}\n\n.saltCarouselCard-content {\n display: flex;\n user-select: none;\n overflow: hidden;\n flex-direction: column;\n gap: var(--salt-spacing-200);\n flex-grow: 1;\n}\n\n.saltCarouselCard:focus-visible {\n outline: none;\n}\n\n.saltCarouselCard:focus-visible::after {\n content: \"\";\n position: absolute;\n top: 0;\n bottom: 0;\n left: var(--carousel-slide-spacing);\n right: 0;\n outline: var(--salt-focused-outline);\n outline-offset: calc(var(--salt-focused-outlineWidth) * -1);\n cursor: var(--salt-cursor-hover);\n border-radius: var(--salt-palette-corner, 0);\n}\n\n.saltCarouselCard-body {\n display: flex;\n overflow: hidden;\n flex-direction: column;\n flex-grow: 1;\n padding-bottom: var(--salt-spacing-200);\n}\n\n.saltCarouselCard-header {\n padding-bottom: var(--salt-spacing-100);\n}\n.saltCarouselCard-actions {\n padding-top: var(--salt-spacing-200);\n}\n\n.saltCarouselCard-body.saltCarouselCard-bordered-body {\n padding: 0 var(--salt-spacing-200) var(--salt-spacing-200) var(--salt-spacing-200);\n}\n\n.saltCarouselCard-content h2,\n.saltCarouselCard-content h3 {\n margin: 0;\n}\n\n.saltCarouselCard-bordered {\n background: var(--salt-container-primary-background);\n border: var(--salt-size-fixed-100) var(--salt-container-borderStyle) var(--salt-container-primary-borderColor);\n border-radius: var(--salt-palette-corner, 0);\n}\n";
|
|
4
4
|
|
|
5
5
|
module.exports = css_248z;
|
|
6
6
|
//# sourceMappingURL=CarouselCard.css.js.map
|
package/dist-cjs/CarouselCard.js
CHANGED
|
@@ -7,6 +7,7 @@ var window = require('@salt-ds/window');
|
|
|
7
7
|
var clsx = require('clsx');
|
|
8
8
|
var react = require('react');
|
|
9
9
|
var CarouselCard$1 = require('./CarouselCard.css.js');
|
|
10
|
+
var CarouselContext = require('./CarouselContext.js');
|
|
10
11
|
|
|
11
12
|
const withBaseName = core.makePrefixer("saltCarouselCard");
|
|
12
13
|
const CarouselCard = react.forwardRef(
|
|
@@ -17,14 +18,15 @@ const CarouselCard = react.forwardRef(
|
|
|
17
18
|
css: CarouselCard$1,
|
|
18
19
|
window: targetWindow
|
|
19
20
|
});
|
|
21
|
+
const { ariaVariant } = CarouselContext.useCarouselContext();
|
|
20
22
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
21
23
|
"div",
|
|
22
24
|
{
|
|
23
|
-
role: "tabpanel",
|
|
24
25
|
"aria-roledescription": "slide",
|
|
25
|
-
className: clsx.clsx(withBaseName(), className),
|
|
26
|
-
...rest,
|
|
26
|
+
className: clsx.clsx([withBaseName(), className]),
|
|
27
27
|
ref,
|
|
28
|
+
role: ariaVariant,
|
|
29
|
+
...rest,
|
|
28
30
|
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
29
31
|
"div",
|
|
30
32
|
{
|
|
@@ -33,11 +35,19 @@ const CarouselCard = react.forwardRef(
|
|
|
33
35
|
}),
|
|
34
36
|
children: [
|
|
35
37
|
media,
|
|
36
|
-
children && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
children && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
39
|
+
"div",
|
|
40
|
+
{
|
|
41
|
+
className: clsx.clsx(withBaseName("body"), {
|
|
42
|
+
[withBaseName("bordered-body")]: appearance === "bordered"
|
|
43
|
+
}),
|
|
44
|
+
children: [
|
|
45
|
+
header ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: withBaseName("header"), children: header }) : null,
|
|
46
|
+
children,
|
|
47
|
+
actions ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: withBaseName("actions"), children: actions }) : null
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
)
|
|
41
51
|
]
|
|
42
52
|
}
|
|
43
53
|
)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CarouselCard.js","sources":["../src/CarouselCard.tsx"],"sourcesContent":["import { makePrefixer } from \"@salt-ds/core\";\nimport { useComponentCssInjection } from \"@salt-ds/styles\";\nimport { useWindow } from \"@salt-ds/window\";\nimport { clsx } from \"clsx\";\nimport { type ComponentProps, forwardRef, type ReactNode } from \"react\";\nimport saltCarouselCardCss from \"./CarouselCard.css\";\n\nconst withBaseName = makePrefixer(\"saltCarouselCard\");\n\n/**\n * Props for the CarouselCard component.\n */\nexport interface CarouselCardProps extends ComponentProps<\"div\"> {\n /**\n * Actions to be displayed in the content footer.\n * This can include buttons or any other interactive elements.\n */\n actions?: ReactNode;\n\n /**\n * Media content to be displayed inside the slide.\n * This could include images, videos, etc., that are visually prominent.\n * It differs from children in that media is intended to be the main visual element of the slide.\n */\n media?: ReactNode;\n\n /**\n * The appearance of the slide. Options are 'bordered', and 'transparent'.\n * 'transparent' is the default value.\n **/\n appearance?: \"bordered\" | \"transparent\";\n\n /**\n * Header content to be displayed at the top of the slide.\n * This can be text or any other React node.\n */\n header?: ReactNode;\n\n /**\n * Carousel slide id.\n * This can be used to uniquely identify the slide.\n */\n id?: string;\n}\n\nexport const CarouselCard = forwardRef<HTMLDivElement, CarouselCardProps>(\n function CarouselCard(\n { actions, appearance, children, className, header, media, ...rest },\n ref,\n ) {\n const targetWindow = useWindow();\n useComponentCssInjection({\n testId: \"salt-carousel-card\",\n css: saltCarouselCardCss,\n window: targetWindow,\n });\n\n return (\n <div\n
|
|
1
|
+
{"version":3,"file":"CarouselCard.js","sources":["../src/CarouselCard.tsx"],"sourcesContent":["import { makePrefixer } from \"@salt-ds/core\";\nimport { useComponentCssInjection } from \"@salt-ds/styles\";\nimport { useWindow } from \"@salt-ds/window\";\nimport { clsx } from \"clsx\";\nimport { type ComponentProps, forwardRef, type ReactNode } from \"react\";\nimport saltCarouselCardCss from \"./CarouselCard.css\";\nimport { useCarouselContext } from \"./CarouselContext\";\n\nconst withBaseName = makePrefixer(\"saltCarouselCard\");\n\n/**\n * Props for the CarouselCard component.\n */\nexport interface CarouselCardProps extends ComponentProps<\"div\"> {\n /**\n * Actions to be displayed in the content footer.\n * This can include buttons or any other interactive elements.\n */\n actions?: ReactNode;\n\n /**\n * Media content to be displayed inside the slide.\n * This could include images, videos, etc., that are visually prominent.\n * It differs from children in that media is intended to be the main visual element of the slide.\n */\n media?: ReactNode;\n\n /**\n * The appearance of the slide. Options are 'bordered', and 'transparent'.\n * 'transparent' is the default value.\n **/\n appearance?: \"bordered\" | \"transparent\";\n\n /**\n * Header content to be displayed at the top of the slide.\n * This can be text or any other React node.\n */\n header?: ReactNode;\n\n /**\n * Carousel slide id.\n * This can be used to uniquely identify the slide.\n */\n id?: string;\n}\n\nexport const CarouselCard = forwardRef<HTMLDivElement, CarouselCardProps>(\n function CarouselCard(\n { actions, appearance, children, className, header, media, ...rest },\n ref,\n ) {\n const targetWindow = useWindow();\n useComponentCssInjection({\n testId: \"salt-carousel-card\",\n css: saltCarouselCardCss,\n window: targetWindow,\n });\n\n const { ariaVariant } = useCarouselContext();\n\n return (\n <div\n aria-roledescription=\"slide\"\n className={clsx([withBaseName(), className])}\n ref={ref}\n role={ariaVariant}\n {...rest}\n >\n <div\n className={clsx(withBaseName(\"content\"), {\n [withBaseName(\"bordered\")]: appearance === \"bordered\",\n })}\n >\n {media}\n {children && (\n <div\n className={clsx(withBaseName(\"body\"), {\n [withBaseName(\"bordered-body\")]: appearance === \"bordered\",\n })}\n >\n {header ? (\n <div className={withBaseName(\"header\")}>{header}</div>\n ) : null}\n {children}\n {actions ? (\n <div className={withBaseName(\"actions\")}>{actions}</div>\n ) : null}\n </div>\n )}\n </div>\n </div>\n );\n },\n);\n"],"names":["makePrefixer","forwardRef","CarouselCard","useWindow","useComponentCssInjection","saltCarouselCardCss","useCarouselContext","jsx","clsx","jsxs"],"mappings":";;;;;;;;;;;AAQA,MAAM,YAAA,GAAeA,kBAAa,kBAAkB,CAAA;AAsC7C,MAAM,YAAA,GAAeC,gBAAA;AAAA,EAC1B,SAASC,aAAAA,CACP,EAAE,OAAA,EAAS,UAAA,EAAY,QAAA,EAAU,SAAA,EAAW,MAAA,EAAQ,KAAA,EAAO,GAAG,IAAA,EAAK,EACnE,GAAA,EAC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AEJ;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CarouselContext.js","sources":["../src/CarouselContext.tsx"],"sourcesContent":["import { createContext } from \"@salt-ds/core\";\nimport { useContext } from \"react\";\nimport type { CarouselEmblaApiType, CarouselEmblaRefType } from \"./Carousel\";\n\n/**\n * Type definition for the Carousel context.\n * Provides access to the Embla Carousel API and reference.\n */\ninterface CarouselContextType {\n /**\n * The API instance of the Embla Carousel.\n * Provides methods to control the carousel programmatically.\n */\n emblaApi?: CarouselEmblaApiType;\n\n /**\n * The reference to the Embla Carousel viewport.\n * Used to directly interact with the carousel DOM element.\n */\n emblaRef?: CarouselEmblaRefType;\n}\n\nexport const CarouselContext = createContext<CarouselContextType | undefined>(\n \"CarouselContext\",\n undefined,\n);\n\nexport const useCarouselContext = (): CarouselContextType => {\n const context = useContext(CarouselContext);\n if (!context) {\n throw new Error(\n \"useCarouselContext must be used within a CarouselProvider\",\n );\n }\n return context;\n};\n"],"names":["createContext","useContext"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"CarouselContext.js","sources":["../src/CarouselContext.tsx"],"sourcesContent":["import { createContext } from \"@salt-ds/core\";\nimport { type Dispatch, type SetStateAction, useContext } from \"react\";\nimport type { CarouselEmblaApiType, CarouselEmblaRefType } from \"./Carousel\";\n\nexport type CarouselAriaVariant = \"group\" | \"tabpanel\";\n\nexport type CarouselAnnouncementTrigger =\n | \"tab\"\n | \"navigation\"\n | \"drag\"\n | \"focus\";\n\n/**\n * Type definition for the Carousel context.\n * Provides access to the Embla Carousel API and reference.\n */\ninterface CarouselContextType {\n /**\n * The API instance of the Embla Carousel.\n * Provides methods to control the carousel programmatically.\n */\n emblaApi?: CarouselEmblaApiType;\n\n /**\n * The reference to the Embla Carousel viewport.\n * Used to directly interact with the carousel DOM element.\n */\n emblaRef?: CarouselEmblaRefType;\n /**\n * Aria variant for the Carousel.\n * When used with a `CarouselTabList` the screenreader will be presented as a `tablist` of tabpanels.\n * When used without a `CarouselTabList` the screenreader will be presented as a `group` of slides.\n */\n ariaVariant: CarouselAriaVariant;\n /**\n * Function to set the aria variant for the Carousel.\n */\n setAriaVariant: Dispatch<SetStateAction<CarouselAriaVariant>>;\n /**\n * Disable screenreader announcing slide updates, defaults to false.\n */\n disableSlideAnnouncements?: boolean;\n /**\n * Id for the carousel\n */\n carouselId: string | undefined;\n /**\n * Announcement state, determines whether change is communicated to screenreader.\n * @param trigger\n */\n announcementState: CarouselAnnouncementTrigger | undefined;\n /**\n * Set announcement state, determines whether change is communicated to screenreader.\n * @param trigger\n */\n setAnnouncementState: (\n trigger: CarouselAnnouncementTrigger | undefined,\n ) => void;\n}\n\nexport const CarouselContext = createContext<CarouselContextType | undefined>(\n \"CarouselContext\",\n undefined,\n);\n\nexport const useCarouselContext = (): CarouselContextType => {\n const context = useContext(CarouselContext);\n if (!context) {\n throw new Error(\n \"useCarouselContext must be used within a CarouselProvider\",\n );\n }\n return context;\n};\n"],"names":["createContext","useContext"],"mappings":";;;;;AA4DO,MAAM,eAAA,GAAkBA,kBAAA;AAAA,EAC7B,iBAAA;AAAA,EACA;AACF;AAEO,MAAM,qBAAqB,MAA2B;AAC3D,EAAA,MAAM,OAAA,GAAUC,iBAAW,eAAe,CAAA;AAC1C,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;;;;;"}
|
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var core = require('@salt-ds/core');
|
|
5
5
|
var react = require('react');
|
|
6
|
+
var CarouselContext = require('./CarouselContext.js');
|
|
6
7
|
var usePrevNextButtons = require('./usePrevNextButtons.js');
|
|
7
8
|
|
|
8
9
|
const CarouselNextButton = react.forwardRef(function CarouselNextButton2({ className, onClick, ...rest }, ref) {
|
|
9
10
|
const { NextIcon } = core.useIcon();
|
|
10
11
|
const { nextBtnDisabled, onNextButtonClick } = usePrevNextButtons.usePrevNextButtons();
|
|
12
|
+
const { carouselId } = CarouselContext.useCarouselContext();
|
|
11
13
|
const handleClick = (event) => {
|
|
12
14
|
onNextButtonClick();
|
|
13
15
|
onClick == null ? void 0 : onClick(event);
|
|
@@ -18,7 +20,8 @@ const CarouselNextButton = react.forwardRef(function CarouselNextButton2({ class
|
|
|
18
20
|
onClick: handleClick,
|
|
19
21
|
disabled: nextBtnDisabled,
|
|
20
22
|
focusableWhenDisabled: true,
|
|
21
|
-
appearance: "
|
|
23
|
+
appearance: "transparent",
|
|
24
|
+
"aria-controls": `${carouselId}-slides`,
|
|
22
25
|
sentiment: "neutral",
|
|
23
26
|
"aria-label": "Next slide",
|
|
24
27
|
ref,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CarouselNextButton.js","sources":["../src/CarouselNextButton.tsx"],"sourcesContent":["import { Button, type ButtonProps, useIcon } from \"@salt-ds/core\";\nimport { forwardRef, type MouseEventHandler } from \"react\";\nimport { usePrevNextButtons } from \"./usePrevNextButtons\";\n\n/**\n * Props for the CarouselNextButton component.\n */\nexport interface CarouselNextButtonProps\n extends Omit<ButtonProps, \"variant\" | \"loading\" | \"loadingAnnouncement\"> {}\n\nexport const CarouselNextButton = forwardRef<\n HTMLButtonElement,\n CarouselNextButtonProps\n>(function CarouselNextButton({ className, onClick, ...rest }, ref) {\n const { NextIcon } = useIcon();\n const { nextBtnDisabled, onNextButtonClick } = usePrevNextButtons();\n\n const handleClick: MouseEventHandler<HTMLButtonElement> = (event) => {\n onNextButtonClick();\n onClick?.(event);\n };\n\n return (\n <Button\n onClick={handleClick}\n disabled={nextBtnDisabled}\n focusableWhenDisabled\n appearance=\"
|
|
1
|
+
{"version":3,"file":"CarouselNextButton.js","sources":["../src/CarouselNextButton.tsx"],"sourcesContent":["import { Button, type ButtonProps, useIcon } from \"@salt-ds/core\";\nimport { forwardRef, type MouseEventHandler } from \"react\";\nimport { useCarouselContext } from \"./CarouselContext\";\nimport { usePrevNextButtons } from \"./usePrevNextButtons\";\n\n/**\n * Props for the CarouselNextButton component.\n */\nexport interface CarouselNextButtonProps\n extends Omit<ButtonProps, \"variant\" | \"loading\" | \"loadingAnnouncement\"> {}\n\nexport const CarouselNextButton = forwardRef<\n HTMLButtonElement,\n CarouselNextButtonProps\n>(function CarouselNextButton({ className, onClick, ...rest }, ref) {\n const { NextIcon } = useIcon();\n const { nextBtnDisabled, onNextButtonClick } = usePrevNextButtons();\n\n const { carouselId } = useCarouselContext();\n\n const handleClick: MouseEventHandler<HTMLButtonElement> = (event) => {\n onNextButtonClick();\n onClick?.(event);\n };\n\n return (\n <Button\n onClick={handleClick}\n disabled={nextBtnDisabled}\n focusableWhenDisabled\n appearance=\"transparent\"\n aria-controls={`${carouselId}-slides`}\n sentiment=\"neutral\"\n aria-label=\"Next slide\"\n ref={ref}\n {...rest}\n >\n <NextIcon aria-hidden />\n </Button>\n );\n});\n"],"names":["forwardRef","CarouselNextButton","useIcon","usePrevNextButtons","useCarouselContext","jsx","Button"],"mappings":";;;;;;;;AAWO,MAAM,kBAAA,GAAqBA,gBAAA,CAGhC,SAASC,mBAAAA,CAAmB,EAAE,WAAW,OAAA,EAAS,GAAG,IAAA,EAAK,EAAG,GAAA,EAAK;AAClE,EAAA,MAAM,EAAE,QAAA,EAAS,GAAIC,YAAA,EAAQ;AAC7B,EAAA,MAAM,EAAE,eAAA,EAAiB,iBAAA,EAAkB,GAAIC,qCAAA,EAAmB;AAElE,EAAA,MAAM,EAAE,UAAA,EAAW,GAAIC,kCAAA,EAAmB;AAE1C,EAAA,MAAM,WAAA,GAAoD,CAAC,KAAA,KAAU;AACnE,IAAA,iBAAA,EAAkB;AAClB,IAAA,OAAA,IAAA,IAAA,GAAA,MAAA,GAAA,OAAA,CAAU,KAAA,CAAA;AAAA,EACZ,CAAA;AAEA,EAAA,uBACEC,cAAA;AAAA,IAACC,WAAA;AAAA,IAAA;AAAA,MACC,OAAA,EAAS,WAAA;AAAA,MACT,QAAA,EAAU,eAAA;AAAA,MACV,qBAAA,EAAqB,IAAA;AAAA,MACrB,UAAA,EAAW,aAAA;AAAA,MACX,eAAA,EAAe,GAAG,UAAU,CAAA,OAAA,CAAA;AAAA,MAC5B,SAAA,EAAU,SAAA;AAAA,MACV,YAAA,EAAW,YAAA;AAAA,MACX,GAAA;AAAA,MACC,GAAG,IAAA;AAAA,MAEJ,QAAA,kBAAAD,cAAA,CAAC,QAAA,EAAA,EAAS,aAAA,EAAW,IAAA,EAAC;AAAA;AAAA,GACxB;AAEJ,CAAC;;;;"}
|
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var core = require('@salt-ds/core');
|
|
5
5
|
var react = require('react');
|
|
6
|
+
var CarouselContext = require('./CarouselContext.js');
|
|
6
7
|
var usePrevNextButtons = require('./usePrevNextButtons.js');
|
|
7
8
|
|
|
8
9
|
const CarouselPreviousButton = react.forwardRef(function CarouselPreviousButton2({ className, onClick, ...rest }, ref) {
|
|
9
10
|
const { PreviousIcon } = core.useIcon();
|
|
10
11
|
const { prevBtnDisabled, onPrevButtonClick } = usePrevNextButtons.usePrevNextButtons();
|
|
12
|
+
const { carouselId } = CarouselContext.useCarouselContext();
|
|
11
13
|
const handleClick = (event) => {
|
|
12
14
|
onPrevButtonClick();
|
|
13
15
|
onClick == null ? void 0 : onClick(event);
|
|
@@ -18,7 +20,8 @@ const CarouselPreviousButton = react.forwardRef(function CarouselPreviousButton2
|
|
|
18
20
|
onClick: handleClick,
|
|
19
21
|
disabled: prevBtnDisabled,
|
|
20
22
|
focusableWhenDisabled: true,
|
|
21
|
-
appearance: "
|
|
23
|
+
appearance: "transparent",
|
|
24
|
+
"aria-controls": `${carouselId}-slides`,
|
|
22
25
|
sentiment: "neutral",
|
|
23
26
|
"aria-label": "Previous slide",
|
|
24
27
|
ref,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CarouselPreviousButton.js","sources":["../src/CarouselPreviousButton.tsx"],"sourcesContent":["import { Button, type ButtonProps, useIcon } from \"@salt-ds/core\";\nimport { forwardRef, type MouseEventHandler } from \"react\";\nimport { usePrevNextButtons } from \"./usePrevNextButtons\";\n\n/**\n * Props for the CarouselPreviousButton component.\n */\nexport interface CarouselPreviousButtonProps\n extends Omit<ButtonProps, \"variant\" | \"loading\" | \"loadingAnnouncement\"> {}\n\nexport const CarouselPreviousButton = forwardRef<\n HTMLButtonElement,\n CarouselPreviousButtonProps\n>(function CarouselPreviousButton({ className, onClick, ...rest }, ref) {\n const { PreviousIcon } = useIcon();\n const { prevBtnDisabled, onPrevButtonClick } = usePrevNextButtons();\n\n const handleClick: MouseEventHandler<HTMLButtonElement> = (event) => {\n onPrevButtonClick();\n onClick?.(event);\n };\n\n return (\n <Button\n onClick={handleClick}\n disabled={prevBtnDisabled}\n focusableWhenDisabled\n appearance=\"
|
|
1
|
+
{"version":3,"file":"CarouselPreviousButton.js","sources":["../src/CarouselPreviousButton.tsx"],"sourcesContent":["import { Button, type ButtonProps, useIcon } from \"@salt-ds/core\";\nimport { forwardRef, type MouseEventHandler } from \"react\";\nimport { useCarouselContext } from \"./CarouselContext\";\nimport { usePrevNextButtons } from \"./usePrevNextButtons\";\n\n/**\n * Props for the CarouselPreviousButton component.\n */\nexport interface CarouselPreviousButtonProps\n extends Omit<ButtonProps, \"variant\" | \"loading\" | \"loadingAnnouncement\"> {}\n\nexport const CarouselPreviousButton = forwardRef<\n HTMLButtonElement,\n CarouselPreviousButtonProps\n>(function CarouselPreviousButton({ className, onClick, ...rest }, ref) {\n const { PreviousIcon } = useIcon();\n const { prevBtnDisabled, onPrevButtonClick } = usePrevNextButtons();\n\n const { carouselId } = useCarouselContext();\n\n const handleClick: MouseEventHandler<HTMLButtonElement> = (event) => {\n onPrevButtonClick();\n onClick?.(event);\n };\n\n return (\n <Button\n onClick={handleClick}\n disabled={prevBtnDisabled}\n focusableWhenDisabled\n appearance=\"transparent\"\n aria-controls={`${carouselId}-slides`}\n sentiment=\"neutral\"\n aria-label=\"Previous slide\"\n ref={ref}\n {...rest}\n >\n <PreviousIcon aria-hidden />\n </Button>\n );\n});\n"],"names":["forwardRef","CarouselPreviousButton","useIcon","usePrevNextButtons","useCarouselContext","jsx","Button"],"mappings":";;;;;;;;AAWO,MAAM,sBAAA,GAAyBA,gBAAA,CAGpC,SAASC,uBAAAA,CAAuB,EAAE,WAAW,OAAA,EAAS,GAAG,IAAA,EAAK,EAAG,GAAA,EAAK;AACtE,EAAA,MAAM,EAAE,YAAA,EAAa,GAAIC,YAAA,EAAQ;AACjC,EAAA,MAAM,EAAE,eAAA,EAAiB,iBAAA,EAAkB,GAAIC,qCAAA,EAAmB;AAElE,EAAA,MAAM,EAAE,UAAA,EAAW,GAAIC,kCAAA,EAAmB;AAE1C,EAAA,MAAM,WAAA,GAAoD,CAAC,KAAA,KAAU;AACnE,IAAA,iBAAA,EAAkB;AAClB,IAAA,OAAA,IAAA,IAAA,GAAA,MAAA,GAAA,OAAA,CAAU,KAAA,CAAA;AAAA,EACZ,CAAA;AAEA,EAAA,uBACEC,cAAA;AAAA,IAACC,WAAA;AAAA,IAAA;AAAA,MACC,OAAA,EAAS,WAAA;AAAA,MACT,QAAA,EAAU,eAAA;AAAA,MACV,qBAAA,EAAqB,IAAA;AAAA,MACrB,UAAA,EAAW,aAAA;AAAA,MACX,eAAA,EAAe,GAAG,UAAU,CAAA,OAAA,CAAA;AAAA,MAC5B,SAAA,EAAU,SAAA;AAAA,MACV,YAAA,EAAW,gBAAA;AAAA,MACX,GAAA;AAAA,MACC,GAAG,IAAA;AAAA,MAEJ,QAAA,kBAAAD,cAAA,CAAC,YAAA,EAAA,EAAa,aAAA,EAAW,IAAA,EAAC;AAAA;AAAA,GAC5B;AAEJ,CAAC;;;;"}
|
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var core = require('@salt-ds/core');
|
|
5
|
-
var styles = require('@salt-ds/styles');
|
|
6
|
-
var window = require('@salt-ds/window');
|
|
7
5
|
var clsx = require('clsx');
|
|
8
6
|
var react = require('react');
|
|
9
7
|
var CarouselContext = require('./CarouselContext.js');
|
|
10
|
-
var
|
|
8
|
+
var getVisibleSlideIndexes = require('./getVisibleSlideIndexes.js');
|
|
11
9
|
|
|
12
10
|
const withBaseName = core.makePrefixer("saltCarouselTabList");
|
|
13
11
|
function CarouselProgressLabel({
|
|
@@ -16,35 +14,20 @@ function CarouselProgressLabel({
|
|
|
16
14
|
children,
|
|
17
15
|
...props
|
|
18
16
|
}) {
|
|
19
|
-
const targetWindow = window.useWindow();
|
|
20
|
-
styles.useComponentCssInjection({
|
|
21
|
-
testId: "salt-carousel-progress-label",
|
|
22
|
-
css: CarouselProgressLabel$1,
|
|
23
|
-
window: targetWindow
|
|
24
|
-
});
|
|
25
17
|
const { emblaApi } = CarouselContext.useCarouselContext();
|
|
26
|
-
const [
|
|
27
|
-
const [totalSlides, setTotalSlides] = react.useState(0);
|
|
18
|
+
const [progress, setProgress] = react.useState("");
|
|
28
19
|
react.useEffect(() => {
|
|
29
20
|
const handleSelect = (emblaApi2) => {
|
|
30
|
-
const
|
|
21
|
+
const selectedScrollSnap = (emblaApi2 == null ? void 0 : emblaApi2.selectedScrollSnap()) ?? 0;
|
|
31
22
|
const numberOfSlides = (emblaApi2 == null ? void 0 : emblaApi2.slideNodes().length) ?? 0;
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
slideIndexInView * slidesPerTransition + 1,
|
|
36
|
-
numberOfSlides - (slidesPerTransition - 1)
|
|
23
|
+
const visibleSlides = getVisibleSlideIndexes.getVisibleSlideIndexes(
|
|
24
|
+
emblaApi2,
|
|
25
|
+
selectedScrollSnap
|
|
37
26
|
);
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
);
|
|
42
|
-
if (startSlideNumber === endSlideNumber) {
|
|
43
|
-
setCurrentSlide(startSlideNumber.toString(10));
|
|
44
|
-
} else {
|
|
45
|
-
setCurrentSlide(`${startSlideNumber}-${endSlideNumber}`);
|
|
46
|
-
}
|
|
47
|
-
setTotalSlides(numberOfSlides);
|
|
27
|
+
const startSlideNumber = visibleSlides.length >= 1 ? visibleSlides[0] : 0;
|
|
28
|
+
const endSlideNumber = visibleSlides.length > 1 ? visibleSlides[visibleSlides.length - 1] : 0;
|
|
29
|
+
const slidePosition = endSlideNumber ? `${startSlideNumber}-${endSlideNumber}` : startSlideNumber;
|
|
30
|
+
setProgress(`Slide ${slidePosition} of ${numberOfSlides}`);
|
|
48
31
|
};
|
|
49
32
|
if (!emblaApi) return;
|
|
50
33
|
emblaApi.on("init", handleSelect).on("reInit", handleSelect).on("select", handleSelect);
|
|
@@ -53,12 +36,7 @@ function CarouselProgressLabel({
|
|
|
53
36
|
emblaApi.off("init", handleSelect).off("reInit", handleSelect).off("select", handleSelect);
|
|
54
37
|
};
|
|
55
38
|
}, [emblaApi]);
|
|
56
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
57
|
-
"Slide ",
|
|
58
|
-
currentSlide,
|
|
59
|
-
" of ",
|
|
60
|
-
totalSlides
|
|
61
|
-
] });
|
|
39
|
+
return /* @__PURE__ */ jsxRuntime.jsx(core.Text, { className: clsx.clsx(withBaseName(), className), ...props, children: progress });
|
|
62
40
|
}
|
|
63
41
|
|
|
64
42
|
exports.CarouselProgressLabel = CarouselProgressLabel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CarouselProgressLabel.js","sources":["../src/CarouselProgressLabel.tsx"],"sourcesContent":["import { makePrefixer, Text, type TextProps } from \"@salt-ds/core\";\nimport {
|
|
1
|
+
{"version":3,"file":"CarouselProgressLabel.js","sources":["../src/CarouselProgressLabel.tsx"],"sourcesContent":["import { makePrefixer, Text, type TextProps } from \"@salt-ds/core\";\nimport { clsx } from \"clsx\";\nimport type { EmblaCarouselType } from \"embla-carousel\";\nimport { useEffect, useState } from \"react\";\nimport { useCarouselContext } from \"./CarouselContext\";\nimport { getVisibleSlideIndexes } from \"./getVisibleSlideIndexes\";\n\n/**\n * Props for the CarouselProgressLabel component.\n */\nexport interface CarouselProgressLabelProps extends TextProps<\"div\"> {}\n\nconst withBaseName = makePrefixer(\"saltCarouselTabList\");\n\nexport function CarouselProgressLabel({\n className,\n styleAs = \"label\",\n children,\n ...props\n}: CarouselProgressLabelProps) {\n const { emblaApi } = useCarouselContext();\n\n const [progress, setProgress] = useState(\"\");\n\n useEffect(() => {\n const handleSelect = (emblaApi: EmblaCarouselType) => {\n const selectedScrollSnap = emblaApi?.selectedScrollSnap() ?? 0;\n const numberOfSlides = emblaApi?.slideNodes().length ?? 0;\n const visibleSlides = getVisibleSlideIndexes(\n emblaApi,\n selectedScrollSnap,\n );\n const startSlideNumber = visibleSlides.length >= 1 ? visibleSlides[0] : 0;\n const endSlideNumber =\n visibleSlides.length > 1 ? visibleSlides[visibleSlides.length - 1] : 0;\n const slidePosition = endSlideNumber\n ? `${startSlideNumber}-${endSlideNumber}`\n : startSlideNumber;\n setProgress(`Slide ${slidePosition} of ${numberOfSlides}`);\n };\n\n if (!emblaApi) return;\n emblaApi\n .on(\"init\", handleSelect)\n .on(\"reInit\", handleSelect)\n .on(\"select\", handleSelect);\n handleSelect(emblaApi);\n // Cleanup listener on component unmount\n return () => {\n emblaApi\n .off(\"init\", handleSelect)\n .off(\"reInit\", handleSelect)\n .off(\"select\", handleSelect);\n };\n }, [emblaApi]);\n\n return (\n <Text className={clsx(withBaseName(), className)} {...props}>\n {progress}\n </Text>\n );\n}\n"],"names":["makePrefixer","useCarouselContext","useState","useEffect","emblaApi","getVisibleSlideIndexes","jsx","Text","clsx"],"mappings":";;;;;;;;;AAYA,MAAM,YAAA,GAAeA,kBAAa,qBAAqB,CAAA;AAEhD,SAAS,qBAAA,CAAsB;AAAA,EACpC,SAAA;AAAA,EACA,OAAA,GAAU,OAAA;AAAA,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O,MAAM;AACX,MAAA,QAAA,CACG,GAAA,CAAI,MAAA,EAAQ,YAAY,CAAA,CACxB,GAAA,CAAI,UAAU,YAAY,CAAA,CAC1B,GAAA,CAAI,QAAA,EAAU,YAAY,CAAA;AAAA,IAC/B,CAAA;AAAA,EACF,CAAA,EAAG,CAAC,QAAQ,CAAC,CAAA;AAEb,EAAA,uBACEE,cAAA,CAACC,SAAA,EAAA,EAAK,SAAA,EAAWC,SAAA,CAAK,YAAA,IAAgB,SAAS,CAAA,EAAI,GAAG,KAAA,EACnD,QAAA,EAAA,QAAA,EACH,CAAA;AAEJ;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var css_248z = ".saltCarouselSlides {\n overflow: hidden;\n}\n.saltCarouselSlides-container {\n display: flex;\n touch-action: pan-y pinch-zoom;\n margin-left: calc(var(--carousel-slide-spacing) * -1);\n}\n";
|
|
3
|
+
var css_248z = ".saltCarouselSlides {\n overflow: hidden;\n cursor: var(--salt-cursor-grab);\n}\n\n.saltCarouselSlides-container {\n display: flex;\n touch-action: pan-y pinch-zoom;\n margin-left: calc(var(--carousel-slide-spacing) * -1);\n}\n\n.saltCarouselSlides-sr-only {\n position: absolute;\n height: 1px;\n width: 1px;\n padding: 0;\n margin: -1px;\n overflow: hidden;\n clip: rect(0, 0, 0, 0);\n white-space: nowrap;\n border-width: 0;\n}\n\n.saltCarouselSlides-dragging {\n cursor: var(--salt-cursor-grab-active);\n}\n";
|
|
4
4
|
|
|
5
5
|
module.exports = css_248z;
|
|
6
6
|
//# sourceMappingURL=CarouselSlides.css.js.map
|