yyllff / split-pane-react

Resizable split panes for React.js.
https://yyllff.github.io/split-pane-react
MIT License
95 stars 25 forks source link

SashContent children and Typescript #16

Open LindaJuffermans opened 1 year ago

LindaJuffermans commented 1 year ago

I'm trying to use this in a Next w/Typescript project:

<SashContent className={styles.sashWrapLineActive}>
  <span className={styles.sashWrapLine}></span>
</SashContent>

Typescript complains about the span element:

types.d.ts(60, 5): The expected type comes from property 'children' which is declared here on type 'IntrinsicAttributes & ISashContentProps'

Do I need to add anything to allow the element or is this a bug in split-pane-react? On the interface, I see children is defined as JSX.Element[]

InTheNooB commented 1 year ago

Same here

InTheNooB commented 1 year ago

In my case it was because i was using react-split-pan instead of split-pane-react...

RCQE commented 1 year ago

Maybe you need to add sashRender paras like this: https://codesandbox.io/s/split-pane-themes-xmsqtt And u can use the default like this: https://github.com/yyllff/split-pane-react/issues/12#issuecomment-1357527567

cwellsx commented 11 months ago

I guess it's a bug in the definition of the children property of ISashContentProps

Instead of declaring it as type JSX.Element[] it should also support other types e.g. a single element.

Using React with Typescript, children is normally defined as being of type ReactNode see e.g. https://blog.logrocket.com/react-children-prop-typescript/

cwellsx commented 11 months ago

FYI I too get the error in the OP if I try to compile this code using TypeScript.

The code in question is in (and copied from) the themes demo e.g.:

That demo is a .jsx file not a .tsx file.

cwellsx commented 11 months ago

I worked-around this problem by using the normal typescript instead of trying to use a theme, and instead adding some CSS to get something looking like the "line" style.

sashRender={(_, active) => <SashContent active={active} type="vscode"></SashContent>}

and

.split-sash-content.split-sash-content-vscode {
  background-color: rgb(200,200,200);
  width: 2px;
}
.split-sash-content.split-sash-content-vscode.split-sash-content-active {
  width: 100%;
}