react-icons/hi#HiViewGrid TypeScript Examples

The following examples show how to use react-icons/hi#HiViewGrid. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Items.tsx    From ksana.in with Apache License 2.0 4 votes vote down vote up
export function Items({ user, isFormVisible, onShowForm }: IUrlListProps) {
  const { data, isLoading = true } = useUrls(user?.id || '')
  const [searchText, setSearchText] = useState<string>('')
  const [view, setView] = useState<string>(VIEW.LIST)
  const [filteredData, setFilteredData] = useState<IUrl[]>(data)

  useEffect(() => {
    if (!isLoading) {
      if (searchText === '') {
        setFilteredData(data)
      } else if (searchText && searchText.length > 1) {
        const foundData = data.filter((d: IUrl) => {
          const containUrl = d.real_url.toLowerCase().includes(searchText.toLowerCase())
          const containSlug = d.slug.toLowerCase().includes(searchText.toLowerCase())
          return containSlug || containUrl
        })
        setFilteredData(foundData)
      }
    }
  }, [isLoading, searchText, data])

  if (isLoading) {
    return <LoadingSkeleton />
  }

  const handleSearch = (e: ChangeEvent<HTMLInputElement>) => {
    setSearchText(e.target.value)
  }

  const isGrid = view === VIEW.GRID
  const isList = view === VIEW.LIST

  const handleViewGrid = () => {
    setView(VIEW.GRID)
  }

  const handleViewList = () => {
    setView(VIEW.LIST)
  }

  return (
    <>
      {!isLoading && data && data.length > 0 ? (
        <>
          <TotalStats data={data} />
          <SearchInput onChangeSearch={handleSearch} searchText={searchText} />
          <Flex justifyContent="flex-end" alignItems="center">
            <ButtonGroup spacing="2" variant="outline">
              <IconButton
                variant="outline"
                borderColor={'orange.400'}
                color="orange.400"
                _hover={{
                  bg: 'orange.200'
                }}
                _focus={{
                  bg: 'orange.200'
                }}
                _active={{
                  bg: 'orange.400',
                  color: 'white'
                }}
                aria-label="View Grid"
                isActive={isGrid}
                onClick={handleViewGrid}
                icon={<HiViewGrid />}
              />
              <IconButton
                variant="outline"
                borderColor={'orange.400'}
                color="orange.400"
                _hover={{
                  bg: 'orange.200'
                }}
                _focus={{
                  bg: 'orange.200'
                }}
                _active={{
                  bg: 'orange.400',
                  color: 'white'
                }}
                aria-label="View List"
                isActive={isList}
                onClick={handleViewList}
                icon={<HiViewList />}
              />
            </ButtonGroup>
          </Flex>
          {filteredData.length > 0 ? (
            <SimpleGrid columns={isGrid ? 2 : 1} spacing={2}>
              {filteredData.map((urlItem: IUrl) => (
                <Item data={urlItem} user={user} key={urlItem.id} />
              ))}
            </SimpleGrid>
          ) : (
            <ErrorDataNotFound
              useCta={false}
              title="Tidak menemukan apapun nih, coba kata kunci lain!"
            />
          )}
        </>
      ) : (
        <>{!isFormVisible ? <ErrorDataNotFound useCta ctaAction={onShowForm} /> : null}</>
      )}
    </>
  )
}