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

Modernize bgcolor #294

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213,909 changes: 213,762 additions & 147 deletions dist/ParaViewWeb.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/Component/Native/BackgroundColor/body.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="bg-color-container">
<div class="bg-color-placeholder">
</div>
</div>
96 changes: 68 additions & 28 deletions src/Component/Native/BackgroundColor/index.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,76 @@
/* eslint-disable class-methods-use-this */

export default class NativeBackgroundColorComponent {
constructor(color, el) {
this.color = color;
this.setContainer(el);
this.previousColor = '';
}

/*
* We must not mess with the position properties of the style on the container
* we are given, or we will break the workbench layout functionality! Setting the
* background color is fine, however, as long as we don't use the setAttribute()
* approach to this. Also, we could always create our own container
* within the element we are given, and we can do whatever we want with that.
*/

setContainer(el) {
if (this.el) {
this.el.style['background-color'] = this.previousColor;
import style from 'PVWStyle/ComponentNative/BackgroundColor.mcss';
import htmlContent from './body.html';
import CompositeClosureHelper from '../../../Common/Core/CompositeClosureHelper';

function backgroundColorComponent(publicAPI, model) {
publicAPI.resize = () => {
// When using this component as a template, respond
// to resize events by updating the DOM to match.
};

publicAPI.setContainer = (el) => {
if (model.container) {
while (model.container.firstChild) {
model.container.removeChild(model.container.firstChild);
}
}

this.el = el;
model.container = el;

if (model.container) {
// Create placeholder
model.container.innerHTML = htmlContent;

// Apply style
const colorEle = model.container.querySelector('.bg-color-container');
colorEle.classList.add(style.bgColorContainer);
colorEle.style.backgroundColor = model.color;
}
};

if (el) {
this.previousColor = this.el.style['background-color'];
this.el.style['background-color'] = this.color;
publicAPI.setColor = (colorSpec) => {
let color = colorSpec;
if (typeof colorSpec !== 'string' || colorSpec === '') {
color = 'inherit';
}
model.color = color;
if (model.container) {
model.container.querySelector('.bg-color-container').style.backgroundColor = model.color;
}
}
};

// When removing this component, clean up its container and call the parent
// object's destroy method:
publicAPI.destroy = CompositeClosureHelper.chain(() => {
publicAPI.setContainer(null);
}, publicAPI.destroy);
}

render() {}
// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------

resize() {}
const DEFAULT_VALUES = {
container: null,
color: 'inherit',
};

destroy() {}
// ----------------------------------------------------------------------------

export function extend(publicAPI, model, initialValues = {}) {
Object.assign(model, DEFAULT_VALUES, initialValues);

CompositeClosureHelper.destroy(publicAPI, model);
CompositeClosureHelper.isA(publicAPI, model, 'VizComponent');
CompositeClosureHelper.get(publicAPI, model, ['color', 'container']);

backgroundColorComponent(publicAPI, model);
}

// ----------------------------------------------------------------------------

export const newInstance = CompositeClosureHelper.newInstance(extend);

// ----------------------------------------------------------------------------

export default { newInstance, extend };
10 changes: 5 additions & 5 deletions src/Component/Native/Composite/example/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import CompositeComponent from '..';
import BGColorComponent from '../../BackgroundColor';
import BackgroundColor from '../../BackgroundColor';

// Load CSS
require('normalize.css');
Expand All @@ -10,10 +10,10 @@ container.style.width = '100%';
container.style.height = '600px';

const composite = new CompositeComponent();
const green = new BGColorComponent('green');
const red = new BGColorComponent('red');
const blue = new BGColorComponent('blue');
const pink = new BGColorComponent('pink');
const green = BackgroundColor.newInstance({ color:'green' });
const red = BackgroundColor.newInstance({ color:'red' });
const blue = BackgroundColor.newInstance({ color:'blue' });
const pink = BackgroundColor.newInstance({ color:'pink' });

composite.addViewport(green);
composite.addViewport(red);
Expand Down
4 changes: 2 additions & 2 deletions src/Component/Native/ToggleControl/example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import 'normalize.css';
const container = document.querySelector('.content');
container.style.height = '100vh';

const green = new BGColorComponent('green');
const red = new BGColorComponent('red');
const green = BGColorComponent.newInstance({ color:'green' });
const red = BGColorComponent.newInstance({ color:'red' });
const toggleView = new ToggleControlComponent(green, red);

toggleView.setContainer(container);
Expand Down
10 changes: 5 additions & 5 deletions src/Component/Native/Workbench/example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ const container = document.querySelector('.content');
container.style.height = '100vh';
container.style.width = '100vw';

const green = new BGColor('green');
const red = new BGColor('red');
const blue = new BGColor('blue');
const pink = new BGColor('pink');
const gray = new BGColor('gray');
const green = BGColor.newInstance({ color:'green' });
const red = BGColor.newInstance({ color:'red' });
const blue = BGColor.newInstance({ color:'blue' });
const pink = BGColor.newInstance({ color:'pink' });
const gray = BGColor.newInstance({ color:'gray' });

// const toggleView = new ToggleControl(green, red);

Expand Down
11 changes: 11 additions & 0 deletions style/ComponentNative/BackgroundColor.mcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.bgColorContainer {
border-radius: 15px;
font-family: "Optima", "Linux Biolinum", "URW Classico", sans;
position: absolute;
top: 5px;
right: 5px;
bottom: 5px;
left: 5px;
pointer-events: none;
overflow: hidden;
}