tw-react-components 0.0.180 → 0.0.183
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/index.esm.js +35 -3
- package/package.json +1 -1
package/index.esm.js
CHANGED
|
@@ -1478,8 +1478,9 @@ const FormGroup = ({ className, label, children }) => (jsxs(Flex, { className: c
|
|
|
1478
1478
|
|
|
1479
1479
|
function withForm(Component) {
|
|
1480
1480
|
return (props) => {
|
|
1481
|
-
const _a = props, { name, pattern, validate } = _a,
|
|
1481
|
+
const _a = props, { name, pattern, validate } = _a, _restProps = __rest(_a, ["name", "pattern", "validate"]);
|
|
1482
1482
|
const { control, formState } = useFormContext();
|
|
1483
|
+
const restProps = _restProps;
|
|
1483
1484
|
return (jsx(Controller, { name: name, control: control, rules: {
|
|
1484
1485
|
required: restProps.required,
|
|
1485
1486
|
min: restProps.min,
|
|
@@ -1490,7 +1491,9 @@ function withForm(Component) {
|
|
|
1490
1491
|
validate,
|
|
1491
1492
|
}, render: ({ field, fieldState }) => {
|
|
1492
1493
|
var _a, _b;
|
|
1493
|
-
return (jsx(Component, Object.assign({}, restProps, field, {
|
|
1494
|
+
return (jsx(Component, Object.assign({}, restProps, field, { onChange: Component === NumberInput
|
|
1495
|
+
? (value) => field.onChange(value.target.valueAsNumber)
|
|
1496
|
+
: field.onChange, value: (_a = field.value) !== null && _a !== void 0 ? _a : '', disabled: ((_b = field.disabled) !== null && _b !== void 0 ? _b : restProps.disabled) ||
|
|
1494
1497
|
formState.isSubmitting, hasErrors: fieldState.error })));
|
|
1495
1498
|
} }));
|
|
1496
1499
|
};
|
|
@@ -1773,12 +1776,20 @@ const Dialog = Object.assign($Dialog, {
|
|
|
1773
1776
|
});
|
|
1774
1777
|
|
|
1775
1778
|
const ConfirmDialog = ({ open, title, children, yesLabel, noLabel, onConfirm, onClose, dataTestId = 'confirm-dialog', }) => {
|
|
1779
|
+
const { toast } = useToast();
|
|
1776
1780
|
const [loading, setLoading] = useState(false);
|
|
1777
1781
|
const handleConfirm = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1778
1782
|
setLoading(true);
|
|
1779
1783
|
try {
|
|
1780
1784
|
yield onConfirm();
|
|
1781
1785
|
}
|
|
1786
|
+
catch (error) {
|
|
1787
|
+
toast({
|
|
1788
|
+
variant: 'destructive',
|
|
1789
|
+
title: 'Error',
|
|
1790
|
+
description: error instanceof Error ? error.message : 'Something went wrong',
|
|
1791
|
+
});
|
|
1792
|
+
}
|
|
1782
1793
|
finally {
|
|
1783
1794
|
setLoading(false);
|
|
1784
1795
|
}
|
|
@@ -1847,7 +1858,20 @@ const Sheet = Object.assign(DialogPrimitive.Root, {
|
|
|
1847
1858
|
|
|
1848
1859
|
const FormDialog = ({ className, formClassName, open, title, form, children, submitLabel = 'Submit', cancelLabel = 'Cancel', extraAction, as: As = Sheet, onSubmit, onInvalid, onClose, dataTestId = 'form-dialog', }) => {
|
|
1849
1860
|
const id = useId();
|
|
1850
|
-
|
|
1861
|
+
const { toast } = useToast();
|
|
1862
|
+
const handleSubmit = (data, event) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1863
|
+
try {
|
|
1864
|
+
yield onSubmit(data, event);
|
|
1865
|
+
}
|
|
1866
|
+
catch (error) {
|
|
1867
|
+
toast({
|
|
1868
|
+
variant: 'destructive',
|
|
1869
|
+
title: 'Error',
|
|
1870
|
+
description: error instanceof Error ? error.message : 'Something went wrong',
|
|
1871
|
+
});
|
|
1872
|
+
}
|
|
1873
|
+
});
|
|
1874
|
+
return (jsx(As, { open: open, onOpenChange: (value) => !value && onClose(), children: jsxs(As.Content, { className: className, dataTestId: `${dataTestId}-content`, children: [jsx(As.Header, { dataTestId: `${dataTestId}-header`, children: jsx(As.Title, { dataTestId: `${dataTestId}-title`, children: title }) }), jsx(FormProvider, Object.assign({}, form, { children: jsx("form", { id: `form-${id}`, className: cn('flex h-full w-full flex-col gap-2 overflow-auto', formClassName), onSubmit: form.handleSubmit(handleSubmit, onInvalid), "data-testid": `${dataTestId}-form`, children: children }) })), jsxs(As.Footer, { className: "w-full sm:justify-between", dataTestId: `${dataTestId}-footer`, children: [extraAction, jsxs(As.Footer, { className: "ml-auto", dataTestId: `${dataTestId}-actions`, children: [jsx(As.Close, { asChild: true, children: jsx(Button, { color: "red", dataTestId: `${dataTestId}-cancel-button`, disabled: form.formState.isSubmitting, children: cancelLabel }) }), jsx(Button, { color: "green", type: "submit", form: `form-${id}`, loading: form.formState.isSubmitting, dataTestId: `${dataTestId}-submit-button`, children: submitLabel })] })] })] }) }));
|
|
1851
1875
|
};
|
|
1852
1876
|
|
|
1853
1877
|
function ListSorter({ className, items, dataTestId = 'list-sorter', idResolver, renderer, onChange, }) {
|
|
@@ -1877,6 +1901,7 @@ function SortableItem({ item, index, dataTestId, renderer, }) {
|
|
|
1877
1901
|
}
|
|
1878
1902
|
|
|
1879
1903
|
function ListSorterDialog({ className, open, title, items, idResolver, renderer, cancelLabel, submitLabel, onSubmit, onClose, dataTestId = 'list-sorter-dialog', }) {
|
|
1904
|
+
const { toast } = useToast();
|
|
1880
1905
|
const [sortedItems, setSortedItems] = useState(structuredClone(items));
|
|
1881
1906
|
const [loading, setLoading] = useState(false);
|
|
1882
1907
|
useEffect(() => {
|
|
@@ -1889,6 +1914,13 @@ function ListSorterDialog({ className, open, title, items, idResolver, renderer,
|
|
|
1889
1914
|
try {
|
|
1890
1915
|
yield onSubmit(sortedItems);
|
|
1891
1916
|
}
|
|
1917
|
+
catch (error) {
|
|
1918
|
+
toast({
|
|
1919
|
+
variant: 'destructive',
|
|
1920
|
+
title: 'Error',
|
|
1921
|
+
description: error instanceof Error ? error.message : 'Something went wrong',
|
|
1922
|
+
});
|
|
1923
|
+
}
|
|
1892
1924
|
finally {
|
|
1893
1925
|
setLoading(false);
|
|
1894
1926
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tw-react-components",
|
|
3
3
|
"description": "A set of React components build with TailwindCSS to make a nice dashboard.",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.183",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://bacali95.github.io/tw-react-components",
|
|
7
7
|
"type": "module",
|