Skip to content

Commit

Permalink
[PickerTogglerTag]: removed tooltipContext and made a doc example
Browse files Browse the repository at this point in the history
  • Loading branch information
vik753 committed Mar 25, 2024
1 parent 1535bea commit e74fe08
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 124 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React, { useState } from 'react';
import { DataQueryFilter, useLazyDataSource, useUuiContext } from '@epam/uui-core';
import { FlexCell, PickerInput, PickerTogglerTag, Tooltip } from '@epam/uui';
import { Location } from '@epam/uui-docs';

const cascadeSelectionModes: Array<{ id: 'explicit' | 'implicit'; caption: string }> = [
{
id: 'explicit',
caption: 'Explicit cascade selection',
}, {
id: 'implicit',
caption: 'Implicit cascade selection',
},
];

export default function PickerTogglerTagDemoExample() {
const svc = useUuiContext();
const [value, onValueChange] = useState<string[]>();
const [cascadeSelection] = useState(cascadeSelectionModes[0].id);

const dataSource = useLazyDataSource<Location, string, DataQueryFilter<Location>>(
{
api: (request, ctx) => {
const { search } = request;
// and since parentId is meaningful value, it is required to exclude it from the filter.
const filter = search ? {} : { parentId: ctx?.parentId };
return svc.api.demo.locations({ ...request, search, filter });
},
getId: (i) => i.id,
getParentId: (i) => i.parentId,
getChildCount: (l) => l.childCount,
},
[],
);

return (
<FlexCell width={ 300 }>
<PickerInput
dataSource={ dataSource }
value={ value }
onValueChange={ onValueChange }
entityName="location"
selectionMode="multi"
valueType="id"
cascadeSelection={ cascadeSelection }
maxItems={ 2 }
renderTag={ (props) => {
if (props.isCollapsed) {
return (
<PickerTogglerTag { ...props } key="selected" />
);
} else {
return (
<Tooltip key={ props.rowProps?.id } content={ `${props.rowProps?.path.map((i) => i.value.name).join('/')}/${props.caption}` }>
<PickerTogglerTag { ...props } />
</Tooltip>
);
}
} }
/>
</FlexCell>
);
}
1 change: 1 addition & 0 deletions app/src/docs/pickerInput/PickerInput.doc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,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="PickerTogglerTag and renderTag demo" path="./_examples/pickerInput/PickerTogglerTagDemo.example.tsx" />
</>
);
}
Expand Down
2 changes: 0 additions & 2 deletions app/src/sandbox/SandboxPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { ProjectTasksDemo } from './tasks/ProjectTasksDemo';
import { RichTextEditorDemo } from './RTE/rteDemo';
import { TableColumnConfigModalTest } from './tableColConfigModal/TableColumnConfigModalTest';
import { PalettePage } from './tokens/palette/palettePage';
import { PickerTogglerTagDemo } from './pickerTogglerTag/PickerTogglerTagDemo';

export function SandboxPage() {
const items = useMemo(
Expand All @@ -47,7 +46,6 @@ export function SandboxPage() {
{ id: 'tagInput', name: 'Tag Input', component: TagInputDemo },
{ id: 'tokens', name: 'Tokens' },
{ parentId: 'tokens', id: 'tokensPalette', name: 'Palette', component: PalettePage },
{ id: 'pickerTogglerTag', name: 'PickerTogglerTag', component: PickerTogglerTagDemo },
],
[],
);
Expand Down
92 changes: 0 additions & 92 deletions app/src/sandbox/pickerTogglerTag/PickerTogglerTagDemo.tsx

This file was deleted.

17 changes: 17 additions & 0 deletions public/docs/content/examples-pickerInput-PickerTogglerTagDemo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{
"type": "paragraph",
"children": [
{
"text": "In this example we use "
},
{
"text": "renderTag",
"uui-richTextEditor-code": true
},
{
"text": " callback to make custom Tags with Tooltip if they are not a Tag for collapsed values."
}
]
}
]
28 changes: 10 additions & 18 deletions public/docs/docsGenOutput/docsGenOutput.json
Original file line number Diff line number Diff line change
Expand Up @@ -72060,6 +72060,10 @@
"raw": "SizeMod & IHasEditMode & PickerBaseOptions<TItem, TId> & { selectionMode: 'single'; valueType?: 'id' | undefined; } & IEditable<TId> & IAnalyticableOnChange<any> & ICanFocus<HTMLElement> & IHasPlaceholder & IDisableable & ICanBeReadonly & IHasIcon & { editMode?: PickerInputEditMode | undefined; maxItems?: number | undefined; minBodyWidth?: number | undefined; isSingleLine?: boolean | undefined; dropdownPlacement?: Placement | undefined; renderToggler?: ((props: PickerTogglerProps<TItem, TId>) => React.ReactNode) | undefined; searchPosition?: PickerInputSearchPosition | undefined; disableClear?: boolean | undefined; minCharsToSearch?: number | undefined; dropdownHeight?: number | undefined; autoFocus?: boolean | undefined; rawProps?: { input?: (React.HTMLAttributes<HTMLDivElement> & Record<`data-${string}`, string>) | undefined; body?: (React.HTMLAttributes<HTMLDivElement> & Record<`data-${string}`, string>) | undefined; } | undefined; renderFooter?: ((props: PickerInputFooterProps<TItem, TId>) => React.ReactNode) | undefined; fixedBodyPosition?: boolean | undefined; portalTarget?: HTMLElement | undefined; inputCx?: ClassValue; bodyCx?: ClassValue; highlightSearchMatches?: boolean | undefined; searchDebounceDelay?: number | undefined; id?: string | undefined; } & { renderTag?: ((props: PickerTogglerTagProps<TItem, TId>) => JSX.Element) | undefined; } | SizeMod & IHasEditMode & PickerBaseOptions<TItem, TId> & { selectionMode: 'single'; valueType: 'entity'; } & IEditable<TItem> & IAnalyticableOnChange<any> & ICanFocus<HTMLElement> & IHasPlaceholder & IDisableable & ICanBeReadonly & IHasIcon & { editMode?: PickerInputEditMode | undefined; maxItems?: number | undefined; minBodyWidth?: number | undefined; isSingleLine?: boolean | undefined; dropdownPlacement?: Placement | undefined; renderToggler?: ((props: PickerTogglerProps<TItem, TId>) => React.ReactNode) | undefined; searchPosition?: PickerInputSearchPosition | undefined; disableClear?: boolean | undefined; minCharsToSearch?: number | undefined; dropdownHeight?: number | undefined; autoFocus?: boolean | undefined; rawProps?: { input?: (React.HTMLAttributes<HTMLDivElement> & Record<`data-${string}`, string>) | undefined; body?: (React.HTMLAttributes<HTMLDivElement> & Record<`data-${string}`, string>) | undefined; } | undefined; renderFooter?: ((props: PickerInputFooterProps<TItem, TId>) => React.ReactNode) | undefined; fixedBodyPosition?: boolean | undefined; portalTarget?: HTMLElement | undefined; inputCx?: ClassValue; bodyCx?: ClassValue; highlightSearchMatches?: boolean | undefined; searchDebounceDelay?: number | undefined; id?: string | undefined; } & { renderTag?: ((props: PickerTogglerTagProps<TItem, TId>) => JSX.Element) | undefined; } | SizeMod & IHasEditMode & PickerBaseOptions<TItem, TId> & { selectionMode: 'multi'; valueType?: 'id' | undefined; emptyValue?: [] | null | undefined; } & IEditable<TId[]> & IAnalyticableOnChange<any> & ICanFocus<HTMLElement> & IHasPlaceholder & IDisableable & ICanBeReadonly & IHasIcon & { editMode?: PickerInputEditMode | undefined; maxItems?: number | undefined; minBodyWidth?: number | undefined; isSingleLine?: boolean | undefined; dropdownPlacement?: Placement | undefined; renderToggler?: ((props: PickerTogglerProps<TItem, TId>) => React.ReactNode) | undefined; searchPosition?: PickerInputSearchPosition | undefined; disableClear?: boolean | undefined; minCharsToSearch?: number | undefined; dropdownHeight?: number | undefined; autoFocus?: boolean | undefined; rawProps?: { input?: (React.HTMLAttributes<HTMLDivElement> & Record<`data-${string}`, string>) | undefined; body?: (React.HTMLAttributes<HTMLDivElement> & Record<`data-${string}`, string>) | undefined; } | undefined; renderFooter?: ((props: PickerInputFooterProps<TItem, TId>) => React.ReactNode) | undefined; fixedBodyPosition?: boolean | undefined; portalTarget?: HTMLElement | undefined; inputCx?: ClassValue; bodyCx?: ClassValue; highlightSearchMatches?: boolean | undefined; searchDebounceDelay?: number | undefined; id?: string | undefined; } & { renderTag?: ((props: PickerTogglerTagProps<TItem, TId>) => JSX.Element) | undefined; } | SizeMod & IHasEditMode & PickerBaseOptions<TItem, TId> & { selectionMode: 'multi'; valueType: 'entity'; emptyValue?: [] | null | undefined; } & IEditable<TItem[]> & IAnalyticableOnChange<any> & ICanFocus<HTMLElement> & IHasPlaceholder & IDisableable & ICanBeReadonly & IHasIcon & { editMode?: PickerInputEditMode | undefined; maxItems?: number | undefined; minBodyWidth?: number | undefined; isSingleLine?: boolean | undefined; dropdownPlacement?: Placement | undefined; renderToggler?: ((props: PickerTogglerProps<TItem, TId>) => React.ReactNode) | undefined; searchPosition?: PickerInputSearchPosition | undefined; disableClear?: boolean | undefined; minCharsToSearch?: number | undefined; dropdownHeight?: number | undefined; autoFocus?: boolean | undefined; rawProps?: { input?: (React.HTMLAttributes<HTMLDivElement> & Record<`data-${string}`, string>) | undefined; body?: (React.HTMLAttributes<HTMLDivElement> & Record<`data-${string}`, string>) | undefined; } | undefined; renderFooter?: ((props: PickerInputFooterProps<TItem, TId>) => React.ReactNode) | undefined; fixedBodyPosition?: boolean | undefined; portalTarget?: HTMLElement | undefined; inputCx?: ClassValue; bodyCx?: ClassValue; highlightSearchMatches?: boolean | undefined; searchDebounceDelay?: number | undefined; id?: string | undefined; } & { renderTag?: ((props: PickerTogglerTagProps<TItem, TId>) => JSX.Element) | undefined; }",
"print": [
"type PickerInputProps<TItem, TId> = SizeMod & IHasEditMode & PickerInputBaseProps<TItem, TId> & {",
" /**",
" * Render Callback for the Tags.",
" * If omitted, they will be rendered by default.",
" */",
" renderTag?: (props: PickerTogglerTagProps<TItem, TId>) => JSX.Element;",
"};"
]
Expand Down Expand Up @@ -72997,6 +73001,12 @@
{
"uid": "renderTag",
"name": "renderTag",
"comment": {
"raw": [
"Render Callback for the Tags.",
" If omitted, they will be rendered by default."
]
},
"typeValue": {
"raw": "(props: PickerTogglerTagProps<TItem, TId>) => JSX.Element"
},
Expand Down Expand Up @@ -76447,8 +76457,6 @@
" size?: types.ControlSize;",
" /** If this is true, then the PickerTogglerTag will be an additional tag with the number of collapsed elements in the caption. */",
" isCollapsed?: boolean;",
" /** Defines content for tooltip */",
" tooltipContent?: string;",
" /** Defines row props (see more: uui-components/src/pickers/PickerToggler.tsx PickerTogglerProps<TItem = any, TId = any>) */",
" rowProps?: DataRowProps<TItem, TId>;",
"};"
Expand Down Expand Up @@ -76901,22 +76909,6 @@
},
"required": false
},
{
"uid": "tooltipContent",
"name": "tooltipContent",
"comment": {
"raw": [
"Defines content for tooltip"
]
},
"typeValue": {
"raw": "string"
},
"editor": {
"type": "string"
},
"required": false
},
{
"uid": "rowProps",
"name": "rowProps",
Expand Down
4 changes: 4 additions & 0 deletions uui/components/pickers/PickerInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const pickerHeight = 300;
const pickerWidth = 360;

export type PickerInputProps<TItem, TId> = SizeMod & IHasEditMode & PickerInputBaseProps<TItem, TId> & {
/**
* Render Callback for making custom Tags.
* If omitted, they will be rendered by default component PickerTogglerTag.
*/
renderTag?: (props: PickerTogglerTagProps<TItem, TId>) => JSX.Element;
};

Expand Down
15 changes: 3 additions & 12 deletions uui/components/pickers/PickerTogglerTag.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import * as React from 'react';
import * as types from '../types';
import { Tag, TagProps } from '../widgets';
import { Tooltip } from '../overlays';
import { DataRowProps } from '@epam/uui-core';

export type PickerTogglerTagProps<TItem, TId> = TagProps & {
/** Defines component size */
size?: types.ControlSize;
/** If this is true, then the PickerTogglerTag will be an additional tag with the number of collapsed elements in the caption. */
isCollapsed?: boolean;
/** Defines content for tooltip */
tooltipContent?: string;
/** Defines row props (see more: uui-components/src/pickers/PickerToggler.tsx PickerTogglerProps<TItem = any, TId = any>) */
rowProps?: DataRowProps<TItem, TId>;
};
Expand All @@ -32,18 +29,12 @@ const getPickerTogglerButtonSize = (propSize?: types.ControlSize):TagProps['size
}
};

export function PickerTogglerTag(props: PickerTogglerTagProps<any, any>): JSX.Element {
export const PickerTogglerTag = React.forwardRef((props: PickerTogglerTagProps<any, any>, ref: React.Ref<HTMLSpanElement>): JSX.Element => {
const tagProps = {
...props,
tabIndex: -1,
size: getPickerTogglerButtonSize(props.size),
};

return (props.tooltipContent)
? (
<Tooltip content={ props.tooltipContent } openDelay={ 400 }>
<Tag { ...tagProps } />
</Tooltip>
)
: <Tag { ...tagProps } />;
}
return <Tag ref={ ref } { ...tagProps } />;
});

0 comments on commit e74fe08

Please sign in to comment.