trotl-filter 1.0.44 → 1.0.46

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/dist/index.cjs.js CHANGED
@@ -8651,6 +8651,164 @@ MultiSelect.propTypes = {
8651
8651
  className: PropTypes.string
8652
8652
  };
8653
8653
 
8654
+ // Simple, dependency-free ColorPicker
8655
+ // Props: value (hex), onChange(hex), disabled, label, presetColors, allowCustom, size
8656
+ function ColorPicker({
8657
+ value = '#1677ff',
8658
+ onChange,
8659
+ disabled = false,
8660
+ label = null,
8661
+ presetColors = ['#1677ff', '#ff4d4f', '#52c41a', '#faad14', '#722ed1', '#13c2c2', '#f5222d'],
8662
+ allowCustom = true,
8663
+ showHexInput = true,
8664
+ size = 'medium',
8665
+ // small | medium | large
8666
+ className = '',
8667
+ style = {}
8668
+ }) {
8669
+ const [open, setOpen] = React.useState(false);
8670
+ const [internal, setInternal] = React.useState(value || '');
8671
+ const ref = React.useRef(null);
8672
+ React.useEffect(() => setInternal(value || ''), [value]);
8673
+ React.useEffect(() => {
8674
+ const onDoc = e => {
8675
+ if (!ref.current) return;
8676
+ if (!ref.current.contains(e.target)) setOpen(false);
8677
+ };
8678
+ window.addEventListener('mousedown', onDoc);
8679
+ return () => window.removeEventListener('mousedown', onDoc);
8680
+ }, []);
8681
+ const apply = hex => {
8682
+ setInternal(hex);
8683
+ onChange?.(hex);
8684
+ };
8685
+ const btnSize = size === 'small' ? 20 : size === 'large' ? 36 : 28;
8686
+ return /*#__PURE__*/React.createElement("div", {
8687
+ ref: ref,
8688
+ className: `color-picker ${className}`,
8689
+ style: {
8690
+ display: 'inline-block',
8691
+ ...style
8692
+ }
8693
+ }, label && /*#__PURE__*/React.createElement("div", {
8694
+ style: {
8695
+ marginBottom: 6,
8696
+ fontSize: 13
8697
+ }
8698
+ }, label), /*#__PURE__*/React.createElement("button", {
8699
+ type: "button",
8700
+ onClick: () => !disabled && setOpen(s => !s),
8701
+ disabled: disabled,
8702
+ "aria-label": label || 'Choose color',
8703
+ style: {
8704
+ display: 'inline-flex',
8705
+ alignItems: 'center',
8706
+ gap: 8,
8707
+ padding: '6px 8px',
8708
+ borderRadius: 6,
8709
+ border: '1px solid #d9d9d9',
8710
+ background: '#fff',
8711
+ cursor: disabled ? 'not-allowed' : 'pointer'
8712
+ }
8713
+ }, /*#__PURE__*/React.createElement("span", {
8714
+ style: {
8715
+ width: btnSize,
8716
+ height: btnSize,
8717
+ borderRadius: 4,
8718
+ background: internal || '#fff',
8719
+ border: '1px solid #ccc'
8720
+ }
8721
+ }), /*#__PURE__*/React.createElement("span", {
8722
+ style: {
8723
+ fontSize: 13,
8724
+ color: disabled ? '#9ca3af' : '#000'
8725
+ }
8726
+ }, internal || '—')), open && /*#__PURE__*/React.createElement("div", {
8727
+ style: {
8728
+ position: 'absolute',
8729
+ zIndex: 60,
8730
+ marginTop: 8,
8731
+ background: '#fff',
8732
+ border: '1px solid #e8e8e8',
8733
+ boxShadow: '0 6px 18px rgba(0,0,0,0.08)',
8734
+ borderRadius: 6,
8735
+ padding: 12,
8736
+ minWidth: 220
8737
+ }
8738
+ }, /*#__PURE__*/React.createElement("div", {
8739
+ style: {
8740
+ display: 'flex',
8741
+ gap: 8,
8742
+ flexWrap: 'wrap'
8743
+ }
8744
+ }, presetColors.map(c => /*#__PURE__*/React.createElement("button", {
8745
+ key: c,
8746
+ onClick: () => apply(c),
8747
+ "aria-label": c,
8748
+ style: {
8749
+ width: 28,
8750
+ height: 28,
8751
+ borderRadius: 4,
8752
+ background: c,
8753
+ border: c.toLowerCase() === (internal || '').toLowerCase() ? '2px solid #00000033' : '1px solid #eee',
8754
+ cursor: 'pointer'
8755
+ }
8756
+ })), allowCustom && /*#__PURE__*/React.createElement("input", {
8757
+ type: "color",
8758
+ value: internal || '#000000',
8759
+ onChange: e => apply(e.target.value),
8760
+ style: {
8761
+ width: 36,
8762
+ height: 36,
8763
+ padding: 0,
8764
+ border: 'none',
8765
+ background: 'transparent',
8766
+ cursor: 'pointer'
8767
+ },
8768
+ title: "Custom color"
8769
+ })), showHexInput && /*#__PURE__*/React.createElement("div", {
8770
+ style: {
8771
+ marginTop: 8,
8772
+ display: 'flex',
8773
+ gap: 8,
8774
+ alignItems: 'center'
8775
+ }
8776
+ }, /*#__PURE__*/React.createElement("input", {
8777
+ value: internal || '',
8778
+ onChange: e => setInternal(e.target.value),
8779
+ onBlur: e => {
8780
+ const v = e.target.value.trim();
8781
+ if (/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/.test(v)) apply(v);else setInternal(value || '');
8782
+ },
8783
+ placeholder: "#rrggbb",
8784
+ disabled: disabled,
8785
+ style: {
8786
+ padding: '6px 8px',
8787
+ borderRadius: 4,
8788
+ border: '1px solid #e5e7eb',
8789
+ width: 120
8790
+ }
8791
+ }), /*#__PURE__*/React.createElement("button", {
8792
+ onClick: () => {
8793
+ if (/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/.test(internal)) apply(internal);
8794
+ },
8795
+ disabled: disabled,
8796
+ className: "basic-btn"
8797
+ }, "Apply"))));
8798
+ }
8799
+ ColorPicker.propTypes = {
8800
+ value: PropTypes.string,
8801
+ onChange: PropTypes.func,
8802
+ disabled: PropTypes.bool,
8803
+ label: PropTypes.string,
8804
+ presetColors: PropTypes.array,
8805
+ allowCustom: PropTypes.bool,
8806
+ showHexInput: PropTypes.bool,
8807
+ size: PropTypes.oneOf(['small', 'medium', 'large']),
8808
+ className: PropTypes.string,
8809
+ style: PropTypes.object
8810
+ };
8811
+
8654
8812
  // import "src/style/DebounceSelect.css";
8655
8813
 
8656
8814
  const DebounceSelect = ({
@@ -9356,6 +9514,7 @@ function DateTimeInput({
9356
9514
  style = {},
9357
9515
  predefinedRanges = ["today", "yesterday"],
9358
9516
  startWith = "sunday",
9517
+ presets = [],
9359
9518
  ...rest
9360
9519
  }) {
9361
9520
  let translate;
@@ -9725,6 +9884,56 @@ function DateTimeInput({
9725
9884
  applySelection(d);
9726
9885
  setSelectedPredefined(String(idx));
9727
9886
  };
9887
+ const handlePresetClick = preset => {
9888
+ if (!preset || !preset.type) return;
9889
+ const type = String(preset.type).toLowerCase();
9890
+ if (type === 'clear') {
9891
+ handleClear();
9892
+ return;
9893
+ }
9894
+ if (type === 'today') {
9895
+ const d = new Date();
9896
+ if (time && timeStart) {
9897
+ const [h, m] = (timeStart || "00:00").split(":");
9898
+ d.setHours(Number(h), Number(m), 0, 0);
9899
+ } else if (!time) {
9900
+ d.setHours(0, 0, 0, 0);
9901
+ }
9902
+ applySelection(d);
9903
+ return;
9904
+ }
9905
+
9906
+ // base = selected date (if present) or now
9907
+ const base = selectedDate ? new Date(selectedDate) : new Date();
9908
+ const val = Number(preset.value || 0);
9909
+ if (type === 'days') {
9910
+ base.setDate(base.getDate() + val);
9911
+ if (!selectedDate && time && timeStart) {
9912
+ const [h, m] = (timeStart || "00:00").split(":");
9913
+ base.setHours(Number(h), Number(m), 0, 0);
9914
+ }
9915
+ applySelection(base);
9916
+ return;
9917
+ }
9918
+ if (type === 'months') {
9919
+ base.setMonth(base.getMonth() + val);
9920
+ if (!selectedDate && time && timeStart) {
9921
+ const [h, m] = (timeStart || "00:00").split(":");
9922
+ base.setHours(Number(h), Number(m), 0, 0);
9923
+ }
9924
+ applySelection(base);
9925
+ return;
9926
+ }
9927
+ if (type === 'years') {
9928
+ base.setFullYear(base.getFullYear() + val);
9929
+ if (!selectedDate && time && timeStart) {
9930
+ const [h, m] = (timeStart || "00:00").split(":");
9931
+ base.setHours(Number(h), Number(m), 0, 0);
9932
+ }
9933
+ applySelection(base);
9934
+ return;
9935
+ }
9936
+ };
9728
9937
  const handleDayClick = day => {
9729
9938
  applySelection(day);
9730
9939
  };
@@ -9928,7 +10137,30 @@ function DateTimeInput({
9928
10137
  background: disabled ? '#f9fafb' : undefined,
9929
10138
  color: disabled ? '#9ca3af' : undefined
9930
10139
  }
9931
- })), /*#__PURE__*/React.createElement("div", {
10140
+ })), presets && presets.length > 0 && /*#__PURE__*/React.createElement("div", {
10141
+ style: {
10142
+ display: 'flex',
10143
+ gap: 8,
10144
+ marginTop: 8,
10145
+ marginBottom: 8,
10146
+ flexWrap: 'wrap'
10147
+ }
10148
+ }, presets.map((p, i) => /*#__PURE__*/React.createElement("button", {
10149
+ key: `preset_${i}`,
10150
+ type: "button",
10151
+ onClick: () => !disabled && handlePresetClick(p),
10152
+ disabled: disabled,
10153
+ className: "basic-btn",
10154
+ style: {
10155
+ padding: '6px 10px',
10156
+ fontSize: 12,
10157
+ background: disabled ? '#f9fafb' : '#fff',
10158
+ color: disabled ? '#9ca3af' : '#000',
10159
+ border: '1px solid #d9d9d9',
10160
+ borderRadius: 4,
10161
+ cursor: disabled ? 'not-allowed' : 'pointer'
10162
+ }
10163
+ }, p.label || p.type))), /*#__PURE__*/React.createElement("div", {
9932
10164
  style: {
9933
10165
  display: 'flex',
9934
10166
  justifyContent: 'space-between',
@@ -9992,7 +10224,8 @@ DateTimeInput.propTypes = {
9992
10224
  disabled: PropTypes.bool,
9993
10225
  className: PropTypes.string,
9994
10226
  style: PropTypes.object,
9995
- predefinedRanges: PropTypes.array
10227
+ predefinedRanges: PropTypes.array,
10228
+ presets: PropTypes.array
9996
10229
  };
9997
10230
  const buttonStyle = {
9998
10231
  padding: '6px 16px',
@@ -11444,6 +11677,7 @@ Upload.propTypes = {
11444
11677
 
11445
11678
  exports.Button = Button;
11446
11679
  exports.CalendarRangePicker = CalendarRangePicker;
11680
+ exports.ColorPicker = ColorPicker;
11447
11681
  exports.DateTimeInput = DateTimeInput;
11448
11682
  exports.DebounceSelect = DebounceSelect;
11449
11683
  exports.IconInput = IconInput;