Skip to content

Commit

Permalink
feature: support props.wrapStyle (#70)
Browse files Browse the repository at this point in the history
* feature: support props.wrapStyle

* fix: delete parcelProps.wrapWith in getParcelProps()

Co-authored-by: ermin.zem <[email protected]>
  • Loading branch information
harbin1053020115 and alijs authored Mar 20, 2020
1 parent a27e052 commit bee0bb0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/parcel.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {SingleSpaContext} from '../lib/single-spa-react.js'
export default class Parcel extends React.Component {
static defaultProps = {
wrapWith: 'div',
wrapStyle: {},
parcelDidMount: () => {},
}
constructor(props) {
Expand Down Expand Up @@ -36,6 +37,9 @@ export default class Parcel extends React.Component {
domElement = this.el
} else {
this.createdDomElement = domElement = document.createElement(this.props.wrapWith)
Object.keys(this.props.wrapStyle).forEach(key => {
domElement.style[key] = this.props.wrapStyle[key];
});
this.props.appendTo.appendChild(domElement)
}
this.parcel = mountParcel(this.props.config, {domElement, ...this.getParcelProps()})
Expand Down Expand Up @@ -91,7 +95,7 @@ export default class Parcel extends React.Component {
)
: undefined

return React.createElement(this.props.wrapWith, {ref: this.handleRef}, children)
return React.createElement(this.props.wrapWith, {ref: this.handleRef, style: this.props.wrapStyle}, children)
}
}
handleRef = el => {
Expand Down Expand Up @@ -136,6 +140,7 @@ export default class Parcel extends React.Component {
delete parcelProps.mountParcel
delete parcelProps.config
delete parcelProps.wrapWith
delete parcelProps.wrapStyle
delete parcelProps.appendTo
delete parcelProps.handleError
delete parcelProps.parcelDidMount
Expand Down
5 changes: 5 additions & 0 deletions src/parcel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ describe(`<Parcel />`, () => {
expect(wrapper.find('div').length).toBe(1)
})

it(`renders a div wrap with style`, () => {
const wrapper = mount(<Parcel {...props} wrapStyle={{ height: '100px' }} />);
expect(/style\=\"height\:\s{1}100px;\"/.test(wrapper.find('div').html())).toBe(true);
})

it(`calls the mountParcel prop when it mounts`, () => {
const wrapper = mount(<Parcel {...props} />)
return wrapper.instance().nextThingToDo.then(() => {
Expand Down

0 comments on commit bee0bb0

Please sign in to comment.