@trionesdev/antd-mobile-base-react 0.0.2-beta.15 → 0.0.2-beta.16

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.
@@ -1,15 +1,13 @@
1
- import React from "react";
2
- import { FC } from "react";
1
+ import React, { FC } from "react";
3
2
  import "./style.scss";
4
- import { SizeType } from "../types";
5
3
  export type InputNumberProps = {
6
- size?: SizeType;
7
4
  value?: number;
8
5
  onChange?: (value: number) => void;
9
6
  step?: number;
10
7
  min?: number;
11
8
  max?: number;
12
9
  disabled?: boolean;
10
+ block?: boolean;
13
11
  className?: string;
14
12
  style?: React.CSSProperties;
15
13
  };
@@ -8,66 +8,84 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
8
8
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
9
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
10
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
- import React, { useEffect } from "react";
11
+ import React, { useEffect, useState } from "react";
12
12
  import classNames from "classnames";
13
- import { AddOutline, MinusOutline } from "../../../antd-mobile-icons-react";
13
+ import { AddOutline, MinusOutline } from "@trionesdev/antd-mobile-icons-react";
14
14
  import "./style.scss";
15
+ function clampValue(n, min, max) {
16
+ var v = n;
17
+ if (min !== undefined) v = Math.max(min, v);
18
+ if (max !== undefined) v = Math.min(max, v);
19
+ return v;
20
+ }
15
21
  export var InputNumber = function InputNumber(_ref) {
16
- var size = _ref.size,
17
- value = _ref.value,
18
- _onChange = _ref.onChange,
22
+ var value = _ref.value,
23
+ onChange = _ref.onChange,
19
24
  step = _ref.step,
20
25
  min = _ref.min,
21
26
  max = _ref.max,
22
27
  _ref$disabled = _ref.disabled,
23
28
  disabled = _ref$disabled === void 0 ? false : _ref$disabled,
29
+ _ref$block = _ref.block,
30
+ block = _ref$block === void 0 ? false : _ref$block,
24
31
  className = _ref.className,
25
32
  style = _ref.style;
26
- var _React$useState = React.useState(value || 0),
27
- _React$useState2 = _slicedToArray(_React$useState, 2),
28
- internalValue = _React$useState2[0],
29
- setInternalValue = _React$useState2[1];
33
+ var _useState = useState(value !== null && value !== void 0 ? value : 0),
34
+ _useState2 = _slicedToArray(_useState, 2),
35
+ internalValue = _useState2[0],
36
+ setInternalValue = _useState2[1];
37
+ var stepSize = step !== null && step !== void 0 ? step : 1;
30
38
  useEffect(function () {
31
39
  if (value !== undefined) {
32
- if (value !== internalValue) {
33
- setInternalValue(value);
34
- }
40
+ setInternalValue(clampValue(value, min, max));
35
41
  }
36
- }, [value]);
42
+ }, [value, min, max]);
37
43
  var minMatch = min !== undefined && internalValue <= min;
38
44
  var maxMatch = max !== undefined && internalValue >= max;
39
45
  var trionesInputNumberCls = 'triones-antm-input-number';
46
+ var setValue = function setValue(next) {
47
+ var clamped = clampValue(next, min, max);
48
+ setInternalValue(clamped);
49
+ onChange === null || onChange === void 0 || onChange(clamped);
50
+ };
40
51
  return /*#__PURE__*/React.createElement("div", {
41
- className: classNames(trionesInputNumberCls, className),
52
+ className: classNames(trionesInputNumberCls, _defineProperty({}, "".concat(trionesInputNumberCls, "--block"), block), className),
42
53
  style: style
43
54
  }, /*#__PURE__*/React.createElement("div", {
44
- className: classNames("".concat(trionesInputNumberCls, "-button"), _defineProperty(_defineProperty(_defineProperty({}, "".concat(trionesInputNumberCls, "-button-sm"), size == 'small'), "".concat(trionesInputNumberCls, "-button-lg"), size == 'large'), "".concat(trionesInputNumberCls, "-button-disabled"), minMatch || disabled)),
55
+ className: classNames("".concat(trionesInputNumberCls, "-button"), _defineProperty({}, "".concat(trionesInputNumberCls, "-button-disabled"), minMatch || disabled)),
56
+ role: "button",
57
+ tabIndex: disabled || minMatch ? -1 : 0,
45
58
  onClick: function onClick() {
46
- if (minMatch) {
59
+ if (minMatch || disabled) {
47
60
  return;
48
61
  }
49
- var newValue = internalValue - (step || 1);
50
- setInternalValue(newValue);
51
- _onChange === null || _onChange === void 0 || _onChange(newValue);
62
+ setValue(internalValue - stepSize);
52
63
  }
53
- }, /*#__PURE__*/React.createElement(MinusOutline, null)), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("input", {
64
+ }, /*#__PURE__*/React.createElement(MinusOutline, null)), /*#__PURE__*/React.createElement("div", {
65
+ className: "".concat(trionesInputNumberCls, "-input")
66
+ }, /*#__PURE__*/React.createElement("input", {
54
67
  type: "number",
55
68
  disabled: disabled,
69
+ min: min,
70
+ max: max,
71
+ step: stepSize,
56
72
  value: internalValue,
57
73
  onChange: function onChange(e) {
58
- var newVal = Number(e.target.value);
59
- setInternalValue(newVal);
60
- _onChange === null || _onChange === void 0 || _onChange(newVal);
74
+ var num = Number(e.target.value);
75
+ if (!Number.isFinite(num)) {
76
+ return;
77
+ }
78
+ setValue(num);
61
79
  }
62
80
  })), /*#__PURE__*/React.createElement("div", {
63
- className: classNames("".concat(trionesInputNumberCls, "-button"), _defineProperty(_defineProperty(_defineProperty({}, "".concat(trionesInputNumberCls, "-button-sm"), size == 'small'), "".concat(trionesInputNumberCls, "-button-lg"), size == 'large'), "".concat(trionesInputNumberCls, "-button-disabled"), maxMatch || disabled)),
81
+ className: classNames("".concat(trionesInputNumberCls, "-button"), _defineProperty({}, "".concat(trionesInputNumberCls, "-button-disabled"), maxMatch || disabled)),
82
+ role: "button",
83
+ tabIndex: disabled || maxMatch ? -1 : 0,
64
84
  onClick: function onClick() {
65
- if (maxMatch) {
85
+ if (maxMatch || disabled) {
66
86
  return;
67
87
  }
68
- var newVal = internalValue + (step || 1);
69
- setInternalValue(newVal);
70
- _onChange === null || _onChange === void 0 || _onChange(newVal);
88
+ setValue(internalValue + stepSize);
71
89
  }
72
90
  }, /*#__PURE__*/React.createElement(AddOutline, null)));
73
91
  };
@@ -1,45 +1,82 @@
1
1
  @use "../style/variable" as variable;
2
+
2
3
  $trionesInputNumberCls: 'triones-antm-input-number';
3
4
 
4
- $inputNumberBg: #EEEEEE;
5
+ $inputNumberBg: #F5F5F5;
5
6
  $inputSm: 24Px;
6
7
  $inputLg: 40Px;
8
+ $inputNumberControlHeight: 28Px;
7
9
 
8
10
  .#{$trionesInputNumberCls} {
9
11
  display: inline-flex;
10
- align-items: center;
11
- gap: 4Px;
12
- border-radius: variable.$trionesBorderRadius;
13
- background-color: $inputNumberBg;
12
+ align-items: stretch;
13
+ gap: 2Px;
14
+ border-radius: variable.$trionesBorderRadiusXs;
15
+ overflow: hidden;
14
16
 
15
- input {
17
+ &--block {
18
+ display: flex;
19
+ width: 100%;
16
20
 
17
- &::-webkit-outer-spin-button,
18
- &::-webkit-inner-spin-button {
19
- -webkit-appearance: none;
20
- margin: 0;
21
+ .#{$trionesInputNumberCls}-input {
22
+ flex: 1 1 auto;
23
+ min-width: 0;
21
24
  }
25
+ }
22
26
 
23
- background-color: transparent;
24
- border: 0;
25
- text-align: center ;
26
- width: 32Px;
27
+ &-input {
28
+ display: flex;
29
+ align-items: stretch;
30
+ flex: 0 1 auto;
31
+ min-width: 36Px;
32
+ min-height: $inputNumberControlHeight;
27
33
 
34
+ input {
35
+ width: 100%;
36
+ min-width: 0;
37
+ height: 100%;
38
+ min-height: $inputNumberControlHeight;
39
+ box-sizing: border-box;
40
+ margin: 0;
41
+ padding: 0 8Px;
42
+ border: 0;
43
+ border-radius: variable.$trionesBorderRadiusXs;
44
+ background-color: $inputNumberBg;
45
+ color: variable.$trionesColorText;
46
+ font-size: 14Px;
47
+ line-height: $inputNumberControlHeight;
48
+ text-align: center;
49
+ -moz-appearance: textfield;
50
+ appearance: textfield;
51
+
52
+ &::-webkit-outer-spin-button,
53
+ &::-webkit-inner-spin-button {
54
+ -webkit-appearance: none;
55
+ margin: 0;
56
+ }
28
57
 
29
- &:focus {
30
- outline: none;
58
+ &:focus {
59
+ outline: none;
60
+ }
61
+
62
+ &:disabled {
63
+ color: variable.$trionesColorTextDisabled;
64
+ cursor: not-allowed;
65
+ }
31
66
  }
32
67
  }
33
68
 
34
-
35
69
  &-button {
36
70
  cursor: pointer;
37
71
  display: flex;
72
+ flex-shrink: 0;
38
73
  font-size: 10Px;
39
- height: 32Px;
40
- width: 32Px;
74
+ height: $inputNumberControlHeight;
75
+ width: $inputNumberControlHeight;
41
76
  justify-content: center;
42
77
  align-items: center;
78
+ background-color: $inputNumberBg;
79
+ border-radius: variable.$trionesBorderRadiusXs;
43
80
 
44
81
  &-sm {
45
82
  width: $inputSm;
@@ -60,4 +97,4 @@ $inputLg: 40Px;
60
97
  font-size: 10Px !important;
61
98
  }
62
99
  }
63
- }
100
+ }
@@ -0,0 +1,3 @@
1
+ import { Stepper, StepperProps } from "./stepper";
2
+ export type { StepperProps };
3
+ export default Stepper;
@@ -0,0 +1,2 @@
1
+ import { Stepper } from "./stepper";
2
+ export default Stepper;
@@ -0,0 +1,14 @@
1
+ import React, { FC } from "react";
2
+ import "./style.scss";
3
+ export type StepperProps = {
4
+ value?: number;
5
+ onChange?: (value: number) => void;
6
+ step?: number;
7
+ min?: number;
8
+ max?: number;
9
+ disabled?: boolean;
10
+ block?: boolean;
11
+ className?: string;
12
+ style?: React.CSSProperties;
13
+ };
14
+ export declare const Stepper: FC<StepperProps>;
@@ -0,0 +1,91 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
3
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
4
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
5
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
+ import React, { useEffect, useState } from "react";
12
+ import classNames from "classnames";
13
+ import { AddOutline, MinusOutline } from "@trionesdev/antd-mobile-icons-react";
14
+ import "./style.scss";
15
+ function clampValue(n, min, max) {
16
+ var v = n;
17
+ if (min !== undefined) v = Math.max(min, v);
18
+ if (max !== undefined) v = Math.min(max, v);
19
+ return v;
20
+ }
21
+ export var Stepper = function Stepper(_ref) {
22
+ var value = _ref.value,
23
+ onChange = _ref.onChange,
24
+ step = _ref.step,
25
+ min = _ref.min,
26
+ max = _ref.max,
27
+ _ref$disabled = _ref.disabled,
28
+ disabled = _ref$disabled === void 0 ? false : _ref$disabled,
29
+ _ref$block = _ref.block,
30
+ block = _ref$block === void 0 ? false : _ref$block,
31
+ className = _ref.className,
32
+ style = _ref.style;
33
+ var _useState = useState(value !== null && value !== void 0 ? value : 0),
34
+ _useState2 = _slicedToArray(_useState, 2),
35
+ internalValue = _useState2[0],
36
+ setInternalValue = _useState2[1];
37
+ var stepSize = step !== null && step !== void 0 ? step : 1;
38
+ useEffect(function () {
39
+ if (value !== undefined) {
40
+ setInternalValue(clampValue(value, min, max));
41
+ }
42
+ }, [value, min, max]);
43
+ var minMatch = min !== undefined && internalValue <= min;
44
+ var maxMatch = max !== undefined && internalValue >= max;
45
+ var trionesStepperCls = 'triones-antm-stepper';
46
+ var setValue = function setValue(next) {
47
+ var clamped = clampValue(next, min, max);
48
+ setInternalValue(clamped);
49
+ onChange === null || onChange === void 0 || onChange(clamped);
50
+ };
51
+ return /*#__PURE__*/React.createElement("div", {
52
+ className: classNames(trionesStepperCls, _defineProperty({}, "".concat(trionesStepperCls, "--block"), block), className),
53
+ style: style
54
+ }, /*#__PURE__*/React.createElement("div", {
55
+ className: classNames("".concat(trionesStepperCls, "-button"), _defineProperty({}, "".concat(trionesStepperCls, "-button-disabled"), minMatch || disabled)),
56
+ role: "button",
57
+ tabIndex: disabled || minMatch ? -1 : 0,
58
+ onClick: function onClick() {
59
+ if (minMatch || disabled) {
60
+ return;
61
+ }
62
+ setValue(internalValue - stepSize);
63
+ }
64
+ }, /*#__PURE__*/React.createElement(MinusOutline, null)), /*#__PURE__*/React.createElement("div", {
65
+ className: "".concat(trionesStepperCls, "-input")
66
+ }, /*#__PURE__*/React.createElement("input", {
67
+ type: "number",
68
+ disabled: disabled,
69
+ min: min,
70
+ max: max,
71
+ step: stepSize,
72
+ value: internalValue,
73
+ onChange: function onChange(e) {
74
+ var num = Number(e.target.value);
75
+ if (!Number.isFinite(num)) {
76
+ return;
77
+ }
78
+ setValue(num);
79
+ }
80
+ })), /*#__PURE__*/React.createElement("div", {
81
+ className: classNames("".concat(trionesStepperCls, "-button"), _defineProperty({}, "".concat(trionesStepperCls, "-button-disabled"), maxMatch || disabled)),
82
+ role: "button",
83
+ tabIndex: disabled || maxMatch ? -1 : 0,
84
+ onClick: function onClick() {
85
+ if (maxMatch || disabled) {
86
+ return;
87
+ }
88
+ setValue(internalValue + stepSize);
89
+ }
90
+ }, /*#__PURE__*/React.createElement(AddOutline, null)));
91
+ };
@@ -0,0 +1,100 @@
1
+ @use "../style/variable" as variable;
2
+
3
+ $trionesStepperCls: 'triones-antm-stepper';
4
+
5
+ $inputNumberBg: #F5F5F5;
6
+ $inputSm: 24Px;
7
+ $inputLg: 40Px;
8
+ $stepperControlHeight: 28Px;
9
+
10
+ .#{$trionesStepperCls} {
11
+ display: inline-flex;
12
+ align-items: stretch;
13
+ gap: 2Px;
14
+ border-radius: variable.$trionesBorderRadiusXs;
15
+ overflow: hidden;
16
+ width: 110Px;
17
+
18
+ &--block {
19
+ display: flex;
20
+ box-sizing: border-box;
21
+ width: 100%;
22
+ max-width: 100%;
23
+ min-width: 0;
24
+ flex: 1 1 auto;
25
+
26
+ .#{$trionesStepperCls}-input {
27
+ flex: 1 1 auto;
28
+ min-width: 0;
29
+
30
+ input {
31
+ width: 100%;
32
+ }
33
+ }
34
+ }
35
+
36
+ &-input {
37
+ display: flex;
38
+ align-items: stretch;
39
+ //flex: 0 1 auto;
40
+ min-width: 36Px;
41
+ min-height: $stepperControlHeight;
42
+
43
+ input {
44
+ width: 100%;
45
+ min-width: 0;
46
+ height: 100%;
47
+ min-height: $stepperControlHeight;
48
+ box-sizing: border-box;
49
+ margin: 0;
50
+ padding: 0 8Px;
51
+ border: 0;
52
+ border-radius: variable.$trionesBorderRadiusXs;
53
+ background-color: $inputNumberBg;
54
+ color: variable.$trionesColorText;
55
+ font-size: 14Px;
56
+ line-height: $stepperControlHeight;
57
+ text-align: center;
58
+ appearance: textfield;
59
+
60
+ &::-webkit-outer-spin-button,
61
+ &::-webkit-inner-spin-button {
62
+ -webkit-appearance: none;
63
+ margin: 0;
64
+ }
65
+
66
+ &:focus {
67
+ outline: none;
68
+ }
69
+
70
+ &:disabled {
71
+ color: variable.$trionesColorTextDisabled;
72
+ cursor: not-allowed;
73
+ }
74
+ }
75
+ }
76
+
77
+ &-button {
78
+ cursor: pointer;
79
+ display: flex;
80
+ flex-shrink: 0;
81
+ font-size: 10Px;
82
+ height: $stepperControlHeight;
83
+ width: $stepperControlHeight;
84
+ justify-content: center;
85
+ align-items: center;
86
+ background-color: $inputNumberBg;
87
+ border-radius: variable.$trionesBorderRadiusXs;
88
+ color: variable.$trionesColorPrimary;
89
+
90
+
91
+ &-disabled {
92
+ cursor: not-allowed;
93
+ color: variable.$trionesColorTextDisabled;
94
+ }
95
+
96
+ .triones-antm-icon {
97
+ font-size: 12Px !important;
98
+ }
99
+ }
100
+ }
package/dist/index.d.ts CHANGED
@@ -59,6 +59,8 @@ export { default as Space } from './Space';
59
59
  export type { SpaceProps } from './Space';
60
60
  export { default as SpinLoading } from './SpinLoading';
61
61
  export type { SpinLoadingProps } from './SpinLoading';
62
+ export { default as Stepper } from './Stepper';
63
+ export type { StepperProps } from './Stepper';
62
64
  export { default as Steps } from './Steps';
63
65
  export type { StepsProps, StepsItemProps } from './Steps';
64
66
  export { default as Switch } from './Switch';
package/dist/index.js CHANGED
@@ -29,6 +29,7 @@ export { default as Scaffold } from "./Scaffold";
29
29
  export { Segmented } from "./Segmented";
30
30
  export { default as Space } from "./Space";
31
31
  export { default as SpinLoading } from "./SpinLoading";
32
+ export { default as Stepper } from "./Stepper";
32
33
  export { default as Steps } from "./Steps";
33
34
  export { default as Switch } from "./Switch";
34
35
  export { default as TabBar } from "./TabBar";
@@ -106,7 +106,7 @@ $trionesColorDanger: var(--triones-color-danger,#ff4d4f) !default;
106
106
 
107
107
 
108
108
  $trionesColorBgBase: var(--triones-color-bg-base,#fff) !default;
109
- $trionesColorBgScaffold: var(--triones-color-bg-scaffold,#EDEDED) !default;
109
+ $trionesColorBgScaffold: var(--triones-color-bg-scaffold,#F6F7FA) !default;
110
110
 
111
111
  $trionesBorderRadius: var(--triones-border-radius,6Px) !default;
112
112
  $trionesBorderRadiusXs: var(--triones-border-radius-xs,2Px) !default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trionesdev/antd-mobile-base-react",
3
- "version": "0.0.2-beta.15",
3
+ "version": "0.0.2-beta.16",
4
4
  "description": "antd mobile base react",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -48,7 +48,7 @@
48
48
  "runes2": "^1.1.4"
49
49
  },
50
50
  "optionalDependencies": {
51
- "@trionesdev/antd-mobile-icons-react": "0.0.2-beta.14"
51
+ "@trionesdev/antd-mobile-icons-react": "0.0.2-beta.16"
52
52
  },
53
- "gitHead": "5d9e7dbf380ca19c5e35509f0a31865ec5bdcc06"
53
+ "gitHead": "c43752ae341cc478de96784586fbf3b36251f4a0"
54
54
  }