Skip to content

Commit a4dfbcc

Browse files
committed
chore(select): move ChangeHistory to StatelessSelect
1 parent 6dcda98 commit a4dfbcc

File tree

5 files changed

+92
-211
lines changed

5 files changed

+92
-211
lines changed

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

Lines changed: 0 additions & 130 deletions
This file was deleted.

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

Lines changed: 0 additions & 67 deletions
This file was deleted.

packages/ui-components/Common/ChangeHistory/index.module.css renamed to packages/ui-components/Common/StatelessSelect/index.module.css

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,3 @@
6767
text-white;
6868
}
6969
}
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-
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { Meta as MetaObj, StoryObj } from '@storybook/react';
2+
3+
import StatelessSelect from '.';
4+
5+
type Story = StoryObj<typeof StatelessSelect>;
6+
type Meta = MetaObj<typeof StatelessSelect>;
7+
8+
// Basic example with default anchor links
9+
export const Default: Story = {
10+
args: {
11+
label: 'History',
12+
values: [
13+
{ href: '#item1', children: 'Item 1' },
14+
{ href: '#item2', children: 'Item 2' },
15+
{ href: '#item3', children: 'Item 3' },
16+
],
17+
children: <span>Select Option</span>,
18+
},
19+
};
20+
21+
export default {
22+
component: StatelessSelect,
23+
decorators: [
24+
Story => (
25+
<div className="flex h-screen items-center justify-center">
26+
<Story />
27+
</div>
28+
),
29+
],
30+
} as Meta;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import classNames from 'classnames';
2+
import type { FC, ComponentProps, PropsWithChildren, HTMLProps } from 'react';
3+
4+
import type { LinkLike } from '#ui/types.js';
5+
6+
import styles from './index.module.css';
7+
8+
type StatelessSelectProps = ComponentProps<'div'> & {
9+
label: string;
10+
values: Array<HTMLProps<HTMLAnchorElement | HTMLDivElement>>;
11+
as?: LinkLike;
12+
};
13+
14+
const StatelessSelect: FC<PropsWithChildren<StatelessSelectProps>> = ({
15+
values = [],
16+
className,
17+
as: As = 'a',
18+
'aria-label': ariaLabel,
19+
children,
20+
...props
21+
}) => (
22+
<div className={classNames('relative', 'inline-block', className)} {...props}>
23+
<details className="group">
24+
<summary className={styles.summary} role="button" aria-haspopup="menu">
25+
{children}
26+
</summary>
27+
<div
28+
className={styles.dropdownContentWrapper}
29+
role="menu"
30+
aria-label={ariaLabel}
31+
>
32+
<div className={styles.dropdownContentInner}>
33+
{values.map((value, index) => {
34+
if (value.href) {
35+
return (
36+
<As
37+
key={index}
38+
className={styles.dropdownItem}
39+
role="menuitem"
40+
tabIndex={0}
41+
{...(value as ComponentProps<LinkLike>)}
42+
/>
43+
);
44+
} else {
45+
return (
46+
<div
47+
key={index}
48+
className={styles.dropdownItem}
49+
role="menuitem"
50+
tabIndex={0}
51+
{...(value as HTMLProps<HTMLDivElement>)}
52+
/>
53+
);
54+
}
55+
})}
56+
</div>
57+
</div>
58+
</details>
59+
</div>
60+
);
61+
62+
export default StatelessSelect;

0 commit comments

Comments
 (0)