-
Notifications
You must be signed in to change notification settings - Fork 25
feat: Oc card component #1172
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
Merged
Merged
feat: Oc card component #1172
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
127 changes: 127 additions & 0 deletions
127
packages/design-system/src/components/OcCard/OcCard.vue
This file contains hidden or 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,127 @@ | ||
| <template> | ||
| <component :is="tag" class="oc-card"> | ||
| <div v-if="hasSlotHeader" class="oc-card-header" :class="headerClass"> | ||
| <slot name="header"> | ||
| <img | ||
| v-if="logoUrl" | ||
| :src="logoUrl" | ||
| alt="" | ||
| :aria-hidden="true" | ||
| class="max-w-48 max-h-48 absolute -translate-y-16" | ||
| /> | ||
| <component :is="titleTag" v-if="title" class="mt-0"> | ||
| {{ title }} | ||
| </component> | ||
| </slot> | ||
| </div> | ||
| <div class="oc-card-body" :class="bodyClass"> | ||
| <slot /> | ||
| </div> | ||
| <div v-if="hasSlotFooter" class="oc-card-footer" :class="footerClass"> | ||
| <slot name="footer" /> | ||
| </div> | ||
| </component> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import { computed, unref } from 'vue' | ||
|
|
||
| export interface Props { | ||
| /** | ||
| * @docs The html tag being used to render this card. | ||
| * @default 'div' | ||
| */ | ||
| tag?: string | ||
| /** | ||
| * @docs The title for the default card header. Don't provide one if you fill the 'header' slot yourself. | ||
| */ | ||
| title?: string | ||
| /** | ||
| * @docs The html tag being used to render the title of this card. | ||
| * @default 'h2' | ||
| */ | ||
| titleTag?: string | ||
| /** | ||
| * @docs The url of the logo to be rendered in the header of this card. | ||
| * @default '' | ||
| */ | ||
| logoUrl?: string | ||
| /** | ||
| * @docs The classes to be applied on the card header | ||
| * @default '' | ||
| */ | ||
| headerClass?: string | string[] | Record<string, boolean> | Record<string, boolean>[] | ||
| /** | ||
| * @docs The classes to be applied on the card body. | ||
| * @default '' | ||
| */ | ||
| bodyClass?: string | string[] | Record<string, boolean> | Record<string, boolean>[] | ||
| /** | ||
| * @docs The classes to be applied on the card footer. | ||
| * @default '' | ||
| */ | ||
| footerClass?: string | string[] | Record<string, boolean> | Record<string, boolean>[] | ||
| } | ||
|
|
||
| export interface Slots { | ||
| /** | ||
| * @docs Content of the card. | ||
| */ | ||
| default?: () => unknown | ||
| /** | ||
| * @docs Content of the header. By default, this is filled with a `<h2>` tag which renders the title. | ||
| */ | ||
| header?: () => unknown | ||
| /** | ||
| * @docs Content of the footer. Empty by default. | ||
| */ | ||
| footer?: () => unknown | ||
| } | ||
|
|
||
| const { | ||
| tag = 'div', | ||
| title, | ||
| titleTag = 'h2', | ||
| logoUrl = '', | ||
| headerClass = '', | ||
| bodyClass = '', | ||
| footerClass = '' | ||
| } = defineProps<Props>() | ||
|
|
||
| const slots = defineSlots<Slots>() | ||
|
|
||
| const hasSlotHeader = computed(() => { | ||
| return Object.hasOwn(slots, 'header') || !!unref(title) || !!unref(logoUrl) | ||
| }) | ||
| const hasSlotFooter = computed(() => { | ||
| return Object.hasOwn(slots, 'footer') | ||
| }) | ||
| </script> | ||
|
|
||
| <style> | ||
| @reference "@opencloud-eu/design-system/tailwind"; | ||
|
|
||
| @layer components { | ||
| .oc-card { | ||
| @apply bg-role-surface text-role-on-surface rounded-sm relative; | ||
| } | ||
|
|
||
| .oc-card-header { | ||
| @apply p-4 pb-0 flex flex-col items-center relative; | ||
| } | ||
|
|
||
| .oc-card-body { | ||
| @apply p-4 flow-root; | ||
| } | ||
|
|
||
| .oc-card-footer { | ||
| @apply p-4 pt-0 flex flex-col items-center text-sm; | ||
| } | ||
|
|
||
| .oc-card-body > :last-child, | ||
| .oc-card-header > :last-child, | ||
| .oc-card-footer > :last-child { | ||
| @apply mb-0; | ||
| } | ||
| } | ||
| </style> |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.