Skip to content

Commit

Permalink
Improve figure widget
Browse files Browse the repository at this point in the history
  • Loading branch information
aguingand committed Jul 17, 2023
1 parent 226548b commit e0502b0
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 31 deletions.
7 changes: 5 additions & 2 deletions packages/dashboard/scss/_page.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@

.dashboard {
.SharpDashboardPage {
.row+.row {
margin-top: 1rem;
.SharpGrid > * {
margin-bottom: 1rem;
&:last-child {
margin-bottom: 0;
}
}
}
}
2 changes: 1 addition & 1 deletion packages/dashboard/scss/components/_Widget.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
text-align: center;
border-width: 0;

&--link {
&--panel.SharpWidget--link {
border: 1px solid transparent;
text-decoration: none;
transition: $btn-transition;
Expand Down
2 changes: 1 addition & 1 deletion packages/dashboard/src/components/Section.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</template>
</div>

<Grid :rows="section.rows" row-class="gx-3" v-slot="{ itemLayout }">
<Grid :rows="section.rows" row-class="g-3" v-slot="{ itemLayout }">
<slot :widget-layout="itemLayout" />
</Grid>
</div>
Expand Down
20 changes: 8 additions & 12 deletions packages/dashboard/src/components/Widget.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<template>
<component :is="tag" class="SharpWidget card" :class="classes" :href="widgetProps.link">
<div class="SharpWidget card" :class="classes" :href="widgetProps.link">
<div class="card-body">
<component :is="widgetComp" v-bind="exposedProps"></component>
<component
:is="widgetComp"
:value="value"
v-bind="widgetProps"
/>
</div>
</component>
</div>
</template>
<script>
import { widgetByType } from './widgets/index';
Expand All @@ -21,21 +25,13 @@
classes() {
return {
'SharpWidget--chart': this.widgetType === 'graph',
'SharpWidget--panel': this.widgetType === 'panel',
'SharpWidget--link': this.widgetProps.link,
}
},
tag() {
return this.widgetProps.link ? 'a' : 'div';
},
widgetComp() {
return widgetByType(this.widgetType, this.widgetProps.display);
},
exposedProps() {
return { ...this.widgetProps, value:this.value }
},
hasLink() {
return !!this.widgetProps.link;
}
},
}
</script>
41 changes: 30 additions & 11 deletions packages/dashboard/src/components/widgets/Figure.vue
Original file line number Diff line number Diff line change
@@ -1,41 +1,60 @@
<template>
<div>
<h2 class="SharpWidget__title mb-3">
{{ title }}
</h2>
<template v-if="title">
<h2 class="SharpWidget__title mb-2">
{{ title }}
</h2>
</template>
<div class="d-flex align-items-center">
<p class="display-4 fw-bold mb-0" :style="{ color: value.data.color }">
<p class="display-5 fw-bold mb-0" :style="{ color: value.data.color }">
{{ value.data.figure }}
<template v-if="value.data.unit">
<span class="fs-4 fw-normal">{{ value.data.unit }}</span>
<span class="fs-5 fw-normal">{{ value.data.unit }}</span>
</template>
</p>
<template v-if="value.data.evolution">
<div class="ms-3" :class="value.data.evolution.increase ? 'text-success' : 'text-danger'">
<div class="d-flex align-items-center ms-3"
:style="{ color: value.data.evolution.increase ? '#198754' : '#dc3545' }"
>
<template v-if="value.data.evolution.increase">
&uarr;
<!-- heroicons: 20/solid/arrow-up -->
<svg width="20" height="20" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M10 17a.75.75 0 01-.75-.75V5.612L5.29 9.77a.75.75 0 01-1.08-1.04l5.25-5.5a.75.75 0 011.08 0l5.25 5.5a.75.75 0 11-1.08 1.04l-3.96-4.158V16.25A.75.75 0 0110 17z" clip-rule="evenodd" />
</svg>
</template>
<template v-else>
&darr;
<!-- heroicons: 20/solid/arrow-down -->
<svg width="20" height="20" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M10 3a.75.75 0 01.75.75v10.638l3.96-4.158a.75.75 0 111.08 1.04l-5.25 5.5a.75.75 0 01-1.08 0l-5.25-5.5a.75.75 0 111.08-1.04l3.96 4.158V3.75A.75.75 0 0110 3z" clip-rule="evenodd" />
</svg>
</template>
{{ value.data.evolution.value }}
<span class="ms-1">
{{ value.data.evolution.value }}
</span>
</div>
</template>
</div>
<template v-if="link">
<div class="text-start mt-2">
See details
<a :href="link">
{{ lang('dashboard.widget.link_label') }}
</a>
</div>
</template>
</div>
</template>

<script>
import { lang } from "sharp";
export default {
props: {
title: String,
link: String,
value: Object,
}
},
methods: {
lang,
},
}
</script>
25 changes: 22 additions & 3 deletions packages/dashboard/src/components/widgets/Panel.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
<template>
<div class="SharpWidgetPanel">
<template v-if="title">
<h2 class="SharpWidget__title mb-2">
{{ title }}
</h2>
</template>
<TemplateRenderer name="WidgetPanel" :template="template" :template-data="value.data" />
<template v-if="link">
<a class="stretched-link" :href="link">
<span class="visually-hidden">
{{ lang('dashboard.widget.link_label') }}
</span>
</a>
</template>
</div>
</template>

<script>
import { TemplateRenderer } from 'sharp/components';
import { lang } from "sharp";
export default {
name:'SharpWidgetPanel',
name: 'SharpWidgetPanel',
inheritAttrs: false,
components: {
TemplateRenderer
},
props: {
value: Object,
title: String,
template: String,
}
link: String,
},
methods: {
lang,
},
}
</script>
</script>
4 changes: 3 additions & 1 deletion packages/dashboard/src/components/widgets/chart/Chart.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<template>
<div>
<template v-if="title">
<h2 class="SharpWidget__title mb-2 mt-3 px-3">{{title}}</h2>
<h2 class="SharpWidget__title mb-2 mt-3 px-3">
{{ title }}
</h2>
</template>
<component
:is="chartComp"
Expand Down
1 change: 1 addition & 0 deletions resources/lang/front/en/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

return [
'commands.dashboard.label' => 'Actions',
'widget.link_label' => 'See details',
];
1 change: 1 addition & 0 deletions resources/lang/front/fr/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

return [
'commands.dashboard.label' => 'Actions',
'widget.link_label' => 'See details',
];

0 comments on commit e0502b0

Please sign in to comment.