File tree Expand file tree Collapse file tree 4 files changed +28
-10
lines changed
Expand file tree Collapse file tree 4 files changed +28
-10
lines changed Original file line number Diff line number Diff line change 3636yarn add react-nice-avatar
3737```
3838
39- or
40-
41- ``` sh
42- pnpm i react-nice-avatar
43- ```
44-
4539## Usage
4640
47411 . 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("hi@dapi.to" )
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
58623. Render the component with specific width / height and configuration.
5963 ```jsx
Original file line number Diff line number Diff line change 44 background : #000 ;
55 color : #fff ;
66}
7+
8+ .inputField {
9+ background : rgba (255 , 255 , 255 , 0.1 );
10+ }
Original file line number Diff line number Diff 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 */ }
Original file line number Diff line number Diff line change 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" ,
You can’t perform that action at this time.
0 commit comments