Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow callback for "dotStyle" and "activeDotStyle" props #828

Closed
wants to merge 4 commits into from

Conversation

sarimarton
Copy link

I have to use rc-slider to make a range selector, where the active range has a horizontal color gradient. I can style the trackline with pure CSS, but not the step dots. I even went to great extents with CSS by adding some creative attribute selectors based on the style="left: ..." values, which was enough to have the correct dot colors when the full range is selected. But when the range is set to a narrower state, the gradient changes too, and the dots can't adapt to that. I can only solve this with a callback where I can set the style based on the dot position and the slider value. This is what this PR is about.

I have to use rc-slider to make a range selector, where the active range has a horizontal color gradient. I can style the trackline with pure CSS, but not the step dots. I even went to great extents with CSS by adding some creative attribute selectors based on the `style="left: ..."` values, which was enough to have the correct dot colors when the full range is selected. But when the range is set to a narrower state, the gradient changes too, and the dots can't adapt to that. I can only solve this with a callback where I can set the style based on the dot position and the slider value. This is what this PR is about.
@vercel
Copy link

vercel bot commented Apr 22, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
slider ✅ Ready (Inspect) Visit Preview Apr 23, 2022 at 5:08PM (UTC)

@yoyo837
Copy link
Member

yoyo837 commented Apr 23, 2022

Please change the type definition, and add some test case for this.

@codecov
Copy link

codecov bot commented Apr 23, 2022

Codecov Report

Merging #828 (0168d82) into master (410717a) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #828   +/-   ##
=======================================
  Coverage   99.81%   99.81%           
=======================================
  Files          13       13           
  Lines         533      535    +2     
  Branches      135      137    +2     
=======================================
+ Hits          532      534    +2     
  Misses          1        1           
Impacted Files Coverage Δ
src/Slider.tsx 100.00% <ø> (ø)
src/Steps/index.tsx 100.00% <ø> (ø)
src/Steps/Dot.tsx 100.00% <100.00%> (ø)

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@sarimarton
Copy link
Author

Please change the type definition, and add some test case for this.

I've added the types. As for the tests, I can't run the test suite because of an error which I couldn't fix, even after googling around. I'm pasting the output below. I've tried it on Windows and macOS.

~/repos.nosync/slider (patch-1) $ npm run test        

> rc-slider@10.0.0 test
> father test

 FAIL  tests/Slider.test.js
  ● Test suite failed to run

    TypeError: this._environment.runScript is not a function

      at Runtime._execModule (node_modules/umi-test/node_modules/jest-runtime/build/index.js:856:41)

 FAIL  tests/marks.test.js
  ● Test suite failed to run

    TypeError: this._environment.runScript is not a function

      at Runtime._execModule (node_modules/umi-test/node_modules/jest-runtime/build/index.js:856:41)

 FAIL  tests/common.test.js
  ● Test suite failed to run

    TypeError: this._environment.runScript is not a function

      at Runtime._execModule (node_modules/umi-test/node_modules/jest-runtime/build/index.js:856:41)

 FAIL  tests/Range.test.js
  ● Test suite failed to run

    TypeError: this._environment.runScript is not a function

      at Runtime._execModule (node_modules/umi-test/node_modules/jest-runtime/build/index.js:856:41)

Test Suites: 4 failed, 4 total
Tests:       0 total
Snapshots:   0 total
Time:        0.54s
Ran all test suites.
✖  error     Error: Jest failed 
    at /Users/sarimarton/repos.nosync/slider/node_modules/umi-test/lib/index.js:143:16
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Apr 23, 2022

This pull request introduces 4 alerts when merging cbc16b2 into 410717a - view on LGTM.com

new alerts:

  • 4 for Ineffective parameter type

@yann-combarnous
Copy link
Contributor

yann-combarnous commented Apr 23, 2022

Please change the type definition, and add some test case for this.

I've added the types. As for the tests, I can't run the test suite because of an error which I couldn't fix, even after googling around. I'm pasting the output below. I've tried it on Windows and macOS.

~/repos.nosync/slider (patch-1) $ npm run test        

> rc-slider@10.0.0 test
> father test

 FAIL  tests/Slider.test.js
  ● Test suite failed to run

    TypeError: this._environment.runScript is not a function

      at Runtime._execModule (node_modules/umi-test/node_modules/jest-runtime/build/index.js:856:41)

 FAIL  tests/marks.test.js
  ● Test suite failed to run

    TypeError: this._environment.runScript is not a function

      at Runtime._execModule (node_modules/umi-test/node_modules/jest-runtime/build/index.js:856:41)

 FAIL  tests/common.test.js
  ● Test suite failed to run

    TypeError: this._environment.runScript is not a function

      at Runtime._execModule (node_modules/umi-test/node_modules/jest-runtime/build/index.js:856:41)

 FAIL  tests/Range.test.js
  ● Test suite failed to run

    TypeError: this._environment.runScript is not a function

      at Runtime._execModule (node_modules/umi-test/node_modules/jest-runtime/build/index.js:856:41)

Test Suites: 4 failed, 4 total
Tests:       0 total
Snapshots:   0 total
Time:        0.54s
Ran all test suites.
✖  error     Error: Jest failed 
    at /Users/sarimarton/repos.nosync/slider/node_modules/umi-test/lib/index.js:143:16
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Your types are wrong I believe, should be:

React.CSSProperties | ((value: number) => React.CSSProperties);

See the related CI alert from LGTM in comment above.

You are also missing types updates in Slider.tsx for activeDotStyle and dotStyle props.

@sarimarton
Copy link
Author

You are also missing types updates in Slider.tsx for activeDotStyle and dotStyle props.

Thanks, @yann-combarnous, for the suggestions.

@yann-combarnous
Copy link
Contributor

yann-combarnous commented Apr 25, 2022

@yoyo837, I followed the steps for installation and test commands from the README, and I am getting the same errors as the PR author.

So looks like some step is missing in the installation / contribution instructions. Any hint? I also removed any global Jest installation, as some suggested online.

npm@8.1.2
node@16.13.2

@@ -97,8 +97,8 @@ The following APIs are shared by Slider and Range.
| handleStyle | Array[Object] \| Object | `[{}]` | The style used for handle. (`both for slider(`Object`) and range(`Array of Object`), the array will be used for multi handle following element order`) |
| trackStyle | Array[Object] \| Object | `[{}]` | The style used for track. (`both for slider(`Object`) and range(`Array of Object`), the array will be used for multi track following element order`)|
| railStyle | Object | `{}` | The style used for the track base color. |
| dotStyle | Object | `{}` | The style used for the dots. |
| activeDotStyle | Object | `{}` | The style used for the active dots. |
| dotStyle | Object or (dotValue) => Object | `{}` | The style used for the dots. |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| dotStyle | Object or (dotValue) => Object | `{}` | The style used for the dots. |
| dotStyle | Object \| (dotValue) => Object | `{}` | The style used for the dots. |

| dotStyle | Object | `{}` | The style used for the dots. |
| activeDotStyle | Object | `{}` | The style used for the active dots. |
| dotStyle | Object or (dotValue) => Object | `{}` | The style used for the dots. |
| activeDotStyle | Object or (dotValue) => Object | `{}` | The style used for the active dots. |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| activeDotStyle | Object or (dotValue) => Object | `{}` | The style used for the active dots. |
| activeDotStyle | Object \| (dotValue) => Object | `{}` | The style used for the active dots. |

@yoyo837
Copy link
Member

yoyo837 commented Apr 25, 2022

The failed does not seem to be caused by PR.

@yann-combarnous
Copy link
Contributor

Thx @yoyo837 , any chance a new release can be made to include this feature?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants