Skip to content

useTypography

useTypography() is the text-property control composable for text editing panels.

It exposes:

  • font family
  • font weight
  • font size
  • formatting state
  • missing-font status
  • helpers for changing family, weight, alignment, and decorations

Usage

ts
import { useTypography } from '@open-pencil/vue'

const typography = useTypography()

Basic example

ts
const {
  fontFamily,
  fontWeight,
  fontSize,
  activeFormatting,
  setFamily,
  setWeight,
  setAlign,
} = useTypography()

Practical examples

Load and switch a font family

ts
const typography = useTypography({
  loadFont: async (family, style) => {
    await myFontLoader(family, style)
  },
})

Toggle formatting

ts
typography.toggleBold()
typography.toggleItalic()
typography.toggleDecoration('UNDERLINE')

Released under the MIT License.