MCPcopy
hub / github.com/untitleduico/react / Trigger

Function Trigger

components/application/carousel/carousel-base.tsx:187–223  ·  view source on GitHub ↗
({ className, children, asChild, direction, style, ...props }: TriggerProps)

Source from the content-addressed store, hash-verified

185}
186
187const Trigger = ({ className, children, asChild, direction, style, ...props }: TriggerProps) => {
188 const { scrollPrev, canScrollNext, scrollNext, canScrollPrev } = useCarousel();
189
190 const isDisabled = direction === "prev" ? !canScrollPrev : !canScrollNext;
191
192 const handleClick = () => {
193 if (isDisabled) return;
194
195 direction === "prev" ? scrollPrev() : scrollNext();
196 };
197
198 const computedClassName = typeof className === "function" ? className({ isDisabled }) : className;
199
200 const defaultAriaLabel = direction === "prev" ? "Previous slide" : "Next slide";
201
202 // If the children is a render prop, we need to pass the necessary props to the render prop.
203 if (typeof children === "function") {
204 return <>{children({ isDisabled, onClick: handleClick })}</>;
205 }
206
207 // If the children is a valid element, we need to clone it and pass the necessary props to the cloned element.
208 if (asChild && isValidElement(children)) {
209 return cloneElement(children, {
210 onClick: handleClick,
211 disabled: isDisabled,
212 "aria-label": defaultAriaLabel,
213 style: { ...(children.props as HTMLAttributes<HTMLElement>).style, ...style },
214 className: [computedClassName, (children.props as HTMLAttributes<HTMLElement>).className].filter(Boolean).join(" ") || undefined,
215 } as HTMLAttributes<HTMLElement>);
216 }
217
218 return (
219 <button aria-label={defaultAriaLabel} disabled={isDisabled} className={computedClassName} onClick={handleClick} {...props}>
220 {children}
221 </button>
222 );
223};
224
225const CarouselPrevTrigger = (props: Omit<TriggerProps, "direction">) => <Trigger {...props} direction="prev" />;
226

Callers

nothing calls this directly

Calls 1

useCarouselFunction · 0.85

Tested by

no test coverage detected