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

Blockquote Element and Elements are now top level #1088

Merged
merged 16 commits into from
Jan 21, 2020

Conversation

gtrufitt
Copy link
Contributor

What does this change?

  • Blockquotes are now blockquotes
  • Elements are now top level
  • TextComponent storybook uses lorem instead of orem

Blockquotes are now blockquotes

This PR splits out the BlockQuoteElement from the TextBlockElement and is the prerequisite for guardian/frontend#22215.

Note that there is not full styling here, but adding some basic italics to differentiate the quotes.

Before

Screen Shot 2020-01-20 at 16 26 28

After

Screen Shot 2020-01-20 at 16 07 45

Elements are now top level

It also implements two pieces of workaround for dangerouslySetInnerHtml is not allowed on Fragments.

  1. Extracts out the logic to unwrapHtml based on a prefix and a suffix to a testable function which takes params:
	prefix: string,
    suffix: string,
    html: string,

Returning isUnwrapped if the prefix and suffix match first and last in a string match and returning either modified (matches stripped) html or unmodified html string.

  1. Extracts out the generation of a component to a generic component RewrappedComponent which takes params and generates an HTML element component either based on the tagName if isUnwrapped is true and span if false, containing the html and adding elCss via className:
{
    isUnwrapped: boolean;
    html: string;
    elCss?: string;
    tagName: string;
}

Before

image

After

image

TextComponent storybook uses lorem instead of orem

This tripped me up... twice 😆 First, I thought I'd caused an issue by removing the first letter, then realised it was because the L is omitted in the storybook, but then I realised I actually did have the issue but almost missed it because of the missing L. So this is purely from being able to reason with the story POV...

Screen Shot 2020-01-20 at 16 11 06

Why?

This allows us to have the proper elements at the top level, so as to:

a) have semantic markup on the page and the correct HTML structure for a11y and SEO reasons.
b) Allow spacefinder to see the correct elements. Note @shtukas - have we worked around this, do we need to adjust spacefinder?

Link to supporting Trello card

https://trello.com/c/kbiUllfA
https://trello.com/c/qL7tNWZT

Note

After all this, I discovered https://github.com/jonathantneal/react-dom-fragment

I don't think the solution we have here is great and it's possible this'll be nicer, so it might be worth reviewing if we touch this code again but I'd be more interested in whether someone creates a proper RFC and implementation in React/Preact.

Anyway.

tenor-42206596

@PRBuilds
Copy link

PRBuilds commented Jan 20, 2020

PRbuilds results:

LightHouse Reporting
1579597962.report.html

--automated message

Copy link
Contributor

@oliverlloyd oliverlloyd left a comment

Choose a reason for hiding this comment

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

I was initially confused here but then I read through commit by commit and everything clicked. Thanks for working in such an organised manner!

Comment on lines 5 to 9
export const unwrapHtml = (
prefix: string,
suffix: string,
html: string,
): { unwrappedHtml: string; willUnwrap: boolean } => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This might work better if the params were passed as an object? I'm really just throwing this out there as its a lot subjective (and somewhat IDE dependant) but I always get confused by param ordering and objects solve that.

Copy link
Contributor

Choose a reason for hiding this comment

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

After looking deeper, I see this was originally my code 🤦‍♂

I guess my comment still stands though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😄 Yeah no worries will update to object, because I actually did trip up with suffix and prefix the wrong way during dev!

suffix: string,
html: string,
): { unwrappedHtml: string; willUnwrap: boolean } => {
const willUnwrap = html.startsWith(prefix) && html.endsWith(suffix);
Copy link
Contributor

Choose a reason for hiding this comment

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

Sooo readable... ❤️

@@ -0,0 +1,15 @@
const stripTags = (html: string, prefix: string, suffix: string) => {
return html.slice(prefix.length, html.length - suffix.length);
Copy link
Contributor

Choose a reason for hiding this comment

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

I made a mistake here of thinking, hmm, what about substring()...

Several rabbit holes later: ignore me, slice() is good 👍

};

export const BlockquoteComponent: React.FC<Props> = ({ html }: Props) => {
const blockquote = css`
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a lot of the word 'blockquote' around, maybe blockquoteStyles?

@gtrufitt gtrufitt force-pushed the gtrufitt/add-blockquote-element branch from 54e3687 to d9b76b0 Compare January 21, 2020 09:11
@gtrufitt gtrufitt merged commit 38223e2 into master Jan 21, 2020
@gtrufitt gtrufitt deleted the gtrufitt/add-blockquote-element branch January 21, 2020 09:23
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