WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit b55fe91

Browse files
committed
feat: improve api
1 parent 88c211c commit b55fe91

File tree

7 files changed

+19
-12
lines changed

7 files changed

+19
-12
lines changed

src/internal/components/option/interfaces.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ export interface DropdownOption {
4343
afterHeader?: boolean;
4444
}
4545

46-
export interface DropdownOptionItem<T> {
47-
type: 'child' | 'parent' | 'select-all' | 'use-entered';
46+
export type DropdownOptionItemType = 'child' | 'parent' | 'select-all' | 'use-entered';
47+
export interface DropdownOptionItem<
48+
T,
49+
TType extends DropdownOptionItemType = 'child' | 'parent' | 'select-all' | 'use-entered',
50+
> {
51+
type: TType;
4852
disabled: boolean;
4953
highlighted: boolean;
5054
selected: boolean;

src/multiselect/interfaces.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface MultiselectProps extends BaseSelectProps {
1616
*
1717
* @awsuiSystem core
1818
*/
19-
renderOption?: (item: MultiselectProps.MultiselectOptionItem) => ReactNode;
19+
renderOption?: MultiselectProps.MultiselectOptionItemRenderer;
2020

2121
/**
2222
* Specifies the currently selected options.
@@ -91,7 +91,8 @@ export namespace MultiselectProps {
9191
export type Option = OptionDefinition;
9292
export type OptionGroup = OptionGroupDefinition;
9393
export type Options = ReadonlyArray<Option | OptionGroup>;
94-
export type MultiselectOptionItem = DropdownOptionItem<Option | OptionGroup>;
94+
export type MultiselectOptionItem = DropdownOptionItem<Option | OptionGroup, 'child' | 'parent' | 'select-all'>;
95+
export type MultiselectOptionItemRenderer = (item: MultiselectOptionItem) => ReactNode;
9596

9697
export type DeselectAriaLabelFunction = (option: Option) => string;
9798
export type TriggerVariant = 'placeholder' | 'tokens';

src/select/interfaces.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export interface SelectProps extends BaseSelectProps {
165165
*
166166
* @awsuiSystem core
167167
*/
168-
renderOption?: (option: SelectProps.SelectOptionItem) => ReactNode;
168+
renderOption?: SelectProps.SelectOptionItemRenderer;
169169

170170
/**
171171
* Adds a small label inline with the input for saving vertical space in the UI.
@@ -210,7 +210,9 @@ export namespace SelectProps {
210210
export type Option = OptionDefinition;
211211
export type OptionGroup = OptionGroupDefinition;
212212
export type Options = ReadonlyArray<Option | OptionGroup>;
213-
export type SelectOptionItem = DropdownOptionItem<Option | OptionGroup>;
213+
export type SelectOptionItem = DropdownOptionItem<Option | OptionGroup, 'child' | 'parent'>;
214+
export type SelectOptionItemRenderer = (item: SelectOptionItem) => ReactNode;
215+
214216
export type LoadItemsDetail = OptionsLoadItemsDetail;
215217

216218
export interface ChangeDetail {

src/select/parts/item.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const Item = (
110110
selected: !!selected,
111111
highlighted: !!highlighted,
112112
disabled: !!disabled,
113-
type: option.type === 'select-all' ? 'child' : (option.type ?? 'child'),
113+
type: option.type === 'parent' ? 'parent' : 'child',
114114
})
115115
) : (
116116
<Option

src/select/parts/multiselect-item.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const MultiSelectItem = (
105105
selected: !!selected,
106106
highlighted: !!highlighted,
107107
disabled: !!disabled,
108-
type: option.type ?? 'child',
108+
type: option.type !== 'use-entered' ? (option.type ?? 'child') : 'child',
109109
})
110110
) : (
111111
<Option

src/select/parts/plain-list.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3-
import React, { forwardRef, ReactNode, useImperativeHandle, useRef, useState } from 'react';
3+
import React, { forwardRef, useImperativeHandle, useRef, useState } from 'react';
44

55
import { useContainerQuery } from '@cloudscape-design/component-toolkit';
66
import { useMergeRefs, useUniqueId } from '@cloudscape-design/component-toolkit/internal';
@@ -29,7 +29,7 @@ export interface SelectListProps {
2929
useInteractiveGroups?: boolean;
3030
screenReaderContent?: string;
3131
firstOptionSticky?: boolean;
32-
renderOption?: (option: SelectProps.SelectOptionItem | MultiselectProps.MultiselectOptionItem) => ReactNode;
32+
renderOption?: SelectProps.SelectOptionItemRenderer | MultiselectProps.MultiselectOptionItemRenderer;
3333
}
3434

3535
export namespace SelectListProps {

src/select/utils/render-options.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3-
import React, { ReactNode } from 'react';
3+
import React from 'react';
44

55
import { DropdownOption } from '../../internal/components/option/interfaces';
66
import { NestedDropdownOption, unflattenOptions } from '../../internal/components/option/utils/unflatten-options';
@@ -28,7 +28,7 @@ interface RenderOptionProps {
2828
withScrollbar: boolean;
2929
firstOptionSticky?: boolean;
3030
stickyOptionRef?: React.Ref<HTMLDivElement>;
31-
renderOption?: (option: SelectProps.SelectOptionItem | MultiselectProps.MultiselectOptionItem) => ReactNode;
31+
renderOption?: SelectProps.SelectOptionItemRenderer | MultiselectProps.MultiselectOptionItemRenderer;
3232
}
3333

3434
export const renderOptions = ({

0 commit comments

Comments
 (0)