plane/apps/app/components/ui/multi-input.tsx
Aaryan Khandelwal 3c2f5d12ed
feat: themes (#902)
* chore: add next theme and initial setup

* chore: add dark mode colors to layouts

* chore: user general setting page theming

* chore: dashboard theming

* chore: project page theming

* chore: workspace setting page theming

* chore: my issue page theming

* chore: cmdk theming

* chore: change hardcode bg and text color to theme

* chore: change color name according to the design

* style: fix card in the dashboard

* style: fix merge conflict design issues

* style: add light high contrast and dark high contrast

* style: fix cmd k menu color and selection

* feat: change theme from cmdk menu

* chore: add multiple theme field to custom theme

* chore: removed custom theming

* fix: build error

---------

Co-authored-by: Saheb Giri <iamsahebgiri@gmail.com>
2023-04-20 13:41:24 +05:30

75 lines
2.3 KiB
TypeScript

// react
import React from "react";
const isEmailValid = (email: string) =>
String(email)
.toLowerCase()
.match(
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
);
export const MultiInput = ({ label, name, placeholder, setValue, watch }: any) => {
const handleKeyDown = (e: any) => {
if (e.key !== "Enter") return;
const value = e.target.value;
if (!value.trim()) return;
if (isEmailValid(value) && !watch(name)?.find((item: any) => item.email === value)) {
setValue(name, [...(watch(name) || []), { email: value }]);
e.target.value = "";
}
};
const handleBlur = (e: React.FocusEvent<HTMLInputElement, Element>) => {
const value = e.target.value;
if (!value.trim()) return;
if (isEmailValid(value) && !watch(name)?.find((item: any) => item.email === value)) {
setValue(name, [...(watch(name) || []), { email: value }]);
e.target.value = "";
} else {
e.target.value = "";
}
};
const handleChange = (e: any) => {
const value = e.target.value.trim();
if (!value) return;
if (value.includes(",")) {
const tags = value.split(",");
tags.forEach((tag: string) => {
if (isEmailValid(tag) && !watch(name)?.find((item: any) => item.email === tag)) {
setValue(name, [...(watch(name) || []), { email: tag }]);
}
});
e.target.value = "";
}
};
const removeTag = (index: Number) => {
setValue(
name,
watch(name).filter((_: string, i: any) => i !== index)
);
};
return (
<>
{label && <label className="mb-2 text-brand-secondary">{label}</label>}
<div className="rounded-md border border-brand-base p-2">
{watch(name)?.map((tag: any, index: number) => (
<button type="button" className="m-1.5 rounded-full bg-slate-300 p-1.5" key={index}>
{tag.email} <span onClick={() => removeTag(index)}>&times;</span>
</button>
))}
<input
onKeyDown={handleKeyDown}
onBlur={handleBlur}
onChange={handleChange}
type="text"
placeholder={placeholder}
className="block w-full rounded-md bg-transparent p-1.5 text-sm focus:outline-none"
/>
</div>
</>
);
};