clxx 2.0.0 → 2.0.1
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/build/Picker/Wrapper.d.ts +19 -0
- package/build/Picker/Wrapper.js +84 -0
- package/build/Picker/index.d.ts +12 -0
- package/build/Picker/index.js +55 -0
- package/build/Picker/style.d.ts +3 -0
- package/build/Picker/style.js +119 -0
- package/build/Picker/swiperStyle.d.ts +1 -0
- package/build/Picker/swiperStyle.js +66 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/package.json +4 -2
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx } from "@emotion/react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export declare type OptionType = {
|
|
4
|
+
value: string | number;
|
|
5
|
+
label?: React.ReactNode;
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
};
|
|
8
|
+
export interface PickerWrapperProps {
|
|
9
|
+
options: OptionType[];
|
|
10
|
+
defaultValue?: number;
|
|
11
|
+
renderOption?: (option: OptionType, index: number) => React.ReactNode;
|
|
12
|
+
onConfirm?: (option: OptionType, index: number) => void;
|
|
13
|
+
onCancel?: () => void;
|
|
14
|
+
renderCancel?: () => React.ReactNode;
|
|
15
|
+
renderConfirm?: () => React.ReactNode;
|
|
16
|
+
showTitle?: boolean;
|
|
17
|
+
renderTitle?: (option: OptionType, index: number) => React.ReactNode;
|
|
18
|
+
}
|
|
19
|
+
export declare function Wrapper(props: PickerWrapperProps): jsx.JSX.Element;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { jsx } from "@emotion/react";
|
|
2
|
+
import { RowBetween } from "../Flex/Row";
|
|
3
|
+
import { Col } from "../Flex/Col";
|
|
4
|
+
import { style } from "./style";
|
|
5
|
+
import { swiperStyle } from "./swiperStyle";
|
|
6
|
+
import { Clickable } from "../Clickable";
|
|
7
|
+
import Swiper from "swiper";
|
|
8
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
9
|
+
export function Wrapper(props) {
|
|
10
|
+
const { onConfirm, onCancel, renderCancel, renderConfirm, options, renderOption, showTitle = true, renderTitle, defaultValue, } = props;
|
|
11
|
+
const getInitialSlide = useCallback(() => {
|
|
12
|
+
let initialSlide = 0;
|
|
13
|
+
if (Array.isArray(options)) {
|
|
14
|
+
let findIndex = options.findIndex((option) => option.value === defaultValue);
|
|
15
|
+
if (findIndex >= 0) {
|
|
16
|
+
initialSlide = findIndex;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return initialSlide;
|
|
20
|
+
}, [options, defaultValue]);
|
|
21
|
+
const swiperRef = useRef(null);
|
|
22
|
+
const [index, setIndex] = useState(getInitialSlide());
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
const swiper = new Swiper(swiperRef.current, {
|
|
25
|
+
initialSlide: getInitialSlide(),
|
|
26
|
+
direction: "vertical",
|
|
27
|
+
slidesPerView: 5,
|
|
28
|
+
centeredSlides: true,
|
|
29
|
+
freeMode: true,
|
|
30
|
+
freeModeSticky: true,
|
|
31
|
+
});
|
|
32
|
+
swiper.on("init", () => {
|
|
33
|
+
setIndex(swiper.realIndex);
|
|
34
|
+
});
|
|
35
|
+
swiper.on("slideChange", () => {
|
|
36
|
+
setIndex(swiper.realIndex);
|
|
37
|
+
});
|
|
38
|
+
return () => {
|
|
39
|
+
swiper.destroy();
|
|
40
|
+
};
|
|
41
|
+
}, [getInitialSlide]);
|
|
42
|
+
const showTitleContent = () => {
|
|
43
|
+
if (showTitle) {
|
|
44
|
+
const option = options[index];
|
|
45
|
+
if (typeof renderTitle === "function") {
|
|
46
|
+
return renderTitle(option, index);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return (jsx(Col, { css: style.title },
|
|
50
|
+
jsx("span", null, "\u5F53\u524D\u9009\u62E9"),
|
|
51
|
+
jsx("span", null, option.label)));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const showCancel = () => {
|
|
56
|
+
var _a;
|
|
57
|
+
return (_a = renderCancel === null || renderCancel === void 0 ? void 0 : renderCancel()) !== null && _a !== void 0 ? _a : jsx("div", { css: [style.btn, style.btnCancel] }, "\u53D6\u6D88");
|
|
58
|
+
};
|
|
59
|
+
const showConfirm = () => {
|
|
60
|
+
var _a;
|
|
61
|
+
return (_a = renderConfirm === null || renderConfirm === void 0 ? void 0 : renderConfirm()) !== null && _a !== void 0 ? _a : jsx("div", { css: [style.btn, style.btnConfirm] }, "\u786E\u5B9A");
|
|
62
|
+
};
|
|
63
|
+
const showOptions = () => {
|
|
64
|
+
if (Array.isArray(options)) {
|
|
65
|
+
return options.map((option, index) => {
|
|
66
|
+
let content = option.label;
|
|
67
|
+
if (typeof renderOption === "function") {
|
|
68
|
+
content = renderOption(option, index);
|
|
69
|
+
}
|
|
70
|
+
return (jsx("div", { className: "swiper-slide", key: option.value }, content));
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
return (jsx("div", { css: [style.container] },
|
|
75
|
+
jsx(RowBetween, { css: style.header },
|
|
76
|
+
showTitleContent(),
|
|
77
|
+
jsx(Clickable, { onClick: onCancel }, showCancel()),
|
|
78
|
+
jsx(Clickable, { onClick: () => onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm(options[index], index) }, showConfirm())),
|
|
79
|
+
jsx("div", { css: [swiperStyle, style.body] },
|
|
80
|
+
jsx("div", { className: "swiper", css: style.swiper, ref: swiperRef },
|
|
81
|
+
jsx("div", { className: "swiper-wrapper" }, showOptions()),
|
|
82
|
+
jsx("div", { css: [style.mask, style.maskTop] }),
|
|
83
|
+
jsx("div", { css: [style.mask, style.maskBottom] })))));
|
|
84
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PickerWrapperProps } from "./Wrapper";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export interface ShowPickerOption extends PickerWrapperProps {
|
|
4
|
+
blankClosable?: boolean;
|
|
5
|
+
showMask?: boolean;
|
|
6
|
+
maskColor?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface PickerOption extends ShowPickerOption, Omit<React.HTMLProps<HTMLDivElement>, "defaultValue"> {
|
|
9
|
+
children?: React.ReactNode;
|
|
10
|
+
}
|
|
11
|
+
export declare function showPicker(option: ShowPickerOption): void;
|
|
12
|
+
export declare function Picker(props: PickerOption): JSX.Element;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { showDialog } from "../Dialog";
|
|
13
|
+
import { Wrapper } from "./Wrapper";
|
|
14
|
+
import React from "react";
|
|
15
|
+
import pick from "lodash/pick";
|
|
16
|
+
import omit from "lodash/omit";
|
|
17
|
+
export function showPicker(option) {
|
|
18
|
+
const { blankClosable, showMask, maskColor, onCancel, onConfirm } = option, extra = __rest(option, ["blankClosable", "showMask", "maskColor", "onCancel", "onConfirm"]);
|
|
19
|
+
const stop = showDialog({
|
|
20
|
+
content: (React.createElement(Wrapper, Object.assign({}, extra, { onCancel: () => {
|
|
21
|
+
stop();
|
|
22
|
+
onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
23
|
+
}, onConfirm: (option, index) => {
|
|
24
|
+
stop();
|
|
25
|
+
onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm(option, index);
|
|
26
|
+
} }))),
|
|
27
|
+
type: "pullUp",
|
|
28
|
+
blankClosable,
|
|
29
|
+
showMask,
|
|
30
|
+
maskColor,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export function Picker(props) {
|
|
34
|
+
const { children, onClick } = props, option = __rest(props, ["children", "onClick"]);
|
|
35
|
+
const pickerProps = [
|
|
36
|
+
"blankClosable",
|
|
37
|
+
"showMask",
|
|
38
|
+
"maskColor",
|
|
39
|
+
"options",
|
|
40
|
+
"defaultValue",
|
|
41
|
+
"renderOption",
|
|
42
|
+
"onConfirm",
|
|
43
|
+
"onCancel",
|
|
44
|
+
"renderCancel",
|
|
45
|
+
"renderConfirm",
|
|
46
|
+
"showTitle",
|
|
47
|
+
"renderTitle",
|
|
48
|
+
];
|
|
49
|
+
const showPickerOption = pick(option, pickerProps);
|
|
50
|
+
const boxProps = omit(option, pickerProps);
|
|
51
|
+
return (React.createElement("div", Object.assign({ onClick: (event) => {
|
|
52
|
+
onClick === null || onClick === void 0 ? void 0 : onClick(event);
|
|
53
|
+
showPicker(showPickerOption);
|
|
54
|
+
} }, boxProps), children));
|
|
55
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { adaptive } from "../utils/cssUtil";
|
|
2
|
+
export const tinyLine = {
|
|
3
|
+
"&:after,&::after": {
|
|
4
|
+
content: "''",
|
|
5
|
+
position: "absolute",
|
|
6
|
+
left: 0,
|
|
7
|
+
right: 0,
|
|
8
|
+
height: "1px",
|
|
9
|
+
backgroundColor: "#c0c0c0",
|
|
10
|
+
transform: `scale(1, ${1 / window.devicePixelRatio})`,
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
const itemHeight = 90;
|
|
14
|
+
export const style = {
|
|
15
|
+
container: [
|
|
16
|
+
{
|
|
17
|
+
backgroundColor: "#fff",
|
|
18
|
+
overflow: "hidden",
|
|
19
|
+
position: "relative",
|
|
20
|
+
},
|
|
21
|
+
adaptive({
|
|
22
|
+
borderTopLeftRadius: 16,
|
|
23
|
+
borderTopRightRadius: 16,
|
|
24
|
+
}),
|
|
25
|
+
],
|
|
26
|
+
header: [
|
|
27
|
+
{
|
|
28
|
+
position: "relative",
|
|
29
|
+
backgroundColor: "#fafafa",
|
|
30
|
+
zIndex: 2,
|
|
31
|
+
"&:after,&::after": {
|
|
32
|
+
bottom: 0,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
tinyLine,
|
|
36
|
+
adaptive({
|
|
37
|
+
height: itemHeight,
|
|
38
|
+
}),
|
|
39
|
+
],
|
|
40
|
+
title: {
|
|
41
|
+
position: "absolute",
|
|
42
|
+
left: "50%",
|
|
43
|
+
top: "50%",
|
|
44
|
+
transform: "translate(-50%, -50%)",
|
|
45
|
+
zIndex: 1,
|
|
46
|
+
"span:nth-of-type(1)": [
|
|
47
|
+
{
|
|
48
|
+
color: "#666",
|
|
49
|
+
lineHeight: 1,
|
|
50
|
+
},
|
|
51
|
+
adaptive({
|
|
52
|
+
fontSize: 20,
|
|
53
|
+
marginBottom: 5,
|
|
54
|
+
}),
|
|
55
|
+
],
|
|
56
|
+
"span:nth-of-type(2)": [
|
|
57
|
+
{
|
|
58
|
+
color: "#333",
|
|
59
|
+
lineHeight: 1,
|
|
60
|
+
},
|
|
61
|
+
adaptive({
|
|
62
|
+
fontSize: 28,
|
|
63
|
+
}),
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
btn: [
|
|
67
|
+
{ textAlign: "center", lineHeight: 2 },
|
|
68
|
+
adaptive({
|
|
69
|
+
width: 120,
|
|
70
|
+
fontSize: 32,
|
|
71
|
+
}),
|
|
72
|
+
],
|
|
73
|
+
btnCancel: {
|
|
74
|
+
color: "#666",
|
|
75
|
+
},
|
|
76
|
+
btnConfirm: {
|
|
77
|
+
color: "#007afe",
|
|
78
|
+
},
|
|
79
|
+
body: {
|
|
80
|
+
overflow: "hidden",
|
|
81
|
+
position: "relative",
|
|
82
|
+
},
|
|
83
|
+
swiper: [
|
|
84
|
+
adaptive({ height: itemHeight * 5, fontSize: 32 }),
|
|
85
|
+
{
|
|
86
|
+
".swiper-slide": {
|
|
87
|
+
display: "flex",
|
|
88
|
+
justifyContent: "center",
|
|
89
|
+
alignItems: "center",
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
mask: [
|
|
94
|
+
{
|
|
95
|
+
position: "absolute",
|
|
96
|
+
left: 0,
|
|
97
|
+
width: "100%",
|
|
98
|
+
zIndex: 2,
|
|
99
|
+
},
|
|
100
|
+
tinyLine,
|
|
101
|
+
adaptive({
|
|
102
|
+
height: itemHeight * 2,
|
|
103
|
+
}),
|
|
104
|
+
],
|
|
105
|
+
maskTop: {
|
|
106
|
+
top: 0,
|
|
107
|
+
backgroundImage: "linear-gradient(180deg, #fefefe, transparent)",
|
|
108
|
+
"&:after,&::after": {
|
|
109
|
+
bottom: 0,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
maskBottom: {
|
|
113
|
+
backgroundImage: "linear-gradient(0deg, #fefefe, transparent)",
|
|
114
|
+
bottom: 0,
|
|
115
|
+
"&:after,&::after": {
|
|
116
|
+
top: 0,
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const swiperStyle: import("@emotion/utils").SerializedStyles;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { css } from "@emotion/react";
|
|
2
|
+
export const swiperStyle = css `
|
|
3
|
+
.swiper-container {
|
|
4
|
+
margin-left: auto;
|
|
5
|
+
margin-right: auto;
|
|
6
|
+
position: relative;
|
|
7
|
+
overflow: hidden;
|
|
8
|
+
list-style: none;
|
|
9
|
+
padding: 0;
|
|
10
|
+
z-index: 1;
|
|
11
|
+
}
|
|
12
|
+
.swiper-container-vertical > .swiper-wrapper {
|
|
13
|
+
flex-direction: column;
|
|
14
|
+
}
|
|
15
|
+
.swiper-wrapper {
|
|
16
|
+
position: relative;
|
|
17
|
+
width: 100%;
|
|
18
|
+
height: 100%;
|
|
19
|
+
z-index: 1;
|
|
20
|
+
display: flex;
|
|
21
|
+
transition-property: transform;
|
|
22
|
+
box-sizing: content-box;
|
|
23
|
+
}
|
|
24
|
+
.swiper-container-android .swiper-slide,
|
|
25
|
+
.swiper-wrapper {
|
|
26
|
+
transform: translate3d(0px, 0, 0);
|
|
27
|
+
}
|
|
28
|
+
.swiper-container-multirow > .swiper-wrapper {
|
|
29
|
+
flex-wrap: wrap;
|
|
30
|
+
}
|
|
31
|
+
.swiper-container-multirow-column > .swiper-wrapper {
|
|
32
|
+
flex-wrap: wrap;
|
|
33
|
+
flex-direction: column;
|
|
34
|
+
}
|
|
35
|
+
.swiper-container-free-mode > .swiper-wrapper {
|
|
36
|
+
transition-timing-function: ease-out;
|
|
37
|
+
margin: 0 auto;
|
|
38
|
+
}
|
|
39
|
+
.swiper-container-pointer-events {
|
|
40
|
+
touch-action: pan-y;
|
|
41
|
+
&.swiper-container-vertical {
|
|
42
|
+
touch-action: pan-x;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
.swiper-slide {
|
|
46
|
+
flex-shrink: 0;
|
|
47
|
+
width: 100%;
|
|
48
|
+
height: 100%;
|
|
49
|
+
position: relative;
|
|
50
|
+
transition-property: transform;
|
|
51
|
+
}
|
|
52
|
+
.swiper-slide-invisible-blank {
|
|
53
|
+
visibility: hidden;
|
|
54
|
+
}
|
|
55
|
+
.swiper-container-autoheight {
|
|
56
|
+
&,
|
|
57
|
+
.swiper-slide {
|
|
58
|
+
height: auto;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.swiper-wrapper {
|
|
62
|
+
align-items: flex-start;
|
|
63
|
+
transition-property: transform, height;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
`;
|
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clxx",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Basic JS library for mobile devices",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"module": "./build/index.js",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"@types/lodash": "^4.14.175",
|
|
37
37
|
"@types/react": "^17.0.27",
|
|
38
38
|
"@types/react-dom": "^17.0.9",
|
|
39
|
+
"@types/swiper": "^5.4.3",
|
|
39
40
|
"csstype": "^3.0.9",
|
|
40
41
|
"typescript": "^4.4.3"
|
|
41
42
|
},
|
|
@@ -45,6 +46,7 @@
|
|
|
45
46
|
"history": "^5.0.1",
|
|
46
47
|
"lodash": "^4.17.21",
|
|
47
48
|
"react": "^17.0.2",
|
|
48
|
-
"react-dom": "^17.0.2"
|
|
49
|
+
"react-dom": "^17.0.2",
|
|
50
|
+
"swiper": "^6.8.4"
|
|
49
51
|
}
|
|
50
52
|
}
|