1
- import { default as Rate } from "antd/es/rate" ;
2
- import styled , { css } from "styled-components" ;
3
- import { Section , sectionNames } from "lowcoder-design" ;
4
- import { NumberControl , BoolCodeControl } from "../controls/codeControl" ;
5
- import { BoolControl } from "../controls/boolControl" ;
6
- import { changeEvent , eventHandlerControl } from "../controls/eventHandlerControl" ;
7
- import { LabelControl } from "../controls/labelControl" ;
8
- import { numberExposingStateControl } from "../controls/codeStateControl" ;
9
- import { UICompBuilder , withDefault } from "../generators" ;
10
- import { CommonNameConfig , NameConfig , withExposingConfigs } from "../generators/withExposing" ;
11
- import { formDataChildren , FormDataPropertyView } from "./formComp/formDataConstants" ;
12
- import { styleControl } from "comps/controls/styleControl" ;
13
- import { InputFieldStyle , LabelStyle , RatingStyle , RatingStyleType } from "comps/controls/styleControlConstants" ;
14
- import { migrateOldData } from "comps/generators/simpleGenerators" ;
15
- import { disabledPropertyView , hiddenPropertyView } from "comps/utils/propertyUtils" ;
16
- import { trans } from "i18n" ;
17
-
18
- import { useContext , useEffect , useRef } from "react" ;
19
- import { EditorContext } from "comps/editorState" ;
1
+ import { default as Rate } from 'antd/es/rate' ;
2
+ import styled , { css } from 'styled-components' ;
3
+ import { Section , sectionNames } from 'lowcoder-design' ;
4
+ import { NumberControl , BoolCodeControl } from '../controls/codeControl' ;
5
+ import { BoolControl } from '../controls/boolControl' ;
6
+ import {
7
+ changeEvent ,
8
+ eventHandlerControl ,
9
+ } from '../controls/eventHandlerControl' ;
10
+ import { LabelControl } from '../controls/labelControl' ;
11
+ import { numberExposingStateControl } from '../controls/codeStateControl' ;
12
+ import { UICompBuilder , withDefault } from '../generators' ;
13
+ import {
14
+ CommonNameConfig ,
15
+ NameConfig ,
16
+ withExposingConfigs ,
17
+ } from '../generators/withExposing' ;
18
+ import {
19
+ formDataChildren ,
20
+ FormDataPropertyView ,
21
+ } from './formComp/formDataConstants' ;
22
+ import { styleControl } from 'comps/controls/styleControl' ;
23
+ import {
24
+ AnimationStyle ,
25
+ InputFieldStyle ,
26
+ LabelStyle ,
27
+ RatingStyle ,
28
+ RatingStyleType ,
29
+ } from 'comps/controls/styleControlConstants' ;
30
+ import { migrateOldData } from 'comps/generators/simpleGenerators' ;
31
+ import {
32
+ disabledPropertyView ,
33
+ hiddenPropertyView ,
34
+ } from 'comps/utils/propertyUtils' ;
35
+ import { trans } from 'i18n' ;
36
+
37
+ import { useContext , useEffect , useRef } from 'react' ;
38
+ import { EditorContext } from 'comps/editorState' ;
20
39
21
40
const EventOptions = [ changeEvent ] as const ;
22
41
23
42
/**
24
43
* Compatible with old data 2022-08-23
25
44
*/
26
45
function fixOldData ( oldData : any ) {
27
- if ( oldData && oldData . hasOwnProperty ( " unChecked" ) ) {
46
+ if ( oldData && oldData . hasOwnProperty ( ' unChecked' ) ) {
28
47
return {
29
48
label : oldData . label ,
30
49
checked : oldData . checked ,
@@ -36,22 +55,27 @@ function fixOldData(oldData: any) {
36
55
37
56
const RatingBasicComp = ( function ( ) {
38
57
const childrenMap = {
39
- defaultValue : numberExposingStateControl ( " defaultValue" ) ,
40
- value : numberExposingStateControl ( " value" ) ,
41
- max : withDefault ( NumberControl , "5" ) ,
58
+ defaultValue : numberExposingStateControl ( ' defaultValue' ) ,
59
+ value : numberExposingStateControl ( ' value' ) ,
60
+ max : withDefault ( NumberControl , '5' ) ,
42
61
label : LabelControl ,
43
62
allowHalf : BoolControl ,
44
63
disabled : BoolCodeControl ,
45
64
onEvent : eventHandlerControl ( EventOptions ) ,
46
65
style : withDefault ( styleControl ( InputFieldStyle ) , { borderWidth : '1px' } ) ,
47
- labelStyle : styleControl ( LabelStyle . filter ( ( style ) => [ 'accent' , 'validate' ] . includes ( style . name ) === false ) ) ,
48
- inputFieldStyle :migrateOldData ( styleControl ( RatingStyle ) , fixOldData ) ,
66
+ animationStyle : styleControl ( AnimationStyle ) ,
67
+ labelStyle : styleControl (
68
+ LabelStyle . filter (
69
+ ( style ) => [ 'accent' , 'validate' ] . includes ( style . name ) === false
70
+ )
71
+ ) ,
72
+ inputFieldStyle : migrateOldData ( styleControl ( RatingStyle ) , fixOldData ) ,
49
73
...formDataChildren ,
50
74
} ;
51
75
return new UICompBuilder ( childrenMap , ( props ) => {
52
- const defaultValue = { ...props . defaultValue } . value ;
53
- const value = { ...props . value } . value ;
54
- const changeRef = useRef ( false )
76
+ const defaultValue = { ...props . defaultValue } . value ;
77
+ const value = { ...props . value } . value ;
78
+ const changeRef = useRef ( false ) ;
55
79
56
80
useEffect ( ( ) => {
57
81
props . value . onChange ( defaultValue ) ;
@@ -60,14 +84,15 @@ const RatingBasicComp = (function () {
60
84
useEffect ( ( ) => {
61
85
if ( ! changeRef . current ) return ;
62
86
63
- props . onEvent ( " change" ) ;
87
+ props . onEvent ( ' change' ) ;
64
88
changeRef . current = false ;
65
89
} , [ value ] ) ;
66
90
67
91
return props . label ( {
68
92
style : props . style ,
69
93
labelStyle : props . labelStyle ,
70
- inputFieldStyle :props . inputFieldStyle ,
94
+ inputFieldStyle : props . inputFieldStyle ,
95
+ animationStyle : props . animationStyle ,
71
96
children : (
72
97
< RateStyled
73
98
count = { props . max }
@@ -87,33 +112,40 @@ const RatingBasicComp = (function () {
87
112
return (
88
113
< >
89
114
< Section name = { sectionNames . basic } >
90
- { children . defaultValue . propertyView ( { label : trans ( "prop.defaultValue" ) } ) }
115
+ { children . defaultValue . propertyView ( {
116
+ label : trans ( 'prop.defaultValue' ) ,
117
+ } ) }
91
118
{ children . max . propertyView ( {
92
- label : trans ( " rating.max" ) ,
119
+ label : trans ( ' rating.max' ) ,
93
120
} ) }
94
121
</ Section >
95
122
96
123
< FormDataPropertyView { ...children } />
97
124
98
- { [ "logic" , "both" ] . includes ( useContext ( EditorContext ) . editorModeStatus ) && (
99
- < > < Section name = { sectionNames . interaction } >
100
- { children . onEvent . getPropertyView ( ) }
101
- { disabledPropertyView ( children ) }
102
- { hiddenPropertyView ( children ) }
103
- </ Section >
125
+ { [ 'logic' , 'both' ] . includes (
126
+ useContext ( EditorContext ) . editorModeStatus
127
+ ) && (
128
+ < >
129
+ < Section name = { sectionNames . interaction } >
130
+ { children . onEvent . getPropertyView ( ) }
131
+ { disabledPropertyView ( children ) }
132
+ { hiddenPropertyView ( children ) }
133
+ </ Section >
104
134
< Section name = { sectionNames . advanced } >
105
135
{ children . allowHalf . propertyView ( {
106
- label : trans ( " rating.allowHalf" ) ,
136
+ label : trans ( ' rating.allowHalf' ) ,
107
137
} ) }
108
138
</ Section >
109
139
</ >
110
140
) }
111
141
112
- { [ " layout" , " both" ] . includes ( useContext ( EditorContext ) . editorModeStatus ) && (
113
- children . label . getPropertyView ( )
114
- ) }
142
+ { [ ' layout' , ' both' ] . includes (
143
+ useContext ( EditorContext ) . editorModeStatus
144
+ ) && children . label . getPropertyView ( ) }
115
145
116
- { [ "layout" , "both" ] . includes ( useContext ( EditorContext ) . editorModeStatus ) && (
146
+ { [ 'layout' , 'both' ] . includes (
147
+ useContext ( EditorContext ) . editorModeStatus
148
+ ) && (
117
149
< >
118
150
< Section name = { sectionNames . style } >
119
151
{ children . style . getPropertyView ( ) }
@@ -124,6 +156,9 @@ const RatingBasicComp = (function () {
124
156
< Section name = { sectionNames . inputFieldStyle } >
125
157
{ children . inputFieldStyle . getPropertyView ( ) }
126
158
</ Section >
159
+ < Section name = { sectionNames . animationStyle } >
160
+ { children . animationStyle . getPropertyView ( ) }
161
+ </ Section >
127
162
</ >
128
163
) }
129
164
</ >
@@ -133,8 +168,8 @@ const RatingBasicComp = (function () {
133
168
} ) ( ) ;
134
169
135
170
export const RatingComp = withExposingConfigs ( RatingBasicComp , [
136
- new NameConfig ( " value" , trans ( " export.ratingValueDesc" ) ) ,
137
- new NameConfig ( " max" , trans ( " export.ratingMaxDesc" ) ) ,
171
+ new NameConfig ( ' value' , trans ( ' export.ratingValueDesc' ) ) ,
172
+ new NameConfig ( ' max' , trans ( ' export.ratingMaxDesc' ) ) ,
138
173
...CommonNameConfig ,
139
174
] ) ;
140
175
@@ -156,6 +191,6 @@ const getStyle = (style: RatingStyleType) => {
156
191
` ;
157
192
} ;
158
193
159
- export const RateStyled = styled ( Rate ) < { $style : RatingStyleType } > `
194
+ export const RateStyled = styled ( Rate ) < { $style : RatingStyleType } > `
160
195
${ ( props ) => props . $style && getStyle ( props . $style ) }
161
196
` ;
0 commit comments