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

Fixes #1285 - API proposal to ClayLabelsInputField component #1292

Closed

Conversation

matuzalemsteles
Copy link
Member

🚨 This PR is not to be merged. Do not stick to the code now, but the idea behind. I will still send another PR to evaluate the implementation and our good practices, once this idea is valid.

Disclaimer

I'm sending the API proposal to the new ClayLabelsInputField component. View the documents and Invision to analyze the use cases.

Proposal

The component does not manipulate the data or changes internal states, it only triggers events of what is happening and letting the developer decide what to do with the information or validate the information for example. but always respecting the principles that the Lexicon is predicting.

Events

The developer has the freedom to make decisions using the "life cycles" of the component, some of them are:

  • labelAdded - The event is triggered when the user interacts with the input or dropdown by pressing comma or enter to create a new label or by clicking a dropdown item.
    • It's a good time for the developer to create their validation rules to add the label.
  • labelRemoved - The event is triggered when the user interacts with the labels, removing them through the backspace or clicking the label's close button.
  • labelFocused - The event is triggered when any label is focused.
  • queryChange - The event is triggered when the user is typing in the input.
    • This is a good time to evaluate autocomplete or provide suggestions based on your criteria.

I'm still not sure about the names of the events, if you think of something please comment.

Helper methods

The component provides some auxiliary methods so that it can be used with events.

  • filterAutocomplete - Filters an Array<string> that corresponds to query.
  • clearInput- It just clears the input.

Extension points

Lexicon predicts that developers can customize dropdown items with a list of contacts, phones ... or customize the labels for example. You can start by creating a variation using soy exclusivity deltemplate to achieve the expected results.

  • ClayInputField.Label
  • ClayInputField.ItemDropdown

Both deltemplates are given the corresponding data parameter. causing the developer to decide the data API.

As the markup is still not 100% ready I added some css on the demo page to get closer to the Lexicon just for testing purposes, this will change when the markup is ready.

Copy link
Contributor

@jbalsas jbalsas left a comment

Choose a reason for hiding this comment

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

Hey @matuzalemsteles, the component is amazing!! It's gorgeous and works perfectly!!

I've added some changes I'd like to see before we push this in. I'll summarize here:

  • Create a clay-dataprovider package that can abstract configuring components that show data. Data can come locally or remotely. This could be attached to other components later such as Table, List, CardGrid, Dropdown...
  • Generalize the concept of what gets selected to items, rather than just labels. Maybe we should rename this component to something like multiselect or itemselector... @victorvalle?
  • Keep hidden inputs that match the selected items values for standard form compatibility
  • Investigate if we can reuse fuzzy search from some existing implementation

What do you think?

Nice job overall, let's keep this going! 💪

* @public
* @return {Array} A list of items containing the corresponding characters
*/
filterAutocomplete(data, query) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's extract this to something like clay-dataprovider. See DataProvider for some reference or Kendo DataSource.

We should support both local and remote data. See also how we started doing it in clay-charts-shared and ClayBase

Copy link
Member Author

Choose a reason for hiding this comment

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

I was really thinking about not dealing with the DataProvider here 😅, I'll separate a task to just deal with it. Thanks for the examples.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, let's get this component through and open an issue to abstract that!


<div {$attributes}>
{if $label}
<label>{$label}</label>
Copy link
Contributor

Choose a reason for hiding this comment

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

I think <label> here will be missing a11y attributes like for

<div class="input-group input-group-stacked-sm-down">
<div class="input-group-item">
<div data-keydown="{$_handleOnKeydown}" ref="formGroupInput" class="form-control dropdown-full form-control-tag-group">
{if $selectedLabels}
Copy link
Contributor

Choose a reason for hiding this comment

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

For easier integration, it might be good to have hidden input fields here with the label values. That way the component will be compatible with standard form submission.

We can't just select labels, they need to have values associated with them, so our input data should look more like:

data: [{
    value: '123',
    label: 'Element 1'
}, {
    value: '456',
    label: 'Element 2'
}]

On the UI, we should show the labels, but we would be updating and keeping a list of <input type="hidden"> with the values of the selected items. There should also be a way to configure the name of the input so the server will be able to retrieve the data as a native array as expected.

{@param? _removeFocusedLabel: any}
{@param? contentRenderer: string}
{@param? filteredItems: list<?>}
{@param? selectedLabels: list<?>}
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's call this selectedItems?

Copy link
Member Author

Choose a reason for hiding this comment

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

I had put them as items, but I had decided to change thinking it was not a good option 😅. Referring to items is better. Thanks Chema!

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

* @param {!String} string
* @return {null|Object}
*/
export const match = (query, string) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

@gcmznt used fuzzy. Do you think that might be an option so we don't have to code and maintain this?

Copy link
Member Author

Choose a reason for hiding this comment

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

hey @jbalsas, Yeah, I thought of using it here, but I had trouble getting to the Lexicon markup result, with the fuzzy it concatenates in the characters that are match the strong tag, but we're having problems with the parameters that they accept HTML in Metal soy (metal/metal.js#381). And this utility is the same fuzzy implementation, but without the option to concatenate some markup, just list which items are active... so we can get to the desired https://github.com/liferay/clay/pull/1292/files#diff-087a55086d39969ce453305b7bca6fcfR160

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good for now, then!

@victorvalle
Copy link

@jbalsas multiselect sounds good to me. It could be confused with other old pattern but we could even use this to replace that one.

@jbalsas
Copy link
Contributor

jbalsas commented Nov 22, 2018

Doing some research I've found several instances of MultiSelect, and Select (with multipleSelection) and one of Picker.

I'd say the Select with a multipleSelection option sounds reasonable, but I particularly liked Microsoft's Picker approach. They then extend that idea to group specific pickers like DatePicker, TimePicker, PeoplePicker, ColorPicker... my vote would go to this last one... what do you think, @victorvalle, @matuzalemsteles?

Select

React Select
Material UI
Ant Design
Atlas Kit

MultiSelect

Webix
KendoUI
Blueprint

Picker

Microsoft Fabric

@matuzalemsteles
Copy link
Member Author

matuzalemsteles commented Nov 22, 2018

I like the idea of going with Picker but I think we would have to follow this line with the rest of the other components that are part of this group. Does it make sense?

Hey @matuzalemsteles, the component is amazing!! It's gorgeous and works perfectly!!
I've added some changes I'd like to see before we push this in. I'll summarize here:
Create a clay-dataprovider package that can abstract configuring components that show data. Data can come locally or remotely. This could be attached to other components later such as Table, List, CardGrid, Dropdown...
Generalize the concept of what gets selected to items, rather than just labels. Maybe we should rename this component to something like multiselect or itemselector... @victorvalle?
Keep hidden inputs that match the selected items values for standard form compatibility
Investigate if we can reuse fuzzy search from some existing implementation
What do you think?
Nice job overall, let's keep this going! 💪

hey @jbalsas, thanks 💪. I'm going back to this in the next episode, I'll take care of adding some additional tasks with what we have here.

@victorvalle
Copy link

I prefer mutli select when it can select multiple things.

@jbalsas
Copy link
Contributor

jbalsas commented Nov 22, 2018

Let's go with ClayMultiSelect, then! 👌

@matuzalemsteles matuzalemsteles mentioned this pull request Nov 26, 2018
7 tasks
@matuzalemsteles
Copy link
Member Author

I'm closing this to send the final changes in another PR.

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.

3 participants