hyper icon indicating copy to clipboard operation
hyper copied to clipboard

Additional helper for setting link text and defaults

Open gateszies opened this issue 10 months ago • 4 comments

What are you trying to do?

I'm migrating from Typed Link and am having difficulty handling link text without writing if/else statements for different link types.

Right now, there is text which returns the custom text or element title, but I lose the ability to override with a default. Ex. for URL link types, text will return as the URL string. Because text has a value, I can't override with a default (and don't want the button text to be /product/example).

There is also linkText which will always use the custom inputted text, but I lose the ability to fall back to the element title if the custom text isn't defined.

What's your proposed solution?

I would love a functionality similar the TypedLink helper function getText(). This gives the ability to pass in more intelligent defaults for link text which from my understanding currently aren't possible in Hyper without writing several if/and statements based on Link Type. The logic for getText() applies the link text as follows:

  • Custom text of the link
  • Intrinsic text defined by the linked element
  • Default text defined in the field settings
  • Fallback text as passed to the function

By using logic similar to the getText() helper, I'd have greater flexibility to use custom text if its there, fallback to the element title if not, and finally use a default if there is neither custom text or an element title exists (great for URL link types)

Additional context

No response

gateszies avatar Apr 17 '24 17:04 gateszies