@@ -2,6 +2,8 @@ import { ChevronDownIcon, ClockIcon } from '@heroicons/react/24/outline';
22import classNames from 'classnames' ;
33import type { FC , ComponentProps } from 'react' ;
44
5+ import type { LinkLike } from '#ui/types.js' ;
6+
57import styles from './index.module.css' ;
68
79export type HistoryChange = {
@@ -13,66 +15,52 @@ export type HistoryChange = {
1315type ChangeHistoryProps = ComponentProps < 'div' > & {
1416 label : string ;
1517 changes : Array < HistoryChange > ;
18+ as ?: LinkLike ;
1619} ;
1720
1821const ChangeHistory : FC < ChangeHistoryProps > = ( {
1922 label = 'History' ,
2023 changes = [ ] ,
2124 className,
25+ as : As = 'a' ,
2226 'aria-label' : ariaLabel = label ,
2327 ...props
24- } ) => {
25- if ( changes . length === 0 ) {
26- return null ;
27- }
28- return (
29- < div
30- className = { classNames ( 'relative' , 'inline-block' , className ) }
31- { ...props }
32- >
33- < details className = "group" >
34- < summary className = { styles . summary } role = "button" aria-haspopup = "menu" >
35- < ClockIcon className = "h-4 w-4" />
36- < span > { label } </ span >
37- < ChevronDownIcon className = "h-3 w-3 group-open:rotate-180 motion-safe:transition-transform" />
38- </ summary >
39- < div
40- className = { styles . dropdownContentWrapper }
41- role = "menu"
42- aria-label = { ariaLabel }
43- >
44- < div className = "max-h-80 w-52 overflow-y-auto" >
45- { changes . map ( ( change , index ) => {
46- const content = (
47- < >
48- < div className = "block text-sm font-medium leading-tight" >
49- { change . label }
50- </ div >
51- < div className = "block text-xs leading-tight opacity-75" >
52- { change . versions . join ( ', ' ) }
53- </ div >
54- </ >
55- ) ;
56-
57- const MenuItem = change . url ? 'a' : 'div' ;
58- return (
59- < MenuItem
60- key = { index }
61- className = { styles . dropdownItem }
62- role = { 'menuitem' }
63- tabIndex = { 0 }
64- aria-label = { `${ change . label } :${ change . versions . join ( ', ' ) } ` }
65- href = { change . url }
66- >
67- { content }
68- </ MenuItem >
69- ) ;
70- } ) }
71- </ div >
28+ } ) => (
29+ < div className = { classNames ( 'relative' , 'inline-block' , className ) } { ...props } >
30+ < details className = "group" >
31+ < summary className = { styles . summary } role = "button" aria-haspopup = "menu" >
32+ < ClockIcon className = "h-4 w-4" />
33+ < span > { label } </ span >
34+ < ChevronDownIcon className = "h-3 w-3 group-open:rotate-180 motion-safe:transition-transform" />
35+ </ summary >
36+ < div
37+ className = { styles . dropdownContentWrapper }
38+ role = "menu"
39+ aria-label = { ariaLabel }
40+ >
41+ < div className = { styles . dropdownContentInner } >
42+ { changes . map ( ( change , index ) => {
43+ const MenuItem = change . url ? As : 'div' ;
44+ return (
45+ < MenuItem
46+ key = { index }
47+ className = { styles . dropdownItem }
48+ role = { 'menuitem' }
49+ tabIndex = { 0 }
50+ aria-label = { `${ change . label } : ${ change . versions . join ( ', ' ) } ` }
51+ href = { change . url }
52+ >
53+ < div className = { styles . dropdownLabel } > { change . label } </ div >
54+ < div className = { styles . dropdownVersions } >
55+ { change . versions . join ( ', ' ) }
56+ </ div >
57+ </ MenuItem >
58+ ) ;
59+ } ) }
7260 </ div >
73- </ details >
74- </ div >
75- ) ;
76- } ;
61+ </ div >
62+ </ details >
63+ </ div >
64+ ) ;
7765
7866export default ChangeHistory ;
0 commit comments