Skip to content

Commit 8f300bc

Browse files
authored
refactor: migrate classnames to clsx (#121)
1 parent 1cc7f3c commit 8f300bc

File tree

11 files changed

+45
-47
lines changed

11 files changed

+45
-47
lines changed

__tests__/regression/fix-1813.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ function MultipleItems() {
3131
return <GenericSliderComponent slidesCount={9} settings={settings} />;
3232
}
3333

34-
describe("Multiple Items with slidesToShow = slides count in infinite mode", function() {
35-
it("should have 9 active slides", function() {
34+
describe("Multiple Items with slidesToShow = slides count in infinite mode", function () {
35+
it("should have 9 active slides", function () {
3636
const { container } = render(<MultipleItems />);
3737
expect(getActiveSlidesCount(container)).toEqual(9);
3838
});
39-
it("should show first 9 slides", function() {
39+
it("should show first 9 slides", function () {
4040
const { container } = render(<MultipleItems />);
4141
//expect(getActiveButton(container)).toEqual(["1"]);
4242
expect(getActiveSlidesText(container)).toEqual([

__tests__/regression/fix-2414.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,32 @@ function SliderWithUnslick() {
2929
return <GenericSliderComponent slidesCount={2} settings={settings} />;
3030
}
3131

32-
describe("Slider with one slide", function() {
33-
it("should have 1 active slide", function() {
32+
describe("Slider with one slide", function () {
33+
it("should have 1 active slide", function () {
3434
const { container } = render(<SliderWithOneSlide />);
3535
expect(getActiveSlidesCount(container)).toEqual(1);
3636
});
37-
it("should not have any clones", function() {
37+
it("should not have any clones", function () {
3838
const { container } = render(<SliderWithOneSlide />);
3939
expect(getClonesCount(container)).toEqual(0);
4040
});
41-
it("should no have dots and arrows", function() {
41+
it("should no have dots and arrows", function () {
4242
const { container } = render(<SliderWithOneSlide />);
4343
expect(hasArrows(container)).toEqual(false);
4444
expect(hasDots(container)).toEqual(false);
4545
});
4646
});
4747

48-
describe("Slider with unslick=true", function() {
49-
it("should have one active slide", function() {
48+
describe("Slider with unslick=true", function () {
49+
it("should have one active slide", function () {
5050
const { container } = render(<SliderWithUnslick />);
5151
expect(getActiveSlidesCount(container)).toEqual(1);
5252
});
53-
it("should not have any clones", function() {
53+
it("should not have any clones", function () {
5454
const { container } = render(<SliderWithUnslick />);
5555
expect(getClonesCount(container)).toEqual(0);
5656
});
57-
it("should no have dots and arrows", function() {
57+
it("should no have dots and arrows", function () {
5858
const { container } = render(<SliderWithUnslick />);
5959
expect(hasArrows(container)).toEqual(false);
6060
expect(hasDots(container)).toEqual(false);

examples/__tests__/MultipleItems.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import {
1919
} from "../../test-utils";
2020
import MultipleItems from "../MultipleItems";
2121

22-
describe("Multiple Items", function() {
23-
it("should have 9 actual slides and (3(pre) + 3(post)) clone slides", function() {
22+
describe("Multiple Items", function () {
23+
it("should have 9 actual slides and (3(pre) + 3(post)) clone slides", function () {
2424
const { container } = render(<MultipleItems />);
2525
expect(getSlidesCount(container)).toEqual(15);
2626
expect(getClonesCount(container)).toEqual(6);

examples/__tests__/SimpleSlider.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from "../../test-utils";
1717

1818
describe("SimpleSlider example", () => {
19-
it("should have 13 slides (1(preclone) + 6(actual) + 1(postclone))", function() {
19+
it("should have 13 slides (1(preclone) + 6(actual) + 1(postclone))", function () {
2020
const { container } = render(<SimpleSlider />);
2121
expect(container.getElementsByClassName("slick-slide").length).toBe(8);
2222
});

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ gulp.task("copy", function () {
3030
.pipe(gulp.dest("./build"));
3131
});
3232

33-
gulp.task("prepare-playwright", function() {
33+
gulp.task("prepare-playwright", function () {
3434
// Copy files to src-jsx directory with jsx extension
3535
return gulp
3636
.src("./src/**/*.js")

jest.config.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
module.exports = {
22
collectCoverage: true,
3-
coverageReporters: ['text', 'cobertura'],
4-
collectCoverageFrom: [
5-
'src/**/*',
6-
],
3+
coverageReporters: ["text", "cobertura"],
4+
collectCoverageFrom: ["src/**/*"],
75
testEnvironment: "jsdom",
86
setupFilesAfterEnv: ["<rootDir>/test-setup.js"],
97
testPathIgnorePatterns: ["/node_modules/", "playwright-tests"],

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,9 @@
101101
},
102102
"dependencies": {
103103
"@babel/runtime": "^7.20.7",
104+
"clsx": "^2.1.1",
104105
"@testing-library/dom": "^10.4.1",
105-
"classnames": "^2.2.5",
106106
"json2mq": "^0.2.0",
107-
"resize-observer-polyfill": "^1.5.1",
108107
"throttle-debounce": "^5.0.0"
109108
},
110109
"peerDependencies": {

src/arrows.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22

33
import React from "react";
4-
import classnames from "classnames";
4+
import { clsx } from "clsx";
55
import { canGoNext } from "./utils/innerSliderUtils";
66

77
export class PrevArrow extends React.PureComponent {
@@ -27,7 +27,7 @@ export class PrevArrow extends React.PureComponent {
2727
let prevArrowProps = {
2828
key: "0",
2929
"data-role": "none",
30-
className: classnames(prevClasses),
30+
className: clsx(prevClasses),
3131
style: { display: "block" },
3232
onClick: prevHandler
3333
};
@@ -74,7 +74,7 @@ export class NextArrow extends React.PureComponent {
7474
let nextArrowProps = {
7575
key: "1",
7676
"data-role": "none",
77-
className: classnames(nextClasses),
77+
className: clsx(nextClasses),
7878
style: { display: "block" },
7979
onClick: nextHandler
8080
};

src/dots.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"use strict";
22

33
import React from "react";
4-
import classnames from "classnames";
4+
import { clsx } from "clsx";
55
import { clamp } from "./utils/innerSliderUtils";
66

7-
const getDotCount = spec => {
7+
const getDotCount = (spec) => {
88
let dots;
99

1010
if (spec.infinite) {
@@ -55,7 +55,7 @@ export class Dots extends React.PureComponent {
5555
? _leftBound
5656
: clamp(_leftBound, 0, slideCount - 1);
5757

58-
let className = classnames({
58+
let className = clsx({
5959
"slick-active": infinite
6060
? currentSlide >= leftBound && currentSlide <= rightBound
6161
: currentSlide === leftBound

src/inner-slider.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import React from "react";
44
import initialState from "./initial-state";
55
import { debounce } from "throttle-debounce";
6-
import classnames from "classnames";
6+
import { clsx } from "clsx";
77
import {
88
getOnDemandLazySlides,
99
extractObject,
@@ -25,7 +25,6 @@ import {
2525
import { Track } from "./track";
2626
import { Dots } from "./dots";
2727
import { PrevArrow, NextArrow } from "./arrows";
28-
import ResizeObserver from "resize-observer-polyfill";
2928

3029
export class InnerSlider extends React.Component {
3130
constructor(props) {
@@ -78,17 +77,19 @@ export class InnerSlider extends React.Component {
7877
if (this.props.lazyLoad === "progressive") {
7978
this.lazyLoadTimer = setInterval(this.progressiveLazyLoad, 1000);
8079
}
81-
this.ro = new ResizeObserver(() => {
82-
if (this.state.animating) {
83-
this.onWindowResized(false); // don't set trackStyle hence don't break animation
84-
this.callbackTimers.push(
85-
setTimeout(() => this.onWindowResized(), this.props.speed)
86-
);
87-
} else {
88-
this.onWindowResized();
89-
}
90-
});
91-
this.ro.observe(this.list);
80+
if (typeof ResizeObserver !== "undefined") {
81+
this.ro = new ResizeObserver(() => {
82+
if (this.state.animating) {
83+
this.onWindowResized(false); // don't set trackStyle hence don't break animation
84+
this.callbackTimers.push(
85+
setTimeout(() => this.onWindowResized(), this.props.speed)
86+
);
87+
} else {
88+
this.onWindowResized();
89+
}
90+
});
91+
this.ro.observe(this.list);
92+
}
9293
document.querySelectorAll &&
9394
Array.prototype.forEach.call(
9495
document.querySelectorAll(".slick-slide"),
@@ -122,7 +123,7 @@ export class InnerSlider extends React.Component {
122123
if (this.autoplayTimer) {
123124
clearInterval(this.autoplayTimer);
124125
}
125-
this.ro.disconnect();
126+
this.ro?.disconnect();
126127
};
127128

128129
didPropsChange(prevProps) {
@@ -619,7 +620,7 @@ export class InnerSlider extends React.Component {
619620
this.autoPlay("blur");
620621

621622
render = () => {
622-
var className = classnames("slick-slider", this.props.className, {
623+
var className = clsx("slick-slider", this.props.className, {
623624
"slick-vertical": this.props.vertical,
624625
"slick-initialized": true
625626
});

0 commit comments

Comments
 (0)