UNPKG

@teamsparta/stack-button

Version:
190 lines (185 loc) 6.46 kB
"use client"; "use strict"; "use client"; var __defProp = Object.defineProperty; var __defProps = Object.defineProperties; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropDescs = Object.getOwnPropertyDescriptors; var __getOwnPropNames = Object.getOwnPropertyNames; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) { if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]); } return a; }; var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); var __objRest = (source, exclude) => { var target = {}; for (var prop in source) if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0) target[prop] = source[prop]; if (source != null && __getOwnPropSymbols) for (var prop of __getOwnPropSymbols(source)) { if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop)) target[prop] = source[prop]; } return target; }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/TextButton/TextButton.tsx var TextButton_exports = {}; __export(TextButton_exports, { TextButton: () => TextButton }); module.exports = __toCommonJS(TextButton_exports); var import_stack_core = require("@teamsparta/stack-core"); var import_stack_tokens2 = require("@teamsparta/stack-tokens"); var import_react2 = require("react"); // src/TextButton/TextButton.style.ts var import_react = require("@emotion/react"); var import_stack_font = require("@teamsparta/stack-font"); var import_stack_tokens = require("@teamsparta/stack-tokens"); var import_stack_utils = require("@teamsparta/stack-utils"); var textButtonIconVariants = { sm: { svg: { width: "16px", height: "16px" } }, md: { svg: { width: "16px", height: "16px" } }, lg: { svg: { width: "20px", height: "20px" } } }; var buttonTextFontVariants = { sm: import_stack_font.captionSb, md: import_stack_font.bodyB, lg: import_stack_font.subTitle3 }; var textButtonTextColorVar = "--stack-text-button-text-color"; var buttonTextCss = (sizes) => sizes.map( ({ breakpoint, size }) => import_react.css` @media screen and (min-width: ${breakpoint}px) { ${buttonTextFontVariants[size]} } ` ); var buttonBaseCss = (0, import_react.css)({ position: "relative", display: "inline-flex", gap: "4px", alignItems: "center", justifyContent: "center", cursor: "pointer", outline: "none", backgroundColor: "transparent", border: "none", textAlign: "center", color: (0, import_stack_utils.getVar)(textButtonTextColorVar), "&:focus": { outline: "revert" } }); var addonCss = (0, import_react.css)({ display: "inline-flex", alignItems: "center", justifyContent: "center" }); var textButtonColorVariants = { default: { [textButtonTextColorVar]: import_stack_tokens.vars.neutral[50] }, link: { [textButtonTextColorVar]: import_stack_tokens.vars.blue[70] } }; var buttonIconSizeCss = (sizes) => sizes.map( ({ breakpoint, size }) => import_react.css` @media screen and (min-width: ${breakpoint}px) { ${textButtonIconVariants[size]} } ` ); // src/TextButton/TextButton.tsx var import_jsx_runtime = require("@emotion/react/jsx-runtime"); var TextButton = (0, import_react2.forwardRef)( function _TextButton(_a, ref) { var _b = _a, { variant = "default", size: sizeFromProps = "md", style: styleFromProps, leftAddon, rightAddon, children } = _b, restProps = __objRest(_b, [ "variant", "size", "style", "leftAddon", "rightAddon", "children" ]); var _a2, _b2, _c, _d, _e, _f; const breakpoints = (0, import_stack_core.useBreakpointContext)("TextButton"); const sizes = (0, import_stack_core.mapResponsive)( breakpoints, sizeFromProps, (breakpoint, size) => ({ breakpoint, size }) ); const style = __spreadValues(__spreadValues({}, textButtonColorVariants[variant]), styleFromProps); const buttonContainerCss = [ buttonBaseCss, buttonIconSizeCss(sizes), buttonTextCss(sizes) ]; const color = variant === "link" ? import_stack_tokens2.vars.blue[70] : import_stack_tokens2.vars.neutral[50]; const enhancedLeftIcon = (0, import_react2.isValidElement)(leftAddon) ? (0, import_react2.cloneElement)(leftAddon, __spreadProps(__spreadValues({}, (_a2 = leftAddon.props) != null ? _a2 : {}), { color: (_c = (_b2 = leftAddon.props) == null ? void 0 : _b2.color) != null ? _c : color })) : leftAddon; const enhancedRightIcon = (0, import_react2.isValidElement)(rightAddon) ? (0, import_react2.cloneElement)(rightAddon, __spreadProps(__spreadValues({}, (_d = rightAddon.props) != null ? _d : {}), { color: (_f = (_e = rightAddon.props) == null ? void 0 : _e.color) != null ? _f : color })) : rightAddon; return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", __spreadProps(__spreadValues({ ref, style, css: buttonContainerCss }, restProps), { children: [ leftAddon && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { css: addonCss, children: enhancedLeftIcon }), children, rightAddon && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { css: addonCss, children: enhancedRightIcon }) ] })); } ); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { TextButton });