Skip to content

Commit db89daa

Browse files
committed
init project.
0 parents  commit db89daa

File tree

20 files changed

+675
-0
lines changed

20 files changed

+675
-0
lines changed

.babelrc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"env": {
3+
"cjs": {
4+
"plugins": [
5+
[
6+
"babel-plugin-transform-remove-imports",
7+
{ "test": "(less|css)$" }
8+
]
9+
]
10+
},
11+
"esm": {
12+
"plugins": [
13+
[
14+
"babel-plugin-transform-rename-import",
15+
{ "original": "^(.+?)\\.less$", "replacement": "$1.css" }
16+
]
17+
]
18+
},
19+
"esm:dev": {
20+
"presets": [
21+
"@babel/preset-react",
22+
[
23+
"@tsbb/babel-preset-tsbb",
24+
{
25+
"modules": false,
26+
"targets": {
27+
"browsers": [ "last 2 versions" ]
28+
},
29+
"transformRuntime": {
30+
"useESModules": true
31+
}
32+
}
33+
]
34+
]
35+
}
36+
}
37+
}

.github/workflows/ci.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Build & Deploy
2+
on:
3+
push:
4+
branches:
5+
- master
6+
7+
env:
8+
SKIP_PREFLIGHT_CHECK: true
9+
10+
jobs:
11+
build-deploy:
12+
runs-on: ubuntu-18.04
13+
steps:
14+
- uses: actions/checkout@v2
15+
- uses: actions/setup-node@v2
16+
with:
17+
node-version: 14
18+
19+
- run: npm install
20+
- run: npm run build:lib
21+
- run: npm run doc
22+
- run: npm run test:coverage
23+
24+
- name: Create Tag
25+
id: create_tag
26+
uses: jaywcjlove/create-tag-action@v1.2.0
27+
with:
28+
token: ${{ secrets.GITHUB_TOKEN }}
29+
package-path: ./package.json
30+
31+
- name: Generate Changelog
32+
id: changelog
33+
uses: jaywcjlove/changelog-generator@v1.4.2
34+
with:
35+
token: ${{ secrets.GITHUB_TOKEN }}
36+
head-ref: ${{steps.create_tag.outputs.version}}
37+
filter-author: (jaywcjlove|小弟调调™|dependabot\[bot\]|Renovate Bot)
38+
filter: '[R|r]elease[d]\s+[v|V]\d(\.\d+){0,2}'
39+
40+
- name: Deploy
41+
uses: peaceiris/actions-gh-pages@v3
42+
with:
43+
github_token: ${{ secrets.GITHUB_TOKEN }}
44+
publish_dir: ./build
45+
46+
- name: Create Release
47+
uses: ncipollo/release-action@v1
48+
if: steps.create_tag.outputs.successful
49+
with:
50+
name: ${{ steps.create_tag.outputs.version }}
51+
tag: ${{ steps.create_tag.outputs.version }}
52+
token: ${{ secrets.GITHUB_TOKEN }}
53+
body: |
54+
[![](https://img.shields.io/badge/Open%20in-unpkg-blue)](https://uiwjs.github.io/npm-unpkg/#/pkg/@uiw/react-only-when@${{steps.changelog.outputs.version}}/file/README.md)
55+
56+
```bash
57+
npm i @uiw/react-only-when@${{steps.changelog.outputs.version}}
58+
```
59+
${{ steps.changelog.outputs.compareurl }}
60+
${{ steps.changelog.outputs.changelog }}
61+
62+
- run: npm install @jsdevtools/npm-publish -g
63+
- run: npm-publish --token="${{ secrets.NPM_TOKEN }}" ./package.json

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
lib
2+
build
3+
coverage
4+
node_modules
5+
npm-debug.log*
6+
package-lock.json
7+
8+
.eslintcache
9+
.DS_Store
10+
.cache
11+
.vscode
12+
13+
*.bak
14+
*.tem
15+
*.temp
16+
#.swp
17+
*.*~
18+
~*.*

.kktrc.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import path from 'path';
2+
import webpack, { Configuration } from 'webpack';
3+
import { LoaderConfOptions } from 'kkt';
4+
import WebpackDevServer from 'webpack-dev-server';
5+
import lessModules from '@kkt/less-modules';
6+
import rawModules from '@kkt/raw-modules';
7+
import scopePluginOptions from '@kkt/scope-plugin-options';
8+
import pkg from './package.json';
9+
10+
export default (conf: Configuration, env: 'development' | 'production', options: LoaderConfOptions) => {
11+
conf = rawModules(conf, env, { ...options });
12+
conf = scopePluginOptions(conf, env, {
13+
...options,
14+
allowedFiles: [path.resolve(process.cwd(), 'README.md'), path.resolve(process.cwd(), 'src')],
15+
});
16+
conf = lessModules(conf, env, options);
17+
// Get the project version.
18+
conf.plugins!.push(
19+
new webpack.DefinePlugin({
20+
VERSION: JSON.stringify(pkg.version),
21+
}),
22+
);
23+
conf.output = { ...conf.output, publicPath: './' };
24+
return conf;
25+
};
26+
27+
/**
28+
* Modify WebpackDevServer Configuration Example
29+
*/
30+
export const devServer = (config: WebpackDevServer.Configuration) => {
31+
// Return your customised Webpack Development Server config.
32+
return config;
33+
};

.prettierignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
**/*.md
2+
**/*.svg
3+
**/*.ejs
4+
**/*.yml
5+
package.json
6+
node_modules
7+
dist
8+
build
9+
lib
10+
test

.prettierrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all",
4+
"printWidth": 120,
5+
"overrides": [
6+
{
7+
"files": ".prettierrc",
8+
"options": { "parser": "json" }
9+
}
10+
]
11+
}

README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
react-only-when
2+
===
3+
4+
A declarative component for conditional rendering. Copy [`react-only-when`](https://github.com/sag1v/react-only-when), let it support TypeScript.
5+
6+
## Quick Start
7+
8+
```bash
9+
$ npm install --save @uiw/react-only-when
10+
```
11+
12+
## Usage
13+
14+
```jsx
15+
import Only from '@uiw/react-only-when'
16+
17+
<Only when={true}>
18+
<h1>Here I Am</h1>
19+
</Only>
20+
```
21+
22+
## Example
23+
24+
```jsx
25+
import React from 'react';
26+
import Only from '@uiw/react-only-when';
27+
28+
function App() {
29+
const [show, setShow] = useState(true)
30+
return (
31+
<div className="app">
32+
<button onClick={() => setShow(!show)}>Toggle</button>
33+
<Only when={show}>
34+
<h1>Here I Am</h1>
35+
</Only>
36+
</div>
37+
)
38+
}
39+
```
40+
41+
## props
42+
43+
| prop name | type | default | isRequired | description |
44+
| ----- | ----- | ----- | ----- | ----- |
45+
| children | react element | `null` | `true` | A single child element |
46+
| when | bool | `false` | `true` | When true, children will rendered as is |
47+
| hiddenMode | string | `null` | `false` | Determines how children should be hidden |
48+
| className | string | `r-o_hidden` | `false` | This is working in combination with `hiddenMode={"css"}` |
49+
50+
### hiddenMode enum
51+
52+
| hiddenMode | description |
53+
| ----- | ----- |
54+
| `null` | Will not render the child |
55+
| `display` | Will render the child with `display:none` |
56+
| `visibility` | Will render the child with `visibility:hidden` |
57+
| `css` | Will render the child with a CSS class (you can pass it a custom `className` prop) |
58+
59+
60+
## Development
61+
62+
Runs the project in development mode.
63+
64+
```bash
65+
# Step 1, run first, listen to the component compile and output the .js file
66+
# listen for compilation output type .d.ts file
67+
npm run watch
68+
# Step 2, development mode, listen to compile preview website instance
69+
npm run start
70+
```
71+
72+
**production**
73+
74+
Builds the app for production to the build folder.
75+
76+
```bash
77+
npm run build
78+
```
79+
80+
The build is minified and the filenames include the hashes.
81+
Your app is ready to be deployed!
82+
83+
84+
## License
85+
86+
MIT © [`sag1v`](https://github.com/sag1v) & [`uiwjs`](https://github.com/uiwjs)

package.json

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"name": "@uiw/react-only-when",
3+
"version": "1.0.0",
4+
"description": "A declarative component for conditional rendering.",
5+
"main": "lib/cjs/index.js",
6+
"module": "lib/esm/index.js",
7+
"scripts": {
8+
"prepack": "npm run build:lib",
9+
"doc": "kkt build --app-src ./website",
10+
"start": "kkt start --app-src ./website",
11+
"build": "npm run build:lib && npm run doc",
12+
"build:lib": "npm run ts:build && npm run types:esm && npm run types:cjs",
13+
"watch": "npm run ts:watch & npm run types:watch",
14+
"types:build": "tsbb types --sourceRoot src --target ESNEXT",
15+
"types:watch": "npm run types:esm -- --watch & npm run types:cjs -- --watch",
16+
"types:esm": "npm run types:build -- --outDir ../lib/esm",
17+
"types:cjs": "npm run types:build -- --outDir ../lib/cjs",
18+
"ts:watch": "tsbb watch --env-name esm:dev --env-name cjs --target react",
19+
"ts:build": "tsbb build --target react",
20+
"prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"",
21+
"test": "kkt test --env=jsdom --app-src=./website",
22+
"test:coverage": "kkt test --env=jsdom --coverage --app-src=./website"
23+
},
24+
"repository": {
25+
"type": "git",
26+
"url": "https://github.com/uiwjs/react-only-when.git"
27+
},
28+
"author": "kenny wang <wowohoo@qq.com>",
29+
"license": "MIT",
30+
"husky": {
31+
"hooks": {
32+
"pre-commit": "lint-staged"
33+
}
34+
},
35+
"lint-staged": {
36+
"*.{js,jsx,tsx,ts,less,md,json}": [
37+
"prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\""
38+
]
39+
},
40+
"peerDependencies": {
41+
"@babel/runtime": ">=7.10.0",
42+
"react": ">=16.9.0",
43+
"react-dom": ">=16.9.0"
44+
},
45+
"devDependencies": {
46+
"@kkt/less-modules": "6.10.4",
47+
"@kkt/raw-modules": "6.10.4",
48+
"@kkt/scope-plugin-options": "6.10.4",
49+
"@types/react": "17.0.11",
50+
"@types/react-dom": "17.0.7",
51+
"@types/react-test-renderer": "17.0.1",
52+
"@uiw/react-github-corners": "1.4.0",
53+
"@uiw/react-markdown-preview": "3.1.1",
54+
"husky": "4.3.8",
55+
"kkt": "6.10.4",
56+
"lint-staged": "11.0.0",
57+
"prettier": "2.3.1",
58+
"react": "17.0.2",
59+
"react-dom": "17.0.2",
60+
"react-test-renderer": "17.0.2",
61+
"tsbb": "2.2.0"
62+
},
63+
"eslintConfig": {
64+
"extends": [
65+
"react-app",
66+
"react-app/jest"
67+
]
68+
},
69+
"browserslist": {
70+
"production": [
71+
">0.2%",
72+
"not dead",
73+
"not op_mini all"
74+
],
75+
"development": [
76+
"last 1 chrome version",
77+
"last 1 firefox version",
78+
"last 1 safari version"
79+
]
80+
}
81+
}

public/favicon.ico

3.78 KB
Binary file not shown.

public/index.html

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
7+
<meta name="theme-color" content="#000000">
8+
<!--<link rel="manifest" href="%PUBLIC_URL%/manifest.json">-->
9+
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
10+
<!--
11+
Notice the use of %PUBLIC_URL% in the tags above.
12+
It will be replaced with the URL of the `public` folder during the build.
13+
Only files inside the `public` folder can be referenced from the HTML.
14+
15+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
16+
work correctly both with client-side routing and a non-root public URL.
17+
Learn how to configure a non-root public URL by running `npm run build`.
18+
-->
19+
<title>React App - A declarative component for conditional rendering.</title>
20+
</head>
21+
22+
<body>
23+
<noscript>
24+
You need to enable JavaScript to run this app.
25+
</noscript>
26+
<div id="root"></div>
27+
<!--
28+
This HTML file is a template.
29+
If you open it directly in the browser, you will see an empty page.
30+
31+
You can add webfonts, meta tags, or analytics to this file.
32+
The build step will place the bundled scripts into the <body> tag.
33+
34+
To begin the development, run `npm start` or `yarn start`.
35+
To create a production bundle, use `npm run build` or `yarn build`.
36+
-->
37+
</body>
38+
39+
</html>

0 commit comments

Comments
 (0)