@hitachivantara/uikit-react-core 5.68.0 → 5.69.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Button/Button.cjs +1 -1
- package/dist/cjs/Calendar/CalendarHeader/CalendarHeader.styles.cjs +1 -1
- package/dist/cjs/Calendar/CalendarNavigation/ComposedNavigation/ComposedNavigation.styles.cjs +1 -1
- package/dist/cjs/Calendar/SingleCalendar/SingleCalendar.cjs +4 -3
- package/dist/cjs/Calendar/SingleCalendar/SingleCalendar.styles.cjs +4 -12
- package/dist/cjs/Calendar/utils.cjs +5 -5
- package/dist/cjs/Carousel/Carousel.cjs +2 -3
- package/dist/cjs/Dropdown/List/List.cjs +14 -22
- package/dist/cjs/Dropdown/List/List.styles.cjs +13 -1
- package/dist/cjs/Pagination/Pagination.cjs +1 -2
- package/dist/cjs/ProgressBar/ProgressBar.cjs +1 -2
- package/dist/cjs/Table/TableBody/TableBody.cjs +1 -1
- package/dist/cjs/Table/TableCell/TableCell.cjs +1 -1
- package/dist/cjs/Table/TableHead/TableHead.cjs +1 -1
- package/dist/cjs/Table/TableHeader/TableHeader.cjs +1 -1
- package/dist/cjs/Table/TableRow/TableRow.cjs +1 -1
- package/dist/cjs/Table/TableSectionContext.cjs +2 -2
- package/dist/cjs/Typography/Typography.cjs +1 -1
- package/dist/cjs/providers/ThemeProvider.cjs +31 -4
- package/dist/cjs/utils/helpers.cjs +0 -4
- package/dist/esm/BaseSwitch/BaseSwitch.js.map +1 -1
- package/dist/esm/Button/Button.js +1 -1
- package/dist/esm/Button/Button.js.map +1 -1
- package/dist/esm/Calendar/CalendarHeader/CalendarHeader.styles.js +1 -1
- package/dist/esm/Calendar/CalendarHeader/CalendarHeader.styles.js.map +1 -1
- package/dist/esm/Calendar/CalendarNavigation/ComposedNavigation/ComposedNavigation.styles.js +1 -1
- package/dist/esm/Calendar/CalendarNavigation/ComposedNavigation/ComposedNavigation.styles.js.map +1 -1
- package/dist/esm/Calendar/SingleCalendar/SingleCalendar.js +5 -4
- package/dist/esm/Calendar/SingleCalendar/SingleCalendar.js.map +1 -1
- package/dist/esm/Calendar/SingleCalendar/SingleCalendar.styles.js +4 -12
- package/dist/esm/Calendar/SingleCalendar/SingleCalendar.styles.js.map +1 -1
- package/dist/esm/Calendar/utils.js +5 -5
- package/dist/esm/Calendar/utils.js.map +1 -1
- package/dist/esm/Carousel/Carousel.js +2 -3
- package/dist/esm/Carousel/Carousel.js.map +1 -1
- package/dist/esm/Dropdown/List/List.js +15 -23
- package/dist/esm/Dropdown/List/List.js.map +1 -1
- package/dist/esm/Dropdown/List/List.styles.js +13 -1
- package/dist/esm/Dropdown/List/List.styles.js.map +1 -1
- package/dist/esm/Pagination/Pagination.js +1 -2
- package/dist/esm/Pagination/Pagination.js.map +1 -1
- package/dist/esm/ProgressBar/ProgressBar.js +1 -2
- package/dist/esm/ProgressBar/ProgressBar.js.map +1 -1
- package/dist/esm/Switch/Switch.js.map +1 -1
- package/dist/esm/Table/TableBody/TableBody.js +1 -1
- package/dist/esm/Table/TableBody/TableBody.js.map +1 -1
- package/dist/esm/Table/TableCell/TableCell.js +1 -1
- package/dist/esm/Table/TableCell/TableCell.js.map +1 -1
- package/dist/esm/Table/TableHead/TableHead.js +1 -1
- package/dist/esm/Table/TableHead/TableHead.js.map +1 -1
- package/dist/esm/Table/TableHeader/TableHeader.js +1 -1
- package/dist/esm/Table/TableHeader/TableHeader.js.map +1 -1
- package/dist/esm/Table/TableRow/TableRow.js +1 -1
- package/dist/esm/Table/TableRow/TableRow.js.map +1 -1
- package/dist/esm/Table/TableSectionContext.js +1 -1
- package/dist/esm/Table/TableSectionContext.js.map +1 -1
- package/dist/esm/Typography/Typography.js +1 -1
- package/dist/esm/Typography/Typography.js.map +1 -1
- package/dist/esm/Typography/utils.js.map +1 -1
- package/dist/esm/providers/ThemeProvider.js +31 -4
- package/dist/esm/providers/ThemeProvider.js.map +1 -1
- package/dist/esm/utils/helpers.js +0 -4
- package/dist/esm/utils/helpers.js.map +1 -1
- package/dist/types/index.d.ts +27 -26
- package/package.json +7 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SingleCalendar.js","sources":["../../../../src/Calendar/SingleCalendar/SingleCalendar.tsx"],"sourcesContent":["import { useMemo, useState } from \"react\";\nimport { type ExtractNames } from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvTypography } from \"../../Typography\";\nimport { isKey } from \"../../utils/keyboardUtils\";\nimport { setId } from \"../../utils/setId\";\nimport { HvCalendarHeader } from \"../CalendarHeader/CalendarHeader\";\nimport { HvComposedNavigation, HvMonthSelector } from \"../CalendarNavigation\";\nimport { ViewMode } from \"../enums\";\nimport { generateCalendarModel } from \"../model\";\nimport { DateRangeProp, VisibilitySelectorActions } from \"../types\";\nimport { getWeekdayNamesList, isDate, isRange } from \"../utils\";\nimport { HvCalendarCell } from \"./CalendarCell\";\nimport { staticClasses, useClasses } from \"./SingleCalendar.styles\";\n\nexport { staticClasses as singleCalendarClasses };\n\nexport type HvSingleCalendarClasses = ExtractNames<typeof useClasses>;\n\nexport const HvSingleCalendar = ({\n classes: classesProp,\n className,\n id,\n locale = \"en-US\",\n value,\n visibleMonth,\n visibleYear,\n minimumDate,\n maximumDate,\n onChange,\n onInputChange,\n onVisibleDateChange,\n showEndDate,\n showDayOfWeek,\n invalidDateLabel,\n children,\n ...others\n}: HvSingleCalendarProps) => {\n // TODO: refactor this out\n // const { HvCalendarHeader } = useContext(HvFormElementDescriptorsContext);\n\n const { classes, cx } = useClasses(classesProp);\n\n const today = new Date();\n const localValue = value ?? today;\n\n const [calViewMode, setCalViewMode] = useState<ViewMode>(\"calendar\");\n\n const rangeMode = isRange(localValue);\n const isDateSelectionMode = rangeMode && !isDate(localValue.endDate);\n const calModel = rangeMode\n ? generateCalendarModel(localValue.startDate, visibleMonth, visibleYear)\n : generateCalendarModel(localValue, visibleMonth, visibleYear);\n const firstDayOfCurrentMonth = new Date(calModel.year, calModel.month - 1, 1);\n const firstDayOfCurrentMonthTime = firstDayOfCurrentMonth.getTime();\n\n const listWeekdayNames = useMemo(() => getWeekdayNamesList(locale), [locale]);\n\n const handleChange = (event: any, date: Date | DateRangeProp) => {\n event?.preventDefault();\n onChange?.(event, date);\n };\n\n const handleInputChange = (event: any, date: any) => {\n event?.preventDefault();\n onInputChange?.(event, date);\n };\n\n const getNavChild = (event: KeyboardEvent, siblings: any, i: number) => {\n if (isKey(event, \"ArrowLeft\")) return siblings[i - 1];\n if (isKey(event, \"ArrowRight\")) return siblings[i + 1];\n if (isKey(event, \"ArrowUp\")) return siblings[i - 7];\n if (isKey(event, \"ArrowDown\")) return siblings[i + 7];\n return undefined;\n };\n\n const handleKeyDown = (event: any) => {\n // This code is very brittle and should be managed with the focus wrapper\n const el = document?.activeElement;\n const parent = el?.parentElement?.parentElement;\n const siblings =\n parent != null\n ? Array.from(\n parent.getElementsByClassName(classes.cellContainer as string),\n )\n : [];\n const elIndex = el ? siblings.indexOf(el) : 0;\n\n if (isKey(event, \"Enter\")) {\n (el as HTMLElement).focus();\n return;\n }\n\n const child = getNavChild(event, siblings, elIndex);\n\n if (child) {\n const inMonth = child.getAttribute(\"data-in-month\");\n if (inMonth === \"true\") {\n event?.preventDefault();\n child?.focus();\n }\n }\n };\n\n const renderWeekLabel = (dayName: string, index: number) => (\n <HvTypography key={index} variant=\"label\" className={classes.calendarDay}>\n {dayName}\n </HvTypography>\n );\n\n /** Renders the element representing the received date. */\n const renderCalendarDate = (currentDate: Date) => {\n return (\n <HvCalendarCell\n classes={classes}\n key={currentDate.toString()}\n tabIndex={currentDate.getTime() === firstDayOfCurrentMonthTime ? 0 : -1}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n value={currentDate}\n today={today}\n calendarValue={localValue}\n rangeMode={rangeMode}\n isDateSelectionMode={isDateSelectionMode}\n locale={locale}\n firstDayOfCurrentMonth={firstDayOfCurrentMonth}\n maximumDate={maximumDate}\n minimumDate={minimumDate}\n />\n );\n };\n\n return (\n <div className={cx(classes.calendarContainer, className)} {...others}>\n <div id={id} className={classes.calendarWrapper}>\n <HvCalendarHeader\n id={setId(id, \"header\")}\n locale={locale}\n onChange={handleInputChange}\n showEndDate={showEndDate && !isDateSelectionMode}\n showDayOfWeek={showDayOfWeek}\n invalidDateLabel={invalidDateLabel}\n />\n {calViewMode === \"calendar\" && (\n <div>\n <HvComposedNavigation\n id={id}\n locale={locale}\n onChange={onVisibleDateChange}\n onViewModeChange={setCalViewMode}\n visibleYear={visibleYear || today.getFullYear()}\n visibleMonth={visibleMonth || today.getMonth() + 1}\n />\n <div\n className={classes.calendarGrid}\n // @ts-ignore TODO: review\n aria-controls={HvCalendarHeader?.[0]?.id}\n >\n {listWeekdayNames.map(renderWeekLabel)}\n {calModel.dates.map(renderCalendarDate)}\n </div>\n </div>\n )}\n {calViewMode === \"monthly\" && (\n <HvMonthSelector\n id={id}\n locale={locale}\n onChange={onVisibleDateChange}\n onViewModeChange={setCalViewMode}\n visibleMonth={visibleMonth || today.getMonth() + 1}\n rangeMode={rangeMode}\n />\n )}\n </div>\n </div>\n );\n};\n\nexport interface HvSingleCalendarProps {\n /**\n * Styles applied from the theme.\n */\n classes?: HvSingleCalendarClasses;\n /**\n * Identifier.\n */\n id?: string;\n /**\n * The class name to add at the root of the single calendar\n */\n className?: string;\n /**\n * The calendar locale.\n *\n */\n locale: string;\n /**\n * Date that the calendar would show.\n */\n value?: string | Date | DateRangeProp;\n /**\n * Date that will be used to know which month and year should be displayed on the calendar. The value of the day is\n * irrelevant.\n */\n visibleDate?: Date;\n /**\n * Controls the visible month of the Calendar\n */\n visibleMonth?: number;\n /**\n * Controls the visible month of the Calendar\n */\n visibleYear?: number;\n /**\n * Callback function to be triggered when the selected date has changed.\n */\n onChange?: (\n event:\n | React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>\n | undefined,\n value: Date | DateRangeProp,\n ) => void;\n /**\n * Callback function to be triggered when the selected date input has changed.\n */\n onInputChange?: (\n event:\n | React.ChangeEvent<\n HTMLTextAreaElement | HTMLInputElement | HTMLButtonElement\n >\n | undefined,\n value: Date | DateRangeProp,\n position?: \"left\" | \"right\",\n ) => void;\n /**\n * Callback function to be triggered when visible date has changed.\n */\n onVisibleDateChange?: (\n event:\n | React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>\n | undefined,\n action: VisibilitySelectorActions,\n value?: Date | DateRangeProp | number,\n ) => void;\n /**\n * The maximum selectable date after this all values are disabled.\n */\n maximumDate?: Date;\n /**\n * The minimum selectable date before this all values are disabled.\n */\n minimumDate?: Date;\n /**\n * Indicates if header should display end date in a date range.\n */\n showEndDate?: boolean;\n /**\n * Indicates if header should display the day of week.\n */\n showDayOfWeek?: boolean;\n /**\n * Content on the upper part of the calendar.\n */\n children?: React.ReactNode;\n /**\n * Label shown when date is invalid.\n */\n invalidDateLabel?: string;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAmBO,MAAM,mBAAmB,CAAC;AAAA,EAC/B,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAA6B;AAI3B,QAAM,EAAE,SAAS,GAAG,IAAI,WAAW,WAAW;AAExC,QAAA,4BAAY;AAClB,QAAM,aAAa,SAAS;AAE5B,QAAM,CAAC,aAAa,cAAc,IAAI,SAAmB,UAAU;AAE7D,QAAA,YAAY,QAAQ,UAAU;AACpC,QAAM,sBAAsB,aAAa,CAAC,OAAO,WAAW,OAAO;AAC7D,QAAA,WAAW,YACb,sBAAsB,WAAW,WAAW,cAAc,WAAW,IACrE,sBAAsB,YAAY,cAAc,WAAW;AACzD,QAAA,yBAAyB,IAAI,KAAK,SAAS,MAAM,SAAS,QAAQ,GAAG,CAAC;AACtE,QAAA,6BAA6B,uBAA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AAgB,MAAM,SAAa,IAAA;AAAA,QACjD;AAAA,MAAA;AAAA,IACF;AAAA,EAAA,EAEJ,CAAA,EACF,CAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"SingleCalendar.js","sources":["../../../../src/Calendar/SingleCalendar/SingleCalendar.tsx"],"sourcesContent":["import { useMemo, useState } from \"react\";\nimport { type ExtractNames } from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvPanel } from \"../../Panel\";\nimport { HvTypography } from \"../../Typography\";\nimport { isKey } from \"../../utils/keyboardUtils\";\nimport { setId } from \"../../utils/setId\";\nimport { HvCalendarHeader } from \"../CalendarHeader/CalendarHeader\";\nimport { HvComposedNavigation, HvMonthSelector } from \"../CalendarNavigation\";\nimport { ViewMode } from \"../enums\";\nimport { generateCalendarModel } from \"../model\";\nimport { DateRangeProp, VisibilitySelectorActions } from \"../types\";\nimport { getWeekdayNamesList, isDate, isRange } from \"../utils\";\nimport { HvCalendarCell } from \"./CalendarCell\";\nimport { staticClasses, useClasses } from \"./SingleCalendar.styles\";\n\nexport { staticClasses as singleCalendarClasses };\n\nexport type HvSingleCalendarClasses = ExtractNames<typeof useClasses>;\n\nexport const HvSingleCalendar = ({\n classes: classesProp,\n className,\n id,\n locale = \"en-US\",\n value,\n visibleMonth,\n visibleYear,\n minimumDate,\n maximumDate,\n onChange,\n onInputChange,\n onVisibleDateChange,\n showEndDate,\n showDayOfWeek,\n invalidDateLabel,\n children,\n ...others\n}: HvSingleCalendarProps) => {\n // TODO: refactor this out\n // const { HvCalendarHeader } = useContext(HvFormElementDescriptorsContext);\n\n const { classes, cx } = useClasses(classesProp);\n\n const today = new Date();\n const localValue = value ?? today;\n\n const [calViewMode, setCalViewMode] = useState<ViewMode>(\"calendar\");\n\n const rangeMode = isRange(localValue);\n const isDateSelectionMode = rangeMode && !isDate(localValue.endDate);\n const calModel = rangeMode\n ? generateCalendarModel(localValue.startDate, visibleMonth, visibleYear)\n : generateCalendarModel(localValue, visibleMonth, visibleYear);\n const firstDayOfCurrentMonth = new Date(calModel.year, calModel.month - 1, 1);\n const firstDayOfCurrentMonthTime = firstDayOfCurrentMonth.getTime();\n\n const listWeekdayNames = useMemo(() => getWeekdayNamesList(locale), [locale]);\n\n const handleChange = (event: any, date: Date | DateRangeProp) => {\n event?.preventDefault();\n onChange?.(event, date);\n };\n\n const handleInputChange = (event: any, date: any) => {\n event?.preventDefault();\n onInputChange?.(event, date);\n };\n\n const getNavChild = (event: KeyboardEvent, siblings: any, i: number) => {\n if (isKey(event, \"ArrowLeft\")) return siblings[i - 1];\n if (isKey(event, \"ArrowRight\")) return siblings[i + 1];\n if (isKey(event, \"ArrowUp\")) return siblings[i - 7];\n if (isKey(event, \"ArrowDown\")) return siblings[i + 7];\n return undefined;\n };\n\n const handleKeyDown = (event: any) => {\n // This code is very brittle and should be managed with the focus wrapper\n const el = document?.activeElement;\n const parent = el?.parentElement?.parentElement;\n const siblings =\n parent != null\n ? Array.from(\n parent.getElementsByClassName(classes.cellContainer as string),\n )\n : [];\n const elIndex = el ? siblings.indexOf(el) : 0;\n\n if (isKey(event, \"Enter\")) {\n (el as HTMLElement).focus();\n return;\n }\n\n const child = getNavChild(event, siblings, elIndex);\n\n if (child) {\n const inMonth = child.getAttribute(\"data-in-month\");\n if (inMonth === \"true\") {\n event?.preventDefault();\n child?.focus();\n }\n }\n };\n\n const renderWeekLabel = (dayName: string, index: number) => (\n <HvTypography key={index} variant=\"label\" className={classes.calendarDay}>\n {dayName}\n </HvTypography>\n );\n\n /** Renders the element representing the received date. */\n const renderCalendarDate = (currentDate: Date) => {\n return (\n <HvCalendarCell\n classes={classes}\n key={currentDate.toString()}\n tabIndex={currentDate.getTime() === firstDayOfCurrentMonthTime ? 0 : -1}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n value={currentDate}\n today={today}\n calendarValue={localValue}\n rangeMode={rangeMode}\n isDateSelectionMode={isDateSelectionMode}\n locale={locale}\n firstDayOfCurrentMonth={firstDayOfCurrentMonth}\n maximumDate={maximumDate}\n minimumDate={minimumDate}\n />\n );\n };\n\n return (\n <HvPanel id={id} className={cx(classes.root, className)} {...others}>\n <HvCalendarHeader\n id={setId(id, \"header\")}\n locale={locale}\n onChange={handleInputChange}\n showEndDate={showEndDate && !isDateSelectionMode}\n showDayOfWeek={showDayOfWeek}\n invalidDateLabel={invalidDateLabel}\n />\n {calViewMode === \"calendar\" && (\n <>\n <HvComposedNavigation\n id={id}\n locale={locale}\n onChange={onVisibleDateChange}\n onViewModeChange={setCalViewMode}\n visibleYear={visibleYear || today.getFullYear()}\n visibleMonth={visibleMonth || today.getMonth() + 1}\n />\n <div\n className={classes.calendarGrid}\n // @ts-ignore TODO: review\n aria-controls={HvCalendarHeader?.[0]?.id}\n >\n {listWeekdayNames.map(renderWeekLabel)}\n {calModel.dates.map(renderCalendarDate)}\n </div>\n </>\n )}\n {calViewMode === \"monthly\" && (\n <HvMonthSelector\n id={id}\n locale={locale}\n onChange={onVisibleDateChange}\n onViewModeChange={setCalViewMode}\n visibleMonth={visibleMonth || today.getMonth() + 1}\n rangeMode={rangeMode}\n />\n )}\n </HvPanel>\n );\n};\n\nexport interface HvSingleCalendarProps {\n /**\n * Styles applied from the theme.\n */\n classes?: HvSingleCalendarClasses;\n /**\n * Identifier.\n */\n id?: string;\n /**\n * The class name to add at the root of the single calendar\n */\n className?: string;\n /**\n * The calendar locale.\n *\n */\n locale: string;\n /**\n * Date that the calendar would show.\n */\n value?: string | Date | DateRangeProp;\n /**\n * Date that will be used to know which month and year should be displayed on the calendar. The value of the day is\n * irrelevant.\n */\n visibleDate?: Date;\n /**\n * Controls the visible month of the Calendar\n */\n visibleMonth?: number;\n /**\n * Controls the visible month of the Calendar\n */\n visibleYear?: number;\n /**\n * Callback function to be triggered when the selected date has changed.\n */\n onChange?: (\n event:\n | React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>\n | undefined,\n value: Date | DateRangeProp,\n ) => void;\n /**\n * Callback function to be triggered when the selected date input has changed.\n */\n onInputChange?: (\n event:\n | React.ChangeEvent<\n HTMLTextAreaElement | HTMLInputElement | HTMLButtonElement\n >\n | undefined,\n value: Date | DateRangeProp,\n position?: \"left\" | \"right\",\n ) => void;\n /**\n * Callback function to be triggered when visible date has changed.\n */\n onVisibleDateChange?: (\n event:\n | React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>\n | undefined,\n action: VisibilitySelectorActions,\n value?: Date | DateRangeProp | number,\n ) => void;\n /**\n * The maximum selectable date after this all values are disabled.\n */\n maximumDate?: Date;\n /**\n * The minimum selectable date before this all values are disabled.\n */\n minimumDate?: Date;\n /**\n * Indicates if header should display end date in a date range.\n */\n showEndDate?: boolean;\n /**\n * Indicates if header should display the day of week.\n */\n showDayOfWeek?: boolean;\n /**\n * Content on the upper part of the calendar.\n */\n children?: React.ReactNode;\n /**\n * Label shown when date is invalid.\n */\n invalidDateLabel?: string;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAoBO,MAAM,mBAAmB,CAAC;AAAA,EAC/B,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAA6B;AAI3B,QAAM,EAAE,SAAS,GAAG,IAAI,WAAW,WAAW;AAExC,QAAA,4BAAY;AAClB,QAAM,aAAa,SAAS;AAE5B,QAAM,CAAC,aAAa,cAAc,IAAI,SAAmB,UAAU;AAE7D,QAAA,YAAY,QAAQ,UAAU;AACpC,QAAM,sBAAsB,aAAa,CAAC,OAAO,WAAW,OAAO;AAC7D,QAAA,WAAW,YACb,sBAAsB,WAAW,WAAW,cAAc,WAAW,IACrE,sBAAsB,YAAY,cAAc,WAAW;AACzD,QAAA,yBAAyB,IAAI,KAAK,SAAS,MAAM,SAAS,QAAQ,GAAG,CAAC;AACtE,QAAA,6BAA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AAA,MAAA;AAAA,IACF;AAAA,EAEJ,EAAA,CAAA;AAEJ;"}
|
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
import { createClasses } from "@hitachivantara/uikit-react-utils";
|
|
2
2
|
import { theme } from "@hitachivantara/uikit-styles";
|
|
3
3
|
const { staticClasses, useClasses } = createClasses("HvSingleCalendar", {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
minHeight: "440px",
|
|
7
|
-
position: "relative"
|
|
8
|
-
},
|
|
9
|
-
calendarWrapper: {
|
|
10
|
-
overflow: "hidden",
|
|
11
|
-
backgroundColor: theme.colors.atmo1,
|
|
12
|
-
padding: theme.spacing("sm")
|
|
4
|
+
root: {
|
|
5
|
+
overflow: "hidden"
|
|
13
6
|
},
|
|
14
7
|
calendarGrid: {
|
|
15
|
-
display: "
|
|
16
|
-
|
|
17
|
-
width: "280px",
|
|
8
|
+
display: "grid",
|
|
9
|
+
gridTemplateColumns: "repeat(7, 1fr)",
|
|
18
10
|
"& $cellsInRange": {
|
|
19
11
|
backgroundColor: theme.colors.atmo3,
|
|
20
12
|
"& $startBookend": {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SingleCalendar.styles.js","sources":["../../../../src/Calendar/SingleCalendar/SingleCalendar.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvSingleCalendar\", {\n
|
|
1
|
+
{"version":3,"file":"SingleCalendar.styles.js","sources":["../../../../src/Calendar/SingleCalendar/SingleCalendar.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvSingleCalendar\", {\n root: {\n overflow: \"hidden\",\n },\n calendarGrid: {\n display: \"grid\",\n gridTemplateColumns: \"repeat(7, 1fr)\",\n \"& $cellsInRange\": {\n backgroundColor: theme.colors.atmo3,\n \"& $startBookend\": {\n borderLeft: `1px solid ${theme.colors.secondary}`,\n backgroundColor: theme.colors.atmo3,\n \"&:hover\": {\n borderRight: `1px solid ${theme.colors.secondary}`,\n },\n },\n },\n \"&:hover $cellsInRange\": {\n backgroundColor: theme.colors.atmo3,\n \"& $startBookend\": {\n borderLeft: `1px solid ${theme.colors.secondary}`,\n borderRight: \"inherit\",\n },\n },\n \"& $cellsInRange:hover\": {\n backgroundColor: theme.colors.atmo3,\n \"& $calendarDate\": {\n borderRight: `1px solid ${theme.colors.secondary}`,\n },\n },\n \"& $cellsInRange:hover ~ $cellsInRange\": {\n backgroundColor: theme.colors.atmo1, // controls the right side of the hovered range\n },\n \"& $cellsOutsideRange:hover ~ $cellsInRange\": {\n backgroundColor: theme.colors.atmo1, // control the right side when hovering outside of the range\n },\n },\n calendarDay: {\n display: \"flex\",\n justifyContent: \"center\",\n flexDirection: \"column\",\n textAlign: \"center\",\n height: \"40px\",\n width: \"40px\",\n },\n navigationContainer: {},\n focusSelection: {},\n navigationMonth: {},\n calendarDate: {},\n calendarDateNotInMonth: {},\n calendarDateSelected: {},\n calendarDateInvalid: {},\n calendarDateInSelectionRange: {},\n startBookend: {},\n endBookend: {},\n cellsInRange: {\n backgroundColor: theme.colors.atmo3,\n },\n cellsOutsideRange: {},\n cellContainer: {},\n});\n"],"names":[],"mappings":";;AAGO,MAAM,EAAE,eAAe,eAAe,cAAc,oBAAoB;AAAA,EAC7E,MAAM;AAAA,IACJ,UAAU;AAAA,EACZ;AAAA,EACA,cAAc;AAAA,IACZ,SAAS;AAAA,IACT,qBAAqB;AAAA,IACrB,mBAAmB;AAAA,MACjB,iBAAiB,MAAM,OAAO;AAAA,MAC9B,mBAAmB;AAAA,QACjB,YAAY,aAAa,MAAM,OAAO,SAAS;AAAA,QAC/C,iBAAiB,MAAM,OAAO;AAAA,QAC9B,WAAW;AAAA,UACT,aAAa,aAAa,MAAM,OAAO,SAAS;AAAA,QAClD;AAAA,MACF;AAAA,IACF;AAAA,IACA,yBAAyB;AAAA,MACvB,iBAAiB,MAAM,OAAO;AAAA,MAC9B,mBAAmB;AAAA,QACjB,YAAY,aAAa,MAAM,OAAO,SAAS;AAAA,QAC/C,aAAa;AAAA,MACf;AAAA,IACF;AAAA,IACA,yBAAyB;AAAA,MACvB,iBAAiB,MAAM,OAAO;AAAA,MAC9B,mBAAmB;AAAA,QACjB,aAAa,aAAa,MAAM,OAAO,SAAS;AAAA,MAClD;AAAA,IACF;AAAA,IACA,yCAAyC;AAAA,MACvC,iBAAiB,MAAM,OAAO;AAAA;AAAA,IAChC;AAAA,IACA,8CAA8C;AAAA,MAC5C,iBAAiB,MAAM,OAAO;AAAA;AAAA,IAChC;AAAA,EACF;AAAA,EACA,aAAa;AAAA,IACX,SAAS;AAAA,IACT,gBAAgB;AAAA,IAChB,eAAe;AAAA,IACf,WAAW;AAAA,IACX,QAAQ;AAAA,IACR,OAAO;AAAA,EACT;AAAA,EACA,qBAAqB,CAAC;AAAA,EACtB,gBAAgB,CAAC;AAAA,EACjB,iBAAiB,CAAC;AAAA,EAClB,cAAc,CAAC;AAAA,EACf,wBAAwB,CAAC;AAAA,EACzB,sBAAsB,CAAC;AAAA,EACvB,qBAAqB,CAAC;AAAA,EACtB,8BAA8B,CAAC;AAAA,EAC/B,cAAc,CAAC;AAAA,EACf,YAAY,CAAC;AAAA,EACb,cAAc;AAAA,IACZ,iBAAiB,MAAM,OAAO;AAAA,EAChC;AAAA,EACA,mBAAmB,CAAC;AAAA,EACpB,eAAe,CAAC;AAClB,CAAC;"}
|
|
@@ -26,7 +26,7 @@ const getNextMonth = (month, year) => {
|
|
|
26
26
|
};
|
|
27
27
|
const getMonthNamesList = (locale, representationValue = "long") => {
|
|
28
28
|
const options = { month: representationValue, timeZone: "UTC" };
|
|
29
|
-
return [...
|
|
29
|
+
return [...Array(12).keys()].map((index) => {
|
|
30
30
|
const auxDate = makeUTCDate(1970, index, 1);
|
|
31
31
|
return capitalize(Intl.DateTimeFormat(locale, options).format(auxDate));
|
|
32
32
|
});
|
|
@@ -36,7 +36,7 @@ const getWeekdayNamesList = (locale) => {
|
|
|
36
36
|
weekday: "narrow",
|
|
37
37
|
timeZone: "UTC"
|
|
38
38
|
});
|
|
39
|
-
return [...
|
|
39
|
+
return [...Array(7).keys()].map((index) => {
|
|
40
40
|
return formatter.format(makeUTCDate(1970, 0, 4 + index));
|
|
41
41
|
});
|
|
42
42
|
};
|
|
@@ -49,15 +49,15 @@ const createDatesArray = (month, year) => {
|
|
|
49
49
|
const prevMonthYear = getPreviousMonth(month, year);
|
|
50
50
|
const nextMonthYear = getNextMonth(month, year);
|
|
51
51
|
const prevMonthDays = getMonthDays(prevMonthYear.month, prevMonthYear.year);
|
|
52
|
-
const prevMonthDates = [...
|
|
52
|
+
const prevMonthDates = [...Array(daysFromPrevMonth).keys()].map((index) => {
|
|
53
53
|
const day = index + 1 + (prevMonthDays - daysFromPrevMonth);
|
|
54
54
|
return new Date(prevMonthYear.year, prevMonthYear.month - 1, day);
|
|
55
55
|
});
|
|
56
|
-
const currentMonthDates = [...
|
|
56
|
+
const currentMonthDates = [...Array(monthDays).keys()].map((index) => {
|
|
57
57
|
const day = index + 1;
|
|
58
58
|
return new Date(year, month - 1, day);
|
|
59
59
|
});
|
|
60
|
-
const nextMonthDates = [...
|
|
60
|
+
const nextMonthDates = [...Array(daysFromNextMonth).keys()].map((index) => {
|
|
61
61
|
const day = index + 1;
|
|
62
62
|
return new Date(nextMonthYear.year, nextMonthYear.month - 1, day);
|
|
63
63
|
});
|
|
@@ -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 [...new Array(12)].map((n, 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 [...new Array(7)].map((n, 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 = [...new Array(daysFromPrevMonth)].map((n, index) => {\n const day = index + 1 + (prevMonthDays - daysFromPrevMonth);\n return new Date(prevMonthYear.year, prevMonthYear.month - 1, day);\n });\n const currentMonthDates = [...new Array(monthDays)].map((n, index) => {\n const day = index + 1;\n return new Date(year, month - 1, day);\n });\n const nextMonthDates = [...new Array(daysFromNextMonth)].map((n, 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.DateT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AgB,MAAM,IAAI,EAAE,OAAO,YAAY;AAErD,SACG,iBAAiB,UAAa,gBAAgB,gBAC9C,eAAe,UAAa,gBAAgB;AAEjD;AAEa,MAAA,iBAAiB,CAAC,MAAW,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 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,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,KAAK,IAAI,CAAC;AAQ5C,MAAM,SAAS,CAAC,SACrB,OAAO,UAAU,SAAS,KAAK,IAAI,MAAM,mBACzC,CAAC,OAAO,MAAM,KAAK,SAAS;AAEjB,MAAA,kBAAkB,CAAC,SAC9B,eAAe;AASJ,MAAA,cAAc,CAAC,OAAY,UAAe;AACrD,MAAI,EAAE,OAAO,KAAK,KAAK,OAAO,KAAK,GAAW,QAAA;AAG5C,SAAA,MAAM,eAAe,MAAM,SAAA,KAC3B,MAAM,YAAkB,MAAA,MAAM;AAElC;AASa,MAAA,YAAY,CA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AAI,CAAC,QAAQ,kBAAkB,KAAK,WAAW,KAAa,QAAA;AAC5D,QAAM,eAAe;AAErB,QAAM,eAAe,MAAM,SAAS,EAAE,OAAO,YAAY;AACzD,QAAM,aAAa,MAAM,YAAY,EAAE,OAAO,YAAY;AAE1D,QAAM,gBAAgB,MAAM,IAAI,EAAE,OAAO,YAAY;AAE9C,SAAA,iBAAiB,gBAAgB,iBAAiB;AAC3D;AAEO,MAAM,wBAAwB,CACnC,MACA,aACA,gBACG;AACH,MAAI,CAAC,eAAe,CAAC,YAAoB,QAAA;AACzC,QAAM,eAAe,cACjB,MAAM,WAAW,EAAE,OAAO,YAAY,IACtC;AACJ,QAAM,aAAa,cACf,MAAM,WAAW,EAAE,OAAO,YAAY,IACtC;AAEJ,QAAM,gBAAgB,MAAM,IAAI,EAAE,OAAO,YAAY;AAErD,SACG,iBAAiB,UAAa,gBAAgB,gBAC9C,eAAe,UAAa,gBAAgB;AAEjD;AAEa,MAAA,iBAAiB,CAAC,MAAW,WAAgB;AACjD,SAAA,IAAI,KAAK,eAAe,QAAQ;AAAA,IACrC,KAAK;AAAA,IACL,OAAO;AAAA,IACP,MAAM;AAAA,EAAA,CACP,EAAE,OAAO,IAAI;AAChB;"}
|
|
@@ -2,9 +2,8 @@ import { jsxs, jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { useRef, useState, Children, useCallback, useEffect } from "react";
|
|
3
3
|
import useCarousel from "embla-carousel-react";
|
|
4
4
|
import { Close, Fullscreen, Backwards, Forwards } from "@hitachivantara/uikit-react-icons";
|
|
5
|
-
import { useDefaultProps, useTheme } from "@hitachivantara/uikit-react-utils";
|
|
5
|
+
import { useDefaultProps, useTheme, clamp } from "@hitachivantara/uikit-react-utils";
|
|
6
6
|
import { useLabels } from "../hooks/useLabels.js";
|
|
7
|
-
import { clamp } from "../utils/helpers.js";
|
|
8
7
|
import { useClasses } from "./Carousel.styles.js";
|
|
9
8
|
import { staticClasses } from "./Carousel.styles.js";
|
|
10
9
|
import { HvCarouselControls } from "./CarouselControls.js";
|
|
@@ -48,7 +47,7 @@ const HvCarousel = (props) => {
|
|
|
48
47
|
const labels = useLabels(DEFAULT_LABELS, labelsProps);
|
|
49
48
|
const thumbnailsRef = useRef(null);
|
|
50
49
|
const [isFullscreen, setIsFullscreen] = useState(false);
|
|
51
|
-
const isDs3 = activeTheme?.
|
|
50
|
+
const isDs3 = activeTheme?.base === "ds3";
|
|
52
51
|
const actionsPosition = isDs3 ? "header" : "controls";
|
|
53
52
|
const controlsPosition = controlsPositionProp ?? (isDs3 ? "bottom" : "top");
|
|
54
53
|
const thumbnailsPosition = thumbnailsPositionProp ?? "bottom";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Carousel.js","sources":["../../../src/Carousel/Carousel.tsx"],"sourcesContent":["import { Children, useCallback, useEffect, useRef, useState } from \"react\";\nimport useCarousel from \"embla-carousel-react\";\nimport {\n Backwards,\n Close,\n Forwards,\n Fullscreen,\n} from \"@hitachivantara/uikit-react-icons\";\nimport {\n useDefaultProps,\n useTheme,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvButton } from \"../Button\";\nimport { HvContainer } from \"../Container\";\nimport { useLabels } from \"../hooks/useLabels\";\nimport { HvIconButton, HvIconButtonProps } from \"../IconButton\";\nimport { HvBaseProps } from \"../types/generic\";\nimport { HvTypography } from \"../Typography\";\nimport { clamp } from \"../utils/helpers\";\nimport { staticClasses, useClasses } from \"./Carousel.styles\";\nimport { HvCarouselControls } from \"./CarouselControls\";\nimport { HvCarouselThumbnails } from \"./CarouselThumbnails\";\n\nexport { staticClasses as carouselClasses };\n\nexport type HvCarouselClasses = ExtractNames<typeof useClasses>;\n\nconst DEFAULT_LABELS = {\n close: \"Close\",\n fullscreen: \"Fullscreen\",\n backwards: \"Backwards\",\n forwards: \"Forwards\",\n};\n\nexport interface HvCarouselProps\n extends HvBaseProps<HTMLDivElement, \"title\" | \"onChange\"> {\n /** A Jss Object used to override or extend the styles applied. */\n classes?: HvCarouselClasses;\n /** Height of the Slider container. If `undefined`, images will keep a 16/9 aspect-ratio */\n height?: React.CSSProperties[\"height\"];\n /** Width of the thumbnail. Height will try to maintain a 16/9 aspect-ratio */\n thumbnailWidth?: React.CSSProperties[\"width\"];\n /** Title of the carousel */\n title?: React.ReactNode;\n /** Content slides to be displayed. @see `<HvCarouselSlide />` */\n children?: React.ReactNode;\n /** Custom content to render in the actions area */\n actions?: React.ReactNode;\n /** Whether Carousel is in \"xs mode\" - to use in embedded contexts */\n xs?: boolean;\n /** Whether to show dots instead of arrow pagination. Defaults to true under 5 elements */\n showDots?: boolean;\n /** Whether to show the counter on the top-right corner of the active slide */\n showCounter?: boolean;\n /** Whether to show the back/forwards buttons over the active slide */\n showSlideControls?: boolean;\n /** Whether to enable the fullscreen toggle button */\n showFullscreen?: boolean;\n /** Whether to hide the thumbnails. Hidden by default in \"xs\" mode */\n hideThumbnails?: boolean;\n /** Controls position. */\n controlsPosition?: \"top\" | \"bottom\";\n /** Thumbnails position. */\n thumbnailsPosition?: \"top\" | \"bottom\";\n /** Carousel configuration options. @see https://www.embla-carousel.com/api/options/ */\n carouselOptions?: Parameters<typeof useCarousel>[0];\n /** Function that renders the thumbnail. */\n renderThumbnail?: (index: number) => React.ReactNode;\n /** The callback fired when the active slide changes. */\n onChange?: (index: number) => void;\n /** The callback fired fullscreen is toggled. */\n onFullscreen?: (\n event: React.MouseEvent<HTMLButtonElement>,\n isFullscreen: boolean,\n ) => void;\n /** Labels used on the component. */\n labels?: Partial<typeof DEFAULT_LABELS>;\n}\n\n/**\n * A Carousel is commonly used to browse images, it can also be used to browse any kind of content like text, video, or charts.\n * It allows you to focus on a particular content while having a notion of how many you have to explore.\n */\nexport const HvCarousel = (props: HvCarouselProps) => {\n const {\n className,\n classes: classesProp,\n height: heightProp = \"auto\",\n thumbnailWidth = 90,\n title,\n children,\n actions: actionsProp,\n xs,\n showDots: showDotsProp,\n showCounter: showCounterProp,\n showSlideControls,\n showFullscreen: showFullscreenProp,\n hideThumbnails: hideThumbnailsProp,\n controlsPosition: controlsPositionProp,\n thumbnailsPosition: thumbnailsPositionProp,\n labels: labelsProps,\n carouselOptions,\n renderThumbnail,\n onChange,\n onFullscreen,\n ...others\n } = useDefaultProps(\"HvCarousel\", props);\n const { activeTheme } = useTheme();\n const { classes, css, cx } = useClasses(classesProp);\n const labels = useLabels(DEFAULT_LABELS, labelsProps);\n const thumbnailsRef = useRef<HTMLDivElement>(null);\n const [isFullscreen, setIsFullscreen] = useState(false);\n\n const isDs3 = activeTheme?.name === \"ds3\";\n const actionsPosition = isDs3 ? \"header\" : \"controls\";\n const controlsPosition = controlsPositionProp ?? (isDs3 ? \"bottom\" : \"top\");\n const thumbnailsPosition = thumbnailsPositionProp ?? \"bottom\";\n\n const [containerRef, controller] = useCarousel({\n align: \"start\",\n loop: true,\n ...carouselOptions,\n });\n\n const [selectedIndex, setSelectedIndex] = useState(\n carouselOptions?.startIndex ?? 0,\n );\n\n const numSlides = Children.count(children);\n\n const handlePrevious = useCallback(() => {\n controller?.scrollPrev();\n }, [controller]);\n\n const handleNext = useCallback(() => {\n controller?.scrollNext();\n }, [controller]);\n\n const handleScroll = (index: number) => {\n controller?.scrollTo(index);\n };\n\n const handleSelect = useCallback(() => {\n if (!controller) return;\n\n const slideIndex = controller.selectedScrollSnap();\n setSelectedIndex(slideIndex);\n\n // scroll to thumbnail button\n thumbnailsRef.current\n ?.querySelectorAll(\"button\")\n ?.[slideIndex]?.scrollIntoView({\n behavior: \"smooth\",\n block: \"nearest\",\n });\n\n onChange?.(slideIndex);\n }, [controller, onChange]);\n\n useEffect(() => {\n if (!controller) return;\n\n controller.on(\"select\", handleSelect);\n\n return () => {\n controller.off(\"select\", handleSelect);\n };\n }, [controller, handleSelect]);\n\n useEffect(() => {\n if (!controller) return;\n\n controller.reInit();\n setSelectedIndex((currentIndex) => clamp(currentIndex, numSlides));\n }, [numSlides, controller]);\n\n const handleFullscreen: HvIconButtonProps[\"onClick\"] = (event) => {\n onFullscreen?.(event, !isFullscreen);\n setIsFullscreen((curr) => !curr);\n };\n\n const canPrev = controller?.canScrollPrev() ?? false;\n const canNext = controller?.canScrollNext() ?? false;\n const showTitle = !!title && (!xs || isFullscreen);\n const showFullscreen = showFullscreenProp ?? xs;\n const height = isFullscreen ? \"100%\" : (heightProp ?? \"auto\");\n const showCounter = xs;\n const hideThumbnails = hideThumbnailsProp ?? (xs && !isFullscreen);\n const showThumbnails = !hideThumbnails && !!renderThumbnail;\n const showDots = showDotsProp ?? numSlides <= 5;\n\n const actions = (\n <div\n className={cx(\n classes.actions,\n actionsPosition === \"header\"\n ? css({ position: \"relative\", top: -40, height: 0 })\n : css({ position: \"absolute\" }),\n )}\n >\n {actionsProp}\n {showFullscreen && (\n <HvIconButton\n title={isFullscreen ? labels.close : labels.fullscreen}\n onClick={handleFullscreen}\n className={classes.closeButton}\n >\n {isFullscreen ? <Close /> : <Fullscreen />}\n </HvIconButton>\n )}\n </div>\n );\n\n const controls = (\n <HvCarouselControls\n classes={classes}\n showDots={showDots}\n page={selectedIndex}\n pages={numSlides}\n canPrevious={canPrev}\n canNext={canNext}\n onPreviousClick={handlePrevious}\n onNextClick={handleNext}\n actions={actionsPosition === \"controls\" && actions}\n labels={{\n backwards: labels.backwards,\n forwards: labels.forwards,\n }}\n />\n );\n\n const thumbnails = showThumbnails && (\n <HvCarouselThumbnails\n classes={classes}\n ref={thumbnailsRef}\n page={selectedIndex}\n pages={numSlides}\n width={thumbnailWidth}\n onThumbnailClick={(evt, i) => handleScroll(i)}\n renderThumbnail={renderThumbnail}\n />\n );\n\n return (\n <HvContainer\n className={cx(classes.root, className, {\n [classes.xs]: xs,\n [classes.fullscreen]: isFullscreen,\n })}\n {...others}\n >\n {showTitle && (\n <HvTypography variant=\"title2\" className={classes.title}>\n {title}\n </HvTypography>\n )}\n\n {actionsPosition === \"header\" && actions}\n {thumbnailsPosition === \"top\" && thumbnails}\n {controlsPosition === \"top\" && controls}\n <div\n className={cx(classes.main, {\n [classes.mainXs]: xs,\n [classes.mainFullscreen]: isFullscreen,\n })}\n >\n {showCounter && (\n <div className={classes.counterContainer}>\n <span className={classes.counter}>\n {`${selectedIndex + 1}/${numSlides}`}\n </span>\n </div>\n )}\n\n {showSlideControls && (\n <div className={classes.slideControls}>\n <HvButton\n icon\n disabled={!canPrev}\n variant=\"secondarySubtle\"\n aria-label={labels.backwards}\n onClick={handlePrevious}\n >\n <Backwards iconSize=\"XS\" />\n </HvButton>\n <HvButton\n icon\n disabled={!canNext}\n variant=\"secondarySubtle\"\n aria-label={labels.forwards}\n onClick={handleNext}\n >\n <Forwards iconSize=\"XS\" />\n </HvButton>\n </div>\n )}\n\n <div\n ref={containerRef}\n style={{ height }}\n className={classes.slidesViewport}\n >\n <div className={classes.slidesContainer}>{children}</div>\n </div>\n </div>\n {controlsPosition === \"bottom\" && controls}\n {thumbnailsPosition === \"bottom\" && thumbnails}\n </HvContainer>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AA6BA,MAAM,iBAAiB;AAAA,EACrB,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,UAAU;AACZ;AAmDa,MAAA,aAAa,CAAC,UAA2B;AAC9C,QAAA;AAAA,IACJ;AAAA,IACA,SAAS;AAAA,IACT,QAAQ,aAAa;AAAA,IACrB,iBAAiB;AAAA,IACjB;AAAA,IACA;AAAA,IACA,SAAS;AAAA,IACT;AAAA,IACA,UAAU;AAAA,IACV,aAAa;AAAA,IACb;AAAA,IACA,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB,kBAAkB;AAAA,IAClB,oBAAoB;AAAA,IACpB,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,IACD,gBAAgB,cAAc,KAAK;AACjC,QAAA,EAAE,gBAAgB;AACxB,QAAM,EAAE,SAAS,KAAK,GAAG,IAAI,WAAW,WAAW;AAC7C,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U,EAAA,UAAS,KAAK,CAAA;AAAA,kBAAA;AAAA,gBAC3B;AAAA,gBACA;AAAA,kBAAC;AAAA,kBAAA;AAAA,oBACC,MAAI;AAAA,oBACJ,UAAU,CAAC;AAAA,oBACX,SAAQ;AAAA,oBACR,cAAY,OAAO;AAAA,oBACnB,SAAS;AAAA,oBAET,UAAA,oBAAC,UAAS,EAAA,UAAS,KAAK,CAAA;AAAA,kBAAA;AAAA,gBAC1B;AAAA,cAAA,GACF;AAAA,cAGF;AAAA,gBAAC;AAAA,gBAAA;AAAA,kBACC,KAAK;AAAA,kBACL,OAAO,EAAE,OAAO;AAAA,kBAChB,WAAW,QAAQ;AAAA,kBAEnB,UAAC,oBAAA,OAAA,EAAI,WAAW,QAAQ,iBAAkB,UAAS;AAAA,gBAAA;AAAA,cACrD;AAAA,YAAA;AAAA,UAAA;AAAA,QACF;AAAA,QACC,qBAAqB,YAAY;AAAA,QACjC,uBAAuB,YAAY;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAG1C;"}
|
|
1
|
+
{"version":3,"file":"Carousel.js","sources":["../../../src/Carousel/Carousel.tsx"],"sourcesContent":["import { Children, useCallback, useEffect, useRef, useState } from \"react\";\nimport useCarousel from \"embla-carousel-react\";\nimport {\n Backwards,\n Close,\n Forwards,\n Fullscreen,\n} from \"@hitachivantara/uikit-react-icons\";\nimport {\n clamp,\n useDefaultProps,\n useTheme,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvButton } from \"../Button\";\nimport { HvContainer } from \"../Container\";\nimport { useLabels } from \"../hooks/useLabels\";\nimport { HvIconButton, HvIconButtonProps } from \"../IconButton\";\nimport { HvBaseProps } from \"../types/generic\";\nimport { HvTypography } from \"../Typography\";\nimport { staticClasses, useClasses } from \"./Carousel.styles\";\nimport { HvCarouselControls } from \"./CarouselControls\";\nimport { HvCarouselThumbnails } from \"./CarouselThumbnails\";\n\nexport { staticClasses as carouselClasses };\n\nexport type HvCarouselClasses = ExtractNames<typeof useClasses>;\n\nconst DEFAULT_LABELS = {\n close: \"Close\",\n fullscreen: \"Fullscreen\",\n backwards: \"Backwards\",\n forwards: \"Forwards\",\n};\n\nexport interface HvCarouselProps\n extends HvBaseProps<HTMLDivElement, \"title\" | \"onChange\"> {\n /** A Jss Object used to override or extend the styles applied. */\n classes?: HvCarouselClasses;\n /** Height of the Slider container. If `undefined`, images will keep a 16/9 aspect-ratio */\n height?: React.CSSProperties[\"height\"];\n /** Width of the thumbnail. Height will try to maintain a 16/9 aspect-ratio */\n thumbnailWidth?: React.CSSProperties[\"width\"];\n /** Title of the carousel */\n title?: React.ReactNode;\n /** Content slides to be displayed. @see `<HvCarouselSlide />` */\n children?: React.ReactNode;\n /** Custom content to render in the actions area */\n actions?: React.ReactNode;\n /** Whether Carousel is in \"xs mode\" - to use in embedded contexts */\n xs?: boolean;\n /** Whether to show dots instead of arrow pagination. Defaults to true under 5 elements */\n showDots?: boolean;\n /** Whether to show the counter on the top-right corner of the active slide */\n showCounter?: boolean;\n /** Whether to show the back/forwards buttons over the active slide */\n showSlideControls?: boolean;\n /** Whether to enable the fullscreen toggle button */\n showFullscreen?: boolean;\n /** Whether to hide the thumbnails. Hidden by default in \"xs\" mode */\n hideThumbnails?: boolean;\n /** Controls position. */\n controlsPosition?: \"top\" | \"bottom\";\n /** Thumbnails position. */\n thumbnailsPosition?: \"top\" | \"bottom\";\n /** Carousel configuration options. @see https://www.embla-carousel.com/api/options/ */\n carouselOptions?: Parameters<typeof useCarousel>[0];\n /** Function that renders the thumbnail. */\n renderThumbnail?: (index: number) => React.ReactNode;\n /** The callback fired when the active slide changes. */\n onChange?: (index: number) => void;\n /** The callback fired fullscreen is toggled. */\n onFullscreen?: (\n event: React.MouseEvent<HTMLButtonElement>,\n isFullscreen: boolean,\n ) => void;\n /** Labels used on the component. */\n labels?: Partial<typeof DEFAULT_LABELS>;\n}\n\n/**\n * A Carousel is commonly used to browse images, it can also be used to browse any kind of content like text, video, or charts.\n * It allows you to focus on a particular content while having a notion of how many you have to explore.\n */\nexport const HvCarousel = (props: HvCarouselProps) => {\n const {\n className,\n classes: classesProp,\n height: heightProp = \"auto\",\n thumbnailWidth = 90,\n title,\n children,\n actions: actionsProp,\n xs,\n showDots: showDotsProp,\n showCounter: showCounterProp,\n showSlideControls,\n showFullscreen: showFullscreenProp,\n hideThumbnails: hideThumbnailsProp,\n controlsPosition: controlsPositionProp,\n thumbnailsPosition: thumbnailsPositionProp,\n labels: labelsProps,\n carouselOptions,\n renderThumbnail,\n onChange,\n onFullscreen,\n ...others\n } = useDefaultProps(\"HvCarousel\", props);\n const { activeTheme } = useTheme();\n const { classes, css, cx } = useClasses(classesProp);\n const labels = useLabels(DEFAULT_LABELS, labelsProps);\n const thumbnailsRef = useRef<HTMLDivElement>(null);\n const [isFullscreen, setIsFullscreen] = useState(false);\n\n const isDs3 = activeTheme?.base === \"ds3\";\n const actionsPosition = isDs3 ? \"header\" : \"controls\";\n const controlsPosition = controlsPositionProp ?? (isDs3 ? \"bottom\" : \"top\");\n const thumbnailsPosition = thumbnailsPositionProp ?? \"bottom\";\n\n const [containerRef, controller] = useCarousel({\n align: \"start\",\n loop: true,\n ...carouselOptions,\n });\n\n const [selectedIndex, setSelectedIndex] = useState(\n carouselOptions?.startIndex ?? 0,\n );\n\n const numSlides = Children.count(children);\n\n const handlePrevious = useCallback(() => {\n controller?.scrollPrev();\n }, [controller]);\n\n const handleNext = useCallback(() => {\n controller?.scrollNext();\n }, [controller]);\n\n const handleScroll = (index: number) => {\n controller?.scrollTo(index);\n };\n\n const handleSelect = useCallback(() => {\n if (!controller) return;\n\n const slideIndex = controller.selectedScrollSnap();\n setSelectedIndex(slideIndex);\n\n // scroll to thumbnail button\n thumbnailsRef.current\n ?.querySelectorAll(\"button\")\n ?.[slideIndex]?.scrollIntoView({\n behavior: \"smooth\",\n block: \"nearest\",\n });\n\n onChange?.(slideIndex);\n }, [controller, onChange]);\n\n useEffect(() => {\n if (!controller) return;\n\n controller.on(\"select\", handleSelect);\n\n return () => {\n controller.off(\"select\", handleSelect);\n };\n }, [controller, handleSelect]);\n\n useEffect(() => {\n if (!controller) return;\n\n controller.reInit();\n setSelectedIndex((currentIndex) => clamp(currentIndex, numSlides));\n }, [numSlides, controller]);\n\n const handleFullscreen: HvIconButtonProps[\"onClick\"] = (event) => {\n onFullscreen?.(event, !isFullscreen);\n setIsFullscreen((curr) => !curr);\n };\n\n const canPrev = controller?.canScrollPrev() ?? false;\n const canNext = controller?.canScrollNext() ?? false;\n const showTitle = !!title && (!xs || isFullscreen);\n const showFullscreen = showFullscreenProp ?? xs;\n const height = isFullscreen ? \"100%\" : (heightProp ?? \"auto\");\n const showCounter = xs;\n const hideThumbnails = hideThumbnailsProp ?? (xs && !isFullscreen);\n const showThumbnails = !hideThumbnails && !!renderThumbnail;\n const showDots = showDotsProp ?? numSlides <= 5;\n\n const actions = (\n <div\n className={cx(\n classes.actions,\n actionsPosition === \"header\"\n ? css({ position: \"relative\", top: -40, height: 0 })\n : css({ position: \"absolute\" }),\n )}\n >\n {actionsProp}\n {showFullscreen && (\n <HvIconButton\n title={isFullscreen ? labels.close : labels.fullscreen}\n onClick={handleFullscreen}\n className={classes.closeButton}\n >\n {isFullscreen ? <Close /> : <Fullscreen />}\n </HvIconButton>\n )}\n </div>\n );\n\n const controls = (\n <HvCarouselControls\n classes={classes}\n showDots={showDots}\n page={selectedIndex}\n pages={numSlides}\n canPrevious={canPrev}\n canNext={canNext}\n onPreviousClick={handlePrevious}\n onNextClick={handleNext}\n actions={actionsPosition === \"controls\" && actions}\n labels={{\n backwards: labels.backwards,\n forwards: labels.forwards,\n }}\n />\n );\n\n const thumbnails = showThumbnails && (\n <HvCarouselThumbnails\n classes={classes}\n ref={thumbnailsRef}\n page={selectedIndex}\n pages={numSlides}\n width={thumbnailWidth}\n onThumbnailClick={(evt, i) => handleScroll(i)}\n renderThumbnail={renderThumbnail}\n />\n );\n\n return (\n <HvContainer\n className={cx(classes.root, className, {\n [classes.xs]: xs,\n [classes.fullscreen]: isFullscreen,\n })}\n {...others}\n >\n {showTitle && (\n <HvTypography variant=\"title2\" className={classes.title}>\n {title}\n </HvTypography>\n )}\n\n {actionsPosition === \"header\" && actions}\n {thumbnailsPosition === \"top\" && thumbnails}\n {controlsPosition === \"top\" && controls}\n <div\n className={cx(classes.main, {\n [classes.mainXs]: xs,\n [classes.mainFullscreen]: isFullscreen,\n })}\n >\n {showCounter && (\n <div className={classes.counterContainer}>\n <span className={classes.counter}>\n {`${selectedIndex + 1}/${numSlides}`}\n </span>\n </div>\n )}\n\n {showSlideControls && (\n <div className={classes.slideControls}>\n <HvButton\n icon\n disabled={!canPrev}\n variant=\"secondarySubtle\"\n aria-label={labels.backwards}\n onClick={handlePrevious}\n >\n <Backwards iconSize=\"XS\" />\n </HvButton>\n <HvButton\n icon\n disabled={!canNext}\n variant=\"secondarySubtle\"\n aria-label={labels.forwards}\n onClick={handleNext}\n >\n <Forwards iconSize=\"XS\" />\n </HvButton>\n </div>\n )}\n\n <div\n ref={containerRef}\n style={{ height }}\n className={classes.slidesViewport}\n >\n <div className={classes.slidesContainer}>{children}</div>\n </div>\n </div>\n {controlsPosition === \"bottom\" && controls}\n {thumbnailsPosition === \"bottom\" && thumbnails}\n </HvContainer>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;AA6BA,MAAM,iBAAiB;AAAA,EACrB,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,UAAU;AACZ;AAmDa,MAAA,aAAa,CAAC,UAA2B;AAC9C,QAAA;AAAA,IACJ;AAAA,IACA,SAAS;AAAA,IACT,QAAQ,aAAa;AAAA,IACrB,iBAAiB;AAAA,IACjB;AAAA,IACA;AAAA,IACA,SAAS;AAAA,IACT;AAAA,IACA,UAAU;AAAA,IACV,aAAa;AAAA,IACb;AAAA,IACA,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB,kBAAkB;AAAA,IAClB,oBAAoB;AAAA,IACpB,QAA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,eACtB,UAAA;AAAA,gBAAA;AAAA,kBAAC;AAAA,kBAAA;AAAA,oBACC,MAAI;AAAA,oBACJ,UAAU,CAAC;AAAA,oBACX,SAAQ;AAAA,oBACR,cAAY,OAAO;AAAA,oBACnB,SAAS;AAAA,oBAET,UAAA,oBAAC,WAAU,EAAA,UAAS,KAAK,CAAA;AAAA,kBAAA;AAAA,gBAC3B;AAAA,gBACA;AAAA,kBAAC;AAAA,kBAAA;AAAA,oBACC,MAAI;AAAA,oBACJ,UAAU,CAAC;AAAA,oBACX,SAAQ;AAAA,oBACR,cAAY,OAAO;AAAA,oBACnB,SAAS;AAAA,oBAET,UAAA,oBAAC,UAAS,EAAA,UAAS,KAAK,CAAA;AAAA,kBAAA;AAAA,gBAC1B;AAAA,cAAA,GACF;AAAA,cAGF;AAAA,gBAAC;AAAA,gBAAA;AAAA,kBACC,KAAK;AAAA,kBACL,OAAO,EAAE,OAAO;AAAA,kBAChB,WAAW,QAAQ;AAAA,kBAEnB,UAAC,oBAAA,OAAA,EAAI,WAAW,QAAQ,iBAAkB,UAAS;AAAA,gBAAA;AAAA,cACrD;AAAA,YAAA;AAAA,UAAA;AAAA,QACF;AAAA,QACC,qBAAqB,YAAY;AAAA,QACjC,uBAAuB,YAAY;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAG1C;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useState, useMemo, useEffect } from "react";
|
|
3
|
-
import { useDefaultProps } from "@hitachivantara/uikit-react-utils";
|
|
3
|
+
import { useDefaultProps, mergeStyles } from "@hitachivantara/uikit-react-utils";
|
|
4
4
|
import { theme } from "@hitachivantara/uikit-styles";
|
|
5
5
|
import { useBaseDropdownContext } from "../../BaseDropdown/BaseDropdownContext/BaseDropdownContext.js";
|
|
6
6
|
import { setId } from "../../utils/setId.js";
|
|
@@ -30,12 +30,12 @@ const HvDropdownList = (props) => {
|
|
|
30
30
|
notifyChangesOnFirstRender = false,
|
|
31
31
|
hasTooltips = false,
|
|
32
32
|
singleSelectionToggle,
|
|
33
|
-
height:
|
|
33
|
+
height: heightProp,
|
|
34
34
|
maxHeight,
|
|
35
35
|
virtualized = false,
|
|
36
36
|
...others
|
|
37
37
|
} = useDefaultProps("HvDropdownList", props);
|
|
38
|
-
const { classes, cx
|
|
38
|
+
const { classes, cx } = useClasses(classesProp);
|
|
39
39
|
const [searchStr, setSearchStr] = useState("");
|
|
40
40
|
const [list, setList] = useState(clone(values));
|
|
41
41
|
const [allSelected, setAllSelected] = useState(false);
|
|
@@ -168,6 +168,9 @@ const HvDropdownList = (props) => {
|
|
|
168
168
|
] });
|
|
169
169
|
};
|
|
170
170
|
const showList = valuesExist(values);
|
|
171
|
+
const elementsSize = theme.spacing(
|
|
172
|
+
5 + 2 + (showSearch ? 5 : 0) + (showList && multiSelect ? 4 + 6 : 0)
|
|
173
|
+
);
|
|
171
174
|
return /* @__PURE__ */ jsxs("div", { className: classes.rootList, children: [
|
|
172
175
|
/* @__PURE__ */ jsx("div", { className: classes.listBorderDown }),
|
|
173
176
|
/* @__PURE__ */ jsxs("div", { className: classes.listContainer, children: [
|
|
@@ -177,26 +180,15 @@ const HvDropdownList = (props) => {
|
|
|
177
180
|
HvList,
|
|
178
181
|
{
|
|
179
182
|
id: setId(id, "list"),
|
|
183
|
+
style: mergeStyles(void 0, {
|
|
184
|
+
height: heightProp,
|
|
185
|
+
"--maxW": width,
|
|
186
|
+
"--maxH": maxHeight ?? `calc(${height}px - ${elementsSize})`
|
|
187
|
+
}),
|
|
180
188
|
classes: {
|
|
181
|
-
root: cx(
|
|
182
|
-
classes.
|
|
183
|
-
|
|
184
|
-
maxWidth: width,
|
|
185
|
-
maxHeight: maxHeight ?? `calc(${height}px - 32px - ${theme.space.xs} - ${theme.space.sm})`,
|
|
186
|
-
overflow: "auto",
|
|
187
|
-
padding: 4,
|
|
188
|
-
margin: -4
|
|
189
|
-
}),
|
|
190
|
-
dropdownHeight && css({
|
|
191
|
-
height: dropdownHeight
|
|
192
|
-
}),
|
|
193
|
-
virtualized && css({
|
|
194
|
-
maxWidth: "inherit",
|
|
195
|
-
maxHeight: "inherit",
|
|
196
|
-
overflow: "inherit",
|
|
197
|
-
padding: 0
|
|
198
|
-
})
|
|
199
|
-
)
|
|
189
|
+
root: cx(classes.dropdownListContainer, {
|
|
190
|
+
[classes.virtualized]: virtualized
|
|
191
|
+
})
|
|
200
192
|
},
|
|
201
193
|
values: list,
|
|
202
194
|
multiSelect,
|
|
@@ -208,7 +200,7 @@ const HvDropdownList = (props) => {
|
|
|
208
200
|
selectable: true,
|
|
209
201
|
condensed: true,
|
|
210
202
|
singleSelectionToggle,
|
|
211
|
-
height:
|
|
203
|
+
height: heightProp,
|
|
212
204
|
virtualized,
|
|
213
205
|
...others
|
|
214
206
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"List.js","sources":["../../../../src/Dropdown/List/List.tsx"],"sourcesContent":["import { useEffect, useMemo, useState } from \"react\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nimport { HvActionBar } from \"../../ActionBar\";\nimport { useBaseDropdownContext } from \"../../BaseDropdown/BaseDropdownContext/BaseDropdownContext\";\nimport { HvButton } from \"../../Button\";\nimport { HvCheckBox } from \"../../CheckBox\";\nimport { HvInput } from \"../../Input\";\nimport { HvList, HvListProps, HvListValue } from \"../../List\";\nimport { HvTypography } from \"../../Typography\";\nimport { setId } from \"../../utils/setId\";\nimport type { HvDropdownLabels } from \"../Dropdown\";\nimport { getSelected } from \"../utils\";\nimport { staticClasses, useClasses } from \"./List.styles\";\n\nexport { staticClasses as dropdownListClasses };\n\nexport type HvDropdownListClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvDropdownListProps {\n /**\n * Id to be applied to the root node.\n */\n id?: string;\n /**\n * A Jss Object used to override or extend the component styles.\n */\n classes?: HvDropdownListClasses;\n /**\n * The list to be rendered.\n */\n values?: HvListValue[];\n /**\n * If true renders a multi select list.\n */\n multiSelect?: boolean;\n /**\n * If true renders the search component.\n */\n showSearch?: boolean;\n /**\n * A function to be executed whenever a item is selected in the list\n * or the Apply button is activated (when `multiSelect` is `true`).\n */\n onChange: (\n /** An array containing the selected values */\n listValues: HvListValue[],\n /** If `true` the selection if finally committed the dropdown header text should reflect the new selection */\n commitChanges: boolean,\n /** If `true` the dropdown should toggle it's current state */\n toggle: boolean,\n /** If `true` the dropdown will call onChange */\n notifyChanges: boolean,\n ) => void;\n /**\n * A function to be executed whenever the Cancel button is activated.\n */\n onCancel: (event: React.MouseEvent) => void;\n /**\n * An object containing all the labels for the dropdown.\n */\n labels?: HvDropdownLabels;\n /**\n * If 'true' the dropdown will notify on the first render.\n */\n notifyChangesOnFirstRender?: boolean;\n /**\n * If `true` the dropdown will show tooltips when user mouseenter text in list\n */\n hasTooltips?: boolean;\n /**\n * If `true`, selection can be toggled when single selection.\n */\n singleSelectionToggle?: boolean;\n /**\n * Experimental. Height of the dropdown, in case you want to control it from a prop. Styles can also be used through dropdownListContainer class. Required in case virtualized is used\n */\n height?: number;\n /**\n * Experimental. Max height of the dropdown, in case you want to control it from a prop. Styles can also be used through dropdownListContainer class.\n */\n maxHeight?: number;\n /**\n * Experimental. Uses dropdown in a virtualized form, where not all options are rendered initially. Good for use cases with a lot of options.\n */\n virtualized?: boolean;\n}\n\n/**\n * The values property was being deeply cloned. That created a significant performance\n * hit when the values contained complex properties' values, like React Nodes.\n *\n * For minimizing the impact of removing the clone, a shallow clone of the array and its\n * objects is performed instead. That should have the same effect in the majority of the\n * cases, where the properties' values are primitive.\n */\nconst clone = (values: HvListValue[]) => values.map((value) => ({ ...value }));\n\n/**\n * Set all hidden's to false.\n */\nconst cleanHidden = (lst: HvListValue[]) =>\n lst.map((item) => ({ ...item, isHidden: false }));\n\nconst valuesExist = (values: HvListValue[]) =>\n values != null && values?.length > 0;\n\n/** Filter selected ordered element `id`s (or `label`) */\nconst getSelectedIds = (list: HvListValue[]) =>\n getSelected(list).map((item) => item.id || item.label);\n\nexport const HvDropdownList = (props: HvDropdownListProps) => {\n const {\n id,\n classes: classesProp,\n values = [],\n multiSelect = false,\n showSearch = false,\n onChange,\n onCancel,\n labels,\n notifyChangesOnFirstRender = false,\n hasTooltips = false,\n singleSelectionToggle,\n height: dropdownHeight,\n maxHeight,\n virtualized = false,\n ...others\n } = useDefaultProps(\"HvDropdownList\", props);\n const { classes, cx, css } = useClasses(classesProp);\n\n const [searchStr, setSearchStr] = useState<string>(\"\");\n const [list, setList] = useState<HvListValue[]>(clone(values));\n const [allSelected, setAllSelected] = useState<boolean>(false);\n const [anySelected, setAnySelected] = useState<boolean>(false);\n const { width, height } = useBaseDropdownContext();\n\n const hasChanges = useMemo(() => {\n return String(getSelectedIds(values)) !== String(getSelectedIds(list));\n }, [list, values]);\n\n const newLabels = {\n selectAll: labels?.selectAll,\n selectionConjunction: labels?.multiSelectionConjunction,\n };\n\n /**\n * Update states associated with select all.\n */\n const updateSelectAll = (listValues: HvListValue[]) => {\n if (!listValues) return;\n const nbrSelected = getSelected(listValues).length;\n const hasSelection = nbrSelected > 0;\n const allSelect = nbrSelected === listValues.length;\n\n setAnySelected(hasSelection);\n setAllSelected(hasSelection && allSelect);\n };\n\n /**\n * After the first render, call onChange if notifyChangesOnFirstRender.\n */\n useEffect(() => {\n if (!valuesExist(values)) return;\n setList(clone(values));\n updateSelectAll(values);\n if (notifyChangesOnFirstRender) {\n onChange?.(values, false, false, true);\n }\n }, [values, notifyChangesOnFirstRender, onChange]);\n\n /**\n * Sets the filtered values to the state.\n *\n * @param {String} str - The value that is being looked.\n */\n const handleSearch = (str: string) => {\n const results = list\n ? list.filter(\n ({\n searchValue,\n label,\n value,\n }: {\n searchValue?: any;\n label?: any;\n value?: any;\n }) => {\n let stringValue = \"\";\n if (\n typeof searchValue === \"string\" ||\n searchValue instanceof String\n ) {\n stringValue = searchValue.toLowerCase();\n } else if (typeof label === \"string\" || label instanceof String) {\n stringValue = label.toLowerCase();\n } else if (typeof value === \"string\" || value instanceof String) {\n stringValue = value.toLowerCase();\n }\n\n return stringValue.indexOf(str.toLowerCase()) >= 0;\n },\n )\n : null;\n\n if (results != null) {\n const newList = list.map((elem) => {\n const isResult = results.find((result) => result.label === elem.label);\n return { ...elem, isHidden: !isResult };\n });\n\n setList(newList);\n setSearchStr(str);\n }\n return str;\n };\n\n /**\n * Create search element.\n *\n * @returns {*}\n */\n const renderSearch = () => (\n <div className={classes.searchContainer}>\n <HvInput\n id={setId(id, \"search\")}\n type=\"search\"\n value={searchStr}\n placeholder={labels?.searchPlaceholder}\n aria-label={labels?.searchPlaceholder}\n onChange={(event, str) => handleSearch(str)}\n />\n </div>\n );\n\n /**\n * Select all the values inside the dropdown.\n *\n */\n const handleSelectAll = () => {\n const newList = list.map((elem) => ({ ...elem, selected: !anySelected }));\n setList(newList);\n updateSelectAll(newList);\n };\n\n /**\n * Create selecteAll component.\n *\n * @returns {*}\n */\n const renderSelectAll = () => {\n const selectAll = labels?.selectAll;\n const multiSelectionConjunction = labels?.multiSelectionConjunction;\n const nbrSelected = getSelected(list).length;\n\n const defaultLabel = (\n <HvTypography component=\"span\">\n {nbrSelected > 0 ? (\n <>\n <b>{nbrSelected}</b>\n {` ${multiSelectionConjunction} ${list.length}`}\n </>\n ) : (\n <>\n <b>{selectAll}</b>\n {` (${list.length})`}\n </>\n )}\n </HvTypography>\n );\n\n return (\n <div className={classes.selectAllContainer}>\n <HvCheckBox\n id={setId(id, \"select-all\")}\n label={defaultLabel}\n onChange={() => handleSelectAll()}\n classes={{\n container: classes.selection,\n }}\n className={classes.selectAll}\n indeterminate={anySelected && !allSelected}\n checked={allSelected}\n />\n </div>\n );\n };\n\n /**\n * When selecting the state list is updated with the corresponding selection.\n *\n * @param listValues - elements selected.\n */\n const onSelection: HvListProps[\"onChange\"] = (listValues) => {\n if (!multiSelect) {\n onChange(cleanHidden(listValues), true, true, true);\n } else {\n updateSelectAll(listValues);\n setList(clone(listValues));\n }\n };\n\n /**\n * Render action buttons.\n */\n const renderActions = () => {\n const applyLabel = labels?.applyLabel;\n const cancelLabel = labels?.cancelLabel;\n return (\n <HvActionBar id={setId(id, \"actions\")}>\n <HvButton\n id={setId(id, \"actions-apply\")}\n disabled={!hasChanges}\n onClick={() => onChange(cleanHidden(list), true, true, true)}\n variant=\"primaryGhost\"\n >\n {applyLabel}\n </HvButton>\n <HvButton\n id={setId(id, \"actions-cancel\")}\n onClick={onCancel}\n variant=\"primaryGhost\"\n >\n {cancelLabel}\n </HvButton>\n </HvActionBar>\n );\n };\n\n const showList = valuesExist(values);\n\n return (\n <div className={classes.rootList}>\n <div className={classes.listBorderDown} />\n <div className={classes.listContainer}>\n {showSearch && renderSearch()}\n {showList && multiSelect && renderSelectAll()}\n {showList && (\n <HvList\n id={setId(id, \"list\")}\n classes={{\n root: cx(\n classes.dropdownListContainer,\n css({\n maxWidth: width,\n maxHeight:\n maxHeight ??\n `calc(${height}px - 32px - ${theme.space.xs} - ${theme.space.sm})`,\n overflow: \"auto\",\n padding: 4,\n margin: -4,\n }),\n dropdownHeight &&\n css({\n height: dropdownHeight,\n }),\n virtualized &&\n css({\n maxWidth: \"inherit\",\n maxHeight: \"inherit\",\n overflow: \"inherit\",\n padding: 0,\n }),\n ),\n }}\n values={list}\n multiSelect={multiSelect}\n useSelector={multiSelect}\n showSelectAll={false}\n onChange={onSelection}\n labels={newLabels}\n hasTooltips={hasTooltips}\n selectable\n condensed\n singleSelectionToggle={singleSelectionToggle}\n height={dropdownHeight}\n virtualized={virtualized}\n {...others}\n />\n )}\n </div>\n {showList && multiSelect ? renderActions() : null}\n </div>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAoGA,MAAM,QAAQ,CAAC,WAA0B,OAAO,IAAI,CAAC,WAAW,EAAE,GAAG,MAAQ,EAAA;AAK7E,MAAM,cAAc,CAAC,QACnB,IAAI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X,UAAU;AAAA,gBACV,SAAS;AAAA,cAAA,CACV;AAAA,YACL;AAAA,UACF;AAAA,UACA,QAAQ;AAAA,UACR;AAAA,UACA,aAAa;AAAA,UACb,eAAe;AAAA,UACf,UAAU;AAAA,UACV,QAAQ;AAAA,UACR;AAAA,UACA,YAAU;AAAA,UACV,WAAS;AAAA,UACT;AAAA,UACA,QAAQ;AAAA,UACR;AAAA,UACC,GAAG;AAAA,QAAA;AAAA,MACN;AAAA,IAAA,GAEJ;AAAA,IACC,YAAY,cAAc,cAAA,IAAkB;AAAA,EAC/C,EAAA,CAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"List.js","sources":["../../../../src/Dropdown/List/List.tsx"],"sourcesContent":["import { useEffect, useMemo, useState } from \"react\";\nimport {\n mergeStyles,\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nimport { HvActionBar } from \"../../ActionBar\";\nimport { useBaseDropdownContext } from \"../../BaseDropdown/BaseDropdownContext/BaseDropdownContext\";\nimport { HvButton } from \"../../Button\";\nimport { HvCheckBox } from \"../../CheckBox\";\nimport { HvInput } from \"../../Input\";\nimport { HvList, HvListProps, HvListValue } from \"../../List\";\nimport { HvTypography } from \"../../Typography\";\nimport { setId } from \"../../utils/setId\";\nimport type { HvDropdownLabels } from \"../Dropdown\";\nimport { getSelected } from \"../utils\";\nimport { staticClasses, useClasses } from \"./List.styles\";\n\nexport { staticClasses as dropdownListClasses };\n\nexport type HvDropdownListClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvDropdownListProps {\n /**\n * Id to be applied to the root node.\n */\n id?: string;\n /**\n * A Jss Object used to override or extend the component styles.\n */\n classes?: HvDropdownListClasses;\n /**\n * The list to be rendered.\n */\n values?: HvListValue[];\n /**\n * If true renders a multi select list.\n */\n multiSelect?: boolean;\n /**\n * If true renders the search component.\n */\n showSearch?: boolean;\n /**\n * A function to be executed whenever a item is selected in the list\n * or the Apply button is activated (when `multiSelect` is `true`).\n */\n onChange: (\n /** An array containing the selected values */\n listValues: HvListValue[],\n /** If `true` the selection if finally committed the dropdown header text should reflect the new selection */\n commitChanges: boolean,\n /** If `true` the dropdown should toggle it's current state */\n toggle: boolean,\n /** If `true` the dropdown will call onChange */\n notifyChanges: boolean,\n ) => void;\n /**\n * A function to be executed whenever the Cancel button is activated.\n */\n onCancel: (event: React.MouseEvent) => void;\n /**\n * An object containing all the labels for the dropdown.\n */\n labels?: HvDropdownLabels;\n /**\n * If 'true' the dropdown will notify on the first render.\n */\n notifyChangesOnFirstRender?: boolean;\n /**\n * If `true` the dropdown will show tooltips when user mouseenter text in list\n */\n hasTooltips?: boolean;\n /**\n * If `true`, selection can be toggled when single selection.\n */\n singleSelectionToggle?: boolean;\n /**\n * Experimental. Height of the dropdown, in case you want to control it from a prop. Styles can also be used through dropdownListContainer class. Required in case virtualized is used\n */\n height?: number;\n /**\n * Experimental. Max height of the dropdown, in case you want to control it from a prop. Styles can also be used through dropdownListContainer class.\n */\n maxHeight?: number;\n /**\n * Experimental. Uses dropdown in a virtualized form, where not all options are rendered initially. Good for use cases with a lot of options.\n */\n virtualized?: boolean;\n}\n\n/**\n * The values property was being deeply cloned. That created a significant performance\n * hit when the values contained complex properties' values, like React Nodes.\n *\n * For minimizing the impact of removing the clone, a shallow clone of the array and its\n * objects is performed instead. That should have the same effect in the majority of the\n * cases, where the properties' values are primitive.\n */\nconst clone = (values: HvListValue[]) => values.map((value) => ({ ...value }));\n\n/**\n * Set all hidden's to false.\n */\nconst cleanHidden = (lst: HvListValue[]) =>\n lst.map((item) => ({ ...item, isHidden: false }));\n\nconst valuesExist = (values: HvListValue[]) =>\n values != null && values?.length > 0;\n\n/** Filter selected ordered element `id`s (or `label`) */\nconst getSelectedIds = (list: HvListValue[]) =>\n getSelected(list).map((item) => item.id || item.label);\n\nexport const HvDropdownList = (props: HvDropdownListProps) => {\n const {\n id,\n classes: classesProp,\n values = [],\n multiSelect = false,\n showSearch = false,\n onChange,\n onCancel,\n labels,\n notifyChangesOnFirstRender = false,\n hasTooltips = false,\n singleSelectionToggle,\n height: heightProp,\n maxHeight,\n virtualized = false,\n ...others\n } = useDefaultProps(\"HvDropdownList\", props);\n const { classes, cx } = useClasses(classesProp);\n\n const [searchStr, setSearchStr] = useState<string>(\"\");\n const [list, setList] = useState<HvListValue[]>(clone(values));\n const [allSelected, setAllSelected] = useState<boolean>(false);\n const [anySelected, setAnySelected] = useState<boolean>(false);\n const { width, height } = useBaseDropdownContext();\n\n const hasChanges = useMemo(() => {\n return String(getSelectedIds(values)) !== String(getSelectedIds(list));\n }, [list, values]);\n\n const newLabels = {\n selectAll: labels?.selectAll,\n selectionConjunction: labels?.multiSelectionConjunction,\n };\n\n /**\n * Update states associated with select all.\n */\n const updateSelectAll = (listValues: HvListValue[]) => {\n if (!listValues) return;\n const nbrSelected = getSelected(listValues).length;\n const hasSelection = nbrSelected > 0;\n const allSelect = nbrSelected === listValues.length;\n\n setAnySelected(hasSelection);\n setAllSelected(hasSelection && allSelect);\n };\n\n /**\n * After the first render, call onChange if notifyChangesOnFirstRender.\n */\n useEffect(() => {\n if (!valuesExist(values)) return;\n setList(clone(values));\n updateSelectAll(values);\n if (notifyChangesOnFirstRender) {\n onChange?.(values, false, false, true);\n }\n }, [values, notifyChangesOnFirstRender, onChange]);\n\n /**\n * Sets the filtered values to the state.\n *\n * @param {String} str - The value that is being looked.\n */\n const handleSearch = (str: string) => {\n const results = list\n ? list.filter(\n ({\n searchValue,\n label,\n value,\n }: {\n searchValue?: any;\n label?: any;\n value?: any;\n }) => {\n let stringValue = \"\";\n if (\n typeof searchValue === \"string\" ||\n searchValue instanceof String\n ) {\n stringValue = searchValue.toLowerCase();\n } else if (typeof label === \"string\" || label instanceof String) {\n stringValue = label.toLowerCase();\n } else if (typeof value === \"string\" || value instanceof String) {\n stringValue = value.toLowerCase();\n }\n\n return stringValue.indexOf(str.toLowerCase()) >= 0;\n },\n )\n : null;\n\n if (results != null) {\n const newList = list.map((elem) => {\n const isResult = results.find((result) => result.label === elem.label);\n return { ...elem, isHidden: !isResult };\n });\n\n setList(newList);\n setSearchStr(str);\n }\n return str;\n };\n\n /**\n * Create search element.\n *\n * @returns {*}\n */\n const renderSearch = () => (\n <div className={classes.searchContainer}>\n <HvInput\n id={setId(id, \"search\")}\n type=\"search\"\n value={searchStr}\n placeholder={labels?.searchPlaceholder}\n aria-label={labels?.searchPlaceholder}\n onChange={(event, str) => handleSearch(str)}\n />\n </div>\n );\n\n /**\n * Select all the values inside the dropdown.\n *\n */\n const handleSelectAll = () => {\n const newList = list.map((elem) => ({ ...elem, selected: !anySelected }));\n setList(newList);\n updateSelectAll(newList);\n };\n\n /**\n * Create selecteAll component.\n *\n * @returns {*}\n */\n const renderSelectAll = () => {\n const selectAll = labels?.selectAll;\n const multiSelectionConjunction = labels?.multiSelectionConjunction;\n const nbrSelected = getSelected(list).length;\n\n const defaultLabel = (\n <HvTypography component=\"span\">\n {nbrSelected > 0 ? (\n <>\n <b>{nbrSelected}</b>\n {` ${multiSelectionConjunction} ${list.length}`}\n </>\n ) : (\n <>\n <b>{selectAll}</b>\n {` (${list.length})`}\n </>\n )}\n </HvTypography>\n );\n\n return (\n <div className={classes.selectAllContainer}>\n <HvCheckBox\n id={setId(id, \"select-all\")}\n label={defaultLabel}\n onChange={() => handleSelectAll()}\n classes={{\n container: classes.selection,\n }}\n className={classes.selectAll}\n indeterminate={anySelected && !allSelected}\n checked={allSelected}\n />\n </div>\n );\n };\n\n /**\n * When selecting the state list is updated with the corresponding selection.\n *\n * @param listValues - elements selected.\n */\n const onSelection: HvListProps[\"onChange\"] = (listValues) => {\n if (!multiSelect) {\n onChange(cleanHidden(listValues), true, true, true);\n } else {\n updateSelectAll(listValues);\n setList(clone(listValues));\n }\n };\n\n /**\n * Render action buttons.\n */\n const renderActions = () => {\n const applyLabel = labels?.applyLabel;\n const cancelLabel = labels?.cancelLabel;\n return (\n <HvActionBar id={setId(id, \"actions\")}>\n <HvButton\n id={setId(id, \"actions-apply\")}\n disabled={!hasChanges}\n onClick={() => onChange(cleanHidden(list), true, true, true)}\n variant=\"primaryGhost\"\n >\n {applyLabel}\n </HvButton>\n <HvButton\n id={setId(id, \"actions-cancel\")}\n onClick={onCancel}\n variant=\"primaryGhost\"\n >\n {cancelLabel}\n </HvButton>\n </HvActionBar>\n );\n };\n\n const showList = valuesExist(values);\n /** bottom margin + Panel padding + Search size + SelectAll + ActionBar size */\n const elementsSize = theme.spacing(\n 5 + 2 + (showSearch ? 5 : 0) + (showList && multiSelect ? 4 + 6 : 0),\n );\n\n return (\n <div className={classes.rootList}>\n <div className={classes.listBorderDown} />\n <div className={classes.listContainer}>\n {showSearch && renderSearch()}\n {showList && multiSelect && renderSelectAll()}\n {showList && (\n <HvList\n id={setId(id, \"list\")}\n style={mergeStyles(undefined, {\n height: heightProp,\n \"--maxW\": width,\n \"--maxH\": maxHeight ?? `calc(${height}px - ${elementsSize})`,\n })}\n classes={{\n root: cx(classes.dropdownListContainer, {\n [classes.virtualized]: virtualized,\n }),\n }}\n values={list}\n multiSelect={multiSelect}\n useSelector={multiSelect}\n showSelectAll={false}\n onChange={onSelection}\n labels={newLabels}\n hasTooltips={hasTooltips}\n selectable\n condensed\n singleSelectionToggle={singleSelectionToggle}\n height={heightProp}\n virtualized={virtualized}\n {...others}\n />\n )}\n </div>\n {showList && multiSelect ? renderActions() : null}\n </div>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAqGA,MAAM,QAAQ,CAAC,WAA0B,OAAO,IAAI,CAAC,WAAW,EAAE,GAAG,MAAQ,EAAA;AAK7E,MAAM,cAAc,CAAC,QACnB,IAAI,IAAI,CAAC,UAAU,EAAE,GAAG,MAAM,UAAU,MAAA,EAAQ;AAElD,MAAM,cAAc,CAAC,WACnB,UAAU,QAAQ,QAAQ,SAAS;AAGrC,MAAM,iBAAiB,CAAC,SACtB,YAAY,IAAI,EAAE,IAAI,CAAC,SAAS,KAA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,QAAA;AAAA,MACN;AAAA,IAAA,GAEJ;AAAA,IACC,YAAY,cAAc,cAAA,IAAkB;AAAA,EAC/C,EAAA,CAAA;AAEJ;"}
|
|
@@ -2,7 +2,19 @@ import { createClasses } from "@hitachivantara/uikit-react-utils";
|
|
|
2
2
|
import { theme } from "@hitachivantara/uikit-styles";
|
|
3
3
|
const { staticClasses, useClasses } = createClasses("HvDropdownList", {
|
|
4
4
|
rootList: {},
|
|
5
|
-
dropdownListContainer: {
|
|
5
|
+
dropdownListContainer: {
|
|
6
|
+
overflow: "auto",
|
|
7
|
+
padding: 4,
|
|
8
|
+
margin: -4,
|
|
9
|
+
maxWidth: "var(--maxW)",
|
|
10
|
+
maxHeight: "var(--maxH)"
|
|
11
|
+
},
|
|
12
|
+
virtualized: {
|
|
13
|
+
maxWidth: "inherit",
|
|
14
|
+
maxHeight: "inherit",
|
|
15
|
+
overflow: "inherit",
|
|
16
|
+
padding: 0
|
|
17
|
+
},
|
|
6
18
|
searchContainer: { marginBottom: theme.space.xs },
|
|
7
19
|
listBorderDown: {},
|
|
8
20
|
listContainer: { padding: theme.space.sm },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"List.styles.js","sources":["../../../../src/Dropdown/List/List.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvDropdownList\", {\n rootList: {},\n dropdownListContainer: {},\n searchContainer: { marginBottom: theme.space.xs },\n listBorderDown: {},\n listContainer: { padding: theme.space.sm },\n selectAllContainer: {},\n selection: {},\n selectAll: {},\n});\n"],"names":[],"mappings":";;AAGO,MAAM,EAAE,eAAe,eAAe,cAAc,kBAAkB;AAAA,EAC3E,UAAU,CAAC;AAAA,EACX,uBAAuB,
|
|
1
|
+
{"version":3,"file":"List.styles.js","sources":["../../../../src/Dropdown/List/List.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvDropdownList\", {\n rootList: {},\n dropdownListContainer: {\n overflow: \"auto\",\n padding: 4,\n margin: -4,\n maxWidth: \"var(--maxW)\",\n maxHeight: \"var(--maxH)\",\n },\n virtualized: {\n maxWidth: \"inherit\",\n maxHeight: \"inherit\",\n overflow: \"inherit\",\n padding: 0,\n },\n searchContainer: { marginBottom: theme.space.xs },\n listBorderDown: {},\n listContainer: { padding: theme.space.sm },\n selectAllContainer: {},\n selection: {},\n selectAll: {},\n});\n"],"names":[],"mappings":";;AAGO,MAAM,EAAE,eAAe,eAAe,cAAc,kBAAkB;AAAA,EAC3E,UAAU,CAAC;AAAA,EACX,uBAAuB;AAAA,IACrB,UAAU;AAAA,IACV,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,WAAW;AAAA,EACb;AAAA,EACA,aAAa;AAAA,IACX,UAAU;AAAA,IACV,WAAW;AAAA,IACX,UAAU;AAAA,IACV,SAAS;AAAA,EACX;AAAA,EACA,iBAAiB,EAAE,cAAc,MAAM,MAAM,GAAG;AAAA,EAChD,gBAAgB,CAAC;AAAA,EACjB,eAAe,EAAE,SAAS,MAAM,MAAM,GAAG;AAAA,EACzC,oBAAoB,CAAC;AAAA,EACrB,WAAW,CAAC;AAAA,EACZ,WAAW,CAAC;AACd,CAAC;"}
|
|
@@ -2,9 +2,8 @@ import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
|
2
2
|
import { useState, useCallback, useEffect } from "react";
|
|
3
3
|
import Hidden from "@mui/material/Hidden";
|
|
4
4
|
import { Start, Backwards, Forwards, End } from "@hitachivantara/uikit-react-icons";
|
|
5
|
-
import { useDefaultProps } from "@hitachivantara/uikit-react-utils";
|
|
5
|
+
import { useDefaultProps, clamp } from "@hitachivantara/uikit-react-utils";
|
|
6
6
|
import { useLabels } from "../hooks/useLabels.js";
|
|
7
|
-
import { clamp } from "../utils/helpers.js";
|
|
8
7
|
import { setId } from "../utils/setId.js";
|
|
9
8
|
import { useClasses } from "./Pagination.styles.js";
|
|
10
9
|
import { staticClasses } from "./Pagination.styles.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Pagination.js","sources":["../../../src/Pagination/Pagination.tsx"],"sourcesContent":["import { useCallback, useEffect, useState } from \"react\";\nimport Hidden from \"@mui/material/Hidden\";\nimport {\n Backwards,\n End,\n Forwards,\n Start,\n} from \"@hitachivantara/uikit-react-icons\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { useLabels } from \"../hooks/useLabels\";\nimport { HvIconButton } from \"../IconButton\";\nimport { HvInput, HvInputProps } from \"../Input\";\nimport { HvBaseProps } from \"../types/generic\";\nimport { HvTypography } from \"../Typography\";\nimport { clamp } from \"../utils/helpers\";\nimport { setId } from \"../utils/setId\";\nimport { staticClasses, useClasses } from \"./Pagination.styles\";\nimport HvSelect, { Option } from \"./Select\";\n\nexport { staticClasses as paginationClasses };\n\nexport type HvPaginationClasses = ExtractNames<typeof useClasses>;\n\nconst defaultPageSizeOptions = [5, 10, 20, 25, 50, 100];\n\nconst DEFAULT_LABELS = {\n /** The show label. */\n pageSizePrev: \"Show\",\n /** Indicate the units of the page size selection. */\n pageSizeEntryName: \"rows\",\n /** Used for the aria-label of the selection of number of unit.s */\n pageSizeSelectorDescription: \"Select how many to display\",\n /** Separator of current page and total pages. */\n pagesSeparator: \"/\",\n /** Title of button `firstPage`. @deprecated Use `firstPage` instead. */\n paginationFirstPageTitle: \"First page\",\n /** Title of button `previousPage`. @deprecated Use `previousPage` instead. */\n paginationPreviousPageTitle: \"Previous page\",\n /** Title of button `nextPage`. @deprecated Use `nextPage` instead. */\n paginationNextPageTitle: \"Next page\",\n /** Title of button `lastPage`. @deprecated Use `lastPage` instead. */\n paginationLastPageTitle: \"Last page\",\n /** Aria-label passed to the page input. */\n paginationInputLabel: \"Current page\",\n /** Label of the first page button */\n firstPage: \"First Page\",\n /** Label of the previous page button */\n previousPage: \"Previous Page\",\n /** Label of the next page button */\n nextPage: \"Next Page\",\n /** Label of the last page button */\n lastPage: \"Last Page\",\n};\n\nexport type HvPaginationLabels = Partial<typeof DEFAULT_LABELS>;\n\nexport interface HvPaginationProps extends HvBaseProps {\n /** The number of pages the component has. */\n pages?: number;\n /** The currently selected page (0-indexed). */\n page?: number;\n /** Controls whether the left page size mechanism should be visible. */\n showPageSizeOptions?: boolean;\n /** The array of possible page sizes for the dropdown. */\n pageSizeOptions?: number[];\n /** The currently selected page size. */\n pageSize?: number;\n /** Controls whether the central page changing mechanism should be visible. */\n showPageJump?: boolean;\n /** Controls whether the previous/first page buttons are enabled. */\n canPrevious?: boolean;\n /** Controls whether the next/last page buttons are enabled. */\n canNext?: boolean;\n /** Function called when the page changes. */\n onPageChange?: (page: number) => void;\n /** Function called when the page size changes. */\n onPageSizeChange?: (pageSize: number) => void;\n /** An object containing all the labels for the component. */\n labels?: HvPaginationLabels;\n /** Other props to show page component. */\n showPageProps?: React.HTMLAttributes<HTMLDivElement>;\n /** Other props to pagination component. */\n navigationProps?: React.HTMLAttributes<HTMLDivElement>;\n /** Extra properties passed to the input component representing the current pages. */\n currentPageInputProps?: HvInputProps;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvPaginationClasses;\n}\n\n/**\n * Pagination is the process of dividing a document into discrete pages. It relates to how users interact\n * with structured content on a website or application.\n */\nexport const HvPagination = (props: HvPaginationProps) => {\n const {\n classes: classesProp,\n className,\n id,\n pages = 1,\n page = 0,\n showPageSizeOptions = true,\n pageSizeOptions = defaultPageSizeOptions,\n pageSize = defaultPageSizeOptions[1],\n showPageJump = true,\n canPrevious = false,\n canNext = false,\n onPageChange,\n onPageSizeChange,\n labels: labelsProp,\n showPageProps,\n navigationProps,\n currentPageInputProps,\n ...others\n } = useDefaultProps(\"HvPagination\", props);\n const { classes, cx } = useClasses(classesProp);\n const labels = useLabels(DEFAULT_LABELS, labelsProp);\n\n const [pageInput, setPageInput] = useState(page);\n\n const changePage = useCallback(\n (newPage: number) => {\n const safePage = Number.isNaN(newPage) ? page : clamp(newPage, pages - 1);\n\n onPageChange?.(safePage);\n setPageInput(safePage);\n },\n [page, pages, onPageChange],\n );\n\n useEffect(() => {\n if (page >= pages && pages > 0) {\n changePage(page);\n }\n }, [changePage, page, pages]);\n\n useEffect(() => {\n setPageInput(page);\n }, [page]);\n\n const renderPageJump = () => (\n <div className={classes.pageJump}>\n <HvInput\n id={setId(id, \"currentPage\")}\n labels={labels}\n inputProps={{\n \"aria-label\": labels?.paginationInputLabel,\n // We really want the native number input\n type: \"number\",\n }}\n classes={{\n root: classes?.pageSizeInputContainer,\n input: classes?.pageSizeInput,\n inputRoot: classes?.pageSizeInputRoot,\n }}\n value={String(pageInput + 1)}\n onChange={(event, value) => setPageInput(Number(value) - 1)}\n onBlur={(evt, value) => changePage(Math.round(Number(value)) - 1)}\n onEnter={(evt, value) => changePage(Math.round(Number(value)) - 1)}\n disabled={pageSize === 0}\n disableClear\n {...currentPageInputProps}\n />\n </div>\n );\n\n return (\n <div id={id} className={cx(classes.root, className)} {...others}>\n <div className={classes.pageSizeOptions} {...showPageProps}>\n {showPageSizeOptions && (\n <>\n <Hidden xsDown>\n <HvTypography\n component=\"span\"\n className={classes?.pageSizeTextContainer}\n >\n {labels?.pageSizePrev}\n </HvTypography>\n </Hidden>\n <HvSelect\n id={setId(id, \"pageSize\")}\n disabled={pageSize === 0}\n className={classes.pageSizeOptionsSelect}\n aria-label={labels?.pageSizeSelectorDescription}\n onChange={(_: any, val: number) => onPageSizeChange?.(val)}\n value={pageSize}\n classes={{\n header: classes.pageSizeHeader,\n root: classes.pageSizeRoot,\n }}\n >\n {pageSizeOptions.map((option) => (\n <Option key={option} value={option}>\n {option}\n </Option>\n ))}\n </HvSelect>\n <Hidden xsDown>\n <HvTypography\n component=\"span\"\n className={classes.pageSizeTextContainer}\n >\n {labels?.pageSizeEntryName}\n </HvTypography>\n </Hidden>\n </>\n )}\n </div>\n <div className={classes.pageNavigator} {...navigationProps}>\n <HvIconButton\n id={setId(id, \"firstPage-button\")}\n className={classes.iconContainer}\n disabled={!canPrevious}\n onClick={() => changePage(0)}\n title={labels?.firstPage || labels?.paginationFirstPageTitle}\n >\n <Start className={classes.icon} iconSize=\"XS\" />\n </HvIconButton>\n <HvIconButton\n id={setId(id, \"previousPage-button\")}\n className={classes.iconContainer}\n disabled={!canPrevious}\n onClick={() => changePage(page - 1)}\n title={labels?.previousPage || labels?.paginationPreviousPageTitle}\n >\n <Backwards className={classes.icon} iconSize=\"XS\" />\n </HvIconButton>\n <div className={classes.pageInfo}>\n {showPageJump ? (\n renderPageJump()\n ) : (\n <HvTypography variant=\"caption2\" component=\"span\">{`${\n page + 1\n }`}</HvTypography>\n )}\n <HvTypography component=\"span\">{`${labels?.pagesSeparator} `}</HvTypography>\n <HvTypography\n component=\"span\"\n id={setId(id, \"totalPages\")}\n className={classes.totalPagesTextContainer}\n >\n {pages}\n </HvTypography>\n </div>\n <HvIconButton\n id={setId(id, \"nextPage-button\")}\n className={classes.iconContainer}\n disabled={!canNext}\n onClick={() => changePage(page + 1)}\n title={labels?.nextPage || labels?.paginationNextPageTitle}\n >\n <Forwards className={classes.icon} iconSize=\"XS\" />\n </HvIconButton>\n <HvIconButton\n id={setId(id, \"lastPage-button\")}\n className={classes.iconContainer}\n disabled={!canNext}\n onClick={() => changePage(pages - 1)}\n title={labels?.lastPage || labels?.paginationLastPageTitle}\n >\n <End className={classes.icon} iconSize=\"XS\" />\n </HvIconButton>\n </div>\n </div>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;AA2BA,MAAM,yBAAyB,CAAC,GAAG,IAAI,IAAI,IAAI,IAAI,GAAG;AAEtD,MAAM,iBAAiB;AAAA;AAAA,EAErB,cAAc;AAAA;AAAA,EAEd,mBAAmB;AAAA;AAAA,EAEnB,6BAA6B;AAAA;AAAA,EAE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AG,GAAA,QAAQ,cAAc,KAAI;AAAA,QAC7D;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,WAAU;AAAA,YACV,IAAI,MAAM,IAAI,YAAY;AAAA,YAC1B,WAAW,QAAQ;AAAA,YAElB,UAAA;AAAA,UAAA;AAAA,QACH;AAAA,MAAA,GACF;AAAA,MACA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,IAAI,MAAM,IAAI,iBAAiB;AAAA,UAC/B,WAAW,QAAQ;AAAA,UACnB,UAAU,CAAC;AAAA,UACX,SAAS,MAAM,WAAW,OAAO,CAAC;AAAA,UAClC,OAAO,QAAQ,YAAY,QAAQ;AAAA,UAEnC,8BAAC,UAAS,EAAA,WAAW,QAAQ,MAAM,UAAS,MAAK;AAAA,QAAA;AAAA,MACnD;AAAA,MACA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,IAAI,MAAM,IAAI,iBAAiB;AAAA,UAC/B,WAAW,QAAQ;AAAA,UACnB,UAAU,CAAC;AAAA,UACX,SAAS,MAAM,WAAW,QAAQ,CAAC;AAAA,UACnC,OAAO,QAAQ,YAAY,QAAQ;AAAA,UAEnC,8BAAC,KAAI,EAAA,WAAW,QAAQ,MAAM,UAAS,MAAK;AAAA,QAAA;AAAA,MAC9C;AAAA,IAAA,GACF;AAAA,EACF,EAAA,CAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"Pagination.js","sources":["../../../src/Pagination/Pagination.tsx"],"sourcesContent":["import { useCallback, useEffect, useState } from \"react\";\nimport Hidden from \"@mui/material/Hidden\";\nimport {\n Backwards,\n End,\n Forwards,\n Start,\n} from \"@hitachivantara/uikit-react-icons\";\nimport {\n clamp,\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { useLabels } from \"../hooks/useLabels\";\nimport { HvIconButton } from \"../IconButton\";\nimport { HvInput, HvInputProps } from \"../Input\";\nimport { HvBaseProps } from \"../types/generic\";\nimport { HvTypography } from \"../Typography\";\nimport { setId } from \"../utils/setId\";\nimport { staticClasses, useClasses } from \"./Pagination.styles\";\nimport HvSelect, { Option } from \"./Select\";\n\nexport { staticClasses as paginationClasses };\n\nexport type HvPaginationClasses = ExtractNames<typeof useClasses>;\n\nconst defaultPageSizeOptions = [5, 10, 20, 25, 50, 100];\n\nconst DEFAULT_LABELS = {\n /** The show label. */\n pageSizePrev: \"Show\",\n /** Indicate the units of the page size selection. */\n pageSizeEntryName: \"rows\",\n /** Used for the aria-label of the selection of number of unit.s */\n pageSizeSelectorDescription: \"Select how many to display\",\n /** Separator of current page and total pages. */\n pagesSeparator: \"/\",\n /** Title of button `firstPage`. @deprecated Use `firstPage` instead. */\n paginationFirstPageTitle: \"First page\",\n /** Title of button `previousPage`. @deprecated Use `previousPage` instead. */\n paginationPreviousPageTitle: \"Previous page\",\n /** Title of button `nextPage`. @deprecated Use `nextPage` instead. */\n paginationNextPageTitle: \"Next page\",\n /** Title of button `lastPage`. @deprecated Use `lastPage` instead. */\n paginationLastPageTitle: \"Last page\",\n /** Aria-label passed to the page input. */\n paginationInputLabel: \"Current page\",\n /** Label of the first page button */\n firstPage: \"First Page\",\n /** Label of the previous page button */\n previousPage: \"Previous Page\",\n /** Label of the next page button */\n nextPage: \"Next Page\",\n /** Label of the last page button */\n lastPage: \"Last Page\",\n};\n\nexport type HvPaginationLabels = Partial<typeof DEFAULT_LABELS>;\n\nexport interface HvPaginationProps extends HvBaseProps {\n /** The number of pages the component has. */\n pages?: number;\n /** The currently selected page (0-indexed). */\n page?: number;\n /** Controls whether the left page size mechanism should be visible. */\n showPageSizeOptions?: boolean;\n /** The array of possible page sizes for the dropdown. */\n pageSizeOptions?: number[];\n /** The currently selected page size. */\n pageSize?: number;\n /** Controls whether the central page changing mechanism should be visible. */\n showPageJump?: boolean;\n /** Controls whether the previous/first page buttons are enabled. */\n canPrevious?: boolean;\n /** Controls whether the next/last page buttons are enabled. */\n canNext?: boolean;\n /** Function called when the page changes. */\n onPageChange?: (page: number) => void;\n /** Function called when the page size changes. */\n onPageSizeChange?: (pageSize: number) => void;\n /** An object containing all the labels for the component. */\n labels?: HvPaginationLabels;\n /** Other props to show page component. */\n showPageProps?: React.HTMLAttributes<HTMLDivElement>;\n /** Other props to pagination component. */\n navigationProps?: React.HTMLAttributes<HTMLDivElement>;\n /** Extra properties passed to the input component representing the current pages. */\n currentPageInputProps?: HvInputProps;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvPaginationClasses;\n}\n\n/**\n * Pagination is the process of dividing a document into discrete pages. It relates to how users interact\n * with structured content on a website or application.\n */\nexport const HvPagination = (props: HvPaginationProps) => {\n const {\n classes: classesProp,\n className,\n id,\n pages = 1,\n page = 0,\n showPageSizeOptions = true,\n pageSizeOptions = defaultPageSizeOptions,\n pageSize = defaultPageSizeOptions[1],\n showPageJump = true,\n canPrevious = false,\n canNext = false,\n onPageChange,\n onPageSizeChange,\n labels: labelsProp,\n showPageProps,\n navigationProps,\n currentPageInputProps,\n ...others\n } = useDefaultProps(\"HvPagination\", props);\n const { classes, cx } = useClasses(classesProp);\n const labels = useLabels(DEFAULT_LABELS, labelsProp);\n\n const [pageInput, setPageInput] = useState(page);\n\n const changePage = useCallback(\n (newPage: number) => {\n const safePage = Number.isNaN(newPage) ? page : clamp(newPage, pages - 1);\n\n onPageChange?.(safePage);\n setPageInput(safePage);\n },\n [page, pages, onPageChange],\n );\n\n useEffect(() => {\n if (page >= pages && pages > 0) {\n changePage(page);\n }\n }, [changePage, page, pages]);\n\n useEffect(() => {\n setPageInput(page);\n }, [page]);\n\n const renderPageJump = () => (\n <div className={classes.pageJump}>\n <HvInput\n id={setId(id, \"currentPage\")}\n labels={labels}\n inputProps={{\n \"aria-label\": labels?.paginationInputLabel,\n // We really want the native number input\n type: \"number\",\n }}\n classes={{\n root: classes?.pageSizeInputContainer,\n input: classes?.pageSizeInput,\n inputRoot: classes?.pageSizeInputRoot,\n }}\n value={String(pageInput + 1)}\n onChange={(event, value) => setPageInput(Number(value) - 1)}\n onBlur={(evt, value) => changePage(Math.round(Number(value)) - 1)}\n onEnter={(evt, value) => changePage(Math.round(Number(value)) - 1)}\n disabled={pageSize === 0}\n disableClear\n {...currentPageInputProps}\n />\n </div>\n );\n\n return (\n <div id={id} className={cx(classes.root, className)} {...others}>\n <div className={classes.pageSizeOptions} {...showPageProps}>\n {showPageSizeOptions && (\n <>\n <Hidden xsDown>\n <HvTypography\n component=\"span\"\n className={classes?.pageSizeTextContainer}\n >\n {labels?.pageSizePrev}\n </HvTypography>\n </Hidden>\n <HvSelect\n id={setId(id, \"pageSize\")}\n disabled={pageSize === 0}\n className={classes.pageSizeOptionsSelect}\n aria-label={labels?.pageSizeSelectorDescription}\n onChange={(_: any, val: number) => onPageSizeChange?.(val)}\n value={pageSize}\n classes={{\n header: classes.pageSizeHeader,\n root: classes.pageSizeRoot,\n }}\n >\n {pageSizeOptions.map((option) => (\n <Option key={option} value={option}>\n {option}\n </Option>\n ))}\n </HvSelect>\n <Hidden xsDown>\n <HvTypography\n component=\"span\"\n className={classes.pageSizeTextContainer}\n >\n {labels?.pageSizeEntryName}\n </HvTypography>\n </Hidden>\n </>\n )}\n </div>\n <div className={classes.pageNavigator} {...navigationProps}>\n <HvIconButton\n id={setId(id, \"firstPage-button\")}\n className={classes.iconContainer}\n disabled={!canPrevious}\n onClick={() => changePage(0)}\n title={labels?.firstPage || labels?.paginationFirstPageTitle}\n >\n <Start className={classes.icon} iconSize=\"XS\" />\n </HvIconButton>\n <HvIconButton\n id={setId(id, \"previousPage-button\")}\n className={classes.iconContainer}\n disabled={!canPrevious}\n onClick={() => changePage(page - 1)}\n title={labels?.previousPage || labels?.paginationPreviousPageTitle}\n >\n <Backwards className={classes.icon} iconSize=\"XS\" />\n </HvIconButton>\n <div className={classes.pageInfo}>\n {showPageJump ? (\n renderPageJump()\n ) : (\n <HvTypography variant=\"caption2\" component=\"span\">{`${\n page + 1\n }`}</HvTypography>\n )}\n <HvTypography component=\"span\">{`${labels?.pagesSeparator} `}</HvTypography>\n <HvTypography\n component=\"span\"\n id={setId(id, \"totalPages\")}\n className={classes.totalPagesTextContainer}\n >\n {pages}\n </HvTypography>\n </div>\n <HvIconButton\n id={setId(id, \"nextPage-button\")}\n className={classes.iconContainer}\n disabled={!canNext}\n onClick={() => changePage(page + 1)}\n title={labels?.nextPage || labels?.paginationNextPageTitle}\n >\n <Forwards className={classes.icon} iconSize=\"XS\" />\n </HvIconButton>\n <HvIconButton\n id={setId(id, \"lastPage-button\")}\n className={classes.iconContainer}\n disabled={!canNext}\n onClick={() => changePage(pages - 1)}\n title={labels?.lastPage || labels?.paginationLastPageTitle}\n >\n <End className={classes.icon} iconSize=\"XS\" />\n </HvIconButton>\n </div>\n </div>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;AA2BA,MAAM,yBAAyB,CAAC,GAAG,IAAI,IAAI,IAAI,IAAI,GAAG;AAEtD,MAAM,iBAAiB;AAAA;AAAA,EAErB,cAAc;AAAA;AAAA,EAEd,mBAAmB;AAAA;AAAA,EAEnB,6BAA6B;AAAA;AAAA,EAE7B,gBAAgB;AAAA;AAAA,EAEhB,0BAA0B;AAAA;AAAA,EAE1B,6BAA6B;AAAA;AAAA,EAE7B,yBAAyB;AAAA;AAAA,EAEzB,yBAAyB;AAAA;AAAA,EAEzB,sBAAsB;AAAA;AAAA,EAEtB,WAAW;AAAA;AAAA,EAEX,cAAc;AAAA;AAAA,EAEd,UAAU;AAAA;AAAA,EAEV,UAAU;AACZ;AAyCa,MAAA,eAAe,CAAC,UAA6B;AAClD,QAAA;AAAA,IACJ,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,sBAAsB;AAAA,IACtB,kBAAkB;AAAA,IAClB,WAAW,uBAAuB,CAAC;AAAA,IACnC,eAAe;AAAA,IACf,cAAc;AAAA,IACd,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA;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,UAC/B,WAAW,QAAQ;AAAA,UACnB,UAAU,CAAC;AAAA,UACX,SAAS,MAAM,WAAW,QAAQ,CAAC;AAAA,UACnC,OAAO,QAAQ,YAAY,QAAQ;AAAA,UAEnC,8BAAC,KAAI,EAAA,WAAW,QAAQ,MAAM,UAAS,MAAK;AAAA,QAAA;AAAA,MAC9C;AAAA,IAAA,GACF;AAAA,EACF,EAAA,CAAA;AAEJ;"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useDefaultProps } from "@hitachivantara/uikit-react-utils";
|
|
3
|
-
import { clamp } from "../utils/helpers.js";
|
|
2
|
+
import { useDefaultProps, clamp } from "@hitachivantara/uikit-react-utils";
|
|
4
3
|
import { useClasses } from "./ProgressBar.styles.js";
|
|
5
4
|
import { staticClasses } from "./ProgressBar.styles.js";
|
|
6
5
|
import { HvTypography } from "../Typography/Typography.js";
|