Skip to content

Commit

Permalink
Add Badges (Fixes #10) (PR #15)
Browse files Browse the repository at this point in the history
* Add badges

* undo hard coded hex color

* separate expiry badge

* remove un-needed type
  • Loading branch information
micahilbery authored Dec 3, 2024
1 parent 15d3b9e commit 729c3ee
Show file tree
Hide file tree
Showing 18 changed files with 295 additions and 107 deletions.
13 changes: 13 additions & 0 deletions src/assets/styles/colours.css
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,19 @@ html {
--colour-send-primary-accent-2: #1F8DDB;
}

/*
* Brand Colours
* Thunderbird
* The fallback if no service is set.
*/
--colour-service-soft: var(--colour-primary-soft);
--colour-service-primary: var(--colour-primary-default);
--colour-service-primary-hover: var(--colour-primary-hover);
--colour-service-primary-pressed: var(--colour-primary-pressed);
--colour-service-secondary: var(--colour-secondary-default);
--colour-service-accent-1: var(--colour-accent-purple);
--colour-service-accent-2: var(--colour-accent-teal);

&[data-tbpro-service='apmt'] {
--colour-service-soft: var(--colour-apmt-soft);
--colour-service-primary: var(--colour-apmt-primary);
Expand Down
File renamed without changes
6 changes: 6 additions & 0 deletions src/assets/svg/icons/status-info.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/assets/svg/icons/status-warning.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions src/elements/BaseBadge.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import type { Meta, StoryObj } from '@storybook/vue3';

import BaseBadge from "@/elements/BaseBadge.vue";

// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
const meta: Meta<typeof BaseBadge> = {
title: "Elements/Badge",
component: BaseBadge,
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/writing-docs/autodocs
tags: ["autodocs"],
argTypes: {
type: { control: "select", options: ["primary", "secondary", "warning"] },
icon: { control: "boolean" },
default: { control: "text" },
},
args: {
default: "Recommended",
},
};

export default meta;
type Story = StoryObj<typeof meta>;

export const Default: Story = {
args: {
type: "primary",
icon: false,
},
};

export const Secondary: Story = {
args: {
type: "secondary",
icon: false,
default: "Updated",
},
};

export const Warning: Story = {
args: {
type: "warning",
icon: false,
default: "Experimental"
},
};

export const IconPrimary: Story = {
args: {
type: "primary",
icon: true,
},
};

export const IconSecondary: Story = {
args: {
type: "secondary",
icon: true,
default: "Updated",
},
};

export const IconWarning: Story = {
args: {
type: "warning",
icon: true,
default: "Experimental",
},
};
75 changes: 75 additions & 0 deletions src/elements/BaseBadge.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<script setup lang="ts">
import StatusInfoIcon from '@/icons/StatusInfoIcon.vue';
import StatusWarningIcon from '@/icons/StatusWarningIcon.vue';
// component properties
interface Props {
type?: string;
icon?: boolean;
}
withDefaults(defineProps<Props>(), {
type: "primary",
icon: false,
})
</script>

<template>
<div :class="{ [type]: type }" class="badge">
<span class="icon" v-if="icon">
<slot name="icon">
<status-info-icon v-if="type == 'primary' || type == 'secondary'"/>
<status-warning-icon v-if="type == 'warning'"/>
</slot>
</span>
<span class="text">
<slot/>
</span>
</div>
</template>

<style scoped>
@import '@/assets/styles/custom-media.pcss';
.icon {
margin-top: auto;
margin-bottom: auto;
}
.text {
margin: auto;
font-size: 0.8125rem;
font-weight: 700;
line-height: 1.2;
text-transform: uppercase;
}
.badge {
position: relative;
display: inline-flex;
justify-content: center;
align-items: center;
border-radius: 0.1875rem;
gap: 0.3125rem;
border: 0.0625rem solid;
padding: 0.140625rem 0.28125rem;
}
.primary {
background-color: var(--colour-primary-soft);
border-color: var(--colour-service-primary-hover);
color: var(--colour-service-primary-hover);
}
.secondary {
background-color: var(--colour-neutral-subtle);
border-color: var(--colour-ti-secondary);
color: var(--colour-ti-secondary);
}
.warning {
background-color: var(--colour-warning-soft);
border-color: var(--colour-ti-warning);
color: var(--colour-ti-warning);
}
</style>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { Meta, StoryObj } from '@storybook/vue3';
import ExpiryIndicator from "@/elements/ExpiryIndicator.vue";
import ExpiryBadge from "@/elements/ExpiryBadge.vue";
import { ExpiryUnitTypes } from "@/definitions";

// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
const meta: Meta<typeof ExpiryIndicator> = {
title: "Elements/ExpiryIndicator",
component: ExpiryIndicator,
const meta: Meta<typeof ExpiryBadge> = {
title: "Elements/ExpiryBadge",
component: ExpiryBadge,
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/writing-docs/autodocs
tags: ["autodocs"],
args: {
Expand All @@ -18,7 +18,7 @@ const meta: Meta<typeof ExpiryIndicator> = {
export default meta;
type Story = StoryObj<typeof meta>;

export const Info: Story = {
export const Default: Story = {
args: {
timeRemaining: 10,
timeUnit: ExpiryUnitTypes.Years,
Expand Down
42 changes: 42 additions & 0 deletions src/elements/ExpiryBadge.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<script setup lang="ts">
import BaseBadge from "./BaseBadge.vue";
import StatusExpiryIcon from "@/icons/StatusExpiryIcon.vue";
import { computed, toRef } from "vue";
import { t } from '@/composable/i18n';
import { ExpiryUnitTypes } from "@/definitions";
// component properties
interface Props {
timeRemaining?: number;
warningThreshold?: number;
timeUnit?: ExpiryUnitTypes;
}
const props = withDefaults(defineProps<Props>(), {
timeRemaining: 10,
warningThreshold: 5,
timeUnit: ExpiryUnitTypes.Days
})
const timeRemaining = toRef(() => props.timeRemaining);
const warningThreshold = toRef(() => props.warningThreshold);
const timeRemainingLabel = computed(() => timeRemaining.value.toString());
const status = computed(() => {
if (timeRemaining.value <= 0) {
return "secondary";
} else if (timeRemaining.value < warningThreshold.value) {
return "warning";
} else {
return "primary";
}
});
</script>

<template>
<base-badge :class="status" icon>
<template #icon>
<status-expiry-icon/>
</template>
{{ t(`expiryIndicator.${timeUnit}`, { 'n': timeRemainingLabel }) }}
</base-badge>
</template>
89 changes: 0 additions & 89 deletions src/elements/ExpiryIndicator.vue

This file was deleted.

9 changes: 9 additions & 0 deletions src/elements/PrimaryBadge.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script setup lang="ts">
import BaseBadge from '@/elements/BaseBadge.vue';
</script>

<template>
<base-badge type="primary">
<slot/>
</base-badge>
</template>
9 changes: 9 additions & 0 deletions src/elements/SecondaryBadge.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script setup lang="ts">
import BaseBadge from '@/elements/BaseBadge.vue';
</script>

<template>
<base-badge type="secondary">
<slot/>
</base-badge>
</template>
9 changes: 9 additions & 0 deletions src/elements/WarningBadge.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script setup lang="ts">
import BaseBadge from '@/elements/BaseBadge.vue';
</script>

<template>
<base-badge type="warning">
<slot/>
</base-badge>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { t } from '@/composable/i18n';
</script>

<template>
<svg :aria-label="t('expiryIcon.fileExpires')" width="11" height="11" viewBox="0 0 11 11" fill="none" xmlns="http://www.w3.org/2000/svg">
<svg :aria-label="t('icons.expires')" width="11" height="11" viewBox="0 0 11 11" fill="none" xmlns="http://www.w3.org/2000/svg">
<g id="icon">
<path opacity="0.2" d="M10.5 5.5C10.5 8.26142 8.26142 10.5 5.5 10.5C2.73858 10.5 0.5 8.26142 0.5 5.5C0.5 2.73858 2.73858 0.5 5.5 0.5C8.26142 0.5 10.5 2.73858 10.5 5.5Z" fill="currentColor"/>
<path d="M5.5 0C2.46839 0 0 2.46836 0 5.5C0 7.29555 0.86526 8.89387 2.20117 9.8984C2.20311 9.9004 2.20506 9.9023 2.20703 9.9043L2.21094 9.9062C3.12888 10.5933 4.26841 11 5.5 11C6.73159 11 7.87112 10.5933 8.78906 9.9062C8.7924 9.9043 8.79549 9.9014 8.79883 9.8984C10.1347 8.89387 11 7.29555 11 5.5C11 2.46836 8.53161 0 5.5 0ZM5.5 1C5.57361 1.00015 5.64719 1.00186 5.7207 1.00586C5.72458 1.00604 5.72855 1.00566 5.73242 1.00586C5.80219 1.00986 5.87188 1.01488 5.94141 1.02148C5.94791 1.02211 5.95445 1.02224 5.96094 1.02344C6.10047 1.03754 6.23764 1.05944 6.37305 1.08594H6.37695C6.38737 1.08794 6.39782 1.0898 6.4082 1.0918C6.69047 1.1493 6.96253 1.23432 7.22266 1.3418C8.32443 1.79703 9.20297 2.67556 9.6582 3.77734C9.7657 4.03747 9.8507 4.30953 9.9082 4.5918C9.9102 4.6022 9.9121 4.61265 9.9141 4.62305V4.62695C9.9405 4.76237 9.9625 4.89953 9.9766 5.03906C9.9772 5.04606 9.9779 5.05209 9.9785 5.05859C9.9852 5.12799 9.9906 5.1973 9.9941 5.26758C9.9981 5.34498 10 5.42249 10 5.5C10 5.71478 9.9839 5.92616 9.9551 6.13281V6.13477V6.13672V6.13867V6.14062C9.9546 6.14362 9.9536 6.14639 9.9531 6.15039C9.9228 6.36147 9.8768 6.56714 9.8184 6.76758C9.6483 7.351 9.36553 7.88534 8.99219 8.34375C8.99163 8.33875 8.99084 8.33333 8.99023 8.32812C8.70742 8.6741 8.37367 8.98486 8 9.23633V9.24414C7.97846 9.25854 7.95539 9.27116 7.93359 9.28516C7.75744 9.39839 7.57283 9.49959 7.38086 9.5879C7.37056 9.5929 7.35995 9.5969 7.34961 9.6016C7.16401 9.6853 6.97347 9.7581 6.77539 9.8164C6.7677 9.8184 6.75966 9.8203 6.75195 9.8223C6.55703 9.8785 6.35728 9.9235 6.15234 9.9531C6.13738 9.9541 6.1224 9.956 6.10742 9.957C5.90877 9.9837 5.7061 10 5.5 10C5.2939 10 5.09123 9.9838 4.89258 9.957C4.8776 9.956 4.86262 9.9541 4.84766 9.9531C4.64272 9.9234 4.44297 9.8785 4.24805 9.8223C4.24023 9.8203 4.23241 9.8184 4.22461 9.8164C4.02653 9.7581 3.83599 9.6852 3.65039 9.6016C3.63996 9.5966 3.62954 9.5926 3.61914 9.5879C3.42717 9.49959 3.24256 9.39839 3.06641 9.28516C3.04461 9.27116 3.02154 9.25854 3 9.24414V9.23633C2.62633 8.98486 2.29253 8.67871 2.00977 8.32812C2.00916 8.33313 2.00836 8.33855 2.00781 8.34375C1.63447 7.88534 1.35165 7.351 1.18164 6.76758C1.12323 6.56714 1.07721 6.36147 1.04688 6.15039C1.04621 6.14439 1.04556 6.13871 1.04492 6.13281C1.01601 5.92646 1 5.71478 1 5.5C1 5.28389 1.01568 5.07114 1.04492 4.86328V4.85742C1.07531 4.64334 1.12237 4.43557 1.18164 4.23242C1.2421 4.02517 1.31803 3.82443 1.40625 3.63086C1.84358 2.67127 2.60666 1.89553 3.55664 1.44141C3.58126 1.42961 3.60599 1.41765 3.63086 1.40625C3.82443 1.31805 4.02518 1.2421 4.23242 1.18164C4.43557 1.12234 4.64334 1.07532 4.85742 1.04492H4.86328C5.07113 1.01572 5.28389 1 5.5 1ZM5.5 2C5.223 2 5 2.223 5 2.5V5.5C5 5.53462 5.00313 5.56896 5.00977 5.60156C5.0164 5.63417 5.02645 5.66538 5.03906 5.69531C5.05168 5.72524 5.068 5.75271 5.08594 5.7793C5.10387 5.80589 5.12389 5.83092 5.14648 5.85352C5.16908 5.87611 5.19411 5.89613 5.2207 5.91406C5.24729 5.932 5.27476 5.94832 5.30469 5.96094C5.33462 5.97355 5.36583 5.9836 5.39844 5.99023C5.43105 5.99687 5.46537 6 5.5 6H8.5C8.77614 6 9 5.77614 9 5.5C9 5.22386 8.77614 5 8.5 5H6V2.5C6 2.223 5.777 2 5.5 2Z" fill="currentColor"/>
Expand Down
Loading

0 comments on commit 729c3ee

Please sign in to comment.