Skip to content

Commit

Permalink
Merge pull request #607 from weni-ai/feature/new-default-funnel-compo…
Browse files Browse the repository at this point in the history
…nent

[ENGAGE-1894] Add new variant funnel and eslint typescript support
  • Loading branch information
MarcusviniciusLsantos authored Oct 31, 2024
2 parents 3fe9c34 + 9df0882 commit 375c78e
Show file tree
Hide file tree
Showing 13 changed files with 556 additions and 63 deletions.
54 changes: 30 additions & 24 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
module.exports = {
root: true,
env: {
node: true,
},
extends: ['@weni/eslint-config/vue3'],
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'import/extensions': 'off',
'no-shadow': 'off',
},
overrides: [
{
files: [
'**/__tests__/*.{j,t}s?(x)',
'**/tests/unit/**/*.spec.{j,t}s?(x)',
],
env: {
jest: true,
},
},
],
};
module.exports = {
root: true,
env: {
node: true,
},
extends: ['@weni/eslint-config/vue3'],
plugins: ['@typescript-eslint'],
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'import/extensions': 'off',
'no-shadow': 'off',
},
parserOptions: {
parser: '@typescript-eslint/parser',
ecmaVersion: 2020,
sourceType: 'module',
},
overrides: [
{
files: [
'**/__tests__/*.{j,t}s?(x)',
'**/tests/unit/**/*.spec.{j,t}s?(x)',
],
env: {
jest: true,
},
},
],
};
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@
"@storybook/testing-library": "^0.2.2",
"@storybook/vue3": "^8.0.10",
"@storybook/vue3-vite": "^8.0.10",
"@typescript-eslint/eslint-plugin": "^8.11.0",
"@typescript-eslint/parser": "^8.11.0",
"@vitejs/plugin-vue": "^4.2.3",
"@vitejs/plugin-vue-jsx": "^3.0.1",
"@vitest/coverage-v8": "^1.6.0",
"@vitest/coverage-istanbul": "^1.6.0",
"@vitest/coverage-v8": "^1.6.0",
"@vitest/ui": "^1.6.0",
"@vue/eslint-config-prettier": "^9.0.0",
"@vue/test-utils": "^2.4.6",
Expand All @@ -79,8 +81,9 @@
"react-dom": "^18.2.0",
"sass": "^1.62.1",
"storybook": "^8.0.10",
"typescript": "^5.6.3",
"vite": "4.3.5",
"vitest": "^1.6.0",
"vue-eslint-parser": "^9.4.2"
}
}
}
46 changes: 38 additions & 8 deletions src/components/ChartFunnel/ChartFunnel.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<template>
<component
:is="chartComponent"
:data="data"
:data="chartData"
/>
</template>

<script>
import ChartFunnelThreeRows from './ChartFunnelThreeRows.vue';
import ChartFunnelFourRows from './ChartFunnelFourRows.vue';
import ChartFunnelFiveRows from './ChartFunnelFiveRows.vue';
import ChartFunnelThreeRows from './SvgFunnel/ChartFunnelThreeRows.vue';
import ChartFunnelFourRows from './SvgFunnel/ChartFunnelFourRows.vue';
import ChartFunnelFiveRows from './SvgFunnel/ChartFunnelFiveRows.vue';
import ChartDefaultFunnelThreeRows from './DefaultFunnel/ChartDefaultFunnelThreeRows.vue';
import ChartDefaultFunnelFourRows from './DefaultFunnel/ChartDefaultFunnelFourRows.vue';
import ChartDefaultFunnelFiveRows from './DefaultFunnel/ChartDefaultFunnelFiveRows.vue';
export default {
name: 'UnnnicChartFunnel',
Expand All @@ -17,23 +20,50 @@ export default {
ChartFunnelThreeRows,
ChartFunnelFourRows,
ChartFunnelFiveRows,
ChartDefaultFunnelFiveRows,
ChartDefaultFunnelThreeRows,
ChartDefaultFunnelFourRows,
},
props: {
data: {
type: Array,
required: true,
},
type: {
type: String,
default: 'default',
},
},
computed: {
chartComponent() {
const componentMap = {
3: 'ChartFunnelThreeRows',
4: 'ChartFunnelFourRows',
5: 'ChartFunnelFiveRows',
default: {
3: ChartDefaultFunnelThreeRows,
4: ChartDefaultFunnelFourRows,
5: ChartDefaultFunnelFiveRows,
},
basic: {
3: 'ChartFunnelThreeRows',
4: 'ChartFunnelFourRows',
5: 'ChartFunnelFiveRows',
},
};
return componentMap[this.data.length] || null;
return componentMap[this.type][this.data.length] || null;
},
chartData() {
const classIndex = ['w-60', 'w-50', 'w-40', 'w-30', 'w-20'];
if (this.type === 'default')
return this.data.map((e, index) => ({
percentage: e.title,
value: e.value,
description: e.description,
widthClass: classIndex[index],
color: e.color,
}));
return this.data;
},
},
};
Expand Down
150 changes: 150 additions & 0 deletions src/components/ChartFunnel/DefaultFunnel/ChartDefaultFunnelBase.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<template>
<section class="unnnic-chart-funnel-base-container">
<section
v-for="(step, index) in data"
:key="index"
:class="[
'unnnic-chart-funnel-base-item',
{ 'first-item': index === 0, 'last-item': index === data.length - 1 },
]"
>
<section class="unnnic-chart-funnel-base-item__card">
<svg
:width="step.svgWidth"
:height="step.svgHeight"
:viewBox="`0 0 ${step.svgWidth} ${step.svgHeight}`"
fill="none"
xmlns="http://www.w3.org/2000/svg"
class="funnel-svg"
>
<path
:d="step.svgPath"
:fill="step.color"
/>
</svg>
</section>
<section class="unnnic-chart-funnel-base-item__text">
<section class="unnnic-chart-funnel-base-item__text__values">
<p class="unnnic-chart-funnel-base-item__text__values-title">
{{ step.percentage }}
</p>
<p class="unnnic-chart-funnel-base-item__text__values-sub-title">
&nbsp; | {{ step.value }}
</p>
</section>
<p class="unnnic-chart-funnel-base-item__text-description">
{{ step.description }}
</p>
</section>
</section>
</section>
</template>

<script setup lang="ts">
interface FunnelStep {
percentage: number | string;
value: number | string;
description: string;
color: string;
svgPath: string;
svgWidth: number;
svgHeight: number;
}
defineProps<{
data: FunnelStep[];
}>();
</script>

<style lang="scss" scoped>
@import '../../../assets/scss/unnnic.scss';
.unnnic-chart-funnel-base-container {
display: flex;
flex-direction: column;
flex-wrap: wrap;
}
.unnnic-chart-funnel-base-item {
display: flex;
justify-content: flex-start;
&__card {
position: relative;
display: flex;
align-items: center;
&::after {
content: '';
position: absolute;
left: 0;
bottom: -1px;
width: 100%;
height: 1px;
background-color: $unnnic-color-neutral-soft;
z-index: -1;
}
}
&__text {
display: flex;
flex-direction: column;
justify-content: center;
position: relative;
padding-left: 1rem;
&::after {
content: '';
position: absolute;
left: 0;
bottom: -1px;
width: 100%;
height: 1px;
background-color: $unnnic-color-neutral-soft;
z-index: -1;
}
&-description {
margin: 0;
color: $unnnic-color-neutral-dark;
text-align: center;
font-family: $unnnic-font-family-secondary;
font-size: $unnnic-font-size-body-md;
font-style: normal;
font-weight: $unnnic-font-weight-regular;
line-height: $unnnic-font-size-body-md + $unnnic-line-height-md;
}
&__values {
display: flex;
&-title {
margin: 0;
color: $unnnic-color-neutral-dark;
font-family: $unnnic-font-family-secondary;
font-size: $unnnic-font-size-body-lg;
font-style: normal;
font-weight: $unnnic-font-weight-bold;
line-height: $unnnic-font-size-body-lg + $unnnic-line-height-md;
}
&-sub-title {
display: flex;
align-items: end;
margin: 0;
color: $unnnic-color-neutral-cloudy;
font-family: $unnnic-font-family-secondary;
font-size: $unnnic-font-size-body-md;
font-style: normal;
font-weight: $unnnic-font-weight-regular;
line-height: $unnnic-font-size-body-md + $unnnic-line-height-md;
}
}
}
&:last-child .unnnic-chart-funnel-base-item__card::after,
&:last-child .unnnic-chart-funnel-base-item__text::after {
content: none;
}
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<template>
<ChartDefaultFunnelBase :data="rows" />
</template>

<script>
import ChartDefaultFunnelBase from './ChartDefaultFunnelBase.vue';
export default {
name: 'UnnnicDefaultChartFunnelFiveRows',
components: {
ChartDefaultFunnelBase,
},
props: {
data: {
type: Array,
required: true,
},
},
computed: {
rows() {
const { data } = this;
return [
{
...data[0],
svgPath:
'M218.999 0H8C3.58172 0 0 3.58173 0 8.00001V92.4H201.798C205.539 92.4 208.781 89.8071 209.602 86.1572L226.803 9.75715C227.929 4.75524 224.126 0 218.999 0Z',
svgWidth: 228,
svgHeight: 92,
},
{
...data[1],
svgPath:
'M192 0.399902H0L1.04385e-05 92.7999H163.476C167.174 92.7999 170.39 90.2656 171.254 86.6703L192 0.399902Z',
svgWidth: 192,
svgHeight: 92,
},
{
...data[2],
svgPath:
'M152 0.800049H2.59253e-05L0 93.2001H123.948C127.661 93.2001 130.886 90.645 131.736 87.0302L152 0.800049Z',
svgWidth: 152,
svgHeight: 92,
},
{
...data[3],
svgPath:
'M117 0.199951H0L2.21175e-05 92.6H86.3723C90.0018 92.6 93.1765 90.1566 94.1057 86.648L117 0.199951Z',
svgWidth: 117,
svgHeight: 92,
},
{
...data[4],
svgPath:
'M79 0.600098H0L3.72103e-05 85.0001C3.91582e-05 89.4184 3.58177 93.0001 8.00004 93.0001H46.3116C49.8754 93.0001 53.0095 90.6427 53.9978 87.2187L79 0.600098Z',
svgWidth: 79,
svgHeight: 92,
},
];
},
},
};
</script>
Loading

0 comments on commit 375c78e

Please sign in to comment.