create-rslib 0.0.14 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +141 -9
- package/package.json +10 -7
- package/template-[node-dual]-[]-js/src/index.js +1 -0
- package/{template-node-dual-ts → template-[node-dual]-[]-ts}/package.json +1 -0
- package/template-[node-dual]-[]-ts/rslib.config.ts +16 -0
- package/template-[node-dual]-[]-ts/src/index.ts +1 -0
- package/{template-node-dual-ts → template-[node-dual]-[]-ts}/tsconfig.json +1 -2
- package/template-[node-dual]-[vitest]-js/package.json +25 -0
- package/{template-node-dual-ts/rslib.config.ts → template-[node-dual]-[vitest]-js/rslib.config.mjs} +0 -1
- package/template-[node-dual]-[vitest]-js/src/index.js +1 -0
- package/template-[node-dual]-[vitest]-js/tests/index.test.js +7 -0
- package/template-[node-dual]-[vitest]-js/vitest.config.js +8 -0
- package/template-[node-dual]-[vitest]-ts/package.json +29 -0
- package/template-[node-dual]-[vitest]-ts/rslib.config.ts +16 -0
- package/template-[node-dual]-[vitest]-ts/src/index.ts +1 -0
- package/template-[node-dual]-[vitest]-ts/tests/index.test.ts +7 -0
- package/{template-node-esm-ts → template-[node-dual]-[vitest]-ts}/tsconfig.json +1 -2
- package/template-[node-dual]-[vitest]-ts/vitest.config.ts +6 -0
- package/template-[node-esm]-[]-js/src/index.js +1 -0
- package/{template-node-esm-ts → template-[node-esm]-[]-ts}/package.json +1 -0
- package/template-[node-esm]-[]-ts/rslib.config.ts +12 -0
- package/template-[node-esm]-[]-ts/src/index.ts +1 -0
- package/template-[node-esm]-[]-ts/tsconfig.json +15 -0
- package/template-[node-esm]-[vitest]-js/package.json +23 -0
- package/{template-node-esm-ts/rslib.config.ts → template-[node-esm]-[vitest]-js/rslib.config.mjs} +0 -1
- package/template-[node-esm]-[vitest]-js/src/index.js +1 -0
- package/template-[node-esm]-[vitest]-js/tests/index.test.js +7 -0
- package/template-[node-esm]-[vitest]-js/vitest.config.js +8 -0
- package/template-[node-esm]-[vitest]-ts/package.json +27 -0
- package/template-[node-esm]-[vitest]-ts/rslib.config.ts +12 -0
- package/template-[node-esm]-[vitest]-ts/src/index.ts +1 -0
- package/template-[node-esm]-[vitest]-ts/tests/index.test.ts +7 -0
- package/template-[node-esm]-[vitest]-ts/tsconfig.json +15 -0
- package/template-[node-esm]-[vitest]-ts/vitest.config.ts +6 -0
- package/template-[react]-[]-js/package.json +27 -0
- package/template-[react]-[]-js/rslib.config.mjs +23 -0
- package/template-[react]-[]-js/src/Button.jsx +22 -0
- package/template-[react]-[]-js/src/button.css +34 -0
- package/template-[react]-[]-js/src/index.jsx +1 -0
- package/template-[react]-[]-ts/package.json +31 -0
- package/template-[react]-[]-ts/rslib.config.ts +24 -0
- package/template-[react]-[]-ts/src/Button.tsx +30 -0
- package/template-[react]-[]-ts/src/button.css +34 -0
- package/template-[react]-[]-ts/src/index.tsx +1 -0
- package/template-[react]-[]-ts/tsconfig.json +14 -0
- package/template-[react]-[storybook,vitest]-js/.storybook/main.js +36 -0
- package/template-[react]-[storybook,vitest]-js/.storybook/preview.js +12 -0
- package/template-[react]-[storybook,vitest]-js/package.json +45 -0
- package/template-[react]-[storybook,vitest]-js/rslib.config.mjs +23 -0
- package/template-[react]-[storybook,vitest]-js/src/Button.jsx +22 -0
- package/template-[react]-[storybook,vitest]-js/src/button.css +34 -0
- package/template-[react]-[storybook,vitest]-js/src/index.jsx +1 -0
- package/template-[react]-[storybook,vitest]-js/stories/Button.stories.jsx +50 -0
- package/template-[react]-[storybook,vitest]-js/tests/index.test.jsx +12 -0
- package/template-[react]-[storybook,vitest]-js/vitest.config.js +11 -0
- package/template-[react]-[storybook,vitest]-js/vitest.setup.js +1 -0
- package/template-[react]-[storybook,vitest]-ts/.storybook/main.ts +37 -0
- package/template-[react]-[storybook,vitest]-ts/.storybook/preview.ts +14 -0
- package/template-[react]-[storybook,vitest]-ts/package.json +49 -0
- package/template-[react]-[storybook,vitest]-ts/rslib.config.ts +24 -0
- package/template-[react]-[storybook,vitest]-ts/src/Button.tsx +30 -0
- package/template-[react]-[storybook,vitest]-ts/src/button.css +34 -0
- package/template-[react]-[storybook,vitest]-ts/src/index.tsx +1 -0
- package/template-[react]-[storybook,vitest]-ts/stories/Button.stories.ts +52 -0
- package/template-[react]-[storybook,vitest]-ts/tests/index.test.tsx +12 -0
- package/template-[react]-[storybook,vitest]-ts/tsconfig.json +14 -0
- package/template-[react]-[storybook,vitest]-ts/vitest.config.ts +9 -0
- package/template-[react]-[storybook,vitest]-ts/vitest.setup.ts +1 -0
- package/template-[react]-[storybook]-js/.storybook/main.js +36 -0
- package/template-[react]-[storybook]-js/.storybook/preview.js +12 -0
- package/template-[react]-[storybook]-js/package.json +40 -0
- package/template-[react]-[storybook]-js/rslib.config.mjs +23 -0
- package/template-[react]-[storybook]-js/src/Button.jsx +22 -0
- package/template-[react]-[storybook]-js/src/button.css +34 -0
- package/template-[react]-[storybook]-js/src/index.jsx +1 -0
- package/template-[react]-[storybook]-js/stories/Button.stories.jsx +50 -0
- package/template-[react]-[storybook]-ts/.storybook/main.ts +37 -0
- package/template-[react]-[storybook]-ts/.storybook/preview.ts +14 -0
- package/template-[react]-[storybook]-ts/package.json +44 -0
- package/template-[react]-[storybook]-ts/rslib.config.ts +24 -0
- package/template-[react]-[storybook]-ts/src/Button.tsx +30 -0
- package/template-[react]-[storybook]-ts/src/button.css +34 -0
- package/template-[react]-[storybook]-ts/src/index.tsx +1 -0
- package/template-[react]-[storybook]-ts/stories/Button.stories.ts +52 -0
- package/template-[react]-[storybook]-ts/tsconfig.json +14 -0
- package/template-[react]-[vitest]-js/package.json +32 -0
- package/template-[react]-[vitest]-js/rslib.config.mjs +23 -0
- package/template-[react]-[vitest]-js/src/Button.jsx +22 -0
- package/template-[react]-[vitest]-js/src/button.css +34 -0
- package/template-[react]-[vitest]-js/src/index.jsx +1 -0
- package/template-[react]-[vitest]-js/tests/index.test.jsx +12 -0
- package/template-[react]-[vitest]-js/vitest.config.js +11 -0
- package/template-[react]-[vitest]-js/vitest.setup.js +1 -0
- package/template-[react]-[vitest]-ts/package.json +36 -0
- package/template-[react]-[vitest]-ts/rslib.config.ts +24 -0
- package/template-[react]-[vitest]-ts/src/Button.tsx +30 -0
- package/template-[react]-[vitest]-ts/src/button.css +34 -0
- package/template-[react]-[vitest]-ts/src/index.tsx +1 -0
- package/template-[react]-[vitest]-ts/tests/index.test.tsx +12 -0
- package/template-[react]-[vitest]-ts/tsconfig.json +14 -0
- package/template-[react]-[vitest]-ts/vitest.config.ts +9 -0
- package/template-[react]-[vitest]-ts/vitest.setup.ts +1 -0
- package/template-common/README.md +1 -1
- package/template-node-dual-js/src/index.js +0 -3
- package/template-node-dual-ts/src/index.ts +0 -3
- package/template-node-esm-js/src/index.js +0 -3
- package/template-node-esm-ts/src/index.ts +0 -3
- /package/{template-node-dual-js → template-[node-dual]-[]-js}/package.json +0 -0
- /package/{template-node-dual-js → template-[node-dual]-[]-js}/rslib.config.mjs +0 -0
- /package/{template-node-esm-js → template-[node-esm]-[]-js}/package.json +0 -0
- /package/{template-node-esm-js → template-[node-esm]-[]-js}/rslib.config.mjs +0 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { fn } from '@storybook/test';
|
|
3
|
+
import { Button } from '../src/Button';
|
|
4
|
+
|
|
5
|
+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
|
|
6
|
+
const meta = {
|
|
7
|
+
title: 'Example/Button',
|
|
8
|
+
component: Button,
|
|
9
|
+
parameters: {
|
|
10
|
+
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
|
|
11
|
+
layout: 'centered',
|
|
12
|
+
},
|
|
13
|
+
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
|
14
|
+
tags: ['autodocs'],
|
|
15
|
+
// More on argTypes: https://storybook.js.org/docs/api/argtypes
|
|
16
|
+
argTypes: {
|
|
17
|
+
backgroundColor: { control: 'color' },
|
|
18
|
+
},
|
|
19
|
+
// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
|
|
20
|
+
args: { onClick: fn() },
|
|
21
|
+
} satisfies Meta<typeof Button>;
|
|
22
|
+
|
|
23
|
+
export default meta;
|
|
24
|
+
type Story = StoryObj<typeof meta>;
|
|
25
|
+
|
|
26
|
+
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
|
|
27
|
+
export const Primary: Story = {
|
|
28
|
+
args: {
|
|
29
|
+
primary: true,
|
|
30
|
+
label: 'Button',
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const Secondary: Story = {
|
|
35
|
+
args: {
|
|
36
|
+
label: 'Button',
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const Large: Story = {
|
|
41
|
+
args: {
|
|
42
|
+
size: 'large',
|
|
43
|
+
label: 'Button',
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const Small: Story = {
|
|
48
|
+
args: {
|
|
49
|
+
size: 'small',
|
|
50
|
+
label: 'Button',
|
|
51
|
+
},
|
|
52
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { expect, test } from 'vitest';
|
|
4
|
+
import { Button } from '../src/Button';
|
|
5
|
+
|
|
6
|
+
test('The button should have correct background color', async () => {
|
|
7
|
+
render(<Button backgroundColor="#ccc" label="Demo Button" />);
|
|
8
|
+
const button = screen.getByText('Demo Button');
|
|
9
|
+
expect(button).toHaveStyle({
|
|
10
|
+
backgroundColor: '#ccc',
|
|
11
|
+
});
|
|
12
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"lib": ["DOM", "ES2021"],
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"jsx": "react",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"isolatedModules": true,
|
|
9
|
+
"resolveJsonModule": true,
|
|
10
|
+
"moduleResolution": "bundler",
|
|
11
|
+
"useDefineForClassFields": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src"]
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom/vitest';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { dirname, join } from 'node:path';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This function is used to resolve the absolute path of a package.
|
|
5
|
+
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
|
|
6
|
+
*/
|
|
7
|
+
function getAbsolutePath(value) {
|
|
8
|
+
return dirname(require.resolve(join(value, 'package.json')));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const config = {
|
|
12
|
+
stories: [
|
|
13
|
+
'../stories/**/*.mdx',
|
|
14
|
+
'../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)',
|
|
15
|
+
],
|
|
16
|
+
addons: [
|
|
17
|
+
'@storybook/addon-onboarding',
|
|
18
|
+
'@storybook/addon-links',
|
|
19
|
+
'@storybook/addon-essentials',
|
|
20
|
+
'@storybook/addon-interactions',
|
|
21
|
+
'storybook-addon-rslib',
|
|
22
|
+
],
|
|
23
|
+
framework: {
|
|
24
|
+
name: getAbsolutePath('storybook-react-rsbuild'),
|
|
25
|
+
options: {},
|
|
26
|
+
},
|
|
27
|
+
docs: {
|
|
28
|
+
autodocs: 'tag',
|
|
29
|
+
},
|
|
30
|
+
typescript: {
|
|
31
|
+
reactDocgen: 'react-docgen-typescript',
|
|
32
|
+
check: true,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export default config;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rslib-react-js",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"import": "./dist/index.js"
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "rslib build",
|
|
16
|
+
"build:storybook": "storybook build",
|
|
17
|
+
"dev": "rslib build --watch",
|
|
18
|
+
"storybook": "storybook dev"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@rsbuild/core": "~1.0.19",
|
|
22
|
+
"@rsbuild/plugin-react": "^1.0.6",
|
|
23
|
+
"@rslib/core": "workspace:*",
|
|
24
|
+
"@storybook/addon-essentials": "^8.3.6",
|
|
25
|
+
"@storybook/addon-interactions": "^8.3.6",
|
|
26
|
+
"@storybook/addon-links": "^8.3.6",
|
|
27
|
+
"@storybook/addon-onboarding": "^8.3.6",
|
|
28
|
+
"@storybook/blocks": "^8.3.6",
|
|
29
|
+
"@storybook/react": "^8.3.6",
|
|
30
|
+
"@storybook/test": "^8.3.6",
|
|
31
|
+
"react": "^18.3.1",
|
|
32
|
+
"storybook": "^8.3.6",
|
|
33
|
+
"storybook-addon-rslib": "^0.1.2",
|
|
34
|
+
"storybook-react-rsbuild": "^0.1.2"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"react": ">=16.9.0",
|
|
38
|
+
"react-dom": ">=16.9.0"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { pluginReact } from '@rsbuild/plugin-react';
|
|
2
|
+
import { defineConfig } from '@rslib/core';
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
source: {
|
|
6
|
+
entry: {
|
|
7
|
+
index: ['./src/**'],
|
|
8
|
+
},
|
|
9
|
+
},
|
|
10
|
+
lib: [
|
|
11
|
+
{
|
|
12
|
+
bundle: false,
|
|
13
|
+
format: 'esm',
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
plugins: [
|
|
17
|
+
pluginReact({
|
|
18
|
+
swcReactOptions: {
|
|
19
|
+
runtime: 'classic',
|
|
20
|
+
},
|
|
21
|
+
}),
|
|
22
|
+
],
|
|
23
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './button.css';
|
|
3
|
+
|
|
4
|
+
export const Button = ({
|
|
5
|
+
primary = false,
|
|
6
|
+
size = 'medium',
|
|
7
|
+
backgroundColor,
|
|
8
|
+
label,
|
|
9
|
+
...props
|
|
10
|
+
}) => {
|
|
11
|
+
const mode = primary ? 'demo-button--primary' : 'demo-button--secondary';
|
|
12
|
+
return (
|
|
13
|
+
<button
|
|
14
|
+
type="button"
|
|
15
|
+
className={['demo-button', `demo-button--${size}`, mode].join(' ')}
|
|
16
|
+
style={{ backgroundColor }}
|
|
17
|
+
{...props}
|
|
18
|
+
>
|
|
19
|
+
{label}
|
|
20
|
+
</button>
|
|
21
|
+
);
|
|
22
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
.demo-button {
|
|
2
|
+
font-weight: 700;
|
|
3
|
+
border: 0;
|
|
4
|
+
border-radius: 3em;
|
|
5
|
+
cursor: pointer;
|
|
6
|
+
display: inline-block;
|
|
7
|
+
line-height: 1;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.demo-button--primary {
|
|
11
|
+
color: white;
|
|
12
|
+
background-color: #1ea7fd;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.demo-button--secondary {
|
|
16
|
+
color: #333;
|
|
17
|
+
background-color: transparent;
|
|
18
|
+
box-shadow: rgba(0, 0, 0, 0.15) 0px 0px 0px 1px inset;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.demo-button--small {
|
|
22
|
+
font-size: 12px;
|
|
23
|
+
padding: 10px 16px;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.demo-button--medium {
|
|
27
|
+
font-size: 14px;
|
|
28
|
+
padding: 11px 20px;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.demo-button--large {
|
|
32
|
+
font-size: 16px;
|
|
33
|
+
padding: 12px 24px;
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Button } from './Button';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { fn } from '@storybook/test';
|
|
2
|
+
import { Button } from '../src/Button';
|
|
3
|
+
|
|
4
|
+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
|
|
5
|
+
const meta = {
|
|
6
|
+
title: 'Example/Button',
|
|
7
|
+
component: Button,
|
|
8
|
+
parameters: {
|
|
9
|
+
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
|
|
10
|
+
layout: 'centered',
|
|
11
|
+
},
|
|
12
|
+
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
|
13
|
+
tags: ['autodocs'],
|
|
14
|
+
// More on argTypes: https://storybook.js.org/docs/api/argtypes
|
|
15
|
+
argTypes: {
|
|
16
|
+
backgroundColor: { control: 'color' },
|
|
17
|
+
},
|
|
18
|
+
// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
|
|
19
|
+
args: { onClick: fn() },
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default meta;
|
|
23
|
+
|
|
24
|
+
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
|
|
25
|
+
export const Primary = {
|
|
26
|
+
args: {
|
|
27
|
+
primary: true,
|
|
28
|
+
label: 'Button',
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const Secondary = {
|
|
33
|
+
args: {
|
|
34
|
+
label: 'Button',
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const Large = {
|
|
39
|
+
args: {
|
|
40
|
+
size: 'large',
|
|
41
|
+
label: 'Button',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const Small = {
|
|
46
|
+
args: {
|
|
47
|
+
size: 'small',
|
|
48
|
+
label: 'Button',
|
|
49
|
+
},
|
|
50
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { dirname, join } from 'node:path';
|
|
2
|
+
import type { StorybookConfig } from 'storybook-react-rsbuild';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This function is used to resolve the absolute path of a package.
|
|
6
|
+
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
|
|
7
|
+
*/
|
|
8
|
+
function getAbsolutePath(value: string): any {
|
|
9
|
+
return dirname(require.resolve(join(value, 'package.json')));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const config: StorybookConfig = {
|
|
13
|
+
stories: [
|
|
14
|
+
'../stories/**/*.mdx',
|
|
15
|
+
'../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)',
|
|
16
|
+
],
|
|
17
|
+
addons: [
|
|
18
|
+
'@storybook/addon-onboarding',
|
|
19
|
+
'@storybook/addon-links',
|
|
20
|
+
'@storybook/addon-essentials',
|
|
21
|
+
'@storybook/addon-interactions',
|
|
22
|
+
'storybook-addon-rslib',
|
|
23
|
+
],
|
|
24
|
+
framework: {
|
|
25
|
+
name: getAbsolutePath('storybook-react-rsbuild'),
|
|
26
|
+
options: {},
|
|
27
|
+
},
|
|
28
|
+
docs: {
|
|
29
|
+
autodocs: 'tag',
|
|
30
|
+
},
|
|
31
|
+
typescript: {
|
|
32
|
+
reactDocgen: 'react-docgen-typescript',
|
|
33
|
+
check: true,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default config;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rslib-react-ts",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"import": "./dist/index.js"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"module": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "rslib build",
|
|
18
|
+
"build:storybook": "storybook build",
|
|
19
|
+
"dev": "rslib build --watch",
|
|
20
|
+
"storybook": "storybook dev"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@rsbuild/core": "~1.0.19",
|
|
24
|
+
"@rsbuild/plugin-react": "^1.0.6",
|
|
25
|
+
"@rslib/core": "workspace:*",
|
|
26
|
+
"@storybook/addon-essentials": "^8.3.6",
|
|
27
|
+
"@storybook/addon-interactions": "^8.3.6",
|
|
28
|
+
"@storybook/addon-links": "^8.3.6",
|
|
29
|
+
"@storybook/addon-onboarding": "^8.3.6",
|
|
30
|
+
"@storybook/blocks": "^8.3.6",
|
|
31
|
+
"@storybook/react": "^8.3.6",
|
|
32
|
+
"@storybook/test": "^8.3.6",
|
|
33
|
+
"@types/react": "^18.3.12",
|
|
34
|
+
"react": "^18.3.1",
|
|
35
|
+
"storybook": "^8.3.6",
|
|
36
|
+
"storybook-addon-rslib": "^0.1.2",
|
|
37
|
+
"storybook-react-rsbuild": "^0.1.2",
|
|
38
|
+
"typescript": "^5.6.3"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"react": ">=16.9.0",
|
|
42
|
+
"react-dom": ">=16.9.0"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { pluginReact } from '@rsbuild/plugin-react';
|
|
2
|
+
import { defineConfig } from '@rslib/core';
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
source: {
|
|
6
|
+
entry: {
|
|
7
|
+
index: ['./src/**'],
|
|
8
|
+
},
|
|
9
|
+
},
|
|
10
|
+
lib: [
|
|
11
|
+
{
|
|
12
|
+
bundle: false,
|
|
13
|
+
dts: true,
|
|
14
|
+
format: 'esm',
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
plugins: [
|
|
18
|
+
pluginReact({
|
|
19
|
+
swcReactOptions: {
|
|
20
|
+
runtime: 'classic',
|
|
21
|
+
},
|
|
22
|
+
}),
|
|
23
|
+
],
|
|
24
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './button.css';
|
|
3
|
+
|
|
4
|
+
interface ButtonProps {
|
|
5
|
+
primary?: boolean;
|
|
6
|
+
backgroundColor?: string;
|
|
7
|
+
size?: 'small' | 'medium' | 'large';
|
|
8
|
+
label: string;
|
|
9
|
+
onClick?: () => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const Button = ({
|
|
13
|
+
primary = false,
|
|
14
|
+
size = 'medium',
|
|
15
|
+
backgroundColor,
|
|
16
|
+
label,
|
|
17
|
+
...props
|
|
18
|
+
}: ButtonProps) => {
|
|
19
|
+
const mode = primary ? 'demo-button--primary' : 'demo-button--secondary';
|
|
20
|
+
return (
|
|
21
|
+
<button
|
|
22
|
+
type="button"
|
|
23
|
+
className={['demo-button', `demo-button--${size}`, mode].join(' ')}
|
|
24
|
+
style={{ backgroundColor }}
|
|
25
|
+
{...props}
|
|
26
|
+
>
|
|
27
|
+
{label}
|
|
28
|
+
</button>
|
|
29
|
+
);
|
|
30
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
.demo-button {
|
|
2
|
+
font-weight: 700;
|
|
3
|
+
border: 0;
|
|
4
|
+
border-radius: 3em;
|
|
5
|
+
cursor: pointer;
|
|
6
|
+
display: inline-block;
|
|
7
|
+
line-height: 1;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.demo-button--primary {
|
|
11
|
+
color: white;
|
|
12
|
+
background-color: #1ea7fd;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.demo-button--secondary {
|
|
16
|
+
color: #333;
|
|
17
|
+
background-color: transparent;
|
|
18
|
+
box-shadow: rgba(0, 0, 0, 0.15) 0px 0px 0px 1px inset;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.demo-button--small {
|
|
22
|
+
font-size: 12px;
|
|
23
|
+
padding: 10px 16px;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.demo-button--medium {
|
|
27
|
+
font-size: 14px;
|
|
28
|
+
padding: 11px 20px;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.demo-button--large {
|
|
32
|
+
font-size: 16px;
|
|
33
|
+
padding: 12px 24px;
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Button } from './Button';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { fn } from '@storybook/test';
|
|
3
|
+
import { Button } from '../src/Button';
|
|
4
|
+
|
|
5
|
+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
|
|
6
|
+
const meta = {
|
|
7
|
+
title: 'Example/Button',
|
|
8
|
+
component: Button,
|
|
9
|
+
parameters: {
|
|
10
|
+
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
|
|
11
|
+
layout: 'centered',
|
|
12
|
+
},
|
|
13
|
+
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
|
14
|
+
tags: ['autodocs'],
|
|
15
|
+
// More on argTypes: https://storybook.js.org/docs/api/argtypes
|
|
16
|
+
argTypes: {
|
|
17
|
+
backgroundColor: { control: 'color' },
|
|
18
|
+
},
|
|
19
|
+
// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
|
|
20
|
+
args: { onClick: fn() },
|
|
21
|
+
} satisfies Meta<typeof Button>;
|
|
22
|
+
|
|
23
|
+
export default meta;
|
|
24
|
+
type Story = StoryObj<typeof meta>;
|
|
25
|
+
|
|
26
|
+
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
|
|
27
|
+
export const Primary: Story = {
|
|
28
|
+
args: {
|
|
29
|
+
primary: true,
|
|
30
|
+
label: 'Button',
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const Secondary: Story = {
|
|
35
|
+
args: {
|
|
36
|
+
label: 'Button',
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const Large: Story = {
|
|
41
|
+
args: {
|
|
42
|
+
size: 'large',
|
|
43
|
+
label: 'Button',
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const Small: Story = {
|
|
48
|
+
args: {
|
|
49
|
+
size: 'small',
|
|
50
|
+
label: 'Button',
|
|
51
|
+
},
|
|
52
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"lib": ["DOM", "ES2021"],
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"jsx": "react",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"isolatedModules": true,
|
|
9
|
+
"resolveJsonModule": true,
|
|
10
|
+
"moduleResolution": "bundler",
|
|
11
|
+
"useDefineForClassFields": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src"]
|
|
14
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rslib-react-js",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"import": "./dist/index.js"
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "rslib build",
|
|
16
|
+
"dev": "rslib build --watch",
|
|
17
|
+
"test": "vitest run"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@rsbuild/plugin-react": "^1.0.6",
|
|
21
|
+
"@rslib/core": "workspace:*",
|
|
22
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
23
|
+
"@testing-library/react": "^16.0.1",
|
|
24
|
+
"jsdom": "^25.0.1",
|
|
25
|
+
"react": "^18.3.1",
|
|
26
|
+
"vitest": "^2.1.4"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"react": ">=16.9.0",
|
|
30
|
+
"react-dom": ">=16.9.0"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { pluginReact } from '@rsbuild/plugin-react';
|
|
2
|
+
import { defineConfig } from '@rslib/core';
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
source: {
|
|
6
|
+
entry: {
|
|
7
|
+
index: ['./src/**'],
|
|
8
|
+
},
|
|
9
|
+
},
|
|
10
|
+
lib: [
|
|
11
|
+
{
|
|
12
|
+
bundle: false,
|
|
13
|
+
format: 'esm',
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
plugins: [
|
|
17
|
+
pluginReact({
|
|
18
|
+
swcReactOptions: {
|
|
19
|
+
runtime: 'classic',
|
|
20
|
+
},
|
|
21
|
+
}),
|
|
22
|
+
],
|
|
23
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './button.css';
|
|
3
|
+
|
|
4
|
+
export const Button = ({
|
|
5
|
+
primary = false,
|
|
6
|
+
size = 'medium',
|
|
7
|
+
backgroundColor,
|
|
8
|
+
label,
|
|
9
|
+
...props
|
|
10
|
+
}) => {
|
|
11
|
+
const mode = primary ? 'demo-button--primary' : 'demo-button--secondary';
|
|
12
|
+
return (
|
|
13
|
+
<button
|
|
14
|
+
type="button"
|
|
15
|
+
className={['demo-button', `demo-button--${size}`, mode].join(' ')}
|
|
16
|
+
style={{ backgroundColor }}
|
|
17
|
+
{...props}
|
|
18
|
+
>
|
|
19
|
+
{label}
|
|
20
|
+
</button>
|
|
21
|
+
);
|
|
22
|
+
};
|