Skip to content

Make table switch column editable #867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ export function EditableCell<T extends JSONValue>(props: EditableCellProps<T>) {
const editable = editViewFn ? props.editable : false;
const { isEditing, setIsEditing } = useContext(TableCellContext);
const value = changeValue ?? baseValue!;

const [tmpValue, setTmpValue] = useState<T | null>(value);

useEffect(() => {
setTmpValue(value);
}, [value]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ const SwitchWrapper = styled.div<{ disabled: boolean }>`
`};
`;

const Wrapper = styled.div`
background: transparent !important;
padding: 0 8px;
`

const childrenMap = {
value: booleanExposingStateControl("value"),
switchState: BoolCodeControl,
Expand All @@ -80,18 +85,16 @@ export const SwitchComp = (function () {
const value = props.changeValue ?? getBaseValue(props, dispatch);
const CheckBoxComp = () => {
return (
<SwitchWrapper disabled={props.disabled}>
<Switch
checked={props.value.value || true}
disabled={props.disabled}
ref={props.viewRef}
onChange={(checked) => {
props.value.onChange(checked);
props.onEvent("change");
props.onEvent(checked ? "true" : "false");
}}
/>
</SwitchWrapper>
<Switch
checked={value}
disabled={props.disabled || true}
ref={props.viewRef}
onChange={(checked) => {
props.value.onChange(checked);
props.onEvent("change");
props.onEvent(checked ? "true" : "false");
}}
/>
);
};
return <CheckBoxComp />;
Expand All @@ -101,15 +104,22 @@ export const SwitchComp = (function () {
)
.setEditViewFn((props) => {
return (
<Switch
checked={props.value}
disabled={false}
onChange={(checked) => {
props.onChange(checked);
// props.onEvent("change");
// props.onEvent(checked ? "true" : "false");
<Wrapper
onBlur={(e) => {
if (!e.currentTarget?.contains(e.relatedTarget)) {
props.onChangeEnd();
}
}}
/>
>
<Switch
defaultChecked={props.value}
disabled={false}
onChange={(checked) => {
props.onChange(checked);
}}
/>

</Wrapper>
);
})
.setPropertyViewFn((children) => {
Expand Down
Loading