Skip to content

Commit

Permalink
[Components] [Button] Support calculation of hover color
Browse files Browse the repository at this point in the history
  • Loading branch information
qianmoQ committed Apr 11, 2024
1 parent 0457f80 commit 7d0d9ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ui/button/button.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<Button :class="cn(computedSize,
`bg-[${computedType}]`,
`bg-[${computedType}] hover:bg-[${calculateHoverColor(computedType)}]`,
{ 'rounded-full': round },
{ 'rounded-full': circle })"
:size="circle ? 'icon' : 'default'"
Expand Down Expand Up @@ -28,6 +28,7 @@ import { Button } from '@/components/ui/button'
import { Type } from '@/ui/enum/Type.ts'
import { cn } from '@/lib/utils.ts'
import { Loader2 } from 'lucide-vue-next'
import { calculateHoverColor } from '@/utils/Color.ts'
export default defineComponent({
name: 'IButton',
Expand Down Expand Up @@ -75,6 +76,7 @@ export default defineComponent({
return {
cn,
calculateHoverColor,
computedSize,
computedType
}
Expand Down
12 changes: 12 additions & 0 deletions src/utils/Color.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export function calculateHoverColor(color: string): string
{
const hex = color.replace('#', '')
const r = parseInt(hex.substring(0, 2), 16)
const g = parseInt(hex.substring(2, 4), 16)
const b = parseInt(hex.substring(4, 6), 16)
const hoverR = Math.max(0, r - 20)
const hoverG = Math.max(0, g - 20)
const hoverB = Math.max(0, b - 20)
const hoverHex = `#${hoverR.toString(16).padStart(2, '0')}${hoverG.toString(16).padStart(2, '0')}${hoverB.toString(16).padStart(2, '0')}`
return hoverHex
}

0 comments on commit 7d0d9ef

Please sign in to comment.