Skip to content

Commit f01cb45

Browse files
committed
First commit
0 parents  commit f01cb45

19 files changed

+12563
-0
lines changed

.github/workflows/main.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: CI
2+
on: [push]
3+
jobs:
4+
build:
5+
runs-on: ubuntu-latest
6+
7+
steps:
8+
- name: Begin CI...
9+
uses: actions/checkout@v2
10+
11+
- name: Use Node 12
12+
uses: actions/setup-node@v1
13+
with:
14+
node-version: 12.x
15+
16+
- name: Use cached node_modules
17+
uses: actions/cache@v1
18+
with:
19+
path: node_modules
20+
key: nodeModules-${{ hashFiles('**/yarn.lock') }}
21+
restore-keys: |
22+
nodeModules-
23+
24+
- name: Install dependencies
25+
run: yarn install --frozen-lockfile
26+
env:
27+
CI: true
28+
29+
- name: Lint
30+
run: yarn lint
31+
env:
32+
CI: true
33+
34+
- name: Test
35+
run: yarn test --ci --coverage --maxWorkers=2
36+
env:
37+
CI: true
38+
39+
- name: Build
40+
run: yarn build
41+
env:
42+
CI: true

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.log
2+
.DS_Store
3+
node_modules
4+
.cache
5+
dist

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 F2 .net engineering s.r.l.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# React Inline Edit Async
2+
3+
Congrats! You just saved yourself hours of work by bootstrapping this project with TSDX. Let’s get you oriented with what’s here and how to use it.
4+
5+
> This TSDX setup is meant for developing React components (not apps!) that can be published to NPM. If you’re looking to build an app, you should use `create-react-app`, `razzle`, `nextjs`, `gatsby`, or `react-static`.
6+
7+
> If you’re new to TypeScript and React, checkout [this handy cheatsheet](https://github.com/sw-yx/react-typescript-cheatsheet/)
8+
9+
## Commands
10+
11+
TSDX scaffolds your new library inside `/src`, and also sets up a [Parcel-based](https://parceljs.org) playground for it inside `/example`.
12+
13+
The recommended workflow is to run TSDX in one terminal:
14+
15+
```bash
16+
npm start # or yarn start
17+
```
18+
19+
This builds to `/dist` and runs the project in watch mode so any edits you save inside `src` causes a rebuild to `/dist`.
20+
21+
Then run the example inside another:
22+
23+
```bash
24+
cd example
25+
npm i # or yarn to install dependencies
26+
npm start # or yarn start
27+
```
28+
29+
The default example imports and live reloads whatever is in `/dist`, so if you are seeing an out of date component, make sure TSDX is running in watch mode like we recommend above. **No symlinking required**, [we use Parcel's aliasing](https://github.com/palmerhq/tsdx/pull/88/files).
30+
31+
To do a one-off build, use `npm run build` or `yarn build`.
32+
33+
To run tests, use `npm test` or `yarn test`.
34+
35+
## Configuration
36+
37+
Code quality is [set up for you](https://github.com/palmerhq/tsdx/pull/45/files) with `prettier`, `husky`, and `lint-staged`. Adjust the respective fields in `package.json` accordingly.
38+
39+
### Jest
40+
41+
Jest tests are set up to run with `npm test` or `yarn test`. This runs the test watcher (Jest) in an interactive mode. By default, runs tests related to files changed since the last commit.
42+
43+
#### Setup Files
44+
45+
This is the folder structure we set up for you:
46+
47+
```shell
48+
/example
49+
index.html
50+
index.tsx # test your component here in a demo app
51+
package.json
52+
tsconfig.json
53+
/src
54+
index.tsx # EDIT THIS
55+
/test
56+
blah.test.tsx # EDIT THIS
57+
.gitignore
58+
package.json
59+
README.md # EDIT THIS
60+
tsconfig.json
61+
```
62+
63+
#### React Testing Library
64+
65+
We do not set up `react-testing-library` for you yet, we welcome contributions and documentation on this.
66+
67+
### Rollup
68+
69+
TSDX uses [Rollup v1.x](https://rollupjs.org) as a bundler and generates multiple rollup configs for various module formats and build settings. See [Optimizations](#optimizations) for details.
70+
71+
### TypeScript
72+
73+
`tsconfig.json` is set up to interpret `dom` and `esnext` types, as well as `react` for `jsx`. Adjust according to your needs.
74+
75+
## Continuous Integration
76+
77+
### Travis
78+
79+
_to be completed_
80+
81+
### Circle
82+
83+
_to be completed_
84+
85+
## Optimizations
86+
87+
Please see the main `tsdx` [optimizations docs](https://github.com/palmerhq/tsdx#optimizations). In particular, know that you can take advantage of development-only optimizations:
88+
89+
```js
90+
// ./types/index.d.ts
91+
declare var __DEV__: boolean;
92+
93+
// inside your code...
94+
if (__DEV__) {
95+
console.log('foo');
96+
}
97+
```
98+
99+
You can also choose to install and use [invariant](https://github.com/palmerhq/tsdx#invariant) and [warning](https://github.com/palmerhq/tsdx#warning) functions.
100+
101+
## Module Formats
102+
103+
CJS, ESModules, and UMD module formats are supported.
104+
105+
The appropriate paths are configured in `package.json` and `dist/index.js` accordingly. Please report if any issues are found.
106+
107+
## Using the Playground
108+
109+
```bash
110+
cd example
111+
npm i # or yarn to install dependencies
112+
npm start # or yarn start
113+
```
114+
115+
The default example imports and live reloads whatever is in `/dist`, so if you are seeing an out of date component, make sure TSDX is running in watch mode like we recommend above. **No symlinking required**!
116+
117+
## Deploying the Playground
118+
119+
The Playground is just a simple [Parcel](https://parceljs.org) app, you can deploy it anywhere you would normally deploy that. Here are some guidelines for **manually** deploying with the Netlify CLI (`npm i -g netlify-cli`):
120+
121+
```bash
122+
cd example # if not already in the example folder
123+
npm run build # builds to dist
124+
netlify deploy # deploy the dist folder
125+
```
126+
127+
Alternatively, if you already have a git repo connected, you can set up continuous deployment with Netlify:
128+
129+
```bash
130+
netlify init
131+
# build command: yarn build && cd example && yarn && yarn build
132+
# directory to deploy: example/dist
133+
# pick yes for netlify.toml
134+
```
135+
136+
## Named Exports
137+
138+
Per Palmer Group guidelines, [always use named exports.](https://github.com/palmerhq/typescript#exports) Code split inside your React app instead of your React library.
139+
140+
## Including Styles
141+
142+
There are many ways to ship styles, including with CSS-in-JS. TSDX has no opinion on this, configure how you like.
143+
144+
For vanilla CSS, you can include it at the root directory and add it to the `files` section in your `package.json`, so that it can be imported separately by your users and run through their bundler's loader.
145+
146+
## Publishing to NPM
147+
148+
We recommend using [np](https://github.com/sindresorhus/np).
149+
150+
## Usage with Lerna
151+
152+
When creating a new package with TSDX within a project set up with Lerna, you might encounter a `Cannot resolve dependency` error when trying to run the `example` project. To fix that you will need to make changes to the `package.json` file _inside the `example` directory_.
153+
154+
The problem is that due to the nature of how dependencies are installed in Lerna projects, the aliases in the example project's `package.json` might not point to the right place, as those dependencies might have been installed in the root of your Lerna project.
155+
156+
Change the `alias` to point to where those packages are actually installed. This depends on the directory structure of your Lerna project, so the actual path might be different from the diff below.
157+
158+
```diff
159+
"alias": {
160+
- "react": "../node_modules/react",
161+
- "react-dom": "../node_modules/react-dom"
162+
+ "react": "../../../node_modules/react",
163+
+ "react-dom": "../../../node_modules/react-dom"
164+
},
165+
```
166+
167+
An alternative to fixing this problem would be to remove aliases altogether and define the dependencies referenced as aliases as dev dependencies instead. [However, that might cause other problems.](https://github.com/palmerhq/tsdx/issues/64)

example/.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.cache
3+
dist

example/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
7+
<title>Playground</title>
8+
</head>
9+
10+
<body>
11+
<div id="root"></div>
12+
<script src="./index.tsx"></script>
13+
</body>
14+
</html>

example/index.tsx

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import 'react-app-polyfill/ie11'
2+
import * as React from 'react'
3+
import * as ReactDOM from 'react-dom'
4+
import InlineEdit, { InputType } from '../.'
5+
6+
const App = () => {
7+
const validate = input => input.length > 3
8+
const onChange = value => {
9+
return fetch(value).then(_ => value)
10+
}
11+
12+
const options = [
13+
{ id: 1, name: 'Mela' },
14+
{ id: 2, name: 'Arancia' },
15+
{ id: 3, name: 'Albicocca' },
16+
]
17+
18+
return (
19+
<div>
20+
<style
21+
dangerouslySetInnerHTML={{
22+
__html: `
23+
.styled { display: block; padding: 5px 10px; border-radius: 3px; }
24+
.styled:hover { background-color: #f0f0f0 }
25+
`,
26+
}}
27+
/>
28+
29+
<InlineEdit
30+
value="pizza"
31+
validate={validate}
32+
onChange={onChange}
33+
viewClass="styled"
34+
allowEditWhileLoading
35+
/>
36+
<InlineEdit
37+
value="disabled"
38+
validate={validate}
39+
onChange={onChange}
40+
editProps={{ style: { padding: 10 } }}
41+
isDisabled
42+
/>
43+
<InlineEdit
44+
value="koala"
45+
validate={validate}
46+
onChange={onChange}
47+
editProps={{ style: { padding: 10 } }}
48+
/>
49+
<InlineEdit
50+
type={InputType.Number}
51+
value="34"
52+
validate={i => parseInt(i, 10) > 0}
53+
onChange={onChange}
54+
editProps={{ min: 10, max: 20, step: 2 }}
55+
format={value => '€ ' + value}
56+
/>
57+
<InlineEdit
58+
type={InputType.Date}
59+
value="2020-03-12"
60+
onChange={onChange}
61+
/>
62+
<InlineEdit
63+
type={InputType.Range}
64+
value="6"
65+
validate={i => parseInt(i, 10) > 3}
66+
onChange={onChange}
67+
editProps={{ min: 0, max: 10, step: 1 }}
68+
/>
69+
<InlineEdit
70+
type={InputType.TextArea}
71+
value="pizza patatine"
72+
onChange={onChange}
73+
editProps={{ rows: 4 }}
74+
format={v => v.toUpperCase()}
75+
/>
76+
<InlineEdit
77+
type={InputType.Select}
78+
value="2"
79+
onChange={onChange}
80+
options={options}
81+
valueKey="id"
82+
labelKey="name"
83+
/>
84+
</div>
85+
)
86+
}
87+
88+
ReactDOM.render(<App />, document.getElementById('root'))

example/package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "example",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"scripts": {
7+
"start": "parcel index.html",
8+
"build": "parcel build index.html"
9+
},
10+
"dependencies": {
11+
"react-app-polyfill": "^1.0.0"
12+
},
13+
"alias": {
14+
"react": "../node_modules/react",
15+
"react-dom": "../node_modules/react-dom/profiling",
16+
"scheduler/tracing": "../node_modules/scheduler/tracing-profiling"
17+
},
18+
"devDependencies": {
19+
"@types/react": "^16.9.11",
20+
"@types/react-dom": "^16.8.4",
21+
"parcel": "^1.12.3",
22+
"typescript": "^3.4.5"
23+
}
24+
}

example/tsconfig.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"allowSyntheticDefaultImports": false,
4+
"target": "es5",
5+
"module": "commonjs",
6+
"jsx": "react",
7+
"moduleResolution": "node",
8+
"noImplicitAny": false,
9+
"noUnusedLocals": false,
10+
"noUnusedParameters": false,
11+
"removeComments": true,
12+
"strictNullChecks": true,
13+
"preserveConstEnums": true,
14+
"sourceMap": true,
15+
"lib": ["es2015", "es2016", "dom"],
16+
"baseUrl": ".",
17+
"types": ["node"]
18+
}
19+
}

0 commit comments

Comments
 (0)