Skip to content
Snippets Groups Projects
Commit 8cbf7b5d authored by David Sehnal's avatar David Sehnal
Browse files

mol-plugin-ui: Controls improvements

parent 2c40b858
No related branches found
No related tags found
No related merge requests found
...@@ -41,7 +41,7 @@ export namespace ActionMenu { ...@@ -41,7 +41,7 @@ export namespace ActionMenu {
export type ToggleProps = { export type ToggleProps = {
style?: React.HTMLAttributes<HTMLButtonElement>, style?: React.CSSProperties,
className?: string, className?: string,
menu: ActionMenu, menu: ActionMenu,
disabled?: boolean, disabled?: boolean,
...@@ -180,11 +180,14 @@ export namespace ActionMenu { ...@@ -180,11 +180,14 @@ export namespace ActionMenu {
if (typeof items === 'string') return null; if (typeof items === 'string') return null;
if (isItem(items)) return <Action menu={menu} item={items} onSelect={onSelect} current={current} /> if (isItem(items)) return <Action menu={menu} item={items} onSelect={onSelect} current={current} />
const hasCurrent = header && current && !!findCurrent(items, current.value)
return <div> return <div>
{header && <div className='msp-control-group-header' style={{ marginTop: '1px' }}> {header && <div className='msp-control-group-header' style={{ marginTop: '1px' }}>
<button className='msp-btn msp-btn-block' onClick={this.toggleExpanded}> <button className='msp-btn msp-btn-block' onClick={this.toggleExpanded}>
<span className={`msp-icon msp-icon-${this.state.isExpanded ? 'collapse' : 'expand'}`} /> <span className={`msp-icon msp-icon-${this.state.isExpanded ? 'collapse' : 'expand'}`} />
{header} {hasCurrent ? <b>{header}</b> : header}
</button> </button>
</div>} </div>}
<div className='msp-control-offset'> <div className='msp-control-offset'>
......
...@@ -341,8 +341,7 @@ export class SelectControl extends SimpleParam<PD.Select<string | number>> { ...@@ -341,8 +341,7 @@ export class SelectControl extends SimpleParam<PD.Select<string | number>> {
renderControl() { renderControl() {
const items = this.items(this.props.param); const items = this.items(this.props.param);
const current = ActionMenu.findCurrent(items, this.props.value); const current = ActionMenu.findCurrent(items, this.props.value);
return <ActionMenu.Toggle menu={this.menu} disabled={this.props.isDisabled} style={{ textAlign: 'left', overflow: 'hidden', textOverflow: 'ellipsis' }}
return <ActionMenu.Toggle menu={this.menu} disabled={this.props.isDisabled}
onSelect={this.onSelect} items={items as ActionMenu.Spec} label={current?.name || `[Invalid] ${this.props.value}`} onSelect={this.onSelect} items={items as ActionMenu.Spec} label={current?.name || `[Invalid] ${this.props.value}`}
current={current} />; current={current} />;
} }
...@@ -614,7 +613,7 @@ export class MultiSelectControl extends React.PureComponent<ParamProps<PD.MultiS ...@@ -614,7 +613,7 @@ export class MultiSelectControl extends React.PureComponent<ParamProps<PD.MultiS
} }
} }
export class GroupControl extends React.PureComponent<ParamProps<PD.Group<any>>, { isExpanded: boolean }> { export class GroupControl extends React.PureComponent<ParamProps<PD.Group<any>> & { inMapped?: boolean }, { isExpanded: boolean }> {
state = { isExpanded: !!this.props.param.isExpanded } state = { isExpanded: !!this.props.param.isExpanded }
change(value: any) { change(value: any) {
...@@ -637,6 +636,10 @@ export class GroupControl extends React.PureComponent<ParamProps<PD.Group<any>>, ...@@ -637,6 +636,10 @@ export class GroupControl extends React.PureComponent<ParamProps<PD.Group<any>>,
const controls = <ParameterControls params={params} onChange={this.onChangeParam} values={this.props.value} onEnter={this.props.onEnter} isDisabled={this.props.isDisabled} />; const controls = <ParameterControls params={params} onChange={this.onChangeParam} values={this.props.value} onEnter={this.props.onEnter} isDisabled={this.props.isDisabled} />;
if (this.props.inMapped) {
return <div className='msp-control-offset'>{controls}</div>;
}
if (this.props.param.isFlat) { if (this.props.param.isFlat) {
return controls; return controls;
} }
...@@ -655,7 +658,9 @@ export class GroupControl extends React.PureComponent<ParamProps<PD.Group<any>>, ...@@ -655,7 +658,9 @@ export class GroupControl extends React.PureComponent<ParamProps<PD.Group<any>>,
} }
} }
export class MappedControl extends React.PureComponent<ParamProps<PD.Mapped<any>>> { export class MappedControl extends React.PureComponent<ParamProps<PD.Mapped<any>>, { isExpanded: boolean }> {
state = { isExpanded: false }
private valuesCache: { [name: string]: PD.Values<any> } = {} private valuesCache: { [name: string]: PD.Values<any> } = {}
private setValues(name: string, values: PD.Values<any>) { private setValues(name: string, values: PD.Values<any>) {
this.valuesCache[name] = values this.valuesCache[name] = values
...@@ -681,6 +686,8 @@ export class MappedControl extends React.PureComponent<ParamProps<PD.Mapped<any> ...@@ -681,6 +686,8 @@ export class MappedControl extends React.PureComponent<ParamProps<PD.Mapped<any>
this.change({ name: this.props.value.name, params: e.value }); this.change({ name: this.props.value.name, params: e.value });
} }
toggleExpanded = () => this.setState({ isExpanded: !this.state.isExpanded });
render() { render() {
const value: PD.Mapped<any>['defaultValue'] = this.props.value; const value: PD.Mapped<any>['defaultValue'] = this.props.value;
const param = this.props.param.map(value.name); const param = this.props.param.map(value.name);
...@@ -703,6 +710,14 @@ export class MappedControl extends React.PureComponent<ParamProps<PD.Mapped<any> ...@@ -703,6 +710,14 @@ export class MappedControl extends React.PureComponent<ParamProps<PD.Mapped<any>
return Select; return Select;
} }
if (param.type === 'group' && !param.isFlat && Object.keys(param.params).length > 0) {
return <div className='msp-mapped-parameter-group'>
{Select}
<IconButton icon='log' onClick={this.toggleExpanded} toggleState={this.state.isExpanded} title={`${label} Properties`} />
{this.state.isExpanded && <GroupControl inMapped param={param} value={value.params} name={`${label} Properties`} onChange={this.onChangeParam} onEnter={this.props.onEnter} isDisabled={this.props.isDisabled} />}
</div>
}
return <> return <>
{Select} {Select}
<Mapped param={param} value={value.params} name={`${label} Properties`} onChange={this.onChangeParam} onEnter={this.props.onEnter} isDisabled={this.props.isDisabled} /> <Mapped param={param} value={value.params} name={`${label} Properties`} onChange={this.onChangeParam} onEnter={this.props.onEnter} isDisabled={this.props.isDisabled} />
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
position: relative;
@include non-selectable; @include non-selectable;
} }
......
...@@ -166,4 +166,21 @@ ...@@ -166,4 +166,21 @@
.msp-scrollable-container { .msp-scrollable-container {
left: $row-height + 1px; left: $row-height + 1px;
} }
}
.msp-mapped-parameter-group {
position: relative;
> .msp-control-row:first-child {
> div:nth-child(2) {
right: 33px;
}
}
> .msp-btn-icon {
position: absolute;
right: 0;
width: 32px;
top: 0;
}
} }
\ No newline at end of file
...@@ -46,7 +46,8 @@ const sharedConfig = { ...@@ -46,7 +46,8 @@ const sharedConfig = {
'node_modules', 'node_modules',
path.resolve(__dirname, 'lib/') path.resolve(__dirname, 'lib/')
], ],
} },
devtool: ''
} }
......
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