Skip to content

Commit

Permalink
feat: convert to typescript
Browse files Browse the repository at this point in the history
* replace mocha with jest
* example updated to run in vite
* update packages
* Add example for padding to docs
* remove decorators back into main class (due to issues with typescript conversion)
  • Loading branch information
jafin committed Apr 3, 2022
1 parent 89429a9 commit dc547c1
Show file tree
Hide file tree
Showing 53 changed files with 32,443 additions and 23,035 deletions.
26 changes: 18 additions & 8 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
{
"env": {
"test": {
"presets": [
"@babel/preset-env",
"@babel/preset-typescript",
["@babel/preset-react", { "runtime": "automatic" }]
],
"plugins": []
}
},
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }],
"@babel/plugin-syntax-dynamic-import",
Expand All @@ -7,13 +17,13 @@
"@babel/plugin-proposal-json-strings"
],
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "entry",
"corejs": "3.12"
}
],
"@babel/preset-react"
[
"@babel/preset-env",
{
"useBuiltIns": "entry",
"corejs": "3.21"
}
],
"@babel/preset-react"
]
}
104 changes: 57 additions & 47 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,47 +1,57 @@
{
"parser": "babel-eslint",
"extends": ["standard", "standard-react", "prettier", "eslint:recommended"],
"env": {
"es6": true,
"jest": true
},
"plugins": ["react", "prettier"],
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2018,
"ecmaFeatures": {
"impliedStrict": true,
"jsx": true,
"arrowFunctions": true,
"blockBindings": true,
"defaultParams": true,
"destructuring": true,
"forOf": true,
"generators": true,
"objectLiteralComputedProperties": true,
"objectLiteralShorthandMethods": true,
"objectLiteralShorthandProperties": true,
"experimentalObjectRestSpread": true,
"restParams": true,
"spread": true,
"templateStrings": true,
"modules": true,
"classes": true
}
},
"rules": {
"react/jsx-no-bind": "off",
"space-before-function-paren": 0,
"react/jsx-boolean-value": 0,
"max-len": [2, { "code": 120, "ignoreComments": true }],
"newline-per-chained-call": 0,
"no-trailing-spaces": ["error"],
"quotes": ["error", "single", { "avoidEscape": true }],
"comma-dangle": ["error", "never"],
"no-template-curly-in-string": "off",
"semi": ["error", "always"],
"object-curly-spacing": ["error", "always"],
"quote-props": ["error", "consistent"],
"no-var": ["error"]
}
}
{
"parser": "@typescript-eslint/parser",
"settings": {
"react": {
"version": "detect"
}
},
"extends": [
// "standard",
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended"
],
"env": {
//error with "es2021": true
"es6": true,
"jest": true,
"node": true,
"browser": true
},
"plugins": ["@typescript-eslint", "react", "react-hooks"],
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module",
"requireConfigFile": false,
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"react/jsx-uses-react": "off",
"react/react-in-jsx-scope": "off",
"react/prop-types": "off",
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"@typescript-eslint/explicit-module-boundary-types": "off",
"react/jsx-no-bind": [
"warn",
{
"ignoreRefs": true
}
],
"space-before-function-paren": 0,
"react/jsx-boolean-value": 0,
"max-len": [2, { "code": 120, "ignoreComments": true }],
"newline-per-chained-call": 0,
"no-trailing-spaces": ["error"],
"quotes": ["error", "single", { "avoidEscape": true }],
"comma-dangle": ["error", "never"],
"no-template-curly-in-string": "off",
"semi": ["error", "always"],
"object-curly-spacing": ["error", "always"],
"quote-props": ["error", "consistent"],
"no-var": ["error"],
"indent": "off"
}
}
34 changes: 34 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [master, wip/react-18]
pull_request:
branches: [master]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- run: yarn install
- run: yarn test
- name: Semantic release
uses: cycjimmy/semantic-release-action@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,14 @@
node_modules/
dist/
build/
/out-tsc/**

# yarn
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
/example/.yarn/*
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn commitlint --edit $1
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn pretest
9 changes: 9 additions & 0 deletions .mocharc.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
// Specify "require" for CommonJS
"require": "ts-node/register",
// Specify "loader" for native ESM
"loader": "ts-node/esm",
"extensions": ["ts", "tsx"],
"spec": ["test/**/*.spec.*"],
"watch-files": ["src"]
}
5 changes: 2 additions & 3 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// prettier.config.js or .prettierrc.js
module.exports = {
singleQuote: true,
trailingComma: "none",
trailingComma: 'none',
tabWidth: 2,
printWidth: 80,
semi: true,
bracketSpacing: true,
jsxBracketSameLine: false,
endOfLine: "lf"
endOfLine: 'lf'
};
11 changes: 11 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/git"
],
"ci": true,
"debug": true
}
9 changes: 5 additions & 4 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "stylelint-config-standard",
"ignoreFiles": [
"src/decorators/*.js"
]
"extends": "stylelint-config-standard-scss",
"ignoreFiles": ["src/decorators/*.js", "src/*.jsx", "**/*.js"],
"rules": {
"selector-class-pattern": null
}
}
546 changes: 546 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

Large diffs are not rendered by default.

785 changes: 785 additions & 0 deletions .yarn/releases/yarn-3.2.0.cjs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
nodeLinker: node-modules

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: '@yarnpkg/plugin-interactive-tools'

yarnPath: .yarn/releases/yarn-3.2.0.cjs
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Notes:
| padding | data-padding | String | e.g. `8px 21px` | Popup padding style |
| multiline | data-multiline | Bool | true, false | support `<br>`, `<br />` to make multiline |
| className | data-class | String | | extra custom class, can use !important to overwrite react-tooltip's default class |
| html | data-html | Bool | true, false | `<p data-tip="<p>HTML tooltip</p>" data-html={true}></p>` or `<ReactTooltip html={true} />`, but see [Security Note](#security-note) below.<br/>When using JSX, see [this note](#jsx-note) below. |
| html | data-html | Bool | true, false | `<p data-tip="<p>HTML tooltip</p>" data-html={true}></p>` or `<ReactTooltip html={true} />`, but see [Security Note](#security-note) below.<br/>When using JSX, see [this note](#jsx-note) below. |
| delayHide | data-delay-hide | Number | | `<p data-tip="tooltip" data-delay-hide='1000'></p>` or `<ReactTooltip delayHide={1000} />` |
| delayShow | data-delay-show | Number | | `<p data-tip="tooltip" data-delay-show='1000'></p>` or `<ReactTooltip delayShow={1000} />` |
| delayUpdate | data-delay-update | Number | | `<p data-tip="tooltip" data-delay-update='1000'></p>` or `<ReactTooltip delayUpdate={1000} />` Sets a delay in calling getContent if the tooltip is already shown and you mouse over another target |
Expand All @@ -109,8 +109,10 @@ Notes:
The `html` option allows a tooltip to directly display raw HTML. This is a security risk if any of that content is supplied by the user. Any user-supplied content must be sanitized, using a package like [sanitize-html](https://www.npmjs.com/package/sanitize-html). We chose not to include sanitization after discovering it [increased our package size](https://github.com/wwayne/react-tooltip/issues/429) too much - we don't want to penalize people who don't use the `html` option.

#### JSX Note

You can use React's [`renderToStaticMarkup`-function](https://reactjs.org/docs/react-dom-server.html#rendertostaticmarkup) to use JSX instead of HTML. You still need to set `data-html={true}`.
**Example:**

```jsx
import ReactDOMServer from 'react-dom/server';
[...]
Expand Down Expand Up @@ -186,22 +188,22 @@ Same for empty children, if you don't want show the tooltip when the children is

### 3. Tooltip not binding to dynamic content

When you render `<ReactTooltip>` ahead of dynamic content, and are using `data-for={id}` attributes
on new dynamic content, the tooltip will not register its event listener.
When you render `<ReactTooltip>` ahead of dynamic content, and are using `data-for={id}` attributes
on new dynamic content, the tooltip will not register its event listener.

For example, you render a generic tooltip in the root of your app, then load a list of content async.
Elements in the list use the `data-for={id}` attribute to bind the tooltip on hover.
Since the tooltip has already scanned for data-tip these new elements will not trigger.

One workaround for this is to trigger `ReactTooltip.rebuild()` after the data load to scan for the attribute again,
One workaround for this is to trigger `ReactTooltip.rebuild()` after the data load to scan for the attribute again,
to allow event wireup.

#### Example

```jsx
<app>
<ReactTooltip id="foo" />
<list/>
<list />
</app>
```

Expand Down
33 changes: 0 additions & 33 deletions bower.json

This file was deleted.

1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = { extends: ['@commitlint/config-conventional'] };
13 changes: 13 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="src/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite React TypeScript Tailwind Starter</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/index.tsx"></script>
</body>
</html>
Loading

0 comments on commit dc547c1

Please sign in to comment.