Skip to content
Snippets Groups Projects
Commit 5240e7d8 authored by Glenn Vorhes's avatar Glenn Vorhes
Browse files

use default react imports

parent da3310dc
No related branches found
No related tags found
No related merge requests found
...@@ -3,21 +3,23 @@ ...@@ -3,21 +3,23 @@
*/ */
import React = require("react"); import React = require("react");
import 'jquery-ui'; import 'jquery-ui';
export interface iRadioItem { export interface iRadioItemOpt {
index?: number;
}
export interface iRadioItem extends iRadioItemOpt {
groupId: string; groupId: string;
text: string; text: string;
checked: boolean; checked: boolean;
inline: boolean; inline: boolean;
change: (s: string) => any; change: (s: string) => any;
connected: boolean; connected?: boolean;
index: number;
} }
export declare class Radio extends React.Component<{ export declare class Radio extends React.Component<{
title: string; title: string;
items: string[]; items: string[];
callback: (val: string) => any; callback: (val: string) => any;
inline?: boolean;
defaultValue: string; defaultValue: string;
inline?: boolean;
classes?: string[]; classes?: string[];
}, {}> { }, {}> {
render(): JSX.Element; render(): JSX.Element;
......
...@@ -42,10 +42,6 @@ class RadioItem extends React.Component { ...@@ -42,10 +42,6 @@ class RadioItem extends React.Component {
React.createElement("label", { htmlFor: this.guid }, this.props.text)); React.createElement("label", { htmlFor: this.guid }, this.props.text));
} }
} }
RadioItem.defaultProps = {
connected: false,
index: null
};
class RadioBase extends React.Component { class RadioBase extends React.Component {
constructor(props, context) { constructor(props, context) {
super(props, context); super(props, context);
...@@ -83,9 +79,29 @@ class RadioBase extends React.Component { ...@@ -83,9 +79,29 @@ class RadioBase extends React.Component {
React.createElement("ul", { style: { listStyle: 'none' } }, arr)); React.createElement("ul", { style: { listStyle: 'none' } }, arr));
} }
} }
RadioBase.defaultProps = { //
inline: false // interface _iRadioBaseOpt {
}; // inline?: boolean;
// classes?: string[];
// }
//
// interface _iRadioBase extends _iRadioBaseOpt{
// title: string;
// items: string[];
// callback: (val: string) => any;
// connected: boolean;
// }
//
// interface iRadioBase extends _iRadioBase{
// selectedValueOrIndex: string|number;
// }
// interface iRadio {
// title: string;
// items: string[];
// callback: (val: string) => any;
// inline?: boolean;
// classes?: string[];
// }
class Radio extends React.Component { class Radio extends React.Component {
render() { render() {
return React.createElement(RadioBase, { title: this.props.title, items: this.props.items, callback: this.props.callback, inline: this.props.inline, selectedValueOrIndex: this.props.defaultValue, connected: false, classes: this.props.classes }); return React.createElement(RadioBase, { title: this.props.title, items: this.props.items, callback: this.props.callback, inline: this.props.inline, selectedValueOrIndex: this.props.defaultValue, connected: false, classes: this.props.classes });
......
{"version":3,"file":"Radio.js","sourceRoot":"","sources":["../../src/reactComponents/Radio.tsx"],"names":[],"mappings":";AAAA;;GAEG;;AAGH,+BAAgC;AAGhC,qBAAmB;AACnB,+CAAwC;AAaxC,MAAM,SAAU,SAAQ,KAAK,CAAC,SAAyB;IAQnD,YAAY,KAAiB,EAAE,OAAe;QAC1C,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,kBAAQ,EAAE,CAAA;IAC1B,CAAC;IAGD,MAAM;QACF,IAAI,KAAK,GAAG,EAAE,CAAC;QACf,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;YACnB,KAAK,GAAG;gBACJ,OAAO,EAAE,cAAc;gBACvB,OAAO,EAAE,OAAO;aACnB,CAAC;SACL;QAED,IAAI,KAAK,GAAG;YACR,EAAE,EAAE,IAAI,CAAC,IAAI;YACb,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO;YACxB,KAAK,EAAE,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE;YAC5F,QAAQ,EAAE,CAAC,GAAkC,EAAE,EAAE;gBAC7C,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACpC,GAAG,CAAC,M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EF,OAAO,oBAAC,SAAS,IACb,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EACvB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EACvB,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,EAC7B,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,EACzB,oBAAoB,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY,EAC7C,SAAS,EAAE,KAAK,EAChB,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,GAC7B,CAAA;IACN,CAAC;CACJ;AAhBD,sBAgBC;AAED,MAAa,cAAe,SAAQ,KAAK,CAAC,SAEU;IAEhD,MAAM;QACF,OAAO,oBAAC,SAAS,IACb,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EACvB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EACvB,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,EAC7B,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,EACzB,oBAAoB,EAAE,IAAI,CAAC,KAAK,CAAC,aAAa,EAC9C,SAAS,EAAE,IAAI,EACf,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,GAC7B,CAAA;IACN,CAAC;CACJ;AAfD,wCAeC","sourcesContent":["/**\r\n * Created by glenn on 6/12/2017.\r\n */\r\n\r\n\r\nimport React = require(\"react\");\r\n\r\nimport $ = require('jquery');\r\nimport 'jquery-ui';\r\nimport makeGuid from '../util/makeGuid';\r\nimport {ChangeEvent} from \"react\";\r\n\r\nexport interface iRadioItem{\r\n groupId: string;\r\n text: string;\r\n checked: boolean;\r\n inline: boolean;\r\n change: (s: string) => any;\r\n connected: boolean;\r\n index: number\r\n}\r\n\r\nclass RadioItem extends React.Component<iRadioItem, {}> {\r\n static defaultProps = {\r\n connected: false,\r\n index: null\r\n }\r\n\r\n guid: string;\r\n\r\n constructor(props: iRadioItem, context: Object){\r\n super(props, context);\r\n this.guid = makeGuid()\r\n }\r\n\r\n\r\n render() {\r\n let style = {};\r\n if (this.props.inline) {\r\n style = {\r\n display: 'inline-block',\r\n padding: '0 5px'\r\n };\r\n }\r\n\r\n let props = {\r\n id: this.guid,\r\n type: \"radio\",\r\n name: this.props.groupId,\r\n value: typeof this.props.index == 'undefined' ? this.props.text : this.props.index.toFixed(),\r\n onChange: (evt: ChangeEvent<HTMLInputElement>) => {\r\n this.props.change(evt.target.value);\r\n evt.target.checked = true;\r\n },\r\n checked: this.props.checked,\r\n defaultChecked: this.props.checked\r\n };\r\n\r\n if (this.props.connected) {\r\n delete props.defaultChecked;\r\n } else {\r\n delete props.checked\r\n }\r\n\r\n return <li style={style}>\r\n <input {...props}/>\r\n <label htmlFor={this.guid}>{this.props.text}</label>\r\n </li>;\r\n }\r\n}\r\n\r\ninterface iRadioBase {\r\n title: string;\r\n items: string[];\r\n callback: (val: string) => any;\r\n inline: boolean;\r\n selectedValueOrIndex: string|number;\r\n connected: boolean;\r\n classes?: string[]\r\n}\r\n\r\nclass RadioBase extends React.Component<iRadioBase, {}> {\r\n static defaultProps = {\r\n inline: false\r\n };\r\n\r\n inline: boolean;\r\n groupId: string;\r\n\r\n constructor(props: iRadioBase, context: Object) {\r\n super(props, context);\r\n this.inline = this.props.inline || false;\r\n this.groupId = this.props.title.toLowerCase().replace(/ /g, '');\r\n }\r\n\r\n render() {\r\n\r\n let arr = [];\r\n\r\n for (let i = 0; i < this.props.items.length; i++) {\r\n\r\n let itemProps = {\r\n groupId: this.groupId,\r\n text: this.props.items[i],\r\n inline: this.props.inline,\r\n change: (s: string) => (this.props.callback(s)),\r\n key: this.props.items[i],\r\n connected: this.props.connected || false,\r\n checked: false,\r\n index: i\r\n };\r\n\r\n if (typeof this.props.selectedValueOrIndex == 'number'){\r\n itemProps.checked = i == this.props.selectedValueOrIndex;\r\n } else {\r\n itemProps.checked = this.props.items[i] == this.props.selectedValueOrIndex;\r\n delete itemProps.index\r\n }\r\n\r\n arr.push(<RadioItem {...itemProps}/>)\r\n }\r\n\r\n let classes = ['radio-list'];\r\n\r\n if (this.props.classes){\r\n classes = classes.concat(this.props.classes);\r\n }\r\n\r\n return <div className={classes.join(' ')}>\r\n <h4>{this.props.title}</h4>\r\n <ul style={{listStyle: 'none'}}>\r\n {arr}\r\n </ul>\r\n </div>\r\n }\r\n}\r\n\r\n\r\nexport class Radio extends React.Component<{\r\n title: string, items: string[], callback: (val: string) => any, inline?: boolean,\r\n defaultValue: string, classes?: string[] }, {}> {\r\n\r\n render() {\r\n\r\n return <RadioBase\r\n title={this.props.title}\r\n items={this.props.items}\r\n callback={this.props.callback}\r\n inline={this.props.inline}\r\n selectedValueOrIndex={this.props.defaultValue}\r\n connected={false}\r\n classes={this.props.classes}\r\n />\r\n }\r\n}\r\n\r\nexport class RadioConnected extends React.Component<{\r\n title: string, items: string[], callback: (val: string) => any, inline?: boolean,\r\n selectedIndex: number, classes?: string[] }, {}> {\r\n\r\n render() {\r\n return <RadioBase\r\n title={this.props.title}\r\n items={this.props.items}\r\n callback={this.props.callback}\r\n inline={this.props.inline}\r\n selectedValueOrIndex={this.props.selectedIndex}\r\n connected={true}\r\n classes={this.props.classes}\r\n />\r\n }\r\n}"]} {"version":3,"file":"Radio.js","sourceRoot":"","sources":["../../src/reactComponents/Radio.tsx"],"names":[],"mappings":";AAAA;;GAEG;;AAGH,+BAAgC;AAGhC,qBAAmB;AACnB,+CAAwC;AAiBxC,MAAM,SAAU,SAAQ,KAAK,CAAC,SAAyB;IAGnD,YAAY,KAAiB,EAAE,OAAe;QAC1C,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,kBAAQ,EAAE,CAAA;IAC1B,CAAC;IAGD,MAAM;QACF,IAAI,KAAK,GAAG,EAAE,CAAC;QACf,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;YACnB,KAAK,GAAG;gBACJ,OAAO,EAAE,cAAc;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CAAC,KAAK,CAAC,KAAK,EACvB,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,EAC7B,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,EACzB,oBAAoB,EAAE,IAAI,CAAC,KAAK,CAAC,aAAa,EAC9C,SAAS,EAAE,IAAI,EACf,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,GAC7B,CAAA;IACN,CAAC;CACJ;AAnBD,wCAmBC","sourcesContent":["/**\r\n * Created by glenn on 6/12/2017.\r\n */\r\n\r\n\r\nimport React = require(\"react\");\r\n\r\nimport $ = require('jquery');\r\nimport 'jquery-ui';\r\nimport makeGuid from '../util/makeGuid';\r\nimport {ChangeEvent} from \"react\";\r\n\r\nexport interface iRadioItemOpt {\r\n index?: number\r\n}\r\n\r\nexport interface iRadioItem extends iRadioItemOpt{\r\n groupId: string;\r\n text: string;\r\n checked: boolean;\r\n inline: boolean;\r\n change: (s: string) => any;\r\n connected?: boolean;\r\n\r\n}\r\n\r\nclass RadioItem extends React.Component<iRadioItem, {}> {\r\n guid: string;\r\n\r\n constructor(props: iRadioItem, context: Object){\r\n super(props, context);\r\n this.guid = makeGuid()\r\n }\r\n\r\n\r\n render() {\r\n let style = {};\r\n if (this.props.inline) {\r\n style = {\r\n display: 'inline-block',\r\n padding: '0 5px'\r\n };\r\n }\r\n\r\n let props = {\r\n id: this.guid,\r\n type: \"radio\",\r\n name: this.props.groupId,\r\n value: typeof this.props.index == 'undefined' ? this.props.text : this.props.index.toFixed(),\r\n onChange: (evt: ChangeEvent<HTMLInputElement>) => {\r\n this.props.change(evt.target.value);\r\n evt.target.checked = true;\r\n },\r\n checked: this.props.checked,\r\n defaultChecked: this.props.checked\r\n };\r\n\r\n if (this.props.connected) {\r\n delete props.defaultChecked;\r\n } else {\r\n delete props.checked\r\n }\r\n\r\n return <li style={style}>\r\n <input {...props}/>\r\n <label htmlFor={this.guid}>{this.props.text}</label>\r\n </li>;\r\n }\r\n}\r\n\r\ninterface _iRadioBaseOpt {\r\n inline?: boolean;\r\n classes?: string[];\r\n}\r\n\r\ninterface _iRadioBase extends _iRadioBaseOpt{\r\n title: string;\r\n items: string[];\r\n callback: (val: string) => any;\r\n connected: boolean;\r\n}\r\n\r\ninterface iRadioBase extends _iRadioBase{\r\n selectedValueOrIndex: string|number;\r\n}\r\n\r\nclass RadioBase extends React.Component<iRadioBase, {}> {\r\n inline: boolean;\r\n groupId: string;\r\n\r\n constructor(props: iRadioBase, context: Object) {\r\n super(props, context);\r\n this.inline = this.props.inline || false;\r\n this.groupId = this.props.title.toLowerCase().replace(/ /g, '');\r\n }\r\n\r\n render() {\r\n\r\n let arr = [];\r\n\r\n for (let i = 0; i < this.props.items.length; i++) {\r\n\r\n let itemProps = {\r\n groupId: this.groupId,\r\n text: this.props.items[i],\r\n inline: this.props.inline,\r\n change: (s: string) => (this.props.callback(s)),\r\n key: this.props.items[i],\r\n connected: this.props.connected || false,\r\n checked: false,\r\n index: i\r\n };\r\n\r\n if (typeof this.props.selectedValueOrIndex == 'number'){\r\n itemProps.checked = i == this.props.selectedValueOrIndex;\r\n } else {\r\n itemProps.checked = this.props.items[i] == this.props.selectedValueOrIndex;\r\n delete itemProps.index\r\n }\r\n\r\n arr.push(<RadioItem {...itemProps}/>)\r\n }\r\n\r\n let classes = ['radio-list'];\r\n\r\n if (this.props.classes){\r\n classes = classes.concat(this.props.classes);\r\n }\r\n\r\n return <div className={classes.join(' ')}>\r\n <h4>{this.props.title}</h4>\r\n <ul style={{listStyle: 'none'}}>\r\n {arr}\r\n </ul>\r\n </div>\r\n }\r\n}\r\n\r\n//\r\n// interface _iRadioBaseOpt {\r\n// inline?: boolean;\r\n// classes?: string[];\r\n// }\r\n//\r\n// interface _iRadioBase extends _iRadioBaseOpt{\r\n// title: string;\r\n// items: string[];\r\n// callback: (val: string) => any;\r\n// connected: boolean;\r\n// }\r\n//\r\n// interface iRadioBase extends _iRadioBase{\r\n// selectedValueOrIndex: string|number;\r\n// }\r\n\r\n// interface iRadio {\r\n// title: string;\r\n// items: string[];\r\n// callback: (val: string) => any;\r\n// inline?: boolean;\r\n// classes?: string[];\r\n// }\r\n\r\n\r\n\r\n\r\n\r\n\r\nexport class Radio extends React.Component<{\r\n title: string,\r\n items: string[],\r\n callback: (val: string) => any,\r\n defaultValue: string,\r\n inline?: boolean,\r\n classes?: string[] }, {}> {\r\n\r\n render() {\r\n\r\n return <RadioBase\r\n title={this.props.title}\r\n items={this.props.items}\r\n callback={this.props.callback}\r\n inline={this.props.inline}\r\n selectedValueOrIndex={this.props.defaultValue}\r\n connected={false}\r\n classes={this.props.classes}\r\n />\r\n }\r\n}\r\n\r\nexport class RadioConnected extends React.Component<{\r\n title: string,\r\n items: string[],\r\n callback: (val: string) => any,\r\n inline?: boolean,\r\n selectedIndex: number,\r\n classes?: string[] }, {}> {\r\n\r\n render() {\r\n return <RadioBase\r\n title={this.props.title}\r\n items={this.props.items}\r\n callback={this.props.callback}\r\n inline={this.props.inline}\r\n selectedValueOrIndex={this.props.selectedIndex}\r\n connected={true}\r\n classes={this.props.classes}\r\n />\r\n }\r\n}"]}
\ No newline at end of file \ No newline at end of file
...@@ -10,22 +10,21 @@ import 'jquery-ui'; ...@@ -10,22 +10,21 @@ import 'jquery-ui';
import makeGuid from '../util/makeGuid'; import makeGuid from '../util/makeGuid';
import {ChangeEvent} from "react"; import {ChangeEvent} from "react";
export interface iRadioItem{ export interface iRadioItemOpt {
index?: number
}
export interface iRadioItem extends iRadioItemOpt{
groupId: string; groupId: string;
text: string; text: string;
checked: boolean; checked: boolean;
inline: boolean; inline: boolean;
change: (s: string) => any; change: (s: string) => any;
connected: boolean; connected?: boolean;
index: number
} }
class RadioItem extends React.Component<iRadioItem, {}> { class RadioItem extends React.Component<iRadioItem, {}> {
static defaultProps = {
connected: false,
index: null
}
guid: string; guid: string;
constructor(props: iRadioItem, context: Object){ constructor(props: iRadioItem, context: Object){
...@@ -69,21 +68,23 @@ class RadioItem extends React.Component<iRadioItem, {}> { ...@@ -69,21 +68,23 @@ class RadioItem extends React.Component<iRadioItem, {}> {
} }
} }
interface iRadioBase { interface _iRadioBaseOpt {
inline?: boolean;
classes?: string[];
}
interface _iRadioBase extends _iRadioBaseOpt{
title: string; title: string;
items: string[]; items: string[];
callback: (val: string) => any; callback: (val: string) => any;
inline: boolean;
selectedValueOrIndex: string|number;
connected: boolean; connected: boolean;
classes?: string[]
} }
class RadioBase extends React.Component<iRadioBase, {}> { interface iRadioBase extends _iRadioBase{
static defaultProps = { selectedValueOrIndex: string|number;
inline: false }
};
class RadioBase extends React.Component<iRadioBase, {}> {
inline: boolean; inline: boolean;
groupId: string; groupId: string;
...@@ -135,10 +136,43 @@ class RadioBase extends React.Component<iRadioBase, {}> { ...@@ -135,10 +136,43 @@ class RadioBase extends React.Component<iRadioBase, {}> {
} }
} }
//
// interface _iRadioBaseOpt {
// inline?: boolean;
// classes?: string[];
// }
//
// interface _iRadioBase extends _iRadioBaseOpt{
// title: string;
// items: string[];
// callback: (val: string) => any;
// connected: boolean;
// }
//
// interface iRadioBase extends _iRadioBase{
// selectedValueOrIndex: string|number;
// }
// interface iRadio {
// title: string;
// items: string[];
// callback: (val: string) => any;
// inline?: boolean;
// classes?: string[];
// }
export class Radio extends React.Component<{ export class Radio extends React.Component<{
title: string, items: string[], callback: (val: string) => any, inline?: boolean, title: string,
defaultValue: string, classes?: string[] }, {}> { items: string[],
callback: (val: string) => any,
defaultValue: string,
inline?: boolean,
classes?: string[] }, {}> {
render() { render() {
...@@ -155,8 +189,12 @@ export class Radio extends React.Component<{ ...@@ -155,8 +189,12 @@ export class Radio extends React.Component<{
} }
export class RadioConnected extends React.Component<{ export class RadioConnected extends React.Component<{
title: string, items: string[], callback: (val: string) => any, inline?: boolean, title: string,
selectedIndex: number, classes?: string[] }, {}> { items: string[],
callback: (val: string) => any,
inline?: boolean,
selectedIndex: number,
classes?: string[] }, {}> {
render() { render() {
return <RadioBase return <RadioBase
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment