create-rslib 0.0.15 → 0.0.17

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.
Files changed (112) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +140 -8
  3. package/package.json +10 -7
  4. package/{template-node-dual-js → template-[node-dual]-[]-js}/rslib.config.mjs +0 -1
  5. package/template-[node-dual]-[]-js/src/index.js +1 -0
  6. package/{template-node-dual-ts → template-[node-dual]-[]-ts}/package.json +1 -0
  7. package/{template-node-dual-ts → template-[node-dual]-[]-ts}/rslib.config.ts +0 -1
  8. package/template-[node-dual]-[]-ts/src/index.ts +1 -0
  9. package/{template-node-dual-ts → template-[node-dual]-[]-ts}/tsconfig.json +1 -2
  10. package/template-[node-dual]-[vitest]-js/package.json +25 -0
  11. package/template-[node-dual]-[vitest]-js/rslib.config.mjs +14 -0
  12. package/template-[node-dual]-[vitest]-js/src/index.js +1 -0
  13. package/template-[node-dual]-[vitest]-js/tests/index.test.js +7 -0
  14. package/template-[node-dual]-[vitest]-js/vitest.config.js +8 -0
  15. package/template-[node-dual]-[vitest]-ts/package.json +29 -0
  16. package/template-[node-dual]-[vitest]-ts/rslib.config.ts +15 -0
  17. package/template-[node-dual]-[vitest]-ts/src/index.ts +1 -0
  18. package/template-[node-dual]-[vitest]-ts/tests/index.test.ts +7 -0
  19. package/{template-node-esm-ts → template-[node-dual]-[vitest]-ts}/tsconfig.json +1 -2
  20. package/template-[node-dual]-[vitest]-ts/vitest.config.ts +6 -0
  21. package/{template-node-esm-js → template-[node-esm]-[]-js}/rslib.config.mjs +0 -1
  22. package/template-[node-esm]-[]-js/src/index.js +1 -0
  23. package/{template-node-esm-ts → template-[node-esm]-[]-ts}/package.json +1 -0
  24. package/{template-node-esm-ts → template-[node-esm]-[]-ts}/rslib.config.ts +0 -1
  25. package/template-[node-esm]-[]-ts/src/index.ts +1 -0
  26. package/template-[node-esm]-[]-ts/tsconfig.json +15 -0
  27. package/template-[node-esm]-[vitest]-js/package.json +23 -0
  28. package/template-[node-esm]-[vitest]-js/rslib.config.mjs +10 -0
  29. package/template-[node-esm]-[vitest]-js/src/index.js +1 -0
  30. package/template-[node-esm]-[vitest]-js/tests/index.test.js +7 -0
  31. package/template-[node-esm]-[vitest]-js/vitest.config.js +8 -0
  32. package/template-[node-esm]-[vitest]-ts/package.json +27 -0
  33. package/template-[node-esm]-[vitest]-ts/rslib.config.ts +11 -0
  34. package/template-[node-esm]-[vitest]-ts/src/index.ts +1 -0
  35. package/template-[node-esm]-[vitest]-ts/tests/index.test.ts +7 -0
  36. package/template-[node-esm]-[vitest]-ts/tsconfig.json +15 -0
  37. package/template-[node-esm]-[vitest]-ts/vitest.config.ts +6 -0
  38. package/template-[react]-[]-js/package.json +27 -0
  39. package/template-[react]-[]-js/rslib.config.mjs +26 -0
  40. package/template-[react]-[]-js/src/Button.jsx +22 -0
  41. package/template-[react]-[]-js/src/button.css +34 -0
  42. package/template-[react]-[]-js/src/index.jsx +1 -0
  43. package/template-[react]-[]-ts/package.json +31 -0
  44. package/template-[react]-[]-ts/rslib.config.ts +27 -0
  45. package/template-[react]-[]-ts/src/Button.tsx +30 -0
  46. package/template-[react]-[]-ts/src/button.css +34 -0
  47. package/template-[react]-[]-ts/src/index.tsx +1 -0
  48. package/template-[react]-[]-ts/tsconfig.json +14 -0
  49. package/template-[react]-[storybook,vitest]-js/.storybook/main.js +36 -0
  50. package/template-[react]-[storybook,vitest]-js/.storybook/preview.js +12 -0
  51. package/template-[react]-[storybook,vitest]-js/package.json +45 -0
  52. package/template-[react]-[storybook,vitest]-js/rslib.config.mjs +26 -0
  53. package/template-[react]-[storybook,vitest]-js/src/Button.jsx +22 -0
  54. package/template-[react]-[storybook,vitest]-js/src/button.css +34 -0
  55. package/template-[react]-[storybook,vitest]-js/src/index.jsx +1 -0
  56. package/template-[react]-[storybook,vitest]-js/stories/Button.stories.jsx +50 -0
  57. package/template-[react]-[storybook,vitest]-js/tests/index.test.jsx +12 -0
  58. package/template-[react]-[storybook,vitest]-js/vitest.config.js +11 -0
  59. package/template-[react]-[storybook,vitest]-js/vitest.setup.js +1 -0
  60. package/template-[react]-[storybook,vitest]-ts/.storybook/main.ts +37 -0
  61. package/template-[react]-[storybook,vitest]-ts/.storybook/preview.ts +14 -0
  62. package/template-[react]-[storybook,vitest]-ts/package.json +49 -0
  63. package/template-[react]-[storybook,vitest]-ts/rslib.config.ts +27 -0
  64. package/template-[react]-[storybook,vitest]-ts/src/Button.tsx +30 -0
  65. package/template-[react]-[storybook,vitest]-ts/src/button.css +34 -0
  66. package/template-[react]-[storybook,vitest]-ts/src/index.tsx +1 -0
  67. package/template-[react]-[storybook,vitest]-ts/stories/Button.stories.ts +52 -0
  68. package/template-[react]-[storybook,vitest]-ts/tests/index.test.tsx +12 -0
  69. package/template-[react]-[storybook,vitest]-ts/tsconfig.json +14 -0
  70. package/template-[react]-[storybook,vitest]-ts/vitest.config.ts +9 -0
  71. package/template-[react]-[storybook,vitest]-ts/vitest.setup.ts +1 -0
  72. package/template-[react]-[storybook]-js/.storybook/main.js +36 -0
  73. package/template-[react]-[storybook]-js/.storybook/preview.js +12 -0
  74. package/template-[react]-[storybook]-js/package.json +40 -0
  75. package/template-[react]-[storybook]-js/rslib.config.mjs +26 -0
  76. package/template-[react]-[storybook]-js/src/Button.jsx +22 -0
  77. package/template-[react]-[storybook]-js/src/button.css +34 -0
  78. package/template-[react]-[storybook]-js/src/index.jsx +1 -0
  79. package/template-[react]-[storybook]-js/stories/Button.stories.jsx +50 -0
  80. package/template-[react]-[storybook]-ts/.storybook/main.ts +37 -0
  81. package/template-[react]-[storybook]-ts/.storybook/preview.ts +14 -0
  82. package/template-[react]-[storybook]-ts/package.json +44 -0
  83. package/template-[react]-[storybook]-ts/rslib.config.ts +27 -0
  84. package/template-[react]-[storybook]-ts/src/Button.tsx +30 -0
  85. package/template-[react]-[storybook]-ts/src/button.css +34 -0
  86. package/template-[react]-[storybook]-ts/src/index.tsx +1 -0
  87. package/template-[react]-[storybook]-ts/stories/Button.stories.ts +52 -0
  88. package/template-[react]-[storybook]-ts/tsconfig.json +14 -0
  89. package/template-[react]-[vitest]-js/package.json +32 -0
  90. package/template-[react]-[vitest]-js/rslib.config.mjs +26 -0
  91. package/template-[react]-[vitest]-js/src/Button.jsx +22 -0
  92. package/template-[react]-[vitest]-js/src/button.css +34 -0
  93. package/template-[react]-[vitest]-js/src/index.jsx +1 -0
  94. package/template-[react]-[vitest]-js/tests/index.test.jsx +12 -0
  95. package/template-[react]-[vitest]-js/vitest.config.js +11 -0
  96. package/template-[react]-[vitest]-js/vitest.setup.js +1 -0
  97. package/template-[react]-[vitest]-ts/package.json +36 -0
  98. package/template-[react]-[vitest]-ts/rslib.config.ts +27 -0
  99. package/template-[react]-[vitest]-ts/src/Button.tsx +30 -0
  100. package/template-[react]-[vitest]-ts/src/button.css +34 -0
  101. package/template-[react]-[vitest]-ts/src/index.tsx +1 -0
  102. package/template-[react]-[vitest]-ts/tests/index.test.tsx +12 -0
  103. package/template-[react]-[vitest]-ts/tsconfig.json +14 -0
  104. package/template-[react]-[vitest]-ts/vitest.config.ts +9 -0
  105. package/template-[react]-[vitest]-ts/vitest.setup.ts +1 -0
  106. package/template-common/README.md +1 -1
  107. package/template-node-dual-js/src/index.js +0 -3
  108. package/template-node-dual-ts/src/index.ts +0 -3
  109. package/template-node-esm-js/src/index.js +0 -3
  110. package/template-node-esm-ts/src/index.ts +0 -3
  111. /package/{template-node-dual-js → template-[node-dual]-[]-js}/package.json +0 -0
  112. /package/{template-node-esm-js → template-[node-esm]-[]-js}/package.json +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,9 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ // Configure Vitest (https://vitest.dev/config/)
5
+ test: {
6
+ environment: 'jsdom',
7
+ setupFiles: './vitest.setup.ts',
8
+ },
9
+ });
@@ -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,12 @@
1
+ const preview = {
2
+ parameters: {
3
+ controls: {
4
+ matchers: {
5
+ color: /(background|color)$/i,
6
+ date: /Date$/i,
7
+ },
8
+ },
9
+ },
10
+ };
11
+
12
+ export default preview;
@@ -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.1.0",
22
+ "@rsbuild/plugin-react": "^1.0.7",
23
+ "@rslib/core": "workspace:*",
24
+ "@storybook/addon-essentials": "^8.4.2",
25
+ "@storybook/addon-interactions": "^8.4.2",
26
+ "@storybook/addon-links": "^8.4.2",
27
+ "@storybook/addon-onboarding": "^8.4.2",
28
+ "@storybook/blocks": "^8.4.2",
29
+ "@storybook/react": "^8.4.2",
30
+ "@storybook/test": "^8.4.2",
31
+ "react": "^18.3.1",
32
+ "storybook": "^8.4.2",
33
+ "storybook-addon-rslib": "^0.1.3",
34
+ "storybook-react-rsbuild": "^0.1.3"
35
+ },
36
+ "peerDependencies": {
37
+ "react": ">=16.9.0",
38
+ "react-dom": ">=16.9.0"
39
+ }
40
+ }
@@ -0,0 +1,26 @@
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: [
20
+ pluginReact({
21
+ swcReactOptions: {
22
+ runtime: 'classic',
23
+ },
24
+ }),
25
+ ],
26
+ });
@@ -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,14 @@
1
+ import type { Preview } from '@storybook/react';
2
+
3
+ const preview: Preview = {
4
+ parameters: {
5
+ controls: {
6
+ matchers: {
7
+ color: /(background|color)$/i,
8
+ date: /Date$/i,
9
+ },
10
+ },
11
+ },
12
+ };
13
+
14
+ export default preview;
@@ -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.1.0",
24
+ "@rsbuild/plugin-react": "^1.0.7",
25
+ "@rslib/core": "workspace:*",
26
+ "@storybook/addon-essentials": "^8.4.2",
27
+ "@storybook/addon-interactions": "^8.4.2",
28
+ "@storybook/addon-links": "^8.4.2",
29
+ "@storybook/addon-onboarding": "^8.4.2",
30
+ "@storybook/blocks": "^8.4.2",
31
+ "@storybook/react": "^8.4.2",
32
+ "@storybook/test": "^8.4.2",
33
+ "@types/react": "^18.3.12",
34
+ "react": "^18.3.1",
35
+ "storybook": "^8.4.2",
36
+ "storybook-addon-rslib": "^0.1.3",
37
+ "storybook-react-rsbuild": "^0.1.3",
38
+ "typescript": "^5.6.3"
39
+ },
40
+ "peerDependencies": {
41
+ "react": ">=16.9.0",
42
+ "react-dom": ">=16.9.0"
43
+ }
44
+ }
@@ -0,0 +1,27 @@
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: [
21
+ pluginReact({
22
+ swcReactOptions: {
23
+ runtime: 'classic',
24
+ },
25
+ }),
26
+ ],
27
+ });
@@ -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.7",
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,26 @@
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: [
20
+ pluginReact({
21
+ swcReactOptions: {
22
+ runtime: 'classic',
23
+ },
24
+ }),
25
+ ],
26
+ });
@@ -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
+ };