Skip to content

Commit 0e5d96b

Browse files
committed
feat: update demo and readme for seed generation
1 parent 49f8828 commit 0e5d96b

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,28 @@ or
3636
yarn add react-nice-avatar
3737
```
3838

39-
or
40-
41-
```sh
42-
pnpm i react-nice-avatar
43-
```
44-
4539
## Usage
4640

4741
1. Import the component.
4842
```js
4943
import Avatar, { genConfig } from 'react-nice-avatar'
5044
```
51-
2. Generate a random configuration, save it so that you can always rendering a same avatar with the configuration.
45+
2. Generate a configuration
46+
47+
Config can be generated with a seed, seed is a string of name, email or anything you like
5248
```js
53-
const config = genConfig(AvatarConfig?)
49+
const config = genConfig("[email protected]")
5450
```
5551

56-
`tip`: AvatarConfig is an Object, plz check the **Options** below for what attributes can be passed in
52+
or it can be generate with customized object, plz check the Options below for what attributes can be passed in
53+
```js
54+
const config = genConfig({ sex: "man", hairStyle: "mohawk" })
55+
```
56+
57+
or generate a random config by passing nothing to the function genConfig
58+
```js
59+
const config = genConfig()
60+
```
5761

5862
3. Render the component with specific width / height and configuration.
5963
```jsx

demo/src/App/index.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@
44
background: #000;
55
color: #fff;
66
}
7+
8+
.inputField {
9+
background: rgba(255, 255, 255, 0.1);
10+
}

demo/src/App/index.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ class App extends Component {
5454
}
5555
}
5656

57+
onInputKeyUp (e) {
58+
this.setState({
59+
config: genConfig(e.target.value)
60+
})
61+
}
62+
5763
render() {
5864
const { config, shape } = this.state
5965
return (
@@ -74,6 +80,10 @@ class App extends Component {
7480
updateConfig={this.updateConfig.bind(this)}
7581
updateShape={this.updateShape.bind(this)}
7682
download={this.download.bind(this)} />
83+
<input
84+
className="w-64 h-10 p-2 rounded mt-10 inputField text-center outline-none"
85+
placeholder="input name or email ..."
86+
onKeyUp={this.onInputKeyUp.bind(this)} />
7787
</main>
7888

7989
{/* Avatar list */}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-nice-avatar",
3-
"version": "1.2.4",
3+
"version": "1.3.0",
44
"description": "react library for generating avatar",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

0 commit comments

Comments
 (0)