astrum-ui 0.1.6 → 0.1.7

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.
@@ -21,7 +21,12 @@
21
21
  transition: all ease-in-out 0.15s;
22
22
  }
23
23
 
24
- .astrum-btn:disabled {
24
+ a.astrum-btn {
25
+ text-decoration: none;
26
+ box-sizing: border-box;
27
+ }
28
+
29
+ .astrum-btn:is(:disabled, [aria-disabled="true"]) {
25
30
  cursor: not-allowed;
26
31
  }
27
32
 
@@ -71,12 +76,12 @@
71
76
  color: var(--astrum-primary-white);
72
77
  }
73
78
 
74
- .astrum-btn-primary:hover:not(:disabled) {
79
+ .astrum-btn-primary:hover:not(:disabled):not([aria-disabled="true"]) {
75
80
  background-color: var(--astrum-hover-blue);
76
81
  color: var(--astrum-primary-white);
77
82
  }
78
83
 
79
- .astrum-btn-primary:disabled {
84
+ .astrum-btn-primary:is(:disabled, [aria-disabled="true"]) {
80
85
  background-color: var(--astrum-gray-20);
81
86
  color: var(--astrum-gray-60);
82
87
  }
@@ -87,13 +92,13 @@
87
92
  border: 1px solid var(--astrum-primary-white);
88
93
  }
89
94
 
90
- .astrum-btn-outlined:hover:not(:disabled) {
95
+ .astrum-btn-outlined:hover:not(:disabled):not([aria-disabled="true"]) {
91
96
  background-color: var(--astrum-primary-white);
92
97
  border-color: var(--astrum-primary-white);
93
98
  color: var(--astrum-hover-blue);
94
99
  }
95
100
 
96
- .astrum-btn-outlined:disabled {
101
+ .astrum-btn-outlined:is(:disabled, [aria-disabled="true"]) {
97
102
  background-color: transparent;
98
103
  border-color: transparent;
99
104
  color: var(--astrum-primary-white);
@@ -106,13 +111,13 @@
106
111
  border: 1px dashed var(--astrum-gray-60);
107
112
  }
108
113
 
109
- .astrum-btn-dashed:hover:not(:disabled) {
114
+ .astrum-btn-dashed:hover:not(:disabled):not([aria-disabled="true"]) {
110
115
  background-color: transparent;
111
116
  border-color: var(--astrum-gray-80);
112
117
  color: var(--astrum-gray-80);
113
118
  }
114
119
 
115
- .astrum-btn-dashed:disabled {
120
+ .astrum-btn-dashed:is(:disabled, [aria-disabled="true"]) {
116
121
  background-color: transparent;
117
122
  border-color: transparent;
118
123
  color: transparent;
@@ -124,14 +129,14 @@
124
129
  color: var(--astrum-primary);
125
130
  }
126
131
 
127
- .astrum-btn-grey:hover:not(:disabled) {
132
+ .astrum-btn-grey:hover:not(:disabled):not([aria-disabled="true"]) {
128
133
  outline-width: 2px;
129
134
  outline-color: var(--astrum-primary);
130
135
  background-color: var(--astrum-gray-5);
131
136
  color: var(--astrum-primary);
132
137
  }
133
138
 
134
- .astrum-btn-grey:disabled {
139
+ .astrum-btn-grey:is(:disabled, [aria-disabled="true"]) {
135
140
  background-color: var(--astrum-gray-20);
136
141
  color: var(--astrum-gray-60);
137
142
  }
@@ -142,14 +147,14 @@
142
147
  color: var(--astrum-primary);
143
148
  }
144
149
 
145
- .astrum-btn-white:hover:not(:disabled) {
150
+ .astrum-btn-white:hover:not(:disabled):not([aria-disabled="true"]) {
146
151
  outline-width: 2px;
147
152
  outline-color: var(--astrum-primary);
148
153
  background-color: var(--astrum-primary-white);
149
154
  color: var(--astrum-primary);
150
155
  }
151
156
 
152
- .astrum-btn-white:disabled {
157
+ .astrum-btn-white:is(:disabled, [aria-disabled="true"]) {
153
158
  background-color: var(--astrum-gray-20);
154
159
  color: var(--astrum-gray-60);
155
160
  }
@@ -159,12 +164,12 @@
159
164
  color: var(--astrum-gray-80);
160
165
  }
161
166
 
162
- .astrum-btn-ghost:hover:not(:disabled) {
167
+ .astrum-btn-ghost:hover:not(:disabled):not([aria-disabled="true"]) {
163
168
  background-color: transparent;
164
169
  color: var(--astrum-primary);
165
170
  }
166
171
 
167
- .astrum-btn-ghost:disabled {
172
+ .astrum-btn-ghost:is(:disabled, [aria-disabled="true"]) {
168
173
  background-color: transparent;
169
174
  color: var(--astrum-gray-40);
170
175
  }
package/dist/index.d.mts CHANGED
@@ -1,14 +1,24 @@
1
1
  import * as React from 'react';
2
2
 
3
- interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
3
+ type SharedButtonProps = {
4
4
  variant?: "primary" | "outlined" | "dashed" | "grey" | "white" | "ghost";
5
5
  size?: "s" | "m" | "l";
6
6
  icon?: React.ReactNode;
7
7
  iconPosition?: "left" | "right";
8
8
  shape?: "default" | "square" | "circle";
9
9
  children?: React.ReactNode;
10
- }
11
- declare const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement>>;
10
+ className?: string;
11
+ };
12
+ type ButtonProps = (SharedButtonProps & {
13
+ href?: undefined;
14
+ as?: undefined;
15
+ } & React.ButtonHTMLAttributes<HTMLButtonElement>) | (SharedButtonProps & {
16
+ href: string;
17
+ as?: React.ElementType;
18
+ /** Для ссылки: `aria-disabled` и блокировка перехода */
19
+ disabled?: boolean;
20
+ } & Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, keyof SharedButtonProps | "disabled">);
21
+ declare const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement | HTMLAnchorElement>>;
12
22
 
13
23
  interface ColorPickerProps {
14
24
  value?: string | null;
package/dist/index.d.ts CHANGED
@@ -1,14 +1,24 @@
1
1
  import * as React from 'react';
2
2
 
3
- interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
3
+ type SharedButtonProps = {
4
4
  variant?: "primary" | "outlined" | "dashed" | "grey" | "white" | "ghost";
5
5
  size?: "s" | "m" | "l";
6
6
  icon?: React.ReactNode;
7
7
  iconPosition?: "left" | "right";
8
8
  shape?: "default" | "square" | "circle";
9
9
  children?: React.ReactNode;
10
- }
11
- declare const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement>>;
10
+ className?: string;
11
+ };
12
+ type ButtonProps = (SharedButtonProps & {
13
+ href?: undefined;
14
+ as?: undefined;
15
+ } & React.ButtonHTMLAttributes<HTMLButtonElement>) | (SharedButtonProps & {
16
+ href: string;
17
+ as?: React.ElementType;
18
+ /** Для ссылки: `aria-disabled` и блокировка перехода */
19
+ disabled?: boolean;
20
+ } & Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, keyof SharedButtonProps | "disabled">);
21
+ declare const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement | HTMLAnchorElement>>;
12
22
 
13
23
  interface ColorPickerProps {
14
24
  value?: string | null;
package/dist/index.js CHANGED
@@ -70,16 +70,20 @@ var shapeStyles = {
70
70
  circle: "astrum-btn-shape-circle"
71
71
  };
72
72
  var Button = React.forwardRef(
73
- ({
74
- variant = "primary",
75
- size = "l",
76
- icon,
77
- iconPosition = "right",
78
- shape = "default",
79
- className = "",
80
- children,
81
- ...rest
82
- }, ref) => {
73
+ function Button2(props, ref) {
74
+ const {
75
+ variant = "primary",
76
+ size = "l",
77
+ icon,
78
+ iconPosition = "right",
79
+ shape = "default",
80
+ className = "",
81
+ children,
82
+ href,
83
+ as,
84
+ ...rest
85
+ } = props;
86
+ const isLink = typeof href === "string" && href.length > 0;
83
87
  const iconOnly = icon != null && (children == null || children === "");
84
88
  const effectiveShape = iconOnly && shape !== "default" ? shape : "default";
85
89
  const classes = [
@@ -95,7 +99,45 @@ var Button = React.forwardRef(
95
99
  children != null && children !== "" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "astrum-btn-text", children }),
96
100
  icon && iconPosition === "right" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "astrum-btn-icon", children: icon })
97
101
  ] });
98
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { ref, className: classes, type: "button", ...rest, children: content });
102
+ if (isLink) {
103
+ const Component = as ?? "a";
104
+ const {
105
+ disabled: anchorDisabled,
106
+ onClick,
107
+ onKeyDown,
108
+ ...anchorRest
109
+ } = rest;
110
+ const disabled = Boolean(anchorDisabled);
111
+ const handleClick = (e) => {
112
+ if (disabled) {
113
+ e.preventDefault();
114
+ return;
115
+ }
116
+ onClick?.(e);
117
+ };
118
+ const handleKeyDown = (e) => {
119
+ if (disabled && (e.key === "Enter" || e.key === " ")) {
120
+ e.preventDefault();
121
+ }
122
+ onKeyDown?.(e);
123
+ };
124
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
125
+ Component,
126
+ {
127
+ ref,
128
+ ...anchorRest,
129
+ href,
130
+ className: classes,
131
+ "aria-disabled": disabled || void 0,
132
+ tabIndex: disabled ? -1 : anchorRest.tabIndex,
133
+ onClick: handleClick,
134
+ onKeyDown: handleKeyDown,
135
+ children: content
136
+ }
137
+ );
138
+ }
139
+ const buttonRest = rest;
140
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { ref, className: classes, type: "button", ...buttonRest, children: content });
99
141
  }
100
142
  );
101
143
  Button.displayName = "Button";