feat(gradient-text): background-image transition

This commit is contained in:
07akioni 2020-11-17 02:17:38 +08:00
parent 6d22635148
commit cf0881fb34
4 changed files with 71 additions and 20 deletions

View File

@ -24,6 +24,8 @@ import {
import { formatLength } from '../../_utils' import { formatLength } from '../../_utils'
import styles from './styles/index' import styles from './styles/index'
let houdiniRegistered = false
export default { export default {
name: 'GradientText', name: 'GradientText',
mixins: [ mixins: [
@ -75,6 +77,25 @@ export default {
} }
return undefined return undefined
} }
},
beforeMount () {
if (!houdiniRegistered) {
houdiniRegistered = true
if (window.CSS) {
CSS.registerProperty({
name: '--start-stop',
syntax: '<color>',
inherits: false,
initialValue: 'transparent'
})
CSS.registerProperty({
name: '--end-stop',
syntax: '<color>',
inherits: false,
initialValue: 'transparent'
})
}
}
} }
} }
</script> </script>

View File

@ -3,13 +3,22 @@ import { c, cTB, cM } from '../../../_utils/cssr'
export default c([ export default c([
({ props }) => { ({ props }) => {
const { const {
backgroundImagePrimary, rotate,
backgroundImageInfo, colorStartPrimary,
backgroundImageSuccess, colorEndPrimary,
backgroundImageWarning, colorStartInfo,
backgroundImageError, colorEndInfo,
colorStartWarning,
colorEndWarning,
colorStartError,
colorEndError,
colorStartSuccess,
colorEndSuccess,
fontWeight fontWeight
} = props.$local } = props.$local
const {
cubicBezierEaseInOut
} = props.$base
return cTB('gradient-text', { return cTB('gradient-text', {
raw: ` raw: `
display: inline-block; display: inline-block;
@ -19,32 +28,41 @@ export default c([
background-clip: text; background-clip: text;
color: transparent; color: transparent;
white-space: nowrap; white-space: nowrap;
background-image: linear-gradient(${rotate}, var(--start-stop) 0%, var(--end-stop) 100%);
transition:
--start-stop .3s ${cubicBezierEaseInOut},
--end-stop .3s ${cubicBezierEaseInOut};
` `
}, },
[ [
cM('default-type', { cM('default-type', {
raw: ` raw: `
background-image: ${backgroundImagePrimary}; --start-stop: ${colorStartPrimary};
--end-stop: ${colorEndPrimary};
` `
}), }),
cM('success-type', { cM('success-type', {
raw: ` raw: `
background-image: ${backgroundImageSuccess}; --start-stop: ${colorStartSuccess};
--end-stop: ${colorEndSuccess};
` `
}), }),
cM('warning-type', { cM('warning-type', {
raw: ` raw: `
background-image: ${backgroundImageWarning}; --start-stop: ${colorStartWarning};
--end-stop: ${colorEndWarning};
` `
}), }),
cM('error-type', { cM('error-type', {
raw: ` raw: `
background-image: ${backgroundImageError}; --start-stop: ${colorStartError};
--end-stop: ${colorEndError};
` `
}), }),
cM('info-type', { cM('info-type', {
raw: ` raw: `
background-image: ${backgroundImageInfo}; --start-stop: ${colorStartInfo};
--end-stop: ${colorEndInfo};
` `
}) })
]) ])

View File

@ -18,11 +18,17 @@ export default create({
} = derived } = derived
return { return {
fontWeight: base.fontWeightStrong, fontWeight: base.fontWeightStrong,
backgroundImagePrimary: `linear-gradient(252deg, ${primaryColor} 0%, ${primaryColorSuppl} 100%)`, rotate: '252deg',
backgroundImageSuccess: `linear-gradient(252deg, ${successColor} 0%, ${successColorSuppl} 100%)`, colorStartPrimary: primaryColor,
backgroundImageWarning: ` linear-gradient(252deg, ${warningColor} 0%, ${warningColorSuppl} 100%)`, colorEndPrimary: primaryColorSuppl,
backgroundImageError: `linear-gradient(252deg, ${errorColor} 0%, ${errorColorSuppl} 100%)`, colorStartInfo: infoColor,
backgroundImageInfo: `linear-gradient(252deg, ${infoColor} 0%, ${infoColorSuppl} 100%)` colorEndInfo: infoColorSuppl,
colorStartWarning: warningColor,
colorEndWarning: warningColorSuppl,
colorStartError: errorColor,
colorEndError: errorColorSuppl,
colorStartSuccess: successColor,
colorEndSuccess: successColorSuppl
} }
} }
}) })

View File

@ -14,11 +14,17 @@ export default create({
} = derived } = derived
return { return {
fontWeight: base.fontWeightStrong, fontWeight: base.fontWeightStrong,
backgroundImagePrimary: `linear-gradient(252deg, ${changeColor(primaryColor, { alpha: 0.6 })} 0%, ${primaryColor} 100%)`, rotate: '252deg',
backgroundImageSuccess: `linear-gradient(252deg, ${changeColor(successColor, { alpha: 0.6 })} 0%, ${successColor} 100%)`, colorStartPrimary: changeColor(primaryColor, { alpha: 0.6 }),
backgroundImageWarning: ` linear-gradient(252deg, ${changeColor(warningColor, { alpha: 0.6 })} 0%, ${warningColor} 100%)`, colorEndPrimary: primaryColor,
backgroundImageError: `linear-gradient(252deg, ${changeColor(errorColor, { alpha: 0.6 })} 0%, ${errorColor} 100%)`, colorStartInfo: changeColor(infoColor, { alpha: 0.6 }),
backgroundImageInfo: `linear-gradient(252deg, ${changeColor(infoColor, { alpha: 0.6 })} 0%, ${infoColor} 100%)` colorEndInfo: infoColor,
colorStartWarning: changeColor(warningColor, { alpha: 0.6 }),
colorEndWarning: warningColor,
colorStartError: changeColor(errorColor, { alpha: 0.6 }),
colorEndError: errorColor,
colorStartSuccess: changeColor(successColor, { alpha: 0.6 }),
colorEndSuccess: successColor
} }
} }
}) })