Path: blob/master/src/packages/frontend/editors/slate/elements/checkbox/index.tsx
1698 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { SlateElement, register, RenderElementProps } from "../register";6import { Checkbox as AntdCheckbox } from "antd";78export interface Checkbox extends SlateElement {9type: "checkbox";10value?: boolean; // important: using the field value results in more efficient diffs11}1213interface Props extends RenderElementProps {14setElement?: (SlateElement) => void;15}1617function StaticElement({ attributes, children, element, setElement }: Props) {18if (element.type != "checkbox") {19throw Error("bug");20}21return (22<span {...attributes}>23<AntdCheckbox24style={{25padding: "0 0.2em 0.2em 0.2em",26verticalAlign: "middle",27border: "1px solid transparent",28}}29checked={!!element.value}30disabled={setElement == null}31onChange={32setElement == null33? undefined34: () => {35setElement({ value: !element.value });36}37}38/>39{children}40</span>41);42}4344register({45slateType: "checkbox",46markdownType: "checkbox_input",47toSlate: ({ token }) => {48return {49type: "checkbox",50isVoid: true,51isInline: true,52value: token.checked,53children: [{ text: "" }],54};55},5657StaticElement,58});596061