Commit f17360fa authored by tom's avatar tom

refactor Select usage

parent 7025b758
...@@ -178,11 +178,12 @@ export interface SelectProps extends SelectRootProps { ...@@ -178,11 +178,12 @@ export interface SelectProps extends SelectRootProps {
collection: ListCollection<CollectionItem>; collection: ListCollection<CollectionItem>;
placeholder: string; placeholder: string;
portalled?: boolean; portalled?: boolean;
loading?: boolean;
} }
// TODO @tom2drum refactor selects // TODO @tom2drum refactor selects
export const Select = React.forwardRef<HTMLDivElement, SelectProps>((props, ref) => { export const Select = React.forwardRef<HTMLDivElement, SelectProps>((props, ref) => {
const { collection, placeholder, portalled = true, ...rest } = props; const { collection, placeholder, portalled = true, loading, ...rest } = props;
return ( return (
<SelectRoot <SelectRoot
ref={ ref } ref={ ref }
...@@ -190,7 +191,7 @@ export const Select = React.forwardRef<HTMLDivElement, SelectProps>((props, ref) ...@@ -190,7 +191,7 @@ export const Select = React.forwardRef<HTMLDivElement, SelectProps>((props, ref)
variant="outline" variant="outline"
{ ...rest } { ...rest }
> >
<SelectControl> <SelectControl loading={ loading }>
<SelectValueText placeholder={ placeholder }/> <SelectValueText placeholder={ placeholder }/>
</SelectControl> </SelectControl>
<SelectContent portalled={ portalled }> <SelectContent portalled={ portalled }>
......
...@@ -3,7 +3,7 @@ import React from 'react'; ...@@ -3,7 +3,7 @@ import React from 'react';
import { route } from 'nextjs-routes'; import { route } from 'nextjs-routes';
import { SelectContent, SelectControl, SelectItem, SelectRoot, SelectValueText } from 'toolkit/chakra/select'; import { Select } from 'toolkit/chakra/select';
import { Skeleton } from 'toolkit/chakra/skeleton'; import { Skeleton } from 'toolkit/chakra/skeleton';
import CopyToClipboard from 'ui/shared/CopyToClipboard'; import CopyToClipboard from 'ui/shared/CopyToClipboard';
import AddressEntity from 'ui/shared/entities/address/AddressEntity'; import AddressEntity from 'ui/shared/entities/address/AddressEntity';
...@@ -59,23 +59,14 @@ const ContractSourceAddressSelector = ({ className, selectedItem, onItemSelect, ...@@ -59,23 +59,14 @@ const ContractSourceAddressSelector = ({ className, selectedItem, onItemSelect,
return ( return (
<Flex columnGap={ 3 } rowGap={ 2 } alignItems="center" className={ className }> <Flex columnGap={ 3 } rowGap={ 2 } alignItems="center" className={ className }>
<chakra.span fontWeight={ 500 } fontSize="sm">{ label }</chakra.span> <chakra.span fontWeight={ 500 } fontSize="sm">{ label }</chakra.span>
<SelectRoot <Select
collection={ collection } collection={ collection }
variant="outline" placeholder="Select contract"
defaultValue={ [ selectedItem.address ] } defaultValue={ [ selectedItem.address ] }
onValueChange={ handleItemSelect } onValueChange={ handleItemSelect }
> maxW={{ base: '180px', lg: 'none' }}
<SelectControl maxW={{ base: '180px', lg: 'none' }} loading={ isLoading }> loading={ isLoading }
<SelectValueText placeholder="Select contract"/> />
</SelectControl>
<SelectContent>
{ collection.items.map((item) => (
<SelectItem item={ item } key={ item.value }>
{ item.label }
</SelectItem>
)) }
</SelectContent>
</SelectRoot>
<Flex columnGap={ 2 } alignItems="center"> <Flex columnGap={ 2 } alignItems="center">
<CopyToClipboard text={ selectedItem.address } ml={ 0 }/> <CopyToClipboard text={ selectedItem.address } ml={ 0 }/>
<LinkNewTab <LinkNewTab
......
...@@ -9,7 +9,7 @@ import hexToBase64 from 'lib/hexToBase64'; ...@@ -9,7 +9,7 @@ import hexToBase64 from 'lib/hexToBase64';
import hexToBytes from 'lib/hexToBytes'; import hexToBytes from 'lib/hexToBytes';
import hexToUtf8 from 'lib/hexToUtf8'; import hexToUtf8 from 'lib/hexToUtf8';
import { Button } from 'toolkit/chakra/button'; import { Button } from 'toolkit/chakra/button';
import { SelectContent, SelectItem, SelectRoot, SelectControl, SelectValueText } from 'toolkit/chakra/select'; import { Select } from 'toolkit/chakra/select';
import { Skeleton } from 'toolkit/chakra/skeleton'; import { Skeleton } from 'toolkit/chakra/skeleton';
import CopyToClipboard from 'ui/shared/CopyToClipboard'; import CopyToClipboard from 'ui/shared/CopyToClipboard';
import RawDataSnippet from 'ui/shared/RawDataSnippet'; import RawDataSnippet from 'ui/shared/RawDataSnippet';
...@@ -115,23 +115,15 @@ const BlobData = ({ data, isLoading, hash }: Props) => { ...@@ -115,23 +115,15 @@ const BlobData = ({ data, isLoading, hash }: Props) => {
<Skeleton fontWeight={{ base: 700, lg: 500 }} loading={ isLoading }> <Skeleton fontWeight={{ base: 700, lg: 500 }} loading={ isLoading }>
Blob data Blob data
</Skeleton> </Skeleton>
<SelectRoot <Select
collection={ collection } collection={ collection }
variant="outline" placeholder="Select type"
value={ [ format ] } defaultValue={ [ format ] }
onValueChange={ handleFormatChange } onValueChange={ handleFormatChange }
> ml={ 5 }
<SelectControl loading={ isLoading } ml={ 5 } w="100px"> w="100px"
<SelectValueText placeholder="Select framework"/> loading={ isLoading }
</SelectControl> />
<SelectContent>
{ collection.items.map((item) => (
<SelectItem item={ item } key={ item.value }>
{ item.label }
</SelectItem>
)) }
</SelectContent>
</SelectRoot>
<Skeleton ml="auto" mr={ 3 } loading={ isLoading }> <Skeleton ml="auto" mr={ 3 } loading={ isLoading }>
<Button <Button
variant="outline" variant="outline"
......
...@@ -17,7 +17,7 @@ import * as mixpanel from 'lib/mixpanel/index'; ...@@ -17,7 +17,7 @@ import * as mixpanel from 'lib/mixpanel/index';
import getQueryParamString from 'lib/router/getQueryParamString'; import getQueryParamString from 'lib/router/getQueryParamString';
import { Button } from 'toolkit/chakra/button'; import { Button } from 'toolkit/chakra/button';
import { IconButton } from 'toolkit/chakra/icon-button'; import { IconButton } from 'toolkit/chakra/icon-button';
import { SelectContent, SelectControl, SelectItem, SelectRoot, SelectValueText } from 'toolkit/chakra/select'; import { Select } from 'toolkit/chakra/select';
import { Skeleton } from 'toolkit/chakra/skeleton'; import { Skeleton } from 'toolkit/chakra/skeleton';
import isCustomAppError from 'ui/shared/AppError/isCustomAppError'; import isCustomAppError from 'ui/shared/AppError/isCustomAppError';
import ChartIntervalSelect from 'ui/shared/chart/ChartIntervalSelect'; import ChartIntervalSelect from 'ui/shared/chart/ChartIntervalSelect';
...@@ -201,24 +201,14 @@ const Chart = () => { ...@@ -201,24 +201,14 @@ const Chart = () => {
<Skeleton loading={ isInfoLoading }> <Skeleton loading={ isInfoLoading }>
{ isMobile ? 'Res.' : 'Resolution' } { isMobile ? 'Res.' : 'Resolution' }
</Skeleton> </Skeleton>
<SelectRoot <Select
collection={ resolutionCollection } collection={ resolutionCollection }
variant="outline" placeholder="Select resolution"
defaultValue={ [ defaultResolution ] } defaultValue={ [ defaultResolution ] }
onValueChange={ onResolutionChange } onValueChange={ onResolutionChange }
w={{ base: 'fit-content', lg: '160px' }} w={{ base: 'fit-content', lg: '160px' }}
> loading={ isInfoLoading }
<SelectControl loading={ isInfoLoading }> />
<SelectValueText placeholder="Select resolution"/>
</SelectControl>
<SelectContent>
{ resolutionCollection.items.map((item) => (
<SelectItem item={ item } key={ item.value }>
{ item.label }
</SelectItem>
)) }
</SelectContent>
</SelectRoot>
</Flex> </Flex>
) } ) }
{ (Boolean(zoomRange)) && ( { (Boolean(zoomRange)) && (
......
...@@ -2,7 +2,7 @@ import { createListCollection } from '@chakra-ui/react'; ...@@ -2,7 +2,7 @@ import { createListCollection } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import hexToUtf8 from 'lib/hexToUtf8'; import hexToUtf8 from 'lib/hexToUtf8';
import { SelectItem, SelectContent, SelectValueText, SelectRoot, SelectControl } from 'toolkit/chakra/select'; import { Select } from 'toolkit/chakra/select';
import RawDataSnippet from 'ui/shared/RawDataSnippet'; import RawDataSnippet from 'ui/shared/RawDataSnippet';
const OPTIONS = [ const OPTIONS = [
...@@ -33,26 +33,15 @@ const RawInputData = ({ hex, rightSlot: rightSlotProp, defaultDataType = 'Hex', ...@@ -33,26 +33,15 @@ const RawInputData = ({ hex, rightSlot: rightSlotProp, defaultDataType = 'Hex',
const rightSlot = ( const rightSlot = (
<> <>
<SelectRoot <Select
name="data-type"
collection={ collection } collection={ collection }
variant="outline" placeholder="Select type"
defaultValue={ [ defaultDataType ] } defaultValue={ [ defaultDataType ] }
onValueChange={ handleValueChange } onValueChange={ handleValueChange }
w="100px" w="100px"
mr="auto" mr="auto"
> loading={ isLoading }
<SelectControl loading={ isLoading }> />
<SelectValueText placeholder="Select type"/>
</SelectControl>
<SelectContent>
{ collection.items.map((item) => (
<SelectItem item={ item } key={ item.value }>
{ item.label }
</SelectItem>
)) }
</SelectContent>
</SelectRoot>
{ rightSlotProp } { rightSlotProp }
</> </>
); );
......
...@@ -3,7 +3,7 @@ import React from 'react'; ...@@ -3,7 +3,7 @@ import React from 'react';
import type { StatsInterval, StatsIntervalIds } from 'types/client/stats'; import type { StatsInterval, StatsIntervalIds } from 'types/client/stats';
import { SelectContent, SelectControl, SelectItem, SelectRoot, SelectValueText } from 'toolkit/chakra/select'; import { Select } from 'toolkit/chakra/select';
import { Skeleton } from 'toolkit/chakra/skeleton'; import { Skeleton } from 'toolkit/chakra/skeleton';
import type { TagProps } from 'toolkit/chakra/tag'; import type { TagProps } from 'toolkit/chakra/tag';
import TagGroupSelect from 'ui/shared/tagGroupSelect/TagGroupSelect'; import TagGroupSelect from 'ui/shared/tagGroupSelect/TagGroupSelect';
...@@ -12,7 +12,7 @@ import { STATS_INTERVALS } from 'ui/stats/constants'; ...@@ -12,7 +12,7 @@ import { STATS_INTERVALS } from 'ui/stats/constants';
const intervalCollection = createListCollection({ const intervalCollection = createListCollection({
items: Object.keys(STATS_INTERVALS).map((id: string) => ({ items: Object.keys(STATS_INTERVALS).map((id: string) => ({
value: id, value: id,
label: STATS_INTERVALS[id as StatsIntervalIds].shortTitle, label: STATS_INTERVALS[id as StatsIntervalIds].title,
})), })),
}); });
...@@ -39,25 +39,15 @@ const ChartIntervalSelect = ({ interval, onIntervalChange, isLoading, selectTagS ...@@ -39,25 +39,15 @@ const ChartIntervalSelect = ({ interval, onIntervalChange, isLoading, selectTagS
<Skeleton hideBelow="lg" borderRadius="base" loading={ isLoading }> <Skeleton hideBelow="lg" borderRadius="base" loading={ isLoading }>
<TagGroupSelect<StatsIntervalIds> items={ intervalListShort } onChange={ onIntervalChange } value={ interval } tagSize={ selectTagSize }/> <TagGroupSelect<StatsIntervalIds> items={ intervalListShort } onChange={ onIntervalChange } value={ interval } tagSize={ selectTagSize }/>
</Skeleton> </Skeleton>
<SelectRoot <Select
collection={ intervalCollection } collection={ intervalCollection }
variant="outline" placeholder="Select interval"
defaultValue={ [ interval ] } defaultValue={ [ interval ] }
onValueChange={ handleItemSelect } onValueChange={ handleItemSelect }
hideFrom="lg" hideFrom="lg"
w="100%" w="100%"
> loading={ isLoading }
<SelectControl loading={ isLoading }> />
<SelectValueText placeholder="Select interval"/>
</SelectControl>
<SelectContent>
{ intervalCollection.items.map((item) => (
<SelectItem item={ item } key={ item.value }>
{ item.label }
</SelectItem>
)) }
</SelectContent>
</SelectRoot>
</> </>
); );
}; };
......
...@@ -4,7 +4,7 @@ import React from 'react'; ...@@ -4,7 +4,7 @@ import React from 'react';
import type * as stats from '@blockscout/stats-types'; import type * as stats from '@blockscout/stats-types';
import type { StatsIntervalIds } from 'types/client/stats'; import type { StatsIntervalIds } from 'types/client/stats';
import { SelectContent, SelectControl, SelectItem, SelectRoot, SelectValueText } from 'toolkit/chakra/select'; import { Select } from 'toolkit/chakra/select';
import ChartIntervalSelect from 'ui/shared/chart/ChartIntervalSelect'; import ChartIntervalSelect from 'ui/shared/chart/ChartIntervalSelect';
import FilterInput from 'ui/shared/filters/FilterInput'; import FilterInput from 'ui/shared/filters/FilterInput';
...@@ -58,24 +58,14 @@ const StatsFilters = ({ ...@@ -58,24 +58,14 @@ const StatsFilters = ({
w={{ base: '100%', lg: 'auto' }} w={{ base: '100%', lg: 'auto' }}
area="section" area="section"
> >
<SelectRoot <Select
collection={ collection } collection={ collection }
variant="outline" placeholder="Select section"
defaultValue={ [ currentSection ] } defaultValue={ [ currentSection ] }
onValueChange={ handleItemSelect } onValueChange={ handleItemSelect }
w={{ base: '100%', lg: '136px' }} w={{ base: '100%', lg: '136px' }}
> loading={ isLoading }
<SelectControl loading={ isLoading }> />
<SelectValueText placeholder="Select section"/>
</SelectControl>
<SelectContent>
{ collection.items.map((item) => (
<SelectItem item={ item } key={ item.value }>
{ item.label }
</SelectItem>
)) }
</SelectContent>
</SelectRoot>
</GridItem> </GridItem>
<GridItem <GridItem
......
...@@ -4,7 +4,7 @@ import React from 'react'; ...@@ -4,7 +4,7 @@ import React from 'react';
import type { TokenInstance } from 'types/api/token'; import type { TokenInstance } from 'types/api/token';
import { Alert } from 'toolkit/chakra/alert'; import { Alert } from 'toolkit/chakra/alert';
import { SelectContent, SelectControl, SelectItem, SelectRoot, SelectValueText } from 'toolkit/chakra/select'; import { Select } from 'toolkit/chakra/select';
import ContentLoader from 'ui/shared/ContentLoader'; import ContentLoader from 'ui/shared/ContentLoader';
import CopyToClipboard from 'ui/shared/CopyToClipboard'; import CopyToClipboard from 'ui/shared/CopyToClipboard';
import RawDataSnippet from 'ui/shared/RawDataSnippet'; import RawDataSnippet from 'ui/shared/RawDataSnippet';
...@@ -56,24 +56,14 @@ const TokenInstanceMetadata = ({ data, isPlaceholderData }: Props) => { ...@@ -56,24 +56,14 @@ const TokenInstanceMetadata = ({ data, isPlaceholderData }: Props) => {
) } ) }
<Flex alignItems="center" mb={ 6 }> <Flex alignItems="center" mb={ 6 }>
<chakra.span fontWeight={ 500 }>Metadata</chakra.span> <chakra.span fontWeight={ 500 }>Metadata</chakra.span>
<SelectRoot <Select
collection={ collection } collection={ collection }
variant="outline" placeholder="Select type"
defaultValue={ [ format ] }
onValueChange={ handleValueChange } onValueChange={ handleValueChange }
value={ [ format ] }
ml={ 5 } ml={ 5 }
> w="100px"
<SelectControl w="100px"> />
<SelectValueText placeholder="Select format"/>
</SelectControl>
<SelectContent>
{ collection.items.map((item) => (
<SelectItem item={ item } key={ item.value }>
{ item.label }
</SelectItem>
)) }
</SelectContent>
</SelectRoot>
{ format === 'JSON' && <CopyToClipboard text={ JSON.stringify(data) } ml="auto"/> } { format === 'JSON' && <CopyToClipboard text={ JSON.stringify(data) } ml="auto"/> }
</Flex> </Flex>
{ content } { content }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment