-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathindex.tsx
More file actions
67 lines (60 loc) · 1.9 KB
/
index.tsx
File metadata and controls
67 lines (60 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { ChevronDownIcon, ClockIcon } from '@heroicons/react/24/outline';
import classNames from 'classnames';
import type { FC, ComponentProps } from 'react';
import type { LinkLike } from '#ui/types.js';
import styles from './index.module.css';
export type HistoryChange = {
versions: Array<string>;
label: string;
url?: string;
};
type ChangeHistoryProps = ComponentProps<'div'> & {
label: string;
changes: Array<HistoryChange>;
as?: LinkLike;
};
const ChangeHistory: FC<ChangeHistoryProps> = ({
label = 'History',
changes = [],
className,
as: As = 'a',
'aria-label': ariaLabel = label,
...props
}) => (
<div className={classNames('relative', 'inline-block', className)} {...props}>
<details className="group">
<summary className={styles.summary} role="button" aria-haspopup="menu">
<ClockIcon className="size-4" />
<span>{label}</span>
<ChevronDownIcon className="size-3 group-open:rotate-180 motion-safe:transition-transform" />
</summary>
<div
className={styles.dropdownContentWrapper}
role="menu"
aria-label={ariaLabel}
>
<div className={styles.dropdownContentInner}>
{changes.map((change, index) => {
const MenuItem = change.url ? As : 'div';
return (
<MenuItem
key={index}
className={styles.dropdownItem}
role="menuitem"
tabIndex={0}
aria-label={`${change.label}: ${change.versions.join(', ')}`}
href={change.url}
>
<div className={styles.dropdownLabel}>{change.label}</div>
<div className={styles.dropdownVersions}>
{change.versions.join(', ')}
</div>
</MenuItem>
);
})}
</div>
</div>
</details>
</div>
);
export default ChangeHistory;