Skip to content

bewestphal/react-scaled-component

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

React Scaled Component

Scale a react component dynamically to a height/width

For use with dynamically rendered components, such as those loaded from external sources https://github.com/bewestphal/url-component, to fit to a container component.

Example Usage

class RenderComponentPreview extends Component {
  constructor(props) {
    super(props)
    this.preview = React.createRef();
  }

  onImportLoad = () => {
    this.preview.current.setComponentSize()
  }

  render() {
    const {componentDef} = this.props
    
    var url = "https://cdnjs.cloudflare.com/ajax/libs/react-bootstrap/0.32.3/react-bootstrap.min.js"
    
    return (
      <ScaledComponent
        wrapperClass={styles.wrapperClass}
        maxHeight={150}
        maxWidth={150}
        ref={this.preview}
      >
        <URLComponent
          componentName="Alert"
          url={url}
          onComponentLoaded={this.onImportLoad}
        >
          Alert Text
        </URLComponent>
      </ScaledComponent>
    )
  }
}

About

Scale a react component dynamically to a height/width

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published