Skip to content
This repository has been archived by the owner on Sep 19, 2022. It is now read-only.

Commit

Permalink
Dropdown control added
Browse files Browse the repository at this point in the history
  • Loading branch information
FeodorFitsner committed Nov 30, 2020
1 parent b570a07 commit d31c85c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
2 changes: 2 additions & 0 deletions client/src/controls/ControlsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Row from './Row'
import Col from './Col'
import MyStack from './Stack'
import { Textbox } from './Textbox'
import { MyDropdown } from './Dropdown'
import Button from './Button'
import Text from './Text'

Expand All @@ -14,6 +15,7 @@ const ControlsList = ({ controls }) => {
'row': Row,
'col': Col,
'textbox': Textbox,
'dropdown': MyDropdown,
'text': Text,
'button': Button,
'stack': MyStack,
Expand Down
48 changes: 48 additions & 0 deletions client/src/controls/Dropdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React, { useContext } from 'react';
import { WebSocketContext } from '../WebSocket';
import { useDispatch, shallowEqual, useSelector } from 'react-redux'
import { changeProps } from '../slices/pageSlice'
import { Dropdown, IDropdownOption, IDropdownProps } from '@fluentui/react';
import { IControlProps } from './IControlProps'

export const MyDropdown = React.memo<IControlProps>(({control}) => {

console.log(`render Dropdown: ${control.i}`);

const ws = useContext(WebSocketContext);

const dispatch = useDispatch();

const handleChange = (event: React.FormEvent<HTMLDivElement>, option?: IDropdownOption, index?: number) => {

console.log("DROPDOWN:", option);

const payload = [
{
i: control.i,
"value": option!.key
}
];

dispatch(changeProps(payload));
ws.updateControlProps(payload);
}

const dropdownProps: IDropdownProps = {
label: control.label ? control.label : null,
placeholder: control.placeholder ? control.placeholder : null,
errorMessage: control.errormessage ? control.errormessage : null,
options: []
};

dropdownProps.options = useSelector<any, IDropdownOption[]>((state: any) => control.c.map((childId: any) =>
state.page.controls[childId])
.filter((oc: any) => oc.t === 'option')
.map((oc: any) => ({ key: oc.key, text: oc.text})), shallowEqual);

if (control.value) {
dropdownProps.defaultSelectedKey = control.value;
}

return <Dropdown {...dropdownProps} onChange={handleChange} />;
})
6 changes: 5 additions & 1 deletion tests/test-add-command.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ try {
pglet_send "add to=page at=0
stack width=600px horizontalAlign=stretch
textbox id=fullName value='someone' label=Name placeholder='Your name, please' description='That\'s your name'
textbox id=bio label='Bio' description='A few words about yourself' value='Line1\nLine2' multiline=true"
textbox id=bio label='Bio' description='A few words about yourself' value='Line1\nLine2' multiline=true
dropdown id=color label='Your favorite color' placeholder='Select color'
option key=red text=Red
option key=green text=Green
option key=blue text=Blue"

pglet_send "add stack at=0 id=buttons horizontal=true
button id=submit text=Submit primary=yes event=btn_event
Expand Down

0 comments on commit d31c85c

Please sign in to comment.