-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from qianmoQ/feature-dev
[Components] Add `card`, `button`
- Loading branch information
Showing
12 changed files
with
391 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<template> | ||
<Button :class="cn(computedSize, | ||
`bg-[${computedType}] hover:bg-[${calculateHoverColor(computedType)}]`, | ||
{ 'rounded-full': round }, | ||
{ 'rounded-full': circle })" | ||
:size="circle ? 'icon' : 'default'" | ||
:style="{backgroundColor: color}"> | ||
<span :class="cn({'animate-spin mr-1.5': (loading || $slots.loading)})"> | ||
<slot v-if="!$slots.icon && $slots.loading" name="loading"/> | ||
<Loader2 v-else-if="loading"/> | ||
</span> | ||
|
||
<span v-if="$slots.icon" :class="cn({'mr-1.5': (text || $slots.default)})"> | ||
<slot name="icon"/> | ||
</span> | ||
|
||
<span> | ||
<span v-if="text">{{ text }}</span> | ||
<slot v-else/> | ||
</span> | ||
</Button> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, ref, watchEffect } from 'vue' | ||
import { Size } from '@/ui/enum/Size.ts' | ||
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', | ||
components: { | ||
Button, | ||
Loader2 | ||
}, | ||
props: { | ||
text: { | ||
type: String | ||
}, | ||
size: { | ||
type: String, | ||
default: 'default' | ||
}, | ||
type: { | ||
type: String, | ||
default: 'primary' | ||
}, | ||
round: { | ||
type: Boolean, | ||
default: false | ||
}, | ||
circle: { | ||
type: Boolean, | ||
default: false | ||
}, | ||
loading: { | ||
type: Boolean, | ||
default: false | ||
}, | ||
color: { | ||
type: String | ||
} | ||
}, | ||
setup(props) | ||
{ | ||
const computedSize = ref<string>('default') | ||
const computedType = ref<string>('primary') | ||
watchEffect(() => { | ||
computedSize.value = Size[props.size as keyof typeof Size] | ||
computedType.value = Type[props.type as keyof typeof Type] | ||
}) | ||
return { | ||
cn, | ||
calculateHoverColor, | ||
computedSize, | ||
computedType | ||
} | ||
} | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<template> | ||
<Card :class="cn('rounded-sm', computedShadow)"> | ||
<CardHeader v-if="$slots.title || title" :class="`flex flex-row items-center justify-between border-b p-4 ${titleClass}`"> | ||
<div class="grid gap-2"> | ||
<CardTitle> | ||
<span v-if="title">{{ title }}</span> | ||
<slot v-else name="title"/> | ||
</CardTitle> | ||
</div> | ||
<div> | ||
<slot name="extra"/> | ||
</div> | ||
</CardHeader> | ||
<CardContent :class="`${bodyClass}`"> | ||
<slot/> | ||
</CardContent> | ||
<CardFooter class="border-t p-4" v-if="$slots.footer"> | ||
<slot name="footer"/> | ||
</CardFooter> | ||
</Card> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, ref, watchEffect } from 'vue' | ||
import { Card, CardContent, CardFooter, CardHeader, CardTitle } from '@/components/ui/card' | ||
import { cn } from '@/lib/utils.ts' | ||
import { Shadow } from '@/ui/enum/Shadow.ts' | ||
export default defineComponent({ | ||
name: 'ICard', | ||
components: { | ||
CardFooter, Card, CardContent, CardHeader, CardTitle | ||
}, | ||
props: { | ||
title: { | ||
type: String | ||
}, | ||
titleClass: { | ||
type: String | ||
}, | ||
bodyClass: { | ||
type: String | ||
}, | ||
shadow: { | ||
type: String, | ||
default: 'never' | ||
} | ||
}, | ||
setup(props) | ||
{ | ||
const computedShadow = ref<string>('never') | ||
watchEffect(() => { | ||
computedShadow.value = Shadow[props.shadow as keyof typeof Shadow] | ||
}) | ||
return { | ||
cn, | ||
computedShadow | ||
} | ||
} | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export enum Shadow | ||
{ | ||
never = 'shadow-background', | ||
always = 'shadow-2xl', | ||
hover = 'hover:shadow-2xl', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export enum Size | ||
{ | ||
default = 'h-8', | ||
small = 'h-6', | ||
large = 'h-10' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export enum Type | ||
{ | ||
primary = '#409EFF', | ||
success = '#67C23A', | ||
warning = '#E6A23C', | ||
danger = '#F56C6C', | ||
info = '#909399', | ||
text = '#606266' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.