@woobee/ui 0.2.0 → 0.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.
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +130 -110
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -31
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
-
import
|
|
2
|
+
import React16, { forwardRef, useRef, useEffect, createContext, useState, useImperativeHandle, useContext, useReducer, useCallback } from 'react';
|
|
3
3
|
import { createPortal } from 'react-dom';
|
|
4
4
|
import { CSSTransition } from 'react-transition-group';
|
|
5
5
|
|
|
@@ -29,6 +29,7 @@ function Button({
|
|
|
29
29
|
leftIcon = null,
|
|
30
30
|
rightIcon = null,
|
|
31
31
|
compact = false,
|
|
32
|
+
darkMode = false,
|
|
32
33
|
...props
|
|
33
34
|
}) {
|
|
34
35
|
return /* @__PURE__ */ jsxs(
|
|
@@ -45,11 +46,20 @@ function Button({
|
|
|
45
46
|
"px-5 py-3 text-base": size === "big",
|
|
46
47
|
"px-5 py-3 text-lg font-medium": size === "huge",
|
|
47
48
|
"!px-1 !py-0.5": compact,
|
|
48
|
-
"border bg-brown-500
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
49
|
+
"border bg-brown-500 border-transparent text-white": variant === "primary" && !darkMode,
|
|
50
|
+
"dark:bg-primary-500 dark:hover:bg-primary-600 dark:text-black": variant === "primary" && !darkMode,
|
|
51
|
+
"border bg-primary-500 hover:bg-primary-600 border-transparent text-black": variant === "primary" && !!darkMode,
|
|
52
|
+
"text-gray-700 bg-white border border-gray-300 hover:text-gray-500": variant === "secondary" && !darkMode,
|
|
53
|
+
"text-charcoal-100 bg-charcoal-800 hover:bg-charcoal-700 border border-charcoal-700": variant === "secondary" && !!darkMode,
|
|
54
|
+
"!rounded-md text-left w-full text-gray-700 bg-white border border-gray-200 hover:bg-gray-50 hover:text-gray-500": variant === "form-input" && !darkMode,
|
|
55
|
+
"!rounded-md text-left w-full text-charcoal-100 bg-charcoal-800 hover:bg-charcoal-700 border border-charcoal-700": variant === "form-input" && !!darkMode,
|
|
56
|
+
"dark:bg-charcoal-800 dark:hover:bg-charcoal-700 dark:text-charcoal-100 dark:border-charcoal-700": (variant === "secondary" || variant === "form-input") && !darkMode,
|
|
57
|
+
"hover:text-brown-500 !shadow-none": variant === "flat" && !darkMode,
|
|
58
|
+
"dark:text-charcoal-100 dark:hover:text-primary-500": variant === "flat" && !darkMode,
|
|
59
|
+
"text-charcoal-100 hover:text-primary-500 !shadow-none": variant === "flat" && !!darkMode,
|
|
60
|
+
"!text-gray-300 hover:!text-gray-400": !children && !darkMode,
|
|
61
|
+
"dark:!text-charcoal-400": !children && !darkMode,
|
|
62
|
+
"!text-charcoal-400": !children && !!darkMode,
|
|
53
63
|
...classNameObject(className)
|
|
54
64
|
}),
|
|
55
65
|
...props,
|
|
@@ -255,6 +265,10 @@ function CheckboxList({
|
|
|
255
265
|
loading = false,
|
|
256
266
|
placeholder = "No items found."
|
|
257
267
|
}) {
|
|
268
|
+
const hasLoadedRef = useRef(false);
|
|
269
|
+
if (!loading) {
|
|
270
|
+
hasLoadedRef.current = true;
|
|
271
|
+
}
|
|
258
272
|
const getFinalKey = (item, index) => {
|
|
259
273
|
const key = typeof itemKey === "function" ? itemKey(item) : item[itemKey];
|
|
260
274
|
return key !== void 0 && key !== null ? key : index;
|
|
@@ -265,7 +279,7 @@ function CheckboxList({
|
|
|
265
279
|
}
|
|
266
280
|
return placeholder;
|
|
267
281
|
};
|
|
268
|
-
return /* @__PURE__ */ jsx("div", { className: "w-full border border-gray-300 dark:border-charcoal-700 rounded-lg shadow-sm bg-white dark:bg-charcoal-800 overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "max-h-60 overflow-y-auto divide-y divide-gray-100 dark:divide-charcoal-700", children: loading &&
|
|
282
|
+
return /* @__PURE__ */ jsx("div", { className: "w-full border border-gray-300 dark:border-charcoal-700 rounded-lg shadow-sm bg-white dark:bg-charcoal-800 overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "max-h-60 overflow-y-auto divide-y divide-gray-100 dark:divide-charcoal-700", children: loading && !hasLoadedRef.current ? /* @__PURE__ */ jsx("div", { className: "p-4 flex items-center justify-center min-h-36", children: /* @__PURE__ */ jsx(Loading, { spinSizeClassName: "w-6 h-6", className: "inline-block" }) }) : /* @__PURE__ */ jsx(Fragment, { children: items.length > 0 ? items.map((item, index) => {
|
|
269
283
|
const finalKey = getFinalKey(item, index);
|
|
270
284
|
const label = typeof itemLabel === "function" ? itemLabel(item) : item[itemLabel];
|
|
271
285
|
const checked = typeof isChecked === "function" ? isChecked(item, selected) : selected.some(
|
|
@@ -452,7 +466,7 @@ function CSSTransitionComponent({
|
|
|
452
466
|
removeClasses(nodeRef.current, [...leaveToClasses, ...leaveClasses]);
|
|
453
467
|
onExited(nodeRef.current);
|
|
454
468
|
},
|
|
455
|
-
children:
|
|
469
|
+
children: React16.cloneElement(children, {
|
|
456
470
|
ref: (node) => {
|
|
457
471
|
nodeRef.current = node;
|
|
458
472
|
const childRef = children.ref;
|
|
@@ -1649,31 +1663,37 @@ var ThemeContext = createContext(void 0);
|
|
|
1649
1663
|
function ThemeProvider({ children, defaultTheme = "system" }) {
|
|
1650
1664
|
const [mode, setMode] = useState(defaultTheme);
|
|
1651
1665
|
const [isDark, setIsDark] = useState(false);
|
|
1652
|
-
const
|
|
1653
|
-
useEffect(() => {
|
|
1654
|
-
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
1655
|
-
const isDark2 = mode === "dark" || mode === "system" && prefersDark;
|
|
1656
|
-
document.documentElement.classList.toggle("dark", isDark2);
|
|
1657
|
-
stateRef.current = mode;
|
|
1658
|
-
setIsDark(isDark2);
|
|
1659
|
-
}, [mode]);
|
|
1666
|
+
const [mounted, setMounted] = useState(false);
|
|
1660
1667
|
useEffect(() => {
|
|
1661
1668
|
const saved = localStorage.getItem("theme") || defaultTheme;
|
|
1662
1669
|
setMode(saved);
|
|
1670
|
+
setMounted(true);
|
|
1663
1671
|
}, [defaultTheme]);
|
|
1664
1672
|
useEffect(() => {
|
|
1673
|
+
if (!mounted) return;
|
|
1665
1674
|
const media = window.matchMedia("(prefers-color-scheme: dark)");
|
|
1666
|
-
const
|
|
1667
|
-
const
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1675
|
+
const updateTheme = () => {
|
|
1676
|
+
const prefersDark = media.matches;
|
|
1677
|
+
const currentIsDark = mode === "dark" || mode === "system" && prefersDark;
|
|
1678
|
+
if (currentIsDark) {
|
|
1679
|
+
document.documentElement.classList.add("dark");
|
|
1680
|
+
document.documentElement.classList.remove("light");
|
|
1681
|
+
} else {
|
|
1682
|
+
document.documentElement.classList.remove("dark");
|
|
1683
|
+
document.documentElement.classList.add("light");
|
|
1672
1684
|
}
|
|
1685
|
+
setIsDark(currentIsDark);
|
|
1673
1686
|
};
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1687
|
+
const timeoutId = setTimeout(updateTheme, 0);
|
|
1688
|
+
const handleMediaChange = () => {
|
|
1689
|
+
updateTheme();
|
|
1690
|
+
};
|
|
1691
|
+
media.addEventListener("change", handleMediaChange);
|
|
1692
|
+
return () => {
|
|
1693
|
+
clearTimeout(timeoutId);
|
|
1694
|
+
media.removeEventListener("change", handleMediaChange);
|
|
1695
|
+
};
|
|
1696
|
+
}, [mode, mounted]);
|
|
1677
1697
|
function handleToggleTheme(triggerMode) {
|
|
1678
1698
|
const triggeredMode = triggerMode === mode ? "system" : triggerMode;
|
|
1679
1699
|
setMode(triggeredMode);
|
|
@@ -2420,9 +2440,9 @@ function Dragger({
|
|
|
2420
2440
|
}
|
|
2421
2441
|
dispatch({ dragging: false });
|
|
2422
2442
|
}
|
|
2423
|
-
const derivedItems = !!items &&
|
|
2443
|
+
const derivedItems = !!items && React16.cloneElement(children, {
|
|
2424
2444
|
children: items.map((grandChild, index) => {
|
|
2425
|
-
return
|
|
2445
|
+
return React16.cloneElement(grandChild, {
|
|
2426
2446
|
id: (records[index] || {}).id,
|
|
2427
2447
|
draggable: true,
|
|
2428
2448
|
className: classNames({
|
|
@@ -2439,9 +2459,9 @@ function Dragger({
|
|
|
2439
2459
|
});
|
|
2440
2460
|
})
|
|
2441
2461
|
});
|
|
2442
|
-
const derivedDisplayItems = !!displayItems &&
|
|
2462
|
+
const derivedDisplayItems = !!displayItems && React16.cloneElement(children, {
|
|
2443
2463
|
children: displayItems.map((grandChild, index) => {
|
|
2444
|
-
return
|
|
2464
|
+
return React16.cloneElement(grandChild, {
|
|
2445
2465
|
draggable: true,
|
|
2446
2466
|
className: classNames({
|
|
2447
2467
|
...classNameObject(grandChild.props.className),
|
|
@@ -3040,7 +3060,7 @@ function DataTableRow({ index, selected, label, description, additionalDescripti
|
|
|
3040
3060
|
"!text-left": dataItem.align === "left",
|
|
3041
3061
|
"align-middle": vertical === "middle"
|
|
3042
3062
|
}),
|
|
3043
|
-
children: typeof dataItem.data[index] === "string" ||
|
|
3063
|
+
children: typeof dataItem.data[index] === "string" || React16.isValidElement(dataItem.data[index]) ? dataItem.data[index] : numberFormatter(dataItem.data[index], dataItem.decimal != null ? dataItem.decimal : 1)
|
|
3044
3064
|
},
|
|
3045
3065
|
`${dataIndex}-${index}`
|
|
3046
3066
|
))
|
|
@@ -3177,7 +3197,7 @@ function DataTable({
|
|
|
3177
3197
|
backgroundColor: `${colors[dataIndex]}`,
|
|
3178
3198
|
color: bestTextColorForBg(colors[dataIndex])
|
|
3179
3199
|
} : void 0,
|
|
3180
|
-
children: typeof total[dataIndex] === "string" ||
|
|
3200
|
+
children: typeof total[dataIndex] === "string" || React16.isValidElement(total[dataIndex]) ? total[dataIndex] : showCurrency ? /* @__PURE__ */ jsx(CurrencyDisplay, { amount: total[dataIndex] }) : numberFormatter(total[dataIndex], 1)
|
|
3181
3201
|
},
|
|
3182
3202
|
`${dataIndex}-total`
|
|
3183
3203
|
))
|