@planningcenter/tapestry-react 2.1.2 → 2.2.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/cjs/Badge/Badge.js +5 -1
- package/dist/cjs/Card/Card.js +5 -2
- package/dist/cjs/Combobox/Combobox.js +16 -43
- package/dist/cjs/Combobox/ComboboxInput.js +112 -146
- package/dist/cjs/Combobox/ComboboxItem.js +38 -53
- package/dist/cjs/Combobox/ComboboxItems.js +41 -58
- package/dist/cjs/Combobox/index.js +12 -0
- package/dist/cjs/DateField/DateField.js +109 -128
- package/dist/cjs/Field/Field.js +80 -106
- package/dist/cjs/Menu/Item.js +1 -0
- package/dist/cjs/Popover/utils.js +1 -0
- package/dist/cjs/SegmentedControl/SegmentedControl.js +89 -111
- package/dist/cjs/SegmentedTabs/SegmentedTabs.js +54 -84
- package/dist/cjs/Tabs/Tab.js +9 -6
- package/dist/cjs/Tabs/TabList.js +49 -64
- package/dist/cjs/Tabs/TabPanel.js +6 -2
- package/dist/cjs/Tabs/TabPanels.js +14 -27
- package/dist/cjs/Tabs/Tabs.js +72 -106
- package/dist/cjs/Tabs/index.js +12 -0
- package/dist/cjs/ThemeProvider/ThemeProvider.js +1 -1
- package/dist/cjs/Tooltip/Tooltip.js +158 -182
- package/dist/cjs/Wizard/Wizard.js +143 -193
- package/dist/cjs/Wizard/index.js +3 -0
- package/dist/esm/Badge/Badge.js +5 -1
- package/dist/esm/Card/Card.js +5 -2
- package/dist/esm/Combobox/Combobox.js +18 -43
- package/dist/esm/Combobox/ComboboxInput.js +111 -149
- package/dist/esm/Combobox/ComboboxItem.js +38 -52
- package/dist/esm/Combobox/ComboboxItems.js +38 -56
- package/dist/esm/Combobox/index.js +8 -0
- package/dist/esm/DateField/DateField.js +106 -133
- package/dist/esm/Field/Field.js +76 -103
- package/dist/esm/Menu/Item.js +1 -0
- package/dist/esm/Popover/utils.js +1 -0
- package/dist/esm/SegmentedControl/SegmentedControl.js +90 -114
- package/dist/esm/SegmentedTabs/SegmentedTabs.js +51 -83
- package/dist/esm/Tabs/Tab.js +8 -6
- package/dist/esm/Tabs/TabList.js +49 -66
- package/dist/esm/Tabs/TabPanel.js +4 -2
- package/dist/esm/Tabs/TabPanels.js +14 -28
- package/dist/esm/Tabs/Tabs.js +76 -120
- package/dist/esm/Tabs/index.js +8 -0
- package/dist/esm/ThemeProvider/ThemeProvider.js +1 -1
- package/dist/esm/Tooltip/Tooltip.js +154 -195
- package/dist/esm/Wizard/Wizard.js +144 -201
- package/dist/esm/Wizard/index.js +2 -0
- package/dist/types/Popover/utils.d.ts +3 -0
- package/package.json +1 -1
- package/src/.DS_Store +0 -0
- package/src/Badge/Badge.js +5 -0
- package/src/Card/Card.tsx +22 -1
- package/src/Combobox/Combobox.js +18 -32
- package/src/Combobox/Combobox.mdx +1 -0
- package/src/Combobox/Combobox.test.js +1 -1
- package/src/Combobox/ComboboxInput.js +111 -105
- package/src/Combobox/ComboboxItem.js +27 -27
- package/src/Combobox/ComboboxItems.js +38 -60
- package/src/Combobox/index.js +8 -0
- package/src/DateField/DateField.js +109 -105
- package/src/DateField/DateField.mdx +1 -0
- package/src/Field/Field.js +85 -93
- package/src/Field/Field.mdx +1 -0
- package/src/Menu/Heading.js +5 -1
- package/src/Menu/Heading.mdx +20 -0
- package/src/Menu/Item.js +13 -1
- package/src/Menu/Item.mdx +18 -0
- package/src/Menu/Menu.mdx +1 -0
- package/src/Popover/utils.ts +1 -0
- package/src/SegmentedControl/SegmentedControl.js +88 -92
- package/src/SegmentedControl/SegmentedControl.mdx +1 -0
- package/src/SegmentedTabs/SegmentedTabs.js +51 -71
- package/src/SegmentedTabs/SegmentedTabs.mdx +1 -0
- package/src/Tabs/Tab.js +3 -1
- package/src/Tabs/TabList.js +56 -62
- package/src/Tabs/TabPanel.js +2 -1
- package/src/Tabs/TabPanels.js +14 -15
- package/src/Tabs/Tabs.js +63 -84
- package/src/Tabs/Tabs.mdx +16 -17
- package/src/Tabs/index.js +8 -0
- package/src/ThemeProvider/ThemeProvider.tsx +1 -1
- package/src/Tooltip/Tooltip.js +142 -160
- package/src/Tooltip/Tooltip.mdx +1 -0
- package/src/Wizard/Wizard.js +141 -170
- package/src/Wizard/Wizard.mdx +3 -2
- package/src/Wizard/index.js +2 -0
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import React, {
|
|
2
|
+
import React, {
|
|
3
|
+
forwardRef,
|
|
4
|
+
useCallback,
|
|
5
|
+
useImperativeHandle,
|
|
6
|
+
useRef,
|
|
7
|
+
useContext,
|
|
8
|
+
useEffect,
|
|
9
|
+
} from 'react'
|
|
3
10
|
|
|
4
11
|
import Input from '../Input'
|
|
5
|
-
import
|
|
12
|
+
import ItemListContext from '../ItemList/ItemListContext'
|
|
13
|
+
import { useThemeProps } from '../system'
|
|
6
14
|
|
|
7
15
|
type Props = {
|
|
8
16
|
isOpen?: boolean,
|
|
@@ -11,126 +19,124 @@ type Props = {
|
|
|
11
19
|
onClear?: Function | boolean,
|
|
12
20
|
}
|
|
13
21
|
|
|
14
|
-
|
|
15
|
-
|
|
22
|
+
function ComboboxInput(props: Props, ref) {
|
|
23
|
+
const {
|
|
24
|
+
autoFocus,
|
|
25
|
+
defaultValue,
|
|
26
|
+
disabled,
|
|
27
|
+
innerRef,
|
|
28
|
+
isOpen,
|
|
29
|
+
isLoading,
|
|
30
|
+
name,
|
|
31
|
+
onBlur,
|
|
32
|
+
onChange,
|
|
33
|
+
onFocus,
|
|
34
|
+
onClear,
|
|
35
|
+
onClose,
|
|
36
|
+
onKeyDown,
|
|
37
|
+
onKeyUp,
|
|
38
|
+
placeholder,
|
|
39
|
+
readOnly,
|
|
40
|
+
size,
|
|
41
|
+
type,
|
|
42
|
+
value,
|
|
43
|
+
...restProps
|
|
44
|
+
} = useThemeProps('combobox.input', props)
|
|
45
|
+
const inputNode = useRef(null)
|
|
16
46
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
47
|
+
const focus = useCallback(
|
|
48
|
+
function () {
|
|
49
|
+
inputNode.current.focus()
|
|
50
|
+
},
|
|
51
|
+
[inputNode]
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
const blur = useCallback(
|
|
55
|
+
function () {
|
|
56
|
+
inputNode.current.blur()
|
|
57
|
+
},
|
|
58
|
+
[inputNode]
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
useImperativeHandle(ref, () => ({
|
|
62
|
+
focus,
|
|
63
|
+
blur,
|
|
64
|
+
}))
|
|
65
|
+
|
|
66
|
+
const itemList = useContext(ItemListContext)
|
|
67
|
+
const { highlightedItemId, id } = itemList
|
|
25
68
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
setTimeout(() => {
|
|
71
|
+
itemList.setHighlightedIndex(0)
|
|
72
|
+
})
|
|
73
|
+
}, [itemList.items])
|
|
29
74
|
|
|
30
|
-
handleKeyDown = (e) => {
|
|
75
|
+
const handleKeyDown = useCallback((e) => {
|
|
31
76
|
if (e.key === 'ArrowUp') {
|
|
32
77
|
e.preventDefault()
|
|
33
|
-
|
|
78
|
+
itemList.moveHighlightedIndex(-1, { contain: false })
|
|
34
79
|
}
|
|
35
80
|
if (e.key === 'ArrowDown') {
|
|
36
81
|
e.preventDefault()
|
|
37
|
-
|
|
82
|
+
itemList.moveHighlightedIndex(1, { contain: false })
|
|
38
83
|
}
|
|
39
84
|
if (e.key === 'Enter') {
|
|
40
85
|
e.preventDefault()
|
|
41
|
-
|
|
86
|
+
itemList.selectHighlightedItem()
|
|
42
87
|
}
|
|
43
|
-
if (
|
|
44
|
-
|
|
88
|
+
if (onKeyDown) {
|
|
89
|
+
onKeyDown(e)
|
|
45
90
|
}
|
|
46
|
-
if (
|
|
47
|
-
|
|
91
|
+
if (onClose && e.key === 'Tab') {
|
|
92
|
+
onClose()
|
|
48
93
|
}
|
|
49
|
-
}
|
|
94
|
+
})
|
|
50
95
|
|
|
51
|
-
handleDocumentKeyDown = (e) => {
|
|
52
|
-
if (
|
|
53
|
-
|
|
96
|
+
const handleDocumentKeyDown = useCallback((e) => {
|
|
97
|
+
if (onClear && e.key === 'Escape') {
|
|
98
|
+
onClear()
|
|
54
99
|
}
|
|
55
|
-
}
|
|
100
|
+
})
|
|
56
101
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
innerRef,
|
|
71
|
-
isOpen,
|
|
72
|
-
isLoading,
|
|
73
|
-
name,
|
|
74
|
-
onBlur,
|
|
75
|
-
onChange,
|
|
76
|
-
onFocus,
|
|
77
|
-
onClear,
|
|
78
|
-
onClose,
|
|
79
|
-
onKeyDown,
|
|
80
|
-
onKeyUp,
|
|
81
|
-
placeholder,
|
|
82
|
-
readOnly,
|
|
83
|
-
size,
|
|
84
|
-
type,
|
|
85
|
-
value,
|
|
86
|
-
...restProps
|
|
87
|
-
} = this.props
|
|
88
|
-
return (
|
|
89
|
-
<ItemListController>
|
|
90
|
-
{(itemList) => {
|
|
91
|
-
const { highlightedItemId, id } = itemList
|
|
92
|
-
if (!this.itemList) {
|
|
93
|
-
this.itemList = itemList
|
|
94
|
-
}
|
|
95
|
-
return (
|
|
96
|
-
<Input.InputBox
|
|
97
|
-
innerRef={innerRef}
|
|
98
|
-
size={size}
|
|
99
|
-
disabled={disabled}
|
|
100
|
-
isLoading={isLoading}
|
|
101
|
-
onClear={onClear}
|
|
102
|
-
{...restProps}
|
|
103
|
-
grow={1}
|
|
104
|
-
>
|
|
105
|
-
<Input.InputField
|
|
106
|
-
innerRef={this.setInputNode}
|
|
107
|
-
grow={1}
|
|
108
|
-
role="combobox"
|
|
109
|
-
autoComplete="off"
|
|
110
|
-
aria-autocomplete="list"
|
|
111
|
-
aria-controls={id}
|
|
112
|
-
aria-expanded={isOpen}
|
|
113
|
-
aria-activedescendant={highlightedItemId}
|
|
114
|
-
autoFocus={autoFocus}
|
|
115
|
-
type={type}
|
|
116
|
-
name={name}
|
|
117
|
-
disabled={disabled}
|
|
118
|
-
readOnly={readOnly}
|
|
119
|
-
placeholder={placeholder}
|
|
120
|
-
defaultValue={defaultValue}
|
|
121
|
-
value={value}
|
|
122
|
-
onChange={onChange}
|
|
123
|
-
onFocus={onFocus}
|
|
124
|
-
onBlur={onBlur}
|
|
125
|
-
onKeyDown={this.handleKeyDown}
|
|
126
|
-
onKeyUp={onKeyUp}
|
|
127
|
-
/>
|
|
128
|
-
</Input.InputBox>
|
|
129
|
-
)
|
|
102
|
+
return (
|
|
103
|
+
<Input.InputBox
|
|
104
|
+
innerRef={innerRef}
|
|
105
|
+
size={size}
|
|
106
|
+
disabled={disabled}
|
|
107
|
+
isLoading={isLoading}
|
|
108
|
+
onClear={onClear}
|
|
109
|
+
{...restProps}
|
|
110
|
+
grow={1}
|
|
111
|
+
>
|
|
112
|
+
<Input.InputField
|
|
113
|
+
innerRef={(node) => {
|
|
114
|
+
inputNode.current = node
|
|
130
115
|
}}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
116
|
+
grow={1}
|
|
117
|
+
role="combobox"
|
|
118
|
+
autoComplete="off"
|
|
119
|
+
aria-autocomplete="list"
|
|
120
|
+
aria-controls={id}
|
|
121
|
+
aria-expanded={isOpen}
|
|
122
|
+
aria-activedescendant={highlightedItemId}
|
|
123
|
+
autoFocus={autoFocus}
|
|
124
|
+
type={type}
|
|
125
|
+
name={name}
|
|
126
|
+
disabled={disabled}
|
|
127
|
+
readOnly={readOnly}
|
|
128
|
+
placeholder={placeholder}
|
|
129
|
+
defaultValue={defaultValue}
|
|
130
|
+
value={value}
|
|
131
|
+
onChange={onChange}
|
|
132
|
+
onFocus={onFocus}
|
|
133
|
+
onBlur={onBlur}
|
|
134
|
+
onKeyDown={handleKeyDown}
|
|
135
|
+
onKeyUp={onKeyUp}
|
|
136
|
+
/>
|
|
137
|
+
</Input.InputBox>
|
|
138
|
+
)
|
|
134
139
|
}
|
|
135
|
-
|
|
140
|
+
ComboboxInput = forwardRef(ComboboxInput)
|
|
141
|
+
ComboboxInput.displayName = 'Combobox.Input'
|
|
136
142
|
export default ComboboxInput
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react'
|
|
2
2
|
|
|
3
3
|
import { ItemListItem } from '../ItemList'
|
|
4
4
|
import Menu from '../Menu'
|
|
5
|
+
import { useThemeProps } from '../system'
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
7
|
+
function ComboboxItem(props) {
|
|
8
|
+
const { value, index, text, disabled = false, ...restProps } = useThemeProps(
|
|
9
|
+
'combobox.item',
|
|
10
|
+
props
|
|
11
|
+
)
|
|
12
|
+
return (
|
|
13
|
+
<ItemListItem data={value} disabled={disabled} index={index} text={text}>
|
|
14
|
+
{({ id, highlight, highlighted, clearHighlight, select }) => (
|
|
15
|
+
<Menu.Item
|
|
16
|
+
disabled={disabled}
|
|
17
|
+
id={id}
|
|
18
|
+
isHighlighted={highlighted}
|
|
19
|
+
onMouseOver={highlight}
|
|
20
|
+
onMouseOut={clearHighlight}
|
|
21
|
+
onClick={(event) => {
|
|
22
|
+
event.stopPropagation()
|
|
23
|
+
event.nativeEvent.stopImmediatePropagation()
|
|
24
|
+
select()
|
|
25
|
+
}}
|
|
26
|
+
{...restProps}
|
|
27
|
+
/>
|
|
28
|
+
)}
|
|
29
|
+
</ItemListItem>
|
|
30
|
+
)
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
ComboboxItem.displayName = 'Combobox.Item'
|
|
33
33
|
export default ComboboxItem
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import React, {
|
|
2
|
+
import React, { useState, Children, useEffect } from 'react'
|
|
3
3
|
import { matchSorter } from 'match-sorter'
|
|
4
4
|
|
|
5
5
|
import Box from '../Box'
|
|
@@ -7,7 +7,7 @@ import Menu from '../Menu'
|
|
|
7
7
|
import HeadingUppercase from '../HeadingUppercase'
|
|
8
8
|
import StackView from '../StackView'
|
|
9
9
|
import Text from '../Text'
|
|
10
|
-
import {
|
|
10
|
+
import { useThemeProps } from '../system'
|
|
11
11
|
|
|
12
12
|
import ComboboxItem from './ComboboxItem'
|
|
13
13
|
|
|
@@ -56,66 +56,44 @@ type Props = {
|
|
|
56
56
|
renderItem?: (item: mixed, index: number) => null,
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
componentDidUpdate(lastProps) {
|
|
76
|
-
if (
|
|
77
|
-
lastProps.value !== this.props.value ||
|
|
78
|
-
!shallowEqual(lastProps.items, this.props.items) ||
|
|
79
|
-
!shallowEqual(lastProps.filter, this.props.filter)
|
|
80
|
-
) {
|
|
81
|
-
this.setState({
|
|
82
|
-
sortedItems: this.getSortedItems(this.props),
|
|
83
|
-
})
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
getSortedItems({ items, value, filter }) {
|
|
59
|
+
function ComboboxItems(props: Props) {
|
|
60
|
+
const {
|
|
61
|
+
filter,
|
|
62
|
+
items,
|
|
63
|
+
renderEmpty = defaultRenderEmpty,
|
|
64
|
+
renderItem = defaultRenderItem,
|
|
65
|
+
title,
|
|
66
|
+
value = '',
|
|
67
|
+
...restProps
|
|
68
|
+
} = useThemeProps('combobox.items', props)
|
|
69
|
+
const [sortedItems, setSortedItems] = useState(
|
|
70
|
+
getSortedItems({ items, value, filter })
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
function getSortedItems({ items, value, filter }) {
|
|
88
74
|
return matchSorter(items, value.length > 0 ? value : '', filter)
|
|
89
75
|
}
|
|
90
76
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
title
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
? sortedItems.map((item, index) => renderItem(item, index))
|
|
112
|
-
: typeof renderEmpty === 'function'
|
|
113
|
-
? renderEmpty(value)
|
|
114
|
-
: renderEmpty
|
|
115
|
-
)}
|
|
116
|
-
</Box>
|
|
117
|
-
)
|
|
118
|
-
}
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
setSortedItems(getSortedItems({ items, value, filter }))
|
|
79
|
+
}, [items, value, filter])
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<Box {...restProps}>
|
|
83
|
+
{title && (
|
|
84
|
+
<StackView paddingHorizontal={1} paddingVertical={0.5}>
|
|
85
|
+
<HeadingUppercase>{title}</HeadingUppercase>
|
|
86
|
+
</StackView>
|
|
87
|
+
)}
|
|
88
|
+
{Children.toArray(
|
|
89
|
+
sortedItems.length > 0
|
|
90
|
+
? sortedItems.map((item, index) => renderItem(item, index))
|
|
91
|
+
: typeof renderEmpty === 'function'
|
|
92
|
+
? renderEmpty(value)
|
|
93
|
+
: renderEmpty
|
|
94
|
+
)}
|
|
95
|
+
</Box>
|
|
96
|
+
)
|
|
119
97
|
}
|
|
120
|
-
|
|
98
|
+
ComboboxItems.displayName = 'Combobox.Items'
|
|
121
99
|
export default ComboboxItems
|
package/src/Combobox/index.js
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
import Combobox from './Combobox'
|
|
2
|
+
import ComboboxInput from './ComboboxInput'
|
|
3
|
+
import ComboboxItem from './ComboboxItem'
|
|
4
|
+
import ComboboxItems from './ComboboxItems'
|
|
5
|
+
import ComboboxPopover from './ComboboxPopover'
|
|
6
|
+
Combobox.Input = ComboboxInput
|
|
7
|
+
Combobox.Item = ComboboxItem
|
|
8
|
+
Combobox.Items = ComboboxItems
|
|
9
|
+
Combobox.Popover = ComboboxPopover
|
|
2
10
|
export default Combobox
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import React, {
|
|
2
|
+
import React, { useState, useCallback, useRef } from 'react'
|
|
3
3
|
import { format } from 'date-fns'
|
|
4
4
|
|
|
5
5
|
import Card from '../Card'
|
|
@@ -9,6 +9,7 @@ import Icon from '../Icon'
|
|
|
9
9
|
import Input from '../Input/Input'
|
|
10
10
|
import Popover from '../Popover'
|
|
11
11
|
import { generateId } from '../utils'
|
|
12
|
+
import { useThemeProps } from '../system'
|
|
12
13
|
|
|
13
14
|
export type DateFieldProps = {
|
|
14
15
|
/**
|
|
@@ -56,127 +57,130 @@ export type DateFieldProps = {
|
|
|
56
57
|
*/
|
|
57
58
|
keepInView?: boolean,
|
|
58
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Accepts any valid [Calendar](/calendar) props.
|
|
62
|
+
*/
|
|
63
|
+
calendarProps?: object,
|
|
64
|
+
|
|
59
65
|
/**
|
|
60
66
|
* Accepts any valid [Popover](/popover) props.
|
|
61
67
|
*/
|
|
62
68
|
popoverProps?: object,
|
|
63
69
|
}
|
|
64
70
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
71
|
+
function DateField({
|
|
72
|
+
formatValue = 'MMMM dd, yyyy',
|
|
73
|
+
defaultOpen = false,
|
|
74
|
+
keepInView,
|
|
75
|
+
lockScrollWhileOpen = true,
|
|
76
|
+
minDate,
|
|
77
|
+
maxDate,
|
|
78
|
+
onChange,
|
|
79
|
+
placement,
|
|
80
|
+
value,
|
|
81
|
+
...props
|
|
82
|
+
}: DateFieldProps) {
|
|
83
|
+
const {
|
|
84
|
+
calendarProps,
|
|
85
|
+
color,
|
|
86
|
+
popoverProps,
|
|
87
|
+
sizes,
|
|
88
|
+
thickness: sizeThickness,
|
|
89
|
+
trackColor,
|
|
90
|
+
...restProps
|
|
91
|
+
} = useThemeProps('dateField', props)
|
|
92
|
+
let canClosePopover = true
|
|
93
|
+
const [isPopoverOpen, setIsPopoverOpen] = useState(defaultOpen)
|
|
94
|
+
const id = generateId('datefield')
|
|
95
|
+
const popover = useRef(null)
|
|
96
|
+
const inputWrapper = useRef(null)
|
|
97
|
+
|
|
98
|
+
const openPopover = useCallback(() => {
|
|
99
|
+
setIsPopoverOpen(true)
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
const closePopover = useCallback(() => {
|
|
103
|
+
if (canClosePopover) {
|
|
104
|
+
setIsPopoverOpen(false)
|
|
87
105
|
}
|
|
88
|
-
}
|
|
106
|
+
})
|
|
89
107
|
|
|
90
|
-
togglePopover = () => {
|
|
91
|
-
if (
|
|
92
|
-
|
|
108
|
+
const togglePopover = useCallback(() => {
|
|
109
|
+
if (isPopoverOpen) {
|
|
110
|
+
closePopover()
|
|
93
111
|
} else {
|
|
94
|
-
|
|
112
|
+
openPopover()
|
|
95
113
|
}
|
|
96
|
-
}
|
|
114
|
+
})
|
|
97
115
|
|
|
98
|
-
handleDateSelect = (date) => {
|
|
99
|
-
const input =
|
|
116
|
+
const handleDateSelect = useCallback((date) => {
|
|
117
|
+
const input = inputWrapper.current.querySelector('input')
|
|
100
118
|
if (input.focus) {
|
|
101
119
|
input.focus()
|
|
102
120
|
}
|
|
103
|
-
if (
|
|
104
|
-
|
|
121
|
+
if (onChange) {
|
|
122
|
+
onChange(date)
|
|
105
123
|
}
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
this.inputWrapper = node
|
|
148
|
-
setRef(`${this.id}-input`)(node)
|
|
149
|
-
}}
|
|
150
|
-
readOnly
|
|
151
|
-
value={value ? format(value, formatValue) : ''}
|
|
152
|
-
renderRight={
|
|
153
|
-
<Icon name="general.calendar" color="foregroundTertiary" />
|
|
124
|
+
closePopover()
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<FocusGroup onBlur={closePopover}>
|
|
129
|
+
{({ requestBlur, setRef }) => (
|
|
130
|
+
<Popover
|
|
131
|
+
{...popoverProps}
|
|
132
|
+
ref={(component) => {
|
|
133
|
+
popover.current = component
|
|
134
|
+
}}
|
|
135
|
+
innerRef={(node) => {
|
|
136
|
+
popover.current = node
|
|
137
|
+
setRef(`${id}-popover`)(node)
|
|
138
|
+
}}
|
|
139
|
+
as={Card}
|
|
140
|
+
tabIndex={-1}
|
|
141
|
+
elevation={2}
|
|
142
|
+
onBlur={requestBlur}
|
|
143
|
+
keepInView={keepInView}
|
|
144
|
+
lockScrollWhileOpen={lockScrollWhileOpen}
|
|
145
|
+
placement={placement}
|
|
146
|
+
open={isPopoverOpen}
|
|
147
|
+
onRequestClose={closePopover}
|
|
148
|
+
anchorElement={
|
|
149
|
+
<Input
|
|
150
|
+
innerRef={(node) => {
|
|
151
|
+
inputWrapper.current = node
|
|
152
|
+
setRef(`${id}-input`)(node)
|
|
153
|
+
}}
|
|
154
|
+
readOnly
|
|
155
|
+
value={value ? format(value, formatValue) : ''}
|
|
156
|
+
renderRight={
|
|
157
|
+
<Icon name="general.calendar" color="foregroundTertiary" />
|
|
158
|
+
}
|
|
159
|
+
onClick={togglePopover}
|
|
160
|
+
onBlur={requestBlur}
|
|
161
|
+
onKeyDown={(event) => {
|
|
162
|
+
if (event.key === ' ') {
|
|
163
|
+
event.preventDefault()
|
|
164
|
+
togglePopover()
|
|
154
165
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
onKeyDown={(event) => {
|
|
158
|
-
if (event.key === ' ') {
|
|
159
|
-
event.preventDefault()
|
|
160
|
-
this.togglePopover()
|
|
161
|
-
}
|
|
162
|
-
}}
|
|
163
|
-
{...restProps}
|
|
164
|
-
/>
|
|
165
|
-
}
|
|
166
|
-
>
|
|
167
|
-
<Calendar
|
|
168
|
-
size="sm"
|
|
169
|
-
initialDate={value}
|
|
170
|
-
selected={value}
|
|
171
|
-
minDate={minDate}
|
|
172
|
-
maxDate={maxDate}
|
|
173
|
-
onDateSelect={this.handleDateSelect}
|
|
166
|
+
}}
|
|
167
|
+
{...restProps}
|
|
174
168
|
/>
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
169
|
+
}
|
|
170
|
+
>
|
|
171
|
+
<Calendar
|
|
172
|
+
size="sm"
|
|
173
|
+
{...calendarProps}
|
|
174
|
+
initialDate={value}
|
|
175
|
+
selected={value}
|
|
176
|
+
minDate={minDate}
|
|
177
|
+
maxDate={maxDate}
|
|
178
|
+
onDateSelect={handleDateSelect}
|
|
179
|
+
/>
|
|
180
|
+
</Popover>
|
|
181
|
+
)}
|
|
182
|
+
</FocusGroup>
|
|
183
|
+
)
|
|
180
184
|
}
|
|
181
185
|
|
|
182
186
|
export default DateField
|