@lumx/react 3.10.1-alpha.2 → 3.10.1-alpha.3
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/_internal/{8d67e1e3.d.ts → index.d.ts} +1 -1
- package/_internal/index.js +99 -0
- package/_internal/index.js.map +1 -0
- package/index.d.ts +3000 -66
- package/index.js +14554 -64
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/button/Button.tsx +4 -5
- package/src/components/button/ButtonRoot.tsx +1 -3
- package/src/components/chip/Chip.tsx +6 -10
- package/src/components/dialog/Dialog.tsx +1 -1
- package/src/components/expansion-panel/ExpansionPanel.tsx +14 -18
- package/src/components/flex-box/FlexBox.tsx +1 -1
- package/src/components/generic-block/GenericBlock.tsx +6 -7
- package/src/components/generic-block/constants.ts +9 -4
- package/src/components/grid-column/GridColumn.tsx +1 -2
- package/src/components/link/Link.tsx +3 -5
- package/src/components/list/ListItem.tsx +1 -2
- package/src/components/list/useInteractiveList.tsx +1 -2
- package/src/components/mosaic/Mosaic.test.tsx +3 -3
- package/src/components/mosaic/Mosaic.tsx +2 -3
- package/src/components/navigation/Navigation.tsx +42 -37
- package/src/components/navigation/NavigationSection.tsx +76 -79
- package/src/components/notification/Notification.tsx +1 -5
- package/src/components/post-block/PostBlock.tsx +4 -8
- package/src/components/progress-tracker/ProgressTracker.stories.tsx +11 -11
- package/src/components/select/Select.stories.tsx +14 -5
- package/src/components/select/Select.tsx +1 -2
- package/src/components/select/SelectMultiple.stories.tsx +12 -10
- package/src/components/side-navigation/SideNavigationItem.tsx +1 -1
- package/src/components/slideshow/Slides.tsx +1 -1
- package/src/components/slideshow/SlideshowControls.tsx +1 -1
- package/src/components/switch/Switch.tsx +1 -2
- package/src/components/tabs/Tabs.stories.tsx +3 -4
- package/src/components/text-field/TextField.test.tsx +2 -2
- package/src/components/text-field/TextField.tsx +2 -3
- package/src/components/user-block/UserBlock.tsx +7 -9
- package/src/hooks/useClickAway.tsx +1 -2
- package/src/hooks/useInterval.tsx +1 -4
- package/src/hooks/useKeyboardListNavigation.tsx +2 -4
- package/src/hooks/useStopPropagation.ts +1 -2
- package/src/stories/decorators/withCombinations.tsx +1 -1
- package/src/testing/utils/commonTestsSuiteRTL.tsx +2 -2
- package/src/utils/collection/castArray.test.ts +15 -0
- package/src/utils/collection/castArray.ts +3 -0
- package/src/utils/collection/chunk.test.ts +15 -0
- package/src/utils/collection/chunk.ts +6 -0
- package/src/utils/collection/isEmpty.test.js +20 -0
- package/src/utils/collection/isEmpty.ts +4 -0
- package/src/utils/collection/last.ts +2 -0
- package/src/utils/collection/partitionMulti.test.ts +35 -0
- package/src/utils/{partitionMulti.ts → collection/partitionMulti.ts} +13 -12
- package/src/utils/collection/pull.test.ts +17 -0
- package/src/utils/collection/pull.ts +7 -0
- package/src/utils/collection/range.test.js +9 -0
- package/src/utils/collection/range.ts +2 -0
- package/src/utils/date/getMonthCalendar.ts +3 -4
- package/src/utils/flattenChildren.ts +2 -3
- package/src/utils/makeListenerTowerContext.ts +2 -2
- package/src/utils/react/forwardRef.ts +3 -2
- package/src/utils/react/forwardRefPolymorphic.ts +1 -2
- package/src/utils/utils.test.ts +0 -27
- package/utils/index.d.ts +1 -1
- package/utils/index.js +1 -96
- package/utils/index.js.map +1 -1
- package/_internal/17c3ea1d.js +0 -137
- package/_internal/17c3ea1d.js.map +0 -1
- package/_internal/1da25128.js +0 -411
- package/_internal/1da25128.js.map +0 -1
- package/_internal/230173a8.js +0 -13
- package/_internal/230173a8.js.map +0 -1
- package/_internal/23bdba2d.js +0 -71
- package/_internal/23bdba2d.js.map +0 -1
- package/_internal/26926e5c.d.ts +0 -36
- package/_internal/2a3d237c.js +0 -12
- package/_internal/2a3d237c.js.map +0 -1
- package/_internal/2c5dbb03.js +0 -26
- package/_internal/2c5dbb03.js.map +0 -1
- package/_internal/2e2abe51.js +0 -2154
- package/_internal/2e2abe51.js.map +0 -1
- package/_internal/31490c59.d.ts +0 -167
- package/_internal/3181f000.js +0 -14
- package/_internal/3181f000.js.map +0 -1
- package/_internal/35f100be.d.ts +0 -104
- package/_internal/36bd7352.js +0 -219
- package/_internal/36bd7352.js.map +0 -1
- package/_internal/3a1facc0.js +0 -18
- package/_internal/3a1facc0.js.map +0 -1
- package/_internal/4c20d932.js +0 -89
- package/_internal/4c20d932.js.map +0 -1
- package/_internal/4c28d012.js +0 -305
- package/_internal/4c28d012.js.map +0 -1
- package/_internal/4cd0bf32.js +0 -160
- package/_internal/4cd0bf32.js.map +0 -1
- package/_internal/4daccdd5.js +0 -25
- package/_internal/4daccdd5.js.map +0 -1
- package/_internal/524b1d04.js +0 -64
- package/_internal/524b1d04.js.map +0 -1
- package/_internal/53c94227.js +0 -123
- package/_internal/53c94227.js.map +0 -1
- package/_internal/54d9ded5.js +0 -418
- package/_internal/54d9ded5.js.map +0 -1
- package/_internal/56aec41b.js +0 -652
- package/_internal/56aec41b.js.map +0 -1
- package/_internal/5720caf5.js +0 -124
- package/_internal/5720caf5.js.map +0 -1
- package/_internal/646f0db6.js +0 -113
- package/_internal/646f0db6.js.map +0 -1
- package/_internal/6cc8dca8.d.ts +0 -22
- package/_internal/7f022f8c.d.ts +0 -34
- package/_internal/b8f2948d.js +0 -691
- package/_internal/b8f2948d.js.map +0 -1
- package/_internal/bc28d510.js +0 -784
- package/_internal/bc28d510.js.map +0 -1
- package/_internal/c68d24e4.js +0 -145
- package/_internal/c68d24e4.js.map +0 -1
- package/_internal/c6c99f76.js +0 -105
- package/_internal/c6c99f76.js.map +0 -1
- package/_internal/cae46566.js +0 -65
- package/_internal/cae46566.js.map +0 -1
- package/_internal/components/alert-dialog/index.ts-623b1ed3.d.ts +0 -37
- package/_internal/components/alert-dialog/index.ts-f83bd6ef.js +0 -148
- package/_internal/components/alert-dialog/index.ts-f83bd6ef.js.map +0 -1
- package/_internal/components/autocomplete/index.ts-3f8f125c.js +0 -264
- package/_internal/components/autocomplete/index.ts-3f8f125c.js.map +0 -1
- package/_internal/components/autocomplete/index.ts-8d6b123f.d.ts +0 -201
- package/_internal/components/avatar/index.ts-93ee0ea9.js +0 -89
- package/_internal/components/avatar/index.ts-93ee0ea9.js.map +0 -1
- package/_internal/components/avatar/index.ts-f92852b4.d.ts +0 -43
- package/_internal/components/badge/index.ts-2d7700ef.d.ts +0 -30
- package/_internal/components/badge/index.ts-6753d67f.js +0 -88
- package/_internal/components/badge/index.ts-6753d67f.js.map +0 -1
- package/_internal/components/button/index.ts-031307ce.js +0 -51
- package/_internal/components/button/index.ts-031307ce.js.map +0 -1
- package/_internal/components/button/index.ts-b29e26a4.d.ts +0 -22
- package/_internal/components/checkbox/index.ts-a33166d7.js +0 -127
- package/_internal/components/checkbox/index.ts-a33166d7.js.map +0 -1
- package/_internal/components/checkbox/index.ts-f82358ff.d.ts +0 -38
- package/_internal/components/chip/index.ts-4a91f1a7.d.ts +0 -68
- package/_internal/components/chip/index.ts-a2b5b771.js +0 -110
- package/_internal/components/chip/index.ts-a2b5b771.js.map +0 -1
- package/_internal/components/comment-block/index.ts-58fa051a.js +0 -121
- package/_internal/components/comment-block/index.ts-58fa051a.js.map +0 -1
- package/_internal/components/comment-block/index.ts-8cfa5af0.d.ts +0 -67
- package/_internal/components/date-picker/index.ts-145262d5.js +0 -2
- package/_internal/components/date-picker/index.ts-145262d5.js.map +0 -1
- package/_internal/components/date-picker/index.ts-70a34fa7.d.ts +0 -95
- package/_internal/components/dialog/index.ts-ea044db2.js +0 -224
- package/_internal/components/dialog/index.ts-ea044db2.js.map +0 -1
- package/_internal/components/dialog/index.ts-eca28654.d.ts +0 -55
- package/_internal/components/divider/index.ts-4a56db75.js +0 -55
- package/_internal/components/divider/index.ts-4a56db75.js.map +0 -1
- package/_internal/components/divider/index.ts-b011d8ca.d.ts +0 -18
- package/_internal/components/drag-handle/index.ts-0aebf92f.js +0 -54
- package/_internal/components/drag-handle/index.ts-0aebf92f.js.map +0 -1
- package/_internal/components/drag-handle/index.ts-3ab31dd1.d.ts +0 -18
- package/_internal/components/dropdown/index.ts-2a17db51.js +0 -154
- package/_internal/components/dropdown/index.ts-2a17db51.js.map +0 -1
- package/_internal/components/dropdown/index.ts-b648a15c.d.ts +0 -87
- package/_internal/components/expansion-panel/index.ts-69f09f5b.d.ts +0 -38
- package/_internal/components/expansion-panel/index.ts-fae3762e.js +0 -143
- package/_internal/components/expansion-panel/index.ts-fae3762e.js.map +0 -1
- package/_internal/components/flag/index.ts-8dcd685b.js +0 -56
- package/_internal/components/flag/index.ts-8dcd685b.js.map +0 -1
- package/_internal/components/flag/index.ts-fda89adb.d.ts +0 -23
- package/_internal/components/flex-box/index.ts-87f2b58d.d.ts +0 -43
- package/_internal/components/flex-box/index.ts-c216e957.js +0 -60
- package/_internal/components/flex-box/index.ts-c216e957.js.map +0 -1
- package/_internal/components/generic-block/index.ts-999a62a4.js +0 -115
- package/_internal/components/generic-block/index.ts-999a62a4.js.map +0 -1
- package/_internal/components/generic-block/index.ts-cd3b0e21.d.ts +0 -106
- package/_internal/components/grid/index.ts-67e0694f.d.ts +0 -50
- package/_internal/components/grid/index.ts-fdf1b306.js +0 -113
- package/_internal/components/grid/index.ts-fdf1b306.js.map +0 -1
- package/_internal/components/grid-column/index.ts-97c61cbe.js +0 -64
- package/_internal/components/grid-column/index.ts-97c61cbe.js.map +0 -1
- package/_internal/components/grid-column/index.ts-c89e1c18.d.ts +0 -31
- package/_internal/components/heading/index.ts-0179e9a9.js +0 -112
- package/_internal/components/heading/index.ts-0179e9a9.js.map +0 -1
- package/_internal/components/heading/index.ts-587579e8.d.ts +0 -37
- package/_internal/components/icon/index.ts-740ca1de.js +0 -2
- package/_internal/components/icon/index.ts-740ca1de.js.map +0 -1
- package/_internal/components/icon/index.ts-b3fa5e15.d.ts +0 -34
- package/_internal/components/image-block/index.ts-36b3828f.d.ts +0 -49
- package/_internal/components/image-block/index.ts-ef5e2e7d.js +0 -111
- package/_internal/components/image-block/index.ts-ef5e2e7d.js.map +0 -1
- package/_internal/components/image-lightbox/index.ts-137f85a8.js +0 -765
- package/_internal/components/image-lightbox/index.ts-137f85a8.js.map +0 -1
- package/_internal/components/image-lightbox/index.ts-2cb92d18.d.ts +0 -75
- package/_internal/components/inline-list/index.ts-033dd358.js +0 -76
- package/_internal/components/inline-list/index.ts-033dd358.js.map +0 -1
- package/_internal/components/inline-list/index.ts-e1c8a3ff.d.ts +0 -34
- package/_internal/components/input-helper/index.ts-32a9ca90.d.ts +0 -22
- package/_internal/components/input-helper/index.ts-ab3a1ef5.js +0 -75
- package/_internal/components/input-helper/index.ts-ab3a1ef5.js.map +0 -1
- package/_internal/components/input-label/index.ts-86f2ea41.d.ts +0 -24
- package/_internal/components/input-label/index.ts-d6ca5569.js +0 -60
- package/_internal/components/input-label/index.ts-d6ca5569.js.map +0 -1
- package/_internal/components/lightbox/index.ts-5370e8e6.d.ts +0 -36
- package/_internal/components/lightbox/index.ts-7a16cdc7.js +0 -149
- package/_internal/components/lightbox/index.ts-7a16cdc7.js.map +0 -1
- package/_internal/components/link/index.ts-26435006.d.ts +0 -37
- package/_internal/components/link/index.ts-d04f4e53.js +0 -120
- package/_internal/components/link/index.ts-d04f4e53.js.map +0 -1
- package/_internal/components/link-preview/index.ts-e560a274.d.ts +0 -36
- package/_internal/components/link-preview/index.ts-fee89f66.js +0 -109
- package/_internal/components/link-preview/index.ts-fee89f66.js.map +0 -1
- package/_internal/components/list/index.ts-ab57902e.d.ts +0 -118
- package/_internal/components/list/index.ts-f3101625.js +0 -86
- package/_internal/components/list/index.ts-f3101625.js.map +0 -1
- package/_internal/components/message/index.ts-041cf0cb.js +0 -97
- package/_internal/components/message/index.ts-041cf0cb.js.map +0 -1
- package/_internal/components/message/index.ts-2d38e0ea.d.ts +0 -37
- package/_internal/components/mosaic/index.ts-232d5aed.d.ts +0 -23
- package/_internal/components/mosaic/index.ts-d2128cd3.js +0 -94
- package/_internal/components/mosaic/index.ts-d2128cd3.js.map +0 -1
- package/_internal/components/navigation/index.ts-6d8bea53.d.ts +0 -58
- package/_internal/components/navigation/index.ts-e8dc0a7f.js +0 -222
- package/_internal/components/navigation/index.ts-e8dc0a7f.js.map +0 -1
- package/_internal/components/notification/index.ts-235fd340.js +0 -140
- package/_internal/components/notification/index.ts-235fd340.js.map +0 -1
- package/_internal/components/notification/index.ts-bb3f03f6.d.ts +0 -34
- package/_internal/components/popover/index.ts-2f17a9b6.js +0 -3
- package/_internal/components/popover/index.ts-2f17a9b6.js.map +0 -1
- package/_internal/components/popover/index.ts-e3b4ff19.d.ts +0 -66
- package/_internal/components/post-block/index.ts-0acb9bb4.js +0 -101
- package/_internal/components/post-block/index.ts-0acb9bb4.js.map +0 -1
- package/_internal/components/post-block/index.ts-9b8ff90b.d.ts +0 -41
- package/_internal/components/progress/index.ts-2a713859.js +0 -189
- package/_internal/components/progress/index.ts-2a713859.js.map +0 -1
- package/_internal/components/progress/index.ts-dfdfa5fb.d.ts +0 -60
- package/_internal/components/progress-tracker/index.ts-2649f756.js +0 -312
- package/_internal/components/progress-tracker/index.ts-2649f756.js.map +0 -1
- package/_internal/components/progress-tracker/index.ts-95320f32.d.ts +0 -101
- package/_internal/components/radio-button/index.ts-5eaab4cf.d.ts +0 -54
- package/_internal/components/radio-button/index.ts-b4dfb2a0.js +0 -150
- package/_internal/components/radio-button/index.ts-b4dfb2a0.js.map +0 -1
- package/_internal/components/select/index.ts-a65e3507.d.ts +0 -91
- package/_internal/components/select/index.ts-e8fad28b.js +0 -257
- package/_internal/components/select/index.ts-e8fad28b.js.map +0 -1
- package/_internal/components/side-navigation/index.ts-3f5f3785.d.ts +0 -60
- package/_internal/components/side-navigation/index.ts-c9a5fc3e.js +0 -184
- package/_internal/components/side-navigation/index.ts-c9a5fc3e.js.map +0 -1
- package/_internal/components/skeleton/index.ts-a7daefac.d.ts +0 -75
- package/_internal/components/skeleton/index.ts-ffc995af.js +0 -179
- package/_internal/components/skeleton/index.ts-ffc995af.js.map +0 -1
- package/_internal/components/slider/index.ts-24a0d598.d.ts +0 -52
- package/_internal/components/slider/index.ts-72aadf4c.js +0 -308
- package/_internal/components/slider/index.ts-72aadf4c.js.map +0 -1
- package/_internal/components/slideshow/index.ts-c99f2892.js +0 -151
- package/_internal/components/slideshow/index.ts-c99f2892.js.map +0 -1
- package/_internal/components/slideshow/index.ts-e49462c6.d.ts +0 -25
- package/_internal/components/switch/index.ts-207ba52b.d.ts +0 -34
- package/_internal/components/switch/index.ts-542e6eaf.js +0 -115
- package/_internal/components/switch/index.ts-542e6eaf.js.map +0 -1
- package/_internal/components/table/index.ts-905ce390.js +0 -310
- package/_internal/components/table/index.ts-905ce390.js.map +0 -1
- package/_internal/components/table/index.ts-c4f39b2d.d.ts +0 -108
- package/_internal/components/tabs/index.ts-713119f4.js +0 -289
- package/_internal/components/tabs/index.ts-713119f4.js.map +0 -1
- package/_internal/components/tabs/index.ts-dbfc48d9.d.ts +0 -106
- package/_internal/components/text/index.ts-6afbe8cd.js +0 -2
- package/_internal/components/text/index.ts-6afbe8cd.js.map +0 -1
- package/_internal/components/text/index.ts-8a812048.d.ts +0 -53
- package/_internal/components/text-field/index.ts-92e6b3b3.d.ts +0 -77
- package/_internal/components/text-field/index.ts-c3be8563.js +0 -341
- package/_internal/components/text-field/index.ts-c3be8563.js.map +0 -1
- package/_internal/components/thumbnail/index.ts-16d7b403.js +0 -40
- package/_internal/components/thumbnail/index.ts-16d7b403.js.map +0 -1
- package/_internal/components/thumbnail/index.ts-1b6c0b48.d.ts +0 -8
- package/_internal/components/toolbar/index.ts-813b902e.js +0 -63
- package/_internal/components/toolbar/index.ts-813b902e.js.map +0 -1
- package/_internal/components/toolbar/index.ts-9f5129d1.d.ts +0 -24
- package/_internal/components/tooltip/index.ts-905c847c.js +0 -322
- package/_internal/components/tooltip/index.ts-905c847c.js.map +0 -1
- package/_internal/components/tooltip/index.ts-c6931e9e.d.ts +0 -35
- package/_internal/components/uploader/index.ts-31f21c2a.js +0 -132
- package/_internal/components/uploader/index.ts-31f21c2a.js.map +0 -1
- package/_internal/components/uploader/index.ts-c3ccba98.d.ts +0 -51
- package/_internal/components/user-block/index.ts-18c58e19.d.ts +0 -50
- package/_internal/components/user-block/index.ts-d43e5f3c.js +0 -136
- package/_internal/components/user-block/index.ts-d43e5f3c.js.map +0 -1
- package/_internal/dc3e28c8.d.ts +0 -38
- package/_internal/f39a1ba4.js +0 -73
- package/_internal/f39a1ba4.js.map +0 -1
- package/_internal/f3e77e3e.js +0 -22
- package/_internal/f3e77e3e.js.map +0 -1
- package/_internal/f502ab30.js +0 -78
- package/_internal/f502ab30.js.map +0 -1
- package/_internal/f52adbae.js +0 -36
- package/_internal/f52adbae.js.map +0 -1
- package/_internal/f57e1239.js +0 -205
- package/_internal/f57e1239.js.map +0 -1
- package/_internal/f5ff1aa4.d.ts +0 -47
- package/_internal/fb975afe.js +0 -52
- package/_internal/fb975afe.js.map +0 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import isFunction from 'lodash/isFunction';
|
|
2
1
|
import { MouseEventHandler, useCallback } from 'react';
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -10,7 +9,7 @@ import { MouseEventHandler, useCallback } from 'react';
|
|
|
10
9
|
export function useStopPropagation(handler?: MouseEventHandler): MouseEventHandler {
|
|
11
10
|
return useCallback(
|
|
12
11
|
(evt) => {
|
|
13
|
-
if (!evt || !
|
|
12
|
+
if (!evt || !handler) {
|
|
14
13
|
return;
|
|
15
14
|
}
|
|
16
15
|
handler(evt);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable react/display-name,jsx-a11y/control-has-associated-label,prefer-object-spread */
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import isEmpty from '
|
|
3
|
+
import { isEmpty } from '@lumx/react/utils/collection/isEmpty';
|
|
4
4
|
import { Heading, HeadingLevelProvider } from '@lumx/react';
|
|
5
5
|
|
|
6
6
|
type PropEntry = [key: string, value: unknown];
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
2
|
|
|
3
3
|
import { GenericProps } from '@lumx/react/utils/type';
|
|
4
4
|
import { queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
5
|
-
import React from 'react';
|
|
6
5
|
import { Theme } from '@lumx/react';
|
|
7
6
|
import { RenderOptions } from '@testing-library/react';
|
|
8
7
|
import { ThemeProvider } from '@lumx/react/utils/theme/ThemeContext';
|
|
9
8
|
import castArray from 'lodash/castArray';
|
|
10
9
|
import { invertTheme } from '@lumx/react/utils/theme/invertTheme';
|
|
10
|
+
import { isEmpty } from '@lumx/react/utils/collection/isEmpty';
|
|
11
11
|
|
|
12
12
|
interface CommonSetup {
|
|
13
13
|
props: GenericProps;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { castArray } from '@lumx/react/utils/collection/castArray';
|
|
2
|
+
|
|
3
|
+
describe(castArray, () => {
|
|
4
|
+
it('should keep existing array', () => {
|
|
5
|
+
const input = [1, 2];
|
|
6
|
+
const output = castArray(input);
|
|
7
|
+
expect(output).toEqual([1, 2]);
|
|
8
|
+
expect(output).toBe(input);
|
|
9
|
+
});
|
|
10
|
+
it('should cast item to array', () => {
|
|
11
|
+
const input = 1;
|
|
12
|
+
const output = castArray(input);
|
|
13
|
+
expect(output).toEqual([1]);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { chunk } from '@lumx/react/utils/collection/chunk';
|
|
2
|
+
|
|
3
|
+
describe(chunk, () => {
|
|
4
|
+
it('should do nothing on empty array', () => {
|
|
5
|
+
expect(chunk([], 2)).toEqual([]);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it('should work with size larger than input array', () => {
|
|
9
|
+
expect(chunk([1, 2], 4)).toEqual([[1, 2]]);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('should chunk array with size not perfectly dividing the array length', () => {
|
|
13
|
+
expect(chunk([1, 2, 3, 4, 5], 2)).toEqual([[1, 2], [3, 4], [5]]);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Chunk array in slices of given size */
|
|
2
|
+
export function chunk<T>(input: Array<T>, size: number): T[][] {
|
|
3
|
+
return input.reduce((arr, item, idx) => {
|
|
4
|
+
return idx % size === 0 ? [...arr, [item]] : [...arr.slice(0, -1), [...arr.slice(-1)[0], item]];
|
|
5
|
+
}, [] as T[][]);
|
|
6
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isEmpty } from './isEmpty';
|
|
2
|
+
|
|
3
|
+
describe(isEmpty, () => {
|
|
4
|
+
it('should return true for falsy values', () => {
|
|
5
|
+
expect(isEmpty(undefined)).toBe(true);
|
|
6
|
+
expect(isEmpty(null)).toBe(true);
|
|
7
|
+
expect(isEmpty(0)).toBe(true);
|
|
8
|
+
expect(isEmpty('')).toBe(true);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should return true for empty object or array', () => {
|
|
12
|
+
expect(isEmpty([])).toBe(true);
|
|
13
|
+
expect(isEmpty({})).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should return false for non empty object or array', () => {
|
|
17
|
+
expect(isEmpty([''])).toBe(false);
|
|
18
|
+
expect(isEmpty({ foo: false })).toBe(false);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { partitionMulti } from './partitionMulti';
|
|
2
|
+
|
|
3
|
+
describe('partitionMulti', () => {
|
|
4
|
+
it('should partition with single predicate', () => {
|
|
5
|
+
const data = [0, 1, 2, 3, 4, 5];
|
|
6
|
+
const isEven = (n: number): boolean => n % 2 === 0;
|
|
7
|
+
|
|
8
|
+
const actual = partitionMulti(data, [isEven]);
|
|
9
|
+
|
|
10
|
+
expect(actual).toEqual([
|
|
11
|
+
[0, 2, 4],
|
|
12
|
+
[1, 3, 5],
|
|
13
|
+
]);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should partition on multiple predicates', () => {
|
|
17
|
+
type T = string | number | boolean;
|
|
18
|
+
const data: T[] = ['a', 1, 'b', false, true];
|
|
19
|
+
const isString = (s: T): boolean => typeof s === 'string';
|
|
20
|
+
const isNumber = (s: T): boolean => typeof s === 'number';
|
|
21
|
+
const isNull = (s: T): boolean => s === null;
|
|
22
|
+
|
|
23
|
+
const partitions = partitionMulti(data, [isString, isNumber, isNull]);
|
|
24
|
+
expect(partitions).toEqual([
|
|
25
|
+
// strings
|
|
26
|
+
['a', 'b'],
|
|
27
|
+
// numbers
|
|
28
|
+
[1],
|
|
29
|
+
// nulls
|
|
30
|
+
[],
|
|
31
|
+
// others
|
|
32
|
+
[false, true],
|
|
33
|
+
]);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import dropRight from 'lodash/dropRight';
|
|
3
|
-
import last from 'lodash/last';
|
|
4
|
-
import partition from 'lodash/partition';
|
|
5
|
-
import reduce from 'lodash/reduce';
|
|
6
|
-
import { Predicate } from './type';
|
|
1
|
+
import type { Predicate } from '../type';
|
|
7
2
|
|
|
8
3
|
/**
|
|
9
4
|
* Similar to lodash `partition` function but working with multiple predicates.
|
|
@@ -19,10 +14,16 @@ import { Predicate } from './type';
|
|
|
19
14
|
* @return partitioned elements by the given predicates
|
|
20
15
|
*/
|
|
21
16
|
export function partitionMulti<T>(elements: T[], predicates: Array<Predicate<T>>): T[][] {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
17
|
+
const others = [] as T[];
|
|
18
|
+
const groups = predicates.map(() => []) as T[][];
|
|
19
|
+
|
|
20
|
+
for (const element of elements) {
|
|
21
|
+
const index = predicates.findIndex((predicate) => predicate(element));
|
|
22
|
+
if (index !== -1) {
|
|
23
|
+
groups[index].push(element);
|
|
24
|
+
} else {
|
|
25
|
+
others.push(element);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return [...groups, others];
|
|
28
29
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { pull } from '@lumx/react/utils/collection/pull';
|
|
2
|
+
|
|
3
|
+
describe(pull, () => {
|
|
4
|
+
it('should do nothing if element does not exist', () => {
|
|
5
|
+
const a = [1, 2];
|
|
6
|
+
pull(a, 0);
|
|
7
|
+
expect(a).toBe(a);
|
|
8
|
+
expect(a).toEqual([1, 2]);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should pull an element from the array', () => {
|
|
12
|
+
const a = [1, 2];
|
|
13
|
+
pull(a, 1);
|
|
14
|
+
expect(a).toBe(a);
|
|
15
|
+
expect(a).toEqual([2]);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import last from 'lodash/last';
|
|
2
|
-
|
|
3
1
|
import { getWeekDays, WeekDayInfo } from '@lumx/react/utils/date/getWeekDays';
|
|
4
2
|
import { Locale } from '@lumx/react/utils/locale/types';
|
|
3
|
+
import { last } from '@lumx/react/utils/collection/last';
|
|
5
4
|
|
|
6
5
|
type AnnotatedDay = { date: Date; isOutOfRange?: boolean };
|
|
7
6
|
type AnnotatedWeek = Partial<Record<number, AnnotatedDay>>;
|
|
@@ -29,7 +28,7 @@ export const getMonthCalendar = (
|
|
|
29
28
|
iterDate.setDate(1);
|
|
30
29
|
|
|
31
30
|
const weekDays = getWeekDays(locale);
|
|
32
|
-
const lastDayOfWeek = last(weekDays)
|
|
31
|
+
const lastDayOfWeek = last(weekDays);
|
|
33
32
|
|
|
34
33
|
const weeks: Array<AnnotatedWeek> = [];
|
|
35
34
|
let week: AnnotatedWeek = {};
|
|
@@ -47,7 +46,7 @@ export const getMonthCalendar = (
|
|
|
47
46
|
week[weekDayNumber] = day;
|
|
48
47
|
}
|
|
49
48
|
|
|
50
|
-
if (weekDayNumber === lastDayOfWeek
|
|
49
|
+
if (weekDayNumber === lastDayOfWeek?.number) {
|
|
51
50
|
weeks.push(week);
|
|
52
51
|
rowCount += 1;
|
|
53
52
|
week = {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Children, Key, ReactChild, ReactNode, cloneElement, isValidElement } from 'react';
|
|
1
|
+
import { Children, Key, ReactChild, ReactNode, cloneElement, isValidElement, ReactElement } from 'react';
|
|
3
2
|
import { isFragment } from 'react-is';
|
|
4
3
|
|
|
5
4
|
/**
|
|
@@ -17,7 +16,7 @@ import { isFragment } from 'react-is';
|
|
|
17
16
|
export function flattenChildren(children: ReactNode) {
|
|
18
17
|
function recur(nodes: ReactNode, keys: Key[] = []) {
|
|
19
18
|
return Children.toArray(nodes).reduce((acc: ReactChild[], node, index) => {
|
|
20
|
-
const nodeKeys = keys.concat(
|
|
19
|
+
const nodeKeys = keys.concat((node as ReactElement)?.key ?? index);
|
|
21
20
|
if (isFragment(node)) {
|
|
22
21
|
acc.push(...recur(node.props.children, nodeKeys));
|
|
23
22
|
} else if (isValidElement(node)) {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React, { type ReactNode, type ForwardedRef } from 'react';
|
|
2
2
|
import type { Comp } from '../type';
|
|
3
3
|
|
|
4
|
-
type ForwardRef = <P, T = HTMLElement
|
|
4
|
+
type ForwardRef = <P, T = HTMLElement, A = unknown>(
|
|
5
|
+
render: (props: P, ref: ForwardedRef<T>) => ReactNode,
|
|
6
|
+
) => Comp<P, T> & A;
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* React.forwardRef but re-typed to attach some custom metadata on our components.
|
|
8
10
|
*/
|
|
9
|
-
/*#__NO_SIDE_EFFECTS__*/
|
|
10
11
|
export const forwardRef = React.forwardRef as ForwardRef;
|
|
@@ -3,8 +3,7 @@ import type { ComponentRef } from '@lumx/react/utils/type';
|
|
|
3
3
|
|
|
4
4
|
type ForwardRefPolymorphic = <E extends ElementType, P extends { as?: E }>(
|
|
5
5
|
render: (props: P, ref: ComponentRef<E>) => React.ReactNode,
|
|
6
|
-
) => (props: P & { ref?: ComponentRef<E> }) => React.
|
|
6
|
+
) => (props: P & React.ComponentProps<E> & { ref?: ComponentRef<E> }) => React.JSX.Element;
|
|
7
7
|
|
|
8
8
|
/** Same as `React.forwardRef` but inferring Ref type from the `as` prop. */
|
|
9
|
-
/*#__NO_SIDE_EFFECTS__*/
|
|
10
9
|
export const forwardRefPolymorphic = React.forwardRef as ForwardRefPolymorphic;
|
package/src/utils/utils.test.ts
CHANGED
|
@@ -1,32 +1,5 @@
|
|
|
1
|
-
import partition from 'lodash/partition';
|
|
2
|
-
import { partitionMulti } from './partitionMulti';
|
|
3
1
|
import { isInternetExplorer } from './isInternetExplorer';
|
|
4
2
|
|
|
5
|
-
describe('partitionMulti', () => {
|
|
6
|
-
it('should act like partition for single predicate', () => {
|
|
7
|
-
const data = [0, 1, 2, 3, 4, 5];
|
|
8
|
-
const isEven = (n: number): boolean => n % 2 === 0;
|
|
9
|
-
|
|
10
|
-
const expected = partition(data, isEven);
|
|
11
|
-
const actual = partitionMulti(data, [isEven]);
|
|
12
|
-
|
|
13
|
-
expect(actual).toEqual(expected);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('should partition on multiple predicates', () => {
|
|
17
|
-
type T = string | number | boolean;
|
|
18
|
-
const data: T[] = ['a', 1, 'b', false, true];
|
|
19
|
-
const isString = (s: T): boolean => typeof s === 'string';
|
|
20
|
-
const isNumber = (s: T): boolean => typeof s === 'number';
|
|
21
|
-
|
|
22
|
-
const [strings, numbers, others] = partitionMulti(data, [isString, isNumber]);
|
|
23
|
-
|
|
24
|
-
expect(strings).toEqual(['a', 'b']);
|
|
25
|
-
expect(numbers).toEqual([1]);
|
|
26
|
-
expect(others).toEqual([false, true]);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
3
|
describe('isInternetExplorer', () => {
|
|
31
4
|
it('should detect IE 10', () => {
|
|
32
5
|
const userAgentIE10 = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)';
|
package/utils/index.d.ts
CHANGED
package/utils/index.js
CHANGED
|
@@ -1,97 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import isEmpty from 'lodash/isEmpty';
|
|
3
|
-
|
|
4
|
-
const EVENT_TYPES = ['mousedown', 'touchstart'];
|
|
5
|
-
function isClickAway(target, refs) {
|
|
6
|
-
// The target element is not contained in any of the listed element references.
|
|
7
|
-
return !refs.some(e => {
|
|
8
|
-
var _e$current;
|
|
9
|
-
return e === null || e === void 0 ? void 0 : (_e$current = e.current) === null || _e$current === void 0 ? void 0 : _e$current.contains(target);
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Listen to clicks away from the given elements and callback the passed in function.
|
|
14
|
-
*
|
|
15
|
-
* Warning: If you need to detect click away on nested React portals, please use the `ClickAwayProvider` component.
|
|
16
|
-
*/
|
|
17
|
-
function useClickAway(_ref) {
|
|
18
|
-
let {
|
|
19
|
-
callback,
|
|
20
|
-
childrenRefs
|
|
21
|
-
} = _ref;
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
const {
|
|
24
|
-
current: currentRefs
|
|
25
|
-
} = childrenRefs;
|
|
26
|
-
if (!callback || !currentRefs || isEmpty(currentRefs)) {
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
const listener = evt => {
|
|
30
|
-
if (isClickAway(evt.target, currentRefs)) {
|
|
31
|
-
callback(evt);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
EVENT_TYPES.forEach(evtType => document.addEventListener(evtType, listener));
|
|
35
|
-
return () => {
|
|
36
|
-
EVENT_TYPES.forEach(evtType => document.removeEventListener(evtType, listener));
|
|
37
|
-
};
|
|
38
|
-
}, [callback, childrenRefs]);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const ClickAwayAncestorContext = /*#__PURE__*/createContext(null);
|
|
42
|
-
/**
|
|
43
|
-
* Component combining the `useClickAway` hook with a React context to hook into the React component tree and make sure
|
|
44
|
-
* we take into account both the DOM tree and the React tree to detect click away.
|
|
45
|
-
*
|
|
46
|
-
* @return the react component.
|
|
47
|
-
*/
|
|
48
|
-
const ClickAwayProvider = _ref => {
|
|
49
|
-
let {
|
|
50
|
-
children,
|
|
51
|
-
callback,
|
|
52
|
-
childrenRefs,
|
|
53
|
-
parentRef
|
|
54
|
-
} = _ref;
|
|
55
|
-
const parentContext = useContext(ClickAwayAncestorContext);
|
|
56
|
-
const currentContext = useMemo(() => {
|
|
57
|
-
const context = {
|
|
58
|
-
childrenRefs: [],
|
|
59
|
-
/**
|
|
60
|
-
* Add element refs to the current context and propagate to the parent context.
|
|
61
|
-
*/
|
|
62
|
-
addRefs() {
|
|
63
|
-
// Add element refs that should be considered as inside the click away context.
|
|
64
|
-
context.childrenRefs.push(...arguments);
|
|
65
|
-
if (parentContext) {
|
|
66
|
-
// Also add then to the parent context
|
|
67
|
-
parentContext.addRefs(...arguments);
|
|
68
|
-
if (parentRef) {
|
|
69
|
-
// The parent element is also considered as inside the parent click away context but not inside the current context
|
|
70
|
-
parentContext.addRefs(parentRef);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
return context;
|
|
76
|
-
}, [parentContext, parentRef]);
|
|
77
|
-
useEffect(() => {
|
|
78
|
-
const {
|
|
79
|
-
current: currentRefs
|
|
80
|
-
} = childrenRefs;
|
|
81
|
-
if (!currentRefs) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
currentContext.addRefs(...currentRefs);
|
|
85
|
-
}, [currentContext, childrenRefs]);
|
|
86
|
-
useClickAway({
|
|
87
|
-
callback,
|
|
88
|
-
childrenRefs: useRef(currentContext.childrenRefs)
|
|
89
|
-
});
|
|
90
|
-
return /*#__PURE__*/React__default.createElement(ClickAwayAncestorContext.Provider, {
|
|
91
|
-
value: currentContext
|
|
92
|
-
}, children);
|
|
93
|
-
};
|
|
94
|
-
ClickAwayProvider.displayName = 'ClickAwayProvider';
|
|
95
|
-
|
|
96
|
-
export { ClickAwayProvider };
|
|
1
|
+
export { C as ClickAwayProvider } from '../_internal/index.js';
|
|
97
2
|
//# sourceMappingURL=index.js.map
|
package/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/_internal/17c3ea1d.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { i as forwardRef, j as _objectWithoutProperties, E as Emphasis, T as Theme, C as ColorPalette, k as _objectSpread2, g as classNames, _ as _extends, l as CSS_PREFIX } from './1da25128.js';
|
|
2
|
-
import React__default from 'react';
|
|
3
|
-
import isEmpty from 'lodash/isEmpty';
|
|
4
|
-
import 'lodash/kebabCase';
|
|
5
|
-
import { h as handleBasicClasses } from './f57e1239.js';
|
|
6
|
-
import { r as renderLink } from './2c5dbb03.js';
|
|
7
|
-
|
|
8
|
-
const _excluded = ["aria-label", "children", "className", "color", "disabled", "emphasis", "hasBackground", "href", "isDisabled", "isSelected", "isActive", "isFocused", "isHovered", "linkAs", "name", "size", "target", "theme", "variant", "type", "fullWidth"];
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Button size definition.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Component display name.
|
|
16
|
-
*/
|
|
17
|
-
const COMPONENT_NAME = 'ButtonRoot';
|
|
18
|
-
const BUTTON_WRAPPER_CLASSNAME = `${CSS_PREFIX}-button-wrapper`;
|
|
19
|
-
const BUTTON_CLASSNAME = `${CSS_PREFIX}-button`;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Render a button wrapper with the ButtonRoot inside.
|
|
23
|
-
*
|
|
24
|
-
* @param props Component props.
|
|
25
|
-
* @return React element.
|
|
26
|
-
*/
|
|
27
|
-
const renderButtonWrapper = props => {
|
|
28
|
-
const {
|
|
29
|
-
color,
|
|
30
|
-
emphasis,
|
|
31
|
-
variant,
|
|
32
|
-
fullWidth
|
|
33
|
-
} = props;
|
|
34
|
-
const adaptedColor = emphasis === Emphasis.low && (color === ColorPalette.light ? ColorPalette.dark : ColorPalette.light);
|
|
35
|
-
const wrapperClassName = classNames(handleBasicClasses({
|
|
36
|
-
color: adaptedColor,
|
|
37
|
-
prefix: BUTTON_WRAPPER_CLASSNAME,
|
|
38
|
-
variant,
|
|
39
|
-
fullWidth
|
|
40
|
-
}));
|
|
41
|
-
const buttonProps = _objectSpread2(_objectSpread2({}, props), {}, {
|
|
42
|
-
hasBackground: false
|
|
43
|
-
});
|
|
44
|
-
return /*#__PURE__*/React__default.createElement("div", {
|
|
45
|
-
className: wrapperClassName
|
|
46
|
-
}, /*#__PURE__*/React__default.createElement(ButtonRoot, buttonProps));
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* ButtonRoot component.
|
|
51
|
-
*
|
|
52
|
-
* @param props Component props.
|
|
53
|
-
* @param ref Component ref.
|
|
54
|
-
* @return React element.
|
|
55
|
-
*/
|
|
56
|
-
const ButtonRoot = forwardRef((props, ref) => {
|
|
57
|
-
const {
|
|
58
|
-
'aria-label': ariaLabel,
|
|
59
|
-
children,
|
|
60
|
-
className,
|
|
61
|
-
color,
|
|
62
|
-
disabled,
|
|
63
|
-
emphasis,
|
|
64
|
-
hasBackground,
|
|
65
|
-
href,
|
|
66
|
-
isDisabled = disabled,
|
|
67
|
-
isSelected,
|
|
68
|
-
isActive,
|
|
69
|
-
isFocused,
|
|
70
|
-
isHovered,
|
|
71
|
-
linkAs,
|
|
72
|
-
name,
|
|
73
|
-
size,
|
|
74
|
-
target,
|
|
75
|
-
theme,
|
|
76
|
-
variant,
|
|
77
|
-
type = 'button',
|
|
78
|
-
fullWidth
|
|
79
|
-
} = props,
|
|
80
|
-
forwardedProps = _objectWithoutProperties(props, _excluded);
|
|
81
|
-
const adaptedColor = color || emphasis !== Emphasis.high && theme === Theme.dark && ColorPalette.light || emphasis === Emphasis.high && ColorPalette.primary || ColorPalette.dark;
|
|
82
|
-
if (hasBackground) {
|
|
83
|
-
return renderButtonWrapper(_objectSpread2(_objectSpread2({}, props), {}, {
|
|
84
|
-
ref,
|
|
85
|
-
variant,
|
|
86
|
-
color: adaptedColor
|
|
87
|
-
}));
|
|
88
|
-
}
|
|
89
|
-
const buttonClassName = classNames(className, handleBasicClasses({
|
|
90
|
-
color: adaptedColor,
|
|
91
|
-
emphasis,
|
|
92
|
-
isSelected,
|
|
93
|
-
isDisabled,
|
|
94
|
-
isActive,
|
|
95
|
-
isFocused,
|
|
96
|
-
isHovered,
|
|
97
|
-
prefix: BUTTON_CLASSNAME,
|
|
98
|
-
size,
|
|
99
|
-
theme: emphasis === Emphasis.high && theme,
|
|
100
|
-
variant,
|
|
101
|
-
fullWidth
|
|
102
|
-
}));
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* If the linkAs prop is used, we use the linkAs component instead of a <button>.
|
|
106
|
-
* If there is an href attribute, we display an <a> instead of a <button>.
|
|
107
|
-
*
|
|
108
|
-
* However, in any case, if the component is disabled, we returned a <button> since disabled is not compatible with <a>.
|
|
109
|
-
*/
|
|
110
|
-
if ((linkAs || !isEmpty(props.href)) && !isDisabled) {
|
|
111
|
-
return renderLink(_objectSpread2(_objectSpread2({
|
|
112
|
-
linkAs
|
|
113
|
-
}, forwardedProps), {}, {
|
|
114
|
-
'aria-label': ariaLabel,
|
|
115
|
-
href,
|
|
116
|
-
target,
|
|
117
|
-
className: buttonClassName,
|
|
118
|
-
ref: ref
|
|
119
|
-
}), children);
|
|
120
|
-
}
|
|
121
|
-
return /*#__PURE__*/React__default.createElement("button", _extends({}, forwardedProps, {
|
|
122
|
-
disabled: isDisabled,
|
|
123
|
-
"aria-disabled": isDisabled,
|
|
124
|
-
"aria-label": ariaLabel,
|
|
125
|
-
ref: ref,
|
|
126
|
-
className: buttonClassName,
|
|
127
|
-
name: name,
|
|
128
|
-
type:
|
|
129
|
-
// eslint-disable-next-line react/button-has-type
|
|
130
|
-
type
|
|
131
|
-
}), children);
|
|
132
|
-
});
|
|
133
|
-
ButtonRoot.displayName = COMPONENT_NAME;
|
|
134
|
-
ButtonRoot.defaultProps = {};
|
|
135
|
-
|
|
136
|
-
export { ButtonRoot as B };
|
|
137
|
-
//# sourceMappingURL=17c3ea1d.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"17c3ea1d.js","sources":["../../src/components/button/ButtonRoot.tsx"],"sourcesContent":["import React, { AriaAttributes, ButtonHTMLAttributes, DetailedHTMLProps, RefObject } from 'react';\n\nimport isEmpty from 'lodash/isEmpty';\n\nimport classNames from 'classnames';\n\nimport { ColorPalette, Emphasis, Size, Theme } from '@lumx/react';\nimport { CSS_PREFIX } from '@lumx/react/constants';\nimport { GenericProps, HasTheme } from '@lumx/react/utils/type';\nimport { handleBasicClasses } from '@lumx/react/utils/className';\nimport { renderLink } from '@lumx/react/utils/renderLink';\nimport { forwardRef } from '@lumx/react/utils/react/forwardRef';\n\ntype HTMLButtonProps = DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>;\n\n/**\n * Button size definition.\n */\nexport type ButtonSize = Extract<Size, 's' | 'm'>;\n\nexport interface BaseButtonProps\n extends GenericProps,\n Pick<AriaAttributes, 'aria-expanded' | 'aria-haspopup' | 'aria-pressed' | 'aria-label'>,\n HasTheme {\n /** Color variant. */\n color?: ColorPalette;\n /** Emphasis variant. */\n emphasis?: Emphasis;\n /** Whether or not the button has a background color in low emphasis. */\n hasBackground?: boolean;\n /** Native anchor href property. It determines whether the Button will be a <button> or an <a>. */\n href?: string;\n /** Whether the component is disabled or not. */\n isDisabled?: boolean;\n /** Whether the component is selected or not (unsupported in `high` emphasis). */\n isSelected?: boolean;\n /** Native button name property. */\n name?: string;\n /** Size variant. */\n size?: ButtonSize;\n /** Native anchor target property. */\n target?: '_self' | '_blank' | '_parent' | '_top';\n /** Native button type. */\n type?: HTMLButtonProps['type'];\n /** Custom react component for the link (can be used to inject react router Link). */\n linkAs?: 'a' | any;\n}\n\nexport interface ButtonRootProps extends BaseButtonProps {\n variant: 'button' | 'icon';\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'ButtonRoot';\n\nexport const BUTTON_WRAPPER_CLASSNAME = `${CSS_PREFIX}-button-wrapper`;\nexport const BUTTON_CLASSNAME = `${CSS_PREFIX}-button`;\n\n/**\n * Render a button wrapper with the ButtonRoot inside.\n *\n * @param props Component props.\n * @return React element.\n */\nconst renderButtonWrapper: React.FC<ButtonRootProps> = (props) => {\n const { color, emphasis, variant, fullWidth } = props;\n\n const adaptedColor =\n emphasis === Emphasis.low && (color === ColorPalette.light ? ColorPalette.dark : ColorPalette.light);\n\n const wrapperClassName = classNames(\n handleBasicClasses({\n color: adaptedColor,\n prefix: BUTTON_WRAPPER_CLASSNAME,\n variant,\n fullWidth,\n }),\n );\n const buttonProps = { ...props, hasBackground: false };\n\n return (\n <div className={wrapperClassName}>\n {/* eslint-disable-next-line @typescript-eslint/no-use-before-define */}\n <ButtonRoot {...buttonProps} />\n </div>\n );\n};\n\n/**\n * ButtonRoot component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const ButtonRoot = forwardRef<ButtonRootProps, HTMLButtonElement | HTMLAnchorElement>((props, ref) => {\n const {\n 'aria-label': ariaLabel,\n children,\n className,\n color,\n disabled,\n emphasis,\n hasBackground,\n href,\n isDisabled = disabled,\n isSelected,\n isActive,\n isFocused,\n isHovered,\n linkAs,\n name,\n size,\n target,\n theme,\n variant,\n type = 'button',\n fullWidth,\n ...forwardedProps\n } = props;\n\n const adaptedColor =\n color ||\n (emphasis !== Emphasis.high && theme === Theme.dark && ColorPalette.light) ||\n (emphasis === Emphasis.high && ColorPalette.primary) ||\n ColorPalette.dark;\n\n if (hasBackground) {\n return renderButtonWrapper({ ...props, ref, variant, color: adaptedColor });\n }\n\n const buttonClassName = classNames(\n className,\n handleBasicClasses({\n color: adaptedColor,\n emphasis,\n isSelected,\n isDisabled,\n isActive,\n isFocused,\n isHovered,\n prefix: BUTTON_CLASSNAME,\n size,\n theme: emphasis === Emphasis.high && theme,\n variant,\n fullWidth,\n }),\n );\n\n /**\n * If the linkAs prop is used, we use the linkAs component instead of a <button>.\n * If there is an href attribute, we display an <a> instead of a <button>.\n *\n * However, in any case, if the component is disabled, we returned a <button> since disabled is not compatible with <a>.\n */\n if ((linkAs || !isEmpty(props.href)) && !isDisabled) {\n return renderLink(\n {\n linkAs,\n ...forwardedProps,\n 'aria-label': ariaLabel,\n href,\n target,\n className: buttonClassName,\n ref: ref as RefObject<HTMLAnchorElement>,\n },\n children,\n );\n }\n return (\n <button\n {...forwardedProps}\n disabled={isDisabled}\n aria-disabled={isDisabled}\n aria-label={ariaLabel}\n ref={ref as RefObject<HTMLButtonElement>}\n className={buttonClassName}\n name={name}\n type={\n // eslint-disable-next-line react/button-has-type\n type\n }\n >\n {children}\n </button>\n );\n});\nButtonRoot.displayName = COMPONENT_NAME;\nButtonRoot.defaultProps = {};\n"],"names":["COMPONENT_NAME","BUTTON_WRAPPER_CLASSNAME","CSS_PREFIX","BUTTON_CLASSNAME","renderButtonWrapper","props","color","emphasis","variant","fullWidth","adaptedColor","Emphasis","low","ColorPalette","light","dark","wrapperClassName","classNames","handleBasicClasses","prefix","buttonProps","_objectSpread","hasBackground","React","createElement","className","ButtonRoot","forwardRef","ref","ariaLabel","children","disabled","href","isDisabled","isSelected","isActive","isFocused","isHovered","linkAs","name","size","target","theme","type","forwardedProps","_objectWithoutProperties","_excluded","high","Theme","primary","buttonClassName","isEmpty","renderLink","_extends","displayName","defaultProps"],"mappings":";;;;;;;;;AAeA;AACA;AACA;;AAmCA;AACA;AACA;AACA,MAAMA,cAAc,GAAG,YAAY,CAAA;AAE5B,MAAMC,wBAAwB,GAAI,CAAA,EAAEC,UAAW,CAAgB,eAAA,CAAA,CA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