diff --git a/packages/core/admin/package.json b/packages/core/admin/package.json index b9e6804a3a..1035cd798a 100644 --- a/packages/core/admin/package.json +++ b/packages/core/admin/package.json @@ -119,7 +119,7 @@ "react-refresh": "0.11.0", "react-router": "5.2.0", "react-router-dom": "5.2.0", - "react-virtualized": "^9.22.3", + "react-window": "1.8.7", "redux": "^4.0.1", "redux-saga": "^0.16.0", "reselect": "^4.0.0", diff --git a/packages/core/admin/webpack.alias.js b/packages/core/admin/webpack.alias.js index 827483b2b5..737a914286 100644 --- a/packages/core/admin/webpack.alias.js +++ b/packages/core/admin/webpack.alias.js @@ -28,7 +28,7 @@ const aliasExactMatch = [ 'react-redux', 'react-router', 'react-router-dom', - 'react-virtualized', + 'react-window', 'react-select', 'redux', 'reselect', diff --git a/packages/core/content-type-builder/admin/src/components/ComponentIconPicker/index.js b/packages/core/content-type-builder/admin/src/components/ComponentIconPicker/index.js index ea0f0177b9..c4a0b925d3 100644 --- a/packages/core/content-type-builder/admin/src/components/ComponentIconPicker/index.js +++ b/packages/core/content-type-builder/admin/src/components/ComponentIconPicker/index.js @@ -1,7 +1,7 @@ import React, { useEffect, useState, useRef } from 'react'; import PropTypes from 'prop-types'; import { useIntl } from 'react-intl'; -import { AutoSizer, Collection } from 'react-virtualized'; +import { FixedSizeGrid } from 'react-window'; import { Searchbar } from '@strapi/design-system/Searchbar'; import { IconButton } from '@strapi/design-system/IconButton'; import Search from '@strapi/icons/Search'; @@ -10,11 +10,14 @@ import { Box } from '@strapi/design-system/Box'; import { Flex } from '@strapi/design-system/Flex'; import { Stack } from '@strapi/design-system/Stack'; import { Typography } from '@strapi/design-system/Typography'; + +import { getIndexFromColAndRow } from './utils/getIndexFromColAndRow'; import useDataManager from '../../hooks/useDataManager'; import getTrad from '../../utils/getTrad'; import Cell from './Cell'; -const CELL_WIDTH = 44; +const CELL_WIDTH = 42; +const COLUMN_COUNT = 18; const ComponentIconPicker = ({ error, intlLabel, name, onChange, value }) => { const { allIcons } = useDataManager(); @@ -37,26 +40,32 @@ const ComponentIconPicker = ({ error, intlLabel, name, onChange, value }) => { setIcons(() => allIcons.filter(icon => icon.includes(value))); }; - const errorMessage = error ? formatMessage({ id: error, defaultMessage: error }) : ''; + // eslint-disable-next-line react/prop-types + const IconRenderer = ({ columnIndex, rowIndex, style }) => { + const icon = icons[getIndexFromColAndRow(columnIndex, rowIndex, COLUMN_COUNT)]; - const cellSizeAndPositionGetter = ({ index }) => { - const columnCount = 16; - const columnPosition = index % (columnCount || 1); - - const height = CELL_WIDTH; - const width = CELL_WIDTH; - const x = columnPosition * (width + 1); - const y = parseInt(index / 16, 10) * CELL_WIDTH; - - return { - height, - width, - x, - y, - }; + return ( +