Skip to content

Commit 887325e

Browse files
Rename capacity to total (#23)
1 parent 0c333d6 commit 887325e

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

src/components/CapacityIndicator/CapacityIndicator.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import CapacityIndicator from "./CapacityIndicator.vue";
66

77
describe("CapacityIndicator", () => {
88
it("shows the remaining capacity", () => {
9-
const wrapper = mount(CapacityIndicator, { props: { capacity: 20, used: 14 } });
9+
const wrapper = mount(CapacityIndicator, { props: { total: 20, used: 14 } });
1010
expect(wrapper.text()).toBe("6");
1111
});
1212

13-
it("shows an icon if the capacity is infinite", () => {
14-
const wrapper = mount(CapacityIndicator, { props: { capacity: Infinity, used: 14 } });
13+
it("shows an icon if the total capacity is infinite", () => {
14+
const wrapper = mount(CapacityIndicator, { props: { total: Infinity, used: 14 } });
1515
expect(wrapper.findComponent(AllInclusiveIcon).isVisible()).toBe(true);
1616
});
1717
});

src/components/CapacityIndicator/CapacityIndicator.stories.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ import type { Meta, StoryFn } from "@storybook/vue3";
55
export default {
66
title: "Components/CapacityIndicator",
77
component: CapacityIndicator,
8-
argTypes: {},
8+
argTypes: {
9+
total: {
10+
description: "The total available capacity",
11+
},
12+
used: {
13+
description: "How much from the total capacity is not available",
14+
},
15+
},
916
} as Meta<typeof CapacityIndicator>;
1017

1118
const Template: StoryFn<typeof CapacityIndicator> = (args) => ({
@@ -23,19 +30,19 @@ Example.parameters = {
2330
viewMode: "docs",
2431
};
2532
Example.args = {
26-
capacity: 20,
33+
total: 20,
2734
used: 14,
2835
};
2936

3037
export const State: StoryFn<typeof CapacityIndicator> = () => ({
3138
components: { CapacityIndicator },
3239
template: `
3340
<div class="flex items-center space-x-4">
34-
<CapacityIndicator :capacity="200" :used="1" />
35-
<CapacityIndicator :capacity="20" :used="6" />
36-
<CapacityIndicator :capacity="20" :used="18" />
37-
<CapacityIndicator :capacity="20" :used="20" />
38-
<CapacityIndicator :capacity="Infinity" />
41+
<CapacityIndicator :total="200" :used="1" />
42+
<CapacityIndicator :total="20" :used="6" />
43+
<CapacityIndicator :total="20" :used="18" />
44+
<CapacityIndicator :total="20" :used="20" />
45+
<CapacityIndicator :total="Infinity" />
3946
</div>
4047
`,
4148
});

src/components/CapacityIndicator/CapacityIndicator.vue

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import { AllInclusiveIcon } from "@bcc-code/icons-vue";
33
import { ref } from "vue";
44
55
type Props = {
6-
capacity?: number;
6+
total: number;
77
used?: number;
88
};
99
1010
const props = withDefaults(defineProps<Props>(), {
11-
capacity: Infinity,
11+
total: Infinity,
1212
used: 0,
1313
});
1414
1515
const size = 40;
16-
const progress = ref(props.capacity === Infinity ? 100 : (props.used / props.capacity) * 100);
16+
const progress = ref(props.total === Infinity ? 100 : (props.used / props.total) * 100);
1717
const trackWidth = 2;
1818
1919
const center = size / 2;
@@ -25,7 +25,7 @@ const dashOffset = dashArray * ((100 - progress.value) / 100);
2525
<template>
2626
<div class="relative inline-block">
2727
<div class="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2">
28-
<span v-if="capacity === Infinity">
28+
<span v-if="total === Infinity">
2929
<AllInclusiveIcon class="h-4 w-4 text-neutral-900" />
3030
</span>
3131
<span
@@ -37,7 +37,7 @@ const dashOffset = dashArray * ((100 - progress.value) / 100);
3737
'text-red-900': progress >= 100,
3838
}"
3939
>
40-
{{ capacity - used }}
40+
{{ total - used }}
4141
</span>
4242
</div>
4343

@@ -49,13 +49,13 @@ const dashOffset = dashArray * ((100 - progress.value) / 100);
4949
:stroke-width="trackWidth"
5050
fill="transparent"
5151
:class="{
52-
'stroke-neutral-200': capacity === Infinity,
53-
'stroke-neutral-300': capacity !== Infinity && progress < 50,
54-
'stroke-muddy-waters-100': capacity !== Infinity && progress >= 50,
52+
'stroke-neutral-200': total === Infinity,
53+
'stroke-neutral-300': total !== Infinity && progress < 50,
54+
'stroke-muddy-waters-100': total !== Infinity && progress >= 50,
5555
}"
5656
/>
5757
<circle
58-
v-if="capacity !== Infinity"
58+
v-if="total !== Infinity"
5959
:cx="center"
6060
:cy="center"
6161
:r="radius"

0 commit comments

Comments
 (0)