@linzjs/lui 17.15.1 → 17.16.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,3 +1,10 @@
1
+ # [17.16.0](https://github.com/linz/lui/compare/v17.15.1...v17.16.0) (2022-09-29)
2
+
3
+
4
+ ### Features
5
+
6
+ * update the tooltip UX and add the following cursor support ([#772](https://github.com/linz/lui/issues/772)) ([9a812de](https://github.com/linz/lui/commit/9a812de282e2c9266ae9d75be0d4bfbe0ac69870))
7
+
1
8
  ## [17.15.1](https://github.com/linz/lui/compare/v17.15.0...v17.15.1) (2022-09-22)
2
9
 
3
10
  # [17.15.0](https://github.com/linz/lui/compare/v17.14.1...v17.15.0) (2022-09-20)
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  export declare const LuiSidePanel: React.FC<{
3
3
  onClose: () => void;
4
4
  width?: string;
5
+ closeBtnTitleAttr?: string;
5
6
  top?: number;
6
7
  }>;
7
8
  export declare const LuiSidePanelProvider: React.FC;
@@ -1,12 +1,14 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { Placement } from 'tippy.js';
3
- import 'tippy.js/dist/tippy.css';
4
3
  import 'tippy.js/dist/border.css';
4
+ import 'tippy.js/dist/tippy.css';
5
5
  export interface ILuiTooltipProperties {
6
6
  message: string;
7
7
  placement?: Placement;
8
8
  trigger?: string;
9
9
  children: ReactNode;
10
10
  animation?: boolean;
11
+ followCursor?: boolean;
12
+ mode?: 'default' | 'info' | 'error';
11
13
  }
12
14
  export declare const LuiTooltip: (props: ILuiTooltipProperties) => JSX.Element;
package/dist/index.js CHANGED
@@ -32830,20 +32830,198 @@ Object.assign({}, applyStyles$1, {
32830
32830
  }
32831
32831
  });
32832
32832
 
32833
+ var mouseCoords = {
32834
+ clientX: 0,
32835
+ clientY: 0
32836
+ };
32837
+ var activeInstances = [];
32838
+
32839
+ function storeMouseCoords(_ref) {
32840
+ var clientX = _ref.clientX,
32841
+ clientY = _ref.clientY;
32842
+ mouseCoords = {
32843
+ clientX: clientX,
32844
+ clientY: clientY
32845
+ };
32846
+ }
32847
+
32848
+ function addMouseCoordsListener(doc) {
32849
+ doc.addEventListener('mousemove', storeMouseCoords);
32850
+ }
32851
+
32852
+ function removeMouseCoordsListener(doc) {
32853
+ doc.removeEventListener('mousemove', storeMouseCoords);
32854
+ }
32855
+
32856
+ var followCursor = {
32857
+ name: 'followCursor',
32858
+ defaultValue: false,
32859
+ fn: function fn(instance) {
32860
+ var reference = instance.reference;
32861
+ var doc = getOwnerDocument(instance.props.triggerTarget || reference);
32862
+ var isInternalUpdate = false;
32863
+ var wasFocusEvent = false;
32864
+ var isUnmounted = true;
32865
+ var prevProps = instance.props;
32866
+
32867
+ function getIsInitialBehavior() {
32868
+ return instance.props.followCursor === 'initial' && instance.state.isVisible;
32869
+ }
32870
+
32871
+ function addListener() {
32872
+ doc.addEventListener('mousemove', onMouseMove);
32873
+ }
32874
+
32875
+ function removeListener() {
32876
+ doc.removeEventListener('mousemove', onMouseMove);
32877
+ }
32878
+
32879
+ function unsetGetReferenceClientRect() {
32880
+ isInternalUpdate = true;
32881
+ instance.setProps({
32882
+ getReferenceClientRect: null
32883
+ });
32884
+ isInternalUpdate = false;
32885
+ }
32886
+
32887
+ function onMouseMove(event) {
32888
+ // If the instance is interactive, avoid updating the position unless it's
32889
+ // over the reference element
32890
+ var isCursorOverReference = event.target ? reference.contains(event.target) : true;
32891
+ var followCursor = instance.props.followCursor;
32892
+ var clientX = event.clientX,
32893
+ clientY = event.clientY;
32894
+ var rect = reference.getBoundingClientRect();
32895
+ var relativeX = clientX - rect.left;
32896
+ var relativeY = clientY - rect.top;
32897
+
32898
+ if (isCursorOverReference || !instance.props.interactive) {
32899
+ instance.setProps({
32900
+ // @ts-ignore - unneeded DOMRect properties
32901
+ getReferenceClientRect: function getReferenceClientRect() {
32902
+ var rect = reference.getBoundingClientRect();
32903
+ var x = clientX;
32904
+ var y = clientY;
32905
+
32906
+ if (followCursor === 'initial') {
32907
+ x = rect.left + relativeX;
32908
+ y = rect.top + relativeY;
32909
+ }
32910
+
32911
+ var top = followCursor === 'horizontal' ? rect.top : y;
32912
+ var right = followCursor === 'vertical' ? rect.right : x;
32913
+ var bottom = followCursor === 'horizontal' ? rect.bottom : y;
32914
+ var left = followCursor === 'vertical' ? rect.left : x;
32915
+ return {
32916
+ width: right - left,
32917
+ height: bottom - top,
32918
+ top: top,
32919
+ right: right,
32920
+ bottom: bottom,
32921
+ left: left
32922
+ };
32923
+ }
32924
+ });
32925
+ }
32926
+ }
32927
+
32928
+ function create() {
32929
+ if (instance.props.followCursor) {
32930
+ activeInstances.push({
32931
+ instance: instance,
32932
+ doc: doc
32933
+ });
32934
+ addMouseCoordsListener(doc);
32935
+ }
32936
+ }
32937
+
32938
+ function destroy() {
32939
+ activeInstances = activeInstances.filter(function (data) {
32940
+ return data.instance !== instance;
32941
+ });
32942
+
32943
+ if (activeInstances.filter(function (data) {
32944
+ return data.doc === doc;
32945
+ }).length === 0) {
32946
+ removeMouseCoordsListener(doc);
32947
+ }
32948
+ }
32949
+
32950
+ return {
32951
+ onCreate: create,
32952
+ onDestroy: destroy,
32953
+ onBeforeUpdate: function onBeforeUpdate() {
32954
+ prevProps = instance.props;
32955
+ },
32956
+ onAfterUpdate: function onAfterUpdate(_, _ref2) {
32957
+ var followCursor = _ref2.followCursor;
32958
+
32959
+ if (isInternalUpdate) {
32960
+ return;
32961
+ }
32962
+
32963
+ if (followCursor !== undefined && prevProps.followCursor !== followCursor) {
32964
+ destroy();
32965
+
32966
+ if (followCursor) {
32967
+ create();
32968
+
32969
+ if (instance.state.isMounted && !wasFocusEvent && !getIsInitialBehavior()) {
32970
+ addListener();
32971
+ }
32972
+ } else {
32973
+ removeListener();
32974
+ unsetGetReferenceClientRect();
32975
+ }
32976
+ }
32977
+ },
32978
+ onMount: function onMount() {
32979
+ if (instance.props.followCursor && !wasFocusEvent) {
32980
+ if (isUnmounted) {
32981
+ onMouseMove(mouseCoords);
32982
+ isUnmounted = false;
32983
+ }
32984
+
32985
+ if (!getIsInitialBehavior()) {
32986
+ addListener();
32987
+ }
32988
+ }
32989
+ },
32990
+ onTrigger: function onTrigger(_, event) {
32991
+ if (isMouseEvent$1(event)) {
32992
+ mouseCoords = {
32993
+ clientX: event.clientX,
32994
+ clientY: event.clientY
32995
+ };
32996
+ }
32997
+
32998
+ wasFocusEvent = event.type === 'focus';
32999
+ },
33000
+ onHidden: function onHidden() {
33001
+ if (instance.props.followCursor) {
33002
+ unsetGetReferenceClientRect();
33003
+ removeListener();
33004
+ isUnmounted = true;
33005
+ }
33006
+ }
33007
+ };
33008
+ }
33009
+ };
33010
+
32833
33011
  tippy.setDefaultProps({
32834
33012
  render: render
32835
33013
  });
32836
33014
 
32837
- var css_248z$5 = ".tippy-box[data-animation=fade][data-state=hidden]{opacity:0}[data-tippy-root]{max-width:calc(100vw - 10px)}.tippy-box{position:relative;background-color:#333;color:#fff;border-radius:4px;font-size:14px;line-height:1.4;white-space:normal;outline:0;transition-property:transform,visibility,opacity}.tippy-box[data-placement^=top]>.tippy-arrow{bottom:0}.tippy-box[data-placement^=top]>.tippy-arrow:before{bottom:-7px;left:0;border-width:8px 8px 0;border-top-color:initial;transform-origin:center top}.tippy-box[data-placement^=bottom]>.tippy-arrow{top:0}.tippy-box[data-placement^=bottom]>.tippy-arrow:before{top:-7px;left:0;border-width:0 8px 8px;border-bottom-color:initial;transform-origin:center bottom}.tippy-box[data-placement^=left]>.tippy-arrow{right:0}.tippy-box[data-placement^=left]>.tippy-arrow:before{border-width:8px 0 8px 8px;border-left-color:initial;right:-7px;transform-origin:center left}.tippy-box[data-placement^=right]>.tippy-arrow{left:0}.tippy-box[data-placement^=right]>.tippy-arrow:before{left:-7px;border-width:8px 8px 8px 0;border-right-color:initial;transform-origin:center right}.tippy-box[data-inertia][data-state=visible]{transition-timing-function:cubic-bezier(.54,1.5,.38,1.11)}.tippy-arrow{width:16px;height:16px;color:#333}.tippy-arrow:before{content:\"\";position:absolute;border-color:transparent;border-style:solid}.tippy-content{position:relative;padding:5px 9px;z-index:1}";
33015
+ var css_248z$5 = ".tippy-box{border:1px transparent}.tippy-box[data-placement^=top]>.tippy-arrow:after{border-top-color:inherit;border-width:8px 8px 0;bottom:-8px;left:0}.tippy-box[data-placement^=bottom]>.tippy-arrow:after{border-bottom-color:inherit;border-width:0 8px 8px;top:-8px;left:0}.tippy-box[data-placement^=left]>.tippy-arrow:after{border-left-color:inherit;border-width:8px 0 8px 8px;right:-8px;top:0}.tippy-box[data-placement^=right]>.tippy-arrow:after{border-width:8px 8px 8px 0;left:-8px;top:0;border-right-color:inherit}.tippy-box[data-placement^=top]>.tippy-svg-arrow>svg:first-child:not(:last-child){top:17px}.tippy-box[data-placement^=bottom]>.tippy-svg-arrow>svg:first-child:not(:last-child){bottom:17px}.tippy-box[data-placement^=left]>.tippy-svg-arrow>svg:first-child:not(:last-child){left:12px}.tippy-box[data-placement^=right]>.tippy-svg-arrow>svg:first-child:not(:last-child){right:12px}.tippy-arrow{border-color:inherit}.tippy-arrow:after{content:\"\";z-index:-1;position:absolute;border-color:transparent;border-style:solid}";
32838
33016
  styleInject(css_248z$5);
32839
33017
 
32840
- var css_248z$4 = ".tippy-box{border:1px transparent}.tippy-box[data-placement^=top]>.tippy-arrow:after{border-top-color:inherit;border-width:8px 8px 0;bottom:-8px;left:0}.tippy-box[data-placement^=bottom]>.tippy-arrow:after{border-bottom-color:inherit;border-width:0 8px 8px;top:-8px;left:0}.tippy-box[data-placement^=left]>.tippy-arrow:after{border-left-color:inherit;border-width:8px 0 8px 8px;right:-8px;top:0}.tippy-box[data-placement^=right]>.tippy-arrow:after{border-width:8px 8px 8px 0;left:-8px;top:0;border-right-color:inherit}.tippy-box[data-placement^=top]>.tippy-svg-arrow>svg:first-child:not(:last-child){top:17px}.tippy-box[data-placement^=bottom]>.tippy-svg-arrow>svg:first-child:not(:last-child){bottom:17px}.tippy-box[data-placement^=left]>.tippy-svg-arrow>svg:first-child:not(:last-child){left:12px}.tippy-box[data-placement^=right]>.tippy-svg-arrow>svg:first-child:not(:last-child){right:12px}.tippy-arrow{border-color:inherit}.tippy-arrow:after{content:\"\";z-index:-1;position:absolute;border-color:transparent;border-style:solid}";
33018
+ var css_248z$4 = ".tippy-box[data-animation=fade][data-state=hidden]{opacity:0}[data-tippy-root]{max-width:calc(100vw - 10px)}.tippy-box{position:relative;background-color:#333;color:#fff;border-radius:4px;font-size:14px;line-height:1.4;white-space:normal;outline:0;transition-property:transform,visibility,opacity}.tippy-box[data-placement^=top]>.tippy-arrow{bottom:0}.tippy-box[data-placement^=top]>.tippy-arrow:before{bottom:-7px;left:0;border-width:8px 8px 0;border-top-color:initial;transform-origin:center top}.tippy-box[data-placement^=bottom]>.tippy-arrow{top:0}.tippy-box[data-placement^=bottom]>.tippy-arrow:before{top:-7px;left:0;border-width:0 8px 8px;border-bottom-color:initial;transform-origin:center bottom}.tippy-box[data-placement^=left]>.tippy-arrow{right:0}.tippy-box[data-placement^=left]>.tippy-arrow:before{border-width:8px 0 8px 8px;border-left-color:initial;right:-7px;transform-origin:center left}.tippy-box[data-placement^=right]>.tippy-arrow{left:0}.tippy-box[data-placement^=right]>.tippy-arrow:before{left:-7px;border-width:8px 8px 8px 0;border-right-color:initial;transform-origin:center right}.tippy-box[data-inertia][data-state=visible]{transition-timing-function:cubic-bezier(.54,1.5,.38,1.11)}.tippy-arrow{width:16px;height:16px;color:#333}.tippy-arrow:before{content:\"\";position:absolute;border-color:transparent;border-style:solid}.tippy-content{position:relative;padding:5px 9px;z-index:1}";
32841
33019
  styleInject(css_248z$4);
32842
33020
 
32843
33021
  var id = 0;
32844
33022
  var getKey = function () { return id++; };
32845
33023
  var LuiTooltip = function (props) {
32846
- var children = props.children, message = props.message, placement = props.placement, trigger = props.trigger, _a = props.animation, animation = _a === void 0 ? true : _a;
33024
+ var children = props.children, message = props.message, placement = props.placement, trigger = props.trigger, _a = props.animation, animation = _a === void 0 ? true : _a, _b = props.followCursor, followCursor$1 = _b === void 0 ? false : _b, _c = props.mode, mode = _c === void 0 ? 'default' : _c;
32847
33025
  var id = "LuiToolTip_".concat(React.useMemo(getKey, []));
32848
33026
  if (typeof message !== 'string') {
32849
33027
  throw new Error('LuiTooltip message must be a string!');
@@ -32851,18 +33029,20 @@ var LuiTooltip = function (props) {
32851
33029
  React.useEffect(function () {
32852
33030
  tippy("#".concat(id), {
32853
33031
  content: message,
32854
- arrow: true,
33032
+ arrow: false,
32855
33033
  trigger: trigger,
32856
- theme: 'LUI',
33034
+ theme: mode,
32857
33035
  placement: placement,
32858
- offset: [0, 24],
32859
- animation: animation
33036
+ offset: [0, 18],
33037
+ animation: animation,
33038
+ followCursor: followCursor$1,
33039
+ plugins: [followCursor]
32860
33040
  });
32861
33041
  return function () {
32862
33042
  var _a, _b;
32863
33043
  (_b = (_a = document.getElementById(id)) === null || _a === void 0 ? void 0 : _a._tippy) === null || _b === void 0 ? void 0 : _b.destroy();
32864
33044
  };
32865
- }, [id, message, placement, trigger, animation]);
33045
+ }, [id, message, placement, trigger, animation, followCursor$1]);
32866
33046
  return React__default["default"].createElement("span", { id: id }, children);
32867
33047
  };
32868
33048
 
@@ -32899,18 +33079,18 @@ var LuiBadge = function (props) { return (React__default["default"].createElemen
32899
33079
  var LuiSidePanelContext = React__default["default"].createContext({ setProps: function () { return undefined; } });
32900
33080
  /* eslint-disable react/prop-types */
32901
33081
  var LuiSidePanel = function (_a) {
32902
- var children = _a.children, onClose = _a.onClose, width = _a.width, top = _a.top;
33082
+ var children = _a.children, onClose = _a.onClose, width = _a.width, top = _a.top, closeBtnTitleAttr = _a.closeBtnTitleAttr;
32903
33083
  var setProps = React__default["default"].useContext(LuiSidePanelContext).setProps;
32904
33084
  React__default["default"].useEffect(function () {
32905
- setProps({ children: children, onClose: onClose, width: width, top: top });
33085
+ setProps({ children: children, onClose: onClose, width: width, top: top, closeBtnTitleAttr: closeBtnTitleAttr });
32906
33086
  return function () {
32907
33087
  setProps(undefined);
32908
33088
  };
32909
- }, [setProps, children, onClose, width, top]);
33089
+ }, [setProps, children, onClose, width, top, closeBtnTitleAttr]);
32910
33090
  return React__default["default"].createElement(React__default["default"].Fragment, null);
32911
33091
  };
32912
33092
  var LuiSidePanelContainer = function (props) {
32913
- var _a = props !== null && props !== void 0 ? props : {}, children = _a.children, onClose = _a.onClose, _b = _a.width, width = _b === void 0 ? '50%' : _b, _c = _a.top, top = _c === void 0 ? 60 : _c;
33093
+ var _a = props !== null && props !== void 0 ? props : {}, children = _a.children, onClose = _a.onClose, _b = _a.width, width = _b === void 0 ? '50%' : _b, _c = _a.top, top = _c === void 0 ? 60 : _c, _d = _a.closeBtnTitleAttr, closeBtnTitleAttr = _d === void 0 ? 'Close panel' : _d;
32914
33094
  return (React__default["default"].createElement("section", { style: {
32915
33095
  position: 'fixed',
32916
33096
  right: 0,
@@ -32923,7 +33103,7 @@ var LuiSidePanelContainer = function (props) {
32923
33103
  padding: 0,
32924
33104
  zIndex: 3
32925
33105
  } },
32926
- children && (React__default["default"].createElement("button", { type: "button", "data-testid": "close", onClick: onClose, style: {
33106
+ children && (React__default["default"].createElement("button", { type: "button", "data-testid": "close", title: closeBtnTitleAttr, onClick: onClose, style: {
32927
33107
  color: '#5e5e61',
32928
33108
  position: 'absolute',
32929
33109
  right: 15,