settings -> dark/light mode
This commit is contained in:
1 parent
416d88b965
commit
03a735b281
47 files changed
+867
-736
No files matched your search
+6
-9
@@ -8,7 +8,11 @@ import { Page } from "components/Page";
|
||||
|
||||
const ConnectedAutomationRoute = () => {
|
||||
const api = useConnectedApiService();
|
||||
return <AutomationRoute api={api} />;
|
||||
return (
|
||||
<Page api={api}>
|
||||
<AutomationRoute api={api} />
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
|
||||
function App() {
|
||||
@@ -18,14 +22,7 @@ function App() {
|
||||
<CookiesProvider>
|
||||
<BrowserRouter>
|
||||
<Routes>
|
||||
<Route
|
||||
path="*"
|
||||
element={
|
||||
<Page>
|
||||
<ConnectedAutomationRoute />
|
||||
</Page>
|
||||
}
|
||||
/>
|
||||
<Route path="*" element={<ConnectedAutomationRoute />} />
|
||||
</Routes>
|
||||
</BrowserRouter>
|
||||
</CookiesProvider>
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { useEffect } from "react";
|
||||
import { useDefaultApiState, makeReloadAutomations } from "./util";
|
||||
import {
|
||||
useDefaultApiState,
|
||||
makeReloadAutomations,
|
||||
makeProfileManager,
|
||||
} from "./util";
|
||||
import { AutomationAPI } from "./automations";
|
||||
import { UserProfileAPI } from "./profile";
|
||||
|
||||
@@ -10,25 +14,36 @@ export const useAPIService = (
|
||||
) => {
|
||||
// state
|
||||
const [state, setState] = useDefaultApiState();
|
||||
const { reload, wrapCall } = makeReloadAutomations(
|
||||
automationAPI,
|
||||
const autoManager = makeReloadAutomations(automationAPI, state, setState);
|
||||
const userProfileManager = makeProfileManager(
|
||||
userProfileAPI,
|
||||
state,
|
||||
setState
|
||||
);
|
||||
|
||||
// initial load of autos
|
||||
useEffect(() => {
|
||||
reload();
|
||||
autoManager.reload();
|
||||
userProfileManager.reload();
|
||||
// eslint-disable-next-line
|
||||
}, []);
|
||||
|
||||
return {
|
||||
state,
|
||||
removeAutomation: wrapCall(automationAPI.remove),
|
||||
updateAutomation: wrapCall(automationAPI.update),
|
||||
createAutomation: wrapCall(automationAPI.create),
|
||||
updateTags: wrapCall(automationAPI.updateTags),
|
||||
getProfile: wrapCall(userProfileAPI.get),
|
||||
setProfile: wrapCall(userProfileAPI.update),
|
||||
state: {
|
||||
...state,
|
||||
get theme(): "dark" | "light" {
|
||||
if (state.userProfile.ready && state.userProfile.ok) {
|
||||
if (["dark", "light"].includes(state.userProfile.data.theme)) {
|
||||
return state.userProfile.data.theme as any;
|
||||
}
|
||||
}
|
||||
return "dark";
|
||||
},
|
||||
},
|
||||
removeAutomation: autoManager.wrapCall(automationAPI.remove),
|
||||
updateAutomation: autoManager.wrapCall(automationAPI.update),
|
||||
createAutomation: autoManager.wrapCall(automationAPI.create),
|
||||
updateTags: autoManager.wrapCall(automationAPI.updateTags),
|
||||
setProfile: userProfileManager.update,
|
||||
};
|
||||
};
|
||||
@@ -5,6 +5,7 @@ import { USER_PROFILE_ROOT } from "./paths";
|
||||
export const makeProfileAPI = (api: API) => ({
|
||||
async get() {
|
||||
const data = await api.makeCall<UserProfile>({
|
||||
method: "GET",
|
||||
path: USER_PROFILE_ROOT,
|
||||
});
|
||||
return data;
|
||||
|
||||
@@ -32,6 +32,7 @@ export interface ListData<D> {
|
||||
|
||||
export interface ApiState {
|
||||
automations: Errorable<ListData<AutomationData>>;
|
||||
userProfile: Errorable<UserProfile>;
|
||||
}
|
||||
|
||||
export type UserProfile = {
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { useState } from "react";
|
||||
import { ApiState } from "./types";
|
||||
import { AutomationAPI } from "./automations";
|
||||
import { UserProfileAPI } from "./profile";
|
||||
import { UserProfile } from "apiService/types";
|
||||
|
||||
export const useDefaultApiState = () =>
|
||||
useState<ApiState>({
|
||||
automations: { ready: false },
|
||||
userProfile: { ready: false },
|
||||
});
|
||||
|
||||
export const makeReloadAutomations = (
|
||||
@@ -38,3 +41,41 @@ export const makeReloadAutomations = (
|
||||
wrapCall,
|
||||
};
|
||||
};
|
||||
|
||||
export const makeProfileManager = (
|
||||
userProfileAPI: UserProfileAPI,
|
||||
state: ApiState,
|
||||
setState: (s: ApiState) => void
|
||||
) => {
|
||||
const reload = () =>
|
||||
userProfileAPI
|
||||
.get()
|
||||
.then((data) => {
|
||||
setState({
|
||||
...state,
|
||||
userProfile: {
|
||||
ready: true,
|
||||
...data,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) =>
|
||||
setState({
|
||||
...state,
|
||||
userProfile: {
|
||||
ready: true,
|
||||
ok: false,
|
||||
error: JSON.stringify(error),
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
return {
|
||||
reload,
|
||||
update: (data: UserProfile) =>
|
||||
userProfileAPI
|
||||
.update(data)
|
||||
.then(() => reload())
|
||||
.catch(() => reload()),
|
||||
};
|
||||
};
|
||||
@@ -1,23 +1,21 @@
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { AutomationEditor } from "./index";
|
||||
import { useState } from "react";
|
||||
import { Page } from "components/Page";
|
||||
import { useTagDB } from "components/AutomationManager/TagDB";
|
||||
import { DEFAULT_DIMS } from "components/DAGGraph/elements/constants";
|
||||
|
||||
export default {
|
||||
title: "App/AutomationEditor",
|
||||
component: AutomationEditor,
|
||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
||||
args: {
|
||||
dims: DEFAULT_DIMS,
|
||||
},
|
||||
} as ComponentMeta<typeof AutomationEditor>;
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
const Template: ComponentStory<typeof AutomationEditor> = (args) => {
|
||||
const [state, setState] = useState(args.automation);
|
||||
return (
|
||||
<Page>
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: AutomationEditor,
|
||||
meta: {
|
||||
title: "App/AutomationEditor",
|
||||
args: {
|
||||
dims: DEFAULT_DIMS,
|
||||
},
|
||||
},
|
||||
BaseTemplate: (args) => {
|
||||
const [state, setState] = useState(args.automation);
|
||||
return (
|
||||
<AutomationEditor
|
||||
{...args}
|
||||
tagDB={useTagDB(
|
||||
@@ -29,15 +27,15 @@ const Template: ComponentStory<typeof AutomationEditor> = (args) => {
|
||||
window.setTimeout(() => setState(s), 3000);
|
||||
}}
|
||||
/>
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
export const Loading = Template.bind({});
|
||||
export default componentMeta;
|
||||
|
||||
export const Simple = Template.bind({});
|
||||
Simple.args = {
|
||||
...Simple.args,
|
||||
export const Loading = make({});
|
||||
|
||||
export const Simple = make({
|
||||
automation: {
|
||||
condition: [],
|
||||
tags: {
|
||||
@@ -94,11 +92,9 @@ Simple.args = {
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const EmptyStart = Template.bind({});
|
||||
EmptyStart.args = {
|
||||
...EmptyStart.args,
|
||||
export const EmptyStart = make({
|
||||
automation: {
|
||||
condition: [],
|
||||
tags: {},
|
||||
@@ -115,22 +111,18 @@ EmptyStart.args = {
|
||||
trigger: [],
|
||||
action: [],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const BadAutomationInvalidMetadata = Template.bind({});
|
||||
BadAutomationInvalidMetadata.args = {
|
||||
...BadAutomationInvalidMetadata.args,
|
||||
export const BadAutomationInvalidMetadata = make({
|
||||
automation: {
|
||||
condition: [],
|
||||
tags: {},
|
||||
trigger: [],
|
||||
action: [],
|
||||
} as any,
|
||||
};
|
||||
});
|
||||
|
||||
export const BadAutomationInvalidTriggers = Template.bind({});
|
||||
BadAutomationInvalidTriggers.args = {
|
||||
...BadAutomationInvalidTriggers.args,
|
||||
export const BadAutomationInvalidTriggers = make({
|
||||
automation: {
|
||||
condition: [],
|
||||
tags: {},
|
||||
@@ -147,11 +139,9 @@ BadAutomationInvalidTriggers.args = {
|
||||
trigger: ["haha I am a string"] as any,
|
||||
action: [],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const BadAutomationInvalidSequence = Template.bind({});
|
||||
BadAutomationInvalidSequence.args = {
|
||||
...BadAutomationInvalidSequence.args,
|
||||
export const BadAutomationInvalidSequence = make({
|
||||
automation: {
|
||||
condition: [],
|
||||
tags: {},
|
||||
@@ -165,14 +155,12 @@ BadAutomationInvalidSequence.args = {
|
||||
action: [
|
||||
{
|
||||
choose: {},
|
||||
},
|
||||
} as any,
|
||||
],
|
||||
} as any,
|
||||
};
|
||||
});
|
||||
|
||||
export const RepeatExample = Template.bind({});
|
||||
RepeatExample.args = {
|
||||
...RepeatExample.args,
|
||||
export const RepeatExample = make({
|
||||
automation: {
|
||||
id: "1654976151462",
|
||||
alias: "Get out of baby room",
|
||||
@@ -243,4 +231,4 @@ RepeatExample.args = {
|
||||
],
|
||||
tags: {},
|
||||
},
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,63 @@
|
||||
import Alert from "@mui/material/Alert";
|
||||
import Skeleton from "@mui/material/Skeleton";
|
||||
import { ApiService } from "apiService/core";
|
||||
import { UserProfile } from "apiService/types";
|
||||
import { InputList } from "components/Inputs/InputList";
|
||||
import { useLang } from "lang";
|
||||
import { FC, useState } from "react";
|
||||
import LinearProgress from "@mui/material/LinearProgress";
|
||||
|
||||
export type UserProfileProps = {
|
||||
api: ApiService;
|
||||
};
|
||||
export const UserProfileEditor: FC<UserProfileProps> = ({ api }) => {
|
||||
const [saving, setIsSaving] = useState(false);
|
||||
const profile = api.state.userProfile;
|
||||
const lang = useLang();
|
||||
if (!profile.ready) {
|
||||
return (
|
||||
<div className="user-profile">
|
||||
<Skeleton />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (!profile.ok) {
|
||||
return (
|
||||
<div className="user-profile">
|
||||
<Alert color="error">{JSON.stringify(profile.error)}</Alert>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
const update =
|
||||
<K extends keyof UserProfile, D extends UserProfile[K]>(key: K) =>
|
||||
(data: D) => {
|
||||
if (profile.ready) {
|
||||
setIsSaving(true);
|
||||
api
|
||||
.setProfile({
|
||||
...profile.data,
|
||||
[key]: data,
|
||||
})
|
||||
.then(() => {
|
||||
setIsSaving(false);
|
||||
});
|
||||
}
|
||||
};
|
||||
return (
|
||||
<div className="user-profile">
|
||||
<InputList
|
||||
label={lang.get("THEME")}
|
||||
options={["dark", "light"]}
|
||||
current={profile.data.theme}
|
||||
onChange={update("theme")}
|
||||
/>
|
||||
<InputList
|
||||
label={lang.get("LANGUAGE")}
|
||||
options={["eng", "fra"]}
|
||||
current={profile.data.lang}
|
||||
onChange={update("lang")}
|
||||
/>
|
||||
{saving && <LinearProgress />}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
.bottom-bar {
|
||||
width: 100%;
|
||||
font-size: 0.5em;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5em;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.bottom-bar>*, .bottom-bar>div>* {
|
||||
max-height: 1em;
|
||||
height: 1em;
|
||||
min-height: 1em;
|
||||
gap: 0.25em;
|
||||
}
|
||||
|
||||
.bottom-bar #circle {
|
||||
color: var(--mui-primary-main);
|
||||
}
|
||||
|
||||
.bottom-bar #circle::before {
|
||||
content: " ";
|
||||
}
|
||||
|
||||
.bottom-bar #circle.error {
|
||||
color: var(--mui-error-main);
|
||||
}
|
||||
|
||||
|
||||
.bottom-bar #circle.loaded {
|
||||
color: var(--mui-success-light);
|
||||
}
|
||||
|
||||
.bottom-bar .settings {
|
||||
font-size: 0.75em;
|
||||
padding: 1em 0.5em;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.bottom-bar .settings svg {
|
||||
height: 0.5em;
|
||||
width: 0.5em;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import "./index.css";
|
||||
import { FC, useState } from "react";
|
||||
import { useHAConnection } from "haService/connection";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
import SettingsSuggestOutlinedIcon from "@mui/icons-material/SettingsSuggestOutlined";
|
||||
import { useLang } from "lang";
|
||||
import { Modal } from "components/Modal";
|
||||
import { UserProfileEditor, UserProfileProps } from "./UserProfile";
|
||||
|
||||
export type BottomBarProps = UserProfileProps;
|
||||
export const BottomBar: FC<BottomBarProps> = ({ api }) => {
|
||||
const lang = useLang();
|
||||
const ha = useHAConnection();
|
||||
const version = process.env.REACT_APP_BUILD_VERSION ?? "n/a";
|
||||
const [isOpen, setOpen] = useState(false);
|
||||
|
||||
return (
|
||||
<div className="bottom-bar center row">
|
||||
<Modal open={isOpen}>
|
||||
<UserProfileEditor api={api} />
|
||||
<Button onClick={() => setOpen(false)}>{lang.get("CLOSE")}</Button>
|
||||
</Modal>
|
||||
<span id="connection">
|
||||
HA{" "}
|
||||
{ha.status === "loaded"
|
||||
? lang.get("CONNECTED")
|
||||
: ha.status === "error"
|
||||
? lang.get("FAILED")
|
||||
: lang.get("LOADING")}
|
||||
<b id="circle" className={ha.status}>
|
||||
🟢
|
||||
</b>
|
||||
</span>
|
||||
<span>version: {version}</span>
|
||||
<Button className="settings" onClick={() => setOpen(!isOpen)}>
|
||||
<SettingsSuggestOutlinedIcon />
|
||||
settings
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -1,22 +1,17 @@
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import { useState } from "react";
|
||||
import { AutomationCondition } from "types/automations/conditions";
|
||||
import { ConditionNodeBase } from "./ConditionNodeBase";
|
||||
|
||||
export default {
|
||||
title: "ConditionEditor/NodeBase",
|
||||
component: ConditionNodeBase,
|
||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
||||
} as ComponentMeta<typeof ConditionNodeBase>;
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
const Template: ComponentStory<typeof ConditionNodeBase> = ({
|
||||
condition,
|
||||
...args
|
||||
}) => {
|
||||
const [data, setData] = useState(condition);
|
||||
return (
|
||||
<Page>
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: ConditionNodeBase,
|
||||
meta: {
|
||||
title: "ConditionEditor/NodeBase",
|
||||
},
|
||||
BaseTemplate: ({ condition, ...args }) => {
|
||||
const [data, setData] = useState(condition);
|
||||
return (
|
||||
<ConditionNodeBase
|
||||
{...args}
|
||||
condition={data}
|
||||
@@ -24,20 +19,20 @@ const Template: ComponentStory<typeof ConditionNodeBase> = ({
|
||||
setData(data);
|
||||
}}
|
||||
/>
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
export const TemplateViewer = Template.bind({});
|
||||
TemplateViewer.args = {
|
||||
export default componentMeta;
|
||||
|
||||
export const TemplateViewer = make({
|
||||
condition: {
|
||||
condition: "template",
|
||||
value_template: "states('switch.light_kitchen') == 'on'",
|
||||
} as AutomationCondition,
|
||||
};
|
||||
});
|
||||
|
||||
export const MultipleThings = Template.bind({});
|
||||
MultipleThings.args = {
|
||||
export const MultipleThings = make({
|
||||
condition: {
|
||||
condition: "or",
|
||||
conditions: [
|
||||
@@ -62,4 +57,4 @@ MultipleThings.args = {
|
||||
},
|
||||
],
|
||||
} as AutomationCondition,
|
||||
};
|
||||
});
|
||||
@@ -1,26 +1,22 @@
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import { MockPage, Page } from "components/Page";
|
||||
import { useState } from "react";
|
||||
import { AutomationCondition } from "types/automations/conditions";
|
||||
|
||||
import { ConditionEditor } from ".";
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
export default {
|
||||
title: "ConditionEditor",
|
||||
component: ConditionEditor,
|
||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
||||
args: {
|
||||
initialViewMode: "edit",
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: ConditionEditor,
|
||||
meta: {
|
||||
title: "ConditionEditor",
|
||||
args: {
|
||||
initialViewMode: "edit",
|
||||
},
|
||||
},
|
||||
} as ComponentMeta<typeof ConditionEditor>;
|
||||
|
||||
const Template: ComponentStory<typeof ConditionEditor> = ({
|
||||
condition,
|
||||
...args
|
||||
}) => {
|
||||
const [data, setData] = useState(condition);
|
||||
return (
|
||||
<Page>
|
||||
BaseTemplate: ({ condition, ...args }) => {
|
||||
const [data, setData] = useState(condition);
|
||||
return (
|
||||
<ConditionEditor
|
||||
{...args}
|
||||
condition={data}
|
||||
@@ -28,29 +24,28 @@ const Template: ComponentStory<typeof ConditionEditor> = ({
|
||||
setData(data);
|
||||
}}
|
||||
/>
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
export const TemplateViewer = Template.bind({});
|
||||
TemplateViewer.args = {
|
||||
export default componentMeta;
|
||||
|
||||
export const TemplateViewer = make({
|
||||
condition: {
|
||||
condition: "template",
|
||||
value_template: "states('switch.light_kitchen') == 'on'",
|
||||
} as AutomationCondition,
|
||||
};
|
||||
});
|
||||
|
||||
export const NumericStateViewer = Template.bind({});
|
||||
NumericStateViewer.args = {
|
||||
export const NumericStateViewer = make({
|
||||
condition: {
|
||||
condition: "numeric_state",
|
||||
entity_id: "sensor.humidity_kitchen",
|
||||
above: "10",
|
||||
} as AutomationCondition,
|
||||
};
|
||||
});
|
||||
|
||||
export const LogicCondition = Template.bind({});
|
||||
LogicCondition.args = {
|
||||
export const LogicCondition = make({
|
||||
condition: {
|
||||
condition: "or",
|
||||
conditions: [
|
||||
@@ -81,9 +76,8 @@ LogicCondition.args = {
|
||||
},
|
||||
],
|
||||
} as AutomationCondition,
|
||||
};
|
||||
export const TimeCondition = Template.bind({});
|
||||
TimeCondition.args = {
|
||||
});
|
||||
export const TimeCondition = make({
|
||||
condition: {
|
||||
condition: "or",
|
||||
conditions: [
|
||||
@@ -104,7 +98,7 @@ TimeCondition.args = {
|
||||
},
|
||||
],
|
||||
} as AutomationCondition,
|
||||
};
|
||||
});
|
||||
|
||||
export const MultipleConditions: ComponentStory<typeof ConditionEditor> = (
|
||||
args
|
||||
@@ -134,12 +128,12 @@ export const MultipleConditions: ComponentStory<typeof ConditionEditor> = (
|
||||
],
|
||||
});
|
||||
return (
|
||||
<Page>
|
||||
<MockPage>
|
||||
<ConditionEditor
|
||||
onUpdate={setState}
|
||||
onDelete={() => {}}
|
||||
condition={state}
|
||||
/>
|
||||
</Page>
|
||||
</MockPage>
|
||||
);
|
||||
};
|
||||
@@ -1,46 +1,34 @@
|
||||
import React from "react";
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { DAGGraphBoard } from ".";
|
||||
import { Page } from "components/Page";
|
||||
import { SimpleErrorElement } from "components/SimpleErrorElement";
|
||||
|
||||
export default {
|
||||
title: "DAGGraph/Board",
|
||||
component: DAGGraphBoard,
|
||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
||||
args: {},
|
||||
} as ComponentMeta<typeof DAGGraphBoard>;
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
const Template: ComponentStory<typeof DAGGraphBoard> = (args) => {
|
||||
return (
|
||||
<Page>
|
||||
<DAGGraphBoard {...args} />
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: DAGGraphBoard,
|
||||
meta: {
|
||||
title: "DAGGraph/Board",
|
||||
},
|
||||
});
|
||||
|
||||
export const Loading = Template.bind({});
|
||||
Loading.args = {
|
||||
...Loading.args,
|
||||
export default componentMeta;
|
||||
export const Example = make({});
|
||||
|
||||
export const Loading = make({
|
||||
state: {
|
||||
ready: false,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const Errored = Template.bind({});
|
||||
Errored.args = {
|
||||
...Loading.args,
|
||||
export const Errored = make({
|
||||
state: {
|
||||
ready: true,
|
||||
data: {
|
||||
error: <SimpleErrorElement error={new Error("Test")} />,
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const Empty = Template.bind({});
|
||||
Empty.args = {
|
||||
...Empty.args,
|
||||
export const Empty = make({
|
||||
state: {
|
||||
ready: true,
|
||||
data: {
|
||||
@@ -50,11 +38,9 @@ Empty.args = {
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const Basic = Template.bind({});
|
||||
Basic.args = {
|
||||
...Basic.args,
|
||||
export const Basic = make({
|
||||
state: {
|
||||
ready: true,
|
||||
data: {
|
||||
@@ -88,4 +74,4 @@ Basic.args = {
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from "react";
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import { MockPage } from "components/Page";
|
||||
import { ButtonNode } from "./ButtonNode";
|
||||
import { DAGGraphBoard } from "components/DAGGraph/board";
|
||||
import { ButtonNodeMaker } from ".";
|
||||
@@ -25,7 +25,7 @@ const Template: ComponentStory<typeof ButtonNode> = (args) => {
|
||||
...args,
|
||||
};
|
||||
return (
|
||||
<Page>
|
||||
<MockPage>
|
||||
<DAGGraphBoard
|
||||
closeModal={() => {}}
|
||||
state={{
|
||||
@@ -80,7 +80,7 @@ const Template: ComponentStory<typeof ButtonNode> = (args) => {
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</Page>
|
||||
</MockPage>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import React, { FC } from "react";
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import { CollectionNode } from "./CollectionNode";
|
||||
import { MockPage } from "components/Page";
|
||||
import { DAGGraphBoard } from "components/DAGGraph/board";
|
||||
import { CollectionNodeMaker } from "./index";
|
||||
import { DEFAULT_DIMS } from "components/DAGGraph/elements/constants";
|
||||
@@ -19,7 +18,7 @@ type DemoProps = {
|
||||
};
|
||||
const Demo: FC<DemoProps> = (args) => {
|
||||
return (
|
||||
<Page>
|
||||
<MockPage>
|
||||
<DAGGraphBoard
|
||||
closeModal={() => {}}
|
||||
state={{
|
||||
@@ -64,7 +63,7 @@ const Demo: FC<DemoProps> = (args) => {
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</Page>
|
||||
</MockPage>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -84,7 +83,7 @@ export const Colors: ComponentStory<typeof Demo> = (args) => <Demo {...args} />;
|
||||
|
||||
export const Empty: ComponentStory<typeof Demo> = (args) => {
|
||||
return (
|
||||
<Page>
|
||||
<MockPage>
|
||||
<DAGGraphBoard
|
||||
closeModal={() => {}}
|
||||
state={{
|
||||
@@ -124,7 +123,7 @@ export const Empty: ComponentStory<typeof Demo> = (args) => {
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</Page>
|
||||
</MockPage>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -135,7 +134,7 @@ Empty.args = {
|
||||
|
||||
export const ReturnTarget: ComponentStory<typeof Demo> = (args) => {
|
||||
return (
|
||||
<Page>
|
||||
<MockPage>
|
||||
<DAGGraphBoard
|
||||
closeModal={() => {}}
|
||||
state={{
|
||||
@@ -222,7 +221,7 @@ export const ReturnTarget: ComponentStory<typeof Demo> = (args) => {
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</Page>
|
||||
</MockPage>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from "react";
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import { MockPage } from "components/Page";
|
||||
import { SequenceNode } from "./SequenceNode";
|
||||
import { DAGGraphBoard } from "components/DAGGraph/board";
|
||||
import { SequenceNodeMaker } from "./index";
|
||||
@@ -21,7 +21,7 @@ export default {
|
||||
|
||||
const Template: ComponentStory<typeof SequenceNode> = (args) => {
|
||||
return (
|
||||
<Page>
|
||||
<MockPage>
|
||||
<DAGGraphBoard
|
||||
closeModal={() => {}}
|
||||
state={{
|
||||
@@ -46,13 +46,13 @@ const Template: ComponentStory<typeof SequenceNode> = (args) => {
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</Page>
|
||||
</MockPage>
|
||||
);
|
||||
};
|
||||
|
||||
export const Colors: ComponentStory<typeof SequenceNode> = (args) => {
|
||||
return (
|
||||
<Page>
|
||||
<MockPage>
|
||||
<DAGGraphBoard
|
||||
closeModal={() => {}}
|
||||
state={{
|
||||
@@ -85,7 +85,7 @@ export const Colors: ComponentStory<typeof SequenceNode> = (args) => {
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</Page>
|
||||
</MockPage>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,35 +1,43 @@
|
||||
import React, { FC } from "react";
|
||||
import { ComponentMeta, ComponentStory } from '@storybook/react';
|
||||
import { ErrorBoundary } from ".";
|
||||
import { Page } from "components/Page";
|
||||
|
||||
import { makeStory } from "devUtils";
|
||||
import { MockPage } from "components/Page";
|
||||
import { ComponentStory } from "@storybook/react";
|
||||
|
||||
export default {
|
||||
title: 'ErrorBoundary',
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: () => <div>Example</div>,
|
||||
meta: {
|
||||
title: "ErrorBoundary",
|
||||
component: ErrorBoundary,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
args: {
|
||||
}
|
||||
} as ComponentMeta<typeof ErrorBoundary>
|
||||
},
|
||||
});
|
||||
|
||||
export const ErrorThrown: ComponentStory<typeof ErrorBoundary> = args => {
|
||||
const BadComponent: FC = () => {
|
||||
throw new Error("!!!")
|
||||
}
|
||||
return <Page>
|
||||
<ErrorBoundary>
|
||||
<BadComponent />
|
||||
</ErrorBoundary>
|
||||
</Page>
|
||||
}
|
||||
export default componentMeta;
|
||||
export const Example = make({});
|
||||
|
||||
export const NoError: ComponentStory<typeof ErrorBoundary> = args => {
|
||||
const GoodComponent: FC = () => {
|
||||
return <span>All Good.</span>
|
||||
}
|
||||
return <Page>
|
||||
<ErrorBoundary>
|
||||
<GoodComponent />
|
||||
</ErrorBoundary>
|
||||
</Page>
|
||||
}
|
||||
export const ErrorThrown: ComponentStory<typeof ErrorBoundary> = (args) => {
|
||||
const BadComponent: FC = () => {
|
||||
throw new Error("!!!");
|
||||
};
|
||||
return (
|
||||
<MockPage>
|
||||
<ErrorBoundary>
|
||||
<BadComponent />
|
||||
</ErrorBoundary>
|
||||
</MockPage>
|
||||
);
|
||||
};
|
||||
|
||||
export const NoError: ComponentStory<typeof ErrorBoundary> = (args) => {
|
||||
const GoodComponent: FC = () => {
|
||||
return <span>All Good.</span>;
|
||||
};
|
||||
return (
|
||||
<MockPage>
|
||||
<ErrorBoundary>
|
||||
<GoodComponent />
|
||||
</ErrorBoundary>
|
||||
</MockPage>
|
||||
);
|
||||
};
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
GearIcon,
|
||||
} from ".";
|
||||
import { ButtonIcon } from "./ButtonIcons";
|
||||
import { Page } from "components/Page";
|
||||
import { MockPage } from "components/Page";
|
||||
|
||||
export default {
|
||||
title: "Icons",
|
||||
@@ -21,7 +21,7 @@ export default {
|
||||
|
||||
export const IconList: ComponentStory<typeof IconBase> = (args) => {
|
||||
return (
|
||||
<Page>
|
||||
<MockPage>
|
||||
<PencilIcon {...args} />
|
||||
<CheckMarkIcon {...args} />
|
||||
<AddIcon {...args} />
|
||||
@@ -29,7 +29,7 @@ export const IconList: ComponentStory<typeof IconBase> = (args) => {
|
||||
<InfoIcon {...args} />
|
||||
<ZoomIcon {...args} />
|
||||
<GearIcon {...args} />
|
||||
</Page>
|
||||
</MockPage>
|
||||
);
|
||||
};
|
||||
IconList.args = {
|
||||
@@ -39,9 +39,9 @@ IconList.args = {
|
||||
|
||||
export const ButtonIconExample: ComponentStory<typeof IconBase> = (args) => {
|
||||
return (
|
||||
<Page>
|
||||
<MockPage>
|
||||
<ButtonIcon icon={<ArrowIcon {...args} />} />
|
||||
</Page>
|
||||
</MockPage>
|
||||
);
|
||||
};
|
||||
ButtonIconExample.args = {
|
||||
|
||||
@@ -1,36 +1,39 @@
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import { useState } from "react";
|
||||
|
||||
import { InputDevice } from "./InputDevice";
|
||||
|
||||
export default {
|
||||
title: 'Inputs/InputDevice',
|
||||
component: InputDevice,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
argTypes: {}
|
||||
} as ComponentMeta<typeof InputDevice>;
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: InputDevice,
|
||||
meta: {
|
||||
title: "Inputs/InputDevice",
|
||||
},
|
||||
BaseTemplate: (args) => {
|
||||
const [value, setValue] = useState(args.value);
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
maxWidth: 200,
|
||||
}}
|
||||
>
|
||||
<InputDevice
|
||||
{...args}
|
||||
value={value as any}
|
||||
onChange={(v: any) => {
|
||||
setValue(v);
|
||||
args.onChange(v as any);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
export default componentMeta;
|
||||
export const Example = make({});
|
||||
|
||||
const Template: ComponentStory<typeof InputDevice> = args => {
|
||||
const [value, setValue] = useState(args.value)
|
||||
return <Page>
|
||||
<div style={{
|
||||
maxWidth: 200
|
||||
}}>
|
||||
<InputDevice {...args} value={value as any} onChange={(v: any) => {
|
||||
setValue(v)
|
||||
args.onChange(v as any)
|
||||
}} />
|
||||
</div>
|
||||
</Page>
|
||||
|
||||
}
|
||||
|
||||
export const Single = Template.bind({})
|
||||
Single.args = {
|
||||
...Single.args,
|
||||
export const Single = make({
|
||||
multiple: false,
|
||||
value: 'sensor.humidity_bathroom'
|
||||
} as any
|
||||
value: "sensor.humidity_bathroom",
|
||||
});
|
||||
@@ -1,84 +1,77 @@
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import { useState } from "react";
|
||||
|
||||
import { InputEntity } from "./InputEntities";
|
||||
|
||||
export default {
|
||||
title: 'Inputs/InputEntity',
|
||||
component: InputEntity,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
argTypes: {}
|
||||
} as ComponentMeta<typeof InputEntity>;
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: InputEntity,
|
||||
meta: {
|
||||
title: "Inputs/InputEntity",
|
||||
},
|
||||
BaseTemplate: (args) => {
|
||||
const [value, setValue] = useState(args.value);
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
maxWidth: 200,
|
||||
}}
|
||||
>
|
||||
<InputEntity
|
||||
{...args}
|
||||
value={value as any}
|
||||
onChange={(v: any) => {
|
||||
setValue(v);
|
||||
args.onChange(v as any);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
export default componentMeta;
|
||||
export const Example = make({});
|
||||
|
||||
const Template: ComponentStory<typeof InputEntity> = args => {
|
||||
const [value, setValue] = useState(args.value)
|
||||
return <Page>
|
||||
<div style={{
|
||||
maxWidth: 200
|
||||
}}>
|
||||
<InputEntity {...args} value={value as any} onChange={(v: any) => {
|
||||
setValue(v)
|
||||
args.onChange(v as any)
|
||||
}} />
|
||||
</div>
|
||||
</Page>
|
||||
|
||||
}
|
||||
|
||||
export const Single = Template.bind({})
|
||||
Single.args = {
|
||||
...Single.args,
|
||||
export const Single = make({
|
||||
multiple: false,
|
||||
value: 'sensor.bathroom'
|
||||
} as any
|
||||
value: "sensor.bathroom",
|
||||
});
|
||||
|
||||
export const Many = Template.bind({})
|
||||
Many.args = {
|
||||
...Many.args,
|
||||
export const Many = make({
|
||||
multiple: true,
|
||||
value: ['sensor.bathroom', 'person.ari']
|
||||
} as any
|
||||
value: ["sensor.bathroom", "person.ari"],
|
||||
});
|
||||
|
||||
export const ManyEmpty = Template.bind({})
|
||||
ManyEmpty.args = {
|
||||
...ManyEmpty.args,
|
||||
export const ManyEmpty = make({
|
||||
multiple: true,
|
||||
value: []
|
||||
} as any
|
||||
value: [],
|
||||
});
|
||||
|
||||
|
||||
export const ManyButGotSingle = Template.bind({})
|
||||
ManyButGotSingle.args = {
|
||||
...ManyButGotSingle.args,
|
||||
export const ManyButGotSingle = make({
|
||||
multiple: true,
|
||||
value: 'sensor.bathroom'
|
||||
} as any
|
||||
value: "sensor.bathroom",
|
||||
});
|
||||
|
||||
|
||||
export const InvalidDomain = Template.bind({})
|
||||
InvalidDomain.args = {
|
||||
...InvalidDomain.args,
|
||||
export const InvalidDomain = make({
|
||||
multiple: true,
|
||||
value: 'sensor.bathroom',
|
||||
restrictToDomain: ['zone'],
|
||||
} as any
|
||||
value: "sensor.bathroom",
|
||||
restrictToDomain: ["zone"],
|
||||
});
|
||||
|
||||
|
||||
export const InvalidManyDomain = Template.bind({})
|
||||
InvalidManyDomain.args = {
|
||||
...InvalidManyDomain.args,
|
||||
export const InvalidManyDomain = make({
|
||||
multiple: true,
|
||||
value: 'sensor.bathroom',
|
||||
restrictToDomain: ['zone', 'switch'],
|
||||
} as any
|
||||
value: "sensor.bathroom",
|
||||
restrictToDomain: ["zone", "switch"],
|
||||
});
|
||||
|
||||
export const InvalidLots = Template.bind({})
|
||||
InvalidLots.args = {
|
||||
...InvalidLots.args,
|
||||
export const InvalidLots = make({
|
||||
multiple: true,
|
||||
value: ['person.ari', 'sensor.bathroom', 'binary_sensor.ping_tv', 'device_tracker.phone'],
|
||||
restrictToDomain: ['zone', 'switch'],
|
||||
} as any
|
||||
value: [
|
||||
"person.ari",
|
||||
"sensor.bathroom",
|
||||
"binary_sensor.ping_tv",
|
||||
"device_tracker.phone",
|
||||
],
|
||||
restrictToDomain: ["zone", "switch"],
|
||||
});
|
||||
@@ -1,36 +1,39 @@
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import { useState } from "react";
|
||||
|
||||
import { InputService } from "./InputService";
|
||||
|
||||
export default {
|
||||
title: 'Inputs/InputService',
|
||||
component: InputService,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
argTypes: {}
|
||||
} as ComponentMeta<typeof InputService>;
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: InputService,
|
||||
meta: {
|
||||
title: "Inputs/InputService",
|
||||
},
|
||||
BaseTemplate: (args) => {
|
||||
const [value, setValue] = useState(args.value);
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
maxWidth: 200,
|
||||
}}
|
||||
>
|
||||
<InputService
|
||||
{...args}
|
||||
value={value as any}
|
||||
onChange={(v: any) => {
|
||||
setValue(v);
|
||||
args.onChange(v as any);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
export default componentMeta;
|
||||
export const Example = make({});
|
||||
|
||||
const Template: ComponentStory<typeof InputService> = args => {
|
||||
const [value, setValue] = useState(args.value)
|
||||
return <Page>
|
||||
<div style={{
|
||||
maxWidth: 200
|
||||
}}>
|
||||
<InputService {...args} value={value as any} onChange={(v: any) => {
|
||||
setValue(v)
|
||||
args.onChange(v as any)
|
||||
}} />
|
||||
</div>
|
||||
</Page>
|
||||
|
||||
}
|
||||
|
||||
export const Single = Template.bind({})
|
||||
Single.args = {
|
||||
...Single.args,
|
||||
export const Single = make({
|
||||
multiple: false,
|
||||
value: ''
|
||||
} as any
|
||||
value: "",
|
||||
});
|
||||
@@ -1,19 +1,17 @@
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import { useState } from "react";
|
||||
|
||||
import { InputTimeEntity } from "./InputTimeEntity";
|
||||
|
||||
export default {
|
||||
title: "Inputs/InputTimeEntity",
|
||||
component: InputTimeEntity,
|
||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
||||
} as ComponentMeta<typeof InputTimeEntity>;
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
const Template: ComponentStory<typeof InputTimeEntity> = (args) => {
|
||||
const [value, setValue] = useState("");
|
||||
return (
|
||||
<Page>
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: InputTimeEntity,
|
||||
meta: {
|
||||
title: "Inputs/InputTimeEntity",
|
||||
},
|
||||
BaseTemplate: (args) => {
|
||||
const [value, setValue] = useState("");
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
padding: "1em",
|
||||
@@ -28,8 +26,8 @@ const Template: ComponentStory<typeof InputTimeEntity> = (args) => {
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
export const SimpleText = Template.bind({});
|
||||
export const SimpleText = make({});
|
||||
@@ -1,18 +1,14 @@
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
|
||||
import { SearchItem } from "./extras";
|
||||
|
||||
export default {
|
||||
title: "Inputs/Extras/SearchItem",
|
||||
component: SearchItem,
|
||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
||||
argTypes: {},
|
||||
} as ComponentMeta<typeof SearchItem>;
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
const Template: ComponentStory<typeof SearchItem> = (args) => {
|
||||
return (
|
||||
<Page>
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: SearchItem,
|
||||
meta: {
|
||||
title: "Inputs/Extras/SearchItem",
|
||||
},
|
||||
BaseTemplate: (args) => {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
width: "15em",
|
||||
@@ -22,15 +18,16 @@ const Template: ComponentStory<typeof SearchItem> = (args) => {
|
||||
>
|
||||
<SearchItem {...args} />
|
||||
</div>
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
export const Simple = Template.bind({});
|
||||
Simple.args = {
|
||||
export default componentMeta;
|
||||
|
||||
export const Simple = make({
|
||||
id: "sensor.humidity_main_bedroom",
|
||||
label: "Main Bedroom Humidity",
|
||||
searchTerm: "bedroom",
|
||||
listProps: {},
|
||||
onlyShowLabel: false,
|
||||
};
|
||||
});
|
||||
@@ -4,24 +4,30 @@ import { useState } from "react";
|
||||
|
||||
import InputBoolean from "./InputBoolean";
|
||||
|
||||
export default {
|
||||
title: 'Inputs/InputBoolean',
|
||||
component: InputBoolean,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
} as ComponentMeta<typeof InputBoolean>;
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: InputBoolean,
|
||||
meta: {
|
||||
title: "Inputs/InputBoolean",
|
||||
args: {
|
||||
label: "Template",
|
||||
},
|
||||
},
|
||||
BaseTemplate: (args) => {
|
||||
const [state, onChange] = useState(args.value);
|
||||
return (
|
||||
<InputBoolean
|
||||
{...args}
|
||||
value={state}
|
||||
onChange={(v) => {
|
||||
args.onChange(v);
|
||||
onChange(v);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
const Template: ComponentStory<typeof InputBoolean> = args => {
|
||||
const [state, onChange] = useState(args.value)
|
||||
return <Page>
|
||||
<InputBoolean {...args} value={state} onChange={v => {
|
||||
args.onChange(v)
|
||||
onChange(v)
|
||||
}} />
|
||||
</Page>
|
||||
}
|
||||
|
||||
export const SimpleText = Template.bind({})
|
||||
SimpleText.args = {
|
||||
label: "Template",
|
||||
}
|
||||
export default componentMeta;
|
||||
export const Example = make({});
|
||||
@@ -1,32 +1,31 @@
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import { useState } from "react";
|
||||
|
||||
import InputNumber from "./InputNumber";
|
||||
|
||||
export default {
|
||||
title: 'Inputs/InputNumber',
|
||||
component: InputNumber,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
argTypes: {
|
||||
label: {
|
||||
defaultValue: 'Sample Title'
|
||||
}
|
||||
}
|
||||
} as ComponentMeta<typeof InputNumber>;
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: InputNumber,
|
||||
meta: {
|
||||
title: "Inputs/InputNumber",
|
||||
argTypes: {
|
||||
label: {
|
||||
defaultValue: "Sample Title",
|
||||
},
|
||||
},
|
||||
},
|
||||
BaseTemplate: (args) => {
|
||||
const [value, setValue] = useState<number | undefined>(args.value);
|
||||
return <InputNumber {...args} value={value} onChange={setValue} />;
|
||||
},
|
||||
});
|
||||
|
||||
export const NullStart: ComponentStory<typeof InputNumber> = args => {
|
||||
export default componentMeta;
|
||||
|
||||
const [value, setValue] = useState<number | undefined>(undefined)
|
||||
return <Page>
|
||||
<InputNumber {...args} value={value} onChange={setValue} />
|
||||
</Page>
|
||||
}
|
||||
export const SomeStuffAtStart: ComponentStory<typeof InputNumber> = args => {
|
||||
export const NullStart = make({
|
||||
value: undefined,
|
||||
});
|
||||
|
||||
const [value, setValue] = useState<number | undefined>(10)
|
||||
return <Page>
|
||||
<InputNumber {...args} value={value} onChange={setValue} />
|
||||
</Page>
|
||||
}
|
||||
export const SomeStuffAtStart = make({
|
||||
value: 10,
|
||||
});
|
||||
@@ -4,22 +4,21 @@ import { useState } from "react";
|
||||
|
||||
import InputText from "./InputText";
|
||||
|
||||
export default {
|
||||
title: 'Inputs/InputText',
|
||||
component: InputText,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
} as ComponentMeta<typeof InputText>;
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: InputText,
|
||||
meta: {
|
||||
title: "Inputs/InputText",
|
||||
},
|
||||
BaseTemplate: (args) => {
|
||||
const [value, setValue] = useState("");
|
||||
return <InputText {...args} value={value} onChange={setValue} />;
|
||||
},
|
||||
});
|
||||
|
||||
const Template: ComponentStory<typeof InputText> = args => {
|
||||
export default componentMeta;
|
||||
|
||||
const [value, setValue] = useState('')
|
||||
return <Page>
|
||||
<InputText {...args} value={value} onChange={setValue} />
|
||||
</Page>
|
||||
}
|
||||
|
||||
export const SimpleText = Template.bind({})
|
||||
SimpleText.args = {
|
||||
export const SimpleText = make({
|
||||
label: "Entity ID",
|
||||
}
|
||||
});
|
||||
@@ -1,20 +1,15 @@
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import { useState } from "react";
|
||||
import { AutomationTime } from "types/automations/common";
|
||||
|
||||
import { InputTime } from "./InputTime";
|
||||
|
||||
export default {
|
||||
title: "Inputs/InputTime",
|
||||
component: InputTime,
|
||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
||||
} as ComponentMeta<typeof InputTime>;
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
const Template: ComponentStory<typeof InputTime> = (args) => {
|
||||
const [value, setValue] = useState<AutomationTime | undefined>(undefined);
|
||||
return (
|
||||
<Page>
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: InputTime,
|
||||
BaseTemplate: (args) => {
|
||||
const [value, setValue] = useState<AutomationTime | undefined>(undefined);
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
padding: "1em",
|
||||
@@ -29,12 +24,17 @@ const Template: ComponentStory<typeof InputTime> = (args) => {
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
);
|
||||
},
|
||||
meta: {
|
||||
title: "Inputs/InputTime",
|
||||
},
|
||||
});
|
||||
|
||||
export const SimpleText = Template.bind({});
|
||||
SimpleText.args = {
|
||||
export default componentMeta;
|
||||
export const Example = make({});
|
||||
|
||||
export const SimpleText = make({
|
||||
label: "Time Stamp",
|
||||
value: "10",
|
||||
};
|
||||
});
|
||||
@@ -4,24 +4,24 @@ import { useState } from "react";
|
||||
|
||||
import InputYaml from "./InputYaml";
|
||||
|
||||
export default {
|
||||
title: 'Inputs/InputYaml',
|
||||
component: InputYaml,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
} as ComponentMeta<typeof InputYaml>;
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: InputYaml,
|
||||
BaseTemplate: (args) => {
|
||||
const [value, setValue] = useState({
|
||||
test: "data",
|
||||
});
|
||||
return <InputYaml {...args} value={value} onChange={setValue} />;
|
||||
},
|
||||
meta: {
|
||||
title: "Inputs/InputYaml",
|
||||
},
|
||||
});
|
||||
|
||||
const Template: ComponentStory<typeof InputYaml> = args => {
|
||||
export default componentMeta;
|
||||
export const Example = make({});
|
||||
|
||||
const [value, setValue] = useState({
|
||||
"test": "data"
|
||||
})
|
||||
return <Page>
|
||||
<InputYaml {...args} value={value} onChange={setValue} />
|
||||
</Page>
|
||||
}
|
||||
|
||||
export const SimpleText = Template.bind({})
|
||||
SimpleText.args = {
|
||||
export const SimpleText = make({
|
||||
label: "Template",
|
||||
}
|
||||
});
|
||||
@@ -1,29 +1,22 @@
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import InputAutoText from "./InputAutoText";
|
||||
|
||||
export default {
|
||||
title: "Inputs/InputAutoText",
|
||||
component: InputAutoText,
|
||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
||||
args: {
|
||||
label: "Something",
|
||||
value: "",
|
||||
options: ["test", "usa", "canada"],
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: InputAutoText,
|
||||
meta: {
|
||||
title: "Inputs/InputAutoText",
|
||||
args: {
|
||||
label: "Something",
|
||||
value: "",
|
||||
options: ["test", "usa", "canada"],
|
||||
},
|
||||
},
|
||||
} as ComponentMeta<typeof InputAutoText>;
|
||||
});
|
||||
|
||||
const Template: ComponentStory<typeof InputAutoText> = (args) => {
|
||||
return (
|
||||
<Page>
|
||||
<InputAutoText {...args} />
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
export default componentMeta;
|
||||
export const Example = make({});
|
||||
|
||||
export const Basic = Template.bind({});
|
||||
export const WithError = Template.bind({});
|
||||
WithError.args = {
|
||||
...WithError.args,
|
||||
export const WithError = make({
|
||||
error: "Oh no!",
|
||||
};
|
||||
});
|
||||
@@ -1,47 +1,35 @@
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
import { InputList } from "./InputList";
|
||||
|
||||
export default {
|
||||
title: 'Inputs/InputList',
|
||||
component: InputList,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
} as ComponentMeta<typeof InputList>;
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: InputList,
|
||||
BaseTemplate: (args) => {
|
||||
const [value, setValue] = useState(args.current);
|
||||
useEffect(() => {
|
||||
if (value !== args.current) {
|
||||
setValue(args.current);
|
||||
}
|
||||
}, [args.current]);
|
||||
return <InputList {...args} current={value} onChange={setValue} />;
|
||||
},
|
||||
meta: {
|
||||
title: "Inputs/InputList",
|
||||
},
|
||||
});
|
||||
|
||||
const Template: ComponentStory<typeof InputList> = args => {
|
||||
export default componentMeta;
|
||||
|
||||
const [value, setValue] = useState(args.current);
|
||||
useEffect(() => {
|
||||
if (value !== args.current) {
|
||||
setValue(args.current)
|
||||
}
|
||||
}, [args.current])
|
||||
return <Page>
|
||||
<InputList {...args} current={value} onChange={setValue} />
|
||||
</Page>
|
||||
}
|
||||
|
||||
export const SimpleText = Template.bind({})
|
||||
SimpleText.args = {
|
||||
export const SimpleText = make({
|
||||
label: "Entity ID",
|
||||
options: [
|
||||
'Bob',
|
||||
'Martin',
|
||||
"Toots"
|
||||
]
|
||||
}
|
||||
options: ["Bob", "Martin", "Toots"],
|
||||
});
|
||||
|
||||
|
||||
export const InvalidSelection = Template.bind({})
|
||||
InvalidSelection.args = {
|
||||
export const InvalidSelection = make({
|
||||
current: "Derek",
|
||||
label: "Entity ID",
|
||||
options: [
|
||||
'Bob',
|
||||
'Martin',
|
||||
"Toots"
|
||||
]
|
||||
}
|
||||
options: ["Bob", "Martin", "Toots"],
|
||||
});
|
||||
@@ -1,24 +1,19 @@
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import InputMultiSelect from "./InputMultiSelect";
|
||||
|
||||
export default {
|
||||
title: "Inputs/InputMultiSelect",
|
||||
component: InputMultiSelect,
|
||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
||||
} as ComponentMeta<typeof InputMultiSelect>;
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
const Template: ComponentStory<typeof InputMultiSelect> = (args) => {
|
||||
const [value, setValue] = useState<number[]>(args.selected);
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: InputMultiSelect,
|
||||
BaseTemplate: (args) => {
|
||||
const [value, setValue] = useState<number[]>(args.selected);
|
||||
|
||||
useEffect(() => {
|
||||
setValue(args.selected);
|
||||
}, [args.selected]);
|
||||
useEffect(() => {
|
||||
setValue(args.selected);
|
||||
}, [args.selected]);
|
||||
|
||||
return (
|
||||
<Page>
|
||||
return (
|
||||
<InputMultiSelect
|
||||
{...args}
|
||||
onChange={(a) => {
|
||||
@@ -28,14 +23,18 @@ const Template: ComponentStory<typeof InputMultiSelect> = (args) => {
|
||||
options={args.options}
|
||||
selected={value}
|
||||
/>
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
);
|
||||
},
|
||||
meta: {
|
||||
title: "Inputs/InputMultiSelect",
|
||||
},
|
||||
});
|
||||
|
||||
export const Simple = Template.bind({});
|
||||
Simple.args = {
|
||||
export default componentMeta;
|
||||
|
||||
export const Simple = make({
|
||||
label: "Room Tags",
|
||||
options: ["Bears", "Cats", "Kitchen", "Bathroom"],
|
||||
selected: [1],
|
||||
max: 2,
|
||||
};
|
||||
});
|
||||
@@ -1,58 +1,49 @@
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import { useState } from "react";
|
||||
|
||||
import InputTextBubble from "./InputTextBubble";
|
||||
|
||||
export default {
|
||||
title: 'Inputs/InputTextBubble',
|
||||
component: InputTextBubble,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
argTypes: {
|
||||
label: {
|
||||
defaultValue: 'Sample Title'
|
||||
}
|
||||
}
|
||||
} as ComponentMeta<typeof InputTextBubble>;
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: InputTextBubble,
|
||||
BaseTemplate: (args) => {
|
||||
const [value, setValue] = useState<string | string[]>(args.value ?? "");
|
||||
return (
|
||||
<div style={{ maxWidth: "200px", overflow: "hidden" }}>
|
||||
<InputTextBubble {...args} value={value} onChange={setValue} />
|
||||
</div>
|
||||
);
|
||||
},
|
||||
meta: {
|
||||
title: "Inputs/InputTextBubble",
|
||||
argTypes: {
|
||||
label: {
|
||||
defaultValue: "Sample Title",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const ArrayText: ComponentStory<typeof InputTextBubble> = args => {
|
||||
export default componentMeta;
|
||||
|
||||
const [value, setValue] = useState<string | string[]>(['wow', 'lots of bubbles', 'itchen', 'bathroom'])
|
||||
return <Page>
|
||||
<div style={{ maxWidth: '200px', overflow: 'hidden' }}>
|
||||
<InputTextBubble {...args} value={value} onChange={setValue} />
|
||||
</div>
|
||||
</Page>
|
||||
}
|
||||
export const ArrayText = make({
|
||||
value: ["wow", "lots of bubbles", "itchen", "bathroom"],
|
||||
});
|
||||
export const JustText = make({
|
||||
value: "hello",
|
||||
});
|
||||
|
||||
export const JustText: ComponentStory<typeof InputTextBubble> = args => {
|
||||
|
||||
const [value, setValue] = useState<string | string[]>('hello')
|
||||
return <Page>
|
||||
<InputTextBubble {...args} value={value} onChange={setValue} />
|
||||
</Page>
|
||||
}
|
||||
|
||||
export const ManyOptions: ComponentStory<typeof InputTextBubble> = args => {
|
||||
|
||||
const [value, setValue] = useState<string | string[]>('hello')
|
||||
return <Page>
|
||||
<InputTextBubble {...args} value={value} onChange={setValue} />
|
||||
</Page>
|
||||
}
|
||||
|
||||
ManyOptions.args = {
|
||||
...ManyOptions.args,
|
||||
export const ManyOptions = make({
|
||||
value: "hello",
|
||||
options: [
|
||||
'sensor.humidity_bathroom',
|
||||
'sensor.humidity_bedroom',
|
||||
'sensor.humidity_laundry',
|
||||
'sensor.temp_bathroom',
|
||||
'sensor.temp_bedroom',
|
||||
'switch.living_room',
|
||||
'switch.bathroom',
|
||||
'light.bedroom_main',
|
||||
'light.bedroom_second',
|
||||
]
|
||||
}
|
||||
"sensor.humidity_bathroom",
|
||||
"sensor.humidity_bedroom",
|
||||
"sensor.humidity_laundry",
|
||||
"sensor.temp_bathroom",
|
||||
"sensor.temp_bedroom",
|
||||
"switch.living_room",
|
||||
"switch.bathroom",
|
||||
"light.bedroom_main",
|
||||
"light.bedroom_second",
|
||||
],
|
||||
});
|
||||
@@ -4,17 +4,11 @@ import InputText from "./Base/InputText";
|
||||
|
||||
import { InputTextView } from "./InputTextView";
|
||||
|
||||
export default {
|
||||
title: "Inputs/InputTextView",
|
||||
component: InputTextView,
|
||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
||||
args: {
|
||||
value: "example",
|
||||
},
|
||||
} as ComponentMeta<typeof InputTextView>;
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
export const Basic: ComponentStory<typeof InputTextView> = (args) => (
|
||||
<Page>
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: InputTextView,
|
||||
BaseTemplate: (args) => (
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
@@ -26,5 +20,15 @@ export const Basic: ComponentStory<typeof InputTextView> = (args) => (
|
||||
<InputTextView {...args} />
|
||||
<InputText {...args} />
|
||||
</div>
|
||||
</Page>
|
||||
);
|
||||
),
|
||||
meta: {
|
||||
title: "Inputs/InputTextView",
|
||||
args: {
|
||||
value: "example",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default componentMeta;
|
||||
|
||||
export const Basic = make({});
|
||||
@@ -2,11 +2,10 @@ import React from "react";
|
||||
import { ComponentStory } from "@storybook/react";
|
||||
import { NodeEditor, NodeEditorProps } from ".";
|
||||
|
||||
import { AutomationCondition } from "types/automations/conditions";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
import { useState } from "react";
|
||||
import { Modal } from "components/Modal";
|
||||
import { Page } from "components/Page";
|
||||
import { MockPage } from "components/Page";
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
const { componentMeta, make } = makeStory({
|
||||
@@ -23,16 +22,14 @@ const { componentMeta, make } = makeStory({
|
||||
Component: (props: NodeEditorProps) => {
|
||||
const [state, setState] = useState(props.node);
|
||||
return (
|
||||
<Page>
|
||||
<NodeEditor
|
||||
{...props}
|
||||
node={state}
|
||||
onSave={(s) => {
|
||||
setState(s);
|
||||
props.onSave && props.onSave(s);
|
||||
}}
|
||||
/>
|
||||
</Page>
|
||||
<NodeEditor
|
||||
{...props}
|
||||
node={state}
|
||||
onSave={(s) => {
|
||||
setState(s);
|
||||
props.onSave && props.onSave(s);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
},
|
||||
});
|
||||
@@ -77,12 +74,12 @@ export const DeviceTriggerExample = make({
|
||||
export const InAModal: ComponentStory<typeof NodeEditor> = (props) => {
|
||||
const [open, setOpen] = useState(false);
|
||||
return (
|
||||
<Page>
|
||||
<MockPage>
|
||||
<Button onClick={() => setOpen(!open)}>Open Editor</Button>
|
||||
<Modal open={open}>
|
||||
<NodeEditor {...props} onClose={() => setOpen(!open)} />
|
||||
</Modal>
|
||||
</Page>
|
||||
</MockPage>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -15,4 +15,9 @@
|
||||
|
||||
/* background */
|
||||
background-color: var(--mui-background-default);
|
||||
}
|
||||
|
||||
.page>.page-contents {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import "./index.css";
|
||||
import { createRef, FC, ReactNode, useEffect, useRef } from "react";
|
||||
import { createRef, FC, PropsWithChildren, useEffect, useRef } from "react";
|
||||
import {
|
||||
createTheme,
|
||||
Palette,
|
||||
@@ -7,23 +7,21 @@ import {
|
||||
ThemeProvider,
|
||||
useTheme,
|
||||
} from "@mui/material/styles";
|
||||
import { VersionBox } from "components/VersionBox";
|
||||
import { BottomBar } from "components/BottomBar";
|
||||
import { SnackbarKey, SnackbarProvider, useSnackbar } from "notistack";
|
||||
import Button from "@mui/material/Button";
|
||||
import { useHAConnection } from "haService/connection";
|
||||
import { ConfirmProvider } from "material-ui-confirm";
|
||||
import { Color } from "@mui/material";
|
||||
import useWindowSize from "utils/useWindowSize";
|
||||
import { ApiService } from "apiService/core";
|
||||
import { useMockApiService } from "apiService";
|
||||
|
||||
const theme = createTheme({
|
||||
palette: {
|
||||
mode: "dark",
|
||||
},
|
||||
});
|
||||
export type PageProps = PropsWithChildren<{
|
||||
api: ApiService;
|
||||
}>;
|
||||
|
||||
export const InternalPage: FC<{
|
||||
children: ReactNode;
|
||||
}> = ({ children }) => {
|
||||
export const InternalPage: FC<PageProps> = ({ children, api }) => {
|
||||
const conn = useHAConnection();
|
||||
const theme = useTheme();
|
||||
const snackbar = useSnackbar();
|
||||
@@ -62,25 +60,31 @@ export const InternalPage: FC<{
|
||||
}, [conn, snackbar]);
|
||||
|
||||
return (
|
||||
<main className={["page", isMobile ? "mobile" : ""].join(" ")}>
|
||||
<main
|
||||
className={["page", "center column", isMobile ? "mobile" : ""].join(" ")}
|
||||
>
|
||||
<div className="page-contents center column">{children}</div>
|
||||
<BottomBar api={api} />
|
||||
<style>
|
||||
{`:root {
|
||||
${convertPaletteToCss(theme.palette)}
|
||||
}`}
|
||||
</style>
|
||||
<VersionBox />
|
||||
{children}
|
||||
</main>
|
||||
);
|
||||
};
|
||||
|
||||
export const Page: FC<{
|
||||
children: ReactNode;
|
||||
}> = ({ children }) => {
|
||||
export const Page: FC<PageProps> = (props) => {
|
||||
const notistackRef = createRef<any>();
|
||||
const onClickDismiss = (key: SnackbarKey) => () => {
|
||||
notistackRef.current.closeSnackbar(key);
|
||||
};
|
||||
const theme = createTheme({
|
||||
palette: {
|
||||
mode: props.api.state.theme,
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<ThemeProvider theme={theme}>
|
||||
<ConfirmProvider>
|
||||
@@ -96,13 +100,18 @@ export const Page: FC<{
|
||||
dense
|
||||
preventDuplicate
|
||||
>
|
||||
<InternalPage>{children}</InternalPage>
|
||||
<InternalPage {...props} />
|
||||
</SnackbarProvider>
|
||||
</ConfirmProvider>
|
||||
</ThemeProvider>
|
||||
);
|
||||
};
|
||||
|
||||
export const MockPage: FC<PropsWithChildren<{}>> = (props) => {
|
||||
const api = useMockApiService([]);
|
||||
return <Page api={api} {...props} />;
|
||||
};
|
||||
|
||||
export const convertPaletteToCss = (p: Palette): string => {
|
||||
let out = ``;
|
||||
for (const k of [
|
||||
|
||||
@@ -1,21 +1,15 @@
|
||||
import React, { FC, useEffect, useState } from "react";
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import React, { useState } from "react";
|
||||
import { ServiceEditor } from ".";
|
||||
import { TypedHassService } from "haService/fieldTypes";
|
||||
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||
|
||||
export default {
|
||||
title: "Services/ServiceEditor",
|
||||
component: ServiceEditor,
|
||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
||||
args: {},
|
||||
} as ComponentMeta<typeof ServiceEditor>;
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
const Template: ComponentStory<typeof ServiceEditor> = (props) => {
|
||||
const [state, setState] = useState(props.data);
|
||||
return (
|
||||
<Page>
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: ServiceEditor,
|
||||
BaseTemplate: (props) => {
|
||||
const [state, setState] = useState(props.data);
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
maxHeight: "99vh",
|
||||
@@ -63,22 +57,24 @@ const Template: ComponentStory<typeof ServiceEditor> = (props) => {
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
);
|
||||
},
|
||||
meta: {
|
||||
title: "Services/ServiceEditor",
|
||||
},
|
||||
});
|
||||
|
||||
const makeExample = (service: TypedHassService) => {
|
||||
const Eg = Template.bind({});
|
||||
Eg.args = {
|
||||
...Eg,
|
||||
export default componentMeta;
|
||||
export const Example = make({});
|
||||
|
||||
const makeExample = (service: TypedHassService) =>
|
||||
make({
|
||||
service,
|
||||
data: {
|
||||
target: {},
|
||||
field: {},
|
||||
},
|
||||
};
|
||||
return Eg;
|
||||
};
|
||||
});
|
||||
|
||||
export const NumberSetValue = makeExample({
|
||||
name: "Set",
|
||||
|
||||
@@ -6,26 +6,27 @@ import SettingsApplicationsIcon from "@mui/icons-material/SettingsApplications";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
import { DeleteForeverOutlined } from "@mui/icons-material";
|
||||
import EditIcon from "@mui/icons-material/Edit";
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
export default {
|
||||
title: "Nav/SpeedDial",
|
||||
component: SpeedDial,
|
||||
};
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: SpeedDial,
|
||||
BaseTemplate: () => (
|
||||
<div
|
||||
style={{
|
||||
maxWidth: "10em",
|
||||
maxHeight: "10em",
|
||||
}}
|
||||
>
|
||||
<SpeedDial icon={<SettingsApplicationsIcon />}>
|
||||
<ButtonIcon icon={<DeleteForeverOutlined />} />
|
||||
<ButtonIcon icon={<EditIcon />} />
|
||||
</SpeedDial>
|
||||
</div>
|
||||
),
|
||||
meta: {
|
||||
title: "Nav/SpeedDial",
|
||||
},
|
||||
});
|
||||
|
||||
export const IconList: ComponentStory<typeof SpeedDial> = () => {
|
||||
return (
|
||||
<Page>
|
||||
<div
|
||||
style={{
|
||||
maxWidth: "10em",
|
||||
maxHeight: "10em",
|
||||
}}
|
||||
>
|
||||
<SpeedDial icon={<SettingsApplicationsIcon />}>
|
||||
<ButtonIcon icon={<DeleteForeverOutlined />} />
|
||||
<ButtonIcon icon={<EditIcon />} />
|
||||
</SpeedDial>
|
||||
</div>
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
export default componentMeta;
|
||||
export const IconList = make({});
|
||||
@@ -1,21 +0,0 @@
|
||||
.version-box {
|
||||
position: absolute;
|
||||
bottom: -0.5em;
|
||||
right: 0;
|
||||
font-size: 0.5em;
|
||||
}
|
||||
|
||||
.version-box #circle {
|
||||
color: var(--mui-primary-main);
|
||||
height: 1em;
|
||||
width: 1em;
|
||||
}
|
||||
|
||||
.version-box #circle.error {
|
||||
color: var(--mui-error-main);
|
||||
}
|
||||
|
||||
|
||||
.version-box #circle.loaded {
|
||||
color: var(--mui-success-light);
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
import "./index.css";
|
||||
import { FC } from "react";
|
||||
import { useHAConnection } from "haService/connection";
|
||||
|
||||
export const VersionBox: FC = () => {
|
||||
const ha = useHAConnection();
|
||||
const version = process.env.REACT_APP_BUILD_VERSION ?? "n/a";
|
||||
|
||||
return (
|
||||
<div className="version-box">
|
||||
version: {version} / HA Connection{" "}
|
||||
<span id="circle" className={ha.status}>
|
||||
🟢
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -2,6 +2,8 @@ import "styles/root.css";
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import { ComponentProps, JSXElementConstructor } from "react";
|
||||
import { ApiService } from "apiService/core";
|
||||
import { useConnectedApiService, useMockApiService } from "apiService";
|
||||
|
||||
export type MakeStoryArgs<
|
||||
T extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>
|
||||
@@ -9,6 +11,7 @@ export type MakeStoryArgs<
|
||||
Component: T;
|
||||
BaseTemplate?: ComponentStory<T>;
|
||||
meta: Partial<ComponentMeta<T>> & { title: string };
|
||||
useLiveApi?: boolean;
|
||||
};
|
||||
export const makeStory = <
|
||||
T extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>
|
||||
@@ -16,6 +19,7 @@ export const makeStory = <
|
||||
BaseTemplate,
|
||||
Component,
|
||||
meta,
|
||||
useLiveApi = false,
|
||||
}: MakeStoryArgs<T>) => {
|
||||
const componentMeta: ComponentMeta<T> = {
|
||||
component: Component as any,
|
||||
@@ -24,8 +28,15 @@ export const makeStory = <
|
||||
...meta,
|
||||
};
|
||||
const Template: ComponentStory<T> = (args) => {
|
||||
let api: ApiService;
|
||||
if (useLiveApi) {
|
||||
api = useConnectedApiService();
|
||||
} else {
|
||||
api = useMockApiService([]);
|
||||
}
|
||||
|
||||
return (
|
||||
<Page>
|
||||
<Page api={api}>
|
||||
{BaseTemplate ? <BaseTemplate {...args} /> : <Component {...args} />}
|
||||
</Page>
|
||||
);
|
||||
|
||||
@@ -78,17 +78,14 @@ const Test: FC = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default {
|
||||
title: "Services/HA Service",
|
||||
component: Test,
|
||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
||||
args: {},
|
||||
} as ComponentMeta<typeof Test>;
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
export const AutomationCall: ComponentStory<typeof Test> = (props) => {
|
||||
return (
|
||||
<Page>
|
||||
<Test {...props} />
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: Test,
|
||||
meta: {
|
||||
title: "Services/HA Service",
|
||||
},
|
||||
});
|
||||
|
||||
export default componentMeta;
|
||||
export const AutomationCall = make({});
|
||||
@@ -1,8 +1,7 @@
|
||||
import React, { FC } from "react";
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import { useHADeviceRegistry } from "haService";
|
||||
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
const Test: FC<{ onRender: () => void }> = ({ onRender }) => {
|
||||
const conn = useHADeviceRegistry();
|
||||
@@ -35,17 +34,12 @@ const Test: FC<{ onRender: () => void }> = ({ onRender }) => {
|
||||
return <code>Loading...</code>;
|
||||
};
|
||||
|
||||
export default {
|
||||
title: "Services/Device Registry",
|
||||
component: Test,
|
||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
||||
args: {},
|
||||
} as ComponentMeta<typeof Test>;
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: Test,
|
||||
meta: {
|
||||
title: "Services/Device Registry",
|
||||
},
|
||||
});
|
||||
|
||||
export const Base: ComponentStory<typeof Test> = (props) => {
|
||||
return (
|
||||
<Page>
|
||||
<Test {...props} />
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
export default componentMeta;
|
||||
export const Basic = make({});
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { FC, useState } from "react";
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import { MockPage } from "components/Page";
|
||||
import { useHAEntities } from "haService/HAEntities";
|
||||
|
||||
const Test: FC<{ onRender: () => void }> = ({ onRender }) => {
|
||||
@@ -50,8 +50,8 @@ export default {
|
||||
|
||||
export const Base: ComponentStory<typeof Test> = (props) => {
|
||||
return (
|
||||
<Page>
|
||||
<MockPage>
|
||||
<Test {...props} />
|
||||
</Page>
|
||||
</MockPage>
|
||||
);
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { FC } from "react";
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import { MockPage } from "components/Page";
|
||||
import { useHAEntityRegistry } from "haService";
|
||||
|
||||
const Test: FC<{ onRender: () => void }> = ({ onRender }) => {
|
||||
@@ -43,8 +43,8 @@ export default {
|
||||
|
||||
export const Base: ComponentStory<typeof Test> = (props) => {
|
||||
return (
|
||||
<Page>
|
||||
<MockPage>
|
||||
<Test {...props} />
|
||||
</Page>
|
||||
</MockPage>
|
||||
);
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { FC, useEffect, useState } from "react";
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import { MockPage } from "components/Page";
|
||||
import { useHA } from "haService";
|
||||
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||
import { InputList } from "components/Inputs/InputList";
|
||||
@@ -89,8 +89,8 @@ export default {
|
||||
|
||||
export const ServiceCall: ComponentStory<typeof Test> = (props) => {
|
||||
return (
|
||||
<Page>
|
||||
<MockPage>
|
||||
<Test {...props} />
|
||||
</Page>
|
||||
</MockPage>
|
||||
);
|
||||
};
|
||||
@@ -59,6 +59,10 @@
|
||||
"SUN": "Sun",
|
||||
"MQTT": "MQTT",
|
||||
|
||||
"CONNECTED": "Connected",
|
||||
"FAILED": "Failed",
|
||||
"LOADING": "Loading",
|
||||
|
||||
"DAY_MON": "Monday",
|
||||
"DAY_TUE": "Tuesday",
|
||||
"DAY_WED": "Wednesday",
|
||||
@@ -70,6 +74,9 @@
|
||||
"WEEKDAY": "Weekday",
|
||||
"OPTION": "Option",
|
||||
|
||||
"THEME": "Theme",
|
||||
"LANGUAGE": "Language",
|
||||
|
||||
"SELECT_AUTOMATION": "Select automation",
|
||||
"TRIGGER_AUTOMATION": "Trigger automation",
|
||||
"DELETE_AUTOMATION": "Delete automation",
|
||||
|
||||
@@ -57,6 +57,10 @@
|
||||
"SUN": "Sol",
|
||||
"MQTT": "MQTT",
|
||||
|
||||
"CONNECTED": "Connecté",
|
||||
"FAILED": "Manquée",
|
||||
"LOADING": "Chargement",
|
||||
|
||||
"AND": "et",
|
||||
"NOT": "non",
|
||||
"NUMERIC_STATE": "État numérique",
|
||||
@@ -73,6 +77,9 @@
|
||||
"WEEKDAY": "Jour de la semaine",
|
||||
"OPTION": "Option",
|
||||
|
||||
"THEME": "Thème",
|
||||
"LANGUAGE": "Langue",
|
||||
|
||||
"SELECT_AUTOMATION": "Sélectionnez l'automatisation",
|
||||
"TRIGGER_AUTOMATION": "Déclencher l'automatisation",
|
||||
"DELETE_AUTOMATION": "Supprimer l'automatisation",
|
||||
|
||||
Reference in new issue
Block a user