From 34d3213dbc005eef9c504336224657d905fc0536 Mon Sep 17 00:00:00 2001 From: Steffan Date: Sat, 16 Sep 2023 17:37:07 +0200 Subject: [PATCH 1/9] Implemented BccProgress component --- .../components/BccProgress/BccProgress.css | 20 +++ .../BccProgress/BccProgress.spec.ts | 69 ++++++++++ .../BccProgress/BccProgress.stories.ts | 129 ++++++++++++++++++ .../components/BccProgress/BccProgress.vue | 72 ++++++++++ .../__snapshots__/BccProgress.spec.ts.snap | 59 ++++++++ design-library/src/css/index.css | 1 + 6 files changed, 350 insertions(+) create mode 100644 design-library/src/components/BccProgress/BccProgress.css create mode 100644 design-library/src/components/BccProgress/BccProgress.spec.ts create mode 100644 design-library/src/components/BccProgress/BccProgress.stories.ts create mode 100644 design-library/src/components/BccProgress/BccProgress.vue create mode 100644 design-library/src/components/BccProgress/__snapshots__/BccProgress.spec.ts.snap diff --git a/design-library/src/components/BccProgress/BccProgress.css b/design-library/src/components/BccProgress/BccProgress.css new file mode 100644 index 00000000..afa81089 --- /dev/null +++ b/design-library/src/components/BccProgress/BccProgress.css @@ -0,0 +1,20 @@ +@layer components { + /* Base */ + .bcc-progress-container { + @apply inline-flex flex-col space-y-2; + } + + .bcc-progress { + @apply rounded w-full bg-neutral-200; + } + + /* Color */ + .bcc-progress-line { + @apply rounded bg-silver-tree-600; + } + + /* Size */ + .bcc-progress-container .bcc-form-label-lg .bcc-form-label-optional { + @apply text-label-base; + } +} diff --git a/design-library/src/components/BccProgress/BccProgress.spec.ts b/design-library/src/components/BccProgress/BccProgress.spec.ts new file mode 100644 index 00000000..4010458f --- /dev/null +++ b/design-library/src/components/BccProgress/BccProgress.spec.ts @@ -0,0 +1,69 @@ +import { describe, it, expect } from "vitest"; + +import { mount } from "@vue/test-utils"; +import BccProgress from "./BccProgress.vue"; + +describe("BccProgress", () => { + + it("renders without any properties", () => { + const wrapper = mount(BccProgress); + + expect(wrapper.text()).toContain("0%"); + expect(wrapper.html()).toMatchSnapshot(); + }); + + it("should exceed 100%", () => { + const wrapper = mount(BccProgress, { + props: { value: 110, max: 100 }, + }); + + expect(wrapper.text()).toContain("110%"); + expect(wrapper.html()).toMatchSnapshot(); + }); + + it("should not exceed 110%", () => { + const wrapper = mount(BccProgress, { + props: { value: 110, max: 100, exceed: false }, + }); + + expect(wrapper.text()).toContain("100%"); + expect(wrapper.html()).toMatchSnapshot(); + }); + + it("should render percentage", () => { + const wrapper = mount(BccProgress, { + props: { value: 100, max: 100, showPercentage: true }, + }); + + expect(wrapper.text()).toContain("100%"); + expect(wrapper.html()).toMatchSnapshot(); + }); + + it("should not render percentage", () => { + const wrapper = mount(BccProgress, { + props: { value: 100, max: 100, showPercentage: false }, + }); + + expect(wrapper.text()).not.toContain("100%"); + expect(wrapper.html()).toMatchSnapshot(); + }); + + it("should render values", () => { + const wrapper = mount(BccProgress, { + props: { value: 100, max: 100, showValues: true }, + }); + + expect(wrapper.text()).toContain("100 / 100"); + expect(wrapper.html()).toMatchSnapshot(); + }); + + it("should not render values", () => { + const wrapper = mount(BccProgress, { + props: { value: 100, max: 100, showValues: false }, + }); + + expect(wrapper.text()).not.toContain("100 / 100"); + expect(wrapper.html()).toMatchSnapshot(); + }); + +}); diff --git a/design-library/src/components/BccProgress/BccProgress.stories.ts b/design-library/src/components/BccProgress/BccProgress.stories.ts new file mode 100644 index 00000000..a9bf025a --- /dev/null +++ b/design-library/src/components/BccProgress/BccProgress.stories.ts @@ -0,0 +1,129 @@ +import BccProgress from "./BccProgress.vue"; + +import type { Meta, StoryFn } from "@storybook/vue3"; + +/** + * A `progress` element supporting current and max values + */ +export default { + title: "Forms/BccProgress", + component: BccProgress, + argTypes: { + value: { + description: "Current Value", + control: { type: "number" }, + }, + size: { + options: ["sm", "base", "lg"], + control: { type: "radio" }, + }, + max: { + description: "Max Value", + control: { type: "number" }, + }, + exceed: { + description: "Let or let not percentage exceed 100%", + }, + showValues: { + description: "Display current and max value", + }, + showPercentage: { + description: "Display percentage", + }, + }, +} as Meta; + +const Template: StoryFn = (args) => ({ + components: { BccProgress }, + setup() { + return { args }; + }, + template: ` + + `, +}); + +/** + * Use `value` to control the progress of the progress bar. Pass max value to declare when it reaches 100% and set exceed to false if it should not exceed 100%. + */ +export const Example = Template.bind({}); +Example.args = { + value: 30145.50, + max: 200000, + size: "base", + exceed: true, + showValues: true, + showPercentage: true, +}; +Example.parameters = { + docs: { + source: { + language: "html", + code: ` + +`, + }, + }, +}; + +/** + * Set the `size` prop to control the size + */ +export const Size: StoryFn = () => ({ + components: { BccProgress }, + template: ` +
+ + + +
+ `, +}); + +/** + * Set the `max` value, it supports both decimals and integers + */ +export const Max: StoryFn = () => ({ + components: { BccProgress }, + template: ` +
+ + +
+ `, +}); + +/** + * Do or do not let percentage `exceed` 100% + */ +export const exceed: StoryFn = () => ({ + components: { BccProgress }, + template: ` +
+ + +
+ `, +}); + +/** + * Set `showValues` and / or `showPercentage` to false + */ +export const showValuesAndOrPercentage: StoryFn = () => ({ + components: { BccProgress }, + template: ` +
+ + + + +
+ `, +}); diff --git a/design-library/src/components/BccProgress/BccProgress.vue b/design-library/src/components/BccProgress/BccProgress.vue new file mode 100644 index 00000000..4e1a603a --- /dev/null +++ b/design-library/src/components/BccProgress/BccProgress.vue @@ -0,0 +1,72 @@ + + + + + diff --git a/design-library/src/components/BccProgress/__snapshots__/BccProgress.spec.ts.snap b/design-library/src/components/BccProgress/__snapshots__/BccProgress.spec.ts.snap new file mode 100644 index 00000000..6d0eaeca --- /dev/null +++ b/design-library/src/components/BccProgress/__snapshots__/BccProgress.spec.ts.snap @@ -0,0 +1,59 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`BccProgress > renders without any properties 1`] = ` +"
+
+
+
+
" +`; + +exports[`BccProgress > should exceed 100% 1`] = ` +"
+
+
+
+
" +`; + +exports[`BccProgress > should not exceed 110% 1`] = ` +"
+
+
+
+
" +`; + +exports[`BccProgress > should not render percentage 1`] = ` +"
+
+
+
+
" +`; + +exports[`BccProgress > should not render values 1`] = ` +"
+
+
+
+
" +`; + +exports[`BccProgress > should render percentage 1`] = ` +"
+
+
+
+
" +`; + +exports[`BccProgress > should render values 1`] = ` +"
+
+
+
+
" +`; diff --git a/design-library/src/css/index.css b/design-library/src/css/index.css index 824ddd72..a5d3a098 100644 --- a/design-library/src/css/index.css +++ b/design-library/src/css/index.css @@ -17,6 +17,7 @@ @import "../components/BccRadio/BccRadio.css"; @import "../components/BccAlert/BccAlert.css"; @import "../components/BccSelect/BccSelect.css"; +@import "../components/BccProgress/BccProgress.css"; @import "../components/BccFormLabel/BccFormLabel.css"; @import "../components/BccFormMessage/BccFormMessage.css"; @import "../components/BccTable/BccTable.css"; From bbfee56548296662e589983cbce324c4ffe75deb Mon Sep 17 00:00:00 2001 From: Steffan Date: Mon, 18 Sep 2023 09:02:39 +0200 Subject: [PATCH 2/9] Fix linting --- .../BccProgress/BccProgress.spec.ts | 2 -- .../BccProgress/BccProgress.stories.ts | 6 ++--- .../components/BccProgress/BccProgress.vue | 26 ++++++++++--------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/design-library/src/components/BccProgress/BccProgress.spec.ts b/design-library/src/components/BccProgress/BccProgress.spec.ts index 4010458f..cb389ecb 100644 --- a/design-library/src/components/BccProgress/BccProgress.spec.ts +++ b/design-library/src/components/BccProgress/BccProgress.spec.ts @@ -4,7 +4,6 @@ import { mount } from "@vue/test-utils"; import BccProgress from "./BccProgress.vue"; describe("BccProgress", () => { - it("renders without any properties", () => { const wrapper = mount(BccProgress); @@ -65,5 +64,4 @@ describe("BccProgress", () => { expect(wrapper.text()).not.toContain("100 / 100"); expect(wrapper.html()).toMatchSnapshot(); }); - }); diff --git a/design-library/src/components/BccProgress/BccProgress.stories.ts b/design-library/src/components/BccProgress/BccProgress.stories.ts index a9bf025a..f4531d85 100644 --- a/design-library/src/components/BccProgress/BccProgress.stories.ts +++ b/design-library/src/components/BccProgress/BccProgress.stories.ts @@ -48,7 +48,7 @@ const Template: StoryFn = (args) => ({ */ export const Example = Template.bind({}); Example.args = { - value: 30145.50, + value: 30145.5, max: 200000, size: "base", exceed: true, @@ -103,7 +103,7 @@ export const Max: StoryFn = () => ({ /** * Do or do not let percentage `exceed` 100% */ -export const exceed: StoryFn = () => ({ +export const Exceed: StoryFn = () => ({ components: { BccProgress }, template: `
@@ -116,7 +116,7 @@ export const exceed: StoryFn = () => ({ /** * Set `showValues` and / or `showPercentage` to false */ -export const showValuesAndOrPercentage: StoryFn = () => ({ +export const ShowValuesAndOrPercentage: StoryFn = () => ({ components: { BccProgress }, template: `
diff --git a/design-library/src/components/BccProgress/BccProgress.vue b/design-library/src/components/BccProgress/BccProgress.vue index 4e1a603a..4daf8160 100644 --- a/design-library/src/components/BccProgress/BccProgress.vue +++ b/design-library/src/components/BccProgress/BccProgress.vue @@ -23,31 +23,34 @@ const props = withDefaults(defineProps(), { size: "base", showValues: true, showPercentage: true, - exceed: true + exceed: true, }); const percentage = computed(() => { - if (props.value > props.max && !props.exceed) return 100 - return (props.value / props.max) * 100 + if (props.value > props.max && !props.exceed) return 100; + return (props.value / props.max) * 100; }); const percentageSafe = computed(() => { - if (props.value > props.max) return 100 - return percentage.value + if (props.value > props.max) return 100; + return percentage.value; }); const height = computed(() => { return { - 'h-1': props.size === 'sm', - 'h-1.5': props.size === 'base', - 'h-2': props.size === 'lg', - } + "h-1": props.size === "sm", + "h-1.5": props.size === "base", + "h-2": props.size === "lg", + }; }); - From 0753d5a6948975cafeff0e87f978050213308634 Mon Sep 17 00:00:00 2001 From: Steffan Date: Mon, 18 Sep 2023 09:16:12 +0200 Subject: [PATCH 3/9] Fix typecheck --- design-library/src/components/BccProgress/BccProgress.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/design-library/src/components/BccProgress/BccProgress.vue b/design-library/src/components/BccProgress/BccProgress.vue index 4daf8160..bd912ab4 100644 --- a/design-library/src/components/BccProgress/BccProgress.vue +++ b/design-library/src/components/BccProgress/BccProgress.vue @@ -53,7 +53,7 @@ const height = computed(() => { > From 5fc32028002efab8e5834ff661e4abece9506bd5 Mon Sep 17 00:00:00 2001 From: Steffan Date: Tue, 19 Sep 2023 13:01:02 +0200 Subject: [PATCH 4/9] Add full customization --- .../components/BccProgress/BccProgress.css | 2 +- .../BccProgress/BccProgress.stories.ts | 55 ++++++++++++++++++- .../components/BccProgress/BccProgress.vue | 44 +++++++++------ 3 files changed, 82 insertions(+), 19 deletions(-) diff --git a/design-library/src/components/BccProgress/BccProgress.css b/design-library/src/components/BccProgress/BccProgress.css index afa81089..32cf1bba 100644 --- a/design-library/src/components/BccProgress/BccProgress.css +++ b/design-library/src/components/BccProgress/BccProgress.css @@ -9,7 +9,7 @@ } /* Color */ - .bcc-progress-line { + .bcc-progress-bar { @apply rounded bg-silver-tree-600; } diff --git a/design-library/src/components/BccProgress/BccProgress.stories.ts b/design-library/src/components/BccProgress/BccProgress.stories.ts index f4531d85..bdf22cef 100644 --- a/design-library/src/components/BccProgress/BccProgress.stories.ts +++ b/design-library/src/components/BccProgress/BccProgress.stories.ts @@ -6,7 +6,7 @@ import type { Meta, StoryFn } from "@storybook/vue3"; * A `progress` element supporting current and max values */ export default { - title: "Forms/BccProgress", + title: "Components/BccProgress", component: BccProgress, argTypes: { value: { @@ -30,6 +30,18 @@ export default { showPercentage: { description: "Display percentage", }, + progressClass: { + description: "Override height, background color and other classes.", + control: false, + }, + barClass: { + description: "Override background color and other classes.", + control: false, + }, + labelClass: { + description: "Override label classes.", + control: false, + }, }, } as Meta; @@ -48,12 +60,15 @@ const Template: StoryFn = (args) => ({ */ export const Example = Template.bind({}); Example.args = { - value: 30145.5, + value: 300145.5, max: 200000, size: "base", exceed: true, showValues: true, showPercentage: true, + progressClass: "", + barClass: "", + labelClass: "", }; Example.parameters = { docs: { @@ -67,6 +82,9 @@ Example.parameters = { showValues="true" showPercentage="true" exceed="true" + progressClass="" + barClass="" + labelClass="" /> `, }, @@ -127,3 +145,36 @@ export const ShowValuesAndOrPercentage: StoryFn = () => ({
`, }); + +/** + * Set `progressClass`, `barClass` and `labelClass` to fully customize the progress bar + */ +export const FullCustomization: StoryFn = () => ({ + components: { BccProgress }, + template: ` +
+ + + +
+ `, +}); diff --git a/design-library/src/components/BccProgress/BccProgress.vue b/design-library/src/components/BccProgress/BccProgress.vue index bd912ab4..1c1fbce8 100644 --- a/design-library/src/components/BccProgress/BccProgress.vue +++ b/design-library/src/components/BccProgress/BccProgress.vue @@ -1,17 +1,14 @@ - -