@loomhq/lens 10.44.0 → 10.45.0
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.
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
declare const SwitchInput: import("@emotion/styled-base").StyledComponent<React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>,
|
|
3
|
-
declare const Switch: ({ isActive, isDisabled, onChange, ...props }: SwitchProps & React.ComponentProps<typeof SwitchInput>) => JSX.Element;
|
|
2
|
+
declare const SwitchInput: import("@emotion/styled-base").StyledComponent<React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, SwitchInputProps, object>;
|
|
3
|
+
declare const Switch: ({ isActive, isDisabled, onChange, size, ...props }: SwitchProps & Omit<React.ComponentProps<typeof SwitchInput>, 'size'>) => JSX.Element;
|
|
4
4
|
declare type SwitchProps = {
|
|
5
5
|
isActive?: boolean;
|
|
6
6
|
isDisabled?: boolean;
|
|
7
7
|
onChange?: React.ReactEventHandler;
|
|
8
|
+
size?: 'medium' | 'large';
|
|
9
|
+
};
|
|
10
|
+
declare type SwitchInputProps = {
|
|
11
|
+
switchSize?: 'medium' | 'large';
|
|
8
12
|
};
|
|
9
13
|
export default Switch;
|
|
@@ -9,14 +9,21 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import { getColorValue, getFocusRing
|
|
12
|
+
import { getColorValue, getFocusRing } from '../../utilities';
|
|
13
13
|
import React from 'react';
|
|
14
14
|
import styled from '@emotion/styled';
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
const sizes = {
|
|
16
|
+
medium: {
|
|
17
|
+
switchHeight: 16,
|
|
18
|
+
switchWidth: 32,
|
|
19
|
+
knobOffset: 2,
|
|
20
|
+
},
|
|
21
|
+
large: {
|
|
22
|
+
switchHeight: 28,
|
|
23
|
+
switchWidth: 56,
|
|
24
|
+
knobOffset: 4,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
20
27
|
const colorStyles = {
|
|
21
28
|
knob: {
|
|
22
29
|
active: {
|
|
@@ -39,6 +46,13 @@ const colorStyles = {
|
|
|
39
46
|
},
|
|
40
47
|
},
|
|
41
48
|
};
|
|
49
|
+
const getKnobTravel = props => {
|
|
50
|
+
return (sizes[props.switchSize].switchWidth - sizes[props.switchSize].switchHeight);
|
|
51
|
+
};
|
|
52
|
+
const getKnobSize = props => {
|
|
53
|
+
return (sizes[props.switchSize].switchHeight -
|
|
54
|
+
sizes[props.switchSize].knobOffset * 2);
|
|
55
|
+
};
|
|
42
56
|
const SwitchLabel = styled.label `
|
|
43
57
|
display: block;
|
|
44
58
|
position: relative;
|
|
@@ -68,7 +82,7 @@ const SwitchInput = styled.input `
|
|
|
68
82
|
background-color: ${colorStyles.track.active.disabled};
|
|
69
83
|
}
|
|
70
84
|
& + .SwitchBox:after {
|
|
71
|
-
transform: translateX(${
|
|
85
|
+
transform: translateX(${props => getKnobTravel(props)}px);
|
|
72
86
|
}
|
|
73
87
|
}
|
|
74
88
|
|
|
@@ -77,21 +91,21 @@ const SwitchInput = styled.input `
|
|
|
77
91
|
}
|
|
78
92
|
`;
|
|
79
93
|
const SwitchBox = styled.div `
|
|
80
|
-
width: ${
|
|
81
|
-
height: ${
|
|
94
|
+
width: ${props => sizes[props.switchSize].switchWidth}px;
|
|
95
|
+
height: ${props => sizes[props.switchSize].switchHeight}px;
|
|
82
96
|
position: relative;
|
|
83
|
-
border-radius:
|
|
97
|
+
border-radius: var(--lns-radius-full);
|
|
84
98
|
transition: 0.2s;
|
|
85
99
|
cursor: ${props => (props.isDisabled ? 'default' : 'pointer')};
|
|
86
100
|
|
|
87
101
|
&:after {
|
|
88
102
|
content: '';
|
|
89
103
|
position: absolute;
|
|
90
|
-
top: ${
|
|
91
|
-
left: ${
|
|
92
|
-
width: ${
|
|
93
|
-
height: ${
|
|
94
|
-
border-radius:
|
|
104
|
+
top: ${props => sizes[props.switchSize].knobOffset}px;
|
|
105
|
+
left: ${props => sizes[props.switchSize].knobOffset}px;
|
|
106
|
+
width: ${props => getKnobSize(props)}px;
|
|
107
|
+
height: ${props => getKnobSize(props)}px;
|
|
108
|
+
border-radius: var(--lns-radius-full);
|
|
95
109
|
transition: 0.15s;
|
|
96
110
|
background-color: ${props => props.isDisabled
|
|
97
111
|
? colorStyles.knob.active.disabled
|
|
@@ -99,9 +113,9 @@ const SwitchBox = styled.div `
|
|
|
99
113
|
}
|
|
100
114
|
`;
|
|
101
115
|
const Switch = (_a) => {
|
|
102
|
-
var { isActive, isDisabled, onChange } = _a, props = __rest(_a, ["isActive", "isDisabled", "onChange"]);
|
|
116
|
+
var { isActive, isDisabled, onChange, size = 'medium' } = _a, props = __rest(_a, ["isActive", "isDisabled", "onChange", "size"]);
|
|
103
117
|
return (React.createElement(SwitchLabel, null,
|
|
104
|
-
React.createElement(SwitchInput, Object.assign({}, props, { checked: isActive, disabled: isDisabled, onChange: onChange, type: "checkbox" })),
|
|
105
|
-
React.createElement(SwitchBox, { className: "SwitchBox", isDisabled: isDisabled, isActive: isActive })));
|
|
118
|
+
React.createElement(SwitchInput, Object.assign({}, props, { checked: isActive, disabled: isDisabled, onChange: onChange, type: "checkbox", switchSize: size })),
|
|
119
|
+
React.createElement(SwitchBox, { className: "SwitchBox", isDisabled: isDisabled, isActive: isActive, switchSize: size })));
|
|
106
120
|
};
|
|
107
121
|
export default Switch;
|
|
@@ -35,7 +35,7 @@ const tooltipYPadding = (tooltipMinHeight - textHeight) / 2;
|
|
|
35
35
|
const TooltipBoxWrapper = styled.div `
|
|
36
36
|
background-color: ${getColorValue('grey8')};
|
|
37
37
|
color: ${getColorValue('grey1')};
|
|
38
|
-
${getRadius('
|
|
38
|
+
${getRadius('thdMediumToLarge')};
|
|
39
39
|
${getFontWeight('medium')};
|
|
40
40
|
${getTextSize('small')};
|
|
41
41
|
${getShadow('medium')};
|