Skip to content

fix: Background color of the Card component #385 #386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/FwbCard/FwbCard.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<component
:is="wrapperType"
:class="cardClasses"
:class="[cardClasses, props.class]"
:href="href"
>
<img
Expand Down Expand Up @@ -41,6 +41,10 @@ const props = defineProps({
type: String as PropType<CardsVariant>,
default: 'default',
},
class: {
type: String,
default: '',
},
})

const { cardClasses, horizontalImageClasses } = useCardsClasses(toRefs(props))
Expand Down
16 changes: 10 additions & 6 deletions src/components/FwbCard/composables/useCardClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
export type UseCardsClassesProps = {
variant: Ref<CardsVariant>
href?: Ref<string>
class?: Ref<string>
}

export function useCardsClasses (props: UseCardsClassesProps): {
Expand All @@ -13,17 +14,20 @@
} {
const cardClasses = computed(() => {
let computedClasses = ''

Check failure on line 17 in src/components/FwbCard/composables/useCardClasses.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

Trailing spaces not allowed
if (props.variant.value === 'image') {
computedClasses = 'max-w-sm bg-white rounded-lg border border-gray-200 shadow-md dark:bg-gray-800 dark:border-gray-700'
computedClasses = 'max-w-sm rounded-lg border border-gray-200 shadow-md dark:border-gray-700'
} else if (props.variant.value === 'default') {
computedClasses = 'block max-w-sm rounded-lg border border-gray-200 shadow-md dark:border-gray-700'
} else if (props.variant.value === 'horizontal') {
computedClasses = 'flex flex-col items-center rounded-lg border shadow-md md:flex-row md:max-w-xl dark:border-gray-700'
}

if (props.variant.value === 'default') {
computedClasses = 'block max-w-sm bg-white rounded-lg border border-gray-200 shadow-md dark:bg-gray-800 dark:border-gray-700 '
} else if (props.variant.value === 'horizontal') {
computedClasses = 'flex flex-col items-center bg-white rounded-lg border shadow-md md:flex-row md:max-w-xl dark:border-gray-700 dark:bg-gray-800'
if (!props.class?.value || (!props.class.value.includes('bg-'))) {
computedClasses += ' bg-white dark:bg-gray-800';

Check failure on line 27 in src/components/FwbCard/composables/useCardClasses.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

Extra semicolon
}

if (props.href?.value) {
if (props.href?.value && !props.class?.value) {
computedClasses += ' hover:bg-gray-100 dark:hover:bg-gray-700'
}

Expand Down
Loading