Skip to content

Commit

Permalink
feat(web-core): new Info component
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuRA committed Sep 18, 2024
1 parent 530c30f commit 43ff4bc
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
19 changes: 19 additions & 0 deletions @xen-orchestra/lite/src/stories/web-core/info/ui-info.story.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<template>
<ComponentStory
v-slot="{ properties, settings }"
:params="[
prop('status').enum('info', 'success', 'warning', 'danger').required().preset('info').widget(),
slot(),
setting('defaultSlot').widget(text()).preset('message'),
]"
>
<UiInfo v-bind="properties">{{ settings.defaultSlot }}</UiInfo>
</ComponentStory>
</template>

<script lang="ts" setup>
import ComponentStory from '@/components/component-story/ComponentStory.vue'
import { prop, setting, slot } from '@/libs/story/story-param'
import { text } from '@/libs/story/story-widget'
import UiInfo from '@core/components/info/UiInfo.vue'
</script>
51 changes: 51 additions & 0 deletions @xen-orchestra/web-core/lib/components/info/UiInfo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!-- v2 -->
<template>
<div class="vts-ui-info">
<UiIcon class="icon" :color :icon />
<p class="message"><slot /></p>
</div>
</template>

<script lang="ts" setup>
import UiIcon from '@core/components/icon/UiIcon.vue'
import type { IconColor } from '@core/types/color.type'
import {
faCheckCircle,
faExclamationCircle,
faInfoCircle,
faXmarkCircle,
type IconDefinition,
} from '@fortawesome/free-solid-svg-icons'
import { computed } from 'vue'

type Props = {
status: 'info' | 'success' | 'warning' | 'danger'
}
const props = defineProps<Props>()

const states: Record<Props['status'], { icon: IconDefinition; color: IconColor }> = {
info: { icon: faInfoCircle, color: 'normal' },
success: { icon: faCheckCircle, color: 'success' },
warning: { icon: faExclamationCircle, color: 'warning' },
danger: { icon: faXmarkCircle, color: 'danger' },
}

const icon = computed(() => states[props.status].icon)
const color = computed(() => states[props.status].color)
</script>

<style lang="postcss" scoped>
.vts-ui-info {
align-items: center;
display: flex;
gap: 0.8rem;
}

.icon {
font-size: 1.6rem;
}

.message {
font-size: 1.2rem;
}
</style>

0 comments on commit 43ff4bc

Please sign in to comment.