@adaptabletools/adaptable
Version:
Powerful AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
32 lines (31 loc) • 1.27 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { readJSONFile } from '../../../components/FileDroppable';
import SimpleButton from '../../../components/SimpleButton';
export const LoadButton = (props) => {
const onLoadInitialState = (e) => {
const nativeEvent = e.nativeEvent;
let files;
if (nativeEvent && nativeEvent.dataTransfer) {
files = nativeEvent.dataTransfer.files;
}
else {
files = e.target.files;
}
const file = files[0];
readJSONFile(file).then((json) => {
props.onLoad(json);
});
};
return (_jsxs(SimpleButton, { ...props, className: "ab-StateManagement__Load-Button", children: [_jsx("input", { "aria-label": "Load Adaptable State", type: "file", onChange: (json) => onLoadInitialState(json), accept: '.json', style: {
opacity: 0,
position: 'absolute',
cursor: 'pointer',
fontSize: 0,
lineHeight: 0,
top: 0,
left: 0,
width: '100%',
height: '100%',
zIndex: 1,
} }), ' ', props.children] }));
};