@yusufalperendumlu/component-library 0.0.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/.storybook/main.ts +17 -0
- package/.storybook/preview.ts +14 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/components/Button/Button.d.ts +5 -0
- package/dist/esm/components/Button/index.d.ts +2 -0
- package/dist/esm/components/Input/Input.d.ts +5 -0
- package/dist/esm/components/Input/index.d.ts +2 -0
- package/dist/esm/components/index.d.ts +2 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/package.json +67 -0
- package/rollup.config.mjs +65 -0
- package/src/components/Button/Button.stories.ts +34 -0
- package/src/components/Button/Button.tsx +34 -0
- package/src/components/Button/index.ts +3 -0
- package/src/components/Input/Input.tsx +9 -0
- package/src/components/Input/index.tsx +3 -0
- package/src/components/index.ts +2 -0
- package/src/index.ts +1 -0
- package/src/tests/Button.test.tsx +37 -0
- package/src/tests/styleMock.ts +1 -0
- package/tsconfig.json +26 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
import type { StorybookConfig } from '@storybook/react-webpack5';
|
2
|
+
|
3
|
+
const config: StorybookConfig = {
|
4
|
+
"stories": [
|
5
|
+
"../src/**/*.mdx",
|
6
|
+
"../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"
|
7
|
+
],
|
8
|
+
"addons": [
|
9
|
+
"@storybook/addon-webpack5-compiler-swc",
|
10
|
+
"@storybook/addon-docs"
|
11
|
+
],
|
12
|
+
"framework": {
|
13
|
+
"name": "@storybook/react-webpack5",
|
14
|
+
"options": {}
|
15
|
+
}
|
16
|
+
};
|
17
|
+
export default config;
|
@@ -0,0 +1,2 @@
|
|
1
|
+
"use strict";var r=require("react/jsx-runtime");exports.Button=({variant:e,...o})=>r.jsx("button",{style:{..."primary"===e?{borderColor:"#053786ff",color:"#ca1515ff",backgroundColor:"#bfdbfe",padding:"2rem 5rem"}:"secondary"===e?{borderColor:"#cbd5e1",textColor:"#6b7280",backgroundColor:"#f3f4f6"}:{},...o.style},...o,children:o.title}),exports.Input=({placeholder:e})=>r.jsx("input",{placeholder:e,children:"Input"});
|
2
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/components/Button/Button.tsx","../../src/components/Input/Input.tsx"],"sourcesContent":[null,null],"names":["variant","props","_jsx","style","borderColor","color","backgroundColor","padding","textColor","children","title","placeholder"],"mappings":"+DAKuC,EAAGA,aAAYC,KAsBlDC,EAAAA,cAAQC,MAAO,IApBC,YAAZH,EACK,CACLI,YAAa,YACbC,MAAO,YACPC,gBAAiB,UACjBC,QAAS,aAGG,cAAZP,EACK,CACLI,YAAa,UACbI,UAAW,UACXF,gBAAiB,WAId,CAAA,KAIgCL,EAAME,UAAaF,EAAKQ,SAC5DR,EAAMS,sBCxBuB,EAAGC,iBAC9BT,EAAAA,IAAA,QAAA,CAAOS,YAAaA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./components";
|
@@ -0,0 +1,2 @@
|
|
1
|
+
import{jsx as r}from"react/jsx-runtime";const o=({variant:o,...e})=>r("button",{style:{..."primary"===o?{borderColor:"#053786ff",color:"#ca1515ff",backgroundColor:"#bfdbfe",padding:"2rem 5rem"}:"secondary"===o?{borderColor:"#cbd5e1",textColor:"#6b7280",backgroundColor:"#f3f4f6"}:{},...e.style},...e,children:e.title}),e=({placeholder:o})=>r("input",{placeholder:o,children:"Input"});export{o as Button,e as Input};
|
2
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/components/Button/Button.tsx","../../src/components/Input/Input.tsx"],"sourcesContent":[null,null],"names":["Button","variant","props","_jsx","style","borderColor","color","backgroundColor","padding","textColor","children","title","Input","placeholder"],"mappings":"wCAKA,MAAMA,EAAiC,EAAGC,aAAYC,KAsBlDC,YAAQC,MAAO,IApBC,YAAZH,EACK,CACLI,YAAa,YACbC,MAAO,YACPC,gBAAiB,UACjBC,QAAS,aAGG,cAAZP,EACK,CACLI,YAAa,UACbI,UAAW,UACXF,gBAAiB,WAId,CAAA,KAIgCL,EAAME,UAAaF,EAAKQ,SAC5DR,EAAMS,QCxBPC,EAA8B,EAAGC,iBAC9BV,EAAA,QAAA,CAAOU,YAAaA"}
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
interface IButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
2
|
+
variant?: "primary" | "secondary";
|
3
|
+
}
|
4
|
+
declare const Button: React.FC<IButtonProps>;
|
5
|
+
|
6
|
+
type InputProps = {
|
7
|
+
placeholder?: string;
|
8
|
+
};
|
9
|
+
declare const Input: React.FC<InputProps>;
|
10
|
+
|
11
|
+
export { Button, Input };
|
package/package.json
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
{
|
2
|
+
"name": "@yusufalperendumlu/component-library",
|
3
|
+
"version": "0.0.2",
|
4
|
+
"main": "dist/cjs/index.js",
|
5
|
+
"module": "dist/esm/index.js",
|
6
|
+
"types": "dist/index.d.ts",
|
7
|
+
"private": false,
|
8
|
+
"publishConfig": {
|
9
|
+
"access": "public"
|
10
|
+
},
|
11
|
+
"scripts": {
|
12
|
+
"dev": "rollup -c --watch",
|
13
|
+
"build": "rollup -c",
|
14
|
+
"test": "jest --watchAll --verbose",
|
15
|
+
"clean": "rm -rf dist",
|
16
|
+
"storybook": "storybook dev -p 6006",
|
17
|
+
"build-storybook": "storybook build"
|
18
|
+
},
|
19
|
+
"jest": {
|
20
|
+
"testEnvironment": "jsdom",
|
21
|
+
"preset": "ts-jest",
|
22
|
+
"setupFilesAfterEnv": [
|
23
|
+
"<rootDir>/src/tests/styleMock.ts"
|
24
|
+
],
|
25
|
+
"moduleNameMapper": {
|
26
|
+
"\\.(css|less|scss|sass)$": "/src/tests/styleMock.ts"
|
27
|
+
}
|
28
|
+
},
|
29
|
+
"author": "",
|
30
|
+
"license": "MIT",
|
31
|
+
"description": "A collection of reusable React components for building user interfaces.",
|
32
|
+
"peerDependencies": {
|
33
|
+
"react": ">=16.8.0",
|
34
|
+
"react-dom": ">=16.8.0"
|
35
|
+
},
|
36
|
+
"devDependencies": {
|
37
|
+
"@rollup/plugin-terser": "^0.4.4",
|
38
|
+
"@rollup/plugin-typescript": "^12.1.4",
|
39
|
+
"@storybook/addon-docs": "9.0.17",
|
40
|
+
"@storybook/addon-webpack5-compiler-swc": "3.0.0",
|
41
|
+
"@storybook/react-webpack5": "9.0.17",
|
42
|
+
"@testing-library/dom": "^10.4.0",
|
43
|
+
"@testing-library/jest-dom": "^6.6.3",
|
44
|
+
"@testing-library/react": "^16.3.0",
|
45
|
+
"@testing-library/user-event": "^14.6.1",
|
46
|
+
"@types/jest": "^30.0.0",
|
47
|
+
"@types/react": "^19.1.8",
|
48
|
+
"@types/react-dom": "^18.0.0",
|
49
|
+
"jest": "^30.0.5",
|
50
|
+
"jest-environment-jsdom": "^30.0.5",
|
51
|
+
"postcss": "^8.5.6",
|
52
|
+
"react": "^18.0.0",
|
53
|
+
"react-dom": "^18.0.0",
|
54
|
+
"storybook": "9.0.17",
|
55
|
+
"ts-jest": "^29.4.0",
|
56
|
+
"tslib": "^2.8.1",
|
57
|
+
"typescript": "^5.8.3"
|
58
|
+
},
|
59
|
+
"dependencies": {
|
60
|
+
"@rollup/plugin-commonjs": "^28.0.6",
|
61
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
62
|
+
"rollup": "^4.45.1",
|
63
|
+
"rollup-plugin-dts": "^6.2.1",
|
64
|
+
"rollup-plugin-peer-deps-external": "^2.2.4",
|
65
|
+
"rollup-plugin-postcss": "^4.0.2"
|
66
|
+
}
|
67
|
+
}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
import commonjs from "@rollup/plugin-commonjs";
|
2
|
+
import resolve from "@rollup/plugin-node-resolve";
|
3
|
+
import terser from "@rollup/plugin-terser";
|
4
|
+
import typescript from "@rollup/plugin-typescript";
|
5
|
+
import postcss from "rollup-plugin-postcss";
|
6
|
+
import dts from "rollup-plugin-dts";
|
7
|
+
import peerDepsExternal from "rollup-plugin-peer-deps-external";
|
8
|
+
import { readFileSync } from "fs";
|
9
|
+
|
10
|
+
// Read package.json using ES modules syntax
|
11
|
+
const packageJson = JSON.parse(readFileSync("./package.json", "utf8"));
|
12
|
+
|
13
|
+
export default [
|
14
|
+
// Main build configuration
|
15
|
+
{
|
16
|
+
input: "src/index.ts",
|
17
|
+
output: [
|
18
|
+
{
|
19
|
+
file: packageJson.main,
|
20
|
+
format: "cjs",
|
21
|
+
sourcemap: true,
|
22
|
+
exports: "auto",
|
23
|
+
},
|
24
|
+
{
|
25
|
+
file: packageJson.module,
|
26
|
+
format: "esm",
|
27
|
+
sourcemap: true,
|
28
|
+
},
|
29
|
+
],
|
30
|
+
plugins: [
|
31
|
+
peerDepsExternal(),
|
32
|
+
resolve({
|
33
|
+
browser: true,
|
34
|
+
preferBuiltins: false,
|
35
|
+
}),
|
36
|
+
commonjs(),
|
37
|
+
typescript({
|
38
|
+
tsconfig: "./tsconfig.json",
|
39
|
+
declaration: false, // We'll handle declarations separately
|
40
|
+
declarationMap: false,
|
41
|
+
}),
|
42
|
+
postcss({
|
43
|
+
extensions: [".css"],
|
44
|
+
extract: true,
|
45
|
+
minimize: true,
|
46
|
+
sourceMap: true,
|
47
|
+
inject: {
|
48
|
+
insertAt: "top",
|
49
|
+
},
|
50
|
+
}),
|
51
|
+
terser(),
|
52
|
+
],
|
53
|
+
external: ["react", "react-dom"],
|
54
|
+
},
|
55
|
+
// Type definitions build
|
56
|
+
{
|
57
|
+
input: "src/index.ts",
|
58
|
+
output: {
|
59
|
+
file: packageJson.types,
|
60
|
+
format: "esm",
|
61
|
+
},
|
62
|
+
plugins: [dts()],
|
63
|
+
external: [/\.css$/],
|
64
|
+
},
|
65
|
+
];
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
2
|
+
import Button from "./Button";
|
3
|
+
|
4
|
+
const meta: Meta<typeof Button> = {
|
5
|
+
title: "components-library/Button",
|
6
|
+
component: Button,
|
7
|
+
tags: ["autodocs"],
|
8
|
+
parameters: {
|
9
|
+
layout: "centered",
|
10
|
+
}
|
11
|
+
} as Meta<typeof Button> ;
|
12
|
+
|
13
|
+
export default meta;
|
14
|
+
type Story = StoryObj<typeof Button>;
|
15
|
+
|
16
|
+
export const Primary: Story = {
|
17
|
+
args: {
|
18
|
+
title: "Primary Button",
|
19
|
+
variant: "primary",
|
20
|
+
},
|
21
|
+
};
|
22
|
+
|
23
|
+
export const Secondary: Story = {
|
24
|
+
args: {
|
25
|
+
title: "Secondary Button",
|
26
|
+
variant: "secondary",
|
27
|
+
},
|
28
|
+
};
|
29
|
+
|
30
|
+
export const Default: Story = {
|
31
|
+
args: {
|
32
|
+
title: "Default Button",
|
33
|
+
},
|
34
|
+
};
|
@@ -0,0 +1,34 @@
|
|
1
|
+
export interface IButtonProps
|
2
|
+
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
3
|
+
variant?: "primary" | "secondary";
|
4
|
+
}
|
5
|
+
|
6
|
+
const Button: React.FC<IButtonProps> = ({ variant, ...props }) => {
|
7
|
+
const colorClasses = () => {
|
8
|
+
if (variant === "primary") {
|
9
|
+
return {
|
10
|
+
borderColor: "#053786ff",
|
11
|
+
color: "#ca1515ff",
|
12
|
+
backgroundColor: "#bfdbfe",
|
13
|
+
padding: "2rem 5rem",
|
14
|
+
};
|
15
|
+
}
|
16
|
+
if (variant === "secondary") {
|
17
|
+
return {
|
18
|
+
borderColor: "#cbd5e1",
|
19
|
+
textColor: "#6b7280",
|
20
|
+
backgroundColor: "#f3f4f6",
|
21
|
+
};
|
22
|
+
}
|
23
|
+
|
24
|
+
return {};
|
25
|
+
};
|
26
|
+
|
27
|
+
return (
|
28
|
+
<button style={{ ...colorClasses(), ...props.style }} {...props}>
|
29
|
+
{props.title}
|
30
|
+
</button>
|
31
|
+
);
|
32
|
+
};
|
33
|
+
|
34
|
+
export default Button;
|
package/src/index.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./components";
|
@@ -0,0 +1,37 @@
|
|
1
|
+
// src/tests/Button.test.tsx
|
2
|
+
|
3
|
+
import React from "react";
|
4
|
+
import "@testing-library/jest-dom";
|
5
|
+
import { render, screen } from "@testing-library/react";
|
6
|
+
import Button from "../components/Button";
|
7
|
+
|
8
|
+
describe("Button", () => {
|
9
|
+
test("renders with default styles when no variant is provided", () => {
|
10
|
+
render(<Button title="Default Button" />);
|
11
|
+
const buttonElement = screen.getByRole("button", {
|
12
|
+
name: /default button/i,
|
13
|
+
});
|
14
|
+
|
15
|
+
expect(buttonElement.style.borderColor).toBe("");
|
16
|
+
expect(buttonElement.style.color).toBe("");
|
17
|
+
expect(buttonElement.style.backgroundColor).toBe("");
|
18
|
+
});
|
19
|
+
|
20
|
+
test("renders with custom style prop", () => {
|
21
|
+
render(<Button title="Custom Button" style={{ padding: "10px" }} />);
|
22
|
+
const buttonElement = screen.getByRole("button", {
|
23
|
+
name: /custom button/i,
|
24
|
+
});
|
25
|
+
|
26
|
+
expect(buttonElement).toHaveStyle("padding: 10px");
|
27
|
+
});
|
28
|
+
|
29
|
+
test("button click event works", () => {
|
30
|
+
const handleClick = jest.fn();
|
31
|
+
render(<Button title="Click Me" onClick={handleClick} />);
|
32
|
+
const buttonElement = screen.getByRole("button", { name: /click me/i });
|
33
|
+
|
34
|
+
buttonElement.click();
|
35
|
+
expect(handleClick).toHaveBeenCalledTimes(1);
|
36
|
+
});
|
37
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
module.exports = {}
|
package/tsconfig.json
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"target": "esnext",
|
4
|
+
"jsx": "react-jsx",
|
5
|
+
"module": "ESNext",
|
6
|
+
"moduleResolution": "Node",
|
7
|
+
"declaration": true,
|
8
|
+
"emitDeclarationOnly": false,
|
9
|
+
"sourceMap": true,
|
10
|
+
"outDir": "dist",
|
11
|
+
"allowSyntheticDefaultImports": true,
|
12
|
+
"esModuleInterop": true,
|
13
|
+
"forceConsistentCasingInFileNames": true,
|
14
|
+
"strict": true,
|
15
|
+
"skipLibCheck": true
|
16
|
+
},
|
17
|
+
"include": [
|
18
|
+
"src/**/*"
|
19
|
+
],
|
20
|
+
"exclude": [
|
21
|
+
"node_modules",
|
22
|
+
"dist",
|
23
|
+
"**/*.test.*",
|
24
|
+
"**/*.stories.*"
|
25
|
+
]
|
26
|
+
}
|