Skip to content

Commit 8834462

Browse files
Merge pull request #5993 from matuzalemsteles/fix-dropdown-types-site
fix(@clayui/drop-down): fix Dropdown types to correctly generate API Table
2 parents 4f0a2eb + a6fd186 commit 8834462

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

packages/clay-drop-down/docs/drop-down.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ packageTypes:
1515
'clay-drop-down/src/Help.tsx',
1616
'clay-drop-down/src/Caption.tsx',
1717
'clay-drop-down/src/DropDownWithDrilldown.tsx',
18+
'clay-drop-down/src/DropDownWithItems.tsx',
1819
]
1920
---
2021

packages/clay-drop-down/src/DropDownWithDrilldown.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,24 @@ import Caption from './Caption';
1717
import DropDown from './DropDown';
1818
import Help from './Help';
1919
import {ClayDropDownContext, DropDownItems, findNested} from './Items';
20+
import Menu from './Menu';
2021
import Search from './Search';
2122

2223
import type {AlignPoints} from '@clayui/shared';
2324

2425
import type {Item} from './Items';
26+
import type {IProps as SearchProps} from './Search';
2527

2628
type Messages = {
2729
goTo: string;
2830
back: string;
2931
};
3032

31-
interface IProps extends React.HTMLAttributes<HTMLDivElement> {
33+
type TriggerElement = React.ReactElement & {
34+
ref?: (node: HTMLButtonElement | null) => void;
35+
};
36+
37+
export type Props = {
3238
/**
3339
* Flag to indicate if the menu should be initially open (controlled).
3440
*/
@@ -66,6 +72,8 @@ interface IProps extends React.HTMLAttributes<HTMLDivElement> {
6672
*/
6773
caption?: string;
6874

75+
className?: string;
76+
6977
/**
7078
* HTML element tag that the container should render.
7179
*/
@@ -96,9 +104,8 @@ interface IProps extends React.HTMLAttributes<HTMLDivElement> {
96104
/**
97105
* Prop to pass DOM element attributes to DropDown.Menu.
98106
*/
99-
menuElementAttrs?: React.ComponentProps<
100-
typeof DropDown
101-
>['menuElementAttrs'];
107+
menuElementAttrs?: React.HTMLAttributes<HTMLDivElement> &
108+
Pick<React.ComponentProps<typeof Menu>, 'containerProps'>;
102109

103110
/**
104111
* Adds utility class name `dropdown-menu-height-${height}`
@@ -130,7 +137,7 @@ interface IProps extends React.HTMLAttributes<HTMLDivElement> {
130137
/**
131138
* Function for setting the offset of the menu from the trigger.
132139
*/
133-
offsetFn?: React.ComponentProps<typeof DropDown>['offsetFn'];
140+
offsetFn?: (points: AlignPoints) => [number, number];
134141

135142
/**
136143
* Callback the will be invoked when the active prop is changed (controlled).
@@ -150,9 +157,7 @@ interface IProps extends React.HTMLAttributes<HTMLDivElement> {
150157
/**
151158
* Element that is used as the trigger which will activate the dropdown on click.
152159
*/
153-
trigger: React.ReactElement & {
154-
ref?: (node: HTMLButtonElement | null) => void;
155-
};
160+
trigger: TriggerElement;
156161

157162
/**
158163
* Flag indicating if the caret icon should be displayed on the right side.
@@ -177,16 +182,13 @@ interface IProps extends React.HTMLAttributes<HTMLDivElement> {
177182
/**
178183
* Pass the props to the Search component.
179184
*/
180-
searchProps?: Omit<
181-
React.ComponentProps<typeof Search>,
182-
'onChange' | 'spritemap' | 'value'
183-
>;
185+
searchProps?: SearchProps;
184186

185187
/**
186188
* The value that will be passed to the search input element.
187189
*/
188190
searchValue?: string;
189-
}
191+
};
190192

191193
type History = {
192194
id: string;
@@ -223,7 +225,7 @@ export const ClayDropDownWithDrilldown = ({
223225
spritemap,
224226
trigger,
225227
triggerIcon = null,
226-
}: IProps) => {
228+
}: Props) => {
227229
const [activeMenu, setActiveMenu] = useState(
228230
defaultActiveMenu ?? initialActiveMenu
229231
);

packages/clay-drop-down/src/DropDownWithItems.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ import ClayDropDown from './DropDown';
1111
import {ClayDropDownWithDrilldown} from './DropDownWithDrilldown';
1212
import Help from './Help';
1313
import {ClayDropDownContext, DropDownItems, findNested} from './Items';
14+
import Menu from './Menu';
1415
import Search from './Search';
1516

1617
import type {AlignPoints, InternalDispatch} from '@clayui/shared';
1718

1819
import type {Item} from './Items';
20+
import type {IProps as SearchProps} from './Search';
1921

2022
export type Props = {
2123
/**
@@ -75,9 +77,8 @@ export type Props = {
7577
/**
7678
* Prop to pass DOM element attributes to DropDown.Menu.
7779
*/
78-
menuElementAttrs?: React.ComponentProps<
79-
typeof ClayDropDown
80-
>['menuElementAttrs'];
80+
menuElementAttrs?: React.HTMLAttributes<HTMLDivElement> &
81+
Pick<React.ComponentProps<typeof Menu>, 'containerProps'>;
8182

8283
/**
8384
* Adds utility class name `dropdown-menu-height-${height}`
@@ -102,7 +103,7 @@ export type Props = {
102103
/**
103104
* Function for setting the offset of the menu from the trigger.
104105
*/
105-
offsetFn?: React.ComponentProps<typeof ClayDropDown>['offsetFn'];
106+
offsetFn?: (points: AlignPoints) => [number, number];
106107

107108
/**
108109
* Callback for when the active state changes (controlled).
@@ -127,10 +128,7 @@ export type Props = {
127128
/**
128129
* Pass the props to the Search component.
129130
*/
130-
searchProps?: Omit<
131-
React.ComponentProps<typeof Search>,
132-
'onChange' | 'spritemap' | 'value'
133-
>;
131+
searchProps?: SearchProps;
134132

135133
/**
136134
* The value that will be passed to the search input element.

0 commit comments

Comments
 (0)