import { Component, ReactNode, createElement } from "react"; import { TextStyle, ViewStyle, View, TouchableOpacity } from "react-native"; import { DynamicValue, NativeIcon, ValueStatus } from "mendix"; import { Icon } from 'mendix/components/native/Icon'; import { Style, mergeNativeStyles } from '@mendix/pluggable-widgets-tools'; import { CustomGroupboxProps } from '../typings/CustomGroupboxProps'; export interface CustomStyle extends Style { headerContainer: ViewStyle; label: TextStyle; innerContainer: ViewStyle; selectedContainer: ViewStyle; divider: ViewStyle; icon: ViewStyle; groupboxParent: ViewStyle } const defaultStyle: CustomStyle = { headerContainer: {}, label: {}, innerContainer: {}, selectedContainer: {}, divider: { backgroundColor: '#A2A2A2', height: 1, }, icon: { alignSelf: 'flex-end' }, groupboxParent: {} }; interface State { showContent: boolean; } const defaultCollapseIconGlyph = "glyphicon-minus"; const defaultExpandIconGlyph = "glyphicon-plus"; export class CustomGroupbox extends Component, State> { constructor(props: CustomGroupboxProps){ super(props) this.toggleContent = this.toggleContent.bind(this) this.state = { showContent: (this.props.startCollapsed ? false : true ), } } private readonly styles = mergeNativeStyles(defaultStyle, this.props.style); render(): ReactNode { const icons = { collapseIcon: this.renderIcon(defaultCollapseIconGlyph, this.props.collapseIcon), expandIcon: this.renderIcon(defaultExpandIconGlyph, this.props.expandIcon), }; return ( {this.props.header} {this.state.showContent ? icons.collapseIcon : icons.expandIcon} {this.state.showContent && {this.props.content}} {this.props.showDivider && } ); } toggleContent() { this.setState({ showContent: !this.state.showContent }) } private renderIcon = (glyph: string, toBeRenderedIcon?: DynamicValue) => { const nativeIcon: NativeIcon = toBeRenderedIcon && toBeRenderedIcon.status === ValueStatus.Available ? toBeRenderedIcon.value : { type: "glyph", iconClass: glyph }; return ; }; }