@cypress-design/react-tooltip 0.1.0 → 0.2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @cypress-design/react-tooltip
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#53](https://github.com/cypress-io/cypress-design/pull/53) [`a9a616b`](https://github.com/cypress-io/cypress-design/commit/a9a616bc4684252fcd71e4a82d2141bdfbea32bc) Thanks [@elevatebart](https://github.com/elevatebart)! - - add a default font color when light and dark mode are used
8
+ - add disabled prop to tooltip
9
+
10
+ * [#51](https://github.com/cypress-io/cypress-design/pull/51) [`ccd8f9a`](https://github.com/cypress-io/cypress-design/commit/ccd8f9a8feb624c0a52deaa9754c76969f43fc1e) Thanks [@elevatebart](https://github.com/elevatebart)! - in the build asset, add a comment containing all used windicss classes in the component
11
+
3
12
  ## 0.1.0
4
13
 
5
14
  ### Minor Changes
@@ -5,10 +5,12 @@ import Tooltip from './Tooltip'
5
5
  export default ({
6
6
  color = 'light',
7
7
  placement,
8
+ disabled,
8
9
  tabIndex,
9
10
  }: {
10
11
  color?: 'light' | 'dark'
11
12
  placement?: Placement
13
+ disabled?: boolean
12
14
  tabIndex?: number
13
15
  } = {}) => (
14
16
  <div className="center flex flex-col items-center gap-20">
@@ -18,6 +20,7 @@ export default ({
18
20
  color={color}
19
21
  placement={placement}
20
22
  tabIndex={tabIndex}
23
+ disabled={disabled}
21
24
  >
22
25
  <div>Hover Me (dynamic: {placement?.toString()})</div>
23
26
  </Tooltip>
@@ -29,6 +32,7 @@ export default ({
29
32
  key={placement}
30
33
  color={color}
31
34
  tabIndex={tabIndex}
35
+ disabled={disabled}
32
36
  popper={
33
37
  <div className="bg-jade-200 text-gray-800 p-4">
34
38
  Popover ({placement})
package/Tooltip.tsx CHANGED
@@ -32,6 +32,11 @@ export interface TooltipProps {
32
32
  * The content of the tooltip.
33
33
  */
34
34
  popper?: React.ReactNode
35
+ /**
36
+ * Disable the tooltip.
37
+ * This hides the popper and makes the tooltip inactive.
38
+ */
39
+ disabled?: boolean
35
40
  }
36
41
 
37
42
  const ROTATE_MAP = {
@@ -43,7 +48,15 @@ const ROTATE_MAP = {
43
48
 
44
49
  export const Tooltip: React.FC<
45
50
  TooltipProps & React.HTMLProps<HTMLDivElement>
46
- > = ({ placement, color = 'light', className, children, popper, ...rest }) => {
51
+ > = ({
52
+ placement,
53
+ color = 'light',
54
+ className,
55
+ children,
56
+ popper,
57
+ disabled,
58
+ ...rest
59
+ }) => {
47
60
  const arrowRef = React.useRef(null)
48
61
  const [open, setOpen] = React.useState(false)
49
62
 
@@ -80,13 +93,18 @@ export const Tooltip: React.FC<
80
93
  const { getReferenceProps, getFloatingProps } = useInteractions([
81
94
  useHover(context, {
82
95
  handleClose: safePolygon(),
96
+ enabled: !disabled,
97
+ }),
98
+ useFocus(context, {
99
+ enabled: !disabled,
83
100
  }),
84
- useFocus(context),
85
101
  useRole(context, { role: 'tooltip' }),
86
102
  useDismiss(context),
87
103
  ])
88
104
 
89
- const placementSide = calculatedPlacement.split('-')[0]
105
+ const placementSide = calculatedPlacement.split(
106
+ '-'
107
+ )[0] as keyof typeof ROTATE_MAP
90
108
  const arrowRotate = ROTATE_MAP[placementSide]
91
109
 
92
110
  let arrowXRule = 'left',
@@ -114,7 +132,7 @@ export const Tooltip: React.FC<
114
132
  {children}
115
133
  </div>
116
134
  <FloatingPortal>
117
- {open && (
135
+ {open && !disabled && (
118
136
  <div
119
137
  {...getFloatingProps({
120
138
  ref: floating,
package/dist/Tooltip.d.ts CHANGED
@@ -16,6 +16,11 @@ export interface TooltipProps {
16
16
  * The content of the tooltip.
17
17
  */
18
18
  popper?: React.ReactNode;
19
+ /**
20
+ * Disable the tooltip.
21
+ * This hides the popper and makes the tooltip inactive.
22
+ */
23
+ disabled?: boolean;
19
24
  }
20
25
  export declare const Tooltip: React.FC<TooltipProps & React.HTMLProps<HTMLDivElement>>;
21
26
  export default Tooltip;
@@ -1 +1 @@
1
- {"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../Tooltip.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EACL,SAAS,EAaV,MAAM,qCAAqC,CAAA;AAE5C,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC1B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B;;OAEG;IACH,MAAM,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CACzB;AASD,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAC5B,YAAY,GAAG,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAiI/C,CAAA;AAED,eAAe,OAAO,CAAA"}
1
+ {"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../Tooltip.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EACL,SAAS,EAaV,MAAM,qCAAqC,CAAA;AAE5C,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC1B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B;;OAEG;IACH,MAAM,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IACxB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AASD,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAC5B,YAAY,GAAG,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CA8I/C,CAAA;AAED,eAAe,OAAO,CAAA"}
package/dist/index.es.js CHANGED
@@ -30316,7 +30316,7 @@ var ROTATE_MAP = {
30316
30316
  };
30317
30317
  var Tooltip = function (_a) {
30318
30318
  var _b;
30319
- var placement = _a.placement, _c = _a.color, color = _c === void 0 ? 'light' : _c, className = _a.className, children = _a.children, popper = _a.popper, rest = __rest(_a, ["placement", "color", "className", "children", "popper"]);
30319
+ var placement = _a.placement, _c = _a.color, color = _c === void 0 ? 'light' : _c, className = _a.className, children = _a.children, popper = _a.popper, disabled = _a.disabled, rest = __rest(_a, ["placement", "color", "className", "children", "popper", "disabled"]);
30320
30320
  var arrowRef = React.useRef(null);
30321
30321
  var _d = React.useState(false), open = _d[0], setOpen = _d[1];
30322
30322
  var container = React.useState(function () {
@@ -30339,9 +30339,12 @@ var Tooltip = function (_a) {
30339
30339
  }), x = _e.x, y = _e.y, reference = _e.reference, floating = _e.floating, strategy = _e.strategy, calculatedPlacement = _e.placement, context = _e.context, _f = _e.middlewareData.arrow, _g = _f === void 0 ? {} : _f, arrowX = _g.x, arrowY = _g.y;
30340
30340
  var _h = useInteractions([
30341
30341
  useHover(context, {
30342
- handleClose: safePolygon()
30342
+ handleClose: safePolygon(),
30343
+ enabled: !disabled
30344
+ }),
30345
+ useFocus(context, {
30346
+ enabled: !disabled
30343
30347
  }),
30344
- useFocus(context),
30345
30348
  useRole(context, { role: 'tooltip' }),
30346
30349
  useDismiss(context),
30347
30350
  ]), getReferenceProps = _h.getReferenceProps, getFloatingProps = _h.getFloatingProps;
@@ -30362,7 +30365,7 @@ var Tooltip = function (_a) {
30362
30365
  }
30363
30366
  return (React.createElement(React.Fragment, null,
30364
30367
  React.createElement("div", __assign({}, getReferenceProps(), { ref: reference, className: className }, rest), children),
30365
- React.createElement(FloatingPortal, null, open && (React.createElement("div", __assign({}, getFloatingProps({
30368
+ React.createElement(FloatingPortal, null, open && !disabled && (React.createElement("div", __assign({}, getFloatingProps({
30366
30369
  ref: floating,
30367
30370
  style: {
30368
30371
  position: strategy,
@@ -30395,4 +30398,6 @@ var Tooltip = function (_a) {
30395
30398
  };
30396
30399
 
30397
30400
  export { Tooltip as default };
30401
+ /* <windicss-keep class="container absolute stroke-gray-800 fill-gray-900 stroke-gray-100 fill-white rounded shadow border p-8px text-16px leading-24px min-w-160px text-center bg-gray-900 shadow-gray-800 border-gray-800 bg-white shadow-gray-100 border-gray-100 invisible"> */
30402
+
30398
30403
  //# sourceMappingURL=index.es.js.map