| 1 |
|
| 2 |
export const getBorderAttributes = ( prefix, defaultArgs = {} ) => { |
| 3 |
const defaults = { |
| 4 |
// Width |
| 5 |
borderTopWidth: '', |
| 6 |
borderRightWidth: '', |
| 7 |
borderBottomWidth: '', |
| 8 |
borderLeftWidth: '', |
| 9 |
borderTopWidthTablet: '', |
| 10 |
borderRightWidthTablet: '', |
| 11 |
borderBottomWidthTablet: '', |
| 12 |
borderLeftWidthTablet: '', |
| 13 |
borderTopWidthMobile: '', |
| 14 |
borderRightWidthMobile: '', |
| 15 |
borderBottomWidthMobile: '', |
| 16 |
borderLeftWidthMobile: '', |
| 17 |
// Radius |
| 18 |
borderTopLeftRadius: '', |
| 19 |
borderTopRightRadius: '', |
| 20 |
borderBottomRightRadius: '', |
| 21 |
borderBottomLeftRadius: '', |
| 22 |
borderTopLeftRadiusTablet: '', |
| 23 |
borderTopRightRadiusTablet: '', |
| 24 |
borderBottomRightRadiusTablet: '', |
| 25 |
borderBottomLeftRadiusTablet: '', |
| 26 |
borderTopLeftRadiusMobile: '', |
| 27 |
borderTopRightRadiusMobile: '', |
| 28 |
borderBottomRightRadiusMobile: '', |
| 29 |
borderBottomLeftRadiusMobile: '', |
| 30 |
// unit |
| 31 |
borderRadiusUnit: 'px', |
| 32 |
borderRadiusUnitTablet: 'px', |
| 33 |
borderRadiusUnitMobile: 'px', |
| 34 |
// common |
| 35 |
borderStyle: '', |
| 36 |
borderColor: '', |
| 37 |
borderHColor: '', |
| 38 |
...defaultArgs |
| 39 |
}; |
| 40 |
const attributes = {}; |
| 41 |
const devices = [ |
| 42 |
{ devicePrefix: '', copyPastePrefix: '' }, |
| 43 |
{ devicePrefix: 'Tablet', copyPastePrefix: '-tablet' }, |
| 44 |
{ devicePrefix: 'Mobile', copyPastePrefix: '-mobile' }, |
| 45 |
]; |
| 46 |
|
| 47 |
devices.forEach( item => { |
| 48 |
// border width |
| 49 |
attributes[ prefix + 'BorderTopWidth' + item.devicePrefix ] = { |
| 50 |
type: 'number', |
| 51 |
default: defaults[ `borderTopWidth${ item.devicePrefix }` ], |
| 52 |
UAGCopyPaste: { |
| 53 |
styleType: prefix + '-border-top-width' + item.copyPastePrefix |
| 54 |
} |
| 55 |
} |
| 56 |
attributes[ prefix + 'BorderLeftWidth' + item.devicePrefix ] = { |
| 57 |
type: 'number', |
| 58 |
default: defaults[ `borderLeftWidth${ item.devicePrefix }` ], |
| 59 |
UAGCopyPaste: { |
| 60 |
styleType: prefix + '-border-left-width' + item.copyPastePrefix |
| 61 |
} |
| 62 |
} |
| 63 |
attributes[ prefix + 'BorderRightWidth' + item.devicePrefix ] = { |
| 64 |
type: 'number', |
| 65 |
default: defaults[ `borderRightWidth${ item.devicePrefix }` ], |
| 66 |
UAGCopyPaste: { |
| 67 |
styleType: prefix + '-border-right-width' + item.copyPastePrefix |
| 68 |
} |
| 69 |
} |
| 70 |
attributes[ prefix + 'BorderBottomWidth' + item.devicePrefix ] = { |
| 71 |
type: 'number', |
| 72 |
default: defaults[ `borderBottomWidth${ item.devicePrefix }` ], |
| 73 |
UAGCopyPaste: { |
| 74 |
styleType: prefix + '-border-bottom-width' + item.copyPastePrefix |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
// border radius |
| 79 |
attributes[ prefix + 'BorderTopLeftRadius' + item.devicePrefix ] = { |
| 80 |
type: 'number', |
| 81 |
default: defaults[ `borderTopLeftRadius${ item.devicePrefix }` ], |
| 82 |
UAGCopyPaste: { |
| 83 |
styleType: prefix + '-border-top-left-radius' + item.copyPastePrefix |
| 84 |
} |
| 85 |
} |
| 86 |
attributes[ prefix + 'BorderTopRightRadius' + item.devicePrefix ] = { |
| 87 |
type: 'number', |
| 88 |
default: defaults[ `borderTopRightRadius${ item.devicePrefix }` ], |
| 89 |
UAGCopyPaste: { |
| 90 |
styleType: prefix + '-border-top-right-radius' + item.copyPastePrefix |
| 91 |
} |
| 92 |
} |
| 93 |
attributes[ prefix + 'BorderBottomLeftRadius' + item.devicePrefix ] = { |
| 94 |
type: 'number', |
| 95 |
default: defaults[ `borderBottomLeftRadius${ item.devicePrefix }` ], |
| 96 |
UAGCopyPaste: { |
| 97 |
styleType: prefix + '-border-bottom-left-radius' + item.copyPastePrefix |
| 98 |
} |
| 99 |
} |
| 100 |
attributes[ prefix + 'BorderBottomRightRadius' + item.devicePrefix ] = { |
| 101 |
type: 'number', |
| 102 |
default: defaults[ `borderBottomRightRadius${ item.devicePrefix }` ], |
| 103 |
UAGCopyPaste: { |
| 104 |
styleType: prefix + '-border-bottom-right-radius' + item.copyPastePrefix |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
// radius unit |
| 109 |
attributes[ prefix + 'BorderRadiusUnit' + item.devicePrefix ] = { |
| 110 |
type: 'string', |
| 111 |
default: defaults[ `borderRadiusUnit${ item.devicePrefix }` ], |
| 112 |
UAGCopyPaste: { |
| 113 |
styleType: prefix + '-border-radius-unit' + item.copyPastePrefix |
| 114 |
} |
| 115 |
} |
| 116 |
} ); |
| 117 |
|
| 118 |
attributes[ prefix + 'BorderLink' ] = { |
| 119 |
type: 'boolean', |
| 120 |
default: true, |
| 121 |
UAGCopyPaste: { |
| 122 |
styleType: prefix + '-border-link' |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
attributes[ prefix + 'BorderRadiusLink' ] = { |
| 127 |
type: 'boolean', |
| 128 |
default: true, |
| 129 |
UAGCopyPaste: { |
| 130 |
styleType: prefix + '-border-radius-link' |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
attributes[ prefix + 'BorderStyle' ] = { |
| 135 |
type: 'string', |
| 136 |
default: defaults.borderStyle, |
| 137 |
UAGCopyPaste: { |
| 138 |
styleType: prefix + '-border-style' |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
attributes[ prefix + 'BorderColor' ] = { |
| 143 |
type: 'string', |
| 144 |
default: defaults.borderColor, |
| 145 |
UAGCopyPaste: { |
| 146 |
styleType: prefix + '-border-color' |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
attributes[ prefix + 'BorderHColor' ] = { |
| 151 |
type: 'string', |
| 152 |
default: defaults.borderHColor, |
| 153 |
UAGCopyPaste: { |
| 154 |
styleType: prefix + '-border-hover-color' |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
return attributes; |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
export const migrateBorderAttributes = ( prefix, borderWidth, borderRadius, color = {}, hoverColor = {}, borderStyle = {}, setAttributes, attributes = {} ) => { |
| 163 |
|
| 164 |
if( ! isNaN( borderWidth.value ) ){ |
| 165 |
|
| 166 |
if( '' === attributes[ prefix + 'BorderTopWidth' ] ) { |
| 167 |
setAttributes( { [ prefix + 'BorderTopWidth'] : borderWidth.value } ); |
| 168 |
} |
| 169 |
if( '' === attributes[ prefix + 'BorderLeftWidth' ] ) { |
| 170 |
setAttributes( { [ prefix + 'BorderLeftWidth' ]: borderWidth.value } ); |
| 171 |
} |
| 172 |
if( '' === attributes[ prefix + 'BorderRightWidth' ] ) { |
| 173 |
setAttributes( { [ prefix + 'BorderRightWidth' ]: borderWidth.value } ); |
| 174 |
} |
| 175 |
if( '' === attributes[ prefix + 'BorderBottomWidth' ] ) { |
| 176 |
setAttributes( { [ prefix + 'BorderBottomWidth' ] : borderWidth.value } ); |
| 177 |
} |
| 178 |
// reset |
| 179 |
attributes[borderWidth.label] = ''; |
| 180 |
} |
| 181 |
|
| 182 |
if( ! isNaN ( borderRadius.value ) ){ |
| 183 |
|
| 184 |
if( '' === attributes[ prefix + 'BorderTopLeftRadius' ] ) { |
| 185 |
setAttributes( { [ prefix + 'BorderTopLeftRadius' ] : borderRadius.value } ); |
| 186 |
} |
| 187 |
if( '' === attributes[ prefix + 'BorderTopRightRadius' ] ) { |
| 188 |
setAttributes( { [ prefix + 'BorderTopRightRadius' ] : borderRadius.value } ); |
| 189 |
} |
| 190 |
if( '' === attributes[ prefix + 'BorderBottomLeftRadius' ] ) { |
| 191 |
setAttributes( { [ prefix + 'BorderBottomLeftRadius' ] : borderRadius.value } ); |
| 192 |
} |
| 193 |
if( '' === attributes[ prefix + 'BorderBottomRightRadius' ] ) { |
| 194 |
setAttributes( { [ prefix + 'BorderBottomRightRadius' ] : borderRadius.value } ); |
| 195 |
} |
| 196 |
// reset |
| 197 |
attributes[ borderRadius.label ] = ''; |
| 198 |
} |
| 199 |
|
| 200 |
if( color.value ){ |
| 201 |
if( '' === attributes[ prefix + 'BorderColor' ] ) { |
| 202 |
setAttributes( { [ prefix + 'BorderColor' ] : color.value } ); |
| 203 |
} |
| 204 |
// reset |
| 205 |
attributes[ color.label ] = ''; |
| 206 |
} |
| 207 |
|
| 208 |
if( hoverColor.value ){ |
| 209 |
if( '' === attributes[ prefix + 'BorderHColor' ] ) { |
| 210 |
setAttributes( { [ prefix + 'BorderHColor' ] : hoverColor.value } ); |
| 211 |
} |
| 212 |
// reset |
| 213 |
attributes[ hoverColor.label ] = ''; |
| 214 |
} |
| 215 |
|
| 216 |
if( borderStyle.value ){ |
| 217 |
if( '' === attributes[ prefix + 'BorderStyle' ] ) { |
| 218 |
setAttributes( { [ prefix + 'BorderStyle' ] : borderStyle.value } ); |
| 219 |
} |
| 220 |
// reset |
| 221 |
attributes[ borderStyle.label ] = ''; |
| 222 |
} |
| 223 |
return attributes; |
| 224 |
} |
| 225 |
|