Skip to content

Commit adcfd86

Browse files
committed
allow for external overrides of default styles, but default styles mirror textarea
1 parent b98f58e commit adcfd86

2 files changed

Lines changed: 49 additions & 2 deletions

File tree

packages/react-textarea/src/components/copilot-textarea/base-copilot-textarea/base-copilot-textarea.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
BaseAutosuggestionsConfig,
2626
defaultBaseAutosuggestionsConfig,
2727
} from "../../../types/autosuggestions-config";
28+
import { defaultStylesConsideringClassname } from "./default-styles-considering-classname";
2829
import { renderElement } from "./render-element";
2930
import { makeRenderPlaceholderFunction } from "./render-placeholder";
3031

@@ -132,9 +133,10 @@ export function BaseCopilotTextarea(
132133
...propsToForward
133134
} = props;
134135

136+
const { className } = propsToForward;
135137
const moddedStyle = {
136-
overflow: "auto",
137-
...style, // to merge in styles passed via props if any
138+
...defaultStylesConsideringClassname(className),
139+
...style,
138140
};
139141

140142
return (
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// A slightly hacky way to get the default styles of a CopilotTextarea considering its className --
2+
// to allow for outside (tailwindCSS) overrides of the default styles.
3+
export function defaultStylesConsideringClassname(
4+
className: string | undefined
5+
) {
6+
let defaultStyles: React.CSSProperties = {};
7+
const classNameChunks = (className ?? "").split(" ") ?? [];
8+
9+
// white background color
10+
if (!classNameChunks.some((chunk) => chunk.startsWith("bg-"))) {
11+
defaultStyles = {
12+
...defaultStyles,
13+
backgroundColor: "white",
14+
};
15+
}
16+
17+
// overflow-y: auto
18+
// if there is a overflow- which is NOT overflow-x, then we don't add overflow-y: auto
19+
if (
20+
!classNameChunks.some(
21+
(chunk) =>
22+
chunk.startsWith("overflow-") && !chunk.startsWith("overflow-x")
23+
)
24+
) {
25+
defaultStyles = {
26+
...defaultStyles,
27+
overflowY: "auto",
28+
};
29+
}
30+
31+
// resize-y
32+
// if there is a resize- which is NOT resize-x, then we don't add resize-y
33+
if (
34+
!classNameChunks.some(
35+
(chunk) => chunk.startsWith("resize-") && !chunk.startsWith("resize-x")
36+
)
37+
) {
38+
defaultStyles = {
39+
...defaultStyles,
40+
resize: "vertical",
41+
};
42+
}
43+
44+
return defaultStyles;
45+
}

0 commit comments

Comments
 (0)