Skip to content

Commit

Permalink
Update types
Browse files Browse the repository at this point in the history
  • Loading branch information
mj12albert committed Sep 18, 2023
1 parent 9e38522 commit de5a6c7
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 27 deletions.
4 changes: 2 additions & 2 deletions docs/pages/base-ui/api/use-option.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"returnValue": {
"getRootProps": {
"type": {
"name": "<Other extends EventHandlers>(otherHandlers?: Other) => UseOptionRootSlotProps<Other>",
"description": "<Other extends EventHandlers>(otherHandlers?: Other) => UseOptionRootSlotProps<Other>"
"name": "<ExternalProps extends Record<string, unknown>>(externalProps?: ExternalProps) => UseOptionRootSlotProps<ExternalProps>",
"description": "<ExternalProps extends Record<string, unknown>>(externalProps?: ExternalProps) => UseOptionRootSlotProps<ExternalProps>"
},
"required": true
},
Expand Down
12 changes: 6 additions & 6 deletions docs/pages/base-ui/api/use-select.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,22 @@
},
"getButtonProps": {
"type": {
"name": "<OtherHandlers extends EventHandlers = {}>(otherHandlers?: OtherHandlers) => UseSelectButtonSlotProps<OtherHandlers>",
"description": "<OtherHandlers extends EventHandlers = {}>(otherHandlers?: OtherHandlers) => UseSelectButtonSlotProps<OtherHandlers>"
"name": "<ExternalProps extends Record<string, unknown> = {}>(externalProps?: ExternalProps) => UseSelectButtonSlotProps<ExternalProps>",
"description": "<ExternalProps extends Record<string, unknown> = {}>(externalProps?: ExternalProps) => UseSelectButtonSlotProps<ExternalProps>"
},
"required": true
},
"getHiddenInputProps": {
"type": {
"name": "<OtherHandlers extends EventHandlers = {}>(otherHandlers?: OtherHandlers) => UseSelectHiddenInputSlotProps<OtherHandlers>",
"description": "<OtherHandlers extends EventHandlers = {}>(otherHandlers?: OtherHandlers) => UseSelectHiddenInputSlotProps<OtherHandlers>"
"name": "<ExternalProps extends Record<string, unknown> = {}>(externalProps?: ExternalProps) => UseSelectHiddenInputSlotProps<ExternalProps>",
"description": "<ExternalProps extends Record<string, unknown> = {}>(externalProps?: ExternalProps) => UseSelectHiddenInputSlotProps<ExternalProps>"
},
"required": true
},
"getListboxProps": {
"type": {
"name": "<OtherHandlers extends EventHandlers = {}>(otherHandlers?: OtherHandlers) => UseSelectListboxSlotProps<OtherHandlers>",
"description": "<OtherHandlers extends EventHandlers = {}>(otherHandlers?: OtherHandlers) => UseSelectListboxSlotProps<OtherHandlers>"
"name": "<ExternalProps extends Record<string, unknown> = {}>(externalProps?: ExternalProps) => UseSelectListboxSlotProps<ExternalProps>",
"description": "<ExternalProps extends Record<string, unknown> = {}>(externalProps?: ExternalProps) => UseSelectListboxSlotProps<ExternalProps>"
},
"required": true
},
Expand Down
11 changes: 10 additions & 1 deletion docs/translations/api-docs/use-option/use-option.json
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
{ "hookDescription": "", "parametersDescriptions": {}, "returnValueDescriptions": {} }
{
"hookDescription": "",
"parametersDescriptions": {},
"returnValueDescriptions": {
"getRootProps": { "description": "Resolver for the root slot's props." },
"highlighted": { "description": "If <code>true</code>, the option is highlighted." },
"rootRef": { "description": "Ref to the root slot DOM node." },
"selected": { "description": "If <code>true</code>, the option is selected." }
}
}
27 changes: 20 additions & 7 deletions packages/mui-base/src/useOption/useOption.types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { UseListItemRootSlotProps } from '../useList';
import { EventHandlers } from '../utils';

export interface SelectOption<Value> {
value: Value;
Expand All @@ -18,16 +17,30 @@ export interface UseOptionParameters<Value> {
}

export interface UseOptionReturnValue {
/**
* If `true`, the option is selected.
*/
selected: boolean;
/**
* If `true`, the option is highlighted.
*/
highlighted: boolean;
index: number;
getRootProps: <Other extends EventHandlers>(
otherHandlers?: Other,
) => UseOptionRootSlotProps<Other>;
/**
* Resolver for the root slot's props.
* @param externalProps props for the root slot
* @returns props that should be spread on the root slot
*/
getRootProps: <ExternalProps extends Record<string, unknown>>(
externalProps?: ExternalProps,
) => UseOptionRootSlotProps<ExternalProps>;
/**
* Ref to the root slot DOM node.
*/
rootRef: React.RefCallback<Element> | null;
}

export type UseOptionRootSlotProps<Other extends EventHandlers = {}> =
UseListItemRootSlotProps<Other> & {
export type UseOptionRootSlotProps<ExternalProps extends Record<string, unknown> = {}> =
UseListItemRootSlotProps<ExternalProps> & {
ref?: React.RefCallback<Element> | null;
} & Other;
} & ExternalProps;
23 changes: 12 additions & 11 deletions packages/mui-base/src/useSelect/useSelect.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,27 +182,28 @@ export interface UseSelectReturnValue<Value, Multiple> {
dispatch: (action: ListAction<Value> | SelectAction) => void;
/**
* Resolver for the button slot's props.
* @param otherHandlers event handlers for the button slot
* @param externalProps event handlers for the button slot
* @returns props that should be spread on the button slot
*/
getButtonProps: <OtherHandlers extends EventHandlers = {}>(
otherHandlers?: OtherHandlers,
) => UseSelectButtonSlotProps<OtherHandlers>;
getButtonProps: <ExternalProps extends Record<string, unknown> = {}>(
externalProps?: ExternalProps,
) => UseSelectButtonSlotProps<ExternalProps>;
/**
* Resolver for the hidden input slot's props.
* @param externalProps event handlers for the hidden input slot
* @returns HTML input attributes that should be spread on the hidden input slot
*/
getHiddenInputProps: <OtherHandlers extends EventHandlers = {}>(
otherHandlers?: OtherHandlers,
) => UseSelectHiddenInputSlotProps<OtherHandlers>;
getHiddenInputProps: <ExternalProps extends Record<string, unknown> = {}>(
externalProps?: ExternalProps,
) => UseSelectHiddenInputSlotProps<ExternalProps>;
/**
* Resolver for the listbox slot's props.
* @param otherHandlers event handlers for the listbox slot
* @param externalProps event handlers for the listbox slot
* @returns props that should be spread on the listbox slot
*/
getListboxProps: <OtherHandlers extends EventHandlers = {}>(
otherHandlers?: OtherHandlers,
) => UseSelectListboxSlotProps<OtherHandlers>;
getListboxProps: <ExternalProps extends Record<string, unknown> = {}>(
externalProps?: ExternalProps,
) => UseSelectListboxSlotProps<ExternalProps>;
/**
* A function that returns the metadata of an option with a given value.
*
Expand Down

0 comments on commit de5a6c7

Please sign in to comment.