@scm-manager/ui-core 3.1.0 → 3.1.1-20240311-150935
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/package.json
CHANGED
|
@@ -30,7 +30,9 @@ import {
|
|
|
30
30
|
ButtonVariants,
|
|
31
31
|
ExternalLinkButton as ExternalLinkButtonComponent,
|
|
32
32
|
LinkButton as LinkButtonComponent,
|
|
33
|
+
IconButton as IconButtonComponent,
|
|
33
34
|
} from "./Button";
|
|
35
|
+
import Icon from "./Icon";
|
|
34
36
|
import StoryRouter from "storybook-react-router";
|
|
35
37
|
import { StoryFn } from "@storybook/react";
|
|
36
38
|
|
|
@@ -42,6 +44,7 @@ export default {
|
|
|
42
44
|
Button: ButtonComponent,
|
|
43
45
|
LinkButton: LinkButtonComponent,
|
|
44
46
|
ExternalLinkButton: ExternalLinkButtonComponent,
|
|
47
|
+
IconButton: IconButtonComponent,
|
|
45
48
|
},
|
|
46
49
|
argTypes: {
|
|
47
50
|
variant: {
|
|
@@ -64,6 +67,10 @@ const ExternalLinkButtonTemplate: StoryFn<ComponentProps<typeof ExternalLinkButt
|
|
|
64
67
|
<ExternalLinkButtonComponent {...args} />
|
|
65
68
|
);
|
|
66
69
|
|
|
70
|
+
const IconButtonTemplate: StoryFn<ComponentProps<typeof IconButtonComponent>> = (args) => (
|
|
71
|
+
<IconButtonComponent {...args} />
|
|
72
|
+
);
|
|
73
|
+
|
|
67
74
|
export const Button = ButtonTemplate.bind({});
|
|
68
75
|
// More on args: https://storybook.js.org/docs/react/writing-stories/args
|
|
69
76
|
Button.args = {
|
|
@@ -87,3 +94,41 @@ ExternalLinkButton.args = {
|
|
|
87
94
|
href: "https://scm-manager.org",
|
|
88
95
|
variant: ButtonVariants.PRIMARY,
|
|
89
96
|
};
|
|
97
|
+
|
|
98
|
+
const smallIcon = <Icon className="is-small">trash</Icon>;
|
|
99
|
+
const mediumIcon = <Icon className="is-medium">trash</Icon>;
|
|
100
|
+
|
|
101
|
+
/*
|
|
102
|
+
|
|
103
|
+
Variant and size are defaulted to medium and colored and do not have to be explicitly added as parameters.
|
|
104
|
+
However for the sake of documentation here they are still passed in
|
|
105
|
+
|
|
106
|
+
*/
|
|
107
|
+
export const IconButtonBorder = IconButtonTemplate.bind({});
|
|
108
|
+
IconButtonBorder.args = {
|
|
109
|
+
children: mediumIcon,
|
|
110
|
+
variant: "colored",
|
|
111
|
+
size: "medium",
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
export const IconButtonBorderDefault = IconButtonTemplate.bind({});
|
|
116
|
+
IconButtonBorderDefault.args = {
|
|
117
|
+
children: mediumIcon,
|
|
118
|
+
variant: "default",
|
|
119
|
+
size: "medium",
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export const IconButtonBorderlessSmall = IconButtonTemplate.bind({});
|
|
123
|
+
IconButtonBorderlessSmall.args = {
|
|
124
|
+
children: smallIcon,
|
|
125
|
+
variant: "colored",
|
|
126
|
+
size: "small",
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
export const IconButtonBorderlessSmallDefault = IconButtonTemplate.bind({});
|
|
130
|
+
IconButtonBorderlessSmallDefault.args = {
|
|
131
|
+
children: smallIcon,
|
|
132
|
+
variant: "default",
|
|
133
|
+
size: "small",
|
|
134
|
+
};
|
|
@@ -22,10 +22,11 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import React, { AnchorHTMLAttributes, ButtonHTMLAttributes } from "react";
|
|
25
|
+
import React, { AnchorHTMLAttributes, ButtonHTMLAttributes, ReactNode } from "react";
|
|
26
26
|
import { Link as ReactRouterLink, LinkProps as ReactRouterLinkProps } from "react-router-dom";
|
|
27
27
|
import classNames from "classnames";
|
|
28
28
|
import { createAttributesForTesting } from "../helpers";
|
|
29
|
+
import styled from "styled-components";
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
32
|
* @beta
|
|
@@ -141,3 +142,85 @@ export const ExternalLinkButton = React.forwardRef<HTMLAnchorElement, ExternalLi
|
|
|
141
142
|
</ExternalLink>
|
|
142
143
|
)
|
|
143
144
|
);
|
|
145
|
+
|
|
146
|
+
const StyledIconButton = styled.button`
|
|
147
|
+
border-radius: 6px !important;
|
|
148
|
+
min-width: 2.5rem;
|
|
149
|
+
height: 2.5rem;
|
|
150
|
+
padding: 0.5em;
|
|
151
|
+
&:not(:disabled) {
|
|
152
|
+
&:hover {
|
|
153
|
+
background-color: color-mix(in srgb, currentColor 10%, transparent);
|
|
154
|
+
}
|
|
155
|
+
&:active {
|
|
156
|
+
background-color: color-mix(in srgb, currentColor 25%, transparent);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
`;
|
|
160
|
+
|
|
161
|
+
const StyledIconButtonCircle = styled.button`
|
|
162
|
+
border-radius: 50% !important;
|
|
163
|
+
border: None;
|
|
164
|
+
min-width: 1.5rem;
|
|
165
|
+
height: 1.5rem;
|
|
166
|
+
padding: 0.5em;
|
|
167
|
+
&:not(:disabled) {
|
|
168
|
+
&:hover {
|
|
169
|
+
background-color: color-mix(in srgb, currentColor 10%, transparent);
|
|
170
|
+
}
|
|
171
|
+
&:active {
|
|
172
|
+
background-color: color-mix(in srgb, currentColor 25%, transparent);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
`;
|
|
176
|
+
|
|
177
|
+
export const IconButtonVariants = {
|
|
178
|
+
COLORED: "colored",
|
|
179
|
+
DEFAULT: "default",
|
|
180
|
+
} as const;
|
|
181
|
+
|
|
182
|
+
export const IconSizes = {
|
|
183
|
+
SMALL: "small",
|
|
184
|
+
MEDIUM: "medium",
|
|
185
|
+
} as const;
|
|
186
|
+
|
|
187
|
+
type IconButtonSize = typeof IconSizes[keyof typeof IconSizes];
|
|
188
|
+
|
|
189
|
+
type IconButtonVariant = typeof IconButtonVariants[keyof typeof IconButtonVariants];
|
|
190
|
+
|
|
191
|
+
const createIconButtonClasses = (variant?: IconButtonVariant) =>
|
|
192
|
+
classNames("button", {
|
|
193
|
+
"is-primary is-outlined": variant === "colored",
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
type IconButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
197
|
+
testId?: string;
|
|
198
|
+
variant?: IconButtonVariant;
|
|
199
|
+
children: ReactNode;
|
|
200
|
+
size?: IconButtonSize;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Styled html button.
|
|
205
|
+
*
|
|
206
|
+
* An icon button has to declare an `aria-label`.
|
|
207
|
+
*
|
|
208
|
+
* @beta
|
|
209
|
+
* @since 3.2.0
|
|
210
|
+
*/
|
|
211
|
+
export const IconButton = React.forwardRef<HTMLButtonElement, IconButtonProps>(
|
|
212
|
+
({ className, variant = "default", size = "medium", testId, type, children, ...props }, ref) => {
|
|
213
|
+
const elementAttributes = {
|
|
214
|
+
type: type ?? "button",
|
|
215
|
+
...props,
|
|
216
|
+
className: classNames(createIconButtonClasses(variant), "button", "has-background-transparent"),
|
|
217
|
+
ref: ref,
|
|
218
|
+
...createAttributesForTesting(testId),
|
|
219
|
+
};
|
|
220
|
+
return size === "small" ? (
|
|
221
|
+
<StyledIconButtonCircle {...elementAttributes}>{children}</StyledIconButtonCircle>
|
|
222
|
+
) : (
|
|
223
|
+
<StyledIconButton {...elementAttributes}>{children}</StyledIconButton>
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
);
|