Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PickerTogglerTag#2008 #2087

Merged
merged 16 commits into from
Apr 3, 2024
Merged

Conversation

vik753
Copy link
Collaborator

@vik753 vik753 commented Mar 25, 2024

Issue link(if exists): #2008

Description: added new component PickerTogglerTag to use with maxItems property, and added into a PickerInput new property renderTag, for rendering any custom variants of tags in the PickerToggler.

@vik753 vik753 requested a review from AlekseyManetov March 25, 2024 09:58
Copy link

github-actions bot commented Mar 25, 2024

Generated by: track-bundle-size
Generated at: Wed, 03 Apr 2024 14:16:11 GMT
Bundle size diff (in kBytes). Not gzipped. Both CSS & JS included.
Baseline: v5.6.1 (2024-03-05)
CI Status: ok

Module Baseline Size
(v5.6.1)
Size Diff Within
Threshold
Threshold
(min - max)
templateApp 1041.48 1043.58 +2.1
js:+1.65
css:+0.46
🆗 937.33 - 1145.63
@epam/app 6402.7 6614.61 +211.92
js:+208.36
css:+3.56
🆗 5762.42 - 7042.96
@epam/draft-rte 53.77 53.78 +0.01
js:+0.01
css:+0
🆗 48.39 - 59.15
@epam/electric 4.46 4.49 +0.01
js:+0
css:+0.01
🆗 4.02 - 4.91
@epam/promo 55.29 55.14 -0.14
js:+0.06
css:-0.19
🆗 49.75 - 60.81
@epam/uui-extra 0.21 0.21 0
js:0
css:0
🆗 0.19 - 0.23
@epam/loveship 101.41 101.17 -0.24
js:+0
css:-0.24
🆗 91.27 - 111.55
@epam/uui-components 269.68 271.33 +1.66
js:+1.57
css:+0.08
🆗 242.71 - 296.64
@epam/uui-core 273.65 274.17 +0.51
js:+0.51
css:0
🆗 246.29 - 301.02
@epam/uui-db 42.31 42.31 0
js:0
css:0
🆗 38.08 - 46.54
@epam/uui-docs 174.98 175.53 +0.56
js:+0.98
css:-0.41
🆗 157.47 - 192.47
@epam/uui-editor 157.65 173.26 +15.61
js:+15.92
css:-0.31
🆗 141.89 - 173.42
@epam/uui-timeline 47.19 47.19 0
js:+0
css:0
🆗 42.47 - 51.91
@epam/uui 580.2 581.31 +1.11
js:+0.76
css:+0.35
🆗 522.18 - 638.23
new sizes (raw)

To set the sizes as a new baseline, you can copy/paste next content to the uui-build/config/bundleSizeBaseLine.json and commit the file.

{
  "version": "5.7.1",
  "timestamp": "2024-04-03",
  "sizes": {
    "templateApp": {
      "css": 284412,
      "js": 784215
    },
    "@epam/app": {
      "css": 1618031,
      "js": 5155332
    },
    "@epam/draft-rte": {
      "css": 9762,
      "js": 45308
    },
    "@epam/electric": {
      "css": 2289,
      "js": 2299
    },
    "@epam/promo": {
      "css": 40368,
      "js": 16101
    },
    "@epam/uui-extra": {
      "css": 0,
      "js": 213
    },
    "@epam/loveship": {
      "css": 49451,
      "js": 54148
    },
    "@epam/uui-components": {
      "css": 22214,
      "js": 255628
    },
    "@epam/uui-core": {
      "css": 0,
      "js": 280745
    },
    "@epam/uui-db": {
      "css": 0,
      "js": 43327
    },
    "@epam/uui-docs": {
      "css": 3189,
      "js": 176559
    },
    "@epam/uui-editor": {
      "css": 12625,
      "js": 164792
    },
    "@epam/uui-timeline": {
      "css": 2251,
      "js": 46073
    },
    "@epam/uui": {
      "css": 272887,
      "js": 322377
    }
  }
}

Generated by: generate-components-api
CI Status: ok

Total amount of exported types/props without JSDoc comments

Amount
Types 281 (+2) ⚠️🆗
Props 286 (+0) 🆗
New missing comments
NOTE: It's either a new exported types/props without JSDoc, or it's an existing code from which you deleted the JSDoc comments.
Types:
- @epam/uui-components:PickerTogglerRenderItemParams
- @epam/uui:PickerTogglerTagProps
Props:
- <empty>

import { FlexCell, PickerInput, PickerTogglerTag, Tooltip } from '@epam/uui';
import { Location } from '@epam/uui-docs';

const cascadeSelectionModes: Array<{ id: 'explicit' | 'implicit'; caption: string }> = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have cascadeSelection options in this example?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed it, it will work by default

@@ -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" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change title to 'Custom toggler tag render'

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"uui-richTextEditor-code": true
},
{
"text": " is a component we recommend to use for rendering Tags."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change this here text to - You can utilize the default UUI implementation of tags for PickerInput by using the PickerTogglerTag component.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -10,7 +10,7 @@ export const i18n = {
showAll: 'SHOW ALL',
},
pickerToggler: {
createItemValue: (length: number, entityName: string) => `${length} ${entityName} selected`,
createCollapsedName: (length: number, entityName: string) => `+ ${length} ${entityName} selected`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can't rename this object fields since it will cause the breaking change, let's revert it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

export type PickerInputProps<TItem, TId> = SizeMod & IHasEditMode & PickerInputBaseProps<TItem, TId>;
export type PickerInputProps<TItem, TId> = SizeMod & IHasEditMode & PickerInputBaseProps<TItem, TId> & {
/**
* Render Callback for making custom Tags.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change to - 'Render callback for picker toggler selection tag'

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  - If omitted, default `PickerTogglerTag` component will be rendered.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

const renderTargetFn = props.renderToggler || ((pickerTogglerProps) => (
<PickerToggler
{ ...pickerTogglerProps }
renderItem={ props.renderTag ? (renderItemProps) => props.renderTag(renderItemProps) : null }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add renderItem into targetProps params. And also why do we have this condition? i guess we can just pass it as is, without wrapping into arrow function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

rowProps={ itemProps.rowProps }
key={ itemProps.isCollapsed ? 'collapsed' : itemProps.rowProps?.id as string }
size={ props.size }
isDisabled={ props.isDisabled || props.isReadonly || itemProps.isDisabled }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I supposed that we shouldn't make any props calculation here, we should receive final prop from params and here just spread it to the component, i believe that default renderItem callback should look like:

   const renderItem = (itemProps: PickerTogglerTagProps<TItem, TId>) => (
        <PickerTogglerTag { ...itemProps } /> 
        )

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left only size here, or do we want to move it to the uui-components?

props.onClear?.();
let isDisabled = props.isDisabled || props.isReadonly;

const multiItems = props.selection?.map((row) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename this variable to 'tags', to be more informative

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const multiItems = props.selection?.map((row) => {
isDisabled = isDisabled || row.isDisabled;

const newMultiItems = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename this variable to 'tagProps', to be more informative

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

valueType="id"
maxItems={ 2 }
renderTag={ (props) => {
if (props.isCollapsed) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add comment that it renders 'N items selected' tag

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

/>
);
function PickerTogglerComponent<TItem extends string, TId>(props: PickerTogglerProps<TItem, TId> & PickerTogglerMods, ref: React.ForwardedRef<HTMLElement>): JSX.Element {
const renderItem = (itemProps: PickerTogglerTagProps<TItem, TId>) => <PickerTogglerTag { ...itemProps } size={ props.size } />;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add size to the result itemProps which will be passed to the user renderItem

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

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 row props (see more: uui-components/src/pickers/PickerToggler.tsx PickerTogglerProps<TItem = any, TId = any>) */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** DataRowProps object of the rendered item. */

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

export interface PickerTogglerTagProps<TItem, TId> extends 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. */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** Indicates that tag is collapsed rest selected items, like '+N items selected' */

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


export default function PickerTogglerTagDemoExample() {
const svc = useUuiContext();
const [value, onValueChange] = useState<string[]>([]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add initial items, for example 5

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"type": "paragraph",
"children": [
{
"text": "You can utilize the default UUI implementation of tags for PickerInput by using the "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add description that user should use renderTag prop for such cunstomization

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* Render callback for picker toggler selection tag
* If omitted, default `PickerTogglerTag` component will be rendered
*/
renderTag?: (props: PickerTogglerTagProps<TItem, TId>) => JSX.Element;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this callback receive IRenderItemProps interface, not PickerTogglerTagProps, yes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

import { getMaxItems } from './helpers';

export interface IRenderItemProps<TItem, TId> extends IHasCaption, IDisableable {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets rename to PickerTogglerRenderItemParams

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@AlekseyManetov AlekseyManetov merged commit 744dffa into develop Apr 3, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants