fix build

This commit is contained in:
Sacha Weatherstone
2022-08-09 09:13:27 +10:00
parent ed9ee28745
commit 1f2637eb12
10 changed files with 189 additions and 82 deletions
+14 -17
View File
@@ -10,12 +10,12 @@ import {
Tab,
Tablist,
} from "evergreen-ui";
import type { IconType } from "react-icons";
import { FiBluetooth, FiTerminal, FiWifi } from "react-icons/fi";
import { BLE } from "../connect/BLE.js";
import { HTTP } from "../connect/HTTP.js";
import { Serial } from "../connect/Serial.js";
import type { TabType } from "../layout/page/TabbedContent.js";
export interface NewDeviceProps {
open: boolean;
@@ -28,35 +28,32 @@ export interface CloseProps {
export type connType = "http" | "ble" | "serial";
export interface Tab {
name: connType;
icon: IconType;
displayName: string;
export interface ConnTab extends Omit<TabType, "element"> {
connType: connType;
element: ({ close }: CloseProps) => JSX.Element;
disabled?: boolean;
}
export const NewDevice = ({ open, onClose }: NewDeviceProps) => {
const [selectedConnType, setSelectedConnType] = useState<connType>("ble");
const tabs: Tab[] = [
const tabs: ConnTab[] = [
{
name: "ble",
connType: "ble",
icon: FiBluetooth,
displayName: "BLE",
name: "BLE",
element: BLE,
disabled: !navigator.bluetooth,
},
{
name: "http",
connType: "http",
icon: FiWifi,
displayName: "HTTP",
name: "HTTP",
element: HTTP,
},
{
name: "serial",
connType: "serial",
icon: FiTerminal,
displayName: "Serial",
name: "Serial",
element: Serial,
disabled: !navigator.serial,
},
@@ -85,13 +82,13 @@ export const NewDevice = ({ open, onClose }: NewDeviceProps) => {
<Tab
key={index}
gap={5}
isSelected={selectedConnType === TabData.name}
onSelect={() => setSelectedConnType(TabData.name)}
isSelected={selectedConnType === TabData.connType}
onSelect={() => setSelectedConnType(TabData.connType)}
disabled={TabData.disabled}
>
<>
<TabData.icon />
{TabData.displayName}
{TabData.name}
</>
</Tab>
))}
@@ -106,7 +103,7 @@ export const NewDevice = ({ open, onClose }: NewDeviceProps) => {
backgroundColor="white"
elevation={1}
flexGrow={1}
display={selectedConnType === TabData.name ? "block" : "none"}
display={selectedConnType === TabData.connType ? "block" : "none"}
>
{!TabData.disabled && <TabData.element close={onClose} />}
</Pane>
@@ -0,0 +1,78 @@
import type React from "react";
import { useState } from "react";
import {
Heading,
IconComponent,
majorScale,
Pane,
Paragraph,
Tab,
Tablist,
} from "evergreen-ui";
import type { IconType } from "react-icons";
export interface TabType {
name: string;
icon: IconComponent | IconType;
element: () => JSX.Element;
disabled?: boolean;
}
export interface SlideSheetTabbedContentProps {
heading: string;
description: string;
tabs: TabType[];
}
export const SlideSheetTabbedContent = ({
heading,
description,
tabs,
}: SlideSheetTabbedContentProps): JSX.Element => {
const [selectedTab, setSelectedTab] = useState(0);
return (
<>
<Pane zIndex={1} flexShrink={0} elevation={1} backgroundColor="white">
<Pane padding={16} borderBottom="muted">
<Heading size={600}>{heading}</Heading>
<Paragraph size={400} color="muted">
{description}
</Paragraph>
</Pane>
<Pane display="flex" padding={8}>
<Tablist>
{tabs.map((Entry, index) => (
<Tab
key={index}
userSelect="none"
disabled={Entry.disabled}
gap={5}
onSelect={() => setSelectedTab(index)}
isSelected={selectedTab === index}
>
<Entry.icon />
{Entry.name}
</Tab>
))}
</Tablist>
</Pane>
</Pane>
<Pane display="flex" overflowY="scroll" background="tint1" padding={16}>
{tabs.map((Entry, index) => (
<Pane
key={index}
borderRadius={majorScale(1)}
backgroundColor="white"
elevation={1}
flexGrow={1}
display={selectedTab === index ? "block" : "none"}
>
{!Entry.disabled && <Entry.element />}
</Pane>
))}
</Pane>
</>
);
};
+16 -16
View File
@@ -1,28 +1,27 @@
import type React from "react";
import { useState } from "react";
import { IconComponent, majorScale, Pane, Tab, Tablist } from "evergreen-ui";
import type { IconType } from "react-icons";
export interface Tab {
key: number;
export interface TabType {
name: string;
icon: IconComponent;
icon: IconComponent | IconType;
element: () => JSX.Element;
disabled?: boolean;
}
export interface TabbedContentProps {
active: number;
setActive: (index: number) => void;
tabs: Tab[];
tabs: TabType[];
actions?: (() => JSX.Element)[];
}
export const TabbedContent = ({
active,
setActive,
tabs,
actions,
}: TabbedContentProps): JSX.Element => {
const [selectedTab, setSelectedTab] = useState(0);
return (
<Pane
margin={majorScale(3)}
@@ -38,13 +37,14 @@ export const TabbedContent = ({
<Pane borderBottom="muted" paddingBottom={majorScale(2)}>
<Pane display="flex">
<Tablist>
{tabs.map((Entry) => (
{tabs.map((Entry, index) => (
<Tab
key={Entry.key}
key={index}
userSelect="none"
disabled={Entry.disabled}
gap={5}
onSelect={() => setActive(Entry.key)}
isSelected={active === Entry.key}
onSelect={() => setSelectedTab(index)}
isSelected={selectedTab === index}
>
<Entry.icon />
{Entry.name}
@@ -59,14 +59,14 @@ export const TabbedContent = ({
</Pane>
</Pane>
</Pane>
{tabs.map((Entry) => (
{tabs.map((Entry, index) => (
<Pane
key={Entry.key}
display={active === Entry.key ? "flex" : "none"}
key={index}
display={selectedTab === index ? "flex" : "none"}
flexDirection="column"
flexGrow={1}
>
<Entry.element />
{!Entry.disabled && <Entry.element />}
</Pane>
))}
</Pane>