How to use @create-figma-plugin/utilities - 4 common examples

To help you get started, we’ve selected a few @create-figma-plugin/utilities examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yuanqing / create-figma-plugin / packages / ui / src / components / textbox / textbox-numeric / textbox-numeric.js View on Github external
function (event) {
      const keyCode = event.keyCode
      if (keyCode === ESCAPE_KEY_CODE) {
        if (propagateEscapeKeyDown === false) {
          event.stopPropagation()
        }
        inputElementRef.current.blur()
        return
      }
      if (keyCode === DOWN_KEY_CODE || keyCode === UP_KEY_CODE) {
        event.preventDefault()
        const evaluatedValue = evaluateNumericExpression(value)
        if (
          (event.keyCode === DOWN_KEY_CODE && evaluatedValue <= minimum) ||
          (event.keyCode === UP_KEY_CODE && evaluatedValue >= maximum)
        ) {
          return
        }
        const delta = event.shiftKey === true ? bigIncrement : smallIncrement
        const newValue =
          event.keyCode === DOWN_KEY_CODE
            ? Math.max(evaluatedValue - delta, minimum)
            : Math.min(evaluatedValue + delta, maximum)
        const significantFiguresCount = countSignificantFigures(
          nonDigitRegex.test(value) === true ? `${evaluatedValue}` : value
        )
        inputElementRef.current.value = formatSignificantFigures(
          newValue,
github yuanqing / create-figma-plugin / packages / ui / src / components / textbox / textbox-numeric / textbox-numeric.js View on Github external
nonDigitRegex.test(value) === true ? `${evaluatedValue}` : value
        )
        inputElementRef.current.value = formatSignificantFigures(
          newValue,
          significantFiguresCount
        )
        handleInput()
        handleFocus()
        return
      }
      if (event.ctrlKey === true || event.metaKey === true) {
        return
      }
      if (isKeyCodeCharacterGenerating(event.keyCode) === true) {
        const nextValue = computeNextValue(inputElementRef.current, event.key)
        if (isValidNumericInput(nextValue, isInteger) === false) {
          event.preventDefault()
          return
        }
        const evaluatedValue = evaluateNumericExpression(nextValue)
        if (evaluatedValue < minimum || evaluatedValue > maximum) {
          event.preventDefault()
        }
      }
    },
    [
github yuanqing / create-figma-plugin / packages / ui / src / components / textbox / textbox-numeric / textbox-numeric.js View on Github external
significantFiguresCount
        )
        handleInput()
        handleFocus()
        return
      }
      if (event.ctrlKey === true || event.metaKey === true) {
        return
      }
      if (isKeyCodeCharacterGenerating(event.keyCode) === true) {
        const nextValue = computeNextValue(inputElementRef.current, event.key)
        if (isValidNumericInput(nextValue, isInteger) === false) {
          event.preventDefault()
          return
        }
        const evaluatedValue = evaluateNumericExpression(nextValue)
        if (evaluatedValue < minimum || evaluatedValue > maximum) {
          event.preventDefault()
        }
      }
    },
    [
github yuanqing / create-figma-plugin / packages / ui / src / components / textbox / textbox-numeric / textbox-numeric.js View on Github external
function (event) {
      const nextValue = computeNextValue(
        inputElementRef.current,
        event.clipboardData.getData('Text')
      )
      if (isValidNumericInput(nextValue, isInteger) === false) {
        event.preventDefault()
      }
    },
    [isInteger]

@create-figma-plugin/utilities

An extensive library of utility functions for common Figma/FigJam plugin/widget operations

MIT
Latest version published 13 days ago

Package Health Score

66 / 100
Full package analysis