Skip to content

Commit

Permalink
chore(react-combobox): rollback export of internal hooks (#30648)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsunderhus authored Feb 29, 2024
1 parent 6bd8fa7 commit c7342e3
Show file tree
Hide file tree
Showing 14 changed files with 1,103 additions and 45 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: rollback export of internal hooks",
"packageName": "@fluentui/react-combobox",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
/// <reference types="react" />

import type { ActiveDescendantContextValue } from '@fluentui/react-aria';
import { ActiveDescendantImperativeRef } from '@fluentui/react-aria';
import type { ActiveDescendantImperativeRef } from '@fluentui/react-aria';
import type { ComponentProps } from '@fluentui/react-utilities';
import type { ComponentState } from '@fluentui/react-utilities';
import { ContextSelector } from '@fluentui/react-context-selector';
import type { ExtractSlotProps } from '@fluentui/react-utilities';
import { FC } from 'react';
import type { ForwardRefComponent } from '@fluentui/react-utilities';
import { PortalProps } from '@fluentui/react-portal';
Expand All @@ -21,25 +20,10 @@ import { ProviderProps } from 'react';
import * as React_2 from 'react';
import type { Slot } from '@fluentui/react-utilities';
import { SlotClassNames } from '@fluentui/react-utilities';
import type { SlotComponentType } from '@fluentui/react-utilities';

// @public
export const Combobox: ForwardRefComponent<ComboboxProps>;

// @public
export type ComboboxBaseState = Required<Pick<ComboboxBaseProps, 'appearance' | 'open' | 'clearable' | 'inlinePopup' | 'size'>> & Pick<ComboboxBaseProps, 'mountNode' | 'placeholder' | 'value' | 'multiselect'> & OptionCollectionState & SelectionState & {
activeOption?: OptionValue;
focusVisible: boolean;
ignoreNextBlur: React_2.MutableRefObject<boolean>;
setActiveOption: React_2.Dispatch<React_2.SetStateAction<OptionValue | undefined>>;
setFocusVisible(focusVisible: boolean): void;
hasFocus: boolean;
setHasFocus(hasFocus: boolean): void;
setOpen(event: ComboboxBaseOpenEvents, newState: boolean): void;
setValue(newValue: string | undefined): void;
onOptionClick: (e: React_2.MouseEvent<HTMLElement>) => void;
};

// @public (undocumented)
export const comboboxClassNames: SlotClassNames<ComboboxSlots>;

Expand Down Expand Up @@ -229,19 +213,9 @@ export const renderOptionGroup_unstable: (state: OptionGroupState) => JSX.Elemen
// @public (undocumented)
export type SelectionEvents = React_2.ChangeEvent<HTMLElement> | React_2.KeyboardEvent<HTMLElement> | React_2.MouseEvent<HTMLElement>;

// @internal
export function useButtonTriggerSlot(triggerFromProps: NonNullable<Slot<'button'>>, ref: React_2.Ref<HTMLButtonElement>, options: UseButtonTriggerSlotOptions): SlotComponentType<ExtractSlotProps<Slot<'button'>>>;

// @public
export const useCombobox_unstable: (props: ComboboxProps, ref: React_2.Ref<HTMLInputElement>) => ComboboxState;

// @internal
export const useComboboxBaseState: (props: ComboboxBaseProps & {
children?: React_2.ReactNode;
editable?: boolean;
activeDescendantController: ActiveDescendantImperativeRef;
}) => ComboboxBaseState;

// @public (undocumented)
export function useComboboxContextValues(state: ComboboxBaseState & Pick<ComboboxState, 'activeDescendantController'>): ComboboxBaseContextValues;

Expand All @@ -260,9 +234,6 @@ export const useDropdown_unstable: (props: DropdownProps, ref: React_2.Ref<HTMLB
// @public
export const useDropdownStyles_unstable: (state: DropdownState) => DropdownState;

// @internal
export function useInputTriggerSlot(triggerFromProps: NonNullable<Slot<'input'>>, ref: React_2.Ref<HTMLInputElement>, options: UseInputTriggerSlotOptions): SlotComponentType<ExtractSlotProps<Slot<'input'>>>;

// @public
export const useListbox_unstable: (props: ListboxProps, ref: React_2.Ref<HTMLElement>) => ListboxState;

Expand All @@ -272,9 +243,6 @@ export const useListboxContext_unstable: <T>(selector: ContextSelector<ListboxCo
// @public (undocumented)
export function useListboxContextValues(state: ListboxState): ListboxContextValues;

// @internal (undocumented)
export function useListboxSlot(listboxSlotFromProp: Slot<typeof Listbox> | undefined, ref: React_2.Ref<HTMLDivElement>, options: UseListboxSlotOptions): SlotComponentType<ExtractSlotProps<Slot<typeof Listbox>>> | undefined;

// @public
export const useListboxStyles_unstable: (state: ListboxState) => ListboxState;

Expand Down
5 changes: 0 additions & 5 deletions packages/react-components/react-combobox/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,3 @@ export type { OptionGroupProps, OptionGroupSlots, OptionGroupState } from './Opt
export type { OptionOnSelectData, SelectionEvents } from './Selection';

export { useComboboxFilter } from './hooks/useComboboxFilter';
export { useComboboxBaseState } from './utils/useComboboxBaseState';
export type { ComboboxBaseState } from './utils/ComboboxBase.types';
export { useListboxSlot } from './utils/useListboxSlot';
export { useInputTriggerSlot } from './components/Combobox/useInputTriggerSlot';
export { useButtonTriggerSlot } from './components/Dropdown/useButtonTriggerSlot';
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
"@fluentui/react-shared-contexts": "^9.14.1",
"@fluentui/react-theme": "^9.1.16",
"@fluentui/react-utilities": "^9.18.2",
"@fluentui/react-portal": "^9.4.15",
"@fluentui/react-aria": "^9.9.1",
"@fluentui/react-combobox": "^9.9.0",
"@fluentui/keyboard-keys": "^9.0.7",
"@fluentui/react-tabster": "^9.19.2",
"@griffel/react": "^1.5.14",
"@swc/helpers": "^0.5.1"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import * as React from 'react';
import type { ActiveDescendantContextValue } from '@fluentui/react-aria';
import type { PositioningShorthand } from '@fluentui/react-positioning';
import type { ComboboxContextValue, ListboxContextValue } from '@fluentui/react-combobox';
import type { OptionValue, OptionCollectionState } from './OptionCollection.types';
import { SelectionProps, SelectionState } from './Selection.types';
import { PortalProps } from '@fluentui/react-portal';

/**
* ComboboxBase Props
* Shared types between Combobox and Dropdown components
*/
export type ComboboxBaseProps = SelectionProps &
Pick<PortalProps, 'mountNode'> & {
/**
* Controls the colors and borders of the combobox trigger.
* @default 'outline'
*/
appearance?: 'filled-darker' | 'filled-lighter' | 'outline' | 'underline';

/**
* If set, the combobox will show an icon to clear the current value.
*/
clearable?: boolean;

/**
* The default open state when open is uncontrolled
*/
defaultOpen?: boolean;

/**
* The default value displayed in the trigger input or button when the combobox's value is uncontrolled
*/
defaultValue?: string;

/**
* Render the combobox's popup inline in the DOM.
* This has accessibility benefits, particularly for touch screen readers.
*/
inlinePopup?: boolean;

/**
* Callback when the open/closed state of the dropdown changes
*/
// eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback
onOpenChange?: (e: ComboboxBaseOpenEvents, data: ComboboxBaseOpenChangeData) => void;

/**
* Sets the open/closed state of the dropdown.
* Use together with onOpenChange to fully control the dropdown's visibility
*/
open?: boolean;

/**
* If set, the placeholder will show when no value is selected
*/
placeholder?: string;

/**
* Configure the positioning of the combobox dropdown
*
* @defaultvalue below
*/
positioning?: PositioningShorthand;

/**
* Controls the size of the combobox faceplate
* @default 'medium'
*/
size?: 'small' | 'medium' | 'large';

/**
* The value displayed by the Combobox.
* Use this with `onOptionSelect` to directly control the displayed value string
*/
value?: string;
};

/**
* State used in rendering Combobox
*/
export type ComboboxBaseState = Required<
Pick<ComboboxBaseProps, 'appearance' | 'open' | 'clearable' | 'inlinePopup' | 'size'>
> &
Pick<ComboboxBaseProps, 'mountNode' | 'placeholder' | 'value' | 'multiselect'> &
OptionCollectionState &
SelectionState & {
/**
* @deprecated - no longer used internally
*/
activeOption?: OptionValue;

/**
* @deprecated - no longer used internally and handled automatically be activedescendant utilities
* @see ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE for writing styles involving focusVisible
*/
focusVisible: boolean;

/**
* @deprecated - no longer used internally
* Whether the next blur event should be ignored, and the combobox/dropdown will not close.
*/
ignoreNextBlur: React.MutableRefObject<boolean>;

/**
* @deprecated - no longer used internally
*/
setActiveOption: React.Dispatch<React.SetStateAction<OptionValue | undefined>>;

/**
* @deprecated - no longer used internally and handled automatically be activedescendant utilities
* @see useSetKeyboardNavigation for imperatively setting focus visible state
*/
setFocusVisible(focusVisible: boolean): void;

/**
* whether the combobox/dropdown currently has focus
*/
hasFocus: boolean;

setHasFocus(hasFocus: boolean): void;

setOpen(event: ComboboxBaseOpenEvents, newState: boolean): void;

setValue(newValue: string | undefined): void;

onOptionClick: (e: React.MouseEvent<HTMLElement>) => void;
};

/**
* Data for the Combobox onOpenChange event.
*/
export type ComboboxBaseOpenChangeData = {
open: boolean;
};

/* Possible event types for onOpen */
export type ComboboxBaseOpenEvents =
| React.MouseEvent<HTMLElement>
| React.KeyboardEvent<HTMLElement>
| React.FocusEvent<HTMLElement>;

export type ComboboxBaseContextValues = {
combobox: ComboboxContextValue;
activeDescendant: ActiveDescendantContextValue;
listbox: ListboxContextValue;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
export type OptionValue = {
/** The disabled state of the option. */
disabled?: boolean;

/** The `id` attribute of the option. */
id: string;

/** The `text` string for the option. */
text: string;

/** The value string of the option. */
value: string;
};

export type OptionCollectionState = {
/**
* @deprecated - no longer used internally
*/
getIndexOfId(id: string): number;

/**
* @deprecated - no longer used internally
*/
getOptionAtIndex(index: number): OptionValue | undefined;

/**
* @deprecated - no longer used internally
*/
getOptionsMatchingText(matcher: (text: string) => boolean): OptionValue[];

/** The total number of options in the collection. */
getCount: () => number;

/** Returns the option data by key. */
getOptionById(id: string): OptionValue | undefined;

/** Returns an array of options filtered by a value matching function against the option's value string. */
getOptionsMatchingValue(matcher: (value: string) => boolean): OptionValue[];

/** The unordered option data. */
options: OptionValue[];

/* A function that child options call to register their values. Returns a function to unregister the option. */
registerOption: (option: OptionValue, element: HTMLElement) => () => void;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import * as React from 'react';
import { OptionValue } from './OptionCollection.types';

export type SelectionProps = {
/**
* For an uncontrolled component, sets the initial selection.
* If this is set, the `defaultValue` prop MUST also be set.
*/
defaultSelectedOptions?: string[];

/**
* Sets the selection type to multiselect.
* Set this to true for multiselect, even if fully controlling selection state.
* This enables styles and accessibility properties to be set.
* @default false
*/
multiselect?: boolean;

/* Callback when an option is selected */
// eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback
onOptionSelect?: (event: SelectionEvents, data: OptionOnSelectData) => void;

/**
* An array of selected option keys.
* Use this with `onOptionSelect` to directly control the selected option(s)
* If this is set, the `value` prop MUST also be controlled.
*/
selectedOptions?: string[];
};

/* Values returned by the useSelection hook */
export type SelectionState = {
clearSelection: (event: SelectionEvents) => void;
selectedOptions: string[];
selectOption: (event: SelectionEvents, option: OptionValue) => void;
};

/*
* Data for the onOptionSelect callback.
* `optionValue` and `optionText` will be undefined if multiple options are modified at once.
*/
export type OptionOnSelectData = {
optionValue: string | undefined;
optionText: string | undefined;
selectedOptions: string[];
};

/* Possible event types for onOptionSelect */
export type SelectionEvents =
| React.ChangeEvent<HTMLElement>
| React.KeyboardEvent<HTMLElement>
| React.MouseEvent<HTMLElement>;
Loading

0 comments on commit c7342e3

Please sign in to comment.