How to use the @instructure/ui-react-utils.safeCloneElement function in @instructure/ui-react-utils

To help you get started, we’ve selected a few @instructure/ui-react-utils 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 instructure / instructure-ui / packages / ui-elements / src / TruncateText / index.js View on Github external
renderChildren (truncated, data, width) {
    if (!truncated) {
      return this._text
    }

    let childElements = []
    // iterate over each node used in the truncated string
    for (let i = 0; i < data.length; i++) {
      const item = data[i]
      const element = this._text.props.children[i]
      const nodeText = item.join('')

      if (element && element.props) {
        // if node is an html element and not just a string
        childElements.push(safeCloneElement(element, element.props, nodeText))
      } else {
        childElements.push(nodeText)
      }
    }
    // this spacer element is set to the max width the full text could potentially be
    // without this, text in `width: auto` elements won't expand to accomodate more text, once truncated
    childElements.push(<span width="" style="{{width:">)

    const children = React.Children.map(childElements, child =&gt; child)
    return (
      this._text.props
        ? safeCloneElement(this._text, this._text.props, children)
        : children
    )
  }
</span>
github instructure / instructure-ui / packages / ui-date-input / src / DateInput / index.js View on Github external
renderMonthNavigationButton (type = 'prev') {
    const { renderPrevMonthButton, renderNextMonthButton } = this.props
    const button = type === 'prev' ? renderPrevMonthButton : renderNextMonthButton
    return button && safeCloneElement(callRenderProp(button), { tabIndex: -1 })
  }
github instructure / instructure-ui / packages / ui-position / src / Position / index.js View on Github external
renderTarget () {
    let target = ComponentIdentifier.pick(Position.Target, this.props.children)
    if (!target) {
      target = callRenderProp(this.props.renderTarget)
    }

    if (target) {
      return safeCloneElement(target, {
        ref: el => { this._target = el },
        [Position.targetLocatorAttribute]: this._id
      })
    } else if (this.props.target) {
      this._target = callRenderProp(this.props.target)
    } else {
      return null
    }
  }
github instructure / instructure-ui / packages / ui-calendar / src / Calendar / index.js View on Github external
{row.map((day, i) =&gt; (
            
              {role === 'presentation'
                ? safeCloneElement(day, { 'aria-describedby': this._weekdayHeaderIds[i] })
                : day
              }
            
          ))}
github instructure / instructure-ui / packages / ui-calendar / src / Calendar / index.js View on Github external
    const cloneButton = (button, onClick) => safeCloneElement(button, {
      onClick: createChainedFunction(button.props.onClick, onClick)
    })
github instructure / instructure-ui / packages / ui-table / src / Table / Body / index.js View on Github external
{Children.map(children, (child) =&gt; matchComponentTypes(child, [Row])
          ? safeCloneElement(child, {
            key: child.props.name,
            hover,
            isStacked,
            headers,
          })
          : null)}
github instructure / instructure-ui / packages / ui-pages / src / Pages / index.js View on Github external
get activePage () {
    const { activePageIndex, children } = this.props
    const pages = React.Children.toArray(children)
    const activePage = (activePageIndex &lt; pages.length) ? pages[activePageIndex] : null

    error(activePage, '[Pages] Invalid `activePageIndex`.')

    return activePage ? safeCloneElement(activePage, {
      ref: (el) =&gt; { this._activePage = el }
    }) : null
  }
github instructure / instructure-ui / packages / ui-tabs / src / Tabs / index.js View on Github external
clonePanel (index, generatedId, selected, panel) {
    const id = panel.props.id || generatedId

    return safeCloneElement(panel, {
      id: panel.props.id || `panel-${id}`,
      labelledBy: `tab-${id}`,
      selected: undefined,
      isSelected: selected,
      key: panel.props.id || `panel-${id}`,
      variant: this.props.variant,
      padding: panel.props.padding || this.props.padding,
      textAlign: panel.props.textAlign || this.props.textAlign,
      maxHeight: panel.maxHeight || this.props.maxHeight,
      minHeight: panel.minHeight || this.props.minHeight
    })
  }
github instructure / instructure-ui / packages / ui-tabs / src / TabList / index.js View on Github external
clonePanel (index, cachedId, selected, panel) {
    const id = panel.props.id || cachedId
    return safeCloneElement(panel, {
      ref: (c) => {
        this._panels[index] = c
      },
      id: `panel-${id}`,
      labelledBy: `tab-${id}`,
      selected,
      key: `panel-${id}`,
      variant: this.props.variant,
      padding: panel.props.padding || this.props.padding,
      textAlign: panel.props.textAlign || this.props.textAlign,
      maxHeight: panel.maxHeight || this.props.maxHeight,
      minHeight: panel.minHeight || this.props.minHeight
    })
  }