@ceed/ads 1.8.0-next.6 → 1.8.0-next.8

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,6 +1,9 @@
1
1
  import React from "react";
2
2
  import Input from "../Input";
3
3
  interface BaseDateRangePickerProps {
4
+ /**
5
+ * props.format 의 형식을 따라야 한다.
6
+ */
4
7
  value?: string;
5
8
  defaultValue?: string;
6
9
  onChange?: (event: {
@@ -19,7 +22,14 @@ interface BaseDateRangePickerProps {
19
22
  maxDate?: string;
20
23
  disableFuture?: boolean;
21
24
  disablePast?: boolean;
25
+ /**
26
+ * value, onChange의 값은 해당 포맷을 따른다.
27
+ */
22
28
  format?: string;
29
+ /**
30
+ * Input 에 표시되는 값의 포맷을 지정한다.
31
+ */
32
+ displayFormat?: string;
23
33
  inputReadOnly?: boolean;
24
34
  hideClearButton?: boolean;
25
35
  }
@@ -4,6 +4,7 @@ interface FilterMenuProps {
4
4
  filters?: FilterItem[];
5
5
  values?: Record<string, any>;
6
6
  defaultValues?: Record<string, any>;
7
+ resetValues?: Record<string, any>;
7
8
  onChange?: (values: Record<string, any>) => void;
8
9
  onClose?: () => void;
9
10
  /**
@@ -24,7 +24,7 @@ export interface FilterRadioGroupItem extends FilterBaseItem<string | number> {
24
24
  value: string | number;
25
25
  }[];
26
26
  }
27
- export interface FilterDateRangeItem extends FilterBaseItem<[DateTime, DateTime]>, Pick<DateRangePickerProps, "minDate" | "maxDate" | "disableFuture" | "disablePast" | "format" | "inputReadOnly" | "hideClearButton"> {
27
+ export interface FilterDateRangeItem extends FilterBaseItem<[DateTime, DateTime]>, Pick<DateRangePickerProps, "minDate" | "maxDate" | "disableFuture" | "disablePast" | "format" | "displayFormat" | "inputReadOnly" | "hideClearButton"> {
28
28
  type: "date-range";
29
29
  }
30
30
  export interface FilterCurrencyInputItem extends FilterBaseItem<number>, Pick<CurrencyInputProps, "max" | "placeholder" | "useMinorUnit" | "currency"> {
package/dist/index.cjs CHANGED
@@ -4157,7 +4157,9 @@ var CalendarButton2 = (0, import_joy34.styled)(IconButton_default, {
4157
4157
  "&:focus": {
4158
4158
  "--Icon-color": "currentColor",
4159
4159
  outlineOffset: `${theme.getCssVar("focus-thickness")}`,
4160
- outline: `${theme.getCssVar("focus-thickness")} solid ${theme.getCssVar("palette-focusVisible")}`
4160
+ outline: `${theme.getCssVar("focus-thickness")} solid ${theme.getCssVar(
4161
+ "palette-focusVisible"
4162
+ )}`
4161
4163
  }
4162
4164
  }));
4163
4165
  var StyledPopper2 = (0, import_joy34.styled)(import_base3.Popper, {
@@ -4183,6 +4185,32 @@ var DateRangePickerRoot = (0, import_joy34.styled)("div", {
4183
4185
  })({
4184
4186
  width: "100%"
4185
4187
  });
4188
+ var validValueFormat2 = (value, format) => {
4189
+ try {
4190
+ const [date1Str, date2Str] = value.split(" - ");
4191
+ if (!date1Str || !date2Str) {
4192
+ return false;
4193
+ }
4194
+ const parsedDate1 = parseDate2(date1Str, format);
4195
+ const parsedDate2 = parseDate2(date2Str, format);
4196
+ if (parsedDate1.toString() === "Invalid Date" || parsedDate2.toString() === "Invalid Date") {
4197
+ return false;
4198
+ }
4199
+ const formattedValue = formatValueString2(
4200
+ [parsedDate1, parsedDate2],
4201
+ format
4202
+ );
4203
+ if (value !== formattedValue) {
4204
+ return false;
4205
+ }
4206
+ const regex = new RegExp(
4207
+ `^${format.replace(/Y/g, "\\d").replace(/M/g, "\\d").replace(/D/g, "\\d")} - ${format.replace(/Y/g, "\\d").replace(/M/g, "\\d").replace(/D/g, "\\d")}$`
4208
+ );
4209
+ return regex.test(value);
4210
+ } catch (e) {
4211
+ return false;
4212
+ }
4213
+ };
4186
4214
  var formatValueString2 = ([date1, date2], format) => {
4187
4215
  const getStr = (date) => {
4188
4216
  let day = `${date.getDate()}`;
@@ -4279,6 +4307,7 @@ var DateRangePicker = (0, import_react26.forwardRef)(
4279
4307
  sx,
4280
4308
  className,
4281
4309
  format = "YYYY/MM/DD",
4310
+ displayFormat = "YYYY/MM/DD",
4282
4311
  size,
4283
4312
  inputReadOnly,
4284
4313
  hideClearButton,
@@ -4295,12 +4324,27 @@ var DateRangePicker = (0, import_react26.forwardRef)(
4295
4324
  [props.name, onChange]
4296
4325
  )
4297
4326
  );
4327
+ const [displayValue, setDisplayValue] = (0, import_react26.useState)(
4328
+ () => value ? formatValueString2(parseDates(value, format), displayFormat) : ""
4329
+ );
4298
4330
  const [anchorEl, setAnchorEl] = (0, import_react26.useState)(null);
4299
4331
  const open = Boolean(anchorEl);
4300
4332
  const calendarValue = (0, import_react26.useMemo)(
4301
4333
  () => value ? parseDates(value, format) : void 0,
4302
4334
  [value, format]
4303
4335
  );
4336
+ (0, import_react26.useEffect)(() => {
4337
+ if (value) {
4338
+ try {
4339
+ const dates = parseDates(value, format);
4340
+ const newDisplayValue = formatValueString2(dates, displayFormat);
4341
+ setDisplayValue(newDisplayValue);
4342
+ } catch (error2) {
4343
+ }
4344
+ } else {
4345
+ setDisplayValue("");
4346
+ }
4347
+ }, [displayFormat, value, format]);
4304
4348
  (0, import_react26.useEffect)(() => {
4305
4349
  if (!anchorEl) {
4306
4350
  innerRef.current?.blur();
@@ -4311,9 +4355,41 @@ var DateRangePicker = (0, import_react26.forwardRef)(
4311
4355
  ]);
4312
4356
  const handleChange = (0, import_react26.useCallback)(
4313
4357
  (event) => {
4314
- setValue(event.target.value);
4358
+ const value2 = event.target.value;
4359
+ setDisplayValue(
4360
+ value2 ? formatValueString2(parseDates(value2, format), displayFormat) : value2
4361
+ );
4362
+ setValue(value2);
4315
4363
  },
4316
- [setValue]
4364
+ [displayFormat, format, setValue]
4365
+ );
4366
+ const handleDisplayInputChange = (0, import_react26.useCallback)(
4367
+ (event) => {
4368
+ if (event.target.value === "") {
4369
+ handleChange({
4370
+ target: {
4371
+ name: props.name,
4372
+ value: ""
4373
+ }
4374
+ });
4375
+ return;
4376
+ }
4377
+ const isValidDisplayValue = validValueFormat2(
4378
+ event.target.value,
4379
+ displayFormat
4380
+ );
4381
+ if (isValidDisplayValue) {
4382
+ const dates = parseDates(event.target.value, displayFormat);
4383
+ const formattedValue = formatValueString2(dates, format);
4384
+ handleChange({
4385
+ target: {
4386
+ name: props.name,
4387
+ value: formattedValue
4388
+ }
4389
+ });
4390
+ }
4391
+ },
4392
+ [displayFormat, format, handleChange, props.name]
4317
4393
  );
4318
4394
  const handleCalendarToggle = (0, import_react26.useCallback)(
4319
4395
  (event) => {
@@ -4325,10 +4401,26 @@ var DateRangePicker = (0, import_react26.forwardRef)(
4325
4401
  const handleCalendarChange = (0, import_react26.useCallback)(
4326
4402
  ([date1, date2]) => {
4327
4403
  if (!date1 || !date2) return;
4328
- setValue(formatValueString2([date1, date2], format));
4404
+ const formattedValue = formatValueString2([date1, date2], format);
4405
+ if (props.value !== void 0) {
4406
+ onChange?.({ target: { name: props.name, value: formattedValue } });
4407
+ } else {
4408
+ setDisplayValue(
4409
+ formatValueString2([date1, date2], displayFormat)
4410
+ );
4411
+ setValue(formattedValue);
4412
+ }
4329
4413
  setAnchorEl(null);
4330
4414
  },
4331
- [setValue, setAnchorEl, format]
4415
+ [
4416
+ props.value,
4417
+ props.name,
4418
+ onChange,
4419
+ setValue,
4420
+ setAnchorEl,
4421
+ format,
4422
+ displayFormat
4423
+ ]
4332
4424
  );
4333
4425
  const handleInputMouseDown = (0, import_react26.useCallback)(
4334
4426
  (event) => {
@@ -4346,17 +4438,21 @@ var DateRangePicker = (0, import_react26.forwardRef)(
4346
4438
  color: error ? "danger" : innerProps.color,
4347
4439
  ref,
4348
4440
  size,
4349
- value,
4350
- onChange: handleChange,
4441
+ value: displayValue,
4442
+ onChange: handleDisplayInputChange,
4351
4443
  disabled,
4352
4444
  required,
4353
- placeholder: `${format} - ${format}`,
4445
+ placeholder: `${displayFormat} - ${displayFormat}`,
4354
4446
  slotProps: {
4355
4447
  input: {
4356
4448
  component: TextMaskAdapter5,
4357
4449
  ref: innerRef,
4358
- format,
4359
- sx: { "&:hover": { cursor: inputReadOnly || readOnly ? "default" : "text" } },
4450
+ format: displayFormat,
4451
+ sx: {
4452
+ "&:hover": {
4453
+ cursor: inputReadOnly || readOnly ? "default" : "text"
4454
+ }
4455
+ },
4360
4456
  onMouseDown: handleInputMouseDown
4361
4457
  }
4362
4458
  },
@@ -4426,6 +4522,7 @@ var DateRangePicker = (0, import_react26.forwardRef)(
4426
4522
  color: "neutral",
4427
4523
  onClick: () => {
4428
4524
  setValue("");
4525
+ setDisplayValue("");
4429
4526
  setAnchorEl(null);
4430
4527
  }
4431
4528
  },
@@ -4582,7 +4679,7 @@ function CheckboxGroup(props) {
4582
4679
  {
4583
4680
  key: `${id}-${option.value}`,
4584
4681
  label: option.label,
4585
- checked: internalValue.includes(option.value),
4682
+ checked: internalValue?.includes(option.value),
4586
4683
  onChange: handleCheckboxChange(option.value)
4587
4684
  }
4588
4685
  )));
@@ -4666,6 +4763,7 @@ function DateRange(props) {
4666
4763
  disableFuture,
4667
4764
  disablePast,
4668
4765
  format = "YYYY/MM/DD",
4766
+ displayFormat,
4669
4767
  inputReadOnly,
4670
4768
  hideClearButton
4671
4769
  } = props;
@@ -4690,6 +4788,12 @@ function DateRange(props) {
4690
4788
  const now = /* @__PURE__ */ new Date();
4691
4789
  const currentYear = now.getFullYear();
4692
4790
  const currentMonth = now.getMonth();
4791
+ const formatDate = (date) => {
4792
+ const year = date.getFullYear();
4793
+ const month = String(date.getMonth() + 1).padStart(2, "0");
4794
+ const day = String(date.getDate()).padStart(2, "0");
4795
+ return `${year}-${month}-${day}`;
4796
+ };
4693
4797
  switch (option) {
4694
4798
  case "all-time":
4695
4799
  return null;
@@ -4697,24 +4801,26 @@ function DateRange(props) {
4697
4801
  const startOfMonth = new Date(currentYear, currentMonth, 1);
4698
4802
  const endOfMonth = new Date(currentYear, currentMonth + 1, 0);
4699
4803
  return [
4700
- startOfMonth.toISOString().split("T")[0],
4701
- endOfMonth.toISOString().split("T")[0]
4804
+ formatDate(startOfMonth),
4805
+ formatDate(endOfMonth)
4702
4806
  ];
4703
4807
  }
4704
4808
  case "this-year": {
4705
4809
  const startOfYear = new Date(currentYear, 0, 1);
4706
4810
  const endOfYear = new Date(currentYear, 11, 31);
4707
4811
  return [
4708
- startOfYear.toISOString().split("T")[0],
4709
- endOfYear.toISOString().split("T")[0]
4812
+ formatDate(startOfYear),
4813
+ formatDate(endOfYear)
4710
4814
  ];
4711
4815
  }
4712
4816
  case "last-month": {
4713
- const startOfLastMonth = new Date(currentYear, currentMonth - 1, 1);
4714
- const endOfLastMonth = new Date(currentYear, currentMonth, 0);
4817
+ const lastMonthYear = currentMonth === 0 ? currentYear - 1 : currentYear;
4818
+ const lastMonth = currentMonth === 0 ? 11 : currentMonth - 1;
4819
+ const startOfLastMonth = new Date(lastMonthYear, lastMonth, 1);
4820
+ const endOfLastMonth = new Date(lastMonthYear, lastMonth + 1, 0);
4715
4821
  return [
4716
- startOfLastMonth.toISOString().split("T")[0],
4717
- endOfLastMonth.toISOString().split("T")[0]
4822
+ formatDate(startOfLastMonth),
4823
+ formatDate(endOfLastMonth)
4718
4824
  ];
4719
4825
  }
4720
4826
  case "custom":
@@ -4725,12 +4831,32 @@ function DateRange(props) {
4725
4831
  },
4726
4832
  [internalValue]
4727
4833
  );
4834
+ const determineOptionFromValue = (0, import_react32.useCallback)(
4835
+ (value2) => {
4836
+ if (!value2) {
4837
+ return "all-time";
4838
+ }
4839
+ const options = ["this-month", "this-year", "last-month"];
4840
+ for (const option of options) {
4841
+ const optionRange = getDateRangeForOption(option);
4842
+ if (optionRange && optionRange[0] === value2[0] && optionRange[1] === value2[1]) {
4843
+ return option;
4844
+ }
4845
+ }
4846
+ return "custom";
4847
+ },
4848
+ [getDateRangeForOption]
4849
+ );
4728
4850
  const customDateRangeValue = (0, import_react32.useMemo)(() => {
4729
4851
  if (selectedOption === "custom" && internalValue) {
4730
4852
  return `${internalValue[0]} - ${internalValue[1]}`;
4731
4853
  }
4732
4854
  return "";
4733
4855
  }, [selectedOption, internalValue]);
4856
+ (0, import_react32.useEffect)(() => {
4857
+ const newOption = determineOptionFromValue(internalValue);
4858
+ setSelectedOption(newOption);
4859
+ }, [internalValue, determineOptionFromValue]);
4734
4860
  const handleOptionChange = (0, import_react32.useCallback)(
4735
4861
  (event) => {
4736
4862
  const newOption = event.target.value;
@@ -4792,6 +4918,7 @@ function DateRange(props) {
4792
4918
  disableFuture,
4793
4919
  disablePast,
4794
4920
  format,
4921
+ displayFormat,
4795
4922
  inputReadOnly,
4796
4923
  hideClearButton
4797
4924
  }
@@ -5173,13 +5300,14 @@ function PercentageRange(props) {
5173
5300
  ), /* @__PURE__ */ import_react37.default.createElement(import_joy49.Stack, { direction: "row", spacing: 2, alignItems: "flex-end" }, /* @__PURE__ */ import_react37.default.createElement(
5174
5301
  PercentageInput,
5175
5302
  {
5303
+ key: maxValue,
5176
5304
  label: "Minimum",
5177
5305
  value: minValue,
5178
5306
  onChange: handleMinChange,
5179
5307
  useMinorUnit,
5180
5308
  maxDecimalScale,
5181
5309
  min,
5182
- max,
5310
+ max: maxValue || max,
5183
5311
  "aria-labelledby": label ? id : void 0,
5184
5312
  "aria-label": "Minimum percentage",
5185
5313
  placeholder: "0%"
@@ -5187,12 +5315,13 @@ function PercentageRange(props) {
5187
5315
  ), /* @__PURE__ */ import_react37.default.createElement(
5188
5316
  PercentageInput,
5189
5317
  {
5318
+ key: minValue,
5190
5319
  label: "Maximum",
5191
5320
  value: maxValue,
5192
5321
  onChange: handleMaxChange,
5193
5322
  useMinorUnit,
5194
5323
  maxDecimalScale,
5195
- min,
5324
+ min: minValue || min,
5196
5325
  max,
5197
5326
  "aria-labelledby": label ? id : void 0,
5198
5327
  "aria-label": "Maximum percentage",
@@ -5267,6 +5396,7 @@ function FilterMenu(props) {
5267
5396
  filters,
5268
5397
  values,
5269
5398
  defaultValues,
5399
+ resetValues = {},
5270
5400
  onChange,
5271
5401
  onClose,
5272
5402
  useClear,
@@ -5292,11 +5422,11 @@ function FilterMenu(props) {
5292
5422
  onClose?.();
5293
5423
  }, [onChange, onClose, internalValues]);
5294
5424
  const handleClear = (0, import_react39.useCallback)(() => {
5295
- const clearedValues = defaultValues || {};
5425
+ const clearedValues = resetValues || {};
5296
5426
  setInternalValues(clearedValues);
5297
5427
  onChange?.(clearedValues);
5298
5428
  onClose?.();
5299
- }, [defaultValues, setInternalValues, onChange, onClose]);
5429
+ }, [resetValues, setInternalValues, onChange, onClose]);
5300
5430
  return /* @__PURE__ */ import_react39.default.createElement(
5301
5431
  ModalDialog,
5302
5432
  {