mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-07-13 06:24:54 +10:00
v5.0.12 (#2814)
* refactor to @base-ui/react * fix all * fixes to accordion * more updates * switch to chat/completions api from openai * update version to v5.0.12
This commit is contained in:
@@ -76,6 +76,7 @@ export function ConfirmDialogProvider({ children }: { children: React.ReactNode
|
||||
{state.description}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel onClick={handleCancel}>{state.cancelText ?? "Cancel"}</AlertDialogCancel>
|
||||
<AlertDialogAction onClick={handleConfirm}>{state.confirmText ?? "Confirm"}</AlertDialogAction>
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import * as React from "react";
|
||||
|
||||
type DataStateValue = string | boolean | null;
|
||||
|
||||
function parseDatasetValue(value: string | null): DataStateValue {
|
||||
if (value === null) return null;
|
||||
if (value === "" || value === "true") return true;
|
||||
if (value === "false") return false;
|
||||
return value;
|
||||
}
|
||||
|
||||
function useDataState<T extends HTMLElement = HTMLElement>(
|
||||
key: string,
|
||||
forwardedRef?: React.Ref<T | null>,
|
||||
onChange?: (value: DataStateValue) => void,
|
||||
): [DataStateValue, React.RefObject<T | null>] {
|
||||
const localRef = React.useRef<T | null>(null);
|
||||
React.useImperativeHandle(forwardedRef, () => localRef.current as T);
|
||||
|
||||
const getSnapshot = (): DataStateValue => {
|
||||
const el = localRef.current;
|
||||
return el ? parseDatasetValue(el.getAttribute(`data-${key}`)) : null;
|
||||
};
|
||||
|
||||
const subscribe = (callback: () => void) => {
|
||||
const el = localRef.current;
|
||||
if (!el) return () => {};
|
||||
const observer = new MutationObserver((records) => {
|
||||
for (const record of records) {
|
||||
if (record.attributeName === `data-${key}`) {
|
||||
callback();
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
observer.observe(el, {
|
||||
attributes: true,
|
||||
attributeFilter: [`data-${key}`],
|
||||
});
|
||||
return () => observer.disconnect();
|
||||
};
|
||||
|
||||
const value = React.useSyncExternalStore(subscribe, getSnapshot);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (onChange) onChange(value);
|
||||
}, [value, onChange]);
|
||||
|
||||
return [value, localRef];
|
||||
}
|
||||
|
||||
export { useDataState };
|
||||
Reference in New Issue
Block a user