Skip to content

Replace per-type config parameters with a single map #44

Description

@developerjamiu

SmartText spends one constructor parameter per span type: config, addressConfig, phoneConfig, urlConfig, dateTimeConfig, emailConfig.

Six types, six parameters. The roadmap adds flight, date, hashtag, mention and custom detectors, which would mean eleven or more. That is not a simple API, and every type added makes it worse.

This blocks the type expansion work and should land before any new type.

Proposed shape:

SmartText(
  text,
  style: baseStyle,
  linkConfig: ItemSpanConfig(...),                   // applies to every link type
  spanConfigs: {                                      // per-type override, optional
    ItemSpanType.address: ItemSpanConfig(...),
  },
)

One parameter that scales to any number of types, const-able and declarative.

A builder form (spanConfigBuilder: (span) => ItemSpanConfig(...)) would additionally allow per-span logic, such as styling links to your own domain differently. It cannot be const and most users will not need it. Worth adding only if someone asks.

Migration: ship the map in the next minor release with the six existing parameters marked @Deprecated, and remove them in a later major.

Found during the v0.4.0 codebase audit.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiPublic API shapeenhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions