Skip to content

Commit

Permalink
Add support for multi-line label, #53
Browse files Browse the repository at this point in the history
  • Loading branch information
cocopon committed Jun 1, 2020
1 parent ff59169 commit 5f281c1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/doc/js/route/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,19 @@ ${indentedProps}
},

label: (container) => {
const PARAMS = {initSpd: 0};
const PARAMS = {
initSpd: 0,
size: 30,
};
const pane = new Tweakpane({
container: container,
});
pane.addInput(PARAMS, 'initSpd', {
label: 'Initial speed',
});
pane.addInput(PARAMS, 'size', {
label: 'Force field\nradius',
});
},

insert: (container) => {
Expand Down
3 changes: 3 additions & 0 deletions src/doc/template/misc.html
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ <h3>Custom label</h3>
pane.addInput(PARAMS, 'initSpd', {
<strong>label</strong>: 'Initial speed',
});
pane.addInput(PARAMS, 'size', {
<strong>label</strong>: 'Force field<strong>\n</strong>radius',
});
</code></pre></div>
</div>
<div class="common-demo_resultLayout">
Expand Down
18 changes: 17 additions & 1 deletion src/main/js/view/labeled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ interface Config extends ViewConfig {

const className = ClassName('lbl');

function createLabelNode(document: Document, label: string): DocumentFragment {
const frag = document.createDocumentFragment();

const lineNodes = label.split('\n').map((line) => {
return document.createTextNode(line);
});
lineNodes.forEach((lineNode, index) => {
if (index > 0) {
frag.appendChild(document.createElement('br'));
}
frag.appendChild(lineNode);
});

return frag;
}

/**
* @hidden
*/
Expand All @@ -23,7 +39,7 @@ export class LabeledView extends View {

const labelElem = document.createElement('div');
labelElem.classList.add(className('l'));
labelElem.textContent = this.label;
labelElem.appendChild(createLabelNode(document, this.label));
this.element.appendChild(labelElem);

const viewElem = document.createElement('div');
Expand Down
1 change: 1 addition & 0 deletions src/main/sass/components/_labeled.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
padding-right: 16px;
}
&_v {
align-self: flex-start;
flex-grow: 0;
flex-shrink: 0;
width: 160px;
Expand Down

0 comments on commit 5f281c1

Please sign in to comment.