Skip to content

Commit

Permalink
[PickerInput]: fixed '+N' toggler tag tooltip content with custom `ge…
Browse files Browse the repository at this point in the history
…tName` callback
  • Loading branch information
AlekseyManetov committed Jul 22, 2024
1 parent 9c1e1c8 commit c3d6060
Show file tree
Hide file tree
Showing 23 changed files with 67 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default function ArrayPickerInputExample() {
selectionMode="multi"
valueType="id"
sorting={ { field: 'level', direction: 'asc' } }
maxItems={ 3 }
/>
<PickerInput
dataSource={ dataSource }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default function AsyncPickerInputExample() {
entityName="location"
selectionMode="multi"
valueType="id"
maxItems={ 3 }
/>
</FlexCell>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default function CascadeSelectionModesExample() {
entityName="location"
selectionMode="multi"
valueType="id"
maxItems={ 3 }
cascadeSelection={ cascadeSelection }
/>
</FlexCell>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default function ConfigurePortalTargetAndPlacement() {
selectionMode="multi"
valueType="id"
dropdownPlacement="right-start"
maxItems={ 3 }
portalTarget={ portalTargetRef.current }
/>
</FlexCell>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { useState } from 'react';
import { DataQueryFilter, useLazyDataSource, useUuiContext } from '@epam/uui-core';
import { FlexCell, PickerInput, PickerTogglerTag, PickerTogglerTagProps, Tooltip } from '@epam/uui';
import { FlexCell, PickerInput, PickerTogglerTag, Tooltip } from '@epam/uui';
import { PickerTogglerRenderItemParams } from '@epam/uui-components';
import { Location } from '@epam/uui-docs';

export default function PickerTogglerTagDemoExample() {
export default function CustomPickerTogglerTagExample() {
const svc = useUuiContext();
const [value, onValueChange] = useState<string[]>(['225284', '2747351', '3119841', '3119746']);
const [value, onValueChange] = useState<string[]>(['625144', '703448', '756135', '2950159', '4717560']);

const dataSource = useLazyDataSource<Location, string, DataQueryFilter<Location>>(
{
Expand All @@ -23,20 +24,20 @@ export default function PickerTogglerTagDemoExample() {
[],
);

const renderTag = (props: PickerTogglerTagProps<Location, string>) => {
const renderTag = (props: PickerTogglerRenderItemParams<Location, string>) => {
const { isCollapsed, rowProps } = props;

if (isCollapsed) {
// rendering '+ N items selected' Tag, tooltip is present here by default
return <PickerTogglerTag { ...props } key="collapsed" />;
return <PickerTogglerTag { ...props } key="collapsed" getName={ (i) => i?.name } />;
} else {
// rendering all other Tags with Tooltip
const continent = rowProps?.value?.tz ? rowProps?.value?.tz.split('/')[0].concat('/') : '';
const country = rowProps?.value?.countryName ? rowProps?.value?.countryName.concat('/') : '';
const tooltipContent = `${continent}${country}${props.caption}`;
return (
<Tooltip key={ props.rowProps?.id } content={ tooltipContent }>
<PickerTogglerTag { ...props } />
<PickerTogglerTag { ...props } getName={ (i) => i?.name } />
</Tooltip>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default function LazyPersonsMultiPickerWithCustomUserRow() {
entityName="person"
selectionMode="multi"
valueType="id"
maxItems={ 3 }
/>
</FlexCell>
);
Expand Down
11 changes: 10 additions & 1 deletion app/src/docs/_examples/pickerInput/EditMode.example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ export default function EditModePickerExample() {

return (
<FlexCell width={ 300 }>
<PickerInput dataSource={ dataSource } value={ value } onValueChange={ onValueChange } entityName="person" selectionMode="multi" valueType="id" editMode="modal" />
<PickerInput
dataSource={ dataSource }
value={ value }
onValueChange={ onValueChange }
entityName="person"
selectionMode="multi"
valueType="id"
editMode="modal"
maxItems={ 3 }
/>
</FlexCell>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default function GetRowOptionsExample() {
entityName="Product"
selectionMode="multi"
valueType="id"
maxItems={ 3 }
/>
</FlexRow>
</FlexCell>
Expand Down
10 changes: 9 additions & 1 deletion app/src/docs/_examples/pickerInput/LazyPickerInput.example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ export default function LazyPersonsMultiPicker() {

return (
<FlexCell width={ 300 }>
<PickerInput dataSource={ dataSource } value={ value } onValueChange={ onValueChange } entityName="person" selectionMode="multi" valueType="id" />
<PickerInput
dataSource={ dataSource }
value={ value }
onValueChange={ onValueChange }
entityName="person"
selectionMode="multi"
valueType="id"
maxItems={ 3 }
/>
</FlexCell>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default function LazyTreePicker() {
selectionMode="multi"
valueType="id"
cascadeSelection="implicit"
maxItems={ 3 }
/>
</FlexCell>
);
Expand Down
2 changes: 2 additions & 0 deletions app/src/docs/_examples/pickerInput/LazyTreeSearch.example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default function LazyTreeSearch() {
entityName="location"
selectionMode="multi"
valueType="id"
maxItems={ 3 }
placeholder="Flatten search results"
/>
<PickerInput
Expand All @@ -65,6 +66,7 @@ export default function LazyTreeSearch() {
entityName="location"
selectionMode="multi"
valueType="id"
maxItems={ 3 }
placeholder="Tree search results"
/>
</FlexRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default function ArrayLinkedPickers() {
entityName="City"
selectionMode="multi"
valueType="id"
maxItems={ 3 }
filter={ { country: country?.id } } // Your filter object, which will be send to the server
/>
</LabeledInput>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function AsyncPickerInputExample() {
entityName="location"
selectionMode="multi"
valueType="id"
maxItems={ 3 }
/>
</FlexCell>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default function PickerInputWithCustomFooter() {
selectionMode="single"
valueType="id"
sorting={ { field: 'level', direction: 'asc' } }
maxItems={ 3 }
renderFooter={ () => {
return (
<FlexRow padding="12">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default function SearchPositionsExample() {
onValueChange={ onValueChange }
entityName="person"
selectionMode="multi"
maxItems={ 3 }
searchPosition="input"
valueType="id"
/>
Expand All @@ -36,6 +37,7 @@ export default function SearchPositionsExample() {
onValueChange={ onValueChange }
entityName="person"
selectionMode="multi"
maxItems={ 3 }
searchPosition="none"
valueType="id"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import css from './TogglerConfiguration.module.scss';

export default function PickerTogglerConfigurationExample() {
const svc = useUuiContext();
const [value, onValueChange] = useState<string[]>([
'225284', '2747351', '3119841', '3119746',
]);
const [value, onValueChange] = useState<string[]>(['625144', '703448', '756135', '2950159']);

const loadCities = useCallback((request: LazyDataSourceApiRequest<City, string>) => {
return svc.api.demo.cities(request);
Expand Down
1 change: 1 addition & 0 deletions app/src/docs/_examples/pickerInput/ValueType.example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default function ValueTypeExamplePicker() {
selectionMode="multi"
emptyValue={ [] }
valueType="entity"
maxItems={ 3 }
/>
<Text>
Selected users:
Expand Down
2 changes: 1 addition & 1 deletion app/src/docs/pickerInput/PickerInput.doc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class PickerInputDoc extends BaseDocsBlock {
<DocExample title="Picker with changed array of items" path="./_examples/pickerInput/PickerWithChangingItemsArray.example.tsx" />
<DocExample title="Linked pickers" path="./_examples/pickerInput/LinkedPickers.example.tsx" />
<DocExample title="Change portal target and dropdown placement" path="./_examples/pickerInput/ConfigurePortalTargetAndPlacement.example.tsx" />
<DocExample title="Custom toggler tag render" path="./_examples/pickerInput/PickerTogglerTagDemo.example.tsx" />
<DocExample title="Custom toggler tag render" path="./_examples/pickerInput/CustomPickerTogglerTag.example.tsx" />
</>
);
}
Expand Down
12 changes: 7 additions & 5 deletions app/src/docs/pickerInput/pickerInputExamples.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as React from 'react';
import * as uui from '@epam/uui';
import { PickerTogglerTag, PickerTogglerTagProps, Tooltip } from '@epam/uui';
import { PickerInputProps, PickerTogglerTag, Tooltip } from '@epam/uui';
import { PickerTogglerRenderItemParams } from '@epam/uui-components';
import { IPropSamplesCreationContext } from '@epam/uui-docs';

type TRenderTogglerParam = Parameters<uui.PickerInputProps<any, any>['renderToggler']>[0];

Expand All @@ -25,20 +27,20 @@ export const renderTogglerExamples = [
},
];

export const renderTagExamples = [
export const renderTagExamples = (ctx: IPropSamplesCreationContext<PickerInputProps<any, any>>) => [
{
value: (props: PickerTogglerTagProps<any, any>) => {
value: (props: PickerTogglerRenderItemParams<any, any>) => {
if (props.isCollapsed) {
// rendering '+ N items selected' Tag, tooltip is present here by default
return <PickerTogglerTag { ...props } key="collapsed" />;
return <PickerTogglerTag { ...props } key="collapsed" getName={ (i) => ctx.getSelectedProps().getName(i) } />;
} else {
// rendering all other Tags with Tooltip
const continent = props.rowProps?.value?.tz ? props.rowProps?.value?.tz.split('/')[0].concat('/') : '';
const country = props.rowProps?.value?.countryName ? props.rowProps?.value?.countryName.concat('/') : '';
const tooltipContent = `${continent}${country}${props.caption}`;
return (
<Tooltip key={ props.rowProps?.id } content={ tooltipContent }>
<PickerTogglerTag { ...props } />
<PickerTogglerTag { ...props } getName={ (i) => ctx.getSelectedProps().getName(i) } />
</Tooltip>
);
}
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 5.8.4 - 22.07.2024

**What's Fixed**
* [PickerInput]: fixed '+N' toggler tag tooltip content with custom `getName` callback

# 5.8.3 - 19.07.2024

**What's New**
Expand Down
10 changes: 8 additions & 2 deletions uui/components/pickers/PickerToggler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ function PickerTogglerComponent<TItem extends string, TId>(
if (!!props.renderItem) {
return props.renderItem(itemPropsWithSize);
}
return <PickerTogglerTag { ...itemPropsWithSize } />;

return (
<PickerTogglerTag
{ ...itemPropsWithSize }
getName={ props.getName }
/>
);
};

return (
Expand All @@ -46,7 +52,7 @@ function PickerTogglerComponent<TItem extends string, TId>(
ref={ ref }
cx={ [applyPickerTogglerMods(props), props.cx] }
renderItem={ renderItem }
getName={ (item) => (props.getName ? props.getName(item) : item) }
getName={ props.getName }
cancelIcon={ systemIcons.clear }
dropdownIcon={ systemIcons.foldingArrow }
/>
Expand Down
6 changes: 4 additions & 2 deletions uui/components/pickers/PickerTogglerTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ interface PickerTogglerTagMods {
size?: types.ControlSize;
}

export interface PickerTogglerTagProps<TItem, TId> extends Overwrite<PickerTogglerTagMods, PickerTogglerTagModsOverride>, PickerTogglerRenderItemParams<TItem, TId>, Omit<TagProps, 'size'> {}
export interface PickerTogglerTagProps<TItem, TId> extends Overwrite<PickerTogglerTagMods, PickerTogglerTagModsOverride>, PickerTogglerRenderItemParams<TItem, TId>, Omit<TagProps, 'size'> {
getName: (item: TItem) => string;
}

export const PickerTogglerTag = React.forwardRef((props: PickerTogglerTagProps<any, any>, ref: React.Ref<HTMLElement>) => {
const tagProps = {
Expand All @@ -26,7 +28,7 @@ export const PickerTogglerTag = React.forwardRef((props: PickerTogglerTagProps<a
};

if (props.isCollapsed) {
const collapsedRows = props.collapsedRows.map((row) => row.value?.name).join(', ');
const collapsedRows = props.collapsedRows.map((row) => props.getName(row.value)).join(', ');
return (
<Tooltip
key="selected"
Expand Down

0 comments on commit c3d6060

Please sign in to comment.