@ray-js/lamp-style-slider 0.0.2-beta-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.
@@ -0,0 +1,90 @@
1
+ <sjs src="./index.sjs" module="computed"></sjs>
2
+
3
+ <view
4
+ id="{{instanceId}}"
5
+ class="rayui-slider {{direction === 'vertical' ? 'vertical': 'horizontal'}} {{reverse ? 'reverse': 'no-reverse'}} {{disable ? 'disabled': ''}} {{className}}"
6
+ disable="{{disable}}"
7
+
8
+ change:start="{{computed.startPropObserver(instanceId)}}"
9
+ change:end="{{computed.endPropObserver(instanceId)}}"
10
+ change:watchstart="{{computed.watchstartPropObserver(instanceId)}}"
11
+ change:watchend="{{computed.watchenddPropObserver(instanceId)}}"
12
+ change:hue="{{hue}}"
13
+ start="{{start}}"
14
+ end="{{end}}"
15
+ watchstart="{{watchStart}}"
16
+ watchend="{{watchEnd}}"
17
+
18
+ data-hue="{{hue}}"
19
+ data-min="{{min}}"
20
+ data-max="{{max}}"
21
+ data-closed="{{closed}}"
22
+
23
+ data-step="{{step}}"
24
+
25
+ bind:touchstart="{{computed.handleTrackMouseDown(instanceId)}}"
26
+ bind:touchmove="{{computed.onMouseMove(instanceId)}}"
27
+ bind:touchend="{{computed.onTrackMouseUp(instanceId)}}"
28
+
29
+ data-startmin="{{startMin}}"
30
+ data-startmax="{{startMax}}"
31
+
32
+ data-endmin="{{endMin}}"
33
+ data-endmax="{{endMax}}"
34
+
35
+ data-mode="{{mode}}"
36
+ data-barpad="{{barPad}}"
37
+ data-hidethumb="{{hideThumb}}"
38
+ data-showsteps="{{showSteps}}"
39
+ data-direction="{{direction}}"
40
+ data-reverse="{{reverse}}"
41
+ data-enabletouch="{{enableTouch}}"
42
+ data-enabletouchbar="{{enableTouchBar}}"
43
+ data-maxrangeoffset="{{maxRangeOffset}}"
44
+ data-texttemplate="{{textTemplate}}"
45
+ data-showtext="{{showText}}"
46
+ data-thumbstylecalc="{{thumbStyleCalc}}"
47
+
48
+ style="{{trackStyle}}"
49
+ >
50
+ <view ty:if="{{disable}}" class="rayui-slider-mask"></view>
51
+ <view ty:if="{{showSteps}}" class="rayui-slider-steps">
52
+ <view class="rayui-slider-steps-dot" ty:for="{{steps}}" style="{{stepStyle}}" ty:for-item="step">
53
+ </view>
54
+ </view>
55
+ <view class="rayui-slider-bar"
56
+ style="{{barStyle}}"
57
+ >
58
+ <view ty:if="{{showText}}" class="rayui-slider-bar-text" style="{{textStyle}}">
59
+ {{text}}
60
+ </view>
61
+ <view class="rayui-slider-bar-steps_wrap">
62
+ <view ty:if="{{showSteps}}" class="rayui-slider-steps">
63
+ <view class="rayui-slider-steps-dot" ty:for="{{steps}}" style="{{activeStepStyle}}" ty:for-item="step">
64
+ </view>
65
+ </view>
66
+ </view>
67
+ </view>
68
+ <view
69
+ class="rayui-slider-thumb rayui-slider-thumb-start"
70
+ data-name="start"
71
+ bind:touchstart="{{computed.handleMouseDown(instanceId)}}"
72
+ bind:touchend="{{computed.onMouseUp(instanceId)}}"
73
+ >
74
+ <view
75
+ data-name="start"
76
+ class="rayui-slider-thumb-render rayui-slider-thumb-start-render" style="{{thumbStartStyle}}"
77
+ ></view>
78
+ </view>
79
+ <view
80
+ class="rayui-slider-thumb rayui-slider-thumb-end"
81
+ data-name="end"
82
+ bind:touchstart="{{computed.handleMouseDown(instanceId)}}"
83
+ bind:touchend="{{computed.onMouseUp(instanceId)}}"
84
+ >
85
+ <view
86
+ data-name="end"
87
+ class="rayui-slider-thumb-render rayui-slider-thumb-end-render" style="{{thumbEndStyle}}"
88
+ ></view>
89
+ </view>
90
+ </view>
@@ -0,0 +1,14 @@
1
+ export var tuya = {
2
+ backgroundColor: '#f2f4f6',
3
+ navigationBarTitleText: 'Ray 跨端组件'
4
+ };
5
+ export var wechat = {
6
+ backgroundColor: '#f2f4f6',
7
+ navigationBarTitleText: 'Ray 跨端组件'
8
+ };
9
+ export var native = {
10
+ backgroundColor: '#000000',
11
+ isBleOfflineOverlay: false,
12
+ useSafeAreaView: true,
13
+ navigationBarTitleText: 'Ray 跨端组件'
14
+ };
package/lib/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import { IProps } from './props';
3
+ declare function OpacitySlider(props: IProps): JSX.Element;
4
+ declare namespace OpacitySlider {
5
+ var defaultProps: IProps;
6
+ }
7
+ export default OpacitySlider;
package/lib/index.js ADDED
@@ -0,0 +1,144 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import "core-js/modules/es.array.concat.js";
4
+ import "core-js/modules/es.array.slice.js";
5
+ /* eslint-disable @typescript-eslint/no-unused-vars */
6
+ import React, { useRef, useState, useEffect } from 'react';
7
+ import { View, Text } from '@ray-js/ray';
8
+ import { useDebounceFn, useThrottleFn } from 'ahooks';
9
+ import { formatPercent } from './utils';
10
+ import styles from './index.module.less';
11
+ import Slider from './components/slider';
12
+ import { defaultProps } from './props';
13
+ function OpacitySlider(props) {
14
+ var preValue = useRef(-1);
15
+ var lastValue = useRef(null);
16
+ var timer = useRef(null);
17
+ var isMove = useRef(false);
18
+ var label = props.label,
19
+ _props$min = props.min,
20
+ min = _props$min === void 0 ? 0 : _props$min,
21
+ _props$max = props.max,
22
+ max = _props$max === void 0 ? 1000 : _props$max,
23
+ value = props.value,
24
+ style = props.style,
25
+ _props$trackStyle = props.trackStyle,
26
+ trackStyle = _props$trackStyle === void 0 ? {} : _props$trackStyle,
27
+ _props$thumbStyle = props.thumbStyle,
28
+ thumbStyle = _props$thumbStyle === void 0 ? {} : _props$thumbStyle,
29
+ textValue = props.textValue,
30
+ _props$disable = props.disable,
31
+ disable = _props$disable === void 0 ? false : _props$disable,
32
+ valueStyle = props.valueStyle,
33
+ trackBackgroundColor = props.trackBackgroundColor,
34
+ onTouchStart = props.onTouchStart,
35
+ onTouchMove = props.onTouchMove,
36
+ onTouchEnd = props.onTouchEnd;
37
+ var startRefValue = useRef(-1);
38
+ var handTouchMove = useThrottleFn(function (_ref2) {
39
+ var detail = _ref2.detail;
40
+ if (!onTouchMove || disable) {
41
+ return;
42
+ }
43
+ isMove.current = true;
44
+ lastValue.current = detail.end + min;
45
+ if (detail.end + min === preValue.current) {
46
+ return;
47
+ }
48
+ if (timer.current) {
49
+ return;
50
+ }
51
+ onTouchMove && onTouchMove(detail.end + min);
52
+ setControllerValue(detail.end + min);
53
+ preValue.current = detail.end + min;
54
+ clearTimeout(timer.current);
55
+ timer.current = null;
56
+ if (lastValue.current !== preValue.current) {
57
+ onTouchMove && onTouchMove(lastValue.current + min);
58
+ }
59
+ }, {
60
+ wait: 80
61
+ }).run;
62
+ var endRefValue = useRef(-1);
63
+ var instanceId = useRef("Color_".concat(String(+new Date()).slice(-4), "_").concat(String(Math.random()).slice(-2)));
64
+ var _useState = useState(-1),
65
+ _useState2 = _slicedToArray(_useState, 2),
66
+ controllerValue = _useState2[0],
67
+ setControllerValue = _useState2[1];
68
+ useEffect(function () {
69
+ if (!isMove.current && value !== controllerValue) {
70
+ updateControlVal(value);
71
+ }
72
+ }, [value]);
73
+ var updateControlVal = useDebounceFn(function (val) {
74
+ setControllerValue(val);
75
+ }, {
76
+ wait: 150
77
+ }).run;
78
+ return /*#__PURE__*/React.createElement(View, {
79
+ style: style
80
+ }, label && function renderTextRow() {
81
+ return /*#__PURE__*/React.createElement(View, {
82
+ className: styles.textRow
83
+ }, /*#__PURE__*/React.createElement(Text, {
84
+ className: styles.label
85
+ }, label), /*#__PURE__*/React.createElement(Text, {
86
+ className: styles.label,
87
+ style: {
88
+ margin: '0 4px'
89
+ }
90
+ }, "\xB7"), /*#__PURE__*/React.createElement(Text, {
91
+ className: styles.value,
92
+ style: valueStyle
93
+ }, textValue || "".concat(formatPercent(controllerValue, {
94
+ min: min,
95
+ max: 1000,
96
+ minPercent: min
97
+ }), "%")));
98
+ }(), /*#__PURE__*/React.createElement(View, {
99
+ style: trackStyle
100
+ }, /*#__PURE__*/React.createElement(Slider, {
101
+ instanceId: instanceId.current,
102
+ min: 0,
103
+ max: max - min,
104
+ closed: false,
105
+ disable: disable,
106
+ end: controllerValue - min,
107
+ step: 1,
108
+ enableTouch: true,
109
+ maxRangeOffset: 38,
110
+ bindstart: function handleTouchStart(_ref) {
111
+ var detail = _ref.detail;
112
+ if (!onTouchStart || disable) {
113
+ return;
114
+ }
115
+ if (detail.end === startRefValue.current) {
116
+ return;
117
+ }
118
+ isMove.current = false;
119
+ onTouchStart && onTouchStart(detail.end);
120
+ startRefValue.current = detail.end;
121
+ },
122
+ bindmove: handTouchMove,
123
+ bindend: function handTouchEnd(_ref3) {
124
+ var detail = _ref3.detail;
125
+ if (!onTouchEnd || disable) {
126
+ return;
127
+ }
128
+ if (detail.end + min === endRefValue.current) {
129
+ return;
130
+ }
131
+ isMove.current = false;
132
+ onTouchEnd && onTouchEnd(detail.end + min);
133
+ endRefValue.current = detail.end + min;
134
+ },
135
+ trackStyle: _objectSpread(_objectSpread({}, trackStyle), {}, {
136
+ background: trackBackgroundColor
137
+ }),
138
+ thumbEndStyle: _objectSpread({
139
+ background: "".concat(disable ? '#000' : 'transparent')
140
+ }, thumbStyle)
141
+ })));
142
+ }
143
+ OpacitySlider.defaultProps = defaultProps;
144
+ export default OpacitySlider;
@@ -0,0 +1,27 @@
1
+ .lampSliderMask {
2
+ color: #000;
3
+ font-size: 48rpx;
4
+ font-weight: bold;
5
+ }
6
+ .textRow {
7
+ display: flex;
8
+ justify-content: start;
9
+ margin: 0 0 32rpx 0rpx;
10
+
11
+ .label {
12
+ font-size: 14px;
13
+ font-weight: 700;
14
+ line-height: 19px;
15
+ color: #fff;
16
+ opacity: .9;
17
+ }
18
+
19
+ .value {
20
+ font-size: 14px;
21
+ font-weight: 600;
22
+ line-height: 20px;
23
+ letter-spacing: 0px;
24
+ text-align: left;
25
+ opacity: .9;
26
+ }
27
+ }
package/lib/props.d.ts ADDED
@@ -0,0 +1,87 @@
1
+ /// <reference types="react" />
2
+ export interface IProps {
3
+ /**
4
+ * @description.zh value文字样式
5
+ * @description.en Value style
6
+ * @default false
7
+ */
8
+ valueStyle?: React.CSSProperties;
9
+ /**
10
+ * @description.zh slider的背景颜色
11
+ * @description.en Slider track background color
12
+ * @default false
13
+ */
14
+ trackBackgroundColor?: string;
15
+ /**
16
+ * @description.zh 整体外层样式
17
+ * @description.en Style
18
+ * @default false
19
+ */
20
+ style?: React.CSSProperties;
21
+ /**
22
+ * @description.zh 禁止滑动
23
+ * @description.en Ban sliding
24
+ * @default false
25
+ */
26
+ disable?: boolean;
27
+ /**
28
+ * @description.zh 值的标签,不传不显示标签和值
29
+ * @description.en label
30
+ * @default false
31
+ */
32
+ label?: string;
33
+ /**
34
+ * @description.zh 自定义值显示,不传默认按百分比显示
35
+ * @description.en custom textValue
36
+ * @default false
37
+ */
38
+ textValue?: string;
39
+ /**
40
+ * @description.zh 滑动条Track样式
41
+ * @description.en Sliding track style
42
+ * @default {}
43
+ */
44
+ trackStyle?: React.CSSProperties;
45
+ /**
46
+ * @description.en Fingers sliding block style
47
+ * @description.zh 手指滑块样式
48
+ */
49
+ thumbStyle?: React.CSSProperties;
50
+ /**
51
+ * @description.zh slider值 对应hsv的saturation 范围 1 - 1000
52
+ * @description.en slider value
53
+ * @default 0
54
+ */
55
+ value: number;
56
+ /**
57
+ * @description.zh slider最小值
58
+ * @description.en slider min value
59
+ * @default 0
60
+ */
61
+ min?: number;
62
+ /**
63
+ * @description.zh slider值 最大值
64
+ * @description.en slider max value
65
+ * @default 0
66
+ */
67
+ max?: number;
68
+ /**
69
+ * @description.zh slider 手指点击时触发
70
+ * @description.en slider Value changes
71
+ * @default () => {}
72
+ */
73
+ onTouchStart?: (value: number) => void;
74
+ /**
75
+ * @description.zh slider 手指拖动时触发
76
+ * @description.en slider Value changes
77
+ * @default () => {}
78
+ */
79
+ onTouchMove: (value: number) => void;
80
+ /**
81
+ * @description.zh slider 手指离开时触发
82
+ * @description.en Values change after the trigger
83
+ * @default () => {}
84
+ */
85
+ onTouchEnd?: (value: number) => void;
86
+ }
87
+ export declare const defaultProps: IProps;
package/lib/props.js ADDED
@@ -0,0 +1,20 @@
1
+ /* eslint-disable prettier/prettier */
2
+ /* eslint-disable @typescript-eslint/no-empty-function */
3
+
4
+ export var defaultProps = {
5
+ value: 1,
6
+ trackStyle: {},
7
+ trackBackgroundColor: 'transparent',
8
+ style: {},
9
+ min: 0,
10
+ max: 1000,
11
+ onTouchStart: function onTouchStart() {
12
+ return null;
13
+ },
14
+ onTouchMove: function onTouchMove() {
15
+ return null;
16
+ },
17
+ onTouchEnd: function onTouchEnd() {
18
+ return null;
19
+ }
20
+ };
@@ -0,0 +1,13 @@
1
+ declare module '*.less';
2
+ declare global {
3
+ interface Window {
4
+ devToolsExtension?: () => any;
5
+ ty: Ty;
6
+ }
7
+ }
8
+
9
+ interface Ty {
10
+ [key]: any;
11
+ }
12
+
13
+ declare const ty: Ty;
@@ -0,0 +1,7 @@
1
+ interface PercentOption {
2
+ min?: number;
3
+ max?: number;
4
+ minPercent?: number;
5
+ }
6
+ export declare const formatPercent: (value?: number, { min, max, minPercent }?: PercentOption) => number;
7
+ export {};
@@ -0,0 +1,11 @@
1
+ export var formatPercent = function () {
2
+ var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
3
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
4
+ _ref$min = _ref.min,
5
+ min = _ref$min === void 0 ? 0 : _ref$min,
6
+ _ref$max = _ref.max,
7
+ max = _ref$max === void 0 ? 1000 : _ref$max,
8
+ _ref$minPercent = _ref.minPercent,
9
+ minPercent = _ref$minPercent === void 0 ? 0 : _ref$minPercent;
10
+ return Math.min(100, Math.round((100 - minPercent) * (value - min) / (max - min) + minPercent));
11
+ };
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@ray-js/lamp-style-slider",
3
+ "version": "0.0.2-beta-1",
4
+ "description": "照明样式的基础滑动条",
5
+ "main": "lib/index",
6
+ "files": [
7
+ "lib"
8
+ ],
9
+ "license": "MIT",
10
+ "types": "lib/index.d.ts",
11
+ "maintainers": [
12
+ "tuya_npm",
13
+ {
14
+ "name": "tuyafe",
15
+ "email": "tuyafe@tuya.com"
16
+ }
17
+ ],
18
+ "scripts": {
19
+ "lint": "eslint src --ext .js,.jsx,.ts,.tsx --fix",
20
+ "build": "ray build --type=component",
21
+ "watch": "ray start --type=component",
22
+ "build:tuya": "ray build ./example --target=tuya",
23
+ "build:wechat": "ray build ./example --target=wechat",
24
+ "build:web": "ray build ./example --target=web",
25
+ "build:native": "ray build ./example --target=native",
26
+ "start:native": "ray start ./example -t native --verbose",
27
+ "start:tuya": "ray start ./example -t tuya --verbose",
28
+ "start:wechat": "ray start ./example -t wechat --verbose",
29
+ "start:web": "ray start ./example -t web",
30
+ "prepublishOnly": "yarn build",
31
+ "release-it": "standard-version",
32
+ "copy": "sh copy.sh"
33
+ },
34
+ "peerDependencies": {
35
+ "@ray-js/panel-sdk": "^1.1.4"
36
+ },
37
+ "devDependencies": {
38
+ "@commitlint/cli": "^7.2.1",
39
+ "@commitlint/config-conventional": "^9.0.1",
40
+ "@ray-js/babel-preset-standard": "^0.6.14",
41
+ "@ray-js/cli": "^0.6.14",
42
+ "@ray-js/panel-sdk": "^1.1.4",
43
+ "@ray-js/ray": "^0.6.14",
44
+ "@ray-js/rn-transformer-helper": "^0.5.5",
45
+ "@types/node": "^17.0.43",
46
+ "core-js": "^3.19.1",
47
+ "eslint-config-tuya-panel": "^0.4.1",
48
+ "husky": "^1.2.0",
49
+ "lint-staged": "^10.2.11",
50
+ "standard-version": "9.3.2"
51
+ },
52
+ "husky": {
53
+ "hooks": {
54
+ "commit-msg": "commitlint -E HUSKY_GIT_PARAMS --config commitlint.config.js",
55
+ "pre-commit": "lint-staged && npm run copy"
56
+ }
57
+ },
58
+ "lint-staged": {
59
+ "*.{ts,tsx,js,jsx}": [
60
+ "eslint --fix",
61
+ "git add"
62
+ ],
63
+ "*.{json,md,yml,yaml}": [
64
+ "prettier --write",
65
+ "git add"
66
+ ]
67
+ },
68
+ "dependencies": {}
69
+ }