@lumx/react 2.2.12-alpha.2 → 2.2.14

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.
Files changed (37) hide show
  1. package/esm/_internal/Checkbox2.js +3 -1
  2. package/esm/_internal/Checkbox2.js.map +1 -1
  3. package/esm/_internal/CommentBlock.js +12 -5
  4. package/esm/_internal/CommentBlock.js.map +1 -1
  5. package/esm/_internal/Dropdown2.js +5 -2
  6. package/esm/_internal/Dropdown2.js.map +1 -1
  7. package/esm/_internal/List2.js +11 -2
  8. package/esm/_internal/List2.js.map +1 -1
  9. package/esm/_internal/Popover2.js +69 -4
  10. package/esm/_internal/Popover2.js.map +1 -1
  11. package/esm/_internal/RadioGroup.js +3 -1
  12. package/esm/_internal/RadioGroup.js.map +1 -1
  13. package/esm/_internal/Slides.js +1 -24
  14. package/esm/_internal/Slides.js.map +1 -1
  15. package/esm/_internal/Tooltip2.js +1 -3
  16. package/esm/_internal/Tooltip2.js.map +1 -1
  17. package/esm/_internal/comment-block.js +8 -0
  18. package/esm/_internal/comment-block.js.map +1 -1
  19. package/package.json +4 -4
  20. package/src/components/autocomplete/__snapshots__/Autocomplete.test.tsx.snap +4 -0
  21. package/src/components/autocomplete/__snapshots__/AutocompleteMultiple.test.tsx.snap +1 -0
  22. package/src/components/checkbox/Checkbox.tsx +4 -0
  23. package/src/components/comment-block/CommentBlock.stories.tsx +7 -4
  24. package/src/components/comment-block/CommentBlock.tsx +13 -3
  25. package/src/components/comment-block/__snapshots__/CommentBlock.test.tsx.snap +10 -5
  26. package/src/components/dialog/__snapshots__/Dialog.test.tsx.snap +1 -0
  27. package/src/components/dropdown/Dropdown.tsx +5 -0
  28. package/src/components/dropdown/__snapshots__/Dropdown.test.tsx.snap +1 -0
  29. package/src/components/list/List.tsx +12 -2
  30. package/src/components/list/__snapshots__/List.test.tsx.snap +5 -5
  31. package/src/components/popover/Popover.tsx +42 -2
  32. package/src/components/radio-button/RadioButton.tsx +4 -0
  33. package/src/components/select/__snapshots__/Select.test.tsx.snap +1 -0
  34. package/src/components/select/__snapshots__/SelectMultiple.test.tsx.snap +2 -0
  35. package/src/components/tooltip/useTooltipOpen.tsx +0 -1
  36. package/src/stories/generated/Toolbar/Demos.stories.tsx +1 -0
  37. package/types.d.ts +13 -1
@@ -10,18 +10,21 @@ export const WithHeaderActions = ({ theme }: any) => (
10
10
  <CommentBlock
11
11
  hasActions
12
12
  actions={[
13
- <Button key="button0" emphasis={Emphasis.low} size={Size.s} leftIcon={mdiHeart}>
13
+ <Button key="button0" theme={theme} emphasis={Emphasis.low} size={Size.s} leftIcon={mdiHeart}>
14
14
  24 likes
15
15
  </Button>,
16
- <Button key="button1" emphasis={Emphasis.low} size={Size.s} leftIcon={mdiReply}>
16
+ <Button key="button1" theme={theme} emphasis={Emphasis.low} size={Size.s} leftIcon={mdiReply}>
17
17
  Reply
18
18
  </Button>,
19
19
  ]}
20
20
  theme={theme}
21
21
  avatarProps={{ image: avatarImageKnob(), alt: 'Avatar' }}
22
- date="4 hours ago"
22
+ date="5 days"
23
+ fullDate="Monday, March 30, 2021 at 4:06 PM"
23
24
  name="Emmitt O. Lum"
24
25
  text="All the rumors have finally died down and many skeptics have tightened their lips, the iPod does support video format now on its fifth generation."
25
- headerActions={<IconButton label="Actions" icon={mdiDotsHorizontal} emphasis={Emphasis.low} size={Size.s} />}
26
+ headerActions={
27
+ <IconButton label="Actions" icon={mdiDotsHorizontal} theme={theme} emphasis={Emphasis.low} size={Size.s} />
28
+ }
26
29
  />
27
30
  );
@@ -2,7 +2,7 @@ import React, { Children, forwardRef, KeyboardEvent, KeyboardEventHandler, React
2
2
 
3
3
  import classNames from 'classnames';
4
4
 
5
- import { Avatar, Size, Theme } from '@lumx/react';
5
+ import { Avatar, Size, Theme, Tooltip } from '@lumx/react';
6
6
  import { Comp, GenericProps, getRootClassName, handleBasicClasses, ValueOf } from '@lumx/react/utils';
7
7
 
8
8
  import isFunction from 'lodash/isFunction';
@@ -27,8 +27,10 @@ export interface CommentBlockProps extends GenericProps {
27
27
  avatarProps: AvatarProps;
28
28
  /** Comment block replies. */
29
29
  children?: ReactNode;
30
- /** Comment date. */
30
+ /** Comment date with the minimal timestamp informations (xx minutes, x hours, yesterday, 6 days, Month Day, Month Day Year)*/
31
31
  date: string;
32
+ /** Comment date with the full timestamp informations (day, month, year, time) */
33
+ fullDate?: string;
32
34
  /** Whether the component has actions to display or not. */
33
35
  hasActions?: boolean;
34
36
  /** Action toolbar header content. */
@@ -85,6 +87,7 @@ export const CommentBlock: Comp<CommentBlockProps, HTMLDivElement> = forwardRef(
85
87
  children,
86
88
  className,
87
89
  date,
90
+ fullDate,
88
91
  hasActions,
89
92
  headerActions,
90
93
  isOpen,
@@ -146,11 +149,18 @@ export const CommentBlock: Comp<CommentBlockProps, HTMLDivElement> = forwardRef(
146
149
  >
147
150
  {name}
148
151
  </span>
149
- {date && <span className={`${CLASSNAME}__date`}>{date}</span>}
150
152
  {headerActions && <span className={`${CLASSNAME}__header-actions`}>{headerActions}</span>}
151
153
  </div>
152
154
 
153
155
  <div className={`${CLASSNAME}__text`}>{text}</div>
156
+ {date &&
157
+ (fullDate ? (
158
+ <Tooltip label={fullDate} placement="top">
159
+ <span className={`${CLASSNAME}__date`}>{date}</span>
160
+ </Tooltip>
161
+ ) : (
162
+ <span className={`${CLASSNAME}__date`}>{date}</span>
163
+ ))}
154
164
  </div>
155
165
  {hasActions && <div className={`${CLASSNAME}__actions`}>{actions}</div>}
156
166
  </div>
@@ -36,11 +36,6 @@ exports[`<CommentBlock> Snapshots and structure should render story 'WithHeaderA
36
36
  >
37
37
  Emmitt O. Lum
38
38
  </span>
39
- <span
40
- className="lumx-comment-block__date"
41
- >
42
- 4 hours ago
43
- </span>
44
39
  <span
45
40
  className="lumx-comment-block__header-actions"
46
41
  >
@@ -58,6 +53,16 @@ exports[`<CommentBlock> Snapshots and structure should render story 'WithHeaderA
58
53
  >
59
54
  All the rumors have finally died down and many skeptics have tightened their lips, the iPod does support video format now on its fifth generation.
60
55
  </div>
56
+ <Tooltip
57
+ label="Monday, March 30, 2021 at 4:06 PM"
58
+ placement="top"
59
+ >
60
+ <span
61
+ className="lumx-comment-block__date"
62
+ >
63
+ 5 days
64
+ </span>
65
+ </Tooltip>
61
66
  </div>
62
67
  <div
63
68
  className="lumx-comment-block__actions"
@@ -182,6 +182,7 @@ exports[`<Dialog> Snapshots and structure should render story DialogWithFocusabl
182
182
  >
183
183
  <List
184
184
  isClickable={true}
185
+ tabIndex={-1}
185
186
  >
186
187
  <ListItem
187
188
  isSelected={true}
@@ -58,6 +58,8 @@ export interface DropdownProps extends GenericProps {
58
58
  placement?: Placement;
59
59
  /** Whether the focus should be set on the list when the dropdown is open or not. */
60
60
  shouldFocusOnOpen?: boolean;
61
+ /** Whether the focus should go back on the anchor when dropdown closes and focus is within. */
62
+ focusAnchorOnClose?: boolean;
61
63
  /**
62
64
  * Z-axis position.
63
65
  * @see {@link PopoverProps#zIndex}
@@ -93,6 +95,7 @@ const DEFAULT_PROPS: Partial<DropdownProps> = {
93
95
  fitWithinViewportHeight: true,
94
96
  placement: Placement.BOTTOM_START,
95
97
  shouldFocusOnOpen: true,
98
+ focusAnchorOnClose: true,
96
99
  };
97
100
 
98
101
  /**
@@ -114,6 +117,7 @@ export const Dropdown: Comp<DropdownProps, HTMLDivElement> = forwardRef((props,
114
117
  fitWithinViewportHeight,
115
118
  isOpen,
116
119
  offset,
120
+ focusAnchorOnClose,
117
121
  onClose,
118
122
  onInfiniteScroll,
119
123
  placement,
@@ -147,6 +151,7 @@ export const Dropdown: Comp<DropdownProps, HTMLDivElement> = forwardRef((props,
147
151
  <Popover
148
152
  ref={ref}
149
153
  {...forwardedProps}
154
+ focusAnchorOnClose={focusAnchorOnClose}
150
155
  anchorRef={anchorRef}
151
156
  className={classNames(className, handleBasicClasses({ prefix: CLASSNAME }))}
152
157
  elevation={0 as any}
@@ -13,6 +13,7 @@ exports[`<Dropdown> Snapshots and structure should render correctly 1`] = `
13
13
  elevation={0}
14
14
  fitToAnchorWidth={true}
15
15
  fitWithinViewportHeight={true}
16
+ focusAnchorOnClose={true}
16
17
  focusElement={
17
18
  Object {
18
19
  "current": null,
@@ -21,6 +21,8 @@ export interface ListProps extends GenericProps {
21
21
  isClickable?: boolean;
22
22
  /** Item padding size. */
23
23
  itemPadding?: Extract<Size, 'big' | 'huge'>;
24
+ /** Tab index of the list. Default to -1 */
25
+ tabIndex?: number;
24
26
  /**
25
27
  * On list item selected callback.
26
28
  *
@@ -41,6 +43,13 @@ const COMPONENT_NAME = 'List';
41
43
  */
42
44
  const CLASSNAME = getRootClassName(COMPONENT_NAME);
43
45
 
46
+ /**
47
+ * Component default props.
48
+ */
49
+ const DEFAULT_PROPS: Partial<ListProps> = {
50
+ tabIndex: -1,
51
+ };
52
+
44
53
  /* eslint-disable jsx-a11y/no-noninteractive-tabindex */
45
54
  /**
46
55
  * List component.
@@ -50,7 +59,7 @@ const CLASSNAME = getRootClassName(COMPONENT_NAME);
50
59
  * @return React element.
51
60
  */
52
61
  const InternalList: Comp<ListProps, HTMLUListElement> = forwardRef((props, ref) => {
53
- const { children, className, isClickable, itemPadding, onListItemSelected, ...forwardedProps } = props;
62
+ const { children, className, isClickable, itemPadding, onListItemSelected, tabIndex, ...forwardedProps } = props;
54
63
  const listElementRef = useRef<HTMLUListElement>(null);
55
64
 
56
65
  const { items, hasClickableItem } = useInteractiveList({
@@ -70,7 +79,7 @@ const InternalList: Comp<ListProps, HTMLUListElement> = forwardRef((props, ref)
70
79
  itemPadding: itemPadding ?? (clickable ? Size.big : undefined),
71
80
  }),
72
81
  )}
73
- tabIndex={clickable ? 0 : -1}
82
+ tabIndex={tabIndex}
74
83
  ref={mergeRefs(ref, listElementRef)}
75
84
  >
76
85
  {items}
@@ -79,5 +88,6 @@ const InternalList: Comp<ListProps, HTMLUListElement> = forwardRef((props, ref)
79
88
  });
80
89
  InternalList.displayName = COMPONENT_NAME;
81
90
  InternalList.className = CLASSNAME;
91
+ InternalList.defaultProps = DEFAULT_PROPS;
82
92
 
83
93
  export const List = Object.assign(InternalList, { useKeyboardListNavigation });
@@ -3,7 +3,7 @@
3
3
  exports[`<List> Snapshots and structure should render story 'AsLink' 1`] = `
4
4
  <ul
5
5
  className="lumx-list lumx-list--item-padding-big"
6
- tabIndex={0}
6
+ tabIndex={-1}
7
7
  >
8
8
  <ListItem
9
9
  before={
@@ -62,7 +62,7 @@ exports[`<List> Snapshots and structure should render story 'AsLink' 1`] = `
62
62
  exports[`<List> Snapshots and structure should render story 'KeyboardNavigation' 1`] = `
63
63
  <ul
64
64
  className="lumx-list lumx-list--item-padding-big"
65
- tabIndex={0}
65
+ tabIndex={-1}
66
66
  >
67
67
  <ListItem
68
68
  isHighlighted={false}
@@ -193,7 +193,7 @@ exports[`<List> Snapshots and structure should render story 'WithItemPadding' 1`
193
193
  Array [
194
194
  <ul
195
195
  className="lumx-list lumx-list--item-padding-big"
196
- tabIndex={0}
196
+ tabIndex={-1}
197
197
  >
198
198
  <ListItem
199
199
  className="lumx-color-background-dark-L6"
@@ -248,7 +248,7 @@ Array [
248
248
  </ul>,
249
249
  <ul
250
250
  className="lumx-list lumx-list--item-padding-big"
251
- tabIndex={0}
251
+ tabIndex={-1}
252
252
  >
253
253
  <ListItem
254
254
  className="lumx-color-background-dark-L6"
@@ -303,7 +303,7 @@ Array [
303
303
  </ul>,
304
304
  <ul
305
305
  className="lumx-list lumx-list--item-padding-huge"
306
- tabIndex={0}
306
+ tabIndex={-1}
307
307
  >
308
308
  <ListItem
309
309
  className="lumx-color-background-dark-L6"
@@ -12,6 +12,7 @@ import { ClickAwayProvider } from '@lumx/react/utils/ClickAwayProvider';
12
12
 
13
13
  import { Comp, GenericProps, getRootClassName, handleBasicClasses, ValueOf } from '@lumx/react/utils';
14
14
  import { mergeRefs } from '@lumx/react/utils/mergeRefs';
15
+ import { useFocusWithin } from '@lumx/react/hooks/useFocusWithin';
15
16
 
16
17
  /**
17
18
  * Different possible placements for the popover.
@@ -81,6 +82,8 @@ export interface PopoverProps extends GenericProps {
81
82
  fitWithinViewportHeight?: boolean;
82
83
  /** Element to focus when opening the popover. */
83
84
  focusElement?: RefObject<HTMLElement>;
85
+ /** Whether the focus should go back on the anchor when popover closes and focus is within. */
86
+ focusAnchorOnClose?: boolean;
84
87
  /** Whether we put an arrow or not. */
85
88
  hasArrow?: boolean;
86
89
  /** Whether the popover is open or not. */
@@ -213,6 +216,7 @@ export const Popover: Comp<PopoverProps, HTMLDivElement> = forwardRef((props, re
213
216
  style,
214
217
  usePortal,
215
218
  zIndex,
219
+ focusAnchorOnClose = true,
216
220
  ...forwardedProps
217
221
  } = props;
218
222
  // eslint-disable-next-line react-hooks/rules-of-hooks
@@ -222,6 +226,42 @@ export const Popover: Comp<PopoverProps, HTMLDivElement> = forwardRef((props, re
222
226
  // eslint-disable-next-line react-hooks/rules-of-hooks
223
227
  const clickAwayRef = useRef<HTMLDivElement>(null);
224
228
 
229
+ /**
230
+ * Track whether the focus is currently set in the
231
+ * popover.
232
+ * */
233
+ // eslint-disable-next-line react-hooks/rules-of-hooks
234
+ const isFocusedWithin = useRef(false);
235
+
236
+ // eslint-disable-next-line react-hooks/rules-of-hooks
237
+ useFocusWithin({
238
+ element: popperElement || null,
239
+ onFocusIn: () => {
240
+ isFocusedWithin.current = true;
241
+ },
242
+ onFocusOut: () => {
243
+ isFocusedWithin.current = false;
244
+ },
245
+ });
246
+
247
+ /** Action on close */
248
+ const handleClose = () => {
249
+ if (!onClose) {
250
+ return;
251
+ }
252
+
253
+ /**
254
+ * If the focus is currently within the popover
255
+ * when the popover closes, reset the focus back to the anchor element
256
+ * unless specifically requested not to.
257
+ */
258
+ if (isFocusedWithin.current && focusAnchorOnClose) {
259
+ anchorRef.current?.focus();
260
+ }
261
+
262
+ onClose();
263
+ };
264
+
225
265
  const modifiers: any = [];
226
266
  const actualOffset: [number, number] = [offset?.along ?? 0, (offset?.away ?? 0) + (hasArrow ? ARROW_SIZE : 0)];
227
267
  modifiers.push({
@@ -267,7 +307,7 @@ export const Popover: Comp<PopoverProps, HTMLDivElement> = forwardRef((props, re
267
307
  }, [style, styles.popper, zIndex, fitWithinViewportHeight]);
268
308
 
269
309
  // eslint-disable-next-line react-hooks/rules-of-hooks
270
- useCallbackOnEscape(onClose, isOpen && closeOnEscape);
310
+ useCallbackOnEscape(handleClose, isOpen && closeOnEscape);
271
311
  // eslint-disable-next-line react-hooks/rules-of-hooks
272
312
  useFocus(focusElement?.current, isOpen && (state?.rects?.popper?.y ?? -1) >= 0);
273
313
 
@@ -286,7 +326,7 @@ export const Popover: Comp<PopoverProps, HTMLDivElement> = forwardRef((props, re
286
326
  style={popoverStyle}
287
327
  {...attributes.popper}
288
328
  >
289
- <ClickAwayProvider callback={closeOnClickAway && onClose} refs={clickAwayRefs}>
329
+ <ClickAwayProvider callback={closeOnClickAway && handleClose} refs={clickAwayRefs}>
290
330
  {hasArrow && <div ref={setArrowElement} className={`${CLASSNAME}__arrow`} style={styles.arrow} />}
291
331
  {children}
292
332
  </ClickAwayProvider>
@@ -15,6 +15,8 @@ export interface RadioButtonProps extends GenericProps {
15
15
  helper?: string;
16
16
  /** Native input id property. */
17
17
  id?: string;
18
+ /** Native input ref. */
19
+ inputRef?: React.Ref<HTMLInputElement>;
18
20
  /** Whether it is checked or not. */
19
21
  isChecked?: boolean;
20
22
  /** Whether the component is disabled or not. */
@@ -62,6 +64,7 @@ export const RadioButton: Comp<RadioButtonProps, HTMLDivElement> = forwardRef((p
62
64
  disabled,
63
65
  helper,
64
66
  id,
67
+ inputRef,
65
68
  isChecked = checked,
66
69
  isDisabled = disabled,
67
70
  label,
@@ -96,6 +99,7 @@ export const RadioButton: Comp<RadioButtonProps, HTMLDivElement> = forwardRef((p
96
99
  >
97
100
  <div className={`${CLASSNAME}__input-wrapper`}>
98
101
  <input
102
+ ref={inputRef}
99
103
  className={`${CLASSNAME}__input-native`}
100
104
  disabled={isDisabled}
101
105
  id={radioButtonId}
@@ -29,6 +29,7 @@ exports[`<Select> Snapshots and structure should render correctly 1`] = `
29
29
  closeOnEscape={true}
30
30
  fitToAnchorWidth={true}
31
31
  fitWithinViewportHeight={true}
32
+ focusAnchorOnClose={true}
32
33
  isOpen={false}
33
34
  onClose={[Function]}
34
35
  placement="bottom-start"
@@ -30,6 +30,7 @@ exports[`<SelectMultiple> Snapshots and structure should render chips 1`] = `
30
30
  closeOnEscape={true}
31
31
  fitToAnchorWidth={true}
32
32
  fitWithinViewportHeight={true}
33
+ focusAnchorOnClose={true}
33
34
  isOpen={false}
34
35
  onClose={[Function]}
35
36
  placement="bottom-start"
@@ -72,6 +73,7 @@ exports[`<SelectMultiple> Snapshots and structure should render defaults 1`] = `
72
73
  closeOnEscape={true}
73
74
  fitToAnchorWidth={true}
74
75
  fitWithinViewportHeight={true}
76
+ focusAnchorOnClose={true}
75
77
  isOpen={false}
76
78
  onClose={[Function]}
77
79
  placement="bottom-start"
@@ -103,7 +103,6 @@ export function useTooltipOpen(delay: number | undefined, anchorElement: HTMLEle
103
103
  for (const [node, eventType, evenHandler] of events) {
104
104
  node.removeEventListener(eventType, evenHandler);
105
105
  }
106
- closeImmediately();
107
106
  };
108
107
  }, [anchorElement, delay]);
109
108
 
@@ -6,4 +6,5 @@ export default { title: 'LumX components/toolbar/Toolbar Demos' };
6
6
  export { App as Back } from './back';
7
7
  export { App as Default } from './default';
8
8
  export { App as Dialog } from './dialog';
9
+ export { App as FileWidget } from './file-widget';
9
10
  export { App as MediaPicker } from './media-picker';
package/types.d.ts CHANGED
@@ -585,6 +585,8 @@ export interface CheckboxProps extends GenericProps {
585
585
  helper?: string;
586
586
  /** Native input id property. */
587
587
  id?: string;
588
+ /** Native input ref. */
589
+ inputRef?: React.Ref<HTMLInputElement>;
588
590
  /** Whether it is checked or not. */
589
591
  isChecked?: boolean;
590
592
  /** Whether the component is disabled or not. */
@@ -688,8 +690,10 @@ export interface CommentBlockProps extends GenericProps {
688
690
  avatarProps: AvatarProps;
689
691
  /** Comment block replies. */
690
692
  children?: ReactNode;
691
- /** Comment date. */
693
+ /** Comment date with the minimal timestamp informations (xx minutes, x hours, yesterday, 6 days, Month Day, Month Day Year)*/
692
694
  date: string;
695
+ /** Comment date with the full timestamp informations (day, month, year, time) */
696
+ fullDate?: string;
693
697
  /** Whether the component has actions to display or not. */
694
698
  hasActions?: boolean;
695
699
  /** Action toolbar header content. */
@@ -938,6 +942,8 @@ export interface PopoverProps extends GenericProps {
938
942
  fitWithinViewportHeight?: boolean;
939
943
  /** Element to focus when opening the popover. */
940
944
  focusElement?: RefObject<HTMLElement>;
945
+ /** Whether the focus should go back on the anchor when popover closes and focus is within. */
946
+ focusAnchorOnClose?: boolean;
941
947
  /** Whether we put an arrow or not. */
942
948
  hasArrow?: boolean;
943
949
  /** Whether the popover is open or not. */
@@ -1012,6 +1018,8 @@ export interface DropdownProps extends GenericProps {
1012
1018
  placement?: Placement;
1013
1019
  /** Whether the focus should be set on the list when the dropdown is open or not. */
1014
1020
  shouldFocusOnOpen?: boolean;
1021
+ /** Whether the focus should go back on the anchor when dropdown closes and focus is within. */
1022
+ focusAnchorOnClose?: boolean;
1015
1023
  /**
1016
1024
  * Z-axis position.
1017
1025
  * @see {@link PopoverProps#zIndex}
@@ -1474,6 +1482,8 @@ export interface ListProps extends GenericProps {
1474
1482
  isClickable?: boolean;
1475
1483
  /** Item padding size. */
1476
1484
  itemPadding?: Extract<Size, "big" | "huge">;
1485
+ /** Tab index of the list. Default to -1 */
1486
+ tabIndex?: number;
1477
1487
  /**
1478
1488
  * On list item selected callback.
1479
1489
  *
@@ -1788,6 +1798,8 @@ export interface RadioButtonProps extends GenericProps {
1788
1798
  helper?: string;
1789
1799
  /** Native input id property. */
1790
1800
  id?: string;
1801
+ /** Native input ref. */
1802
+ inputRef?: React.Ref<HTMLInputElement>;
1791
1803
  /** Whether it is checked or not. */
1792
1804
  isChecked?: boolean;
1793
1805
  /** Whether the component is disabled or not. */