Skip to content

Commit

Permalink
Support passing elements for text (#493)
Browse files Browse the repository at this point in the history
Fixes #492
  • Loading branch information
RobbieTheWagner authored Aug 9, 2019
1 parent c5bde9b commit 55086da
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
5 changes: 4 additions & 1 deletion demo/js/welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,14 @@
useModalOverlay: true
});

const element = document.createElement('p');
element.innerText = 'Including Shepherd is easy! Just include shepherd.js. The styles are bundled with the JS.';

// These steps should be added via `addSteps`
const steps = [
{
title: 'Including',
text: 'Including Shepherd is easy! Just include shepherd.js. The styles are bundled with the JS.',
text: element,
attachTo: {
element: '.hero-including',
on: 'bottom'
Expand Down
21 changes: 19 additions & 2 deletions src/js/components/shepherd-content/shepherd-text/index.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
import preact from 'preact';
import { isFunction } from '../../../utils/type-check';
import { isElement, isFunction } from '../../../utils/type-check';

const { Component } = preact;

export default class ShepherdText extends Component {
shouldComponentUpdate() {
return false;
}

componentDidMount() {
const { step } = this.props;
let { text } = step.options;

if (isFunction(text)) {
text = text.call(step);
}

if (isElement(text)) {
this.base.appendChild(text);
}
}

render(props) {
const { descriptionId, step, styles } = props;
let { text } = step.options;
Expand All @@ -14,7 +31,7 @@ export default class ShepherdText extends Component {

return <div
className={styles.text.trim()}
dangerouslySetInnerHTML={{ __html: text }}
dangerouslySetInnerHTML={{ __html: !isElement(text) ? text : null }}
id={descriptionId}
/>;
}
Expand Down

0 comments on commit 55086da

Please sign in to comment.