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