@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basic-ui/material",
3
- "version": "1.0.0-alpha.29",
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": "ee3fb47600f6b456b30902d30436894fde9c5387"
55
+ "gitHead": "4c7fdd9ea2da383ea6f249ba864346e48da1e31a"
56
56
  }
@@ -25,6 +25,7 @@ export const SelectionControlLabel = forwardRef<
25
25
  position: 'relative',
26
26
  alignItems: 'center',
27
27
  WebkitTapHighlightColor: 'transparent',
28
+ gap: 1,
28
29
  ...__css,
29
30
  }}
30
31
  {...otherProps}
@@ -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
  };
@@ -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 p={2} display="inline-block" minWidth="auto">
44
- <Box position="relative">
45
- <SwitchTrail checked={checked} disabled={disabled} />
46
- <SwitchThumb checked={checked}>
47
- <RippleBox<
48
- RippleBoxProps<
49
- HTMLInputElement,
50
- InputHTMLAttributes<HTMLInputElement>
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
- as={Comp}
54
- role="switch"
55
- type="checkbox"
56
- checked={checked}
57
- onChange={onChange}
58
- theme={theme}
59
- ref={forwardedRef}
60
- aria-checked={checked ? 'true' : 'false'}
61
- rippleColor={color}
62
- baseOpacity={0}
63
- hoverOpacity={0.04}
64
- focusOpacity={0.12}
65
- center={true}
66
- disabled={disabled}
67
- data-switch-thumb=""
68
- {...otherProps}
69
- __css={{
70
- top: '50%',
71
- left: '50%',
72
- backgroundColor: 'transparent',
73
- transform: 'translate(-50%, -50%)',
74
- width: '100%',
75
- height: '100%',
76
- appearance: 'none',
77
- ':focus': {
78
- outline: 'none',
79
- },
80
- border: 'none',
81
- borderRadius: 'full',
82
- zIndex: 1,
83
- position: 'absolute',
84
- ...__css,
85
- }}
86
- />
87
- <SwitchCircle checked={checked} />
88
- </SwitchThumb>
89
- </Box>
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 = 2;
7
- const TRAIL_WIDTH = 52;
8
- const TRAIL_HEIGHT = 32;
9
- const CIRCLE_SIZE_INACTIVE_CHECKED = 24;
10
- const CIRCLE_SIZE_ACTIVE_CHECKED = 28;
11
- const CIRCLE_SIZE_INACTIVE_UNCHECKED = 16;
12
- const CIRCLE_SIZE_ACTIVE_UNCHECKED = 28;
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: rem(TRAIL_WIDTH),
22
- height: rem(TRAIL_HEIGHT),
23
- borderRadius: rem(TRAIL_HEIGHT / 2),
24
- borderWidth: rem(BORDER_WIDTH),
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={rem(THUMB_SIZE)}
43
- height={rem(THUMB_SIZE)}
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 ? '+' : '-'} ${rem(
49
- (TRAIL_WIDTH - CIRCLE_SIZE_INACTIVE_CHECKED - BORDER_WIDTH * 4) / 2
50
- )})) translateY(-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: THUMB_SIZE,
55
- height: THUMB_SIZE,
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
- ? rem(CIRCLE_SIZE_INACTIVE_CHECKED)
68
- : rem(CIRCLE_SIZE_INACTIVE_UNCHECKED),
68
+ ? CIRCLE_SIZE_INACTIVE_CHECKED
69
+ : CIRCLE_SIZE_INACTIVE_UNCHECKED,
69
70
  height: checked
70
- ? rem(CIRCLE_SIZE_INACTIVE_CHECKED)
71
- : rem(CIRCLE_SIZE_INACTIVE_UNCHECKED),
71
+ ? CIRCLE_SIZE_INACTIVE_CHECKED
72
+ : CIRCLE_SIZE_INACTIVE_UNCHECKED,
72
73
  boxSizing: 'border-box',
73
74
  borderRadius: 'full',
74
75
  pointerEvents: 'none',