Skip to content

Commit 232884b

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

File tree

3 files changed

+46
-126
lines changed

3 files changed

+46
-126
lines changed
Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
@reference "../../styles/index.css";
22

3-
.changeHistory {
4-
@apply relative
5-
inline-block;
6-
}
7-
83
.summary {
94
@apply outline-hidden
105
flex
@@ -28,33 +23,11 @@
2823
@apply bg-neutral-100
2924
dark:bg-neutral-900;
3025
}
31-
32-
&.disabled {
33-
@apply cursor-not-allowed
34-
opacity-50;
35-
36-
&:hover,
37-
&:focus-visible {
38-
@apply bg-transparent
39-
dark:bg-transparent;
40-
}
41-
}
4226
}
4327

44-
.icon {
45-
@apply h-4
46-
w-4;
47-
}
48-
49-
.chevron {
50-
@apply h-3
51-
w-3
52-
group-open:rotate-180
53-
motion-safe:transition-transform;
54-
}
55-
56-
.dropdownContent {
28+
.dropdownContentWrapper {
5729
@apply absolute
30+
right-0
5831
top-full
5932
z-50
6033
mt-1
@@ -70,20 +43,6 @@
7043
dark:bg-neutral-950;
7144
}
7245

73-
.dropdownContent.alignLeft {
74-
@apply left-0;
75-
}
76-
77-
.dropdownContent.alignRight {
78-
@apply right-0;
79-
}
80-
81-
.dropdownContentInner {
82-
@apply max-h-80
83-
w-52
84-
overflow-y-auto;
85-
}
86-
8746
.dropdownItem {
8847
@apply outline-hidden
8948
block
@@ -102,17 +61,3 @@
10261
text-white;
10362
}
10463
}
105-
106-
.dropdownLabel {
107-
@apply block
108-
text-sm
109-
font-medium
110-
leading-tight;
111-
}
112-
113-
.dropdownVersions {
114-
@apply block
115-
text-xs
116-
leading-tight
117-
opacity-75;
118-
}

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

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const LARGE_SAMPLE_CHANGES = [
107107

108108
export const Default: Story = {
109109
render: args => (
110-
<div className="flex justify-end">
110+
<div className="right-0 flex justify-end">
111111
<ChangeHistory {...args} />
112112
</div>
113113
),
@@ -116,27 +116,9 @@ export const Default: Story = {
116116
},
117117
};
118118

119-
export const NoChanges: Story = {
120-
render: args => (
121-
<div className="flex justify-end">
122-
<ChangeHistory {...args} />
123-
</div>
124-
),
125-
args: {
126-
changes: [],
127-
},
128-
};
129-
130-
export const LeftAligned: Story = {
131-
args: {
132-
align: 'left',
133-
changes: SAMPLE_CHANGES,
134-
},
135-
};
136-
137119
export const LargeHistory: Story = {
138120
render: args => (
139-
<div className="flex justify-end">
121+
<div className="right-0 flex justify-end">
140122
<ChangeHistory {...args} />
141123
</div>
142124
),
Lines changed: 42 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,78 @@
11
import { ChevronDownIcon, ClockIcon } from '@heroicons/react/24/outline';
2-
import type { FC } from 'react';
2+
import classNames from 'classnames';
3+
import type { FC, ComponentProps } from 'react';
34

45
import styles from './index.module.css';
56

6-
type ChangeHistoryProps = React.JSX.IntrinsicElements['div'] & {
7+
export type HistoryChange = {
8+
versions: Array<string>;
79
label: string;
8-
changes: Array<{
9-
versions: Array<string>;
10-
label: string;
11-
url?: string;
12-
}>;
13-
align?: 'left' | 'right';
10+
url?: string;
11+
};
12+
13+
type ChangeHistoryProps = ComponentProps<'div'> & {
14+
label: string;
15+
changes: Array<HistoryChange>;
1416
};
1517

1618
const ChangeHistory: FC<ChangeHistoryProps> = ({
1719
label = 'History',
1820
changes = [],
19-
align = 'right',
2021
className,
2122
'aria-label': ariaLabel = label,
2223
...props
23-
}) => (
24-
<div className={`${styles.changeHistory} ${className ?? ''}`} {...props}>
25-
{changes.length > 0 ? (
24+
}) => {
25+
if (changes.length === 0) {
26+
return null;
27+
}
28+
return (
29+
<div
30+
className={classNames('relative', 'inline-block', className)}
31+
{...props}
32+
>
2633
<details className="group">
2734
<summary className={styles.summary} role="button" aria-haspopup="menu">
28-
<ClockIcon className={styles.icon} />
35+
<ClockIcon className="h-4 w-4" />
2936
<span>{label}</span>
30-
<ChevronDownIcon className={styles.chevron} />
37+
<ChevronDownIcon className="h-3 w-3 group-open:rotate-180 motion-safe:transition-transform" />
3138
</summary>
3239
<div
33-
className={`${styles.dropdownContent} ${
34-
align === 'left' ? styles.alignLeft : styles.alignRight
35-
}`}
40+
className={styles.dropdownContentWrapper}
3641
role="menu"
3742
aria-label={ariaLabel}
3843
>
39-
<div className={styles.dropdownContentInner}>
40-
{changes.map(change => {
44+
<div className="max-h-80 w-52 overflow-y-auto">
45+
{changes.map((change, index) => {
4146
const content = (
4247
<>
43-
<div className={styles.dropdownLabel}>{change.label}</div>
44-
<div className={styles.dropdownVersions}>
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">
4552
{change.versions.join(', ')}
4653
</div>
4754
</>
4855
);
4956

50-
const ariaLabel = `${change.label}: ${change.versions.join(', ')}`;
51-
52-
const itemProps = {
53-
key: ariaLabel,
54-
className: styles.dropdownItem,
55-
role: 'menuitem',
56-
tabIndex: 0,
57-
['aria-label']: ariaLabel,
58-
};
59-
60-
return change.url ? (
61-
<a {...itemProps} href={change.url}>
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+
>
6267
{content}
63-
</a>
64-
) : (
65-
<div {...itemProps}>{content}</div>
68+
</MenuItem>
6669
);
6770
})}
6871
</div>
6972
</div>
7073
</details>
71-
) : (
72-
<div
73-
className={`${styles.summary} ${styles.disabled}`}
74-
role="button"
75-
aria-disabled="true"
76-
>
77-
<ClockIcon className={styles.icon} aria-hidden="true" />
78-
<span>{label}</span>
79-
<ChevronDownIcon className={styles.chevron} aria-hidden="true" />
80-
</div>
81-
)}
82-
</div>
83-
);
74+
</div>
75+
);
76+
};
8477

8578
export default ChangeHistory;

0 commit comments

Comments
 (0)