spectrum-web-components
spectrum-web-components copied to clipboard
[Refactor][Number Field][Slider] Extract custom logic around generic units
trafficstars
Code of conduct
- [X] I agree to follow this project's code of conduct.
Description of issue
Could the extra state (_forcedUnit) and duplication of logic (between NumberField & Slider) be factored out by following a strategy pattern wrapping NumberFormatter/NumberParser? Alternatively, we could extend those classes in @internationalized/number to support these extra units.
Either way, to the consuming code in NumberField & Slider, there would just be a single NumberFormatter/NumberParser interface, with the error catching and forced unit fallback encapsulated inside.
There may also be room to encapsulate the local caching/language resolution logic in this way as well so it is more uniformly shared across the library. A possible use case for https://lit.dev/docs/composition/controllers/