Skip to content

Commit a53eae7

Browse files
committed
Add CellList component
1 parent b767b94 commit a53eae7

File tree

1 file changed

+81
-0
lines changed
  • gui/src/renderer/components/cell

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import React, { useCallback } from 'react';
2+
import styled from 'styled-components';
3+
import { colors } from '../../../config.json';
4+
import ImageView from '../ImageView';
5+
import * as Cell from '.';
6+
7+
export interface ICellListItem<T> {
8+
label: string;
9+
value: T;
10+
}
11+
12+
interface ICellListProps<T> {
13+
title?: string;
14+
items: Array<ICellListItem<T>>;
15+
onSelect?: (value: T) => void;
16+
onRemove?: (value: T) => void;
17+
className?: string;
18+
paddingLeft?: number;
19+
}
20+
21+
export default function CellList<T>(props: ICellListProps<T>) {
22+
const paddingLeft = props.paddingLeft ?? 32;
23+
24+
return (
25+
<Cell.Section role="listbox" className={props.className}>
26+
{props.title && <Cell.SectionTitle as="label">{props.title}</Cell.SectionTitle>}
27+
{props.items.map((item, i) => {
28+
return (
29+
<CellListItem
30+
key={`${i}-${item.value}`}
31+
value={item.value}
32+
onSelect={props.onSelect}
33+
onRemove={props.onRemove}
34+
paddingLeft={paddingLeft}>
35+
{item.label}
36+
</CellListItem>
37+
);
38+
})}
39+
</Cell.Section>
40+
);
41+
}
42+
43+
const StyledLabel = styled(Cell.Label)({}, (props: { paddingLeft: number }) => ({
44+
fontFamily: 'Open Sans',
45+
fontWeight: 'normal',
46+
fontSize: '16px',
47+
paddingLeft: props.paddingLeft + 'px',
48+
whiteSpace: 'pre-wrap',
49+
overflowWrap: 'break-word',
50+
width: '171px',
51+
marginRight: '25px',
52+
}));
53+
54+
interface ICellListItemProps<T> {
55+
value: T;
56+
onSelect?: (application: T) => void;
57+
onRemove?: (application: T) => void;
58+
paddingLeft: number;
59+
children: string;
60+
}
61+
62+
function CellListItem<T>(props: ICellListItemProps<T>) {
63+
const onSelect = useCallback(() => props.onSelect?.(props.value), [props.onSelect, props.value]);
64+
const onRemove = useCallback(() => props.onRemove?.(props.value), [props.onRemove, props.value]);
65+
66+
return (
67+
<Cell.CellButton onClick={props.onSelect ? onSelect : undefined}>
68+
<StyledLabel paddingLeft={props.paddingLeft}>{props.children}</StyledLabel>
69+
{props.onRemove && (
70+
<ImageView
71+
source="icon-close"
72+
width={22}
73+
height={22}
74+
onClick={onRemove}
75+
tintColor={colors.white60}
76+
tintHoverColor={colors.white80}
77+
/>
78+
)}
79+
</Cell.CellButton>
80+
);
81+
}

0 commit comments

Comments
 (0)