11/**
2- * Copyright (c) 2022 - present TinyVue Authors.
3- * Copyright (c) 2022 - present Huawei Cloud Computing Technologies Co., Ltd.
4- *
5- * Use of this source code is governed by an MIT-style license.
6- *
7- * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8- * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9- * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10- *
11- */
2+ * Copyright (c) 2022 - present TinyVue Authors.
3+ * Copyright (c) 2022 - present Huawei Cloud Computing Technologies Co., Ltd.
4+ *
5+ * Use of this source code is governed by an MIT-style license.
6+ *
7+ * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8+ * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9+ * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10+ *
11+ */
1212
13- export const computedStyle = ( { state, props } ) => ( ) => ( {
14- fill : props . color ,
15- color : props . color ,
16- backgroundColor : props . backgroundColor ,
17- backgroundImage : / ^ ( i m a g e ) $ / . test ( props . type ) && state . internalValue ? `url(${ state . internalValue } )` : 'none'
18- } )
13+ export const computedStyle =
14+ ( { state, props } ) =>
15+ ( ) => {
16+ return {
17+ fill : props . color ,
18+ color : props . color ,
19+ backgroundColor : props . backgroundColor ,
20+ backgroundImage : / ^ ( i m a g e ) $ / . test ( props . type ) && state . internalValue ? `url(${ state . internalValue } )` : 'none'
21+ }
22+ }
1923
2024export const computedMessage = ( props ) => ( ) => {
2125 let result = ''
@@ -32,27 +36,32 @@ export const computedMessage = (props) => () => {
3236 return result
3337}
3438
35- export const computedFontSize = ( { props, state } ) => ( ) => {
36- let fontSize = ''
39+ export const computedFontSize =
40+ ( { props, state } ) =>
41+ ( ) => {
42+ let fontSize = ''
43+
44+ if ( props . type === 'label' && state . label && ! props . min ) {
45+ const length = state . label . length
46+ const sizeMap = {
47+ 1 : '40px' ,
48+ 2 : '30px' ,
49+ 3 : '22px' ,
50+ 4 : '20px' ,
51+ 5 : '18px' ,
52+ 6 : '16px'
53+ }
3754
38- if ( props . type === 'label' && state . label && ! props . min ) {
39- const length = state . label . length
40- const sizeMap = {
41- 1 : '40px' ,
42- 2 : '30px' ,
43- 3 : '22px' ,
44- 4 : '20px' ,
45- 5 : '18px' ,
46- 6 : '16px'
55+ fontSize = sizeMap [ length ]
4756 }
4857
49- fontSize = sizeMap [ length ]
58+ return { fontSize }
5059 }
5160
52- return { fontSize }
53- }
54-
55- export const computedLabel = ( { state , props } ) => ( ) => ( props . min ? state . internalValue . substr ( 0 , 2 ) : state . internalValue . substr ( 0 , 6 ) )
61+ export const computedLabel =
62+ ( { state , props } ) =>
63+ ( ) =>
64+ props . min ? state . internalValue . substr ( 0 , 2 ) : state . internalValue . substr ( 0 , 6 )
5665
5766export const getInternalValue = ( props ) => ( ) => {
5867 if ( ! props . modelValue ) {
@@ -69,3 +78,27 @@ export const getInternalValue = (props) => () => {
6978 return props . modelValue
7079 }
7180}
81+
82+ export const computedSize =
83+ ( { props, state } ) =>
84+ ( ) => {
85+ let size = props . size
86+
87+ if ( typeof size === 'string' ) {
88+ switch ( size ) {
89+ case 'large' :
90+ size = 64
91+ break
92+ case 'medium' :
93+ size = 40
94+ break
95+ case 'small' :
96+ size = 22
97+ break
98+ default :
99+ size = 40
100+ break
101+ }
102+ }
103+ return size
104+ }
0 commit comments