UNPKG

@workday/canvas-kit-react

Version:

The parent module that contains all Workday Canvas Kit React components

165 lines (164 loc) • 6.15 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DeprecatedButton = void 0; const React = __importStar(require("react")); const tokens_1 = require("@workday/canvas-kit-react/tokens"); const common_1 = require("@workday/canvas-kit-react/common"); const styled_1 = __importDefault(require("@emotion/styled")); const Container = (0, styled_1.default)('button')({ fontFamily: tokens_1.type.properties.fontFamilies.default, fontSize: 14, fontWeight: 500, boxSizing: 'border-box', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', borderRadius: tokens_1.borderRadius.circle, border: '1px solid transparent', boxShadow: 'none', position: 'relative', cursor: 'pointer', outline: 'none', transition: 'box-shadow 120ms linear, border 120ms linear, background-color 120ms linear, color 120ms linear', // Makes the "down" state of the button happens faster than the hover state, so it animates in correctly. '&:hover:active': { transitionDuration: '40ms' }, '&:disabled, &:disabled:active': { cursor: 'default', boxShadow: 'none' }, }, ({ size }) => { switch (size) { case 'large': return { height: '40px', padding: `0 ${tokens_1.canvas.space.l}`, minWidth: '112px', maxWidth: '288px', }; case 'medium': default: return { height: '24px', padding: `0 ${tokens_1.canvas.space.m}`, minWidth: '80px', maxWidth: '200px', fontSize: 13, // hardcoded value to prevent shifting from type changes }; case 'small': return { height: '18px', padding: `0 ${tokens_1.canvas.space.xxs}`, minWidth: '56px', maxWidth: '120px', fontSize: 10, lineHeight: 'normal', }; } }, ({ grow }) => grow && { width: '100%', maxWidth: '100%' }, ({ variant }) => { let buttonColors; switch (variant) { case 'primary': buttonColors = tokens_1.canvas.buttonColors.primary; break; case 'secondary': default: buttonColors = tokens_1.canvas.buttonColors.secondary; break; case 'delete': buttonColors = { ...tokens_1.canvas.buttonColors.delete, focusBorder: tokens_1.canvas.colors.cinnamon500, activeBorder: tokens_1.canvas.colors.cinnamon500, }; break; } if (!buttonColors) { return {}; } const baseStyles = { backgroundColor: buttonColors.background, borderColor: buttonColors.border, color: buttonColors.text, }; const hoverStyles = { ':hover': { backgroundColor: buttonColors.hoverBackground, borderColor: buttonColors.hoverBorder, color: buttonColors.hoverText, }, }; const activeStyles = { ':active, :focus:active, :hover:active': { backgroundColor: buttonColors.activeBackground, borderColor: buttonColors.activeBorder, color: buttonColors.activeText, }, }; return { ...baseStyles, ':focus': { backgroundColor: buttonColors.focusBackground, borderColor: buttonColors.focusBorder, color: buttonColors.focusText, }, ...activeStyles, ...hoverStyles, ':disabled, :active:disabled, :focus:disabled, :hover:disabled': { backgroundColor: buttonColors.disabledBackground, borderColor: buttonColors.disabledBorder, color: buttonColors.disabledText, }, '&:not([disabled])': { '&:focus': { borderColor: buttonColors.focusBorder, ...(0, common_1.focusRing)(), }, '&:active': { borderColor: buttonColors.activeBorder, ...(0, common_1.focusRing)(), }, }, ...(0, common_1.mouseFocusBehavior)({ '&:focus': { ...baseStyles, outline: 'none', boxShadow: 'none', animation: 'none', ...hoverStyles, ...activeStyles, }, }), }; }); exports.DeprecatedButton = (0, common_1.createComponent)('button')({ displayName: 'DeprecatedButton', Component: ({ variant = 'secondary', size = 'large', children, ...elemProps }, ref, Element) => { React.useEffect(() => { console.warn('This component is now deprecated, consider using the new Button component'); }, []); return (React.createElement(Container, { ref: ref, as: Element, variant: variant, size: size, ...elemProps }, children)); }, });