mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-01-02 03:03:23 -05:00
* refactor: explicit types for validate * refactor: explicit return types for ui-components * refactor: use exec instead of match * refactor: add lots more boundary types * refactor: more eslint warnings * refactor: more explicit exports * refactor: more explicit types * refactor: even more explicit types * fix: relax type contrainsts for superblock-order * refactor: final boundaries * refactor: avoid using 'object' type * fix: use named import for captureException This uses TypeScript (which works) instead of import/namespace (which doesn't) to check if captureException exists in sentry/gatsby (it does)
60 lines
1.3 KiB
TypeScript
60 lines
1.3 KiB
TypeScript
// component.tsx
|
|
export const component = (name: string): string => `
|
|
import React from 'react';
|
|
|
|
import { ${name}Props } from './types';
|
|
|
|
export const ${name} = ({}: ${name}Props) => {
|
|
return <div>Hello, I am a ${name} component</div>;
|
|
};
|
|
`;
|
|
|
|
// types.ts
|
|
export const type = (name: string): string => `
|
|
export interface ${name}Props {
|
|
className?: string
|
|
}
|
|
`;
|
|
|
|
// component.test.tsx
|
|
export const test = (name: string): string => `
|
|
import React from 'react';
|
|
import { render, screen } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
|
|
import { ${name} } from '.';
|
|
|
|
describe('<${name} />', () => {
|
|
it('should render correctly', () => {});
|
|
});
|
|
`;
|
|
|
|
// component.stories.tsx
|
|
export const story = (name: string): string => `
|
|
import React from 'react';
|
|
import { Story } from '@storybook/react';
|
|
import { ${name}, ${name}Props } from '.';
|
|
|
|
const story = {
|
|
title: 'Example/${name}',
|
|
component: ${name}
|
|
};
|
|
|
|
const Template: Story<${name}Props> = args => {
|
|
return <${name} {...args} />;
|
|
};
|
|
|
|
export const Default = Template.bind({});
|
|
Default.args = {
|
|
// default props go here
|
|
};
|
|
|
|
export default story;
|
|
`;
|
|
|
|
// index.ts
|
|
export const barrel = (name: string, kebabCasedName: string): string => `
|
|
export { ${name} } from './${kebabCasedName}';
|
|
export type { ${name}Props } from './types';
|
|
`;
|