// @flow // $FlowIssue import React, { useState, useRef } from 'react'; import { AppsContainer, SectionHeading, ExpandContainer, ExpandContent } from './style'; import { Button } from '../Button'; import type { ChecklistResource } from '../../types'; import { AppRow } from './App'; type Props = { resource: ChecklistResource, handleAppsExpand: Function, }; export const Apps = ({ resource, handleAppsExpand }: Props) => { const [overflowExpanded, setOverflowExpanded] = useState(false); const [contentHeight, setcontentHeight] = useState(2000); const expandContentContainer = useRef(null); function handleExpand() { let expandContentHeight = expandContentContainer.current ? expandContentContainer.current.scrollHeight : contentHeight; setcontentHeight(expandContentHeight) setOverflowExpanded(!overflowExpanded) handleAppsExpand(overflowExpanded ? -expandContentHeight : expandContentHeight); } if (!resource.apps) return null; let appList = resource.apps; let overflowAppList; if (appList && appList.length > 3) { overflowAppList = appList.slice(3, appList.length); appList = appList.slice(0, 3); } return ( Apps {appList && appList.map(app => ( ))} {overflowAppList && ( {overflowAppList.map(app => )} )} ); };