Skip to content

Commit

Permalink
Added comments (#plugins-292)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Feb 26, 2024
1 parent 9316a00 commit a8173a1
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/components/src/spectrum/picker/PickerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,27 @@ import { PopperOptions } from '../../popper';

export type ItemElement = ReactElement<ItemProps<unknown>>;
export type PickerItem = number | string | boolean | ItemElement;

/**
* Augment the Spectrum selection key type to include boolean values.
* The Spectrum Picker already supports this, but the built in types don't
* reflect it.
*/
export type PickerItemKey = Key | boolean;

/**
* Augment the Spectrum selection change handler type to include boolean keys.
* The Spectrum Picker already supports this, but the built in types don't
* reflect it.
*/
export type PickerSelectionChangeHandler = (key: PickerItemKey) => void;

/**
* The Picker supports a variety of item types, including strings, numbers,
* booleans, and more complex React elements. This type represents a normalized
* form to make rendering items simpler and keep the logic of transformation
* in separate util methods.
*/
export interface NormalizedPickerItem {
key: PickerItemKey;
content: ReactNode;
Expand All @@ -25,10 +43,12 @@ export type TooltipOptions = { placement: PopperOptions['placement'] };
* @returns A `PickerItemKey` for the picker item
*/
function normalizeItemKey(item: PickerItem): PickerItemKey {
// string, number, or boolean
if (typeof item !== 'object') {
return item;
}

// `ItemElement` with `key` prop set
if (item.key != null) {
return item.key;
}
Expand Down

0 comments on commit a8173a1

Please sign in to comment.