create-rslib 0.12.0 → 0.12.2
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 +117 -20
- package/package.json +5 -5
- package/template-[node-dual]-[]-ts/package.json +1 -1
- package/template-[node-dual]-[rstest]-js/package.json +24 -0
- package/template-[node-dual]-[rstest]-js/rslib.config.mjs +14 -0
- package/template-[node-dual]-[rstest]-js/rstest.config.js +3 -0
- package/template-[node-dual]-[rstest]-js/src/index.js +1 -0
- package/template-[node-dual]-[rstest]-js/tests/index.test.js +7 -0
- package/template-[node-dual]-[rstest]-ts/package.json +28 -0
- package/template-[node-dual]-[rstest]-ts/rslib.config.ts +15 -0
- package/template-[node-dual]-[rstest]-ts/rstest.config.ts +3 -0
- package/template-[node-dual]-[rstest]-ts/src/index.ts +1 -0
- package/template-[node-dual]-[rstest]-ts/tests/index.test.ts +7 -0
- package/template-[node-dual]-[rstest]-ts/tsconfig.json +15 -0
- package/template-[node-dual]-[vitest]-ts/package.json +1 -1
- package/template-[node-esm]-[]-ts/package.json +1 -1
- package/template-[node-esm]-[rstest]-js/package.json +22 -0
- package/template-[node-esm]-[rstest]-js/rslib.config.mjs +10 -0
- package/template-[node-esm]-[rstest]-js/rstest.config.js +3 -0
- package/template-[node-esm]-[rstest]-js/src/index.js +1 -0
- package/template-[node-esm]-[rstest]-js/tests/index.test.js +7 -0
- package/template-[node-esm]-[rstest]-ts/package.json +26 -0
- package/template-[node-esm]-[rstest]-ts/rslib.config.ts +11 -0
- package/template-[node-esm]-[rstest]-ts/rstest.config.ts +3 -0
- package/template-[node-esm]-[rstest]-ts/src/index.ts +1 -0
- package/template-[node-esm]-[rstest]-ts/tests/index.test.ts +7 -0
- package/template-[node-esm]-[rstest]-ts/tsconfig.json +15 -0
- package/template-[node-esm]-[vitest]-ts/package.json +1 -1
- package/template-[react]-[]-ts/package.json +1 -1
- package/template-[react]-[rstest,storybook]-js/.storybook/main.js +36 -0
- package/template-[react]-[rstest,storybook]-js/.storybook/preview.js +12 -0
- package/template-[react]-[rstest,storybook]-js/package.json +45 -0
- package/template-[react]-[rstest,storybook]-js/rslib.config.mjs +20 -0
- package/template-[react]-[rstest,storybook]-js/rstest.config.js +8 -0
- package/template-[react]-[rstest,storybook]-js/rstest.setup.js +4 -0
- package/template-[react]-[rstest,storybook]-js/src/Button.jsx +21 -0
- package/template-[react]-[rstest,storybook]-js/src/button.css +34 -0
- package/template-[react]-[rstest,storybook]-js/src/index.jsx +1 -0
- package/template-[react]-[rstest,storybook]-js/stories/Button.stories.jsx +50 -0
- package/template-[react]-[rstest,storybook]-js/tests/index.test.jsx +11 -0
- package/template-[react]-[rstest,storybook]-ts/.storybook/main.ts +37 -0
- package/template-[react]-[rstest,storybook]-ts/.storybook/preview.ts +14 -0
- package/template-[react]-[rstest,storybook]-ts/package.json +49 -0
- package/template-[react]-[rstest,storybook]-ts/rslib.config.ts +21 -0
- package/template-[react]-[rstest,storybook]-ts/rstest.config.ts +8 -0
- package/template-[react]-[rstest,storybook]-ts/rstest.setup.ts +4 -0
- package/template-[react]-[rstest,storybook]-ts/src/Button.tsx +29 -0
- package/template-[react]-[rstest,storybook]-ts/src/button.css +34 -0
- package/template-[react]-[rstest,storybook]-ts/src/index.tsx +1 -0
- package/template-[react]-[rstest,storybook]-ts/stories/Button.stories.ts +52 -0
- package/template-[react]-[rstest,storybook]-ts/tests/index.test.tsx +11 -0
- package/template-[react]-[rstest,storybook]-ts/tests/test.d.ts +1 -0
- package/template-[react]-[rstest,storybook]-ts/tests/tsconfig.json +4 -0
- package/template-[react]-[rstest,storybook]-ts/tsconfig.json +14 -0
- package/template-[react]-[rstest]-js/package.json +31 -0
- package/template-[react]-[rstest]-js/rslib.config.mjs +20 -0
- package/template-[react]-[rstest]-js/rstest.config.js +8 -0
- package/template-[react]-[rstest]-js/rstest.setup.js +4 -0
- package/template-[react]-[rstest]-js/src/Button.jsx +21 -0
- package/template-[react]-[rstest]-js/src/button.css +34 -0
- package/template-[react]-[rstest]-js/src/index.jsx +1 -0
- package/template-[react]-[rstest]-js/tests/index.test.jsx +11 -0
- package/template-[react]-[rstest]-ts/package.json +35 -0
- package/template-[react]-[rstest]-ts/rslib.config.ts +21 -0
- package/template-[react]-[rstest]-ts/rstest.config.ts +8 -0
- package/template-[react]-[rstest]-ts/rstest.setup.ts +4 -0
- package/template-[react]-[rstest]-ts/src/Button.tsx +29 -0
- package/template-[react]-[rstest]-ts/src/button.css +34 -0
- package/template-[react]-[rstest]-ts/src/index.tsx +1 -0
- package/template-[react]-[rstest]-ts/tests/index.test.tsx +11 -0
- package/template-[react]-[rstest]-ts/tests/test.d.ts +1 -0
- package/template-[react]-[rstest]-ts/tests/tsconfig.json +4 -0
- package/template-[react]-[rstest]-ts/tsconfig.json +14 -0
- package/template-[react]-[storybook,vitest]-js/package.json +9 -9
- package/template-[react]-[storybook,vitest]-ts/package.json +10 -10
- package/template-[react]-[storybook]-js/package.json +8 -8
- package/template-[react]-[storybook]-ts/package.json +9 -9
- package/template-[react]-[vitest]-js/package.json +1 -1
- package/template-[react]-[vitest]-ts/package.json +2 -2
- package/template-[vue]-[rstest,storybook]-js/.storybook/main.js +35 -0
- package/template-[vue]-[rstest,storybook]-js/.storybook/preview.js +12 -0
- package/template-[vue]-[rstest,storybook]-js/package.json +47 -0
- package/template-[vue]-[rstest,storybook]-js/rslib.config.ts +15 -0
- package/template-[vue]-[rstest,storybook]-js/rstest.config.js +8 -0
- package/template-[vue]-[rstest,storybook]-js/rstest.setup.js +4 -0
- package/template-[vue]-[rstest,storybook]-js/src/Button.vue +43 -0
- package/template-[vue]-[rstest,storybook]-js/src/index.js +1 -0
- package/template-[vue]-[rstest,storybook]-js/src/style.css +34 -0
- package/template-[vue]-[rstest,storybook]-js/stories/Button.stories.js +50 -0
- package/template-[vue]-[rstest,storybook]-js/tests/index.test.js +16 -0
- package/template-[vue]-[rstest,storybook]-ts/.storybook/main.ts +36 -0
- package/template-[vue]-[rstest,storybook]-ts/.storybook/preview.ts +12 -0
- package/template-[vue]-[rstest,storybook]-ts/package.json +49 -0
- package/template-[vue]-[rstest,storybook]-ts/rslib.config.ts +15 -0
- package/template-[vue]-[rstest,storybook]-ts/rstest.config.ts +8 -0
- package/template-[vue]-[rstest,storybook]-ts/rstest.setup.ts +4 -0
- package/template-[vue]-[rstest,storybook]-ts/src/Button.vue +35 -0
- package/template-[vue]-[rstest,storybook]-ts/src/index.ts +1 -0
- package/template-[vue]-[rstest,storybook]-ts/src/style.css +34 -0
- package/template-[vue]-[rstest,storybook]-ts/stories/Button.stories.js +50 -0
- package/template-[vue]-[rstest,storybook]-ts/tests/index.test.ts +16 -0
- package/template-[vue]-[rstest,storybook]-ts/tests/test.d.ts +1 -0
- package/template-[vue]-[rstest,storybook]-ts/tests/tsconfig.json +4 -0
- package/template-[vue]-[rstest,storybook]-ts/tsconfig.json +24 -0
- package/template-[vue]-[rstest]-js/package.json +33 -0
- package/template-[vue]-[rstest]-js/rslib.config.ts +15 -0
- package/template-[vue]-[rstest]-js/rstest.config.js +8 -0
- package/template-[vue]-[rstest]-js/rstest.setup.js +4 -0
- package/template-[vue]-[rstest]-js/src/Button.vue +43 -0
- package/template-[vue]-[rstest]-js/src/index.js +1 -0
- package/template-[vue]-[rstest]-js/src/style.css +34 -0
- package/template-[vue]-[rstest]-js/tests/index.test.js +16 -0
- package/template-[vue]-[rstest]-ts/package.json +35 -0
- package/template-[vue]-[rstest]-ts/rslib.config.ts +15 -0
- package/template-[vue]-[rstest]-ts/rstest.config.ts +8 -0
- package/template-[vue]-[rstest]-ts/rstest.setup.ts +4 -0
- package/template-[vue]-[rstest]-ts/src/Button.vue +35 -0
- package/template-[vue]-[rstest]-ts/src/index.ts +1 -0
- package/template-[vue]-[rstest]-ts/src/style.css +34 -0
- package/template-[vue]-[rstest]-ts/tests/index.test.ts +16 -0
- package/template-[vue]-[rstest]-ts/tests/test.d.ts +1 -0
- package/template-[vue]-[rstest]-ts/tests/tsconfig.json +4 -0
- package/template-[vue]-[rstest]-ts/tsconfig.json +24 -0
- package/template-[vue]-[storybook,vitest]-js/package.json +9 -9
- package/template-[vue]-[storybook,vitest]-ts/package.json +9 -9
- package/template-[vue]-[storybook]-js/package.json +8 -8
- package/template-[vue]-[storybook]-ts/package.json +8 -8
- package/template-[vue]-[vitest]-js/package.json +1 -1
- package/template-[vue]-[vitest]-ts/package.json +1 -1
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
output: {
|
|
17
|
+
target: 'web',
|
|
18
|
+
},
|
|
19
|
+
plugins: [pluginReact()],
|
|
20
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import './button.css';
|
|
2
|
+
|
|
3
|
+
export const Button = ({
|
|
4
|
+
primary = false,
|
|
5
|
+
size = 'medium',
|
|
6
|
+
backgroundColor,
|
|
7
|
+
label,
|
|
8
|
+
...props
|
|
9
|
+
}) => {
|
|
10
|
+
const mode = primary ? 'demo-button--primary' : 'demo-button--secondary';
|
|
11
|
+
return (
|
|
12
|
+
<button
|
|
13
|
+
type="button"
|
|
14
|
+
className={['demo-button', `demo-button--${size}`, mode].join(' ')}
|
|
15
|
+
style={{ backgroundColor }}
|
|
16
|
+
{...props}
|
|
17
|
+
>
|
|
18
|
+
{label}
|
|
19
|
+
</button>
|
|
20
|
+
);
|
|
21
|
+
};
|
|
@@ -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,11 @@
|
|
|
1
|
+
import { expect, test } from '@rstest/core';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { Button } from '../src/Button';
|
|
4
|
+
|
|
5
|
+
test('The button should have correct background color', async () => {
|
|
6
|
+
render(<Button backgroundColor="#ccc" label="Demo Button" />);
|
|
7
|
+
const button = screen.getByText('Demo Button');
|
|
8
|
+
expect(button).toHaveStyle({
|
|
9
|
+
backgroundColor: '#ccc',
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -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-docs',
|
|
19
|
+
'@storybook/addon-onboarding',
|
|
20
|
+
'@storybook/addon-links',
|
|
21
|
+
'@storybook/addon-essentials',
|
|
22
|
+
'@storybook/addon-interactions',
|
|
23
|
+
{
|
|
24
|
+
name: getAbsolutePath('storybook-addon-rslib'),
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
framework: {
|
|
28
|
+
name: getAbsolutePath('storybook-react-rsbuild'),
|
|
29
|
+
options: {},
|
|
30
|
+
},
|
|
31
|
+
typescript: {
|
|
32
|
+
reactDocgen: 'react-docgen-typescript',
|
|
33
|
+
check: true,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default config;
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "rslib build",
|
|
17
|
+
"build:storybook": "storybook build",
|
|
18
|
+
"dev": "rslib build --watch",
|
|
19
|
+
"storybook": "storybook dev",
|
|
20
|
+
"test": "rstest"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@rsbuild/core": "1.5.0-beta.4",
|
|
24
|
+
"@rsbuild/plugin-react": "^1.3.5",
|
|
25
|
+
"@rslib/core": "workspace:*",
|
|
26
|
+
"@rstest/core": "^0.2.1",
|
|
27
|
+
"@storybook/addon-docs": "^9.1.2",
|
|
28
|
+
"@storybook/addon-essentials": "^9.0.0-alpha.12",
|
|
29
|
+
"@storybook/addon-interactions": "^9.0.0-alpha.10",
|
|
30
|
+
"@storybook/addon-links": "^9.1.2",
|
|
31
|
+
"@storybook/addon-onboarding": "^9.1.2",
|
|
32
|
+
"@storybook/blocks": "^9.0.0-alpha.17",
|
|
33
|
+
"@storybook/react": "^9.1.2",
|
|
34
|
+
"@storybook/test": "^9.0.0-alpha.2",
|
|
35
|
+
"@testing-library/jest-dom": "^6.7.0",
|
|
36
|
+
"@testing-library/react": "^16.3.0",
|
|
37
|
+
"@types/react": "^19.1.10",
|
|
38
|
+
"jsdom": "^26.1.0",
|
|
39
|
+
"react": "^19.1.1",
|
|
40
|
+
"storybook": "^9.1.2",
|
|
41
|
+
"storybook-addon-rslib": "^2.0.4",
|
|
42
|
+
"storybook-react-rsbuild": "^2.0.4",
|
|
43
|
+
"typescript": "^5.9.2"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"react": ">=16.9.0",
|
|
47
|
+
"react-dom": ">=16.9.0"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
output: {
|
|
18
|
+
target: 'web',
|
|
19
|
+
},
|
|
20
|
+
plugins: [pluginReact()],
|
|
21
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import './button.css';
|
|
2
|
+
|
|
3
|
+
interface ButtonProps {
|
|
4
|
+
primary?: boolean;
|
|
5
|
+
backgroundColor?: string;
|
|
6
|
+
size?: 'small' | 'medium' | 'large';
|
|
7
|
+
label: string;
|
|
8
|
+
onClick?: () => void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const Button = ({
|
|
12
|
+
primary = false,
|
|
13
|
+
size = 'medium',
|
|
14
|
+
backgroundColor,
|
|
15
|
+
label,
|
|
16
|
+
...props
|
|
17
|
+
}: ButtonProps) => {
|
|
18
|
+
const mode = primary ? 'demo-button--primary' : 'demo-button--secondary';
|
|
19
|
+
return (
|
|
20
|
+
<button
|
|
21
|
+
type="button"
|
|
22
|
+
className={['demo-button', `demo-button--${size}`, mode].join(' ')}
|
|
23
|
+
style={{ backgroundColor }}
|
|
24
|
+
{...props}
|
|
25
|
+
>
|
|
26
|
+
{label}
|
|
27
|
+
</button>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
@@ -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,11 @@
|
|
|
1
|
+
import { expect, test } from '@rstest/core';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { Button } from '../src/Button';
|
|
4
|
+
|
|
5
|
+
test('The button should have correct background color', async () => {
|
|
6
|
+
render(<Button backgroundColor="#ccc" label="Demo Button" />);
|
|
7
|
+
const button = screen.getByText('Demo Button');
|
|
8
|
+
expect(button).toHaveStyle({
|
|
9
|
+
backgroundColor: '#ccc',
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="@testing-library/jest-dom" />
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"lib": ["DOM", "ES2022"],
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"jsx": "react-jsx",
|
|
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,31 @@
|
|
|
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
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "rslib build",
|
|
15
|
+
"dev": "rslib build --watch",
|
|
16
|
+
"test": "rstest"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@rsbuild/plugin-react": "^1.3.5",
|
|
20
|
+
"@rslib/core": "workspace:*",
|
|
21
|
+
"@rstest/core": "^0.2.1",
|
|
22
|
+
"@testing-library/jest-dom": "^6.7.0",
|
|
23
|
+
"@testing-library/react": "^16.3.0",
|
|
24
|
+
"jsdom": "^26.1.0",
|
|
25
|
+
"react": "^19.1.1"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"react": ">=16.9.0",
|
|
29
|
+
"react-dom": ">=16.9.0"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
output: {
|
|
17
|
+
target: 'web',
|
|
18
|
+
},
|
|
19
|
+
plugins: [pluginReact()],
|
|
20
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import './button.css';
|
|
2
|
+
|
|
3
|
+
export const Button = ({
|
|
4
|
+
primary = false,
|
|
5
|
+
size = 'medium',
|
|
6
|
+
backgroundColor,
|
|
7
|
+
label,
|
|
8
|
+
...props
|
|
9
|
+
}) => {
|
|
10
|
+
const mode = primary ? 'demo-button--primary' : 'demo-button--secondary';
|
|
11
|
+
return (
|
|
12
|
+
<button
|
|
13
|
+
type="button"
|
|
14
|
+
className={['demo-button', `demo-button--${size}`, mode].join(' ')}
|
|
15
|
+
style={{ backgroundColor }}
|
|
16
|
+
{...props}
|
|
17
|
+
>
|
|
18
|
+
{label}
|
|
19
|
+
</button>
|
|
20
|
+
);
|
|
21
|
+
};
|
|
@@ -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,11 @@
|
|
|
1
|
+
import { expect, test } from '@rstest/core';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { Button } from '../src/Button';
|
|
4
|
+
|
|
5
|
+
test('The button should have correct background color', async () => {
|
|
6
|
+
render(<Button backgroundColor="#ccc" label="Demo Button" />);
|
|
7
|
+
const button = screen.getByText('Demo Button');
|
|
8
|
+
expect(button).toHaveStyle({
|
|
9
|
+
backgroundColor: '#ccc',
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "rslib build",
|
|
17
|
+
"dev": "rslib build --watch",
|
|
18
|
+
"test": "rstest"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@rsbuild/plugin-react": "^1.3.5",
|
|
22
|
+
"@rslib/core": "workspace:*",
|
|
23
|
+
"@rstest/core": "^0.2.1",
|
|
24
|
+
"@testing-library/jest-dom": "^6.7.0",
|
|
25
|
+
"@testing-library/react": "^16.3.0",
|
|
26
|
+
"@types/react": "^19.1.10",
|
|
27
|
+
"jsdom": "^26.1.0",
|
|
28
|
+
"react": "^19.1.1",
|
|
29
|
+
"typescript": "^5.9.2"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"react": ">=16.9.0",
|
|
33
|
+
"react-dom": ">=16.9.0"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
output: {
|
|
18
|
+
target: 'web',
|
|
19
|
+
},
|
|
20
|
+
plugins: [pluginReact()],
|
|
21
|
+
});
|