-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add TypeScript components generation support. #1956
Conversation
8d4f7f4
to
8d520b1
Compare
@alexcjohnson Ready for review, thank you. |
6210fd4
to
a4fca7d
Compare
Component template: https://github.com/T4rk1n/dash-typescript-component-template It install Dash from this PR, there's an issue with the setup and the installation is not complete but it generates the component. |
33a4726
to
c4ff36b
Compare
I want to refactor the dash-mantine-components library with typescript support. Is there any estimate as to when this will be merged into dev? |
The current solution requires that all components in a package are in TypeScript, we would like to more easily migrate existing libraries by combining the extract-meta script with the new ts compiler for |
c4ff36b
to
f3f0da3
Compare
@T4rk1n I had one more request. Will this change support imported prop types? So for example many a times react components accept common props such as style, class_name, padding props (p, px, py, pr, pt, etc.), margin props (m, mx, my, etc). It would be nice if these props can be defined in one module and imported in all the components. |
@snehilvj You can use all the typescript type utilities to combine & manipulate the prop types. Like if you want to wrap the props of an html element but remove the ./src/props.ts import React from 'react'
export type DashComponentProps = {
/**
* Unique ID to identify this component in Dash callbacks.
*/
id?: string;
/**
* Update props to trigger callbacks.
*/
setProps: (props: Record<string, any>) => void;
}
type InvalidHtmlProps =
| 'dangerouslySetInnerHTML'
| 'defaultChecked'
| 'defaultValue'
| 'suppressContentEditableWarning'
| 'suppressHydrationWarning'
| 'ref'
| 'key'
| 'async';
type EventsProps = keyof Omit<React.DOMAttributes<any>, 'children'>;
type AriaProps = keyof React.AriaAttributes;
export type HtmlOmittedProps = InvalidHtmlProps | EventsProps | AriaProps;
type SourceProps = Omit<React.SourceHTMLAttributes<any>, HtmlOmittedProps>;
export type AudioProps = Omit<React.AudioHTMLAttributes<any>, HtmlOmittedProps> & Partial<{
sources: JSX.Element[] | SourceProps[];
/**
* Set to true to play the audio source.
*/
play: boolean;
status: 'playing' | 'paused' | 'stopped';
/**
* READONLY: true when the audio can be played.
*/
can_play: boolean;
/**
* READONLY: true when the audio has been download completely.
*/
can_play_through: boolean;
}> & DashComponentProps; Then import it in the component: ./src/components/Audio.tsx import React from 'react'
import { AudioProps } from '../props';
const Audio = (props: AudioProps) => {
// Remove the custom props & keep the rest to give to the html component.
const { sources, play, status, can_play, can_play_throught, setProps, ...audioProps } = props;
return (
<audio {...audioProps}>
// ...
</audio>
)
}
export default Audio; |
You made me cry. 😭 Thanks for all the efforts @T4rk1n. |
@T4rk1n , I tried using https://github.com/T4rk1n/dash-typescript-component-template but, it is not generating the python class file in the example_component directory. How can I run the python-dash app with the typescript component? |
I realized that the metadata.json file is empty and hence the python class is not being generate? @T4rk1n , could you please comment on this? |
824afde
to
033a4dd
Compare
@rohitranjan017 There were a few errors in the template because it was not up to date with the latest development here. I updated the template and this branch, should work now if you generate again from the template. |
033a4dd
to
36ef5d2
Compare
70b99ae
to
efb54ce
Compare
@plotly/dash-generator-test-component-typescript/src/components/MemoTypeScriptComponent.tsx
Show resolved
Hide resolved
@T4rk1n this is looking great! My only real questions about it are about how folks will learn to use it:
|
I think for now I'd like to keep them separated, the original boilerplate has more stuff in it and the component it generates is a class component while the new template is structured differently and generates a functional component. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💃 Excellent work!
I think for now I'd like to keep them separated, the original boilerplate has more stuff in it and the component it generates is a class component while the new template is structured differently and generates a functional component.
We don't need to deal with this before merging this PR, but if the original has unnecessary things in it or is out-of-date we should update it. I think it would be a mistake to split component creation into two different cookiecutters, because it would give people a false impression that JS/TS is a difficult transition, also it'd be more for us to maintain and more for users to learn about.
Co-authored-by: Alex Johnson <johnson.alex.c@gmail.com>
5769545
to
c469c72
Compare
c469c72
to
de009db
Compare
Add typescript component support for Dash components, custom replacement for
react-docgen
.Use with
dash-generate-components
CLI.Requires npm modules installed as
devDependencies
:typescript
Contributor Checklist
optionals
CHANGELOG.md