Files
tabler/shared/components/cards/UsersList.astro

71 lines
2.4 KiB
Plaintext

---
import Avatar from '@ui/Avatar.astro'
import { people } from '@shared/lib/people'
import Icon from '@ui/Icon.astro'
import ListGroup from '@ui/ListGroup.astro'
import ListGroupItem from '@ui/ListGroupItem.astro'
import CardTitle from '@ui/CardTitle.astro'
import commits from '@data/commits.json'
import { randomNumber } from '@shared/lib/pseudo-random'
interface Props {
offset?: number
hoverable?: boolean
checkbox?: boolean
/** 1-based indices of the checked rows, e.g. [2, 5, 8] */
checkedIds?: number[]
title?: string
class?: string
}
const { offset = 0, hoverable = false, checkbox = false, checkedIds, title = 'Last commits', class: className } = Astro.props
const limit = 8
const colors = ['green', 'red', 'yellow', 'x', 'x']
const commitList = commits as { description: string }[]
const rows = people.slice(offset, offset + limit).map((person, idx) => {
const index = idx + 1
const color = colors[randomNumber(index + 5, 0, colors.length - 1)]
const checked = checkedIds?.includes(index) ?? false
const i = index + offset
return {
person,
color,
checked,
description: commitList[i]?.description,
starColor: checked ? 'text-yellow' : 'text-secondary',
}
})
---
<div class={`card${className ? ` ${className}` : ''}`}>
<div class="card-header">
<CardTitle>{title}</CardTitle>
</div>
<ListGroup flush hoverable={hoverable} selectable={checkbox}>
{
rows.map((row) => (
<ListGroupItem active={!checkbox && row.checked} showActions={row.checked}>
<Fragment slot="media">
{checkbox ? <input type="checkbox" class="form-check-input list-group-selectable-check m-0" checked={row.checked} aria-label={`Select ${row.person.full_name}`} /> : <span class={`badge${row.color !== 'x' ? ` bg-${row.color}` : ''}`} />}
<a href="#" class="ms-3" tabindex="-1" aria-hidden="true">
<Avatar person={row.person} />
</a>
</Fragment>
<a href="#" class="list-group-item-title">
{row.person.full_name}
</a>
<div class="list-group-item-description">{row.description}</div>
{hoverable && (
<a href="#" slot="actions" aria-label={row.checked ? 'Remove from favorites' : 'Add to favorites'}>
<Icon name="star" class={row.starColor} />
</a>
)}
</ListGroupItem>
))
}
</ListGroup>
</div>