Skip to content

Commit

Permalink
Placeholder param. Closes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
kgolinski committed May 24, 2022
1 parent d2ec9dd commit 7fb19ae
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const params = {

pane.addInput(params, 'prop', {
view: 'textarea',
placeholder: 'Type here...'
}).on('change', (ev) => {
console.log(ev.value);
});
Expand Down
23 changes: 12 additions & 11 deletions src/controller.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import {Controller, forceCast, Value, ViewProps} from '@tweakpane/core';
import { Controller, forceCast, Value, ViewProps } from '@tweakpane/core';

import {TextAreaView} from './view';
import { TextAreaView } from './view';
/**
* @hidden
*/
export interface Config {
value: Value<string>;
viewProps: ViewProps;
lineCount: number;
placeholder: string;
}

/**
Expand All @@ -18,34 +19,34 @@ export class TextAreaController implements Controller<TextAreaView> {
public readonly view: TextAreaView;
public readonly viewProps: ViewProps;
public readonly lineCount: number;
public readonly placeholder: string;

constructor(doc: Document, config: Config) {
this.onInputChange_ = this.onInputChange_.bind(this);
this.value = config.value;
this.viewProps = config.viewProps;
this.lineCount = config.lineCount;
this.placeholder = config.placeholder;

console.log( this.lineCount )
// console.log( this.lineCount )

this.view = new TextAreaView(doc, {
value: this.value,
viewProps: this.viewProps,
lineCount: this.lineCount
lineCount: this.lineCount,
placeholder: this.placeholder,
});
this.view.inputElement.addEventListener('keyup', this.onInputChange_);
}

private onInputChange_(e: KeyboardEvent): void {

//console.log( e.key )

//if( e.key === 'Enter' ){
const inputElem: HTMLInputElement = forceCast(e.currentTarget);
const value = inputElem.value;
this.value.rawValue = value;
this.view.refresh();
const inputElem: HTMLInputElement = forceCast(e.currentTarget);
const value = inputElem.value;
this.value.rawValue = value;
this.view.refresh();
//}


}
}
7 changes: 5 additions & 2 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {TextAreaController} from './controller';
export interface PluginInputParams extends BaseInputParams {
view: 'textarea';
lineCount?: number;
placeholder?: string;
}

// NOTE: You can see JSDoc comments of `InputBindingPlugin` for details about each property
Expand Down Expand Up @@ -43,12 +44,13 @@ export const TweakpaneTextareaPlugin: InputBindingPlugin<
}

// Parse parameters object
console.log( params)
// console.log(params)
const p = ParamsParsers;
const result = parseParams<PluginInputParams>(params, {
// `view` option may be useful to provide a custom control for primitive values
view: p.required.constant('textarea'),
lineCount: p.optional.number
lineCount: p.optional.number,
placeholder: p.optional.string
});
if (!result) {
return null;
Expand Down Expand Up @@ -83,6 +85,7 @@ export const TweakpaneTextareaPlugin: InputBindingPlugin<
return new TextAreaController(args.document, {
value: args.value,
lineCount: args.params.lineCount ?? 3,
placeholder: args.params.placeholder ?? 'Enter text here',
viewProps: args.viewProps,
});
},
Expand Down
3 changes: 2 additions & 1 deletion src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ interface Config {
value: Value<string>;
viewProps: ViewProps;
lineCount: number;
placeholder: string;
}

const className = ClassName('txtr');
Expand All @@ -25,7 +26,7 @@ export class TextAreaView implements View {
const inputElem = doc.createElement('textarea');
inputElem.rows = config.lineCount;
inputElem.cols = 22;
inputElem.placeholder = 'Enter text here';
inputElem.placeholder = config.placeholder;
inputElem.classList.add(className('i'));

config.viewProps.bindDisabled(inputElem);
Expand Down
3 changes: 2 additions & 1 deletion test/browser.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
// Add text area input
pane.addInput(params, 'prop', {
view: 'textarea',
lineCount: 6
lineCount: 6,
placeholder: 'Type here...',
}).on('change', (ev) => {
console.log( ev.value );
document.getElementById('output').textContent = ev.value
Expand Down

0 comments on commit 7fb19ae

Please sign in to comment.