Skip to content

Commit f5fbcfc

Browse files
committed
Update everything
1 parent 3f36fce commit f5fbcfc

File tree

15 files changed

+801
-585
lines changed

15 files changed

+801
-585
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ node_modules/
1616
.Trashes
1717
ehthumbs.db
1818
Thumbs.db
19+
20+
# Build directory
21+
/dist

.npmignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,3 @@ webpack.config.js
3838
# Prettier
3939
.prettierrc
4040
.prettierignore
41-

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,15 @@ const items = news.map(({ date, title, content }) => ({
4040
content: <p>{content}</p>
4141
}));
4242

43-
export const MyComponent = () => (
44-
<Accordion items={news} duration={300} multiple={true} />
45-
);
43+
export const MyComponent = () => <Accordion items={news} duration={300} multiple={true} />;
4644
```
4745

4846
## Props
4947

5048
1. items: Array of objects with the following properties:
5149

52-
- title [Required] - React Node
53-
- content [Required] - React Node
50+
- title [Required] - React Node
51+
- content [Required] - React Node
5452

5553
2. Duration [Required] - Number (Duration of the toggling transition)
5654

__tests__/__snapshots__/accordion.test.tsx.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Accordion should render no items 1`] = `""`;
4-
53
exports[`Accordion should render properly 1`] = `
64
Array [
75
<div

__tests__/accordion.test.tsx

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import * as renderer from 'react-test-renderer';
33

4-
import { default as Accordion } from '../dist/accordion';
4+
import { default as Accordion } from '../src/accordion';
55

66
const mock = [
77
{
@@ -28,25 +28,13 @@ describe('Accordion', () => {
2828
}));
2929

3030
it('should render properly', () => {
31-
const tree = renderer
32-
.create(<Accordion items={items} duration={300} multiple={true} />)
33-
.toJSON();
31+
const tree = renderer.create(<Accordion items={items} duration={300} multiple={true} />).toJSON();
3432

3533
expect(tree).toMatchSnapshot();
3634
});
3735

3836
it('should render properly', () => {
39-
const tree = renderer
40-
.create(<Accordion items={[]} duration={0} multiple={false} />)
41-
.toJSON();
42-
43-
expect(tree).toMatchSnapshot();
44-
});
45-
46-
it('should render no items', () => {
47-
const tree = renderer
48-
.create(<Accordion items={undefined} duration={500} multiple={true} />)
49-
.toJSON();
37+
const tree = renderer.create(<Accordion items={[]} duration={0} multiple={false} />).toJSON();
5038

5139
expect(tree).toMatchSnapshot();
5240
});

dist/accordion.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/accordion.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/panel.js

Lines changed: 3 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/panel.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
11
{
2-
"name": "react-accordion-ts",
3-
"version": "0.1.0",
4-
"description": "A ReactJS Accordion component",
5-
"main": "dist/index.js",
6-
"style": "src/panel.css",
7-
"scripts": {
8-
"clear": "rm -rf dist",
9-
"start": "tsc -w",
10-
"build": "yarn clear && tsc --build tsconfig.json",
11-
"test": "jest",
12-
"lint": "tslint -c tslint.json --project tsconfig.json",
13-
"prepare": "yarn lint && yarn build && yarn test"
14-
},
15-
"keywords": [
16-
"React",
17-
"Accordion",
18-
"Typescript",
19-
"Widget"
20-
],
21-
"author": "Atanas Atanasov <scriptex.bg@gmail.com> (https://atanas.info)",
22-
"repository": "https://github.com/scriptex/react-ion",
23-
"bugs": {
24-
"url": "https://github.com/scriptex/react-ion/issues",
25-
"email": "scriptex.bg@gmail.com"
26-
},
27-
"license": "MIT",
28-
"dependencies": {
29-
"react": "^16.5.2",
30-
"react-dom": "^16.5.2"
31-
},
32-
"peerDependencies": {
33-
"react": "^16.5.2",
34-
"react-dom": "^16.5.2"
35-
},
36-
"devDependencies": {
37-
"@types/jest": "23.3.10",
38-
"@types/react": "16.4.16",
39-
"@types/react-dom": "16.0.11",
40-
"@types/react-test-renderer": "16.0.3",
41-
"jest": "23.6.0",
42-
"react-test-renderer": "16.6.3",
43-
"ts-jest": "22.4.6",
44-
"tslint": "5.11.0",
45-
"tslint-react": "3.6.0",
46-
"typescript": "3.2.1"
47-
},
48-
"jest": {
49-
"moduleFileExtensions": [
50-
"ts",
51-
"tsx",
52-
"js"
53-
],
54-
"transform": {
55-
"\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
56-
},
57-
"testRegex": "/__tests__/.*\\.(ts|tsx|js)$"
58-
}
2+
"name": "react-accordion-ts",
3+
"version": "0.1.1",
4+
"description": "A ReactJS Accordion component",
5+
"main": "dist/index.js",
6+
"style": "src/panel.css",
7+
"scripts": {
8+
"clear": "rm -rf dist",
9+
"start": "tsc -w",
10+
"build": "yarn clear && tsc --build tsconfig.json",
11+
"test": "jest",
12+
"lint": "tslint -c tslint.json --project tsconfig.json",
13+
"prepare": "yarn lint && yarn build && yarn test"
14+
},
15+
"keywords": [
16+
"React",
17+
"Accordion",
18+
"Typescript",
19+
"Widget"
20+
],
21+
"author": "Atanas Atanasov <scriptex.bg@gmail.com> (https://atanas.info)",
22+
"repository": "https://github.com/scriptex/react-ion",
23+
"bugs": {
24+
"url": "https://github.com/scriptex/react-ion/issues",
25+
"email": "scriptex.bg@gmail.com"
26+
},
27+
"license": "MIT",
28+
"dependencies": {
29+
"react": "16.6.3",
30+
"react-dom": "16.6.3"
31+
},
32+
"peerDependencies": {
33+
"react": "16.5.2",
34+
"react-dom": "16.5.2"
35+
},
36+
"devDependencies": {
37+
"@types/jest": "23.3.10",
38+
"@types/react": "16.7.10",
39+
"@types/react-dom": "16.0.11",
40+
"@types/react-test-renderer": "16.0.3",
41+
"jest": "23.6.0",
42+
"react-test-renderer": "16.6.3",
43+
"ts-jest": "23.10.5",
44+
"tslint": "5.11.0",
45+
"tslint-react": "3.6.0",
46+
"typescript": "3.2.1"
47+
},
48+
"jest": {
49+
"moduleFileExtensions": [
50+
"ts",
51+
"tsx",
52+
"js"
53+
],
54+
"transform": {
55+
"\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
56+
},
57+
"testRegex": "/__tests__/.*\\.(ts|tsx|js)$"
58+
}
5959
}

src/accordion.tsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Accordion extends React.Component<Props> {
2525
super(props);
2626
}
2727

28+
// prettier-ignore
2829
public activatePanel = (index: number): void => {
2930
if (!this.props.multiple) {
3031
this.setState((prev: AccordionState) => ({
@@ -39,20 +40,20 @@ class Accordion extends React.Component<Props> {
3940

4041
return Array.isArray(items) && items.length
4142
? items.map(({ title, content }, index) => (
42-
<div className="accordion" role="tablist">
43-
<Panel
44-
key={index}
45-
title={title}
46-
index={index}
47-
duration={duration}
48-
multiple={multiple}
49-
activeTab={activeTab}
50-
activatePanel={this.activatePanel}
51-
>
52-
{content}
53-
</Panel>
54-
</div>
55-
))
43+
<div className="accordion" role="tablist">
44+
<Panel
45+
key={index}
46+
title={title}
47+
index={index}
48+
duration={duration}
49+
multiple={multiple}
50+
activeTab={activeTab}
51+
activatePanel={this.activatePanel}
52+
>
53+
{content}
54+
</Panel>
55+
</div>
56+
))
5657
: '';
5758
}
5859
}

src/panel.css

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
.panel__head {
2-
padding: 0;
3-
border: 0;
2+
padding: 0;
3+
border: 0;
44
cursor: pointer;
55
background-color: transparent;
6-
appearance: none;
7-
-moz-appearance: none;
8-
-webkit-appearance: none;
6+
appearance: none;
7+
-moz-appearance: none;
8+
-webkit-appearance: none;
99
}
1010

1111
.panel__body {
12-
overflow: hidden;
13-
-webkit-overflow-scrolling: touch;
14-
transition: height 0.35s ease-in-out;
12+
overflow: hidden;
13+
-webkit-overflow-scrolling: touch;
14+
transition: height 0.35s ease-in-out;
1515
}
1616

1717
.panel__content {
18-
opacity: 0;
19-
transition: opacity 0.35s ease-in-out;
18+
opacity: 0;
19+
transition: opacity 0.35s ease-in-out;
2020
}
2121

2222
.panel[aria-expanded='true'] .panel__content {
23-
opacity: 1;
23+
opacity: 1;
2424
}

src/panel.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,14 @@ class Panel extends React.Component<Props> {
3333
public componentDidMount(): void {
3434
setTimeout(() => {
3535
const el = findDOMNode(this);
36-
const height = (el as ExtendedElement).querySelector('.panel__body')
37-
.scrollHeight;
36+
const height = (el as ExtendedElement).querySelector('.panel__body').scrollHeight;
3837

3938
this.setState({ height });
4039
}, this.props.duration || 300);
4140
}
4241

4342
public render(): React.ReactNode {
44-
const {
45-
index,
46-
title,
47-
multiple,
48-
children,
49-
activeTab,
50-
activatePanel
51-
} = this.props;
43+
const { index, title, multiple, children, activeTab, activatePanel } = this.props;
5244

5345
const isActive = multiple ? this.state.isActive : activeTab === index;
5446

@@ -62,9 +54,7 @@ class Panel extends React.Component<Props> {
6254
role="tab"
6355
className="panel__head"
6456
onClick={_ => {
65-
multiple
66-
? this.setState({ isActive: !this.state.isActive })
67-
: activatePanel(index);
57+
multiple ? this.setState({ isActive: !this.state.isActive }) : activatePanel(index);
6858
}}
6959
>
7060
{title}

0 commit comments

Comments
 (0)