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

Highlight own vaadin-messages from others #30

Closed
juuso-vaadin opened this issue May 3, 2021 · 8 comments
Closed

Highlight own vaadin-messages from others #30

juuso-vaadin opened this issue May 3, 2021 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@juuso-vaadin
Copy link

Is your feature request related to a use case? Please describe.
In vaadin-message-list, I would like to be able to style my own messages to be different from other messages.

Describe the solution you'd like
There should be an easy way to apply custom styling to certain messages. This could be done by introducing an attribute to vaadin-message.

Additional context
image

@juuso-vaadin juuso-vaadin added the enhancement New feature or request label May 3, 2021
@jouni
Copy link
Member

jouni commented May 3, 2021

The same feature could also be used to distinguish “system messages” from messages from end users.

@Peppe
Copy link
Contributor

Peppe commented May 3, 2021

Agreed. I think this could be called something like "source" or "origin". We should still separate "me" and "system" so that they can be handled separately, as both can have separate visuals and separate features (delete, edit..)

Thoughts on how this could be implemented. Names can be debated:

  1. Add a new property to called "origin". Recognized values would be "me", "system" and "others". "others" would be the default if nothing is configured.
  2. Add the origin property to the json format that 's input property takes in.
  3. CollaborationMessageList would automatically add "origin=me" on those messages that has the same userName as the currentUser attached to the list.

@anezthes
Copy link

anezthes commented May 3, 2021

I can write the CSS for that on Wednesday.

Semi-related: we have a PR for 'system' messages here:

https://github.com/vaadin/vaadin-messages/pull/47/files

Just CSS though.

@jouni
Copy link
Member

jouni commented May 3, 2021

My initial thought was to add support for setting a theme attribute value for individual message components. Basically the same as what Jens suggested, but avoiding a new concept of “origin”.

And apparently Jonte had a similar idea, since me already wrote the CSS like that.

@pekam
Copy link
Contributor

pekam commented May 11, 2021

We're indeed planning to implement this with the theme variant mechanism, which enables users to provide also custom attributes for custom theming per message. One challenge there is that the Flow's HasTheme interface can't be applied for the non-component MessageListItem class. We'll just add some of the HasTheme API to MessageListItem and live with the fact that it's not fully compatible with the Flow component theme APIs.

The theme variant for own messages would be called outbound.

Steps:

  1. Web component: Support theme property in the items of <vaadin-message-list>: messageList.items = [{text: "Hello", theme: "outbound foo bar"}]. The theme will be simply propagated to the message element: <vaadin-message theme="outbound foo bar">.
  2. Flow component: Add Java APIs for addThemeNames and removeThemeNames in MessageListItem, copied from HasTheme interface.
  3. CE: Automatically call addThemeNames("outbound") when generating the message item that is sent by the local user.

At this point the developers can target own messages for styling.

  1. Enable CE users to configure custom theme variants per message. This needs some form of function API because CE automatically manages the items. It can as well be made generic so that you can configure any part of the MessageListItem instead of limiting to the theme variant case. E.g. to disable the default outbound variant and add a custom inbound variant:
collaborationMessageList.setMessageConfigurator((item, user) -> {
    item.removeThemeNames("outbound");
    if (!user.equals(localUser)) {
        item.addThemeNames("inbound");
    }
});
  1. Implement outbound theme for Lumo and Material (and potentially other variants like filled), add type-safe Flow theme variant APIs such as item.addThemeVariants(MessageVariant.LUMO_OUTBOUND).

@pekam pekam self-assigned this May 11, 2021
pekam added a commit to vaadin/web-components that referenced this issue May 11, 2021
the first step towards highlighting your own messages:
vaadin/collaboration-kit#30
pekam added a commit to vaadin/web-components that referenced this issue May 11, 2021
the first step towards highlighting your own messages:
vaadin/collaboration-kit#30
pekam added a commit to vaadin/flow-components that referenced this issue May 12, 2021
Only with strings at this point, since no theme
variants have been implemented so far.

This enables developers to apply custom theming
per each message in a MessageList.

Related issue: vaadin/collaboration-kit#30
pekam added a commit to vaadin/flow-components that referenced this issue May 18, 2021
Only with strings at this point, since no theme
variants have been implemented so far.

This enables developers to apply custom theming
per each message in a MessageList.

Related issue: vaadin/collaboration-kit#30
@pekam
Copy link
Contributor

pekam commented May 24, 2021

We concluded with @anezthes that we should not set any theme variant to own messages by default. Highlighting your own messages looks good only with a theme that has "bubbles" around the content, like in the screenshot in this ticket. Our message components are similar to Slack and Discord, where there's also no highlight for own messages.

Any custom theme variant can still be added to own messages with the new message configurator API:

collaborationMessageList.setMessageConfigurator((message, user) -> {
    if (user.equals(localUser)) {
        message.addThemeNames("outbound");
    }
});

@pekam
Copy link
Contributor

pekam commented May 24, 2021

The issue is resolved with the following PRs:

  1. feat: add theme property to vaadin-message-list items web-components#372 add theme property to vaadin-message-list items
  2. feat: add theme API to MessageListItem flow-components#979 add theme API to MessageListItem
  3. https://github.com/vaadin/collaboration-engine-internal/pull/588 add MessageConfigurator API

@pekam
Copy link
Contributor

pekam commented May 25, 2021

I opened a new ticket for providing Lumo theme variants out of the box: vaadin/web-components#1994

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants