mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-03 05:04:51 +08:00
Merge pull request #19451 from storybookjs/tom/sb-557-typescript-2
Add Preact/Webpack templates and update renderer/preset (2)
This commit is contained in:
commit
c83449fed2
@ -17,11 +17,20 @@ type BabelParams = {
|
|||||||
};
|
};
|
||||||
function createBabelOptions({ babelOptions, mdxBabelOptions, configureJSX }: BabelParams) {
|
function createBabelOptions({ babelOptions, mdxBabelOptions, configureJSX }: BabelParams) {
|
||||||
const babelPlugins = mdxBabelOptions?.plugins || babelOptions?.plugins || [];
|
const babelPlugins = mdxBabelOptions?.plugins || babelOptions?.plugins || [];
|
||||||
|
|
||||||
|
const filteredBabelPlugins = babelPlugins.filter((p: any) => {
|
||||||
|
const name = Array.isArray(p) ? p[0] : p;
|
||||||
|
if (typeof name === 'string') {
|
||||||
|
return !name.includes('plugin-transform-react-jsx');
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
const jsxPlugin = [
|
const jsxPlugin = [
|
||||||
require.resolve('@babel/plugin-transform-react-jsx'),
|
require.resolve('@babel/plugin-transform-react-jsx'),
|
||||||
{ pragma: 'React.createElement', pragmaFrag: 'React.Fragment' },
|
{ pragma: 'React.createElement', pragmaFrag: 'React.Fragment' },
|
||||||
];
|
];
|
||||||
const plugins = configureJSX ? [...babelPlugins, jsxPlugin] : babelPlugins;
|
const plugins = configureJSX ? [...filteredBabelPlugins, jsxPlugin] : babelPlugins;
|
||||||
return {
|
return {
|
||||||
// don't use the root babelrc by default (users can override this in mdxBabelOptions)
|
// don't use the root babelrc by default (users can override this in mdxBabelOptions)
|
||||||
babelrc: false,
|
babelrc: false,
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from 'preact';
|
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import './button.css';
|
import './button.css';
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from 'preact';
|
|
||||||
import { Button } from './Button';
|
import { Button } from './Button';
|
||||||
|
|
||||||
// More on default export: https://storybook.js.org/docs/preact/writing-stories/introduction#default-export
|
// More on default export: https://storybook.js.org/docs/preact/writing-stories/introduction#default-export
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h, Fragment } from 'preact';
|
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import { Button } from './Button';
|
import { Button } from './Button';
|
||||||
@ -29,17 +27,17 @@ export const Header = ({ user, onLogin, onLogout, onCreateAccount }) => (
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
{user ? (
|
{user ? (
|
||||||
<Fragment>
|
<>
|
||||||
<span className="welcome">
|
<span className="welcome">
|
||||||
Welcome, <b>{user.name}</b>!
|
Welcome, <b>{user.name}</b>!
|
||||||
</span>
|
</span>
|
||||||
<Button size="small" onClick={onLogout} label="Log out" />
|
<Button size="small" onClick={onLogout} label="Log out" />
|
||||||
</Fragment>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<Fragment>
|
<>
|
||||||
<Button size="small" onClick={onLogin} label="Log in" />
|
<Button size="small" onClick={onLogin} label="Log in" />
|
||||||
<Button primary size="small" onClick={onCreateAccount} label="Sign up" />
|
<Button primary size="small" onClick={onCreateAccount} label="Sign up" />
|
||||||
</Fragment>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from 'preact';
|
|
||||||
import { Header } from './Header';
|
import { Header } from './Header';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from 'preact';
|
|
||||||
import { useState } from 'preact/hooks';
|
import { useState } from 'preact/hooks';
|
||||||
|
|
||||||
import { Header } from './Header';
|
import { Header } from './Header';
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
/** @jsx h */
|
|
||||||
import { h } from 'preact';
|
|
||||||
import { within, userEvent } from '@storybook/testing-library';
|
import { within, userEvent } from '@storybook/testing-library';
|
||||||
|
|
||||||
import { Page } from './Page';
|
import { Page } from './Page';
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
const craTemplates = {
|
const craTemplates = {
|
||||||
'cra/default-js': {
|
'cra/default-js': {
|
||||||
name: 'Create React App (Javascript)',
|
name: 'Create React App (Javascript)',
|
||||||
script: 'npx create-react-app .',
|
script: 'npx create-react-app {{beforeDir}}',
|
||||||
cadence: ['ci', 'daily', 'weekly'],
|
cadence: ['ci', 'daily', 'weekly'],
|
||||||
expected: {
|
expected: {
|
||||||
framework: '@storybook/cra',
|
framework: '@storybook/cra',
|
||||||
@ -11,7 +11,7 @@ const craTemplates = {
|
|||||||
},
|
},
|
||||||
'cra/default-ts': {
|
'cra/default-ts': {
|
||||||
name: 'Create React App (Typescript)',
|
name: 'Create React App (Typescript)',
|
||||||
script: 'npx create-react-app . --template typescript',
|
script: 'npx create-react-app {{beforeDir}} --template typescript',
|
||||||
cadence: ['ci', 'daily', 'weekly'],
|
cadence: ['ci', 'daily', 'weekly'],
|
||||||
// Re-enable once https://github.com/storybookjs/storybook/issues/19351 is fixed.
|
// Re-enable once https://github.com/storybookjs/storybook/issues/19351 is fixed.
|
||||||
skipTasks: ['smoke-test'],
|
skipTasks: ['smoke-test'],
|
||||||
@ -26,7 +26,7 @@ const craTemplates = {
|
|||||||
const reactViteTemplates = {
|
const reactViteTemplates = {
|
||||||
'react-vite/default-js': {
|
'react-vite/default-js': {
|
||||||
name: 'React Vite (JS)',
|
name: 'React Vite (JS)',
|
||||||
script: 'yarn create vite . --template react',
|
script: 'yarn create vite {{beforeDir}} --template react',
|
||||||
cadence: ['ci', 'daily', 'weekly'],
|
cadence: ['ci', 'daily', 'weekly'],
|
||||||
expected: {
|
expected: {
|
||||||
framework: '@storybook/react-vite',
|
framework: '@storybook/react-vite',
|
||||||
@ -36,7 +36,7 @@ const reactViteTemplates = {
|
|||||||
},
|
},
|
||||||
'react-vite/default-ts': {
|
'react-vite/default-ts': {
|
||||||
name: 'React Vite (TS)',
|
name: 'React Vite (TS)',
|
||||||
script: 'yarn create vite . --template react-ts',
|
script: 'yarn create vite {{beforeDir}} --template react-ts',
|
||||||
cadence: ['ci', 'daily', 'weekly'],
|
cadence: ['ci', 'daily', 'weekly'],
|
||||||
expected: {
|
expected: {
|
||||||
framework: '@storybook/react-vite',
|
framework: '@storybook/react-vite',
|
||||||
@ -49,7 +49,7 @@ const reactViteTemplates = {
|
|||||||
const reactWebpackTemplates = {
|
const reactWebpackTemplates = {
|
||||||
'react-webpack/18-ts': {
|
'react-webpack/18-ts': {
|
||||||
name: 'React Webpack5 (TS)',
|
name: 'React Webpack5 (TS)',
|
||||||
script: 'yarn create webpack5-react .',
|
script: 'yarn create webpack5-react {{beforeDir}}',
|
||||||
cadence: ['ci', 'daily', 'weekly'],
|
cadence: ['ci', 'daily', 'weekly'],
|
||||||
expected: {
|
expected: {
|
||||||
framework: '@storybook/react-webpack5',
|
framework: '@storybook/react-webpack5',
|
||||||
@ -59,7 +59,8 @@ const reactWebpackTemplates = {
|
|||||||
},
|
},
|
||||||
'react-webpack/17-ts': {
|
'react-webpack/17-ts': {
|
||||||
name: 'React Webpack5 (TS)',
|
name: 'React Webpack5 (TS)',
|
||||||
script: 'yarn create webpack5-react . --version-react="17" --version-react-dom="17"',
|
script:
|
||||||
|
'yarn create webpack5-react {{beforeDir}} --version-react="17" --version-react-dom="17"',
|
||||||
cadence: ['ci', 'daily', 'weekly'],
|
cadence: ['ci', 'daily', 'weekly'],
|
||||||
expected: {
|
expected: {
|
||||||
framework: '@storybook/react-webpack5',
|
framework: '@storybook/react-webpack5',
|
||||||
@ -72,7 +73,7 @@ const reactWebpackTemplates = {
|
|||||||
const vue3ViteTemplates = {
|
const vue3ViteTemplates = {
|
||||||
'vue3-vite/default-js': {
|
'vue3-vite/default-js': {
|
||||||
name: 'Vue3 Vite (JS)',
|
name: 'Vue3 Vite (JS)',
|
||||||
script: 'yarn create vite . --template vue',
|
script: 'yarn create vite {{beforeDir}} --template vue',
|
||||||
cadence: ['ci', 'daily', 'weekly'],
|
cadence: ['ci', 'daily', 'weekly'],
|
||||||
expected: {
|
expected: {
|
||||||
framework: '@storybook/vue3-vite',
|
framework: '@storybook/vue3-vite',
|
||||||
@ -82,7 +83,7 @@ const vue3ViteTemplates = {
|
|||||||
},
|
},
|
||||||
'vue3-vite/default-ts': {
|
'vue3-vite/default-ts': {
|
||||||
name: 'Vue3 Vite (TS)',
|
name: 'Vue3 Vite (TS)',
|
||||||
script: 'yarn create vite . --template vue-ts',
|
script: 'yarn create vite {{beforeDir}} --template vue-ts',
|
||||||
cadence: ['ci', 'daily', 'weekly'],
|
cadence: ['ci', 'daily', 'weekly'],
|
||||||
expected: {
|
expected: {
|
||||||
framework: '@storybook/vue3-vite',
|
framework: '@storybook/vue3-vite',
|
||||||
@ -99,7 +100,7 @@ const vue2ViteTemplates = {
|
|||||||
// We don't really want to maintain weird custom scripts like this,
|
// We don't really want to maintain weird custom scripts like this,
|
||||||
// preferring community bootstrap scripts / generators instead.
|
// preferring community bootstrap scripts / generators instead.
|
||||||
script:
|
script:
|
||||||
'yarn create vite . --template vanilla && yarn add --dev @vitejs/plugin-vue2 vue-template-compiler vue@2 && echo "import vue2 from \'@vitejs/plugin-vue2\';\n\nexport default {\n\tplugins: [vue2()]\n};" > vite.config.js',
|
'yarn create vite {{beforeDir}} --template vanilla && yarn add --dev @vitejs/plugin-vue2 vue-template-compiler vue@2 && echo "import vue2 from \'@vitejs/plugin-vue2\';\n\nexport default {\n\tplugins: [vue2()]\n};" > vite.config.js',
|
||||||
cadence: ['ci', 'daily', 'weekly'],
|
cadence: ['ci', 'daily', 'weekly'],
|
||||||
expected: {
|
expected: {
|
||||||
framework: '@storybook/vue2-vite',
|
framework: '@storybook/vue2-vite',
|
||||||
@ -112,7 +113,7 @@ const vue2ViteTemplates = {
|
|||||||
const htmlWebpackTemplates = {
|
const htmlWebpackTemplates = {
|
||||||
'html-webpack/default': {
|
'html-webpack/default': {
|
||||||
name: 'HTML Webpack5',
|
name: 'HTML Webpack5',
|
||||||
script: 'yarn create webpack5-html .',
|
script: 'yarn create webpack5-html {{beforeDir}}',
|
||||||
cadence: ['ci', 'daily', 'weekly'],
|
cadence: ['ci', 'daily', 'weekly'],
|
||||||
expected: {
|
expected: {
|
||||||
framework: '@storybook/html-webpack5',
|
framework: '@storybook/html-webpack5',
|
||||||
@ -125,7 +126,7 @@ const htmlWebpackTemplates = {
|
|||||||
const svelteViteTemplates = {
|
const svelteViteTemplates = {
|
||||||
'svelte-vite/default-js': {
|
'svelte-vite/default-js': {
|
||||||
name: 'Svelte Vite (JS)',
|
name: 'Svelte Vite (JS)',
|
||||||
script: 'yarn create vite . --template svelte',
|
script: 'yarn create vite {{beforeDir}} --template svelte',
|
||||||
cadence: ['ci', 'daily', 'weekly'],
|
cadence: ['ci', 'daily', 'weekly'],
|
||||||
expected: {
|
expected: {
|
||||||
framework: '@storybook/svelte-vite',
|
framework: '@storybook/svelte-vite',
|
||||||
@ -135,7 +136,7 @@ const svelteViteTemplates = {
|
|||||||
},
|
},
|
||||||
'svelte-vite/default-ts': {
|
'svelte-vite/default-ts': {
|
||||||
name: 'Svelte Vite (TS)',
|
name: 'Svelte Vite (TS)',
|
||||||
script: 'yarn create vite . --template svelte-ts',
|
script: 'yarn create vite {{beforeDir}} --template svelte-ts',
|
||||||
cadence: ['ci', 'daily', 'weekly'],
|
cadence: ['ci', 'daily', 'weekly'],
|
||||||
expected: {
|
expected: {
|
||||||
framework: '@storybook/svelte-vite',
|
framework: '@storybook/svelte-vite',
|
||||||
@ -148,7 +149,7 @@ const svelteViteTemplates = {
|
|||||||
const litViteTemplates = {
|
const litViteTemplates = {
|
||||||
'lit-vite/default-js': {
|
'lit-vite/default-js': {
|
||||||
name: 'Lit Vite (JS)',
|
name: 'Lit Vite (JS)',
|
||||||
script: 'yarn create vite . --template lit',
|
script: 'yarn create vite {{beforeDir}} --template lit',
|
||||||
cadence: ['ci', 'daily', 'weekly'] as any,
|
cadence: ['ci', 'daily', 'weekly'] as any,
|
||||||
// Re-enable once https://github.com/storybookjs/storybook/issues/19351 is fixed.
|
// Re-enable once https://github.com/storybookjs/storybook/issues/19351 is fixed.
|
||||||
skipTasks: ['smoke-test'],
|
skipTasks: ['smoke-test'],
|
||||||
@ -160,7 +161,7 @@ const litViteTemplates = {
|
|||||||
},
|
},
|
||||||
'lit-vite/default-ts': {
|
'lit-vite/default-ts': {
|
||||||
name: 'Lit Vite (TS)',
|
name: 'Lit Vite (TS)',
|
||||||
script: 'yarn create vite . --template lit-ts',
|
script: 'yarn create vite {{beforeDir}} --template lit-ts',
|
||||||
cadence: ['ci', 'daily', 'weekly'] as any,
|
cadence: ['ci', 'daily', 'weekly'] as any,
|
||||||
// Re-enable once https://github.com/storybookjs/storybook/issues/19351 is fixed.
|
// Re-enable once https://github.com/storybookjs/storybook/issues/19351 is fixed.
|
||||||
skipTasks: ['smoke-test'],
|
skipTasks: ['smoke-test'],
|
||||||
@ -175,7 +176,8 @@ const litViteTemplates = {
|
|||||||
const vueCliTemplates = {
|
const vueCliTemplates = {
|
||||||
'vue-cli/default-js': {
|
'vue-cli/default-js': {
|
||||||
name: 'Vue-CLI (Default JS)',
|
name: 'Vue-CLI (Default JS)',
|
||||||
script: 'npx -p @vue/cli vue create . --default --packageManager=yarn --force --merge',
|
script:
|
||||||
|
'npx -p @vue/cli vue create {{beforeDir}} --default --packageManager=yarn --force --merge',
|
||||||
cadence: ['ci', 'daily', 'weekly'],
|
cadence: ['ci', 'daily', 'weekly'],
|
||||||
// Re-enable once https://github.com/storybookjs/storybook/issues/19351 is fixed.
|
// Re-enable once https://github.com/storybookjs/storybook/issues/19351 is fixed.
|
||||||
skipTasks: ['smoke-test'],
|
skipTasks: ['smoke-test'],
|
||||||
@ -188,7 +190,7 @@ const vueCliTemplates = {
|
|||||||
'vue-cli/vue2-default-js': {
|
'vue-cli/vue2-default-js': {
|
||||||
name: 'Vue-CLI (Vue2 JS)',
|
name: 'Vue-CLI (Vue2 JS)',
|
||||||
script:
|
script:
|
||||||
'npx -p @vue/cli vue create . --default --packageManager=yarn --force --merge --preset=Default\\ (Vue\\ 2)',
|
'npx -p @vue/cli vue create {{beforeDir}} --default --packageManager=yarn --force --merge --preset=Default\\ (Vue\\ 2)',
|
||||||
cadence: ['ci', 'daily', 'weekly'],
|
cadence: ['ci', 'daily', 'weekly'],
|
||||||
// Re-enable once https://github.com/storybookjs/storybook/issues/19351 is fixed.
|
// Re-enable once https://github.com/storybookjs/storybook/issues/19351 is fixed.
|
||||||
skipTasks: ['smoke-test'],
|
skipTasks: ['smoke-test'],
|
||||||
@ -200,6 +202,31 @@ const vueCliTemplates = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const preactWebpackTemplates = {
|
||||||
|
'preact-webpack5/default-js': {
|
||||||
|
name: 'Preact CLI (Default JS)',
|
||||||
|
script: 'npx preact-cli create default {{beforeDir}} --name preact-app --yarn --no-install',
|
||||||
|
// cadence: ['ci', 'daily', 'weekly'],
|
||||||
|
cadence: [] as string[],
|
||||||
|
expected: {
|
||||||
|
framework: '@storybook/preact-webpack5',
|
||||||
|
renderer: '@storybook/preact',
|
||||||
|
builder: '@storybook/builder-webpack5',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'preact-webpack5/default-ts': {
|
||||||
|
name: 'Preact CLI (Default TS)',
|
||||||
|
script: 'npx preact-cli create typescript {{beforeDir}} --name preact-app --yarn --no-install',
|
||||||
|
// cadence: ['ci', 'daily', 'weekly'],
|
||||||
|
cadence: [] as string[],
|
||||||
|
expected: {
|
||||||
|
framework: '@storybook/preact-webpack5',
|
||||||
|
renderer: '@storybook/preact',
|
||||||
|
builder: '@storybook/builder-webpack5',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
...craTemplates,
|
...craTemplates,
|
||||||
...reactWebpackTemplates,
|
...reactWebpackTemplates,
|
||||||
@ -210,6 +237,7 @@ export default {
|
|||||||
...litViteTemplates,
|
...litViteTemplates,
|
||||||
...vueCliTemplates,
|
...vueCliTemplates,
|
||||||
...htmlWebpackTemplates,
|
...htmlWebpackTemplates,
|
||||||
|
...preactWebpackTemplates,
|
||||||
// FIXME: missing documentation.json
|
// FIXME: missing documentation.json
|
||||||
// 'angular/latest': {
|
// 'angular/latest': {
|
||||||
// name: 'Angular (latest)',
|
// name: 'Angular (latest)',
|
||||||
|
@ -14,7 +14,7 @@ export const babel: StorybookConfig['babelDefault'] = (config) => {
|
|||||||
...(config.plugins || []).filter((p) => {
|
...(config.plugins || []).filter((p) => {
|
||||||
const name = Array.isArray(p) ? p[0] : p;
|
const name = Array.isArray(p) ? p[0] : p;
|
||||||
if (typeof name === 'string') {
|
if (typeof name === 'string') {
|
||||||
return !name.includes('babel-plugin-transform-react-jsx');
|
return !name.includes('plugin-transform-react-jsx');
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}),
|
}),
|
||||||
@ -23,20 +23,6 @@ export const babel: StorybookConfig['babelDefault'] = (config) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const webpackFinal: StorybookConfig['webpackFinal'] = (config) => {
|
export const webpackFinal: StorybookConfig['webpackFinal'] = (config) => {
|
||||||
const rules = config.module?.rules || [];
|
|
||||||
const tsxRule = rules.find((rule) => (rule.test as RegExp).test?.('main.tsx'));
|
|
||||||
tsxRule.use = (tsxRule.use as any).map((entry: any) => {
|
|
||||||
let newPlugins = entry.options.plugins;
|
|
||||||
if (entry.loader?.includes('babel-loader')) {
|
|
||||||
newPlugins = (entry.options as any).plugins.map((plugin: any) => {
|
|
||||||
if (plugin[0]?.includes?.('@babel/plugin-transform-react-jsx')) {
|
|
||||||
return [plugin[0], { importSource: 'preact', runtime: 'automatic' }];
|
|
||||||
}
|
|
||||||
return plugin;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return { ...entry, options: { ...entry.options, plugins: newPlugins } };
|
|
||||||
});
|
|
||||||
return {
|
return {
|
||||||
...config,
|
...config,
|
||||||
resolve: {
|
resolve: {
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
export { renderToDOM } from './render';
|
export { renderToDOM, render } from './render';
|
||||||
|
|
||||||
export const parameters = { framework: 'preact' as const };
|
export const parameters = { framework: 'preact' as const };
|
||||||
|
@ -1,8 +1,26 @@
|
|||||||
|
/** @jsx h */
|
||||||
import * as preact from 'preact';
|
import * as preact from 'preact';
|
||||||
import { dedent } from 'ts-dedent';
|
import { dedent } from 'ts-dedent';
|
||||||
import type { RenderContext } from '@storybook/store';
|
import type { RenderContext } from '@storybook/store';
|
||||||
|
import { ArgsStoryFn } from '@storybook/csf';
|
||||||
|
|
||||||
import type { StoryFnPreactReturnType, PreactFramework } from './types';
|
import type { StoryFnPreactReturnType, PreactFramework } from './types';
|
||||||
|
|
||||||
|
const { h } = preact;
|
||||||
|
|
||||||
|
export const render: ArgsStoryFn<PreactFramework> = (args, context) => {
|
||||||
|
const { id, component: Component } = context;
|
||||||
|
if (!Component) {
|
||||||
|
throw new Error(
|
||||||
|
`Unable to render story ${id} as the component annotation is missing from the default export`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @ts-expect-error I think the type of Component should be Preact.ComponentType, but even that
|
||||||
|
// doens't make TS happy, I suspect because TS wants "react" components.
|
||||||
|
return <Component {...args} />;
|
||||||
|
};
|
||||||
|
|
||||||
let renderedStory: Element;
|
let renderedStory: Element;
|
||||||
|
|
||||||
function preactRender(story: StoryFnPreactReturnType | null, domElement: Element): void {
|
function preactRender(story: StoryFnPreactReturnType | null, domElement: Element): void {
|
||||||
|
14
code/renderers/preact/template/components/Button.jsx
Normal file
14
code/renderers/preact/template/components/Button.jsx
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/* eslint-disable react/react-in-jsx-scope */
|
||||||
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
export const Button = ({ onClick, children }) => (
|
||||||
|
<button type="button" onClick={onClick}>
|
||||||
|
{children}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
|
||||||
|
Button.propTypes = {
|
||||||
|
onClick: PropTypes.func.isRequired,
|
||||||
|
children: PropTypes.node.isRequired,
|
||||||
|
};
|
38
code/renderers/preact/template/components/Form.jsx
Normal file
38
code/renderers/preact/template/components/Form.jsx
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/* eslint-disable react/react-in-jsx-scope */
|
||||||
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { useState } from 'preact/hooks';
|
||||||
|
|
||||||
|
export const Form = ({ onSuccess }) => {
|
||||||
|
const [value, setValue] = useState('');
|
||||||
|
const [complete, setComplete] = useState(false);
|
||||||
|
|
||||||
|
function onSubmit(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
onSuccess(value);
|
||||||
|
|
||||||
|
setTimeout(() => setComplete(true), 500);
|
||||||
|
setTimeout(() => setComplete(false), 1500);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form id="interaction-test-form" onSubmit={onSubmit}>
|
||||||
|
<label>
|
||||||
|
Enter Value
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
data-testid="value"
|
||||||
|
value={value}
|
||||||
|
required
|
||||||
|
onChange={(event) => setValue(event.target.value)}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<button type="submit">Submit</button>
|
||||||
|
{complete && <p>Completed!!</p>}
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
Form.propTypes = {
|
||||||
|
onSuccess: PropTypes.func.isRequired,
|
||||||
|
};
|
10
code/renderers/preact/template/components/Html.jsx
Normal file
10
code/renderers/preact/template/components/Html.jsx
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/* eslint-disable react/react-in-jsx-scope */
|
||||||
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
// eslint-disable-next-line react/no-danger
|
||||||
|
export const Html = ({ content }) => <div dangerouslySetInnerHTML={{ __html: content }} />;
|
||||||
|
|
||||||
|
Html.propTypes = {
|
||||||
|
content: PropTypes.string.isRequired,
|
||||||
|
};
|
21
code/renderers/preact/template/components/Pre.jsx
Normal file
21
code/renderers/preact/template/components/Pre.jsx
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* eslint-disable react/react-in-jsx-scope */
|
||||||
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
export const Pre = ({ style, object, text }) => (
|
||||||
|
<pre style={style} data-testid="pre">
|
||||||
|
{object ? JSON.stringify(object, null, 2) : text}
|
||||||
|
</pre>
|
||||||
|
);
|
||||||
|
|
||||||
|
Pre.propTypes = {
|
||||||
|
style: PropTypes.shape({}),
|
||||||
|
object: PropTypes.shape({}),
|
||||||
|
text: PropTypes.string,
|
||||||
|
};
|
||||||
|
|
||||||
|
Pre.defaultProps = {
|
||||||
|
style: {},
|
||||||
|
object: null,
|
||||||
|
text: '',
|
||||||
|
};
|
9
code/renderers/preact/template/components/index.js
Normal file
9
code/renderers/preact/template/components/index.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import globalThis from 'global';
|
||||||
|
|
||||||
|
import { Button } from './Button.jsx';
|
||||||
|
import { Pre } from './Pre.jsx';
|
||||||
|
import { Form } from './Form.jsx';
|
||||||
|
import { Html } from './Html.jsx';
|
||||||
|
|
||||||
|
globalThis.Components = { Button, Pre, Form, Html };
|
||||||
|
globalThis.storybookRenderer = 'preact';
|
0
code/renderers/preact/template/stories/.gitkeep
Normal file
0
code/renderers/preact/template/stories/.gitkeep
Normal file
@ -84,7 +84,7 @@ export const runCommand = async (script: string, options: ExecaOptions) => {
|
|||||||
console.log(`Running command: ${script}`);
|
console.log(`Running command: ${script}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return command(script, { stdout: shouldDebug ? 'inherit' : 'ignore', ...options });
|
return command(script, { stdout: shouldDebug ? 'inherit' : 'ignore', shell: true, ...options });
|
||||||
};
|
};
|
||||||
|
|
||||||
const addDocumentation = async (
|
const addDocumentation = async (
|
||||||
@ -133,13 +133,11 @@ const runGenerators = async (
|
|||||||
|
|
||||||
// We do the creation inside a temp dir to avoid yarn container problems
|
// We do the creation inside a temp dir to avoid yarn container problems
|
||||||
const createBaseDir = directory();
|
const createBaseDir = directory();
|
||||||
const createBeforeDir = join(createBaseDir, BEFORE_DIR_NAME);
|
|
||||||
|
|
||||||
await ensureDir(createBeforeDir);
|
|
||||||
|
|
||||||
await setupYarn({ cwd: createBaseDir });
|
await setupYarn({ cwd: createBaseDir });
|
||||||
|
|
||||||
await runCommand(script, { cwd: createBeforeDir });
|
const createBeforeDir = join(createBaseDir, BEFORE_DIR_NAME);
|
||||||
|
const scriptWithBeforeDir = script.replace('{{beforeDir}}', createBeforeDir);
|
||||||
|
await runCommand(scriptWithBeforeDir, { cwd: createBaseDir });
|
||||||
|
|
||||||
await localizeYarnConfigFiles(createBaseDir, createBeforeDir);
|
await localizeYarnConfigFiles(createBaseDir, createBeforeDir);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user