@teamturing/react-kit 2.45.4 → 2.46.1

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.
@@ -11,13 +11,15 @@ const Avatar = ({
11
11
  src,
12
12
  alt = '',
13
13
  size = 'm',
14
- sx
14
+ sx,
15
+ ...props
15
16
  }, ref) => /*#__PURE__*/jsxRuntimeExports.jsx(BaseAvatar, {
16
17
  ref: ref,
17
18
  src: src,
18
19
  alt: alt,
19
20
  sx: sx,
20
- size: size
21
+ size: size,
22
+ ...props
21
23
  });
22
24
  const BaseAvatar = styled(Image)`
23
25
  border-radius: ${({
@@ -61,6 +63,7 @@ const BaseAvatar = styled(Image)`
61
63
  }
62
64
  }
63
65
  })}
66
+
64
67
  ${sx}
65
68
  `;
66
69
  var index = /*#__PURE__*/forwardRef(Avatar);
@@ -29,9 +29,6 @@ const BreadcrumbsItem = ({
29
29
  return isOverflow ? /*#__PURE__*/jsxRuntimeExports.jsx(Tooltip, {
30
30
  text: text,
31
31
  direction: 'bottom-center',
32
- sx: {
33
- display: 'inline-flex'
34
- },
35
32
  children: baseBreadCrumbsItem
36
33
  }) : baseBreadCrumbsItem;
37
34
  };
@@ -1,4 +1,4 @@
1
- import { useFloating } from '../../node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.js';
1
+ import { useFloating } from '../../node_modules/@floating-ui/react/dist/floating-ui.react.js';
2
2
  import { isFunction } from '../../packages/utils/esm/isFunction.js';
3
3
  import { Children, cloneElement } from 'react';
4
4
  import { useTheme } from 'styled-components';
@@ -8,7 +8,7 @@ import useFocusZone from '../../hook/useFocusZone.js';
8
8
  import useToggleState from '../../hook/useToggleState.js';
9
9
  import { j as jsxRuntimeExports } from '../../node_modules/react/jsx-runtime.js';
10
10
  import { autoUpdate } from '../../node_modules/@floating-ui/dom/dist/floating-ui.dom.js';
11
- import { offset, flip, shift } from '../../node_modules/@floating-ui/core/dist/floating-ui.core.js';
11
+ import { offset, flip, shift } from '../../node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.js';
12
12
 
13
13
  const OverlayPopper = ({
14
14
  children: propChildren,
@@ -0,0 +1,125 @@
1
+ import { useMergeRefs, FloatingPortal, FloatingArrow } from '../../node_modules/@floating-ui/react/dist/floating-ui.react.js';
2
+ import { forcePixelValue } from '../../packages/utils/esm/forcePixelValue.js';
3
+ import { forwardRef, isValidElement, cloneElement } from 'react';
4
+ import styled, { keyframes, useTheme } from 'styled-components';
5
+ import { sx } from '../../utils/styled-system/index.js';
6
+ import { useTooltip } from './useTooltip.js';
7
+ import { TooltipContext, useTooltipContext } from './useTooltipContext.js';
8
+ import { j as jsxRuntimeExports } from '../../node_modules/react/jsx-runtime.js';
9
+
10
+ function BaseTooltip({
11
+ children,
12
+ ...options
13
+ }) {
14
+ const tooltip = useTooltip(options);
15
+ return /*#__PURE__*/jsxRuntimeExports.jsx(TooltipContext.Provider, {
16
+ value: tooltip,
17
+ children: children
18
+ });
19
+ }
20
+ const BaseTooltipTrigger = /*#__PURE__*/forwardRef(function TooltipTrigger({
21
+ children,
22
+ ...props
23
+ }, propRef) {
24
+ const context = useTooltipContext();
25
+ const childrenRef = children.ref;
26
+ const ref = useMergeRefs([context.refs.setReference, propRef, childrenRef]);
27
+ if ( /*#__PURE__*/isValidElement(children)) {
28
+ return /*#__PURE__*/cloneElement(children, context.getReferenceProps({
29
+ ref,
30
+ ...props,
31
+ ...children.props,
32
+ 'data-state': context.open ? 'open' : 'closed'
33
+ }));
34
+ }
35
+ return /*#__PURE__*/jsxRuntimeExports.jsx("button", {
36
+ ref: ref,
37
+ "data-state": context.open ? 'open' : 'closed',
38
+ ...context.getReferenceProps(props),
39
+ children: children
40
+ });
41
+ });
42
+ const BaseTooltipContent = /*#__PURE__*/forwardRef(function TooltipContent({
43
+ style,
44
+ ...props
45
+ }, propRef) {
46
+ const theme = useTheme();
47
+ const context = useTooltipContext();
48
+ const ref = useMergeRefs([context.refs.setFloating, propRef]);
49
+ if (!context.open) return null;
50
+ return /*#__PURE__*/jsxRuntimeExports.jsx(FloatingPortal, {
51
+ children: /*#__PURE__*/jsxRuntimeExports.jsxs(StyledBaseTooltipContent, {
52
+ ref: ref,
53
+ style: {
54
+ ...context.floatingStyles,
55
+ ...style
56
+ },
57
+ ...context.getFloatingProps(props),
58
+ children: [props.children, /*#__PURE__*/jsxRuntimeExports.jsx(FloatingArrow, {
59
+ ref: context.arrowRef,
60
+ context: context,
61
+ width: 10,
62
+ height: 6,
63
+ fill: theme.colors['bg/neutral/bolder'],
64
+ stroke: theme.colors['bg/neutral/bolder']
65
+ })]
66
+ })
67
+ });
68
+ });
69
+ const tooltipAppear = keyframes`
70
+ from {
71
+ opacity: 0;
72
+ }
73
+
74
+ to {
75
+ opacity: 1;
76
+ }
77
+ `;
78
+ const StyledBaseTooltipContent = styled.div`
79
+ z-index: 99999;
80
+ background-color: ${({
81
+ theme
82
+ }) => theme.colors['bg/neutral/bolder']};
83
+ border-radius: ${({
84
+ theme
85
+ }) => forcePixelValue(theme.radii.xs)};
86
+ padding: ${({
87
+ theme
88
+ }) => `${forcePixelValue(theme.space[2])} ${forcePixelValue(theme.space[3])}`};
89
+ font-size: ${({
90
+ theme
91
+ }) => forcePixelValue(theme.fontSizes.xxs)};
92
+ font-weight: ${({
93
+ theme
94
+ }) => theme.fontWeights.medium};
95
+ line-height: ${({
96
+ theme
97
+ }) => theme.lineHeights[2]};
98
+ -webkit-font-smoothing: subpixel-antialiased;
99
+ color: ${({
100
+ theme
101
+ }) => theme.colors['text/inverse']};
102
+ text-align: center;
103
+ text-decoration: none;
104
+ text-shadow: none;
105
+ text-transform: none;
106
+ letter-spacing: normal;
107
+ word-wrap: break-word;
108
+ white-space: pre;
109
+ pointer-events: none;
110
+
111
+ width: max-content;
112
+ max-width: ${forcePixelValue(240)};
113
+ word-wrap: break-word;
114
+ white-space: pre-line;
115
+ border-collapse: separate;
116
+
117
+ animation-name: ${tooltipAppear};
118
+ animation-duration: 100ms;
119
+ animation-fill-mode: forwards;
120
+ animation-timing-function: ease-in;
121
+
122
+ ${sx}
123
+ `;
124
+
125
+ export { BaseTooltip, BaseTooltipContent, BaseTooltipTrigger };
@@ -1,287 +1,29 @@
1
- import { forcePixelValue } from '../../packages/utils/esm/forcePixelValue.js';
2
- import { forwardRef } from 'react';
3
- import styled, { keyframes } from 'styled-components';
4
- import '../../node_modules/styled-system/dist/index.esm.js';
5
- import { sx } from '../../utils/styled-system/index.js';
1
+ import { BaseTooltip, BaseTooltipTrigger, BaseTooltipContent } from './BaseTooltip.js';
6
2
  import { j as jsxRuntimeExports } from '../../node_modules/react/jsx-runtime.js';
7
- import { variant } from '../../node_modules/@styled-system/variant/dist/index.esm.js';
8
3
 
9
4
  const Tooltip = ({
10
5
  children,
11
6
  direction = 'top-center',
12
- text,
13
- disabled,
14
- className: propClassName,
15
- sx
16
- }, ref) => {
17
- const className = [propClassName, `tooltip-direction-${direction}`].join(' ');
18
- return /*#__PURE__*/jsxRuntimeExports.jsx(BaseTooltip, {
19
- ref: ref,
20
- role: 'tooltip',
21
- "aria-label": text,
22
- disabled: disabled,
23
- className: className,
24
- sx: sx,
25
- children: children
7
+ text
8
+ }) => {
9
+ const directionToPlacement = {
10
+ 'top-center': 'top',
11
+ 'top-right': 'top-start',
12
+ 'right': 'right',
13
+ 'bottom-right': 'bottom-start',
14
+ 'bottom-center': 'bottom',
15
+ 'bottom-left': 'bottom-end',
16
+ 'left': 'left',
17
+ 'top-left': 'top-end'
18
+ }[direction];
19
+ return /*#__PURE__*/jsxRuntimeExports.jsxs(BaseTooltip, {
20
+ placement: directionToPlacement,
21
+ children: [/*#__PURE__*/jsxRuntimeExports.jsx(BaseTooltipTrigger, {
22
+ children: children
23
+ }), /*#__PURE__*/jsxRuntimeExports.jsx(BaseTooltipContent, {
24
+ children: text
25
+ })]
26
26
  });
27
27
  };
28
- const tooltipAppear = keyframes`
29
- from {
30
- opacity: 0;
31
- }
32
28
 
33
- to {
34
- opacity: 1;
35
- }
36
- `;
37
- const BaseTooltip = styled.span`
38
- display: inline-block;
39
- position: relative;
40
-
41
- &::before {
42
- position: absolute;
43
- z-index: 1000001;
44
- display: none;
45
- width: 0px;
46
- height: 0px;
47
- color: ${({
48
- theme
49
- }) => theme.colors['bg/neutral/bolder']};
50
- pointer-events: none;
51
- content: '';
52
- border: 6px solid transparent;
53
- opacity: 0;
54
- }
55
-
56
- &::after {
57
- position: absolute;
58
- z-index: 1000000;
59
- display: none;
60
- padding: ${({
61
- theme
62
- }) => `${forcePixelValue(theme.space[2])} ${forcePixelValue(theme.space[3])}`};
63
- font-size: ${({
64
- theme
65
- }) => forcePixelValue(theme.fontSizes.xxs)};
66
- font-weight: ${({
67
- theme
68
- }) => theme.fontWeights.medium};
69
- line-height: ${({
70
- theme
71
- }) => theme.lineHeights[2]};
72
- -webkit-font-smoothing: subpixel-antialiased;
73
- color: ${({
74
- theme
75
- }) => theme.colors['text/inverse']};
76
- text-align: center;
77
- text-decoration: none;
78
- text-shadow: none;
79
- text-transform: none;
80
- letter-spacing: normal;
81
- word-wrap: break-word;
82
- white-space: pre;
83
- pointer-events: none;
84
- content: attr(aria-label);
85
- background: ${({
86
- theme
87
- }) => theme.colors['bg/neutral/bolder']};
88
- border-radius: ${({
89
- theme
90
- }) => forcePixelValue(theme.radii.xs)};
91
- box-shadow: ${({
92
- theme
93
- }) => theme.shadows['shadow/overlay']};
94
- opacity: 0;
95
- }
96
-
97
- &:hover,
98
- &:active,
99
- &:focus {
100
- &::before,
101
- &::after {
102
- display: table-cell;
103
- text-decoration: none;
104
- animation-name: ${tooltipAppear};
105
- animation-duration: 100ms;
106
- animation-fill-mode: forwards;
107
- animation-timing-function: ease-in;
108
- animation-delay: 300ms;
109
- }
110
- }
111
-
112
- &.tooltip-direction-bottom-center,
113
- &.tooltip-direction-bottom-right,
114
- &.tooltip-direction-bottom-left {
115
- &::after {
116
- top: 100%;
117
- right: 50%;
118
- margin-top: ${({
119
- theme
120
- }) => forcePixelValue(theme.space[2])};
121
- }
122
-
123
- &::before {
124
- top: auto;
125
- right: 50%;
126
- bottom: ${({
127
- theme
128
- }) => forcePixelValue(theme.space[-2] + theme.space['-0.25'])};
129
- margin-right: -6px;
130
- border-bottom-color: ${({
131
- theme
132
- }) => theme.colors['bg/neutral/bolder']};
133
- }
134
- }
135
-
136
- &.tooltip-direction-bottom-right {
137
- &::after {
138
- right: auto;
139
- left: 50%;
140
- margin-left: -${({
141
- theme
142
- }) => forcePixelValue(theme.space[4])};
143
- }
144
- }
145
-
146
- &.tooltip-direction-bottom-left::after {
147
- margin-right: -${({
148
- theme
149
- }) => forcePixelValue(theme.space[4])};
150
- }
151
-
152
- // Tooltips above the object
153
- &.tooltip-direction-top-center,
154
- &.tooltip-direction-top-right,
155
- &.tooltip-direction-top-left {
156
- &::after {
157
- right: 50%;
158
- bottom: 100%;
159
- margin-bottom: ${({
160
- theme
161
- }) => forcePixelValue(theme.space[2])};
162
- }
163
-
164
- &::before {
165
- top: ${({
166
- theme
167
- }) => forcePixelValue(theme.space[-2] + theme.space['-0.25'])};
168
- right: 50%;
169
- bottom: auto;
170
- margin-right: -6px;
171
- border-top-color: ${({
172
- theme
173
- }) => theme.colors['bg/neutral/bolder']};
174
- }
175
- }
176
-
177
- &.tooltip-direction-top-right {
178
- &::after {
179
- right: auto;
180
- left: 50%;
181
- margin-left: -${({
182
- theme
183
- }) => forcePixelValue(theme.space[4])};
184
- }
185
- }
186
-
187
- &.tooltip-direction-top-left::after {
188
- margin-right: -${({
189
- theme
190
- }) => forcePixelValue(theme.space[4])};
191
- }
192
-
193
- &.tooltip-direction-top-center::after,
194
- &.tooltip-direction-bottom-center::after {
195
- transform: translateX(50%);
196
- }
197
-
198
- &.tooltip-direction-left {
199
- &::after {
200
- right: 100%;
201
- bottom: 50%;
202
- margin-right: ${({
203
- theme
204
- }) => forcePixelValue(theme.space[2])};
205
- transform: translateY(50%);
206
- }
207
-
208
- &::before {
209
- top: 50%;
210
- bottom: 50%;
211
- left: ${({
212
- theme
213
- }) => forcePixelValue(theme.space[-2] + theme.space['-0.25'])};
214
- margin-top: -6px;
215
- border-left-color: ${({
216
- theme
217
- }) => theme.colors['bg/neutral/bolder']};
218
- }
219
- }
220
-
221
- &.tooltip-direction-right {
222
- &::after {
223
- bottom: 50%;
224
- left: 100%;
225
- margin-left: ${({
226
- theme
227
- }) => forcePixelValue(theme.space[2])};
228
- transform: translateY(50%);
229
- }
230
-
231
- &::before {
232
- top: 50%;
233
- right: ${({
234
- theme
235
- }) => forcePixelValue(theme.space[-2] + theme.space['-0.25'])};
236
- bottom: 50%;
237
- margin-top: -6px;
238
- border-right-color: ${({
239
- theme
240
- }) => theme.colors['bg/neutral/bolder']};
241
- }
242
- }
243
-
244
- &::after {
245
- width: max-content;
246
- max-width: 240px;
247
- word-wrap: break-word;
248
- white-space: pre-line;
249
- border-collapse: separate;
250
- }
251
-
252
- &.tooltip-direction-bottom-center::after,
253
- &.tooltip-direction-top-center::after {
254
- right: auto;
255
- left: 50%;
256
- transform: translateX(-50%);
257
- }
258
-
259
- &.tooltip-direction-left::after,
260
- &.tooltip-direction-right::after {
261
- right: 100%;
262
- }
263
-
264
- ${sx}
265
- ${variant({
266
- prop: 'disabled',
267
- variants: {
268
- true: {
269
- '&:hover , &:active, &:focus': {
270
- '&::before, &::after': {
271
- display: 'none'
272
- }
273
- }
274
- },
275
- false: {
276
- '&:hover , &:active, &:focus': {
277
- '&::before, &::after': {
278
- display: 'table-cell'
279
- }
280
- }
281
- }
282
- }
283
- })}
284
- `;
285
- var Tooltip$1 = /*#__PURE__*/forwardRef(Tooltip);
286
-
287
- export { Tooltip$1 as default };
29
+ export { Tooltip as default };
@@ -0,0 +1,56 @@
1
+ import { useFloating, useHover, useFocus, useDismiss, useRole, useInteractions } from '../../node_modules/@floating-ui/react/dist/floating-ui.react.js';
2
+ import { useState, useRef, useMemo } from 'react';
3
+ import { useTheme } from 'styled-components';
4
+ import { autoUpdate } from '../../node_modules/@floating-ui/dom/dist/floating-ui.dom.js';
5
+ import { offset, flip, shift, arrow } from '../../node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.js';
6
+
7
+ function useTooltip({
8
+ initialOpen = false,
9
+ placement = 'top',
10
+ open: controlledOpen,
11
+ onOpenChange: setControlledOpen
12
+ } = {}) {
13
+ const theme = useTheme();
14
+ const [uncontrolledOpen, setUncontrolledOpen] = useState(initialOpen);
15
+ const open = controlledOpen ?? uncontrolledOpen;
16
+ const setOpen = setControlledOpen ?? setUncontrolledOpen;
17
+ const arrowRef = useRef(null);
18
+ const data = useFloating({
19
+ placement,
20
+ open,
21
+ onOpenChange: setOpen,
22
+ whileElementsMounted: autoUpdate,
23
+ middleware: [offset(theme.space[2]), flip({
24
+ crossAxis: placement.includes('-'),
25
+ fallbackAxisSideDirection: 'start',
26
+ padding: theme.space[2]
27
+ }), shift({
28
+ padding: theme.space[2]
29
+ }), arrow({
30
+ element: arrowRef
31
+ })]
32
+ });
33
+ const context = data.context;
34
+ const hover = useHover(context, {
35
+ move: false,
36
+ restMs: 300,
37
+ enabled: controlledOpen == null
38
+ });
39
+ const focus = useFocus(context, {
40
+ enabled: controlledOpen == null
41
+ });
42
+ const dismiss = useDismiss(context);
43
+ const role = useRole(context, {
44
+ role: 'tooltip'
45
+ });
46
+ const interactions = useInteractions([hover, focus, dismiss, role]);
47
+ return useMemo(() => ({
48
+ open,
49
+ setOpen,
50
+ ...interactions,
51
+ ...data,
52
+ arrowRef
53
+ }), [open, setOpen, interactions, data, arrowRef]);
54
+ }
55
+
56
+ export { useTooltip };
@@ -0,0 +1,12 @@
1
+ import { createContext, useContext } from 'react';
2
+
3
+ const TooltipContext = /*#__PURE__*/createContext(null);
4
+ const useTooltipContext = () => {
5
+ const context = useContext(TooltipContext);
6
+ if (context == null) {
7
+ throw new Error('Tooltip components must be wrapped in <Tooltip />');
8
+ }
9
+ return context;
10
+ };
11
+
12
+ export { TooltipContext, useTooltipContext };