@loadsmart/loadsmart-ui 6.0.14 → 6.0.15
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/components/Banner/Banner.d.ts +4 -4
- package/dist/components/Banner/Banner.stories.d.ts +2 -1
- package/dist/components/Button/Button.stories.d.ts +3 -2
- package/dist/components/DatePicker/useDatePicker.d.ts +8 -2
- package/dist/components/DatePicker/useDateRangePicker.d.ts +12 -3
- package/dist/components/Dialog/Dialog.d.ts +4 -4
- package/dist/components/DragDropFile/DragDropFile.d.ts +2 -1
- package/dist/components/DragDropFile/components/Wrapper.d.ts +2 -1
- package/dist/components/DragDropFile/styles.d.ts +3 -2
- package/dist/components/ErrorMessage/ErrorMessage.d.ts +2 -1
- package/dist/components/Modal/Modal.d.ts +1 -1
- package/dist/components/Popover/Popover.types.d.ts +6 -8
- package/dist/components/Section/Section.d.ts +2 -2
- package/dist/components/SideNavigation/Menu/Menu.d.ts +1 -1
- package/dist/components/SideNavigation/SideNavigation.d.ts +1 -1
- package/dist/components/Tabs/Tabs.d.ts +5 -5
- package/dist/components/Tag/Tag.stories.d.ts +2 -1
- package/dist/index.js +189 -186
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/components/Dropdown/Dropdown.test.tsx +1 -1
- package/src/components/Dropdown/DropdownMenu.tsx +3 -0
- package/src/components/Popover/Popover.test.tsx +1 -2
- package/src/components/Popover/Popover.tsx +25 -68
- package/src/components/Popover/Popover.types.ts +6 -8
- package/src/components/Select/SelectTrigger.tsx +1 -8
- package/src/components/Tooltip/Tooltip.tsx +1 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loadsmart/loadsmart-ui",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.15",
|
|
4
4
|
"description": "Miranda UI, a React UI library",
|
|
5
5
|
"main": "dist",
|
|
6
6
|
"files": [
|
|
@@ -78,10 +78,10 @@
|
|
|
78
78
|
"@types/lodash.range": "^3.2.6",
|
|
79
79
|
"@types/mdx": "^2.0.2",
|
|
80
80
|
"@types/node": "^18.11.18",
|
|
81
|
-
"@types/react": "^17.0.
|
|
82
|
-
"@types/react-dom": "^17.0.
|
|
81
|
+
"@types/react": "^17.0.59",
|
|
82
|
+
"@types/react-dom": "^17.0.20",
|
|
83
83
|
"@types/react-test-renderer": "^17.0.1",
|
|
84
|
-
"@types/styled-components": "^5.1.
|
|
84
|
+
"@types/styled-components": "^5.1.26",
|
|
85
85
|
"@typescript-eslint/eslint-plugin": "^4.22.1",
|
|
86
86
|
"@typescript-eslint/parser": "^4.22.1",
|
|
87
87
|
"@zerollup/ts-transform-paths": "^1.7.18",
|
|
@@ -149,7 +149,7 @@
|
|
|
149
149
|
"styled-components": ">=5.3.0"
|
|
150
150
|
},
|
|
151
151
|
"dependencies": {
|
|
152
|
-
"@floating-ui/react-dom": "^
|
|
152
|
+
"@floating-ui/react-dom": "^2.0.0",
|
|
153
153
|
"@loadsmart/utils-function": "0.3.1",
|
|
154
154
|
"@loadsmart/utils-object": "0.3.1",
|
|
155
155
|
"@loadsmart/utils-string": "0.3.1",
|
|
@@ -10,7 +10,7 @@ const { Playground, WithSections, Extended } = composeStories(stories)
|
|
|
10
10
|
|
|
11
11
|
describe('Dropdown', () => {
|
|
12
12
|
describe('Generic', () => {
|
|
13
|
-
const setup = (overrides?: stories.DropdownStoryProps) =>
|
|
13
|
+
const setup = (overrides?: Partial<stories.DropdownStoryProps>) =>
|
|
14
14
|
renderer(<Playground {...overrides} />).render()
|
|
15
15
|
|
|
16
16
|
it('starts collapsed', () => {
|
|
@@ -32,6 +32,7 @@ const StyledPopover = styled(Popover.Floating)`
|
|
|
32
32
|
border: 1px solid ${token('dropdown-border-color')};
|
|
33
33
|
border-radius: ${token('dropdown-border-radius')};
|
|
34
34
|
box-shadow: ${token('dropdown-shadow')};
|
|
35
|
+
width: max-content;
|
|
35
36
|
`
|
|
36
37
|
|
|
37
38
|
const StyledSpan = styled.span`
|
|
@@ -154,6 +155,8 @@ const GenericDropdownMenuWrapper = styled.div`
|
|
|
154
155
|
const DropdownMenuWrapper = styled(GenericDropdownMenuWrapper)`
|
|
155
156
|
max-height: 240px;
|
|
156
157
|
overflow-y: auto;
|
|
158
|
+
max-width: 100%;
|
|
159
|
+
width: 100%;
|
|
157
160
|
|
|
158
161
|
${DropdownItemWrapper} + ${DropdownItemWrapper},
|
|
159
162
|
${DropdownSectionHeader} + ${DropdownItemWrapper} {
|
|
@@ -4,8 +4,7 @@ import { composeStories } from '@storybook/testing-react'
|
|
|
4
4
|
import * as stories from './Popover.stories'
|
|
5
5
|
import generator from '../../tests/generator'
|
|
6
6
|
import renderer, { screen } from '../../tests/renderer'
|
|
7
|
-
|
|
8
|
-
import type { PopoverProps } from './Popover'
|
|
7
|
+
import type { PopoverProps } from './Popover.types'
|
|
9
8
|
|
|
10
9
|
const { Playground } = composeStories(stories)
|
|
11
10
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import React, { useMemo } from 'react'
|
|
2
|
-
import { useFloating, autoUpdate } from '@floating-ui/react-dom'
|
|
3
|
-
import {
|
|
4
|
-
import type { Placement, MiddlewareState } from '@floating-ui/core'
|
|
1
|
+
import React, { CSSProperties, useMemo, useRef } from 'react'
|
|
2
|
+
import { useFloating, offset, flip, shift, arrow, autoUpdate } from '@floating-ui/react-dom'
|
|
3
|
+
import type { Placement } from '@floating-ui/react-dom'
|
|
5
4
|
|
|
6
5
|
import type {
|
|
7
6
|
PopoverAlign,
|
|
@@ -25,75 +24,50 @@ export function usePopover(): UsePopoverReturn {
|
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
function Popover(props: PopoverProps): JSX.Element {
|
|
28
|
-
const arrowRef =
|
|
27
|
+
const arrowRef = useRef<HTMLElement | null>(null)
|
|
29
28
|
|
|
30
29
|
const { position = 'bottom', align = 'start', strategy = 'fixed' } = props
|
|
31
30
|
|
|
32
|
-
const desiredPlacement = `${position}${
|
|
31
|
+
const desiredPlacement: Placement = `${position}${
|
|
32
|
+
align === 'center' ? '' : `-${align}`
|
|
33
|
+
}` as Placement
|
|
33
34
|
|
|
34
|
-
const
|
|
35
|
+
const floating = useFloating({
|
|
35
36
|
placement: desiredPlacement,
|
|
36
37
|
strategy,
|
|
37
|
-
middleware: [
|
|
38
|
-
offset(10),
|
|
39
|
-
flip(),
|
|
40
|
-
shift(),
|
|
41
|
-
{
|
|
42
|
-
name: 'arrow',
|
|
43
|
-
fn(args: MiddlewareState) {
|
|
44
|
-
if (arrowRef.current) {
|
|
45
|
-
return arrow({ element: arrowRef.current, padding: 8 }).fn(args)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return {}
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
],
|
|
38
|
+
middleware: [offset(10), flip(), shift(), arrow({ element: arrowRef, padding: 8 })],
|
|
52
39
|
// TODO: FloatingUI docs states that `autoUpdate` is expensive.
|
|
53
40
|
// This should be properly investidated since it's the way to
|
|
54
41
|
// update fixed positions after scrolling.
|
|
55
42
|
whileElementsMounted: autoUpdate,
|
|
56
43
|
})
|
|
57
44
|
|
|
58
|
-
const
|
|
59
|
-
(node: HTMLElement) => {
|
|
60
|
-
arrowRef.current = node
|
|
61
|
-
result.update()
|
|
62
|
-
},
|
|
63
|
-
[result]
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
const [resultPosition = position, resultAlign = align] = result.placement.split('-') as [
|
|
45
|
+
const [resultPosition = position, resultAlign = align] = floating.placement.split('-') as [
|
|
67
46
|
PopoverPosition,
|
|
68
47
|
PopoverAlign
|
|
69
48
|
]
|
|
70
49
|
|
|
71
|
-
const value = useMemo(
|
|
50
|
+
const value = useMemo<UsePopoverReturn>(
|
|
72
51
|
() => ({
|
|
73
52
|
strategy,
|
|
74
53
|
register: {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
54
|
+
setReference: floating.refs.setReference,
|
|
55
|
+
setFloating: floating.refs.setFloating,
|
|
56
|
+
setArrow: arrowRef,
|
|
78
57
|
},
|
|
79
58
|
result: {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
left: result.x ?? 0,
|
|
83
|
-
},
|
|
84
|
-
arrow: { top: result.middlewareData.arrow?.y, left: result.middlewareData.arrow?.x },
|
|
59
|
+
floatingStyles: floating.floatingStyles,
|
|
60
|
+
arrow: { top: floating.middlewareData.arrow?.y, left: floating.middlewareData.arrow?.x },
|
|
85
61
|
position: resultPosition,
|
|
86
62
|
align: resultAlign,
|
|
87
63
|
},
|
|
88
64
|
}),
|
|
89
65
|
[
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
result.x,
|
|
96
|
-
result.y,
|
|
66
|
+
floating.refs.setFloating,
|
|
67
|
+
floating.middlewareData.arrow?.x,
|
|
68
|
+
floating.middlewareData.arrow?.y,
|
|
69
|
+
floating.refs.setReference,
|
|
70
|
+
floating.floatingStyles,
|
|
97
71
|
resultAlign,
|
|
98
72
|
resultPosition,
|
|
99
73
|
strategy,
|
|
@@ -104,41 +78,24 @@ function Popover(props: PopoverProps): JSX.Element {
|
|
|
104
78
|
}
|
|
105
79
|
|
|
106
80
|
function PopoverReference({ children, ...others }: PopoverReferenceProps): JSX.Element {
|
|
107
|
-
const ref = React.useRef<HTMLDivElement | null>(null)
|
|
108
81
|
const { register } = usePopover()
|
|
109
82
|
|
|
110
|
-
React.useLayoutEffect(() => {
|
|
111
|
-
if (ref.current) {
|
|
112
|
-
register.reference(ref.current)
|
|
113
|
-
}
|
|
114
|
-
}, [register])
|
|
115
|
-
|
|
116
83
|
return (
|
|
117
|
-
<div ref={
|
|
84
|
+
<div ref={register.setReference} {...others}>
|
|
118
85
|
{children}
|
|
119
86
|
</div>
|
|
120
87
|
)
|
|
121
88
|
}
|
|
122
89
|
|
|
123
90
|
function PopoverFloating({ children, style, ...others }: PopoverFloatingProps): JSX.Element {
|
|
124
|
-
const { register, result
|
|
125
|
-
|
|
126
|
-
const ref = React.useRef<HTMLDivElement | null>(null)
|
|
127
|
-
|
|
128
|
-
React.useLayoutEffect(() => {
|
|
129
|
-
if (ref.current) {
|
|
130
|
-
register.floating(ref.current)
|
|
131
|
-
}
|
|
132
|
-
}, [register])
|
|
91
|
+
const { register, result } = usePopover()
|
|
133
92
|
|
|
134
93
|
return (
|
|
135
94
|
<div
|
|
136
|
-
ref={
|
|
95
|
+
ref={register.setFloating}
|
|
137
96
|
{...others}
|
|
138
97
|
style={{
|
|
139
|
-
|
|
140
|
-
top: result.floating.top,
|
|
141
|
-
left: result.floating.left,
|
|
98
|
+
...result.floatingStyles,
|
|
142
99
|
...style,
|
|
143
100
|
}}
|
|
144
101
|
>
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { UseFloatingReturn } from '@floating-ui/react-dom'
|
|
2
|
+
import type { CSSProperties, HTMLAttributes, MutableRefObject, PropsWithChildren } from 'react'
|
|
2
3
|
|
|
3
4
|
export interface UsePopoverReturn {
|
|
4
5
|
register: {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
setReference: UseFloatingReturn['refs']['setReference']
|
|
7
|
+
setFloating: UseFloatingReturn['refs']['setFloating']
|
|
8
|
+
setArrow: MutableRefObject<Element | null>
|
|
8
9
|
}
|
|
9
10
|
result: {
|
|
10
|
-
|
|
11
|
-
top: number
|
|
12
|
-
left: number
|
|
13
|
-
}
|
|
11
|
+
floatingStyles: CSSProperties
|
|
14
12
|
arrow: {
|
|
15
13
|
top: number | undefined
|
|
16
14
|
left: number | undefined
|
|
@@ -49,16 +49,9 @@ const SelectTrigger = forwardRef<HTMLInputElement, SelectTriggerProps>(function
|
|
|
49
49
|
) {
|
|
50
50
|
const { className, ...others } = props
|
|
51
51
|
const { disabled, expanded, toggle } = useContext(DropdownContext)
|
|
52
|
-
const triggerRef = React.useRef<HTMLElement | null>(null)
|
|
53
52
|
|
|
54
53
|
const { register } = usePopover()
|
|
55
54
|
|
|
56
|
-
React.useEffect(() => {
|
|
57
|
-
if (triggerRef.current) {
|
|
58
|
-
register.reference(triggerRef.current)
|
|
59
|
-
}
|
|
60
|
-
}, [register])
|
|
61
|
-
|
|
62
55
|
function handleClick() {
|
|
63
56
|
if (!expanded) {
|
|
64
57
|
toggle()
|
|
@@ -75,7 +68,7 @@ const SelectTrigger = forwardRef<HTMLInputElement, SelectTriggerProps>(function
|
|
|
75
68
|
ref(node)
|
|
76
69
|
}
|
|
77
70
|
|
|
78
|
-
|
|
71
|
+
register.setReference(node)
|
|
79
72
|
}}
|
|
80
73
|
type="search"
|
|
81
74
|
disabled={disabled}
|
|
@@ -129,17 +129,10 @@ const StyledArrow = styled.span<ArrowProps>`
|
|
|
129
129
|
|
|
130
130
|
function Arrow() {
|
|
131
131
|
const { register, result } = usePopover()
|
|
132
|
-
const ref = React.useRef<HTMLDivElement | null>(null)
|
|
133
|
-
|
|
134
|
-
React.useLayoutEffect(() => {
|
|
135
|
-
if (ref.current) {
|
|
136
|
-
register.arrow(ref.current)
|
|
137
|
-
}
|
|
138
|
-
}, [register])
|
|
139
132
|
|
|
140
133
|
return (
|
|
141
134
|
<StyledArrow
|
|
142
|
-
ref={
|
|
135
|
+
ref={(element) => (register.setArrow.current = element)}
|
|
143
136
|
position={result.position}
|
|
144
137
|
top={result.arrow.top}
|
|
145
138
|
left={result.arrow.left}
|