@matteoaliano/forest-ui 0.2.9 → 0.2.10

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/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { bg, navColors, text, forestTheme, getPreset, buildTheme } from './chunk-QF5T6J4D.mjs';
2
- export { alkemyPlusPreset, alpha, avatarColors, bg, border, breadcrumbColors, buildTheme, buildThemeOptions, buttonColors, chartColors, colors, container, display, fg, focusRings, fontFamily, fontSize, fontWeight, forestPreset, forestTheme, forestThemeOptions, getAvailablePresets, getPreset, iconColors, lineHeight, navColors, radius, registerPreset, sliderColors, spacing, text, toggleColors, shadows as tokenShadows, widths } from './chunk-QF5T6J4D.mjs';
1
+ import { bg, navColors, text, forestTheme, getPreset, buildTheme } from './chunk-7B6NCKX3.mjs';
2
+ export { alkemyPlusPreset, alpha, avatarColors, bg, border, breadcrumbColors, buildTheme, buildThemeOptions, buttonColors, chartColors, colors, container, display, fg, focusRings, fontFamily, fontSize, fontWeight, forestPreset, forestTheme, forestThemeOptions, getAvailablePresets, getPreset, iconColors, lineHeight, navColors, radius, registerPreset, sliderColors, spacing, text, toggleColors, shadows as tokenShadows, widths } from './chunk-7B6NCKX3.mjs';
3
3
  import { createContext, useMemo, useContext } from 'react';
4
- import { ThemeProvider } from '@mui/material/styles';
4
+ import { ThemeProvider, useTheme } from '@mui/material/styles';
5
5
  import CssBaseline from '@mui/material/CssBaseline';
6
6
  import { jsx, jsxs } from 'react/jsx-runtime';
7
7
  import MuiAutocomplete from '@mui/material/Autocomplete';
@@ -13,6 +13,9 @@ import MuiRadioGroup from '@mui/material/RadioGroup';
13
13
  import MuiRadio from '@mui/material/Radio';
14
14
  import MuiSelect from '@mui/material/Select';
15
15
  import MuiMenuItem from '@mui/material/MenuItem';
16
+ import MuiListItemText from '@mui/material/ListItemText';
17
+ import MuiFormControl from '@mui/material/FormControl';
18
+ import MuiInputLabel from '@mui/material/InputLabel';
16
19
  import MuiSwitch from '@mui/material/Switch';
17
20
  import MuiTextField from '@mui/material/TextField';
18
21
  import MuiToggleButton from '@mui/material/ToggleButton';
@@ -25,7 +28,6 @@ import MuiList from '@mui/material/List';
25
28
  import MuiListItem from '@mui/material/ListItem';
26
29
  import MuiListItemButton2 from '@mui/material/ListItemButton';
27
30
  import ListItemIcon2 from '@mui/material/ListItemIcon';
28
- import MuiListItemText from '@mui/material/ListItemText';
29
31
  import MuiListItemAvatar from '@mui/material/ListItemAvatar';
30
32
  import MuiListSubheader from '@mui/material/ListSubheader';
31
33
  import MuiTable from '@mui/material/Table';
@@ -64,6 +66,10 @@ import MuiSnackbar from '@mui/material/Snackbar';
64
66
  import MuiDrawer from '@mui/material/Drawer';
65
67
  import Box from '@mui/material/Box';
66
68
  import IconButton from '@mui/material/IconButton';
69
+ import { LineChart as LineChart$1 } from '@mui/x-charts/LineChart';
70
+ import { Box as Box$1, Typography as Typography$1 } from '@mui/material';
71
+ import { BarChart as BarChart$1 } from '@mui/x-charts/BarChart';
72
+ import { PieChart as PieChart$1 } from '@mui/x-charts/PieChart';
67
73
 
68
74
  function ForestProvider({
69
75
  children,
@@ -122,6 +128,64 @@ function Select(props) {
122
128
  function MenuItem(props) {
123
129
  return /* @__PURE__ */ jsx(MuiMenuItem, { ...props });
124
130
  }
131
+ function MultiSelect({
132
+ options,
133
+ value,
134
+ onChange,
135
+ selectAll = true,
136
+ selectAllLabel = "Select All",
137
+ label,
138
+ ...rest
139
+ }) {
140
+ const allSelected = options.length > 0 && value.length === options.length;
141
+ const handleChange = (event) => {
142
+ const selected = event.target.value;
143
+ const arr = typeof selected === "string" ? selected.split(",") : selected;
144
+ onChange(arr);
145
+ };
146
+ const handleSelectAll = (e) => {
147
+ e.stopPropagation();
148
+ onChange(allSelected ? [] : options.map((o) => o.value));
149
+ };
150
+ const labelMap = new Map(options.map((o) => [o.value, o.label]));
151
+ const renderValue2 = (selected) => selected.map((v) => {
152
+ var _a;
153
+ return (_a = labelMap.get(v)) != null ? _a : v;
154
+ }).join(", ");
155
+ const labelId = label ? `forest-multiselect-${String(label).replace(/\s+/g, "-").toLowerCase()}` : void 0;
156
+ return /* @__PURE__ */ jsxs(MuiFormControl, { fullWidth: true, children: [
157
+ label && /* @__PURE__ */ jsx(MuiInputLabel, { id: labelId, shrink: value.length > 0, children: label }),
158
+ /* @__PURE__ */ jsxs(
159
+ MuiSelect,
160
+ {
161
+ labelId,
162
+ label,
163
+ multiple: true,
164
+ notched: value.length > 0,
165
+ value,
166
+ onChange: handleChange,
167
+ displayEmpty: true,
168
+ renderValue: renderValue2,
169
+ ...rest,
170
+ children: [
171
+ selectAll && /* @__PURE__ */ jsx(
172
+ MuiButton,
173
+ {
174
+ size: "small",
175
+ variant: "text",
176
+ onMouseDown: handleSelectAll,
177
+ children: allSelected ? "Deselect All" : selectAllLabel
178
+ }
179
+ ),
180
+ options.map((option) => /* @__PURE__ */ jsxs(MuiMenuItem, { value: option.value, children: [
181
+ /* @__PURE__ */ jsx(MuiCheckbox, { checked: value.includes(option.value) }),
182
+ /* @__PURE__ */ jsx(MuiListItemText, { primary: option.label })
183
+ ] }, option.value))
184
+ ]
185
+ }
186
+ )
187
+ ] });
188
+ }
125
189
  function Switch(props) {
126
190
  return /* @__PURE__ */ jsx(MuiSwitch, { ...props });
127
191
  }
@@ -431,7 +495,360 @@ function SidebarItem({
431
495
  endAdornment
432
496
  ] });
433
497
  }
498
+ function useChartColors(count, palette = "categorical") {
499
+ const theme = useTheme();
500
+ const chart = theme.palette.chart;
501
+ const colors2 = chart[palette] || chart.categorical || [
502
+ "#7B61FF",
503
+ "#FF7E67",
504
+ "#76DFD5",
505
+ "#F6C343",
506
+ "#B36A6F"
507
+ ];
508
+ return colors2.slice(0, Math.min(count, colors2.length));
509
+ }
510
+ function formatDate(date) {
511
+ if (!date) return "";
512
+ const d = new Date(date);
513
+ if (isNaN(d.getTime())) return String(date);
514
+ return d.toLocaleDateString("en-US", {
515
+ weekday: "short",
516
+ month: "short",
517
+ day: "numeric",
518
+ year: "numeric"
519
+ });
520
+ }
521
+ function renderValue(val) {
522
+ if (val == null) return "0";
523
+ if (typeof val === "object" && "y" in val) {
524
+ return String(val.y);
525
+ }
526
+ return String(val);
527
+ }
528
+ function CustomTooltip(props) {
529
+ const { series, axisValue, dataIndex } = props;
530
+ const theme = useTheme();
531
+ if (dataIndex == null) {
532
+ return null;
533
+ }
534
+ return /* @__PURE__ */ jsxs(
535
+ Box$1,
536
+ {
537
+ sx: {
538
+ backgroundColor: theme.palette.common.white,
539
+ borderRadius: "12px",
540
+ boxShadow: "0px 12px 24px -4px #1018281a, 0px 4px 8px -2px #1018280f",
541
+ // Very high elevation shadow per reference
542
+ padding: "16px",
543
+ minWidth: "200px",
544
+ display: "flex",
545
+ flexDirection: "column",
546
+ gap: "12px",
547
+ borderTop: `1px solid ${theme.palette.divider}`,
548
+ borderRight: `1px solid ${theme.palette.divider}`,
549
+ borderBottom: `1px solid ${theme.palette.divider}`,
550
+ borderLeft: `4px solid ${theme.palette.chart.series1Fg}`
551
+ // Primary Accent line
552
+ },
553
+ children: [
554
+ /* @__PURE__ */ jsx(
555
+ Typography$1,
556
+ {
557
+ variant: "body2",
558
+ sx: {
559
+ fontWeight: 600,
560
+ color: theme.palette.text.primary,
561
+ marginBottom: "4px"
562
+ },
563
+ children: formatDate(axisValue)
564
+ }
565
+ ),
566
+ series.map((s) => {
567
+ const color = typeof s.getColor === "function" ? s.getColor(dataIndex) : s.color;
568
+ const value = s.data ? s.data[dataIndex] : null;
569
+ if (value == null) return null;
570
+ return /* @__PURE__ */ jsx(Box$1, { sx: { display: "flex", flexDirection: "column", gap: "6px" }, children: /* @__PURE__ */ jsxs(Box$1, { sx: { display: "flex", alignItems: "center", gap: "8px" }, children: [
571
+ /* @__PURE__ */ jsx(
572
+ Box$1,
573
+ {
574
+ sx: {
575
+ width: 16,
576
+ height: 16,
577
+ borderRadius: "4px",
578
+ backgroundColor: color,
579
+ flexShrink: 0
580
+ }
581
+ }
582
+ ),
583
+ /* @__PURE__ */ jsxs(
584
+ Typography$1,
585
+ {
586
+ variant: "body2",
587
+ sx: {
588
+ color: theme.palette.text.secondary,
589
+ display: "flex",
590
+ alignItems: "center",
591
+ gap: "6px"
592
+ },
593
+ children: [
594
+ /* @__PURE__ */ jsx(
595
+ Box$1,
596
+ {
597
+ component: "span",
598
+ sx: {
599
+ backgroundColor: theme.palette.grey[50] || "#f9fafb",
600
+ padding: "2px 6px",
601
+ borderRadius: "4px",
602
+ fontWeight: 500,
603
+ color: theme.palette.text.primary,
604
+ border: `1px solid ${theme.palette.divider}`
605
+ },
606
+ children: renderValue(value)
607
+ }
608
+ ),
609
+ " ",
610
+ "events"
611
+ ]
612
+ }
613
+ )
614
+ ] }) }, s.id);
615
+ })
616
+ ]
617
+ }
618
+ );
619
+ }
620
+ function LineChart({ series, colors: colors2, palette = "categorical", ...props }) {
621
+ var _a, _b;
622
+ const theme = useTheme();
623
+ const chart = theme.palette.chart;
624
+ const seriesColors = useChartColors((_a = series == null ? void 0 : series.length) != null ? _a : 0, palette);
625
+ const modifiedSeries = series == null ? void 0 : series.map((s) => {
626
+ var _a2, _b2;
627
+ return {
628
+ ...s,
629
+ curve: (_a2 = s.curve) != null ? _a2 : "monotoneX",
630
+ highlightScope: (_b2 = s.highlightScope) != null ? _b2 : { highlighted: "item", faded: "global" }
631
+ };
632
+ });
633
+ return /* @__PURE__ */ jsx(
634
+ LineChart$1,
635
+ {
636
+ series: modifiedSeries != null ? modifiedSeries : [],
637
+ colors: colors2 != null ? colors2 : seriesColors,
638
+ grid: { horizontal: true },
639
+ slots: {
640
+ axisContent: CustomTooltip
641
+ },
642
+ slotProps: {
643
+ legend: {
644
+ itemMarkWidth: 12,
645
+ itemMarkHeight: 12,
646
+ padding: { bottom: 20 }
647
+ }
648
+ },
649
+ sx: {
650
+ "& .MuiChartsAxis-line": { stroke: chart.axisFg },
651
+ "& .MuiChartsAxis-tick": { stroke: chart.axisFg },
652
+ "& .MuiChartsAxis-tickLabel": {
653
+ fill: chart.labelFg,
654
+ fontFamily: theme.typography.fontFamily,
655
+ fontSize: typeof theme.typography.body2.fontSize === "number" ? theme.typography.body2.fontSize : 12
656
+ },
657
+ "& .MuiChartsAxis-label": {
658
+ fill: chart.labelFgEmphasis,
659
+ fontFamily: theme.typography.fontFamily,
660
+ fontSize: typeof theme.typography.body1.fontSize === "number" ? theme.typography.body1.fontSize : 14,
661
+ fontWeight: theme.typography.fontWeightMedium
662
+ },
663
+ "& .MuiChartsGrid-line": {
664
+ stroke: chart.gridlineFg,
665
+ strokeDasharray: "4 4"
666
+ },
667
+ "& .MuiChartsLegend-series text": {
668
+ fill: chart.legendFg,
669
+ fontFamily: theme.typography.fontFamily,
670
+ fontSize: "14px !important"
671
+ },
672
+ "& .MuiChartsLegend-mark": {
673
+ ry: 4,
674
+ rx: 4,
675
+ width: 12,
676
+ height: 12
677
+ },
678
+ "& .MuiChartsTooltip-root": {
679
+ fontFamily: theme.typography.fontFamily,
680
+ fontSize: typeof theme.typography.body1.fontSize === "number" ? theme.typography.body1.fontSize : 14
681
+ },
682
+ "& .MuiChartsTooltip-table": {
683
+ backgroundColor: chart.tooltipBg,
684
+ color: chart.tooltipFg,
685
+ borderRadius: theme.shape.borderRadius,
686
+ boxShadow: theme.shadows[4]
687
+ },
688
+ "& .MuiLineElement-root": {
689
+ strokeWidth: 3
690
+ // Thicker lines for line charts
691
+ },
692
+ ...(_b = props.sx) != null ? _b : {}
693
+ },
694
+ ...props
695
+ }
696
+ );
697
+ }
698
+ function BarChart({ series, colors: colors2, palette = "categorical", ...props }) {
699
+ var _a, _b;
700
+ const theme = useTheme();
701
+ const chart = theme.palette.chart;
702
+ const seriesColors = useChartColors((_a = series == null ? void 0 : series.length) != null ? _a : 0, palette);
703
+ const resolvedColors = colors2 != null ? colors2 : seriesColors;
704
+ const modifiedSeries = series == null ? void 0 : series.map((s, idx) => {
705
+ var _a2;
706
+ const baseColor = s.color || resolvedColors[idx % resolvedColors.length];
707
+ const actualColor = s.variant === "striped" ? `url(#striped-pattern-${idx})` : baseColor;
708
+ const { variant, ...rest } = s;
709
+ return {
710
+ ...rest,
711
+ color: actualColor,
712
+ highlightScope: (_a2 = s.highlightScope) != null ? _a2 : { highlighted: "item", faded: "global" }
713
+ };
714
+ });
715
+ return /* @__PURE__ */ jsx(
716
+ BarChart$1,
717
+ {
718
+ series: modifiedSeries != null ? modifiedSeries : [],
719
+ colors: colors2 != null ? colors2 : seriesColors,
720
+ grid: { horizontal: true },
721
+ borderRadius: 4,
722
+ slots: {
723
+ axisContent: CustomTooltip
724
+ },
725
+ slotProps: {
726
+ legend: {
727
+ itemMarkWidth: 12,
728
+ itemMarkHeight: 12,
729
+ padding: { bottom: 20 }
730
+ }
731
+ },
732
+ sx: {
733
+ "& .MuiChartsAxis-line": { stroke: chart.axisFg },
734
+ "& .MuiChartsAxis-tick": { stroke: chart.axisFg },
735
+ "& .MuiChartsAxis-tickLabel": {
736
+ fill: chart.labelFg,
737
+ fontFamily: theme.typography.fontFamily,
738
+ fontSize: typeof theme.typography.body2.fontSize === "number" ? theme.typography.body2.fontSize : 12
739
+ // fallback to xs value conceptually if needed
740
+ },
741
+ "& .MuiChartsAxis-label": {
742
+ fill: chart.labelFgEmphasis,
743
+ fontFamily: theme.typography.fontFamily,
744
+ fontSize: typeof theme.typography.body1.fontSize === "number" ? theme.typography.body1.fontSize : 14,
745
+ fontWeight: theme.typography.fontWeightMedium
746
+ },
747
+ "& .MuiChartsGrid-line": {
748
+ stroke: chart.gridlineFg,
749
+ strokeDasharray: "4 4"
750
+ },
751
+ "& .MuiChartsLegend-series text": {
752
+ fill: chart.legendFg,
753
+ fontFamily: theme.typography.fontFamily,
754
+ fontSize: "14px !important"
755
+ },
756
+ "& .MuiChartsLegend-mark": {
757
+ ry: 4,
758
+ rx: 4,
759
+ width: 12,
760
+ height: 12
761
+ },
762
+ "& .MuiChartsTooltip-root": {
763
+ fontFamily: theme.typography.fontFamily,
764
+ fontSize: typeof theme.typography.body1.fontSize === "number" ? theme.typography.body1.fontSize : 14
765
+ },
766
+ "& .MuiChartsTooltip-table": {
767
+ backgroundColor: chart.tooltipBg,
768
+ color: chart.tooltipFg,
769
+ borderRadius: theme.shape.borderRadius,
770
+ boxShadow: theme.shadows[4]
771
+ // md equivalent in MUI default array length
772
+ },
773
+ ...(_b = props.sx) != null ? _b : {}
774
+ },
775
+ ...props,
776
+ children: /* @__PURE__ */ jsx("defs", { children: series == null ? void 0 : series.map((s, idx) => {
777
+ if (s.variant !== "striped") return null;
778
+ const baseColor = s.color || resolvedColors[idx % resolvedColors.length];
779
+ return /* @__PURE__ */ jsxs(
780
+ "pattern",
781
+ {
782
+ id: `striped-pattern-${idx}`,
783
+ patternUnits: "userSpaceOnUse",
784
+ width: "8",
785
+ height: "8",
786
+ patternTransform: "rotate(45)",
787
+ children: [
788
+ /* @__PURE__ */ jsx("rect", { width: "8", height: "8", fill: theme.palette.background.paper }),
789
+ /* @__PURE__ */ jsx("line", { x1: "0", y: "0", x2: "0", y2: "8", stroke: baseColor, strokeWidth: "4" })
790
+ ]
791
+ },
792
+ `striped-${idx}`
793
+ );
794
+ }) })
795
+ }
796
+ );
797
+ }
798
+ function PieChart({ series, colors: colors2, palette = "categorical", ...props }) {
799
+ var _a, _b, _c, _d;
800
+ const theme = useTheme();
801
+ const chart = theme.palette.chart;
802
+ const sliceCount = (_c = (_b = (_a = series == null ? void 0 : series[0]) == null ? void 0 : _a.data) == null ? void 0 : _b.length) != null ? _c : 0;
803
+ const seriesColors = useChartColors(sliceCount, palette);
804
+ const modifiedSeries = series == null ? void 0 : series.map((s) => {
805
+ var _a2;
806
+ return {
807
+ ...s,
808
+ highlightScope: (_a2 = s.highlightScope) != null ? _a2 : { highlighted: "item", faded: "global" }
809
+ };
810
+ });
811
+ return /* @__PURE__ */ jsx(
812
+ PieChart$1,
813
+ {
814
+ series: modifiedSeries != null ? modifiedSeries : [],
815
+ colors: colors2 != null ? colors2 : seriesColors,
816
+ slotProps: {
817
+ legend: {
818
+ itemMarkWidth: 12,
819
+ itemMarkHeight: 12,
820
+ padding: { bottom: 20 }
821
+ }
822
+ },
823
+ sx: {
824
+ "& .MuiChartsLegend-series text": {
825
+ fill: chart.legendFg,
826
+ fontFamily: theme.typography.fontFamily,
827
+ fontSize: "14px !important"
828
+ },
829
+ "& .MuiChartsLegend-mark": {
830
+ ry: 4,
831
+ rx: 4,
832
+ width: 12,
833
+ height: 12
834
+ },
835
+ "& .MuiChartsTooltip-root": {
836
+ fontFamily: theme.typography.fontFamily,
837
+ fontSize: typeof theme.typography.body1.fontSize === "number" ? theme.typography.body1.fontSize : 14
838
+ },
839
+ "& .MuiChartsTooltip-table": {
840
+ backgroundColor: chart.tooltipBg,
841
+ color: chart.tooltipFg,
842
+ borderRadius: theme.shape.borderRadius,
843
+ boxShadow: theme.shadows[4]
844
+ },
845
+ ...(_d = props.sx) != null ? _d : {}
846
+ },
847
+ ...props
848
+ }
849
+ );
850
+ }
434
851
 
435
- export { Accordion, AccordionActions, AccordionDetails, AccordionSummary, Alert, AlertTitle, AppBar, Autocomplete, Backdrop, Badge, Button, ButtonGroup, Card, CardActions, CardContent, CardHeader, CardMedia, Checkbox, Chip, CircularProgress, DataGrid, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, Divider, Fab, ForestProvider, LinearProgress, List, ListItem, ListItemAvatar, ListItemButton, ListItemIcon, ListItemText, ListSubheader, MenuItem, Paper, Radio, RadioGroup, Select, SidebarItem, SidebarNav, Skeleton, Snackbar, Switch, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, TextField, ToggleButton, ToggleButtonGroup, Toolbar, Tooltip, Typography, useSidebar };
852
+ export { Accordion, AccordionActions, AccordionDetails, AccordionSummary, Alert, AlertTitle, AppBar, Autocomplete, Backdrop, Badge, BarChart, Button, ButtonGroup, Card, CardActions, CardContent, CardHeader, CardMedia, Checkbox, Chip, CircularProgress, DataGrid, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, Divider, Fab, ForestProvider, LineChart, LinearProgress, List, ListItem, ListItemAvatar, ListItemButton, ListItemIcon, ListItemText, ListSubheader, MenuItem, MultiSelect, Paper, PieChart, Radio, RadioGroup, Select, SidebarItem, SidebarNav, Skeleton, Snackbar, Switch, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, TextField, ToggleButton, ToggleButtonGroup, Toolbar, Tooltip, Typography, useChartColors, useSidebar };
436
853
  //# sourceMappingURL=index.mjs.map
437
854
  //# sourceMappingURL=index.mjs.map