Socket
Socket
Sign inDemoInstall

@launchpad-ui/button

Package Overview
Dependencies
Maintainers
1
Versions
134
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@launchpad-ui/button - npm Package Compare versions

Comparing version 0.4.1 to 0.5.0

dist/IconButton.d.ts

114

dist/Button.d.ts
/// <reference types="react" />
import type { ButtonSize } from './types';
import './styles/Button.css';
import { ButtonKind, ButtonSize, ButtonType } from './types';
declare type ButtonProps = {
/**
* Text for screenreaders to use if the content of the button isn't descriptive (text)
*/
'aria-label'?: string;
/**
* When true, this property will disable the button and show the `loadingText`
*/
import { ButtonKind } from './types';
declare type ButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {
isLoading?: boolean;
/**
* Button text to display when `isLoading` is true
*/
loadingText?: string | JSX.Element;
/**
* One of `button`, `submit`, `reset`, `icon`
*/
type?: ButtonType;
/**
* One of `tiny`, `small`, `normal`, `big`
*/
size?: ButtonSize;
/**
* One of `default`, `primary`, `destructive`, `link`
*/
kind?: ButtonKind;
/**
* When true, the button will take up the full width of its container
*/
fit?: boolean;
/**
* Url to take user to when clicking on button
*/
href?: string;
/**
* Where to open a button link (target="_blank" to open in new tab)
*/
target?: string;
/**
* Icon to add to the contents of the button
*/
disabled?: boolean;
icon?: React.ReactElement<{

@@ -49,64 +17,22 @@ size?: string;

}>;
/**
* When true, adds an outline to icon buttons
*/
outlined?: boolean;
/**
* When true, disables the button
*/
disabled?: boolean;
/**
* Function to execute button is clicked
*/
onClick?(event: React.MouseEvent): void;
/**
* React router compatible location to take user to when button is clicked
*/
to?: string | Record<string, unknown>;
/**
* When true, renders the icon before the text
*/
renderIconFirst?: boolean;
/**
* Custom classname(s) to add to the button
*/
className?: string;
/**
* Adds the html `rel` property to the rendered dom element
*/
rel?: string;
/**
* Sets the tabindex on the button
*/
tabIndex?: number;
/**
* Sets the data-test-id selector on the button for tests
*/
testId?: string;
/**
* Sets the `name` attribute on the dom element
*/
name?: string;
/**
* Function to execute when the mouse enters the button
*/
onMouseEnter?: () => void;
/**
* Function to execute when the mouse leaves the button
*/
onMouseLeave?: () => void;
id?: string;
/**
* Role when `button` is not rendered as the component
*/
role?: string;
/**
* Function to execute when a keyboard key is pressed
*/
onKeyDown?(event: React.KeyboardEvent): void;
children?: React.ReactNode;
asChild?: boolean;
};
declare const Button: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<ButtonProps & import("react").RefAttributes<HTMLAnchorElement | HTMLButtonElement>>>;
declare const Button: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<import("react").ButtonHTMLAttributes<HTMLButtonElement> & {
isLoading?: boolean | undefined;
loadingText?: string | JSX.Element | undefined;
size?: ButtonSize | undefined;
kind?: ButtonKind | undefined;
fit?: boolean | undefined;
disabled?: boolean | undefined;
icon?: import("react").ReactElement<{
size?: string | undefined;
key: string;
'aria-hidden': boolean;
}, string | import("react").JSXElementConstructor<any>> | undefined;
renderIconFirst?: boolean | undefined;
asChild?: boolean | undefined;
} & import("react").RefAttributes<HTMLButtonElement>>>;
export { Button };
export type { ButtonProps };
//# sourceMappingURL=Button.d.ts.map
export type { ButtonProps } from './Button';
export type { UploadButtonProps } from './UploadButton';
export type { ButtonGroupProps } from './ButtonGroup';
export type { IconButtonProps } from './IconButton';
export { Button } from './Button';
export { ButtonGroup } from './ButtonGroup';
export { UploadButton } from './UploadButton';
export { ButtonGroupSpacing, ButtonKind, ButtonSize, ButtonType } from './types';
export { IconButton } from './IconButton';
export { ButtonGroupSpacing, ButtonKind, ButtonSize, ButtonType, IconButtonSize } from './types';
//# sourceMappingURL=index.d.ts.map
// src/Button.tsx
import { Slot } from "@radix-ui/react-slot";
import { cx } from "classix";
import { cloneElement, forwardRef, memo } from "react";
import { isValidElement, cloneElement, forwardRef, memo } from "react";
import "./styles/Button.css";

@@ -10,7 +11,9 @@

ButtonType2["SUBMIT"] = "submit";
ButtonType2["RESET"] = "reset";
ButtonType2["ICON"] = "icon";
ButtonType2["BORDERLESS"] = "borderless";
return ButtonType2;
})(ButtonType || {});
var IconButtonSize = /* @__PURE__ */ ((IconButtonSize2) => {
IconButtonSize2["SMALL"] = "small";
IconButtonSize2["NORMAL"] = "normal";
return IconButtonSize2;
})(IconButtonSize || {});
var ButtonKind = /* @__PURE__ */ ((ButtonKind2) => {

@@ -20,4 +23,5 @@ ButtonKind2["DEFAULT"] = "default";

ButtonKind2["DESTRUCTIVE"] = "destructive";
ButtonKind2["MINIMAL"] = "minimal";
ButtonKind2["LINK"] = "link";
ButtonKind2["SUBMIT"] = "submit";
ButtonKind2["CLOSE"] = "close";
return ButtonKind2;

@@ -41,125 +45,78 @@ })(ButtonKind || {});

import { jsx } from "react/jsx-runtime";
var ButtonComponent = forwardRef(
(props, ref) => {
const {
className,
size = "normal" /* NORMAL */,
fit,
kind = "default" /* DEFAULT */,
icon,
outlined = false,
type,
children,
isLoading,
loadingText,
renderIconFirst = false,
onKeyDown,
disabled = false,
href,
target,
onClick = () => void 0,
to
} = props;
const kindClass = `Button--${kind}`;
const sizeClass = `Button--${size}`;
const classes = cx(
"Button",
className,
kindClass,
sizeClass,
fit && "Button--fit",
type === "icon" && "Button--icon",
type === "icon" && outlined && "Button--outlined",
type === "borderless" && "Button--borderless"
);
const handleClick = (event) => {
if (disabled) {
var ButtonComponent = forwardRef((props, ref) => {
const {
icon,
children,
className,
size,
fit,
kind = "default" /* DEFAULT */,
isLoading = false,
loadingText,
renderIconFirst = false,
disabled = false,
asChild = false,
onKeyDown,
onClick,
...rest
} = props;
const Component = asChild ? Slot : "button";
const classes = cx(
"Button",
`Button--${kind}`,
disabled && "Button--disabled",
size && `Button--${size}`,
fit && "Button--fit",
className
);
const renderIcon = icon && cloneElement(icon, {
key: "icon",
size: icon.props.size || "small",
"aria-hidden": true
});
const getFinalChildren = (c) => [
renderIconFirst && renderIcon,
isLoading && /* @__PURE__ */ jsx("span", {
children: loadingText || c
}, "text"),
!isLoading && c && /* @__PURE__ */ jsx("span", {
children: c
}, "text"),
!renderIconFirst && renderIcon,
isLoading && /* @__PURE__ */ jsx("span", {
children: "\u2026"
}, "spinner")
];
const renderChildren = () => {
if (asChild && isValidElement(children)) {
return cloneElement(children, void 0, getFinalChildren(children.props.children));
}
return getFinalChildren(children);
};
const isDisabled = disabled || isLoading;
const handleClick = (event) => {
if (disabled)
return event.preventDefault();
onClick && onClick(event);
};
const handleKeyDown = (event) => {
if (event.target instanceof HTMLAnchorElement) {
const spacebarKeys = ["Spacebar", " "];
if (spacebarKeys.includes(event.key)) {
event.preventDefault();
return;
const link = event.target;
link.click();
}
onClick && onClick(event);
};
const handleKeyDown = (event) => {
const spacebarKeys = ["Spacebar", " "];
if (!!to || !!href || !!target) {
if (spacebarKeys.includes(event.key)) {
event.preventDefault();
const link = event.target;
link.click();
}
}
};
const extraProps = {
disabled: disabled || isLoading,
className: classes,
onClick: handleClick,
ref,
onKeyDown: onKeyDown || handleKeyDown
};
const renderIcon = icon && cloneElement(icon, {
key: "icon",
size: icon.props.size || "small",
"aria-hidden": true
});
const finalChildren = [
renderIconFirst && renderIcon,
isLoading && /* @__PURE__ */ jsx("span", {
children: loadingText || children
}, "text"),
!isLoading && children && /* @__PURE__ */ jsx("span", {
children
}, "text"),
!renderIconFirst && renderIcon,
isLoading && /* @__PURE__ */ jsx("span", {
children: "\u2026"
}, "spinner")
];
const renderAnchor = (extraProps2, children2) => {
const {
isLoading: isLoading2,
loadingText: loadingText2,
size: size2,
kind: kind2,
fit: fit2,
icon: icon2,
outlined: outlined2,
renderIconFirst: renderIconFirst2,
testId,
...otherProps
} = props;
return /* @__PURE__ */ jsx("a", {
...otherProps,
...extraProps2,
"data-test-id": testId,
children: children2
});
};
const renderButton = (extraProps2, children2) => {
const {
type: type2,
isLoading: isLoading2,
loadingText: loadingText2,
size: size2,
kind: kind2,
fit: fit2,
icon: icon2,
outlined: outlined2,
renderIconFirst: renderIconFirst2,
testId,
...otherProps
} = props;
const buttonType = type2 && type2 !== "icon" /* ICON */ && type2 !== "borderless" /* BORDERLESS */ ? type2 : "button" /* BUTTON */;
return /* @__PURE__ */ jsx("button", {
...otherProps,
...extraProps2,
type: buttonType,
"data-test-id": testId,
children: children2
});
};
const renderFunc = href || target ? renderAnchor : renderButton;
const content = renderFunc(extraProps, finalChildren);
return content;
}
);
}
};
return /* @__PURE__ */ jsx(Component, {
className: classes,
ref,
onClick: handleClick,
onKeyDown: onKeyDown || handleKeyDown,
disabled: isDisabled,
...rest,
children: renderChildren()
});
});
ButtonComponent.displayName = "Button";

@@ -259,2 +216,70 @@ var Button = memo(ButtonComponent);

};
// src/IconButton.tsx
import { Slot as Slot2 } from "@radix-ui/react-slot";
import { cx as cx4 } from "classix";
import { isValidElement as isValidElement2, cloneElement as cloneElement2, forwardRef as forwardRef2, memo as memo2 } from "react";
import "./styles/Button.css";
import { jsx as jsx4 } from "react/jsx-runtime";
var IconButtonComponent = forwardRef2((props, ref) => {
const {
icon,
children,
className,
size = "normal" /* NORMAL */,
kind = "minimal" /* MINIMAL */,
disabled = false,
asChild = false,
onKeyDown,
onClick,
...rest
} = props;
const Component = asChild ? Slot2 : "button";
const classes = cx4(
"IconButton",
"Button",
"Button--icon",
`Button--${kind}`,
disabled && "Button--disabled",
size && `Button--${size}`,
className
);
const clonedIcon = cloneElement2(icon, {
key: "icon",
size: icon.props.size || "medium",
"aria-hidden": true
});
const renderChildren = () => {
if (asChild && isValidElement2(children)) {
return cloneElement2(children, void 0, clonedIcon);
}
return clonedIcon;
};
const handleClick = (event) => {
if (disabled)
return event.preventDefault();
onClick && onClick(event);
};
const handleKeyDown = (event) => {
if (event.target instanceof HTMLAnchorElement) {
const spacebarKeys = ["Spacebar", " "];
if (spacebarKeys.includes(event.key)) {
event.preventDefault();
const link = event.target;
link.click();
}
}
};
return /* @__PURE__ */ jsx4(Component, {
className: classes,
ref,
onClick: handleClick,
disabled,
onKeyDown: onKeyDown || handleKeyDown,
...rest,
children: renderChildren()
});
});
IconButtonComponent.displayName = "IconButton";
var IconButton = memo2(IconButtonComponent);
export {

@@ -267,4 +292,6 @@ Button,

ButtonType,
IconButton,
IconButtonSize,
UploadButton
};
//# sourceMappingURL=index.es.js.map

@@ -29,2 +29,4 @@ "use strict";

ButtonType: () => ButtonType,
IconButton: () => IconButton,
IconButtonSize: () => IconButtonSize,
UploadButton: () => UploadButton

@@ -35,2 +37,3 @@ });

// src/Button.tsx
var import_react_slot = require("@radix-ui/react-slot");
var import_classix = require("classix");

@@ -44,7 +47,9 @@ var import_react = require("react");

ButtonType2["SUBMIT"] = "submit";
ButtonType2["RESET"] = "reset";
ButtonType2["ICON"] = "icon";
ButtonType2["BORDERLESS"] = "borderless";
return ButtonType2;
})(ButtonType || {});
var IconButtonSize = /* @__PURE__ */ ((IconButtonSize2) => {
IconButtonSize2["SMALL"] = "small";
IconButtonSize2["NORMAL"] = "normal";
return IconButtonSize2;
})(IconButtonSize || {});
var ButtonKind = /* @__PURE__ */ ((ButtonKind2) => {

@@ -54,4 +59,5 @@ ButtonKind2["DEFAULT"] = "default";

ButtonKind2["DESTRUCTIVE"] = "destructive";
ButtonKind2["MINIMAL"] = "minimal";
ButtonKind2["LINK"] = "link";
ButtonKind2["SUBMIT"] = "submit";
ButtonKind2["CLOSE"] = "close";
return ButtonKind2;

@@ -75,125 +81,78 @@ })(ButtonKind || {});

var import_jsx_runtime = require("react/jsx-runtime");
var ButtonComponent = (0, import_react.forwardRef)(
(props, ref) => {
const {
className,
size = "normal" /* NORMAL */,
fit,
kind = "default" /* DEFAULT */,
icon,
outlined = false,
type,
children,
isLoading,
loadingText,
renderIconFirst = false,
onKeyDown,
disabled = false,
href,
target,
onClick = () => void 0,
to
} = props;
const kindClass = `Button--${kind}`;
const sizeClass = `Button--${size}`;
const classes = (0, import_classix.cx)(
"Button",
className,
kindClass,
sizeClass,
fit && "Button--fit",
type === "icon" && "Button--icon",
type === "icon" && outlined && "Button--outlined",
type === "borderless" && "Button--borderless"
);
const handleClick = (event) => {
if (disabled) {
var ButtonComponent = (0, import_react.forwardRef)((props, ref) => {
const {
icon,
children,
className,
size,
fit,
kind = "default" /* DEFAULT */,
isLoading = false,
loadingText,
renderIconFirst = false,
disabled = false,
asChild = false,
onKeyDown,
onClick,
...rest
} = props;
const Component = asChild ? import_react_slot.Slot : "button";
const classes = (0, import_classix.cx)(
"Button",
`Button--${kind}`,
disabled && "Button--disabled",
size && `Button--${size}`,
fit && "Button--fit",
className
);
const renderIcon = icon && (0, import_react.cloneElement)(icon, {
key: "icon",
size: icon.props.size || "small",
"aria-hidden": true
});
const getFinalChildren = (c) => [
renderIconFirst && renderIcon,
isLoading && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
children: loadingText || c
}, "text"),
!isLoading && c && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
children: c
}, "text"),
!renderIconFirst && renderIcon,
isLoading && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
children: "\u2026"
}, "spinner")
];
const renderChildren = () => {
if (asChild && (0, import_react.isValidElement)(children)) {
return (0, import_react.cloneElement)(children, void 0, getFinalChildren(children.props.children));
}
return getFinalChildren(children);
};
const isDisabled = disabled || isLoading;
const handleClick = (event) => {
if (disabled)
return event.preventDefault();
onClick && onClick(event);
};
const handleKeyDown = (event) => {
if (event.target instanceof HTMLAnchorElement) {
const spacebarKeys = ["Spacebar", " "];
if (spacebarKeys.includes(event.key)) {
event.preventDefault();
return;
const link = event.target;
link.click();
}
onClick && onClick(event);
};
const handleKeyDown = (event) => {
const spacebarKeys = ["Spacebar", " "];
if (!!to || !!href || !!target) {
if (spacebarKeys.includes(event.key)) {
event.preventDefault();
const link = event.target;
link.click();
}
}
};
const extraProps = {
disabled: disabled || isLoading,
className: classes,
onClick: handleClick,
ref,
onKeyDown: onKeyDown || handleKeyDown
};
const renderIcon = icon && (0, import_react.cloneElement)(icon, {
key: "icon",
size: icon.props.size || "small",
"aria-hidden": true
});
const finalChildren = [
renderIconFirst && renderIcon,
isLoading && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
children: loadingText || children
}, "text"),
!isLoading && children && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
children
}, "text"),
!renderIconFirst && renderIcon,
isLoading && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
children: "\u2026"
}, "spinner")
];
const renderAnchor = (extraProps2, children2) => {
const {
isLoading: isLoading2,
loadingText: loadingText2,
size: size2,
kind: kind2,
fit: fit2,
icon: icon2,
outlined: outlined2,
renderIconFirst: renderIconFirst2,
testId,
...otherProps
} = props;
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", {
...otherProps,
...extraProps2,
"data-test-id": testId,
children: children2
});
};
const renderButton = (extraProps2, children2) => {
const {
type: type2,
isLoading: isLoading2,
loadingText: loadingText2,
size: size2,
kind: kind2,
fit: fit2,
icon: icon2,
outlined: outlined2,
renderIconFirst: renderIconFirst2,
testId,
...otherProps
} = props;
const buttonType = type2 && type2 !== "icon" /* ICON */ && type2 !== "borderless" /* BORDERLESS */ ? type2 : "button" /* BUTTON */;
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
...otherProps,
...extraProps2,
type: buttonType,
"data-test-id": testId,
children: children2
});
};
const renderFunc = href || target ? renderAnchor : renderButton;
const content = renderFunc(extraProps, finalChildren);
return content;
}
);
}
};
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {
className: classes,
ref,
onClick: handleClick,
onKeyDown: onKeyDown || handleKeyDown,
disabled: isDisabled,
...rest,
children: renderChildren()
});
});
ButtonComponent.displayName = "Button";

@@ -293,2 +252,70 @@ var Button = (0, import_react.memo)(ButtonComponent);

};
// src/IconButton.tsx
var import_react_slot2 = require("@radix-ui/react-slot");
var import_classix4 = require("classix");
var import_react3 = require("react");
var import_Button2 = require("./styles/Button.css");
var import_jsx_runtime = require("react/jsx-runtime");
var IconButtonComponent = (0, import_react3.forwardRef)((props, ref) => {
const {
icon,
children,
className,
size = "normal" /* NORMAL */,
kind = "minimal" /* MINIMAL */,
disabled = false,
asChild = false,
onKeyDown,
onClick,
...rest
} = props;
const Component = asChild ? import_react_slot2.Slot : "button";
const classes = (0, import_classix4.cx)(
"IconButton",
"Button",
"Button--icon",
`Button--${kind}`,
disabled && "Button--disabled",
size && `Button--${size}`,
className
);
const clonedIcon = (0, import_react3.cloneElement)(icon, {
key: "icon",
size: icon.props.size || "medium",
"aria-hidden": true
});
const renderChildren = () => {
if (asChild && (0, import_react3.isValidElement)(children)) {
return (0, import_react3.cloneElement)(children, void 0, clonedIcon);
}
return clonedIcon;
};
const handleClick = (event) => {
if (disabled)
return event.preventDefault();
onClick && onClick(event);
};
const handleKeyDown = (event) => {
if (event.target instanceof HTMLAnchorElement) {
const spacebarKeys = ["Spacebar", " "];
if (spacebarKeys.includes(event.key)) {
event.preventDefault();
const link = event.target;
link.click();
}
}
};
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {
className: classes,
ref,
onClick: handleClick,
disabled,
onKeyDown: onKeyDown || handleKeyDown,
...rest,
children: renderChildren()
});
});
IconButtonComponent.displayName = "IconButton";
var IconButton = (0, import_react3.memo)(IconButtonComponent);
// Annotate the CommonJS export names for ESM import in node:

@@ -302,4 +329,6 @@ 0 && (module.exports = {

ButtonType,
IconButton,
IconButtonSize,
UploadButton
});
//# sourceMappingURL=index.js.map
declare enum ButtonType {
BUTTON = "button",
SUBMIT = "submit",
RESET = "reset",
ICON = "icon",
BORDERLESS = "borderless"
SUBMIT = "submit"
}
declare enum IconButtonSize {
SMALL = "small",
NORMAL = "normal"
}
declare enum EllipsisButtonType {

@@ -19,4 +20,5 @@ VERTICAL = "vertical",

DESTRUCTIVE = "destructive",
MINIMAL = "minimal",
LINK = "link",
SUBMIT = "submit"
CLOSE = "close"
}

@@ -34,3 +36,3 @@ declare enum ButtonSize {

}
export { ButtonType, EllipsisButtonType, ButtonKind, ButtonSize, ButtonGroupSpacing };
export { ButtonType, EllipsisButtonType, ButtonKind, ButtonSize, IconButtonSize, ButtonGroupSpacing, };
//# sourceMappingURL=types.d.ts.map
{
"name": "@launchpad-ui/button",
"version": "0.4.1",
"version": "0.5.0",
"status": "beta",

@@ -30,2 +30,3 @@ "publishConfig": {

"@launchpad-ui/tokens": "~0.1.5",
"@radix-ui/react-slot": "^1.0.0",
"classix": "^2.1.13"

@@ -32,0 +33,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc