4 Commits

8 changed files with 176 additions and 39 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
node_modules

Binary file not shown.

View File

@@ -16,12 +16,31 @@
<attributeType name="String"/> <attributeType name="String"/>
</attributeTypes> </attributeTypes>
</property> </property>
<property key="editable" type="boolean" required="true" defaultValue="true">
<caption>Editable</caption>
<description/>
</property>
<property key="autoFocus" type="attribute">
<caption>Auto focus</caption>
<description>Boolean attribute to focus the element.</description>
<attributeTypes>
<attributeType name="Boolean"/>
</attributeTypes>
</property>
</propertyGroup> </propertyGroup>
<propertyGroup caption="Events"> <propertyGroup caption="Events">
<property key="onChange" type="action" required="false"> <property key="onChange" type="action" required="false">
<caption>On change</caption> <caption>On change</caption>
<description/> <description/>
</property> </property>
<property key="onEnter" type="action" required="false">
<caption>On focus</caption>
<description/>
</property>
<property key="onLeave" type="action" required="false">
<caption>On submit</caption>
<description/>
</property>
</propertyGroup> </propertyGroup>
<propertyGroup caption="Common"> <propertyGroup caption="Common">
<systemProperty key="Name"/> <systemProperty key="Name"/>

View File

@@ -244,12 +244,15 @@ __webpack_require__.r(__webpack_exports__);
const defaultStyle = { const defaultStyle = {
container: {}, container: {},
label: { label: {
color: "#F6BB42" color: "#003C85"
}, },
input: { input: {},
height: 45, text: {
borderBottomWidth: 1, color: "#003C85",
borderBottomColor: '#de712b', fontSize: 15,
paddingTop: 10,
paddingLeft: 10,
paddingBottom: 10
} }
}; };
class Autosearch extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] { class Autosearch extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
@@ -257,20 +260,56 @@ class Autosearch extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
super(props); super(props);
this.styles = Object(_mendix_pluggable_widgets_tools__WEBPACK_IMPORTED_MODULE_2__["mergeNativeStyles"])(defaultStyle, this.props.style); this.styles = Object(_mendix_pluggable_widgets_tools__WEBPACK_IMPORTED_MODULE_2__["mergeNativeStyles"])(defaultStyle, this.props.style);
this.onChangeHandler = this.onChange.bind(this); this.onChangeHandler = this.onChange.bind(this);
this.onTouchStart = this.onTouch.bind(this);
this.onEndHandler = this.onEnd.bind(this);
this.onLeaveHandler = this.onLeave.bind(this);
this.inputRef = Object(react__WEBPACK_IMPORTED_MODULE_0__["createRef"])();
this.state = { this.state = {
textboxValue: '', textboxValue: this.props.searchvalue.displayValue,
}; };
} }
componentDidUpdate(prevProps) {
var _a;
if (prevProps.autoFocus !== this.props.autoFocus) {
if (this.props.autoFocus.value) {
setTimeout(() => {
var _a;
(_a = this.inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
this.props.autoFocus.setValue(false);
return;
}, 500);
}
}
if (prevProps.searchvalue !== this.props.searchvalue) {
if (this.props.searchvalue === undefined || this.props.searchvalue.displayValue === '') {
this.setState({ textboxValue: '' });
(_a = this.inputRef.current) === null || _a === void 0 ? void 0 : _a.clear;
}
else {
this.setState({ textboxValue: this.props.searchvalue.displayValue });
}
}
}
render() { render() {
return (Object(react__WEBPACK_IMPORTED_MODULE_0__["createElement"])(react_native__WEBPACK_IMPORTED_MODULE_1__["View"], { style: this.styles.container }, return (Object(react__WEBPACK_IMPORTED_MODULE_0__["createElement"])(react_native__WEBPACK_IMPORTED_MODULE_1__["View"], { style: this.styles.input },
Object(react__WEBPACK_IMPORTED_MODULE_0__["createElement"])(react_native__WEBPACK_IMPORTED_MODULE_1__["TextInput"], { style: this.styles.input, value: this.state.textboxValue, onChangeText: this.onChangeHandler, placeholder: 'Zoeken...' }))); Object(react__WEBPACK_IMPORTED_MODULE_0__["createElement"])(react_native__WEBPACK_IMPORTED_MODULE_1__["TextInput"], { style: this.styles.text, value: this.state.textboxValue, onChangeText: this.onChangeHandler, onFocus: this.onTouchStart, onSubmitEditing: this.onLeaveHandler, onEndEditing: this.onEndHandler, placeholder: 'Zoeken naar monumentenborden', placeholderTextColor: "#5997C0", editable: this.props.editable, ref: this.inputRef })));
} }
onChange(text) { onChange(text) {
var _a;
this.setState({ textboxValue: text }); this.setState({ textboxValue: text });
this.props.searchvalue.setValue(text); this.props.searchvalue.setValue(text);
}
onTouch() {
var _a;
(_a = this.props.onEnter) === null || _a === void 0 ? void 0 : _a.execute();
}
onEnd() {
var _a;
(_a = this.props.onChange) === null || _a === void 0 ? void 0 : _a.execute(); (_a = this.props.onChange) === null || _a === void 0 ? void 0 : _a.execute();
} }
onLeave() {
var _a;
(_a = this.props.onLeave) === null || _a === void 0 ? void 0 : _a.execute();
}
} }

File diff suppressed because one or more lines are too long

View File

@@ -1,4 +1,4 @@
import { Component, ReactNode, createElement } from "react"; import { Component, ReactNode, createElement, createRef } from "react";
import { TextStyle, ViewStyle, TextInput, View } from "react-native"; import { TextStyle, ViewStyle, TextInput, View } from "react-native";
import { Style, mergeNativeStyles } from "@mendix/pluggable-widgets-tools"; import { Style, mergeNativeStyles } from "@mendix/pluggable-widgets-tools";
@@ -16,32 +16,72 @@ interface State {
} }
const defaultStyle: AutosearchStyle = { const defaultStyle: AutosearchStyle = {
container: {}, container: {
},
label: { label: {
color: "#F6BB42" color: "#003C85"
}, },
input: { input: {
height: 45, },
borderBottomWidth: 1, text: {
borderBottomColor: '#de712b', color: "#003C85",
fontSize: 15,
paddingTop: 10,
paddingLeft: 10,
paddingBottom: 10
} }
}; };
export class Autosearch extends Component<AutosearchProps<AutosearchStyle>, State> { export class Autosearch extends Component<AutosearchProps<AutosearchStyle>, State> {
private readonly styles = mergeNativeStyles(defaultStyle, this.props.style); private readonly styles = mergeNativeStyles(defaultStyle, this.props.style);
private readonly onChangeHandler = this.onChange.bind(this); private readonly onChangeHandler = this.onChange.bind(this);
private readonly onTouchStart = this.onTouch.bind(this);
private readonly onEndHandler = this.onEnd.bind(this);
private readonly onLeaveHandler = this.onLeave.bind(this);
inputRef = createRef<TextInput>();
constructor(props: AutosearchProps<AutosearchStyle>){ constructor(props: AutosearchProps<AutosearchStyle>){
super(props) super(props)
this.state = { this.state = {
textboxValue: '', textboxValue: this.props.searchvalue.displayValue,
} }
} }
componentDidUpdate(prevProps: AutosearchProps<AutosearchStyle>) {
if (prevProps.autoFocus !== this.props.autoFocus) {
if (this.props.autoFocus.value) {
setTimeout(() => {
this.inputRef.current?.focus();
this.props.autoFocus.setValue(false);
return;
}, 500)
}
}
if (prevProps.searchvalue !== this.props.searchvalue) {
if (this.props.searchvalue === undefined || this.props.searchvalue.displayValue === '') {
this.setState({textboxValue: ''});
this.inputRef.current?.clear;
}
else {
this.setState({textboxValue: this.props.searchvalue.displayValue});
}
}
}
render(): ReactNode { render(): ReactNode {
return ( return (
<View style={this.styles.container}> <View style={this.styles.input}>
<TextInput style={this.styles.input} value={this.state.textboxValue} onChangeText={this.onChangeHandler} placeholder={'Zoeken...'}></TextInput> <TextInput style={this.styles.text}
value={this.state.textboxValue}
onChangeText={this.onChangeHandler}
onFocus={this.onTouchStart}
onSubmitEditing={this.onLeaveHandler}
onEndEditing={this.onEndHandler}
placeholder={'Zoeken naar monumentenborden'}
placeholderTextColor="#5997C0"
editable={this.props.editable}
ref={this.inputRef}
>
</TextInput>
</View> </View>
) )
} }
@@ -49,6 +89,17 @@ export class Autosearch extends Component<AutosearchProps<AutosearchStyle>, Stat
private onChange(text: string) { private onChange(text: string) {
this.setState({textboxValue: text}); this.setState({textboxValue: text});
this.props.searchvalue.setValue(text); this.props.searchvalue.setValue(text);
}
private onTouch() {
this.props.onEnter?.execute();
}
private onEnd() {
this.props.onChange?.execute(); this.props.onChange?.execute();
} }
private onLeave() {
this.props.onLeave?.execute();
}
} }

View File

@@ -16,12 +16,31 @@
<attributeType name="String"/> <attributeType name="String"/>
</attributeTypes> </attributeTypes>
</property> </property>
<property key="editable" type="boolean" required="true" defaultValue="true">
<caption>Editable</caption>
<description/>
</property>
<property key="autoFocus" type="attribute">
<caption>Auto focus</caption>
<description>Boolean attribute to focus the element.</description>
<attributeTypes>
<attributeType name="Boolean"/>
</attributeTypes>
</property>
</propertyGroup> </propertyGroup>
<propertyGroup caption="Events"> <propertyGroup caption="Events">
<property key="onChange" type="action" required="false"> <property key="onChange" type="action" required="false">
<caption>On change</caption> <caption>On change</caption>
<description/> <description/>
</property> </property>
<property key="onEnter" type="action" required="false">
<caption>On focus</caption>
<description/>
</property>
<property key="onLeave" type="action" required="false">
<caption>On submit</caption>
<description/>
</property>
</propertyGroup> </propertyGroup>
<propertyGroup caption="Common"> <propertyGroup caption="Common">
<systemProperty key="Name"/> <systemProperty key="Name"/>

View File

@@ -9,12 +9,20 @@ export interface AutosearchProps<Style> {
name: string; name: string;
style: Style[]; style: Style[];
searchvalue: EditableValue<string>; searchvalue: EditableValue<string>;
editable: boolean;
autoFocus: EditableValue<boolean>;
onChange?: ActionValue; onChange?: ActionValue;
onEnter?: ActionValue;
onLeave?: ActionValue;
} }
export interface AutosearchPreviewProps { export interface AutosearchPreviewProps {
class: string; class: string;
style: string; style: string;
searchvalue: string; searchvalue: string;
editable: boolean;
autoFocus: string;
onChange: {} | null; onChange: {} | null;
onEnter: {} | null;
onLeave: {} | null;
} }