Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: editable ide tabs #36665

Open
wants to merge 25 commits into
base: release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4c4694f
perf: do not mutate history for the same url
alex-golovanov Sep 27, 2024
295a041
chore: add usehooks-ts
alex-golovanov Sep 27, 2024
144edb7
perf: correct state styles & fix spacing
alex-golovanov Oct 2, 2024
8f09c44
perf: add input ref & remove redundant callback prop
alex-golovanov Oct 2, 2024
6924378
chore: fix typo
alex-golovanov Oct 2, 2024
6f6bc3d
feat: hook for common name editing needs
alex-golovanov Oct 2, 2024
195daa7
feat: adde editable tab name
alex-golovanov Oct 2, 2024
70add12
chore: remove unused files
alex-golovanov Oct 2, 2024
2d6bc28
Merge branch 'release' into feat/32440-editable-ide-tabs
alex-golovanov Oct 2, 2024
b98f363
fix: replace lock
alex-golovanov Oct 2, 2024
f2c6924
perf: tweak positioning
alex-golovanov Oct 2, 2024
aa4c87e
fix: stop event propagation on tab close
alex-golovanov Oct 2, 2024
d6cc17a
fix: validation reset on escape
alex-golovanov Oct 2, 2024
df31a7a
perf: replace tw with styled & tweak styles
alex-golovanov Oct 3, 2024
072f1d6
perf: lifted state into editable component for perf
alex-golovanov Oct 4, 2024
1d128f6
chore: add usehooks-ts to jest config
alex-golovanov Oct 7, 2024
95f041e
chore: add forwardRef & rename striked to strikethrough for consistency
alex-golovanov Oct 7, 2024
ede76cd
chore: move test constants to a file
alex-golovanov Oct 7, 2024
bfadb0b
test: add tab tests
alex-golovanov Oct 7, 2024
47ee66b
chore: correct typing and story
alex-golovanov Oct 7, 2024
d05671f
fix: revert tab close button name change
alex-golovanov Oct 7, 2024
a47adb5
chore: fix a linter error
alex-golovanov Oct 7, 2024
b1f6a7c
fix: addressed focusOut related issues
alex-golovanov Oct 10, 2024
14a6c75
Merge branch 'release' into feat/32440-editable-ide-tabs
alex-golovanov Oct 10, 2024
dc89acb
Merge branch 'release' into feat/32440-editable-ide-tabs
alex-golovanov Oct 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/client/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node", "css"],
moduleDirectories: ["node_modules", "src", "test"],
transformIgnorePatterns: [
"<rootDir>/node_modules/(?!codemirror|konva|react-dnd|dnd-core|@babel|(@blueprintjs)|@github|lodash-es|@draft-js-plugins|react-documents|linkedom|assert-never|axios)",
"<rootDir>/node_modules/(?!codemirror|konva|react-dnd|dnd-core|@babel|(@blueprintjs)|@github|lodash-es|@draft-js-plugins|react-documents|linkedom|assert-never|axios|usehooks-ts)",
],
moduleNameMapper: {
"\\.(css|less)$": "<rootDir>/test/__mocks__/styleMock.js",
Expand Down
1 change: 1 addition & 0 deletions app/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
"typescript": "^5.5.4",
"unescape-js": "^1.1.4",
"url-search-params-polyfill": "^8.0.0",
"usehooks-ts": "^3.1.0",
"uuid": "^9.0.0",
"validate-color": "^2.2.4",
"web-vitals": "3.5.2",
Expand Down
18 changes: 10 additions & 8 deletions app/client/packages/design-system/ads/src/Text/Text.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useMemo } from "react";
import { Text } from "./Text";
import type { Meta, StoryObj } from "@storybook/react";

Expand All @@ -25,15 +25,17 @@ export const EditableTextStory: Story = {
},
render: function Render(args) {
const [text, setText] = React.useState(args.children);
const inputProps = useMemo(
() => ({
onChange: (e: React.ChangeEvent<HTMLInputElement>) => {
setText(e.target.value);
},
}),
[],
);

return (
<Text
{...args}
onChange={(e) => {
// @ts-expect-error type error
setText(e.target.value);
}}
>
<Text inputProps={inputProps} {...args}>
{text}
</Text>
);
Expand Down
10 changes: 4 additions & 6 deletions app/client/packages/design-system/ads/src/Text/Text.styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export const StyledText = styled.span<{
isBold?: boolean;
isItalic?: boolean;
isUnderlined?: boolean;
isStriked?: boolean;
isStrikethrough?: boolean;
isEditable?: boolean;
}>`
${TypographyScales}
Expand Down Expand Up @@ -160,8 +160,8 @@ export const StyledText = styled.span<{
text-decoration: underline;
}

/* Striked style */
&[data-striked="true"] {
/* Strikethrough style */
&[data-strikethrough="true"] {
text-decoration: line-through;
}

Expand Down Expand Up @@ -191,10 +191,8 @@ export const StyledEditableInput = styled.input`
border: 1px solid transparent;
border-radius: var(--ads-v2-border-radius);
outline: none;
padding: 0;
margin: 0;
position: absolute;
left: -3px;
top: -3px;
width: 100%;
padding: var(--ads-v2-spaces-1);
Expand All @@ -205,6 +203,6 @@ export const StyledEditableInput = styled.input`

&:focus,
&:active {
border-color: var(--ads-v2-colors-control-field-default-border);
border-color: var(--ads-v2-colors-control-field-active-border);
}
`;
42 changes: 21 additions & 21 deletions app/client/packages/design-system/ads/src/Text/Text.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import React, { forwardRef } from "react";
import clsx from "classnames";
import type { TextProps } from "./Text.types";
import type { RenderAsElement, TextProps } from "./Text.types";
import { StyledEditableInput, StyledText } from "./Text.styles";
import { TextClassName } from "./Text.constants";

Expand All @@ -9,49 +9,49 @@ TODO:
- add segment header style to list of styles
*/

function Text({
children,
className,
color,
inputProps,
isEditable,
kind,
onChange,
renderAs,
...rest
}: TextProps) {
const Text = forwardRef<RenderAsElement, TextProps>(function Text(
{
children,
className,
color,
inputProps,
inputRef,
isEditable,
kind,
renderAs,
...rest
}: TextProps,
ref,
) {
return (
<StyledText
as={renderAs}
className={clsx(TextClassName, className)}
color={color}
data-bold={rest.isBold}
data-italic={rest.isItalic}
data-striked={rest.isStriked}
data-strikethrough={rest.isStrikethrough}
data-underlined={rest.isUnderlined}
data-value={isEditable && typeof children === "string" ? children : null}
isEditable={isEditable && typeof children === "string"}
kind={kind}
ref={ref}
{...rest}
>
{isEditable && typeof children === "string" ? (
<StyledEditableInput
onChange={onChange}
value={children}
{...inputProps}
/>
<StyledEditableInput ref={inputRef} value={children} {...inputProps} />
) : (
alex-golovanov marked this conversation as resolved.
Show resolved Hide resolved
children
)}
</StyledText>
);
}
});

Text.displayName = "Text";

Text.defaultProps = {
renderAs: "span",
kind: "span",
kind: "body-m",
};

export { Text };
23 changes: 14 additions & 9 deletions app/client/packages/design-system/ads/src/Text/Text.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ReactNode } from "react";
import type React from "react";

/** Text style variant */
export type TextKind =
| "heading-xl"
| "heading-l"
Expand All @@ -14,7 +15,14 @@ export type TextKind =
| "action-s"
| "code";

// Text props
/** All possible element types text can be rendered as, matches renderAs prop */
export type RenderAsElement =
| HTMLHeadingElement
| HTMLLabelElement
| HTMLParagraphElement
| HTMLSpanElement;

/** Text component props */
export type TextProps = {
/** to change the rendering component */
renderAs?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "p" | "span" | "label";
Expand All @@ -32,17 +40,14 @@ export type TextProps = {
isItalic?: boolean;
/** whether the text is underlined or not */
isUnderlined?: boolean;
/** whether the text is striked or not */
isStriked?: boolean;
/** whether the text is strikethrough or not */
isStrikethrough?: boolean;
alex-golovanov marked this conversation as resolved.
Show resolved Hide resolved
/** whether the text is editable or not */
isEditable?: boolean;
/** onChange event for editable text */
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
/** input component props while isEditable is true */
inputProps?: Omit<
React.InputHTMLAttributes<HTMLInputElement>,
"value" | "onChange"
>;
inputProps?: Omit<React.InputHTMLAttributes<HTMLInputElement>, "value">;
/** ref for input component */
inputRef?: React.RefObject<HTMLInputElement>;
} & React.HTMLAttributes<HTMLLabelElement> &
React.HTMLAttributes<HTMLHeadingElement> &
React.HTMLAttributes<HTMLParagraphElement> &
Expand Down
99 changes: 0 additions & 99 deletions app/client/src/IDE/Components/FileTab.tsx

This file was deleted.

Loading
Loading