Files
flipper/desktop/plugins/public/layout/MultipleSelectionSection.tsx
Michel Weststrate 0fe879c838 Improve multiple element selector UI
Summary:
Layer selection is pretty easy to miss, as reported in for example: https://fb.workplace.com/groups/flippersupport/permalink/1098169193997071/

Moved the layer selection to the top of the view and gave it some highlighting + dynamic height. The section is no longer collapsible.

Changelog: [Layout] Make the layer selection more prominent

Reviewed By: priteshrnandgaonkar

Differential Revision: D27708650

fbshipit-source-id: c86a55c3a20794aee86e64b6766b2ca4dd6b563f
2021-04-15 07:48:33 -07:00

67 lines
1.9 KiB
TypeScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import {Typography} from 'antd';
import {Element, ElementID, ElementsInspector, styled} from 'flipper';
import {Layout, theme} from 'flipper-plugin';
import React, {memo, useState} from 'react';
const MultipleSelectorSectionContainer = styled(Layout.Container)({
padding: theme.space.medium,
background: theme.backgroundWash,
borderTop: `${theme.space.tiny}px solid ${theme.warningColor}`,
borderBottom: `${theme.space.tiny}px solid ${theme.warningColor}`,
});
type MultipleSelectorSectionProps = {
initialSelectedElement: ElementID | null | undefined;
elements: {[id: string]: Element};
onElementSelected: (key: string) => void;
onElementHovered:
| ((key: string | null | undefined) => any)
| null
| undefined;
};
const MultipleSelectorSection: React.FC<MultipleSelectorSectionProps> = memo(
(props: MultipleSelectorSectionProps) => {
const {
initialSelectedElement,
elements,
onElementSelected,
onElementHovered,
} = props;
const [selectedId, setSelectedId] = useState<ElementID | null | undefined>(
initialSelectedElement,
);
return (
<MultipleSelectorSectionContainer gap>
<Typography.Text>
Multiple elements were found at the target coordinates. Please select
one:
</Typography.Text>
<ElementsInspector
onElementSelected={(key: string) => {
setSelectedId(key);
onElementSelected(key);
}}
onElementHovered={onElementHovered}
onElementExpanded={() => {}}
root={null}
selected={selectedId}
elements={elements}
scrollable={false}
/>
</MultipleSelectorSectionContainer>
);
},
);
export default MultipleSelectorSection;