@energysage/es-ds-components 3.1.7 → 3.2.1

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.
@@ -80,14 +80,15 @@ const getRootClasses = computed(() => {
80
80
  const btnSize = props.size ? `btn-${props.size}` : 'btn-md';
81
81
  return `btn ${btnVariant} ${btnInline} ${btnSize}`;
82
82
  });
83
+
84
+ /*
85
+ <a> is needed for href because a root-relative link like /market/start/
86
+ that is passed to <nuxt-link :to="" /> will attempt to internally navigate
87
+ within a micro frontend, which will result in a 404
88
+ */
83
89
  </script>
84
90
 
85
91
  <template>
86
- <!--
87
- <a> is needed for href because a root-relative link like /market/start/
88
- that is passed to <nuxt-link :to="" /> will attempt to internally navigate
89
- within a micro frontend, which will result in a 404
90
- -->
91
92
  <a
92
93
  v-if="props.href"
93
94
  :class="getRootClasses"
@@ -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_CIRCLE_GLOW_SIZE = 4;
7
+ const DIFF_CIRCLE_SIZE_FROM_BAR_HEIGHT_IN_PX = 4;
8
+ const DEFAULT_CIRCLE_DIMENSION = DEFAULT_BAR_HEIGHT + DIFF_CIRCLE_SIZE_FROM_BAR_HEIGHT_IN_PX;
9
+
10
+ interface Props {
11
+ formatter?: Function;
12
+ height?: string;
13
+ showCircle?: boolean;
14
+ showValue?: boolean;
15
+ value: number;
16
+ valueClass?: string;
17
+ }
18
+
19
+ const props = withDefaults(defineProps<Props>(), {
20
+ formatter: (val: number) => `${val}%`,
21
+ height: '0.125rem',
22
+ showCircle: true,
23
+ showValue: false,
24
+ valueClass: '',
17
25
  });
26
+
18
27
  const progressBarPt = {
19
28
  value: {
20
- class: 'EsProgressValue progress-bar',
29
+ class: [
30
+ 'EsProgressValue progress-bar overflow-visible position-relative rounded-sm',
31
+ {
32
+ 'progress-bar--with-circle': props.showCircle,
33
+ },
34
+ ],
21
35
  style: {
22
36
  height: props.height,
23
- borderRadius: props.value === 100 ? '0' : '0 0.125rem 0.125rem 0',
24
37
  },
25
38
  },
26
39
  };
40
+
41
+ const barHeight = computed(() => {
42
+ let barHeight = DEFAULT_BAR_HEIGHT;
43
+
44
+ if (props.height.indexOf('rem') === props.height.length - 3) {
45
+ barHeight = parseFloat(props.height.replace('rem', '')) * BASE_FONT_SIZE;
46
+ } else if (props.height.indexOf('px') === props.height.length - 2) {
47
+ barHeight = parseInt(props.height.replace('px', ''), 10);
48
+ }
49
+
50
+ return barHeight;
51
+ });
52
+ const circleDimension = computed(
53
+ () => barHeight.value + (DIFF_CIRCLE_SIZE_FROM_BAR_HEIGHT_IN_PX * barHeight.value) / DEFAULT_BAR_HEIGHT,
54
+ );
55
+
56
+ const circleDimensionPx = computed(() => `${circleDimension.value}px`);
57
+ const circleRightPx = computed(() => `${circleDimension.value * -0.5}px`);
58
+ const circleGlowSizePx = computed(
59
+ () => `${(DEFAULT_CIRCLE_GLOW_SIZE * circleDimension.value) / DEFAULT_CIRCLE_DIMENSION}px`,
60
+ );
61
+
62
+ const verticalContainerPaddingPx = computed(() =>
63
+ props.showCircle ? `${(circleDimension.value - barHeight.value) / 2}px` : '0',
64
+ );
27
65
  </script>
66
+
28
67
  <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>
68
+ <div
69
+ class="es-progress"
70
+ :class="$attrs.class">
71
+ <progress-bar
72
+ class="bg-gray-200 rounded-sm"
73
+ :pt="progressBarPt"
74
+ :show-value="false"
75
+ :value="value"
76
+ v-bind="omit('class', $attrs)">
77
+ </progress-bar>
78
+ <div
79
+ v-if="showValue"
80
+ class="font-size-75 mt-25 text-right"
81
+ :class="valueClass">
82
+ {{ formatter(value) }}
83
+ </div>
84
+ </div>
36
85
  </template>
86
+
87
+ <style lang="scss" scoped>
88
+ @use '@energysage/es-ds-styles/scss/variables' as variables;
89
+
90
+ .es-progress {
91
+ padding-bottom: v-bind(verticalContainerPaddingPx);
92
+ padding-top: v-bind(verticalContainerPaddingPx);
93
+
94
+ :deep(.progress-bar--with-circle::after) {
95
+ /*
96
+ * using v-bind for this border width gets disappeared during npm run generate,
97
+ * so we need to hardcode it, and the radial background gradient makes it look
98
+ * good enough at larger sizes
99
+ */
100
+ border: 0.5px solid variables.$warm-orange;
101
+ /*
102
+ * do not mix both an inset box shadow (has been converted to radial background gradient)
103
+ * with a non-inset box shadow while using v-bind, or you will get unexpected results
104
+ * after npm run generate
105
+ */
106
+ box-shadow: 0 0 v-bind(circleGlowSizePx) 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.1",
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.1",
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
+ };