@uxf/ui 10.7.0 → 10.8.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.
@@ -6,6 +6,7 @@ export interface FileInputBaseProps extends FormControlProps<FileResponse | null
6
6
  className?: string;
7
7
  form?: string;
8
8
  id?: string;
9
+ maxFileSize?: number;
9
10
  onUploadError?: (err: unknown) => void;
10
11
  onUploadFile: (file: File) => Promise<FileResponse>;
11
12
  }
@@ -25,12 +25,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports._FileInputBase = void 0;
27
27
  const react_1 = __importStar(require("react"));
28
+ const validator_exceptions_1 = require("../utils/validator/validator-exceptions");
28
29
  exports._FileInputBase = (0, react_1.forwardRef)((props, ref) => {
29
30
  const onChange = async (e) => {
30
31
  var _a;
31
32
  if (e.target.files) {
32
33
  try {
33
- const response = await props.onUploadFile(e.target.files[0]);
34
+ const file = e.target.files[0];
35
+ if (props.maxFileSize && file.size > props.maxFileSize) {
36
+ throw validator_exceptions_1.ValidatorExceptions.MaxFileSize;
37
+ }
38
+ const response = await props.onUploadFile(file);
34
39
  await props.onChange(response, e);
35
40
  }
36
41
  catch (err) {
@@ -49,7 +49,7 @@ exports.AvatarFileInput = (0, react_1.forwardRef)((props, ref) => {
49
49
  return (react_1.default.createElement(form_component_1.FormComponent, { className: rootClassName, errorId: props.id, helperText: props.helperText, hiddenLabel: props.hiddenLabel, inputId: id, label: props.label },
50
50
  react_1.default.createElement("div", { className: "uxf-avatar-file-input__inner-wrapper" },
51
51
  react_1.default.createElement("div", { className: (0, cx_1.cx)("uxf-avatar-file-input__input", stateClassName), onClick: onSelectFile },
52
- react_1.default.createElement(_file_input_base_1._FileInputBase, { accept: (_c = props.accept) !== null && _c !== void 0 ? _c : "image/*", "aria-describedby": errorId, "aria-invalid": props.isInvalid, className: "uxf-avatar-file-input__input-element", form: props.form, id: id, isDisabled: props.isDisabled, isFocused: props.isFocused, isInvalid: props.isInvalid, isReadOnly: props.isReadOnly, isRequired: props.isRequired, name: props.name, onBlur: input.onBlur, onFocus: input.onFocus, onChange: props.onChange, onUploadError: props.onUploadError, onUploadFile: props.onUploadFile, ref: (0, composeRefs_1.composeRefs)(innerRef, ref), value: props.value }),
52
+ react_1.default.createElement(_file_input_base_1._FileInputBase, { accept: (_c = props.accept) !== null && _c !== void 0 ? _c : "image/*", "aria-describedby": errorId, "aria-invalid": props.isInvalid, className: "uxf-avatar-file-input__input-element", form: props.form, id: id, isDisabled: props.isDisabled, isFocused: props.isFocused, isInvalid: props.isInvalid, isReadOnly: props.isReadOnly, isRequired: props.isRequired, maxFileSize: props.maxFileSize, name: props.name, onBlur: input.onBlur, onFocus: input.onFocus, onChange: props.onChange, onUploadError: props.onUploadError, onUploadFile: props.onUploadFile, ref: (0, composeRefs_1.composeRefs)(innerRef, ref), value: props.value }),
53
53
  props.value ? (react_1.default.createElement(avatar_1.Avatar, { className: "uxf-avatar-file-input__input-avatar", src: (0, file_1.getFileUrl)(props.value) })) : (react_1.default.createElement("div", { className: "uxf-avatar-file-input__input-empty" },
54
54
  react_1.default.createElement(icon_1.Icon, { className: "uxf-avatar-file-input__input-empty-icon", name: (_d = props.icon) !== null && _d !== void 0 ? _d : "cloud" })))),
55
55
  react_1.default.createElement("div", { className: "uxf-avatar-file-input__controls" }, props.customControls ? (props.customControls({
@@ -33,7 +33,7 @@ const react_1 = __importStar(require("react"));
33
33
  exports.CalendarDayCell = (0, react_1.memo)((props) => {
34
34
  const dayCellRef = (0, react_1.useRef)(null);
35
35
  const innerRef = (0, react_1.useRef)(null);
36
- const { disabledDate, isHovered, isSelected, isInsideRange, isToday, isWithinHoverRange, onClick, onKeyDown, onMouseEnter, tabIndex, } = (0, use_day_1.useDay)({
36
+ const { disabledDate, isHovered, isSelected, isInsideRange, isToday, isWithinHoverRange, onClick, onKeyDown, onMouseEnter, tabIndex, isFirstDisabled, isLastDisabled, } = (0, use_day_1.useDay)({
37
37
  date: props.day.date,
38
38
  focusedDate: props.datePickerProps.focusedDate,
39
39
  isDateBlocked: props.datePickerProps.isDateBlocked,
@@ -46,6 +46,7 @@ exports.CalendarDayCell = (0, react_1.memo)((props) => {
46
46
  onDateSelect: props.datePickerProps.onDateSelect,
47
47
  dayRef: dayCellRef,
48
48
  preventScroll: props.datePickerProps.preventScroll,
49
+ unavailableDates: props.datePickerProps.unavailableDates,
49
50
  });
50
51
  (0, useOnMount_1.useOnMount)(() => {
51
52
  const node = innerRef.current;
@@ -56,7 +57,7 @@ exports.CalendarDayCell = (0, react_1.memo)((props) => {
56
57
  if (!props.day.dayLabel) {
57
58
  return react_1.default.createElement("div", null);
58
59
  }
59
- return (react_1.default.createElement("button", { className: (0, cx_1.cx)("uxf-calendar__cell uxf-calendar__cell-day", disabledDate && classes_1.CLASSES.IS_DISABLED, isToday && "uxf-calendar__cell--today", isSelected && "uxf-calendar__cell--selected", isInsideRange && "uxf-calendar__cell--inside-range", isWithinHoverRange && "uxf-calendar__cell--is-within-hover-range", isHovered && "uxf-calendar__cell--is-hovered", !props.day.currentMonth && "uxf-calendar__cell--not-current-month"), ref: disabledDate ? undefined : (0, composeRefs_1.composeRefs)(dayCellRef, innerRef), onClick: onClick, onKeyDown: onKeyDown, onMouseEnter: onMouseEnter, tabIndex: tabIndex, type: "button" },
60
+ return (react_1.default.createElement("button", { className: (0, cx_1.cx)("uxf-calendar__cell uxf-calendar__cell-day", isFirstDisabled && props.day.currentMonth && "is-disabled-start", isLastDisabled && props.day.currentMonth && "is-disabled-end", disabledDate && classes_1.CLASSES.IS_DISABLED, isToday && "uxf-calendar__cell--today", isSelected && "uxf-calendar__cell--selected", isInsideRange && "uxf-calendar__cell--inside-range", isWithinHoverRange && "uxf-calendar__cell--is-within-hover-range", isHovered && "uxf-calendar__cell--is-hovered", !props.day.currentMonth && "uxf-calendar__cell--not-current-month"), ref: disabledDate ? undefined : (0, composeRefs_1.composeRefs)(dayCellRef, innerRef), onClick: onClick, onKeyDown: onKeyDown, onMouseEnter: onMouseEnter, tabIndex: tabIndex, type: "button" },
60
61
  react_1.default.createElement("span", { className: "uxf-calendar__cell__inner" }, props.day.dayLabel)));
61
62
  });
62
63
  exports.CalendarDayCell.displayName = "UxfUiCalendarDayCell";
@@ -8,5 +8,6 @@ export interface CheckboxInputProps extends FormControlProps<boolean | undefined
8
8
  label: ReactNode;
9
9
  size?: CheckboxSize;
10
10
  style?: CSSProperties;
11
+ helperText?: ReactNode;
11
12
  }
12
13
  export declare const CheckboxInput: React.ForwardRefExoticComponent<CheckboxInputProps & React.RefAttributes<HTMLDivElement>>;
@@ -28,10 +28,15 @@ const react_1 = require("@headlessui/react");
28
28
  const react_2 = __importStar(require("react"));
29
29
  const checkbox_1 = require("../checkbox");
30
30
  exports.CheckboxInput = (0, react_2.forwardRef)((props, ref) => {
31
- var _a;
31
+ var _a, _b;
32
+ const generatedId = (0, react_2.useId)();
33
+ const id = (_a = props.id) !== null && _a !== void 0 ? _a : generatedId;
34
+ const errorId = props.isInvalid ? `${id}--error-message` : undefined;
32
35
  return (react_2.default.createElement(react_1.Switch.Group, null,
33
- react_2.default.createElement("div", { className: `uxf-checkbox-input__wrapper ${(_a = props.className) !== null && _a !== void 0 ? _a : ""}` },
36
+ react_2.default.createElement("div", { className: `uxf-checkbox-input__wrapper ${(_b = props.className) !== null && _b !== void 0 ? _b : ""}` },
34
37
  react_2.default.createElement(react_1.Switch, { as: react_2.Fragment, checked: props.value, name: props.name, onChange: props.onChange }, ({ checked }) => (react_2.default.createElement(checkbox_1.Checkbox, { className: "uxf-checkbox-input", id: props.id, indeterminate: props.indeterminate, isDisabled: props.isDisabled, isFocused: props.isFocused, isInvalid: props.isInvalid, isReadOnly: props.isReadOnly, isRequired: props.isRequired, onChange: props.onChange, ref: ref, size: props.size, style: props.style, value: checked }))),
35
- react_2.default.createElement(react_1.Switch.Label, { className: "uxf-checkbox-input__label" }, props.label))));
38
+ react_2.default.createElement(react_1.Switch.Label, { className: "uxf-checkbox-input__label" },
39
+ react_2.default.createElement("span", { className: "uxf-checkbox-input__label--text" }, props.label),
40
+ react_2.default.createElement("span", { id: errorId, className: "uxf-checkbox-input__label--subtitle" }, props.helperText)))));
36
41
  });
37
42
  exports.CheckboxInput.displayName = "UxfUiCheckboxInput";
@@ -1,6 +1,8 @@
1
1
  .uxf-checkbox-input {
2
+ margin-top: 4px;
3
+
2
4
  &__wrapper {
3
- @apply flex items-center justify-between space-x-3;
5
+ @apply flex justify-between space-x-3;
4
6
  }
5
7
 
6
8
  &__label {
@@ -15,6 +17,12 @@
15
17
  }
16
18
  }
17
19
 
20
+ &__label--subtitle {
21
+ color: theme("colors.error.DEFAULT");
22
+ display: block;
23
+ font-size: theme("fontSize.caption");
24
+ }
25
+
18
26
  &.is-disabled,
19
27
  &.is-readonly {
20
28
  & + .uxf-checkbox-input__label {
@@ -22,8 +22,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
25
28
  Object.defineProperty(exports, "__esModule", { value: true });
26
29
  exports.Default = void 0;
30
+ const dayjs_1 = __importDefault(require("dayjs"));
27
31
  const react_1 = __importStar(require("react"));
28
32
  const action_1 = require("../utils/action");
29
33
  const date_picker_1 = require("./date-picker");
@@ -31,12 +35,24 @@ exports.default = {
31
35
  title: "UI/DatePicker",
32
36
  component: date_picker_1.DatePicker,
33
37
  };
38
+ const today = (0, dayjs_1.default)();
39
+ const unavailableDates = [
40
+ today.toDate(),
41
+ today.add(5, "days").toDate(),
42
+ today.add(6, "days").toDate(),
43
+ today.add(7, "days").toDate(),
44
+ today.add(11, "days").toDate(),
45
+ today.add(12, "days").toDate(),
46
+ ];
34
47
  function Default() {
35
48
  const [value, setValue] = (0, react_1.useState)(null);
36
49
  const onChange = (0, action_1.action)("onChange", setValue);
37
50
  const onClose = () => null;
38
51
  const testDatePickers = (react_1.default.createElement(react_1.default.Fragment, null,
39
- react_1.default.createElement(date_picker_1.DatePicker, { closePopoverHandler: onClose, onChange: onChange, selectedDate: value })));
52
+ react_1.default.createElement("p", { className: "text-lg" }, "Date picker"),
53
+ react_1.default.createElement(date_picker_1.DatePicker, { closePopoverHandler: onClose, onChange: onChange, selectedDate: value }),
54
+ react_1.default.createElement("p", { className: "text-lg" }, "Date picker with unavailable dates"),
55
+ react_1.default.createElement(date_picker_1.DatePicker, { onChange: onChange, selectedDate: value, unavailableDates: unavailableDates })));
40
56
  return (react_1.default.createElement(react_1.default.Fragment, null,
41
57
  react_1.default.createElement("div", { className: "light max-w-[640px] space-y-4 rounded bg-white p-8" }, testDatePickers),
42
58
  react_1.default.createElement("div", { className: "dark max-w-[640px] space-y-4 rounded bg-gray-900 p-8 text-white" }, testDatePickers)));
@@ -5,11 +5,11 @@ import { FileInputBaseProps } from "../_file-input-base";
5
5
  export interface FileInputProps extends FileInputBaseProps, Clearable {
6
6
  className?: string;
7
7
  helperText?: ReactNode;
8
- label?: ReactNode;
9
8
  hiddenLabel?: boolean;
9
+ label?: ReactNode;
10
10
  placeholder?: string;
11
- uploadButtonLabel?: string;
12
11
  size?: keyof InputGroupSizes;
12
+ uploadButtonLabel?: string;
13
13
  variant?: keyof InputGroupVariants;
14
14
  }
15
15
  export declare const FileInput: React.ForwardRefExoticComponent<FileInputProps & React.RefAttributes<HTMLInputElement>>;
@@ -53,7 +53,7 @@ exports.FileInput = (0, react_1.forwardRef)((props, ref) => {
53
53
  };
54
54
  return (react_1.default.createElement(form_component_1.FormComponent, { className: (0, cx_1.cx)(input.focused && classes_1.CLASSES.IS_FOCUSED, props.isDisabled && classes_1.CLASSES.IS_DISABLED, props.isInvalid && classes_1.CLASSES.IS_INVALID, props.isReadOnly && classes_1.CLASSES.IS_READONLY), errorId: errorId, form: props.form, helperText: props.helperText, inputId: id, isRequired: props.isRequired, label: props.label, hiddenLabel: props.hiddenLabel },
55
55
  react_1.default.createElement(react_1.default.Fragment, null,
56
- react_1.default.createElement(_file_input_base_1._FileInputBase, { accept: props.accept, "aria-describedby": errorId, "aria-invalid": props.isInvalid, className: `uxf-file-input__input ${(_a = props.className) !== null && _a !== void 0 ? _a : ""}`, form: props.form, id: id, isDisabled: props.isDisabled || isUploading, isInvalid: props.isInvalid, isReadOnly: props.isReadOnly, isRequired: props.isRequired, name: props.name, onBlur: input.onBlur, onChange: props.onChange, onFocus: input.onFocus, onUploadError: props.onUploadError, onUploadFile: onUploadFile, ref: ref, value: props.value }),
56
+ react_1.default.createElement(_file_input_base_1._FileInputBase, { accept: props.accept, "aria-describedby": errorId, "aria-invalid": props.isInvalid, className: `uxf-file-input__input ${(_a = props.className) !== null && _a !== void 0 ? _a : ""}`, form: props.form, id: id, isDisabled: props.isDisabled || isUploading, isInvalid: props.isInvalid, isReadOnly: props.isReadOnly, isRequired: props.isRequired, maxFileSize: props.maxFileSize, name: props.name, onBlur: input.onBlur, onChange: props.onChange, onFocus: input.onFocus, onUploadError: props.onUploadError, onUploadFile: onUploadFile, ref: ref, value: props.value }),
57
57
  react_1.default.createElement("label", { className: (0, cx_1.cx)("uxf-input", "uxf-file-input__label", input.focused && classes_1.CLASSES.IS_FOCUSED, (props.isDisabled || props.isReadOnly) && classes_1.CLASSES.IS_DISABLED, props.isInvalid && classes_1.CLASSES.IS_INVALID, isUploading && classes_1.CLASSES.IS_LOADING, isUploading && "uxf-file-input__label--has-right-addon", `uxf-input--size-${(_b = props.size) !== null && _b !== void 0 ? _b : "default"}`, `uxf-input--variant-${(_c = props.variant) !== null && _c !== void 0 ? _c : "default"}`), htmlFor: id },
58
58
  react_1.default.createElement("div", { className: "uxf-input__left-addon uxf-file-input__label__button" }, !isUploading ? ((_d = props.uploadButtonLabel) !== null && _d !== void 0 ? _d : "Vyberte soubor") : (react_1.default.createElement(loader_1.Loader, { className: "uxf-file-input__label__loader", size: "sm" }))),
59
59
  react_1.default.createElement("div", { className: "uxf-file-input__label__wrapper" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/ui",
3
- "version": "10.7.0",
3
+ "version": "10.8.0",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -18,7 +18,7 @@
18
18
  "@floating-ui/react": "0.26.0",
19
19
  "@headlessui/react": "1.7.14",
20
20
  "@uxf/core": "10.4.0",
21
- "@uxf/datepicker": "10.0.0",
21
+ "@uxf/datepicker": "10.8.0",
22
22
  "@uxf/styles": "10.4.0",
23
23
  "color2k": "2.0.2",
24
24
  "dayjs": "1.11.10",
@@ -0,0 +1,3 @@
1
+ export declare enum ValidatorExceptions {
2
+ MaxFileSize = "MaxFileSizeException"
3
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValidatorExceptions = void 0;
4
+ var ValidatorExceptions;
5
+ (function (ValidatorExceptions) {
6
+ ValidatorExceptions["MaxFileSize"] = "MaxFileSizeException";
7
+ })(ValidatorExceptions || (exports.ValidatorExceptions = ValidatorExceptions = {}));