1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 | var constants_1 = require("@kalamazoo/theme/constants");
|
5 | var theme_1 = require("../theme");
|
6 | var compactButtonHeight = (constants_1.gridSize() * 3) / constants_1.fontSize() + "em";
|
7 | var buttonHeight = (constants_1.gridSize() * 4) / constants_1.fontSize() + "em";
|
8 |
|
9 | var getBackground = function (props) {
|
10 | return theme_1.applyPropertyStyle('background', props, theme_1.baseTheme);
|
11 | };
|
12 |
|
13 | var getBoxShadow = function (props) {
|
14 | var boxShadowColor = theme_1.applyPropertyStyle('boxShadowColor', props, theme_1.baseTheme);
|
15 | return "0 0 0 2px " + boxShadowColor;
|
16 | };
|
17 |
|
18 | var getColor = function (props) {
|
19 | return theme_1.applyPropertyStyle('color', props, theme_1.baseTheme);
|
20 | };
|
21 |
|
22 | var 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 |
|
31 | var 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 |
|
40 | var 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 |
|
49 | var 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 |
|
54 | var 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 |
|
61 | var 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 |
|
68 | var 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 |
|
73 | var getVerticalAlign = function (_a) {
|
74 | var _b = _a.spacing, spacing = _b === void 0 ? 'default' : _b;
|
75 | return spacing === 'none' ? 'baseline' : 'middle';
|
76 | };
|
77 |
|
78 | var getWidth = function (_a) {
|
79 | var shouldFitContainer = _a.shouldFitContainer;
|
80 | return shouldFitContainer ? '100%' : 'auto';
|
81 | };
|
82 |
|
83 | var 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 |
|
99 |
|
100 | exports.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 |
|
109 |
|
110 | exports.getSpinnerStyles = function () { return ({
|
111 | display: 'flex',
|
112 | position: 'absolute',
|
113 | left: '50%',
|
114 | top: '50%',
|
115 | transform: 'translate(-50%, -50%)',
|
116 | }); };
|
117 |
|
\ | No newline at end of file |