@makolabs/ripple 0.2.2-0 → 0.3.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.
@@ -127,7 +127,7 @@
127
127
  function getAreaStyle(seriesConfig: SeriesConfig<any>) {
128
128
  if (!seriesConfig.color) return undefined;
129
129
  if (!seriesConfig.showArea) return undefined;
130
-
130
+
131
131
  const baseLinearAreaStyle = {
132
132
  type: 'linear',
133
133
  x: 0,
@@ -265,7 +265,7 @@
265
265
  type: actualType,
266
266
  yAxisIndex: seriesConfig.yAxisIndex || 0,
267
267
  data: seriesData,
268
- stack: null,
268
+ stack: seriesConfig.stack,
269
269
  barWidth:
270
270
  seriesConfig.barWidth ||
271
271
  (barSeriesCount > 3 ? '15%' : barSeriesCount > 1 ? '25%' : '60%'),
@@ -274,7 +274,7 @@
274
274
  color: getColor(seriesConfig.color),
275
275
  itemStyle: {
276
276
  color: getColor(seriesConfig.color),
277
- borderRadius: [4, 4, 0, 0],
277
+ borderRadius: [0, 0, 0, 0],
278
278
  opacity: seriesConfig.opacity || 1
279
279
  }
280
280
  }),
package/dist/index.d.ts CHANGED
@@ -165,18 +165,6 @@ export type AlertProps = {
165
165
  footer?: Snippet;
166
166
  icon?: Component;
167
167
  };
168
- export type StatsCardProps = {
169
- label?: string;
170
- value?: string | number;
171
- previousValue?: string | number;
172
- previousValuePrefix?: string;
173
- trend?: number;
174
- color?: VariantColors;
175
- chartData?: number[];
176
- children?: Snippet;
177
- class?: ClassValue;
178
- formatLargeNumbers?: boolean;
179
- };
180
168
  export type MetricDetail = {
181
169
  label: string;
182
170
  value: string | number;
@@ -355,7 +343,6 @@ export { default as Badge } from './elements/badge/Badge.svelte';
355
343
  export { default as Dropdown } from './elements/dropdown/Dropdown.svelte';
356
344
  export { default as Select } from './elements/dropdown/Select.svelte';
357
345
  export { default as Card } from './layout/card/Card.svelte';
358
- export { default as StatsCard } from './layout/card/StatsCard.svelte';
359
346
  export { default as MetricCard } from './layout/card/MetricCard.svelte';
360
347
  export { default as Alert } from './elements/alert/Alert.svelte';
361
348
  export type TabProps = {
package/dist/index.js CHANGED
@@ -27,7 +27,6 @@ export { default as Dropdown } from './elements/dropdown/Dropdown.svelte';
27
27
  export { default as Select } from './elements/dropdown/Select.svelte';
28
28
  // Elements - Card
29
29
  export { default as Card } from './layout/card/Card.svelte';
30
- export { default as StatsCard } from './layout/card/StatsCard.svelte';
31
30
  export { default as MetricCard } from './layout/card/MetricCard.svelte';
32
31
  // Elements - Alert
33
32
  export { default as Alert } from './elements/alert/Alert.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makolabs/ripple",
3
- "version": "0.2.2-0",
3
+ "version": "0.3.0",
4
4
  "description": "Simple Svelte 5 powered component library ✨",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,266 +0,0 @@
1
- <script lang="ts">
2
- import { cn } from '../../helper/cls.js';
3
- import { statsCard } from './stats-card.js';
4
- import { onMount } from 'svelte';
5
- import * as echarts from 'echarts/core';
6
-
7
- // @ts-expect-error - ECharts types are not available
8
- import { LineChart } from 'echarts/charts';
9
-
10
- // @ts-expect-error - ECharts types are not available
11
- import { GridComponent } from 'echarts/components';
12
- // @ts-expect-error - ECharts types are not available
13
- import { SVGRenderer } from 'echarts/renderers';
14
- import { Color } from '../../variants.js';
15
- import type { StatsCardProps } from '../../index.js';
16
-
17
- // @ts-expect-error - ECharts types are not available
18
- echarts.use([LineChart, GridComponent, SVGRenderer]);
19
-
20
- let {
21
- label,
22
- value,
23
- previousValue,
24
- previousValuePrefix = 'from',
25
- trend,
26
- color = Color.PRIMARY,
27
- chartData,
28
- children,
29
- class: className = '',
30
- formatLargeNumbers = true
31
- }: StatsCardProps = $props();
32
-
33
- // Chart container reference
34
- let chartContainer: HTMLDivElement | undefined = $state();
35
- // @ts-expect-error - ECharts types are not available
36
- let chart: echarts.ECharts | undefined = $state();
37
-
38
- function getTrendDirection(trendX?: number): 'up' | 'down' | 'neutral' {
39
- if (trendX === undefined || trendX === null) return 'neutral';
40
- if (trendX > 0) {
41
- return 'up';
42
- } else if (trendX < 0) {
43
- return 'down';
44
- }
45
- return 'neutral';
46
- }
47
-
48
- function formatValue(val?: string | number): string {
49
- if (val === undefined || val === null) return '';
50
-
51
- let numValue: number;
52
- let currencySymbol: string | null = null;
53
-
54
- // Handle string inputs
55
- if (typeof val === 'string') {
56
- // Check for currency symbols
57
- const currencyMatch = val.match(/^(\$|€|£|¥)/);
58
- if (currencyMatch) {
59
- currencySymbol = currencyMatch[0];
60
- }
61
-
62
- // Extract the numeric value
63
- const cleanedStr = val.replace(/[^0-9.-]/g, '');
64
- if (/^-?\d+(\.\d+)?$/.test(cleanedStr)) {
65
- numValue = parseFloat(cleanedStr);
66
- } else {
67
- // Not a number we can format
68
- return val;
69
- }
70
- } else {
71
- // Already a number
72
- numValue = val;
73
- }
74
-
75
- // Format based on whether it's currency and size
76
- if (currencySymbol) {
77
- // Currency formatting with compact notation if needed
78
- return new Intl.NumberFormat('en-US', {
79
- style: 'currency',
80
- currency: currencySymbolToCode(currencySymbol),
81
- notation: formatLargeNumbers ? 'compact' : 'standard',
82
- compactDisplay: 'short',
83
- maximumFractionDigits: 1
84
- }).format(numValue);
85
- } else {
86
- // Regular number formatting with compact notation if needed
87
- return new Intl.NumberFormat('en-US', {
88
- notation: formatLargeNumbers ? 'compact' : 'standard',
89
- compactDisplay: 'short',
90
- maximumFractionDigits: 1
91
- }).format(numValue);
92
- }
93
- }
94
-
95
- // Helper function to convert currency symbols to ISO codes
96
- function currencySymbolToCode(symbol: string): string {
97
- const map: Record<string, string> = {
98
- $: 'USD',
99
- '€': 'EUR',
100
- '£': 'GBP',
101
- '¥': 'JPY'
102
- };
103
- return map[symbol] || 'USD';
104
- }
105
-
106
- const chartColorMap = {
107
- [Color.PRIMARY]: '#4F46E5',
108
- [Color.SECONDARY]: '#6B7280',
109
- [Color.INFO]: '#3B82F6',
110
- [Color.SUCCESS]: '#10B981',
111
- [Color.WARNING]: '#F59E0B',
112
- [Color.DANGER]: '#EF4444',
113
- [Color.DEFAULT]: '#6B7280'
114
- };
115
-
116
- const trendDirection = $derived(getTrendDirection(trend));
117
- const formattedValue = $derived(formatValue(value));
118
- const formattedPreviousValue = $derived(
119
- previousValue !== undefined ? formatValue(previousValue) : undefined
120
- );
121
-
122
- const {
123
- base,
124
- label: labelSlot,
125
- value: valueSlot,
126
- trend: trendSlot,
127
- previousValue: previousValueSlot
128
- } = $derived(
129
- statsCard({
130
- color,
131
- trendDirection
132
- })
133
- );
134
-
135
- const labelClasses = $derived(cn(labelSlot(), 'text-sm font-medium mb-1'));
136
- const valueClasses = $derived(cn(valueSlot(), 'text-4xl font-bold'));
137
- const trendClasses = $derived(cn(trendSlot(), 'text-sm font-medium ml-2'));
138
- const previousValueClasses = $derived(cn(previousValueSlot(), 'text-sm text-default-500 mt-1'));
139
-
140
- const trendFormatted = $derived.by(() => {
141
- if (trend === undefined || trend === null) return '';
142
- const absValue = Math.abs(trend);
143
- const formattedValue = absValue.toFixed(1).replace(/\.0$/, '');
144
- return trend >= 0 ? `+${formattedValue}%` : `-${formattedValue}%`;
145
- });
146
-
147
- const chartColor = $derived(chartColorMap[color] || chartColorMap[Color.DEFAULT]);
148
-
149
- onMount(() => {
150
- if (!chartData || chartData.length < 2 || !chartContainer) return;
151
-
152
- // @ts-expect-error - ECharts types are not available
153
- chart = echarts.init(chartContainer);
154
-
155
- // Set chart options
156
- const options = {
157
- grid: {
158
- left: 0,
159
- right: 0,
160
- top: 0,
161
- bottom: 0
162
- },
163
- xAxis: {
164
- type: 'category',
165
- show: false,
166
- data: Array.from({ length: chartData.length }, (_, i) => i)
167
- },
168
- yAxis: {
169
- type: 'value',
170
- show: false
171
- },
172
- series: [
173
- {
174
- data: chartData,
175
- type: 'line',
176
- symbol: 'none',
177
- lineStyle: {
178
- color: chartColor,
179
- width: 2
180
- },
181
- areaStyle: {
182
- color: {
183
- type: 'linear',
184
- x: 0,
185
- y: 0,
186
- x2: 0,
187
- y2: 1,
188
- colorStops: [
189
- {
190
- offset: 0,
191
- color: chartColor + '40' // 25% opacity
192
- },
193
- {
194
- offset: 1,
195
- color: chartColor + '00' // 0% opacity
196
- }
197
- ]
198
- }
199
- },
200
- smooth: true
201
- }
202
- ],
203
- animation: false,
204
- animationDuration: 1000
205
- };
206
-
207
- chart.setOption(options);
208
-
209
- const resizeObserver = new ResizeObserver(() => {
210
- chart && chart.resize();
211
- });
212
-
213
- resizeObserver.observe(chartContainer);
214
-
215
- return () => {
216
- resizeObserver.disconnect();
217
- chart.dispose();
218
- };
219
- });
220
- </script>
221
-
222
- <div
223
- class={cn(
224
- base(),
225
- '@container flex flex-col rounded-lg border border-default-200 bg-white p-6 shadow-sm',
226
- className
227
- )}
228
- >
229
- <div class="flex items-center justify-between">
230
- {#if label}
231
- <dt class={labelClasses}>{label}</dt>
232
- {/if}
233
- {#if trend !== undefined && trend !== null}
234
- <span class={trendClasses}>
235
- {trendFormatted}
236
- </span>
237
- {/if}
238
- </div>
239
-
240
- <div class="mt-1 flex flex-row items-center overflow-clip">
241
- <div class="w-full flex-grow">
242
- {#if value !== undefined}
243
- <dd class={valueClasses} title={value}>
244
- {formattedValue}
245
- </dd>
246
- {/if}
247
-
248
- {#if previousValue !== undefined}
249
- <div class={previousValueClasses}>
250
- {previousValuePrefix}
251
- {formattedPreviousValue}
252
- </div>
253
- {/if}
254
- </div>
255
-
256
- {#if chartData && chartData.length > 1}
257
- <div class="h-10 w-full min-w-32 @max-[212.862px]:hidden" bind:this={chartContainer}></div>
258
- {/if}
259
- </div>
260
-
261
- {#if children}
262
- <div class="mt-4">
263
- {@render children()}
264
- </div>
265
- {/if}
266
- </div>
@@ -1,4 +0,0 @@
1
- import type { StatsCardProps } from '../../index.js';
2
- declare const StatsCard: import("svelte").Component<StatsCardProps, {}, "">;
3
- type StatsCard = ReturnType<typeof StatsCard>;
4
- export default StatsCard;
@@ -1,191 +0,0 @@
1
- import { Color } from '../../variants.js';
2
- export declare const statsCard: import("tailwind-variants").TVReturnType<{
3
- color: {
4
- [Color.DEFAULT]: {
5
- label: string;
6
- value: string;
7
- trend: string;
8
- previousValue: string;
9
- };
10
- [Color.PRIMARY]: {
11
- label: string;
12
- value: string;
13
- trend: string;
14
- previousValue: string;
15
- };
16
- [Color.SECONDARY]: {
17
- label: string;
18
- value: string;
19
- trend: string;
20
- previousValue: string;
21
- };
22
- [Color.INFO]: {
23
- label: string;
24
- value: string;
25
- trend: string;
26
- previousValue: string;
27
- };
28
- [Color.SUCCESS]: {
29
- label: string;
30
- value: string;
31
- trend: string;
32
- previousValue: string;
33
- };
34
- [Color.WARNING]: {
35
- label: string;
36
- value: string;
37
- trend: string;
38
- previousValue: string;
39
- };
40
- [Color.DANGER]: {
41
- label: string;
42
- value: string;
43
- trend: string;
44
- previousValue: string;
45
- };
46
- };
47
- trendDirection: {
48
- up: {
49
- trend: string;
50
- };
51
- down: {
52
- trend: string;
53
- };
54
- neutral: {
55
- trend: string;
56
- };
57
- };
58
- }, {
59
- base: string;
60
- label: string;
61
- value: string;
62
- trend: string;
63
- previousValue: string;
64
- unit: string;
65
- }, undefined, {
66
- color: {
67
- [Color.DEFAULT]: {
68
- label: string;
69
- value: string;
70
- trend: string;
71
- previousValue: string;
72
- };
73
- [Color.PRIMARY]: {
74
- label: string;
75
- value: string;
76
- trend: string;
77
- previousValue: string;
78
- };
79
- [Color.SECONDARY]: {
80
- label: string;
81
- value: string;
82
- trend: string;
83
- previousValue: string;
84
- };
85
- [Color.INFO]: {
86
- label: string;
87
- value: string;
88
- trend: string;
89
- previousValue: string;
90
- };
91
- [Color.SUCCESS]: {
92
- label: string;
93
- value: string;
94
- trend: string;
95
- previousValue: string;
96
- };
97
- [Color.WARNING]: {
98
- label: string;
99
- value: string;
100
- trend: string;
101
- previousValue: string;
102
- };
103
- [Color.DANGER]: {
104
- label: string;
105
- value: string;
106
- trend: string;
107
- previousValue: string;
108
- };
109
- };
110
- trendDirection: {
111
- up: {
112
- trend: string;
113
- };
114
- down: {
115
- trend: string;
116
- };
117
- neutral: {
118
- trend: string;
119
- };
120
- };
121
- }, {
122
- base: string;
123
- label: string;
124
- value: string;
125
- trend: string;
126
- previousValue: string;
127
- unit: string;
128
- }, import("tailwind-variants").TVReturnType<{
129
- color: {
130
- [Color.DEFAULT]: {
131
- label: string;
132
- value: string;
133
- trend: string;
134
- previousValue: string;
135
- };
136
- [Color.PRIMARY]: {
137
- label: string;
138
- value: string;
139
- trend: string;
140
- previousValue: string;
141
- };
142
- [Color.SECONDARY]: {
143
- label: string;
144
- value: string;
145
- trend: string;
146
- previousValue: string;
147
- };
148
- [Color.INFO]: {
149
- label: string;
150
- value: string;
151
- trend: string;
152
- previousValue: string;
153
- };
154
- [Color.SUCCESS]: {
155
- label: string;
156
- value: string;
157
- trend: string;
158
- previousValue: string;
159
- };
160
- [Color.WARNING]: {
161
- label: string;
162
- value: string;
163
- trend: string;
164
- previousValue: string;
165
- };
166
- [Color.DANGER]: {
167
- label: string;
168
- value: string;
169
- trend: string;
170
- previousValue: string;
171
- };
172
- };
173
- trendDirection: {
174
- up: {
175
- trend: string;
176
- };
177
- down: {
178
- trend: string;
179
- };
180
- neutral: {
181
- trend: string;
182
- };
183
- };
184
- }, {
185
- base: string;
186
- label: string;
187
- value: string;
188
- trend: string;
189
- previousValue: string;
190
- unit: string;
191
- }, undefined, unknown, unknown, undefined>>;
@@ -1,73 +0,0 @@
1
- import { tv } from 'tailwind-variants';
2
- import { Color } from '../../variants.js';
3
- export const statsCard = tv({
4
- slots: {
5
- base: '',
6
- label: '',
7
- value: '',
8
- trend: '',
9
- previousValue: '',
10
- unit: '',
11
- },
12
- variants: {
13
- color: {
14
- [Color.DEFAULT]: {
15
- label: 'text-default-500',
16
- value: 'text-default-900',
17
- trend: 'text-default-600',
18
- previousValue: 'text-default-500'
19
- },
20
- [Color.PRIMARY]: {
21
- label: 'text-primary-500',
22
- value: 'text-primary-600',
23
- trend: 'text-primary-600',
24
- previousValue: 'text-primary-400'
25
- },
26
- [Color.SECONDARY]: {
27
- label: 'text-secondary-500',
28
- value: 'text-secondary-600',
29
- trend: 'text-secondary-600',
30
- previousValue: 'text-secondary-400'
31
- },
32
- [Color.INFO]: {
33
- label: 'text-info-500',
34
- value: 'text-info-600',
35
- trend: 'text-info-600',
36
- previousValue: 'text-info-400'
37
- },
38
- [Color.SUCCESS]: {
39
- label: 'text-success-500',
40
- value: 'text-success-600',
41
- trend: 'text-success-600',
42
- previousValue: 'text-success-400'
43
- },
44
- [Color.WARNING]: {
45
- label: 'text-warning-500',
46
- value: 'text-warning-600',
47
- trend: 'text-warning-600',
48
- previousValue: 'text-warning-400'
49
- },
50
- [Color.DANGER]: {
51
- label: 'text-danger-500',
52
- value: 'text-danger-600',
53
- trend: 'text-danger-600',
54
- previousValue: 'text-danger-400'
55
- }
56
- },
57
- trendDirection: {
58
- up: {
59
- trend: 'text-success-600'
60
- },
61
- down: {
62
- trend: 'text-danger-600'
63
- },
64
- neutral: {
65
- trend: 'text-default-600'
66
- }
67
- }
68
- },
69
- defaultVariants: {
70
- color: Color.DEFAULT,
71
- trendDirection: 'neutral'
72
- }
73
- });