Skip to content

Commit

Permalink
generic tag and block status tag (#197)
Browse files Browse the repository at this point in the history
* generic tag and block status tag
  • Loading branch information
MauserBitfly authored Apr 15, 2024
1 parent 28fc22a commit 8061afd
Show file tree
Hide file tree
Showing 10 changed files with 256 additions and 7 deletions.
19 changes: 17 additions & 2 deletions frontend/assets/css/colors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
--primary-orange: #ffaa31;
--primary-orange-hover: #ff951a;
--primary-orange-pressed: #ffb346;
--orange-color: var(--light-orange);

--black-transparent-3: rgba(0, 0, 0, 0.3);

Expand Down Expand Up @@ -72,8 +73,17 @@
--link-color: var(--blue);

--negative-color: var(--light-red);
--negative-contrast-color: var(--text-color-inverted);
--positive-color: var(--light-green);
--orange-color: var(--light-orange);
--positive-contrast-color: var(--text-color-inverted);
--partial-color: var(--light-orange);
--partial-contrast-color: var(--text-color-inverted);
--orphaned-color: var(--purple);
--orphaned-contrast-color: var(--text-color-inverted);
--dark-tag-color: var(--graphite);
--dark-tag-contrast-color: var(--light-grey);
--light-tag-color: var(--light-grey-5);
--light-tag-contrast-color: var(--light-black);

--megamenu-panel-color: var(--light-grey);
--megamenu-text-color: var(--grey);
Expand All @@ -89,6 +99,7 @@
--primary-color: var(--primary-orange);
--primary-contrast-color: var(--light-black);
--primary-contrast-color-discreet: var(--dark-grey);
--orange-color: var(--orange);

--scrollbar-thumb-color: var(--light-grey);

Expand Down Expand Up @@ -124,8 +135,12 @@
--link-color: var(--light-blue);

--negative-color: var(--flashy-red);
--negative-contrast-color: var(--text-color);
--positive-color: var(--green);
--orange-color: var(--orange);
--positive-contrast-color: var(--text-color-inverted);
--partial-color: var(--orange);
--partial-contrast-color: var(--text-color);
--light-tag-color: var(--light-grey);

--megamenu-panel-color: var(--graphite);
--megamenu-text-color: var(--grey);
Expand Down
36 changes: 33 additions & 3 deletions frontend/assets/css/utils.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,42 @@
color: var(--negative-color);
}

.mixed {
color: var(--orange);
.partial {
color: var(--partial-color);
}

.orphaned {
color: var(--purple);
color: var(--orphaned-color);
}

@mixin positive-background() {
background-color: var(--positive-color);
color: var(--positive-contrast-color);
}

@mixin negative-background(){
background-color: var(--negative-color);
color: var(--negative-contrast-color);
}

@mixin partial-background() {
background-color: var(--partial-color);
color: var(--partial-contrast-color);
}

@mixin orphaned-background() {
background-color: var(--orphaned-color);
color: var(--orphaned-contrast-color);
}

@mixin dark-tag-background() {
background-color: var(--dark-tag-color);
color: var(--dark-tag-contrast-color);
}

@mixin light-tag-background() {
background-color: var(--light-tag-color);
color: var(--light-tag-contrast-color);
}

.comma {
Expand Down
86 changes: 86 additions & 0 deletions frontend/components/bc/table/BcTableTag.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<script setup lang="ts">
import type { IconDefinition } from '@fortawesome/fontawesome-svg-core'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import type { TagColor, TagSize } from '~/types/tag'
interface Props {
color?: TagColor
size?: TagSize
label?: string,
tooltip?: string
icon?: IconDefinition,
}
defineProps<Props>()
</script>
<template>
<BcTooltip v-if="label || icon" class="tag" :class="[color, size]" :text="tooltip">
{{ label }}
<FontAwesomeIcon v-if="icon" :icon="icon" />
</BcTooltip>
</template>
<style lang="scss" scoped>
@use "~/assets/css/utils.scss";
.tag {
min-width: 80px;
height: 20px;
padding: 0 14px;
display: inline-flex;
justify-content: center;
align-items: center;
border-radius: 10px;
font-size: var(--small_text_font_weight);
font-weight: var(--small_text_bold_font_weight);
cursor: default;
svg {
margin-left: var(--padding-small);
width: 12px;
height: 12px;
}
&.compact {
min-width: unset;
}
&.circle {
min-width: unset;
width: 14px;
height: 14px;
padding: 0;
border-radius: 50%;
font-size: var(--tooltip_text_font_size);
svg {
margin-left: unset;
width: 10px;
height: 10px;
}
}
&.success {
@include utils.positive-background;
}
&.failed {
@include utils.negative-background;
}
&.orphaned {
@include utils.orphaned-background;
}
&.partial {
@include utils.partial-background;
}
&.light {
@include utils.light-tag-background;
}
&.dark {
@include utils.dark-tag-background;
}
}
</style>
48 changes: 48 additions & 0 deletions frontend/components/block/table/BlockTableStatus.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<script setup lang="ts">
import { type BlockStatus } from '~/types/block'
import type { TagSize, TagColor } from '~/types/tag'
interface Props {
status?: BlockStatus,
mobile?: boolean
}
const props = defineProps<Props>()
const { t: $t } = useI18n()
const mapped = computed(() => {
if (!props.status) {
return
}
const size: TagSize = props.mobile ? 'circle' : 'default'
let color: TagColor
const tStatus = $t(`block.status.${props.status}`)
const label = props.mobile ? tStatus.substring(0, 1) : tStatus
const tooltip = props.mobile ? tStatus : undefined
switch (props.status) {
case 'missed':
color = 'failed'
break
case 'success':
color = 'success'
break
case 'orphaned':
color = 'orphaned'
break
case 'scheduled':
color = 'dark'
break
}
return {
size,
color,
label,
tooltip
}
})
</script>
<template>
<BcTableTag v-if="mapped" v-bind="mapped" />
</template>
3 changes: 3 additions & 0 deletions frontend/components/playground/PlaygroundComponents.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<template>
<TabView lazy>
<TabPanel header="Tags">
<PlaygroundTags />
</TabPanel>
<TabPanel header="Duty Status">
<PlaygroundDutyStatus />
</TabPanel>
Expand Down
52 changes: 52 additions & 0 deletions frontend/components/playground/PlaygroundTags.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<script setup lang="ts">
import {
faAnchor,
faTrophy
} from '@fortawesome/pro-solid-svg-icons'
import type { BlockStatus } from '~/types/block'
import { TagColors } from '~/types/tag'
const blockStati: BlockStatus[] = ['missed', 'orphaned', 'scheduled', 'success']
</script>

<template>
<h1>Block table status tags</h1>
<div class="container">
<div v-for="status in blockStati" :key="status" class="item">
<BlockTableStatus :status="status" />
<BlockTableStatus :status="status" :mobile="true" />
</div>
</div>
<h1>Generic tags</h1>
<div class="container">
<div v-for="color in TagColors" :key="color" class="item">
<BcTableTag :color="color" :label="color" />
<BcTableTag :color="color" :label="color" :icon="faAnchor" />
<BcTableTag :color="color" :label="color" size="compact" />
<BcTableTag :color="color" :label="color" size="compact" />
<BcTableTag :color="color" :label="color" :icon="faAnchor" size="compact" />
<BcTableTag :color="color" :label="color.substring(0,2)" size="circle" :tooltip="color" />
<BcTableTag :color="color" :icon="faAnchor" size="circle" :tooltip="color" />
</div>
</div>
<h1>Custom colors</h1>
<div class="container">
<div class="item">
<BcTableTag label="this is gold" :icon="faTrophy" :style="{'background-color': 'gold', 'color': 'silver'}" tooltip="we can also set custom colors on our tags!" />
</div>
</div>
</template>
<style lang="scss" scoped>
.container{
display: flex;
flex-wrap: wrap;
.item{
flex-grow: 0;
margin: 10px;
display: flex;
align-items: center;
gap: 5px;
}
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const mapped = computed(() => {
className = 'positive'
break
case 'partial':
className = 'mixed'
className = 'partial'
break
case 'failed':
className = 'negative'
Expand Down
10 changes: 9 additions & 1 deletion frontend/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"average": "Average",
"index": "Index",
"edit": "Edit",
"true": "True",
"true": "True",
"false": "False"
},
"clipboard": {
Expand Down Expand Up @@ -78,6 +78,14 @@
"total": "All Time",
"all": "All Time"
},
"block": {
"status": {
"missed": "Missed",
"orphaned": "Orphaned",
"scheduled": "Scheduled",
"success": "Proposed"
}
},
"slotViz": {
"head": "Head",
"tooltip": {
Expand Down
3 changes: 3 additions & 0 deletions frontend/types/block/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { VDBBlocksTableRow } from '../api/validator_dashboard'

export type BlockStatus = VDBBlocksTableRow['status']
4 changes: 4 additions & 0 deletions frontend/types/tag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const TagColors = ['success', 'failed', 'orphaned', 'partial', 'light', 'dark'] as const
export type TagColor = typeof TagColors[number]

export type TagSize = 'default' | 'compact' | 'circle'

0 comments on commit 8061afd

Please sign in to comment.