Skip to content

Commit

Permalink
issue/2876 JSX version of text
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverfoster authored Aug 26, 2021
2 parents c9bd0d1 + ab178c7 commit df4f5fb
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 59 deletions.
3 changes: 3 additions & 0 deletions js/TextModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import ComponentModel from 'core/js/models/componentModel';

export default class TextModel extends ComponentModel {}
30 changes: 30 additions & 0 deletions js/TextView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import ComponentView from 'core/js/views/componentView';

class TextView extends ComponentView {

postRender() {
this.setReadyStatus();
this.setupInview();
}

setupInview() {
const selector = this.getInviewElementSelector();
if (!selector) return this.setCompletionStatus();
this.setupInviewCompletion(selector);
}

/**
* determines which element should be used for inview logic - body, instruction or title - and returns the selector for that element
*/
getInviewElementSelector() {
if (this.model.get('body')) return '.component__body';
if (this.model.get('instruction')) return '.component__instruction';
if (this.model.get('displayTitle')) return '.component__title';
return null;
}

}

TextView.template = 'text.jsx';

export default TextView;
62 changes: 6 additions & 56 deletions js/adapt-contrib-text.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,8 @@
define([
'core/js/adapt',
'core/js/views/componentView',
'core/js/models/componentModel'
], function(Adapt, ComponentView, ComponentModel) {
import Adapt from 'core/js/adapt';
import TextView from './TextView';
import TextModel from './TextModel';

class TextView extends ComponentView {

preRender() {
this.checkIfResetOnRevisit();
}

postRender() {
this.setReadyStatus();

this.setupInview();
}

setupInview() {
const selector = this.getInviewElementSelector();
if (!selector) {
this.setCompletionStatus();
return;
}

this.setupInviewCompletion(selector);
}

/**
* determines which element should be used for inview logic - body, instruction or title - and returns the selector for that element
*/
getInviewElementSelector() {
if (this.model.get('body')) return '.component__body';

if (this.model.get('instruction')) return '.component__instruction';

if (this.model.get('displayTitle')) return '.component__title';

return null;
}

checkIfResetOnRevisit() {
const isResetOnRevisit = this.model.get('_isResetOnRevisit');

// If reset is enabled set defaults
if (isResetOnRevisit) {
this.model.reset(isResetOnRevisit);
}
}
}

TextView.template = 'text';

return Adapt.register('text', {
model: ComponentModel.extend({}),// create a new class in the inheritance chain so it can be extended per component type if necessary later
view: TextView
});
export default Adapt.register('text', {
model: TextModel,
view: TextView
});
3 changes: 0 additions & 3 deletions templates/text.hbs

This file was deleted.

10 changes: 10 additions & 0 deletions templates/text.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import { templates } from 'core/js/reactHelpers';

export default function Text(props) {
return (
<div className="component__inner text__inner">
<templates.header {...props} />
</div>
);
}

0 comments on commit df4f5fb

Please sign in to comment.