diff --git a/packages/ui-components/src/components/List/List.tsx b/packages/ui-components/src/components/List/List.tsx deleted file mode 100644 index 78f55dc66e..0000000000 --- a/packages/ui-components/src/components/List/List.tsx +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Tupaia - * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd - */ - -import React from 'react'; -import { List as MuiList } from '@material-ui/core'; -import { ListItem as Item, ListItemType } from './ListItem'; - -interface SelectListProps { - items?: ListItemType[]; - onSelect: (item: ListItemType) => void; - ListItem?: React.ElementType; -} - -export const List = ({ items, onSelect, ListItem = Item }: SelectListProps) => { - return ( - - {items?.map(item => ( - - {item?.children && } - - ))} - - ); -}; diff --git a/packages/ui-components/src/components/List/ListItem.tsx b/packages/ui-components/src/components/List/ListItem.tsx deleted file mode 100644 index 866fe36c1e..0000000000 --- a/packages/ui-components/src/components/List/ListItem.tsx +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Tupaia - * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd - */ - -import React, { ReactElement, ReactNode, useState } from 'react'; -import styled from 'styled-components'; -import { - Collapse, - ListItem as MuiListItem, - ListItemProps as MuiListItemProps, -} from '@material-ui/core'; -import { Check, KeyboardArrowRight } from '@material-ui/icons'; -import { Tooltip } from '../Tooltip'; - -// explicitly set the types so that the overrides are applied, for the `button` prop -export const BaseListItem = styled(MuiListItem)` - display: flex; - align-items: center; - border: 1px solid transparent; - border-radius: 3px; - padding: 0.3rem 1rem 0.3rem 0.5rem; - &.Mui-selected { - border-color: ${({ theme }) => theme.palette.primary.main}; - background-color: transparent; - } - .MuiCollapse-container & { - padding-left: 1rem; - } - &.MuiButtonBase-root { - &:hover, - &.Mui-selected:hover, - &:focus, - &.Mui-selected:focus { - background-color: ${({ theme }) => theme.palette.primary.main}33; - } - } - .MuiSvgIcon-root { - font-size: 1rem; - } - &.Mui-disabled { - opacity: 1; // still have the icon as the full opacity - color: ${({ theme }) => theme.palette.text.disabled}; - } - .text-secondary { - color: ${({ theme }) => theme.palette.text.secondary}; - margin-left: 0.4em; - } -`; - -const Arrow = styled(KeyboardArrowRight)<{ - $open?: boolean; -}>` - transform: ${({ $open }) => ($open ? 'rotate(90deg)' : 'rotate(0deg)')}; - transition: transform 0.1s ease-in-out; -`; - -const ButtonContainer = styled.div<{ - $fullWidth?: boolean; -}>` - display: flex; - align-items: center; - width: ${({ $fullWidth }) => ($fullWidth ? '100%' : 'auto')}; -`; - -const IconWrapper = styled.div` - padding-right: 0.5rem; - display: flex; - align-items: center; - width: 1.5rem; - svg { - color: ${({ theme }) => theme.palette.primary.main}; - height: auto; - } -`; - -export type ListItemType = Record & { - children?: ListItemType[]; - content: string | ReactNode; - value: string; - selected?: boolean; - icon?: ReactNode; - tooltip?: string; - button?: boolean; - disabled?: boolean; -}; - -interface ListItemProps { - item: ListItemType; - children?: ReactNode; - onSelect: (item: ListItemType) => void; -} - -const Wrapper = ({ - children, - tooltip, -}: { - children: ReactElement; - tooltip: ListItemType['tooltip']; -}) => { - if (tooltip) { - return ( - - {children} - - ); - } - return <>{children}; -}; - -export const ListItem = ({ item, children, onSelect }: ListItemProps) => { - const [open, setOpen] = useState(false); - const { content, selected, icon, tooltip, button = true, disabled } = item; - const isNested = !!item.children; - - const toggleOpen = () => { - setOpen(!open); - }; - - const onClick = () => { - if (isNested) { - return toggleOpen(); - } - return onSelect(item); - }; - - return ( -
  • - {/*@ts-ignore*/} - - - - {icon} - {content} - {isNested && } - - - {selected && } - - {isNested && {children}} -
  • - ); -}; diff --git a/packages/ui-components/src/components/List/SelectList.tsx b/packages/ui-components/src/components/List/SelectList.tsx deleted file mode 100644 index 409b8759c7..0000000000 --- a/packages/ui-components/src/components/List/SelectList.tsx +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Tupaia - * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd - */ - -import React from 'react'; -import styled, { css } from 'styled-components'; -import { FormLabel, Typography } from '@material-ui/core'; -import { ListItemType } from './ListItem'; -import { List } from './List'; - -const Wrapper = styled.div` - padding: 0; - height: 100%; - overflow-y: hidden; - display: flex; - flex-direction: column; - flex: 1; -`; - -const FullBorder = css` - border: 1px solid ${({ theme }) => theme.palette.divider}; - border-radius: 3px; - padding: 0 1rem; -`; - -const TopBorder = css` - border-top: 1px solid ${({ theme }) => theme.palette.divider}; - border-radius: 0; - padding: 0.5rem 0; -`; - -const ListWrapper = styled.div<{ - $variant: string; -}>` - overflow-y: auto; - max-height: 100%; - ${({ $variant }) => ($variant === 'fullPage' ? TopBorder : FullBorder)}; - flex: 1; - height: 100%; -`; - -const NoResultsMessage = styled(Typography)` - padding: 0.8rem 0.5rem; - font-size: 0.875rem; - color: ${({ theme }) => theme.palette.text.secondary}; -`; - -const Label = styled(FormLabel).attrs({ - component: 'h2', -})` - margin-bottom: 1rem; - font-size: 0.875rem; - color: ${({ theme }) => theme.palette.text.secondary}; - font-weight: 400; -`; -interface SelectListProps { - items?: ListItemType[]; - onSelect: (item: ListItemType) => void; - label?: string; - ListItem?: React.ElementType; - variant?: 'fullPage' | 'inline'; -} - -export const SelectList = ({ - items = [], - onSelect, - label, - ListItem, - variant = 'inline', -}: SelectListProps) => { - return ( - - {label && } - - {items.length === 0 ? ( - No items to display - ) : ( - - )} - - - ); -}; diff --git a/packages/ui-components/src/components/List/index.ts b/packages/ui-components/src/components/List/index.ts deleted file mode 100644 index fec041cb2e..0000000000 --- a/packages/ui-components/src/components/List/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Tupaia - * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd - */ - -export { List } from './List'; -export { ListItem } from './ListItem'; -export { SelectList } from './SelectList';