@gm-mobile/c-react 3.12.7-beta.0 → 3.12.7-beta.2
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/package.json +5 -5
- package/src/component/calendar/base.tsx +2 -0
- package/src/component/calendar/months_list.tsx +58 -3
- package/src/component/calendar/types.ts +3 -0
- package/src/component/calendar/use_previous.ts +13 -0
- package/src/component/search/search.weapp.tsx +3 -46
- package/src/component/search/stories.tsx +1 -11
- package/src/component/search/style.less +1 -56
- package/src/component/search/type.ts +1 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gm-mobile/c-react",
|
|
3
|
-
"version": "3.12.7-beta.
|
|
3
|
+
"version": "3.12.7-beta.2",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "liyatang <liyatang@qq.com>",
|
|
6
6
|
"homepage": "https://github.com/gmfe/gm-mobile#readme",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"url": "https://github.com/gmfe/gm-mobile/issues"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@gm-mobile/c-font": "^3.12.7-beta.
|
|
25
|
-
"@gm-mobile/c-tool": "^3.12.7-beta.
|
|
26
|
-
"@gm-mobile/locales": "^3.12.7-beta.
|
|
24
|
+
"@gm-mobile/c-font": "^3.12.7-beta.2",
|
|
25
|
+
"@gm-mobile/c-tool": "^3.12.7-beta.2",
|
|
26
|
+
"@gm-mobile/locales": "^3.12.7-beta.2",
|
|
27
27
|
"dayjs": "^1.11.6"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"prop-types": "^15.7.2",
|
|
35
35
|
"react": "^16.13.1"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "ed1c43a175d8b7af4bc3206ce1944c56b3e48d34"
|
|
38
38
|
}
|
|
@@ -31,6 +31,7 @@ const BaseCalendar: FC<BaseCalendarProps> = ({
|
|
|
31
31
|
height = 400,
|
|
32
32
|
className,
|
|
33
33
|
style,
|
|
34
|
+
canScrollWhenMaxOrMinChange = false,
|
|
34
35
|
...rest
|
|
35
36
|
}) => {
|
|
36
37
|
const [isSelectBegin, setIsSelectBegin] = useState(true)
|
|
@@ -101,6 +102,7 @@ const BaseCalendar: FC<BaseCalendarProps> = ({
|
|
|
101
102
|
))}
|
|
102
103
|
</Flex>
|
|
103
104
|
<MonthsList
|
|
105
|
+
canScrollWhenMaxOrMinChange={canScrollWhenMaxOrMinChange}
|
|
104
106
|
selected={selected}
|
|
105
107
|
type={type}
|
|
106
108
|
height={height - 40} // 固定展示星期头部高度40
|
|
@@ -6,10 +6,36 @@ import { VList, VListRef } from '../v_list'
|
|
|
6
6
|
import Month from './month'
|
|
7
7
|
import { CALENDAR_TYPE } from './util'
|
|
8
8
|
import { MonthListProps } from './types'
|
|
9
|
+
import usePreviousObject from './use_previous'
|
|
9
10
|
|
|
10
11
|
// 目前只支持固定高度,定为265
|
|
11
12
|
const MONTH_HEIGHT = 265
|
|
12
13
|
|
|
14
|
+
function whichValueChanged(
|
|
15
|
+
prevArray: [Dayjs, Dayjs],
|
|
16
|
+
currentArray: [Dayjs, Dayjs]
|
|
17
|
+
) {
|
|
18
|
+
const changes: number[] = []
|
|
19
|
+
|
|
20
|
+
if (!prevArray) {
|
|
21
|
+
return 0
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!moment(prevArray[0]).isSame(moment(currentArray[0]))) {
|
|
25
|
+
changes.push(0)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!moment(prevArray[1]).isSame(moment(currentArray[1]))) {
|
|
29
|
+
changes.push(1)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** 没有变化 */
|
|
33
|
+
if (changes.length === 0) return 0
|
|
34
|
+
/** 两个都变化了 */
|
|
35
|
+
if (changes.length === 2) return 1
|
|
36
|
+
return 0
|
|
37
|
+
}
|
|
38
|
+
|
|
13
39
|
const MonthsList: FC<MonthListProps> = ({
|
|
14
40
|
min,
|
|
15
41
|
max,
|
|
@@ -19,8 +45,10 @@ const MonthsList: FC<MonthListProps> = ({
|
|
|
19
45
|
onSelectDay,
|
|
20
46
|
disabledDate,
|
|
21
47
|
showDateLabel,
|
|
48
|
+
canScrollWhenMaxOrMinChange = false,
|
|
22
49
|
}) => {
|
|
23
50
|
const refList = useRef<VListRef>(null)
|
|
51
|
+
const previous = usePreviousObject(selected)
|
|
24
52
|
|
|
25
53
|
const computedMonthList = () => {
|
|
26
54
|
// 优先 min,其次 begin ,其次 当前
|
|
@@ -50,7 +78,7 @@ const MonthsList: FC<MonthListProps> = ({
|
|
|
50
78
|
}
|
|
51
79
|
const monthsList = computedMonthList()
|
|
52
80
|
|
|
53
|
-
|
|
81
|
+
const scrollToTarget = (flag: boolean) => {
|
|
54
82
|
if (selected.length) {
|
|
55
83
|
const date = type === CALENDAR_TYPE.RANGE ? selected[1] : selected[0]
|
|
56
84
|
const targetId = _.findIndex(
|
|
@@ -60,12 +88,39 @@ const MonthsList: FC<MonthListProps> = ({
|
|
|
60
88
|
moment(item).month() === moment(date).month()
|
|
61
89
|
)
|
|
62
90
|
|
|
63
|
-
|
|
91
|
+
if (flag) {
|
|
92
|
+
setTimeout(() => {
|
|
93
|
+
refList.current && refList.current.apiDoScrollToKey(targetId)
|
|
94
|
+
}, 200)
|
|
95
|
+
} else {
|
|
64
96
|
refList.current && refList.current.apiDoScrollToKey(targetId)
|
|
65
|
-
}
|
|
97
|
+
}
|
|
66
98
|
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
scrollToTarget(true)
|
|
67
103
|
}, [])
|
|
68
104
|
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (!canScrollWhenMaxOrMinChange) {
|
|
107
|
+
return
|
|
108
|
+
}
|
|
109
|
+
if (max || min) {
|
|
110
|
+
const flagItem = whichValueChanged(previous as any, selected as any)
|
|
111
|
+
const date = selected[flagItem]
|
|
112
|
+
const targetId = _.findIndex(
|
|
113
|
+
monthsList,
|
|
114
|
+
(item) =>
|
|
115
|
+
moment(item).year() === moment(date).year() &&
|
|
116
|
+
moment(item).month() === moment(date).month()
|
|
117
|
+
)
|
|
118
|
+
if (targetId !== -1) {
|
|
119
|
+
refList.current && refList.current.apiDoScrollToKey(targetId)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}, [max, min])
|
|
123
|
+
|
|
69
124
|
return (
|
|
70
125
|
<VList
|
|
71
126
|
ref={refList}
|
|
@@ -31,6 +31,7 @@ interface MonthProps {
|
|
|
31
31
|
|
|
32
32
|
interface MonthListProps extends Omit<MonthProps, 'currentMoment'> {
|
|
33
33
|
height: number
|
|
34
|
+
canScrollWhenMaxOrMinChange?: boolean
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
interface BaseCalendarProps
|
|
@@ -51,6 +52,8 @@ interface BaseCalendarProps
|
|
|
51
52
|
disabledDate?: (date: Date) => boolean
|
|
52
53
|
/** 定义日历高度,默认400 */
|
|
53
54
|
height?: number
|
|
55
|
+
/** 当min 和max 改变时是否滚动 */
|
|
56
|
+
canScrollWhenMaxOrMinChange: boolean
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
interface CalendarProps
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react'
|
|
2
|
+
|
|
3
|
+
function usePreviousObject<T extends Record<string, any>>(obj: T): T {
|
|
4
|
+
const ref = useRef<T | null>(null)
|
|
5
|
+
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
ref.current = obj
|
|
8
|
+
}, [obj])
|
|
9
|
+
|
|
10
|
+
return ref.current as T
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default usePreviousObject
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getLocale } from '@gm-mobile/locales'
|
|
2
|
-
import React, { ChangeEvent, FC, FormEvent, MouseEvent
|
|
2
|
+
import React, { ChangeEvent, FC, FormEvent, MouseEvent } from 'react'
|
|
3
3
|
import classNames from 'classnames'
|
|
4
4
|
import _ from 'lodash'
|
|
5
5
|
import Input from '../input/input'
|
|
@@ -12,9 +12,6 @@ const Search: FC<SearchProps> = ({
|
|
|
12
12
|
value,
|
|
13
13
|
placeholder = getLocale('搜索'),
|
|
14
14
|
searchText,
|
|
15
|
-
searchType,
|
|
16
|
-
onSearchType,
|
|
17
|
-
searchOptions = [],
|
|
18
15
|
type = 'search',
|
|
19
16
|
onCancel = _.noop,
|
|
20
17
|
onSearch = _.noop,
|
|
@@ -23,11 +20,6 @@ const Search: FC<SearchProps> = ({
|
|
|
23
20
|
autoFocus,
|
|
24
21
|
...rest
|
|
25
22
|
}) => {
|
|
26
|
-
const [showSelect, setShowSelect] = useState(false)
|
|
27
|
-
const needSelect = searchOptions?.length > 0
|
|
28
|
-
const searchTypeText =
|
|
29
|
-
searchOptions?.find((item) => item.key === searchType)?.name || '请选择'
|
|
30
|
-
|
|
31
23
|
const handleSearch = (
|
|
32
24
|
e: FormEvent<HTMLFormElement> | MouseEvent<HTMLButtonElement>
|
|
33
25
|
) => {
|
|
@@ -49,48 +41,13 @@ const Search: FC<SearchProps> = ({
|
|
|
49
41
|
onChange('')
|
|
50
42
|
}
|
|
51
43
|
|
|
52
|
-
const handleSelect = (key: string) => {
|
|
53
|
-
// eslint-disable-next-line no-unused-expressions
|
|
54
|
-
onSearchType?.(key)
|
|
55
|
-
setShowSelect(false)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
44
|
return (
|
|
59
45
|
<View
|
|
60
46
|
{...rest}
|
|
61
|
-
className={classNames('m-search m-flex m-flex-align-center', className
|
|
62
|
-
'm-search-select': needSelect,
|
|
63
|
-
})}
|
|
47
|
+
className={classNames('m-search m-flex m-flex-align-center', className)}
|
|
64
48
|
>
|
|
65
49
|
<View className='m-search-input m-flex m-flex-flex'>
|
|
66
|
-
|
|
67
|
-
<View
|
|
68
|
-
className='m-search-select-text'
|
|
69
|
-
onClick={() => setShowSelect((prev) => !prev)}
|
|
70
|
-
>
|
|
71
|
-
<Text>{searchTypeText}</Text>
|
|
72
|
-
<Text className='m-font m-font-arrow-triangle' />
|
|
73
|
-
</View>
|
|
74
|
-
) : (
|
|
75
|
-
<Text className='m-font m-font-search m-search-icon-search' />
|
|
76
|
-
)}
|
|
77
|
-
{showSelect && (
|
|
78
|
-
<View className='m-search-select-content'>
|
|
79
|
-
{searchOptions.map((option) => {
|
|
80
|
-
return (
|
|
81
|
-
<View
|
|
82
|
-
key={option.key}
|
|
83
|
-
className={classNames('m-search-select-content-item', {
|
|
84
|
-
'm-search-select-active': searchType === option.key,
|
|
85
|
-
})}
|
|
86
|
-
onClick={() => handleSelect(option.key)}
|
|
87
|
-
>
|
|
88
|
-
<Text>{option.name}</Text>
|
|
89
|
-
</View>
|
|
90
|
-
)
|
|
91
|
-
})}
|
|
92
|
-
</View>
|
|
93
|
-
)}
|
|
50
|
+
<Text className='m-font m-font-search m-search-icon-search' />
|
|
94
51
|
<Input
|
|
95
52
|
type='text'
|
|
96
53
|
confirmType='search'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react'
|
|
2
2
|
import Search from './search'
|
|
3
3
|
import SearchPage from './page'
|
|
4
4
|
import FakeSearch from './fake_search'
|
|
@@ -40,24 +40,14 @@ export const normal = () => {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export const cancel = () => {
|
|
43
|
-
const [type, setType] = useState('1')
|
|
44
43
|
return (
|
|
45
44
|
<View>
|
|
46
45
|
<View>带取消按钮(点Header的搜索按钮)</View>
|
|
47
46
|
<View>
|
|
48
47
|
<Search
|
|
49
48
|
type='cancel'
|
|
50
|
-
searchType={type}
|
|
51
|
-
onSearchType={setType}
|
|
52
|
-
searchOptions={[
|
|
53
|
-
{ name: '供应商', key: '1' },
|
|
54
|
-
{ name: '商品', key: '2' },
|
|
55
|
-
]}
|
|
56
49
|
placeholder='在站内搜索'
|
|
57
50
|
value={store.value}
|
|
58
|
-
style={{
|
|
59
|
-
background: '#fff',
|
|
60
|
-
}}
|
|
61
51
|
onChange={(value) => store.setValue(value)}
|
|
62
52
|
onCancel={() => console.log('cancel')}
|
|
63
53
|
/>
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
.m-search {
|
|
2
2
|
height: var(--m-size-header-height);
|
|
3
3
|
padding: 0 15px;
|
|
4
|
-
position: relative;
|
|
5
4
|
|
|
6
5
|
.m-search-input {
|
|
7
6
|
border-radius: var(--m-size-form-height-sm);
|
|
7
|
+
overflow: hidden;
|
|
8
8
|
position: relative;
|
|
9
9
|
|
|
10
10
|
.m-input {
|
|
11
|
-
border-radius: var(--m-size-form-height-sm);
|
|
12
11
|
height: var(--m-size-form-height-sm);
|
|
13
12
|
background: var(--m-color-bg-back);
|
|
14
13
|
padding: 0 25px 0 25px;
|
|
@@ -36,60 +35,6 @@
|
|
|
36
35
|
.m-btn {
|
|
37
36
|
margin-right: -15px;
|
|
38
37
|
}
|
|
39
|
-
|
|
40
|
-
&.m-search-select {
|
|
41
|
-
.m-search-select-text {
|
|
42
|
-
position: absolute;
|
|
43
|
-
display: flex;
|
|
44
|
-
width: 72px;
|
|
45
|
-
flex: 1;
|
|
46
|
-
height: 100%;
|
|
47
|
-
align-items: center;
|
|
48
|
-
justify-content: center;
|
|
49
|
-
|
|
50
|
-
.m-font-arrow-triangle {
|
|
51
|
-
font-size: 6px;
|
|
52
|
-
transform: scale(0.6);
|
|
53
|
-
margin-left: 4px;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
.m-input {
|
|
58
|
-
padding-left: 72px;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
.m-search-select-content {
|
|
62
|
-
position: absolute;
|
|
63
|
-
top: 38px;
|
|
64
|
-
background: #fff;
|
|
65
|
-
border-radius: 4px;
|
|
66
|
-
padding: 6px 10px;
|
|
67
|
-
box-shadow: 0 0 8px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
|
|
68
|
-
|
|
69
|
-
&::before {
|
|
70
|
-
content: '';
|
|
71
|
-
position: absolute;
|
|
72
|
-
top: -8px;
|
|
73
|
-
left: calc(50% - 4px);
|
|
74
|
-
border: 4px solid transparent;
|
|
75
|
-
border-bottom: 4px solid #fff;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
.m-search-select-content-item {
|
|
79
|
-
padding: 4px;
|
|
80
|
-
border-bottom: 1.5px solid #eee;
|
|
81
|
-
text-align: center;
|
|
82
|
-
|
|
83
|
-
&:last-child {
|
|
84
|
-
border-bottom: none;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
.m-search-select-active {
|
|
89
|
-
color: var(--m-color-accent);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
38
|
}
|
|
94
39
|
|
|
95
40
|
.m-fake-search {
|
|
@@ -10,11 +10,6 @@ interface SearchPageProps extends Omit<PageProps, 'onChange'> {
|
|
|
10
10
|
onSearch?: () => void
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
interface SearchOption {
|
|
14
|
-
name?: string
|
|
15
|
-
key: string
|
|
16
|
-
}
|
|
17
|
-
|
|
18
13
|
interface SearchProps {
|
|
19
14
|
value: string
|
|
20
15
|
onChange: (value: string) => void
|
|
@@ -29,16 +24,11 @@ interface SearchProps {
|
|
|
29
24
|
searchText?: string
|
|
30
25
|
className?: string
|
|
31
26
|
style?: CSSProperties
|
|
32
|
-
/** options */
|
|
33
|
-
searchType?: string
|
|
34
|
-
searchOptions?: SearchOption[]
|
|
35
|
-
onSearchType?: (key: string) => void
|
|
36
27
|
}
|
|
37
|
-
|
|
38
28
|
interface FakeSearchProps extends HtmlHTMLAttributes<HTMLDivElement> {
|
|
39
29
|
placeholder?: string
|
|
40
30
|
center?: boolean
|
|
41
31
|
light?: boolean
|
|
42
32
|
}
|
|
43
33
|
|
|
44
|
-
export type { SearchPageProps, SearchProps,
|
|
34
|
+
export type { SearchPageProps, SearchProps, FakeSearchProps }
|