@via-profit/ui-kit 0.1.0-rc.77 → 0.1.0-rc.78

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.
@@ -25,7 +25,7 @@ const StyledAccordionContent = styled_1.default.div `
25
25
  overflow: hidden;
26
26
  `;
27
27
  const Wrapper = styled_1.default.div `
28
- padding: ${({ $noPadding }) => ($noPadding ? '0' : '1rem 1rem 0 1rem')};
28
+ padding: ${({ $noPadding }) => ($noPadding ? '0' : '1rem')};
29
29
  `;
30
30
  const AccordionContent = (props, ref) => {
31
31
  const { children, noPadding, isOpen } = props, nativeProps = __rest(props, ["children", "noPadding", "isOpen"]);
@@ -0,0 +1,13 @@
1
+ import * as React from 'react';
2
+ export interface SwitchAsteriskProps extends React.HTMLAttributes<HTMLSpanElement> {
3
+ /**
4
+ * If true, the asterisk will be set the error color
5
+ */
6
+ readonly error?: boolean;
7
+ /**
8
+ * Not used
9
+ */
10
+ readonly focused?: boolean;
11
+ }
12
+ declare const _default: React.ForwardRefExoticComponent<SwitchAsteriskProps & React.RefAttributes<HTMLSpanElement>>;
13
+ export default _default;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __rest = (this && this.__rest) || function (s, e) {
26
+ var t = {};
27
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
28
+ t[p] = s[p];
29
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
30
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
31
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
32
+ t[p[i]] = s[p[i]];
33
+ }
34
+ return t;
35
+ };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ const React = __importStar(require("react"));
41
+ const styled_1 = __importDefault(require("@emotion/styled"));
42
+ const Asterisk = styled_1.default.span `
43
+ font-size: 0.8em;
44
+ margin-left: 0.2em;
45
+ position: relative;
46
+ top: -0.4em;
47
+ color: ${({ theme }) => theme.color.error.toString()};
48
+ `;
49
+ const SwitchAsterisk = (props, ref) => {
50
+ const { children, error, focused } = props, nativeProps = __rest(props, ["children", "error", "focused"]);
51
+ return (React.createElement(Asterisk, Object.assign({}, nativeProps, { "$error": error, "$focused": focused, ref: ref }), children));
52
+ };
53
+ exports.default = React.forwardRef(SwitchAsterisk);
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ export type SwitchContainerProps = React.LabelHTMLAttributes<HTMLLabelElement> & {
3
+ /**
4
+ * This property changes position of switch and its label.
5
+ * Default: `end`
6
+ */
7
+ readonly labelPosition?: 'start' | 'end' | 'top' | 'bottom';
8
+ /**
9
+ * if `true` switch state can not be changed
10
+ * Default: false;
11
+ */
12
+ readonly disabled?: boolean;
13
+ };
14
+ declare const _default: React.ForwardRefExoticComponent<React.LabelHTMLAttributes<HTMLLabelElement> & {
15
+ /**
16
+ * This property changes position of switch and its label.
17
+ * Default: `end`
18
+ */
19
+ readonly labelPosition?: "bottom" | "top" | "start" | "end" | undefined;
20
+ /**
21
+ * if `true` switch state can not be changed
22
+ * Default: false;
23
+ */
24
+ readonly disabled?: boolean | undefined;
25
+ } & React.RefAttributes<HTMLLabelElement>>;
26
+ export default _default;
@@ -0,0 +1,52 @@
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 StyledContainer = styled_1.default.label `
21
+ cursor: ${({ disabled }) => (disabled ? 'default' : 'pointer')};
22
+ font-size: 1em;
23
+ padding-right: 1em;
24
+ display: inline-flex;
25
+ align-items: center;
26
+ opacity: ${({ disabled }) => (disabled ? 0.6 : 1)};
27
+ ${({ labelPosition }) => {
28
+ let direction = 'row';
29
+ switch (labelPosition) {
30
+ case 'bottom':
31
+ direction = 'column';
32
+ break;
33
+ case 'start':
34
+ direction = 'row-reverse';
35
+ break;
36
+ case 'top':
37
+ direction = 'column-reverse';
38
+ break;
39
+ default:
40
+ //do nothing
41
+ break;
42
+ }
43
+ return (0, react_2.css) `
44
+ flex-direction: ${direction};
45
+ `;
46
+ }}
47
+ `;
48
+ const SwitchContainer = (props, ref) => {
49
+ const { children, labelPosition, disabled } = props, nativeProps = __rest(props, ["children", "labelPosition", "disabled"]);
50
+ return (react_1.default.createElement(StyledContainer, Object.assign({}, nativeProps, { labelPosition: labelPosition, disabled: disabled, ref: ref }), children));
51
+ };
52
+ exports.default = react_1.default.forwardRef(SwitchContainer);
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { SwitchProps } from './index';
3
+ export type SwitchDotProps = React.HTMLAttributes<HTMLSpanElement> & {
4
+ /**
5
+ * This prop allows you to provide switch state and control it. This property overrides internal component state
6
+ */
7
+ readonly checked: boolean;
8
+ readonly color?: SwitchProps['color'];
9
+ };
10
+ declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLSpanElement> & {
11
+ /**
12
+ * This prop allows you to provide switch state and control it. This property overrides internal component state
13
+ */
14
+ readonly checked: boolean;
15
+ readonly color?: string | undefined;
16
+ } & React.RefAttributes<HTMLSpanElement>>;
17
+ export default _default;
@@ -0,0 +1,145 @@
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 ToggleContainer = styled_1.default.span `
22
+ display: inline-flex;
23
+ align-items: center;
24
+ justify-content: center;
25
+ box-sizing: border-box;
26
+ background-color: transparent;
27
+ vertical-align: middle;
28
+ text-decoration: none;
29
+ padding: 0.8rem;
30
+ border-radius: 50%;
31
+ position: absolute;
32
+ top: 0px;
33
+ left: 0px;
34
+ z-index: 1;
35
+ color: rgb(255, 255, 255);
36
+ transition:
37
+ left 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,
38
+ transform 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
39
+ transform: ${({ checked }) => (checked ? 'translateX(1.5rem)' : 'translateX(0)')};
40
+ `;
41
+ const Dot = styled_1.default.span `
42
+ width: 1.4rem;
43
+ height: 1.4rem;
44
+ border-radius: 50%;
45
+ box-shadow:
46
+ rgba(0, 0, 0, 0.2) 0px 2px 1px -1px,
47
+ rgba(0, 0, 0, 0.14) 0px 1px 1px 0px,
48
+ rgba(0, 0, 0, 0.12) 0px 1px 3px 0px;
49
+ background-color: ${({ $color, checked, theme }) => {
50
+ switch (true) {
51
+ case checked:
52
+ return $color ? $color.toString() : theme.color.accentPrimary.toString();
53
+ default:
54
+ return theme.isDark ? theme.color.textPrimary.toString() : theme.color.surface.toString();
55
+ }
56
+ }};
57
+ &:before {
58
+ content: '';
59
+ position: absolute;
60
+ width: 1.4rem;
61
+ height: 1.4rem;
62
+ border-radius: 50%;
63
+ transition: all 0.3s ease-out;
64
+ top: 50%;
65
+ left: 50%;
66
+ transform: translate(-50%, -50%) scale(0);
67
+ background-color: ${({ $color, checked, theme }) => {
68
+ switch (true) {
69
+ case checked:
70
+ return $color
71
+ ? $color.alpha(0.2).toString()
72
+ : theme.color.accentPrimary.alpha(0.2).toString();
73
+ default:
74
+ return theme.isDark
75
+ ? theme.color.textPrimary.alpha(0.2).toString()
76
+ : theme.color.surface.alpha(0.2).toString();
77
+ }
78
+ }};
79
+ }
80
+ &:after {
81
+ content: '';
82
+ position: absolute;
83
+ width: 1.4rem;
84
+ height: 1.4rem;
85
+ border-radius: 50%;
86
+ transition: all 0.3s ease-out;
87
+ top: 50%;
88
+ left: 50%;
89
+ transform: translate(-50%, -50%) scale(0);
90
+ background-color: ${({ $color, checked, theme }) => {
91
+ switch (true) {
92
+ case checked:
93
+ return $color
94
+ ? $color.alpha(0.1).toString()
95
+ : theme.color.accentPrimary.alpha(0.1).toString();
96
+ default:
97
+ return theme.isDark
98
+ ? theme.color.textPrimary.alpha(0.1).toString()
99
+ : theme.color.surface.alpha(0.1).toString();
100
+ }
101
+ }};
102
+ }
103
+ `;
104
+ const SwitchDot = (props, ref) => {
105
+ const { children, color, checked } = props, nativeProps = __rest(props, ["children", "color", "checked"]);
106
+ const theme = (0, react_2.useTheme)();
107
+ const { $color } = react_1.default.useMemo(() => {
108
+ switch (true) {
109
+ case color === 'primary':
110
+ return {
111
+ $color: theme.color.accentPrimary,
112
+ };
113
+ case color === 'secondary':
114
+ return {
115
+ $color: theme.color.accentSecondary,
116
+ };
117
+ case typeof color === 'undefined':
118
+ case color === 'default':
119
+ return {
120
+ $color: theme.color.accentPrimary,
121
+ };
122
+ case typeof color === 'string': {
123
+ let $color = theme.color.surface;
124
+ try {
125
+ if (color) {
126
+ $color = new Color_1.default(color);
127
+ }
128
+ }
129
+ catch (err) {
130
+ console.error(`invalid color value «${color}»`);
131
+ }
132
+ return {
133
+ $color,
134
+ };
135
+ }
136
+ default:
137
+ return {
138
+ $color: theme.color.surface,
139
+ };
140
+ }
141
+ }, [color, theme.color]);
142
+ return (react_1.default.createElement(ToggleContainer, Object.assign({}, nativeProps, { ref: ref, "$color": $color, checked: checked }),
143
+ react_1.default.createElement(Dot, { "$color": $color, checked: checked }, children)));
144
+ };
145
+ exports.default = react_1.default.forwardRef(SwitchDot);
@@ -0,0 +1,6 @@
1
+ import * as React from 'react';
2
+ export interface SwitchErrorTextProps extends React.HTMLAttributes<HTMLSpanElement> {
3
+ readonly error?: boolean;
4
+ }
5
+ declare const _default: React.ForwardRefExoticComponent<SwitchErrorTextProps & React.RefAttributes<HTMLDivElement>>;
6
+ export default _default;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __rest = (this && this.__rest) || function (s, e) {
26
+ var t = {};
27
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
28
+ t[p] = s[p];
29
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
30
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
31
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
32
+ t[p[i]] = s[p[i]];
33
+ }
34
+ return t;
35
+ };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ const React = __importStar(require("react"));
41
+ const styled_1 = __importDefault(require("@emotion/styled"));
42
+ const NoSSR_1 = __importDefault(require("../NoSSR"));
43
+ const ErrorTextContainer = styled_1.default.div `
44
+ margin-left: 0.5em;
45
+ max-height: 0;
46
+ max-height: ${({ $maxHeight }) => typeof $maxHeight === 'number' ? `${$maxHeight}px` : $maxHeight};
47
+ transition: max-height 240ms cubic-bezier(0.22, 0.61, 0.36, 1);
48
+ overflow: hidden;
49
+ `;
50
+ const ErrorTextInner = styled_1.default.div `
51
+ color: ${({ theme }) => theme.color.error.toString()};
52
+ font-size: 0.8em;
53
+ transform: translateY(${({ $error }) => ($error ? 0 : '0.2em')});
54
+ opacity: ${({ $error }) => ($error ? 1 : 0)};
55
+ transition: all 240ms 240ms ease-out;
56
+ `;
57
+ const SwitchErrorText = (props, ref) => {
58
+ const { children, error } = props, nativeProps = __rest(props, ["children", "error"]);
59
+ const innerRef = React.useRef(null);
60
+ const [maxHeight, setMaxHeight] = React.useState('initial');
61
+ React.useEffect(() => {
62
+ const updateMaxHeight = () => {
63
+ if (innerRef.current && innerRef.current.getBoundingClientRect().height > 0) {
64
+ setMaxHeight(innerRef.current.getBoundingClientRect().height);
65
+ }
66
+ };
67
+ updateMaxHeight();
68
+ window.addEventListener('resize', updateMaxHeight);
69
+ return () => {
70
+ window.removeEventListener('resize', updateMaxHeight);
71
+ };
72
+ }, [children]);
73
+ return (React.createElement(ErrorTextContainer, Object.assign({}, nativeProps, { "$maxHeight": error ? maxHeight : 0, ref: ref }),
74
+ React.createElement(ErrorTextInner, { ref: innerRef, "$error": Boolean(error) }, children ? React.createElement(NoSSR_1.default, null, children) : React.createElement(React.Fragment, null, "\u00A0"))));
75
+ };
76
+ exports.default = React.forwardRef(SwitchErrorText);
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ export type SwitchTextWrapperProps = React.HTMLAttributes<HTMLSpanElement>;
3
+ declare const _default: React.ForwardRefExoticComponent<SwitchTextWrapperProps & React.RefAttributes<HTMLSpanElement>>;
4
+ export default _default;
@@ -0,0 +1,30 @@
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
+ // type StyleProps = {};
20
+ const TextWrapper = styled_1.default.span `
21
+ font-size: 0.86em;
22
+ display: flex;
23
+ align-items: center;
24
+ user-select: none;
25
+ `;
26
+ const SwitchTextWrapper = (props, ref) => {
27
+ const { children } = props, nativeProps = __rest(props, ["children"]);
28
+ return (react_1.default.createElement(TextWrapper, Object.assign({}, nativeProps, { ref: ref }), children));
29
+ };
30
+ exports.default = react_1.default.forwardRef(SwitchTextWrapper);
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ export type SwitchToggleWrapperProps = React.InputHTMLAttributes<HTMLInputElement>;
3
+ declare const _default: React.ForwardRefExoticComponent<SwitchToggleWrapperProps & React.RefAttributes<HTMLSpanElement>>;
4
+ export default _default;
@@ -0,0 +1,57 @@
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 ToggleWrapper = styled_1.default.span `
20
+ font-size: 0.86em;
21
+ display: inline-flex;
22
+ align-items: center;
23
+ user-select: none;
24
+ position: relative;
25
+ height: 3rem;
26
+ width: 4.5rem;
27
+ padding: 1.1rem;
28
+ overflow: hidden;
29
+ box-sizing: border-box;
30
+ &:hover span[class*='ToggleContainer'] > span[class*='Dot']:after {
31
+ transform: translate(-50%, -50%) scale(1.7);
32
+ }
33
+ `;
34
+ const StyledInput = styled_1.default.input `
35
+ cursor: inherit;
36
+ position: absolute;
37
+ width: 100%;
38
+ opacity: 0;
39
+ height: 100%;
40
+ top: 0px;
41
+ left: 0px;
42
+ margin: 0px;
43
+ padding: 0px;
44
+ z-index: 1;
45
+ &:focus-visible ~ span[class*='ToggleContainer'] > span[class*='Dot']:before {
46
+ transform: translate(-50%, -50%) scale(1.7);
47
+ }
48
+ `;
49
+ const SwitchToggleWrapper = (props, ref) => {
50
+ const { children, disabled } = props, nativeProps = __rest(props, ["children", "disabled"]);
51
+ return (react_1.default.createElement(ToggleWrapper, { ref: ref },
52
+ react_1.default.createElement(StyledInput, Object.assign({}, nativeProps, { disabled: disabled, onChange: e => {
53
+ (nativeProps === null || nativeProps === void 0 ? void 0 : nativeProps.onChange) && nativeProps.onChange(e);
54
+ }, type: "checkbox" })),
55
+ children));
56
+ };
57
+ exports.default = react_1.default.forwardRef(SwitchToggleWrapper);
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { SwitchProps } from './index';
3
+ export type SwitchTrackProps = React.HTMLAttributes<HTMLSpanElement> & {
4
+ /**
5
+ * This prop allows you to provide switch state and control it. This property overrides internal component state
6
+ */
7
+ readonly checked: boolean;
8
+ readonly color?: SwitchProps['color'];
9
+ };
10
+ declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLSpanElement> & {
11
+ /**
12
+ * This prop allows you to provide switch state and control it. This property overrides internal component state
13
+ */
14
+ readonly checked: boolean;
15
+ readonly color?: string | undefined;
16
+ } & React.RefAttributes<HTMLSpanElement>>;
17
+ export default _default;
@@ -0,0 +1,80 @@
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 Track = styled_1.default.span `
22
+ height: 100%;
23
+ width: 100%;
24
+ border-radius: 7px;
25
+ transition:
26
+ opacity 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,
27
+ background-color 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
28
+ background-color: ${({ $color, checked, theme }) => {
29
+ switch (true) {
30
+ case checked:
31
+ return $color ? $color.toString() : theme.color.accentPrimary.toString();
32
+ default:
33
+ return theme.isDark
34
+ ? theme.color.textPrimary.darken(10).toString()
35
+ : theme.color.surface.darken(200).toString();
36
+ }
37
+ }};
38
+ opacity: 0.5;
39
+ `;
40
+ const SwitchTrack = (props, ref) => {
41
+ const { color, checked, children } = props, nativeProps = __rest(props, ["color", "checked", "children"]);
42
+ const theme = (0, react_2.useTheme)();
43
+ const { $color } = react_1.default.useMemo(() => {
44
+ switch (true) {
45
+ case color === 'primary':
46
+ return {
47
+ $color: theme.color.accentPrimary,
48
+ };
49
+ case color === 'secondary':
50
+ return {
51
+ $color: theme.color.accentSecondary,
52
+ };
53
+ case typeof color === 'undefined':
54
+ case color === 'default':
55
+ return {
56
+ $color: theme.color.accentPrimary,
57
+ };
58
+ case typeof color === 'string': {
59
+ let $color = theme.color.surface;
60
+ try {
61
+ if (color) {
62
+ $color = new Color_1.default(color);
63
+ }
64
+ }
65
+ catch (err) {
66
+ console.error(`invalid color value «${color}»`);
67
+ }
68
+ return {
69
+ $color,
70
+ };
71
+ }
72
+ default:
73
+ return {
74
+ $color: theme.color.surface,
75
+ };
76
+ }
77
+ }, [color, theme.color]);
78
+ return (react_1.default.createElement(Track, Object.assign({}, nativeProps, { ref: ref, "$color": $color, checked: checked }), children));
79
+ };
80
+ exports.default = react_1.default.forwardRef(SwitchTrack);
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ export type SwitchWrapperProps = React.HTMLAttributes<HTMLSpanElement>;
3
+ declare const _default: React.ForwardRefExoticComponent<SwitchWrapperProps & React.RefAttributes<HTMLSpanElement>>;
4
+ export default _default;
@@ -0,0 +1,31 @@
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 StyledWrapper = styled_1.default.span `
20
+ font-size: 1em;
21
+ padding-right: 1em;
22
+ display: inline-flex;
23
+ justify-content: center;
24
+ flex-direction: column;
25
+ align-items: center;
26
+ `;
27
+ const SwitchWrapper = (props, ref) => {
28
+ const { children } = props, nativeProps = __rest(props, ["children"]);
29
+ return (react_1.default.createElement(StyledWrapper, Object.assign({}, nativeProps, { ref: ref }), children));
30
+ };
31
+ exports.default = react_1.default.forwardRef(SwitchWrapper);
@@ -0,0 +1,138 @@
1
+ import React from 'react';
2
+ import { SwitchContainerProps } from './SwitchContainer';
3
+ import { SwitchToggleWrapperProps } from './SwitchToggleWrapper';
4
+ import { SwitchTextWrapperProps } from './SwitchTextWrapper';
5
+ import { SwitchDotProps } from './SwitchDot';
6
+ import { SwitchTrackProps } from './SwitchTrack';
7
+ import { SwitchWrapperProps } from './SwitchWrapper';
8
+ import { SwitchErrorTextProps } from './SwitchErrorText';
9
+ import { SwitchAsteriskProps } from './SwitchAsterisk';
10
+ export type SwitchProps = Omit<SwitchToggleWrapperProps, 'checked' | 'onChange' | 'disabled'> & {
11
+ /**
12
+ * If true then `errorText` value will be displayed under the Switch element
13
+ */
14
+ readonly error?: boolean;
15
+ /**
16
+ * If is true then the asterisk will be displayed in label\
17
+ * If is ReactNode then ReactNode will be displayed in label
18
+ */
19
+ readonly requiredAsterisk?: boolean | React.ReactNode;
20
+ /**
21
+ * Text or ReactNode to show in error element\
22
+ * Will be displaed only if `error` property is tru
23
+ */
24
+ readonly errorText?: React.ReactNode;
25
+ /**
26
+ * This prop allows you to provide switch state and control it. This property overrides internal component state
27
+ * Default: undefined
28
+ */
29
+ readonly checked?: boolean;
30
+ /**
31
+ * This prop allows you to control switch component. Function will be executed when user click a switch
32
+ * This prop overrides internal comonent control function
33
+ * Default: undefined
34
+ */
35
+ readonly onChange?: React.InputHTMLAttributes<HTMLInputElement>['onChange'];
36
+ /**
37
+ * if `true` switch state can not be changed
38
+ * Default: false;
39
+ */
40
+ readonly disabled?: boolean;
41
+ /**
42
+ * if `true` switch would be turned on by default
43
+ * Default: false;
44
+ */
45
+ readonly defaultChecked?: boolean;
46
+ /**
47
+ * You can pass the primary, default, secondary name of the colors or your specified color value
48
+ */
49
+ readonly color?: 'default' | 'primary' | 'secondary' | string;
50
+ /**
51
+ * This property changes position of switch and its label.
52
+ * Default: `end`
53
+ */
54
+ readonly labelPosition?: 'start' | 'end' | 'top' | 'bottom';
55
+ readonly overrides?: SwitchOverrides;
56
+ };
57
+ export interface SwitchOverrides {
58
+ /**
59
+ * Element container
60
+ */
61
+ readonly Container?: React.ForwardRefExoticComponent<SwitchContainerProps & React.RefAttributes<HTMLSpanElement>>;
62
+ /**
63
+ * Element toggle
64
+ */
65
+ readonly ToggleWrapper?: React.ForwardRefExoticComponent<SwitchToggleWrapperProps & React.RefAttributes<HTMLSpanElement>>;
66
+ /**
67
+ * text wrapper
68
+ */
69
+ readonly TextWrapper?: React.ForwardRefExoticComponent<SwitchTextWrapperProps & React.RefAttributes<HTMLSpanElement>>;
70
+ /**
71
+ * Dot wrapper
72
+ */
73
+ readonly Dot?: React.ForwardRefExoticComponent<SwitchDotProps & React.RefAttributes<HTMLSpanElement>>;
74
+ /**
75
+ * Toggle track wrapper
76
+ */
77
+ readonly Track?: React.ForwardRefExoticComponent<SwitchTrackProps & React.RefAttributes<HTMLSpanElement>>;
78
+ /**
79
+ * error text wrapper
80
+ */
81
+ readonly ErrorText?: React.ForwardRefExoticComponent<SwitchErrorTextProps & React.RefAttributes<HTMLSpanElement>>;
82
+ /**
83
+ * error text wrapper
84
+ */
85
+ readonly Asterisk?: React.ForwardRefExoticComponent<SwitchAsteriskProps & React.RefAttributes<HTMLSpanElement>>;
86
+ /**
87
+ * the main cwitch wrapper
88
+ */
89
+ readonly Wrapper?: React.ForwardRefExoticComponent<SwitchWrapperProps & React.RefAttributes<HTMLSpanElement>>;
90
+ }
91
+ declare const _default: React.ForwardRefExoticComponent<Omit<SwitchToggleWrapperProps, "onChange" | "disabled" | "checked"> & {
92
+ /**
93
+ * If true then `errorText` value will be displayed under the Switch element
94
+ */
95
+ readonly error?: boolean | undefined;
96
+ /**
97
+ * If is true then the asterisk will be displayed in label\
98
+ * If is ReactNode then ReactNode will be displayed in label
99
+ */
100
+ readonly requiredAsterisk?: React.ReactNode;
101
+ /**
102
+ * Text or ReactNode to show in error element\
103
+ * Will be displaed only if `error` property is tru
104
+ */
105
+ readonly errorText?: React.ReactNode;
106
+ /**
107
+ * This prop allows you to provide switch state and control it. This property overrides internal component state
108
+ * Default: undefined
109
+ */
110
+ readonly checked?: boolean | undefined;
111
+ /**
112
+ * This prop allows you to control switch component. Function will be executed when user click a switch
113
+ * This prop overrides internal comonent control function
114
+ * Default: undefined
115
+ */
116
+ readonly onChange?: React.ChangeEventHandler<HTMLInputElement> | undefined;
117
+ /**
118
+ * if `true` switch state can not be changed
119
+ * Default: false;
120
+ */
121
+ readonly disabled?: boolean | undefined;
122
+ /**
123
+ * if `true` switch would be turned on by default
124
+ * Default: false;
125
+ */
126
+ readonly defaultChecked?: boolean | undefined;
127
+ /**
128
+ * You can pass the primary, default, secondary name of the colors or your specified color value
129
+ */
130
+ readonly color?: string | undefined;
131
+ /**
132
+ * This property changes position of switch and its label.
133
+ * Default: `end`
134
+ */
135
+ readonly labelPosition?: "bottom" | "top" | "start" | "end" | undefined;
136
+ readonly overrides?: SwitchOverrides | undefined;
137
+ } & React.RefAttributes<HTMLInputElement>>;
138
+ export default _default;
@@ -0,0 +1,56 @@
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 SwitchContainer_1 = __importDefault(require("./SwitchContainer"));
19
+ const SwitchToggleWrapper_1 = __importDefault(require("./SwitchToggleWrapper"));
20
+ const SwitchTextWrapper_1 = __importDefault(require("./SwitchTextWrapper"));
21
+ const SwitchDot_1 = __importDefault(require("./SwitchDot"));
22
+ const SwitchTrack_1 = __importDefault(require("./SwitchTrack"));
23
+ const SwitchWrapper_1 = __importDefault(require("./SwitchWrapper"));
24
+ const SwitchErrorText_1 = __importDefault(require("./SwitchErrorText"));
25
+ const SwitchAsterisk_1 = __importDefault(require("./SwitchAsterisk"));
26
+ const Switch = (props, ref) => {
27
+ const { checked, onChange, defaultChecked, overrides, disabled, labelPosition, children, color, name, error, errorText, requiredAsterisk } = props, nativeProps = __rest(props, ["checked", "onChange", "defaultChecked", "overrides", "disabled", "labelPosition", "children", "color", "name", "error", "errorText", "requiredAsterisk"]);
28
+ const [internalChecked, setInternalChecked] = react_1.default.useState(typeof defaultChecked !== 'undefined' ? defaultChecked : false);
29
+ const overridesMap = react_1.default.useMemo(() => ({
30
+ TextWrapper: (overrides === null || overrides === void 0 ? void 0 : overrides.TextWrapper) || SwitchTextWrapper_1.default,
31
+ ToggleWrapper: (overrides === null || overrides === void 0 ? void 0 : overrides.ToggleWrapper) || SwitchToggleWrapper_1.default,
32
+ Container: (overrides === null || overrides === void 0 ? void 0 : overrides.Container) || SwitchContainer_1.default,
33
+ Track: (overrides === null || overrides === void 0 ? void 0 : overrides.Track) || SwitchTrack_1.default,
34
+ Dot: (overrides === null || overrides === void 0 ? void 0 : overrides.Dot) || SwitchDot_1.default,
35
+ ErrorText: (overrides === null || overrides === void 0 ? void 0 : overrides.ErrorText) || SwitchErrorText_1.default,
36
+ Asterisk: (overrides === null || overrides === void 0 ? void 0 : overrides.Asterisk) || SwitchAsterisk_1.default,
37
+ Wrapper: (overrides === null || overrides === void 0 ? void 0 : overrides.Wrapper) || SwitchWrapper_1.default,
38
+ }), [overrides]);
39
+ if (typeof checked !== 'undefined' && typeof onChange === 'undefined') {
40
+ console.error('The property «onChange» should be passed with prop «checked» to make component controlled');
41
+ }
42
+ return (react_1.default.createElement(overridesMap.Wrapper, null,
43
+ react_1.default.createElement(overridesMap.Container, { labelPosition: labelPosition, disabled: disabled },
44
+ react_1.default.createElement(overridesMap.ToggleWrapper, Object.assign({}, nativeProps, { disabled: disabled, onChange: typeof onChange !== 'undefined'
45
+ ? onChange
46
+ : () => {
47
+ setInternalChecked(!internalChecked);
48
+ }, checked: typeof checked !== 'undefined' ? checked : defaultChecked ? true : undefined, name: name, ref: ref }),
49
+ react_1.default.createElement(overridesMap.Track, { color: color, checked: typeof checked !== 'undefined' ? checked : internalChecked }),
50
+ react_1.default.createElement(overridesMap.Dot, { color: color, checked: typeof checked !== 'undefined' ? checked : internalChecked })),
51
+ react_1.default.createElement(overridesMap.TextWrapper, null,
52
+ children,
53
+ typeof requiredAsterisk !== 'undefined' && requiredAsterisk !== null && (react_1.default.createElement(overridesMap.Asterisk, null, typeof requiredAsterisk === 'boolean' ? '*' : requiredAsterisk)))),
54
+ react_1.default.createElement(overridesMap.ErrorText, { error: error }, errorText)));
55
+ };
56
+ exports.default = react_1.default.forwardRef(Switch);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@via-profit/ui-kit",
3
- "version": "0.1.0-rc.77",
3
+ "version": "0.1.0-rc.78",
4
4
  "description": "UI Kit",
5
5
  "repository": {
6
6
  "type": "git",