@basic-ui/material 1.0.0-alpha.29 → 1.0.0-alpha.30
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/build/cjs/index.js +85 -65
- package/build/cjs/index.js.map +1 -1
- package/build/esm/CheckBox/CheckBox.d.ts +1 -1
- package/build/esm/Chip/ButtonChip.d.ts +1 -1
- package/build/esm/SelectionControl/SelectionControlLabel.d.ts +1 -1
- package/build/esm/SelectionControl/SelectionControlLabel.js +2 -1
- package/build/esm/SelectionControl/SelectionControlLabel.js.map +1 -1
- package/build/esm/Switch/Switch.d.ts +2 -1
- package/build/esm/Switch/Switch.js +59 -46
- package/build/esm/Switch/Switch.js.map +1 -1
- package/build/esm/Switch/styledComponents.js +19 -20
- package/build/esm/Switch/styledComponents.js.map +1 -1
- package/build/esm/Table/TableHead.d.ts +1 -1
- package/build/tsconfig-build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/SelectionControl/SelectionControlLabel.tsx +1 -0
- package/src/Switch/Switch.story.tsx +14 -0
- package/src/Switch/Switch.tsx +75 -46
- package/src/Switch/styledComponents.tsx +26 -25
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@basic-ui/material",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.30",
|
|
4
4
|
"description": "Accessible React Components used as building blocks for UI patterns",
|
|
5
5
|
"author": "Lucas Terra <lucasterra7@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"react": "^16.14.0 || ^17.0.0 || ^18.0.0",
|
|
53
53
|
"react-dom": "^16.14.0 || ^17.0.0 || ^18.0.0"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "4c7fdd9ea2da383ea6f249ba864346e48da1e31a"
|
|
56
56
|
}
|
|
@@ -20,6 +20,20 @@ const Example = () => {
|
|
|
20
20
|
<Switch disabled />
|
|
21
21
|
<Switch disabled defaultChecked={true} />
|
|
22
22
|
</Box>
|
|
23
|
+
<Box>
|
|
24
|
+
<Switch size="small">off/on</Switch>
|
|
25
|
+
<Switch disabled size="small">
|
|
26
|
+
off/on
|
|
27
|
+
</Switch>
|
|
28
|
+
<Switch disabled defaultChecked={true} size="small">
|
|
29
|
+
off/on
|
|
30
|
+
</Switch>
|
|
31
|
+
</Box>
|
|
32
|
+
<Box>
|
|
33
|
+
<Switch size="small" />
|
|
34
|
+
<Switch disabled size="small" />
|
|
35
|
+
<Switch disabled defaultChecked={true} size="small" />
|
|
36
|
+
</Box>
|
|
23
37
|
</>
|
|
24
38
|
);
|
|
25
39
|
};
|
package/src/Switch/Switch.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ElementType, FC, InputHTMLAttributes } from 'react';
|
|
2
2
|
import { forwardRef } from 'react';
|
|
3
3
|
import { CheckBox as _CheckBoxCore } from '@basic-ui/core';
|
|
4
|
+
import { rem } from 'polished';
|
|
4
5
|
|
|
5
6
|
import type { RippleBoxProps } from '../Ripple';
|
|
6
7
|
import { RippleBox } from '../Ripple';
|
|
@@ -24,6 +25,30 @@ export interface SwitchProps
|
|
|
24
25
|
as?: ElementType<any>;
|
|
25
26
|
checked?: boolean;
|
|
26
27
|
disabled?: boolean;
|
|
28
|
+
size?: 'small' | 'default';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function getSizeCssVariables(size: 'small' | 'default') {
|
|
32
|
+
const multiplier = size === 'small' ? 0.75 : 1;
|
|
33
|
+
const BORDER_WIDTH = 2;
|
|
34
|
+
const TRAIL_WIDTH = 52 * multiplier;
|
|
35
|
+
const TRAIL_HEIGHT = 32 * multiplier;
|
|
36
|
+
return {
|
|
37
|
+
['--switch-border-width']: rem(BORDER_WIDTH),
|
|
38
|
+
['--switch-trail-width']: rem(TRAIL_WIDTH),
|
|
39
|
+
['--switch-trail-height']: rem(TRAIL_HEIGHT),
|
|
40
|
+
['--switch-state-layer-size']: rem(40 * multiplier),
|
|
41
|
+
['--switch-thumb-size-checked-inactive']: rem(
|
|
42
|
+
TRAIL_HEIGHT - BORDER_WIDTH * 4
|
|
43
|
+
),
|
|
44
|
+
['--switch-thumb-size-checked-active']: rem(
|
|
45
|
+
TRAIL_HEIGHT - BORDER_WIDTH * 2
|
|
46
|
+
),
|
|
47
|
+
['--switch-thumb-size-unchecked-inactive']: rem(TRAIL_HEIGHT / 2),
|
|
48
|
+
['--switch-thumb-size-unchecked-active']: rem(
|
|
49
|
+
TRAIL_HEIGHT - BORDER_WIDTH * 2
|
|
50
|
+
),
|
|
51
|
+
};
|
|
27
52
|
}
|
|
28
53
|
|
|
29
54
|
const SwitchInner = forwardRef<HTMLInputElement, SwitchProps>(
|
|
@@ -33,6 +58,7 @@ const SwitchInner = forwardRef<HTMLInputElement, SwitchProps>(
|
|
|
33
58
|
disabled,
|
|
34
59
|
checked,
|
|
35
60
|
onChange,
|
|
61
|
+
size = 'default',
|
|
36
62
|
__css,
|
|
37
63
|
...otherProps
|
|
38
64
|
} = props;
|
|
@@ -40,53 +66,56 @@ const SwitchInner = forwardRef<HTMLInputElement, SwitchProps>(
|
|
|
40
66
|
const theme = useTheme();
|
|
41
67
|
|
|
42
68
|
return (
|
|
43
|
-
<Box
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
69
|
+
<Box
|
|
70
|
+
display="inline-block"
|
|
71
|
+
position="relative"
|
|
72
|
+
minWidth="auto"
|
|
73
|
+
sx={getSizeCssVariables(size)}
|
|
74
|
+
>
|
|
75
|
+
<SwitchTrail checked={checked} disabled={disabled} />
|
|
76
|
+
<SwitchThumb checked={checked}>
|
|
77
|
+
<RippleBox<
|
|
78
|
+
RippleBoxProps<
|
|
79
|
+
HTMLInputElement,
|
|
80
|
+
InputHTMLAttributes<HTMLInputElement>
|
|
52
81
|
>
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
</
|
|
82
|
+
>
|
|
83
|
+
as={Comp}
|
|
84
|
+
role="switch"
|
|
85
|
+
type="checkbox"
|
|
86
|
+
checked={checked}
|
|
87
|
+
onChange={onChange}
|
|
88
|
+
theme={theme}
|
|
89
|
+
ref={forwardedRef}
|
|
90
|
+
aria-checked={checked ? 'true' : 'false'}
|
|
91
|
+
rippleColor={color}
|
|
92
|
+
baseOpacity={0}
|
|
93
|
+
hoverOpacity={0.04}
|
|
94
|
+
focusOpacity={0.12}
|
|
95
|
+
center={true}
|
|
96
|
+
disabled={disabled}
|
|
97
|
+
data-switch-thumb=""
|
|
98
|
+
{...otherProps}
|
|
99
|
+
__css={{
|
|
100
|
+
top: '50%',
|
|
101
|
+
left: '50%',
|
|
102
|
+
backgroundColor: 'transparent',
|
|
103
|
+
transform: 'translate(-50%, -50%)',
|
|
104
|
+
width: '100%',
|
|
105
|
+
height: '100%',
|
|
106
|
+
appearance: 'none',
|
|
107
|
+
':focus': {
|
|
108
|
+
outline: 'none',
|
|
109
|
+
},
|
|
110
|
+
border: 'none',
|
|
111
|
+
borderRadius: 'full',
|
|
112
|
+
zIndex: 1,
|
|
113
|
+
position: 'absolute',
|
|
114
|
+
...__css,
|
|
115
|
+
}}
|
|
116
|
+
/>
|
|
117
|
+
<SwitchCircle checked={checked} />
|
|
118
|
+
</SwitchThumb>
|
|
90
119
|
</Box>
|
|
91
120
|
);
|
|
92
121
|
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { rem } from 'polished';
|
|
2
|
-
|
|
3
1
|
import { Box } from '../Box';
|
|
4
2
|
import { EASING_STANDARD } from '../motion';
|
|
5
3
|
|
|
6
|
-
const BORDER_WIDTH =
|
|
7
|
-
const TRAIL_WIDTH =
|
|
8
|
-
const TRAIL_HEIGHT =
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
const
|
|
4
|
+
const BORDER_WIDTH = 'var(--switch-border-width)';
|
|
5
|
+
const TRAIL_WIDTH = 'var(--switch-trail-width)';
|
|
6
|
+
const TRAIL_HEIGHT = 'var(--switch-trail-height)';
|
|
7
|
+
const STATE_LAYER_SIZE = 'var(--switch-state-layer-size)';
|
|
8
|
+
const CIRCLE_SIZE_INACTIVE_CHECKED =
|
|
9
|
+
'var(--switch-thumb-size-checked-inactive)';
|
|
10
|
+
const CIRCLE_SIZE_ACTIVE_CHECKED = 'var(--switch-thumb-size-checked-active)';
|
|
11
|
+
const CIRCLE_SIZE_INACTIVE_UNCHECKED =
|
|
12
|
+
'var(--switch-thumb-size-unchecked-inactive)';
|
|
13
|
+
const CIRCLE_SIZE_ACTIVE_UNCHECKED =
|
|
14
|
+
'var(--switch-thumb-size-unchecked-active)';
|
|
13
15
|
|
|
14
16
|
export const SwitchTrail = ({
|
|
15
17
|
checked = false,
|
|
@@ -18,10 +20,10 @@ export const SwitchTrail = ({
|
|
|
18
20
|
}) => (
|
|
19
21
|
<Box
|
|
20
22
|
__css={{
|
|
21
|
-
width:
|
|
22
|
-
height:
|
|
23
|
-
borderRadius:
|
|
24
|
-
borderWidth:
|
|
23
|
+
width: TRAIL_WIDTH,
|
|
24
|
+
height: TRAIL_HEIGHT,
|
|
25
|
+
borderRadius: 'full',
|
|
26
|
+
borderWidth: BORDER_WIDTH,
|
|
25
27
|
borderStyle: 'solid',
|
|
26
28
|
backgroundColor: checked ? 'primary' : 'surface-variant',
|
|
27
29
|
borderColor: checked ? 'primary' : 'outline',
|
|
@@ -35,24 +37,23 @@ export const SwitchTrail = ({
|
|
|
35
37
|
/>
|
|
36
38
|
);
|
|
37
39
|
|
|
38
|
-
const THUMB_SIZE = 40;
|
|
39
40
|
export const SwitchThumb = ({ checked = false, ...otherProps }) => (
|
|
40
41
|
<Box
|
|
41
42
|
position="absolute"
|
|
42
|
-
width={
|
|
43
|
-
height={
|
|
43
|
+
width={STATE_LAYER_SIZE}
|
|
44
|
+
height={STATE_LAYER_SIZE}
|
|
44
45
|
borderRadius="full"
|
|
45
46
|
left={'50%'}
|
|
46
47
|
top={'50%'}
|
|
47
48
|
__css={{
|
|
48
|
-
transform: `translateX(calc(-50% ${checked ? '+' : '-'}
|
|
49
|
-
(TRAIL_WIDTH - CIRCLE_SIZE_INACTIVE_CHECKED - BORDER_WIDTH * 4) / 2
|
|
50
|
-
)
|
|
49
|
+
transform: `translateX(calc(-50% ${checked ? '+' : '-'}
|
|
50
|
+
(${TRAIL_WIDTH} - ${CIRCLE_SIZE_INACTIVE_CHECKED} - ${BORDER_WIDTH} * 4) / 2
|
|
51
|
+
)) translateY(-50%)`,
|
|
51
52
|
WebkitTapHighlightColor: 'transparent',
|
|
52
53
|
transition: `background-color 90ms ${EASING_STANDARD},border-color 90ms ${EASING_STANDARD},transform 90ms ${EASING_STANDARD},height 90ms ${EASING_STANDARD},width 90ms ${EASING_STANDARD}`,
|
|
53
54
|
'& > input': {
|
|
54
|
-
width:
|
|
55
|
-
height:
|
|
55
|
+
width: STATE_LAYER_SIZE,
|
|
56
|
+
height: STATE_LAYER_SIZE,
|
|
56
57
|
},
|
|
57
58
|
}}
|
|
58
59
|
{...otherProps}
|
|
@@ -64,11 +65,11 @@ export const SwitchCircle = ({ checked = false, ...otherProps }) => (
|
|
|
64
65
|
__css={{
|
|
65
66
|
position: 'absolute',
|
|
66
67
|
width: checked
|
|
67
|
-
?
|
|
68
|
-
:
|
|
68
|
+
? CIRCLE_SIZE_INACTIVE_CHECKED
|
|
69
|
+
: CIRCLE_SIZE_INACTIVE_UNCHECKED,
|
|
69
70
|
height: checked
|
|
70
|
-
?
|
|
71
|
-
:
|
|
71
|
+
? CIRCLE_SIZE_INACTIVE_CHECKED
|
|
72
|
+
: CIRCLE_SIZE_INACTIVE_UNCHECKED,
|
|
72
73
|
boxSizing: 'border-box',
|
|
73
74
|
borderRadius: 'full',
|
|
74
75
|
pointerEvents: 'none',
|