diff --git a/src/accordion.tsx b/src/accordion.tsx index 98274b77bb..87d27f7151 100644 --- a/src/accordion.tsx +++ b/src/accordion.tsx @@ -23,7 +23,7 @@ import type {TouchableElement} from './touchable'; const ACCORDION_TRANSITION_DURATION_IN_MS = 400; type AccordionContextType = { - index: Array; + index: ReadonlyArray; toogle: (item: number) => void; }; const AccordionContext = React.createContext({ @@ -50,43 +50,45 @@ const useAccordionState = ({ onChange, singleOpen, }: { - value?: number | Array; - defaultValue?: number | Array; + value?: number | ReadonlyArray; + defaultValue?: number | ReadonlyArray; onChange?: (item: number, value: boolean) => void; singleOpen?: boolean; -}): [Array, (value: number) => void] => { +}): [ReadonlyArray, (value: number) => void] => { const isControlledByParent = value !== undefined; - const getValueAsList = (value?: number | Array) => { + const getValueAsList = (value?: number | ReadonlyArray) => { return value === undefined ? [] : typeof value === 'number' ? [value] : value; }; - const [index, setIndex] = React.useState>(getValueAsList(defaultValue)); + const [index, setIndex] = React.useState>(getValueAsList(defaultValue)); React.useEffect(() => { if (index.length > 1 && singleOpen) { - index.splice(1); - setIndex([...index]); + const newIndex = [...index]; + newIndex.splice(1); + setIndex(newIndex); } }, [singleOpen, index]); - const updateIndexOnToogle = (item: number, index?: Array) => { + const updateIndexOnToogle = (item: number, index?: ReadonlyArray) => { if (!index) { return [item]; } const valueIndex = index.indexOf(item); + let newIndex = [...index]; if (valueIndex === -1) { if (singleOpen) { - index = [item]; + newIndex = [item]; } else { - index.push(item); + newIndex.push(item); } } else { - index.splice(valueIndex, 1); + newIndex.splice(valueIndex, 1); } - return [...index]; + return newIndex; }; const toggle = (item: number) => { @@ -215,8 +217,8 @@ type SingleOpenProps = { type MultipleOpenProps = { singleOpen?: false; - index?: number | Array; - defaultIndex?: number | Array; + index?: number | ReadonlyArray; + defaultIndex?: number | ReadonlyArray; }; type AccordionProps = AccordionBaseProps & ExclusifyUnion; diff --git a/src/card.tsx b/src/card.tsx index 38ef3ac195..d22a81888e 100644 --- a/src/card.tsx +++ b/src/card.tsx @@ -65,7 +65,7 @@ export type CardAction = { trackingEvent?: TrackingEvent | ReadonlyArray; } & ExclusifyUnion; -const useTopActions = (actions?: Array, onClose?: () => void) => { +const useTopActions = (actions?: ReadonlyArray, onClose?: () => void) => { const {texts} = useTheme(); const finalActions = actions ? [...actions] : []; @@ -83,7 +83,7 @@ const useTopActions = (actions?: Array, onClose const CardActionTypeContext = React.createContext<'default' | 'inverse' | 'media'>('default'); type CardActionsGroupProps = { - actions?: Array; + actions?: ReadonlyArray; onClose?: () => void; padding?: number; type?: 'default' | 'inverse' | 'media'; @@ -475,7 +475,7 @@ interface MediaCardBaseProps { description?: string; descriptionLinesMax?: number; extra?: React.ReactNode; - actions?: Array; + actions?: ReadonlyArray; children?: void; dataAttributes?: DataAttributes; 'aria-label'?: string; @@ -772,7 +772,7 @@ interface DataCardBaseProps { description?: string; descriptionLinesMax?: number; extra?: React.ReactNode; - actions?: Array; + actions?: ReadonlyArray; aspectRatio?: AspectRatio | number; children?: void; /** "data-" prefix is automatically added. For example, use "testid" instead of "data-testid" */ @@ -986,7 +986,7 @@ interface CommonDisplayCardProps { * Typically a mistica-icons component element */ icon?: React.ReactElement; - actions?: Array; + actions?: ReadonlyArray; onClose?: () => void; dataAttributes?: DataAttributes; headline?: React.ReactComponentElement; @@ -1270,7 +1270,7 @@ interface PosterCardBaseProps { width?: number | string; height?: number | string; icon?: React.ReactElement; - actions?: Array; + actions?: ReadonlyArray; onClose?: () => void; dataAttributes?: DataAttributes; headline?: string | RendersNullableElement; diff --git a/src/carousel.tsx b/src/carousel.tsx index 223daa687b..502f0d30ca 100644 --- a/src/carousel.tsx +++ b/src/carousel.tsx @@ -204,7 +204,7 @@ const normalizeItemsPerPage = ( }; }; -const calcPagesScrollPositions = (itemsScrollPosition: ReadonlyArray, numPages: number) => { +const calcPagesScrollPositions = (itemsScrollPosition: Array, numPages: number) => { if (itemsScrollPosition.length === 0) { return []; } @@ -220,7 +220,7 @@ const calcPagesScrollPositions = (itemsScrollPosition: ReadonlyArray, nu return pagesScrollPositions; }; -const calcCurrentPageIndex = (scrollPosition: number, pagesScrollPositions: ReadonlyArray) => { +const calcCurrentPageIndex = (scrollPosition: number, pagesScrollPositions: Array) => { const middlePageScrollPositions = []; for (let i = 0; i < pagesScrollPositions.length; i++) { if (i === 0) { diff --git a/src/community/advanced-data-card.tsx b/src/community/advanced-data-card.tsx index 87d5bd220f..9f8072c5af 100644 --- a/src/community/advanced-data-card.tsx +++ b/src/community/advanced-data-card.tsx @@ -240,7 +240,7 @@ type AdvancedDataCardProps = MaybeTouchableCard<{ subtitleLinesMax?: number; description?: string; descriptionLinesMax?: number; - extra?: Array>; + extra?: ReadonlyArray>; extraDividerPadding?: 8 | 24; button?: RendersNullableElement; footerImage?: RendersNullableElement; @@ -248,7 +248,7 @@ type AdvancedDataCardProps = MaybeTouchableCard<{ footerTextLinesMax?: number; buttonLink?: RendersNullableElement; dataAttributes?: DataAttributes; - actions?: Array; + actions?: ReadonlyArray; 'aria-label'?: string; onClose?: () => void; }>; diff --git a/src/feedback.tsx b/src/feedback.tsx index a5459647d2..58ba94137f 100644 --- a/src/feedback.tsx +++ b/src/feedback.tsx @@ -182,7 +182,7 @@ type FeedbackButtonsProps = ButtonGroupProps; interface FeedbackProps extends FeedbackButtonsProps { title: string; - description?: string | Array; + description?: string | ReadonlyArray; /** * @deprecated This field is deprecated, please use extra instead. */ diff --git a/src/loading-screen.tsx b/src/loading-screen.tsx index b9c49d1a2d..1032ae4764 100644 --- a/src/loading-screen.tsx +++ b/src/loading-screen.tsx @@ -30,7 +30,7 @@ type TextProps = ExclusifyUnion< description?: string; } | { - texts: Array<{ + texts: ReadonlyArray<{ title?: string; description?: string; duration?: number; @@ -42,7 +42,7 @@ type LoadingScreenTextsProps = { animateText?: boolean; isLoading?: boolean; onClose?: () => void; - texts: Array<{ + texts: ReadonlyArray<{ title?: string; description?: string; duration?: number; diff --git a/src/sheet.tsx b/src/sheet.tsx index 4ba7ab3e6e..78eb3a16de 100644 --- a/src/sheet.tsx +++ b/src/sheet.tsx @@ -281,7 +281,7 @@ const paddingX = { type SheetBodyProps = { title?: string; subtitle?: string; - description?: string | Array; + description?: string | ReadonlyArray; button?: RendersNullableElement; secondaryButton?: RendersNullableElement; link?: RendersNullableElement; @@ -393,8 +393,8 @@ export const SheetBody = ({ type RadioListSheetProps = { title?: string; subtitle?: string; - description?: string | Array; - items: Array<{ + description?: string | ReadonlyArray; + items: ReadonlyArray<{ id: string; title?: string; description?: string; @@ -487,8 +487,8 @@ export const RadioListSheet = React.forwardRef; - items: Array<{ + description?: string | ReadonlyArray; + items: ReadonlyArray<{ id: string; title: string; style?: 'normal' | 'destructive'; // "normal" by default @@ -582,8 +582,8 @@ export const ActionsListSheet = React.forwardRef; - items: Array<{ + description?: string | ReadonlyArray; + items: ReadonlyArray<{ id?: string; title: string; description?: string; @@ -674,7 +674,7 @@ type ButtonProps = { type ActionsSheetProps = { title?: string; subtitle?: string; - description?: string | Array; + description?: string | ReadonlyArray; button: ButtonProps; secondaryButton?: ButtonProps; buttonLink?: ButtonProps & {withChevron?: boolean}; diff --git a/src/slider.tsx b/src/slider.tsx index aeb523ff4d..3778dd0027 100644 --- a/src/slider.tsx +++ b/src/slider.tsx @@ -32,7 +32,7 @@ interface BaseSliderProps { } interface SliderWithValuesProps { - values: Array; + values: ReadonlyArray; } interface SliderWithStepProps { @@ -69,7 +69,7 @@ const getValueInRange = (isPercentage: boolean, min: number, max: number, step: : valueRoundedDown; }; -const getClosestValidValue = (min: number, value?: number, values?: Array) => { +const getClosestValidValue = (min: number, value?: number, values?: ReadonlyArray) => { if (!values) { return value; }