@spaced-out/ui-design-system 0.1.14 → 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
  }
@@ -13,7 +13,6 @@ var _space = require("../../styles/variables/_space");
13
13
  var _classify = require("../../utils/classify");
14
14
  var _mergeRefs = require("../../utils/merge-refs");
15
15
  var _string = require("../../utils/string");
16
- var _Text = require("../Text");
17
16
  var _Truncate = require("../Truncate");
18
17
  var _TooltipModule = _interopRequireDefault(require("./Tooltip.module.css"));
19
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -87,12 +86,14 @@ const Tooltip = _ref => {
87
86
  }
88
87
  }, getFloatingProps()), !!title && /*#__PURE__*/React.createElement(_Truncate.Truncate, {
89
88
  line: titleMaxLines
90
- }, /*#__PURE__*/React.createElement(_Text.SubTitleExtraSmall, {
91
- color: "inversePrimary"
89
+ }, /*#__PURE__*/React.createElement("div", {
90
+ className: (0, _classify.classify)(_TooltipModule.default.title, classNames?.title)
92
91
  }, title)), !!body && /*#__PURE__*/React.createElement(_Truncate.Truncate, {
93
92
  line: bodyMaxLines
94
- }, /*#__PURE__*/React.createElement(_Text.BodyMedium, {
95
- color: !title ? 'inversePrimary' : 'inverseSecondary'
93
+ }, /*#__PURE__*/React.createElement("div", {
94
+ className: (0, _classify.classify)(_TooltipModule.default.body, {
95
+ [_TooltipModule.default.hasTitle]: !!title
96
+ }, classNames?.body)
96
97
  }, body))), bodyRef.current));
97
98
  };
98
99
  exports.Tooltip = Tooltip;
@@ -32,13 +32,12 @@ import {spaceNone, spaceXXSmall} from '../../styles/variables/_space';
32
32
  import {classify} from '../../utils/classify';
33
33
  import {mergeRefs} from '../../utils/merge-refs';
34
34
  import {capitalize} from '../../utils/string';
35
- import {BodyMedium, SubTitleExtraSmall} from '../Text';
36
35
  import {Truncate} from '../Truncate';
37
36
 
38
37
  import css from './Tooltip.module.css';
39
38
 
40
39
 
41
- type ClassNames = $ReadOnly<{tooltip?: string}>;
40
+ type ClassNames = $ReadOnly<{tooltip?: string, title?: string, body?: string}>;
42
41
 
43
42
  export const DELAY_MOTION_DURATION_TYPES = Object.freeze({
44
43
  none: 'none',
@@ -147,19 +146,25 @@ export const Tooltip = ({
147
146
  >
148
147
  {!!title && (
149
148
  <Truncate line={titleMaxLines}>
150
- <SubTitleExtraSmall color="inversePrimary">
149
+ <div className={classify(css.title, classNames?.title)}>
151
150
  {title}
152
- </SubTitleExtraSmall>
151
+ </div>
153
152
  </Truncate>
154
153
  )}
155
154
 
156
155
  {!!body && (
157
156
  <Truncate line={bodyMaxLines}>
158
- <BodyMedium
159
- color={!title ? 'inversePrimary' : 'inverseSecondary'}
157
+ <div
158
+ className={classify(
159
+ css.body,
160
+ {
161
+ [css.hasTitle]: !!title,
162
+ },
163
+ classNames?.body,
164
+ )}
160
165
  >
161
166
  {body}
162
- </BodyMedium>
167
+ </div>
163
168
  </Truncate>
164
169
  )}
165
170
  </div>,
@@ -1,4 +1,4 @@
1
- @value (colorTooltipFill) from '../../styles/variables/_color.css';
1
+ @value (colorTooltipFill, colorTextInversePrimary, colorTextInverseSecondary) from '../../styles/variables/_color.css';
2
2
  @value (size300) from '../../styles/variables/_size.css';
3
3
  @value (spaceXSmall, spaceSmall, spaceXXSmall) from '../../styles/variables/_space.css';
4
4
  @value (borderRadiusSmall) from '../../styles/variables/_border.css';
@@ -17,3 +17,17 @@
17
17
  word-wrap: break-word;
18
18
  z-index: var(--tooltip-elevation);
19
19
  }
20
+
21
+ .title {
22
+ composes: subTitleExtraSmall from '../../styles/typography.module.css';
23
+ color: colorTextInversePrimary;
24
+ }
25
+
26
+ .body {
27
+ composes: bodyMedium from '../../styles/typography.module.css';
28
+ color: colorTextInversePrimary;
29
+ }
30
+
31
+ .hasTitle {
32
+ color: colorTextInverseSecondary;
33
+ }
@@ -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.14",
3
+ "version": "0.1.16",
4
4
  "main": "index.js",
5
5
  "description": "Sense UI components library",
6
6
  "author": {