@ultraviolet/ui 1.21.0 → 1.22.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/dist/index.d.ts CHANGED
@@ -1153,12 +1153,14 @@ type BannerProps = {
1153
1153
  linkText?: string;
1154
1154
  linkHref?: string;
1155
1155
  image?: ReactNode;
1156
+ closable?: boolean;
1156
1157
  className?: string;
1158
+ ['data-testid']?: string;
1157
1159
  };
1158
1160
  /**
1159
1161
  * Banner component is used to display an informative message to the user with style.
1160
1162
  */
1161
- declare const Banner: ({ variant, size, title, children, direction, onClose, buttonText, onClickButton, linkText, linkHref, image, className, }: BannerProps) => _emotion_react_jsx_runtime.JSX.Element | null;
1163
+ declare const Banner: ({ variant, size, title, children, direction, onClose, buttonText, onClickButton, linkText, linkHref, image, className, closable, "data-testid": dataTestId, }: BannerProps) => _emotion_react_jsx_runtime.JSX.Element | null;
1162
1164
 
1163
1165
  type BarChartToolTipProps = {
1164
1166
  color: string;
@@ -2842,11 +2844,14 @@ type DisclosureProps = {
2842
2844
  type DisclosureElement = ((disclosure: DisclosureProps) => ReactElement<ButtonHTMLAttributes<HTMLButtonElement>>) | (ReactElement<ButtonHTMLAttributes<HTMLButtonElement>> & {
2843
2845
  ref?: Ref<HTMLButtonElement>;
2844
2846
  });
2847
+ type ChildMenuProps = {
2848
+ toggle: () => void;
2849
+ };
2845
2850
  type MenuProps = {
2846
2851
  id?: string;
2847
2852
  ariaLabel?: string;
2848
2853
  placement?: ComponentProps<typeof Popup>['placement'];
2849
- children?: ReactNode;
2854
+ children?: ReactNode | (({ toggle }: ChildMenuProps) => ReactNode);
2850
2855
  className?: string;
2851
2856
  disclosure: DisclosureElement;
2852
2857
  hasArrow?: boolean;
@@ -40,7 +40,7 @@ const styles = _ref => {
40
40
  return null;
41
41
  };
42
42
  const Container = /*#__PURE__*/_styled('div', {
43
- shouldForwardProp: prop => !['variant', 'size'].includes(prop),
43
+ shouldForwardProp: prop => !['variant', 'size', 'padding'].includes(prop),
44
44
  target: "e1kdwp5x1"
45
45
  })("padding:", _ref2 => {
46
46
  let {
@@ -100,7 +100,9 @@ const Banner = _ref8 => {
100
100
  linkText,
101
101
  linkHref,
102
102
  image,
103
- className
103
+ className,
104
+ closable = true,
105
+ 'data-testid': dataTestId
104
106
  } = _ref8;
105
107
  const {
106
108
  theme
@@ -112,6 +114,7 @@ const Banner = _ref8 => {
112
114
  variant: variant,
113
115
  size: size,
114
116
  className: className,
117
+ "data-testid": dataTestId,
115
118
  children: [jsx(ImageStack, {
116
119
  size: size,
117
120
  justifyContent: "center",
@@ -165,7 +168,7 @@ const Banner = _ref8 => {
165
168
  children: linkText
166
169
  }) : null]
167
170
  })]
168
- }), jsx(Button, {
171
+ }), closable ? jsx(Button, {
169
172
  icon: "close",
170
173
  size: "small",
171
174
  name: "close",
@@ -175,7 +178,7 @@ const Banner = _ref8 => {
175
178
  setOpened(false);
176
179
  onClose?.();
177
180
  }
178
- })]
181
+ }) : null]
179
182
  });
180
183
  };
181
184
 
@@ -70,12 +70,12 @@ const FwdMenu = /*#__PURE__*/forwardRef((_ref7, ref) => {
70
70
 
71
71
  // Focus the first item when the menu is opened
72
72
  if (!isVisible) {
73
- requestIdleCallback(() => {
73
+ setTimeout(() => {
74
74
  // We have to wait for the popup to be inserted in the DOM
75
75
  if (popupRef.current?.firstChild?.firstChild instanceof HTMLElement) {
76
76
  popupRef.current.firstChild.firstChild.focus();
77
77
  }
78
- });
78
+ }, 1);
79
79
  }
80
80
  };
81
81
  const onClose = () => {
@@ -109,7 +109,9 @@ const FwdMenu = /*#__PURE__*/forwardRef((_ref7, ref) => {
109
109
  "data-testid": dataTestId,
110
110
  className: className,
111
111
  role: "menu",
112
- children: children
112
+ children: typeof children === 'function' ? children({
113
+ toggle: toggleVisible
114
+ }) : children
113
115
  }),
114
116
  children: finalDisclosure
115
117
  });
@@ -13,7 +13,7 @@ const SIZES_WIDTH = {
13
13
  };
14
14
  const StyledPopup = /*#__PURE__*/_styled(Popup, {
15
15
  shouldForwardProp: prop => !['sentiment', 'size'].includes(prop),
16
- target: "ejpxv5a0"
16
+ target: "ejpxv5a1"
17
17
  })("padding:", _ref => {
18
18
  let {
19
19
  theme
@@ -55,18 +55,28 @@ const StyledPopup = /*#__PURE__*/_styled(Popup, {
55
55
  }
56
56
  `;
57
57
  }, ";");
58
- const ContentWrapper = _ref5 => {
58
+
59
+ // This is to avoid having text inherit color from popup (which is white on white background)
60
+ const StyledStack = /*#__PURE__*/_styled(Stack, {
61
+ target: "ejpxv5a0"
62
+ })("color:", _ref5 => {
63
+ let {
64
+ theme
65
+ } = _ref5;
66
+ return theme.colors.neutral.text;
67
+ }, ";");
68
+ const ContentWrapper = _ref6 => {
59
69
  let {
60
70
  title,
61
71
  onClose,
62
72
  children,
63
73
  sentiment
64
- } = _ref5;
74
+ } = _ref6;
65
75
  const buttonRef = useRef(null);
66
76
  useEffect(() => {
67
77
  buttonRef.current?.focus();
68
78
  }, []);
69
- return jsxs(Stack, {
79
+ return jsxs(StyledStack, {
70
80
  gap: 1,
71
81
  children: [jsxs(Stack, {
72
82
  direction: "row",
@@ -99,7 +109,7 @@ const ContentWrapper = _ref5 => {
99
109
  * Popover component is used to display additional information or actions on top of the main content of the page.
100
110
  * It is usually triggered by clicking on a button. It includes a title, a close button and a content area.
101
111
  */
102
- const Popover = /*#__PURE__*/forwardRef((_ref6, ref) => {
112
+ const Popover = /*#__PURE__*/forwardRef((_ref7, ref) => {
103
113
  let {
104
114
  visible = false,
105
115
  children,
@@ -111,7 +121,7 @@ const Popover = /*#__PURE__*/forwardRef((_ref6, ref) => {
111
121
  onClose,
112
122
  className,
113
123
  'data-testid': dataTestId
114
- } = _ref6;
124
+ } = _ref7;
115
125
  const innerRef = useRef(null);
116
126
  const [localVisible, setLocalVisible] = useState(visible);
117
127
 
@@ -267,7 +267,7 @@ const Popup = /*#__PURE__*/forwardRef((_ref13, ref) => {
267
267
  const handleClickOutside = event => {
268
268
  const tooltipCurrent = innerTooltipRef.current;
269
269
  const childrenCurrent = childrenRef.current;
270
- if (tooltipCurrent && hideOnClickOutside) {
270
+ if (tooltipCurrent && hideOnClickOutside && !event.defaultPrevented) {
271
271
  if (event.target && event.target !== tooltipCurrent && event.target !== childrenCurrent && !childrenCurrent?.contains(event.target) && !tooltipCurrent.contains(event.target)) {
272
272
  event.preventDefault();
273
273
  event.stopPropagation();
@@ -277,11 +277,11 @@ const Popup = /*#__PURE__*/forwardRef((_ref13, ref) => {
277
277
  };
278
278
  if (visibleInDom) {
279
279
  document.body.addEventListener('keyup', handleEscPress);
280
- document.body.addEventListener('mousedown', handleClickOutside);
280
+ document.body.addEventListener('click', handleClickOutside);
281
281
  }
282
282
  return () => {
283
283
  document.body.removeEventListener('keyup', handleEscPress);
284
- document.body.removeEventListener('mousedown', handleClickOutside);
284
+ document.body.removeEventListener('click', handleClickOutside);
285
285
  };
286
286
  }, [hideTooltip, visibleInDom, innerTooltipRef, childrenRef, hideOnClickOutside]);
287
287
 
@@ -322,6 +322,13 @@ const Popup = /*#__PURE__*/forwardRef((_ref13, ref) => {
322
322
  children: children
323
323
  });
324
324
  }
325
+
326
+ /**
327
+ * This event handle allow us to not bubble the event to document.body like this react-select works fine
328
+ */
329
+ const stopClickPropagation = event => {
330
+ event.nativeEvent.stopImmediatePropagation();
331
+ };
325
332
  return jsxs(Fragment, {
326
333
  children: [renderChildren(), visibleInDom ? /*#__PURE__*/createPortal(jsx(StyledTooltip, {
327
334
  ref: innerTooltipRef,
@@ -333,6 +340,7 @@ const Popup = /*#__PURE__*/forwardRef((_ref13, ref) => {
333
340
  reverseAnimation: reverseAnimation,
334
341
  "data-testid": dataTestId,
335
342
  "data-has-arrow": hasArrow,
343
+ onClick: stopClickPropagation,
336
344
  children: text
337
345
  }), document.body) : null]
338
346
  });
@@ -99,26 +99,31 @@ const TagInputContainer = /*#__PURE__*/_styled('div', {
99
99
  }, ";");
100
100
  const StyledInput = /*#__PURE__*/_styled("input", {
101
101
  target: "ea7vc6o0"
102
- })("font-size:16px;color:", _ref6 => {
102
+ })("display:flex;flex:1;font-size:", _ref6 => {
103
+ let {
104
+ theme
105
+ } = _ref6;
106
+ return theme.typography.body.fontSize;
107
+ }, ";color:", _ref7 => {
103
108
  let {
104
109
  theme: {
105
110
  colors
106
111
  }
107
- } = _ref6;
112
+ } = _ref7;
108
113
  return colors.neutral.text;
109
- }, ";border:none;outline:none;background-color:", _ref7 => {
114
+ }, ";border:none;outline:none;background-color:", _ref8 => {
110
115
  let {
111
116
  theme: {
112
117
  colors
113
118
  }
114
- } = _ref7;
119
+ } = _ref8;
115
120
  return colors.neutral.background;
116
- }, ";&::placeholder{color:", _ref8 => {
121
+ }, ";&::placeholder{color:", _ref9 => {
117
122
  let {
118
123
  theme: {
119
124
  colors
120
125
  }
121
- } = _ref8;
126
+ } = _ref9;
122
127
  return colors.neutral.textWeak;
123
128
  }, ";}");
124
129
  const convertTagArrayToTagStateArray = tags => (tags || [])?.map((tag, index) => typeof tag === 'object' ? {
@@ -132,7 +137,7 @@ const convertTagArrayToTagStateArray = tags => (tags || [])?.map((tag, index) =>
132
137
  * TagInput is a component that allows users to input tags.
133
138
  * @experimental This component is experimental and may be subject to breaking changes in the future.
134
139
  */
135
- const TagInput = _ref9 => {
140
+ const TagInput = _ref10 => {
136
141
  let {
137
142
  disabled = false,
138
143
  id,
@@ -145,7 +150,7 @@ const TagInput = _ref9 => {
145
150
  variant = 'base',
146
151
  className,
147
152
  'data-testid': dataTestId
148
- } = _ref9;
153
+ } = _ref10;
149
154
  const [tagInputState, setTagInput] = useState(convertTagArrayToTagStateArray(tags ?? []));
150
155
  const [input, setInput] = useState('');
151
156
  const [status, setStatus] = useState({});
@@ -189,10 +194,10 @@ const TagInput = _ref9 => {
189
194
  setStatus({
190
195
  [tagIndex]: STATUS.LOADING
191
196
  });
192
- const findIndex = tagInputState.findIndex(_ref10 => {
197
+ const findIndex = tagInputState.findIndex(_ref11 => {
193
198
  let {
194
199
  index
195
- } = _ref10;
200
+ } = _ref11;
196
201
  return index === tagIndex;
197
202
  });
198
203
  const newTagInput = [...tagInputState];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultraviolet/ui",
3
- "version": "1.21.0",
3
+ "version": "1.22.0",
4
4
  "description": "Ultraviolet UI",
5
5
  "homepage": "https://github.com/scaleway/ultraviolet#readme",
6
6
  "repository": {
@@ -67,7 +67,7 @@
67
67
  "react-use-clipboard": "1.0.9",
68
68
  "reakit": "1.3.11",
69
69
  "@ultraviolet/themes": "1.3.0",
70
- "@ultraviolet/icons": "2.4.2"
70
+ "@ultraviolet/icons": "2.5.0"
71
71
  },
72
72
  "scripts": {
73
73
  "build": "rollup -c ../../rollup.config.mjs"