Skip to content

Hooks implementation #350

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

Merged
merged 7 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ yarn-debug.log*
yarn-error.log*

# Dependency directory
node_modules/
node_modules

# Misc
.DS_Store
Expand All @@ -18,4 +18,8 @@ ehthumbs.db
Thumbs.db

# Build directory
/dist
dist

# Demo
demo/.cache
demo/dist
11 changes: 10 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ yarn-debug.log*
yarn-error.log*

# Dependency directory
node_modules/
node_modules

# Misc
.DS_Store
Expand All @@ -31,12 +31,21 @@ Thumbs.db
yarn.lock

# Config files
.github
.whitesource
_config.yml
_.config.yml
tslint.json
tsconfig.json
renovate.json
rollup.config.js
webpack.config.js

# Prettier
.prettierrc
.prettierignore

# Project specific
!dist
demo
__tests__
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ node_js:
install:
- yarn
script:
- yarn prepare
- yarn prod
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@

# React Accordion

An accordion widget for React applications written in Typescript.
> An accordion widget for React web applications written in Typescript.

## About

The latest version of the widget has been built using the Hooks API introduced with React 16.
If you need to support older versions of React, please install [an older version](https://www.npmjs.com/package/react-accordion-ts/v/0.2.0).

**Please note that this widget does NOT work with React Native.**

## Install

Expand Down Expand Up @@ -52,9 +59,25 @@ const items = news.map(({ date, title, content }) => ({
export const MyComponent = () => <Accordion items={items} duration={300} multiple={true} />;
```

You can also use the basic stylesheet included:

```javascript
import 'react-accordion-ts/src/panel.css';
```

or

```css
@import 'react-accordion-ts/src/panel.css';

// If the above doesn't work, add a ~ in the beginning:

@import '~react-accordion-ts/src/panel.css';
```

## Props

1. items: Array of objects with the following properties:
1. items [Required] - Array of objects with the following shape:

- title [Required] - React Node
- content [Required] - React Node
Expand Down
2 changes: 1 addition & 1 deletion __tests__/__snapshots__/accordion.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@ Array [
]
`;

exports[`Accordion should render properly 2`] = `""`;
exports[`Accordion should render properly 2`] = `null`;
28 changes: 3 additions & 25 deletions __tests__/accordion.test.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,18 @@
import * as React from 'react';
import * as renderer from 'react-test-renderer';

import { items } from '../demo/mocks';
import Accordion from '../src/accordion';

const mock = [
{
date: '12-10-2018',
title: 'Awesome title',
content: 'Fantastic content'
},
{
date: '13-10-2018',
title: 'Awesome title',
content: 'Fantastic content'
},
{
date: '13-10-2018',
title: 'Awesome title',
content: 'Fantastic content'
}
];

describe('Accordion', () => {
const items = mock.map(({ date, title, content }) => ({
title: <h2>{date + ' - ' + title}</h2>,
content: <p>{content}</p>
}));

it('should render properly', () => {
const tree = renderer.create(<Accordion items={items} duration={300} multiple={true} /> as any).toJSON();
const tree = renderer.create((<Accordion items={items} duration={300} multiple />) as any).toJSON();

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

it('should render properly', () => {
const tree = renderer.create(<Accordion items={[]} duration={0} multiple={false} /> as any).toJSON();
const tree = renderer.create((<Accordion items={[]} duration={0} multiple={false} />) as any).toJSON();

expect(tree).toMatchSnapshot();
});
Expand Down
17 changes: 17 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />

<title>React Accordion Demo</title>

<link rel="stylesheet" href="../src/panel.css" />
</head>
<body>
<div id="root"></div>

<script src="./index.tsx"></script>
</body>
</html>
11 changes: 11 additions & 0 deletions demo/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';

import { items } from './mocks';
import { Accordion } from '../dist/index';

const App = () => {
return <Accordion items={items} duration={300} multiple />;
};

ReactDOM.render(<App />, document.getElementById('root'));
24 changes: 24 additions & 0 deletions demo/mocks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from 'react';

export const news = [
{
date: '12-10-2018',
title: 'Awesome title',
content: 'Fantastic content'
},
{
date: '13-10-2018',
title: 'Awesome title',
content: 'Fantastic content'
},
{
date: '13-10-2018',
title: 'Awesome title',
content: 'Fantastic content'
}
];

export const items = news.map(({ date, title, content }) => ({
title: <h2>{date + ' - ' + title}</h2>,
content: <p>{content}</p>
}));
21 changes: 21 additions & 0 deletions demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "react-accordion-ts-example",
"version": "1.0.0",
"main": "index.tsx",
"license": "MIT",
"scripts": {
"start": "parcel index.html",
"build": "parcel build index.html"
},
"dependencies": {},
"alias": {
"react": "../node_modules/react",
"react-dom": "../node_modules/react-dom/profiling"
},
"devDependencies": {
"@types/react": "16.9.51",
"@types/react-dom": "16.9.8",
"parcel": "1.12.4",
"typescript": "4.0.3"
}
}
Loading