[Glitch] Update eslint (non-major)
Port 3cc36b98c084f8e5c602e56a486f89cfaa34db0b to glitch-soc Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: diondiondion <mail@diondiondion.com> Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
1 parent
1bd2cf99fd
commit
17092ed87b
11 files changed
+89
-63
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import type { FC } from 'react';
|
||||
import type { CSSProperties, FC } from 'react';
|
||||
|
||||
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||
import { fn, userEvent, expect } from 'storybook/test';
|
||||
@@ -10,16 +10,19 @@ interface TestSlideProps {
|
||||
id: number;
|
||||
text: string;
|
||||
color: string;
|
||||
style?: CSSProperties;
|
||||
}
|
||||
|
||||
const TestSlide: FC<TestSlideProps & { active: boolean }> = ({
|
||||
active,
|
||||
text,
|
||||
color,
|
||||
style,
|
||||
}) => (
|
||||
<div
|
||||
className='test-slide'
|
||||
style={{
|
||||
...style,
|
||||
backgroundColor: active ? color : undefined,
|
||||
}}
|
||||
>
|
||||
@@ -114,7 +117,7 @@ export const DifferentHeights: Story = {
|
||||
args: {
|
||||
items: slides.map((props, index) => ({
|
||||
...props,
|
||||
styles: { height: 100 + index * 100 },
|
||||
style: { height: 100 + index * 100 },
|
||||
})),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useCallback, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useCallback, useMemo, useState } from 'react';
|
||||
import type {
|
||||
ComponentPropsWithoutRef,
|
||||
ComponentType,
|
||||
@@ -75,10 +75,13 @@ export const Carousel = <
|
||||
}: CarouselProps<SlideProps> & ComponentPropsWithoutRef<'div'>) => {
|
||||
// Handle slide change
|
||||
const [slideIndex, setSlideIndex] = useState(0);
|
||||
const wrapperRef = useRef<HTMLDivElement>(null);
|
||||
const [wrapperElement, setWrapperElement] = useState<HTMLDivElement | null>(
|
||||
null,
|
||||
);
|
||||
|
||||
// Handle slide heights
|
||||
const [currentSlideHeight, setCurrentSlideHeight] = useState(
|
||||
() => wrapperRef.current?.scrollHeight ?? 0,
|
||||
const [currentSlideHeight, setCurrentSlideHeight] = useState<number | null>(
|
||||
null,
|
||||
);
|
||||
const previousSlideHeight = usePrevious(currentSlideHeight);
|
||||
const handleSlideChange = useCallback(
|
||||
@@ -92,7 +95,7 @@ export const Carousel = <
|
||||
newIndex = 0;
|
||||
}
|
||||
|
||||
const slide = wrapperRef.current?.children[newIndex];
|
||||
const slide = wrapperElement?.children[newIndex];
|
||||
if (slide) {
|
||||
setCurrentSlideHeight(slide.scrollHeight);
|
||||
if (slide instanceof HTMLElement) {
|
||||
@@ -103,26 +106,27 @@ export const Carousel = <
|
||||
return newIndex;
|
||||
});
|
||||
},
|
||||
[items.length, onChangeSlide],
|
||||
[wrapperElement, items.length, onChangeSlide],
|
||||
);
|
||||
|
||||
const observerRef = useRef<ResizeObserver>(null);
|
||||
observerRef.current ??= new ResizeObserver(() => {
|
||||
// Update slide height when the component mounts
|
||||
if (wrapperElement && currentSlideHeight === null) {
|
||||
handleSlideChange(0);
|
||||
});
|
||||
}
|
||||
|
||||
const [observer] = useState<ResizeObserver>(
|
||||
() =>
|
||||
new ResizeObserver(() => {
|
||||
handleSlideChange(0);
|
||||
}),
|
||||
);
|
||||
|
||||
const wrapperStyles = useSpring({
|
||||
x: `-${slideIndex * 100}%`,
|
||||
height: currentSlideHeight,
|
||||
height: currentSlideHeight ?? 0,
|
||||
// Don't animate from zero to the height of the initial slide
|
||||
immediate: !previousSlideHeight,
|
||||
});
|
||||
useLayoutEffect(() => {
|
||||
// Update slide height when the component mounts
|
||||
if (currentSlideHeight === 0) {
|
||||
handleSlideChange(0);
|
||||
}
|
||||
}, [currentSlideHeight, handleSlideChange]);
|
||||
|
||||
// Handle swiping animations
|
||||
const bind = useDrag(
|
||||
@@ -135,12 +139,12 @@ export const Carousel = <
|
||||
handleSlideChange(-1);
|
||||
// We're focusing on the wrapper as the child slides can potentially be inert.
|
||||
// Because of that, only the active slide can be focused anyway.
|
||||
wrapperRef.current?.focus();
|
||||
}, [handleSlideChange]);
|
||||
wrapperElement?.focus();
|
||||
}, [handleSlideChange, wrapperElement]);
|
||||
const handleNext = useCallback(() => {
|
||||
handleSlideChange(1);
|
||||
wrapperRef.current?.focus();
|
||||
}, [handleSlideChange]);
|
||||
wrapperElement?.focus();
|
||||
}, [handleSlideChange, wrapperElement]);
|
||||
|
||||
const intl = useIntl();
|
||||
|
||||
@@ -173,7 +177,7 @@ export const Carousel = <
|
||||
|
||||
<animated.div
|
||||
className={`${classNamePrefix}__slides`}
|
||||
ref={wrapperRef}
|
||||
ref={setWrapperElement}
|
||||
style={wrapperStyles}
|
||||
aria-label={intl.formatMessage(messages.slide, {
|
||||
current: slideIndex + 1,
|
||||
@@ -185,7 +189,7 @@ export const Carousel = <
|
||||
<CarouselSlideWrapper<SlideProps>
|
||||
item={itemsProps}
|
||||
renderItem={renderItem}
|
||||
observer={observerRef.current}
|
||||
observer={observer}
|
||||
index={index}
|
||||
key={`slide-${itemsProps.id}`}
|
||||
className={classNames(`${classNamePrefix}__slide`, slideClassName, {
|
||||
|
||||
@@ -488,6 +488,8 @@ export const Dropdown = <Item extends object | null = MenuItem>({
|
||||
};
|
||||
|
||||
if (children) {
|
||||
// We're just assigning the ref to an element so this is safe
|
||||
// eslint-disable-next-line react-hooks/refs
|
||||
button = cloneElement(Children.only(children), buttonProps);
|
||||
} else if (icon && iconComponent) {
|
||||
button = (
|
||||
|
||||
@@ -317,6 +317,9 @@ const ComboboxWithRef = <Item extends ComboboxItem, GroupKey extends string>(
|
||||
// Reset scroll & highlight when menu items change
|
||||
useEffect(() => {
|
||||
if (flatItems.length) {
|
||||
// This only runs when the items change so should be safe from
|
||||
// cascade renders.
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||
resetHighlight();
|
||||
}
|
||||
}, [flatItems, resetHighlight]);
|
||||
|
||||
Reference in new issue
Block a user