UNPKG

4.44 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4var constants_1 = require("@kalamazoo/theme/constants");
5var theme_1 = require("../theme");
6var compactButtonHeight = (constants_1.gridSize() * 3) / constants_1.fontSize() + "em";
7var buttonHeight = (constants_1.gridSize() * 4) / constants_1.fontSize() + "em";
8/** Background */
9var getBackground = function (props) {
10 return theme_1.applyPropertyStyle('background', props, theme_1.baseTheme);
11};
12/** Box Shadow */
13var getBoxShadow = function (props) {
14 var boxShadowColor = theme_1.applyPropertyStyle('boxShadowColor', props, theme_1.baseTheme);
15 return "0 0 0 2px " + boxShadowColor;
16};
17/** Color */
18var getColor = function (props) {
19 return theme_1.applyPropertyStyle('color', props, theme_1.baseTheme);
20};
21/** Cursor */
22var getCursor = function (_a) {
23 var _b = _a.state, state = _b === void 0 ? 'default' : _b;
24 return state === 'hover' || state === 'active' || state === 'selected'
25 ? 'pointer'
26 : state === 'disabled'
27 ? 'not-allowed'
28 : 'default';
29};
30/** Height */
31var getHeight = function (_a) {
32 var _b = _a.spacing, spacing = _b === void 0 ? 'default' : _b;
33 return spacing === 'compact'
34 ? compactButtonHeight
35 : spacing === 'none'
36 ? 'auto'
37 : buttonHeight;
38};
39/** Line Height */
40var getLineHeight = function (_a) {
41 var _b = _a.spacing, spacing = _b === void 0 ? 'default' : _b;
42 return spacing === 'compact'
43 ? compactButtonHeight
44 : spacing === 'none'
45 ? 'inherit'
46 : buttonHeight;
47};
48/** Padding */
49var getPadding = function (_a) {
50 var _b = _a.spacing, spacing = _b === void 0 ? 'default' : _b;
51 return spacing === 'none' ? 0 : "0 " + constants_1.gridSize() + "px";
52};
53/** Text Decoration */
54var getTextDecoration = function (_a) {
55 var _b = _a.appearance, appearance = _b === void 0 ? 'default' : _b, _c = _a.state, state = _c === void 0 ? 'default' : _c;
56 return state === 'hover' && (appearance === 'link' || appearance === 'subtle-link')
57 ? 'underline'
58 : 'inherit';
59};
60/** Transition */
61var getTransition = function (_a) {
62 var _b = _a.state, state = _b === void 0 ? 'default' : _b;
63 return state === 'hover'
64 ? 'background 0s ease-out, box-shadow 0.15s cubic-bezier(0.47, 0.03, 0.49, 1.38)'
65 : 'background 0.1s ease-out, box-shadow 0.15s cubic-bezier(0.47, 0.03, 0.49, 1.38)';
66};
67/** Transition Duration */
68var getTransitionDuration = function (_a) {
69 var _b = _a.state, state = _b === void 0 ? 'default' : _b;
70 return state === 'active' ? '0s' : state === 'focus' ? '0s, 0.2s' : '0.1s, 0.15s';
71};
72/** Vertical Align */
73var getVerticalAlign = function (_a) {
74 var _b = _a.spacing, spacing = _b === void 0 ? 'default' : _b;
75 return spacing === 'none' ? 'baseline' : 'middle';
76};
77/** Width */
78var getWidth = function (_a) {
79 var shouldFitContainer = _a.shouldFitContainer;
80 return shouldFitContainer ? '100%' : 'auto';
81};
82/** Base styles */
83var staticStyles = {
84 alignItems: 'baseline',
85 borderWidth: 0,
86 boxSizing: 'border-box',
87 display: 'inline-flex',
88 fontSize: 'inherit',
89 fontStyle: 'normal',
90 fontWeight: 'normal',
91 maxWidth: '100%',
92 outline: 'none !important',
93 textAlign: 'center',
94 textDecoration: 'none',
95 whiteSpace: 'nowrap',
96};
97/**
98 * BUTTON STYLES
99 */
100exports.getButtonStyles = function (props) { return (tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, staticStyles), { background: getBackground(props), borderRadius: constants_1.borderRadius() + "px", boxShadow: getBoxShadow(props), color: getColor(props) + " !important", cursor: getCursor(props), height: getHeight(props), lineHeight: getLineHeight(props), padding: getPadding(props), transition: getTransition(props), transitionDuration: getTransitionDuration(props), verticalAlign: getVerticalAlign(props), width: getWidth(props), '&::-moz-focus-inner': {
101 border: 0,
102 margin: 0,
103 padding: 0,
104 }, '&:hover': {
105 textDecoration: getTextDecoration(props),
106 } }), (props.isLoading && { pointerEvents: 'none' }))); };
107/**
108 * SPINNER STYLES
109 */
110exports.getSpinnerStyles = function () { return ({
111 display: 'flex',
112 position: 'absolute',
113 left: '50%',
114 top: '50%',
115 transform: 'translate(-50%, -50%)',
116}); };
117//# sourceMappingURL=getStyles.js.map
\No newline at end of file