Skip to content

Commit

Permalink
Merge pull request #34 from alampros/develop
Browse files Browse the repository at this point in the history
Typescript refactor
  • Loading branch information
alampros authored Mar 8, 2019
2 parents 470f04d + 72e7473 commit 47c906f
Show file tree
Hide file tree
Showing 20 changed files with 1,941 additions and 687 deletions.
65 changes: 65 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
module.exports = {
root: true,
extends: [
'standard',
'standard-react',
],
env: {
browser: true,
node: true,
},
plugins: [
'react',
'react-hooks',
],
overrides: [
{
files: ['**/*.js'],
parser: 'babel-eslint',
},
{
files: ['**/*.ts', '**/*.tsx'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
rules: {
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error', {
vars: 'all',
args: 'after-used',
ignoreRestSiblings: false,
}],
},
},
],
rules: {
'no-console': ['warn', { allow: ['warn', 'error'] }],
'quote-props': ['error', 'as-needed'],
'comma-dangle': ['warn', {
arrays: 'only-multiline',
objects: 'always-multiline',
imports: 'only-multiline',
}],
quotes: ['warn', 'single'],
'space-before-function-paren': ['error', {
anonymous: 'never',
named: 'never',
asyncArrow: 'always',
}],
'jsx-quotes': ['error', 'prefer-double'],
'react-hooks/rules-of-hooks': 'error',
'react/jsx-closing-tag-location': 2,
'react/jsx-closing-bracket-location': 2,
'react/jsx-indent': [2, 2, { checkAttributes: true }],
'react/jsx-max-props-per-line': ['error', { maximum: 1, when: 'multiline' }],
'react/prop-types': ['error', { ignore: ['children', 'className', 'style'] }],
'keyword-spacing': ['error', {
overrides: {
if: { after: false },
for: { after: false },
while: { after: false },
catch: { after: false },
switch: { after: false },
},
}],
},
}
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,19 @@ export default () => {

## Props

| Property | Type | Default | Description |
| ---------------- | --------------------- | --- | --- |
| `width` | `Number` | `window.innerWidth \|\| 300` | Width of the `<canvas>` element. |
| `height` | `Number` | `window.innerHeight \|\| 200` | Height of the `<canvas>` element. |
| `numberOfPieces` | `Number` | 200 | Number of confetti pieces at one time. |
| `confettiSource` | `{ x: Number, y: Number, w: Number, h: Number }` | `{x: 0, y: 0, w: canvas.width, h:0}` | Rectangle where the confetti should spawn. Default is across the top. |
| `friction` | `Number` | 0.99 | |
| `wind` | `Number` | 0 | |
| `gravity` | `Number` | 0.1 | |
| `colors` | `Array` of `String` | `['#f44336'`</br>`'#e91e63'`</br>`'#9c27b0'`</br>`'#673ab7'`</br>`'#3f51b5'`</br>`'#2196f3'`</br>`'#03a9f4'`</br>`'#00bcd4'`</br>`'#009688'`</br>`'#4CAF50'`</br>`'#8BC34A'`</br>`'#CDDC39'`</br>`'#FFEB3B'`</br>`'#FFC107'`</br>`'#FF9800'`</br>`'#FF5722'`</br>`'#795548']`</br> | All available Colors for the confetti pieces. |
| `opacity` | `Number` | 1.0 | |
| `recycle` | `Bool` | true | Keep spawning confetti after `numberOfPieces` pieces have been shown. |
| `run` | `Bool` | true | Run the animation loop |
| Property | Type | Default | Description |
| ---------------- | --------------------- | --- | --- |
| `width` | `Number` | `window.innerWidth \|\| 300` | Width of the `<canvas>` element. |
| `height` | `Number` | `window.innerHeight \|\| 200` | Height of the `<canvas>` element. |
| `numberOfPieces` | `Number` | 200 | Number of confetti pieces at one time. |
| `confettiSource` | `{ x: Number, y: Number, w: Number, h: Number }` | `{x: 0, y: 0, w: canvas.width, h:0}` | Rectangle where the confetti should spawn. Default is across the top. |
| `friction` | `Number` | 0.99 | |
| `wind` | `Number` | 0 | |
| `gravity` | `Number` | 0.1 | |
| `colors` | `String[]` | `['#f44336'`</br>`'#e91e63'`</br>`'#9c27b0'`</br>`'#673ab7'`</br>`'#3f51b5'`</br>`'#2196f3'`</br>`'#03a9f4'`</br>`'#00bcd4'`</br>`'#009688'`</br>`'#4CAF50'`</br>`'#8BC34A'`</br>`'#CDDC39'`</br>`'#FFEB3B'`</br>`'#FFC107'`</br>`'#FF9800'`</br>`'#FF5722'`</br>`'#795548']`</br> | All available Colors for the confetti pieces. |
| `opacity` | `Number` | 1.0 | |
| `recycle` | `Bool` | true | Keep spawning confetti after `numberOfPieces` pieces have been shown. |
| `run` | `Bool` | true | Run the animation loop |
| `tweenDuration` | `Number` | 5000 | How fast the confetti is added |
| `tweenFunction` | `(currentTime: number, currentValue: number, targetValue: number, duration: number, s?: number) => number` | easeInOutQuad | See [tween-functions](https://github.com/chenglou/tween-functions) |

2 changes: 2 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ module.exports = (api) => {
api.cache(false)
return {
presets: [
'@babel/typescript',
'@babel/preset-react',
'@babel/env',
],
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/proposal-object-rest-spread',
],
}
}
52 changes: 33 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "react-confetti",
"version": "2.4.1",
"description": "React component to draw confetti for your party.",
"main": "index.js",
"main": "dist/react-confetti.min.js",
"types": "dist/types/ReactConfetti.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/alampros/react-confetti.git"
Expand All @@ -26,12 +27,13 @@
"index.js"
],
"scripts": {
"build": "rollup -c",
"build": "tsc && rollup -c",
"prebuild": "yarn clean",
"develop": "rollup -c -w",
"test": "yarn run lint",
"test": "tsc; yarn run lint",
"clean": "git clean -xfd dist/",
"cleanall": "git clean -xfd .",
"lint": "eslint . --ext .js",
"lint": "eslint . --ext .js --ext .ts --ext .tsx",
"prepare": "yarn run clean && yarn run lint && yarn run build",
"semantic-release": "semantic-release",
"commit": "git-cz"
Expand All @@ -40,39 +42,51 @@
"prop-types": "^15.6.0",
"react": "0.14.x || ^15.0.1 || ^16.2.0"
},
"dependencies": {
"tween-functions": "^1.2.0"
},
"devDependencies": {
"@babel/core": "^7.1.6",
"@babel/plugin-proposal-class-properties": "^7.2.3",
"@babel/plugin-proposal-class-properties": "^7.3.4",
"@babel/plugin-proposal-object-rest-spread": "^7.3.4",
"@babel/preset-env": "^7.1.6",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.3.3",
"@semantic-release/changelog": "^3.0.2",
"@semantic-release/commit-analyzer": "^6.1.0",
"@semantic-release/git": "^7.0.8",
"@semantic-release/github": "^5.2.10",
"@semantic-release/npm": "^5.1.4",
"@semantic-release/release-notes-generator": "^7.1.4",
"@types/react": "^16.8.6",
"@typescript-eslint/eslint-plugin": "^1.4.2",
"@typescript-eslint/parser": "^1.3.0",
"babel-eslint": "^10.0.1",
"commitizen": "^3.0.7",
"cz-conventional-changelog": "^2.1.0",
"eslint": "^5.14.1",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-vectron": "^2.1.0",
"eslint-plugin-import": "^2.11.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.7.0",
"eslint-plugin-sorting": "^0.4.1",
"eslint": "^5.13.0",
"eslint-config-standard": "^12.0.0",
"eslint-config-standard-react": "^7.0.2",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-node": "^8.0.1",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-react": "^7.12.4",
"eslint-plugin-react-hooks": "^1.0.1",
"eslint-plugin-standard": "^4.0.0",
"nodemon": "^1.18.10",
"prop-types": "^15.6.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"rollup": "^1.3.1",
"rollup": "^1.4.0",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-commonjs": "^9.2.1",
"rollup-plugin-node-resolve": "^4.0.1",
"rollup-plugin-uglify": "^6.0.2",
"semantic-release": "^15.1.7"
},
"eslintConfig": {
"root": true,
"parser": "babel-eslint",
"extends": "vectron"
"semantic-release": "^15.1.7",
"stylelint": "^9.10.1",
"stylelint-config-rational-order": "^0.0.4",
"stylelint-config-standard": "^18.2.0",
"typescript": "^3.3.3333"
},
"config": {
"commitizen": {
Expand Down
19 changes: 12 additions & 7 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import babel from 'rollup-plugin-babel'
import commonjs from 'rollup-plugin-commonjs'
import resolve from 'rollup-plugin-node-resolve'
import { uglify } from 'rollup-plugin-uglify'

const extensions = ['.js', '.jsx', '.ts', '.tsx']

const base = {
input: './src/react-confetti.js',
input: './src/ReactConfetti.tsx',
output: {
file: './dist/react-confetti.js',
format: 'umd',
name: 'ReactConfetti',
sourcemap: true,
globals: {
react: 'React',
'prop-types': 'PropTypes',
},
},
external: ['react', 'prop-types'],
external: ['react'],
plugins: [
babel(),
]
resolve({ extensions }),
commonjs(),
babel({ extensions, include: ['src/**/*'] }),
],
}

export default [
Expand All @@ -28,8 +33,8 @@ export default [
file: './dist/react-confetti.min.js',
},
plugins: [
babel(),
...base.plugins,
uglify(),
]
],
}
]
16 changes: 16 additions & 0 deletions src/Circle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { IPoint } from './Point'

export interface ICircle extends IPoint {
radius: number
}

export default class Circle implements ICircle {
constructor(init: ICircle) {
this.x = init.x
this.y = init.y
this.radius = init.radius
}
x: number
y: number
radius: number
}
Loading

0 comments on commit 47c906f

Please sign in to comment.