fixed up service editor

This commit is contained in:
ari committed 2022-06-17 14:23:15 -04:00
1 parent 029df7932e
commit 5bef962977
8 files changed
+107 -44

No files matched your search

@@ -38,4 +38,9 @@
max-width: 7em; max-width: 7em;
text-overflow: ellipsis; text-overflow: ellipsis;
overflow: hidden; overflow: hidden;
}
.input-autocomplete--popper {
min-width: fit-content;
/* max-width: 90vw; */
} }
@@ -2,10 +2,11 @@ import "./InputAutoComplete.css";
import Autocomplete from "@mui/material/Autocomplete"; import Autocomplete from "@mui/material/Autocomplete";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import Chip from "@mui/material/Chip"; import Chip from "@mui/material/Chip";
import { Badge } from "@mui/material"; import { Badge, Popper } from "@mui/material";
import { SearchItem } from "./extras"; import { SearchItem } from "./extras";
import { ReactNode } from "react"; import { ReactNode } from "react";
import { prettyName } from "utils/formatting"; import { prettyName } from "utils/formatting";
import { ModalStyleProps } from "../Modal/index";
export type BaseOption<T = {}> = { export type BaseOption<T = {}> = {
id: string; id: string;
@@ -142,6 +143,16 @@ export function InputAutoComplete<T extends Option>(
options={options} options={options}
onChange={onChange} onChange={onChange}
getOptionLabel={getLabel as any} getOptionLabel={getLabel as any}
PopperComponent={(props) => {
return (
<Popper
{...props}
className={[props.className, "input-autocomplete--popper"].join(
" "
)}
/>
);
}}
filterOptions={(opts, s) => { filterOptions={(opts, s) => {
const searchTerm = s.inputValue; const searchTerm = s.inputValue;
if (!searchTerm) { if (!searchTerm) {
@@ -4,25 +4,33 @@ import { Page } from "components/Page";
import { SearchItem } from "./extras"; import { SearchItem } from "./extras";
export default { export default {
title: 'Inputs/Extras/SearchItem', title: "Inputs/Extras/SearchItem",
component: SearchItem, component: SearchItem,
parameters: { actions: { argTypesRegex: '^on.*' } }, parameters: { actions: { argTypesRegex: "^on.*" } },
argTypes: {} argTypes: {},
} as ComponentMeta<typeof SearchItem>; } as ComponentMeta<typeof SearchItem>;
const Template: ComponentStory<typeof SearchItem> = (args) => {
return (
<Page>
<div
style={{
width: "15em",
height: "3em",
border: "1px solid var(--primary-accent)",
}}
>
<SearchItem {...args} />
</div>
</Page>
);
};
export const Simple = Template.bind({});
const Template: ComponentStory<typeof SearchItem> = args => {
return <Page>
<SearchItem {...args} />
</Page>
}
export const Simple = Template.bind({})
Simple.args = { Simple.args = {
id: "sensor.humidity_main_bedroom", id: "sensor.humidity_main_bedroom",
label: 'Main Bedroom Humidity', label: "Main Bedroom Humidity",
searchTerm: "bedroom", searchTerm: "bedroom",
listProps: {}, listProps: {},
} as any onlyShowLabel: false,
};
+37 -4
View File
@@ -1,9 +1,42 @@
.input-extras--search-item--list { .input-extras--search-item--list {
display: flex; display: flex;
flex-direction: row; flex-direction: column;
gap: 0.15em; gap: 0;
justify-content: center;
align-items: flex-start !important;
margin: 0;
padding: 0;
min-height: 2em;
max-height: 100%;
height: 100%;
width: 100%;
max-width: 20em;
text-overflow: ellipsis;
overflow: hidden;
} }
.input-extras--search-item--list>small::before { .input-extras--search-item--list small {
/* max-height: 2em; */
max-width: 100%;
width: fit-content;
overflow: hidden;
text-overflow: ellipsis;
}
.input-extras--search-item--list b {
max-height: 1.5em;
width: fit-content;
max-width: 100%;
padding-right: 0.25em;
overflow: hidden;
text-overflow: ellipsis;
word-break: break-all;
}
/* .input-extras--search-item--list>small::before {
content: "/ "; content: "/ ";
} } */
+15 -20
View File
@@ -36,34 +36,29 @@ export const SearchItem: FC<{
searchTerm: string; searchTerm: string;
onlyShowLabel?: boolean; onlyShowLabel?: boolean;
}> = ({ listProps, label, id, searchTerm, onlyShowLabel = false }) => { }> = ({ listProps, label, id, searchTerm, onlyShowLabel = false }) => {
const labelElm = (
<b className="input-extras--search-item--list--label">
<HighlightElm text={label} searchTerm={searchTerm} />
</b>
);
const idElm = (
<small className="input-extras--search-item--list--id">
<HighlightElm text={id} searchTerm={searchTerm} />
</small>
);
let inner = ( let inner = (
<> <>
<b> {labelElm}
<HighlightElm text={prettyName(label)} searchTerm={searchTerm} /> {idElm}
</b>{" "}
<small>
<HighlightElm text={id} searchTerm={searchTerm} />
</small>
</> </>
); );
if (onlyShowLabel) { if (onlyShowLabel) {
if (label) { if (label) {
inner = ( inner = labelElm;
<>
<b>
<HighlightElm text={prettyName(label)} searchTerm={searchTerm} />
</b>{" "}
</>
);
} else { } else {
inner = ( inner = idElm;
<>
<small>
<HighlightElm text={id} searchTerm={searchTerm} />
</small>
</>
);
} }
} }
@@ -3,8 +3,19 @@
flex-direction: row; flex-direction: row;
gap: 1em; gap: 1em;
padding-bottom: 0.5em; padding-bottom: 0.5em;
overflow: hidden;
flex-wrap: wrap;
align-items: center;
justify-content: center;
} }
.service-editor--targets>div { .service-editor--targets>div {
flex: 1; flex: 1;
min-width: 8em;
}
@media (max-width: 450px) {
.service-editor--targets>div {
max-width: 38vw;
}
} }
@@ -34,7 +34,7 @@ export const ServiceEditorTarget: FC<ServiceEditorTargetProps> = (props) => {
return ( return (
<div className="service-editor--targets"> <div className="service-editor--targets">
<InputEntity <InputEntity
label="Target Entities" label="Entity"
value={value.entity_id} value={value.entity_id}
onChange={(entity_id) => onChange={(entity_id) =>
props.onChange({ props.onChange({
@@ -46,7 +46,7 @@ export const ServiceEditorTarget: FC<ServiceEditorTargetProps> = (props) => {
multiple multiple
/> />
<InputDevice <InputDevice
label="Target Devices" label="Device"
value={value.device_id} value={value.device_id}
onChange={(device_id) => onChange={(device_id) =>
props.onChange({ props.onChange({
@@ -57,7 +57,7 @@ export const ServiceEditorTarget: FC<ServiceEditorTargetProps> = (props) => {
multiple multiple
/> />
<InputArea <InputArea
label="Target Areas" label="Area"
value={value.area_id} value={value.area_id}
onChange={(area_id) => onChange={(area_id) =>
props.onChange({ props.onChange({
@@ -1,8 +1,8 @@
.service-editor { .service-editor {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
padding: 0.5em 1em; padding: 0.5em 0.25em;
margin: 0.5em 1em; margin: 0.5em 0.25em;
border-color: var(--primary-accent); border-color: var(--primary-accent);
border-width: 1px; border-width: 1px;
border-style: solid; border-style: solid;