Skip to content

[HELP WANTED] Add TypeScript Version of Existing Components #34

Closed
@DavidHDev

Description

@DavidHDev

Description

The library now supports TypeScript! But we still need to add the TypeScript code for most of the components!

Help Wanted

Two new folders have been created inside the src folder of the project:

  • /ts-default
  • /ts-tailwind

The steps to adding full TypeScript support for any component are:

  1. Under /ts-default and /ts-tailwind, create a new folder using the component's name (e.g: SplitText)
  2. For /ts-default, create two files: <ComponentName>.tsx and <ComponentName>.css - this will be the TS + CSS version of the component
  3. For /ts-tailwind, create one file: <ComponentName>.tsx - this will be the TS + Tailwind version of the component
  4. It's then up to you to add the component code in both of these folders
  5. Test your code locally to ensure the component is working as expected after the conversion! Replace the import inside the Demo component of the component you just converted to TypeScript, and it should work exactly the same as the JS one, if not, you need to go back and fix any issues!
  6. Now that you have your components, you will have to update the snippet constants that are used for that component in the "Code" tab! You will find this under /src/constants/code/<Category>/<componentName>Code.js. In here you will have to add the following information: cliTsDefault, cliTsTailwind, tsCode, tsTailwind
  7. For the actual component code, you'll need to add some extra imports in the file and append them to the existing object that gets exported out of the file:
import code from '@content/<Category>/<Component>/<Component>.jsx?raw';

// if there's also a css file
import code from '@content/<Category>/<Component>/<Component>.css?raw';

import tailwind from '@tailwind/<Category>/<Component>/<Component>.jsx?raw';
import tsCode from '@ts-default/<Category>/<Component>/<Component>.tsx?raw';
import tsTailwind from '@ts-tailwind/<Category>/<Component>/<Component>.tsx?raw';

Please note: it's important to keep the import keys as code, css, tailwind, tsCode, tsTailwind!

So your final updated file should look similar to this:

import code from '@content/Animations/AnimatedContent/AnimatedContent.jsx?raw';
import tailwind from '@tailwind/Animations/AnimatedContent/AnimatedContent.jsx?raw';
import tsCode from '@ts-default/Animations/AnimatedContent/AnimatedContent.tsx?raw';
import tsTailwind from '@ts-tailwind/Animations/AnimatedContent/AnimatedContent.tsx?raw';

export const animatedContent = {
  installation: `npm install @react-spring/web`,
  cliDefault: `npx jsrepo add https://reactbits.dev/default/Animations/AnimatedContent`,
  cliTailwind: `npx jsrepo add https://reactbits.dev/tailwind/Animations/AnimatedContent`,
  cliTsDefault: `npx jsrepo add https://reactbits.dev/ts/default/Animations/AnimatedContent`,
  cliTsTailwind: `npx jsrepo add https://reactbits.dev/ts/tailwind/Animations/AnimatedContent`,
  usage: `import AnimatedContent from './AnimatedContent'

<AnimatedContent
  distance={150}
  direction="horizontal"
  reverse={false}
  config={{ tension: 80, friction: 20 }}
  initialOpacity={0.2}
  animateOpacity
  scale={1.1}
  threshold={0.2}
>
  <div>Content to Animate</div>
</AnimatedContent>`,
  code,
  tailwind,
  tsCode,
  tsTailwind
}
  1. Finally, inside /demo/<Category>/<ComponentName>Demo.jsx, update the CliInstallation props so that it looks like the example below:
<CliInstallation {...animatedContent} />

Wrapping Up

That's it! When you're done, test your changes, go through all the tabs and make sure the snippets are correct, check the console for errors, and if all is well, you've successfully added the TypeScript snippets to the component!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions