pixuireactcomponents 1.4.13 → 1.5.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/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  export { Carousel } from "./src/components/react/app/carousel/Carousel";
2
+ export { CarouselMulti } from "./src/components/react/app/carouselMulti/CarouselMulti";
2
3
  export { Button } from "./src/components/react/app/button/Button";
3
4
  export { CheckBox } from "./src/components/react/app/checkBox/CheckBox";
4
5
  export { DropDown } from "./src/components/react/app/dropDown/DropDown";
5
6
  export { ImageViewer } from "./src/components/react/app/imageViewer/imageViewer";
6
- export { ToggleGroup } from "./src/components/react/app/togglegroup/ToggleGroup";
7
7
  export { VideoPlayer } from "./src/components/react/app/videoPlayer/VideoPlayer";
8
8
  export { WheelPicker } from "./src/components/react/app/wheelPicker/WheelPicker";
9
9
  export { ScratchCard } from "./src/components/react/app/scratchCard/ScratchCard";
package/index.js CHANGED
@@ -1,11 +1,13 @@
1
1
  // Description: This file is the entry point for the library. It exports all the components.
2
2
  export { Carousel } from './src/components/react/app/carousel/Carousel';
3
+ export { CarouselMulti } from './src/components/react/app/carouselMulti/CarouselMulti';
3
4
  export { Button } from './src/components/react/app/button/Button';
4
5
  export { CheckBox } from './src/components/react/app/checkBox/CheckBox';
6
+ import { CheckBoxGroup } from './src/components/react/app/checkBox/CheckBoxGroup';
5
7
  export { DropDown } from './src/components/react/app/dropDown/DropDown';
6
8
  export { ImageViewer } from './src/components/react/app/imageViewer/imageViewer';
7
9
  export { Slider } from './src/components/react/app/slider/Slider';
8
- export { ToggleGroup } from './src/components/react/app/togglegroup/ToggleGroup';
10
+ // export { ToggleGroup } from './src/components/react/app/togglegroup/ToggleGroup';
9
11
  export { VideoPlayer } from './src/components/react/app/videoPlayer/VideoPlayer';
10
12
  export { WheelPicker } from './src/components/react/app/wheelPicker/WheelPicker';
11
13
  export { ScratchCard } from './src/components/react/app/scratchCard/ScratchCard';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixuireactcomponents",
3
- "version": "1.4.13",
3
+ "version": "1.5.1",
4
4
  "description": "pixui react components",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -4,6 +4,7 @@ interface ButtonProps {
4
4
  rootClassName?: string;
5
5
  text: string;
6
6
  onClick: Function;
7
+ disabled?: boolean;
7
8
  }
8
9
  export declare let Button: (props: ButtonProps) => h.JSX.Element;
9
10
  export {};
@@ -1,5 +1,34 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
1
12
  import { h } from 'preact';
2
13
  import { useState } from 'preact/hooks';
14
+ var defaultButtonStyle = {
15
+ padding: '0px 15px',
16
+ height: '32px',
17
+ border: '1px solid transparent',
18
+ borderRadius: '5px',
19
+ backgroundColor: '#1677E1',
20
+ color: 'white',
21
+ cursor: 'pointer',
22
+ transition: 'all 0.3s',
23
+ display: 'flex',
24
+ flexDirection: 'column',
25
+ fontSize: '14px',
26
+ textAlign: 'center',
27
+ justifyContent: 'center'
28
+ };
29
+ var defaultHoverStyle = __assign(__assign({}, defaultButtonStyle), { backgroundColor: '#4096ff', borderColor: '#4096ff' });
30
+ var defaultClickStyle = __assign(__assign({}, defaultButtonStyle), { backgroundColor: '#1677E1', borderColor: '#1677E1' });
31
+ var defaultDisabledStyle = __assign(__assign({}, defaultButtonStyle), { backgroundColor: '#F5F5F5', borderColor: '#d9d9d9', color: '#D2D2D2' });
3
32
  var ButtonState;
4
33
  (function (ButtonState) {
5
34
  ButtonState[ButtonState["normal"] = 0] = "normal";
@@ -9,14 +38,41 @@ var ButtonState;
9
38
  export var Button = function (props) {
10
39
  var _a;
11
40
  var buttonState = (_a = useState(ButtonState.normal), _a[0]), setButtonState = _a[1];
41
+ var getStyle = function () {
42
+ if (props.disabled) {
43
+ return defaultDisabledStyle;
44
+ }
45
+ else {
46
+ switch (buttonState) {
47
+ case ButtonState.normal:
48
+ return defaultButtonStyle;
49
+ case ButtonState.hover:
50
+ return defaultHoverStyle;
51
+ case ButtonState.press:
52
+ return defaultClickStyle;
53
+ }
54
+ }
55
+ };
12
56
  return (h("div", { onMouseDown: function () {
57
+ if (props.disabled) {
58
+ return;
59
+ }
13
60
  setButtonState(ButtonState.press);
14
61
  }, onMouseUp: function () {
62
+ if (props.disabled) {
63
+ return;
64
+ }
15
65
  setButtonState(ButtonState.hover);
16
66
  props.onClick();
17
67
  }, onMouseOver: function () {
68
+ if (props.disabled) {
69
+ return;
70
+ }
18
71
  setButtonState(ButtonState.hover);
19
72
  }, onMouseOut: function () {
73
+ if (props.disabled) {
74
+ return;
75
+ }
20
76
  setButtonState(ButtonState.normal);
21
- }, id: props.rootId, className: props.rootClassName + ' ' + ButtonState[buttonState] }, props.text));
77
+ }, id: props.rootId, className: props.rootClassName + ' ' + ButtonState[buttonState], style: getStyle() }, props.text));
22
78
  };
@@ -20,7 +20,7 @@ export declare function Carousel(props: {
20
20
  rootId?: string;
21
21
  rootClassName?: string;
22
22
  cRef?: any;
23
- children?: preact.JSX.Element[] | HTMLElement[];
23
+ children?: h.JSX.Element[] | HTMLElement[];
24
24
  defaultIndex?: number;
25
25
  compWidth?: number;
26
26
  compHeight?: number;
@@ -29,7 +29,7 @@ export declare function Carousel(props: {
29
29
  loop?: boolean;
30
30
  isVertical?: boolean;
31
31
  touchable?: boolean;
32
- onSlideChange?: Function | null;
33
- onClick?: Function | null;
32
+ onSlideChange?: (index: number) => void;
33
+ onClick?: (index: number) => void;
34
34
  touchSwitchDistance?: number;
35
35
  }): h.JSX.Element;
@@ -2,16 +2,14 @@ import { h } from 'preact';
2
2
  export declare let CarouselMulti: (props: {
3
3
  rootId?: string | undefined;
4
4
  rootClassName?: string | undefined;
5
+ cRef?: any;
6
+ children: h.JSX.Element[];
5
7
  extShowCount: number;
6
- extShowDist: {
7
- num: number;
8
- unit: 'px' | '%' | 'rem';
9
- };
8
+ extShowDist: number;
10
9
  animationTime?: number | undefined;
11
10
  maxScale?: number | undefined;
12
11
  minOpacity?: number | undefined;
12
+ touchable?: boolean | undefined;
13
13
  onClick?: ((index: number) => void) | undefined;
14
- onIndexChange?: ((index: number) => void) | undefined;
15
- cRef?: any;
16
- children: h.JSX.Element[];
14
+ onSlideChange?: ((index: number) => void) | undefined;
17
15
  }) => h.JSX.Element | null;
@@ -1,10 +1,21 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
1
12
  import { h } from 'preact';
2
13
  import { useImperativeHandle, useState, useRef, useEffect } from 'preact/hooks';
3
14
  export var CarouselMulti = function (props) {
4
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
5
- var extShowCount = props.extShowCount, extShowDist = props.extShowDist, rootId = (_a = props.rootId, _a === void 0 ? '' : _a), rootClassName = (_b = props.rootClassName, _b === void 0 ? '' : _b), animationTime = (_c = props.animationTime, _c === void 0 ? 500 : _c), maxScale = (_d = props.maxScale, _d === void 0 ? 1.5 : _d), minOpacity = (_e = props.minOpacity, _e === void 0 ? 0.5 : _e), onClick = props.onClick,
15
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
16
+ var extShowCount = props.extShowCount, extShowDist = props.extShowDist, rootId = (_a = props.rootId, _a === void 0 ? '' : _a), rootClassName = (_b = props.rootClassName, _b === void 0 ? '' : _b), animationTime = (_c = props.animationTime, _c === void 0 ? 500 : _c), maxScale = (_d = props.maxScale, _d === void 0 ? 1.5 : _d), minOpacity = (_e = props.minOpacity, _e === void 0 ? 0.5 : _e), touchable = (_f = props.touchable, _f === void 0 ? true : _f), onClick = props.onClick,
6
17
  // fillAndLoop = true,
7
- onIndexChange = props.onIndexChange;
18
+ onSlideChange = props.onSlideChange;
8
19
  //元素不足extShowCount*2+3时,复制原数组到可以播放动画的长度
9
20
  var children = (function () {
10
21
  var preChildren = props.children;
@@ -18,59 +29,67 @@ export var CarouselMulti = function (props) {
18
29
  // }
19
30
  return preChildren;
20
31
  })();
21
- var onload = (_f = useState(false), _f[0]), setOnload = _f[1];
22
- var zIndexArr = (_g = useState(Array.from({ length: children.length }).map(function () { return 0; })), _g[0]), setZIndexArr = _g[1];
23
- var opacitiyArr = (_h = useState(Array.from({ length: children.length }).map(function () { return 0; })), _h[0]), setOpacitiyArr = _h[1];
24
- var showIndex = (_j = useState(Math.floor((props.children.length - 1) / 2)), _j[0]), setShowIndex = _j[1];
25
- //用于填入 style 的距离
26
- var getDist = function (num) {
27
- return num + extShowDist.unit;
28
- };
32
+ var rootSize = (_g = useState({ width: 0, height: 0 }), _g[0]), setRootSize = _g[1];
33
+ var firstChildRef = useRef(null);
34
+ var onload = (_h = useState(false), _h[0]), setOnload = _h[1];
35
+ var zIndexArr = (_j = useState(Array.from({ length: children.length }).map(function () { return 0; })), _j[0]), setZIndexArr = _j[1];
36
+ var opacitiyArr = (_k = useState(Array.from({ length: children.length }).map(function () { return 0; })), _k[0]), setOpacitiyArr = _k[1];
37
+ var showIndex = (_l = useState(Math.floor((props.children.length - 1) / 2)), _l[0]), setShowIndex = _l[1];
29
38
  var dragX = useRef(0);
30
39
  var isDraging = useRef(false);
31
40
  var getMinDist = function (_index, _showindex) { return Math.min(Math.abs(_index - _showindex), children.length - Math.abs(_index - _showindex)); };
32
- var getLeft = function (index) {
41
+ var getTrueIndex = function (index, minDist) {
33
42
  //计算元素的left,间隔为extShowDist.num,以showIndex为中心,左右两边各显示extShowCount个元素,余下的元素按数组首尾相接的顺序计算 zindex
34
- var left = -1;
35
- var minDist = getMinDist(index, showIndex);
43
+ var trueIndex = -1;
36
44
  if (index == showIndex) {
37
- left = extShowCount;
45
+ trueIndex = extShowCount;
38
46
  }
39
47
  else if (minDist <= extShowCount) {
40
48
  //需要展示
41
49
  if (index < showIndex) {
42
50
  if (Math.abs(index - showIndex) <= extShowCount) {
43
51
  //没跨边界
44
- left = extShowCount - minDist;
52
+ trueIndex = extShowCount - minDist;
45
53
  }
46
54
  else {
47
- left = extShowCount + minDist;
55
+ trueIndex = extShowCount + minDist;
48
56
  }
49
57
  }
50
58
  else if (index > showIndex) {
51
59
  if (Math.abs(index - showIndex) <= extShowCount) {
52
60
  //没跨边界
53
- left = extShowCount + minDist;
61
+ trueIndex = extShowCount + minDist;
54
62
  }
55
63
  else {
56
- left = extShowCount - minDist;
64
+ trueIndex = extShowCount - minDist;
57
65
  }
58
66
  }
59
67
  }
60
68
  else {
61
69
  //盖在下面的元素,计算放到哪边
62
70
  if (Math.abs(index - showIndex + children.length) % children.length <= Math.abs(showIndex - index + children.length) % children.length) {
63
- left = extShowCount * 2;
71
+ trueIndex = extShowCount * 2 + 1;
64
72
  }
65
73
  else {
66
- left = 0;
74
+ trueIndex = -1;
67
75
  }
68
76
  }
69
- return left * extShowDist.num;
77
+ return trueIndex;
78
+ };
79
+ var getStyle = function (index) {
80
+ var style = { transform: '' };
81
+ var minDist = getMinDist(index, showIndex);
82
+ var trueIndex = getTrueIndex(index, minDist);
83
+ var transformLeft = trueIndex * extShowDist + 'px';
84
+ var topScale = maxScale;
85
+ var baseScale = 1;
86
+ var transformScale = Math.max(baseScale + ((topScale - baseScale) * (extShowCount - minDist)) / extShowCount, baseScale);
87
+ style.transform = "translate(".concat(transformLeft, ",0) scale(").concat(transformScale, ")");
88
+ return style;
70
89
  };
71
90
  var onTransitionEnd = function (ev) { };
72
91
  useEffect(function () {
73
- onIndexChange && onIndexChange(showIndex);
92
+ onSlideChange && onSlideChange(showIndex);
74
93
  }, [showIndex]);
75
94
  useImperativeHandle(props.cRef, function () { return ({
76
95
  switchNext: function () {
@@ -90,12 +109,14 @@ export var CarouselMulti = function (props) {
90
109
  var topOpacity = 1;
91
110
  var baseOpacity = minOpacity;
92
111
  //getMinDist越大,越靠近中间,透明度越高
93
- return Math.max(baseOpacity + ((topOpacity - baseOpacity) * (extShowCount - getMinDist(index, showIndex))) / extShowCount, baseOpacity);
94
- };
95
- var getScale = function (index) {
96
- var topScale = maxScale;
97
- var baseScale = 1;
98
- return Math.max(baseScale + ((topScale - baseScale) * (extShowCount - getMinDist(index, showIndex))) / extShowCount, baseScale);
112
+ var minDist = getMinDist(index, showIndex);
113
+ if (minDist <= extShowCount) {
114
+ return Math.max(baseOpacity + ((topOpacity - baseOpacity) * (extShowCount - minDist)) / extShowCount, baseOpacity);
115
+ }
116
+ else {
117
+ // 不在可视区的情况下透明度调为0
118
+ return 0;
119
+ }
99
120
  };
100
121
  useEffect(function () {
101
122
  if (children.length == 0) {
@@ -116,9 +137,11 @@ export var CarouselMulti = function (props) {
116
137
  children.forEach(function (_, _index) {
117
138
  newOpacityArr[_index] = getOpacity(index, _index);
118
139
  });
140
+ console.log("newOpacityArr, ", newOpacityArr);
119
141
  setOpacitiyArr(newOpacityArr);
120
142
  };
121
143
  var changeShowIndex = function (index) {
144
+ console.log('changeShowIndex: ', index, showIndex);
122
145
  if (index >= 0 && index < children.length) {
123
146
  setShowIndex(index);
124
147
  setTimeout(function () {
@@ -126,8 +149,19 @@ export var CarouselMulti = function (props) {
126
149
  }, animationTime * 0.4);
127
150
  }
128
151
  };
129
- return onload ? (h("div", { id: rootId, className: rootClassName, style: { flexDirection: 'column' }, onDrag: function (ev) {
130
- if (!isDraging.current) {
152
+ // 获取第一个子元素宽高来设置父元素的可见区
153
+ useEffect(function () {
154
+ var _a;
155
+ if (firstChildRef.current) {
156
+ var clientWidth = (_a = firstChildRef.current, _a.clientWidth), clientHeight = _a.clientHeight;
157
+ var rootHeight = clientHeight * maxScale;
158
+ var rootWidth = clientWidth + extShowDist * extShowCount * 2;
159
+ console.log('rootSizepx: ', rootWidth, rootHeight);
160
+ setRootSize({ width: rootWidth, height: rootHeight });
161
+ }
162
+ }, [onload]);
163
+ return onload ? (h("div", { id: rootId, className: rootClassName, style: { display: 'flex', flexDirection: 'column', overflow: 'hidden', justifyContent: 'center', width: "".concat(rootSize.width, "px"), height: "".concat(rootSize.height, "px") }, onDrag: function (ev) {
164
+ if (!isDraging.current || !touchable) {
131
165
  return;
132
166
  }
133
167
  //在外层接受 drag 事件,触发切换动作
@@ -147,23 +181,14 @@ export var CarouselMulti = function (props) {
147
181
  }, onDragEnd: function (ev) {
148
182
  isDraging.current = false;
149
183
  }, draggable: true }, children.map(function (child, index) {
150
- return (h("div", { ref: function (ele) {
151
- if (ele) {
152
- //绕过 pixui 初始化设置zIndex 和 opcity 后 transform 错误的问题
153
- // ele.style.transform = `translate(${getDist(getLeft(index) + 1)},0rem) scale(${getScale(index)})`;
154
- ele.style.transition = "transform ".concat(animationTime, "ms");
155
- }
156
- },
184
+ return (h("div", { ref: index === 0 ? firstChildRef : undefined,
157
185
  /**
158
186
  * child数组首尾相接,拼成一个环,除了显示的 extShowCount*2+1 个元素,其余元素分别放到最左和最右,按离中间元素的距离计算 zindex 和 scale
159
187
  * 用getLeft函数统一计算每个元素当前的left值,pixui 不支持zIndex和opacity动画,直接在播放过程中setstate改变元素的zIndex和opacity值
160
188
  */
161
- style: {
162
- position: 'absolute',
163
- transform: "translate(".concat(getDist(getLeft(index)), ",0px) scale(").concat(getScale(index), ")"),
164
- zIndex: zIndexArr[index] || 0,
165
- opacity: opacitiyArr[index] || 1,
166
- }, onClick: function (ev) {
189
+ style: __assign({ position: 'absolute', zIndex: zIndexArr[index] || 0, opacity: opacitiyArr[index] !== undefined ? opacitiyArr[index] : 1, transition: "transform ".concat(animationTime, "ms") }, getStyle(index)), onClick: function (ev) {
190
+ if (!touchable)
191
+ return;
167
192
  changeShowIndex(index);
168
193
  onClick && onClick(index);
169
194
  ev.stopPropagation();
@@ -1,10 +1,19 @@
1
- import { h } from 'preact';
2
- export declare function CheckBox(props: {
1
+ import { CSSProperties, h } from 'preact';
2
+ export interface checkboxElement {
3
+ checkmarkStyle?: string | CSSProperties;
4
+ checkmarkCheckedStyle?: string | CSSProperties;
5
+ checkmarkAfterStyle?: string | CSSProperties;
6
+ checkmarkAfterCheckedStyle?: string | CSSProperties;
7
+ disabledStyle?: string | CSSProperties;
8
+ }
9
+ export interface CheckBoxProps {
3
10
  rootId?: string;
4
11
  rootClassName?: string;
5
- onSelected?: (selected: boolean) => void;
6
- defauleSelected?: boolean;
7
- toggleSize?: number;
8
- content?: string;
9
- contentClassName?: string;
10
- }): h.JSX.Element;
12
+ defaultChecked?: boolean;
13
+ checked?: boolean;
14
+ disabled?: boolean;
15
+ onChange?: (checked: boolean) => void;
16
+ element?: checkboxElement;
17
+ children?: h.JSX.Element;
18
+ }
19
+ export declare const CheckBox: (props: CheckBoxProps) => h.JSX.Element;
@@ -1,14 +1,97 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
1
12
  import { h } from 'preact';
2
- import { useState } from 'preact/hooks';
3
- export function CheckBox(props) {
4
- var _a = props.rootId, rootId = _a === void 0 ? '' : _a, _b = props.rootClassName, rootClassName = _b === void 0 ? '' : _b, _c = props.onSelected, onSelected = _c === void 0 ? null : _c, _d = props.defauleSelected, defauleSelected = _d === void 0 ? false : _d, _e = props.toggleSize, toggleSize = _e === void 0 ? 20 : _e, _f = props.content, content = _f === void 0 ? '' : _f, contentClassName = props.contentClassName;
5
- var _g = useState(defauleSelected), selected = _g[0], setSelected = _g[1];
6
- var selectedNode = (h("img", { src: "https://game.gtimg.cn/images/gamelet/cp/pixui-jnResources/check-box.png", style: { width: toggleSize + 'px', height: toggleSize + 'px' } }));
7
- var notSelectedNode = (h("img", { src: "https://game.gtimg.cn/images/gamelet/cp/pixui-jnResources/blank-check-box.png", style: { width: toggleSize + 'px', height: toggleSize + 'px' } }));
13
+ import { useEffect, useState } from 'preact/hooks';
14
+ var checkmarkStyle = {
15
+ position: 'relative',
16
+ height: '20px',
17
+ width: '20px',
18
+ backgroundColor: '#fff',
19
+ border: '2px solid #d9d9d9',
20
+ borderRadius: '4px',
21
+ };
22
+ var checkmarkCheckedStyle = __assign(__assign({}, checkmarkStyle), { backgroundColor: '#1890ff', border: '2px solid #1890ff' });
23
+ var checkmarkAfterStyle = {
24
+ position: 'absolute',
25
+ display: 'none',
26
+ };
27
+ var checkmarkAfterCheckedStyle = __assign(__assign({}, checkmarkAfterStyle), { display: 'block', top: '-2px', width: '18px', height: '18px', backgroundImage: 'url(https://game.gtimg.cn/images/gamelet/cp/pixui-components/check.png)', backgroundSize: '100% 100%' });
28
+ var disabledStyle = __assign(__assign({}, checkmarkStyle), { backgroundColor: 'rgba(0, 0, 0, 0.04)', border: '2px solid #d9d9d9' });
29
+ export var CheckBox = function (props) {
30
+ var rootId = props.rootId, rootClassName = props.rootClassName, _a = props.defaultChecked, defaultChecked = _a === void 0 ? false : _a, onChange = props.onChange, element = props.element, children = props.children;
31
+ var getElementStyleOrClass = function () {
32
+ if (element == undefined) {
33
+ return {
34
+ checkmarkStyle: checkmarkStyle,
35
+ checkmarkCheckedStyle: checkmarkCheckedStyle,
36
+ checkmarkAfterStyle: checkmarkAfterStyle,
37
+ checkmarkAfterCheckedStyle: checkmarkAfterCheckedStyle,
38
+ disabledStyle: disabledStyle
39
+ };
40
+ }
41
+ else {
42
+ return element;
43
+ }
44
+ };
45
+ var _b = useState(defaultChecked), nowChecked = _b[0], setNowChecked = _b[1];
46
+ var _c = useState(false), nowDisabled = _c[0], setNowDisabled = _c[1];
47
+ useEffect(function () {
48
+ if (nowDisabled) {
49
+ return;
50
+ }
51
+ setNowChecked(props.checked);
52
+ }, [props.checked]);
53
+ useEffect(function () {
54
+ setNowDisabled(props.disabled);
55
+ }, [props.disabled]);
56
+ var elementStyleOrClass = getElementStyleOrClass();
57
+ var getClassName = function () {
58
+ if (nowDisabled) {
59
+ return typeof elementStyleOrClass.disabledStyle === 'string' ? elementStyleOrClass.disabledStyle : '';
60
+ }
61
+ if (nowChecked) {
62
+ return typeof elementStyleOrClass.checkmarkCheckedStyle === 'string' ? elementStyleOrClass.checkmarkCheckedStyle : '';
63
+ }
64
+ return typeof elementStyleOrClass.checkmarkStyle === 'string' ? elementStyleOrClass.checkmarkStyle : '';
65
+ };
66
+ var getStyle = function () {
67
+ if (nowDisabled) {
68
+ return typeof elementStyleOrClass.disabledStyle === 'object' ? elementStyleOrClass.disabledStyle : undefined;
69
+ }
70
+ if (nowChecked) {
71
+ return typeof elementStyleOrClass.checkmarkCheckedStyle === 'object' ? elementStyleOrClass.checkmarkCheckedStyle : undefined;
72
+ }
73
+ return typeof elementStyleOrClass.checkmarkStyle === 'object' ? elementStyleOrClass.checkmarkStyle : undefined;
74
+ };
75
+ var getCheckmaskClassName = function () {
76
+ if (nowChecked) {
77
+ return typeof elementStyleOrClass.checkmarkAfterCheckedStyle === 'string' ? elementStyleOrClass.checkmarkAfterCheckedStyle : '';
78
+ }
79
+ return typeof elementStyleOrClass.checkmarkAfterStyle === 'string' ? elementStyleOrClass.checkmarkAfterStyle : '';
80
+ };
81
+ var getCheckmarkStyle = function () {
82
+ if (nowChecked) {
83
+ return typeof elementStyleOrClass.checkmarkAfterCheckedStyle === 'object' ? elementStyleOrClass.checkmarkAfterCheckedStyle : undefined;
84
+ }
85
+ return typeof elementStyleOrClass.checkmarkAfterStyle === 'object' ? elementStyleOrClass.checkmarkAfterStyle : undefined;
86
+ };
8
87
  return (h("div", { onClick: function () {
9
- onSelected && onSelected(!selected);
10
- setSelected(!selected);
11
- }, id: rootId, className: rootClassName + ' ' + (selected ? 'selected' : 'not-selected'), style: { display: 'flex', flexdirection: 'row' } },
12
- selected ? selectedNode : notSelectedNode,
13
- h("div", { className: contentClassName, style: { flexShrink: 0 } }, content)));
14
- }
88
+ if (nowDisabled) {
89
+ return;
90
+ }
91
+ onChange && onChange(!nowChecked);
92
+ setNowChecked(!nowChecked);
93
+ }, id: rootId, className: rootClassName },
94
+ h("div", { className: getClassName(), style: __assign({ display: 'flex' }, getStyle()) },
95
+ h("div", { className: getCheckmaskClassName(), style: getCheckmarkStyle() }),
96
+ children)));
97
+ };
@@ -0,0 +1,19 @@
1
+ import { h } from 'preact';
2
+ import { checkboxElement } from './CheckBox';
3
+ export interface checkBoxOption {
4
+ label?: h.JSX.Element;
5
+ value: string;
6
+ disabled?: boolean;
7
+ }
8
+ export interface CheckBoxGroupProps {
9
+ rootId?: string;
10
+ rootClassName?: string;
11
+ defaultValue?: string[];
12
+ value?: string[];
13
+ disabled?: boolean;
14
+ onChange?: (value: string[]) => void;
15
+ options: checkBoxOption[];
16
+ checkedOptionNum?: number;
17
+ element?: checkboxElement;
18
+ }
19
+ export declare const CheckBoxGroup: (props: CheckBoxGroupProps) => h.JSX.Element;
@@ -0,0 +1,56 @@
1
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
+ if (ar || !(i in from)) {
4
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
+ ar[i] = from[i];
6
+ }
7
+ }
8
+ return to.concat(ar || Array.prototype.slice.call(from));
9
+ };
10
+ import { h } from 'preact';
11
+ import { useEffect, useState } from 'preact/hooks';
12
+ import { CheckBox } from './CheckBox';
13
+ export var CheckBoxGroup = function (props) {
14
+ var rootId = props.rootId, rootClassName = props.rootClassName, _a = props.defaultValue, defaultValue = _a === void 0 ? [] : _a, onChange = props.onChange, element = props.element, options = props.options, _b = props.checkedOptionNum, checkedOptionNum = _b === void 0 ? options.length : _b;
15
+ var _c = useState(defaultValue), checkedValueList = _c[0], setCheckedValueList = _c[1];
16
+ var _d = useState(false), nowDisabled = _d[0], setNowDisabled = _d[1];
17
+ useEffect(function () {
18
+ if (nowDisabled) {
19
+ return;
20
+ }
21
+ if (props.value) {
22
+ if (props.value.length < checkedOptionNum) {
23
+ setCheckedValueList(props.value);
24
+ }
25
+ }
26
+ }, [props.value]);
27
+ useEffect(function () {
28
+ setNowDisabled(props.disabled);
29
+ }, [props.disabled]);
30
+ var setCurrentCheckedValue = function (value, isChecked) {
31
+ var oldCheckedValueList = __spreadArray([], checkedValueList, true);
32
+ if (oldCheckedValueList) {
33
+ var index = oldCheckedValueList.findIndex(function (checkedValue) { return checkedValue === value; });
34
+ if (index !== -1) {
35
+ if (!isChecked) {
36
+ oldCheckedValueList === null || oldCheckedValueList === void 0 ? void 0 : oldCheckedValueList.splice(index, 1);
37
+ setCheckedValueList(oldCheckedValueList);
38
+ onChange && onChange(oldCheckedValueList);
39
+ }
40
+ }
41
+ else {
42
+ if (isChecked) {
43
+ if (oldCheckedValueList.length >= checkedOptionNum) {
44
+ oldCheckedValueList.splice(0, 1);
45
+ }
46
+ oldCheckedValueList.push(value);
47
+ setCheckedValueList(oldCheckedValueList);
48
+ onChange && onChange(oldCheckedValueList);
49
+ }
50
+ }
51
+ }
52
+ };
53
+ return (h("div", { id: rootId, className: rootClassName }, options.map(function (option, index) {
54
+ return (h(CheckBox, { checked: checkedValueList.includes(option.value), disabled: option.disabled, onChange: function (isChecked) { setCurrentCheckedValue(option.value, isChecked); }, element: element }, option.label));
55
+ })));
56
+ };
@@ -1,25 +1,18 @@
1
- import { h } from 'preact';
2
- /**
3
- *
4
- * @param rootId 根节点id
5
- * @param rootClassName 根节点className
6
- * @param spreadFrameClassName 展开框className
7
- * @param mainItemClassName 标题项className
8
- * @param itemClassName 选项className
9
- * @param mainContent 标题项内容
10
- * @param itemContent 选项内容
11
- * @param onClick 点击选项回调
12
- * @param onSpread 展开收缩回调
13
- */
14
- export declare let DropDown: (props: {
15
- rootId?: string | undefined;
16
- rootClassName?: string | undefined;
17
- spreadFrameClassName?: string | undefined;
18
- mainItemClassName?: string | undefined;
19
- itemClassName?: string | undefined;
20
- mainContent: string;
21
- itemContent: string[];
22
- onClick?: ((index: number) => void) | undefined;
23
- onSpread?: ((spread: boolean) => void) | undefined;
24
- compRef?: any;
25
- }) => h.JSX.Element;
1
+ import preact, { CSSProperties, h } from 'preact';
2
+ export interface dropDownOption {
3
+ value: string;
4
+ label?: h.JSX.Element;
5
+ }
6
+ export interface dropdownElement {
7
+ dropdownBg?: string | CSSProperties;
8
+ }
9
+ export interface DropDownProps {
10
+ rootId?: string;
11
+ rootClassName?: string;
12
+ options: dropDownOption[];
13
+ element?: dropdownElement;
14
+ children?: h.JSX.Element;
15
+ onChange?: (value: string) => void;
16
+ onSpread?: (spread: boolean) => void;
17
+ }
18
+ export declare const DropDown: (props: DropDownProps) => preact.JSX.Element;