@hitachivantara/uikit-react-core 5.68.1 → 5.70.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/Card/Content/Content.cjs +10 -8
- package/dist/cjs/Carousel/Carousel.cjs +2 -3
- package/dist/cjs/Forms/Adornment/Adornment.cjs +11 -3
- package/dist/cjs/Forms/Adornment/Adornment.styles.cjs +6 -0
- package/dist/cjs/Header/Header.cjs +3 -9
- package/dist/cjs/Header/Header.styles.cjs +3 -3
- 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/VerticalNavigation/TreeView/TreeViewItem.cjs +6 -4
- 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/Card/Content/Content.js +10 -8
- package/dist/esm/Card/Content/Content.js.map +1 -1
- package/dist/esm/Carousel/Carousel.js +2 -3
- package/dist/esm/Carousel/Carousel.js.map +1 -1
- package/dist/esm/Forms/Adornment/Adornment.js +11 -3
- package/dist/esm/Forms/Adornment/Adornment.js.map +1 -1
- package/dist/esm/Forms/Adornment/Adornment.styles.js +6 -0
- package/dist/esm/Forms/Adornment/Adornment.styles.js.map +1 -1
- package/dist/esm/Header/Actions/Actions.styles.js.map +1 -1
- package/dist/esm/Header/Brand/Brand.styles.js.map +1 -1
- package/dist/esm/Header/Header.js +3 -9
- package/dist/esm/Header/Header.js.map +1 -1
- package/dist/esm/Header/Header.styles.js +3 -3
- package/dist/esm/Header/Header.styles.js.map +1 -1
- package/dist/esm/Header/Navigation/MenuBar/Bar.styles.js.map +1 -1
- package/dist/esm/Header/Navigation/MenuItem/MenuItem.styles.js.map +1 -1
- package/dist/esm/Header/Navigation/Navigation.styles.js.map +1 -1
- package/dist/esm/Input/Input.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/VerticalNavigation/TreeView/TreeViewItem.js +7 -5
- package/dist/esm/VerticalNavigation/TreeView/TreeViewItem.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 +372 -297
- package/package.json +7 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx,
|
|
1
|
+
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useState, useMemo } from "react";
|
|
3
3
|
import { isKey } from "../../utils/keyboardUtils.js";
|
|
4
4
|
import { setId } from "../../utils/setId.js";
|
|
@@ -10,6 +10,7 @@ import { useClasses } from "./SingleCalendar.styles.js";
|
|
|
10
10
|
import { staticClasses } from "./SingleCalendar.styles.js";
|
|
11
11
|
import { HvComposedNavigation } from "../CalendarNavigation/ComposedNavigation/ComposedNavigation.js";
|
|
12
12
|
import { HvMonthSelector } from "../CalendarNavigation/MonthSelector/MonthSelector.js";
|
|
13
|
+
import { HvPanel } from "../../Panel/Panel.js";
|
|
13
14
|
import { HvTypography } from "../../Typography/Typography.js";
|
|
14
15
|
const HvSingleCalendar = ({
|
|
15
16
|
classes: classesProp,
|
|
@@ -97,7 +98,7 @@ const HvSingleCalendar = ({
|
|
|
97
98
|
currentDate.toString()
|
|
98
99
|
);
|
|
99
100
|
};
|
|
100
|
-
return /* @__PURE__ */
|
|
101
|
+
return /* @__PURE__ */ jsxs(HvPanel, { id, className: cx(classes.root, className), ...others, children: [
|
|
101
102
|
/* @__PURE__ */ jsx(
|
|
102
103
|
HvCalendarHeader,
|
|
103
104
|
{
|
|
@@ -109,7 +110,7 @@ const HvSingleCalendar = ({
|
|
|
109
110
|
invalidDateLabel
|
|
110
111
|
}
|
|
111
112
|
),
|
|
112
|
-
calViewMode === "calendar" && /* @__PURE__ */ jsxs(
|
|
113
|
+
calViewMode === "calendar" && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
113
114
|
/* @__PURE__ */ jsx(
|
|
114
115
|
HvComposedNavigation,
|
|
115
116
|
{
|
|
@@ -144,7 +145,7 @@ const HvSingleCalendar = ({
|
|
|
144
145
|
rangeMode
|
|
145
146
|
}
|
|
146
147
|
)
|
|
147
|
-
] })
|
|
148
|
+
] });
|
|
148
149
|
};
|
|
149
150
|
export {
|
|
150
151
|
HvSingleCalendar,
|
|
@@ -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 *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;AAAA,QACtB;AAAA,QACA,UAAU;AAAA,QACV,aAAa,eAAe,CAAC;AAAA,QAC7B;AAAA,QACA;AAAA,MAAA;AAAA,IACF;AAAA,IACC,gBAAgB,cACf,qBAAC,OACC,EAAA,UAAA;AAAA,MAAA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA,UAAU;AAAA,UACV,kBAAkB;AAAA,UAClB,aAAa,eAAe,MAAM,YAAY;AAAA,UAC9C,cAAc,gBAAgB,MAAM,SAAa,IAAA;AAAA,QAAA;AAAA,MACnD;AAAA,MACA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,WAAW,QAAQ;AAAA,UAEnB,iBAAe,mBAAmB,CAAC,GAAG;AAAA,UAErC,UAAA;AAAA,YAAA,iBAAiB,IAAI,eAAe;AAAA,YACpC,SAAS,MAAM,IAAI,kBAAkB;AAAA,UAAA;AAAA,QAAA;AAAA,MACxC;AAAA,IAAA,GACF;AAAA,IAED,gBAAgB,aACf;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA,UAAU;AAAA,QACV,kBAAkB;AAAA,QAClB,cAAc,gBAAgB,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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V,aAAa,eAAe,CAAC;AAAA,QAC7B;AAAA,QACA;AAAA,MAAA;AAAA,IACF;AAAA,IACC,gBAAgB,cAEb,qBAAA,UAAA,EAAA,UAAA;AAAA,MAAA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA,UAAU;AAAA,UACV,kBAAkB;AAAA,UAClB,aAAa,eAAe,MAAM,YAAY;AAAA,UAC9C,cAAc,gBAAgB,MAAM,SAAa,IAAA;AAAA,QAAA;AAAA,MACnD;AAAA,MACA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,WAAW,QAAQ;AAAA,UAEnB,iBAAe,mBAAmB,CAAC,GAAG;AAAA,UAErC,UAAA;AAAA,YAAA,iBAAiB,IAAI,eAAe;AAAA,YACpC,SAAS,MAAM,IAAI,kBAAkB;AAAA,UAAA;AAAA,QAAA;AAAA,MACxC;AAAA,IAAA,GACF;AAAA,IAED,gBAAgB,aACf;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA,UAAU;AAAA,QACV,kBAAkB;AAAA,QAClB,cAAc,gBAAgB,MAAM,SAAa,IAAA;AAAA,QACjD;AAAA,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.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,C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G,GAAG;AAAA,EAAA,CACjE;AAED,SAAO,CAAC,GAAG,gBAAgB,GAAG,mBAAmB,GAAG,cAAc;AACpE;AAEa,MAAA,UAAU,CAAC,SACtB,QAAQ,QAAQ,OAAO,SAAS,YAAY,eAAe;AAShD,MAAA,2BAA2B,CACtC,MACA,uBACG;AACG,QAAA,EAAE,WAAW,QAAY,IAAA;AAE/B,MAAI,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;"}
|
|
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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AO,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,15 +1,17 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import MuiCardContent from "@mui/material/CardContent";
|
|
3
|
+
import { useDefaultProps } from "@hitachivantara/uikit-react-utils";
|
|
3
4
|
import { useClasses } from "./Content.styles.js";
|
|
4
5
|
import { staticClasses } from "./Content.styles.js";
|
|
5
|
-
const HvCardContent = ({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
const HvCardContent = (props) => {
|
|
7
|
+
const {
|
|
8
|
+
id,
|
|
9
|
+
classes: classesProp,
|
|
10
|
+
className,
|
|
11
|
+
children,
|
|
12
|
+
onClick,
|
|
13
|
+
...others
|
|
14
|
+
} = useDefaultProps("HvCardContent", props);
|
|
13
15
|
const { classes, cx } = useClasses(classesProp);
|
|
14
16
|
return /* @__PURE__ */ jsx(
|
|
15
17
|
MuiCardContent,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Content.js","sources":["../../../../src/Card/Content/Content.tsx"],"sourcesContent":["import MuiCardContent, {\n CardContentProps as MuiCardContentProps,\n} from \"@mui/material/CardContent\";\nimport {
|
|
1
|
+
{"version":3,"file":"Content.js","sources":["../../../../src/Card/Content/Content.tsx"],"sourcesContent":["import MuiCardContent, {\n CardContentProps as MuiCardContentProps,\n} from \"@mui/material/CardContent\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { staticClasses, useClasses } from \"./Content.styles\";\n\nexport { staticClasses as cardContentClasses };\n\nexport type HvCardContentClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvCardContentProps\n extends Omit<MuiCardContentProps, \"classes\"> {\n /** The function that will be executed when this section is clicked. */\n onClick?: (event: React.SyntheticEvent) => void;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvCardContentClasses;\n}\n\nexport const HvCardContent = (props: HvCardContentProps) => {\n const {\n id,\n classes: classesProp,\n className,\n children,\n onClick,\n ...others\n } = useDefaultProps(\"HvCardContent\", props);\n const { classes, cx } = useClasses(classesProp);\n\n return (\n <MuiCardContent\n id={id}\n className={cx(classes.content, className)}\n onClick={onClick}\n {...others}\n >\n {children}\n </MuiCardContent>\n );\n};\n"],"names":[],"mappings":";;;;;AAsBa,MAAA,gBAAgB,CAAC,UAA8B;AACpD,QAAA;AAAA,IACJ;AAAA,IACA,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,IACD,gBAAgB,iBAAiB,KAAK;AAC1C,QAAM,EAAE,SAAS,GAAG,IAAI,WAAW,WAAW;AAG5C,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC;AAAA,MACA,WAAW,GAAG,QAAQ,SAAS,SAAS;AAAA,MACxC;AAAA,MACC,GAAG;AAAA,MAEH;AAAA,IAAA;AAAA,EAAA;AAGP;"}
|
|
@@ -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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AA,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
|
+
{"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,I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AAgB,CAAC,IAAI,SAAS,GACpC,CAAA,GACF;AAAA,cAGD,qBACC,qBAAC,OAAI,EAAA,WAAW,QAAQ,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;"}
|
|
@@ -18,7 +18,7 @@ const HvAdornment = forwardRef(
|
|
|
18
18
|
...others
|
|
19
19
|
}, ref) => {
|
|
20
20
|
const { classes, cx } = useClasses(classesProp);
|
|
21
|
-
const { elementStatus = "" } = useContext(HvFormElementContext);
|
|
21
|
+
const { elementStatus = "", elementDisabled } = useContext(HvFormElementContext);
|
|
22
22
|
const { input } = useContext(HvFormElementDescriptorsContext);
|
|
23
23
|
const displayIcon = isVisible ?? (showWhen === void 0 || elementStatus === showWhen);
|
|
24
24
|
const isClickable = !!onClick;
|
|
@@ -34,12 +34,17 @@ const HvAdornment = forwardRef(
|
|
|
34
34
|
classes.root,
|
|
35
35
|
classes.adornment,
|
|
36
36
|
classes.adornmentButton,
|
|
37
|
-
{
|
|
37
|
+
{
|
|
38
|
+
[classes.hideIcon]: !displayIcon,
|
|
39
|
+
[classes.disabled]: elementDisabled
|
|
40
|
+
},
|
|
38
41
|
className
|
|
39
42
|
),
|
|
40
43
|
onClick,
|
|
41
44
|
onMouseDown: (event) => event.preventDefault(),
|
|
42
45
|
onKeyDown: noop,
|
|
46
|
+
disabled: elementDisabled,
|
|
47
|
+
"aria-disabled": elementDisabled,
|
|
43
48
|
...others,
|
|
44
49
|
children: /* @__PURE__ */ jsx("div", { className: classes.icon, children: icon })
|
|
45
50
|
}
|
|
@@ -52,7 +57,10 @@ const HvAdornment = forwardRef(
|
|
|
52
57
|
classes.root,
|
|
53
58
|
classes.adornment,
|
|
54
59
|
classes.adornmentIcon,
|
|
55
|
-
{
|
|
60
|
+
{
|
|
61
|
+
[classes.hideIcon]: !displayIcon,
|
|
62
|
+
[classes.disabled]: elementDisabled
|
|
63
|
+
},
|
|
56
64
|
className
|
|
57
65
|
),
|
|
58
66
|
role: "presentation",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Adornment.js","sources":["../../../../src/Forms/Adornment/Adornment.tsx"],"sourcesContent":["import { forwardRef, useContext } from \"react\";\nimport { type ExtractNames } from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvBaseProps } from \"../../types/generic\";\nimport {\n HvFormElementContext,\n HvFormElementDescriptorsContext,\n HvFormStatus,\n} from \"../FormElement\";\nimport { staticClasses, useClasses } from \"./Adornment.styles\";\n\nconst noop = () => {};\n\nexport { staticClasses as adornmentClasses };\n\nexport type HvAdornmentClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvAdornmentProps\n extends HvBaseProps<\n HTMLDivElement | HTMLButtonElement,\n \"onMouseDown\" | \"onKeyDown\"\n > {\n /** The icon to be added into the input. */\n icon: React.ReactNode;\n /** When the adornment should be displayed. */\n showWhen?: HvFormStatus;\n /** Function to be executed when this element is clicked. */\n onClick?: React.MouseEventHandler<HTMLButtonElement>;\n /** If this property is defined the adornment visibility will be exclusively controlled by this value. */\n isVisible?: boolean;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvAdornmentClasses;\n}\n\n/**\n * Allows to add a decorative icon or an action to a form element, usually on the right side of an input.\n * E.g., the reveal password button.\n *\n * In addition to the showWhen feature, which uses the form element's context validation state to determine\n * its visibility, this component also ensures that it does not steal focus from the input and that it is\n * not accessible using the keyboard.\n *\n * As such, its functionality, if any, for accessibility purposes must be provided through an alternative mean,\n * or by using a regular icon button or toggle button instead.\n */\nexport const HvAdornment = forwardRef<\n HTMLDivElement | HTMLButtonElement,\n HvAdornmentProps\n>(\n (\n {\n id,\n classes: classesProp,\n className,\n icon,\n showWhen = undefined,\n onClick,\n isVisible = undefined,\n ...others\n },\n ref,\n ) => {\n const { classes, cx } = useClasses(classesProp);\n\n const { elementStatus = \"\" }
|
|
1
|
+
{"version":3,"file":"Adornment.js","sources":["../../../../src/Forms/Adornment/Adornment.tsx"],"sourcesContent":["import { forwardRef, useContext } from \"react\";\nimport { type ExtractNames } from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvBaseProps } from \"../../types/generic\";\nimport {\n HvFormElementContext,\n HvFormElementDescriptorsContext,\n HvFormStatus,\n} from \"../FormElement\";\nimport { staticClasses, useClasses } from \"./Adornment.styles\";\n\nconst noop = () => {};\n\nexport { staticClasses as adornmentClasses };\n\nexport type HvAdornmentClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvAdornmentProps\n extends HvBaseProps<\n HTMLDivElement | HTMLButtonElement,\n \"onMouseDown\" | \"onKeyDown\"\n > {\n /** The icon to be added into the input. */\n icon: React.ReactNode;\n /** When the adornment should be displayed. */\n showWhen?: HvFormStatus;\n /** Function to be executed when this element is clicked. */\n onClick?: React.MouseEventHandler<HTMLButtonElement>;\n /** If this property is defined the adornment visibility will be exclusively controlled by this value. */\n isVisible?: boolean;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvAdornmentClasses;\n}\n\n/**\n * Allows to add a decorative icon or an action to a form element, usually on the right side of an input.\n * E.g., the reveal password button.\n *\n * In addition to the showWhen feature, which uses the form element's context validation state to determine\n * its visibility, this component also ensures that it does not steal focus from the input and that it is\n * not accessible using the keyboard.\n *\n * As such, its functionality, if any, for accessibility purposes must be provided through an alternative mean,\n * or by using a regular icon button or toggle button instead.\n */\nexport const HvAdornment = forwardRef<\n HTMLDivElement | HTMLButtonElement,\n HvAdornmentProps\n>(\n (\n {\n id,\n classes: classesProp,\n className,\n icon,\n showWhen = undefined,\n onClick,\n isVisible = undefined,\n ...others\n },\n ref,\n ) => {\n const { classes, cx } = useClasses(classesProp);\n\n const { elementStatus = \"\", elementDisabled } =\n useContext(HvFormElementContext);\n\n const { input } = useContext(HvFormElementDescriptorsContext);\n\n const displayIcon =\n isVisible ?? (showWhen === undefined || elementStatus === showWhen);\n\n const isClickable = !!onClick;\n\n return isClickable ? (\n <button\n id={id}\n ref={ref as React.ForwardedRef<HTMLButtonElement>}\n type=\"button\"\n tabIndex={-1}\n aria-controls={input?.[0]?.id}\n className={cx(\n classes.root,\n classes.adornment,\n classes.adornmentButton,\n {\n [classes.hideIcon]: !displayIcon,\n [classes.disabled]: elementDisabled,\n },\n className,\n )}\n onClick={onClick}\n onMouseDown={(event) => event.preventDefault()}\n onKeyDown={noop}\n disabled={elementDisabled}\n aria-disabled={elementDisabled}\n {...others}\n >\n <div className={classes.icon}>{icon}</div>\n </button>\n ) : (\n <div\n id={id}\n ref={ref as React.ForwardedRef<HTMLDivElement>}\n className={cx(\n classes.root,\n classes.adornment,\n classes.adornmentIcon,\n {\n [classes.hideIcon]: !displayIcon,\n [classes.disabled]: elementDisabled,\n },\n className,\n )}\n role=\"presentation\"\n {...others}\n >\n <div className={classes.icon}>{icon}</div>\n </div>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AAAA,UACtB;AAAA,UACA;AAAA,QACF;AAAA,QACA,MAAK;AAAA,QACJ,GAAG;AAAA,QAEJ,UAAC,oBAAA,OAAA,EAAI,WAAW,QAAQ,MAAO,UAAK,MAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAG1C;AACF;"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createClasses } from "@hitachivantara/uikit-react-utils";
|
|
2
|
+
import { theme } from "@hitachivantara/uikit-styles";
|
|
2
3
|
import { outlineStyles } from "../../utils/focusUtils.js";
|
|
3
4
|
const { staticClasses, useClasses } = createClasses("HvAdornment", {
|
|
4
5
|
root: {},
|
|
@@ -16,6 +17,11 @@ const { staticClasses, useClasses } = createClasses("HvAdornment", {
|
|
|
16
17
|
"&:focus": {
|
|
17
18
|
...outlineStyles
|
|
18
19
|
}
|
|
20
|
+
},
|
|
21
|
+
disabled: {
|
|
22
|
+
"&$adornmentButton": { cursor: "not-allowed" },
|
|
23
|
+
"&$adornmentIcon": { cursor: "not-allowed" },
|
|
24
|
+
"& svg *.color0": { fill: theme.colors.secondary_60 }
|
|
19
25
|
}
|
|
20
26
|
});
|
|
21
27
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Adornment.styles.js","sources":["../../../../src/Forms/Adornment/Adornment.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\n\nimport { outlineStyles } from \"../../utils/focusUtils\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvAdornment\", {\n root: {},\n icon: { width: 32, height: 32 },\n adornment: {\n backgroundColor: \"transparent\",\n border: \"none\",\n padding: 0,\n margin: 0,\n },\n adornmentIcon: { cursor: \"default\", pointerEvents: \"none\" },\n hideIcon: { display: \"none\" },\n adornmentButton: {\n cursor: \"pointer\",\n \"&:focus\": {\n ...outlineStyles,\n },\n },\n});\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Adornment.styles.js","sources":["../../../../src/Forms/Adornment/Adornment.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nimport { outlineStyles } from \"../../utils/focusUtils\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvAdornment\", {\n root: {},\n icon: { width: 32, height: 32 },\n adornment: {\n backgroundColor: \"transparent\",\n border: \"none\",\n padding: 0,\n margin: 0,\n },\n adornmentIcon: { cursor: \"default\", pointerEvents: \"none\" },\n hideIcon: { display: \"none\" },\n adornmentButton: {\n cursor: \"pointer\",\n \"&:focus\": {\n ...outlineStyles,\n },\n },\n disabled: {\n \"&$adornmentButton\": { cursor: \"not-allowed\" },\n \"&$adornmentIcon\": { cursor: \"not-allowed\" },\n \"& svg *.color0\": { fill: theme.colors.secondary_60 },\n },\n});\n"],"names":[],"mappings":";;;AAKO,MAAM,EAAE,eAAe,eAAe,cAAc,eAAe;AAAA,EACxE,MAAM,CAAC;AAAA,EACP,MAAM,EAAE,OAAO,IAAI,QAAQ,GAAG;AAAA,EAC9B,WAAW;AAAA,IACT,iBAAiB;AAAA,IACjB,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,QAAQ;AAAA,EACV;AAAA,EACA,eAAe,EAAE,QAAQ,WAAW,eAAe,OAAO;AAAA,EAC1D,UAAU,EAAE,SAAS,OAAO;AAAA,EAC5B,iBAAiB;AAAA,IACf,QAAQ;AAAA,IACR,WAAW;AAAA,MACT,GAAG;AAAA,IACL;AAAA,EACF;AAAA,EACA,UAAU;AAAA,IACR,qBAAqB,EAAE,QAAQ,cAAc;AAAA,IAC7C,mBAAmB,EAAE,QAAQ,cAAc;AAAA,IAC3C,kBAAkB,EAAE,MAAM,MAAM,OAAO,aAAa;AAAA,EACtD;AACF,CAAC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Actions.styles.js","sources":["../../../../src/Header/Actions/Actions.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nimport { buttonClasses } from \"../../Button\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvHeader-Actions\", {\n root: {\n backgroundColor: \"transparent\",\n display: \"flex\",\n gap: theme.space.xs,\n alignItems: \"center\",\n marginLeft: \"auto\",\n [`& .${buttonClasses?.root}`]: {\n \"&:hover\": { backgroundColor: theme.colors.containerBackgroundHover },\n },\n },\n});\n"],"names":["buttonClasses"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"Actions.styles.js","sources":["../../../../src/Header/Actions/Actions.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nimport { buttonClasses } from \"../../Button\";\n\n// TODO - rename to HvHeaderActions (the actual component's name) in v6\nexport const { staticClasses, useClasses } = createClasses(\"HvHeader-Actions\", {\n root: {\n backgroundColor: \"transparent\",\n display: \"flex\",\n gap: theme.space.xs,\n alignItems: \"center\",\n marginLeft: \"auto\",\n [`& .${buttonClasses?.root}`]: {\n \"&:hover\": { backgroundColor: theme.colors.containerBackgroundHover },\n },\n },\n});\n"],"names":["buttonClasses"],"mappings":";;;;AAMO,MAAM,EAAE,eAAe,eAAe,cAAc,oBAAoB;AAAA,EAC7E,MAAM;AAAA,IACJ,iBAAiB;AAAA,IACjB,SAAS;AAAA,IACT,KAAK,MAAM,MAAM;AAAA,IACjB,YAAY;AAAA,IACZ,YAAY;AAAA,IACZ,CAAC,MAAMA,iBAAe,IAAI,EAAE,GAAG;AAAA,MAC7B,WAAW,EAAE,iBAAiB,MAAM,OAAO,yBAAyB;AAAA,IACtE;AAAA,EACF;AACF,CAAC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Brand.styles.js","sources":["../../../../src/Header/Brand/Brand.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvHeader-Brand\", {\n root: { display: \"flex\", alignItems: \"center\" },\n separator: {\n width: 1,\n height: theme.space.sm,\n margin: theme.space.xs,\n backgroundColor: theme.colors.secondary,\n },\n brandName: {},\n});\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"Brand.styles.js","sources":["../../../../src/Header/Brand/Brand.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\n// TODO - rename to HvHeaderBrand (the actual component's name) in v6\nexport const { staticClasses, useClasses } = createClasses(\"HvHeader-Brand\", {\n root: { display: \"flex\", alignItems: \"center\" },\n separator: {\n width: 1,\n height: theme.space.sm,\n margin: theme.space.xs,\n backgroundColor: theme.colors.secondary,\n },\n brandName: {},\n});\n"],"names":[],"mappings":";;AAIO,MAAM,EAAE,eAAe,eAAe,cAAc,kBAAkB;AAAA,EAC3E,MAAM,EAAE,SAAS,QAAQ,YAAY,SAAS;AAAA,EAC9C,WAAW;AAAA,IACT,OAAO;AAAA,IACP,QAAQ,MAAM,MAAM;AAAA,IACpB,QAAQ,MAAM,MAAM;AAAA,IACpB,iBAAiB,MAAM,OAAO;AAAA,EAChC;AAAA,EACA,WAAW,CAAC;AACd,CAAC;"}
|
|
@@ -10,21 +10,15 @@ const HvHeader = (props) => {
|
|
|
10
10
|
position = "fixed",
|
|
11
11
|
...others
|
|
12
12
|
} = useDefaultProps("HvHeader", props);
|
|
13
|
-
const { classes, cx
|
|
13
|
+
const { classes, cx } = useClasses(classesProp);
|
|
14
14
|
return /* @__PURE__ */ jsx(
|
|
15
15
|
"header",
|
|
16
16
|
{
|
|
17
|
+
style: { position },
|
|
17
18
|
className: cx(
|
|
18
19
|
classes.root,
|
|
19
20
|
classes.backgroundColor,
|
|
20
|
-
|
|
21
|
-
position,
|
|
22
|
-
...position === "fixed" && {
|
|
23
|
-
top: 0,
|
|
24
|
-
left: "auto",
|
|
25
|
-
right: 0
|
|
26
|
-
}
|
|
27
|
-
}),
|
|
21
|
+
{ [classes.fixed]: position === "fixed" },
|
|
28
22
|
className
|
|
29
23
|
),
|
|
30
24
|
...others,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Header.js","sources":["../../../src/Header/Header.tsx"],"sourcesContent":["import {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvBaseProps } from \"../types/generic\";\nimport { staticClasses, useClasses } from \"./Header.styles\";\n\nexport { staticClasses as headerClasses };\n\nexport type HvHeaderClasses = ExtractNames<typeof useClasses>;\n\nexport type HvHeaderPosition =\n | \"fixed\"\n | \"absolute\"\n | \"sticky\"\n | \"static\"\n | \"relative\";\n\nexport interface HvHeaderProps extends HvBaseProps {\n /** The position of the header bar */\n position?: HvHeaderPosition;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvHeaderClasses;\n}\n\n/**\n * Header component is used to render a header bar with logo and brand name, navigation and actions.\n */\nexport const HvHeader = (props: HvHeaderProps) => {\n const {\n className,\n classes: classesProp,\n children,\n position = \"fixed\",\n ...others\n } = useDefaultProps(\"HvHeader\", props);\n\n const { classes, cx
|
|
1
|
+
{"version":3,"file":"Header.js","sources":["../../../src/Header/Header.tsx"],"sourcesContent":["import {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvBaseProps } from \"../types/generic\";\nimport { staticClasses, useClasses } from \"./Header.styles\";\n\nexport { staticClasses as headerClasses };\n\nexport type HvHeaderClasses = ExtractNames<typeof useClasses>;\n\nexport type HvHeaderPosition =\n | \"fixed\"\n | \"absolute\"\n | \"sticky\"\n | \"static\"\n | \"relative\";\n\nexport interface HvHeaderProps extends HvBaseProps {\n /** The position of the header bar */\n position?: HvHeaderPosition;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvHeaderClasses;\n}\n\n/**\n * Header component is used to render a header bar with logo and brand name, navigation and actions.\n */\nexport const HvHeader = (props: HvHeaderProps) => {\n const {\n className,\n classes: classesProp,\n children,\n position = \"fixed\",\n ...others\n } = useDefaultProps(\"HvHeader\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n return (\n <header\n style={{ position }}\n className={cx(\n classes.root,\n classes.backgroundColor,\n { [classes.fixed]: position === \"fixed\" },\n className,\n )}\n {...others}\n >\n <div className={classes.header}>{children}</div>\n </header>\n );\n};\n"],"names":[],"mappings":";;;;AA6Ba,MAAA,WAAW,CAAC,UAAyB;AAC1C,QAAA;AAAA,IACJ;AAAA,IACA,SAAS;AAAA,IACT;AAAA,IACA,WAAW;AAAA,IACX,GAAG;AAAA,EAAA,IACD,gBAAgB,YAAY,KAAK;AAErC,QAAM,EAAE,SAAS,GAAG,IAAI,WAAW,WAAW;AAG5C,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,OAAO,EAAE,SAAS;AAAA,MAClB,WAAW;AAAA,QACT,QAAQ;AAAA,QACR,QAAQ;AAAA,QACR,EAAE,CAAC,QAAQ,KAAK,GAAG,aAAa,QAAQ;AAAA,QACxC;AAAA,MACF;AAAA,MACC,GAAG;AAAA,MAEJ,UAAC,oBAAA,OAAA,EAAI,WAAW,QAAQ,QAAS,UAAS;AAAA,IAAA;AAAA,EAAA;AAGhD;"}
|
|
@@ -10,8 +10,8 @@ const { staticClasses, useClasses } = createClasses("HvHeader", {
|
|
|
10
10
|
boxSizing: "border-box",
|
|
11
11
|
flexShrink: 0,
|
|
12
12
|
zIndex: theme.zIndices.banner,
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
borderTop: "none",
|
|
14
|
+
boxShadow: theme.colors.shadow
|
|
15
15
|
},
|
|
16
16
|
header: {
|
|
17
17
|
display: "flex",
|
|
@@ -19,11 +19,11 @@ const { staticClasses, useClasses } = createClasses("HvHeader", {
|
|
|
19
19
|
width: "100%",
|
|
20
20
|
height: "100%",
|
|
21
21
|
padding: `0 ${theme.space.sm}`,
|
|
22
|
-
boxShadow: theme.colors.shadow,
|
|
23
22
|
"& > *:not(nav)": {
|
|
24
23
|
zIndex: 2
|
|
25
24
|
}
|
|
26
25
|
},
|
|
26
|
+
fixed: { position: "fixed", top: 0, left: "auto", right: 0 },
|
|
27
27
|
backgroundColor: {}
|
|
28
28
|
});
|
|
29
29
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Header.styles.js","sources":["../../../src/Header/Header.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvHeader\", {\n root: {\n height: theme.header.height,\n backgroundColor: theme.colors.atmo1,\n display: \"flex\",\n flexDirection: \"column\",\n width: \"100%\",\n boxSizing: \"border-box\",\n flexShrink: 0,\n zIndex: theme.zIndices.banner,\n boxShadow: theme.colors.shadow,\n
|
|
1
|
+
{"version":3,"file":"Header.styles.js","sources":["../../../src/Header/Header.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvHeader\", {\n root: {\n height: theme.header.height,\n backgroundColor: theme.colors.atmo1,\n display: \"flex\",\n flexDirection: \"column\",\n width: \"100%\",\n boxSizing: \"border-box\",\n flexShrink: 0,\n zIndex: theme.zIndices.banner,\n borderTop: \"none\",\n boxShadow: theme.colors.shadow,\n },\n header: {\n display: \"flex\",\n alignItems: \"center\",\n width: \"100%\",\n height: \"100%\",\n padding: `0 ${theme.space.sm}`,\n \"& > *:not(nav)\": {\n zIndex: 2,\n },\n },\n fixed: { position: \"fixed\", top: 0, left: \"auto\", right: 0 },\n backgroundColor: {},\n});\n"],"names":[],"mappings":";;AAGO,MAAM,EAAE,eAAe,eAAe,cAAc,YAAY;AAAA,EACrE,MAAM;AAAA,IACJ,QAAQ,MAAM,OAAO;AAAA,IACrB,iBAAiB,MAAM,OAAO;AAAA,IAC9B,SAAS;AAAA,IACT,eAAe;AAAA,IACf,OAAO;AAAA,IACP,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,QAAQ,MAAM,SAAS;AAAA,IACvB,WAAW;AAAA,IACX,WAAW,MAAM,OAAO;AAAA,EAC1B;AAAA,EACA,QAAQ;AAAA,IACN,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,SAAS,KAAK,MAAM,MAAM,EAAE;AAAA,IAC5B,kBAAkB;AAAA,MAChB,QAAQ;AAAA,IACV;AAAA,EACF;AAAA,EACA,OAAO,EAAE,UAAU,SAAS,KAAK,GAAG,MAAM,QAAQ,OAAO,EAAE;AAAA,EAC3D,iBAAiB,CAAC;AACpB,CAAC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Bar.styles.js","sources":["../../../../../src/Header/Navigation/MenuBar/Bar.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nconst show = {\n top: theme.header.height,\n transition: [\"top\"],\n boxShadow: theme.colors.shadow,\n transitionDuration: \"500ms\",\n backgroundColor: theme.colors.atmo2,\n};\n\nconst hide = {\n top: 0,\n transition: [\"top\"],\n boxShadow: \"none\",\n transitionDuration: \"300ms\",\n};\n\nexport const { staticClasses, useClasses } = createClasses(\"HvHeader-MenuBar\", {\n root: {\n left: 0,\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n justifyContent: \"center\",\n alignItems: \"center\",\n },\n menu: {\n position: \"absolute\",\n zIndex: -2,\n height: theme.header.secondLevelHeight,\n backgroundColor: theme.colors.atmo2,\n \"& li > div\": {\n marginTop: 0,\n },\n },\n menubar: {\n position: \"relative\",\n backgroundColor: theme.colors.atmo1,\n },\n hidden: { ...hide },\n active: { ...show },\n list: {\n margin: 0,\n padding: 0,\n display: \"inherit\",\n alignItems: \"center\",\n height: \"100%\",\n \"&:hover $active\": {\n ...hide,\n },\n \"& li:hover > $hidden\": {\n ...show,\n },\n\n \"&:focus-within $active\": {\n ...hide,\n zIndex: -2,\n },\n \"& li:focus-within > $hidden\": {\n ...show,\n zIndex: -1,\n },\n },\n});\n"],"names":[],"mappings":";;AAGA,MAAM,OAAO;AAAA,EACX,KAAK,MAAM,OAAO;AAAA,EAClB,YAAY,CAAC,KAAK;AAAA,EAClB,WAAW,MAAM,OAAO;AAAA,EACxB,oBAAoB;AAAA,EACpB,iBAAiB,MAAM,OAAO;AAChC;AAEA,MAAM,OAAO;AAAA,EACX,KAAK;AAAA,EACL,YAAY,CAAC,KAAK;AAAA,EAClB,WAAW;AAAA,EACX,oBAAoB;AACtB;
|
|
1
|
+
{"version":3,"file":"Bar.styles.js","sources":["../../../../../src/Header/Navigation/MenuBar/Bar.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nconst show = {\n top: theme.header.height,\n transition: [\"top\"],\n boxShadow: theme.colors.shadow,\n transitionDuration: \"500ms\",\n backgroundColor: theme.colors.atmo2,\n};\n\nconst hide = {\n top: 0,\n transition: [\"top\"],\n boxShadow: \"none\",\n transitionDuration: \"300ms\",\n};\n\n// TODO - rename to HvHeaderMenuBar (the actual component's name) in v6\nexport const { staticClasses, useClasses } = createClasses(\"HvHeader-MenuBar\", {\n root: {\n left: 0,\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n justifyContent: \"center\",\n alignItems: \"center\",\n },\n menu: {\n position: \"absolute\",\n zIndex: -2,\n height: theme.header.secondLevelHeight,\n backgroundColor: theme.colors.atmo2,\n \"& li > div\": {\n marginTop: 0,\n },\n },\n menubar: {\n position: \"relative\",\n backgroundColor: theme.colors.atmo1,\n },\n hidden: { ...hide },\n active: { ...show },\n list: {\n margin: 0,\n padding: 0,\n display: \"inherit\",\n alignItems: \"center\",\n height: \"100%\",\n \"&:hover $active\": {\n ...hide,\n },\n \"& li:hover > $hidden\": {\n ...show,\n },\n\n \"&:focus-within $active\": {\n ...hide,\n zIndex: -2,\n },\n \"& li:focus-within > $hidden\": {\n ...show,\n zIndex: -1,\n },\n },\n});\n"],"names":[],"mappings":";;AAGA,MAAM,OAAO;AAAA,EACX,KAAK,MAAM,OAAO;AAAA,EAClB,YAAY,CAAC,KAAK;AAAA,EAClB,WAAW,MAAM,OAAO;AAAA,EACxB,oBAAoB;AAAA,EACpB,iBAAiB,MAAM,OAAO;AAChC;AAEA,MAAM,OAAO;AAAA,EACX,KAAK;AAAA,EACL,YAAY,CAAC,KAAK;AAAA,EAClB,WAAW;AAAA,EACX,oBAAoB;AACtB;AAGO,MAAM,EAAE,eAAe,eAAe,cAAc,oBAAoB;AAAA,EAC7E,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,gBAAgB;AAAA,IAChB,YAAY;AAAA,EACd;AAAA,EACA,MAAM;AAAA,IACJ,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,QAAQ,MAAM,OAAO;AAAA,IACrB,iBAAiB,MAAM,OAAO;AAAA,IAC9B,cAAc;AAAA,MACZ,WAAW;AAAA,IACb;AAAA,EACF;AAAA,EACA,SAAS;AAAA,IACP,UAAU;AAAA,IACV,iBAAiB,MAAM,OAAO;AAAA,EAChC;AAAA,EACA,QAAQ,EAAE,GAAG,KAAK;AAAA,EAClB,QAAQ,EAAE,GAAG,KAAK;AAAA,EAClB,MAAM;AAAA,IACJ,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,QAAQ;AAAA,IACR,mBAAmB;AAAA,MACjB,GAAG;AAAA,IACL;AAAA,IACA,wBAAwB;AAAA,MACtB,GAAG;AAAA,IACL;AAAA,IAEA,0BAA0B;AAAA,MACxB,GAAG;AAAA,MACH,QAAQ;AAAA,IACV;AAAA,IACA,+BAA+B;AAAA,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