@rc-component/picker 1.2.4 → 1.3.0
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/es/PickerInput/Popup/Footer.js +7 -4
- package/es/PickerInput/RangePicker.js +21 -8
- package/es/PickerInput/Selector/Icon.js +4 -4
- package/es/PickerInput/Selector/Input.js +6 -5
- package/es/PickerInput/Selector/RangeSelector.js +5 -5
- package/es/PickerInput/Selector/SingleSelector/index.js +5 -5
- package/es/PickerInput/Selector/hooks/useClearIcon.d.ts +1 -1
- package/es/PickerInput/SinglePicker.js +21 -8
- package/es/PickerInput/context.d.ts +4 -3
- package/es/PickerPanel/PanelBody.js +10 -10
- package/es/PickerPanel/PanelHeader.js +9 -6
- package/es/PickerPanel/TimePanel/TimePanelBody/TimeColumn.js +7 -8
- package/es/PickerPanel/TimePanel/TimePanelBody/index.js +6 -6
- package/es/PickerPanel/context.d.ts +9 -3
- package/es/PickerPanel/context.js +10 -0
- package/es/PickerPanel/index.d.ts +1 -2
- package/es/PickerPanel/index.js +14 -9
- package/es/hooks/useSemantic.d.ts +13 -0
- package/es/hooks/useSemantic.js +21 -0
- package/es/interface.d.ts +9 -3
- package/es/utils/getClearIcon.d.ts +1 -1
- package/lib/PickerInput/Popup/Footer.js +5 -2
- package/lib/PickerInput/RangePicker.js +21 -8
- package/lib/PickerInput/Selector/Icon.js +3 -3
- package/lib/PickerInput/Selector/Input.js +5 -4
- package/lib/PickerInput/Selector/RangeSelector.js +3 -3
- package/lib/PickerInput/Selector/SingleSelector/index.js +3 -3
- package/lib/PickerInput/Selector/hooks/useClearIcon.d.ts +1 -1
- package/lib/PickerInput/SinglePicker.js +21 -8
- package/lib/PickerInput/context.d.ts +4 -3
- package/lib/PickerPanel/PanelBody.js +9 -9
- package/lib/PickerPanel/PanelHeader.js +4 -1
- package/lib/PickerPanel/TimePanel/TimePanelBody/TimeColumn.js +5 -6
- package/lib/PickerPanel/TimePanel/TimePanelBody/index.js +5 -5
- package/lib/PickerPanel/context.d.ts +9 -3
- package/lib/PickerPanel/context.js +11 -1
- package/lib/PickerPanel/index.d.ts +1 -2
- package/lib/PickerPanel/index.js +13 -8
- package/lib/hooks/useSemantic.d.ts +13 -0
- package/lib/hooks/useSemantic.js +27 -0
- package/lib/interface.d.ts +9 -3
- package/lib/utils/getClearIcon.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import type { PanelMode,
|
|
2
|
+
import type { PanelMode, SharedPanelProps } from '../interface';
|
|
3
|
+
import type { FilledPanelClassNames, FilledPanelStyles } from '../hooks/useSemantic';
|
|
4
|
+
export interface SharedPanelContextProps {
|
|
5
|
+
classNames: FilledPanelClassNames;
|
|
6
|
+
styles: FilledPanelStyles;
|
|
7
|
+
}
|
|
8
|
+
export declare const SharedPanelContext: React.Context<SharedPanelContextProps>;
|
|
3
9
|
export interface PanelContextProps<DateType extends object = any> extends Pick<SharedPanelProps<DateType>, 'prefixCls' | 'cellRender' | 'generateConfig' | 'locale' | 'onSelect' | 'hoverValue' | 'hoverRangeValue' | 'onHover' | 'values' | 'pickerValue' | 'disabledDate' | 'minDate' | 'maxDate' | 'prevIcon' | 'nextIcon' | 'superPrevIcon' | 'superNextIcon'> {
|
|
4
10
|
/** Tell current panel type */
|
|
5
11
|
panelType: PanelMode;
|
|
6
12
|
now: DateType;
|
|
13
|
+
classNames: FilledPanelClassNames;
|
|
14
|
+
styles: FilledPanelStyles;
|
|
7
15
|
}
|
|
8
16
|
/** Used for each single Panel. e.g. DatePanel */
|
|
9
17
|
export declare const PanelContext: React.Context<PanelContextProps<any>>;
|
|
@@ -17,8 +25,6 @@ export interface PickerHackContextProps {
|
|
|
17
25
|
hideNext?: boolean;
|
|
18
26
|
hideHeader?: boolean;
|
|
19
27
|
onCellDblClick?: () => void;
|
|
20
|
-
styles?: Partial<Record<SemanticStructure, React.CSSProperties>>;
|
|
21
|
-
classNames?: Partial<Record<SemanticStructure, string>>;
|
|
22
28
|
}
|
|
23
29
|
/**
|
|
24
30
|
* Internal usage for RangePicker to not to show the operation arrow
|
|
@@ -4,12 +4,13 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.PickerHackContext = exports.PanelContext = void 0;
|
|
7
|
+
exports.SharedPanelContext = exports.PickerHackContext = exports.PanelContext = void 0;
|
|
8
8
|
exports.useInfo = useInfo;
|
|
9
9
|
exports.usePanelContext = usePanelContext;
|
|
10
10
|
var React = _interopRequireWildcard(require("react"));
|
|
11
11
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
12
12
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
|
+
var SharedPanelContext = exports.SharedPanelContext = /*#__PURE__*/React.createContext(null);
|
|
13
14
|
/** Used for each single Panel. e.g. DatePanel */
|
|
14
15
|
var PanelContext = exports.PanelContext = /*#__PURE__*/React.createContext(null);
|
|
15
16
|
function usePanelContext() {
|
|
@@ -20,6 +21,8 @@ function usePanelContext() {
|
|
|
20
21
|
* Get shared props for the SharedPanelProps interface.
|
|
21
22
|
*/
|
|
22
23
|
function useInfo(props, panelType) {
|
|
24
|
+
// TODO: this is not good to get from each props.
|
|
25
|
+
// Should move to `SharedPanelContext` instead.
|
|
23
26
|
var prefixCls = props.prefixCls,
|
|
24
27
|
generateConfig = props.generateConfig,
|
|
25
28
|
locale = props.locale,
|
|
@@ -38,6 +41,11 @@ function useInfo(props, panelType) {
|
|
|
38
41
|
superPrevIcon = props.superPrevIcon,
|
|
39
42
|
superNextIcon = props.superNextIcon;
|
|
40
43
|
|
|
44
|
+
// ======================= Context ========================
|
|
45
|
+
var _React$useContext = React.useContext(SharedPanelContext),
|
|
46
|
+
classNames = _React$useContext.classNames,
|
|
47
|
+
styles = _React$useContext.styles;
|
|
48
|
+
|
|
41
49
|
// ========================= MISC =========================
|
|
42
50
|
var now = generateConfig.getNow();
|
|
43
51
|
|
|
@@ -47,6 +55,8 @@ function useInfo(props, panelType) {
|
|
|
47
55
|
values: values,
|
|
48
56
|
pickerValue: pickerValue,
|
|
49
57
|
prefixCls: prefixCls,
|
|
58
|
+
classNames: classNames,
|
|
59
|
+
styles: styles,
|
|
50
60
|
disabledDate: disabledDate,
|
|
51
61
|
minDate: minDate,
|
|
52
62
|
maxDate: maxDate,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import type { CellRender, Components, Locale, OnPanelChange, PanelMode, PickerMode, SharedPanelProps, SharedTimeProps } from '../interface';
|
|
2
|
+
import type { CellRender, Components, Locale, OnPanelChange, PanelMode, PanelSemanticName, PickerMode, SharedPanelProps, SharedTimeProps } from '../interface';
|
|
3
3
|
export interface PickerPanelRef {
|
|
4
4
|
nativeElement: HTMLDivElement;
|
|
5
5
|
}
|
|
@@ -43,7 +43,6 @@ export interface SinglePickerPanelProps<DateType extends object = any> extends B
|
|
|
43
43
|
value?: DateType | null;
|
|
44
44
|
onChange?: (date: DateType) => void;
|
|
45
45
|
}
|
|
46
|
-
type PanelSemanticName = 'popupBody' | 'popupContent' | 'popupItem';
|
|
47
46
|
export type PickerPanelProps<DateType extends object = any> = BasePickerPanelProps<DateType> & {
|
|
48
47
|
/** multiple selection. Not support time or datetime picker */
|
|
49
48
|
multiple?: boolean;
|
package/lib/PickerPanel/index.js
CHANGED
|
@@ -264,16 +264,19 @@ function PickerPanel(props, ref) {
|
|
|
264
264
|
var PanelComponent = components[internalMode] || DefaultComponents[internalMode] || _DatePanel.default;
|
|
265
265
|
|
|
266
266
|
// ======================== Context =========================
|
|
267
|
-
var
|
|
268
|
-
|
|
267
|
+
var sharedPanelContext = React.useMemo(function () {
|
|
268
|
+
var _ref2, _pickerClassNames$pop, _ref3, _pickerStyles$popup;
|
|
269
|
+
return {
|
|
270
|
+
classNames: (_ref2 = (_pickerClassNames$pop = pickerClassNames === null || pickerClassNames === void 0 ? void 0 : pickerClassNames.popup) !== null && _pickerClassNames$pop !== void 0 ? _pickerClassNames$pop : panelClassNames) !== null && _ref2 !== void 0 ? _ref2 : {},
|
|
271
|
+
styles: (_ref3 = (_pickerStyles$popup = pickerStyles === null || pickerStyles === void 0 ? void 0 : pickerStyles.popup) !== null && _pickerStyles$popup !== void 0 ? _pickerStyles$popup : panelStyles) !== null && _ref3 !== void 0 ? _ref3 : {}
|
|
272
|
+
};
|
|
273
|
+
}, [pickerClassNames, panelClassNames, pickerStyles, panelStyles]);
|
|
269
274
|
var parentHackContext = React.useContext(_context2.PickerHackContext);
|
|
270
275
|
var pickerPanelContext = React.useMemo(function () {
|
|
271
276
|
return _objectSpread(_objectSpread({}, parentHackContext), {}, {
|
|
272
|
-
hideHeader: hideHeader
|
|
273
|
-
classNames: mergedClassNames,
|
|
274
|
-
styles: mergedStyles
|
|
277
|
+
hideHeader: hideHeader
|
|
275
278
|
});
|
|
276
|
-
}, [parentHackContext, hideHeader
|
|
279
|
+
}, [parentHackContext, hideHeader]);
|
|
277
280
|
|
|
278
281
|
// ======================== Warnings ========================
|
|
279
282
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -293,7 +296,9 @@ function PickerPanel(props, ref) {
|
|
|
293
296
|
'disabledDate', 'minDate', 'maxDate',
|
|
294
297
|
// Hover
|
|
295
298
|
'onHover']);
|
|
296
|
-
return /*#__PURE__*/React.createElement(_context2.
|
|
299
|
+
return /*#__PURE__*/React.createElement(_context2.SharedPanelContext.Provider, {
|
|
300
|
+
value: sharedPanelContext
|
|
301
|
+
}, /*#__PURE__*/React.createElement(_context2.PickerHackContext.Provider, {
|
|
297
302
|
value: pickerPanelContext
|
|
298
303
|
}, /*#__PURE__*/React.createElement("div", {
|
|
299
304
|
ref: rootRef,
|
|
@@ -326,7 +331,7 @@ function PickerPanel(props, ref) {
|
|
|
326
331
|
,
|
|
327
332
|
hoverRangeValue: hoverRangeDate,
|
|
328
333
|
hoverValue: hoverValue
|
|
329
|
-
}))));
|
|
334
|
+
})))));
|
|
330
335
|
}
|
|
331
336
|
var RefPanelPicker = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef(PickerPanel));
|
|
332
337
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SharedPickerProps } from '../interface';
|
|
2
|
+
export type FilledPanelClassNames = NonNullable<SharedPickerProps['classNames']>['popup'];
|
|
3
|
+
export type FilledPanelStyles = NonNullable<SharedPickerProps['styles']>['popup'];
|
|
4
|
+
export type FilledClassNames = NonNullable<SharedPickerProps['classNames']> & {
|
|
5
|
+
popup: FilledPanelClassNames;
|
|
6
|
+
};
|
|
7
|
+
export type FilledStyles = NonNullable<SharedPickerProps['styles']> & {
|
|
8
|
+
popup: FilledPanelStyles;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Convert `classNames` & `styles` to a fully filled object
|
|
12
|
+
*/
|
|
13
|
+
export default function useSemantic(classNames?: SharedPickerProps['classNames'], styles?: SharedPickerProps['styles']): readonly [FilledClassNames, FilledStyles];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useSemantic;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
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); }
|
|
9
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
|
+
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; }
|
|
12
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
13
|
+
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); }
|
|
14
|
+
/**
|
|
15
|
+
* Convert `classNames` & `styles` to a fully filled object
|
|
16
|
+
*/
|
|
17
|
+
function useSemantic(classNames, styles) {
|
|
18
|
+
return (0, _react.useMemo)(function () {
|
|
19
|
+
var mergedClassNames = _objectSpread(_objectSpread({}, classNames), {}, {
|
|
20
|
+
popup: (classNames === null || classNames === void 0 ? void 0 : classNames.popup) || {}
|
|
21
|
+
});
|
|
22
|
+
var mergedStyles = _objectSpread(_objectSpread({}, styles), {}, {
|
|
23
|
+
popup: (styles === null || styles === void 0 ? void 0 : styles.popup) || {}
|
|
24
|
+
});
|
|
25
|
+
return [mergedClassNames, mergedStyles];
|
|
26
|
+
}, [classNames, styles]);
|
|
27
|
+
}
|
package/lib/interface.d.ts
CHANGED
|
@@ -201,19 +201,25 @@ export type Components<DateType extends object = any> = Partial<Record<InternalM
|
|
|
201
201
|
button?: React.ComponentType<any> | string;
|
|
202
202
|
input?: React.ComponentType<any> | string;
|
|
203
203
|
}>;
|
|
204
|
-
export type SemanticStructure = 'popup' | 'popupBody' | 'popupContent' | 'popupItem' | 'suffix' | 'prefix' | 'input';
|
|
205
204
|
export type CustomFormat<DateType> = (value: DateType) => string;
|
|
206
205
|
export type FormatType<DateType = any> = string | CustomFormat<DateType>;
|
|
207
206
|
export type SharedHTMLAttrs = Omit<React.InputHTMLAttributes<HTMLDivElement>, 'value' | 'defaultValue' | 'onChange' | 'placeholder' | 'id' | 'onInvalid' | 'disabled' | 'onFocus' | 'onBlur' | 'onSelect' | 'min' | 'max' | 'onKeyDown' | 'size' | 'prefix'>;
|
|
208
207
|
export type PickerFocusEventHandler = (e: React.FocusEvent<HTMLElement>, info: BaseInfo) => void;
|
|
209
208
|
export type LegacyOnKeyDown = (event: React.KeyboardEvent<HTMLElement>, preventDefault: VoidFunction) => void;
|
|
209
|
+
export type SemanticName = 'root' | 'prefix' | 'input' | 'suffix';
|
|
210
|
+
export type PanelSemanticName = 'root' | 'header' | 'body' | 'content' | 'item' | 'footer';
|
|
210
211
|
export interface SharedPickerProps<DateType extends object = any> extends SharedHTMLAttrs, Pick<SharedPanelProps<DateType>, 'prevIcon' | 'nextIcon' | 'superPrevIcon' | 'superNextIcon'> {
|
|
211
212
|
direction?: 'ltr' | 'rtl';
|
|
212
213
|
prefixCls?: string;
|
|
213
214
|
className?: string;
|
|
214
215
|
style?: React.CSSProperties;
|
|
215
|
-
|
|
216
|
-
|
|
216
|
+
rootClassName?: string;
|
|
217
|
+
styles?: Partial<Record<SemanticName, React.CSSProperties>> & {
|
|
218
|
+
popup?: Partial<Record<PanelSemanticName, React.CSSProperties>>;
|
|
219
|
+
};
|
|
220
|
+
classNames?: Partial<Record<SemanticName, string>> & {
|
|
221
|
+
popup?: Partial<Record<PanelSemanticName, string>>;
|
|
222
|
+
};
|
|
217
223
|
locale: Locale;
|
|
218
224
|
generateConfig: GenerateConfig<DateType>;
|
|
219
225
|
picker?: PickerMode;
|
|
@@ -2,4 +2,4 @@ import type { ReactNode } from "react";
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
export declare function getClearIcon(prefixCls: string, allowClear?: boolean | {
|
|
4
4
|
clearIcon?: ReactNode;
|
|
5
|
-
}, clearIcon?: ReactNode): string | number | true |
|
|
5
|
+
}, clearIcon?: ReactNode): string | number | true | React.JSX.Element | Iterable<ReactNode>;
|