Skip to content

Commit c5ad35e

Browse files
committed
Upgrade packages and fixed tests.
- Introduce animation component.
1 parent 6cfc267 commit c5ad35e

File tree

22 files changed

+2776
-1363
lines changed

22 files changed

+2776
-1363
lines changed

babel.config.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ module.exports = {
22
env: {
33
test: {
44
presets: ["@babel/preset-env", "@babel/preset-react"],
5-
plugins: [
6-
"@babel/transform-runtime",
7-
["styled-components", { ssr: false, displayName: false }],
8-
],
5+
plugins: ["@babel/transform-runtime", "babel-plugin-styled-components"],
96
},
107
},
118
}

copy-assets.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ copyFileSync("src/components/tabs/tab.d.ts", "lib/components/tabs/tab.d.ts")
5353
copyFileSync("src/components/tabs/tabs.d.ts", "lib/components/tabs/tabs.d.ts")
5454
copyFileSync("src/components/toggle/toggle.d.ts", "lib/components/toggle/toggle.d.ts")
5555

56+
copyFileSync("src/components/animation/index.d.ts", "lib/components/animation/index.d.ts")
5657
copyFileSync("src/components/collapsible/index.d.ts", "lib/components/collapsible/index.d.ts")
5758
copyFileSync("src/components/modal/index.d.ts", "lib/components/modal/index.d.ts")
5859
copyFileSync(

package.json

Lines changed: 48 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
"/lib"
88
],
99
"scripts": {
10-
"_drop_native": "./node_modules/rimraf/bin.js node_modules/@types/react-native/",
10+
"_drop_native": "rimraf node_modules/@types/react-native/",
1111
"start": "yarn _drop_native && yarn storybook-start",
1212
"storybook-start": "bash start.sh",
1313
"testOut": "yarn test --env=jsdom --json --outputFile=.jest-test-results.json",
1414
"build-storybook": "build-storybook -c .storybook -o public",
1515
"build": "yarn _drop_native && yarn testOut && build-storybook",
16-
"clean": "./node_modules/rimraf/bin.js ./lib",
16+
"clean": "rimraf ./lib",
1717
"ts-bundle": "yarn _drop_native && yarn clean && tsc && tsc -m es6 && node copy-assets && yarn resolveAlias",
1818
"test": "jest --config ./jest/config.js",
1919
"cp-cloud": "cp -R ./lib ../cloud-frontend/node_modules/@netdata/netdata-ui/",
@@ -22,7 +22,6 @@
2222
"to-dashboard": "yarn ts-bundle && yarn cp-dashboard",
2323
"cp-charts": "cp -R ./lib ../charts/node_modules/@netdata/netdata-ui/",
2424
"to-charts": "yarn ts-bundle && yarn cp-charts",
25-
"prepare": "install-peers && yarn ts-bundle",
2625
"resolveAlias": "tsconfig-replace-paths -p tsconfig.json -s ./src -o ./lib"
2726
},
2827
"keywords": [
@@ -32,25 +31,29 @@
3231
],
3332
"author": "netdata",
3433
"license": "ISC",
34+
"resolutions": {
35+
"@storybook/**/@emotion/sheet": "^1",
36+
"@storybook/**/@emotion/styled": "^11"
37+
},
3538
"dependencies": {
36-
"@elastic/react-search-ui": "^1.15.0",
37-
"@elastic/search-ui-site-search-connector": "^1.15.0",
39+
"@elastic/react-search-ui": "^1.19.1",
40+
"@elastic/search-ui-site-search-connector": "^1.19.1",
3841
"@prismicio/client": "5.1.1",
3942
"@styled-system/css": "^5.1.5",
40-
"@tanstack/react-table": "^8.5.11",
43+
"@tanstack/react-table": "^8.7.9",
4144
"@tanstack/react-virtual": "3.0.0-beta.29",
42-
"axios": "^0.27.2",
45+
"axios": "^1.3.4",
4346
"polished": "^4.2.2",
4447
"ramda": "^0.28.0",
45-
"react-beautiful-dnd": "^13.1.0",
48+
"react-beautiful-dnd": "^13.1.1",
4649
"react-filter-box": "^3.4.3",
4750
"react-portal": "^4.2.2",
4851
"react-select": "^5.7.0",
4952
"react-table": "^7.8.0",
5053
"react-use": "^17.4.0",
51-
"react-window": "^1.8.7",
54+
"react-window": "^1.8.8",
5255
"styled-system": "^5.1.5",
53-
"throttle-debounce": "3.0.1"
56+
"throttle-debounce": "5.0.0"
5457
},
5558
"peerDependencies": {
5659
"react": "^18.2.0",
@@ -62,60 +65,53 @@
6265
"url": "[email protected]:netdata/netdata-ui.git"
6366
},
6467
"devDependencies": {
65-
"@babel/core": "^7.18.6",
66-
"@babel/eslint-parser": "^7.18.2",
67-
"@babel/plugin-transform-runtime": "^7.18.6",
68-
"@babel/preset-env": "^7.18.6",
68+
"@babel/core": "^7.21.3",
69+
"@babel/eslint-parser": "^7.21.3",
70+
"@babel/plugin-transform-runtime": "^7.21.0",
71+
"@babel/preset-env": "^7.20.2",
6972
"@babel/preset-react": "^7.18.6",
7073
"@netdata/eslint-config-netdata": "^0.1.2",
71-
"@storybook/addon-actions": "^6.5.9",
74+
"@storybook/addon-actions": "^6.5.16",
7275
"@storybook/addon-centered": "^5.3.21",
73-
"@storybook/addon-essentials": "^6.5.9",
74-
"@storybook/addon-interactions": "^6.5.9",
75-
"@storybook/addon-jest": "^6.5.9",
76+
"@storybook/addon-essentials": "^6.5.16",
77+
"@storybook/addon-interactions": "^6.5.16",
78+
"@storybook/addon-jest": "^6.5.16",
7679
"@storybook/addon-knobs": "^6.4.0",
77-
"@storybook/addon-links": "^6.5.9",
78-
"@storybook/addon-storysource": "^6.5.9",
79-
"@storybook/builder-webpack5": "^6.5.9",
80-
"@storybook/manager-webpack5": "^6.5.9",
81-
"@storybook/react": "^6.5.9",
80+
"@storybook/addon-links": "^6.5.16",
81+
"@storybook/addon-storysource": "^6.5.16",
82+
"@storybook/builder-webpack5": "^6.5.16",
83+
"@storybook/manager-webpack5": "^6.5.16",
84+
"@storybook/react": "^6.5.16",
8285
"@storybook/testing-library": "^0.0.13",
83-
"@testing-library/jest-dom": "^5.16.4",
84-
"@testing-library/react": "^13.3.0",
86+
"@testing-library/jest-dom": "^5.16.5",
87+
"@testing-library/react": "^14.0.0",
8588
"@testing-library/react-hooks": "^8.0.1",
86-
"@testing-library/user-event": "^14.2.1",
87-
"@types/jest": "^28.1.4",
88-
"@types/node": "^18.0.3",
89-
"@types/ramda": "^0.28.15",
90-
"@types/react": "^18.0.15",
91-
"@types/react-dom": "^18.0.6",
92-
"@types/react-portal": "^4.0.4",
93-
"@types/styled-components": "^5.1.25",
94-
"@types/styled-system": "^5.1.15",
95-
"@types/styled-system__css": "^5.0.16",
96-
"@typescript-eslint/eslint-plugin": "^5.30.5",
97-
"@typescript-eslint/parser": "^5.30.5",
98-
"babel-loader": "^8.2.5",
89+
"@testing-library/user-event": "^14.4.3",
90+
"@types/node": "^18.15.3",
91+
"babel-loader": "^9.1.2",
92+
"babel-plugin-styled-components": "^2.0.7",
9993
"cpx": "^1.5.0",
100-
"eslint": "^8.19.0",
101-
"eslint-plugin-react": "^7.30.1",
94+
"eslint": "^8.36.0",
95+
"eslint-plugin-react": "^7.32.2",
10296
"eslint-plugin-react-hooks": "^4.6.0",
103-
"html-loader": "^3.1.2",
97+
"html-loader": "^4.2.0",
10498
"identity-obj-proxy": "^3.0.0",
10599
"install-peers-cli": "^2.2.0",
106-
"jest": "^28.1.2",
107-
"jest-environment-jsdom": "^28.1.2",
108-
"jest-styled-components": "^7.0.8",
109-
"jsdom": "19.0.0",
110-
"markdown-loader": "7.0.0",
111-
"prettier": "^2.7.1",
112-
"rimraf": "^3.0.2",
100+
"jest": "^29.5.0",
101+
"jest-environment-jsdom": "^29.5.0",
102+
"jest-styled-components": "^7.1.1",
103+
"jsdom": "21.1.1",
104+
"markdown-loader": "8.0.0",
105+
"prettier": "^2.8.4",
106+
"react": "^18.2.0",
107+
"react-dom": "^18.2.0",
113108
"storybook-readme": "^5.0.9",
109+
"styled-components": "^5.3.9",
114110
"svg-sprite-loader": "^6.0.11",
115-
"svgo-loader": "^3.0.1",
116-
"ts-jest": "^28.0.5",
117-
"tsconfig-replace-paths": "^0.0.11",
118-
"typescript": "^4.7.4",
111+
"svgo-loader": "^4.0.0",
112+
"ts-jest": "^29.0.5",
113+
"tsconfig-replace-paths": "^0.0.14",
114+
"typescript": "^4.9.5",
119115
"url-loader": "^4.1.1"
120116
}
121117
}

src/components/animation/index.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { FC, ReactNode } from "react"
2+
3+
export interface AnimationProps {
4+
open?: boolean
5+
duration?: number
6+
persist?: boolean
7+
children: ReactNode | (() => ReactNode)
8+
[rest: string]: any
9+
}
10+
11+
declare const Animation: FC<AnimationProps & JSX.IntrinsicElements["div"]>
12+
13+
export { Animation }
14+
15+
export default Animation

src/components/animation/index.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React, { useMemo } from "react"
2+
import styled from "styled-components"
3+
import { Transition } from "react-transition-group"
4+
import makeAnimations from "./makeAnimations"
5+
6+
const Animation = ({
7+
in: isVisible,
8+
as,
9+
toggle,
10+
speed = 200,
11+
timing = "",
12+
transformOrigin,
13+
mount,
14+
children,
15+
...rest
16+
}) => {
17+
const animations = useMemo(() => makeAnimations({ toggle, timing, speed, transformOrigin }), [])
18+
19+
const StyledContainer = useMemo(
20+
() =>
21+
as &&
22+
styled(as)`
23+
${props => props.transitionStyling}
24+
`,
25+
[]
26+
)
27+
28+
return (
29+
<Transition in={isVisible} timeout={speed} mountOnEnter={!mount} unmountOnExit={!mount}>
30+
{transition => {
31+
const transitionStyling = animations[transition]
32+
33+
if (StyledContainer) {
34+
return (
35+
<StyledContainer transitionStyling={transitionStyling} {...rest}>
36+
{children({ transition, transitionStyling })}
37+
</StyledContainer>
38+
)
39+
}
40+
41+
return children({ transition, transitionStyling })
42+
}}
43+
</Transition>
44+
)
45+
}
46+
47+
export default Animation
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import React from "react"
2+
import { render, waitForElementToBeRemoved } from "testUtilities"
3+
import { config } from "react-transition-group"
4+
import Animation from "."
5+
6+
beforeAll(() => {
7+
config.disabled = false
8+
})
9+
10+
afterAll(() => {
11+
config.disabled = true
12+
})
13+
14+
it("toggles content", async () => {
15+
const { queryByText, rerender } = render(<Animation in>{() => "myContent"}</Animation>)
16+
expect(queryByText("myContent")).toBeInTheDocument()
17+
18+
rerender(<Animation>{() => "myContent"}</Animation>)
19+
await waitForElementToBeRemoved(() => queryByText("myContent"))
20+
21+
rerender(<Animation in>{() => "myContent"}</Animation>)
22+
expect(queryByText("myContent")).toBeInTheDocument()
23+
})
24+
25+
it("Mounts", () => {
26+
const { queryByText } = render(<Animation mount>{() => "myContent"}</Animation>)
27+
expect(queryByText("myContent")).toBeInTheDocument()
28+
})
29+
30+
it("provides render props", () => {
31+
const spy = jest.fn()
32+
let props
33+
const { queryByText } = render(
34+
<Animation in toggle="width: 200px;">
35+
{p => {
36+
spy()
37+
props = p
38+
return "myContent"
39+
}}
40+
</Animation>
41+
)
42+
43+
expect(queryByText("myContent")).toBeInTheDocument()
44+
expect(spy).toBeCalledTimes(1)
45+
expect(props.transition).toBe("entered")
46+
})
47+
48+
it("renders in a wrapper", () => {
49+
const spy = jest.fn()
50+
const wrapperSpy = jest.fn()
51+
const Wrapper = ({ children }) => {
52+
wrapperSpy()
53+
return children
54+
}
55+
render(
56+
<Animation as={Wrapper} in toggle="width: 200px;">
57+
{() => {
58+
spy()
59+
return "myContent"
60+
}}
61+
</Animation>
62+
)
63+
64+
expect(spy).toBeCalledTimes(1)
65+
expect(wrapperSpy).toBeCalledTimes(1)
66+
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {keyframes, css} from 'styled-components';
2+
3+
export default ({toggle, timing = '', speed = 200, transformOrigin}) => {
4+
const makeAnimations = keyframe => css`
5+
${transformOrigin && `transform-origin: ${transformOrigin};`}
6+
animation: ${keyframe} ${speed}ms ${timing};
7+
`;
8+
return {
9+
entering: makeAnimations(keyframes`from { ${toggle} }`),
10+
exiting: makeAnimations(keyframes`to { ${toggle} }`)
11+
};
12+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import makeAnimations from "./makeAnimations"
2+
3+
const match = (css, value) =>
4+
expect(
5+
css
6+
.filter(e => typeof e === "string")
7+
.join("")
8+
.trim()
9+
).toBe(value)
10+
11+
it("Creates animation rules based on the transition", () => {
12+
const animation = makeAnimations({ toggle: "height: 200px;" })
13+
const value = "animation: 200ms ;"
14+
match(animation.entering, value)
15+
match(animation.exiting, value)
16+
})
17+
18+
it("Creates animation rules based on the transition", () => {
19+
const animation = makeAnimations({
20+
toggle: "height: 200px;",
21+
timing: "easy-in",
22+
speed: 250,
23+
transformOrigin: "top",
24+
})
25+
const value = "transform-origin: top; animation: 250ms easy-in;"
26+
match(animation.entering, value)
27+
match(animation.exiting, value)
28+
})

0 commit comments

Comments
 (0)