@loomui-ng/ui 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +46 -2
- package/accordion/README.md +38 -0
- package/alert/README.md +32 -0
- package/alert-dialog/README.md +37 -0
- package/aspect-ratio/README.md +24 -0
- package/attachment/README.md +40 -0
- package/avatar/README.md +34 -0
- package/badge/README.md +29 -0
- package/breadcrumb/README.md +33 -0
- package/bubble/README.md +32 -0
- package/button/README.md +31 -0
- package/button-group/README.md +30 -0
- package/calendar/README.md +35 -0
- package/card/README.md +41 -0
- package/carousel/README.md +41 -0
- package/chart/README.md +25 -0
- package/checkbox/README.md +31 -0
- package/collapsible/README.md +31 -0
- package/combobox/README.md +47 -0
- package/command/README.md +44 -0
- package/context-menu/README.md +36 -0
- package/data-table/README.md +39 -0
- package/date-picker/README.md +23 -0
- package/dialog/README.md +52 -0
- package/direction/README.md +19 -0
- package/drawer/README.md +37 -0
- package/dropdown-menu/README.md +46 -0
- package/empty/README.md +38 -0
- package/fesm2022/loomui-ng-ui-accordion.mjs +555 -0
- package/fesm2022/loomui-ng-ui-accordion.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-alert-dialog.mjs +652 -0
- package/fesm2022/loomui-ng-ui-alert-dialog.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-alert.mjs +286 -0
- package/fesm2022/loomui-ng-ui-alert.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-aspect-ratio.mjs +97 -0
- package/fesm2022/loomui-ng-ui-aspect-ratio.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-attachment.mjs +713 -0
- package/fesm2022/loomui-ng-ui-attachment.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-avatar.mjs +561 -0
- package/fesm2022/loomui-ng-ui-avatar.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-badge.mjs +102 -0
- package/fesm2022/loomui-ng-ui-badge.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-breadcrumb.mjs +520 -0
- package/fesm2022/loomui-ng-ui-breadcrumb.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-bubble.mjs +386 -0
- package/fesm2022/loomui-ng-ui-bubble.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-button-group.mjs +193 -0
- package/fesm2022/loomui-ng-ui-button-group.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-button.mjs +162 -0
- package/fesm2022/loomui-ng-ui-button.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-calendar.mjs +681 -0
- package/fesm2022/loomui-ng-ui-calendar.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-card.mjs +461 -0
- package/fesm2022/loomui-ng-ui-card.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-carousel.mjs +532 -0
- package/fesm2022/loomui-ng-ui-carousel.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-chart.mjs +373 -0
- package/fesm2022/loomui-ng-ui-chart.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-checkbox.mjs +265 -0
- package/fesm2022/loomui-ng-ui-checkbox.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-collapsible.mjs +274 -0
- package/fesm2022/loomui-ng-ui-collapsible.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-combobox.mjs +971 -0
- package/fesm2022/loomui-ng-ui-combobox.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-command.mjs +982 -0
- package/fesm2022/loomui-ng-ui-command.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-context-menu.mjs +1359 -0
- package/fesm2022/loomui-ng-ui-context-menu.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-data-table.mjs +535 -0
- package/fesm2022/loomui-ng-ui-data-table.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-date-picker.mjs +312 -0
- package/fesm2022/loomui-ng-ui-date-picker.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-dialog.mjs +508 -0
- package/fesm2022/loomui-ng-ui-dialog.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-direction.mjs +112 -0
- package/fesm2022/loomui-ng-ui-direction.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-drawer.mjs +590 -0
- package/fesm2022/loomui-ng-ui-drawer.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-dropdown-menu.mjs +1322 -0
- package/fesm2022/loomui-ng-ui-dropdown-menu.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-empty.mjs +408 -0
- package/fesm2022/loomui-ng-ui-empty.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-field.mjs +630 -0
- package/fesm2022/loomui-ng-ui-field.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-hover-card.mjs +230 -0
- package/fesm2022/loomui-ng-ui-hover-card.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-icon.mjs +498 -0
- package/fesm2022/loomui-ng-ui-icon.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-input-group.mjs +463 -0
- package/fesm2022/loomui-ng-ui-input-group.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-input-otp.mjs +586 -0
- package/fesm2022/loomui-ng-ui-input-otp.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-input.mjs +289 -0
- package/fesm2022/loomui-ng-ui-input.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-item.mjs +598 -0
- package/fesm2022/loomui-ng-ui-item.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-kbd.mjs +129 -0
- package/fesm2022/loomui-ng-ui-kbd.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-label.mjs +68 -0
- package/fesm2022/loomui-ng-ui-label.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-marker.mjs +234 -0
- package/fesm2022/loomui-ng-ui-marker.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-menubar.mjs +1523 -0
- package/fesm2022/loomui-ng-ui-menubar.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-message-scroller.mjs +519 -0
- package/fesm2022/loomui-ng-ui-message-scroller.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-message.mjs +408 -0
- package/fesm2022/loomui-ng-ui-message.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-native-select.mjs +389 -0
- package/fesm2022/loomui-ng-ui-native-select.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-navigation-menu.mjs +609 -0
- package/fesm2022/loomui-ng-ui-navigation-menu.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-pagination.mjs +611 -0
- package/fesm2022/loomui-ng-ui-pagination.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-popover.mjs +358 -0
- package/fesm2022/loomui-ng-ui-popover.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-progress.mjs +159 -0
- package/fesm2022/loomui-ng-ui-progress.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-questionnaire.mjs +1012 -0
- package/fesm2022/loomui-ng-ui-questionnaire.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-radio-group.mjs +399 -0
- package/fesm2022/loomui-ng-ui-radio-group.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-resizable.mjs +518 -0
- package/fesm2022/loomui-ng-ui-resizable.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-scroll-area.mjs +135 -0
- package/fesm2022/loomui-ng-ui-scroll-area.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-select.mjs +863 -0
- package/fesm2022/loomui-ng-ui-select.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-separator.mjs +114 -0
- package/fesm2022/loomui-ng-ui-separator.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-sheet.mjs +530 -0
- package/fesm2022/loomui-ng-ui-sheet.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-sidebar.mjs +1918 -0
- package/fesm2022/loomui-ng-ui-sidebar.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-skeleton.mjs +69 -0
- package/fesm2022/loomui-ng-ui-skeleton.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-slider.mjs +390 -0
- package/fesm2022/loomui-ng-ui-slider.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-spinner.mjs +85 -0
- package/fesm2022/loomui-ng-ui-spinner.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-switch.mjs +212 -0
- package/fesm2022/loomui-ng-ui-switch.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-table.mjs +559 -0
- package/fesm2022/loomui-ng-ui-table.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-tabs.mjs +544 -0
- package/fesm2022/loomui-ng-ui-tabs.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-textarea.mjs +206 -0
- package/fesm2022/loomui-ng-ui-textarea.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-toast.mjs +432 -0
- package/fesm2022/loomui-ng-ui-toast.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-toggle-group.mjs +477 -0
- package/fesm2022/loomui-ng-ui-toggle-group.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-toggle.mjs +219 -0
- package/fesm2022/loomui-ng-ui-toggle.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-tooltip.mjs +240 -0
- package/fesm2022/loomui-ng-ui-tooltip.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-typography.mjs +129 -0
- package/fesm2022/loomui-ng-ui-typography.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui-utils.mjs +1533 -0
- package/fesm2022/loomui-ng-ui-utils.mjs.map +1 -0
- package/fesm2022/loomui-ng-ui.mjs +4 -0
- package/fesm2022/loomui-ng-ui.mjs.map +1 -0
- package/field/README.md +43 -0
- package/hover-card/README.md +31 -0
- package/icon/README.md +42 -0
- package/input/README.md +26 -0
- package/input-group/README.md +40 -0
- package/input-otp/README.md +35 -0
- package/item/README.md +33 -0
- package/kbd/README.md +21 -0
- package/label/README.md +24 -0
- package/marker/README.md +24 -0
- package/menubar/README.md +40 -0
- package/message/README.md +32 -0
- package/message-scroller/README.md +40 -0
- package/native-select/README.md +26 -0
- package/navigation-menu/README.md +39 -0
- package/package.json +325 -3
- package/pagination/README.md +37 -0
- package/popover/README.md +37 -0
- package/progress/README.md +25 -0
- package/questionnaire/README.md +52 -0
- package/radio-group/README.md +33 -0
- package/resizable/README.md +37 -0
- package/scroll-area/README.md +25 -0
- package/select/README.md +45 -0
- package/separator/README.md +28 -0
- package/sheet/README.md +38 -0
- package/sidebar/README.md +60 -0
- package/skeleton/README.md +21 -0
- package/slider/README.md +29 -0
- package/spinner/README.md +15 -0
- package/styles/loomui.css +330 -0
- package/switch/README.md +29 -0
- package/table/README.md +31 -0
- package/tabs/README.md +42 -0
- package/textarea/README.md +28 -0
- package/toast/README.md +27 -0
- package/toggle/README.md +27 -0
- package/toggle-group/README.md +37 -0
- package/tooltip/README.md +31 -0
- package/types/loomui-ng-ui-accordion.d.ts +141 -0
- package/types/loomui-ng-ui-alert-dialog.d.ts +175 -0
- package/types/loomui-ng-ui-alert.d.ts +77 -0
- package/types/loomui-ng-ui-aspect-ratio.d.ts +31 -0
- package/types/loomui-ng-ui-attachment.d.ts +192 -0
- package/types/loomui-ng-ui-avatar.d.ts +147 -0
- package/types/loomui-ng-ui-badge.d.ts +32 -0
- package/types/loomui-ng-ui-breadcrumb.d.ts +118 -0
- package/types/loomui-ng-ui-bubble.d.ts +100 -0
- package/types/loomui-ng-ui-button-group.d.ts +51 -0
- package/types/loomui-ng-ui-button.d.ts +57 -0
- package/types/loomui-ng-ui-calendar.d.ts +171 -0
- package/types/loomui-ng-ui-card.d.ts +123 -0
- package/types/loomui-ng-ui-carousel.d.ts +140 -0
- package/types/loomui-ng-ui-chart.d.ts +95 -0
- package/types/loomui-ng-ui-checkbox.d.ts +62 -0
- package/types/loomui-ng-ui-collapsible.d.ts +74 -0
- package/types/loomui-ng-ui-combobox.d.ts +229 -0
- package/types/loomui-ng-ui-command.d.ts +231 -0
- package/types/loomui-ng-ui-context-menu.d.ts +288 -0
- package/types/loomui-ng-ui-data-table.d.ts +111 -0
- package/types/loomui-ng-ui-date-picker.d.ts +63 -0
- package/types/loomui-ng-ui-dialog.d.ts +127 -0
- package/types/loomui-ng-ui-direction.d.ts +42 -0
- package/types/loomui-ng-ui-drawer.d.ts +149 -0
- package/types/loomui-ng-ui-dropdown-menu.d.ts +258 -0
- package/types/loomui-ng-ui-empty.d.ts +109 -0
- package/types/loomui-ng-ui-field.d.ts +169 -0
- package/types/loomui-ng-ui-hover-card.d.ts +62 -0
- package/types/loomui-ng-ui-icon.d.ts +156 -0
- package/types/loomui-ng-ui-input-group.d.ts +130 -0
- package/types/loomui-ng-ui-input-otp.d.ts +149 -0
- package/types/loomui-ng-ui-input.d.ts +89 -0
- package/types/loomui-ng-ui-item.d.ts +157 -0
- package/types/loomui-ng-ui-kbd.d.ts +36 -0
- package/types/loomui-ng-ui-label.d.ts +19 -0
- package/types/loomui-ng-ui-marker.d.ts +61 -0
- package/types/loomui-ng-ui-menubar.d.ts +321 -0
- package/types/loomui-ng-ui-message-scroller.d.ts +138 -0
- package/types/loomui-ng-ui-message.d.ts +109 -0
- package/types/loomui-ng-ui-native-select.d.ts +84 -0
- package/types/loomui-ng-ui-navigation-menu.d.ts +160 -0
- package/types/loomui-ng-ui-pagination.d.ts +130 -0
- package/types/loomui-ng-ui-popover.d.ts +90 -0
- package/types/loomui-ng-ui-progress.d.ts +39 -0
- package/types/loomui-ng-ui-questionnaire.d.ts +274 -0
- package/types/loomui-ng-ui-radio-group.d.ts +109 -0
- package/types/loomui-ng-ui-resizable.d.ts +121 -0
- package/types/loomui-ng-ui-scroll-area.d.ts +44 -0
- package/types/loomui-ng-ui-select.d.ts +204 -0
- package/types/loomui-ng-ui-separator.d.ts +35 -0
- package/types/loomui-ng-ui-sheet.d.ts +124 -0
- package/types/loomui-ng-ui-sidebar.d.ts +485 -0
- package/types/loomui-ng-ui-skeleton.d.ts +20 -0
- package/types/loomui-ng-ui-slider.d.ts +103 -0
- package/types/loomui-ng-ui-spinner.d.ts +19 -0
- package/types/loomui-ng-ui-switch.d.ts +56 -0
- package/types/loomui-ng-ui-table.d.ts +148 -0
- package/types/loomui-ng-ui-tabs.d.ts +148 -0
- package/types/loomui-ng-ui-textarea.d.ts +52 -0
- package/types/loomui-ng-ui-toast.d.ts +97 -0
- package/types/loomui-ng-ui-toggle-group.d.ts +138 -0
- package/types/loomui-ng-ui-toggle.d.ts +63 -0
- package/types/loomui-ng-ui-tooltip.d.ts +63 -0
- package/types/loomui-ng-ui-typography.d.ts +42 -0
- package/types/loomui-ng-ui-utils.d.ts +392 -0
- package/types/loomui-ng-ui.d.ts +5 -0
- package/typography/README.md +29 -0
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { ChangeDetectionStrategy, Component, DestroyRef, ElementRef, afterNextRender, computed, effect, inject, input, viewChild } from "@angular/core";
|
|
3
|
+
import { Chart, registerables } from "chart.js";
|
|
4
|
+
import { cn } from "@loomui-ng/ui/utils";
|
|
5
|
+
Chart.register(...registerables);
|
|
6
|
+
var UiChart = class UiChart {
|
|
7
|
+
static n = 0;
|
|
8
|
+
chartId = `chart-${++UiChart.n}`;
|
|
9
|
+
host = inject(ElementRef).nativeElement;
|
|
10
|
+
canvas = viewChild.required("canvas", ...ngDevMode ? [{ debugName: "canvas" }] : /* istanbul ignore next */ []);
|
|
11
|
+
type = input("bar", ...ngDevMode ? [{ debugName: "type" }] : /* istanbul ignore next */ []);
|
|
12
|
+
data = input.required(...ngDevMode ? [{ debugName: "data" }] : /* istanbul ignore next */ []);
|
|
13
|
+
xKey = input.required(...ngDevMode ? [{ debugName: "xKey" }] : /* istanbul ignore next */ []);
|
|
14
|
+
valueKey = input("", ...ngDevMode ? [{ debugName: "valueKey" }] : /* istanbul ignore next */ []);
|
|
15
|
+
config = input.required(...ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []);
|
|
16
|
+
options = input({}, ...ngDevMode ? [{ debugName: "options" }] : /* istanbul ignore next */ []);
|
|
17
|
+
showLegend = input(true, ...ngDevMode ? [{ debugName: "showLegend" }] : /* istanbul ignore next */ []);
|
|
18
|
+
label = input("Chart", ...ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []);
|
|
19
|
+
userClass = input("", {
|
|
20
|
+
...ngDevMode ? { debugName: "userClass" } : /* istanbul ignore next */ {},
|
|
21
|
+
alias: "class"
|
|
22
|
+
});
|
|
23
|
+
destroyRef = inject(DestroyRef);
|
|
24
|
+
chart = null;
|
|
25
|
+
ready = false;
|
|
26
|
+
classes = computed(() => cn("flex aspect-video min-w-0 flex-col justify-center text-xs [&_canvas]:max-w-full", this.userClass()), ...ngDevMode ? [{ debugName: "classes" }] : /* istanbul ignore next */ []);
|
|
27
|
+
cssVars = computed(() => {
|
|
28
|
+
const out = {};
|
|
29
|
+
for (const [k, v] of Object.entries(this.config())) out[`--color-${k}`] = v.color;
|
|
30
|
+
return out;
|
|
31
|
+
}, ...ngDevMode ? [{ debugName: "cssVars" }] : /* istanbul ignore next */ []);
|
|
32
|
+
circular = computed(() => this.type() === "pie" || this.type() === "doughnut" || this.type() === "polarArea", ...ngDevMode ? [{ debugName: "circular" }] : /* istanbul ignore next */ []);
|
|
33
|
+
legend = computed(() => {
|
|
34
|
+
const cfg = this.config();
|
|
35
|
+
return (this.circular() ? this.data().map((r) => String(r[this.xKey()])) : Object.keys(cfg)).filter((k) => cfg[k]).map((k) => ({
|
|
36
|
+
key: k,
|
|
37
|
+
label: cfg[k].label,
|
|
38
|
+
color: cfg[k].color
|
|
39
|
+
}));
|
|
40
|
+
}, ...ngDevMode ? [{ debugName: "legend" }] : /* istanbul ignore next */ []);
|
|
41
|
+
constructor() {
|
|
42
|
+
afterNextRender(() => {
|
|
43
|
+
this.ready = true;
|
|
44
|
+
this.render();
|
|
45
|
+
const mo = new MutationObserver(() => this.render());
|
|
46
|
+
mo.observe(document.documentElement, {
|
|
47
|
+
attributes: true,
|
|
48
|
+
attributeFilter: ["class"]
|
|
49
|
+
});
|
|
50
|
+
this.destroyRef.onDestroy(() => {
|
|
51
|
+
mo.disconnect();
|
|
52
|
+
this.chart?.destroy();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
effect(() => {
|
|
56
|
+
this.type();
|
|
57
|
+
this.data();
|
|
58
|
+
this.config();
|
|
59
|
+
this.options();
|
|
60
|
+
this.xKey();
|
|
61
|
+
this.valueKey();
|
|
62
|
+
if (this.ready) this.render();
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
resolve(color) {
|
|
66
|
+
const probe = this.host;
|
|
67
|
+
const m = /^var\((--[\w-]+)\)$/.exec(color.trim());
|
|
68
|
+
if (!m) return color;
|
|
69
|
+
return getComputedStyle(probe).getPropertyValue(m[1]).trim() || color;
|
|
70
|
+
}
|
|
71
|
+
render() {
|
|
72
|
+
const cfg = this.config();
|
|
73
|
+
const rows = this.data();
|
|
74
|
+
const x = this.xKey();
|
|
75
|
+
const fg = getComputedStyle(this.host).getPropertyValue("--muted-foreground").trim() || "#888";
|
|
76
|
+
const grid = getComputedStyle(this.host).getPropertyValue("--border").trim() || "#8884";
|
|
77
|
+
const type = this.type();
|
|
78
|
+
const labels = rows.map((r) => String(r[x]));
|
|
79
|
+
const datasets = this.circular() ? [{
|
|
80
|
+
label: this.label(),
|
|
81
|
+
data: rows.map((r) => Number(r[this.valueKey()])),
|
|
82
|
+
backgroundColor: labels.map((l) => this.resolve(cfg[l]?.color ?? "#888")),
|
|
83
|
+
borderWidth: 0
|
|
84
|
+
}] : Object.entries(cfg).map(([key, c]) => ({
|
|
85
|
+
label: c.label,
|
|
86
|
+
data: rows.map((r) => Number(r[key])),
|
|
87
|
+
backgroundColor: this.resolve(c.color),
|
|
88
|
+
borderColor: this.resolve(c.color),
|
|
89
|
+
borderRadius: type === "bar" ? 4 : 0,
|
|
90
|
+
borderWidth: type === "bar" ? 0 : 2,
|
|
91
|
+
tension: .3,
|
|
92
|
+
pointRadius: type === "line" ? 0 : 3,
|
|
93
|
+
fill: false
|
|
94
|
+
}));
|
|
95
|
+
const tooltipBg = getComputedStyle(this.host).getPropertyValue("--background").trim() || "#fff";
|
|
96
|
+
const tooltipFg = getComputedStyle(this.host).getPropertyValue("--foreground").trim() || "#000";
|
|
97
|
+
const options = {
|
|
98
|
+
responsive: true,
|
|
99
|
+
maintainAspectRatio: false,
|
|
100
|
+
animation: { duration: 400 },
|
|
101
|
+
plugins: {
|
|
102
|
+
legend: { display: false },
|
|
103
|
+
tooltip: {
|
|
104
|
+
backgroundColor: tooltipBg,
|
|
105
|
+
titleColor: tooltipFg,
|
|
106
|
+
bodyColor: tooltipFg,
|
|
107
|
+
borderColor: grid,
|
|
108
|
+
borderWidth: 1,
|
|
109
|
+
cornerRadius: 8,
|
|
110
|
+
padding: 10,
|
|
111
|
+
boxPadding: 4,
|
|
112
|
+
usePointStyle: false
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
scales: this.circular() || type === "radar" ? {} : {
|
|
116
|
+
x: {
|
|
117
|
+
grid: { display: false },
|
|
118
|
+
border: { display: false },
|
|
119
|
+
ticks: { color: fg }
|
|
120
|
+
},
|
|
121
|
+
y: {
|
|
122
|
+
grid: { color: grid },
|
|
123
|
+
border: { display: false },
|
|
124
|
+
ticks: { color: fg }
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
...this.options()
|
|
128
|
+
};
|
|
129
|
+
const config = {
|
|
130
|
+
type,
|
|
131
|
+
data: {
|
|
132
|
+
labels,
|
|
133
|
+
datasets
|
|
134
|
+
},
|
|
135
|
+
options
|
|
136
|
+
};
|
|
137
|
+
if (this.chart && this.chart.config.type === type) {
|
|
138
|
+
this.chart.data = {
|
|
139
|
+
labels,
|
|
140
|
+
datasets
|
|
141
|
+
};
|
|
142
|
+
this.chart.options = options;
|
|
143
|
+
this.chart.update();
|
|
144
|
+
} else {
|
|
145
|
+
this.chart?.destroy();
|
|
146
|
+
this.chart = new Chart(this.canvas().nativeElement, config);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
150
|
+
minVersion: "12.0.0",
|
|
151
|
+
version: "22.2.2",
|
|
152
|
+
ngImport: i0,
|
|
153
|
+
type: UiChart,
|
|
154
|
+
deps: [],
|
|
155
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
156
|
+
});
|
|
157
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
158
|
+
minVersion: "17.0.0",
|
|
159
|
+
version: "22.2.2",
|
|
160
|
+
type: UiChart,
|
|
161
|
+
isStandalone: true,
|
|
162
|
+
selector: "ui-chart",
|
|
163
|
+
inputs: {
|
|
164
|
+
type: {
|
|
165
|
+
classPropertyName: "type",
|
|
166
|
+
publicName: "type",
|
|
167
|
+
isSignal: true,
|
|
168
|
+
isRequired: false,
|
|
169
|
+
transformFunction: null
|
|
170
|
+
},
|
|
171
|
+
data: {
|
|
172
|
+
classPropertyName: "data",
|
|
173
|
+
publicName: "data",
|
|
174
|
+
isSignal: true,
|
|
175
|
+
isRequired: true,
|
|
176
|
+
transformFunction: null
|
|
177
|
+
},
|
|
178
|
+
xKey: {
|
|
179
|
+
classPropertyName: "xKey",
|
|
180
|
+
publicName: "xKey",
|
|
181
|
+
isSignal: true,
|
|
182
|
+
isRequired: true,
|
|
183
|
+
transformFunction: null
|
|
184
|
+
},
|
|
185
|
+
valueKey: {
|
|
186
|
+
classPropertyName: "valueKey",
|
|
187
|
+
publicName: "valueKey",
|
|
188
|
+
isSignal: true,
|
|
189
|
+
isRequired: false,
|
|
190
|
+
transformFunction: null
|
|
191
|
+
},
|
|
192
|
+
config: {
|
|
193
|
+
classPropertyName: "config",
|
|
194
|
+
publicName: "config",
|
|
195
|
+
isSignal: true,
|
|
196
|
+
isRequired: true,
|
|
197
|
+
transformFunction: null
|
|
198
|
+
},
|
|
199
|
+
options: {
|
|
200
|
+
classPropertyName: "options",
|
|
201
|
+
publicName: "options",
|
|
202
|
+
isSignal: true,
|
|
203
|
+
isRequired: false,
|
|
204
|
+
transformFunction: null
|
|
205
|
+
},
|
|
206
|
+
showLegend: {
|
|
207
|
+
classPropertyName: "showLegend",
|
|
208
|
+
publicName: "showLegend",
|
|
209
|
+
isSignal: true,
|
|
210
|
+
isRequired: false,
|
|
211
|
+
transformFunction: null
|
|
212
|
+
},
|
|
213
|
+
label: {
|
|
214
|
+
classPropertyName: "label",
|
|
215
|
+
publicName: "label",
|
|
216
|
+
isSignal: true,
|
|
217
|
+
isRequired: false,
|
|
218
|
+
transformFunction: null
|
|
219
|
+
},
|
|
220
|
+
userClass: {
|
|
221
|
+
classPropertyName: "userClass",
|
|
222
|
+
publicName: "class",
|
|
223
|
+
isSignal: true,
|
|
224
|
+
isRequired: false,
|
|
225
|
+
transformFunction: null
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
host: {
|
|
229
|
+
attributes: { "data-slot": "chart" },
|
|
230
|
+
properties: {
|
|
231
|
+
"attr.data-chart": "chartId",
|
|
232
|
+
"attr.class": "classes()",
|
|
233
|
+
"style": "cssVars()"
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
viewQueries: [{
|
|
237
|
+
propertyName: "canvas",
|
|
238
|
+
first: true,
|
|
239
|
+
predicate: ["canvas"],
|
|
240
|
+
descendants: true,
|
|
241
|
+
isSignal: true
|
|
242
|
+
}],
|
|
243
|
+
ngImport: i0,
|
|
244
|
+
template: `
|
|
245
|
+
<div class="relative size-full min-h-48 min-w-0 flex-1 overflow-hidden"><canvas #canvas role="img" [attr.aria-label]="label()"></canvas></div>
|
|
246
|
+
@if (showLegend()) {
|
|
247
|
+
<ul data-slot="chart-legend" class="flex items-center justify-center gap-4 pt-3 text-xs">
|
|
248
|
+
@for (item of legend(); track item.key) {
|
|
249
|
+
<li class="flex items-center gap-1.5">
|
|
250
|
+
<span class="size-2 shrink-0 rounded-[2px]" [style.background]="item.color"></span>{{ item.label }}
|
|
251
|
+
</li>
|
|
252
|
+
}
|
|
253
|
+
</ul>
|
|
254
|
+
}
|
|
255
|
+
`,
|
|
256
|
+
isInline: true,
|
|
257
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
261
|
+
minVersion: "12.0.0",
|
|
262
|
+
version: "22.2.2",
|
|
263
|
+
ngImport: i0,
|
|
264
|
+
type: UiChart,
|
|
265
|
+
decorators: [{
|
|
266
|
+
type: Component,
|
|
267
|
+
args: [{
|
|
268
|
+
selector: "ui-chart",
|
|
269
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
270
|
+
host: {
|
|
271
|
+
"data-slot": "chart",
|
|
272
|
+
"[attr.data-chart]": "chartId",
|
|
273
|
+
"[attr.class]": "classes()",
|
|
274
|
+
"[style]": "cssVars()"
|
|
275
|
+
},
|
|
276
|
+
template: `
|
|
277
|
+
<div class="relative size-full min-h-48 min-w-0 flex-1 overflow-hidden"><canvas #canvas role="img" [attr.aria-label]="label()"></canvas></div>
|
|
278
|
+
@if (showLegend()) {
|
|
279
|
+
<ul data-slot="chart-legend" class="flex items-center justify-center gap-4 pt-3 text-xs">
|
|
280
|
+
@for (item of legend(); track item.key) {
|
|
281
|
+
<li class="flex items-center gap-1.5">
|
|
282
|
+
<span class="size-2 shrink-0 rounded-[2px]" [style.background]="item.color"></span>{{ item.label }}
|
|
283
|
+
</li>
|
|
284
|
+
}
|
|
285
|
+
</ul>
|
|
286
|
+
}
|
|
287
|
+
`
|
|
288
|
+
}]
|
|
289
|
+
}],
|
|
290
|
+
ctorParameters: () => [],
|
|
291
|
+
propDecorators: {
|
|
292
|
+
canvas: [{
|
|
293
|
+
type: i0.ViewChild,
|
|
294
|
+
args: ["canvas", { isSignal: true }]
|
|
295
|
+
}],
|
|
296
|
+
type: [{
|
|
297
|
+
type: i0.Input,
|
|
298
|
+
args: [{
|
|
299
|
+
isSignal: true,
|
|
300
|
+
alias: "type",
|
|
301
|
+
required: false
|
|
302
|
+
}]
|
|
303
|
+
}],
|
|
304
|
+
data: [{
|
|
305
|
+
type: i0.Input,
|
|
306
|
+
args: [{
|
|
307
|
+
isSignal: true,
|
|
308
|
+
alias: "data",
|
|
309
|
+
required: true
|
|
310
|
+
}]
|
|
311
|
+
}],
|
|
312
|
+
xKey: [{
|
|
313
|
+
type: i0.Input,
|
|
314
|
+
args: [{
|
|
315
|
+
isSignal: true,
|
|
316
|
+
alias: "xKey",
|
|
317
|
+
required: true
|
|
318
|
+
}]
|
|
319
|
+
}],
|
|
320
|
+
valueKey: [{
|
|
321
|
+
type: i0.Input,
|
|
322
|
+
args: [{
|
|
323
|
+
isSignal: true,
|
|
324
|
+
alias: "valueKey",
|
|
325
|
+
required: false
|
|
326
|
+
}]
|
|
327
|
+
}],
|
|
328
|
+
config: [{
|
|
329
|
+
type: i0.Input,
|
|
330
|
+
args: [{
|
|
331
|
+
isSignal: true,
|
|
332
|
+
alias: "config",
|
|
333
|
+
required: true
|
|
334
|
+
}]
|
|
335
|
+
}],
|
|
336
|
+
options: [{
|
|
337
|
+
type: i0.Input,
|
|
338
|
+
args: [{
|
|
339
|
+
isSignal: true,
|
|
340
|
+
alias: "options",
|
|
341
|
+
required: false
|
|
342
|
+
}]
|
|
343
|
+
}],
|
|
344
|
+
showLegend: [{
|
|
345
|
+
type: i0.Input,
|
|
346
|
+
args: [{
|
|
347
|
+
isSignal: true,
|
|
348
|
+
alias: "showLegend",
|
|
349
|
+
required: false
|
|
350
|
+
}]
|
|
351
|
+
}],
|
|
352
|
+
label: [{
|
|
353
|
+
type: i0.Input,
|
|
354
|
+
args: [{
|
|
355
|
+
isSignal: true,
|
|
356
|
+
alias: "label",
|
|
357
|
+
required: false
|
|
358
|
+
}]
|
|
359
|
+
}],
|
|
360
|
+
userClass: [{
|
|
361
|
+
type: i0.Input,
|
|
362
|
+
args: [{
|
|
363
|
+
isSignal: true,
|
|
364
|
+
alias: "class",
|
|
365
|
+
required: false
|
|
366
|
+
}]
|
|
367
|
+
}]
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
const UI_CHART = [UiChart];
|
|
371
|
+
export { UI_CHART, UiChart };
|
|
372
|
+
|
|
373
|
+
//# sourceMappingURL=loomui-ng-ui-chart.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loomui-ng-ui-chart.mjs","names":[],"sources":["../../../libs/ui/chart/chart.ts"],"sourcesContent":["import {\n afterNextRender,\n ChangeDetectionStrategy,\n Component,\n computed,\n DestroyRef,\n effect,\n ElementRef,\n inject,\n input,\n viewChild,\n} from '@angular/core';\nimport { Chart, registerables, type ChartOptions, type ChartType } from 'chart.js';\nimport { cn } from '@loomui-ng/ui/utils';\n\nChart.register(...registerables);\n\nexport interface ChartSeriesConfig {\n label: string;\n /** CSS color, e.g. 'var(--chart-1)'. Exposed as --color-<key> on the container (as shadcn's ChartContainer does). */\n color: string;\n}\nexport type ChartConfig = Record<string, ChartSeriesConfig>;\n\n/**\n * shadcn's Chart wraps Recharts. This implementation uses Chart.js and keeps shadcn's contract:\n * a `config` maps series keys to label + color; the container exposes `--color-<key>` CSS variables; tooltip and legend\n * follow shadcn styling (card-like tooltip, small legend swatches). Data rows are plain objects.\n *\n * <ui-chart type=\"bar\" [data]=\"rows\" xKey=\"month\" [config]=\"config\" class=\"h-64 w-full\" />\n * For pie/doughnut, rows are categories: xKey = category field, valueKey = number field, config keyed by category value.\n * Deviation: Recharts-specific components (ChartTooltipContent props, <Bar radius>) have no 1:1 equivalent.\n */\n@Component({\n selector: 'ui-chart',\n changeDetection: ChangeDetectionStrategy.OnPush,\n host: {\n 'data-slot': 'chart',\n '[attr.data-chart]': 'chartId',\n '[attr.class]': 'classes()',\n '[style]': 'cssVars()',\n },\n template: `\n <div class=\"relative size-full min-h-48 min-w-0 flex-1 overflow-hidden\"><canvas #canvas role=\"img\" [attr.aria-label]=\"label()\"></canvas></div>\n @if (showLegend()) {\n <ul data-slot=\"chart-legend\" class=\"flex items-center justify-center gap-4 pt-3 text-xs\">\n @for (item of legend(); track item.key) {\n <li class=\"flex items-center gap-1.5\">\n <span class=\"size-2 shrink-0 rounded-[2px]\" [style.background]=\"item.color\"></span>{{ item.label }}\n </li>\n }\n </ul>\n }\n `,\n})\nexport class UiChart {\n private static n = 0;\n protected readonly chartId = `chart-${++UiChart.n}`;\n private readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;\n private readonly canvas = viewChild.required<ElementRef<HTMLCanvasElement>>('canvas');\n\n readonly type = input<ChartType>('bar');\n readonly data = input.required<Record<string, unknown>[]>();\n readonly xKey = input.required<string>();\n readonly valueKey = input<string>('');\n readonly config = input.required<ChartConfig>();\n readonly options = input<Record<string, any>>({});\n readonly showLegend = input(true);\n readonly label = input('Chart');\n readonly userClass = input<string>('', { alias: 'class' });\n\n private readonly destroyRef = inject(DestroyRef);\n private chart: Chart | null = null;\n private ready = false;\n\n protected readonly classes = computed(() =>\n cn('flex aspect-video min-w-0 flex-col justify-center text-xs [&_canvas]:max-w-full', this.userClass()),\n );\n protected readonly cssVars = computed(() => {\n const out: Record<string, string> = {};\n for (const [k, v] of Object.entries(this.config())) out[`--color-${k}`] = v.color;\n return out;\n });\n private readonly circular = computed(() => this.type() === 'pie' || this.type() === 'doughnut' || this.type() === 'polarArea');\n protected readonly legend = computed(() => {\n const cfg = this.config();\n const keys = this.circular() ? this.data().map((r) => String(r[this.xKey()])) : Object.keys(cfg);\n return keys.filter((k) => cfg[k]).map((k) => ({ key: k, label: cfg[k].label, color: cfg[k].color }));\n });\n\n constructor() {\n afterNextRender(() => {\n this.ready = true;\n this.render();\n const mo = new MutationObserver(() => this.render());\n mo.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });\n this.destroyRef.onDestroy(() => {\n mo.disconnect();\n this.chart?.destroy();\n });\n });\n effect(() => {\n this.type();\n this.data();\n this.config();\n this.options();\n this.xKey();\n this.valueKey();\n if (this.ready) this.render();\n });\n }\n\n /** Resolves `var(--x)` to the computed color so Chart.js (canvas) can paint it, honoring .dark. */\n private resolve(color: string): string {\n const probe = this.host;\n const m = /^var\\((--[\\w-]+)\\)$/.exec(color.trim());\n if (!m) return color;\n return getComputedStyle(probe).getPropertyValue(m[1]).trim() || color;\n }\n\n private render(): void {\n const cfg = this.config();\n const rows = this.data();\n const x = this.xKey();\n const fg = getComputedStyle(this.host).getPropertyValue('--muted-foreground').trim() || '#888';\n const grid = getComputedStyle(this.host).getPropertyValue('--border').trim() || '#8884';\n const type = this.type();\n const labels = rows.map((r) => String(r[x]));\n const datasets = this.circular()\n ? [\n {\n label: this.label(),\n data: rows.map((r) => Number(r[this.valueKey()])),\n backgroundColor: labels.map((l) => this.resolve(cfg[l]?.color ?? '#888')),\n borderWidth: 0,\n },\n ]\n : Object.entries(cfg).map(([key, c]) => ({\n label: c.label,\n data: rows.map((r) => Number(r[key])),\n backgroundColor: this.resolve(c.color),\n borderColor: this.resolve(c.color),\n borderRadius: type === 'bar' ? 4 : 0,\n borderWidth: type === 'bar' ? 0 : 2,\n tension: 0.3,\n pointRadius: type === 'line' ? 0 : 3,\n fill: false,\n }));\n const tooltipBg = getComputedStyle(this.host).getPropertyValue('--background').trim() || '#fff';\n const tooltipFg = getComputedStyle(this.host).getPropertyValue('--foreground').trim() || '#000';\n const options: ChartOptions = {\n responsive: true,\n maintainAspectRatio: false,\n animation: { duration: 400 },\n plugins: {\n legend: { display: false },\n tooltip: {\n backgroundColor: tooltipBg,\n titleColor: tooltipFg,\n bodyColor: tooltipFg,\n borderColor: grid,\n borderWidth: 1,\n cornerRadius: 8,\n padding: 10,\n boxPadding: 4,\n usePointStyle: false,\n },\n },\n scales: this.circular() || type === 'radar'\n ? {}\n : {\n x: { grid: { display: false }, border: { display: false }, ticks: { color: fg } },\n y: { grid: { color: grid }, border: { display: false }, ticks: { color: fg } },\n },\n ...this.options(),\n };\n const config = { type, data: { labels, datasets }, options } as never;\n if (this.chart && (this.chart.config as { type?: string }).type === type) {\n this.chart.data = { labels, datasets } as never;\n this.chart.options = options as never;\n this.chart.update();\n } else {\n this.chart?.destroy();\n this.chart = new Chart(this.canvas().nativeElement, config);\n }\n }\n}\n\nexport const UI_CHART = [UiChart] as const;\n"],"mappings":";;;;AAeA,MAAM,SAAS,GAAG,aAAa;AAwC/B,IAAa,UAAb,MAAa,QAAO;CACV,OAAO,IAAI;CACA,UAAU,SAAS,EAAE,QAAQ;CAC/B,OAAO,OAAgC,UAAU,CAAC,CAAC;CACnD,SAAS,UAAU,SAAwC,UAAS,GAAA,YAAA,CAAA,EAAA,WAAA,SAAA,CAAA,+BAAA,CAAA,CAAA;CAE5E,OAAO,MAAiB,OAAM,GAAA,YAAA,CAAA,EAAA,WAAA,OAAA,CAAA,+BAAA,CAAA,CAAA;CAC9B,OAAO,MAAM,SAAqC,GAAA,YAAA,CAAA,EAAA,WAAA,OAAA,CAAA,+BAAA,CAAA,CAAA;CAClD,OAAO,MAAM,SAAkB,GAAA,YAAA,CAAA,EAAA,WAAA,OAAA,CAAA,+BAAA,CAAA,CAAA;CAC/B,WAAW,MAAc,IAAG,GAAA,YAAA,CAAA,EAAA,WAAA,WAAA,CAAA,+BAAA,CAAA,CAAA;CAC5B,SAAS,MAAM,SAAuB,GAAA,YAAA,CAAA,EAAA,WAAA,SAAA,CAAA,+BAAA,CAAA,CAAA;CACtC,UAAU,MAA2B,CAAA,GAAG,GAAA,YAAA,CAAA,EAAA,WAAA,UAAA,CAAA,+BAAA,CAAA,CAAA;CACxC,aAAa,MAAM,MAAK,GAAA,YAAA,CAAA,EAAA,WAAA,aAAA,CAAA,+BAAA,CAAA,CAAA;CACxB,QAAQ,MAAM,SAAQ,GAAA,YAAA,CAAA,EAAA,WAAA,QAAA,CAAA,+BAAA,CAAA,CAAA;CACtB,YAAY,MAAc,IAAE;EAAA,GAAA,YAAA,EAAA,WAAA,YAAA,+BAAA,CAAA;EAAI,OAAO;CAAO,C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AAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,WAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;CAAA;AAAA,CAAA;AAiItF,MAAa,WAAW,CAAC,OAAO"}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { ChangeDetectionStrategy, Component, booleanAttribute, computed, forwardRef, input, model, signal } from "@angular/core";
|
|
3
|
+
import { NG_VALUE_ACCESSOR } from "@angular/forms";
|
|
4
|
+
import * as i1 from "@loomui-ng/ui/utils";
|
|
5
|
+
import { UiElementHost, cn } from "@loomui-ng/ui/utils";
|
|
6
|
+
import { UiIconSvg } from "@loomui-ng/ui/icon";
|
|
7
|
+
const checkboxClasses = "peer relative flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-input transition-colors outline-none group-has-disabled/field:opacity-50 group-has-[:focus-visible]/field-label:ring-0 group-has-[:focus-visible]/field-label:not-data-checked:border-input after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground group-has-[:focus-visible]/field-label:data-checked:border-primary dark:data-checked:bg-primary";
|
|
8
|
+
var UiCheckbox = class UiCheckbox {
|
|
9
|
+
checked = model(false, ...ngDevMode ? [{ debugName: "checked" }] : /* istanbul ignore next */ []);
|
|
10
|
+
indeterminate = model(false, ...ngDevMode ? [{ debugName: "indeterminate" }] : /* istanbul ignore next */ []);
|
|
11
|
+
disabled = input(false, {
|
|
12
|
+
...ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {},
|
|
13
|
+
transform: booleanAttribute
|
|
14
|
+
});
|
|
15
|
+
invalid = input(false, {
|
|
16
|
+
...ngDevMode ? { debugName: "invalid" } : /* istanbul ignore next */ {},
|
|
17
|
+
transform: booleanAttribute
|
|
18
|
+
});
|
|
19
|
+
userClass = input("", {
|
|
20
|
+
...ngDevMode ? { debugName: "userClass" } : /* istanbul ignore next */ {},
|
|
21
|
+
alias: "class"
|
|
22
|
+
});
|
|
23
|
+
cvaDisabled = signal(false, ...ngDevMode ? [{ debugName: "cvaDisabled" }] : /* istanbul ignore next */ []);
|
|
24
|
+
isDisabled = computed(() => this.disabled() || this.cvaDisabled(), ...ngDevMode ? [{ debugName: "isDisabled" }] : /* istanbul ignore next */ []);
|
|
25
|
+
state = computed(() => this.indeterminate() ? "indeterminate" : this.checked() ? "checked" : "unchecked", ...ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []);
|
|
26
|
+
classes = computed(() => cn(checkboxClasses, this.userClass()), ...ngDevMode ? [{ debugName: "classes" }] : /* istanbul ignore next */ []);
|
|
27
|
+
onChange = () => {};
|
|
28
|
+
onTouched = () => {};
|
|
29
|
+
toggle() {
|
|
30
|
+
if (this.isDisabled()) return;
|
|
31
|
+
const next = this.indeterminate() ? true : !this.checked();
|
|
32
|
+
this.indeterminate.set(false);
|
|
33
|
+
this.checked.set(next);
|
|
34
|
+
this.onChange(next);
|
|
35
|
+
}
|
|
36
|
+
writeValue(v) {
|
|
37
|
+
this.checked.set(!!v);
|
|
38
|
+
}
|
|
39
|
+
registerOnChange(fn) {
|
|
40
|
+
this.onChange = fn;
|
|
41
|
+
}
|
|
42
|
+
registerOnTouched(fn) {
|
|
43
|
+
this.onTouched = fn;
|
|
44
|
+
}
|
|
45
|
+
setDisabledState(d) {
|
|
46
|
+
this.cvaDisabled.set(d);
|
|
47
|
+
}
|
|
48
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
49
|
+
minVersion: "12.0.0",
|
|
50
|
+
version: "22.2.2",
|
|
51
|
+
ngImport: i0,
|
|
52
|
+
type: UiCheckbox,
|
|
53
|
+
deps: [],
|
|
54
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
55
|
+
});
|
|
56
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
57
|
+
minVersion: "17.0.0",
|
|
58
|
+
version: "22.2.2",
|
|
59
|
+
type: UiCheckbox,
|
|
60
|
+
isStandalone: true,
|
|
61
|
+
selector: "button[uiCheckbox], ui-checkbox",
|
|
62
|
+
inputs: {
|
|
63
|
+
checked: {
|
|
64
|
+
classPropertyName: "checked",
|
|
65
|
+
publicName: "checked",
|
|
66
|
+
isSignal: true,
|
|
67
|
+
isRequired: false,
|
|
68
|
+
transformFunction: null
|
|
69
|
+
},
|
|
70
|
+
indeterminate: {
|
|
71
|
+
classPropertyName: "indeterminate",
|
|
72
|
+
publicName: "indeterminate",
|
|
73
|
+
isSignal: true,
|
|
74
|
+
isRequired: false,
|
|
75
|
+
transformFunction: null
|
|
76
|
+
},
|
|
77
|
+
disabled: {
|
|
78
|
+
classPropertyName: "disabled",
|
|
79
|
+
publicName: "disabled",
|
|
80
|
+
isSignal: true,
|
|
81
|
+
isRequired: false,
|
|
82
|
+
transformFunction: null
|
|
83
|
+
},
|
|
84
|
+
invalid: {
|
|
85
|
+
classPropertyName: "invalid",
|
|
86
|
+
publicName: "invalid",
|
|
87
|
+
isSignal: true,
|
|
88
|
+
isRequired: false,
|
|
89
|
+
transformFunction: null
|
|
90
|
+
},
|
|
91
|
+
userClass: {
|
|
92
|
+
classPropertyName: "userClass",
|
|
93
|
+
publicName: "class",
|
|
94
|
+
isSignal: true,
|
|
95
|
+
isRequired: false,
|
|
96
|
+
transformFunction: null
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
outputs: {
|
|
100
|
+
checked: "checkedChange",
|
|
101
|
+
indeterminate: "indeterminateChange"
|
|
102
|
+
},
|
|
103
|
+
host: {
|
|
104
|
+
attributes: {
|
|
105
|
+
"type": "button",
|
|
106
|
+
"role": "checkbox",
|
|
107
|
+
"data-slot": "checkbox"
|
|
108
|
+
},
|
|
109
|
+
listeners: {
|
|
110
|
+
"click": "toggle()",
|
|
111
|
+
"keydown.enter": "$event.preventDefault()",
|
|
112
|
+
"blur": "onTouched()"
|
|
113
|
+
},
|
|
114
|
+
properties: {
|
|
115
|
+
"attr.aria-checked": "indeterminate() ? \"mixed\" : checked()",
|
|
116
|
+
"attr.aria-invalid": "invalid() ? \"true\" : null",
|
|
117
|
+
"attr.data-state": "state()",
|
|
118
|
+
"attr.data-disabled": "isDisabled() ? \"\" : null",
|
|
119
|
+
"attr.disabled": "isDisabled() ? \"\" : null",
|
|
120
|
+
"attr.class": "classes()"
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
providers: [{
|
|
124
|
+
provide: NG_VALUE_ACCESSOR,
|
|
125
|
+
useExisting: forwardRef(() => UiCheckbox),
|
|
126
|
+
multi: true
|
|
127
|
+
}],
|
|
128
|
+
hostDirectives: [{ directive: i1.UiElementHost }],
|
|
129
|
+
ngImport: i0,
|
|
130
|
+
template: `
|
|
131
|
+
@if (state() !== 'unchecked') {
|
|
132
|
+
<span
|
|
133
|
+
data-slot="checkbox-indicator"
|
|
134
|
+
[attr.data-state]="state()"
|
|
135
|
+
class="grid place-content-center text-current transition-none [&>svg]:size-3.5 [&>ui-icon]:size-3.5"
|
|
136
|
+
style="pointer-events: none"
|
|
137
|
+
>
|
|
138
|
+
@if (indeterminate()) {
|
|
139
|
+
<svg uiIcon="minus"></svg>
|
|
140
|
+
} @else {
|
|
141
|
+
<svg uiIcon="check"></svg>
|
|
142
|
+
}
|
|
143
|
+
</span>
|
|
144
|
+
}
|
|
145
|
+
`,
|
|
146
|
+
isInline: true,
|
|
147
|
+
dependencies: [{
|
|
148
|
+
kind: "directive",
|
|
149
|
+
type: UiIconSvg,
|
|
150
|
+
selector: "svg[uiIcon]",
|
|
151
|
+
inputs: [
|
|
152
|
+
"uiIcon",
|
|
153
|
+
"icon",
|
|
154
|
+
"size",
|
|
155
|
+
"strokeWidth",
|
|
156
|
+
"absoluteStrokeWidth",
|
|
157
|
+
"color",
|
|
158
|
+
"label",
|
|
159
|
+
"class"
|
|
160
|
+
]
|
|
161
|
+
}],
|
|
162
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
166
|
+
minVersion: "12.0.0",
|
|
167
|
+
version: "22.2.2",
|
|
168
|
+
ngImport: i0,
|
|
169
|
+
type: UiCheckbox,
|
|
170
|
+
decorators: [{
|
|
171
|
+
type: Component,
|
|
172
|
+
args: [{
|
|
173
|
+
selector: "button[uiCheckbox], ui-checkbox",
|
|
174
|
+
hostDirectives: [UiElementHost],
|
|
175
|
+
imports: [UiIconSvg],
|
|
176
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
177
|
+
providers: [{
|
|
178
|
+
provide: NG_VALUE_ACCESSOR,
|
|
179
|
+
useExisting: forwardRef(() => UiCheckbox),
|
|
180
|
+
multi: true
|
|
181
|
+
}],
|
|
182
|
+
host: {
|
|
183
|
+
type: "button",
|
|
184
|
+
role: "checkbox",
|
|
185
|
+
"data-slot": "checkbox",
|
|
186
|
+
"[attr.aria-checked]": "indeterminate() ? \"mixed\" : checked()",
|
|
187
|
+
"[attr.aria-invalid]": "invalid() ? \"true\" : null",
|
|
188
|
+
"[attr.data-state]": "state()",
|
|
189
|
+
"[attr.data-disabled]": "isDisabled() ? \"\" : null",
|
|
190
|
+
"[attr.disabled]": "isDisabled() ? \"\" : null",
|
|
191
|
+
"[attr.class]": "classes()",
|
|
192
|
+
"(click)": "toggle()",
|
|
193
|
+
"(keydown.enter)": "$event.preventDefault()",
|
|
194
|
+
"(blur)": "onTouched()"
|
|
195
|
+
},
|
|
196
|
+
template: `
|
|
197
|
+
@if (state() !== 'unchecked') {
|
|
198
|
+
<span
|
|
199
|
+
data-slot="checkbox-indicator"
|
|
200
|
+
[attr.data-state]="state()"
|
|
201
|
+
class="grid place-content-center text-current transition-none [&>svg]:size-3.5 [&>ui-icon]:size-3.5"
|
|
202
|
+
style="pointer-events: none"
|
|
203
|
+
>
|
|
204
|
+
@if (indeterminate()) {
|
|
205
|
+
<svg uiIcon="minus"></svg>
|
|
206
|
+
} @else {
|
|
207
|
+
<svg uiIcon="check"></svg>
|
|
208
|
+
}
|
|
209
|
+
</span>
|
|
210
|
+
}
|
|
211
|
+
`
|
|
212
|
+
}]
|
|
213
|
+
}],
|
|
214
|
+
propDecorators: {
|
|
215
|
+
checked: [{
|
|
216
|
+
type: i0.Input,
|
|
217
|
+
args: [{
|
|
218
|
+
isSignal: true,
|
|
219
|
+
alias: "checked",
|
|
220
|
+
required: false
|
|
221
|
+
}]
|
|
222
|
+
}, {
|
|
223
|
+
type: i0.Output,
|
|
224
|
+
args: ["checkedChange"]
|
|
225
|
+
}],
|
|
226
|
+
indeterminate: [{
|
|
227
|
+
type: i0.Input,
|
|
228
|
+
args: [{
|
|
229
|
+
isSignal: true,
|
|
230
|
+
alias: "indeterminate",
|
|
231
|
+
required: false
|
|
232
|
+
}]
|
|
233
|
+
}, {
|
|
234
|
+
type: i0.Output,
|
|
235
|
+
args: ["indeterminateChange"]
|
|
236
|
+
}],
|
|
237
|
+
disabled: [{
|
|
238
|
+
type: i0.Input,
|
|
239
|
+
args: [{
|
|
240
|
+
isSignal: true,
|
|
241
|
+
alias: "disabled",
|
|
242
|
+
required: false
|
|
243
|
+
}]
|
|
244
|
+
}],
|
|
245
|
+
invalid: [{
|
|
246
|
+
type: i0.Input,
|
|
247
|
+
args: [{
|
|
248
|
+
isSignal: true,
|
|
249
|
+
alias: "invalid",
|
|
250
|
+
required: false
|
|
251
|
+
}]
|
|
252
|
+
}],
|
|
253
|
+
userClass: [{
|
|
254
|
+
type: i0.Input,
|
|
255
|
+
args: [{
|
|
256
|
+
isSignal: true,
|
|
257
|
+
alias: "class",
|
|
258
|
+
required: false
|
|
259
|
+
}]
|
|
260
|
+
}]
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
export { UiCheckbox };
|
|
264
|
+
|
|
265
|
+
//# sourceMappingURL=loomui-ng-ui-checkbox.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loomui-ng-ui-checkbox.mjs","names":[],"sources":["../../../libs/ui/checkbox/checkbox.ts"],"sourcesContent":["import {\n booleanAttribute,\n ChangeDetectionStrategy,\n Component,\n computed,\n forwardRef,\n input,\n model,\n signal,\n} from '@angular/core';\nimport { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';\nimport { cn } from '@loomui-ng/ui/utils';\nimport { UiIconSvg } from '@loomui-ng/ui/icon';\nimport { UiElementHost } from '@loomui-ng/ui/utils';\n\nconst checkboxClasses =\n 'peer relative flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-input transition-colors outline-none group-has-disabled/field:opacity-50 group-has-[:focus-visible]/field-label:ring-0 group-has-[:focus-visible]/field-label:not-data-checked:border-input after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground group-has-[:focus-visible]/field-label:data-checked:border-primary dark:data-checked:bg-primary';\n\n/**\n * <button uiCheckbox [(checked)]=\"x\"></button>\n *\n * Works with: [(checked)] two-way binding, ngModel / reactive forms (ControlValueAccessor),\n * and signal forms (`checked` model + `disabled`/`invalid` inputs match FormCheckboxControl).\n */\n@Component({\n selector: 'button[uiCheckbox], ui-checkbox', hostDirectives: [UiElementHost],\n imports: [UiIconSvg],\n changeDetection: ChangeDetectionStrategy.OnPush,\n providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => UiCheckbox), multi: true }],\n host: {\n type: 'button',\n role: 'checkbox',\n 'data-slot': 'checkbox',\n '[attr.aria-checked]': 'indeterminate() ? \"mixed\" : checked()',\n '[attr.aria-invalid]': 'invalid() ? \"true\" : null',\n '[attr.data-state]': 'state()',\n '[attr.data-disabled]': 'isDisabled() ? \"\" : null',\n '[attr.disabled]': 'isDisabled() ? \"\" : null',\n '[attr.class]': 'classes()',\n '(click)': 'toggle()',\n // Observed on live site: Space toggles, Enter does not.\n '(keydown.enter)': '$event.preventDefault()',\n '(blur)': 'onTouched()',\n },\n template: `\n @if (state() !== 'unchecked') {\n <span\n data-slot=\"checkbox-indicator\"\n [attr.data-state]=\"state()\"\n class=\"grid place-content-center text-current transition-none [&>svg]:size-3.5 [&>ui-icon]:size-3.5\"\n style=\"pointer-events: none\"\n >\n @if (indeterminate()) {\n <svg uiIcon=\"minus\"></svg>\n } @else {\n <svg uiIcon=\"check\"></svg>\n }\n </span>\n }\n `,\n})\nexport class UiCheckbox implements ControlValueAccessor {\n readonly checked = model(false);\n readonly indeterminate = model(false);\n readonly disabled = input(false, { transform: booleanAttribute });\n readonly invalid = input(false, { transform: booleanAttribute });\n readonly userClass = input<string>('', { alias: 'class' });\n\n private readonly cvaDisabled = signal(false);\n protected readonly isDisabled = computed(() => this.disabled() || this.cvaDisabled());\n protected readonly state = computed(() => (this.indeterminate() ? 'indeterminate' : this.checked() ? 'checked' : 'unchecked'));\n protected readonly classes = computed(() => cn(checkboxClasses, this.userClass()));\n\n private onChange: (v: boolean) => void = () => {};\n protected onTouched: () => void = () => {};\n\n protected toggle(): void {\n if (this.isDisabled()) return;\n const next = this.indeterminate() ? true : !this.checked();\n this.indeterminate.set(false);\n this.checked.set(next);\n this.onChange(next);\n }\n\n writeValue(v: boolean | null): void {\n this.checked.set(!!v);\n }\n registerOnChange(fn: (v: boolean) => void): void {\n this.onChange = fn;\n }\n registerOnTouched(fn: () => void): void {\n this.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