diff --git a/app/client/src/IDE/Components/FileTab.tsx b/app/client/src/IDE/Components/FileTab.tsx new file mode 100644 index 000000000000..af2012b0fe34 --- /dev/null +++ b/app/client/src/IDE/Components/FileTab.tsx @@ -0,0 +1,97 @@ +import React from "react"; +import styled from "styled-components"; +import clsx from "classnames"; + +import { Flex, Icon } from "design-system"; + +interface FileTabProps { + isActive: boolean; + title: string; + onClick: () => void; + onClose: (e: React.MouseEvent) => void; + icon?: React.ReactNode; +} + +export const StyledTab = styled(Flex)` + position: relative; + height: 100%; + font-size: 12px; + color: var(--ads-v2-colors-text-default); + cursor: pointer; + gap: var(--ads-v2-spaces-2); + border-top: 1px solid transparent; + border-top-left-radius: var(--ads-v2-border-radius); + border-top-right-radius: var(--ads-v2-border-radius); + align-items: center; + justify-content: center; + padding: var(--ads-v2-spaces-3); + border-left: 1px solid transparent; + border-right: 1px solid transparent; + border-top: 2px solid transparent; + + &.active { + background: var(--ads-v2-colors-control-field-default-bg); + border-top-color: var(--ads-v2-color-bg-brand); + border-left-color: var(--ads-v2-color-border-muted); + border-right-color: var(--ads-v2-color-border-muted); + } + + & > .tab-close { + position: relative; + right: -2px; + visibility: hidden; + } + + &:hover > .tab-close { + visibility: visible; + } + + &.active > .tab-close { + visibility: visible; + } +`; + +export const TabTextContainer = styled.span` + width: 100%; + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; +`; + +export const TabIconContainer = styled.div` + height: 12px; + width: 12px; + display: flex; + align-items: center; + justify-content: center; + flex-shrink: 0; + img { + width: 12px; + } +`; + +export const FileTab = ({ + icon, + isActive, + onClick, + onClose, + title, +}: FileTabProps) => { + return ( + + {icon ? {icon} : null} + {title} + {/* not using button component because of the size not matching design */} + + + ); +}; diff --git a/app/client/src/pages/Editor/IDE/EditorPane/EditorPaneSegments.tsx b/app/client/src/pages/Editor/IDE/EditorPane/EditorPaneSegments.tsx index 34a89ee61f18..5d44ec5edf28 100644 --- a/app/client/src/pages/Editor/IDE/EditorPane/EditorPaneSegments.tsx +++ b/app/client/src/pages/Editor/IDE/EditorPane/EditorPaneSegments.tsx @@ -29,7 +29,6 @@ const EditorPaneSegments = () => { diff --git a/app/client/src/pages/Editor/IDE/EditorTabs/AddButton.tsx b/app/client/src/pages/Editor/IDE/EditorTabs/AddButton.tsx index b79340e5d6d7..08211551128a 100644 --- a/app/client/src/pages/Editor/IDE/EditorTabs/AddButton.tsx +++ b/app/client/src/pages/Editor/IDE/EditorTabs/AddButton.tsx @@ -1,36 +1,67 @@ -import React from "react"; +import type { Ref } from "react"; +import React, { forwardRef } from "react"; import { Flex, Spinner, Button } from "design-system"; import { useCurrentEditorState, useIDETabClickHandlers } from "../hooks"; import { useIsJSAddLoading } from "@appsmith/pages/Editor/IDE/EditorPane/JS/hooks"; -import { EditorEntityTabState } from "@appsmith/entities/IDE/constants"; +import { + EditorEntityTab, + EditorEntityTabState, +} from "@appsmith/entities/IDE/constants"; +import { FileTab } from "IDE/Components/FileTab"; -const AddButton = () => { - const { addClickHandler } = useIDETabClickHandlers(); - const isJSLoading = useIsJSAddLoading(); - const { segmentMode } = useCurrentEditorState(); +const AddButton = forwardRef( + ( + { + newTabClickCallback, + onClose, + }: { + newTabClickCallback: () => void; + onClose: (actionId?: string) => void; + }, + ref: Ref, + ) => { + const { addClickHandler } = useIDETabClickHandlers(); + const isJSLoading = useIsJSAddLoading(); + const { segment, segmentMode } = useCurrentEditorState(); - if (segmentMode === EditorEntityTabState.Add) { - return null; - } - if (isJSLoading) { - return ( - - - + if (isJSLoading) { + return ( + + + + ); + } + + const onCloseClick = (e: React.MouseEvent) => { + e.stopPropagation(); + onClose(); + }; + + return segmentMode === EditorEntityTabState.Add ? ( + onCloseClick(e)} + title={`New ${segment === EditorEntityTab.JS ? "JS" : "Query"}`} + /> + ) : ( +
+
); - } - return ( -