How to use the @instructure/ui-react-utils.ensureSingleChild 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
!((() => {
        let isTooDeep = false
        const text = ensureSingleChild(this.props.children)
        React.Children.forEach(text.props.children, (child) => {
          if (child.props) {
            React.Children.forEach(child.props.children, (grandChild) => {
              // currently we don't support node trees deeper than 2 levels
              // truncation will still occur on their text content, but their actual node structure will be lost
              if (grandChild.props) {
                isTooDeep = true
              }
            })
          }
        })
        return isTooDeep
      })()),
      `[TruncateText] Some children are too deep in the node tree and will not render.`
github instructure / instructure-ui / packages / ui-position / src / Position / index.js View on Github external
renderContent () {
    let content = ComponentIdentifier.pick(Position.Content, this.props.children)
    if (!content) {
      content = ensureSingleChild(this.props.children)
    }

    if (content) {
      content = safeCloneElement(content, {
        ref: el => { this._content = el },
        style: {
          ...content.props.style,
          ...this.state.style
        },
        className: classnames({
          [styles.root]: true,
          [content.props.className]: content.props.className // eslint-disable-line react/prop-types
        }),
        [Position.contentLocatorAttribute]: this._id
      })
github instructure / instructure-ui / packages / ui-motion / src / Transition / BaseTransition.js View on Github external
renderChildren () {
    return safeCloneElement(ensureSingleChild(this.props.children), {
      'aria-hidden': !this.props.in ? true : null
    })
  }
github instructure / instructure-ui / packages / ui-overlays / src / Mask / index.js View on Github external
render () {
    const content = ensureSingleChild(this.props.children, {
      ref: this.contentRef
    })

    const classes = classnames({
      [styles.root]: true,
      [styles[this.props.placement]]: true,
      [styles.fullscreen]: this.props.fullscreen
    })

    const props = {
      ...omitProps(this.props, Mask.propTypes),
      className: classes,
      ref: this.handleElementRef
    }

    if (typeof this.props.onClick === 'function') {
github instructure / instructure-ui / packages / ui-tooltip / src / Tooltip / index.js View on Github external
)
    } else if (typeof children === 'function') {
      return children(
        {
          focused: hasFocus,
          getTriggerProps: (props) => {
            return {
              ...triggerProps,
              ...props
            }
          }
        }
      )
    } else {
      return ensureSingleChild(this.props.children, triggerProps)
    }
  }
github instructure / instructure-ui / packages / ui-elements / src / TruncateText / index.js View on Github external
const { maxLines, children } = this.props

    return (
      <span> {
          this._ref = el
        }}
      &gt;
        {children &amp;&amp; (
          truncatedElement ? null : (
            <span> {this._stage = el}}&gt;
              {ensureSingleChild(children)}
            </span>
          )
        )}
        {truncatedElement}
      </span>
    )
  }
}
github instructure / instructure-ui / packages / ui-elements / src / TruncateText / index.js View on Github external
componentDidMount () {
    const { children } = this.props

    if (children) {
      this.checkChildren()
      this._text = ensureSingleChild(children)

      this.truncate()

      if (this.props.debounce === 0) {
        this._resizeListener = addResizeListener(this._ref, this.update)
      } else {
        this._debounced = debounce(this.update, this.props.debounce, { leading: true, trailing: true })
        this._resizeListener = addResizeListener(this._ref, this._debounced)
      }
    }
  }