adobe / spectrum-web-components

Spectrum Web Components
https://opensource.adobe.com/spectrum-web-components/
Apache License 2.0
1.25k stars 200 forks source link

feat: Silder: adjust fillStart calculation for value=0 and normalization function #4560

Closed spdev3000 closed 3 months ago

spdev3000 commented 3 months ago

This PR adds a way to use fill-start="0" as reference point as well as respecting a provided normalization function to correctly calculate fill offset and length.

Description

First check, if we really just have the attribute fill-start provided with no number value, if so, use centered point of track like before. For all other number values, use normalization function of model of active handle to calculate real fill-offset and fill-length.

Related issue(s)

4559

Motivation and context

2 current problems:

  1. Currently fill-start attribute only allows to set values !== 0, but sometimes clients have sliders with min<0 , so for example: min="-100", max="200" - so we need a possibility to define fill-start="0" to not start from centered track position
  2. Also currently the fill-start calculation doesn't respect any provided normalization function, so we'd like to calculate all fill-related values (offset + length) by a given normalization function of model of active handle

How has this been tested?

2 new test cases have been added into slider.stories.ts as well as into slider.test.ts

Screenshots (if appropriate)

Types of changes

Checklist

Best practices

This repository uses conventional commit syntax for each commit message; note that the GitHub UI does not use this by default so be cautious when accepting suggested changes. Avoid the "Update branch" button on the pull request and opt instead for rebasing your branch against main.

github-actions[bot] commented 3 months ago

Branch preview

Visual regression test results When a visual regression test fails (or has previously failed while working on this branch), its results can be found in the following URLs: - [High Contrast Mode | Medium | LTR](https://037d9c134d6e5810455f744e79e56de8--spectrum-web-components.netlify.app/review/) - [Spectrum | Lightest | Medium | LTR](https://527427d8f3ba50a3b63bfa0ef702c524--spectrum-web-components.netlify.app/review/) - [Spectrum | Lightest | Medium | RTL](https://52d061d4f39254e83289484739b789f2--spectrum-web-components.netlify.app/review/) - [Spectrum | Lightest | Large | LTR](https://55d7c1896c0a2a0fe766e9b842c86a92--spectrum-web-components.netlify.app/review/) - [Spectrum | Lightest | Large | RTL](https://63854a67d3a06c87a769d200196db3ee--spectrum-web-components.netlify.app/review/) - [Spectrum | Light | Medium | LTR](https://7574e074395c97f9c19ce46f42e6dfc2--spectrum-web-components.netlify.app/review/) - [Spectrum | Light | Medium | RTL](https://897c911a9eb399b7aeabd5bdddc748f1--spectrum-web-components.netlify.app/review/) - [Spectrum | Light | Large | LTR](https://3211318c6cd688eafd9f6b679836554c--spectrum-web-components.netlify.app/review/) - [Spectrum | Light | Large | RTL](https://d239018a3c06c9043c7b039a38c5487f--spectrum-web-components.netlify.app/review/) - [Spectrum | Dark | Medium | LTR](https://56351d78bc938aae682cc6ff023413ae--spectrum-web-components.netlify.app/review/) - [Spectrum | Dark | Medium | RTL](https://bc65396ea162c1245cc7ba7eba5725fd--spectrum-web-components.netlify.app/review/) - [Spectrum | Dark | Large | LTR](https://d84fbab11ddca08bf67e9bf203f6f437--spectrum-web-components.netlify.app/review/) - [Spectrum | Dark | Large | RTL](https://3426fc4813a2378d7fd4da73d65b923b--spectrum-web-components.netlify.app/review/) - [Spectrum | Darkest | Medium | LTR](https://b036dc442395b86d108b4ba2457fac29--spectrum-web-components.netlify.app/review/) - [Spectrum | Darkest | Medium | RTL](https://adcc245e9dd107c1e0d46d576b2fba32--spectrum-web-components.netlify.app/review/) - [Spectrum | Darkest | Large | LTR](https://f6e3583f22551d4b918e41f0fe3f0b61--spectrum-web-components.netlify.app/review/) - [Spectrum | Darkest | Large | RTL](https://d5802107badec30616ff4c7df31053f8--spectrum-web-components.netlify.app/review/) - [Express | Lightest | Medium | LTR](https://58827920337de99c337150c173803268--spectrum-web-components.netlify.app/review/) - [Express | Lightest | Medium | RTL](https://8df95095110d64c18fe924998405a185--spectrum-web-components.netlify.app/review/) - [Express | Lightest | Large | LTR](https://03025da4dee78f2041fdd58e7833d0ec--spectrum-web-components.netlify.app/review/) - [Express | Lightest | Large | RTL](https://f6126b37c1871e19aadf07c8caedc411--spectrum-web-components.netlify.app/review/) - [Express | Light | Medium | LTR](https://e2699768fa7a66a7940f09a9a7ba6693--spectrum-web-components.netlify.app/review/) - [Express | Light | Medium | RTL](https://241d67b5f7122a89895e04757aedf323--spectrum-web-components.netlify.app/review/) - [Express | Light | Large | LTR](https://0fc2736c9835d68114ddaa7827ccf366--spectrum-web-components.netlify.app/review/) - [Express | Light | Large | RTL](https://450b709484bf0bd040588e2eedfef6b4--spectrum-web-components.netlify.app/review/) - [Express | Dark | Medium | LTR](https://b2dac3b99cd5e8fd29273372341ca07b--spectrum-web-components.netlify.app/review/) - [Express | Dark | Medium | RTL](https://788ec89754c26532d1ec62550a3420f5--spectrum-web-components.netlify.app/review/) - [Express | Dark | Large | LTR](https://bb7d559427375b1e1c6cf50b342188cf--spectrum-web-components.netlify.app/review/) - [Express | Dark | Large | RTL](https://96c61ef3aa69db0394b3cf12e9aba706--spectrum-web-components.netlify.app/review/) - [Express | Darkest | Medium | LTR](https://edb327cb9e38581f7c23a8c586f63cbc--spectrum-web-components.netlify.app/review/) - [Express | Darkest | Medium | RTL](https://b9241ea3a74ae8fcc4235d226928275c--spectrum-web-components.netlify.app/review/) - [Express | Darkest | Large | LTR](https://f55f953ee352812e3a28395ef7dfd9bc--spectrum-web-components.netlify.app/review/) - [Express | Darkest | Large | RTL](https://028003ce8485d585ea55b760928e6a49--spectrum-web-components.netlify.app/review/) - [Spectrum-two | Light | Medium | LTR](https://49c2f8b6108e9ead71a152fddea20b4e--spectrum-web-components.netlify.app/review/) - [Spectrum-two | Light | Medium | RTL](https://45305a350fc37becb0dad661a4e7054c--spectrum-web-components.netlify.app/review/) - [Spectrum-two | Light | Large | LTR](https://6be97a99c300e9fd6d622d01fcdf1466--spectrum-web-components.netlify.app/review/) - [Spectrum-two | Light | Large | RTL](https://a5f75ca99599ee1723a83821b8d34d09--spectrum-web-components.netlify.app/review/) - [Spectrum-two | Dark | Medium | LTR](https://376b5d71ecbe6a8e463a25618c1327b1--spectrum-web-components.netlify.app/review/) - [Spectrum-two | Dark | Medium | RTL](https://d31cf7bc86ae98159ed81a77384cfafa--spectrum-web-components.netlify.app/review/) - [Spectrum-two | Dark | Large | LTR](https://03a6d8c3e634ac9ccf012c2a2c4ab4ba--spectrum-web-components.netlify.app/review/) - [Spectrum-two | Dark | Large | RTL](https://e9eefc68c1b84db2de7181c50130f161--spectrum-web-components.netlify.app/review/)
github-actions[bot] commented 3 months ago

Tachometer results

Chrome ## slider [_permalink_](#user-content-slider) ### test-basic | Version | Bytes | Avg Time | vs remote | vs branch | |---|---|---|---|---| | npm latest | 480 kB | 74.24ms - 76.13ms | - | faster ✔
1% - 5%
1.05ms - 3.77ms | | branch | 467 kB | 76.62ms - 78.58ms | slower ❌
1% - 5%
1.05ms - 3.77ms | - |
Firefox ## slider [_permalink_](#user-content-slider) ### test-basic | Version | Bytes | Avg Time | vs remote | vs branch | |---|---|---|---|---| | npm latest | 480 kB | 161.54ms - 168.66ms | - | faster ✔
1% - 6%
1.28ms - 10.28ms | | branch | 467 kB | 168.13ms - 173.63ms | slower ❌
1% - 6%
1.28ms - 10.28ms | - |
Rajdeepc commented 3 months ago

@spdev3000 Can you also add some documentation around it! That would be very helpful to let the consumers know about the flexibility to use the min-max ranges from -ve minimum values. Also can you make sure the storybook and the documentation links are not broken as here

spdev3000 commented 3 months ago

will be continued as #4573