Implementing @layer components for CSS (#594)

This pull request introduces a new feature that enhances our CSS
architecture by adding support for @layer components. With this feature,
we can now organize and manage our CSS more efficiently, making it
easier to work with and maintain.
This commit is contained in:
anovazzi1 2023-07-03 17:59:34 -03:00 • committed by GitHub
commit d91451cbfa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 87 additions and 113 deletions

View file

@ -3,12 +3,7 @@ import { PopUpContext } from "../../contexts/popUpContext";
import CodeAreaModal from "../../modals/codeAreaModal"; import CodeAreaModal from "../../modals/codeAreaModal";
import TextAreaModal from "../../modals/textAreaModal"; import TextAreaModal from "../../modals/textAreaModal";
import { TextAreaComponentType } from "../../types/components"; import { TextAreaComponentType } from "../../types/components";
import {
INPUT_DIALOG,
INPUT_DISABLE,
INPUT_EDIT_NODE,
INPUT_STYLE,
} from "../../constants";
import { ExternalLink } from "lucide-react"; import { ExternalLink } from "lucide-react";
export default function CodeAreaComponent({ export default function CodeAreaComponent({
@ -53,8 +48,8 @@ export default function CodeAreaComponent({
}} }}
className={ className={
editNode editNode
? INPUT_EDIT_NODE + INPUT_DIALOG ? "input-edit-node input-dialog"
: INPUT_STYLE + INPUT_DIALOG + (disabled ? INPUT_DISABLE : "") : "input-primary input-dialog " + (disabled ? "input-disable" : "")
} }
> >
{myValue !== "" ? myValue : "Type something..."} {myValue !== "" ? myValue : "Type something..."}

View file

@ -2,7 +2,6 @@ import { Listbox, Transition } from "@headlessui/react";
import { Fragment, useContext, useEffect, useState } from "react"; import { Fragment, useContext, useEffect, useState } from "react";
import { DropDownComponentType } from "../../types/components"; import { DropDownComponentType } from "../../types/components";
import { classNames } from "../../utils"; import { classNames } from "../../utils";
import { INPUT_EDIT_NODE, INPUT_STYLE } from "../../constants";
import { ChevronsUpDown, Check } from "lucide-react"; import { ChevronsUpDown, Check } from "lucide-react";
import { PopUpContext } from "../../contexts/popUpContext"; import { PopUpContext } from "../../contexts/popUpContext";
import { TabsContext } from "../../contexts/tabsContext"; import { TabsContext } from "../../contexts/tabsContext";
@ -40,8 +39,8 @@ export default function Dropdown({
<Listbox.Button <Listbox.Button
className={ className={
editNode editNode
? "border-1 relative pr-8" + INPUT_EDIT_NODE ? "border-1 relative pr-8 input-edit-node"
: "py-2 pl-3 pr-10 text-left" + INPUT_STYLE : "py-2 pl-3 pr-10 text-left input-primary"
} }
> >
<span className="block w-full truncate bg-background"> <span className="block w-full truncate bg-background">

View file

@ -1,7 +1,6 @@
import { useContext, useEffect, useState } from "react"; import { useContext, useEffect, useState } from "react";
import { FloatComponentType } from "../../types/components"; import { FloatComponentType } from "../../types/components";
import { TabsContext } from "../../contexts/tabsContext"; import { TabsContext } from "../../contexts/tabsContext";
import { INPUT_DISABLE, INPUT_EDIT_NODE, INPUT_STYLE } from "../../constants";
import { PopUpContext } from "../../contexts/popUpContext"; import { PopUpContext } from "../../contexts/popUpContext";
export default function FloatComponent({ export default function FloatComponent({
@ -58,8 +57,8 @@ export default function FloatComponent({
value={myValue} value={myValue}
className={ className={
editNode editNode
? INPUT_EDIT_NODE ? "input-edit-node"
: INPUT_STYLE + (disabled ? INPUT_DISABLE : "") : "input-primary" + (disabled ? " input-disable " : "")
} }
placeholder={ placeholder={
editNode ? "Number 0 to 1" : "Type a number from zero to one" editNode ? "Number 0 to 1" : "Type a number from zero to one"

View file

@ -3,7 +3,6 @@ import { InputComponentType } from "../../types/components";
import { classNames } from "../../utils"; import { classNames } from "../../utils";
import { TabsContext } from "../../contexts/tabsContext"; import { TabsContext } from "../../contexts/tabsContext";
import { PopUpContext } from "../../contexts/popUpContext"; import { PopUpContext } from "../../contexts/popUpContext";
import { INPUT_DISABLE, INPUT_EDIT_NODE, INPUT_STYLE } from "../../constants";
export default function InputComponent({ export default function InputComponent({
value, value,
@ -47,9 +46,9 @@ export default function InputComponent({
}} }}
className={classNames( className={classNames(
" pr-12 ", " pr-12 ",
disabled ? INPUT_DISABLE : "", disabled ? " input-disable " : "",
password && !pwdVisible && myValue !== "" ? "password" : "", password && !pwdVisible && myValue !== "" ? "password" : "",
editNode ? INPUT_EDIT_NODE : INPUT_STYLE, editNode ? " input-edit-node " : " input-primary ",
password && editNode ? "pr-8" : "pr-3" password && editNode ? "pr-8" : "pr-3"
)} )}
placeholder={password && editNode ? "Key" : "Type something..."} placeholder={password && editNode ? "Key" : "Type something..."}

View file

@ -2,7 +2,6 @@ import { useContext, useEffect, useState } from "react";
import { alertContext } from "../../contexts/alertContext"; import { alertContext } from "../../contexts/alertContext";
import { FileComponentType } from "../../types/components"; import { FileComponentType } from "../../types/components";
import { TabsContext } from "../../contexts/tabsContext"; import { TabsContext } from "../../contexts/tabsContext";
import { INPUT_DISABLE, INPUT_EDIT_NODE, INPUT_STYLE } from "../../constants";
import { FileSearch2 } from "lucide-react"; import { FileSearch2 } from "lucide-react";
import { uploadFile } from "../../controllers/API"; import { uploadFile } from "../../controllers/API";
@ -103,8 +102,8 @@ export default function InputFileComponent({
onClick={handleButtonClick} onClick={handleButtonClick}
className={ className={
editNode editNode
? INPUT_EDIT_NODE + INPUT_STYLE ? "input-edit-node " + "input-primary "
: INPUT_STYLE + (disabled ? INPUT_DISABLE : "") : "input-primary " + (disabled ? "input-disable " : "")
} }
> >
{myValue !== "" ? myValue : "No file"} {myValue !== "" ? myValue : "No file"}

View file

@ -3,7 +3,6 @@ import { InputListComponentType } from "../../types/components";
import { TabsContext } from "../../contexts/tabsContext"; import { TabsContext } from "../../contexts/tabsContext";
import _ from "lodash"; import _ from "lodash";
import { INPUT_DISABLE, INPUT_EDIT_NODE, INPUT_STYLE } from "../../constants";
import { X, Plus } from "lucide-react"; import { X, Plus } from "lucide-react";
import { PopUpContext } from "../../contexts/popUpContext"; import { PopUpContext } from "../../contexts/popUpContext";
@ -43,8 +42,8 @@ export default function InputListComponent({
value={i} value={i}
className={ className={
editNode editNode
? INPUT_EDIT_NODE ? "input-edit-node "
: INPUT_STYLE + (disabled ? INPUT_DISABLE : "") : "input-primary " + (disabled ? "input-disable" : "")
} }
placeholder="Type something..." placeholder="Type something..."
onChange={(e) => { onChange={(e) => {

View file

@ -2,7 +2,6 @@ import { useContext, useEffect, useState } from "react";
import { FloatComponentType } from "../../types/components"; import { FloatComponentType } from "../../types/components";
import { TabsContext } from "../../contexts/tabsContext"; import { TabsContext } from "../../contexts/tabsContext";
import { classNames } from "../../utils"; import { classNames } from "../../utils";
import { INPUT_DISABLE, INPUT_EDIT_NODE, INPUT_STYLE } from "../../constants";
import { PopUpContext } from "../../contexts/popUpContext"; import { PopUpContext } from "../../contexts/popUpContext";
export default function IntComponent({ export default function IntComponent({
@ -72,8 +71,8 @@ export default function IntComponent({
value={myValue} value={myValue}
className={ className={
editNode editNode
? INPUT_EDIT_NODE ? " input-edit-node "
: INPUT_STYLE + (disabled ? INPUT_DISABLE : "") : " input-primary " + (disabled ? " input-disable " : "")
} }
placeholder={editNode ? "Integer number" : "Type an integer number"} placeholder={editNode ? "Integer number" : "Type an integer number"}
onChange={(e) => { onChange={(e) => {

View file

@ -3,12 +3,7 @@ import { PopUpContext } from "../../contexts/popUpContext";
import { TextAreaComponentType } from "../../types/components"; import { TextAreaComponentType } from "../../types/components";
import GenericModal from "../../modals/genericModal"; import GenericModal from "../../modals/genericModal";
import { TypeModal } from "../../utils"; import { TypeModal } from "../../utils";
import {
INPUT_DIALOG,
INPUT_DISABLE,
INPUT_EDIT_NODE,
INPUT_STYLE,
} from "../../constants";
import { ExternalLink } from "lucide-react"; import { ExternalLink } from "lucide-react";
export default function PromptAreaComponent({ export default function PromptAreaComponent({
@ -54,8 +49,8 @@ export default function PromptAreaComponent({
}} }}
className={ className={
editNode editNode
? INPUT_EDIT_NODE + INPUT_DIALOG ? " input-edit-node " + " input-dialog "
: (disabled ? INPUT_DISABLE : "") + INPUT_STYLE + INPUT_DIALOG : (disabled ? " input-disable " : "") + " input-primary " + " input-dialog "
} }
> >
{myValue !== "" ? myValue : "Type your prompt here"} {myValue !== "" ? myValue : "Type your prompt here"}
@ -76,7 +71,7 @@ export default function PromptAreaComponent({
); );
}} }}
> >
{!editNode && <ExternalLink strokeWidth={1.5} className="w-6 h-6 hover:text-accent-foreground " />} {!editNode && <ExternalLink strokeWidth={1.5} className="w-6 h-6 hover:text-accent-foreground ml-3" />}
</button> </button>
</div> </div>
</div> </div>

View file

@ -3,12 +3,7 @@ import { PopUpContext } from "../../contexts/popUpContext";
import { TextAreaComponentType } from "../../types/components"; import { TextAreaComponentType } from "../../types/components";
import GenericModal from "../../modals/genericModal"; import GenericModal from "../../modals/genericModal";
import { TypeModal } from "../../utils"; import { TypeModal } from "../../utils";
import {
INPUT_DIALOG,
INPUT_DISABLE,
INPUT_EDIT_NODE,
INPUT_STYLE,
} from "../../constants";
import { ExternalLink } from "lucide-react"; import { ExternalLink } from "lucide-react";
export default function TextAreaComponent({ export default function TextAreaComponent({
@ -57,8 +52,8 @@ export default function TextAreaComponent({
}} }}
className={ className={
editNode editNode
? INPUT_EDIT_NODE + INPUT_DIALOG ? "input-edit-node " + " input-dialog "
: INPUT_DIALOG + "px-3 py-2" + (disabled ? INPUT_DISABLE : "") : " input_dialog " + "px-3 py-2" + (disabled ? " input-disable " : "")
} }
> >
{myValue !== "" ? myValue : "Type something..."} {myValue !== "" ? myValue : "Type something..."}
@ -79,7 +74,7 @@ export default function TextAreaComponent({
); );
}} }}
> >
{!editNode && <ExternalLink strokeWidth={1.5} className="w-6 h-6 hover:text-accent-foreground " />} {!editNode && <ExternalLink strokeWidth={1.5} className="w-6 h-6 hover:text-accent-foreground ml-3" />}
</button> </button>
</div> </div>
</div> </div>

View file

@ -166,37 +166,6 @@ export const IMPORT_DIALOG_SUBTITLE =
export const EXPORT_CODE_DIALOG = export const EXPORT_CODE_DIALOG =
"Generate the code to integrate your flow into an external application."; "Generate the code to integrate your flow into an external application.";
/**
* The base input for clickable ones
* @constant
*/
export const INPUT_DIALOG = " text-ring cursor-pointer bg-transparent";
/**
* The base input style
* @constant
*/
export const INPUT_STYLE =
" bg-background block border-ring focus:placeholder-transparent focus:ring-ring focus:tw-ring-none form-input px-3 placeholder:text-muted-foreground rounded-md shadow-sm sm:text-sm truncate w-full ";
/**
* The base input on edit node
* @constant
*/
export const INPUT_EDIT_NODE =
" placeholder:text-center pt-0.5 pb-0.5 text-center " + INPUT_STYLE;
/**
* The base search input style
* @constant
*/
export const INPUT_SEARCH = INPUT_STYLE + " pr-7 mx-2 ";
/**
* The base disable input style
* @constant
*/
export const INPUT_DISABLE = " bg-input ";
/** /**
* The base text for subtitle of code dialog * The base text for subtitle of code dialog
* @constant * @constant

View file

@ -140,3 +140,25 @@ The cursor: default; property value restores the browser's default cursor style
.react-flow__pane { .react-flow__pane {
cursor: default; cursor: default;
} }
@layer components {
.input-primary:focus{
@apply focus:placeholder-transparent focus:ring-ring focus:border-ring
}
.input-primary {
@apply bg-background block border-ring form-input px-3 placeholder:text-muted-foreground rounded-md shadow-sm sm:text-sm truncate w-full;
}
.input-edit-node{
@apply input-primary placeholder:text-center pt-0.5 pb-0.5 text-center
}
.input-search{
@apply input-primary pr-7 mx-2
}
.input-disable{
@apply bg-input
}
.input-dialog{
@apply text-ring cursor-pointer bg-transparent
}
}

View file

@ -104,10 +104,11 @@ export default function ApiModal({ flow }: { flow: FlowType }) {
useEffect(() => { useEffect(() => {
if (closeEdit !== "") { if (closeEdit !== "") {
tweak.current = getTweak; tweak.current = getTweak;
if (tweak.current.length > 0) { if(tweak.current.length > 0){
setActiveTab("3"); setActiveTab("3");
openAccordions(); openAccordions();
} else { }
else{
startTweaks(); startTweaks();
} }
} else { } else {
@ -138,7 +139,7 @@ export default function ApiModal({ flow }: { flow: FlowType }) {
} }
function startTweaks() { function startTweaks() {
tweak.current.push(buildTweaks(flow)); tweak?.current?.push(buildTweaks(flow));
} }
function filterNodes() { function filterNodes() {
@ -262,18 +263,21 @@ export default function ApiModal({ flow }: { flow: FlowType }) {
return ( return (
<Dialog open={true} onOpenChange={setModalOpen}> <Dialog open={true} onOpenChange={setModalOpen}>
<DialogTrigger></DialogTrigger> <DialogTrigger></DialogTrigger>
<DialogContent className="h-[580px] sm:max-w-[700px] lg:max-w-[850px]"> <DialogContent className="lg:max-w-[80vw] h-[80vh]">
<DialogHeader> <DialogHeader>
<DialogTitle className="flex items-center"> <DialogTitle className="flex items-center">
<span className="pr-2">Code</span> <span className="pr-2">Code</span>
<Code2 strokeWidth={1.5} className="h-6 w-6 text-primary pl-1 " aria-hidden="true" /> <Code2
className="h-6 w-6 text-gray-800 pl-1 dark:text-white"
aria-hidden="true"
/>
</DialogTitle> </DialogTitle>
<DialogDescription>{EXPORT_CODE_DIALOG}</DialogDescription> <DialogDescription>{EXPORT_CODE_DIALOG}</DialogDescription>
</DialogHeader> </DialogHeader>
<Tabs <Tabs
value={activeTab} value={activeTab}
className="h-full w-full overflow-hidden rounded-md border bg-muted text-center" className="w-full h-full overflow-hidden text-center bg-muted rounded-md border"
onValueChange={(value) => { onValueChange={(value) => {
setActiveTab(value); setActiveTab(value);
if (value === "3") { if (value === "3") {
@ -289,26 +293,28 @@ export default function ApiModal({ flow }: { flow: FlowType }) {
</TabsTrigger> </TabsTrigger>
))} ))}
</TabsList> </TabsList>
{Number(activeTab) < 3 && (
<div className="float-right"> <div className="float-right">
<button <button
className="flex gap-1.5 items-center rounded bg-none p-1 text-xs text-ring hover:text-foreground" className="flex gap-1.5 items-center rounded bg-none p-1 text-xs text-gray-500 dark:text-gray-300"
onClick={copyToClipboard} onClick={copyToClipboard}
> >
{isCopied ? <Check size={18} /> : <Clipboard size={15} />} {isCopied ? <Check size={18} /> : <Clipboard size={15} />}
{isCopied ? "Copied!" : "Copy code"} {isCopied ? "Copied!" : "Copy code"}
</button> </button>
</div> </div>
)}
</div> </div>
{tabs.map((tab, index) => ( {tabs.map((tab, index) => (
<TabsContent <TabsContent
value={index.toString()} value={index.toString()}
className="-mt-1 h-full w-full overflow-hidden px-4 pb-4" className="overflow-hidden w-full h-full px-4 pb-4 -mt-1"
key={index} // Remember to add a unique key prop key={index} // Remember to add a unique key prop
> >
{index < 3 ? ( {index < 3 ? (
<SyntaxHighlighter <SyntaxHighlighter
className="h-[400px] w-full overflow-auto" className="w-full overflow-auto h-[60vh]"
language={tab.mode} language={tab.mode}
style={oneDark} style={oneDark}
> >
@ -316,10 +322,10 @@ export default function ApiModal({ flow }: { flow: FlowType }) {
</SyntaxHighlighter> </SyntaxHighlighter>
) : index === 3 ? ( ) : index === 3 ? (
<> <>
<div className="mt-2 flex h-[400px] w-full"> <div className="flex w-full h-full mt-2">
<div <div
className={classNames( className={classNames(
"w-full rounded-lg border-[1px] border-gray-200 bg-muted", "w-full rounded-lg bg-muted h-[60vh]",
1 == 1 1 == 1
? "overflow-scroll overflow-x-hidden custom-scroll" ? "overflow-scroll overflow-x-hidden custom-scroll"
: "overflow-hidden" : "overflow-hidden"
@ -332,14 +338,14 @@ export default function ApiModal({ flow }: { flow: FlowType }) {
trigger={t["data"]["id"]} trigger={t["data"]["id"]}
open={openAccordion} open={openAccordion}
> >
<div className="flex h-fit flex-col gap-5"> <div className="flex flex-col gap-5 h-fit">
<Table className="table-fixed bg-muted outline-1"> <Table className="table-fixed bg-muted outline-1">
<TableHeader className="h-10 border-gray-200 text-xs font-medium text-gray-500"> <TableHeader className="border-input text-xs font-medium text-ring h-10">
<TableRow className="dark:border-b-muted"> <TableRow className="dark:border-b-muted">
<TableHead className="h-7 text-center"> <TableHead className="h-7 text-center">
PARAM PARAM
</TableHead> </TableHead>
<TableHead className="h-7 p-0 text-center"> <TableHead className="p-0 h-7 text-center">
VALUE VALUE
</TableHead> </TableHead>
</TableRow> </TableRow>
@ -373,11 +379,11 @@ export default function ApiModal({ flow }: { flow: FlowType }) {
key={i} key={i}
className="h-10 dark:border-b-muted" className="h-10 dark:border-b-muted"
> >
<TableCell className="p-0 text-center text-sm text-gray-900"> <TableCell className="p-0 text-center text-gray-900 text-sm">
{n} {n}
</TableCell> </TableCell>
<TableCell className="p-0 text-center text-xs text-gray-900 dark:text-gray-300"> <TableCell className="p-0 text-center text-gray-900 text-xs dark:text-gray-300">
<div className="m-auto w-[250px]"> <div className="w-[250px] m-auto">
{t.data.node.template[n] {t.data.node.template[n]
.type === "str" && .type === "str" &&
!t.data.node.template[n] !t.data.node.template[n]

View file

@ -1,7 +1,6 @@
import { classNames } from "../../../utils"; import { classNames } from "../../../utils";
import { useContext, useEffect, useRef, useState } from "react"; import { useContext, useEffect, useRef, useState } from "react";
import { TabsContext } from "../../../contexts/tabsContext"; import { TabsContext } from "../../../contexts/tabsContext";
import { INPUT_STYLE } from "../../../constants";
import { Lock, Send } from "lucide-react"; import { Lock, Send } from "lucide-react";
export default function ChatInput({ export default function ChatInput({
@ -54,7 +53,7 @@ export default function ChatInput({
? " bg-input text-foreground " ? " bg-input text-foreground "
: " bg-background text-foreground ", : " bg-background text-foreground ",
"form-input block w-full rounded-md border-ring pr-10 custom-scroll sm:text-sm" + "form-input block w-full rounded-md border-ring pr-10 custom-scroll sm:text-sm" +
INPUT_STYLE " input-primary "
)} )}
placeholder={"Send a message..."} placeholder={"Send a message..."}
/> />

View file

@ -80,7 +80,7 @@ export default function GenericModal({
<div className="mt-2 flex h-full w-full"> <div className="mt-2 flex h-full w-full">
<Textarea <Textarea
ref={ref} ref={ref}
className="form-input h-[300px] w-full rounded-lg border-ring focus-visible:ring-1" className=" h-[300px] w-full form-primary "
value={myValue} value={myValue}
onChange={(e) => { onChange={(e) => {
setMyValue(e.target.value); setMyValue(e.target.value);

View file

@ -92,7 +92,7 @@ export default function TextAreaModal({
<div className="w-full overflow-hidden rounded-lg bg-background px-4 py-5 shadow sm:p-6"> <div className="w-full overflow-hidden rounded-lg bg-background px-4 py-5 shadow sm:p-6">
<textarea <textarea
ref={ref} ref={ref}
className="form-input h-full w-full rounded-lg border-ring" className="form-input h-full w-full form-primary"
value={myValue} value={myValue}
onChange={(e) => { onChange={(e) => {
setMyValue(e.target.value); setMyValue(e.target.value);

View file

@ -15,7 +15,6 @@ import ExportModal from "../../../../modals/exportModal";
import ApiModal from "../../../../modals/ApiModal"; import ApiModal from "../../../../modals/ApiModal";
import { TabsContext } from "../../../../contexts/tabsContext"; import { TabsContext } from "../../../../contexts/tabsContext";
import { alertContext } from "../../../../contexts/alertContext"; import { alertContext } from "../../../../contexts/alertContext";
import { INPUT_SEARCH, INPUT_STYLE } from "../../../../constants";
import { Separator } from "../../../../components/ui/separator"; import { Separator } from "../../../../components/ui/separator";
import { Menu } from "lucide-react"; import { Menu } from "lucide-react";
@ -124,7 +123,7 @@ export default function ExtraSidebar() {
name="search" name="search"
id="search" id="search"
placeholder="Search" placeholder="Search"
className={INPUT_SEARCH} className="input-search"
onChange={(e) => { onChange={(e) => {
handleSearchInput(e.target.value); handleSearchInput(e.target.value);
setSearch(e.target.value); setSearch(e.target.value);