🎨 (account card) add gradient

This commit is contained in:
Julien Calixte
2020-03-15 17:57:53 +01:00
parent 40f7d02e5b
commit 2e91720e29
4 changed files with 21 additions and 3 deletions

View File

@@ -2,7 +2,7 @@
<div <div
class="account-card box" class="account-card box"
:style="getColor(account.color)" :style="getColor(account.color)"
@click="goToAccount(account._id)" @click="goToAccount(account._id || '')"
> >
<router-link <router-link
:class="{ 'is-primary': !account.color, 'is-white': account.color }" :class="{ 'is-primary': !account.color, 'is-white': account.color }"
@@ -22,7 +22,7 @@
<script lang="ts"> <script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator' import { Component, Prop, Vue } from 'vue-property-decorator'
import { findContrastColor, findDarkValue } from '@/utils' import { findContrastColor, findDarkValue, findSlightLightValue } from '@/utils'
import bus, { SYNC } from '@/utils/bus-event' import bus, { SYNC } from '@/utils/bus-event'
import accountService from '@/services/AccountService' import accountService from '@/services/AccountService'
import IAccount from '@/models/IAccount' import IAccount from '@/models/IAccount'
@@ -33,6 +33,8 @@ import transactionService from '../services/TransactionService'
import TransactionType from '../enums/TransactionType' import TransactionType from '../enums/TransactionType'
import colors from '../data/colors' import colors from '../data/colors'
const GRADIENT = true
@Component @Component
export default class AccountCard extends Vue { export default class AccountCard extends Vue {
@Prop({ type: Object, required: true }) @Prop({ type: Object, required: true })
@@ -57,8 +59,11 @@ export default class AccountCard extends Vue {
if (!color) { if (!color) {
return null return null
} }
return { return {
backgroundColor: color, background: GRADIENT
? `linear-gradient(45deg, ${color}, ${findSlightLightValue(color)})`
: color,
color: this.findContrastColor(color) color: this.findContrastColor(color)
} }
} }

View File

@@ -74,10 +74,12 @@ export default [
(color: IColor): IColor => { (color: IColor): IColor => {
const darkValue = lightness(color.value, dark).toLowerCase() const darkValue = lightness(color.value, dark).toLowerCase()
const lightValue = lightness(color.value, light).toLowerCase() const lightValue = lightness(color.value, light).toLowerCase()
const slightLightValue = lightness(color.value, 10).toLowerCase()
return { return {
...color, ...color,
darkValue, darkValue,
lightValue, lightValue,
slightLightValue,
constrastColor: constrastColor:
fontColorContrast(color.value) === '#000000' ? darkValue : lightValue fontColorContrast(color.value) === '#000000' ? darkValue : lightValue
} }

View File

@@ -3,5 +3,6 @@ export default interface IColor {
value: string | null value: string | null
darkValue?: string | null darkValue?: string | null
lightValue?: string | null lightValue?: string | null
slightLightValue?: string | null
constrastColor?: string | null constrastColor?: string | null
} }

View File

@@ -70,6 +70,16 @@ export const findLightValue = (value: string): string | null => {
return find && find.lightValue ? find.lightValue : null return find && find.lightValue ? find.lightValue : null
} }
export const findSlightLightValue = (value: string): string | null => {
if (!value) {
return null
}
const find: IColor | undefined = colors.find(
(color: IColor) => color.value === value
)
return find && find.slightLightValue ? find.slightLightValue : null
}
export const toHex = (text: string): string => { export const toHex = (text: string): string => {
return ( return (
[...text] [...text]