@energysage/es-ds-components 3.1.7 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,36 +1,112 @@
1
1
  <script setup lang="ts">
2
2
  import ProgressBar from 'primevue/progressbar';
3
3
 
4
- const props = defineProps({
5
- value: {
6
- type: Number,
7
- required: true,
8
- },
9
- height: {
10
- type: String,
11
- default: '0.3125rem',
12
- },
13
- showValue: {
14
- type: Boolean,
15
- default: false,
16
- },
4
+ const BASE_FONT_SIZE = 16;
5
+ const DEFAULT_BAR_HEIGHT = 2;
6
+ const DEFAULT_BORDER_WIDTH = 0.5;
7
+ const DEFAULT_CIRCLE_GLOW_SIZE = 4;
8
+ const DEFAULT_INSET_SHADOW_SIZE = 0.5;
9
+ const DIFF_CIRCLE_SIZE_FROM_BAR_HEIGHT_IN_PX = 4;
10
+ const DEFAULT_CIRCLE_DIMENSION = DEFAULT_BAR_HEIGHT + DIFF_CIRCLE_SIZE_FROM_BAR_HEIGHT_IN_PX;
11
+
12
+ interface Props {
13
+ formatter?: Function;
14
+ height?: string;
15
+ showCircle?: boolean;
16
+ showValue?: boolean;
17
+ value: number;
18
+ valueClass?: string;
19
+ }
20
+
21
+ const props = withDefaults(defineProps<Props>(), {
22
+ formatter: (val: number) => `${val}%`,
23
+ height: '0.125rem',
24
+ showCircle: true,
25
+ showValue: false,
26
+ valueClass: '',
17
27
  });
28
+
18
29
  const progressBarPt = {
19
30
  value: {
20
- class: 'EsProgressValue progress-bar',
31
+ class: [
32
+ 'EsProgressValue progress-bar overflow-visible position-relative rounded-sm',
33
+ {
34
+ 'progress-bar--with-circle': props.showCircle,
35
+ },
36
+ ],
21
37
  style: {
22
38
  height: props.height,
23
- borderRadius: props.value === 100 ? '0' : '0 0.125rem 0.125rem 0',
24
39
  },
25
40
  },
26
41
  };
42
+
43
+ const barHeight = computed(() => {
44
+ let barHeight = DEFAULT_BAR_HEIGHT;
45
+
46
+ if (props.height.indexOf('rem') === props.height.length - 3) {
47
+ barHeight = parseFloat(props.height.replace('rem', '')) * BASE_FONT_SIZE;
48
+ } else if (props.height.indexOf('px') === props.height.length - 2) {
49
+ barHeight = parseInt(props.height.replace('px', ''), 10);
50
+ }
51
+
52
+ return barHeight;
53
+ });
54
+ const circleDimension = computed(
55
+ () => barHeight.value + (DIFF_CIRCLE_SIZE_FROM_BAR_HEIGHT_IN_PX * barHeight.value) / DEFAULT_BAR_HEIGHT,
56
+ );
57
+
58
+ const circleDimensionPx = computed(() => `${circleDimension.value}px`);
59
+ const circleRightPx = computed(() => `${circleDimension.value * -0.5}px`);
60
+ const circleBorderWidthPx = computed(
61
+ () => `${(DEFAULT_BORDER_WIDTH * circleDimension.value) / DEFAULT_CIRCLE_DIMENSION}px`,
62
+ );
63
+ const circleGlowSizePx = computed(
64
+ () => `${(DEFAULT_CIRCLE_GLOW_SIZE * circleDimension.value) / DEFAULT_CIRCLE_DIMENSION}px`,
65
+ );
66
+ const circleInsetShadowSizePx = computed(
67
+ () => `${(DEFAULT_INSET_SHADOW_SIZE * circleDimension.value) / DEFAULT_CIRCLE_DIMENSION}px`,
68
+ );
69
+
70
+ const verticalContainerPaddingPx = computed(() =>
71
+ props.showCircle ? `${(circleDimension.value - barHeight.value) / 2}px` : '0',
72
+ );
27
73
  </script>
74
+
28
75
  <template>
29
- <progress-bar
30
- class="bg-gray-200 rounded-0"
31
- :pt="progressBarPt"
32
- :show-value="showValue"
33
- :value="value"
34
- v-bind="$attrs">
35
- </progress-bar>
76
+ <div
77
+ class="es-progress"
78
+ :class="$attrs.class">
79
+ <progress-bar
80
+ class="bg-gray-200 rounded-sm"
81
+ :pt="progressBarPt"
82
+ :show-value="false"
83
+ :value="value"
84
+ v-bind="omit('class', $attrs)">
85
+ </progress-bar>
86
+ <div
87
+ v-if="showValue"
88
+ class="font-size-75 mt-25 text-right"
89
+ :class="valueClass">
90
+ {{ formatter(value) }}
91
+ </div>
92
+ </div>
36
93
  </template>
94
+
95
+ <style lang="scss" scoped>
96
+ @use '@energysage/es-ds-styles/scss/variables' as variables;
97
+
98
+ .es-progress {
99
+ padding-bottom: v-bind(verticalContainerPaddingPx);
100
+ padding-top: v-bind(verticalContainerPaddingPx);
101
+
102
+ :deep(.progress-bar--with-circle::after) {
103
+ border: v-bind(circleBorderWidthPx) solid variables.$warm-orange;
104
+ box-shadow:
105
+ 0 0 v-bind(circleInsetShadowSizePx) v-bind(circleInsetShadowSizePx) variables.$warm-orange inset,
106
+ 0 0 v-bind(circleGlowSizePx) 0 variables.$warm-orange;
107
+ height: v-bind(circleDimensionPx);
108
+ right: v-bind(circleRightPx);
109
+ width: v-bind(circleDimensionPx);
110
+ }
111
+ }
112
+ </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@energysage/es-ds-components",
3
- "version": "3.1.7",
3
+ "version": "3.2.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "An EnergySage Vue component library",
@@ -17,7 +17,7 @@
17
17
  "author": "EnergySage",
18
18
  "license": "MIT",
19
19
  "dependencies": {
20
- "@energysage/es-ds-styles": "^3.1.6",
20
+ "@energysage/es-ds-styles": "^3.2.0",
21
21
  "@nuxt/eslint": "^1.0.1",
22
22
  "@nuxtjs/google-fonts": "^3.2.0",
23
23
  "@vuelidate/core": "^2.0.3",
package/utils/omit.ts ADDED
@@ -0,0 +1,4 @@
1
+ export const omit = (key: string, obj: any) => {
2
+ const { [key]: omitted, ...rest } = obj;
3
+ return rest;
4
+ };