@flux-ui/statistics 3.0.0-next.74 → 3.0.0-next.75

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@flux-ui/statistics",
3
3
  "description": "Statistics components for the Flux UI library.",
4
- "version": "3.0.0-next.74",
4
+ "version": "3.0.0-next.75",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/basmilius",
@@ -51,9 +51,9 @@
51
51
  "dependencies": {
52
52
  "@basmilius/common": "^3.40.0",
53
53
  "@basmilius/utils": "^3.40.0",
54
- "@flux-ui/components": "3.0.0-next.74",
55
- "@flux-ui/internals": "3.0.0-next.74",
56
- "@flux-ui/types": "3.0.0-next.74",
54
+ "@flux-ui/components": "3.0.0-next.75",
55
+ "@flux-ui/internals": "3.0.0-next.75",
56
+ "@flux-ui/types": "3.0.0-next.75",
57
57
  "clsx": "^2.1.1"
58
58
  },
59
59
  "peerDependencies": {
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div :class="$style.statisticsLegend">
2
+ <div :class="containerClass">
3
3
  <slot v-if="hasSlot"/>
4
4
  <FluxStatisticsLegendItem
5
5
  v-else
@@ -18,17 +18,37 @@
18
18
  <script
19
19
  lang="ts"
20
20
  setup>
21
- import { computed, inject, useSlots } from 'vue';
22
- import { FluxStatisticsChartLegendInjectionKey } from '~flux/statistics/composable';
21
+ import type { FluxDirection } from '@flux-ui/types';
22
+ import { clsx } from 'clsx';
23
+ import { computed, inject, provide, toRef, useSlots } from 'vue';
24
+ import { FluxStatisticsChartLegendInjectionKey, type FluxStatisticsLegendVariant, FluxStatisticsLegendVariantInjectionKey } from '~flux/statistics/composable';
23
25
  import FluxStatisticsLegendItem from './FluxStatisticsLegendItem.vue';
24
26
  import $style from '~flux/statistics/css/Legend.module.scss';
25
27
 
28
+ const {
29
+ direction = 'horizontal',
30
+ variant = 'detailed'
31
+ } = defineProps<{
32
+ readonly direction?: FluxDirection;
33
+ readonly variant?: FluxStatisticsLegendVariant;
34
+ }>();
35
+
26
36
  const slots = useSlots();
27
37
  const legendContext = inject(FluxStatisticsChartLegendInjectionKey, null);
28
38
 
29
39
  const hasSlot = computed(() => !!slots.default);
30
40
  const autoItems = computed(() => legendContext?.items.value ?? []);
31
41
 
42
+ const containerClass = computed(() => {
43
+ if (variant === 'compact') {
44
+ return clsx($style.statisticsLegendCompact, direction === 'vertical' ? $style.isVertical : $style.isHorizontal);
45
+ }
46
+
47
+ return $style.statisticsLegend;
48
+ });
49
+
50
+ provide(FluxStatisticsLegendVariantInjectionKey, toRef(() => variant));
51
+
32
52
  function onItemMouseEnter(index: number): void {
33
53
  if (legendContext) {
34
54
  legendContext.hoveredIndex.value = index;
@@ -1,6 +1,9 @@
1
1
  <template>
2
2
  <div
3
- :class="clsx($style.statisticsLegendItem, isHovered && $style.isHovered)"
3
+ :class="clsx(
4
+ variant === 'compact' ? $style.statisticsLegendItemCompact : $style.statisticsLegendItem,
5
+ variant !== 'compact' && isHovered && $style.isHovered
6
+ )"
4
7
  :style="{
5
8
  '--color': colorValue
6
9
  }">
@@ -34,7 +37,8 @@
34
37
  import { FluxIcon } from '@flux-ui/components';
35
38
  import type { FluxColor, FluxIconName } from '@flux-ui/types';
36
39
  import { clsx } from 'clsx';
37
- import { computed } from 'vue';
40
+ import { computed, inject } from 'vue';
41
+ import { FluxStatisticsLegendVariantInjectionKey } from '~flux/statistics/composable';
38
42
  import $style from '~flux/statistics/css/Legend.module.scss';
39
43
 
40
44
  const {
@@ -47,6 +51,9 @@
47
51
  readonly value?: string | number;
48
52
  }>();
49
53
 
54
+ const variantRef = inject(FluxStatisticsLegendVariantInjectionKey, null);
55
+ const variant = computed(() => variantRef?.value ?? 'detailed');
56
+
50
57
  const colorValue = computed(() => {
51
58
  if (!color) {
52
59
  return;
@@ -10,3 +10,5 @@ export type { UseChartSlicesSetupReturn } from './useChartSlicesSetup';
10
10
  export { useChartSlicesSetup } from './useChartSlicesSetup';
11
11
  export type { EChartsInstance, EChartsOption, UseEChartsReturn } from './useECharts';
12
12
  export { useECharts } from './useECharts';
13
+ export type { FluxStatisticsLegendVariant } from './useLegendVariant';
14
+ export { FluxStatisticsLegendVariantInjectionKey } from './useLegendVariant';
@@ -0,0 +1,5 @@
1
+ import type { InjectionKey, Ref } from 'vue';
2
+
3
+ export type FluxStatisticsLegendVariant = 'detailed' | 'compact';
4
+
5
+ export const FluxStatisticsLegendVariantInjectionKey: InjectionKey<Ref<FluxStatisticsLegendVariant>> = Symbol('flux-statistics-legend-variant');
@@ -68,3 +68,48 @@
68
68
  content: '';
69
69
  border-top: 1px dashed var(--surface-stroke);
70
70
  }
71
+
72
+ .statisticsLegendCompact {
73
+ display: flex;
74
+ user-select: none;
75
+
76
+ &.isHorizontal {
77
+ flex-flow: row wrap;
78
+ gap: 12px 18px;
79
+ }
80
+
81
+ &.isVertical {
82
+ flex-flow: column;
83
+ gap: 12px;
84
+ }
85
+ }
86
+
87
+ .statisticsLegendItemCompact {
88
+ --color: var(--primary-600);
89
+
90
+ display: flex;
91
+ align-items: center;
92
+ flex-flow: row nowrap;
93
+ gap: 6px;
94
+ font-size: 14px;
95
+ line-height: 1;
96
+ white-space: nowrap;
97
+
98
+ .statisticsLegendItemColor {
99
+ margin: 0;
100
+ border-radius: var(--radius-full);
101
+ }
102
+
103
+ .statisticsLegendItemIcon {
104
+ margin: 0;
105
+ }
106
+
107
+ .statisticsLegendItemLabel {
108
+ flex-grow: 0;
109
+ font-weight: 400;
110
+ }
111
+
112
+ .statisticsLegendItemValue {
113
+ margin-left: 0;
114
+ }
115
+ }