Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added React component factory. #3931

Merged
merged 1 commit into from
May 14, 2018
Merged

Conversation

Hyperkid123
Copy link
Contributor

@Hyperkid123 Hyperkid123 commented May 14, 2018

Component factory for mounting react components.

Usage

  • Define react component in app/javascript/packs/component-definitions-common.js
import ComponentName from '../components/ComponentName'; // or other location

// simple definition
  ManageIQ.component.addReact('ComponentName', ComponentName);

// with extra props
  ManageIQ.component.addReact('ComponentName', props => <ComponentName {...props} />);
  • Create root element in template and call factory:
// explicit props definition
#root-element{data-first-props => "something",
              data-second-prop => @rubyObject.property}

//or create props structure from object:
#root-element{:data => {:first-prop => "something", :second-prop => @rubyObject.property}}

javascript:
  ManageIQ.component.componentFactory('ComponentName', '#root-element', [{optional props object}]);

Props

To pass some initial props to component use data attributes on the root element.
Attribue data-first-prop is equal to firstProp prop in React component.

If you want to use prop name, that is not in camel case, use the third optional parameter of ManageIQ.component.componentFactory. It expects a JSON object.

@Hyperkid123
Copy link
Contributor Author

@miq-bot assign @himdel
@miq-bot assign @karelhala
@miq-bot assign @martinpovolny

@miq-bot
Copy link
Member

miq-bot commented May 14, 2018

Checked commit Hyperkid123@febdb42 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
0 files checked, 0 offenses detected
Everything looks fine. ⭐

@himdel himdel merged commit 6cd130d into ManageIQ:master May 14, 2018
@Hyperkid123 Hyperkid123 deleted the component-factory branch May 14, 2018 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants