carbon-react
Version:
A library of reusable React components for easily building user interfaces.
107 lines (106 loc) • 3.76 kB
TypeScript
import { DOMConversionMap, DOMExportOutput, EditorConfig, LexicalNode, NodeKey, SerializedTextNode, TextNode } from "lexical";
import { TypographyKey } from "../__ui__/Toolbar/buttons/typography.component";
export interface SerializedSpanNode extends SerializedTextNode {
fontWeight: string;
fontSize: string;
lineHeight: string;
}
export declare class StyledSpanNode extends TextNode {
__fontWeight: string;
__fontSize: string;
__lineHeight: string;
/**
* Returns the custom type when requested
* @returns the custom "styled-span" typing
*/
static getType(): string;
/**
* [INTERNAL] Copies the node. This method is internal to Lexical and should not be used;
* use $createStyledSpanNode instead.
*/
static clone(node: StyledSpanNode): StyledSpanNode;
/**
* Creates a new styled span node
* @param text The text of the node
* @param fontWeight The font weight
* @param fontSize The font size
* @param lineHeight The line height of the node
* @param key Lexical key
*/
constructor(text: string, fontWeight: string, fontSize: string, lineHeight: string, key?: NodeKey);
/**
* Gets the font weight of the node
* @returns The font weight
*/
getFontWeight(): string;
/**
* Gets the node's font size
* @returns The font size
*/
getFontSize(): string;
/**
* Gets the node's line height
* @returns The line height
*/
getLineHeight(): string;
/**
* Set the node's font weight
* @param weight the font's weight
*/
setFontWeight(weight: string): void;
/**
* Set the node's font size
* @param size the font's size
*/
setFontSize(size: string): void;
/**
* Set the node's font line height
* @param lineHeight the font's line height
*/
setLineHeight(lineHeight: string): void;
/**
* Determine the typography key based on the current styles
* @returns the variant of this styled span
*/
getTypographyKey(): TypographyKey;
exportDOM(): DOMExportOutput;
static importDOM(): DOMConversionMap | null;
exportJSON(): {
type: string;
version: number;
fontWeight: string;
fontSize: string;
lineHeight: string;
$?: Record<string, unknown> | undefined;
detail: number;
format: number;
mode: import("lexical").TextModeType;
style: string;
text: string;
};
static importJSON(serializedNode: SerializedSpanNode): StyledSpanNode;
createDOM(_config: EditorConfig): HTMLElement;
updateDOM(prevNode: StyledSpanNode, dom: HTMLElement, config: EditorConfig): boolean;
/**
* Factory-style helper method to create a StyledSpanNode from a typography key. Initial text can be provided, defaulting to an empty string.
* @param option Typography type to use
* @param text Text to set, or blank
* @returns StyledSpan node
*/
static createFromOption(option: TypographyKey, text?: string): StyledSpanNode;
}
/**
* Create a StyledSpanNode with default styles. Removes the need to manually specify the styles each time
* @param text The text of the node
* @param weight The font weight
* @param size The font size
* @param lineHeight The line height
* @returns a StyledSpanNode representing the config
*/
export declare function $createStyledSpanNode(text: string, weight: string, size: string, lineHeight: string): StyledSpanNode;
/**
* Determines whether a node is a StyledSpanNode
* @param node the node to check
* @returns true if a styled span, otherwise false
*/
export declare function $isStyledSpanNode(node: LexicalNode | null | undefined): node is StyledSpanNode;