News for hackers. Stuff that matters.
Re:React Wrap Balancer: Simple React Component That Makes Ti... by mikojan on Thursday December 22, 2022 @05:16PM (#34099600)
This is amazing! Thank you for bringing it up!

I viciously hate that part of writing an article where I am editing the title text again and again to make it look good in the contexts of my websites.

Re:React Wrap Balancer: Simple React Component That Makes Ti... by josefrichter on Thursday December 22, 2022 @08:00PM (#34101089)
This is fantastic. I remember having a requirement for this on a project some 2 years ago. The devs didn’t know how to do it easily and as always, they had bigger fish to fry. Glad to see this exists now.

Would this work with React Native too?

Re:React Wrap Balancer: Simple React Component That Makes Ti... by shuding on Thursday December 22, 2022 @08:54PM (#34101468)
No it didn’t work with React Native because it uses a bunch of browser APIs to measure the content size, but I hope someone will build an alternative for RN!
Re:React Wrap Balancer: Simple React Component That Makes Ti... by exogen on Thursday December 22, 2022 @10:21PM (#34102019)
Hey, a topic I know something about! I've done something similar to this: "tightening" text to resist wrapping but not prevent it. I'll describe:

A subtle feature of OS X since its early days (but possibly not anymore) is that if you had something like a window title or a filename in Finder's column view, and you made the window or column smaller, before cutting off the text, OS X would shrink the letter spacing (and possibly other metrics) by a barely perceptible amount, so that the text could still fit. I always thought that was brilliant.

One day I was working on a very design-forward web project and wanted the same thing. Occasionally, text would wrap when it really only needed a few pixels of wiggle room to stay on one line. Thus, react-typesetting and a <TightenText> component were born: https://exogen.github.io/react-typesetting/

Eventually I realized it would be neat to make work with variable fonts (and their arbitrary axes) as well. Check out this demo: https://react-typesetting-alpha.surge.sh

I haven't touched or thought about this in a while, but I still think there's an interesting blog post to be made there about how it's done!

An interesting fact I learned about professional typesetting (and justification) is that, in order to justify lines, books don't just shrink the letter and word spacing: they also squish the characters themselves (in CSS this can be done with a scaleX transform). I guess my eyes have actually noticed this when reading books before, but I found it surprising because I always thought of the letterforms themselves as sacrosanct, and any distortion would be unacceptable. But it turns out, in almost every book you've ever read, 2–3% squishiness is perfectly acceptable.

Re:React Wrap Balancer: Simple React Component That Makes Ti... by exogen on Thursday December 22, 2022 @10:30PM (#34102068)
And while the folks who are interested in web typography are here: here's another neat experimental demo: river detection in JavaScript: https://twitter.com/ua6oxa/status/1256734388072574976
Re:React Wrap Balancer: Simple React Component That Makes Ti... by jamesdwilson on Friday December 23, 2022 @11:19AM (#34107448)
Forgive me but, is this a CSS's max-width implemented as a react component?
Re:React Wrap Balancer: Simple React Component That Makes Ti... by Zpalmtree on Friday December 23, 2022 @11:31AM (#34107599)
no
Re:React Wrap Balancer: Simple React Component That Makes Ti... by solardev on Friday December 23, 2022 @12:35PM (#34108457)
No, look at the examples on the page. It avoids typographic orphans, that lonely last word on its own line after a reflow. This is standard in desktop publishing (Word, InDesign, etc.) but CSS has very weak support for it... http://thenewcode.com/946/CSS-last-line-Controlling-Widows-a...

Doesn't work in headings, and not supported by Firefox. So you need JS to hack it.