@obosbbl/grunnmuren-react 2.3.1 → 2.3.3

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/index.d.mts CHANGED
@@ -634,8 +634,16 @@ type CarouselProps = {
634
634
  children: React.ReactNode;
635
635
  /** Additional CSS className for the element. */
636
636
  className?: string;
637
+ /**
638
+ * Callback that is triggered when a user navigates to new item in the Carousel.
639
+ * The argument to the callback is an object containing `index` of the new item scrolled into view and the `id` of that item (if set on the `<CarouselItem>`)
640
+ * It also provides `prevIndex` which is the index of the previous item that was in view
641
+ * And `prevId`, which is the id of the previous item that was in view (if set on the `<CarouselItem>`)
642
+ * @param item { index: number; id?: string; prevIndex: number; prevId?: string }
643
+ */
644
+ onChange?: (item: CarouselItem) => void;
637
645
  };
638
- declare const Carousel: ({ className, children }: CarouselProps) => react_jsx_runtime.JSX.Element;
646
+ declare const Carousel: ({ className, children, onChange }: CarouselProps) => react_jsx_runtime.JSX.Element;
639
647
  type CarouselItemsProps = {
640
648
  /** The <CarouselItem/> components to be displayed within the carousel. */
641
649
  children: React.ReactNode;
@@ -648,7 +656,16 @@ type CarouselItemProps = {
648
656
  children: React.ReactNode;
649
657
  /** Additional CSS className for the element. */
650
658
  className?: string;
659
+ id?: string;
660
+ };
661
+ type CarouselItem = Pick<CarouselItemProps, 'id'> & {
662
+ /** The index of the item that is currently in view */
663
+ index: number;
664
+ /** The index of the previous item that was in view */
665
+ prevIndex: number;
666
+ /** The id of the previous item that was in view */
667
+ prevId?: CarouselItemProps['id'];
651
668
  };
652
- declare const CarouselItem: ({ className, children }: CarouselItemProps) => react_jsx_runtime.JSX.Element;
669
+ declare const CarouselItem: ({ className, children, id }: CarouselItemProps) => react_jsx_runtime.JSX.Element;
653
670
 
654
671
  export { Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, Alertbox, type Props as AlertboxProps, Avatar, type AvatarProps, Backlink, type BacklinkProps, Badge, type BadgeProps, Breadcrumb, type BreadcrumbProps, Breadcrumbs, type BreadcrumbsProps, Button, ButtonContext, type ButtonProps, Caption, type CaptionProps, Card, CardLink, type CardLinkProps, type CardProps, Checkbox, CheckboxGroup, type CheckboxGroupProps, type CheckboxProps, Combobox, ListBoxHeader as ComboboxHeader, ListBoxItem as ComboboxItem, type ComboboxProps, ListBoxSection as ComboboxSection, Content, ContentContext, type ContentProps, DateFormatter, type DateFormatterProps, Description, type DescriptionProps, DisclosureStateContext, ErrorMessage, type ErrorMessageProps, Footer, type FooterProps, GrunnmurenProvider, type GrunnmurenProviderProps, Heading, HeadingContext, type HeadingProps, Label, type Locale, Media, MediaContext, type MediaProps, NumberField, type NumberFieldProps, Radio, RadioGroup, type RadioGroupProps, type RadioProps, Select, ListBoxHeader as SelectHeader, ListBoxItem as SelectItem, type SelectProps, ListBoxSection as SelectSection, type TagGroupProps, type TagListProps, type TagProps, TextArea, type TextAreaProps, TextField, type TextFieldProps, Carousel as UNSAFE_Carousel, CarouselItem as UNSAFE_CarouselItem, type CarouselItemProps as UNSAFE_CarouselItemProps, CarouselItems as UNSAFE_CarouselItems, type CarouselItemsProps as UNSAFE_CarouselItemsProps, type CarouselProps as UNSAFE_CarouselProps, Dialog as UNSAFE_Dialog, type DialogProps as UNSAFE_DialogProps, DialogTrigger as UNSAFE_DialogTrigger, type DialogTriggerProps as UNSAFE_DialogTriggerProps, Disclosure as UNSAFE_Disclosure, DisclosureButton as UNSAFE_DisclosureButton, type DisclosureButtonProps as UNSAFE_DisclosureButtonProps, DisclosurePanel as UNSAFE_DisclosurePanel, type DisclosurePanelProps as UNSAFE_DisclosurePanelProps, type DisclosureProps as UNSAFE_DisclosureProps, FileUpload as UNSAFE_FileUpload, type FileUploadProps as UNSAFE_FileUploadProps, Hero as UNSAFE_Hero, type HeroProps as UNSAFE_HeroProps, Modal as UNSAFE_Modal, type ModalProps as UNSAFE_ModalProps, Tag as UNSAFE_Tag, TagGroup as UNSAFE_TagGroup, TagList as UNSAFE_TagList, VideoLoop, _useLocale as useLocale };
package/dist/index.mjs CHANGED
@@ -1673,7 +1673,9 @@ const translations = {
1673
1673
  return new File([
1674
1674
  file
1675
1675
  ], // Follow the pattern of adding a number in parentheses to the base name (e.g. "file (1).txt")
1676
- `${baseName} (${fileNameCounts[baseName] - 1})${extension}`);
1676
+ `${baseName} (${fileNameCounts[baseName] - 1})${extension}`, {
1677
+ type: file.type
1678
+ });
1677
1679
  }
1678
1680
  return file;
1679
1681
  });
@@ -2105,7 +2107,7 @@ const Hero = ({ variant, className, children })=>{
2105
2107
  });
2106
2108
  };
2107
2109
 
2108
- const Carousel = ({ className, children })=>{
2110
+ const Carousel = ({ className, children, onChange })=>{
2109
2111
  const ref = useRef(null);
2110
2112
  const locale = _useLocale();
2111
2113
  const { previous, next } = translations$1;
@@ -2118,6 +2120,9 @@ const Carousel = ({ className, children })=>{
2118
2120
  }, [
2119
2121
  scrollTargetIndex
2120
2122
  ]);
2123
+ // Keep track of the previous index to determine if the user is scrolling forward or backward
2124
+ // This is used to determine which callback to call (onPrev or onNext)
2125
+ const prevIndex = useRef(0);
2121
2126
  // Handle scrolling when user clicks the arrow icons
2122
2127
  useUpdateEffect(()=>{
2123
2128
  if (!ref.current) return;
@@ -2126,6 +2131,15 @@ const Carousel = ({ className, children })=>{
2126
2131
  inline: 'start',
2127
2132
  block: 'nearest'
2128
2133
  });
2134
+ if (prevIndex.current !== scrollTargetIndex && onChange) {
2135
+ onChange({
2136
+ index: scrollTargetIndex,
2137
+ id: ref.current.children[scrollTargetIndex]?.id,
2138
+ prevIndex: prevIndex.current,
2139
+ prevId: ref.current.children[prevIndex.current]?.id
2140
+ });
2141
+ }
2142
+ prevIndex.current = scrollTargetIndex;
2129
2143
  }, [
2130
2144
  scrollTargetIndex
2131
2145
  ]);
@@ -2247,10 +2261,11 @@ const CarouselItems = ({ className, children })=>/*#__PURE__*/ jsx(CarouselItems
2247
2261
  children: children
2248
2262
  })
2249
2263
  });
2250
- const CarouselItem = ({ className, children })=>{
2264
+ const CarouselItem = ({ className, children, id })=>{
2251
2265
  return /*#__PURE__*/ jsx("div", {
2252
2266
  className: cx(className, 'shrink-0 basis-full snap-start'),
2253
2267
  "data-slot": "carousel-item",
2268
+ id: id,
2254
2269
  children: /*#__PURE__*/ jsx(Provider, {
2255
2270
  values: [
2256
2271
  [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@obosbbl/grunnmuren-react",
3
- "version": "2.3.1",
3
+ "version": "2.3.3",
4
4
  "description": "Grunnmuren components in React",
5
5
  "repository": {
6
6
  "url": "https://github.com/code-obos/grunnmuren"