@via-profit/ui-kit 0.1.0-rc.19 → 0.1.0-rc.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Button/ButtonPlain.d.ts +5 -0
- package/Button/ButtonPlain.js +102 -0
- package/Button/index.d.ts +6 -5
- package/Button/index.js +4 -0
- package/package.json +1 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
const react_1 = __importDefault(require("react"));
|
|
18
|
+
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
19
|
+
const react_2 = require("@emotion/react");
|
|
20
|
+
const Color_1 = __importDefault(require("../Color"));
|
|
21
|
+
const ButtonBase_1 = __importDefault(require("./ButtonBase"));
|
|
22
|
+
const StyledPlainButton = (0, styled_1.default)(ButtonBase_1.default) `
|
|
23
|
+
box-shadow: none;
|
|
24
|
+
color: ${({ $color, disabled }) => {
|
|
25
|
+
switch (true) {
|
|
26
|
+
case disabled:
|
|
27
|
+
return $color.alpha(0.4).toString();
|
|
28
|
+
default:
|
|
29
|
+
return $color.toString();
|
|
30
|
+
}
|
|
31
|
+
}};
|
|
32
|
+
background-color: ${({ $background, disabled }) => {
|
|
33
|
+
switch (true) {
|
|
34
|
+
case disabled:
|
|
35
|
+
return $background.darken(10).toString();
|
|
36
|
+
default:
|
|
37
|
+
return $background.toString();
|
|
38
|
+
}
|
|
39
|
+
}};
|
|
40
|
+
${({ disabled, $background, theme }) => !disabled &&
|
|
41
|
+
(0, react_2.css) `
|
|
42
|
+
&:hover {
|
|
43
|
+
background-color: ${$background.darken(30).toString()};
|
|
44
|
+
}
|
|
45
|
+
&:active {
|
|
46
|
+
background-color: ${$background.darken(80).toString()};
|
|
47
|
+
}
|
|
48
|
+
&:focus-visible {
|
|
49
|
+
outline-color: ${$background.rgbString() === theme.color.accentPrimary.rgbString()
|
|
50
|
+
? theme.color.textPrimary.toString()
|
|
51
|
+
: theme.color.accentPrimary.toString()};
|
|
52
|
+
}
|
|
53
|
+
`}
|
|
54
|
+
`;
|
|
55
|
+
const ButtonPlain = (props, ref) => {
|
|
56
|
+
const { children, disabled, color } = props, restProps = __rest(props, ["children", "disabled", "color"]);
|
|
57
|
+
const theme = (0, react_2.useTheme)();
|
|
58
|
+
const { $background, $color } = react_1.default.useMemo(() => {
|
|
59
|
+
switch (true) {
|
|
60
|
+
case color === 'primary':
|
|
61
|
+
return {
|
|
62
|
+
$color: theme.color.accentPrimaryContrast,
|
|
63
|
+
$background: theme.color.accentPrimary,
|
|
64
|
+
};
|
|
65
|
+
case color === 'secondary':
|
|
66
|
+
return {
|
|
67
|
+
$color: theme.color.accentSecondaryContrast,
|
|
68
|
+
$background: theme.color.accentSecondary,
|
|
69
|
+
};
|
|
70
|
+
case typeof color === 'undefined':
|
|
71
|
+
case color === 'default':
|
|
72
|
+
return {
|
|
73
|
+
$background: theme.color.surface,
|
|
74
|
+
$color: theme.color.textPrimary,
|
|
75
|
+
};
|
|
76
|
+
case typeof color === 'string': {
|
|
77
|
+
let $background = theme.color.surface;
|
|
78
|
+
try {
|
|
79
|
+
if (color) {
|
|
80
|
+
$background = new Color_1.default(color);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
console.error(`invalid color value «${color}»`);
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
$background,
|
|
88
|
+
$color: $background.contrast(theme.color.textPrimary.rgbString()) > 5
|
|
89
|
+
? theme.color.textPrimary
|
|
90
|
+
: theme.color.surface,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
default:
|
|
94
|
+
return {
|
|
95
|
+
$background: theme.color.surface,
|
|
96
|
+
$color: theme.color.textPrimary,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}, [color, theme.color]);
|
|
100
|
+
return (react_1.default.createElement(StyledPlainButton, Object.assign({ "$color": $color, "$background": $background, disabled: disabled }, restProps, { ref: ref }), children));
|
|
101
|
+
};
|
|
102
|
+
exports.default = react_1.default.forwardRef(ButtonPlain);
|
package/Button/index.d.ts
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ButtonStandardProps } from './ButtonStandard';
|
|
3
3
|
import { ButtonOutlinedProps } from './ButtonOutlined';
|
|
4
|
-
|
|
4
|
+
import { ButtonPlainProps } from './ButtonPlain';
|
|
5
|
+
export type ButtonProps = (ButtonStandardProps | ButtonOutlinedProps | ButtonPlainProps) & {
|
|
5
6
|
/**
|
|
6
7
|
* Button style variant\
|
|
7
|
-
* Allowed variants: `standard` or `
|
|
8
|
+
* Allowed variants: `standard` ,`outlined` or `plain`\
|
|
8
9
|
* \
|
|
9
10
|
* **Default**: `standard`
|
|
10
11
|
*/
|
|
11
|
-
readonly variant?: 'standard' | 'outlined';
|
|
12
|
+
readonly variant?: 'standard' | 'outlined' | 'plain';
|
|
12
13
|
};
|
|
13
14
|
declare const _default: React.ForwardRefExoticComponent<import("./ButtonBase").ButtonBaseProps & {
|
|
14
15
|
/**
|
|
15
16
|
* Button style variant\
|
|
16
|
-
* Allowed variants: `standard` or `
|
|
17
|
+
* Allowed variants: `standard` ,`outlined` or `plain`\
|
|
17
18
|
* \
|
|
18
19
|
* **Default**: `standard`
|
|
19
20
|
*/
|
|
20
|
-
readonly variant?: "standard" | "outlined" | undefined;
|
|
21
|
+
readonly variant?: "standard" | "outlined" | "plain" | undefined;
|
|
21
22
|
} & React.RefAttributes<HTMLButtonElement>>;
|
|
22
23
|
export default _default;
|
package/Button/index.js
CHANGED
|
@@ -17,11 +17,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
const react_1 = __importDefault(require("react"));
|
|
18
18
|
const ButtonStandard_1 = __importDefault(require("./ButtonStandard"));
|
|
19
19
|
const ButtonOutlined_1 = __importDefault(require("./ButtonOutlined"));
|
|
20
|
+
const ButtonPlain_1 = __importDefault(require("./ButtonPlain"));
|
|
20
21
|
const Button = (props, ref) => {
|
|
21
22
|
const { variant } = props, buttonProps = __rest(props, ["variant"]);
|
|
22
23
|
if (variant === 'outlined') {
|
|
23
24
|
return react_1.default.createElement(ButtonOutlined_1.default, Object.assign({}, buttonProps, { ref: ref }));
|
|
24
25
|
}
|
|
26
|
+
if (variant === 'plain') {
|
|
27
|
+
return react_1.default.createElement(ButtonPlain_1.default, Object.assign({}, buttonProps, { ref: ref }));
|
|
28
|
+
}
|
|
25
29
|
return react_1.default.createElement(ButtonStandard_1.default, Object.assign({}, buttonProps, { ref: ref }));
|
|
26
30
|
};
|
|
27
31
|
exports.default = react_1.default.forwardRef(Button);
|