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

Add stretchy type block #5

Closed
wants to merge 15 commits into from
Closed

Add stretchy type block #5

wants to merge 15 commits into from

Conversation

jffng
Copy link

@jffng jffng commented Jun 10, 2024

Description
This PR implements a stretchy type block, as a part of the Cool Tools project.

The remaining to-dos I think can be follow ups.

To-Do

  • Add a way to call the text resizing when a style attribute is updated
  • Add block update script
  • Add a better block icon
  • Figure out why rich text block controls are not rendering

@jffng jffng changed the title WIP: add stretchy type Add stretchy type block Jun 14, 2024
@jffng jffng requested a review from tommusrhodus July 1, 2024 17:05
@jffng jffng marked this pull request as ready for review July 1, 2024 17:06
@jffng jffng force-pushed the add/stretchy-type branch from d525f25 to c12a92f Compare July 1, 2024 17:08
}

document.addEventListener( 'DOMContentLoaded', handleFontSize );
window.addEventListener('resize', handleFontSize );
Copy link
Author

Choose a reason for hiding this comment

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

I tried this with the interactivity API, but it performed noticeably (visually) worse — the text would show up at the default size, and a split second later would resize — and it took a lot more code to do the same thing.

e4218c5

Maybe it could be optimized somehow.

@Nyiriland
Copy link

@jffng Take a look at https://cool-tools.mystagingwebsite.com/2024/06/25/stretchy-type/

I played around a bit, noticed the text is by default set to align-wide, unless nested in a full width group block. When nested in a block with horiztontal padding, the text width does not respect the padding, so we probably want to account for that.

@allancole
Copy link

When loading the block, the font resize doesn’t fire as expected, leading to the type sitting off center or breaking out beyond its container. However, when you manually resize the browser window, it fires correctly and resizes the type as expected:

Cool Tools - Stretchy Type Issue

Look at the letter “K” and notice how it initially the K is truncated but after resizing it fits properly.

@SantosGuillamot
Copy link
Collaborator

I was taking a look at this to understand the use case better and see if it could land. I have a couple of questions so far:

  • When you talk about "stretchy type," is it just a text that fits the max-width, or is there something else? (Sorry, I am unfamiliar with this term)
  • If that's the case, I feel we could extend the paragraph block to cover this use case. It would come with some benefits like reusing the block controls, applying styles, etc. Do you think that's worth pursuing?

@allancole
Copy link

allancole commented Oct 21, 2024

  • When you talk about "stretchy type," is it just a text that fits the max-width, or is there something else? (Sorry, I am unfamiliar with this term)

Almost. The idea is that the font-size for text inside a Stretchy Type block adapts to fit the size of its immediate parent container. Example: https://codepen.io/chriscoyier/pen/gKoVBg

  • If that's the case, I feel we could extend the paragraph block to cover this use case. It would come with some benefits like reusing the block controls, applying styles, etc. Do you think that's worth pursuing?

I’m personally okay with this effect extending the paragraph block as long as it can achieve the same thing. But typically, this effect is used on single lines of text. There may be cases where we would want the effect on a text thats more than one line, but we could save that for a second iteration. I also don’t know if there were other reasons for keeping it in a separate block. @Nyiriland may know the reasoning there 🤔

The most important requirements are:

  • The text naturally stretches to always fit the width of it’s parent container (like the example above).
  • The text never breaks outside of its parent container, regardless of other blocks, or changes to device and/or viewport size.
  • Text-block controls like color, font-family, letter-spacing and line-height, etc. remain configurable.

@Nyiriland
Copy link

Nyiriland commented Oct 21, 2024

I also don’t know if there were other reasons for keeping it in a separate block. @Nyiriland may know the reasoning there 🤔

I'm guessing it's like what @allancole said: the function is that it's a single line of text (and usually only a word or two), so many of the paragraph options or functions might be unnecessary.

@tommusrhodus
Copy link
Contributor

Closing this in favour of #32 where work is continuing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done ✅
Development

Successfully merging this pull request may close these issues.

5 participants