1- import React , { useState } from "react"
2- import ReactInputTags from ' ../src'
3- import { TagInterface } from "../src/ReactInputTags"
4- import ' ./index.css'
1+ import React , { useState } from "react" ;
2+ import ReactInputTags from " ../src" ;
3+ import { TagInterface } from "../src/ReactInputTags" ;
4+ import " ./index.css" ;
55
6- function addReadOnlyToTags ( tag : TagInterface ) : Boolean {
7- if ( typeof tag . value === "string" && tag . value . startsWith ( "t" ) ) {
8- return true ;
9- }
10- return false ;
6+ function addReadOnlyToTags ( tag : TagInterface ) : Boolean {
7+ if ( typeof tag . value === "string" && tag . value . startsWith ( "t" ) ) {
8+ return true ;
9+ }
10+ return false ;
1111}
1212
1313export default function ( ) {
14-
15- const [ tags , setTags ] = useState < TagInterface [ ] > ( [ ] )
16- const onChange = ( newTags : TagInterface [ ] , newTag ?: TagInterface ) => {
17- console . log ( newTags )
18- if ( newTag ) {
19- const isTrue = addReadOnlyToTags ( newTag ) ;
20- if ( isTrue ) {
21- const tagIndex = newTags . findIndex ( ( tag_ ) => tag_ . value === newTag . value )
22- newTags [ tagIndex ] . readOnly = true ;
23- }
24- }
25- setTags ( newTags )
14+ const [ tags , setTags ] = useState < TagInterface [ ] > ( [
15+ { label : "Happy" , value : "happy" } ,
16+ // { label: "Sad", value: "sad" },
17+ { label : "Excited" , value : "excited" } ,
18+ { label : "Angry" , value : "angry" } ,
19+ // { label: "Surprised", value: "surprised" },
20+ { label : "Content" , value : "content" } ,
21+ { label : "Inspired" , value : "inspired" } ,
22+ // { label: "Nervous", value: "nervous" },
23+ { label : "Relaxed" , value : "relaxed" } ,
24+ ] ) ;
25+ const onChange = ( newTags : TagInterface [ ] , newTag ?: TagInterface ) => {
26+ console . log ( newTags ) ;
27+ if ( newTag ) {
28+ const isTrue = addReadOnlyToTags ( newTag ) ;
29+ if ( isTrue ) {
30+ const tagIndex = newTags . findIndex ( ( tag_ ) => tag_ . value === newTag . value ) ;
31+ newTags [ tagIndex ] . readOnly = true ;
32+ }
2633 }
27-
28- const options = [
29- {
30- label : "Happy" ,
31- value : "happy"
32- } ,
33- {
34- label : "Sad" ,
35- value : "sad"
36- } ,
37- {
38- label : "Negative" ,
39- value : "negative"
40- } ,
41- {
42- label : "Happy" ,
43- value : "happy"
44- } ,
45- {
46- label : "Sad" ,
47- value : "sad"
48- } ,
49- {
50- label : "Negative" ,
51- value : "negative"
52- } ,
53- {
54- label : "Happy" ,
55- value : "happy"
56- } ,
57- {
58- label : "Sad" ,
59- value : "sad"
60- } ,
61- {
62- label : "Negative" ,
63- value : "negative"
64- } ,
65- {
66- label : "Happy" ,
67- value : "happy"
68- } ,
69- {
70- label : "Sad" ,
71- value : "sad"
72- } ,
73- {
74- label : "Negative" ,
75- value : "negative"
76- } ,
77- {
78- label : "Happy" ,
79- value : "happy"
80- } ,
81- {
82- label : "Sad" ,
83- value : "sad"
84- } ,
85- {
86- label : "Negative" ,
87- value : "negative"
88- } ,
89- ]
34+ setTags ( newTags ) ;
35+ } ;
9036
91- return (
92- < div className = "example-container" >
93- < ReactInputTags
94- tags = { tags }
95- onChange = { onChange }
96- options = { options }
97- creatable = { true }
98- style = { {
99- mainContainer : 'main-container' ,
100- tag : 'tag' ,
101- input : 'input' ,
102- optionContainer : 'option-container' ,
103- option : 'option' ,
104- selectedOption : 'selected-option'
105- } } />
106- </ div >
107- )
108- }
37+ const options = [
38+ { label : "Happy" , value : "happy" } ,
39+ { label : "Sad" , value : "sad" } ,
40+ { label : "Excited" , value : "excited" } ,
41+ { label : "Angry" , value : "angry" } ,
42+ { label : "Surprised" , value : "surprised" } ,
43+ { label : "Bored" , value : "bored" } ,
44+ { label : "Confused" , value : "confused" } ,
45+ { label : "Anxious" , value : "anxious" } ,
46+ { label : "Content" , value : "content" } ,
47+ { label : "Curious" , value : "curious" } ,
48+ { label : "Frustrated" , value : "frustrated" } ,
49+ { label : "Hopeful" , value : "hopeful" } ,
50+ { label : "Inspired" , value : "inspired" } ,
51+ { label : "Nervous" , value : "nervous" } ,
52+ { label : "Relaxed" , value : "relaxed" } ,
53+ { label : "Lonely" , value : "lonely" } ,
54+ { label : "Jealous" , value : "jealous" } ,
55+ { label : "Proud" , value : "proud" } ,
56+ { label : "Shy" , value : "shy" } ,
57+ { label : "Grateful" , value : "grateful" } ,
58+ ] ;
59+
60+ return (
61+ < div className = "example-container" >
62+ < ReactInputTags
63+ tags = { tags }
64+ onChange = { onChange }
65+ options = { options }
66+ creatable = { true }
67+ style = { {
68+ mainContainer : "main-container-1" ,
69+ tag : "tag-1" ,
70+ input : "input-1" ,
71+ optionContainer : "option-container" ,
72+ option : "option" ,
73+ selectedOption : "selected-option" ,
74+ } }
75+ />
76+ </ div >
77+ ) ;
78+ }
0 commit comments