Skip to content

Commit b4d5580

Browse files
committed
feat(ui-components): address feedback on pr v2
1 parent 232884b commit b4d5580

File tree

2 files changed

+60
-52
lines changed

2 files changed

+60
-52
lines changed

packages/ui-components/Common/ChangeHistory/index.module.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
dark:bg-neutral-950;
4444
}
4545

46+
.dropdownContentInner {
47+
@apply max-h-80
48+
w-52
49+
overflow-y-auto;
50+
}
51+
4652
.dropdownItem {
4753
@apply outline-hidden
4854
block
@@ -61,3 +67,17 @@
6167
text-white;
6268
}
6369
}
70+
71+
.dropdownLabel {
72+
@apply block
73+
text-sm
74+
font-medium
75+
leading-tight;
76+
}
77+
78+
.dropdownVersions {
79+
@apply block
80+
text-xs
81+
leading-tight
82+
opacity-75;
83+
}

packages/ui-components/Common/ChangeHistory/index.tsx

Lines changed: 40 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { ChevronDownIcon, ClockIcon } from '@heroicons/react/24/outline';
22
import classNames from 'classnames';
33
import type { FC, ComponentProps } from 'react';
44

5+
import type { LinkLike } from '#ui/types.js';
6+
57
import styles from './index.module.css';
68

79
export type HistoryChange = {
@@ -13,66 +15,52 @@ export type HistoryChange = {
1315
type ChangeHistoryProps = ComponentProps<'div'> & {
1416
label: string;
1517
changes: Array<HistoryChange>;
18+
as?: LinkLike;
1619
};
1720

1821
const 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

7866
export default ChangeHistory;

0 commit comments

Comments
 (0)