diff --git a/.dumirc.ts b/.dumirc.ts new file mode 100644 index 00000000..3983dd72 --- /dev/null +++ b/.dumirc.ts @@ -0,0 +1,14 @@ +import { defineConfig } from 'dumi'; + +export default defineConfig({ + favicons: [ + 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4', + ], + themeConfig: { + name: 'InputNumber', + logo: 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4' + }, + outputPath: '.doc', + exportStatic: {}, + styles: [`body .dumi-default-header-left { width: 230px; } body .dumi-default-hero-title { font-size: 100px; }`], +}); diff --git a/.fatherrc.js b/.fatherrc.js deleted file mode 100644 index 39ff4cbc..00000000 --- a/.fatherrc.js +++ /dev/null @@ -1,10 +0,0 @@ -export default { - cjs: 'babel', - esm: { type: 'babel', importLibToEs: true }, - preCommit: { - // Father preCommit is OOD. comment this tmp. - // eslint: true, - // prettier: true, - }, - runtimeHelpers: true, -}; diff --git a/.fatherrc.ts b/.fatherrc.ts new file mode 100644 index 00000000..96268ae1 --- /dev/null +++ b/.fatherrc.ts @@ -0,0 +1,5 @@ +import { defineConfig } from 'father'; + +export default defineConfig({ + plugins: ['@rc-component/father-plugin'], +}); diff --git a/.gitignore b/.gitignore index 8c2d5a2a..3a0da955 100755 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ lib es coverage yarn.lock +pnpm-lock.yaml package-lock.json .doc/ @@ -34,3 +35,8 @@ package-lock.json .umi-production .umi-test .env.local + +# dumi +.dumi/tmp +.dumi/tmp-production + diff --git a/.umirc.ts b/.umirc.ts deleted file mode 100644 index 00290453..00000000 --- a/.umirc.ts +++ /dev/null @@ -1,19 +0,0 @@ -// more config: https://d.umijs.org/config -import { defineConfig } from 'dumi'; - -export default defineConfig({ - title: 'rc-input-number', - favicon: - 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4', - logo: - 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4', - outputPath: '.doc', - exportStatic: {}, - styles: [ - ` - .markdown table { - width: auto !important; - } - `, - ] -}); diff --git a/docs/api.md b/docs/api.md new file mode 100644 index 00000000..8762db2c --- /dev/null +++ b/docs/api.md @@ -0,0 +1,194 @@ +--- +title: API +nav: + order: 10 + title: API + path: /api +--- + +
| name | +type | +default | +description | +
|---|---|---|---|
| prefixCls | +string | +rc-input-number | +Specifies the class prefix | +
| min | +Number | ++ | Specifies the minimum value | +
| onClick | ++ | + | + |
| placeholder | +string | ++ | + |
| max | +Number | ++ | Specifies the maximum value | +
| step | +Number or String | +1 | +Specifies the legal number intervals | +
| precision | +Number | ++ | Specifies the precision length of value | +
| disabled | +Boolean | +false | +Specifies that an InputNumber should be disabled | +
| focusOnUpDown | +Boolean | +true | +whether focus input when click up or down button | +
| required | +Boolean | +false | +Specifies that an InputNumber is required | +
| autoFocus | +Boolean | +false | +Specifies that an InputNumber should automatically get focus when the page loads | +
| readOnly | +Boolean | +false | +Specifies that an InputNumber is read only | +
| controls | +Boolean | +true | +Whether to enable the control buttons | +
| name | +String | ++ | Specifies the name of an InputNumber | +
| id | +String | ++ | Specifies the id of an InputNumber | +
| value | +Number | ++ | Specifies the value of an InputNumber | +
| defaultValue | +Number | ++ | Specifies the defaultValue of an InputNumber | +
| onChange | +Function | ++ | Called when value of an InputNumber changed | +
| onBlur | +Function | ++ | Called when user leaves an input field | +
| onPressEnter | +Function | ++ | The callback function that is triggered when Enter key is pressed. | +
| onFocus | +Function | ++ | Called when an element gets focus | +
| style | +Object | ++ | root style. such as {width:100} | +
| upHandler | +React.Node | ++ | custom the up step element | +
| downHandler | +React.Node | ++ | custom the down step element | +
| formatter | +(value: number|string): displayValue: string | ++ | Specifies the format of the value presented | +
| parser | +(displayValue: string) => value: number | +`input => input.replace(/[^\w\.-]*/g, '')` | +Specifies the value extracted from formatter | +
| pattern | +string | ++ | Specifies a regex pattern to be added to the input number element - useful for forcing iOS to open the number pad instead of the normal keyboard (supply a regex of "\d*" to do this) or form validation | +
| decimalSeparator | +string | ++ | Specifies the decimal separator | +
| inputMode | +string | ++ | Specifies the inputmode of input | +
diff --git a/docs/examples/combination-key-format.tsx b/docs/demo/combination-key-format.tsx
similarity index 100%
rename from docs/examples/combination-key-format.tsx
rename to docs/demo/combination-key-format.tsx
diff --git a/docs/demo/custom.md b/docs/demo/custom.md
deleted file mode 100644
index 0949653e..00000000
--- a/docs/demo/custom.md
+++ /dev/null
@@ -1,3 +0,0 @@
-## custom
-
-
diff --git a/docs/examples/custom.tsx b/docs/demo/custom.tsx
similarity index 100%
rename from docs/examples/custom.tsx
rename to docs/demo/custom.tsx
diff --git a/docs/demo/debug.md b/docs/demo/debug.md
deleted file mode 100644
index 27706ef0..00000000
--- a/docs/demo/debug.md
+++ /dev/null
@@ -1,3 +0,0 @@
-## debug
-
-
diff --git a/docs/examples/debug.tsx b/docs/demo/debug.tsx
similarity index 100%
rename from docs/examples/debug.tsx
rename to docs/demo/debug.tsx
diff --git a/docs/demo/decimal.md b/docs/demo/decimal.md
deleted file mode 100644
index 4204dc6e..00000000
--- a/docs/demo/decimal.md
+++ /dev/null
@@ -1,3 +0,0 @@
-## decimal
-
-
diff --git a/docs/examples/decimal.tsx b/docs/demo/decimal.tsx
similarity index 100%
rename from docs/examples/decimal.tsx
rename to docs/demo/decimal.tsx
diff --git a/docs/demo/formatter.md b/docs/demo/formatter.md
deleted file mode 100644
index e4a75fba..00000000
--- a/docs/demo/formatter.md
+++ /dev/null
@@ -1,3 +0,0 @@
-## formatter
-
-
diff --git a/docs/examples/formatter.tsx b/docs/demo/formatter.tsx
similarity index 100%
rename from docs/examples/formatter.tsx
rename to docs/demo/formatter.tsx
diff --git a/docs/demo/input-control.md b/docs/demo/input-control.md
deleted file mode 100644
index ec95a8cc..00000000
--- a/docs/demo/input-control.md
+++ /dev/null
@@ -1,3 +0,0 @@
-## input-control
-
-
diff --git a/docs/examples/input-control.tsx b/docs/demo/input-control.tsx
similarity index 100%
rename from docs/examples/input-control.tsx
rename to docs/demo/input-control.tsx
diff --git a/docs/demo/precision.md b/docs/demo/precision.md
deleted file mode 100644
index bb7135df..00000000
--- a/docs/demo/precision.md
+++ /dev/null
@@ -1,3 +0,0 @@
-## precision
-
-
diff --git a/docs/examples/precision.tsx b/docs/demo/precision.tsx
similarity index 100%
rename from docs/examples/precision.tsx
rename to docs/demo/precision.tsx
diff --git a/docs/demo/simple-use-touch.md b/docs/demo/simple-use-touch.md
deleted file mode 100644
index bef7f876..00000000
--- a/docs/demo/simple-use-touch.md
+++ /dev/null
@@ -1,3 +0,0 @@
-## simple-use-touch
-
-
diff --git a/docs/examples/simple-use-touch.tsx b/docs/demo/simple-use-touch.tsx
similarity index 100%
rename from docs/examples/simple-use-touch.tsx
rename to docs/demo/simple-use-touch.tsx
diff --git a/docs/demo/simple.md b/docs/demo/simple.md
deleted file mode 100644
index efaf04c4..00000000
--- a/docs/demo/simple.md
+++ /dev/null
@@ -1,3 +0,0 @@
-## simple
-
-
diff --git a/docs/examples/simple.tsx b/docs/demo/simple.tsx
similarity index 100%
rename from docs/examples/simple.tsx
rename to docs/demo/simple.tsx
diff --git a/docs/demo/small-step.md b/docs/demo/small-step.md
deleted file mode 100644
index a9269a6e..00000000
--- a/docs/demo/small-step.md
+++ /dev/null
@@ -1,3 +0,0 @@
-## small-step
-
-
diff --git a/docs/examples/small-step.tsx b/docs/demo/small-step.tsx
similarity index 100%
rename from docs/examples/small-step.tsx
rename to docs/demo/small-step.tsx
diff --git a/docs/example.md b/docs/example.md
new file mode 100644
index 00000000..ee7ac902
--- /dev/null
+++ b/docs/example.md
@@ -0,0 +1,48 @@
+---
+title: Example
+nav:
+ title: Example
+ path: /example
+---
+
+## simple
+
+
+
+## combination-key-format
+
+
+
+## custom
+
+
+
+## debug
+
+
+
+## decimal
+
+
+
+## formatter
+
+
+
+## input-control
+
+
+
+## precision
+
+
+
+## simple-use-touch
+
+
+
+## small-step
+
+
+
+
diff --git a/docs/index.md b/docs/index.md
index bb209b4a..488dd463 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -1,5 +1,55 @@
---
-title: rc-input-number
+hero:
+ title: rc-input-number
+ description: React InputNumber Component
---
-
+## Install
+
+```sh
+# npm
+npm install --save rc-input-number
+
+# yarn
+yarn install rc-input-number
+
+# pnpm
+pnpm i rc-input-number
+```
+
+## Usage
+
+```ts
+import InputNumber from 'rc-input-number';
+
+export default () => ;
+```
+
+## Development
+
+```sh
+npm install
+npm start
+```
+
+### Keyboard Navigation
+
+- When you hit the ⬆ or ⬇ key, the input value will be increased or decreased by step
+- With the Shift key (Shift+⬆, Shift+⬇), the input value will be changed by 10 * step
+- With the Ctrl or ⌘ key (Ctrl+⬆ or ⌘+⬆ or Ctrl+⬇ or ⌘+⬇ ), the input value will be changed by 0.1 * step
+
+## Test Case
+
+```sh
+npm test
+```
+
+## Coverage
+
+```sh
+npm run coverage
+```
+
+## License
+
+rc-input-number is released under the MIT license.
diff --git a/jest.config.js b/jest.config.js
deleted file mode 100644
index 5328c18e..00000000
--- a/jest.config.js
+++ /dev/null
@@ -1,3 +0,0 @@
-module.exports = {
- setupFiles: ['./tests/setup.js'],
-};
diff --git a/jest.config.ts b/jest.config.ts
new file mode 100644
index 00000000..a81b4f1e
--- /dev/null
+++ b/jest.config.ts
@@ -0,0 +1,16 @@
+import { createConfig, type Config } from '@umijs/test';
+
+const defaultConfig = createConfig({
+ target: 'browser',
+ jsTransformer: 'swc'
+});
+
+const config: Config.InitialOptions = {
+ ...defaultConfig,
+ setupFiles: [
+ ...defaultConfig.setupFiles,
+ './tests/setup.js'
+ ]
+};
+
+export default config;
diff --git a/package.json b/package.json
index c151575c..ee1a71e9 100644
--- a/package.json
+++ b/package.json
@@ -20,14 +20,14 @@
"author": "tsjxyz@gmail.com",
"main": "./lib/index",
"module": "./es/index",
+ "types": "./es/index.d.ts",
"files": [
"lib",
"es",
"assets/*.css"
],
"scripts": {
- "compile": "father-build && lessc assets/index.less assets/index.css",
- "coverage": "father test --coverage",
+ "compile": "father build && lessc assets/index.less assets/index.css",
"docs:build": "dumi build",
"docs:deploy": "gh-pages -d docs-dist",
"lint": "eslint src/ --ext .ts,.tsx,.jsx,.js,.md",
@@ -35,7 +35,8 @@
"prepublishOnly": "npm run compile && np --yolo --no-publish",
"prettier": "prettier --write \"**/*.{ts,tsx,js,jsx,json,md}\"",
"start": "dumi dev",
- "test": "father test"
+ "test": "jest",
+ "coverage": "jest --coverage"
},
"dependencies": {
"@babel/runtime": "^7.10.1",
@@ -44,21 +45,24 @@
"rc-util": "^5.23.0"
},
"devDependencies": {
- "@testing-library/jest-dom": "^5.16.4",
- "@testing-library/react": "^13.3.0",
+ "@rc-component/father-plugin": "^1.0.1",
+ "@testing-library/jest-dom": "^5.16.5",
+ "@testing-library/react": "^13.4.0",
+ "@swc-node/jest": "^1.5.5",
"@types/classnames": "^2.2.9",
- "@types/enzyme": "^3.10.8",
- "@types/jest": "^29.2.3",
- "@types/react": "^17.0.37",
- "@types/react-dom": "^17.0.9",
+ "@types/jest": "^29.2.4",
+ "@types/react": "^18.0.26",
+ "@types/react-dom": "^18.0.9",
"@types/responselike": "^1.0.0",
+ "@umijs/test": "^4.0.36",
"@umijs/fabric": "^2.0.0",
- "cross-env": "^7.0.0",
- "dumi": "^1.1.0",
+ "cross-env": "^7.0.3",
+ "dumi": "^2.0.13",
+ "jest": "^29.3.1",
+ "jest-environment-jsdom": "^29.3.1",
"eslint": "^7.1.0",
"expect.js": "~0.3.1",
- "father": "^2.22.0",
- "father-build": "^1.19.1",
+ "father": "^4.1.1",
"glob": "^7.1.6",
"less": "^3.12.2",
"np": "^7.2.0",
@@ -66,7 +70,8 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"regenerator-runtime": "^0.13.7",
- "typescript": "^4.0.2"
+ "ts-node": "^10.9.1",
+ "typescript": "^4.9.4"
},
"peerDependencies": {
"react": ">=16.9.0",
diff --git a/tests/click.test.tsx b/tests/click.test.tsx
index e5807db2..96023038 100644
--- a/tests/click.test.tsx
+++ b/tests/click.test.tsx
@@ -1,4 +1,4 @@
-import React from 'react';
+import * as React from 'react';
import { render, fireEvent, act } from '@testing-library/react';
import InputNumber, { InputNumberProps } from '../src';
import KeyCode from 'rc-util/lib/KeyCode';
diff --git a/tests/mobile.test.tsx b/tests/mobile.test.tsx
index ff0eaaf1..d997b691 100644
--- a/tests/mobile.test.tsx
+++ b/tests/mobile.test.tsx
@@ -1,4 +1,4 @@
-import React from 'react';
+import * as React from 'react';
import { render, fireEvent } from './util/wrapper';
import InputNumber from '../src';