@yusufalperendumlu/component-library 0.0.6 → 0.0.8

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.
@@ -1,102 +1,102 @@
1
- import React, { useState } from "react";
2
- import type { Meta, StoryObj } from "@storybook/react";
3
- import Dialog from "./Dialog";
4
- import Button from "../Button";
5
- const meta: Meta<typeof Dialog> = {
6
- title: "Components/Dialog",
7
- component: Dialog,
8
- tags: ["autodocs"],
9
- };
10
-
11
- export default meta;
12
- type Story = StoryObj<typeof Dialog>;
13
-
14
- const DialogWrapper = ({
15
- title,
16
- body,
17
- variant = "default",
18
- confirmText = "Update",
19
- cancelText = "Cancel",
20
- }: {
21
- title: string;
22
- body: React.ReactNode;
23
- variant?: "default" | "destructive";
24
- confirmText?: string;
25
- cancelText?: string;
26
- }) => {
27
- const [open, setOpen] = useState(false);
28
-
29
- return (
30
- <>
31
- <Button onClick={() => setOpen(true)} variant="outline" title={title} />
32
- <Dialog isOpen={open} onClose={() => setOpen(false)}>
33
- <Dialog.Header>{title}</Dialog.Header>
34
- <Dialog.Body>{body}</Dialog.Body>
35
- <Dialog.Footer>
36
- <Button
37
- variant="outline"
38
- onClick={() => setOpen(false)}
39
- title={cancelText}
40
- size="small"
41
- />
42
-
43
- <Button
44
- onClick={() => setOpen(false)}
45
- title={confirmText}
46
- variant="primary"
47
- size="small"
48
- />
49
- </Dialog.Footer>
50
- </Dialog>
51
- </>
52
- );
53
- };
54
-
55
- // 🟣 Update Dialog
56
- export const UpdateDialog: Story = {
57
- render: () => (
58
- <DialogWrapper
59
- title="Update XY1234"
60
- body={
61
- <>
62
- <div className="mb-4">
63
- <label className="block text-sm mb-1">Type</label>
64
- <select className="w-full border rounded p-2 dark:bg-zinc-800">
65
- <option>Passenger</option>
66
- <option>Cargo</option>
67
- </select>
68
- </div>
69
- <div>
70
- <label className="block text-sm mb-1">Classification</label>
71
- <select className="w-full border rounded p-2 dark:bg-zinc-800">
72
- <option>Friendly</option>
73
- <option>Hostile</option>
74
- </select>
75
- </div>
76
- </>
77
- }
78
- />
79
- ),
80
- };
81
-
82
- // 🔴 Delete Dialog
83
- export const DeleteDialog: Story = {
84
- render: () => (
85
- <DialogWrapper
86
- title="Delete XY1234"
87
- variant="destructive"
88
- confirmText="Delete"
89
- body={
90
- <>
91
- <p className="text-base font-semibold text-zinc-900 dark:text-white">
92
- Are you sure you want to delete aircraft XY1234?
93
- </p>
94
- <p className="text-sm text-zinc-500 dark:text-zinc-400 mt-2">
95
- This action cannot be undone. The aircraft will be permanently
96
- removed from the system.
97
- </p>
98
- </>
99
- }
100
- />
101
- ),
102
- };
1
+ import React, { useState } from 'react';
2
+ import type { Meta, StoryObj } from '@storybook/react';
3
+ import Dialog from './Dialog';
4
+ import Button from '../Button';
5
+ const meta: Meta<typeof Dialog> = {
6
+ title: 'Components/Dialog',
7
+ component: Dialog,
8
+ tags: ['autodocs'],
9
+ };
10
+
11
+ export default meta;
12
+ type Story = StoryObj<typeof Dialog>;
13
+
14
+ const DialogWrapper = ({
15
+ title,
16
+ body,
17
+ variant = 'default',
18
+ confirmText = 'Update',
19
+ cancelText = 'Cancel',
20
+ }: {
21
+ title: string;
22
+ body: React.ReactNode;
23
+ variant?: 'default' | 'destructive';
24
+ confirmText?: string;
25
+ cancelText?: string;
26
+ }) => {
27
+ const [open, setOpen] = useState(false);
28
+
29
+ return (
30
+ <>
31
+ <Button onClick={() => setOpen(true)} variant='outline' title={title} />
32
+ <Dialog isOpen={open} onClose={() => setOpen(false)}>
33
+ <Dialog.Header>{title}</Dialog.Header>
34
+ <Dialog.Body>{body}</Dialog.Body>
35
+ <Dialog.Footer>
36
+ <Button
37
+ variant='outline'
38
+ onClick={() => setOpen(false)}
39
+ title={cancelText}
40
+ size='small'
41
+ />
42
+
43
+ <Button
44
+ onClick={() => setOpen(false)}
45
+ title={confirmText}
46
+ variant='primary'
47
+ size='small'
48
+ />
49
+ </Dialog.Footer>
50
+ </Dialog>
51
+ </>
52
+ );
53
+ };
54
+
55
+ // 🟣 Update Dialog
56
+ export const UpdateDialog: Story = {
57
+ render: () => (
58
+ <DialogWrapper
59
+ title='Update XY1234'
60
+ body={
61
+ <>
62
+ <div className='mb-4'>
63
+ <label className='block text-sm mb-1'>Type</label>
64
+ <select className='w-full border rounded p-2 dark:bg-zinc-800'>
65
+ <option>Passenger</option>
66
+ <option>Cargo</option>
67
+ </select>
68
+ </div>
69
+ <div>
70
+ <label className='block text-sm mb-1'>Classification</label>
71
+ <select className='w-full border rounded p-2 dark:bg-zinc-800'>
72
+ <option>Friendly</option>
73
+ <option>Hostile</option>
74
+ </select>
75
+ </div>
76
+ </>
77
+ }
78
+ />
79
+ ),
80
+ };
81
+
82
+ // 🔴 Delete Dialog
83
+ export const DeleteDialog: Story = {
84
+ render: () => (
85
+ <DialogWrapper
86
+ title='Delete XY1234'
87
+ variant='destructive'
88
+ confirmText='Delete'
89
+ body={
90
+ <>
91
+ <p className='text-base font-semibold text-zinc-900 dark:text-white'>
92
+ Are you sure you want to delete aircraft XY1234?
93
+ </p>
94
+ <p className='text-sm text-zinc-500 dark:text-zinc-400 mt-2'>
95
+ This action cannot be undone. The aircraft will be permanently
96
+ removed from the system.
97
+ </p>
98
+ </>
99
+ }
100
+ />
101
+ ),
102
+ };
@@ -1,34 +1,34 @@
1
- import React from "react";
2
- import type { Meta, StoryObj } from "@storybook/react";
3
- import Input from "./Input";
4
-
5
- const meta: Meta<typeof Input> = {
6
- title: "Components/Input",
7
- component: Input,
8
- tags: ["autodocs"],
9
- argTypes: {
10
- placeholder: {
11
- control: "text",
12
- description: "Placeholder text for the input field",
13
- },
14
- },
15
- };
16
-
17
- export default meta;
18
-
19
- type Story = StoryObj<typeof Input>;
20
-
21
- export const Primary: Story = {
22
- args: {
23
- label: "Input",
24
- placeholder: "Enter text here",
25
- type: "text",
26
- },
27
- };
28
-
29
- export const Secondary: Story = {
30
- args: {
31
- placeholder: "Search...",
32
- type: "dropdown",
33
- },
34
- };
1
+ import React from 'react';
2
+ import type { Meta, StoryObj } from '@storybook/react';
3
+ import Input from './Input';
4
+
5
+ const meta: Meta<typeof Input> = {
6
+ title: 'Components/Input',
7
+ component: Input,
8
+ tags: ['autodocs'],
9
+ argTypes: {
10
+ placeholder: {
11
+ control: 'text',
12
+ description: 'Placeholder text for the input field',
13
+ },
14
+ },
15
+ };
16
+
17
+ export default meta;
18
+
19
+ type Story = StoryObj<typeof Input>;
20
+
21
+ export const Primary: Story = {
22
+ args: {
23
+ label: 'Input',
24
+ placeholder: 'Enter text here',
25
+ type: 'text',
26
+ },
27
+ };
28
+
29
+ export const Secondary: Story = {
30
+ args: {
31
+ placeholder: 'Search...',
32
+ type: 'dropdown',
33
+ },
34
+ };
@@ -1,53 +1,53 @@
1
- import React from "react";
2
- import { Meta, StoryFn } from "@storybook/react";
3
- import Table from "./Table";
4
- import { TableColumn } from "./Table.types";
5
-
6
- interface Person {
7
- id: number;
8
- name: string;
9
- age: number;
10
- email: string;
11
- }
12
-
13
- const columns: TableColumn<Person>[] = [
14
- { key: "id", label: "ID", sortable: true },
15
- { key: "name", label: "Name", sortable: true },
16
- { key: "age", label: "Age", sortable: true },
17
- {
18
- key: "email",
19
- label: "Email",
20
- render: (value) => (
21
- <a href={`mailto:${value}`} className="text-blue-400 underline">
22
- {value}
23
- </a>
24
- ),
25
- },
26
- ];
27
-
28
- const data: Person[] = [
29
- { id: 1, name: "Alice", age: 28, email: "alice@example.com" },
30
- { id: 2, name: "Bob", age: 34, email: "bob@example.com" },
31
- { id: 3, name: "Charlie", age: 22, email: "charlie@example.com" },
32
- ];
33
-
34
- const meta: Meta<typeof Table> = {
35
- title: "Components/Table",
36
- component: Table,
37
- argTypes: {
38
- onRowClick: { action: "row clicked" },
39
- },
40
- };
41
-
42
- export default meta;
43
-
44
- const Template: StoryFn<React.ComponentProps<typeof Table<Person>>> = (
45
- args
46
- ) => <Table {...args} />;
47
-
48
- export const Default = Template.bind({});
49
- Default.args = {
50
- columns,
51
- data,
52
- onRowClick: (row) => console.log("Row clicked:", row),
53
- };
1
+ import React from 'react';
2
+ import { Meta, StoryFn } from '@storybook/react';
3
+ import Table from './Table';
4
+ import { TableColumn } from './Table.types';
5
+
6
+ interface Person {
7
+ id: number;
8
+ name: string;
9
+ age: number;
10
+ email: string;
11
+ }
12
+
13
+ const columns: TableColumn<Person>[] = [
14
+ { key: 'id', label: 'ID', sortable: true },
15
+ { key: 'name', label: 'Name', sortable: true },
16
+ { key: 'age', label: 'Age', sortable: true },
17
+ {
18
+ key: 'email',
19
+ label: 'Email',
20
+ render: value => (
21
+ <a href={`mailto:${value}`} className='text-blue-400 underline'>
22
+ {value}
23
+ </a>
24
+ ),
25
+ },
26
+ ];
27
+
28
+ const data: Person[] = [
29
+ { id: 1, name: 'Alice', age: 28, email: 'alice@example.com' },
30
+ { id: 2, name: 'Bob', age: 34, email: 'bob@example.com' },
31
+ { id: 3, name: 'Charlie', age: 22, email: 'charlie@example.com' },
32
+ ];
33
+
34
+ const meta: Meta<typeof Table> = {
35
+ title: 'Components/Table',
36
+ component: Table,
37
+ argTypes: {
38
+ onRowClick: { action: 'row clicked' },
39
+ },
40
+ };
41
+
42
+ export default meta;
43
+
44
+ const Template: StoryFn<React.ComponentProps<typeof Table<Person>>> = args => (
45
+ <Table {...args} />
46
+ );
47
+
48
+ export const Default = Template.bind({});
49
+ Default.args = {
50
+ columns,
51
+ data,
52
+ onRowClick: row => console.log('Row clicked:', row),
53
+ };
@@ -0,0 +1,44 @@
1
+ // Toast.stories.tsx
2
+ import React from 'react';
3
+ import type { Meta, StoryObj } from '@storybook/react';
4
+ import Toast from './Toast';
5
+
6
+ const meta: Meta<typeof Toast> = {
7
+ title: 'Components/Toast',
8
+ component: Toast,
9
+ tags: ['autodocs'],
10
+ argTypes: {
11
+ type: {
12
+ control: 'radio',
13
+ options: ['success', 'error'],
14
+ },
15
+ position: {
16
+ control: 'radio',
17
+ options: ['top-left', 'top-right', 'bottom-left', 'bottom-right'],
18
+ },
19
+ },
20
+ };
21
+
22
+ export default meta;
23
+
24
+ type Story = StoryObj<typeof Toast>;
25
+
26
+ export const SuccessTopRight: Story = {
27
+ args: {
28
+ title: 'Success',
29
+ description: 'Operation was successful!',
30
+ duration: 3000,
31
+ type: 'success',
32
+ position: 'top-right',
33
+ },
34
+ };
35
+
36
+ export const ErrorBottomLeft: Story = {
37
+ args: {
38
+ title: 'Error',
39
+ description: 'Something went wrong!',
40
+ duration: 3000,
41
+ type: 'error',
42
+ position: 'bottom-left',
43
+ },
44
+ };
@@ -0,0 +1,70 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { cva } from 'class-variance-authority';
3
+ import { IoClose } from 'react-icons/io5';
4
+ import clsx from 'clsx';
5
+
6
+ import { toastIcons } from './icons';
7
+ import { ToastProps } from './Toast.types';
8
+
9
+ const toastVariants = cva(
10
+ 'flex items-center justify-between w-full max-w-xs px-4 py-2 rounded-md shadow-md transition-opacity duration-300',
11
+ {
12
+ variants: {
13
+ type: {
14
+ success: 'bg-green-500 text-white',
15
+ error: 'bg-red-500 text-white',
16
+ },
17
+ position: {
18
+ 'top-left': 'fixed top-4 left-4',
19
+ 'top-right': 'fixed top-4 right-4',
20
+ 'bottom-left': 'fixed bottom-4 left-4',
21
+ 'bottom-right': 'fixed bottom-4 right-4',
22
+ },
23
+ },
24
+ defaultVariants: {
25
+ type: 'success',
26
+ position: 'top-right',
27
+ },
28
+ }
29
+ );
30
+
31
+ const Toast: React.FC<ToastProps> = ({
32
+ title,
33
+ description,
34
+ duration,
35
+ type,
36
+ position,
37
+ }) => {
38
+ const [isOpen, setIsOpen] = useState(true);
39
+
40
+ const handleClose = () => {
41
+ setIsOpen(false);
42
+ };
43
+
44
+ useEffect(() => {
45
+ if (!duration) return;
46
+
47
+ const timer = setTimeout(() => {
48
+ handleClose();
49
+ }, duration);
50
+
51
+ return () => clearTimeout(timer);
52
+ }, [duration]);
53
+
54
+ if (!isOpen) return null;
55
+
56
+ return (
57
+ <div className={clsx(toastVariants({ type, position }))}>
58
+ <span>{toastIcons[type]}</span>
59
+ <div className='flex flex-col ml-2 flex-1'>
60
+ <span className='font-semibold'>{title}</span>
61
+ <span className='text-sm'>{description}</span>
62
+ </div>
63
+ <button onClick={handleClose} className='ml-4'>
64
+ <IoClose size={16} />
65
+ </button>
66
+ </div>
67
+ );
68
+ };
69
+
70
+ export default Toast;
@@ -0,0 +1,7 @@
1
+ export type ToastProps = {
2
+ title: string;
3
+ description: string;
4
+ duration?: number;
5
+ type: 'success' | 'error';
6
+ position: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
7
+ };
@@ -0,0 +1,9 @@
1
+ import { TiTick } from 'react-icons/ti';
2
+ import { FaTriangleExclamation } from 'react-icons/fa6';
3
+
4
+ export const toastIcons = {
5
+ success: (
6
+ <TiTick className='text-green-500 h-6 w-6 bg-white p-1 rounded-full text-sm mr-2' />
7
+ ),
8
+ error: <FaTriangleExclamation className='text-white text-lg mr-2' />,
9
+ };
@@ -0,0 +1,3 @@
1
+ import Toast from "./Toast";
2
+
3
+ export default Toast;
@@ -3,3 +3,4 @@ export { default as Button } from './Button';
3
3
  export { default as Dialog } from './Dialog';
4
4
  export { default as Input } from './Input';
5
5
  export { default as Table } from './Table';
6
+ export { default as Toast } from './Toast';