@@ -9,6 +9,11 @@ export interface PluginProps {
99 onChange : any ;
1010}
1111
12+ interface IOption {
13+ label : string ;
14+ value : string ;
15+ }
16+
1217export default class ClassNameView extends PureComponent < PluginProps > {
1318 static display = 'ClassName' ;
1419
@@ -22,10 +27,15 @@ export default class ClassNameView extends PureComponent<PluginProps> {
2227 value : '' ,
2328 } ;
2429
30+ state = {
31+ dataSource : [ ] ,
32+ selectValue : [ ] ,
33+ } ;
34+
2535 getClassNameList = ( ) => {
2636 const schema = project . exportSchema ( ) ;
27- const css = schema . componentsTree [ 0 ] . css ;
28- const classNameList = [ ] ;
37+ const { css } = schema . componentsTree [ 0 ] ;
38+ const classNameList : string [ ] = [ ] ;
2939 if ( css ) {
3040 const re = / \. ? \w + [ ^ { ] + \{ [ ^ } ] * \} / g;
3141 const list = css . match ( re ) ;
@@ -47,9 +57,9 @@ export default class ClassNameView extends PureComponent<PluginProps> {
4757 return classNameList ;
4858 } ;
4959
50- handleChange = ( value ) => {
60+ handleChange = ( value ?: string [ ] ) => {
5161 const { onChange } = this . props ;
52- onChange ( value . join ( ' ' ) ) ;
62+ onChange ( value ? .join ( ' ' ) ) ;
5363 this . setState ( {
5464 selectValue : value ,
5565 } ) ;
@@ -59,7 +69,7 @@ export default class ClassNameView extends PureComponent<PluginProps> {
5969 componentWillMount ( ) {
6070 const { value } = this . props ;
6171 const classnameList = this . getClassNameList ( ) ;
62- const dataSource = [ ] ;
72+ const dataSource : IOption [ ] = [ ] ;
6373 classnameList . map ( ( item ) => {
6474 dataSource . push ( {
6575 value : item ,
@@ -69,7 +79,7 @@ export default class ClassNameView extends PureComponent<PluginProps> {
6979 return item ;
7080 } ) ;
7181
72- let selectValue = [ ] ;
82+ let selectValue : string [ ] = [ ] ;
7383 if ( value && value !== '' ) {
7484 selectValue = value . split ( ' ' ) ;
7585 }
@@ -98,7 +108,7 @@ export default class ClassNameView extends PureComponent<PluginProps> {
98108 aria-label = "tag mode"
99109 mode = "tag"
100110 dataSource = { dataSource }
101- onChange = { this . handleChange }
111+ onChange = { ( value ) => this . handleChange ( value as string [ ] ) }
102112 value = { selectValue }
103113 />
104114 ) ;
0 commit comments