From 304eca8cdab778535193c0cc6a3aa66b8334594f Mon Sep 17 00:00:00 2001 From: Josephus Paye II Date: Wed, 20 Feb 2019 20:02:35 +1100 Subject: [PATCH 1/4] Add RobotSelectorSingle --- src/client/components/dropdown/style.css | 9 ++- src/client/components/dropdown/view.tsx | 4 +- .../components/robot_selector_single/plug.svg | 3 + .../robot_selector_single/robot.svg | 3 + .../robot_selector_single/style.css | 30 ++++++++++ .../components/robot_selector_single/view.tsx | 56 +++++++++++++++++++ .../robot_selector_single/view_model.ts | 45 +++++++++++++++ src/client/components/select/view.tsx | 4 +- 8 files changed, 151 insertions(+), 3 deletions(-) create mode 100644 src/client/components/robot_selector_single/plug.svg create mode 100644 src/client/components/robot_selector_single/robot.svg create mode 100644 src/client/components/robot_selector_single/style.css create mode 100644 src/client/components/robot_selector_single/view.tsx create mode 100644 src/client/components/robot_selector_single/view_model.ts diff --git a/src/client/components/dropdown/style.css b/src/client/components/dropdown/style.css index 5922b40f..5096e2ef 100644 --- a/src/client/components/dropdown/style.css +++ b/src/client/components/dropdown/style.css @@ -4,7 +4,6 @@ .dropdownMenu { position: absolute; - top: 100%; z-index: 1; } @@ -15,3 +14,11 @@ .dropdownMenuRight { right: 0; } + +.dropdownMenuUp { + bottom: 100%; +} + +.dropdownMenuDown { + top: 100%; +} diff --git a/src/client/components/dropdown/view.tsx b/src/client/components/dropdown/view.tsx index 38278053..bc9d5f58 100644 --- a/src/client/components/dropdown/view.tsx +++ b/src/client/components/dropdown/view.tsx @@ -13,6 +13,7 @@ export interface DropdownProps { isOpen: boolean isFullwidth?: boolean dropdownPosition?: 'left' | 'right' + dropDirection?: 'up' | 'down' onRef?(dropdown: HTMLDivElement): void onToggleClick?(event: MouseEvent): void } @@ -20,7 +21,8 @@ export interface DropdownProps { export const Dropdown: StatelessComponent = (props: DropdownProps) => { const fullwidth = props.isFullwidth ? style.dropdownMenuFullwidth : '' const position = props.dropdownPosition === 'right' ? style.dropdownMenuRight : '' - const dropdownMenuClassName = classNames(style.dropdownMenu, fullwidth, position) + const direction = props.dropDirection === 'up' ? style.dropdownMenuUp : style.dropdownMenuDown + const dropdownMenuClassName = classNames(style.dropdownMenu, fullwidth, position, direction) return (
diff --git a/src/client/components/robot_selector_single/plug.svg b/src/client/components/robot_selector_single/plug.svg new file mode 100644 index 00000000..418620c1 --- /dev/null +++ b/src/client/components/robot_selector_single/plug.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/client/components/robot_selector_single/robot.svg b/src/client/components/robot_selector_single/robot.svg new file mode 100644 index 00000000..c9f93dd6 --- /dev/null +++ b/src/client/components/robot_selector_single/robot.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/client/components/robot_selector_single/style.css b/src/client/components/robot_selector_single/style.css new file mode 100644 index 00000000..335b5f9c --- /dev/null +++ b/src/client/components/robot_selector_single/style.css @@ -0,0 +1,30 @@ +.empty { + color: #888; + padding: 1em; + text-align: center; +} + +.emptyIcon { + background-color: #888; + border-radius: 100%; + box-shadow: + 0 0 8px 0 rgba(0, 0, 0, 0.2), + 1px 1px 4px 0 rgba(0,0,0,0.2); + fill: #fff; + height: 3em; + margin: 0 auto 1em auto; + opacity: 0.8; + padding: 1em; + width: 3em; +} + +.emptyTitle { + font-size: 1.54em; + padding: 0.25em 0; + white-space: nowrap; +} + +.emptyDescription { + font-size: 0.93em; + white-space: nowrap; +} \ No newline at end of file diff --git a/src/client/components/robot_selector_single/view.tsx b/src/client/components/robot_selector_single/view.tsx new file mode 100644 index 00000000..4d05576a --- /dev/null +++ b/src/client/components/robot_selector_single/view.tsx @@ -0,0 +1,56 @@ +import * as classNames from 'classnames' +import { observer } from 'mobx-react' +import * as React from 'react' + +import { RobotModel } from '../robot/model' +import { Option, Select } from '../select/view' + +import PlugIcon from './plug.svg' +import RobotIcon from './robot.svg' +import * as style from './style.css' +import { RobotSelectorViewModel } from './view_model' + +export type RobotSelectorSingleProps = { + className?: string + robots: RobotModel[] + selected?: RobotModel + dropDirection?: 'up' | 'down' + onSelect(robot: RobotModel): void +} + +@observer +export class RobotSelectorSingle extends React.Component { + render() { + const { className, robots, selected, dropDirection } = this.props + const viewModel = RobotSelectorViewModel.of({ + robots, + selected, + }) + + const empty = ( +
+
+
No connected robots
+ Run yarn start:sim to simulate robots +
+ ) + + return ( +
+ } - dropDirection={dropDirection} - /> -
- ) + const { className, dropDirection } = this.props + return
+