@spaced-out/ui-design-system 0.1.15 → 0.1.16

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.
@@ -3,7 +3,6 @@
3
3
  import * as React from 'react';
4
4
 
5
5
  import classify from '../../utils/classify';
6
- import {FormLabelMedium} from '../Text/Text';
7
6
 
8
7
  import css from './Toggle.module.css';
9
8
 
@@ -25,10 +24,11 @@ export type ToggleProps = {
25
24
  disabled?: boolean,
26
25
  focused?: boolean,
27
26
  value?: string,
27
+ ariaLabel?: string,
28
28
  };
29
29
 
30
- export const Toggle: React$AbstractComponent<ToggleProps, HTMLLabelElement> =
31
- React.forwardRef<ToggleProps, HTMLLabelElement>(
30
+ export const Toggle: React$AbstractComponent<ToggleProps, HTMLInputElement> =
31
+ React.forwardRef<ToggleProps, HTMLInputElement>(
32
32
  (
33
33
  {
34
34
  name = 'toggle',
@@ -39,11 +39,13 @@ export const Toggle: React$AbstractComponent<ToggleProps, HTMLLabelElement> =
39
39
  checked,
40
40
  focused,
41
41
  onChange,
42
+ ariaLabel,
42
43
  ...props
43
44
  }: ToggleProps,
44
- ref,
45
+ forwardRef,
45
46
  ): React.Node => {
46
47
  const toggleInput = React.createRef<HTMLInputElement>();
48
+ React.useImperativeHandle(forwardRef, () => toggleInput.current);
47
49
  const handleOnChange = () => {
48
50
  if (!disabled) {
49
51
  onChange &&
@@ -54,13 +56,17 @@ export const Toggle: React$AbstractComponent<ToggleProps, HTMLLabelElement> =
54
56
  }
55
57
  };
56
58
 
59
+ const onWrapClickHandler = () => {
60
+ toggleInput.current?.click();
61
+ };
62
+
57
63
  React.useEffect(() => {
58
64
  if (toggleInput.current && focused) {
59
65
  toggleInput.current.focus();
60
66
  }
61
67
  }, [focused]);
62
68
  return (
63
- <label
69
+ <div
64
70
  className={classify(
65
71
  css.container,
66
72
  {
@@ -68,7 +74,7 @@ export const Toggle: React$AbstractComponent<ToggleProps, HTMLLabelElement> =
68
74
  },
69
75
  classNames?.wrapper,
70
76
  )}
71
- ref={ref}
77
+ onClick={onWrapClickHandler}
72
78
  >
73
79
  <span className={css.toggleWrap}>
74
80
  <input
@@ -79,6 +85,7 @@ export const Toggle: React$AbstractComponent<ToggleProps, HTMLLabelElement> =
79
85
  onChange={handleOnChange}
80
86
  ref={toggleInput}
81
87
  disabled={disabled}
88
+ aria-label={ariaLabel || children}
82
89
  {...props}
83
90
  />
84
91
  <span
@@ -88,14 +95,11 @@ export const Toggle: React$AbstractComponent<ToggleProps, HTMLLabelElement> =
88
95
  />
89
96
  </span>
90
97
  {React.Children.count(children) > 0 && (
91
- <FormLabelMedium
92
- color="secondary"
93
- className={classify(css.toggleLabel, classNames?.label)}
94
- >
98
+ <div className={classify(css.toggleLabel, classNames?.label)}>
95
99
  {children}
96
- </FormLabelMedium>
100
+ </div>
97
101
  )}
98
- </label>
102
+ </div>
99
103
  );
100
104
  },
101
105
  );
@@ -138,5 +138,7 @@
138
138
  }
139
139
 
140
140
  .toggleLabel {
141
+ composes: formLabelMedium from '../../styles/typography.module.css';
142
+ composes: secondary from '../../styles/typography.module.css';
141
143
  margin-left: spaceNone;
142
144
  }
@@ -16,7 +16,7 @@ export type ChildProps = {
16
16
  anchorRef: (?HTMLElement) => mixed,
17
17
  };
18
18
 
19
- type ClickAwayProps = {
19
+ export type ClickAwayProps = {
20
20
  closeOnEscapeKeypress?: boolean,
21
21
  children: (props: ChildProps) => React.Node,
22
22
  shouldCancel: (event: MouseEvent) => boolean,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spaced-out/ui-design-system",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "main": "index.js",
5
5
  "description": "Sense UI components library",
6
6
  "author": {