@toptal/picasso-switch 1.0.11 → 2.0.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.
- package/dist-package/src/Switch/Switch.d.ts +0 -2
- package/dist-package/src/Switch/Switch.d.ts.map +1 -1
- package/dist-package/src/Switch/Switch.js +25 -10
- package/dist-package/src/Switch/Switch.js.map +1 -1
- package/package.json +6 -4
- package/src/Switch/Switch.tsx +42 -15
- package/src/Switch/__snapshots__/test.tsx.snap +36 -61
- package/dist-package/src/Switch/styles.d.ts +0 -3
- package/dist-package/src/Switch/styles.d.ts.map +0 -1
- package/dist-package/src/Switch/styles.js +0 -79
- package/dist-package/src/Switch/styles.js.map +0 -1
- package/src/Switch/styles.ts +0 -86
|
@@ -10,8 +10,6 @@ export interface Props extends BaseProps, TextLabelProps, Omit<ButtonHTMLAttribu
|
|
|
10
10
|
label?: ReactNode;
|
|
11
11
|
/** Callback invoked when `Switch` changed its value */
|
|
12
12
|
onChange?: (event: React.ChangeEvent<HTMLInputElement>, checked: boolean) => void;
|
|
13
|
-
/** Value of the `Switch` (applicable only for controlled component) */
|
|
14
|
-
value?: string;
|
|
15
13
|
}
|
|
16
14
|
export declare const Switch: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLButtonElement>>;
|
|
17
15
|
export default Switch;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Switch.d.ts","sourceRoot":"","sources":["../../../src/Switch/Switch.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Switch.d.ts","sourceRoot":"","sources":["../../../src/Switch/Switch.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AACvE,OAAO,KAAK,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAC5D,OAAO,KAAqB,MAAM,OAAO,CAAA;AAIzC,MAAM,WAAW,KACf,SAAQ,SAAS,EACf,cAAc,EACd,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC;IACpE,uCAAuC;IACvC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,sCAAsC;IACtC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,kCAAkC;IAClC,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,uDAAuD;IACvD,QAAQ,CAAC,EAAE,CACT,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAC1C,OAAO,EAAE,OAAO,KACb,IAAI,CAAA;CACV;AAED,eAAO,MAAM,MAAM,iFAwFjB,CAAA;AASF,eAAe,MAAM,CAAA"}
|
|
@@ -9,23 +9,38 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import { Switch as MUISwitch } from '@
|
|
13
|
-
import { makeStyles } from '@material-ui/core/styles';
|
|
12
|
+
import { Switch as MUISwitch } from '@mui/base/Switch';
|
|
14
13
|
import React, { forwardRef } from 'react';
|
|
15
14
|
import { FormControlLabel } from '@toptal/picasso-form';
|
|
16
|
-
import
|
|
17
|
-
const useStyles = makeStyles(styles, { name: 'PicassoSwitch' });
|
|
15
|
+
import cx from 'classnames';
|
|
18
16
|
export const Switch = forwardRef(function Switch(props, ref) {
|
|
19
|
-
const { label, id, className, style, disabled, onChange,
|
|
20
|
-
'data-testid': dataTestId } = props, rest = __rest(props, ["label", "id", "className", "style", "disabled", "onChange", "
|
|
21
|
-
const
|
|
22
|
-
|
|
17
|
+
const { label, id, className, style, disabled, onChange, checked, titleCase, color, // eslint-disable-line
|
|
18
|
+
'data-testid': dataTestId } = props, rest = __rest(props, ["label", "id", "className", "style", "disabled", "onChange", "checked", "titleCase", "color", 'data-testid']);
|
|
19
|
+
const onChangeCallback = event => {
|
|
20
|
+
if (onChange) {
|
|
21
|
+
onChange(event, event.target.checked);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const switchElement = (React.createElement(MUISwitch, Object.assign({}, rest, { color: 'primary', ref: ref, checked: checked, className: className, style: style, disabled: disabled, id: id, onChange: onChangeCallback, "data-testid": label ? undefined : dataTestId, slotProps: {
|
|
25
|
+
root: {
|
|
26
|
+
className: 'w-[40px] h-[24px] p-0 relative inline-flex z-0 overflow-visible shrink-0 align-middle group',
|
|
27
|
+
},
|
|
28
|
+
track: {
|
|
29
|
+
className: cx('w-full h-full border border-solid bg-gray-600 border-gray-600 opacity-100 rounded-[12px]', 'transition-colors duration-300 ease-out', 'group-[.base--checked]:bg-blue-500 group-[.base--checked]:border-blue-500', 'group-[.base--disabled]:opacity-40', 'group-[.base--disabled:not(.base--checked)]:bg-black'),
|
|
30
|
+
},
|
|
31
|
+
thumb: {
|
|
32
|
+
className: cx('w-[22px] h-[22px] bg-current text-white block rounded-full shadow-1 absolute z-10 p-0 top-[1px] left-[1px]', 'transition-transform duration-150 ease-out', 'group-[:not(.base--disabled):hover]:shadow-[0_0_0_4px_rgba(32,78,207,0.48)]', 'group-[.base--focusVisible]:shadow-[0_0_0_4px_rgba(32,78,207,0.48)]', 'group-[.base--checked]:translate-x-[16px]'),
|
|
33
|
+
},
|
|
34
|
+
input: {
|
|
35
|
+
className: cx('w-[200%] h-full m-0 p-0 opacity-0 absolute top-0 -left-[50%] cursor-pointer z-20', 'group-[.base--disabled]:cursor-default'),
|
|
36
|
+
},
|
|
37
|
+
} })));
|
|
23
38
|
if (!label) {
|
|
24
39
|
return switchElement;
|
|
25
40
|
}
|
|
26
41
|
return (React.createElement(FormControlLabel, { classes: {
|
|
27
|
-
root:
|
|
28
|
-
label:
|
|
42
|
+
root: 'items-start text-lg',
|
|
43
|
+
label: 'ml-[0.5em] mt-[0.25em] max-w-[calc(100%-1em-0.5em+1px)]',
|
|
29
44
|
}, control: switchElement, disabled: disabled, label: label, titleCase: titleCase, "data-testid": dataTestId }));
|
|
30
45
|
});
|
|
31
46
|
Switch.defaultProps = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Switch.js","sourceRoot":"","sources":["../../../src/Switch/Switch.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Switch.js","sourceRoot":"","sources":["../../../src/Switch/Switch.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAGtD,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,MAAM,YAAY,CAAA;AAmB3B,MAAM,CAAC,MAAM,MAAM,GAAG,UAAU,CAA2B,SAAS,MAAM,CACxE,KAAK,EACL,GAAG;IAEH,MAAM,EACJ,KAAK,EACL,EAAE,EACF,SAAS,EACT,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,SAAS,EACT,KAAK,EAAE,sBAAsB;IAC7B,aAAa,EAAE,UAAU,KAEvB,KAAK,EADJ,IAAI,UACL,KAAK,EAZH,6GAYL,CAAQ,CAAA;IAET,MAAM,gBAAgB,GAElB,KAAK,CAAC,EAAE;QACV,IAAI,QAAQ,EAAE;YACZ,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;SACtC;IACH,CAAC,CAAA;IAED,MAAM,aAAa,GAAG,CACpB,oBAAC,SAAS,oBACJ,IAAI,IACR,KAAK,EAAC,SAAS,EACf,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,QAAQ,EAClB,EAAE,EAAE,EAAE,EACN,QAAQ,EAAE,gBAAgB,iBACb,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,EAC3C,SAAS,EAAE;YACT,IAAI,EAAE;gBACJ,SAAS,EACP,6FAA6F;aAChG;YACD,KAAK,EAAE;gBACL,SAAS,EAAE,EAAE,CACX,0FAA0F,EAC1F,yCAAyC,EACzC,2EAA2E,EAC3E,oCAAoC,EACpC,sDAAsD,CACvD;aACF;YACD,KAAK,EAAE;gBACL,SAAS,EAAE,EAAE,CACX,4GAA4G,EAC5G,4CAA4C,EAC5C,6EAA6E,EAC7E,qEAAqE,EACrE,2CAA2C,CAC5C;aACF;YACD,KAAK,EAAE;gBACL,SAAS,EAAE,EAAE,CACX,kFAAkF,EAClF,wCAAwC,CACzC;aACF;SACF,IACD,CACH,CAAA;IAED,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,aAAa,CAAA;KACrB;IAED,OAAO,CACL,oBAAC,gBAAgB,IACf,OAAO,EAAE;YACP,IAAI,EAAE,qBAAqB;YAC3B,KAAK,EAAE,yDAAyD;SACjE,EACD,OAAO,EAAE,aAAa,EACtB,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,SAAS,iBACP,UAAU,GACvB,CACH,CAAA;AACH,CAAC,CAAC,CAAA;AAEF,MAAM,CAAC,YAAY,GAAG;IACpB,QAAQ,EAAE,KAAK;IACf,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC;CACnB,CAAA;AAED,MAAM,CAAC,WAAW,GAAG,QAAQ,CAAA;AAE7B,eAAe,MAAM,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toptal/picasso-switch",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Toptal UI components library - Switch",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -22,16 +22,18 @@
|
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://github.com/toptal/picasso/tree/master/packages/picasso#readme",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@toptal/picasso-form": "3.0.
|
|
26
|
-
"@toptal/picasso-shared": "15.0.0"
|
|
25
|
+
"@toptal/picasso-form": "3.0.4",
|
|
26
|
+
"@toptal/picasso-shared": "15.0.0",
|
|
27
|
+
"@mui/base": "5.0.0-beta.40",
|
|
28
|
+
"classnames": "^2.5.1"
|
|
27
29
|
},
|
|
28
30
|
"sideEffects": [
|
|
29
31
|
"**/styles.ts",
|
|
30
32
|
"**/styles.js"
|
|
31
33
|
],
|
|
32
34
|
"peerDependencies": {
|
|
33
|
-
"@material-ui/core": "4.12.4",
|
|
34
35
|
"@toptal/picasso-provider": "*",
|
|
36
|
+
"@toptal/picasso-tailwind": "^2.5.0",
|
|
35
37
|
"react": ">=16.12.0 < 19.0.0"
|
|
36
38
|
},
|
|
37
39
|
"exports": {
|
package/src/Switch/Switch.tsx
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import { Switch as MUISwitch } from '@
|
|
2
|
-
import type { Theme } from '@material-ui/core/styles'
|
|
3
|
-
import { makeStyles } from '@material-ui/core/styles'
|
|
1
|
+
import { Switch as MUISwitch } from '@mui/base/Switch'
|
|
4
2
|
import type { BaseProps, TextLabelProps } from '@toptal/picasso-shared'
|
|
5
3
|
import type { ButtonHTMLAttributes, ReactNode } from 'react'
|
|
6
4
|
import React, { forwardRef } from 'react'
|
|
7
5
|
import { FormControlLabel } from '@toptal/picasso-form'
|
|
8
|
-
|
|
9
|
-
import styles from './styles'
|
|
10
|
-
|
|
11
|
-
const useStyles = makeStyles<Theme>(styles, { name: 'PicassoSwitch' })
|
|
6
|
+
import cx from 'classnames'
|
|
12
7
|
|
|
13
8
|
export interface Props
|
|
14
9
|
extends BaseProps,
|
|
@@ -25,8 +20,6 @@ export interface Props
|
|
|
25
20
|
event: React.ChangeEvent<HTMLInputElement>,
|
|
26
21
|
checked: boolean
|
|
27
22
|
) => void
|
|
28
|
-
/** Value of the `Switch` (applicable only for controlled component) */
|
|
29
|
-
value?: string
|
|
30
23
|
}
|
|
31
24
|
|
|
32
25
|
export const Switch = forwardRef<HTMLButtonElement, Props>(function Switch(
|
|
@@ -40,7 +33,6 @@ export const Switch = forwardRef<HTMLButtonElement, Props>(function Switch(
|
|
|
40
33
|
style,
|
|
41
34
|
disabled,
|
|
42
35
|
onChange,
|
|
43
|
-
value,
|
|
44
36
|
checked,
|
|
45
37
|
titleCase,
|
|
46
38
|
color, // eslint-disable-line
|
|
@@ -48,7 +40,13 @@ export const Switch = forwardRef<HTMLButtonElement, Props>(function Switch(
|
|
|
48
40
|
...rest
|
|
49
41
|
} = props
|
|
50
42
|
|
|
51
|
-
const
|
|
43
|
+
const onChangeCallback: React.ChangeEventHandler<
|
|
44
|
+
HTMLInputElement
|
|
45
|
+
> = event => {
|
|
46
|
+
if (onChange) {
|
|
47
|
+
onChange(event, event.target.checked)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
52
50
|
|
|
53
51
|
const switchElement = (
|
|
54
52
|
<MUISwitch
|
|
@@ -60,9 +58,38 @@ export const Switch = forwardRef<HTMLButtonElement, Props>(function Switch(
|
|
|
60
58
|
style={style}
|
|
61
59
|
disabled={disabled}
|
|
62
60
|
id={id}
|
|
63
|
-
onChange={
|
|
64
|
-
value={value}
|
|
61
|
+
onChange={onChangeCallback}
|
|
65
62
|
data-testid={label ? undefined : dataTestId}
|
|
63
|
+
slotProps={{
|
|
64
|
+
root: {
|
|
65
|
+
className:
|
|
66
|
+
'w-[40px] h-[24px] p-0 relative inline-flex z-0 overflow-visible shrink-0 align-middle group',
|
|
67
|
+
},
|
|
68
|
+
track: {
|
|
69
|
+
className: cx(
|
|
70
|
+
'w-full h-full border border-solid bg-gray-600 border-gray-600 opacity-100 rounded-[12px]',
|
|
71
|
+
'transition-colors duration-300 ease-out',
|
|
72
|
+
'group-[.base--checked]:bg-blue-500 group-[.base--checked]:border-blue-500',
|
|
73
|
+
'group-[.base--disabled]:opacity-40',
|
|
74
|
+
'group-[.base--disabled:not(.base--checked)]:bg-black'
|
|
75
|
+
),
|
|
76
|
+
},
|
|
77
|
+
thumb: {
|
|
78
|
+
className: cx(
|
|
79
|
+
'w-[22px] h-[22px] bg-current text-white block rounded-full shadow-1 absolute z-10 p-0 top-[1px] left-[1px]',
|
|
80
|
+
'transition-transform duration-150 ease-out',
|
|
81
|
+
'group-[:not(.base--disabled):hover]:shadow-[0_0_0_4px_rgba(32,78,207,0.48)]',
|
|
82
|
+
'group-[.base--focusVisible]:shadow-[0_0_0_4px_rgba(32,78,207,0.48)]',
|
|
83
|
+
'group-[.base--checked]:translate-x-[16px]'
|
|
84
|
+
),
|
|
85
|
+
},
|
|
86
|
+
input: {
|
|
87
|
+
className: cx(
|
|
88
|
+
'w-[200%] h-full m-0 p-0 opacity-0 absolute top-0 -left-[50%] cursor-pointer z-20',
|
|
89
|
+
'group-[.base--disabled]:cursor-default'
|
|
90
|
+
),
|
|
91
|
+
},
|
|
92
|
+
}}
|
|
66
93
|
/>
|
|
67
94
|
)
|
|
68
95
|
|
|
@@ -73,8 +100,8 @@ export const Switch = forwardRef<HTMLButtonElement, Props>(function Switch(
|
|
|
73
100
|
return (
|
|
74
101
|
<FormControlLabel
|
|
75
102
|
classes={{
|
|
76
|
-
root:
|
|
77
|
-
label:
|
|
103
|
+
root: 'items-start text-lg',
|
|
104
|
+
label: 'ml-[0.5em] mt-[0.25em] max-w-[calc(100%-1em-0.5em+1px)]',
|
|
78
105
|
}}
|
|
79
106
|
control={switchElement}
|
|
80
107
|
disabled={disabled}
|
|
@@ -2,35 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
exports[`Switch behaves correctly when interacting 1`] = `
|
|
4
4
|
<label
|
|
5
|
-
class="PicassoFormControlLabel-root
|
|
5
|
+
class="PicassoFormControlLabel-root items-start text-lg"
|
|
6
6
|
data-testid="switch"
|
|
7
7
|
>
|
|
8
8
|
<span
|
|
9
|
-
class="
|
|
9
|
+
class="base-Switch base- w-[40px] h-[24px] p-0 relative inline-flex z-0 overflow-visible shrink-0 align-middle group"
|
|
10
|
+
color="primary"
|
|
10
11
|
>
|
|
11
12
|
<span
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
>
|
|
15
|
-
<span
|
|
16
|
-
class="MuiIconButton-label"
|
|
17
|
-
>
|
|
18
|
-
<input
|
|
19
|
-
class="PrivateSwitchBase-input MuiSwitch-input"
|
|
20
|
-
type="checkbox"
|
|
21
|
-
value=""
|
|
22
|
-
/>
|
|
23
|
-
<span
|
|
24
|
-
class="MuiSwitch-thumb"
|
|
25
|
-
/>
|
|
26
|
-
</span>
|
|
27
|
-
</span>
|
|
13
|
+
class="base-Switch w-full h-full border border-solid bg-gray border-gray opacity-100 rounded-[12px] transition-colors duration-300 ease-out group-[.base--checked]:bg-blue group-[.base--checked]:border-blue group-[.base--disabled]:opacity group-[.base--disabled:not(.base--checked)]:bg"
|
|
14
|
+
/>
|
|
28
15
|
<span
|
|
29
|
-
class="
|
|
16
|
+
class="base-Switch w-[22px] h-[22px] bg-current text-white block rounded-full shadow-1 absolute z-10 p-0 top-[1px] left-[1px] transition-transform duration-150 ease-out group-[:not(.base--disabled):hover]:shadow group-[.base--focusVisible]:shadow group-[.base--checked]:translate-x"
|
|
17
|
+
/>
|
|
18
|
+
<input
|
|
19
|
+
class="base-Switch w-[200%] h-full m-0 p-0 opacity-0 absolute top-0 -left cursor-pointer z-20 group-[.base--disabled]:cursor"
|
|
20
|
+
role="switch"
|
|
21
|
+
type="checkbox"
|
|
30
22
|
/>
|
|
31
23
|
</span>
|
|
32
24
|
<span
|
|
33
|
-
class="PicassoFormLabel-root PicassoFormLabel-inline PicassoFormControlLabel-label
|
|
25
|
+
class="PicassoFormLabel-root PicassoFormLabel-inline PicassoFormControlLabel-label ml-[0.5em] mt-[0.25em] max-w-[calc(100%-1em"
|
|
34
26
|
>
|
|
35
27
|
<span
|
|
36
28
|
class="PicassoFormLabel-medium"
|
|
@@ -47,28 +39,20 @@ exports[`Switch renders default Switch without label 1`] = `
|
|
|
47
39
|
class="Picasso-root"
|
|
48
40
|
>
|
|
49
41
|
<span
|
|
50
|
-
class="
|
|
42
|
+
class="base-Switch w-[40px] h-[24px] p-0 relative inline-flex z-0 overflow-visible shrink-0 align-middle group"
|
|
43
|
+
color="primary"
|
|
44
|
+
data-testid="switch"
|
|
51
45
|
>
|
|
52
46
|
<span
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
data-testid="switch"
|
|
56
|
-
>
|
|
57
|
-
<span
|
|
58
|
-
class="MuiIconButton-label"
|
|
59
|
-
>
|
|
60
|
-
<input
|
|
61
|
-
class="PrivateSwitchBase-input MuiSwitch-input"
|
|
62
|
-
type="checkbox"
|
|
63
|
-
value=""
|
|
64
|
-
/>
|
|
65
|
-
<span
|
|
66
|
-
class="MuiSwitch-thumb"
|
|
67
|
-
/>
|
|
68
|
-
</span>
|
|
69
|
-
</span>
|
|
47
|
+
class="base-Switch w-full h-full border border-solid bg-gray border-gray opacity-100 rounded-[12px] transition-colors duration-300 ease-out group-[.base--checked]:bg-blue group-[.base--checked]:border-blue group-[.base--disabled]:opacity group-[.base--disabled:not(.base--checked)]:bg"
|
|
48
|
+
/>
|
|
70
49
|
<span
|
|
71
|
-
class="
|
|
50
|
+
class="base-Switch w-[22px] h-[22px] bg-current text-white block rounded-full shadow-1 absolute z-10 p-0 top-[1px] left-[1px] transition-transform duration-150 ease-out group-[:not(.base--disabled):hover]:shadow group-[.base--focusVisible]:shadow group-[.base--checked]:translate-x"
|
|
51
|
+
/>
|
|
52
|
+
<input
|
|
53
|
+
class="base-Switch w-[200%] h-full m-0 p-0 opacity-0 absolute top-0 -left cursor-pointer z-20 group-[.base--disabled]:cursor"
|
|
54
|
+
role="switch"
|
|
55
|
+
type="checkbox"
|
|
72
56
|
/>
|
|
73
57
|
</span>
|
|
74
58
|
</div>
|
|
@@ -77,37 +61,28 @@ exports[`Switch renders default Switch without label 1`] = `
|
|
|
77
61
|
|
|
78
62
|
exports[`Switch renders disabled state 1`] = `
|
|
79
63
|
<label
|
|
80
|
-
class="PicassoFormControlLabel-root
|
|
64
|
+
class="PicassoFormControlLabel-root items-start text-lg PicassoFormControlLabel-disabled"
|
|
81
65
|
data-testid="switch"
|
|
82
66
|
>
|
|
83
67
|
<span
|
|
84
|
-
class="
|
|
68
|
+
class="base-Switch base- w-[40px] h-[24px] p-0 relative inline-flex z-0 overflow-visible shrink-0 align-middle group"
|
|
69
|
+
color="primary"
|
|
85
70
|
>
|
|
86
71
|
<span
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
tabindex="-1"
|
|
90
|
-
>
|
|
91
|
-
<span
|
|
92
|
-
class="MuiIconButton-label"
|
|
93
|
-
>
|
|
94
|
-
<input
|
|
95
|
-
class="PrivateSwitchBase-input MuiSwitch-input"
|
|
96
|
-
disabled=""
|
|
97
|
-
type="checkbox"
|
|
98
|
-
value=""
|
|
99
|
-
/>
|
|
100
|
-
<span
|
|
101
|
-
class="MuiSwitch-thumb"
|
|
102
|
-
/>
|
|
103
|
-
</span>
|
|
104
|
-
</span>
|
|
72
|
+
class="base-Switch w-full h-full border border-solid bg-gray border-gray opacity-100 rounded-[12px] transition-colors duration-300 ease-out group-[.base--checked]:bg-blue group-[.base--checked]:border-blue group-[.base--disabled]:opacity group-[.base--disabled:not(.base--checked)]:bg"
|
|
73
|
+
/>
|
|
105
74
|
<span
|
|
106
|
-
class="
|
|
75
|
+
class="base-Switch w-[22px] h-[22px] bg-current text-white block rounded-full shadow-1 absolute z-10 p-0 top-[1px] left-[1px] transition-transform duration-150 ease-out group-[:not(.base--disabled):hover]:shadow group-[.base--focusVisible]:shadow group-[.base--checked]:translate-x"
|
|
76
|
+
/>
|
|
77
|
+
<input
|
|
78
|
+
class="base-Switch w-[200%] h-full m-0 p-0 opacity-0 absolute top-0 -left cursor-pointer z-20 group-[.base--disabled]:cursor"
|
|
79
|
+
disabled=""
|
|
80
|
+
role="switch"
|
|
81
|
+
type="checkbox"
|
|
107
82
|
/>
|
|
108
83
|
</span>
|
|
109
84
|
<span
|
|
110
|
-
class="PicassoFormLabel-root PicassoFormLabel-disabled PicassoFormLabel-inline PicassoFormControlLabel-label
|
|
85
|
+
class="PicassoFormLabel-root PicassoFormLabel-disabled PicassoFormLabel-inline PicassoFormControlLabel-label ml-[0.5em] mt-[0.25em] max-w-[calc(100%-1em"
|
|
111
86
|
>
|
|
112
87
|
<span
|
|
113
88
|
class="PicassoFormLabel-medium"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../src/Switch/styles.ts"],"names":[],"mappings":";AA4EA,wBASI"}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { createStyles } from '@material-ui/core/styles';
|
|
2
|
-
import { outline } from '@toptal/picasso-shared';
|
|
3
|
-
import { PicassoProvider } from '@toptal/picasso-provider';
|
|
4
|
-
const CONTROL_WIDTH = '1em';
|
|
5
|
-
const LABEL_LEFT_MARGIN = '0.5em';
|
|
6
|
-
const LABEL_TOP_MARGIN = '0.25em';
|
|
7
|
-
const THUMB_SIZE = 22;
|
|
8
|
-
const TRACK_HEIGHT = THUMB_SIZE + 2;
|
|
9
|
-
const TRACK_WIDTH = 40;
|
|
10
|
-
PicassoProvider.override(({ palette, transitions }) => ({
|
|
11
|
-
MuiSwitch: {
|
|
12
|
-
root: {
|
|
13
|
-
width: TRACK_WIDTH,
|
|
14
|
-
height: TRACK_HEIGHT,
|
|
15
|
-
padding: 0,
|
|
16
|
-
overflow: 'visible',
|
|
17
|
-
},
|
|
18
|
-
switchBase: {
|
|
19
|
-
top: 1,
|
|
20
|
-
left: 1,
|
|
21
|
-
padding: 0,
|
|
22
|
-
color: palette.common.white,
|
|
23
|
-
'&$checked': {
|
|
24
|
-
transform: 'translateX(16px)',
|
|
25
|
-
color: palette.common.white,
|
|
26
|
-
'& + $track': {
|
|
27
|
-
backgroundColor: palette.primary.main,
|
|
28
|
-
borderColor: palette.primary.main,
|
|
29
|
-
opacity: 1,
|
|
30
|
-
},
|
|
31
|
-
'&$disabled + $track': {
|
|
32
|
-
opacity: 0.4,
|
|
33
|
-
backgroundColor: palette.primary.main,
|
|
34
|
-
borderColor: palette.primary.main,
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
'&:hover, &.Mui-focusVisible': Object.assign({}, outline(palette.primary.main, 4)),
|
|
38
|
-
'&$disabled': {
|
|
39
|
-
'& + $track': {
|
|
40
|
-
opacity: 0.4,
|
|
41
|
-
backgroundColor: palette.grey.main2,
|
|
42
|
-
borderColor: palette.grey.main2,
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
thumb: {
|
|
47
|
-
width: THUMB_SIZE,
|
|
48
|
-
height: THUMB_SIZE,
|
|
49
|
-
color: palette.common.white,
|
|
50
|
-
// fix for bad subpixel rendering on 150% displays
|
|
51
|
-
'@media (-webkit-min-device-pixel-ratio: 1.5) and (-webkit-max-device-pixel-ratio: 1.5)': {
|
|
52
|
-
transform: 'translate(-0.2px, -0.3px)',
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
track: {
|
|
56
|
-
borderRadius: TRACK_HEIGHT / 2,
|
|
57
|
-
border: `1px solid ${palette.grey.main2}`,
|
|
58
|
-
backgroundColor: palette.grey.main2,
|
|
59
|
-
borderColor: palette.grey.main2,
|
|
60
|
-
opacity: 1,
|
|
61
|
-
transition: transitions.create(['background-color', 'border']),
|
|
62
|
-
},
|
|
63
|
-
disabled: {
|
|
64
|
-
'& + $track': {
|
|
65
|
-
opacity: 0.4,
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
}));
|
|
70
|
-
export default () => createStyles({
|
|
71
|
-
root: { alignItems: 'flex-start', fontSize: '1rem' },
|
|
72
|
-
label: {
|
|
73
|
-
marginLeft: LABEL_LEFT_MARGIN,
|
|
74
|
-
marginTop: LABEL_TOP_MARGIN,
|
|
75
|
-
// 1px is needed for safari
|
|
76
|
-
maxWidth: `calc(100% - ${CONTROL_WIDTH} - ${LABEL_LEFT_MARGIN} + 1px)`,
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
//# sourceMappingURL=styles.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../../../src/Switch/styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE1D,MAAM,aAAa,GAAG,KAAK,CAAA;AAC3B,MAAM,iBAAiB,GAAG,OAAO,CAAA;AACjC,MAAM,gBAAgB,GAAG,QAAQ,CAAA;AAEjC,MAAM,UAAU,GAAG,EAAE,CAAA;AACrB,MAAM,YAAY,GAAG,UAAU,GAAG,CAAC,CAAA;AACnC,MAAM,WAAW,GAAG,EAAE,CAAA;AAEtB,eAAe,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC;IACtD,SAAS,EAAE;QACT,IAAI,EAAE;YACJ,KAAK,EAAE,WAAW;YAClB,MAAM,EAAE,YAAY;YACpB,OAAO,EAAE,CAAC;YACV,QAAQ,EAAE,SAAS;SACpB;QACD,UAAU,EAAE;YACV,GAAG,EAAE,CAAC;YACN,IAAI,EAAE,CAAC;YACP,OAAO,EAAE,CAAC;YACV,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,KAAK;YAC3B,WAAW,EAAE;gBACX,SAAS,EAAE,kBAAkB;gBAC7B,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,KAAK;gBAC3B,YAAY,EAAE;oBACZ,eAAe,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI;oBACrC,WAAW,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI;oBACjC,OAAO,EAAE,CAAC;iBACX;gBACD,qBAAqB,EAAE;oBACrB,OAAO,EAAE,GAAG;oBACZ,eAAe,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI;oBACrC,WAAW,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI;iBAClC;aACF;YACD,6BAA6B,oBACxB,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CACpC;YACD,YAAY,EAAE;gBACZ,YAAY,EAAE;oBACZ,OAAO,EAAE,GAAG;oBACZ,eAAe,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK;oBACnC,WAAW,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK;iBAChC;aACF;SACF;QACD,KAAK,EAAE;YACL,KAAK,EAAE,UAAU;YACjB,MAAM,EAAE,UAAU;YAClB,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,KAAK;YAC3B,kDAAkD;YAClD,wFAAwF,EACtF;gBACE,SAAS,EAAE,2BAA2B;aACvC;SACJ;QACD,KAAK,EAAE;YACL,YAAY,EAAE,YAAY,GAAG,CAAC;YAC9B,MAAM,EAAE,aAAa,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE;YACzC,eAAe,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK;YACnC,WAAW,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK;YAC/B,OAAO,EAAE,CAAC;YACV,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC;SAC/D;QACD,QAAQ,EAAE;YACR,YAAY,EAAE;gBACZ,OAAO,EAAE,GAAG;aACb;SACF;KACF;CACF,CAAC,CAAC,CAAA;AAEH,eAAe,GAAG,EAAE,CAClB,YAAY,CAAC;IACX,IAAI,EAAE,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE;IACpD,KAAK,EAAE;QACL,UAAU,EAAE,iBAAiB;QAC7B,SAAS,EAAE,gBAAgB;QAC3B,2BAA2B;QAC3B,QAAQ,EAAE,eAAe,aAAa,MAAM,iBAAiB,SAAS;KACvE;CACF,CAAC,CAAA"}
|
package/src/Switch/styles.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { createStyles } from '@material-ui/core/styles'
|
|
2
|
-
import { outline } from '@toptal/picasso-shared'
|
|
3
|
-
import { PicassoProvider } from '@toptal/picasso-provider'
|
|
4
|
-
|
|
5
|
-
const CONTROL_WIDTH = '1em'
|
|
6
|
-
const LABEL_LEFT_MARGIN = '0.5em'
|
|
7
|
-
const LABEL_TOP_MARGIN = '0.25em'
|
|
8
|
-
|
|
9
|
-
const THUMB_SIZE = 22
|
|
10
|
-
const TRACK_HEIGHT = THUMB_SIZE + 2
|
|
11
|
-
const TRACK_WIDTH = 40
|
|
12
|
-
|
|
13
|
-
PicassoProvider.override(({ palette, transitions }) => ({
|
|
14
|
-
MuiSwitch: {
|
|
15
|
-
root: {
|
|
16
|
-
width: TRACK_WIDTH,
|
|
17
|
-
height: TRACK_HEIGHT,
|
|
18
|
-
padding: 0,
|
|
19
|
-
overflow: 'visible',
|
|
20
|
-
},
|
|
21
|
-
switchBase: {
|
|
22
|
-
top: 1,
|
|
23
|
-
left: 1,
|
|
24
|
-
padding: 0,
|
|
25
|
-
color: palette.common.white,
|
|
26
|
-
'&$checked': {
|
|
27
|
-
transform: 'translateX(16px)',
|
|
28
|
-
color: palette.common.white,
|
|
29
|
-
'& + $track': {
|
|
30
|
-
backgroundColor: palette.primary.main,
|
|
31
|
-
borderColor: palette.primary.main,
|
|
32
|
-
opacity: 1,
|
|
33
|
-
},
|
|
34
|
-
'&$disabled + $track': {
|
|
35
|
-
opacity: 0.4,
|
|
36
|
-
backgroundColor: palette.primary.main,
|
|
37
|
-
borderColor: palette.primary.main,
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
'&:hover, &.Mui-focusVisible': {
|
|
41
|
-
...outline(palette.primary.main, 4),
|
|
42
|
-
},
|
|
43
|
-
'&$disabled': {
|
|
44
|
-
'& + $track': {
|
|
45
|
-
opacity: 0.4,
|
|
46
|
-
backgroundColor: palette.grey.main2,
|
|
47
|
-
borderColor: palette.grey.main2,
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
thumb: {
|
|
52
|
-
width: THUMB_SIZE,
|
|
53
|
-
height: THUMB_SIZE,
|
|
54
|
-
color: palette.common.white,
|
|
55
|
-
// fix for bad subpixel rendering on 150% displays
|
|
56
|
-
'@media (-webkit-min-device-pixel-ratio: 1.5) and (-webkit-max-device-pixel-ratio: 1.5)':
|
|
57
|
-
{
|
|
58
|
-
transform: 'translate(-0.2px, -0.3px)',
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
track: {
|
|
62
|
-
borderRadius: TRACK_HEIGHT / 2,
|
|
63
|
-
border: `1px solid ${palette.grey.main2}`,
|
|
64
|
-
backgroundColor: palette.grey.main2,
|
|
65
|
-
borderColor: palette.grey.main2,
|
|
66
|
-
opacity: 1,
|
|
67
|
-
transition: transitions.create(['background-color', 'border']),
|
|
68
|
-
},
|
|
69
|
-
disabled: {
|
|
70
|
-
'& + $track': {
|
|
71
|
-
opacity: 0.4,
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
}))
|
|
76
|
-
|
|
77
|
-
export default () =>
|
|
78
|
-
createStyles({
|
|
79
|
-
root: { alignItems: 'flex-start', fontSize: '1rem' },
|
|
80
|
-
label: {
|
|
81
|
-
marginLeft: LABEL_LEFT_MARGIN,
|
|
82
|
-
marginTop: LABEL_TOP_MARGIN,
|
|
83
|
-
// 1px is needed for safari
|
|
84
|
-
maxWidth: `calc(100% - ${CONTROL_WIDTH} - ${LABEL_LEFT_MARGIN} + 1px)`,
|
|
85
|
-
},
|
|
86
|
-
})
|