@canlooks/can-ui 0.0.195 → 0.0.197

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);
@@ -1,7 +1,7 @@
1
1
  import { Dispatch, ReactElement, ReactNode, SetStateAction, ComponentProps } from 'react';
2
2
  import { DivProps } from '../../types';
3
3
  import { ButtonProps } from '../button';
4
- import { DropArea } from './dropArea';
4
+ import { DropArea, DropAreaProps } from './dropArea';
5
5
  export type UploadStatus = 'default' | 'uploading' | 'success' | 'error';
6
6
  export interface UploadFile<R = any, A extends any[] = any[]> extends File {
7
7
  id: string;
@@ -31,6 +31,7 @@ export interface UploadProps<R = any, A extends any[] = any[]> extends UploadSha
31
31
  size?: number;
32
32
  /** 是否支持“将文件拖拽到此处” */
33
33
  droppable?: boolean;
34
+ dropAreaProps?: DropAreaProps;
34
35
  sortable?: boolean;
35
36
  defaultValue?: UploadFile<R, A>[];
36
37
  value?: UploadFile<R, A>[];
@@ -23,7 +23,7 @@ const markFileId = (files) => {
23
23
  }
24
24
  }
25
25
  };
26
- exports.Upload = (0, react_1.memo)(({ inputProps, type = 'file', accept = type === 'image' ? 'image/*' : void 0, max = Infinity, showButton = true, buttonProps, buttonText = '选择文件', variant = 'square', sortable, droppable, defaultValue, value, onChange, onUpload, ...props }) => {
26
+ exports.Upload = (0, react_1.memo)(({ inputProps, type = 'file', accept = type === 'image' ? 'image/*' : void 0, max = Infinity, showButton = true, buttonProps, buttonText = '选择文件', variant = 'square', sortable, droppable, dropAreaProps, defaultValue, value, onChange, onUpload, ...props }) => {
27
27
  const wrapperRef = (0, react_1.useRef)(null);
28
28
  const itemRefs = (0, react_1.useRef)(new Map());
29
29
  (0, react_1.useImperativeHandle)(props.ref, () => {
@@ -99,7 +99,10 @@ exports.Upload = (0, react_1.memo)(({ inputProps, type = 'file', accept = type =
99
99
  onChange: inputChangeHandler
100
100
  }), "data-hidden": "true" }), (0, jsx_runtime_1.jsx)(react_2.DragDropProvider, { sensors: utils_1.defaultSensors, onDragEnd: dragEndHandler, children: type === 'file'
101
101
  ? (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [droppable
102
- ? (0, jsx_runtime_1.jsx)(dropArea_1.DropArea, { onClick: () => innerInputRef.current.click(), onDrop: changeFn })
102
+ ? (0, jsx_runtime_1.jsx)(dropArea_1.DropArea, { ...(0, utils_1.mergeComponentProps)(dropAreaProps, {
103
+ onClick: () => innerInputRef.current.click(),
104
+ onDrop: changeFn
105
+ }) })
103
106
  : showButton &&
104
107
  (0, jsx_runtime_1.jsx)(button_1.Button, { variant: "outlined", prefix: (0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: faUpload_1.faUpload }), ...buttonProps, onClick: buttonClick, children: buttonText }), (0, jsx_runtime_1.jsx)(react_transition_group_1.TransitionGroup, { className: upload_style_1.classes.files, children: innerValue.current.map((file, index) => (0, jsx_runtime_1.jsx)(sortableItem_1.SortableItem, { component: transitionBase_1.Collapse, className: upload_style_1.classes.sortableItem, id: file.id, index: index, disabled: !sortable, children: (0, jsx_runtime_1.jsx)(fileItem_1.FileItem, { ref: r => {
105
108
  r
@@ -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);
@@ -1,7 +1,7 @@
1
1
  import { Dispatch, ReactElement, ReactNode, SetStateAction, ComponentProps } from 'react';
2
2
  import { DivProps } from '../../types.js';
3
3
  import { ButtonProps } from '../button/index.js';
4
- import { DropArea } from './dropArea.js';
4
+ import { DropArea, DropAreaProps } from './dropArea.js';
5
5
  export type UploadStatus = 'default' | 'uploading' | 'success' | 'error';
6
6
  export interface UploadFile<R = any, A extends any[] = any[]> extends File {
7
7
  id: string;
@@ -31,6 +31,7 @@ export interface UploadProps<R = any, A extends any[] = any[]> extends UploadSha
31
31
  size?: number;
32
32
  /** 是否支持“将文件拖拽到此处” */
33
33
  droppable?: boolean;
34
+ dropAreaProps?: DropAreaProps;
34
35
  sortable?: boolean;
35
36
  defaultValue?: UploadFile<R, A>[];
36
37
  value?: UploadFile<R, A>[];
@@ -20,7 +20,7 @@ const markFileId = (files) => {
20
20
  }
21
21
  }
22
22
  };
23
- export const Upload = memo(({ inputProps, type = 'file', accept = type === 'image' ? 'image/*' : void 0, max = Infinity, showButton = true, buttonProps, buttonText = '选择文件', variant = 'square', sortable, droppable, defaultValue, value, onChange, onUpload, ...props }) => {
23
+ export const Upload = memo(({ inputProps, type = 'file', accept = type === 'image' ? 'image/*' : void 0, max = Infinity, showButton = true, buttonProps, buttonText = '选择文件', variant = 'square', sortable, droppable, dropAreaProps, defaultValue, value, onChange, onUpload, ...props }) => {
24
24
  const wrapperRef = useRef(null);
25
25
  const itemRefs = useRef(new Map());
26
26
  useImperativeHandle(props.ref, () => {
@@ -96,7 +96,10 @@ export const Upload = memo(({ inputProps, type = 'file', accept = type === 'imag
96
96
  onChange: inputChangeHandler
97
97
  }), "data-hidden": "true" }), _jsx(DragDropProvider, { sensors: defaultSensors, onDragEnd: dragEndHandler, children: type === 'file'
98
98
  ? _jsxs(_Fragment, { children: [droppable
99
- ? _jsx(DropArea, { onClick: () => innerInputRef.current.click(), onDrop: changeFn })
99
+ ? _jsx(DropArea, { ...mergeComponentProps(dropAreaProps, {
100
+ onClick: () => innerInputRef.current.click(),
101
+ onDrop: changeFn
102
+ }) })
100
103
  : showButton &&
101
104
  _jsx(Button, { variant: "outlined", prefix: _jsx(Icon, { icon: faUpload }), ...buttonProps, onClick: buttonClick, children: buttonText }), _jsx(TransitionGroup, { className: classes.files, children: innerValue.current.map((file, index) => _jsx(SortableItem, { component: Collapse, className: classes.sortableItem, id: file.id, index: index, disabled: !sortable, children: _jsx(FileItem, { ref: r => {
102
105
  r
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.197",
4
4
  "author": "C.CanLiang <canlooks@gmail.com>",
5
5
  "description": "My ui framework",
6
6
  "license": "MIT",