moved back the components
This commit is contained in:
1 parent
24afb602cb
commit
0764feb432
18 files changed
+786
No files matched your search
@@ -0,0 +1,26 @@
|
|||||||
|
import { ButtonHTMLAttributes, FC } from "react";
|
||||||
|
import { createAppUseStyles } from "styles/theme";
|
||||||
|
import { useButtonStyles } from "./styles";
|
||||||
|
|
||||||
|
// const useButtonStyles = createAppUseStyles(theme => ({
|
||||||
|
// button: {
|
||||||
|
// backgroundColor: theme.secondary,
|
||||||
|
// color: theme.primaryAccent,
|
||||||
|
// borderColor: theme.primaryAccent,
|
||||||
|
// borderStyle: 'solid',
|
||||||
|
// borderWidth: 1,
|
||||||
|
// padding: '2.5%',
|
||||||
|
// marginLeft: '5%',
|
||||||
|
// marginRight: '5%',
|
||||||
|
// borderRadius: '5px',
|
||||||
|
// cursor: 'pointer',
|
||||||
|
// '&:hover': {
|
||||||
|
// backgroundColor: theme.primary,
|
||||||
|
// borderColor: theme.secondaryAccent,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }))
|
||||||
|
export const Button: FC<ButtonHTMLAttributes<HTMLButtonElement>> = props => {
|
||||||
|
const { classes } = useButtonStyles({});
|
||||||
|
return <button {...props} className={`${classes.input} ${props.className ?? ''}`} />
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import InputWrapper from "./InputWrapper";
|
||||||
|
|
||||||
|
export interface Props {
|
||||||
|
label: string;
|
||||||
|
value: boolean;
|
||||||
|
onChange: (v: boolean) => void;
|
||||||
|
}
|
||||||
|
export default function InputBoolean({
|
||||||
|
label,
|
||||||
|
value=false,
|
||||||
|
onChange,
|
||||||
|
}: Props) {
|
||||||
|
return <InputWrapper label={label} style={{
|
||||||
|
flexDirection: 'row',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
marginTop: '3%',
|
||||||
|
marginBottom: '3%'
|
||||||
|
}}>
|
||||||
|
<span className="checkbox" onClick={e => {
|
||||||
|
e.preventDefault()
|
||||||
|
onChange(!value)
|
||||||
|
}}>
|
||||||
|
{value ? '✔️' : ' '}
|
||||||
|
</span>
|
||||||
|
</InputWrapper>
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { usePageTheme } from "styles/page";
|
||||||
|
import InputList from "./InputList";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
title: 'Inputs/InputList',
|
||||||
|
component: InputList,
|
||||||
|
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||||
|
} as ComponentMeta<typeof InputList>;
|
||||||
|
|
||||||
|
|
||||||
|
const Template: ComponentStory<typeof InputList> = args => {
|
||||||
|
const { classes } = usePageTheme({});
|
||||||
|
const [value, setValue] = useState('')
|
||||||
|
return <div className={classes.page}>
|
||||||
|
<InputList {...args} current={value} onChange={setValue} />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
export const SimpleText = Template.bind({})
|
||||||
|
SimpleText.args = {
|
||||||
|
label: "Entity ID",
|
||||||
|
options: [
|
||||||
|
'Bob',
|
||||||
|
'Martin',
|
||||||
|
"Toots"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import InputWrapper from "./InputWrapper";
|
||||||
|
import { useInputListStyles } from "./styles";
|
||||||
|
|
||||||
|
|
||||||
|
export interface Props<T extends string> {
|
||||||
|
current: T;
|
||||||
|
options: readonly T[];
|
||||||
|
onChange: (n: T) => void;
|
||||||
|
id?: string;
|
||||||
|
className?: string;
|
||||||
|
label: string;
|
||||||
|
}
|
||||||
|
export default function InputList<T extends string>({
|
||||||
|
current, options, onChange, label,
|
||||||
|
...selattr
|
||||||
|
}: Props<T>) {
|
||||||
|
const {classes} = useInputListStyles({});
|
||||||
|
return <InputWrapper label={label} labelSize={'small'} noMargin>
|
||||||
|
<select
|
||||||
|
className={classes.input}
|
||||||
|
{...selattr} value={current}
|
||||||
|
onChange={e => {
|
||||||
|
e.preventDefault();
|
||||||
|
onChange(e.currentTarget.value);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{options.map((t, i) => <option id={String(i)} key={i}>{t}</option>)}
|
||||||
|
</select>
|
||||||
|
</InputWrapper>
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { usePageTheme } from "styles/page";
|
||||||
|
import InputNumber from "./InputNumber";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
title: 'Inputs/InputNumber',
|
||||||
|
component: InputNumber,
|
||||||
|
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||||
|
argTypes: {
|
||||||
|
label: {
|
||||||
|
defaultValue: 'Sample Title'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} as ComponentMeta<typeof InputNumber>;
|
||||||
|
|
||||||
|
|
||||||
|
export const NullStart: ComponentStory<typeof InputNumber> = args => {
|
||||||
|
const { classes } = usePageTheme({});
|
||||||
|
const [value, setValue] = useState<number | undefined>(undefined)
|
||||||
|
return <div className={classes.page}>
|
||||||
|
<InputNumber {...args} value={value} onChange={setValue} />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
export const SomeStuffAtStart: ComponentStory<typeof InputNumber> = args => {
|
||||||
|
const { classes } = usePageTheme({});
|
||||||
|
const [value, setValue] = useState<number | undefined>(10)
|
||||||
|
return <div className={classes.page}>
|
||||||
|
<InputNumber {...args} value={value} onChange={setValue} />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
// import { useState } from "react";
|
||||||
|
import InputWrapper from "./InputWrapper";
|
||||||
|
import { useInputNumberStyles } from "./styles";
|
||||||
|
|
||||||
|
export interface Props {
|
||||||
|
label: string;
|
||||||
|
value: number | undefined;
|
||||||
|
onChange: (v: number | undefined) => void;
|
||||||
|
}
|
||||||
|
export default function InputNumber({
|
||||||
|
label,
|
||||||
|
value=undefined,
|
||||||
|
onChange,
|
||||||
|
}: Props) {
|
||||||
|
const {classes} = useInputNumberStyles({});
|
||||||
|
return <InputWrapper label={label} labelSize={value !== undefined ? 'small' : 'normal'}>
|
||||||
|
<input
|
||||||
|
className={classes.input}
|
||||||
|
type="number"
|
||||||
|
value={value ?? ""}
|
||||||
|
onChange={e => {
|
||||||
|
e.preventDefault();
|
||||||
|
console.log(e.target.value)
|
||||||
|
onChange(Number(e.target.value))
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{value && <button className={classes.deleteIcon} onClick={() => onChange(undefined)}>X</button>}
|
||||||
|
</InputWrapper>
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { usePageTheme } from "styles/page";
|
||||||
|
import InputText from "./InputText";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
title: 'Inputs/InputText',
|
||||||
|
component: InputText,
|
||||||
|
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||||
|
} as ComponentMeta<typeof InputText>;
|
||||||
|
|
||||||
|
|
||||||
|
const Template: ComponentStory<typeof InputText> = args => {
|
||||||
|
const { classes } = usePageTheme({});
|
||||||
|
const [value, setValue] = useState('')
|
||||||
|
return <div className={classes.page}>
|
||||||
|
<InputText {...args} value={value} onChange={setValue} />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
export const SimpleText = Template.bind({})
|
||||||
|
SimpleText.args = {
|
||||||
|
label: "Entity ID",
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
import { PropsWithChildren, useState } from "react";
|
||||||
|
import { useToolTip } from "tooltip/context";
|
||||||
|
import InputWrapper from "./InputWrapper";
|
||||||
|
import { useInputTextStyles } from "./styles";
|
||||||
|
|
||||||
|
export interface Props {
|
||||||
|
textBoxFor?: string;
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
onChange: (v: string) => void;
|
||||||
|
onEnter?: () => void;
|
||||||
|
additionalTooltipFilters?: Record<string, string>;
|
||||||
|
}
|
||||||
|
export default function InputText({
|
||||||
|
label,
|
||||||
|
textBoxFor,
|
||||||
|
value = "",
|
||||||
|
onChange,
|
||||||
|
onEnter = () => { },
|
||||||
|
additionalTooltipFilters = {},
|
||||||
|
children,
|
||||||
|
}: PropsWithChildren<Props>) {
|
||||||
|
const { classes } = useInputTextStyles({});
|
||||||
|
const tooltip = useToolTip();
|
||||||
|
const [isFocused, setIsFocused] = useState(false)
|
||||||
|
return <InputWrapper label={label} labelSize={(value === '') && !isFocused ? 'normal' : 'small'}>
|
||||||
|
<input
|
||||||
|
className={classes.input}
|
||||||
|
value={value}
|
||||||
|
onKeyDown={e => {
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
onEnter();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onChange={e => {
|
||||||
|
e.preventDefault();
|
||||||
|
onChange(e.target.value)
|
||||||
|
}}
|
||||||
|
onBlur={e => {
|
||||||
|
setIsFocused(false)
|
||||||
|
}}
|
||||||
|
onFocus={e => {
|
||||||
|
setIsFocused(true)
|
||||||
|
if (textBoxFor) {
|
||||||
|
tooltip.setFocus(
|
||||||
|
e.target.getBoundingClientRect(),
|
||||||
|
{
|
||||||
|
searchObject: textBoxFor,
|
||||||
|
searchText: value,
|
||||||
|
filterObjects: additionalTooltipFilters,
|
||||||
|
},
|
||||||
|
onChange
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{children}
|
||||||
|
</InputWrapper>
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { usePageTheme } from "styles/page";
|
||||||
|
import InputTextArea from "./InputTextArea";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
title: 'Inputs/InputTextArea',
|
||||||
|
component: InputTextArea,
|
||||||
|
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||||
|
} as ComponentMeta<typeof InputTextArea>;
|
||||||
|
|
||||||
|
|
||||||
|
const Template: ComponentStory<typeof InputTextArea> = args => {
|
||||||
|
const { classes } = usePageTheme({});
|
||||||
|
const [value, setValue] = useState('')
|
||||||
|
return <div className={classes.page}>
|
||||||
|
<InputTextArea {...args} value={value} onChange={setValue} />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
export const SimpleText = Template.bind({})
|
||||||
|
SimpleText.args = {
|
||||||
|
label: "Entity ID",
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { useToolTip } from "tooltip/context";
|
||||||
|
import InputWrapper from "./InputWrapper";
|
||||||
|
import { useInputTextAreaStyles } from "./styles";
|
||||||
|
|
||||||
|
export interface Props {
|
||||||
|
textBoxFor?: string;
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
onChange: (v: string) => void;
|
||||||
|
additionalTooltipFilters?: Record<string, string>;
|
||||||
|
resizable?: boolean;
|
||||||
|
}
|
||||||
|
export default function InputTextArea({
|
||||||
|
label,
|
||||||
|
textBoxFor,
|
||||||
|
value = "",
|
||||||
|
onChange,
|
||||||
|
additionalTooltipFilters = {},
|
||||||
|
resizable = false,
|
||||||
|
}: Props) {
|
||||||
|
const { classes } = useInputTextAreaStyles({ resizable });
|
||||||
|
const tooltip = useToolTip();
|
||||||
|
const [isFocused, setIsFocused] = useState(false)
|
||||||
|
return <InputWrapper label={label} labelSize={(value === '') && !isFocused ? 'normal' : 'small'}>
|
||||||
|
<textarea
|
||||||
|
className={classes.input}
|
||||||
|
value={value}
|
||||||
|
onChange={e => {
|
||||||
|
e.preventDefault();
|
||||||
|
onChange(e.target.value)
|
||||||
|
}}
|
||||||
|
onBlur={e => {
|
||||||
|
setIsFocused(false)
|
||||||
|
}}
|
||||||
|
onFocus={e => {
|
||||||
|
setIsFocused(true)
|
||||||
|
if (textBoxFor) {
|
||||||
|
tooltip.setFocus(
|
||||||
|
e.target.getBoundingClientRect(),
|
||||||
|
{
|
||||||
|
searchObject: textBoxFor,
|
||||||
|
searchText: value,
|
||||||
|
filterObjects: additionalTooltipFilters,
|
||||||
|
},
|
||||||
|
onChange
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</InputWrapper>
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { usePageTheme } from "styles/page";
|
||||||
|
import InputTextBubble, { InputEntity } from "./InputTextBubble";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
title: 'Inputs/InputTextBubble',
|
||||||
|
component: InputTextBubble,
|
||||||
|
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||||
|
argTypes: {
|
||||||
|
label: {
|
||||||
|
defaultValue: 'Sample Title'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} as ComponentMeta<typeof InputTextBubble>;
|
||||||
|
|
||||||
|
|
||||||
|
export const ArrayText: ComponentStory<typeof InputTextBubble> = args => {
|
||||||
|
const { classes } = usePageTheme({});
|
||||||
|
const [value, setValue] = useState<string | string[]>(['wow', 'lots of bubbles', 'itchen', 'bathroom'])
|
||||||
|
return <div className={classes.page}>
|
||||||
|
<div style={{ maxWidth: '200px', overflow: 'hidden' }}>
|
||||||
|
<InputTextBubble {...args} value={value} onChange={setValue} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
export const JustText: ComponentStory<typeof InputTextBubble> = args => {
|
||||||
|
const { classes } = usePageTheme({});
|
||||||
|
const [value, setValue] = useState<string | string[]>('hello')
|
||||||
|
return <div className={classes.page}>
|
||||||
|
<InputTextBubble {...args} value={value} onChange={setValue} />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const EntityId: ComponentStory<typeof InputTextBubble> = args => {
|
||||||
|
const { classes } = usePageTheme({});
|
||||||
|
const [value, setValue] = useState<string | string[]>(['sensor.bathroom'])
|
||||||
|
return <div className={classes.page}>
|
||||||
|
<InputEntity value={value} onChange={setValue} />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
import { FC, useState } from "react";
|
||||||
|
import { useToolTip } from "tooltip/context";
|
||||||
|
import InputText from "./InputText";
|
||||||
|
import InputWrapper from "./InputWrapper";
|
||||||
|
import { useInputBubblesStyles, useInputTextStyles } from "./styles";
|
||||||
|
|
||||||
|
export interface Props {
|
||||||
|
label: string;
|
||||||
|
textBoxFor?: string;
|
||||||
|
value: string | string[];
|
||||||
|
onChange: (v: string[]) => void;
|
||||||
|
additionalTooltipFilters?: Record<string, string>;
|
||||||
|
}
|
||||||
|
export default function InputTextBubble({
|
||||||
|
value = "",
|
||||||
|
label,
|
||||||
|
textBoxFor,
|
||||||
|
onChange,
|
||||||
|
additionalTooltipFilters = {},
|
||||||
|
}: Props) {
|
||||||
|
const { classes } = useInputBubblesStyles({});
|
||||||
|
let selected: string[];
|
||||||
|
if (typeof value === 'string') {
|
||||||
|
selected = [value]
|
||||||
|
} else {
|
||||||
|
selected = value
|
||||||
|
}
|
||||||
|
const [text, setText] = useState('');
|
||||||
|
const addNew = () => {
|
||||||
|
if (text) {
|
||||||
|
onChange([text].concat(selected))
|
||||||
|
setText("")
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return <InputText
|
||||||
|
label={label}
|
||||||
|
value={text}
|
||||||
|
textBoxFor={textBoxFor}
|
||||||
|
onChange={t => setText(t)}
|
||||||
|
onEnter={() => addNew()}
|
||||||
|
additionalTooltipFilters={additionalTooltipFilters}
|
||||||
|
>
|
||||||
|
<div className={classes.bubbles}>
|
||||||
|
{selected.map((s, i) => <div className={classes.bubble} onClick={() => onChange([
|
||||||
|
...selected.slice(0, i),
|
||||||
|
...selected.slice(i + 1),
|
||||||
|
])}>
|
||||||
|
{s}
|
||||||
|
<span className={classes.deleteIcon}>X</span>
|
||||||
|
</div>)}
|
||||||
|
</div>
|
||||||
|
<button className={classes.addBtn} onClick={() => addNew()}>+</button>
|
||||||
|
</InputText>
|
||||||
|
}
|
||||||
|
|
||||||
|
export const InputEntity: FC<{
|
||||||
|
value: string | string[];
|
||||||
|
onChange: (v: string[]) => void;
|
||||||
|
}> = ({
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
}) => <InputTextBubble
|
||||||
|
value={value}
|
||||||
|
onChange={onChange}
|
||||||
|
label="Entity ID"
|
||||||
|
textBoxFor="entity_id"
|
||||||
|
/>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { PropsWithChildren } from "react";
|
||||||
|
import { useInputWrapperStyles } from "./styles";
|
||||||
|
|
||||||
|
|
||||||
|
export interface Props {
|
||||||
|
label: string;
|
||||||
|
labelSize?: 'normal' | 'small';
|
||||||
|
noMargin?: boolean;
|
||||||
|
}
|
||||||
|
export default function InputWrapper({label, children, labelSize='normal', noMargin=false}: PropsWithChildren<Props>) {
|
||||||
|
const {classes} = useInputWrapperStyles({labelSize, noMargin})
|
||||||
|
return <div className={classes.wrapper}>
|
||||||
|
<label className={classes.label}>{label}</label>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { usePageTheme } from "styles/page";
|
||||||
|
import InputYaml from "./InputYaml";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
title: 'Inputs/InputYaml',
|
||||||
|
component: InputYaml,
|
||||||
|
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||||
|
} as ComponentMeta<typeof InputYaml>;
|
||||||
|
|
||||||
|
|
||||||
|
const Template: ComponentStory<typeof InputYaml> = args => {
|
||||||
|
const { classes } = usePageTheme({});
|
||||||
|
const [value, setValue] = useState({
|
||||||
|
"test": "data"
|
||||||
|
})
|
||||||
|
return <div className={classes.page}>
|
||||||
|
<InputYaml {...args} value={value} onChange={setValue} />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
export const SimpleText = Template.bind({})
|
||||||
|
SimpleText.args = {
|
||||||
|
label: "Template",
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import InputWrapper from "./InputWrapper";
|
||||||
|
import * as yaml from "js-yaml";
|
||||||
|
import { useEffect, useRef, useState } from "react";
|
||||||
|
import InputTextArea from "./InputTextArea";
|
||||||
|
|
||||||
|
export interface Props<T extends {}> {
|
||||||
|
label: string;
|
||||||
|
value: T;
|
||||||
|
onChange: (v: T) => void;
|
||||||
|
resizable?: boolean;
|
||||||
|
}
|
||||||
|
export default function InputYaml<T>({
|
||||||
|
label,
|
||||||
|
value={} as any,
|
||||||
|
onChange,
|
||||||
|
resizable,
|
||||||
|
}: Props<T>) {
|
||||||
|
const [text, setText] = useState("");
|
||||||
|
useEffect(() => {
|
||||||
|
setText(yaml.dump(value));
|
||||||
|
}, [value]);
|
||||||
|
const delayId = useRef<null | number>(null);
|
||||||
|
const delayedUpdate = (update: string) => {
|
||||||
|
setText(update)
|
||||||
|
if (delayId.current) {
|
||||||
|
window.clearTimeout(delayId.current);
|
||||||
|
delayId.current = null;
|
||||||
|
}
|
||||||
|
delayId.current = window.setTimeout(() => {
|
||||||
|
onChange(yaml.load(update) as any)
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
return <InputTextArea
|
||||||
|
label={label}
|
||||||
|
value={text}
|
||||||
|
onChange={delayedUpdate}
|
||||||
|
resizable={resizable}
|
||||||
|
/>
|
||||||
|
}
|
||||||
@@ -0,0 +1,183 @@
|
|||||||
|
import { createAppUseStyles, AppTheme } from "styles/theme";
|
||||||
|
import Color from 'chroma-js';
|
||||||
|
|
||||||
|
const commonInputStyle = (theme: AppTheme) => ({
|
||||||
|
input: {
|
||||||
|
backgroundColor: theme.secondary,
|
||||||
|
color: theme.secondaryAccent,
|
||||||
|
borderColor: theme.primaryAccent,
|
||||||
|
borderStyle: 'solid',
|
||||||
|
borderWidth: 1,
|
||||||
|
borderRadius: 5,
|
||||||
|
padding: 15,
|
||||||
|
marginLeft: 5,
|
||||||
|
marginRight: 5,
|
||||||
|
fontSize: 16,
|
||||||
|
|
||||||
|
"&:hover": {
|
||||||
|
backgroundColor: theme.primary,
|
||||||
|
borderColor: theme.secondaryAccent,
|
||||||
|
},
|
||||||
|
"&:disabled": {
|
||||||
|
backgroundColor: '#403f3f',
|
||||||
|
borderColor: '#403f3f',
|
||||||
|
color: '#403f3faa',
|
||||||
|
cursor: 'not-allowed',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export const useButtonStyles = createAppUseStyles<{}>(theme => ({
|
||||||
|
...commonInputStyle(theme),
|
||||||
|
}));
|
||||||
|
|
||||||
|
export const useInputWrapperStyles = createAppUseStyles<{
|
||||||
|
labelSize: 'normal' | 'small',
|
||||||
|
noMargin: boolean,
|
||||||
|
}>(theme => {
|
||||||
|
return {
|
||||||
|
wrapper: ({ noMargin }) => ({
|
||||||
|
position: 'relative',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
marginTop: noMargin ? 0 : 10,
|
||||||
|
marginBottom: noMargin ? 0 : '0.25em',
|
||||||
|
}),
|
||||||
|
label: ({ labelSize }) => ({
|
||||||
|
fontSize: labelSize === 'normal' ? 16 : 10,
|
||||||
|
position: 'absolute',
|
||||||
|
left: labelSize === 'normal' ? '0.75em' : '1em',
|
||||||
|
top: labelSize === 'normal' ? '0.5em' : '0.25em',
|
||||||
|
fontWeight: 'bold',
|
||||||
|
transition: 'all 200ms',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export const useInputTextStyles = createAppUseStyles<{}>(theme => ({
|
||||||
|
...commonInputStyle(theme),
|
||||||
|
}));
|
||||||
|
|
||||||
|
export const useInputNumberStyles = createAppUseStyles<{}>(theme => {
|
||||||
|
const styles = commonInputStyle(theme);
|
||||||
|
return {
|
||||||
|
input: {
|
||||||
|
...styles.input,
|
||||||
|
textAlign: 'center'
|
||||||
|
},
|
||||||
|
deleteIcon: {
|
||||||
|
position: "absolute",
|
||||||
|
left: 30,
|
||||||
|
top: 17,
|
||||||
|
color: theme.secondaryAccent,
|
||||||
|
backgroundColor: theme.secondary,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderStyle: 'solid',
|
||||||
|
borderColor: theme.secondaryAccent,
|
||||||
|
borderRadius: 5,
|
||||||
|
cursor: 'pointer',
|
||||||
|
padding: "1px 5px",
|
||||||
|
"&:hover": {
|
||||||
|
backgroundColor: theme.primary,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export const useInputListStyles = createAppUseStyles<{}>(theme => {
|
||||||
|
const styles = commonInputStyle(theme);
|
||||||
|
return {
|
||||||
|
input: {
|
||||||
|
...styles.input,
|
||||||
|
cursor: 'pointer'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export const useInputTextAreaStyles = createAppUseStyles<{ resizable: boolean }>(theme => {
|
||||||
|
const styles = commonInputStyle(theme);
|
||||||
|
return {
|
||||||
|
input: ({ resizable }) => ({
|
||||||
|
...styles.input,
|
||||||
|
resize: resizable ? 'both' : 'none'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export const useInputViewEditStyles = createAppUseStyles<{
|
||||||
|
isEditing: boolean;
|
||||||
|
}>(theme => ({
|
||||||
|
...commonInputStyle(theme),
|
||||||
|
inputView: {
|
||||||
|
|
||||||
|
},
|
||||||
|
checkmark: {
|
||||||
|
|
||||||
|
},
|
||||||
|
pencil: {
|
||||||
|
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
export const useInputBubblesStyles = createAppUseStyles<{}>(theme => ({
|
||||||
|
bubbles: {
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'row',
|
||||||
|
maxHeight: 50,
|
||||||
|
maxWidth: '100%',
|
||||||
|
overflowX: 'auto',
|
||||||
|
overflowY: 'hidden',
|
||||||
|
scrollbarWidth: 'thin',
|
||||||
|
},
|
||||||
|
bubble: {
|
||||||
|
position: 'relative',
|
||||||
|
border: `1px solid ${theme.primaryAccent}`,
|
||||||
|
borderRadius: 10,
|
||||||
|
backgroundColor: Color(theme.primary).set('rgb.g', 150).alpha(0.35).hex(),
|
||||||
|
color: Color(theme.primary).brighten(5).hex(),
|
||||||
|
fontSize: 16,
|
||||||
|
|
||||||
|
marginLeft: 1,
|
||||||
|
padding: 5,
|
||||||
|
width: 'fit-content',
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
|
||||||
|
cursor: 'pointer',
|
||||||
|
"&:hover": {
|
||||||
|
backgroundColor: Color(theme.primary).set('rgb.r', 150).alpha(0.35).hex(),
|
||||||
|
color: Color(theme.primary).brighten(5).alpha(0.35).hex(),
|
||||||
|
},
|
||||||
|
|
||||||
|
"&:hover $deleteIcon": {
|
||||||
|
display: 'block',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
deleteIcon: {
|
||||||
|
display: 'none',
|
||||||
|
position: "absolute",
|
||||||
|
left: "48%",
|
||||||
|
top: 5,
|
||||||
|
color: "white",
|
||||||
|
},
|
||||||
|
addBtn: {
|
||||||
|
position: "absolute",
|
||||||
|
top: 10,
|
||||||
|
right: 10,
|
||||||
|
fontSize: 20,
|
||||||
|
cursor: 'pointer',
|
||||||
|
borderStyle: 'solid',
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: theme.secondary,
|
||||||
|
backgroundColor: theme.secondary,
|
||||||
|
color: theme.secondaryAccent,
|
||||||
|
padding: "3px 7px",
|
||||||
|
transition: "200ms ease-out",
|
||||||
|
"&:hover": {
|
||||||
|
borderRadius: 100,
|
||||||
|
backgroundColor: Color(theme.primary).set('rgb.g', 150).alpha(0.35).hex(),
|
||||||
|
borderColor: theme.secondaryAccent,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import { createContext, useContext } from "react"
|
||||||
|
|
||||||
|
export interface TooltipSearchOption {
|
||||||
|
searchObject: string;
|
||||||
|
searchText: string;
|
||||||
|
filterObjects: Record<string, string>;
|
||||||
|
}
|
||||||
|
export interface TooltipState {
|
||||||
|
domrect?: DOMRect;
|
||||||
|
searchOptions?: TooltipSearchOption;
|
||||||
|
onSelected?: (s: string) => void;
|
||||||
|
searchResults: string[];
|
||||||
|
updateState: (s: TooltipState) => void;
|
||||||
|
}
|
||||||
|
export const TooltipContext = createContext<TooltipState>({
|
||||||
|
updateState(s) {},
|
||||||
|
searchResults: [],
|
||||||
|
})
|
||||||
|
|
||||||
|
export const useToolTip = () => {
|
||||||
|
const state = useContext(TooltipContext);
|
||||||
|
|
||||||
|
return {
|
||||||
|
setFocus(
|
||||||
|
domrect: DOMRect,
|
||||||
|
searchOptions: TooltipSearchOption,
|
||||||
|
onSelected: (s: string) => void
|
||||||
|
){
|
||||||
|
state.updateState({
|
||||||
|
...state,
|
||||||
|
domrect, searchOptions, onSelected
|
||||||
|
})
|
||||||
|
},
|
||||||
|
setSearchResults(searchResults: string[]){
|
||||||
|
state.updateState({
|
||||||
|
...state,
|
||||||
|
searchResults
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import { TooltipState } from "./context";
|
||||||
|
|
||||||
|
export default function Tooltip({
|
||||||
|
domrect,
|
||||||
|
searchOptions,
|
||||||
|
searchResults=[],
|
||||||
|
onSelected=()=>{},
|
||||||
|
updateState,
|
||||||
|
}: TooltipState) {
|
||||||
|
|
||||||
|
// state alias
|
||||||
|
const rootClassName = !!domrect && !!searchOptions ? "tooltip show" : "tooltip hide";
|
||||||
|
let tooltipStyle = {};
|
||||||
|
if (domrect) {
|
||||||
|
const {left=0, top=0, height=0, width=0} = domrect;
|
||||||
|
tooltipStyle = {
|
||||||
|
top: `${top + height}px`,
|
||||||
|
left: `${left}px`,
|
||||||
|
width: `${width}px`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const unFocus = () => updateState({
|
||||||
|
updateState,
|
||||||
|
onSelected,
|
||||||
|
searchResults: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
return <div className={rootClassName}>
|
||||||
|
<div className="tooltip-bg" onClick={() => unFocus()}></div>
|
||||||
|
<ul style={tooltipStyle}>
|
||||||
|
{searchResults.map((r, i) => <li key={i} onClick={() => {
|
||||||
|
onSelected(r);
|
||||||
|
unFocus();
|
||||||
|
}}>
|
||||||
|
{r}
|
||||||
|
</li>)}
|
||||||
|
{searchResults.length === 0 ? <li onClick={() => unFocus()}>No Options...</li> : ""}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
Reference in new issue
Block a user