Skip to content

Instantly share code, notes, and snippets.

@diegohaz
Last active August 18, 2022 12:39
Show Gist options
  • Save diegohaz/c48c82775c0ac36fda45987e73e9787c to your computer and use it in GitHub Desktop.
Save diegohaz/c48c82775c0ac36fda45987e73e9787c to your computer and use it in GitHub Desktop.
import {
createEditorComponent,
createEditorInput,
useEditorInput,
useEditorInputValue,
} from "editor";
import {
Text,
TextProps,
} from "editor/components";
type HeadingProps = TextProps & {
inputs: {
level?: number;
};
};
const Heading = createEditorComponent<HeadingProps>((props) => {
const level = useEditorInput("HeadingLevel", { ...props, name: "level", label: "Heading level" });
const component = `h${level}`;
return <Text {...props} as={component} />;
});
Heading.defaultInputs = {
level: 1,
};
Heading.triggers = {
"#{1,6}": (text) => ({
inputs: {
level: text.length,
},
});
};
const HeadingLevel = createEditorInput<HeadingProps>((props) => {
useEditorInputValue(props, "");
...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment