Skip to content

Commit

Permalink
feat: initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
victory726 committed Sep 16, 2020
1 parent 9519960 commit aac8835
Show file tree
Hide file tree
Showing 263 changed files with 11,344 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.js

# build
dist
es
lib
35 changes: 35 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2020,
// project: './tsconfig.eslint.json',
},
extends: [
'airbnb',
'airbnb-typescript',
'prettier',
'prettier/react',
'prettier/@typescript-eslint',
],
env: {
browser: true,
// jest: true,
},
plugins: ['compat', 'react-hooks'],
rules: {
'compat/compat': 'error',
'no-underscore-dangle': 'off',
'react/jsx-filename-extension': 'off',
'react/jsx-props-no-spreading': 'off',
'react/no-array-index-key': 'off',
'react/require-default-props': 'off',
'react/prop-types': 'off',
'react-hooks/rules-of-hooks': 'error',
'jsx-a11y/click-events-have-key-events': 'off',
'jsx-a11y/label-has-associated-control': 'off',
'jsx-a11y/label-has-for': 'off',
},
settings: {
polyfills: ['IntersectionObserver', 'Promise'],
},
};
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# dependencies
/node_modules
/storybook/node_modules

# testing
/coverage

# production
/build
/dist
/lib
/es

# misc
.DS_Store

npm-debug.log*
yarn-debug.log*
yarn-error.log*
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"printWidth": 100,
"singleQuote": true,
"trailingComma": "all",
"proseWrap": "never",
"endOfLine": "lf"
}
73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<p align="center">
<a href="https://chatui.io/">
<img width="109" height="28" src="https://gw.alicdn.com/tfs/TB1uYH4QoY1gK0jSZFMXXaWcVXa-218-56.svg" alt="ChatUI">
</a>
</p>

<p align="center">服务于智能对话领域的设计和开发体系,助力智能对话机器人的搭建</p>

## 安装

```bash
npm install chatui --save
```

```bash
yarn add chatui
```

## 示例

```jsx
import Chat, { Bubble, useMessages } from 'chatui';
import 'chatui/dist/index.css';

const App = () => {
const { messages, appendMsg, setTyping } = useMessages([]);

function handleSend(type, val) {
if (type === 'text' && val.trim()) {
appendMsg({
type: 'text',
content: { text: val },
position: 'right',
});

setTyping(true);

setTimeout(() => {
appendMsg({
type: 'text',
content: { text: 'Bala bala' },
});
}, 1000);
}
}

function renderMessageContent(msg) {
const { content } = msg;
return <Bubble content={content.text} />;
}

return (
<Chat
navbar={{ title: '智能助理' }}
messages={messages}
renderMessageContent={renderMessageContent}
onSend={handleSend}
/>
);
};
```

### 定制主题

参考 [定制主题](https://chatui.io/docs/customize-theme) 文档。

## 国际化

参考 [国际化](https://chatui.io/docs/i18n) 文档。

## License

MIT
50 changes: 50 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module.exports = (api) => {
const env = api.env();
api.cache.using(() => env === 'development');

return {
presets: ['@babel/preset-env', '@babel/preset-typescript', '@babel/preset-react'],
plugins: [
'@babel/plugin-transform-runtime',

// Stage 3
'@babel/plugin-proposal-class-properties',
],
env: {
esm: {
presets: [
[
'@babel/preset-env',
{
modules: false,
},
],
],
plugins: [
[
'@babel/plugin-transform-runtime',
{
useESModules: true,
},
],
],
},
umd: {
presets: [
[
'@babel/preset-env',
{
targets: {
android: '4.4',
ios: '9',
},
useBuiltIns: 'usage',
corejs: 3,
},
],
],
plugins: [['@babel/plugin-transform-runtime', { corejs: 3 }]],
},
},
};
};
3 changes: 3 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
};
43 changes: 43 additions & 0 deletions config/webpack.demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module.exports = () => {
process.env.BROWSERSLIST_ENV = 'production';

return {
mode: 'development',
devtool: 'cheap-module-eval-source-map',
entry: './demo/index.js',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: 'babel-loader',
},
{
test: /\.less$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 2,
sourceMap: true,
},
},
'postcss-loader',
'less-loader',
],
},
],
},
externals: {
react: 'React',
'react-dom': 'ReactDOM',
'chat-ui': 'ChatUI',
},
devServer: {
contentBase: './demo',
port: 9000,
stats: 'minimal',
},
};
};
48 changes: 48 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const gulp = require('gulp');
const babel = require('gulp-babel');
const less = require('gulp-less');
const postcss = require('gulp-postcss');

process.env.NODE_ENV = 'production';

const paths = {
js: ['./src/**/*.js'],
dest: {
lib: 'lib',
esm: 'es',
dist: 'dist',
},
};

function fullStyle(cb) {
gulp.src('./src/styles/index.less').pipe(less()).pipe(postcss()).pipe(gulp.dest(paths.dest.dist));

cb();
}

function copyLess() {
return gulp
.src('src/**/**/*.less')
.pipe(gulp.dest(paths.dest.lib))
.pipe(gulp.dest(paths.dest.esm));
}

function compileScripts(babelEnv, destDir) {
process.env.BABEL_ENV = babelEnv;

return gulp
.src(['src/**/*.{ts,tsx}', '!src/**/__tests__/*.{ts,tsx}'])
.pipe(babel())
.pipe(gulp.dest(destDir));
}

function compileCJS() {
return compileScripts('cjs', paths.dest.lib);
}

function compileESM() {
return compileScripts('esm', paths.dest.esm);
}

exports.default = gulp.series([compileESM, compileCJS, copyLess]);
exports.umd = gulp.series([fullStyle]);
6 changes: 6 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
testPathIgnorePatterns: ['/node_modules/', '/lib/', '/es/', '/dist/', 'examples'],
setupFilesAfterEnv: ['./jest.setup.ts'],
};
2 changes: 2 additions & 0 deletions jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom/extend-expect';
Loading

0 comments on commit aac8835

Please sign in to comment.