JGuang

Typography

Typography · Arco Design

Preview
npm install @arco-design/web-react@2.66.18

Typography

Used to display titles, paragraphs, and text content.

Install

npm install @arco-design/web-react@2.66.18

Import @arco-design/web-react/dist/css/arco.css at the entry and set the locale with ConfigProvider. React 19 projects must also import @arco-design/web-react/es/_util/react-19-adapter first, or imperative APIs such as Message and Modal cannot render.

Examples

  • Basic: Display headings, paragraphs, and text content.
  • Title: Show titles of different levels.
  • Text: Different styles of text.
  • Paragraph: Paragraph style.
  • Interactive: Provide functions such as copying and editing text.
  • Text Ellipsis(Recommended): When the text content exceeds the container, an ellipsis will be automatically displayed. When rows = 1, a single row is omitted. At this time, the operation button will not be displayed by default. You can set expandable = { single: true } to enable it.
  • Text Ellipsis - Action Button(Recommended): Customize action buttons through expandRender.
  • Ellipsis(Not recommended): It is not recommended to use the ellipsis attribute to enable folding. It is recommended to use the Typography.Ellipsis component instead. Omit multiple lines of text when there is insufficient space. Note: In the parent element flex mode, the omitted Typography's ellipsis scene will be affected. You can add width: 100% to make the Typography fill the entire parent element. **Attention: Attention: Using Google Translate results in a white screen error on the page? ** The component uses React.Fragement to cause problems. React native issues (Issue link). It can be solved by setting ellipsis.wrapper. For example ellipsis={{ wrapper: 'span' }}.
  • Ellipsis Controlled (Not recommended): It is not recommended to use the ellipsis attribute to enable folding. It is recommended to use the Typography.Ellipsis component instead. Ellipsis and related configuration controlled cases

Examples come from the official Arco Design repository (MIT) at the commit published as npm 2.66.18. Some use online images or upload endpoints; network requests are disabled in previews.

API

Typography

PropertyDescriptionTypeDefaultValue
classNameAdditional css classstring | string[]-
styleAdditional styleCSSProperties-

Typography.Title

PropertyDescriptionTypeDefaultValueVersion
boldBold styleboolean--
codeCode block styleboolean--
deleteStrikethrough styleboolean--
disabledDisabled styleboolean--
underlineUnderline styleboolean--
typeText type'primary' | 'secondary' | 'success' | 'error' | 'warning'--
classNameAdditional css classstring | string[]--
ellipsisAuto overflow omitted, see EllipsisConfig。Deprecated, Typography.Ellipsis is recommended insteadboolean | EllipsisConfig--
headingHeading level, equivalent to h1 h2 h3 h4 h5 h61 | 2 | 3 | 4 | 5 | 61-
markMark styleboolean | { color: string }--
styleAdditional styleCSSProperties--
copyableWhether to be copyable| boolean| {text?: string;onCopy?: (text: string, e) => void;icon?: ReactNode;tooltips?: [ReactNode, ReactNode];tooltipProps?: TooltipProps;}-onCopy params e in 2.31.0
editableIf editable. Can control edit state when is object| boolean| {editing?: boolean;tooltipProps?: TooltipProps;onStart?: (text, e) => void;onChange?: (text) => void;onEnd?: (text) => void;}-onStart params e in 2.31.0

Typography.Paragraph

PropertyDescriptionTypeDefaultValueVersion
blockquoteBlockquote styleboolean--
boldBold styleboolean--
codeCode block styleboolean--
deleteStrikethrough styleboolean--
disabledDisabled styleboolean--
underlineUnderline styleboolean--
spacingThe line height of the paragraph. The default line height is recommended for long text (more than 5 lines),and the close line height of close is recommended for short text (less than or equal to 3 lines).'default' | 'close'default-
typeText type'primary' | 'secondary' | 'success' | 'error' | 'warning'--
classNameAdditional css classstring | string[]--
ellipsisAuto overflow omitted, see EllipsisConfig。Deprecated, Typography.Ellipsis is recommended insteadboolean | EllipsisConfig--
markMark styleboolean | { color: string }--
styleAdditional styleCSSProperties--
copyableWhether to be copyable| boolean| {text?: string;onCopy?: (text: string, e) => void;icon?: ReactNode;tooltips?: [ReactNode, ReactNode];tooltipProps?: TooltipProps;}-onCopy params e in 2.31.0
editableIf editable. Can control edit state when is object| boolean| {editing?: boolean;tooltipProps?: TooltipProps;onStart?: (text, e) => void;onChange?: (text) => void;onEnd?: (text) => void;}-onStart params e in 2.31.0

Typography.Text

PropertyDescriptionTypeDefaultValueVersion
boldBold styleboolean--
codeCode block styleboolean--
deleteStrikethrough styleboolean--
disabledDisabled styleboolean--
underlineUnderline styleboolean--
typeText type'primary' | 'secondary' | 'success' | 'error' | 'warning'--
classNameAdditional css classstring | string[]--
ellipsisAuto overflow omitted, see EllipsisConfig。Deprecated, Typography.Ellipsis is recommended insteadboolean | EllipsisConfig--
markMark styleboolean | { color: string }--
styleAdditional styleCSSProperties--
copyableWhether to be copyable| boolean| {text?: string;onCopy?: (text: string, e) => void;icon?: ReactNode;tooltips?: [ReactNode, ReactNode];tooltipProps?: TooltipProps;}-onCopy params e in 2.31.0
editableIf editable. Can control edit state when is object| boolean| {editing?: boolean;tooltipProps?: TooltipProps;onStart?: (text, e) => void;onChange?: (text) => void;onEnd?: (text) => void;}-onStart params e in 2.31.0

EllipsisConfig

PropertyDescriptionTypeDefaultValueVersion
cssEllipsisAutomatic overflow omission (only strings are supported). In the case of simple single-line, css will be used by default to handle ellipsis to avoid complicated calculations.boolean-2.36.0 将默认值改为 false 并支持多行CSS省略。
defaultExpandedDefault expanded stateboolean-2.33.0
expandableWhether to support expandboolean--
expandedwhether to expandboolean-2.33.0
rowsThe number of omitted rowsnumber1-
ellipsisStrellipsis stringstring...-
suffixSuffixstring--
showTooltipShow Tooltip when configure ellipsisboolean | { type?: 'tooltip' | 'popover'; props?: Record<string, any> }--
expandNodesConfigure expand elementsReactNode[]--
onEllipsisCallback when the ellipsis state changes, usually triggered by window resize。(isEllipsis: boolean) => void--
onExpandCallback when the expand state changes, usually triggered by clicking the button(isExpand: boolean, e) => void-e in 2.27.0

Typography.Ellipsis

PropertyDescriptionTypeDefaultValue
defaultExpandedExpand by defaultboolean-
disabledWhether to disable the text ellipsisboolean-
expandedWhether to expandboolean-
rowsThe number of omitted rowsnumber1
classNameAdditional css classstring | string[]-
expandableWhether to show control button. 2.61.0 version supports single attributeboolean | { single?: boolean }true
showTooltipWhether to display pop-up promptsboolean | TooltipProps-
styleAdditional styleCSSProperties-
expandRenderCustom rendering control buttons(expanded: boolean) => ReactNode-
onEllipsisTriggered when the omission status changes, and also when omitted for the first time.(isEllipsis: boolean) => void-
onExpandTriggered when clicked to expand or collapse(isExpand: boolean, ev: Event) => void-

About exceeding omission

Exceeding and omitting are currently implemented in two ways: js dichotomy calculation truncation value and CSS exceeding and omitting. The two advantages and disadvantages are as follows:

Metricsjs DichotomyCSS Omit
PerformancePoor (multiple operations of dom calculation by dichotomy)Good
FunctionGoodPoor (string only)
  • By default, js dichotomy is used to continuously truncate the calculation to obtain the omitted critical value. At the same time, recalculation will be triggered multiple times when resize. Therefore, heavy use has a greater impact on performance, but this method will not insert additional style dom under the typesetting component.

  • Enabling ellipsis.cssEllipsis will omit the display by CSS style, which will significantly improve the performance in a large number of usage scenarios. But because the text-overflow style needs to be added, two <span/> dom will be added under the .arco-typography node

Note that the 2.36.0 version refactors and optimizes the excess omission, resulting in the main breaking changes as follows:

  • When ellipsis.cssEllipsis is enabled, an extra style dom is inserted under the typesetting component in order to add text-overflow, causing the dom structure to change.
  • ellipsis.cssEllipsis supports multi-line elision scenarios, and the default value is changed from true to false (to avoid DOM structure changes after upgrade).