Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): add SelectRecipients component
- Loading branch information
1 parent
21cf662
commit 0e624f5
Showing
8 changed files
with
290 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { makeStyles } from '@material-ui/core' | ||
import Chip, { ChipProps } from '@material-ui/core/Chip' | ||
|
||
export interface ClickableChipProps { | ||
ChipProps?: ChipProps | ||
} | ||
|
||
const useStyles = makeStyles({ | ||
root: { | ||
marginRight: 6, | ||
marginBottom: 6, | ||
cursor: 'pointer', | ||
}, | ||
}) | ||
|
||
export function ClickableChip(props: ClickableChipProps) { | ||
const classes = useStyles() | ||
|
||
return <Chip className={classes.root} {...props.ChipProps} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import Chip, { ChipProps } from '@material-ui/core/Chip' | ||
import { Group } from '../../../database' | ||
import DoneIcon from '@material-ui/icons/Done' | ||
import { useResolveSpecialGroupName } from '../SelectPeopleAndGroups/resolveSpecialGroupName' | ||
import { makeStyles } from '@material-ui/styles' | ||
|
||
export interface GroupInChipProps { | ||
item: Group | ||
selected?: boolean | ||
disabled?: boolean | ||
onClick?(): void | ||
ChipProps?: ChipProps | ||
} | ||
|
||
const useStyles = makeStyles({ | ||
root: { | ||
marginRight: 6, | ||
marginBottom: 6, | ||
cursor: 'pointer', | ||
}, | ||
}) | ||
|
||
export function GroupInChip(props: GroupInChipProps) { | ||
const classes = useStyles() | ||
const { selected, onClick } = props | ||
const group = props.item | ||
|
||
return ( | ||
<Chip | ||
className={classes.root} | ||
avatar={selected ? <DoneIcon /> : undefined} | ||
color={selected ? 'primary' : 'default'} | ||
onClick={onClick} | ||
label={useResolveSpecialGroupName(group)} | ||
{...props.ChipProps} | ||
/> | ||
) | ||
} |
65 changes: 65 additions & 0 deletions
65
src/components/shared/SelectRecipients/SelectRecipients.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Group, Person } from '../../../database' | ||
import { makeStyles, Box } from '@material-ui/core' | ||
import { PersonOrGroupInListProps } from '../SelectPeopleAndGroups' | ||
import { GroupInChipProps, GroupInChip } from './GroupInChip' | ||
import { PersonIdentifier, GroupIdentifier } from '../../../database/type' | ||
import AddIcon from '@material-ui/icons/Add' | ||
import { ClickableChip } from './ClickableChip' | ||
|
||
export interface SelectRecipientsProps<T extends Group | Person = Group | Person> | ||
extends withClasses<KeysInferFromUseStyles<typeof useStyles> | 'root'> { | ||
/** Omit myself in the UI and the selected result */ | ||
ignoreMyself?: boolean | ||
items: T[] | ||
selected: T[] | ||
// frozenSelected: T[] | ||
disabled?: boolean | ||
hideSelectAll?: boolean | ||
hideSelectNone?: boolean | ||
showAtNetwork?: boolean | ||
maxSelection?: number | ||
onSetSelected(selected: T[]): void | ||
GroupInChipProps?: Partial<GroupInChipProps> | ||
PersonOrGroupInListProps?: Partial<PersonOrGroupInListProps> | ||
} | ||
const useStyles = makeStyles({ | ||
root: {}, | ||
selectArea: { | ||
display: 'flex', | ||
flexWrap: 'wrap', | ||
}, | ||
}) | ||
export function SelectRecipientsUI<T extends Group | Person = Group | Person>(props: SelectRecipientsProps) { | ||
const classes = useStyles() | ||
const { items, onSetSelected } = props | ||
const groupItems = items.filter(item => isGroup(item)) as Group[] | ||
return ( | ||
<div className={classes.root}> | ||
<Box className={classes.selectArea} display="flex"> | ||
{groupItems.map(item => ( | ||
<GroupInChip | ||
key={item.identifier.toText()} | ||
item={item} | ||
disabled={false} | ||
onClick={() => {}} | ||
{...props.GroupInChipProps} | ||
/> | ||
))} | ||
<ClickableChip | ||
ChipProps={{ | ||
label: 'Specific Friends (12 selected)', | ||
avatar: <AddIcon />, | ||
onClick() {}, | ||
}} | ||
/> | ||
</Box> | ||
</div> | ||
) | ||
} | ||
|
||
export function isPerson(x: Person | Group): x is Person { | ||
return x.identifier instanceof PersonIdentifier | ||
} | ||
export function isGroup(x: Person | Group): x is Group { | ||
return x.identifier instanceof GroupIdentifier | ||
} |
3 changes: 3 additions & 0 deletions
3
src/components/shared/SelectSpecificFriends/SelectSpecificFriendsModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface SelectSpecificFriendsUIProps {} | ||
|
||
export function SelectSpecificFriendsUI() {} |
Oops, something went wrong.