@ayseaistudio/ui-components 3.5.0 → 3.5.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.
|
@@ -8,9 +8,10 @@ interface Props {
|
|
|
8
8
|
className?: string;
|
|
9
9
|
fieldClassName?: string;
|
|
10
10
|
onClick?: () => void;
|
|
11
|
+
onChange?: () => void;
|
|
11
12
|
}
|
|
12
13
|
export declare const Checkbox: {
|
|
13
|
-
({ text, size, status, color, className, fieldClassName, onClick, }: Props): React.JSX.Element;
|
|
14
|
+
({ text, size, status, color, className, fieldClassName, onClick, onChange, }: Props): React.JSX.Element;
|
|
14
15
|
propTypes: {
|
|
15
16
|
text: PropTypes.Requireable<string>;
|
|
16
17
|
withText: PropTypes.Requireable<boolean>;
|
|
@@ -3,7 +3,7 @@ import PropTypes from "prop-types";
|
|
|
3
3
|
import { useReducer } from "react";
|
|
4
4
|
import "./style.css";
|
|
5
5
|
import { IconCheck } from "@tabler/icons-react";
|
|
6
|
-
export const Checkbox = ({ text, size, status, color, className, fieldClassName, onClick, }) => {
|
|
6
|
+
export const Checkbox = ({ text, size, status, color, className, fieldClassName, onClick, onChange, }) => {
|
|
7
7
|
const initialState = {
|
|
8
8
|
size: size ?? "large",
|
|
9
9
|
status: status ?? "selected",
|
|
@@ -17,6 +17,7 @@ export const Checkbox = ({ text, size, status, color, className, fieldClassName,
|
|
|
17
17
|
}, onClick: () => {
|
|
18
18
|
dispatch("click");
|
|
19
19
|
onClick?.();
|
|
20
|
+
onChange?.();
|
|
20
21
|
}, children: [_jsx("div", { className: `field ${fieldClassName}`, children: state.status === "selected" && (_jsx(IconCheck, { className: `${state.size === "large" ? "class" : (state.size === "x-small") ? "class-2" : "class-3"}`, color: ["lime", "mauve"].includes(state.color) ? "#3D3D3D" : "#F1F1F1" })) }), text && _jsx("div", { className: "text", children: text })] }));
|
|
21
22
|
};
|
|
22
23
|
function reducer(state, action) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import PropTypes from "prop-types";
|
|
3
|
-
import { useReducer } from "react";
|
|
3
|
+
import { useReducer, useEffect } from "react";
|
|
4
4
|
import "./style.css";
|
|
5
5
|
export const SelectionButton = ({ text, leftIcon, rightIcon, size, color, status, className, onClick, }) => {
|
|
6
6
|
const [state, dispatch] = useReducer(reducer, {
|
|
@@ -8,17 +8,30 @@ export const SelectionButton = ({ text, leftIcon, rightIcon, size, color, status
|
|
|
8
8
|
color: color || "black",
|
|
9
9
|
status: status || "default",
|
|
10
10
|
});
|
|
11
|
+
// Prop'tan gelen status değiştiğinde state'i güncelle (controlled component)
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (status !== undefined) {
|
|
14
|
+
dispatch({ type: "set_status", payload: status });
|
|
15
|
+
}
|
|
16
|
+
}, [status]);
|
|
11
17
|
return (_jsxs("div", { className: `selection-button ${state.size} ${state.status} ${state.color} ${className}`, onMouseEnter: () => {
|
|
12
|
-
|
|
18
|
+
if (state.status === "default") {
|
|
19
|
+
dispatch({ type: "mouse_enter" });
|
|
20
|
+
}
|
|
13
21
|
}, onClick: () => {
|
|
14
|
-
dispatch("click");
|
|
15
22
|
onClick && onClick();
|
|
23
|
+
// Sadece user interaction'da toggle yap, prop kontrolü parent'ta
|
|
24
|
+
if (status === undefined) {
|
|
25
|
+
dispatch({ type: "click" });
|
|
26
|
+
}
|
|
16
27
|
}, onMouseLeave: () => {
|
|
17
|
-
|
|
28
|
+
if (state.status === "hover") {
|
|
29
|
+
dispatch({ type: "mouse_leave" });
|
|
30
|
+
}
|
|
18
31
|
}, children: [leftIcon && (_jsx("span", { className: `${state.size === "small" ? "class icon" : "class-2 icon"}`, children: leftIcon })), text && _jsx("div", { className: "button", children: text }), rightIcon && (_jsx("span", { className: `${state.size === "small" ? "class icon" : "class-2 icon"}`, children: rightIcon }))] }));
|
|
19
32
|
};
|
|
20
33
|
function reducer(state, action) {
|
|
21
|
-
switch (action) {
|
|
34
|
+
switch (action.type) {
|
|
22
35
|
case "mouse_enter":
|
|
23
36
|
return state.status === "default"
|
|
24
37
|
? { ...state, status: "hover" }
|
|
@@ -29,8 +42,11 @@ function reducer(state, action) {
|
|
|
29
42
|
: state;
|
|
30
43
|
case "click":
|
|
31
44
|
return { ...state, status: state.status === "selected" ? "default" : "selected" };
|
|
45
|
+
case "set_status":
|
|
46
|
+
return { ...state, status: action.payload };
|
|
47
|
+
default:
|
|
48
|
+
return state;
|
|
32
49
|
}
|
|
33
|
-
return state;
|
|
34
50
|
}
|
|
35
51
|
SelectionButton.propTypes = {
|
|
36
52
|
text: PropTypes.string,
|