@hitachivantara/uikit-react-core 5.82.4 → 5.83.1
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/cjs/BaseInput/BaseInput.cjs +4 -7
- package/dist/cjs/ButtonBase/ButtonBase.styles.cjs +6 -5
- package/dist/cjs/Calendar/Calendar.cjs +2 -2
- package/dist/cjs/Calendar/CalendarHeader/CalendarHeader.cjs +12 -28
- package/dist/cjs/Calendar/SingleCalendar/SingleCalendar.cjs +2 -1
- package/dist/cjs/Calendar/utils.cjs +53 -21
- package/dist/cjs/CheckBoxGroup/CheckBoxGroup.cjs +1 -0
- package/dist/cjs/CheckBoxGroup/CheckBoxGroup.styles.cjs +1 -1
- package/dist/cjs/ColorPicker/ColorPicker.cjs +12 -9
- package/dist/cjs/ColorPicker/ColorPicker.styles.cjs +15 -12
- package/dist/cjs/ColorPicker/Fields/Fields.cjs +6 -3
- package/dist/cjs/DatePicker/DatePicker.cjs +2 -2
- package/dist/cjs/DatePicker/DatePicker.styles.cjs +1 -4
- package/dist/cjs/DatePicker/utils.cjs +2 -2
- package/dist/cjs/Dropdown/Dropdown.cjs +1 -0
- package/dist/cjs/Dropdown/Dropdown.styles.cjs +1 -1
- package/dist/cjs/FileUploader/DropZone/DropZone.cjs +1 -0
- package/dist/cjs/FileUploader/DropZone/DropZone.styles.cjs +1 -3
- package/dist/cjs/FilterGroup/FilterGroup.cjs +1 -0
- package/dist/cjs/FilterGroup/FilterGroup.styles.cjs +1 -4
- package/dist/cjs/FormElement/Label/Label.cjs +3 -2
- package/dist/cjs/FormElement/Label/Label.styles.cjs +1 -1
- package/dist/cjs/Input/Input.cjs +10 -8
- package/dist/cjs/Input/Input.styles.cjs +1 -1
- package/dist/cjs/RadioGroup/RadioGroup.cjs +1 -0
- package/dist/cjs/RadioGroup/RadioGroup.styles.cjs +1 -1
- package/dist/cjs/Select/Option.cjs +1 -2
- package/dist/cjs/Select/Select.cjs +7 -1
- package/dist/cjs/Select/Select.styles.cjs +1 -4
- package/dist/cjs/SelectionList/SelectionList.cjs +1 -0
- package/dist/cjs/SelectionList/SelectionList.styles.cjs +1 -1
- package/dist/cjs/Slider/utils.cjs +3 -3
- package/dist/cjs/Switch/Switch.cjs +1 -0
- package/dist/cjs/Switch/Switch.styles.cjs +1 -1
- package/dist/cjs/Table/TableRow/TableRow.styles.cjs +20 -5
- package/dist/cjs/Table/hooks/{useBulkActions.cjs → useHvBulkActions.cjs} +6 -7
- package/dist/cjs/Table/hooks/{useFilters.cjs → useHvFilters.cjs} +2 -2
- package/dist/cjs/Table/hooks/{useGlobalFilter.cjs → useHvGlobalFilter.cjs} +2 -2
- package/dist/cjs/Table/hooks/{useHeaderGroups.cjs → useHvHeaderGroups.cjs} +4 -4
- package/dist/cjs/Table/hooks/{usePagination.cjs → useHvPagination.cjs} +4 -4
- package/dist/cjs/Table/hooks/{useResizeColumns.cjs → useHvResizeColumns.cjs} +4 -4
- package/dist/cjs/Table/hooks/{useRowExpand.cjs → useHvRowExpand.cjs} +6 -5
- package/dist/cjs/Table/hooks/{useRowSelection.cjs → useHvRowSelection.cjs} +4 -8
- package/dist/cjs/Table/hooks/{useRowState.cjs → useHvRowState.cjs} +2 -2
- package/dist/cjs/Table/hooks/{useSortBy.cjs → useHvSortBy.cjs} +4 -4
- package/dist/cjs/Table/hooks/{useSticky.cjs → useHvSticky.cjs} +4 -6
- package/dist/cjs/Table/hooks/{useTable.cjs → useHvTable.cjs} +6 -4
- package/dist/cjs/Table/hooks/{useTableStyles.cjs → useHvTableStyles.cjs} +4 -5
- package/dist/cjs/Table/renderers/{DateColumnCell/DateColumnCell.cjs → DateColumnCell.cjs} +1 -1
- package/dist/cjs/Table/renderers/DefaultCell.cjs +21 -0
- package/dist/cjs/Table/renderers/{DropdownColumnCell/DropdownColumnCell.cjs → DropdownColumnCell.cjs} +1 -1
- package/dist/cjs/Table/renderers/{ProgressColumnCell/ProgressColumnCell.cjs → ProgressColumnCell.cjs} +20 -2
- package/dist/cjs/Table/renderers/{SwitchColumnCell/SwitchColumnCell.cjs → SwitchColumnCell.cjs} +13 -4
- package/dist/cjs/Table/renderers/renderers.cjs +21 -8
- package/dist/cjs/Tag/Tag.cjs +67 -49
- package/dist/cjs/Tag/Tag.styles.cjs +50 -64
- package/dist/cjs/TagsInput/TagsInput.cjs +2 -4
- package/dist/cjs/TagsInput/TagsInput.styles.cjs +2 -5
- package/dist/cjs/TextArea/TextArea.cjs +5 -4
- package/dist/cjs/TextArea/TextArea.styles.cjs +1 -1
- package/dist/cjs/TimeAgo/TimeAgo.cjs +2 -1
- package/dist/cjs/TimePicker/TimePicker.cjs +3 -1
- package/dist/cjs/TimePicker/TimePicker.styles.cjs +1 -4
- package/dist/cjs/index.cjs +40 -50
- package/dist/cjs/utils/keyboardUtils.cjs +4 -0
- package/dist/esm/BaseInput/BaseInput.js +3 -6
- package/dist/esm/BaseInput/BaseInput.js.map +1 -1
- package/dist/esm/ButtonBase/ButtonBase.styles.js +6 -5
- package/dist/esm/ButtonBase/ButtonBase.styles.js.map +1 -1
- package/dist/esm/Calendar/Calendar.js +3 -3
- package/dist/esm/Calendar/Calendar.js.map +1 -1
- package/dist/esm/Calendar/CalendarHeader/CalendarHeader.js +13 -24
- package/dist/esm/Calendar/CalendarHeader/CalendarHeader.js.map +1 -1
- package/dist/esm/Calendar/SingleCalendar/SingleCalendar.js +3 -2
- package/dist/esm/Calendar/SingleCalendar/SingleCalendar.js.map +1 -1
- package/dist/esm/Calendar/utils.js +54 -20
- package/dist/esm/Calendar/utils.js.map +1 -1
- package/dist/esm/CheckBoxGroup/CheckBoxGroup.js +1 -0
- package/dist/esm/CheckBoxGroup/CheckBoxGroup.js.map +1 -1
- package/dist/esm/CheckBoxGroup/CheckBoxGroup.styles.js +1 -1
- package/dist/esm/CheckBoxGroup/CheckBoxGroup.styles.js.map +1 -1
- package/dist/esm/ColorPicker/ColorPicker.js +13 -10
- package/dist/esm/ColorPicker/ColorPicker.js.map +1 -1
- package/dist/esm/ColorPicker/ColorPicker.styles.js +15 -12
- package/dist/esm/ColorPicker/ColorPicker.styles.js.map +1 -1
- package/dist/esm/ColorPicker/Fields/Fields.js +6 -3
- package/dist/esm/ColorPicker/Fields/Fields.js.map +1 -1
- package/dist/esm/Controls/Controls.js.map +1 -1
- package/dist/esm/DatePicker/DatePicker.js +3 -3
- package/dist/esm/DatePicker/DatePicker.js.map +1 -1
- package/dist/esm/DatePicker/DatePicker.styles.js +1 -4
- package/dist/esm/DatePicker/DatePicker.styles.js.map +1 -1
- package/dist/esm/DatePicker/utils.js +2 -2
- package/dist/esm/DatePicker/utils.js.map +1 -1
- package/dist/esm/Dropdown/Dropdown.js +1 -0
- package/dist/esm/Dropdown/Dropdown.js.map +1 -1
- package/dist/esm/Dropdown/Dropdown.styles.js +1 -1
- package/dist/esm/Dropdown/Dropdown.styles.js.map +1 -1
- package/dist/esm/FileUploader/DropZone/DropZone.js +1 -0
- package/dist/esm/FileUploader/DropZone/DropZone.js.map +1 -1
- package/dist/esm/FileUploader/DropZone/DropZone.styles.js +1 -3
- package/dist/esm/FileUploader/DropZone/DropZone.styles.js.map +1 -1
- package/dist/esm/FilterGroup/FilterGroup.js +1 -0
- package/dist/esm/FilterGroup/FilterGroup.js.map +1 -1
- package/dist/esm/FilterGroup/FilterGroup.styles.js +1 -4
- package/dist/esm/FilterGroup/FilterGroup.styles.js.map +1 -1
- package/dist/esm/FormElement/Label/Label.js +3 -2
- package/dist/esm/FormElement/Label/Label.js.map +1 -1
- package/dist/esm/FormElement/Label/Label.styles.js +1 -1
- package/dist/esm/FormElement/Label/Label.styles.js.map +1 -1
- package/dist/esm/Input/Input.js +11 -9
- package/dist/esm/Input/Input.js.map +1 -1
- package/dist/esm/Input/Input.styles.js +1 -1
- package/dist/esm/Input/Input.styles.js.map +1 -1
- package/dist/esm/RadioGroup/RadioGroup.js +1 -0
- package/dist/esm/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/esm/RadioGroup/RadioGroup.styles.js +1 -1
- package/dist/esm/RadioGroup/RadioGroup.styles.js.map +1 -1
- package/dist/esm/Select/Option.js +1 -2
- package/dist/esm/Select/Option.js.map +1 -1
- package/dist/esm/Select/Select.js +7 -1
- package/dist/esm/Select/Select.js.map +1 -1
- package/dist/esm/Select/Select.styles.js +1 -4
- package/dist/esm/Select/Select.styles.js.map +1 -1
- package/dist/esm/SelectionList/SelectionList.js +1 -0
- package/dist/esm/SelectionList/SelectionList.js.map +1 -1
- package/dist/esm/SelectionList/SelectionList.styles.js +1 -1
- package/dist/esm/SelectionList/SelectionList.styles.js.map +1 -1
- package/dist/esm/Slider/utils.js +3 -3
- package/dist/esm/Slider/utils.js.map +1 -1
- package/dist/esm/Switch/Switch.js +1 -0
- package/dist/esm/Switch/Switch.js.map +1 -1
- package/dist/esm/Switch/Switch.styles.js +1 -1
- package/dist/esm/Switch/Switch.styles.js.map +1 -1
- package/dist/esm/Table/TableRow/TableRow.styles.js +16 -1
- package/dist/esm/Table/TableRow/TableRow.styles.js.map +1 -1
- package/dist/esm/Table/hooks/{useBulkActions.js → useHvBulkActions.js} +5 -6
- package/dist/esm/Table/hooks/useHvBulkActions.js.map +1 -0
- package/dist/esm/Table/hooks/{useFilters.js → useHvFilters.js} +1 -1
- package/dist/esm/Table/hooks/useHvFilters.js.map +1 -0
- package/dist/esm/Table/hooks/{useGlobalFilter.js → useHvGlobalFilter.js} +1 -1
- package/dist/esm/Table/hooks/useHvGlobalFilter.js.map +1 -0
- package/dist/esm/Table/hooks/{useHeaderGroups.js → useHvHeaderGroups.js} +3 -3
- package/dist/esm/Table/hooks/useHvHeaderGroups.js.map +1 -0
- package/dist/esm/Table/hooks/{usePagination.js → useHvPagination.js} +4 -4
- package/dist/esm/Table/hooks/useHvPagination.js.map +1 -0
- package/dist/esm/Table/hooks/{useResizeColumns.js → useHvResizeColumns.js} +3 -3
- package/dist/esm/Table/hooks/useHvResizeColumns.js.map +1 -0
- package/dist/esm/Table/hooks/{useRowExpand.js → useHvRowExpand.js} +5 -4
- package/dist/esm/Table/hooks/useHvRowExpand.js.map +1 -0
- package/dist/esm/Table/hooks/{useRowSelection.js → useHvRowSelection.js} +3 -7
- package/dist/esm/Table/hooks/useHvRowSelection.js.map +1 -0
- package/dist/esm/Table/hooks/{useRowState.js → useHvRowState.js} +1 -1
- package/dist/esm/Table/hooks/useHvRowState.js.map +1 -0
- package/dist/esm/Table/hooks/{useSortBy.js → useHvSortBy.js} +3 -3
- package/dist/esm/Table/hooks/useHvSortBy.js.map +1 -0
- package/dist/esm/Table/hooks/{useSticky.js → useHvSticky.js} +3 -5
- package/dist/esm/Table/hooks/useHvSticky.js.map +1 -0
- package/dist/esm/Table/hooks/{useTable.js → useHvTable.js} +5 -3
- package/dist/esm/Table/hooks/useHvTable.js.map +1 -0
- package/dist/esm/Table/hooks/{useTableStyles.js → useHvTableStyles.js} +3 -4
- package/dist/esm/Table/hooks/useHvTableStyles.js.map +1 -0
- package/dist/esm/Table/renderers/{DateColumnCell/DateColumnCell.js → DateColumnCell.js} +1 -1
- package/dist/esm/Table/renderers/DateColumnCell.js.map +1 -0
- package/dist/esm/Table/renderers/DefaultCell.js +21 -0
- package/dist/esm/Table/renderers/DefaultCell.js.map +1 -0
- package/dist/esm/Table/renderers/{DropdownColumnCell/DropdownColumnCell.js → DropdownColumnCell.js} +1 -1
- package/dist/esm/Table/renderers/DropdownColumnCell.js.map +1 -0
- package/dist/esm/Table/renderers/{ProgressColumnCell/ProgressColumnCell.js → ProgressColumnCell.js} +19 -1
- package/dist/esm/Table/renderers/ProgressColumnCell.js.map +1 -0
- package/dist/esm/Table/renderers/{SwitchColumnCell/SwitchColumnCell.js → SwitchColumnCell.js} +12 -3
- package/dist/esm/Table/renderers/SwitchColumnCell.js.map +1 -0
- package/dist/esm/Table/renderers/renderers.js +18 -5
- package/dist/esm/Table/renderers/renderers.js.map +1 -1
- package/dist/esm/Tag/Tag.js +71 -51
- package/dist/esm/Tag/Tag.js.map +1 -1
- package/dist/esm/Tag/Tag.styles.js +50 -64
- package/dist/esm/Tag/Tag.styles.js.map +1 -1
- package/dist/esm/TagsInput/TagsInput.js +2 -4
- package/dist/esm/TagsInput/TagsInput.js.map +1 -1
- package/dist/esm/TagsInput/TagsInput.styles.js +2 -5
- package/dist/esm/TagsInput/TagsInput.styles.js.map +1 -1
- package/dist/esm/TextArea/TextArea.js +5 -4
- package/dist/esm/TextArea/TextArea.js.map +1 -1
- package/dist/esm/TextArea/TextArea.styles.js +1 -1
- package/dist/esm/TextArea/TextArea.styles.js.map +1 -1
- package/dist/esm/TimeAgo/TimeAgo.js +2 -1
- package/dist/esm/TimeAgo/TimeAgo.js.map +1 -1
- package/dist/esm/TimePicker/TimePicker.js +3 -1
- package/dist/esm/TimePicker/TimePicker.js.map +1 -1
- package/dist/esm/TimePicker/TimePicker.styles.js +1 -4
- package/dist/esm/TimePicker/TimePicker.styles.js.map +1 -1
- package/dist/esm/index.js +34 -44
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/keyboardUtils.js +4 -0
- package/dist/esm/utils/keyboardUtils.js.map +1 -1
- package/dist/types/index.d.ts +369 -395
- package/package.json +6 -6
- package/dist/cjs/Table/renderers/ProgressColumnCell/ProgressColumnCell.styles.cjs +0 -26
- package/dist/cjs/Table/renderers/SwitchColumnCell/SwitchColumnCell.styles.cjs +0 -21
- package/dist/cjs/Table/utils/fallbacks.cjs +0 -16
- package/dist/cjs/Table/utils/utils.cjs +0 -19
- package/dist/esm/Table/hooks/useBulkActions.js.map +0 -1
- package/dist/esm/Table/hooks/useFilters.js.map +0 -1
- package/dist/esm/Table/hooks/useGlobalFilter.js.map +0 -1
- package/dist/esm/Table/hooks/useHeaderGroups.js.map +0 -1
- package/dist/esm/Table/hooks/usePagination.js.map +0 -1
- package/dist/esm/Table/hooks/useResizeColumns.js.map +0 -1
- package/dist/esm/Table/hooks/useRowExpand.js.map +0 -1
- package/dist/esm/Table/hooks/useRowSelection.js.map +0 -1
- package/dist/esm/Table/hooks/useRowState.js.map +0 -1
- package/dist/esm/Table/hooks/useSortBy.js.map +0 -1
- package/dist/esm/Table/hooks/useSticky.js.map +0 -1
- package/dist/esm/Table/hooks/useTable.js.map +0 -1
- package/dist/esm/Table/hooks/useTableStyles.js.map +0 -1
- package/dist/esm/Table/renderers/DateColumnCell/DateColumnCell.js.map +0 -1
- package/dist/esm/Table/renderers/DropdownColumnCell/DropdownColumnCell.js.map +0 -1
- package/dist/esm/Table/renderers/ProgressColumnCell/ProgressColumnCell.js.map +0 -1
- package/dist/esm/Table/renderers/ProgressColumnCell/ProgressColumnCell.styles.js +0 -26
- package/dist/esm/Table/renderers/ProgressColumnCell/ProgressColumnCell.styles.js.map +0 -1
- package/dist/esm/Table/renderers/SwitchColumnCell/SwitchColumnCell.js.map +0 -1
- package/dist/esm/Table/renderers/SwitchColumnCell/SwitchColumnCell.styles.js +0 -21
- package/dist/esm/Table/renderers/SwitchColumnCell/SwitchColumnCell.styles.js.map +0 -1
- package/dist/esm/Table/utils/fallbacks.js +0 -16
- package/dist/esm/Table/utils/fallbacks.js.map +0 -1
- package/dist/esm/Table/utils/utils.js +0 -19
- package/dist/esm/Table/utils/utils.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import dayjs from "dayjs";
|
|
2
1
|
import { capitalize } from "../utils/helpers.js";
|
|
3
2
|
const CALENDAR_WEEKS = 6;
|
|
3
|
+
const DEFAULT_LOCALE = "en";
|
|
4
4
|
const getMonthDays = (month, year) => new Date(year, month, 0).getDate();
|
|
5
5
|
const getMonthFirstWeekday = (month, year) => new Date(year, month - 1, 1).getDay();
|
|
6
6
|
const makeUTCDate = (year, monthIndex, day, hour = 1) => new Date(Date.UTC(year, monthIndex, day, hour));
|
|
@@ -14,6 +14,9 @@ const isSameDay = (date1, date2) => {
|
|
|
14
14
|
if (!(isDate(date1) && isDate(date2))) return false;
|
|
15
15
|
return date1.getDate() === date2.getDate() && date1.getMonth() === date2.getMonth() && date1.getFullYear() === date2.getFullYear();
|
|
16
16
|
};
|
|
17
|
+
const getDateISO = (date) => {
|
|
18
|
+
return new Date(date).toISOString().slice(0, 10);
|
|
19
|
+
};
|
|
17
20
|
const getPreviousMonth = (month, year) => {
|
|
18
21
|
const prevMonth = month > 1 ? month - 1 : 12;
|
|
19
22
|
const prevMonthYear = month > 1 ? year : year - 1;
|
|
@@ -41,7 +44,10 @@ const getWeekdayNamesList = (locale) => {
|
|
|
41
44
|
});
|
|
42
45
|
};
|
|
43
46
|
const getMonthName = (date, locale, representationValue = "long") => new Intl.DateTimeFormat(locale, { month: representationValue }).format(date);
|
|
44
|
-
const getFormattedDate = (date, locale
|
|
47
|
+
const getFormattedDate = (date, locale) => {
|
|
48
|
+
const formatter = new Intl.DateTimeFormat(locale, { dateStyle: "medium" });
|
|
49
|
+
return formatter.format(date);
|
|
50
|
+
};
|
|
45
51
|
const createDatesArray = (month, year) => {
|
|
46
52
|
const monthDays = getMonthDays(month, year);
|
|
47
53
|
const daysFromPrevMonth = getMonthFirstWeekday(month, year);
|
|
@@ -64,47 +70,75 @@ const createDatesArray = (month, year) => {
|
|
|
64
70
|
return [...prevMonthDates, ...currentMonthDates, ...nextMonthDates];
|
|
65
71
|
};
|
|
66
72
|
const isRange = (date) => date != null && typeof date === "object" && "startDate" in date;
|
|
67
|
-
const dateInProvidedValueRange = (date,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
const convertedDate = dayjs(date).format("YYYY-MM-DD");
|
|
73
|
+
const dateInProvidedValueRange = (date, dateRange) => {
|
|
74
|
+
if (!isRange(dateRange) || !dateRange?.endDate) return false;
|
|
75
|
+
const { startDate, endDate } = dateRange;
|
|
76
|
+
const modStartDate = getDateISO(startDate);
|
|
77
|
+
const modEndDate = getDateISO(endDate);
|
|
78
|
+
const convertedDate = getDateISO(date ?? /* @__PURE__ */ new Date());
|
|
74
79
|
return convertedDate >= modStartDate && convertedDate <= modEndDate;
|
|
75
80
|
};
|
|
76
81
|
const checkIfDateIsDisabled = (date, minimumDate, maximumDate) => {
|
|
77
82
|
if (!minimumDate && !maximumDate) return false;
|
|
78
|
-
const modStartDate = minimumDate
|
|
79
|
-
const modEndDate = maximumDate
|
|
80
|
-
const convertedDate =
|
|
83
|
+
const modStartDate = minimumDate && getDateISO(minimumDate);
|
|
84
|
+
const modEndDate = maximumDate && getDateISO(maximumDate);
|
|
85
|
+
const convertedDate = getDateISO(date ?? /* @__PURE__ */ new Date());
|
|
81
86
|
return modStartDate !== void 0 && convertedDate < modStartDate || modEndDate !== void 0 && convertedDate > modEndDate;
|
|
82
87
|
};
|
|
83
|
-
|
|
88
|
+
function getEditableDateFormatter(locale) {
|
|
84
89
|
return new Intl.DateTimeFormat(locale, {
|
|
85
|
-
|
|
86
|
-
month: "
|
|
87
|
-
|
|
88
|
-
})
|
|
89
|
-
}
|
|
90
|
+
year: "numeric",
|
|
91
|
+
month: "2-digit",
|
|
92
|
+
day: "2-digit"
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function getStringFromDate(date, locale) {
|
|
96
|
+
return getEditableDateFormatter(locale).format(date);
|
|
97
|
+
}
|
|
98
|
+
function parseDateString(dateString, locale) {
|
|
99
|
+
const dateParts = dateString.split(/\D+/).map(Number);
|
|
100
|
+
if (dateParts.length !== 3) return null;
|
|
101
|
+
if (!dateParts.every(Boolean)) return null;
|
|
102
|
+
const formatter = getEditableDateFormatter(locale);
|
|
103
|
+
const formatOrder = formatter.formatToParts(new Date(2020, 4, 4)).filter((part) => ["year", "month", "day"].includes(part.type)).map((part) => part.type);
|
|
104
|
+
const dateObject = { year: 2020, month: 4, day: 4 };
|
|
105
|
+
formatOrder.forEach((type, index) => {
|
|
106
|
+
dateObject[type] = dateParts[index];
|
|
107
|
+
});
|
|
108
|
+
return new Date(dateObject.year, dateObject.month - 1, dateObject.day);
|
|
109
|
+
}
|
|
110
|
+
function getLocaleDateFormat(locale) {
|
|
111
|
+
const formatter = getEditableDateFormatter(locale);
|
|
112
|
+
const getPartType = (part) => {
|
|
113
|
+
if (part.type === "year") return "YYYY";
|
|
114
|
+
if (part.type === "month") return "MM";
|
|
115
|
+
if (part.type === "day") return "DD";
|
|
116
|
+
return part.value;
|
|
117
|
+
};
|
|
118
|
+
return formatter.formatToParts(new Date(2020, 4, 4)).reduce((acc, part) => acc + getPartType(part), "");
|
|
119
|
+
}
|
|
90
120
|
export {
|
|
91
121
|
CALENDAR_WEEKS,
|
|
122
|
+
DEFAULT_LOCALE,
|
|
92
123
|
checkIfDateIsDisabled,
|
|
93
124
|
createDatesArray,
|
|
94
125
|
dateInProvidedValueRange,
|
|
95
|
-
|
|
126
|
+
getDateISO,
|
|
96
127
|
getFormattedDate,
|
|
128
|
+
getLocaleDateFormat,
|
|
97
129
|
getMonthDays,
|
|
98
130
|
getMonthFirstWeekday,
|
|
99
131
|
getMonthName,
|
|
100
132
|
getMonthNamesList,
|
|
101
133
|
getNextMonth,
|
|
102
134
|
getPreviousMonth,
|
|
135
|
+
getStringFromDate,
|
|
103
136
|
getWeekdayNamesList,
|
|
104
137
|
isDate,
|
|
105
138
|
isDateRangeProp,
|
|
106
139
|
isRange,
|
|
107
140
|
isSameDay,
|
|
108
141
|
isSameMonth,
|
|
109
|
-
makeUTCDate
|
|
142
|
+
makeUTCDate,
|
|
143
|
+
parseDateString
|
|
110
144
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../src/Calendar/utils.tsx"],"sourcesContent":["import dayjs from \"dayjs\";\n\nimport { capitalize } from \"../utils/helpers\";\nimport { DateRangeProp } from \"./types\";\n\n/**\n * Constant with the number of weeks to be displayed on the calendar.\n */\nexport const CALENDAR_WEEKS = 6;\n\n/**\n * Constant with the default locale that should be used as the default.\n */\nexport const DEFAULT_LOCALE = \"en\";\n\n/**\n * Pads a string value with leading zeroes(0) until length is reached.\n *\n * @param value - Value to be padded.\n * @param length - Length of the value after the padding is added.\n * @returns The value as a string with the received amount of padding.\n *\n * @example zeroPad(5, 2) => \"05\"\n */\nexport const zeroPad = (value: number, length: number) =>\n `${value}`.padStart(length, \"0\");\n\n/**\n * Returns the number of days in the month given a month and year.\n *\n * @param month - Number of the month (1 to 12).\n * @param year - Number of the year.\n * @returns The number of days in a month for the received year.\n */\nexport const getMonthDays = (month: number, year: number) =>\n new Date(year, month, 0).getDate();\n\n/**\n * Gets the week day of the first day of a given month and year.\n * From 0 (Sunday) to 6 (Saturday).\n *\n * @param month - Number of the month (1 to 12).\n * @param year - Number of the year.\n * @returns The zero indexed week day where 0 is Sunday (0 to 6).\n */\nexport const getMonthFirstWeekday = (month: number, year: number) =>\n new Date(year, month - 1, 1).getDay();\n\n/**\n * Creates a `Date` instance in UTC timezone.\n *\n * @param year - The year of the date.\n * @param monthIndex - The zero indexed month of the year (0 to 11).\n * @param day - The day of the month.\n * @param [hour=1] - The hour of the day.\n * @returns A `Date` instance in UTC timezone.\n */\nexport const makeUTCDate = (\n year: number,\n monthIndex: number,\n day: number,\n hour = 1,\n) => new Date(Date.UTC(year, monthIndex, day, hour));\n\n/**\n * Checks if the received date is a valid date.\n *\n * @param date - The date to be validated.\n * @returns A flag stating if the date is valid or not.\n */\nexport const isDate = (date: any): date is Date =>\n Object.prototype.toString.call(date) === \"[object Date]\" &&\n !Number.isNaN(date.valueOf());\n\nexport const isDateRangeProp = (date: any): date is DateRangeProp =>\n \"startDate\" in date;\n\n/**\n * Checks if two dates are in the same month and year.\n *\n * @param date1 - First date.\n * @param date2 - Second date.\n * @returns A flag stating if the dates are in the same month and year or not.\n */\nexport const isSameMonth = (date1: any, date2: any) => {\n if (!(isDate(date1) && isDate(date2))) return false;\n\n return (\n date1.getMonth() === date2.getMonth() &&\n date1.getFullYear() === date2.getFullYear()\n );\n};\n\n/**\n * Checks if two dates are on the same day.\n *\n * @param date1 - First date.\n * @param date2 - Second date.\n * @returns A flag stating if the dates are in the same day or not.\n */\nexport const isSameDay = (date1: any, date2: any) => {\n if (!(isDate(date1) && isDate(date2))) return false;\n\n return (\n date1.getDate() === date2.getDate() &&\n date1.getMonth() === date2.getMonth() &&\n date1.getFullYear() === date2.getFullYear()\n );\n};\n\n/**\n * Formats the received date using the ISO format (YYYY-MM-DD).\n *\n * @param date - The date to be formatted.\n * @returns The formatted date in ISO format.\n */\nexport const getDateISO = (date?: Date) => {\n if (!isDate(date)) return null;\n\n return [\n date.getFullYear(),\n zeroPad(date.getMonth() + 1, 2),\n zeroPad(date.getDate(), 2),\n ].join(\"-\");\n};\n\n/**\n * Returns an object with the previous month taking also into consideration the year.\n * For example the previous month of January 2000 will be December 1999.\n *\n * @param month - Number of the month.\n * @param year - Number of the year.\n * @returns Object with new month and year defined.\n */\nexport const getPreviousMonth = (month: number, year: number) => {\n const prevMonth = month > 1 ? month - 1 : 12;\n const prevMonthYear = month > 1 ? year : year - 1;\n\n return { month: prevMonth, year: prevMonthYear };\n};\n\n/**\n * Returns an object with the next month taking also into consideration the year.\n * For example the next month of December 2000 will be January 2001.\n *\n * @param month - Number of the month.\n * @param year - Number of the year.\n * @returns Object with new month and year defined.\n */\nexport const getNextMonth = (month: number, year: number) => {\n const nextMonth = month < 12 ? month + 1 : 1;\n const nextMonthYear = month < 12 ? year : year + 1;\n\n return { month: nextMonth, year: nextMonthYear };\n};\n\n/**\n * Returns a list with the names of all the months localized in the received locale and representation value.\n *\n * @param locale - The locale to be applied to the Intl format.\n * @param representationValue - The representation value for the month.\n * @returns An array with all the months names.\n */\nexport const getMonthNamesList = (\n locale: string | undefined,\n representationValue: Intl.DateTimeFormatOptions[\"month\"] = \"long\",\n) => {\n const options = { month: representationValue, timeZone: \"UTC\" };\n\n return [...Array(12).keys()].map((index) => {\n const auxDate = makeUTCDate(1970, index, 1);\n return capitalize(Intl.DateTimeFormat(locale, options).format(auxDate));\n });\n};\n\n/**\n * Returns a list with the names of all the weekdays localized in the received locale and representation value.\n *\n * @param locale - The locale to be applied.\n * @returns An array with all the weekday names.\n */\nexport const getWeekdayNamesList = (locale: string) => {\n const formatter = new Intl.DateTimeFormat(locale, {\n weekday: \"narrow\",\n timeZone: \"UTC\",\n });\n\n return [...Array(7).keys()].map((index) => {\n return formatter.format(makeUTCDate(1970, 0, 4 + index));\n });\n};\n\n/**\n * Returns the name of the month for the supplied month localized in the received locale and representation value.\n *\n * @param date - The date from which the month name is extracted.\n * @param locale - The locale to be applied to the Intl format.\n * @param representationValue - The locale to be applied to the Intl format.\n * @returns The name of the month.\n */\nexport const getMonthName = (\n date: Date,\n locale: string,\n representationValue: Intl.DateTimeFormatOptions[\"month\"] = \"long\",\n) =>\n new Intl.DateTimeFormat(locale, { month: representationValue }).format(date);\n\n/**\n * Formats the received date according to Design System specifications.\n * Currently: day month, year => `14 Aug, 2019`.\n *\n * @param date - UTC date to be formatted.\n * @param locale - The locale to be applied to the Intl format.\n * @returns The formatted date as a string.\n */\nexport const getFormattedDate = (\n // TODO: fix this\n date: any,\n locale: any,\n rep: Intl.DateTimeFormatOptions[\"month\"] = \"short\",\n) =>\n `${date.getDate()} ${getMonthName(date, locale, rep)} ${date.getFullYear()}`;\n\n/**\n * Creates an array of 42 days. The complete current month and enough days from the previous and next months to fill\n * the 42 positions.\n *\n * @param month - The number of the month (1 to 12).\n * @param year - The number of the year.\n * @returns The array of dates.\n */\nexport const createDatesArray = (month: number, year: number) => {\n // Initializes the variables needed to calculate the dates for the received month and year\n const monthDays = getMonthDays(month, year);\n const daysFromPrevMonth = getMonthFirstWeekday(month, year);\n const daysFromNextMonth =\n CALENDAR_WEEKS * 7 - (daysFromPrevMonth + monthDays);\n const prevMonthYear = getPreviousMonth(month, year);\n const nextMonthYear = getNextMonth(month, year);\n const prevMonthDays = getMonthDays(prevMonthYear.month, prevMonthYear.year);\n\n // Creates the arrays for the dates for previous, current and next months\n const prevMonthDates = [...Array(daysFromPrevMonth).keys()].map((index) => {\n const day = index + 1 + (prevMonthDays - daysFromPrevMonth);\n return new Date(prevMonthYear.year, prevMonthYear.month - 1, day);\n });\n const currentMonthDates = [...Array(monthDays).keys()].map((index) => {\n const day = index + 1;\n return new Date(year, month - 1, day);\n });\n const nextMonthDates = [...Array(daysFromNextMonth).keys()].map((index) => {\n const day = index + 1;\n return new Date(nextMonthYear.year, nextMonthYear.month - 1, day);\n });\n\n return [...prevMonthDates, ...currentMonthDates, ...nextMonthDates];\n};\n\nexport const isRange = (date: any): date is DateRangeProp =>\n date != null && typeof date === \"object\" && \"startDate\" in date;\n\n/**\n * Checks if the date falls within a specified date range.\n *\n * @param date - The date to be evaluated.\n * @param providedValueRange - Provided selection range.\n * @returns - True if the date falls within the range, false otherwise.\n */\nexport const dateInProvidedValueRange = (\n date: any,\n providedValueRange: any,\n) => {\n const { startDate, endDate } = providedValueRange;\n\n if (!isRange(providedValueRange) || endDate == null) return false;\n const localEndDate = endDate;\n\n const modStartDate = dayjs(startDate).format(\"YYYY-MM-DD\");\n const modEndDate = dayjs(localEndDate).format(\"YYYY-MM-DD\");\n\n const convertedDate = dayjs(date).format(\"YYYY-MM-DD\");\n\n return convertedDate >= modStartDate && convertedDate <= modEndDate;\n};\n\nexport const checkIfDateIsDisabled = (\n date?: string | number | Date | dayjs.Dayjs,\n minimumDate?: string | number | Date | dayjs.Dayjs,\n maximumDate?: string | number | Date | dayjs.Dayjs,\n) => {\n if (!minimumDate && !maximumDate) return false;\n const modStartDate = minimumDate\n ? dayjs(minimumDate).format(\"YYYY-MM-DD\")\n : undefined;\n const modEndDate = maximumDate\n ? dayjs(maximumDate).format(\"YYYY-MM-DD\")\n : undefined;\n\n const convertedDate = dayjs(date).format(\"YYYY-MM-DD\");\n\n return (\n (modStartDate !== undefined && convertedDate < modStartDate) ||\n (modEndDate !== undefined && convertedDate > modEndDate)\n );\n};\n\nexport const formatToLocale = (date: any, locale: any) => {\n return new Intl.DateTimeFormat(locale, {\n day: \"numeric\",\n month: \"short\",\n year: \"numeric\",\n }).format(date);\n};\n"],"names":[],"mappings":";;AAQO,MAAM,iBAAiB;AA0BjB,MAAA,eA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W,WAAgB;AACjD,SAAA,IAAI,KAAK,eAAe,QAAQ;AAAA,IACrC,KAAK;AAAA,IACL,OAAO;AAAA,IACP,MAAM;AAAA,EAAA,CACP,EAAE,OAAO,IAAI;AAChB;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../src/Calendar/utils.tsx"],"sourcesContent":["import { capitalize } from \"../utils/helpers\";\nimport type { DateRangeProp } from \"./types\";\n\n/** number of weeks to be displayed on the calendar. */\nexport const CALENDAR_WEEKS = 6;\n\n/** default locale used in the date-aware components */\nexport const DEFAULT_LOCALE = \"en\";\n\n/**\n * Returns the number of days in the month given a month and year.\n *\n * @param month - Number of the month (1 to 12).\n * @param year - Number of the year.\n * @returns The number of days in a month for the received year.\n */\nexport const getMonthDays = (month: number, year: number) =>\n new Date(year, month, 0).getDate();\n\n/**\n * Gets the week day of the first day of a given month and year.\n * From 0 (Sunday) to 6 (Saturday).\n *\n * @param month - Number of the month (1 to 12).\n * @param year - Number of the year.\n * @returns The zero indexed week day where 0 is Sunday (0 to 6).\n */\nexport const getMonthFirstWeekday = (month: number, year: number) =>\n new Date(year, month - 1, 1).getDay();\n\n/**\n * Creates a `Date` instance in UTC timezone.\n *\n * @param year - The year of the date.\n * @param monthIndex - The zero indexed month of the year (0 to 11).\n * @param day - The day of the month.\n * @param [hour=1] - The hour of the day.\n * @returns A `Date` instance in UTC timezone.\n */\nexport const makeUTCDate = (\n year: number,\n monthIndex: number,\n day: number,\n hour = 1,\n) => new Date(Date.UTC(year, monthIndex, day, hour));\n\n/**\n * Checks if the received date is a valid date.\n *\n * @param date - The date to be validated.\n * @returns A flag stating if the date is valid or not.\n */\nexport const isDate = (date: any): date is Date =>\n Object.prototype.toString.call(date) === \"[object Date]\" &&\n !Number.isNaN(date.valueOf());\n\nexport const isDateRangeProp = (date: any): date is DateRangeProp =>\n \"startDate\" in date;\n\n/**\n * Checks if two dates are in the same month and year.\n *\n * @param date1 - First date.\n * @param date2 - Second date.\n * @returns A flag stating if the dates are in the same month and year or not.\n */\nexport const isSameMonth = (date1?: Date, date2?: Date) => {\n if (!(isDate(date1) && isDate(date2))) return false;\n\n return (\n date1.getMonth() === date2.getMonth() &&\n date1.getFullYear() === date2.getFullYear()\n );\n};\n\n/**\n * Checks if two dates are on the same day.\n *\n * @param date1 - First date.\n * @param date2 - Second date.\n * @returns A flag stating if the dates are in the same day or not.\n */\nexport const isSameDay = (date1: any, date2: any) => {\n if (!(isDate(date1) && isDate(date2))) return false;\n\n return (\n date1.getDate() === date2.getDate() &&\n date1.getMonth() === date2.getMonth() &&\n date1.getFullYear() === date2.getFullYear()\n );\n};\n\n/**\n * Formats the received date using the ISO format (YYYY-MM-DD).\n *\n * @param date - The date to be formatted.\n * @returns The formatted date in ISO format.\n */\nexport const getDateISO = (date: string | number | Date) => {\n return new Date(date).toISOString().slice(0, 10);\n};\n\n/**\n * Returns an object with the previous month taking also into consideration the year.\n * For example the previous month of January 2000 will be December 1999.\n *\n * @param month - Number of the month.\n * @param year - Number of the year.\n * @returns Object with new month and year defined.\n */\nexport const getPreviousMonth = (month: number, year: number) => {\n const prevMonth = month > 1 ? month - 1 : 12;\n const prevMonthYear = month > 1 ? year : year - 1;\n\n return { month: prevMonth, year: prevMonthYear };\n};\n\n/**\n * Returns an object with the next month taking also into consideration the year.\n * For example the next month of December 2000 will be January 2001.\n *\n * @param month - Number of the month.\n * @param year - Number of the year.\n * @returns Object with new month and year defined.\n */\nexport const getNextMonth = (month: number, year: number) => {\n const nextMonth = month < 12 ? month + 1 : 1;\n const nextMonthYear = month < 12 ? year : year + 1;\n\n return { month: nextMonth, year: nextMonthYear };\n};\n\n/**\n * Returns a list with the names of all the months localized in the received locale and representation value.\n *\n * @param locale - The locale to be applied to the Intl format.\n * @param representationValue - The representation value for the month.\n * @returns An array with all the months names.\n */\nexport const getMonthNamesList = (\n locale: string | undefined,\n representationValue: Intl.DateTimeFormatOptions[\"month\"] = \"long\",\n) => {\n const options = { month: representationValue, timeZone: \"UTC\" };\n\n return [...Array(12).keys()].map((index) => {\n const auxDate = makeUTCDate(1970, index, 1);\n return capitalize(Intl.DateTimeFormat(locale, options).format(auxDate));\n });\n};\n\n/**\n * Returns a list with the names of all the weekdays localized in the received locale and representation value.\n *\n * @param locale - The locale to be applied.\n * @returns An array with all the weekday names.\n */\nexport const getWeekdayNamesList = (locale: string) => {\n const formatter = new Intl.DateTimeFormat(locale, {\n weekday: \"narrow\",\n timeZone: \"UTC\",\n });\n\n return [...Array(7).keys()].map((index) => {\n return formatter.format(makeUTCDate(1970, 0, 4 + index));\n });\n};\n\n/**\n * Returns the name of the month for the supplied month localized in the received locale and representation value.\n *\n * @param date - The date from which the month name is extracted.\n * @param locale - The locale to be applied to the Intl format.\n * @param representationValue - The locale to be applied to the Intl format.\n * @returns The name of the month.\n */\nexport const getMonthName = (\n date: Date,\n locale: Intl.LocalesArgument,\n representationValue: Intl.DateTimeFormatOptions[\"month\"] = \"long\",\n) =>\n new Intl.DateTimeFormat(locale, { month: representationValue }).format(date);\n\n/**\n * Formats the received date according to the user's locale & Design System specifications.\n *\n * @param date - UTC date to be formatted.\n * @param locale - The locale to be applied to the Intl format.\n * @returns The formatted date as a string.\n */\nexport const getFormattedDate = (date: Date, locale: Intl.LocalesArgument) => {\n const formatter = new Intl.DateTimeFormat(locale, { dateStyle: \"medium\" });\n return formatter.format(date);\n};\n\n/**\n * Creates an array of 42 days. The complete current month and enough days from the previous and next months to fill\n * the 42 positions.\n *\n * @param month - The number of the month (1 to 12).\n * @param year - The number of the year.\n * @returns The array of dates.\n */\nexport const createDatesArray = (month: number, year: number) => {\n // Initializes the variables needed to calculate the dates for the received month and year\n const monthDays = getMonthDays(month, year);\n const daysFromPrevMonth = getMonthFirstWeekday(month, year);\n const daysFromNextMonth =\n CALENDAR_WEEKS * 7 - (daysFromPrevMonth + monthDays);\n const prevMonthYear = getPreviousMonth(month, year);\n const nextMonthYear = getNextMonth(month, year);\n const prevMonthDays = getMonthDays(prevMonthYear.month, prevMonthYear.year);\n\n // Creates the arrays for the dates for previous, current and next months\n const prevMonthDates = [...Array(daysFromPrevMonth).keys()].map((index) => {\n const day = index + 1 + (prevMonthDays - daysFromPrevMonth);\n return new Date(prevMonthYear.year, prevMonthYear.month - 1, day);\n });\n const currentMonthDates = [...Array(monthDays).keys()].map((index) => {\n const day = index + 1;\n return new Date(year, month - 1, day);\n });\n const nextMonthDates = [...Array(daysFromNextMonth).keys()].map((index) => {\n const day = index + 1;\n return new Date(nextMonthYear.year, nextMonthYear.month - 1, day);\n });\n\n return [...prevMonthDates, ...currentMonthDates, ...nextMonthDates];\n};\n\nexport const isRange = (date: any): date is DateRangeProp =>\n date != null && typeof date === \"object\" && \"startDate\" in date;\n\n/**\n * Checks if the date falls within a specified date range.\n *\n * @param date - The date to be evaluated.\n * @param dateRange - Provided selection range.\n * @returns - True if the date falls within the range, false otherwise.\n */\nexport const dateInProvidedValueRange = (\n date: Date | undefined,\n dateRange: string | Date | DateRangeProp,\n) => {\n if (!isRange(dateRange) || !dateRange?.endDate) return false;\n const { startDate, endDate } = dateRange;\n\n const modStartDate = getDateISO(startDate);\n const modEndDate = getDateISO(endDate);\n const convertedDate = getDateISO(date ?? new Date());\n\n return convertedDate >= modStartDate && convertedDate <= modEndDate;\n};\n\nexport const checkIfDateIsDisabled = (\n date?: string | number | Date,\n minimumDate?: string | number | Date,\n maximumDate?: string | number | Date,\n) => {\n if (!minimumDate && !maximumDate) return false;\n const modStartDate = minimumDate && getDateISO(minimumDate);\n const modEndDate = maximumDate && getDateISO(maximumDate);\n const convertedDate = getDateISO(date ?? new Date());\n\n return (\n (modStartDate !== undefined && convertedDate < modStartDate) ||\n (modEndDate !== undefined && convertedDate > modEndDate)\n );\n};\n\n/**\n * gets the *localized* date formatter that's editable via input\n * @example getEditableDateFormatter(\"pt\") // \"DD/MM/YYYY\"\n */\nfunction getEditableDateFormatter(locale: Intl.LocalesArgument) {\n return new Intl.DateTimeFormat(locale, {\n year: \"numeric\",\n month: \"2-digit\",\n day: \"2-digit\",\n });\n}\n\nexport function getStringFromDate(date: Date, locale: Intl.LocalesArgument) {\n return getEditableDateFormatter(locale).format(date);\n}\n\n/**\n * attempts to format a localized `dateString`\n * @returns `Date` or `null` if parsing fails\n * @example parseDateString(\"04/06/2020\", \"pt\")\n */\nexport function parseDateString(\n dateString: string,\n locale: Intl.LocalesArgument,\n) {\n // Split the input dateString by non-numeric separators (like / or -)\n const dateParts = dateString.split(/\\D+/).map(Number);\n if (dateParts.length !== 3) return null;\n if (!dateParts.every(Boolean)) return null;\n\n const formatter = getEditableDateFormatter(locale);\n const formatOrder = formatter\n .formatToParts(new Date(2020, 4, 4))\n .filter((part) => [\"year\", \"month\", \"day\"].includes(part.type))\n .map((part) => part.type as \"year\" | \"month\" | \"day\");\n\n // Map the parts into an object { year, month, day }\n const dateObject = { year: 2020, month: 4, day: 4 };\n formatOrder.forEach((type, index) => {\n dateObject[type] = dateParts[index];\n });\n\n return new Date(dateObject.year, dateObject.month - 1, dateObject.day);\n}\n\nexport function getLocaleDateFormat(locale: Intl.LocalesArgument) {\n const formatter = getEditableDateFormatter(locale);\n\n // Create the format string based on the order of parts\n const getPartType = (part: Intl.DateTimeFormatPart) => {\n if (part.type === \"year\") return \"YYYY\";\n if (part.type === \"month\") return \"MM\";\n if (part.type === \"day\") return \"DD\";\n return part.value; // preserve separators like '/' or '-'\n };\n\n return formatter\n .formatToParts(new Date(2020, 4, 4))\n .reduce((acc, part) => acc + getPartType(part), \"\");\n}\n"],"names":[],"mappings":";AAIO,MAAM,iBAAiB;AAGvB,MAAM,iBAAiB;AASjB,MAAA,eAAe,CAAC,OAAe,SAC1C,IAAI,KAAK,MAAM,OAAO,CAAC,EAAE,QAAQ;AAUtB,MAAA,uBAAuB,CAAC,OAAe,SAClD,IAAI,KAAK,MAAM,QAAQ,GAAG,CAAC,EAAE,OAAO;AAW/B,MAAM,cAAc,CACzB,MACA,YACA,KACA,OAAO,MACJ,IAAI,KAAK,KAAK,IAAI,MAAM,YAAY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MAAM,KAAK,EAAE,IAAI,MAAM;AAChD,MAAA,UAAU,WAAW,EAAU,QAAA;AACnC,MAAI,CAAC,UAAU,MAAM,OAAO,EAAU,QAAA;AAEhC,QAAA,YAAY,yBAAyB,MAAM;AAC3C,QAAA,cAAc,UACjB,cAAc,IAAI,KAAK,MAAM,GAAG,CAAC,CAAC,EAClC,OAAO,CAAC,SAAS,CAAC,QAAQ,SAAS,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC,EAC7D,IAAI,CAAC,SAAS,KAAK,IAAgC;AAGtD,QAAM,aAAa,EAAE,MAAM,MAAM,OAAO,GAAG,KAAK,EAAE;AACtC,cAAA,QAAQ,CAAC,MAAM,UAAU;AACxB,eAAA,IAAI,IAAI,UAAU,KAAK;AAAA,EAAA,CACnC;AAEM,SAAA,IAAI,KAAK,WAAW,MAAM,WAAW,QAAQ,GAAG,WAAW,GAAG;AACvE;AAEO,SAAS,oBAAoB,QAA8B;AAC1D,QAAA,YAAY,yBAAyB,MAAM;AAG3C,QAAA,cAAc,CAAC,SAAkC;AACjD,QAAA,KAAK,SAAS,OAAe,QAAA;AAC7B,QAAA,KAAK,SAAS,QAAgB,QAAA;AAC9B,QAAA,KAAK,SAAS,MAAc,QAAA;AAChC,WAAO,KAAK;AAAA,EACd;AAEA,SAAO,UACJ,cAAc,IAAI,KAAK,MAAM,GAAG,CAAC,CAAC,EAClC,OAAO,CAAC,KAAK,SAAS,MAAM,YAAY,IAAI,GAAG,EAAE;AACtD;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CheckBoxGroup.js","sources":["../../../src/CheckBoxGroup/CheckBoxGroup.tsx"],"sourcesContent":["import {\n Children,\n cloneElement,\n forwardRef,\n useCallback,\n useMemo,\n useRef,\n} from \"react\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvCheckBox } from \"../CheckBox\";\nimport {\n HvFormElement,\n HvFormStatus,\n HvInfoMessage,\n HvLabel,\n HvWarningText,\n} from \"../FormElement\";\nimport { useControlled } from \"../hooks/useControlled\";\nimport { useUniqueId } from \"../hooks/useUniqueId\";\nimport { HvBaseProps } from \"../types/generic\";\nimport { multiSelectionEventHandler } from \"../utils/multiSelectionEventHandler\";\nimport { setId } from \"../utils/setId\";\nimport { staticClasses, useClasses } from \"./CheckBoxGroup.styles\";\n\nconst computeSelectAllState = (selected: number, total: number) => {\n if (selected === 0) {\n return \"none\";\n }\n\n if (selected === total) {\n return \"all\";\n }\n\n return \"some\";\n};\n\nconst getValueFromSelectedChildren = (children: React.ReactNode) => {\n const selectedValues = Children.toArray(children)\n .map((child: any) => {\n const childIsControlled = child?.props?.checked !== undefined;\n const childIsSelected = childIsControlled\n ? child?.props?.checked\n : child?.props?.defaultChecked;\n\n return childIsSelected ? child?.props?.value : undefined;\n })\n .filter((v) => v !== undefined);\n\n return selectedValues;\n};\n\nexport { staticClasses as checkBoxGroupClasses };\n\nexport type HvCheckBoxGroupClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvCheckBoxGroupProps\n extends HvBaseProps<HTMLDivElement, \"onChange\"> {\n /**\n * The form element name.\n *\n * It is propagated to the children checkboxes, unless they already have one.\n */\n name?: string;\n /**\n * The value of the form element. An array of values represented in the child checkboxes.\n *\n * When defined the checkbox group state becomes controlled.\n */\n value?: any[];\n /**\n * When uncontrolled, defines the initial value.\n */\n defaultValue?: any[];\n /**\n * The label of the form element.\n *\n * The form element must be labeled for accessibility reasons.\n * If not provided, an aria-label or aria-labelledby must be provided instead.\n */\n label?: React.ReactNode;\n /**\n * Provide additional descriptive text for the form element.\n */\n description?: React.ReactNode;\n /**\n * Indicates that the form element is disabled.\n * If `true` the state is propagated to the children checkboxes.\n */\n disabled?: boolean;\n /**\n * Indicates that the form element is not editable.\n * If `true` the state is propagated to the children checkboxes.\n */\n readOnly?: boolean;\n /**\n * Indicates that user input is required on the form element.\n */\n required?: boolean;\n /**\n * The status of the form element.\n *\n * Valid is correct, invalid is incorrect and standBy means no validations have run.\n *\n * When uncontrolled and unspecified it will default to \"standBy\" and change to either \"valid\"\n * or \"invalid\" after any change to the state.\n */\n status?: HvFormStatus;\n /**\n * The error message to show when the validation status is \"invalid\".\n *\n * Defaults to \"Required\" when the status is uncontrolled and no `aria-errormessage` is provided.\n */\n statusMessage?: React.ReactNode;\n /**\n * The callback fired when the value changes.\n */\n onChange?: (event: React.ChangeEvent<HTMLInputElement>, value: any[]) => void;\n /**\n * Indicates whether the checkbox group's orientation is horizontal or vertical.\n *\n * Defaults to vertical.\n */\n orientation?: \"vertical\" | \"horizontal\";\n /**\n * Indicates if an additional select all checkbox should be shown.\n */\n showSelectAll?: boolean;\n /**\n * The label of the select all checkbox. Defaults to \"All\".\n */\n selectAllLabel?: string;\n /**\n * Custom label for select all checkbox conjunction\n */\n selectAllConjunctionLabel?: string;\n /**\n * A Jss Object used to override or extend the component styles applied.\n */\n classes?: HvCheckBoxGroupClasses;\n}\n\n/**\n * A checkbox group is a type of selection list that allows the user to select multiple options through the use of checkboxes.\n */\nexport const HvCheckBoxGroup = forwardRef<HTMLDivElement, HvCheckBoxGroupProps>(\n function HvCheckBoxGroup(props, ref) {\n const {\n id,\n classes: classesProp,\n className,\n children,\n name,\n label,\n description,\n status,\n statusMessage,\n defaultValue,\n value: valueProp,\n required,\n readOnly,\n disabled,\n showSelectAll,\n orientation = \"vertical\",\n selectAllLabel = \"All\",\n selectAllConjunctionLabel = \"/\",\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-errormessage\": ariaErrorMessage,\n onChange,\n ...others\n } = useDefaultProps(\"HvCheckBoxGroup\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const [value, setValue] = useControlled(\n valueProp,\n defaultValue !== undefined\n ? defaultValue\n : // When uncontrolled and no default value is given,\n // extract the initial selected values from the children own state\n () => getValueFromSelectedChildren(children),\n );\n\n const [validationState, setValidationState] = useControlled<HvFormStatus>(\n status,\n \"standBy\",\n );\n\n const [validationMessage] = useControlled(statusMessage, \"Required\");\n\n const elementId = useUniqueId(id);\n\n const selectionAnchor = useRef(undefined);\n\n const [allValues, selectedState, selectedCount] = useMemo(() => {\n const childValues: any[] = [];\n const childSelectedState: boolean[] = [];\n let childSelectedCounter = 0;\n\n Children.toArray(children).forEach((child: any, i: number) => {\n const childValue = child?.props?.value;\n const childIsSelected = value.indexOf(childValue) !== -1;\n\n childValues[i] = childValue;\n childSelectedState[i] = childIsSelected;\n\n if (childIsSelected) {\n childSelectedCounter += 1;\n }\n });\n\n return [childValues, childSelectedState, childSelectedCounter];\n }, [children, value]);\n\n const selectAllState = computeSelectAllState(\n value.length,\n selectedState.length,\n );\n\n const onChildChangeInterceptor = useCallback(\n (\n index: number,\n childOnChange: (\n event: React.ChangeEvent<HTMLInputElement>,\n isChecked: boolean,\n ) => void,\n event: React.ChangeEvent<HTMLInputElement>,\n isChecked: boolean,\n ) => {\n const newValue = multiSelectionEventHandler(\n event,\n index,\n selectionAnchor,\n allValues,\n selectedState,\n isChecked,\n );\n\n childOnChange?.(event, isChecked);\n\n onChange?.(event, newValue);\n\n setValue(() => {\n // This will only run if uncontrolled\n\n if (required && newValue.length === 0) {\n setValidationState(\"invalid\");\n } else {\n setValidationState(\"valid\");\n }\n\n return newValue;\n });\n },\n [\n allValues,\n onChange,\n required,\n selectedState,\n setValidationState,\n setValue,\n ],\n );\n\n const modifiedChildren = useMemo(() => {\n return Children.map(children, (child: any, i: number) => {\n const childIsSelected = selectedState[i];\n\n return cloneElement(child, {\n checked: childIsSelected,\n name: child?.props?.name || name,\n onChange: (\n event: React.ChangeEvent<HTMLInputElement>,\n isChecked: boolean,\n ) =>\n onChildChangeInterceptor(\n i,\n child?.props?.onChange,\n event,\n isChecked,\n ),\n disabled: disabled || child?.props?.disabled,\n readOnly: readOnly || child?.props?.readOnly,\n });\n });\n }, [\n children,\n disabled,\n name,\n onChildChangeInterceptor,\n readOnly,\n selectedState,\n ]);\n\n const handleSelectAll = (\n event: React.ChangeEvent<HTMLInputElement>,\n selectAllChecked: boolean,\n ) => {\n let newValue: any[];\n if (selectAllState === \"some\") {\n newValue = [];\n } else if (selectAllChecked) {\n newValue = [...allValues];\n } else {\n newValue = [];\n }\n\n onChange?.(event, newValue);\n\n setValue(() => {\n // This will only run if uncontrolled\n if (required && newValue.length === 0) {\n setValidationState(\"invalid\");\n } else {\n setValidationState(\"valid\");\n }\n\n return newValue;\n });\n };\n\n const selectAllLabelComponent =\n selectedCount === 0 ? (\n <>\n <b>{selectAllLabel}</b>\n {` (${Children.toArray(children).length})`}\n </>\n ) : (\n <>\n <b>{selectedCount}</b>\n {` ${selectAllConjunctionLabel} ${Children.toArray(children).length}`}\n </>\n );\n\n // The error message area will only be created if:\n // - an external element that provides an error message isn't identified via aria-errormessage AND\n // - both status and statusMessage properties are being controlled OR\n // - status is uncontrolled and required is true\n const canShowError =\n ariaErrorMessage == null &&\n ((status !== undefined && statusMessage !== undefined) ||\n (status === undefined && required));\n\n const errorMessageId = canShowError\n ? setId(elementId, \"error\")\n : ariaErrorMessage;\n\n return (\n <HvFormElement\n id={id}\n name={name}\n status={validationState}\n disabled={disabled}\n required={required}\n readOnly={readOnly}\n className={cx(classes.root, className)}\n >\n {label && (\n <HvLabel\n id={setId(elementId, \"label\")}\n label={label}\n className={classes.label}\n />\n )}\n\n {description && (\n <HvInfoMessage id={setId(elementId, \"description\")}>\n {description}\n </HvInfoMessage>\n )}\n\n <div\n ref={ref}\n role=\"group\"\n aria-label={ariaLabel}\n aria-labelledby={\n ariaLabelledBy || (label && setId(elementId, \"label\")) || undefined\n }\n aria-disabled={disabled ? true : undefined}\n aria-invalid={validationState === \"invalid\" ? true : undefined}\n aria-errormessage={\n validationState === \"invalid\" ? errorMessageId : undefined\n }\n aria-describedby={\n [description && setId(elementId, \"description\"), ariaDescribedBy]\n .join(\" \")\n .trim() || undefined\n }\n className={cx(classes.group, {\n [classes.vertical]: orientation === \"vertical\",\n [classes.horizontal]: orientation === \"horizontal\",\n [classes.invalid]: validationState === \"invalid\",\n })}\n {...others}\n >\n {showSelectAll && (\n <HvCheckBox\n checked={selectAllState === \"all\"}\n indeterminate={selectAllState === \"some\"}\n label={selectAllLabelComponent}\n disabled={disabled}\n readOnly={readOnly}\n className={classes.selectAll}\n onChange={handleSelectAll}\n />\n )}\n {modifiedChildren}\n </div>\n\n {canShowError && (\n <HvWarningText\n id={setId(elementId, \"error\")}\n disableBorder\n className={classes.error}\n >\n {validationMessage}\n </HvWarningText>\n )}\n </HvFormElement>\n );\n },\n);\n"],"names":["HvCheckBoxGroup"],"mappings":";;;;;;;;;;;;;;AA4BA,MAAM,wBAAwB,CAAC,UAAkB,UAAkB;AACjE,MAAI,aAAa,GAAG;AACX,WAAA;AAAA,EAAA;AAGT,MAAI,aAAa,OAAO;AACf,WAAA;AAAA,EAAA;AAGF,SAAA;AACT;AAEA,MAAM,+BAA+B,CAAC,aAA8B;AAClE,QAAM,iBAAiB,SAAS,QAAQ,QAAQ,EAC7C,IAAI,CAAC,UAAe;AACb,UAAA,oBAAoB,OAAO,OAAO,YAAY;AACpD,UAAM,kBAAkB,oBACpB,OAAO,OAAO,UACd,OAAO,OAAO;AAEX,WAAA,kBAAkB,OAAO,OAAO,QAAQ;AAAA,EAChD,CAAA,EACA,OAAO,CAAC,MAAM,MAAM,MAAS;AAEzB,SAAA;AACT;AA+FO,MAAM,kBAAkB;AAAA,EAC7B,SAASA,iBAAgB,OAAO,KAAK;AAC7B,UAAA;AAAA,MACJ;AAAA,MACA,SAAS;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,OAAO;AAAA,MACP;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,cAAc;AAAA,MACd,iBAAiB;AAAA,MACjB,4BAA4B;AAAA,MAC5B,cAAc;AAAA,MACd,mBAAmB;AAAA,MACnB,oBAAoB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AAO,GAAG,oBAAoB;AAAA,cAAA,CACxC;AAAA,cACA,GAAG;AAAA,cAEH,UAAA;AAAA,gBACC,iBAAA;AAAA,kBAAC;AAAA,kBAAA;AAAA,oBACC,SAAS,mBAAmB;AAAA,oBAC5B,eAAe,mBAAmB;AAAA,oBAClC,OAAO;AAAA,oBACP;AAAA,oBACA;AAAA,oBACA,WAAW,QAAQ;AAAA,oBACnB,UAAU;AAAA,kBAAA;AAAA,gBACZ;AAAA,gBAED;AAAA,cAAA;AAAA,YAAA;AAAA,UACH;AAAA,UAEC,gBACC;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,IAAI,MAAM,WAAW,OAAO;AAAA,cAC5B,eAAa;AAAA,cACb,WAAW,QAAQ;AAAA,cAElB,UAAA;AAAA,YAAA;AAAA,UAAA;AAAA,QACH;AAAA,MAAA;AAAA,IAEJ;AAAA,EAAA;AAGN;"}
|
|
1
|
+
{"version":3,"file":"CheckBoxGroup.js","sources":["../../../src/CheckBoxGroup/CheckBoxGroup.tsx"],"sourcesContent":["import {\n Children,\n cloneElement,\n forwardRef,\n useCallback,\n useMemo,\n useRef,\n} from \"react\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvCheckBox } from \"../CheckBox\";\nimport {\n HvFormElement,\n HvFormStatus,\n HvInfoMessage,\n HvLabel,\n HvWarningText,\n} from \"../FormElement\";\nimport { useControlled } from \"../hooks/useControlled\";\nimport { useUniqueId } from \"../hooks/useUniqueId\";\nimport { HvBaseProps } from \"../types/generic\";\nimport { multiSelectionEventHandler } from \"../utils/multiSelectionEventHandler\";\nimport { setId } from \"../utils/setId\";\nimport { staticClasses, useClasses } from \"./CheckBoxGroup.styles\";\n\nconst computeSelectAllState = (selected: number, total: number) => {\n if (selected === 0) {\n return \"none\";\n }\n\n if (selected === total) {\n return \"all\";\n }\n\n return \"some\";\n};\n\nconst getValueFromSelectedChildren = (children: React.ReactNode) => {\n const selectedValues = Children.toArray(children)\n .map((child: any) => {\n const childIsControlled = child?.props?.checked !== undefined;\n const childIsSelected = childIsControlled\n ? child?.props?.checked\n : child?.props?.defaultChecked;\n\n return childIsSelected ? child?.props?.value : undefined;\n })\n .filter((v) => v !== undefined);\n\n return selectedValues;\n};\n\nexport { staticClasses as checkBoxGroupClasses };\n\nexport type HvCheckBoxGroupClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvCheckBoxGroupProps\n extends HvBaseProps<HTMLDivElement, \"onChange\"> {\n /**\n * The form element name.\n *\n * It is propagated to the children checkboxes, unless they already have one.\n */\n name?: string;\n /**\n * The value of the form element. An array of values represented in the child checkboxes.\n *\n * When defined the checkbox group state becomes controlled.\n */\n value?: any[];\n /**\n * When uncontrolled, defines the initial value.\n */\n defaultValue?: any[];\n /**\n * The label of the form element.\n *\n * The form element must be labeled for accessibility reasons.\n * If not provided, an aria-label or aria-labelledby must be provided instead.\n */\n label?: React.ReactNode;\n /**\n * Provide additional descriptive text for the form element.\n */\n description?: React.ReactNode;\n /**\n * Indicates that the form element is disabled.\n * If `true` the state is propagated to the children checkboxes.\n */\n disabled?: boolean;\n /**\n * Indicates that the form element is not editable.\n * If `true` the state is propagated to the children checkboxes.\n */\n readOnly?: boolean;\n /**\n * Indicates that user input is required on the form element.\n */\n required?: boolean;\n /**\n * The status of the form element.\n *\n * Valid is correct, invalid is incorrect and standBy means no validations have run.\n *\n * When uncontrolled and unspecified it will default to \"standBy\" and change to either \"valid\"\n * or \"invalid\" after any change to the state.\n */\n status?: HvFormStatus;\n /**\n * The error message to show when the validation status is \"invalid\".\n *\n * Defaults to \"Required\" when the status is uncontrolled and no `aria-errormessage` is provided.\n */\n statusMessage?: React.ReactNode;\n /**\n * The callback fired when the value changes.\n */\n onChange?: (event: React.ChangeEvent<HTMLInputElement>, value: any[]) => void;\n /**\n * Indicates whether the checkbox group's orientation is horizontal or vertical.\n *\n * Defaults to vertical.\n */\n orientation?: \"vertical\" | \"horizontal\";\n /**\n * Indicates if an additional select all checkbox should be shown.\n */\n showSelectAll?: boolean;\n /**\n * The label of the select all checkbox. Defaults to \"All\".\n */\n selectAllLabel?: string;\n /**\n * Custom label for select all checkbox conjunction\n */\n selectAllConjunctionLabel?: string;\n /**\n * A Jss Object used to override or extend the component styles applied.\n */\n classes?: HvCheckBoxGroupClasses;\n}\n\n/**\n * A checkbox group is a type of selection list that allows the user to select multiple options through the use of checkboxes.\n */\nexport const HvCheckBoxGroup = forwardRef<HTMLDivElement, HvCheckBoxGroupProps>(\n function HvCheckBoxGroup(props, ref) {\n const {\n id,\n classes: classesProp,\n className,\n children,\n name,\n label,\n description,\n status,\n statusMessage,\n defaultValue,\n value: valueProp,\n required,\n readOnly,\n disabled,\n showSelectAll,\n orientation = \"vertical\",\n selectAllLabel = \"All\",\n selectAllConjunctionLabel = \"/\",\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-errormessage\": ariaErrorMessage,\n onChange,\n ...others\n } = useDefaultProps(\"HvCheckBoxGroup\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const [value, setValue] = useControlled(\n valueProp,\n defaultValue !== undefined\n ? defaultValue\n : // When uncontrolled and no default value is given,\n // extract the initial selected values from the children own state\n () => getValueFromSelectedChildren(children),\n );\n\n const [validationState, setValidationState] = useControlled<HvFormStatus>(\n status,\n \"standBy\",\n );\n\n const [validationMessage] = useControlled(statusMessage, \"Required\");\n\n const elementId = useUniqueId(id);\n\n const selectionAnchor = useRef(undefined);\n\n const [allValues, selectedState, selectedCount] = useMemo(() => {\n const childValues: any[] = [];\n const childSelectedState: boolean[] = [];\n let childSelectedCounter = 0;\n\n Children.toArray(children).forEach((child: any, i: number) => {\n const childValue = child?.props?.value;\n const childIsSelected = value.indexOf(childValue) !== -1;\n\n childValues[i] = childValue;\n childSelectedState[i] = childIsSelected;\n\n if (childIsSelected) {\n childSelectedCounter += 1;\n }\n });\n\n return [childValues, childSelectedState, childSelectedCounter];\n }, [children, value]);\n\n const selectAllState = computeSelectAllState(\n value.length,\n selectedState.length,\n );\n\n const onChildChangeInterceptor = useCallback(\n (\n index: number,\n childOnChange: (\n event: React.ChangeEvent<HTMLInputElement>,\n isChecked: boolean,\n ) => void,\n event: React.ChangeEvent<HTMLInputElement>,\n isChecked: boolean,\n ) => {\n const newValue = multiSelectionEventHandler(\n event,\n index,\n selectionAnchor,\n allValues,\n selectedState,\n isChecked,\n );\n\n childOnChange?.(event, isChecked);\n\n onChange?.(event, newValue);\n\n setValue(() => {\n // This will only run if uncontrolled\n\n if (required && newValue.length === 0) {\n setValidationState(\"invalid\");\n } else {\n setValidationState(\"valid\");\n }\n\n return newValue;\n });\n },\n [\n allValues,\n onChange,\n required,\n selectedState,\n setValidationState,\n setValue,\n ],\n );\n\n const modifiedChildren = useMemo(() => {\n return Children.map(children, (child: any, i: number) => {\n const childIsSelected = selectedState[i];\n\n return cloneElement(child, {\n checked: childIsSelected,\n name: child?.props?.name || name,\n onChange: (\n event: React.ChangeEvent<HTMLInputElement>,\n isChecked: boolean,\n ) =>\n onChildChangeInterceptor(\n i,\n child?.props?.onChange,\n event,\n isChecked,\n ),\n disabled: disabled || child?.props?.disabled,\n readOnly: readOnly || child?.props?.readOnly,\n });\n });\n }, [\n children,\n disabled,\n name,\n onChildChangeInterceptor,\n readOnly,\n selectedState,\n ]);\n\n const handleSelectAll = (\n event: React.ChangeEvent<HTMLInputElement>,\n selectAllChecked: boolean,\n ) => {\n let newValue: any[];\n if (selectAllState === \"some\") {\n newValue = [];\n } else if (selectAllChecked) {\n newValue = [...allValues];\n } else {\n newValue = [];\n }\n\n onChange?.(event, newValue);\n\n setValue(() => {\n // This will only run if uncontrolled\n if (required && newValue.length === 0) {\n setValidationState(\"invalid\");\n } else {\n setValidationState(\"valid\");\n }\n\n return newValue;\n });\n };\n\n const selectAllLabelComponent =\n selectedCount === 0 ? (\n <>\n <b>{selectAllLabel}</b>\n {` (${Children.toArray(children).length})`}\n </>\n ) : (\n <>\n <b>{selectedCount}</b>\n {` ${selectAllConjunctionLabel} ${Children.toArray(children).length}`}\n </>\n );\n\n // The error message area will only be created if:\n // - an external element that provides an error message isn't identified via aria-errormessage AND\n // - both status and statusMessage properties are being controlled OR\n // - status is uncontrolled and required is true\n const canShowError =\n ariaErrorMessage == null &&\n ((status !== undefined && statusMessage !== undefined) ||\n (status === undefined && required));\n\n const errorMessageId = canShowError\n ? setId(elementId, \"error\")\n : ariaErrorMessage;\n\n return (\n <HvFormElement\n id={id}\n name={name}\n status={validationState}\n disabled={disabled}\n required={required}\n readOnly={readOnly}\n className={cx(classes.root, className)}\n >\n {label && (\n <HvLabel\n showGutter\n id={setId(elementId, \"label\")}\n label={label}\n className={classes.label}\n />\n )}\n\n {description && (\n <HvInfoMessage id={setId(elementId, \"description\")}>\n {description}\n </HvInfoMessage>\n )}\n\n <div\n ref={ref}\n role=\"group\"\n aria-label={ariaLabel}\n aria-labelledby={\n ariaLabelledBy || (label && setId(elementId, \"label\")) || undefined\n }\n aria-disabled={disabled ? true : undefined}\n aria-invalid={validationState === \"invalid\" ? true : undefined}\n aria-errormessage={\n validationState === \"invalid\" ? errorMessageId : undefined\n }\n aria-describedby={\n [description && setId(elementId, \"description\"), ariaDescribedBy]\n .join(\" \")\n .trim() || undefined\n }\n className={cx(classes.group, {\n [classes.vertical]: orientation === \"vertical\",\n [classes.horizontal]: orientation === \"horizontal\",\n [classes.invalid]: validationState === \"invalid\",\n })}\n {...others}\n >\n {showSelectAll && (\n <HvCheckBox\n checked={selectAllState === \"all\"}\n indeterminate={selectAllState === \"some\"}\n label={selectAllLabelComponent}\n disabled={disabled}\n readOnly={readOnly}\n className={classes.selectAll}\n onChange={handleSelectAll}\n />\n )}\n {modifiedChildren}\n </div>\n\n {canShowError && (\n <HvWarningText\n id={setId(elementId, \"error\")}\n disableBorder\n className={classes.error}\n >\n {validationMessage}\n </HvWarningText>\n )}\n </HvFormElement>\n );\n },\n);\n"],"names":["HvCheckBoxGro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AA,YAAA;AAAA,cACC,IAAI,MAAM,WAAW,OAAO;AAAA,cAC5B,eAAa;AAAA,cACb,WAAW,QAAQ;AAAA,cAElB,UAAA;AAAA,YAAA;AAAA,UAAA;AAAA,QACH;AAAA,MAAA;AAAA,IAEJ;AAAA,EAAA;AAGN;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CheckBoxGroup.styles.js","sources":["../../../src/CheckBoxGroup/CheckBoxGroup.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvCheckBoxGroup\", {\n root: {\n display: \"inline-block\",\n overflow: \"clip\",\n overflowClipMargin: 4,\n verticalAlign: \"top\",\n },\n label: {
|
|
1
|
+
{"version":3,"file":"CheckBoxGroup.styles.js","sources":["../../../src/CheckBoxGroup/CheckBoxGroup.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvCheckBoxGroup\", {\n root: {\n display: \"inline-block\",\n overflow: \"clip\",\n overflowClipMargin: 4,\n verticalAlign: \"top\",\n },\n label: {},\n group: { display: \"flex\" },\n vertical: {\n flexDirection: \"column\",\n\n // Prevent the focus ring to be hidden by sibling hover background\n \"&>*\": {\n zIndex: 0,\n },\n \"&>*:focus-within\": {\n zIndex: 1,\n },\n },\n horizontal: {\n flexDirection: \"row\",\n flexWrap: \"wrap\",\n gap: theme.space.sm,\n },\n invalid: {\n paddingBottom: theme.space.xs,\n borderBottom: `1px solid ${theme.colors.negative_120}`,\n },\n selectAll: {},\n error: {},\n});\n"],"names":[],"mappings":";;AAGO,MAAM,EAAE,eAAe,eAAe,cAAc,mBAAmB;AAAA,EAC5E,MAAM;AAAA,IACJ,SAAS;AAAA,IACT,UAAU;AAAA,IACV,oBAAoB;AAAA,IACpB,eAAe;AAAA,EACjB;AAAA,EACA,OAAO,CAAC;AAAA,EACR,OAAO,EAAE,SAAS,OAAO;AAAA,EACzB,UAAU;AAAA,IACR,eAAe;AAAA;AAAA,IAGf,OAAO;AAAA,MACL,QAAQ;AAAA,IACV;AAAA,IACA,oBAAoB;AAAA,MAClB,QAAQ;AAAA,IAAA;AAAA,EAEZ;AAAA,EACA,YAAY;AAAA,IACV,eAAe;AAAA,IACf,UAAU;AAAA,IACV,KAAK,MAAM,MAAM;AAAA,EACnB;AAAA,EACA,SAAS;AAAA,IACP,eAAe,MAAM,MAAM;AAAA,IAC3B,cAAc,aAAa,MAAM,OAAO,YAAY;AAAA,EACtD;AAAA,EACA,WAAW,CAAC;AAAA,EACZ,OAAO,CAAA;AACT,CAAC;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { ColorPicker } from "@hitachivantara/uikit-react-icons";
|
|
4
4
|
import { useDefaultProps } from "@hitachivantara/uikit-react-utils";
|
|
5
5
|
import { useControlled } from "../hooks/useControlled.js";
|
|
6
6
|
import { useLabels } from "../hooks/useLabels.js";
|
|
@@ -70,7 +70,7 @@ const HvColorPicker = forwardRef(
|
|
|
70
70
|
deleteSavedColorButtonArialLabel = "Delete saved color",
|
|
71
71
|
addSavedColorButtonAriaLabel = "Add current color to saved colors"
|
|
72
72
|
} = useDefaultProps("HvColorPicker", props);
|
|
73
|
-
const { classes,
|
|
73
|
+
const { classes, cx } = useClasses(classesProp);
|
|
74
74
|
const labels = useLabels(DEFAULT_LABELS, labelsProp);
|
|
75
75
|
const [isOpen, setIsOpen] = useControlled(expanded, defaultExpanded);
|
|
76
76
|
const [color, setColor] = useControlled(value, defaultValue);
|
|
@@ -129,6 +129,7 @@ const HvColorPicker = forwardRef(
|
|
|
129
129
|
hasLabel && /* @__PURE__ */ jsx(
|
|
130
130
|
HvLabel,
|
|
131
131
|
{
|
|
132
|
+
showGutter: true,
|
|
132
133
|
id: setId(elementId, "label"),
|
|
133
134
|
label,
|
|
134
135
|
className: classes.label
|
|
@@ -153,22 +154,24 @@ const HvColorPicker = forwardRef(
|
|
|
153
154
|
onToggle: handleToggle,
|
|
154
155
|
onContainerCreation: setFocusToContent,
|
|
155
156
|
classes: {
|
|
156
|
-
root: cx({ [classes.dropdownRootIconOnly]: iconOnly })
|
|
157
|
-
selection: cx(iconOnly && css({ padding: 0 }))
|
|
157
|
+
root: cx({ [classes.dropdownRootIconOnly]: iconOnly })
|
|
158
158
|
},
|
|
159
159
|
adornment: iconOnly && color ? /* @__PURE__ */ jsx(
|
|
160
|
-
|
|
160
|
+
"div",
|
|
161
161
|
{
|
|
162
|
-
|
|
163
|
-
|
|
162
|
+
style: { backgroundColor: color },
|
|
163
|
+
className: cx(
|
|
164
|
+
classes.headerColorIcon,
|
|
165
|
+
classes.headerColorIconOnly
|
|
166
|
+
)
|
|
164
167
|
}
|
|
165
168
|
) : dropdownIcon === "colorPicker" ? /* @__PURE__ */ jsx(ColorPicker, { className: classes.colorPickerIcon }) : void 0,
|
|
166
169
|
placeholder: iconOnly ? void 0 : color ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
167
170
|
/* @__PURE__ */ jsx(
|
|
168
|
-
|
|
171
|
+
"div",
|
|
169
172
|
{
|
|
170
|
-
|
|
171
|
-
|
|
173
|
+
style: { backgroundColor: color },
|
|
174
|
+
className: classes.headerColorIcon
|
|
172
175
|
}
|
|
173
176
|
),
|
|
174
177
|
/* @__PURE__ */ jsx(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColorPicker.js","sources":["../../../src/ColorPicker/ColorPicker.tsx"],"sourcesContent":["import { forwardRef } from \"react\";\nimport { ColorState } from \"react-color\";\nimport { Checkbox, ColorPicker } from \"@hitachivantara/uikit-react-icons\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvBaseDropdown } from \"../BaseDropdown\";\nimport { HvDropdownProps } from \"../Dropdown\";\nimport { HvFormElement, HvInfoMessage, HvLabel } from \"../FormElement\";\nimport { useControlled } from \"../hooks/useControlled\";\nimport { useLabels } from \"../hooks/useLabels\";\nimport { useUniqueId } from \"../hooks/useUniqueId\";\nimport { HvPanel } from \"../Panel\";\nimport { HvTypography } from \"../Typography\";\nimport { setId } from \"../utils/setId\";\nimport { staticClasses, useClasses } from \"./ColorPicker.styles\";\nimport { Picker } from \"./Picker\";\nimport { PresetColors } from \"./PresetColors\";\nimport { SavedColors } from \"./SavedColors\";\n\nexport { staticClasses as colorPickerClasses };\n\nexport type HvColorPickerClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvColorPickerProps {\n \"aria-label\"?: string;\n \"aria-labelledby\"?: string;\n \"aria-describedby\"?: string;\n /** Class names to be applied. */\n className?: string;\n /** Id to be applied to the form element root node. */\n id?: string;\n /** The form element name. */\n name?: string;\n /**\n * The label of the form element.\n *\n * The form element must be labeled for accessibility reasons.\n * If not provided, an aria-label or aria-labelledby must be provided instead.\n */\n label?: React.ReactNode;\n /** Provide additional descriptive text for the form element. */\n description?: React.ReactNode;\n /** Indicates that user input is required on the form element. */\n required?: boolean;\n /** The value color, in HEX format. */\n value?: string;\n /** The default value color, in HEX format. */\n defaultValue?: string;\n /** If `true` the dropdown is disabled unable to be interacted, if `false` it is enabled. */\n disabled?: boolean;\n /** If `true` the dropdown starts opened if `false` it starts closed. */\n expanded?: boolean;\n /** When uncontrolled, defines the initial expanded state. */\n defaultExpanded?: boolean;\n /** A function to be executed whenever the color changes. */\n onChange?: (color: string) => void;\n /** A function to be executed whenever the color change is complete. */\n onChangeComplete?: (color: string) => void;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvColorPickerClasses;\n /** The placeholder value when nothing is selected. */\n placeholder?: string;\n /** Recommended colors. The colors are HEX values. */\n recommendedColors?: string[];\n /** Recommended colors position. */\n recommendedColorsPosition?: \"top\" | \"bottom\";\n /** If `true`, the labels are shown. If `false`, they are not shown. */\n showLabels?: boolean;\n /** An object containing all the labels. */\n labels?: Partial<typeof DEFAULT_LABELS>;\n /** Icon type for the input's end adornment. */\n dropdownIcon?: \"arrow\" | \"colorPicker\";\n /** If `true`, the input only shows an icon. If `false`, the input shows text and icons. */\n iconOnly?: boolean;\n /** If `true`, the saved colors area is shown. If `false`, it is not shown. */\n showSavedColors?: boolean;\n /** If `true`, the custom colors area is shown. If `false`, it is not shown. */\n showCustomColors?: boolean;\n /** The saved colors. The colors are HEX values. */\n savedColorsValue?: string[];\n /** The default saved colors. The colors are HEX values. */\n defaultSavedColorsValue?: string[];\n /** Callback fired when a new saved color is added. */\n onSavedColorAdded?: (color?: string) => void;\n /** Callback fired when a new saved color is removed. */\n onSavedColorRemoved?: (color?: string) => void;\n /** Aria label to apply to delete saved color button. */\n deleteSavedColorButtonArialLabel?: string; // TODO: fix typo \"ArialLabel\" in next version\n /** Aria label to apply to add saved color button. */\n addSavedColorButtonAriaLabel?: string;\n}\n\nconst DEFAULT_LABELS = {\n recommendedColorsLabel: \"Recommended colors:\",\n customColorsLabel: \"Custom colors:\",\n};\n\n/**\n * A color picker component which allows the user to select a color from a list of pre-defined colors or freely select one color via the Hue and Saturation.\n * It receives a color string in HEX format and outputs an HEX formatted color.\n */\nexport const HvColorPicker = forwardRef<HTMLDivElement, HvColorPickerProps>(\n function HvColorPicker(props, ref) {\n const {\n id,\n name,\n required,\n disabled,\n label,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n description,\n \"aria-describedby\": ariaDescribedBy,\n className,\n classes: classesProp,\n value,\n onChange,\n onChangeComplete,\n defaultValue = \"\",\n expanded,\n defaultExpanded = false,\n recommendedColorsPosition = \"top\",\n recommendedColors = [\n \"#95AFE8\",\n \"#E89E5D\",\n \"#83B8A6\",\n \"#70759C\",\n \"#C57E7E\",\n \"#FADA95\",\n \"#ADBFE8\",\n \"#E3B386\",\n \"#9AC6B7\",\n \"#8B90AF\",\n \"#CF9797\",\n \"#FAE1AA\",\n ],\n showLabels = true,\n labels: labelsProp,\n dropdownIcon = \"colorPicker\",\n placeholder = \"Select color...\",\n iconOnly = false,\n showSavedColors = true,\n showCustomColors = true,\n savedColorsValue,\n defaultSavedColorsValue = [],\n onSavedColorAdded,\n onSavedColorRemoved,\n deleteSavedColorButtonArialLabel = \"Delete saved color\",\n addSavedColorButtonAriaLabel = \"Add current color to saved colors\",\n } = useDefaultProps(\"HvColorPicker\", props);\n\n const { classes, css, cx } = useClasses(classesProp);\n\n const labels = useLabels(DEFAULT_LABELS, labelsProp);\n\n const [isOpen, setIsOpen] = useControlled(expanded, defaultExpanded);\n const [color, setColor] = useControlled(value, defaultValue);\n const [savedColors, setSavedColors] = useControlled(\n savedColorsValue,\n defaultSavedColorsValue,\n );\n const elementId = useUniqueId(id);\n const hasLabel = label != null;\n const hasDescription = description != null;\n\n const handleToggle: HvDropdownProps[\"onToggle\"] = (_, open) => {\n setIsOpen(open);\n };\n\n const handleSelect = (\n val: ColorState | { hex: string; source: string },\n ) => {\n onChange?.(val.hex);\n onChangeComplete?.(val.hex);\n setColor(val.hex);\n };\n\n const handleOnChange = (\n val: ColorState | { hex: string; source: string },\n ) => {\n onChange?.(val.hex);\n setColor(val.hex);\n };\n\n const handleOnChangeComplete = (\n val: ColorState | { hex: string; source: string },\n ) => {\n onChangeComplete?.(val.hex);\n setColor(val.hex);\n };\n\n const handleAddColor = () => {\n // When no color is provided, react-color sets the picker to #000000.\n // This is the color that should be added in this case.\n const colorToAdd = color || \"#000000\";\n\n onSavedColorAdded?.(colorToAdd);\n setSavedColors([...savedColors, colorToAdd]);\n };\n\n const handleRemoveColor = (val: string, position: number) => {\n if (savedColors[position] === val) {\n const sColors = [...savedColors];\n sColors.splice(position, 1);\n onSavedColorRemoved?.(val);\n setSavedColors(sColors);\n }\n };\n\n const setFocusToContent = (containerRef: HTMLElement | null) => {\n const inputs = containerRef?.getElementsByTagName(\"input\");\n if (inputs && inputs.length > 0) {\n inputs[0].focus();\n }\n };\n\n return (\n <HvFormElement\n id={id}\n name={name}\n disabled={disabled}\n required={required}\n className={cx(classes.root, className)}\n >\n {(hasLabel || hasDescription) && (\n <div className={classes.labelContainer}>\n {hasLabel && (\n <HvLabel\n id={setId(elementId, \"label\")}\n label={label}\n className={classes.label}\n />\n )}\n\n {hasDescription && (\n <HvInfoMessage\n id={setId(elementId, \"description\")}\n className={classes.description}\n >\n {description}\n </HvInfoMessage>\n )}\n </div>\n )}\n <HvBaseDropdown\n ref={ref}\n variableWidth\n className={className}\n expanded={isOpen}\n onToggle={handleToggle}\n onContainerCreation={setFocusToContent}\n classes={{\n root: cx({ [classes.dropdownRootIconOnly]: iconOnly }),\n selection: cx(iconOnly && css({ padding: 0 })),\n }}\n adornment={\n iconOnly && color ? (\n <Checkbox\n className={classes.headerColorIconOnly}\n color={[color, \"transparent\"]}\n />\n ) : dropdownIcon === \"colorPicker\" ? (\n <ColorPicker className={classes.colorPickerIcon} />\n ) : undefined\n }\n placeholder={\n iconOnly ? undefined : color ? (\n <>\n <Checkbox\n className={classes.headerColorIcon}\n color={[color, \"transparent\"]}\n />\n <HvTypography\n className={classes.headerColorValue}\n variant=\"label\"\n >\n {color}\n </HvTypography>\n </>\n ) : (\n placeholder\n )\n }\n aria-label={ariaLabel}\n aria-labelledby={\n [label && setId(elementId, \"label\"), ariaLabelledBy]\n .join(\" \")\n .trim() || undefined\n }\n aria-describedby={\n [description && setId(elementId, \"description\"), ariaDescribedBy]\n .join(\" \")\n .trim() || undefined\n }\n >\n <HvPanel className={classes.panel}>\n <div className={classes.colorPicker}>\n {recommendedColorsPosition === \"top\" && (\n <PresetColors\n className={classes.recommendedColorsRoot}\n colors={recommendedColors}\n onClick={handleSelect}\n title={showLabels ? labels.recommendedColorsLabel : undefined}\n />\n )}\n {showCustomColors && (\n <Picker\n classes={{\n fields: cx({\n [classes.pickerFields]:\n recommendedColorsPosition === \"bottom\" ||\n showSavedColors,\n }),\n }}\n title={showLabels ? labels.customColorsLabel : undefined}\n color={color}\n onChange={handleOnChange}\n onChangeComplete={handleOnChangeComplete}\n />\n )}\n {showSavedColors && (\n <SavedColors\n colors={savedColors}\n onAddColor={handleAddColor}\n onClickColor={handleSelect}\n onRemoveColor={handleRemoveColor}\n deleteButtonAriaLabel={deleteSavedColorButtonArialLabel}\n addButtonAriaLabel={addSavedColorButtonAriaLabel}\n />\n )}\n {recommendedColorsPosition === \"bottom\" && (\n <PresetColors\n colors={recommendedColors}\n onClick={handleSelect}\n title={showLabels ? labels.recommendedColorsLabel : undefined}\n />\n )}\n </div>\n </HvPanel>\n </HvBaseDropdown>\n </HvFormElement>\n );\n },\n);\n"],"names":["HvColorPicker"],"mappings":";;;;;;;;;;;;;;;;;;;AA+FA,MAAM,iBAAiB;AAAA,EACrB,wBAAwB;AAAA,EACxB,mBAAmB;AACrB;AAMO,MAAM,gBAAgB;AAAA,EAC3B,SAASA,eAAc,OAAO,KAAK;AAC3B,UAAA;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,cAAc;AAAA,MACd,mBAAmB;AAAA,MACnB;AAAA,MACA,oBAAoB;AAAA,MACpB;AAAA,MACA,SAAS;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,MACA,eAAe;AAAA,MACf;AAAA,MACA,kBAAkB;AAAA,MAClB,4BAA4B;AAAA,MAC5B,oBAAoB;AAAA,QAClB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACA,aAAa;AAAA,MACb,QAAQ;AAAA,MACR,eAAe;AAAA,MACf,cAAc;AAAA,MACd,WAAW;AAAA,MACX,kBAAkB;AAAA,MAClB,mBAAmB;AAAA,MACnB;AAAA,MACA,0BAA0B,CAAC;AAAA,MAC3B;AA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kBAAA;AAAA,oBACC,QAAQ;AAAA,oBACR,SAAS;AAAA,oBACT,OAAO,aAAa,OAAO,yBAAyB;AAAA,kBAAA;AAAA,gBAAA;AAAA,cACtD,EAAA,CAEJ,EACF,CAAA;AAAA,YAAA;AAAA,UAAA;AAAA,QACF;AAAA,MAAA;AAAA,IACF;AAAA,EAAA;AAGN;"}
|
|
1
|
+
{"version":3,"file":"ColorPicker.js","sources":["../../../src/ColorPicker/ColorPicker.tsx"],"sourcesContent":["import { forwardRef } from \"react\";\nimport { ColorState } from \"react-color\";\nimport { ColorPicker } from \"@hitachivantara/uikit-react-icons\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvBaseDropdown } from \"../BaseDropdown\";\nimport { HvDropdownProps } from \"../Dropdown\";\nimport { HvFormElement, HvInfoMessage, HvLabel } from \"../FormElement\";\nimport { useControlled } from \"../hooks/useControlled\";\nimport { useLabels } from \"../hooks/useLabels\";\nimport { useUniqueId } from \"../hooks/useUniqueId\";\nimport { HvPanel } from \"../Panel\";\nimport { HvTypography } from \"../Typography\";\nimport { setId } from \"../utils/setId\";\nimport { staticClasses, useClasses } from \"./ColorPicker.styles\";\nimport { Picker } from \"./Picker\";\nimport { PresetColors } from \"./PresetColors\";\nimport { SavedColors } from \"./SavedColors\";\n\nexport { staticClasses as colorPickerClasses };\n\nexport type HvColorPickerClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvColorPickerProps {\n \"aria-label\"?: string;\n \"aria-labelledby\"?: string;\n \"aria-describedby\"?: string;\n /** Class names to be applied. */\n className?: string;\n /** Id to be applied to the form element root node. */\n id?: string;\n /** The form element name. */\n name?: string;\n /**\n * The label of the form element.\n *\n * The form element must be labeled for accessibility reasons.\n * If not provided, an aria-label or aria-labelledby must be provided instead.\n */\n label?: React.ReactNode;\n /** Provide additional descriptive text for the form element. */\n description?: React.ReactNode;\n /** Indicates that user input is required on the form element. */\n required?: boolean;\n /** The value color, in HEX format. */\n value?: string;\n /** The default value color, in HEX format. */\n defaultValue?: string;\n /** If `true` the dropdown is disabled unable to be interacted, if `false` it is enabled. */\n disabled?: boolean;\n /** If `true` the dropdown starts opened if `false` it starts closed. */\n expanded?: boolean;\n /** When uncontrolled, defines the initial expanded state. */\n defaultExpanded?: boolean;\n /** A function to be executed whenever the color changes. */\n onChange?: (color: string) => void;\n /** A function to be executed whenever the color change is complete. */\n onChangeComplete?: (color: string) => void;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvColorPickerClasses;\n /** The placeholder value when nothing is selected. */\n placeholder?: string;\n /** Recommended colors. The colors are HEX values. */\n recommendedColors?: string[];\n /** Recommended colors position. */\n recommendedColorsPosition?: \"top\" | \"bottom\";\n /** If `true`, the labels are shown. If `false`, they are not shown. */\n showLabels?: boolean;\n /** An object containing all the labels. */\n labels?: Partial<typeof DEFAULT_LABELS>;\n /** Icon type for the input's end adornment. */\n dropdownIcon?: \"arrow\" | \"colorPicker\";\n /** If `true`, the input only shows an icon. If `false`, the input shows text and icons. */\n iconOnly?: boolean;\n /** If `true`, the saved colors area is shown. If `false`, it is not shown. */\n showSavedColors?: boolean;\n /** If `true`, the custom colors area is shown. If `false`, it is not shown. */\n showCustomColors?: boolean;\n /** The saved colors. The colors are HEX values. */\n savedColorsValue?: string[];\n /** The default saved colors. The colors are HEX values. */\n defaultSavedColorsValue?: string[];\n /** Callback fired when a new saved color is added. */\n onSavedColorAdded?: (color?: string) => void;\n /** Callback fired when a new saved color is removed. */\n onSavedColorRemoved?: (color?: string) => void;\n /** Aria label to apply to delete saved color button. */\n deleteSavedColorButtonArialLabel?: string; // TODO: fix typo \"ArialLabel\" in next version\n /** Aria label to apply to add saved color button. */\n addSavedColorButtonAriaLabel?: string;\n}\n\nconst DEFAULT_LABELS = {\n recommendedColorsLabel: \"Recommended colors:\",\n customColorsLabel: \"Custom colors:\",\n};\n\n/**\n * A color picker component which allows the user to select a color from a list of pre-defined colors or freely select one color via the Hue and Saturation.\n * It receives a color string in HEX format and outputs an HEX formatted color.\n */\nexport const HvColorPicker = forwardRef<HTMLDivElement, HvColorPickerProps>(\n function HvColorPicker(props, ref) {\n const {\n id,\n name,\n required,\n disabled,\n label,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n description,\n \"aria-describedby\": ariaDescribedBy,\n className,\n classes: classesProp,\n value,\n onChange,\n onChangeComplete,\n defaultValue = \"\",\n expanded,\n defaultExpanded = false,\n recommendedColorsPosition = \"top\",\n recommendedColors = [\n \"#95AFE8\",\n \"#E89E5D\",\n \"#83B8A6\",\n \"#70759C\",\n \"#C57E7E\",\n \"#FADA95\",\n \"#ADBFE8\",\n \"#E3B386\",\n \"#9AC6B7\",\n \"#8B90AF\",\n \"#CF9797\",\n \"#FAE1AA\",\n ],\n showLabels = true,\n labels: labelsProp,\n dropdownIcon = \"colorPicker\",\n placeholder = \"Select color...\",\n iconOnly = false,\n showSavedColors = true,\n showCustomColors = true,\n savedColorsValue,\n defaultSavedColorsValue = [],\n onSavedColorAdded,\n onSavedColorRemoved,\n deleteSavedColorButtonArialLabel = \"Delete saved color\",\n addSavedColorButtonAriaLabel = \"Add current color to saved colors\",\n } = useDefaultProps(\"HvColorPicker\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const labels = useLabels(DEFAULT_LABELS, labelsProp);\n\n const [isOpen, setIsOpen] = useControlled(expanded, defaultExpanded);\n const [color, setColor] = useControlled(value, defaultValue);\n const [savedColors, setSavedColors] = useControlled(\n savedColorsValue,\n defaultSavedColorsValue,\n );\n const elementId = useUniqueId(id);\n const hasLabel = label != null;\n const hasDescription = description != null;\n\n const handleToggle: HvDropdownProps[\"onToggle\"] = (_, open) => {\n setIsOpen(open);\n };\n\n const handleSelect = (\n val: ColorState | { hex: string; source: string },\n ) => {\n onChange?.(val.hex);\n onChangeComplete?.(val.hex);\n setColor(val.hex);\n };\n\n const handleOnChange = (\n val: ColorState | { hex: string; source: string },\n ) => {\n onChange?.(val.hex);\n setColor(val.hex);\n };\n\n const handleOnChangeComplete = (\n val: ColorState | { hex: string; source: string },\n ) => {\n onChangeComplete?.(val.hex);\n setColor(val.hex);\n };\n\n const handleAddColor = () => {\n // When no color is provided, react-color sets the picker to #000000.\n // This is the color that should be added in this case.\n const colorToAdd = color || \"#000000\";\n\n onSavedColorAdded?.(colorToAdd);\n setSavedColors([...savedColors, colorToAdd]);\n };\n\n const handleRemoveColor = (val: string, position: number) => {\n if (savedColors[position] === val) {\n const sColors = [...savedColors];\n sColors.splice(position, 1);\n onSavedColorRemoved?.(val);\n setSavedColors(sColors);\n }\n };\n\n const setFocusToContent = (containerRef: HTMLElement | null) => {\n const inputs = containerRef?.getElementsByTagName(\"input\");\n if (inputs && inputs.length > 0) {\n inputs[0].focus();\n }\n };\n\n return (\n <HvFormElement\n id={id}\n name={name}\n disabled={disabled}\n required={required}\n className={cx(classes.root, className)}\n >\n {(hasLabel || hasDescription) && (\n <div className={classes.labelContainer}>\n {hasLabel && (\n <HvLabel\n showGutter\n id={setId(elementId, \"label\")}\n label={label}\n className={classes.label}\n />\n )}\n\n {hasDescription && (\n <HvInfoMessage\n id={setId(elementId, \"description\")}\n className={classes.description}\n >\n {description}\n </HvInfoMessage>\n )}\n </div>\n )}\n <HvBaseDropdown\n ref={ref}\n variableWidth\n className={className}\n expanded={isOpen}\n onToggle={handleToggle}\n onContainerCreation={setFocusToContent}\n classes={{\n root: cx({ [classes.dropdownRootIconOnly]: iconOnly }),\n }}\n adornment={\n iconOnly && color ? (\n <div\n style={{ backgroundColor: color }}\n className={cx(\n classes.headerColorIcon,\n classes.headerColorIconOnly,\n )}\n />\n ) : dropdownIcon === \"colorPicker\" ? (\n <ColorPicker className={classes.colorPickerIcon} />\n ) : undefined\n }\n placeholder={\n iconOnly ? undefined : color ? (\n <>\n <div\n style={{ backgroundColor: color }}\n className={classes.headerColorIcon}\n />\n <HvTypography\n className={classes.headerColorValue}\n variant=\"label\"\n >\n {color}\n </HvTypography>\n </>\n ) : (\n placeholder\n )\n }\n aria-label={ariaLabel}\n aria-labelledby={\n [label && setId(elementId, \"label\"), ariaLabelledBy]\n .join(\" \")\n .trim() || undefined\n }\n aria-describedby={\n [description && setId(elementId, \"description\"), ariaDescribedBy]\n .join(\" \")\n .trim() || undefined\n }\n >\n <HvPanel className={classes.panel}>\n <div className={classes.colorPicker}>\n {recommendedColorsPosition === \"top\" && (\n <PresetColors\n className={classes.recommendedColorsRoot}\n colors={recommendedColors}\n onClick={handleSelect}\n title={showLabels ? labels.recommendedColorsLabel : undefined}\n />\n )}\n {showCustomColors && (\n <Picker\n classes={{\n fields: cx({\n [classes.pickerFields]:\n recommendedColorsPosition === \"bottom\" ||\n showSavedColors,\n }),\n }}\n title={showLabels ? labels.customColorsLabel : undefined}\n color={color}\n onChange={handleOnChange}\n onChangeComplete={handleOnChangeComplete}\n />\n )}\n {showSavedColors && (\n <SavedColors\n colors={savedColors}\n onAddColor={handleAddColor}\n onClickColor={handleSelect}\n onRemoveColor={handleRemoveColor}\n deleteButtonAriaLabel={deleteSavedColorButtonArialLabel}\n addButtonAriaLabel={addSavedColorButtonAriaLabel}\n />\n )}\n {recommendedColorsPosition === \"bottom\" && (\n <PresetColors\n colors={recommendedColors}\n onClick={handleSelect}\n title={showLabels ? labels.recommendedColorsLabel : undefined}\n />\n )}\n </div>\n </HvPanel>\n </HvBaseDropdown>\n </HvFormElement>\n );\n },\n);\n"],"names":["HvColorPicker"],"mappings":";;;;;;;;;;;;;;;;;;;AA+FA,MAAM,iBAAiB;AAAA,EACrB,wBAAwB;AAAA,EACxB,mBAAmB;AACrB;AAMO,MAAM,gBAAgB;AAAA,EAC3B,SAASA,eAAc,OAAO,KAAK;AAC3B,UAAA;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,cAAc;AAAA,MACd,mBAAmB;AAAA,MACnB;AAAA,MACA,oBAAoB;AAAA,MACpB;AAAA,MACA,SAAS;AAAA,MACT;AAAA,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,QAAQ,YAAY,GACnB,8BAA8B,YAC9B;AAAA,sBACH,CAAA;AAAA,oBACH;AAAA,oBACA,OAAO,aAAa,OAAO,oBAAoB;AAAA,oBAC/C;AAAA,oBACA,UAAU;AAAA,oBACV,kBAAkB;AAAA,kBAAA;AAAA,gBACpB;AAAA,gBAED,mBACC;AAAA,kBAAC;AAAA,kBAAA;AAAA,oBACC,QAAQ;AAAA,oBACR,YAAY;AAAA,oBACZ,cAAc;AAAA,oBACd,eAAe;AAAA,oBACf,uBAAuB;AAAA,oBACvB,oBAAoB;AAAA,kBAAA;AAAA,gBACtB;AAAA,gBAED,8BAA8B,YAC7B;AAAA,kBAAC;AAAA,kBAAA;AAAA,oBACC,QAAQ;AAAA,oBACR,SAAS;AAAA,oBACT,OAAO,aAAa,OAAO,yBAAyB;AAAA,kBAAA;AAAA,gBAAA;AAAA,cACtD,EAAA,CAEJ,EACF,CAAA;AAAA,YAAA;AAAA,UAAA;AAAA,QACF;AAAA,MAAA;AAAA,IACF;AAAA,EAAA;AAGN;"}
|
|
@@ -5,20 +5,18 @@ const { staticClasses, useClasses } = createClasses("HvColorPicker", {
|
|
|
5
5
|
display: "flex",
|
|
6
6
|
alignItems: "flex-start"
|
|
7
7
|
},
|
|
8
|
-
label: {
|
|
9
|
-
paddingBottom: "6px",
|
|
10
|
-
display: "block",
|
|
11
|
-
cursor: "pointer"
|
|
12
|
-
},
|
|
8
|
+
label: {},
|
|
13
9
|
description: {},
|
|
14
10
|
headerColorValue: {
|
|
15
|
-
textTransform: "uppercase"
|
|
11
|
+
textTransform: "uppercase",
|
|
12
|
+
minWidth: "8ch",
|
|
13
|
+
fontVariant: "tabular-nums"
|
|
16
14
|
},
|
|
17
15
|
headerColorIcon: {
|
|
18
|
-
width:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
width: 16,
|
|
17
|
+
height: 16,
|
|
18
|
+
marginRight: 8,
|
|
19
|
+
flexShrink: 0
|
|
22
20
|
},
|
|
23
21
|
panel: {
|
|
24
22
|
width: "100%",
|
|
@@ -39,9 +37,14 @@ const { staticClasses, useClasses } = createClasses("HvColorPicker", {
|
|
|
39
37
|
},
|
|
40
38
|
dropdownRootIconOnly: {
|
|
41
39
|
width: 32,
|
|
42
|
-
height: 32
|
|
40
|
+
height: 32,
|
|
41
|
+
"& .HvBaseDropdown-selection": {
|
|
42
|
+
padding: 0
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
headerColorIconOnly: {
|
|
46
|
+
margin: 8
|
|
43
47
|
},
|
|
44
|
-
headerColorIconOnly: {},
|
|
45
48
|
pickerFields: { paddingBottom: 20 }
|
|
46
49
|
});
|
|
47
50
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColorPicker.styles.js","sources":["../../../src/ColorPicker/ColorPicker.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvColorPicker\", {\n root: {},\n labelContainer: {\n display: \"flex\",\n alignItems: \"flex-start\",\n },\n label: {
|
|
1
|
+
{"version":3,"file":"ColorPicker.styles.js","sources":["../../../src/ColorPicker/ColorPicker.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvColorPicker\", {\n root: {},\n labelContainer: {\n display: \"flex\",\n alignItems: \"flex-start\",\n },\n label: {},\n description: {},\n headerColorValue: {\n textTransform: \"uppercase\",\n minWidth: \"8ch\",\n fontVariant: \"tabular-nums\",\n },\n headerColorIcon: {\n width: 16,\n height: 16,\n marginRight: 8,\n flexShrink: 0,\n },\n panel: {\n width: \"100%\",\n minWidth: \"266px\",\n display: \"flex\",\n justifyContent: \"center\",\n padding: \"16px\",\n backgroundColor: \"transparent\",\n },\n colorPicker: {\n width: \"232px\",\n },\n colorPickerIcon: {},\n recommendedColorsRoot: {\n \":not(:only-child)\": {\n paddingBottom: \"24px\",\n },\n },\n dropdownRootIconOnly: {\n width: 32,\n height: 32,\n \"& .HvBaseDropdown-selection\": {\n padding: 0,\n },\n },\n headerColorIconOnly: {\n margin: 8,\n },\n pickerFields: { paddingBottom: 20 },\n});\n"],"names":[],"mappings":";AAEO,MAAM,EAAE,eAAe,eAAe,cAAc,iBAAiB;AAAA,EAC1E,MAAM,CAAC;AAAA,EACP,gBAAgB;AAAA,IACd,SAAS;AAAA,IACT,YAAY;AAAA,EACd;AAAA,EACA,OAAO,CAAC;AAAA,EACR,aAAa,CAAC;AAAA,EACd,kBAAkB;AAAA,IAChB,eAAe;AAAA,IACf,UAAU;AAAA,IACV,aAAa;AAAA,EACf;AAAA,EACA,iBAAiB;AAAA,IACf,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,aAAa;AAAA,IACb,YAAY;AAAA,EACd;AAAA,EACA,OAAO;AAAA,IACL,OAAO;AAAA,IACP,UAAU;AAAA,IACV,SAAS;AAAA,IACT,gBAAgB;AAAA,IAChB,SAAS;AAAA,IACT,iBAAiB;AAAA,EACnB;AAAA,EACA,aAAa;AAAA,IACX,OAAO;AAAA,EACT;AAAA,EACA,iBAAiB,CAAC;AAAA,EAClB,uBAAuB;AAAA,IACrB,qBAAqB;AAAA,MACnB,eAAe;AAAA,IAAA;AAAA,EAEnB;AAAA,EACA,sBAAsB;AAAA,IACpB,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,+BAA+B;AAAA,MAC7B,SAAS;AAAA,IAAA;AAAA,EAEb;AAAA,EACA,qBAAqB;AAAA,IACnB,QAAQ;AAAA,EACV;AAAA,EACA,cAAc,EAAE,eAAe,GAAG;AACpC,CAAC;"}
|
|
@@ -95,9 +95,10 @@ const Fields = (props) => {
|
|
|
95
95
|
ref: redInputRef,
|
|
96
96
|
className: classes.single,
|
|
97
97
|
label: "R",
|
|
98
|
-
value:
|
|
98
|
+
value: internalRed,
|
|
99
99
|
onChange: (event, value) => onChangeRbg(event, value, "r"),
|
|
100
100
|
onBlur: () => setInternalRed(rgb?.r),
|
|
101
|
+
inputProps: { type: "number", min: 0, max: 255 },
|
|
101
102
|
disableClear: true
|
|
102
103
|
}
|
|
103
104
|
),
|
|
@@ -107,9 +108,10 @@ const Fields = (props) => {
|
|
|
107
108
|
ref: greenInputRef,
|
|
108
109
|
className: classes.single,
|
|
109
110
|
label: "G",
|
|
110
|
-
value:
|
|
111
|
+
value: internalGreen,
|
|
111
112
|
onChange: (event, value) => onChangeRbg(event, value, "g"),
|
|
112
113
|
onBlur: () => setInternalGreen(rgb?.g),
|
|
114
|
+
inputProps: { type: "number", min: 0, max: 255 },
|
|
113
115
|
disableClear: true
|
|
114
116
|
}
|
|
115
117
|
),
|
|
@@ -119,9 +121,10 @@ const Fields = (props) => {
|
|
|
119
121
|
ref: blueInputRef,
|
|
120
122
|
className: classes.single,
|
|
121
123
|
label: "B",
|
|
122
|
-
value:
|
|
124
|
+
value: internalBlue,
|
|
123
125
|
onChange: (event, value) => onChangeRbg(event, value, "b"),
|
|
124
126
|
onBlur: () => setInternalBlue(rgb?.b),
|
|
127
|
+
inputProps: { type: "number", min: 0, max: 255 },
|
|
125
128
|
disableClear: true
|
|
126
129
|
}
|
|
127
130
|
)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Fields.js","sources":["../../../../src/ColorPicker/Fields/Fields.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport { HSLColor, HSVColor, RGBColor } from \"react-color\";\n// @ts-ignore\nimport * as color from \"react-color/lib/helpers/color\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvInput } from \"../../Input\";\nimport { staticClasses, useClasses } from \"./Fields.styles\";\n\nexport { staticClasses as colorPickerFieldsClasses };\n\nexport type HvColorPickerFieldsClasses = ExtractNames<typeof useClasses>;\n\ninterface FieldsProps {\n className?: string;\n rgb?: RGBColor;\n hex?: string;\n onChange: (\n data:\n | HSLColor\n | HSVColor\n | RGBColor\n | {\n source?: string;\n hex?: string;\n },\n event: React.ChangeEvent<HTMLInputElement>,\n ) => void;\n classes?: HvColorPickerFieldsClasses;\n}\n\nexport const Fields = (props: FieldsProps) => {\n const {\n className,\n onChange,\n rgb,\n hex,\n classes: classesProp,\n } = useDefaultProps(\"HvColorPickerFields\", props);\n const { classes, cx } = useClasses(classesProp);\n const [internalHex, setInternalHex] = useState(hex);\n const [internalRed, setInternalRed] = useState(rgb?.r);\n const [internalGreen, setInternalGreen] = useState(rgb?.g);\n const [internalBlue, setInternalBlue] = useState(rgb?.b);\n\n const hexInputRef = useRef<HTMLInputElement>(null);\n const redInputRef = useRef<HTMLInputElement>(null);\n const greenInputRef = useRef<HTMLInputElement>(null);\n const blueInputRef = useRef<HTMLInputElement>(null);\n\n useEffect(() => {\n if (document.activeElement !== hexInputRef.current) {\n setInternalHex(hex);\n }\n }, [hex]);\n\n useEffect(() => {\n if (document.activeElement !== redInputRef.current) {\n setInternalRed(rgb?.r);\n }\n\n if (document.activeElement !== greenInputRef.current) {\n setInternalGreen(rgb?.g);\n }\n\n if (document.activeElement !== blueInputRef.current) {\n setInternalBlue(rgb?.b);\n }\n }, [rgb]);\n\n const handleChange = (\n data: {\n hex?: string;\n r?: number;\n g?: number;\n b?: number;\n },\n event: React.ChangeEvent<HTMLInputElement>,\n ) => {\n if (data.hex && color.isValidHex(data.hex)) {\n onChange(\n {\n hex: data.hex,\n source: \"hex\",\n },\n event,\n );\n } else if (\n data.r !== undefined ||\n data.g !== undefined ||\n data.b !== undefined\n ) {\n onChange(\n {\n r: data.r ?? rgb?.r,\n g: data.g ?? rgb?.g,\n b: data.b ?? rgb?.b,\n source: \"rgb\",\n },\n event,\n );\n }\n };\n\n const onChangeHex = (event: React.ChangeEvent<any>, value: string) => {\n setInternalHex(value);\n handleChange({ hex: value }, event);\n };\n\n const onChangeRbg = (\n event: React.ChangeEvent<any>,\n value: string,\n colorPart: \"r\" | \"g\" | \"b\",\n ) => {\n if (colorPart === \"r\") setInternalRed(Number(value));\n if (colorPart === \"g\") setInternalGreen(Number(value));\n if (colorPart === \"b\") setInternalBlue(Number(value));\n\n handleChange(\n {\n r: colorPart === \"r\" ? Number(value) : rgb?.r,\n g: colorPart === \"g\" ? Number(value) : rgb?.g,\n b: colorPart === \"b\" ? Number(value) : rgb?.b,\n },\n event,\n );\n };\n\n return (\n <div className={cx(classes.fields, className)}>\n <HvInput\n ref={hexInputRef}\n className={classes.double}\n label=\"HEX\"\n value={internalHex?.replace(\"#\", \"\")}\n onChange={onChangeHex}\n onBlur={() => setInternalHex(hex)}\n disableClear\n />\n <HvInput\n ref={redInputRef}\n className={classes.single}\n label=\"R\"\n value={
|
|
1
|
+
{"version":3,"file":"Fields.js","sources":["../../../../src/ColorPicker/Fields/Fields.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport { HSLColor, HSVColor, RGBColor } from \"react-color\";\n// @ts-ignore\nimport * as color from \"react-color/lib/helpers/color\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvInput } from \"../../Input\";\nimport { staticClasses, useClasses } from \"./Fields.styles\";\n\nexport { staticClasses as colorPickerFieldsClasses };\n\nexport type HvColorPickerFieldsClasses = ExtractNames<typeof useClasses>;\n\ninterface FieldsProps {\n className?: string;\n rgb?: RGBColor;\n hex?: string;\n onChange: (\n data:\n | HSLColor\n | HSVColor\n | RGBColor\n | {\n source?: string;\n hex?: string;\n },\n event: React.ChangeEvent<HTMLInputElement>,\n ) => void;\n classes?: HvColorPickerFieldsClasses;\n}\n\nexport const Fields = (props: FieldsProps) => {\n const {\n className,\n onChange,\n rgb,\n hex,\n classes: classesProp,\n } = useDefaultProps(\"HvColorPickerFields\", props);\n const { classes, cx } = useClasses(classesProp);\n const [internalHex, setInternalHex] = useState(hex);\n const [internalRed, setInternalRed] = useState(rgb?.r);\n const [internalGreen, setInternalGreen] = useState(rgb?.g);\n const [internalBlue, setInternalBlue] = useState(rgb?.b);\n\n const hexInputRef = useRef<HTMLInputElement>(null);\n const redInputRef = useRef<HTMLInputElement>(null);\n const greenInputRef = useRef<HTMLInputElement>(null);\n const blueInputRef = useRef<HTMLInputElement>(null);\n\n useEffect(() => {\n if (document.activeElement !== hexInputRef.current) {\n setInternalHex(hex);\n }\n }, [hex]);\n\n useEffect(() => {\n if (document.activeElement !== redInputRef.current) {\n setInternalRed(rgb?.r);\n }\n\n if (document.activeElement !== greenInputRef.current) {\n setInternalGreen(rgb?.g);\n }\n\n if (document.activeElement !== blueInputRef.current) {\n setInternalBlue(rgb?.b);\n }\n }, [rgb]);\n\n const handleChange = (\n data: {\n hex?: string;\n r?: number;\n g?: number;\n b?: number;\n },\n event: React.ChangeEvent<HTMLInputElement>,\n ) => {\n if (data.hex && color.isValidHex(data.hex)) {\n onChange(\n {\n hex: data.hex,\n source: \"hex\",\n },\n event,\n );\n } else if (\n data.r !== undefined ||\n data.g !== undefined ||\n data.b !== undefined\n ) {\n onChange(\n {\n r: data.r ?? rgb?.r,\n g: data.g ?? rgb?.g,\n b: data.b ?? rgb?.b,\n source: \"rgb\",\n },\n event,\n );\n }\n };\n\n const onChangeHex = (event: React.ChangeEvent<any>, value: string) => {\n setInternalHex(value);\n handleChange({ hex: value }, event);\n };\n\n const onChangeRbg = (\n event: React.ChangeEvent<any>,\n value: string,\n colorPart: \"r\" | \"g\" | \"b\",\n ) => {\n if (colorPart === \"r\") setInternalRed(Number(value));\n if (colorPart === \"g\") setInternalGreen(Number(value));\n if (colorPart === \"b\") setInternalBlue(Number(value));\n\n handleChange(\n {\n r: colorPart === \"r\" ? Number(value) : rgb?.r,\n g: colorPart === \"g\" ? Number(value) : rgb?.g,\n b: colorPart === \"b\" ? Number(value) : rgb?.b,\n },\n event,\n );\n };\n\n return (\n <div className={cx(classes.fields, className)}>\n <HvInput\n ref={hexInputRef}\n className={classes.double}\n label=\"HEX\"\n value={internalHex?.replace(\"#\", \"\")}\n onChange={onChangeHex}\n onBlur={() => setInternalHex(hex)}\n disableClear\n />\n <HvInput\n ref={redInputRef}\n className={classes.single}\n label=\"R\"\n value={internalRed}\n onChange={(event, value) => onChangeRbg(event, value, \"r\")}\n onBlur={() => setInternalRed(rgb?.r)}\n inputProps={{ type: \"number\", min: 0, max: 255 }}\n disableClear\n />\n <HvInput\n ref={greenInputRef}\n className={classes.single}\n label=\"G\"\n value={internalGreen}\n onChange={(event, value) => onChangeRbg(event, value, \"g\")}\n onBlur={() => setInternalGreen(rgb?.g)}\n inputProps={{ type: \"number\", min: 0, max: 255 }}\n disableClear\n />\n <HvInput\n ref={blueInputRef}\n className={classes.single}\n label=\"B\"\n value={internalBlue}\n onChange={(event, value) => onChangeRbg(event, value, \"b\")}\n onBlur={() => setInternalBlue(rgb?.b)}\n inputProps={{ type: \"number\", min: 0, max: 255 }}\n disableClear\n />\n </div>\n );\n};\n"],"names":[],"mappings":";;;;;;;AAkCa,MAAA,SAAS,CAAC,UAAuB;AACtC,QAAA;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS;AAAA,EAAA,IACP,gBAAgB,uBAAuB,KAAK;AAChD,QAAM,EAAE,SAAS,OAAO,WAAW,WAAW;AAC9C,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,GAAG;AAClD,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,KAAK,CAAC;AACrD,QAAM,CAAC,eAAe,gBAAgB,IAAI,SAAS,KAAK,CAAC;AACzD,QAAM,CAAC,cAAc,eAAe,IAAI,SAAS,KAAK,CAAC;AAEjD,QAAA,cAAc,OAAyB,IAAI;AAC3C,QAAA,cAAc,OAAyB,IAAI;AAC3C,QAAA,gBAAgB,OAAyB,IAAI;AAC7C,QAAA,eAAe,OAAyB,IAAI;AAElD,YAAU,MAAM;AACV,QAAA,SAAS,kBAAkB,YAAY,SAAS;AAClD,qBAAe,GAAG;AAAA,IAAA;AAAA,EACpB,GACC,CAAC,GAAG,CAAC;AAER,YAAU,MAAM;AACV,QAA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