@canlooks/can-ui 0.0.195 → 0.0.196

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.
@@ -14,5 +14,7 @@ export interface CounterProps extends Omit<FlexProps, 'defaultValue' | 'onChange
14
14
  decreaseProps?: ButtonProps;
15
15
  increaseProps?: ButtonProps;
16
16
  inputProps?: InputProps;
17
+ readOnly?: boolean;
18
+ disabled?: boolean;
17
19
  }
18
- export declare const Counter: import("react").MemoExoticComponent<({ size, min, max, step, precision, defaultValue, value, onChange, decreaseProps, increaseProps, inputProps, ...props }: CounterProps) => import("@emotion/react/jsx-runtime").JSX.Element>;
20
+ export declare const Counter: import("react").MemoExoticComponent<({ size, min, max, step, precision, defaultValue, value, onChange, decreaseProps, increaseProps, inputProps, readOnly, disabled, ...props }: CounterProps) => import("@emotion/react/jsx-runtime").JSX.Element>;
@@ -11,7 +11,7 @@ const flex_1 = require("../flex");
11
11
  const icon_1 = require("../icon");
12
12
  const faMinus_1 = require("@fortawesome/free-solid-svg-icons/faMinus");
13
13
  const faPlus_1 = require("@fortawesome/free-solid-svg-icons/faPlus");
14
- exports.Counter = (0, react_1.memo)(({ size, min = -Infinity, max = Infinity, step = 1, precision = 0, defaultValue = 0, value, onChange, decreaseProps, increaseProps, inputProps, ...props }) => {
14
+ exports.Counter = (0, react_1.memo)(({ size, min = -Infinity, max = Infinity, step = 1, precision = 0, defaultValue = 0, value, onChange, decreaseProps, increaseProps, inputProps, readOnly, disabled, ...props }) => {
15
15
  const [innerValue, setInnerValue] = (0, utils_1.useControlled)(defaultValue, value, onChange);
16
16
  const commonButtonProps = {
17
17
  size,
@@ -21,13 +21,13 @@ exports.Counter = (0, react_1.memo)(({ size, min = -Infinity, max = Infinity, st
21
21
  const clickHandler = (dir) => {
22
22
  setInnerValue(Math.max(min, Math.min(max, innerValue.current + dir * step)));
23
23
  };
24
- return ((0, jsx_runtime_1.jsxs)(flex_1.Flex, { compact: true, ...props, css: counter_style_1.style, className: (0, utils_1.clsx)(counter_style_1.classes.root, props.className), children: [(0, jsx_runtime_1.jsx)(button_1.Button, { disabled: innerValue.current <= min, ...(0, utils_1.mergeComponentProps)(commonButtonProps, decreaseProps, {
24
+ return ((0, jsx_runtime_1.jsxs)(flex_1.Flex, { compact: true, ...props, css: counter_style_1.style, className: (0, utils_1.clsx)(counter_style_1.classes.root, props.className), children: [(0, jsx_runtime_1.jsx)(button_1.Button, { readOnly: readOnly, disabled: disabled || innerValue.current <= min, ...(0, utils_1.mergeComponentProps)(commonButtonProps, decreaseProps, {
25
25
  onClick: () => clickHandler(-1)
26
- }), children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: faMinus_1.faMinus }) }), (0, jsx_runtime_1.jsx)(input_1.Input, { type: "number", widthAdaptable: true, size: size, min: min, max: max, step: step, precision: precision, ...(0, utils_1.mergeComponentProps)(inputProps, {
26
+ }), children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: faMinus_1.faMinus }) }), (0, jsx_runtime_1.jsx)(input_1.Input, { type: "number", widthAdaptable: true, size: size, min: min, max: max, step: step, precision: precision, readOnly: readOnly, disabled: disabled, ...(0, utils_1.mergeComponentProps)(inputProps, {
27
27
  className: counter_style_1.classes.input,
28
28
  value: innerValue.current,
29
29
  onChange: e => setInnerValue(+e.target.value)
30
- }) }), (0, jsx_runtime_1.jsx)(button_1.Button, { disabled: innerValue.current >= max, ...(0, utils_1.mergeComponentProps)(commonButtonProps, increaseProps, {
30
+ }) }), (0, jsx_runtime_1.jsx)(button_1.Button, { readOnly: readOnly, disabled: disabled || innerValue.current >= max, ...(0, utils_1.mergeComponentProps)(commonButtonProps, increaseProps, {
31
31
  onClick: () => clickHandler(1)
32
32
  }), children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: faPlus_1.faPlus }) })] }));
33
33
  });
@@ -8,7 +8,7 @@ const pagination_style_1 = require("./pagination.style");
8
8
  const pagination_1 = require("./pagination");
9
9
  exports.PaginationCounter = (0, react_1.memo)((props) => {
10
10
  const { total, page, pageSize } = (0, pagination_1.usePaginationContext)();
11
- const start = (page - 1) * pageSize + 1;
11
+ const start = Math.min((page - 1) * pageSize + 1, total);
12
12
  const end = Math.min(start + pageSize - 1, total);
13
13
  return ((0, jsx_runtime_1.jsxs)("div", { ...props, className: (0, utils_1.clsx)(pagination_style_1.classes.counter, props.className), children: ["\u7B2C ", start, "-", end, " \u6761/\u5171 ", total, " \u6761"] }));
14
14
  });
@@ -15,9 +15,11 @@ const PaginationContext = (0, react_1.createContext)({
15
15
  total: 0,
16
16
  pageCount: 1,
17
17
  page: 1,
18
- onPageChange(page) { },
18
+ onPageChange(page) {
19
+ },
19
20
  pageSize: 10,
20
- onPageSizeChange(pageSize) { }
21
+ onPageSizeChange(pageSize) {
22
+ }
21
23
  });
22
24
  function usePaginationContext() {
23
25
  return (0, react_1.useContext)(PaginationContext);
@@ -14,5 +14,7 @@ export interface CounterProps extends Omit<FlexProps, 'defaultValue' | 'onChange
14
14
  decreaseProps?: ButtonProps;
15
15
  increaseProps?: ButtonProps;
16
16
  inputProps?: InputProps;
17
+ readOnly?: boolean;
18
+ disabled?: boolean;
17
19
  }
18
- export declare const Counter: import("react").MemoExoticComponent<({ size, min, max, step, precision, defaultValue, value, onChange, decreaseProps, increaseProps, inputProps, ...props }: CounterProps) => import("@emotion/react/jsx-runtime").JSX.Element>;
20
+ export declare const Counter: import("react").MemoExoticComponent<({ size, min, max, step, precision, defaultValue, value, onChange, decreaseProps, increaseProps, inputProps, readOnly, disabled, ...props }: CounterProps) => import("@emotion/react/jsx-runtime").JSX.Element>;
@@ -8,7 +8,7 @@ import { Flex } from '../flex/index.js';
8
8
  import { Icon } from '../icon/index.js';
9
9
  import { faMinus } from '@fortawesome/free-solid-svg-icons/faMinus';
10
10
  import { faPlus } from '@fortawesome/free-solid-svg-icons/faPlus';
11
- export const Counter = memo(({ size, min = -Infinity, max = Infinity, step = 1, precision = 0, defaultValue = 0, value, onChange, decreaseProps, increaseProps, inputProps, ...props }) => {
11
+ export const Counter = memo(({ size, min = -Infinity, max = Infinity, step = 1, precision = 0, defaultValue = 0, value, onChange, decreaseProps, increaseProps, inputProps, readOnly, disabled, ...props }) => {
12
12
  const [innerValue, setInnerValue] = useControlled(defaultValue, value, onChange);
13
13
  const commonButtonProps = {
14
14
  size,
@@ -18,13 +18,13 @@ export const Counter = memo(({ size, min = -Infinity, max = Infinity, step = 1,
18
18
  const clickHandler = (dir) => {
19
19
  setInnerValue(Math.max(min, Math.min(max, innerValue.current + dir * step)));
20
20
  };
21
- return (_jsxs(Flex, { compact: true, ...props, css: style, className: clsx(classes.root, props.className), children: [_jsx(Button, { disabled: innerValue.current <= min, ...mergeComponentProps(commonButtonProps, decreaseProps, {
21
+ return (_jsxs(Flex, { compact: true, ...props, css: style, className: clsx(classes.root, props.className), children: [_jsx(Button, { readOnly: readOnly, disabled: disabled || innerValue.current <= min, ...mergeComponentProps(commonButtonProps, decreaseProps, {
22
22
  onClick: () => clickHandler(-1)
23
- }), children: _jsx(Icon, { icon: faMinus }) }), _jsx(Input, { type: "number", widthAdaptable: true, size: size, min: min, max: max, step: step, precision: precision, ...mergeComponentProps(inputProps, {
23
+ }), children: _jsx(Icon, { icon: faMinus }) }), _jsx(Input, { type: "number", widthAdaptable: true, size: size, min: min, max: max, step: step, precision: precision, readOnly: readOnly, disabled: disabled, ...mergeComponentProps(inputProps, {
24
24
  className: classes.input,
25
25
  value: innerValue.current,
26
26
  onChange: e => setInnerValue(+e.target.value)
27
- }) }), _jsx(Button, { disabled: innerValue.current >= max, ...mergeComponentProps(commonButtonProps, increaseProps, {
27
+ }) }), _jsx(Button, { readOnly: readOnly, disabled: disabled || innerValue.current >= max, ...mergeComponentProps(commonButtonProps, increaseProps, {
28
28
  onClick: () => clickHandler(1)
29
29
  }), children: _jsx(Icon, { icon: faPlus }) })] }));
30
30
  });
@@ -5,7 +5,7 @@ import { classes } from './pagination.style.js';
5
5
  import { usePaginationContext } from './pagination.js';
6
6
  export const PaginationCounter = memo((props) => {
7
7
  const { total, page, pageSize } = usePaginationContext();
8
- const start = (page - 1) * pageSize + 1;
8
+ const start = Math.min((page - 1) * pageSize + 1, total);
9
9
  const end = Math.min(start + pageSize - 1, total);
10
10
  return (_jsxs("div", { ...props, className: clsx(classes.counter, props.className), children: ["\u7B2C ", start, "-", end, " \u6761/\u5171 ", total, " \u6761"] }));
11
11
  });
@@ -11,9 +11,11 @@ const PaginationContext = createContext({
11
11
  total: 0,
12
12
  pageCount: 1,
13
13
  page: 1,
14
- onPageChange(page) { },
14
+ onPageChange(page) {
15
+ },
15
16
  pageSize: 10,
16
- onPageSizeChange(pageSize) { }
17
+ onPageSizeChange(pageSize) {
18
+ }
17
19
  });
18
20
  export function usePaginationContext() {
19
21
  return useContext(PaginationContext);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canlooks/can-ui",
3
- "version": "0.0.195",
3
+ "version": "0.0.196",
4
4
  "author": "C.CanLiang <canlooks@gmail.com>",
5
5
  "description": "My ui framework",
6
6
  "license": "MIT",