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

Style overlapping annotations #702

Merged
merged 4 commits into from Sep 22, 2020
Merged

Style overlapping annotations #702

merged 4 commits into from Sep 22, 2020

Conversation

ronnyroeller
Copy link
Collaborator

Description

The annotation-extension would allow to style individual annotations via a CSS class. This led to issues with overlapping annotations. For example, if an annotation with a red background and another with a green background were overlapping, the editor would show (more or less) randomly one of the two colors.
Now, the annotation-extension allows users to style decorations based on all overlapping annotations within a given decoration. The default implementation visualizes overlapping annotations by showing a darker shade the more annotations are overlapping.

The approach was confirmed by Marijn: https://discuss.prosemirror.net/t/how-to-style-overlapping-inline-decorations/3162

Checklist

  • I have read the contributing document.
  • My code follows the code style of this project and pnpm fix completed successfully.
  • I have updated the documentation where necessary.
  • New code is unit tested and all current tests pass when running pnpm test.

Screenshots

image

Ronny Roeller added 2 commits September 22, 2020 21:36
The annotation-extension would allow to style individual annotations via a CSS class. This led to issues with overlapping annotations. For example, if an annotation with a red background and another with a green background were overlapping, the editor would show (more or less) randomly one of the two colors.

Now, the annotation-extension allows users to style decorations based on all overlapping annotations within a given decoration. The default implementation visualizes overlapping annotations by showing a darker shade the more annotations are overlapping.

The approach was confirmed by Marijn: https://discuss.prosemirror.net/t/how-to-style-overlapping-inline-decorations/3162
@changeset-bot
Copy link

changeset-bot bot commented Sep 22, 2020

🦋 Changeset is good to go

Latest commit: 883f163

We got this.

This PR includes changesets to release 6 packages
Name Type
@remirror/extension-annotation Minor
@remirror/storybook Minor
remirror Minor
@remirror/playground Minor
@remirror/website Patch
with-next Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added package: remirror 🟣 Label for the remirror package and all relevant scoped `@remirror/*` packages. test: unit ✅ A label for updating tests and test configuration. type: changeset 🦋 A change has been made to the changesets folder. type: support 📚 A change focused on improving the architecture and structure of the support directory. status: sponsored 💖 All issues and pull requests which have been requested from or created by sponsors. labels Sep 22, 2020
@github-actions
Copy link
Contributor

github-actions bot commented Sep 22, 2020

Copy link
Member

@ifiokjr ifiokjr left a comment

Choose a reason for hiding this comment

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

This looks amazing!

Co-authored-by: Ifiok Jr. <ifiokotung@gmail.com>
*/
function defaultGetStyle<A extends Annotation>(annotations: Array<AnnotationWithoutText<A>>) {
// Consider up to 5 overlapping annotations
const backgroundShade = Math.min(annotations.length, 5) / 5;
Copy link
Member

@ifiokjr ifiokjr Sep 22, 2020

Choose a reason for hiding this comment

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

Your comments are great and give a really good understanding of what’s happening.

Maybe store the number 5 as a constant MAX_OVERLAPPING_ANNOTATIONS or something better named in the outer scope.

*
* Approach was confirmed by Marijn: https://discuss.prosemirror.net/t/how-to-style-overlapping-inline-decorations/3162
*/
export function toSegments<A extends Annotation>(
Copy link
Member

Choose a reason for hiding this comment

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

Brilliant 🤯

Copy link
Member

Choose a reason for hiding this comment

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

The whole function not just this one line 😄

@ifiokjr ifiokjr merged commit 89bd1e8 into next Sep 22, 2020
@ifiokjr ifiokjr deleted the wip/annotation-styling branch September 22, 2020 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: remirror 🟣 Label for the remirror package and all relevant scoped `@remirror/*` packages. status: sponsored 💖 All issues and pull requests which have been requested from or created by sponsors. test: unit ✅ A label for updating tests and test configuration. type: changeset 🦋 A change has been made to the changesets folder. type: support 📚 A change focused on improving the architecture and structure of the support directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants