@hitachivantara/uikit-react-core 5.87.2 → 5.87.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/BaseInput/BaseInput.cjs +44 -83
- package/dist/cjs/BaseInput/BaseInput.styles.cjs +68 -142
- package/dist/cjs/Calendar/CalendarHeader/CalendarHeader.cjs +0 -6
- package/dist/cjs/Calendar/CalendarHeader/CalendarHeader.styles.cjs +1 -5
- package/dist/cjs/Dropdown/Dropdown.cjs +8 -10
- package/dist/cjs/InlineEditor/InlineEditor.cjs +10 -14
- package/dist/cjs/InlineEditor/InlineEditor.styles.cjs +13 -36
- package/dist/cjs/Input/Input.cjs +4 -5
- package/dist/cjs/Input/Input.styles.cjs +5 -19
- package/dist/cjs/List/List.cjs +11 -11
- package/dist/cjs/Pagination/Pagination.styles.cjs +1 -0
- package/dist/cjs/Select/Select.styles.cjs +1 -1
- package/dist/cjs/TagsInput/TagsInput.styles.cjs +3 -8
- package/dist/cjs/TextArea/TextArea.styles.cjs +1 -1
- package/dist/cjs/TimePicker/Unit/Unit.cjs +0 -1
- package/dist/cjs/TimePicker/Unit/Unit.styles.cjs +0 -3
- package/dist/cjs/utils/CounterLabel.cjs +3 -2
- package/dist/esm/BaseInput/BaseInput.js +45 -84
- package/dist/esm/BaseInput/BaseInput.js.map +1 -1
- package/dist/esm/BaseInput/BaseInput.styles.js +68 -142
- package/dist/esm/BaseInput/BaseInput.styles.js.map +1 -1
- package/dist/esm/Calendar/CalendarHeader/CalendarHeader.js +0 -6
- package/dist/esm/Calendar/CalendarHeader/CalendarHeader.js.map +1 -1
- package/dist/esm/Calendar/CalendarHeader/CalendarHeader.styles.js +1 -5
- package/dist/esm/Calendar/CalendarHeader/CalendarHeader.styles.js.map +1 -1
- package/dist/esm/Dropdown/Dropdown.js +8 -10
- package/dist/esm/Dropdown/Dropdown.js.map +1 -1
- package/dist/esm/FilterGroup/RightPanel/RightPanel.js.map +1 -1
- package/dist/esm/InlineEditor/InlineEditor.js +10 -14
- package/dist/esm/InlineEditor/InlineEditor.js.map +1 -1
- package/dist/esm/InlineEditor/InlineEditor.styles.js +13 -36
- package/dist/esm/InlineEditor/InlineEditor.styles.js.map +1 -1
- package/dist/esm/Input/Input.js +4 -5
- package/dist/esm/Input/Input.js.map +1 -1
- package/dist/esm/Input/Input.styles.js +5 -19
- package/dist/esm/Input/Input.styles.js.map +1 -1
- package/dist/esm/List/List.js +11 -11
- package/dist/esm/List/List.js.map +1 -1
- package/dist/esm/Pagination/Pagination.styles.js +1 -0
- package/dist/esm/Pagination/Pagination.styles.js.map +1 -1
- package/dist/esm/Select/Select.styles.js +1 -1
- package/dist/esm/Select/Select.styles.js.map +1 -1
- package/dist/esm/TagsInput/TagsInput.styles.js +3 -8
- package/dist/esm/TagsInput/TagsInput.styles.js.map +1 -1
- package/dist/esm/TextArea/TextArea.styles.js +1 -1
- package/dist/esm/TextArea/TextArea.styles.js.map +1 -1
- package/dist/esm/TimePicker/Unit/Unit.js +0 -1
- package/dist/esm/TimePicker/Unit/Unit.js.map +1 -1
- package/dist/esm/TimePicker/Unit/Unit.styles.js +0 -3
- package/dist/esm/TimePicker/Unit/Unit.styles.js.map +1 -1
- package/dist/esm/utils/CounterLabel.js +3 -2
- package/dist/esm/utils/CounterLabel.js.map +1 -1
- package/dist/types/index.d.ts +27 -29
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseInput.styles.js","sources":["../../../src/BaseInput/BaseInput.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(\"HvBaseInput\", {\n root: {\n
|
|
1
|
+
{"version":3,"file":"BaseInput.styles.js","sources":["../../../src/BaseInput/BaseInput.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(\"HvBaseInput\", {\n root: {\n // #region `input` style reset\n \"input:-webkit-autofill\": {\n WebkitBoxShadow: `0 0 0px 1000px ${theme.colors.atmo1} inset`,\n WebkitTextFillColor: theme.colors.secondary,\n },\n\n // Clears number input up/down arrows in Chrome and Firefox\n \"input[type=number]\": {\n MozAppearance: \"textfield\",\n \"&::-webkit-outer-spin-button,&::-webkit-inner-spin-button\": {\n WebkitAppearance: \"none\",\n margin: 0,\n },\n },\n\n // Clears time input clock in Chrome\n \"input::-webkit-calendar-picker-indicator\": {\n display: \"none\",\n },\n\n // Clears search input clear button in Chrome\n \"input[type=search]::-webkit-search-decoration,input[type=search]::-webkit-search-cancel-button,input[type=search]::-webkit-search-results-button,input[type=search]::-webkit-search-results-decoration\":\n {\n display: \"none\",\n },\n // #endregion\n\n display: \"inline-flex\",\n width: \"100%\",\n position: \"relative\",\n margin: 0,\n borderRadius: theme.radii.base,\n height: \"32px\",\n borderWidth: 1,\n borderColor: theme.colors.secondary,\n boxSizing: \"border-box\",\n backgroundColor: theme.colors.atmo1,\n fontFamily: theme.fontFamily.body,\n\n \":hover:not($disabled,$invalid,$readOnly)\": {\n borderColor: theme.colors.primary,\n },\n \":focus-within:not($disabled)\": {\n ...outlineStyles,\n },\n },\n disabled: {\n backgroundColor: theme.colors.atmo2,\n borderColor: theme.colors.secondary_60,\n\n cursor: \"not-allowed\",\n\n \"&&::before\": {\n borderBottomStyle: \"none\",\n },\n },\n invalid: {\n borderColor: theme.colors.negative_120,\n },\n multiline: {\n padding: 0,\n overflow: \"auto\",\n height: \"auto\",\n\n \"& $input\": {\n borderRadius: theme.radii.base,\n height: \"auto\",\n minHeight: \"21px\",\n padding: \"5px 10px\",\n overflow: \"auto\",\n margin: 0,\n },\n },\n resizable: { width: \"auto\" },\n readOnly: {\n borderColor: theme.colors.secondary_60,\n backgroundColor: theme.colors.atmo2,\n },\n focused: {},\n /** @deprecated unused. use `::after` instead */\n inputBorderContainer: {},\n /** @deprecated use `classes.invalid` instead */\n inputRootInvalid: { borderColor: theme.colors.negative_120 },\n /** @deprecated use `classes.readOnly` instead */\n inputRootReadOnly: {\n borderColor: theme.colors.secondary_60,\n backgroundColor: theme.colors.atmo2,\n },\n /** @deprecated use `classes.root` instead */\n inputRoot: {},\n /** @deprecated unused */\n inputRootFocused: {},\n /** @deprecated use `classes.disabled` instead */\n inputRootDisabled: {},\n /** @deprecated use `classes.multiline` instead */\n inputRootMultiline: {},\n input: {\n height: \"100%\",\n marginLeft: theme.space.xs,\n marginRight: theme.space.xs,\n padding: theme.spacing(\"5px\", 0),\n backgroundColor: \"transparent\",\n overflow: \"hidden\",\n textOverflow: \"ellipsis\",\n outline: \"none\",\n width: \"initial\",\n flexGrow: 1,\n ...theme.typography.body,\n\n \"&::placeholder\": {\n opacity: 1,\n color: theme.colors.secondary_80,\n },\n },\n inputDisabled: {\n color: theme.colors.secondary_60,\n WebkitTextFillColor: theme.colors.secondary_60,\n },\n inputReadOnly: {\n color: theme.colors.secondary_80,\n },\n inputResizable: {\n resize: \"both\",\n width: \"100%\",\n },\n});\n"],"names":[],"mappings":";;;AAKO,MAAM,EAAE,eAAe,eAAe,cAAc,eAAe;AAAA,EACxE,MAAM;AAAA;AAAA,IAEJ,0BAA0B;AAAA,MACxB,iBAAiB,kBAAkB,MAAM,OAAO,KAAK;AAAA,MACrD,qBAAqB,MAAM,OAAO;AAAA,IACpC;AAAA;AAAA,IAGA,sBAAsB;AAAA,MACpB,eAAe;AAAA,MACf,6DAA6D;AAAA,QAC3D,kBAAkB;AAAA,QAClB,QAAQ;AAAA,MAAA;AAAA,IAEZ;AAAA;AAAA,IAGA,4CAA4C;AAAA,MAC1C,SAAS;AAAA,IACX;AAAA;AAAA,IAGA,0MACE;AAAA,MACE,SAAS;AAAA,IACX;AAAA;AAAA,IAGF,SAAS;AAAA,IACT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B,CAAC;AAAA;AAAA,EAEpB,oBAAoB,CAAC;AAAA,EACrB,OAAO;AAAA,IACL,QAAQ;AAAA,IACR,YAAY,MAAM,MAAM;AAAA,IACxB,aAAa,MAAM,MAAM;AAAA,IACzB,SAAS,MAAM,QAAQ,OAAO,CAAC;AAAA,IAC/B,iBAAiB;AAAA,IACjB,UAAU;AAAA,IACV,cAAc;AAAA,IACd,SAAS;AAAA,IACT,OAAO;AAAA,IACP,UAAU;AAAA,IACV,GAAG,MAAM,WAAW;AAAA,IAEpB,kBAAkB;AAAA,MAChB,SAAS;AAAA,MACT,OAAO,MAAM,OAAO;AAAA,IAAA;AAAA,EAExB;AAAA,EACA,eAAe;AAAA,IACb,OAAO,MAAM,OAAO;AAAA,IACpB,qBAAqB,MAAM,OAAO;AAAA,EACpC;AAAA,EACA,eAAe;AAAA,IACb,OAAO,MAAM,OAAO;AAAA,EACtB;AAAA,EACA,gBAAgB;AAAA,IACd,QAAQ;AAAA,IACR,OAAO;AAAA,EAAA;AAEX,CAAC;"}
|
|
@@ -106,12 +106,6 @@ const HvCalendarHeader = (props) => {
|
|
|
106
106
|
{
|
|
107
107
|
type: "text",
|
|
108
108
|
id: setId(id, "header-input"),
|
|
109
|
-
className: classes.headerDate,
|
|
110
|
-
classes: {
|
|
111
|
-
input: classes.input,
|
|
112
|
-
inputBorderContainer: classes.inputBorderContainer,
|
|
113
|
-
error: classes.invalidMessageStyling
|
|
114
|
-
},
|
|
115
109
|
placeholder: localeFormat,
|
|
116
110
|
value: inputValue,
|
|
117
111
|
"aria-labelledby": label?.[0]?.id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CalendarHeader.js","sources":["../../../../src/Calendar/CalendarHeader/CalendarHeader.tsx"],"sourcesContent":["import { useContext, useEffect, useState } from \"react\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport {\n HvFormElementContext,\n HvFormElementDescriptorsContext,\n} from \"../../FormElement\";\nimport { HvInput, HvInputProps } from \"../../Input\";\nimport { HvTypography } from \"../../Typography\";\nimport { isKey } from \"../../utils/keyboardUtils\";\nimport { setId } from \"../../utils/setId\";\nimport type { HvSingleCalendarProps } from \"../SingleCalendar\";\nimport {\n DEFAULT_LOCALE,\n getFormattedDate,\n getLocaleDateFormat,\n getStringFromDate,\n isDate,\n isRange,\n isSameDay,\n parseDateString,\n} from \"../utils\";\nimport { staticClasses, useClasses } from \"./CalendarHeader.styles\";\n\nexport { staticClasses as calendarHeaderClasses };\n\nexport type HvCalendarHeaderClasses = ExtractNames<typeof useClasses>;\n\nexport const HvCalendarHeader = (props: HvCalendarHeaderProps) => {\n const {\n id: idProp,\n value: valueProp,\n locale = DEFAULT_LOCALE,\n classes: classesProp,\n onChange,\n showEndDate,\n showDayOfWeek = false,\n onFocus,\n invalidDateLabel = \"Invalid Date\",\n } = useDefaultProps(\"HvCalendarHeader\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const context = useContext(HvFormElementContext);\n const { label } = useContext(HvFormElementDescriptorsContext);\n\n const localValue = isRange(valueProp)\n ? showEndDate\n ? valueProp.endDate!\n : valueProp.startDate\n : valueProp;\n\n const [dateValue, setDateValue] = useState(localValue);\n const [editedValue, setEditedValue] = useState<string | null>(null);\n const [displayValue, setDisplayValue] = useState(\"\");\n const [weekdayDisplay, setWeekdayDisplay] = useState(\"\");\n\n const id = idProp ?? setId(context.id, \"calendarHeader\");\n\n const inputValue = editedValue ?? displayValue;\n const localeFormat = getLocaleDateFormat(locale);\n\n const [isValidValue, setIsValidValue] = useState(\n inputValue.length === 0 || (inputValue && isDate(new Date(inputValue))),\n );\n\n const validateInput = (incomingValid: any) =>\n incomingValid === undefined || isDate(new Date(incomingValid));\n\n useEffect(() => {\n const valid = validateInput(localValue);\n setIsValidValue(valid);\n if (valid) {\n if (!localValue) {\n setDisplayValue(\"\");\n setEditedValue(null);\n setWeekdayDisplay(\"\");\n return;\n }\n const weekday = new Intl.DateTimeFormat(locale, {\n weekday: \"short\",\n }).format(isDate(localValue) ? localValue : 0);\n setDisplayValue(getFormattedDate(localValue, locale));\n setEditedValue(null);\n setWeekdayDisplay(weekday);\n }\n }, [localValue, locale]);\n\n const handleNewDate = (event: any, date: string) => {\n // attempt to format in locale data, or fallback to default\n const localeParsedDate = parseDateString(date, locale);\n\n const isValidInput = isDate(localeParsedDate);\n const dateParsed = isValidInput ? localeParsedDate : new Date(date);\n // prevent extra updates\n if (!isSameDay(dateParsed, dateValue)) {\n setDateValue(dateParsed);\n onChange?.(event, dateParsed);\n }\n\n setIsValidValue(isValidInput);\n if (isValidInput) {\n setEditedValue(null);\n }\n };\n\n const onBlurHandler: HvInputProps[\"onBlur\"] = (event) => {\n if (editedValue == null) return;\n if (editedValue === \"\") {\n setIsValidValue(true);\n setEditedValue(null);\n return;\n }\n handleNewDate(event, editedValue);\n };\n\n const keyDownHandler: HvInputProps[\"onKeyDown\"] = (event) => {\n if (!isKey(event, \"Enter\") || editedValue == null || editedValue === \"\")\n return;\n event.preventDefault();\n\n handleNewDate(event, editedValue);\n };\n\n const onFocusHandler: HvInputProps[\"onFocus\"] = (event) => {\n if (!localValue) return;\n const formattedDate =\n isValidValue && isDate(localValue)\n ? getStringFromDate(localValue, locale)\n : editedValue;\n setEditedValue(formattedDate);\n onFocus?.(event, formattedDate);\n };\n\n const onChangeHandler: HvInputProps[\"onChange\"] = (event, val) => {\n setEditedValue(val);\n };\n\n const isInvalid = !isValidValue && inputValue !== \"\";\n\n // This component needs to be further refactored\n // It's not possible to clear the date\n // In a new major there's no need for all these classes\n return (\n <div\n id={id}\n className={cx(classes.root, {\n [classes.invalid]: isInvalid,\n })}\n >\n {showDayOfWeek && (\n <HvTypography className={classes.headerDayOfWeek}>\n {weekdayDisplay || \"\\u00A0\"}\n </HvTypography>\n )}\n <HvInput\n type=\"text\"\n id={setId(id, \"header-input\")}\n
|
|
1
|
+
{"version":3,"file":"CalendarHeader.js","sources":["../../../../src/Calendar/CalendarHeader/CalendarHeader.tsx"],"sourcesContent":["import { useContext, useEffect, useState } from \"react\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport {\n HvFormElementContext,\n HvFormElementDescriptorsContext,\n} from \"../../FormElement\";\nimport { HvInput, HvInputProps } from \"../../Input\";\nimport { HvTypography } from \"../../Typography\";\nimport { isKey } from \"../../utils/keyboardUtils\";\nimport { setId } from \"../../utils/setId\";\nimport type { HvSingleCalendarProps } from \"../SingleCalendar\";\nimport {\n DEFAULT_LOCALE,\n getFormattedDate,\n getLocaleDateFormat,\n getStringFromDate,\n isDate,\n isRange,\n isSameDay,\n parseDateString,\n} from \"../utils\";\nimport { staticClasses, useClasses } from \"./CalendarHeader.styles\";\n\nexport { staticClasses as calendarHeaderClasses };\n\nexport type HvCalendarHeaderClasses = ExtractNames<typeof useClasses>;\n\nexport const HvCalendarHeader = (props: HvCalendarHeaderProps) => {\n const {\n id: idProp,\n value: valueProp,\n locale = DEFAULT_LOCALE,\n classes: classesProp,\n onChange,\n showEndDate,\n showDayOfWeek = false,\n onFocus,\n invalidDateLabel = \"Invalid Date\",\n } = useDefaultProps(\"HvCalendarHeader\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const context = useContext(HvFormElementContext);\n const { label } = useContext(HvFormElementDescriptorsContext);\n\n const localValue = isRange(valueProp)\n ? showEndDate\n ? valueProp.endDate!\n : valueProp.startDate\n : valueProp;\n\n const [dateValue, setDateValue] = useState(localValue);\n const [editedValue, setEditedValue] = useState<string | null>(null);\n const [displayValue, setDisplayValue] = useState(\"\");\n const [weekdayDisplay, setWeekdayDisplay] = useState(\"\");\n\n const id = idProp ?? setId(context.id, \"calendarHeader\");\n\n const inputValue = editedValue ?? displayValue;\n const localeFormat = getLocaleDateFormat(locale);\n\n const [isValidValue, setIsValidValue] = useState(\n inputValue.length === 0 || (inputValue && isDate(new Date(inputValue))),\n );\n\n const validateInput = (incomingValid: any) =>\n incomingValid === undefined || isDate(new Date(incomingValid));\n\n useEffect(() => {\n const valid = validateInput(localValue);\n setIsValidValue(valid);\n if (valid) {\n if (!localValue) {\n setDisplayValue(\"\");\n setEditedValue(null);\n setWeekdayDisplay(\"\");\n return;\n }\n const weekday = new Intl.DateTimeFormat(locale, {\n weekday: \"short\",\n }).format(isDate(localValue) ? localValue : 0);\n setDisplayValue(getFormattedDate(localValue, locale));\n setEditedValue(null);\n setWeekdayDisplay(weekday);\n }\n }, [localValue, locale]);\n\n const handleNewDate = (event: any, date: string) => {\n // attempt to format in locale data, or fallback to default\n const localeParsedDate = parseDateString(date, locale);\n\n const isValidInput = isDate(localeParsedDate);\n const dateParsed = isValidInput ? localeParsedDate : new Date(date);\n // prevent extra updates\n if (!isSameDay(dateParsed, dateValue)) {\n setDateValue(dateParsed);\n onChange?.(event, dateParsed);\n }\n\n setIsValidValue(isValidInput);\n if (isValidInput) {\n setEditedValue(null);\n }\n };\n\n const onBlurHandler: HvInputProps[\"onBlur\"] = (event) => {\n if (editedValue == null) return;\n if (editedValue === \"\") {\n setIsValidValue(true);\n setEditedValue(null);\n return;\n }\n handleNewDate(event, editedValue);\n };\n\n const keyDownHandler: HvInputProps[\"onKeyDown\"] = (event) => {\n if (!isKey(event, \"Enter\") || editedValue == null || editedValue === \"\")\n return;\n event.preventDefault();\n\n handleNewDate(event, editedValue);\n };\n\n const onFocusHandler: HvInputProps[\"onFocus\"] = (event) => {\n if (!localValue) return;\n const formattedDate =\n isValidValue && isDate(localValue)\n ? getStringFromDate(localValue, locale)\n : editedValue;\n setEditedValue(formattedDate);\n onFocus?.(event, formattedDate);\n };\n\n const onChangeHandler: HvInputProps[\"onChange\"] = (event, val) => {\n setEditedValue(val);\n };\n\n const isInvalid = !isValidValue && inputValue !== \"\";\n\n // This component needs to be further refactored\n // It's not possible to clear the date\n // In a new major there's no need for all these classes\n return (\n <div\n id={id}\n className={cx(classes.root, {\n [classes.invalid]: isInvalid,\n })}\n >\n {showDayOfWeek && (\n <HvTypography className={classes.headerDayOfWeek}>\n {weekdayDisplay || \"\\u00A0\"}\n </HvTypography>\n )}\n <HvInput\n type=\"text\"\n id={setId(id, \"header-input\")}\n placeholder={localeFormat}\n value={inputValue}\n aria-labelledby={label?.[0]?.id}\n onBlur={onBlurHandler}\n onFocus={onFocusHandler}\n onChange={onChangeHandler}\n onKeyDown={keyDownHandler}\n status={isInvalid ? \"invalid\" : \"valid\"}\n statusMessage={invalidDateLabel}\n />\n </div>\n );\n};\n\n// TODO: refactor this out\nHvCalendarHeader.formElementType = \"HvCalendarHeader\";\n\nexport interface HvCalendarHeaderProps\n extends Pick<\n HvSingleCalendarProps,\n | \"id\"\n | \"value\"\n | \"locale\"\n | \"onChange\"\n | \"showEndDate\"\n | \"showDayOfWeek\"\n | \"invalidDateLabel\"\n > {\n /**\n * A Jss Object used to override or extend the component styles.\n */\n classes?: HvCalendarHeaderClasses;\n /**\n * Callback to handle input onFocus.\n */\n onFocus?: (\n event: React.FocusEvent<HTMLTextAreaElement | HTMLInputElement>,\n formattedDate: string | null,\n ) => void;\n}\n"],"names":[],"mappings":";;;;;;;;;;;AA+Ba,MAAA,mBAAmB,CAAC,UAAiC;AAC1D,QAAA;AAAA,IACJ,IAAI;AAAA,IACJ,OAAO;AAAA,IACP,SAAS;AAAA,IACT,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA,gBAAgB;AAAA,IAChB;AAAA,IACA,mBAAmB;AAAA,EAAA,IACjB,gBAAgB,oBAAoB,KAAK;AAE7C,QAAM,EAAE,SAAS,OAAO,WAAW,WAAW;AAExC,QAAA,UAAU,WAAW,oBAAoB;AAC/C,QAAM,EAAE,MAAA,IAAU,WAAW,+BAA+B;AAEtD,QAAA,aAAa,QAAQ,SAAS,IAChC,cACE,UAAU,UACV,UAAU,YACZ;AAEJ,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,UAAU;AACrD,QAAM,CAAC,aAAa,cAAc,IAAI,SAAwB,IAAI;AAClE,QAAM,CAAC,cAAc,eAAe,I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|
|
10
10
|
invalid: {},
|
|
11
11
|
headerDayOfWeek: {
|
|
12
12
|
color: theme.colors.secondary_80
|
|
13
|
-
}
|
|
14
|
-
headerDate: {},
|
|
15
|
-
input: {},
|
|
16
|
-
inputBorderContainer: {},
|
|
17
|
-
invalidMessageStyling: {}
|
|
13
|
+
}
|
|
18
14
|
});
|
|
19
15
|
export {
|
|
20
16
|
staticClasses,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CalendarHeader.styles.js","sources":["../../../../src/Calendar/CalendarHeader/CalendarHeader.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvCalendarHeader\", {\n root: {\n paddingBottom: theme.space.sm,\n\n \"&$invalid\": {\n paddingBottom: 0,\n },\n },\n invalid: {},\n headerDayOfWeek: {\n color: theme.colors.secondary_80,\n },\n
|
|
1
|
+
{"version":3,"file":"CalendarHeader.styles.js","sources":["../../../../src/Calendar/CalendarHeader/CalendarHeader.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvCalendarHeader\", {\n root: {\n paddingBottom: theme.space.sm,\n\n \"&$invalid\": {\n paddingBottom: 0,\n },\n },\n invalid: {},\n headerDayOfWeek: {\n color: theme.colors.secondary_80,\n },\n});\n"],"names":[],"mappings":";;AAGO,MAAM,EAAE,eAAe,eAAe,cAAc,oBAAoB;AAAA,EAC7E,MAAM;AAAA,IACJ,eAAe,MAAM,MAAM;AAAA,IAE3B,aAAa;AAAA,MACX,eAAe;AAAA,IAAA;AAAA,EAEnB;AAAA,EACA,SAAS,CAAC;AAAA,EACV,iBAAiB;AAAA,IACf,OAAO,MAAM,OAAO;AAAA,EAAA;AAExB,CAAC;"}
|
|
@@ -6,6 +6,7 @@ import { useControlled } from "../hooks/useControlled.js";
|
|
|
6
6
|
import { useLabels } from "../hooks/useLabels.js";
|
|
7
7
|
import { useUniqueId } from "../hooks/useUniqueId.js";
|
|
8
8
|
import { fixedForwardRef } from "../types/generic.js";
|
|
9
|
+
import { CounterLabel } from "../utils/CounterLabel.js";
|
|
9
10
|
import { setId } from "../utils/setId.js";
|
|
10
11
|
import { useClasses } from "./Dropdown.styles.js";
|
|
11
12
|
import { staticClasses } from "./Dropdown.styles.js";
|
|
@@ -21,7 +22,7 @@ import { HvTypography } from "../Typography/Typography.js";
|
|
|
21
22
|
const DEFAULT_LABELS = {
|
|
22
23
|
/** Label for overwrite the default header behavior. */
|
|
23
24
|
select: void 0,
|
|
24
|
-
/** Label used for the All checkbox action. */
|
|
25
|
+
/** Label used for the All checkbox action. @deprecated unused */
|
|
25
26
|
selectAll: "All",
|
|
26
27
|
/** Cancel button label. */
|
|
27
28
|
cancelLabel: "Cancel",
|
|
@@ -182,18 +183,15 @@ const HvDropdown = fixedForwardRef(function HvDropdown2(props, ref) {
|
|
|
182
183
|
}),
|
|
183
184
|
children: selectionLabel.selected
|
|
184
185
|
}
|
|
185
|
-
) : /* @__PURE__ */
|
|
186
|
-
|
|
186
|
+
) : /* @__PURE__ */ jsx(
|
|
187
|
+
CounterLabel,
|
|
187
188
|
{
|
|
188
|
-
|
|
189
|
+
selected: selectionLabel.selected,
|
|
190
|
+
total: selectionLabel.total,
|
|
191
|
+
conjunctionLabel: labels.multiSelectionConjunction,
|
|
189
192
|
className: cx(classes.placeholder, {
|
|
190
193
|
[classes.selectionDisabled]: disabled
|
|
191
|
-
})
|
|
192
|
-
variant: "body",
|
|
193
|
-
children: [
|
|
194
|
-
/* @__PURE__ */ jsx("b", { children: selectionLabel.selected }),
|
|
195
|
-
` ${labels?.multiSelectionConjunction} ${selectionLabel.total}`
|
|
196
|
-
]
|
|
194
|
+
})
|
|
197
195
|
}
|
|
198
196
|
);
|
|
199
197
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dropdown.js","sources":["../../../src/Dropdown/Dropdown.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport { useForkRef } from \"@mui/material/utils\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvBaseDropdown, HvBaseDropdownProps } from \"../BaseDropdown\";\nimport {\n HvFormElement,\n HvFormElementProps,\n HvFormStatus,\n HvInfoMessage,\n HvLabel,\n HvWarningText,\n isInvalid,\n} from \"../FormElement\";\nimport { useControlled } from \"../hooks/useControlled\";\nimport { useLabels } from \"../hooks/useLabels\";\nimport { useUniqueId } from \"../hooks/useUniqueId\";\nimport { HvListValue } from \"../List\";\nimport { fixedForwardRef } from \"../types/generic\";\nimport { HvTypography } from \"../Typography\";\nimport { setId } from \"../utils/setId\";\nimport { staticClasses, useClasses } from \"./Dropdown.styles\";\nimport { HvDropdownList, HvDropdownListProps } from \"./List\";\nimport { getSelected, getSelectionLabel } from \"./utils\";\n\nexport { staticClasses as dropdownClasses };\n\nexport type HvDropdownClasses = ExtractNames<typeof useClasses>;\n\nexport type HvDropdownStatus = \"standBy\" | \"valid\" | \"invalid\";\n\nexport interface HvDropdownProps<\n // TODO: make default `false` in v6\n Multiple extends boolean = boolean,\n OptionValue extends HvListValue = HvListValue,\n> extends Omit<HvFormElementProps, \"value\" | \"onChange\">,\n Pick<\n HvBaseDropdownProps,\n | \"placement\"\n | \"popperProps\"\n | \"disablePortal\"\n | \"variableWidth\"\n | \"expanded\"\n | \"defaultExpanded\"\n > {\n /**\n * A Jss Object used to override or extend the component styles applied.\n */\n classes?: HvDropdownClasses;\n /**\n * The placeholder value when nothing is selected.\n */\n placeholder?: string;\n /**\n * The status of the form element.\n *\n * Valid is correct, invalid is incorrect and standBy means no validations have run.\n *\n * When uncontrolled and unspecified it will default to \"standBy\" and change to either \"valid\"\n * or \"invalid\" after any change to the state.\n */\n status?: HvDropdownStatus;\n /**\n * The error message to show when the validation status is \"invalid\".\n *\n * Defaults to \"Required\" when the status is uncontrolled and no `aria-errormessage` is provided.\n */\n statusMessage?: any;\n /**\n * Identifies the element that provides an error message for the dropdown.\n *\n * Will only be used when the validation status is invalid.\n */\n \"aria-errormessage\"?: string;\n /**\n * The callback fired when the value changes.\n */\n onChange?: (\n selected: Multiple extends true ? OptionValue[] : OptionValue | undefined,\n ) => void;\n /**\n * The list to be rendered by the dropdown.\n */\n values?: OptionValue[];\n /**\n * If `true` the dropdown is multiSelect, if `false` the dropdown is single select.\n */\n multiSelect?: Multiple;\n /**\n * If `true` the dropdown is rendered with a search bar, if `false` there won't be a search bar.\n */\n showSearch?: boolean;\n /**\n * If 'true' the dropdown will notify on the first render.\n */\n notifyChangesOnFirstRender?: boolean;\n /**\n * An object containing all the labels for the dropdown.\n */\n labels?: HvDropdownLabels;\n /**\n * If `true` the dropdown will show tooltips when user mouseenter text in list\n */\n hasTooltips?: boolean;\n /**\n * If `true`, selection can be toggled when single selection.\n */\n singleSelectionToggle?: boolean;\n /**\n * Callback called when the user cancels the changes.\n *\n * Called when the cancel button is used and when the user clicks outside the open container.\n *\n * @param {object} event The event source of the callback.\n */\n onCancel?: (event: Event) => void;\n /**\n * Callback called when dropdown changes the expanded state.\n *\n * @param {object} event The event source of the callback.\n * @param {boolean} open If the dropdown new state is open (`true`) or closed (`false`).\n */\n onToggle?: (event: Event, open: boolean) => void;\n /**\n * Callback called when the user clicks outside the open container.\n *\n * @param {object} event The event source of the callback.\n */\n onClickOutside?: (event: Event) => void;\n /**\n * @ignore\n */\n onFocus?: React.FocusEventHandler<any>;\n /**\n * @ignore\n */\n onBlur?: React.FocusEventHandler<any>;\n /**\n * Experimental. Height of the dropdown, in case you want to control it from a prop. Styles can also be used through dropdownListContainer class. Required in case virtualized is used\n */\n height?: number;\n /**\n * Experimental. Height of the dropdown, in case you want to control it from a prop. Styles can also be used through dropdownListContainer class. Required in case virtualized is used\n */\n maxHeight?: number;\n /**\n * Experimental. Uses dropdown in a virtualized form, where not all options are rendered initially. Good for use cases with a lot of options.\n */\n virtualized?: boolean;\n /**\n * Extra props passed to the dropdown.\n */\n baseDropdownProps?: Partial<HvBaseDropdownProps>;\n /**\n * Extra props passed to the list.\n */\n listProps?: Partial<HvDropdownListProps>;\n}\n\nconst DEFAULT_LABELS = {\n /** Label for overwrite the default header behavior. */\n select: undefined as string | undefined,\n /** Label used for the All checkbox action. */\n selectAll: \"All\",\n /** Cancel button label. */\n cancelLabel: \"Cancel\",\n /** Apply button label. */\n applyLabel: \"Apply\",\n /** The label used in the middle of the multiSelection count. */\n searchPlaceholder: \"Search\",\n /** The label used in search. */\n multiSelectionConjunction: \"/\",\n};\n\nexport type HvDropdownLabels = Partial<typeof DEFAULT_LABELS>;\n/** @deprecated use `HvDropdownLabels` instead */\nexport type HvDropdownLabelsProps = HvDropdownLabels;\n\n/**\n * A dropdown list is a graphical control element, similar to a list box, that allows the user to choose one value from a list.\n */\nexport const HvDropdown = fixedForwardRef(function HvDropdown<\n Multiple extends boolean = false,\n OptionValue extends HvListValue = HvListValue,\n>(\n props: HvDropdownProps<Multiple, OptionValue>,\n ref: React.Ref<HTMLDivElement>,\n) {\n const {\n classes: classesProp,\n className,\n\n id,\n name,\n\n required,\n disabled,\n readOnly,\n\n label,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n description,\n \"aria-describedby\": ariaDescribedBy,\n\n placeholder = \"Select...\",\n\n onChange,\n\n status,\n statusMessage,\n \"aria-errormessage\": ariaErrorMessage,\n\n onCancel,\n onToggle,\n onClickOutside,\n\n onFocus,\n onBlur,\n\n values,\n multiSelect = false,\n showSearch,\n expanded,\n defaultExpanded,\n notifyChangesOnFirstRender,\n labels: labelsProp,\n hasTooltips,\n disablePortal,\n singleSelectionToggle = true,\n placement,\n variableWidth,\n popperProps = {},\n height,\n maxHeight,\n virtualized,\n baseDropdownProps = {},\n listProps = {},\n ...others\n } = useDefaultProps(\"HvDropdown\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const labels = useLabels(DEFAULT_LABELS, labelsProp);\n\n const elementId = useUniqueId(id);\n\n const [validationState, setValidationState] = useControlled<HvFormStatus>(\n status,\n \"standBy\",\n );\n\n const [validationMessage] = useControlled(statusMessage, \"Required\");\n\n const [isOpen, setIsOpen] = useControlled(expanded, Boolean(defaultExpanded));\n const [selectionLabel, setSelectionLabel] = useState(\n getSelectionLabel(labels, placeholder, multiSelect, values),\n );\n\n const [internalValues, setInternalValues] = useState(values);\n\n // Hack - Keeping track of internal values for validation purposes since useState is async\n const internalValuesRef = useRef(values);\n\n useEffect(() => {\n setInternalValues(values);\n internalValuesRef.current = values;\n }, [values]);\n\n useEffect(() => {\n setSelectionLabel(\n getSelectionLabel(labels, placeholder, multiSelect, values),\n );\n }, [labels, multiSelect, placeholder, values]);\n\n if (import.meta.env.DEV && virtualized && !height) {\n // eslint-disable-next-line no-console\n console.error(\n \"Dropdown/List in virtualized mode requires a height. Please define it.\",\n );\n }\n\n const dropdownHeaderRef = useRef<HTMLDivElement>();\n\n const {\n ref: refProp,\n dropdownHeaderRef: dropdownHeaderRefProp,\n ...otherBaseDropdownProps\n } = baseDropdownProps;\n const headerForkedRef = useForkRef(dropdownHeaderRefProp, dropdownHeaderRef);\n\n const dropdownForkedRef = useForkRef(ref, refProp);\n\n const handleToggle: HvBaseDropdownProps[\"onToggle\"] = (event, open) => {\n onToggle?.(event, open);\n\n setIsOpen(open);\n\n if (!open) {\n // also run built-in validation when closing without changes\n // as the user \"touched\" the input\n setValidationState(() => {\n // this will only run if status is uncontrolled\n if (required) {\n const hasSelection =\n getSelected(internalValuesRef.current).length > 0;\n\n if (!hasSelection) {\n return \"invalid\";\n }\n }\n\n return \"valid\";\n });\n }\n };\n\n /** Applies the selected values to the state */\n const handleSelection: HvDropdownListProps[\"onChange\"] = (\n listValues,\n commitChanges,\n toggle,\n notifyChanges = true,\n ) => {\n const selected = getSelected(listValues);\n\n if (commitChanges) {\n setInternalValues(listValues as any);\n internalValuesRef.current = listValues as any;\n\n setSelectionLabel(\n getSelectionLabel(labels, placeholder, multiSelect, listValues),\n );\n\n setValidationState(() => {\n // this will only run if status is uncontrolled\n if (required && selected.length === 0) {\n return \"invalid\";\n }\n\n return \"valid\";\n });\n }\n if (notifyChanges) {\n onChange?.((multiSelect ? selected : selected[0]) as any);\n }\n if (toggle) {\n handleToggle(undefined as any, false);\n\n // focus-ring won't be visible even if using the keyboard:\n // https://github.com/WICG/focus-visible/issues/88\n dropdownHeaderRef.current?.focus({ preventScroll: true });\n }\n };\n\n /**\n * Handles the `Cancel` action. Both single and ranged modes are handled here.\n */\n const handleCancel: HvDropdownListProps[\"onCancel\"] = (evt) => {\n onCancel?.(evt as any);\n\n handleToggle(evt as any, false);\n\n // focus-ring won't be visible even if using the keyboard:\n // https://github.com/WICG/focus-visible/issues/88\n dropdownHeaderRef.current?.focus({ preventScroll: true });\n };\n\n const handleClickOutside: HvBaseDropdownProps[\"onClickOutside\"] = (evt) => {\n onClickOutside?.(evt);\n onCancel?.(evt);\n };\n\n const setFocusToContent: HvBaseDropdownProps[\"onContainerCreation\"] = (\n containerRef,\n ) => {\n const inputs = containerRef?.getElementsByTagName(\"input\");\n if (inputs && inputs.length > 0) {\n inputs[0].focus();\n return;\n }\n const listItems =\n containerRef != null ? [...containerRef.getElementsByTagName(\"li\")] : [];\n listItems.every((listItem) => {\n if (listItem.tabIndex >= 0) {\n listItem.focus();\n return false;\n }\n return true;\n });\n };\n\n const buildHeaderLabel = () => {\n const hasSelection = getSelected(internalValues).length > 0;\n return labels?.select || !multiSelect ? (\n <HvTypography\n component=\"div\"\n variant=\"body\"\n className={cx(classes.placeholder, {\n [classes.selectionDisabled]: disabled,\n [classes.placeholderClosed]: !(isOpen || hasSelection),\n })}\n >\n {selectionLabel.selected}\n </HvTypography>\n ) : (\n <HvTypography\n component=\"div\"\n className={cx(classes.placeholder, {\n [classes.selectionDisabled]: disabled,\n })}\n variant=\"body\"\n >\n <b>{selectionLabel.selected}</b>\n {` ${labels?.multiSelectionConjunction} ${selectionLabel.total}`}\n </HvTypography>\n );\n };\n\n const hasLabel = label != null;\n const hasDescription = description != null;\n\n // the error message area will only be created if:\n // - an external element that provides an error message isn't identified via aria-errormessage AND\n // - both status and statusMessage properties are being controlled OR\n // - status is uncontrolled and required is true\n const canShowError =\n ariaErrorMessage == null &&\n ((status !== undefined && statusMessage !== undefined) ||\n (status === undefined && required));\n\n const isStateInvalid = isInvalid(validationState);\n\n let errorMessageId;\n if (isStateInvalid) {\n errorMessageId = canShowError\n ? setId(elementId, \"error\")\n : ariaErrorMessage;\n }\n\n return (\n <HvFormElement\n id={id}\n name={name}\n status={validationState}\n disabled={disabled}\n readOnly={readOnly}\n required={required}\n className={cx(\n classes.root,\n {\n [classes.disabled]: disabled,\n },\n className,\n )}\n {...others}\n >\n {(hasLabel || hasDescription) && (\n <div className={classes.labelContainer}>\n {hasLabel && (\n <HvLabel\n showGutter\n id={setId(elementId, \"label\")}\n label={label}\n className={classes.label}\n />\n )}\n\n {hasDescription && (\n <HvInfoMessage\n id={setId(elementId, \"description\")}\n className={classes.description}\n >\n {description}\n </HvInfoMessage>\n )}\n </div>\n )}\n <HvBaseDropdown\n ref={dropdownForkedRef}\n id={setId(id, \"dropdown\")}\n classes={{\n root: cx(classes.dropdown, {\n [classes.readOnly]: readOnly,\n }),\n arrow: classes.arrow,\n header: cx(classes.dropdownHeader, {\n [classes.dropdownHeaderInvalid]: isStateInvalid,\n }),\n headerOpen: classes.dropdownHeaderOpen,\n }}\n expanded={isOpen}\n disabled={disabled}\n readOnly={readOnly}\n required={required}\n disablePortal={disablePortal}\n placement={placement}\n popperProps={popperProps}\n placeholder={buildHeaderLabel()}\n onToggle={handleToggle}\n onClickOutside={handleClickOutside}\n onContainerCreation={setFocusToContent}\n role=\"combobox\"\n variableWidth={variableWidth}\n aria-label={ariaLabel}\n aria-labelledby={\n [label && setId(elementId, \"label\"), ariaLabelledBy]\n .join(\" \")\n .trim() || undefined\n }\n aria-invalid={isStateInvalid ? true : undefined}\n aria-errormessage={errorMessageId}\n aria-describedby={\n [description && setId(elementId, \"description\"), ariaDescribedBy]\n .join(\" \")\n .trim() || undefined\n }\n onFocus={onFocus}\n onBlur={onBlur}\n dropdownHeaderRef={headerForkedRef}\n {...otherBaseDropdownProps}\n >\n <HvDropdownList\n id={setId(elementId, \"values\")}\n classes={{\n rootList: classes.rootList,\n dropdownListContainer: classes.dropdownListContainer,\n }}\n values={internalValues}\n multiSelect={multiSelect}\n showSearch={showSearch}\n onChange={handleSelection}\n onCancel={handleCancel}\n labels={labels}\n notifyChangesOnFirstRender={notifyChangesOnFirstRender}\n hasTooltips={hasTooltips}\n singleSelectionToggle={singleSelectionToggle}\n aria-label={ariaLabel}\n aria-labelledby={hasLabel ? setId(elementId, \"label\") : undefined}\n height={height}\n maxHeight={maxHeight}\n virtualized={virtualized}\n {...listProps}\n />\n </HvBaseDropdown>\n {canShowError && (\n <HvWarningText\n id={setId(elementId, \"error\")}\n disableBorder\n className={classes.error}\n >\n {validationMessage}\n </HvWarningText>\n )}\n </HvFormElement>\n );\n});\n"],"names":["HvDropdown"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkKA,MAAM,iBAAiB;AAAA;AAAA,EAErB,QAAQ;AAAA;AAAA,EAER,WAAW;AAAA;AAAA,EAEX,aAAa;AAAA;AAAA,EAEb,YAAY;AAAA;AAAA,EAEZ,mBAAmB;AAAA;AAAA,EAEnB,2BAA2B;AAC7B;AASO,MAAM,aAAa,gBAAgB,SAASA,YAIjD,OACA,KACA;AACM,QAAA;AAAA,IACJ,SAAS;AAAA,IACT;AAAA,IAEA;AAAA,IACA;AAAA,IAEA;AAAA,IACA;AAAA,IACA;AAAA,IAEA;AAAA,IACA,cAAc;AAAA,IACd,mBAAmB;AAAA,IACnB;AAAA,IACA,oBAAoB;AAAA,IAEpB,cAAc;AAAA,IAEd;AAAA,IAEA;AAAA,IACA;AAAA,IACA,qBAAqB;AAAA,IAErB;AAAA,IACA;A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GAAG,EACR,UAAU;AAAA,YAEf,gBAAc,iBAAiB,OAAO;AAAA,YACtC,qBAAmB;AAAA,YACnB,oBACE,CAAC,eAAe,MAAM,WAAW,aAAa,GAAG,eAAe,EAC7D,KAAK,GAAG,EACR,UAAU;AAAA,YAEf;AAAA,YACA;AAAA,YACA,mBAAmB;AAAA,YAClB,GAAG;AAAA,YAEJ,UAAA;AAAA,cAAC;AAAA,cAAA;AAAA,gBACC,IAAI,MAAM,WAAW,QAAQ;AAAA,gBAC7B,SAAS;AAAA,kBACP,UAAU,QAAQ;AAAA,kBAClB,uBAAuB,QAAQ;AAAA,gBACjC;AAAA,gBACA,QAAQ;AAAA,gBACR;AAAA,gBACA;AAAA,gBACA,UAAU;AAAA,gBACV,UAAU;AAAA,gBACV;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA,cAAY;AAAA,gBACZ,mBAAiB,WAAW,MAAM,WAAW,OAAO,IAAI;AAAA,gBACxD;AAAA,gBACA;AAAA,gBACA;AAAA,gBACC,GAAG;AAAA,cAAA;AAAA,YAAA;AAAA,UACN;AAAA,QACF;AAAA,QACC,gBACC;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,IAAI,MAAM,WAAW,OAAO;AAAA,YAC5B,eAAa;AAAA,YACb,WAAW,QAAQ;AAAA,YAElB,UAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MACH;AAAA,IAAA;AAAA,EAEJ;AAEJ,CAAC;"}
|
|
1
|
+
{"version":3,"file":"Dropdown.js","sources":["../../../src/Dropdown/Dropdown.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport { useForkRef } from \"@mui/material/utils\";\nimport {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvBaseDropdown, HvBaseDropdownProps } from \"../BaseDropdown\";\nimport {\n HvFormElement,\n HvFormElementProps,\n HvFormStatus,\n HvInfoMessage,\n HvLabel,\n HvWarningText,\n isInvalid,\n} from \"../FormElement\";\nimport { useControlled } from \"../hooks/useControlled\";\nimport { useLabels } from \"../hooks/useLabels\";\nimport { useUniqueId } from \"../hooks/useUniqueId\";\nimport { HvListValue } from \"../List\";\nimport { fixedForwardRef } from \"../types/generic\";\nimport { HvTypography } from \"../Typography\";\nimport { CounterLabel } from \"../utils/CounterLabel\";\nimport { setId } from \"../utils/setId\";\nimport { staticClasses, useClasses } from \"./Dropdown.styles\";\nimport { HvDropdownList, HvDropdownListProps } from \"./List\";\nimport { getSelected, getSelectionLabel } from \"./utils\";\n\nexport { staticClasses as dropdownClasses };\n\nexport type HvDropdownClasses = ExtractNames<typeof useClasses>;\n\nexport type HvDropdownStatus = \"standBy\" | \"valid\" | \"invalid\";\n\nexport interface HvDropdownProps<\n // TODO: make default `false` in v6\n Multiple extends boolean = boolean,\n OptionValue extends HvListValue = HvListValue,\n> extends Omit<HvFormElementProps, \"value\" | \"onChange\">,\n Pick<\n HvBaseDropdownProps,\n | \"placement\"\n | \"popperProps\"\n | \"disablePortal\"\n | \"variableWidth\"\n | \"expanded\"\n | \"defaultExpanded\"\n > {\n /**\n * A Jss Object used to override or extend the component styles applied.\n */\n classes?: HvDropdownClasses;\n /**\n * The placeholder value when nothing is selected.\n */\n placeholder?: string;\n /**\n * The status of the form element.\n *\n * Valid is correct, invalid is incorrect and standBy means no validations have run.\n *\n * When uncontrolled and unspecified it will default to \"standBy\" and change to either \"valid\"\n * or \"invalid\" after any change to the state.\n */\n status?: HvDropdownStatus;\n /**\n * The error message to show when the validation status is \"invalid\".\n *\n * Defaults to \"Required\" when the status is uncontrolled and no `aria-errormessage` is provided.\n */\n statusMessage?: any;\n /**\n * Identifies the element that provides an error message for the dropdown.\n *\n * Will only be used when the validation status is invalid.\n */\n \"aria-errormessage\"?: string;\n /**\n * The callback fired when the value changes.\n */\n onChange?: (\n selected: Multiple extends true ? OptionValue[] : OptionValue | undefined,\n ) => void;\n /**\n * The list to be rendered by the dropdown.\n */\n values?: OptionValue[];\n /**\n * If `true` the dropdown is multiSelect, if `false` the dropdown is single select.\n */\n multiSelect?: Multiple;\n /**\n * If `true` the dropdown is rendered with a search bar, if `false` there won't be a search bar.\n */\n showSearch?: boolean;\n /**\n * If 'true' the dropdown will notify on the first render.\n */\n notifyChangesOnFirstRender?: boolean;\n /**\n * An object containing all the labels for the dropdown.\n */\n labels?: HvDropdownLabels;\n /**\n * If `true` the dropdown will show tooltips when user mouseenter text in list\n */\n hasTooltips?: boolean;\n /**\n * If `true`, selection can be toggled when single selection.\n */\n singleSelectionToggle?: boolean;\n /**\n * Callback called when the user cancels the changes.\n *\n * Called when the cancel button is used and when the user clicks outside the open container.\n *\n * @param {object} event The event source of the callback.\n */\n onCancel?: (event: Event) => void;\n /**\n * Callback called when dropdown changes the expanded state.\n *\n * @param {object} event The event source of the callback.\n * @param {boolean} open If the dropdown new state is open (`true`) or closed (`false`).\n */\n onToggle?: (event: Event, open: boolean) => void;\n /**\n * Callback called when the user clicks outside the open container.\n *\n * @param {object} event The event source of the callback.\n */\n onClickOutside?: (event: Event) => void;\n /**\n * @ignore\n */\n onFocus?: React.FocusEventHandler<any>;\n /**\n * @ignore\n */\n onBlur?: React.FocusEventHandler<any>;\n /**\n * Experimental. Height of the dropdown, in case you want to control it from a prop. Styles can also be used through dropdownListContainer class. Required in case virtualized is used\n */\n height?: number;\n /**\n * Experimental. Height of the dropdown, in case you want to control it from a prop. Styles can also be used through dropdownListContainer class. Required in case virtualized is used\n */\n maxHeight?: number;\n /**\n * Experimental. Uses dropdown in a virtualized form, where not all options are rendered initially. Good for use cases with a lot of options.\n */\n virtualized?: boolean;\n /**\n * Extra props passed to the dropdown.\n */\n baseDropdownProps?: Partial<HvBaseDropdownProps>;\n /**\n * Extra props passed to the list.\n */\n listProps?: Partial<HvDropdownListProps>;\n}\n\nconst DEFAULT_LABELS = {\n /** Label for overwrite the default header behavior. */\n select: undefined as string | undefined,\n /** Label used for the All checkbox action. @deprecated unused */\n selectAll: \"All\",\n /** Cancel button label. */\n cancelLabel: \"Cancel\",\n /** Apply button label. */\n applyLabel: \"Apply\",\n /** The label used in the middle of the multiSelection count. */\n searchPlaceholder: \"Search\",\n /** The label used in search. */\n multiSelectionConjunction: \"/\",\n};\n\nexport type HvDropdownLabels = Partial<typeof DEFAULT_LABELS>;\n/** @deprecated use `HvDropdownLabels` instead */\nexport type HvDropdownLabelsProps = HvDropdownLabels;\n\n/**\n * A dropdown list is a graphical control element, similar to a list box, that allows the user to choose one value from a list.\n */\nexport const HvDropdown = fixedForwardRef(function HvDropdown<\n Multiple extends boolean = false,\n OptionValue extends HvListValue = HvListValue,\n>(\n props: HvDropdownProps<Multiple, OptionValue>,\n ref: React.Ref<HTMLDivElement>,\n) {\n const {\n classes: classesProp,\n className,\n\n id,\n name,\n\n required,\n disabled,\n readOnly,\n\n label,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n description,\n \"aria-describedby\": ariaDescribedBy,\n\n placeholder = \"Select...\",\n\n onChange,\n\n status,\n statusMessage,\n \"aria-errormessage\": ariaErrorMessage,\n\n onCancel,\n onToggle,\n onClickOutside,\n\n onFocus,\n onBlur,\n\n values,\n multiSelect = false,\n showSearch,\n expanded,\n defaultExpanded,\n notifyChangesOnFirstRender,\n labels: labelsProp,\n hasTooltips,\n disablePortal,\n singleSelectionToggle = true,\n placement,\n variableWidth,\n popperProps = {},\n height,\n maxHeight,\n virtualized,\n baseDropdownProps = {},\n listProps = {},\n ...others\n } = useDefaultProps(\"HvDropdown\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const labels = useLabels(DEFAULT_LABELS, labelsProp);\n\n const elementId = useUniqueId(id);\n\n const [validationState, setValidationState] = useControlled<HvFormStatus>(\n status,\n \"standBy\",\n );\n\n const [validationMessage] = useControlled(statusMessage, \"Required\");\n\n const [isOpen, setIsOpen] = useControlled(expanded, Boolean(defaultExpanded));\n const [selectionLabel, setSelectionLabel] = useState(\n getSelectionLabel(labels, placeholder, multiSelect, values),\n );\n\n const [internalValues, setInternalValues] = useState(values);\n\n // Hack - Keeping track of internal values for validation purposes since useState is async\n const internalValuesRef = useRef(values);\n\n useEffect(() => {\n setInternalValues(values);\n internalValuesRef.current = values;\n }, [values]);\n\n useEffect(() => {\n setSelectionLabel(\n getSelectionLabel(labels, placeholder, multiSelect, values),\n );\n }, [labels, multiSelect, placeholder, values]);\n\n if (import.meta.env.DEV && virtualized && !height) {\n // eslint-disable-next-line no-console\n console.error(\n \"Dropdown/List in virtualized mode requires a height. Please define it.\",\n );\n }\n\n const dropdownHeaderRef = useRef<HTMLDivElement>();\n\n const {\n ref: refProp,\n dropdownHeaderRef: dropdownHeaderRefProp,\n ...otherBaseDropdownProps\n } = baseDropdownProps;\n const headerForkedRef = useForkRef(dropdownHeaderRefProp, dropdownHeaderRef);\n\n const dropdownForkedRef = useForkRef(ref, refProp);\n\n const handleToggle: HvBaseDropdownProps[\"onToggle\"] = (event, open) => {\n onToggle?.(event, open);\n\n setIsOpen(open);\n\n if (!open) {\n // also run built-in validation when closing without changes\n // as the user \"touched\" the input\n setValidationState(() => {\n // this will only run if status is uncontrolled\n if (required) {\n const hasSelection =\n getSelected(internalValuesRef.current).length > 0;\n\n if (!hasSelection) {\n return \"invalid\";\n }\n }\n\n return \"valid\";\n });\n }\n };\n\n /** Applies the selected values to the state */\n const handleSelection: HvDropdownListProps[\"onChange\"] = (\n listValues,\n commitChanges,\n toggle,\n notifyChanges = true,\n ) => {\n const selected = getSelected(listValues);\n\n if (commitChanges) {\n setInternalValues(listValues as any);\n internalValuesRef.current = listValues as any;\n\n setSelectionLabel(\n getSelectionLabel(labels, placeholder, multiSelect, listValues),\n );\n\n setValidationState(() => {\n // this will only run if status is uncontrolled\n if (required && selected.length === 0) {\n return \"invalid\";\n }\n\n return \"valid\";\n });\n }\n if (notifyChanges) {\n onChange?.((multiSelect ? selected : selected[0]) as any);\n }\n if (toggle) {\n handleToggle(undefined as any, false);\n\n // focus-ring won't be visible even if using the keyboard:\n // https://github.com/WICG/focus-visible/issues/88\n dropdownHeaderRef.current?.focus({ preventScroll: true });\n }\n };\n\n /**\n * Handles the `Cancel` action. Both single and ranged modes are handled here.\n */\n const handleCancel: HvDropdownListProps[\"onCancel\"] = (evt) => {\n onCancel?.(evt as any);\n\n handleToggle(evt as any, false);\n\n // focus-ring won't be visible even if using the keyboard:\n // https://github.com/WICG/focus-visible/issues/88\n dropdownHeaderRef.current?.focus({ preventScroll: true });\n };\n\n const handleClickOutside: HvBaseDropdownProps[\"onClickOutside\"] = (evt) => {\n onClickOutside?.(evt);\n onCancel?.(evt);\n };\n\n const setFocusToContent: HvBaseDropdownProps[\"onContainerCreation\"] = (\n containerRef,\n ) => {\n const inputs = containerRef?.getElementsByTagName(\"input\");\n if (inputs && inputs.length > 0) {\n inputs[0].focus();\n return;\n }\n const listItems =\n containerRef != null ? [...containerRef.getElementsByTagName(\"li\")] : [];\n listItems.every((listItem) => {\n if (listItem.tabIndex >= 0) {\n listItem.focus();\n return false;\n }\n return true;\n });\n };\n\n const buildHeaderLabel = () => {\n const hasSelection = getSelected(internalValues).length > 0;\n return labels?.select || !multiSelect ? (\n <HvTypography\n component=\"div\"\n variant=\"body\"\n className={cx(classes.placeholder, {\n [classes.selectionDisabled]: disabled,\n [classes.placeholderClosed]: !(isOpen || hasSelection),\n })}\n >\n {selectionLabel.selected}\n </HvTypography>\n ) : (\n <CounterLabel\n selected={selectionLabel.selected}\n total={selectionLabel.total}\n conjunctionLabel={labels.multiSelectionConjunction}\n className={cx(classes.placeholder, {\n [classes.selectionDisabled]: disabled,\n })}\n />\n );\n };\n\n const hasLabel = label != null;\n const hasDescription = description != null;\n\n // the error message area will only be created if:\n // - an external element that provides an error message isn't identified via aria-errormessage AND\n // - both status and statusMessage properties are being controlled OR\n // - status is uncontrolled and required is true\n const canShowError =\n ariaErrorMessage == null &&\n ((status !== undefined && statusMessage !== undefined) ||\n (status === undefined && required));\n\n const isStateInvalid = isInvalid(validationState);\n\n let errorMessageId;\n if (isStateInvalid) {\n errorMessageId = canShowError\n ? setId(elementId, \"error\")\n : ariaErrorMessage;\n }\n\n return (\n <HvFormElement\n id={id}\n name={name}\n status={validationState}\n disabled={disabled}\n readOnly={readOnly}\n required={required}\n className={cx(\n classes.root,\n {\n [classes.disabled]: disabled,\n },\n className,\n )}\n {...others}\n >\n {(hasLabel || hasDescription) && (\n <div className={classes.labelContainer}>\n {hasLabel && (\n <HvLabel\n showGutter\n id={setId(elementId, \"label\")}\n label={label}\n className={classes.label}\n />\n )}\n\n {hasDescription && (\n <HvInfoMessage\n id={setId(elementId, \"description\")}\n className={classes.description}\n >\n {description}\n </HvInfoMessage>\n )}\n </div>\n )}\n <HvBaseDropdown\n ref={dropdownForkedRef}\n id={setId(id, \"dropdown\")}\n classes={{\n root: cx(classes.dropdown, {\n [classes.readOnly]: readOnly,\n }),\n arrow: classes.arrow,\n header: cx(classes.dropdownHeader, {\n [classes.dropdownHeaderInvalid]: isStateInvalid,\n }),\n headerOpen: classes.dropdownHeaderOpen,\n }}\n expanded={isOpen}\n disabled={disabled}\n readOnly={readOnly}\n required={required}\n disablePortal={disablePortal}\n placement={placement}\n popperProps={popperProps}\n placeholder={buildHeaderLabel()}\n onToggle={handleToggle}\n onClickOutside={handleClickOutside}\n onContainerCreation={setFocusToContent}\n role=\"combobox\"\n variableWidth={variableWidth}\n aria-label={ariaLabel}\n aria-labelledby={\n [label && setId(elementId, \"label\"), ariaLabelledBy]\n .join(\" \")\n .trim() || undefined\n }\n aria-invalid={isStateInvalid ? true : undefined}\n aria-errormessage={errorMessageId}\n aria-describedby={\n [description && setId(elementId, \"description\"), ariaDescribedBy]\n .join(\" \")\n .trim() || undefined\n }\n onFocus={onFocus}\n onBlur={onBlur}\n dropdownHeaderRef={headerForkedRef}\n {...otherBaseDropdownProps}\n >\n <HvDropdownList\n id={setId(elementId, \"values\")}\n classes={{\n rootList: classes.rootList,\n dropdownListContainer: classes.dropdownListContainer,\n }}\n values={internalValues}\n multiSelect={multiSelect}\n showSearch={showSearch}\n onChange={handleSelection}\n onCancel={handleCancel}\n labels={labels}\n notifyChangesOnFirstRender={notifyChangesOnFirstRender}\n hasTooltips={hasTooltips}\n singleSelectionToggle={singleSelectionToggle}\n aria-label={ariaLabel}\n aria-labelledby={hasLabel ? setId(elementId, \"label\") : undefined}\n height={height}\n maxHeight={maxHeight}\n virtualized={virtualized}\n {...listProps}\n />\n </HvBaseDropdown>\n {canShowError && (\n <HvWarningText\n id={setId(elementId, \"error\")}\n disableBorder\n className={classes.error}\n >\n {validationMessage}\n </HvWarningText>\n )}\n </HvFormElement>\n );\n});\n"],"names":["HvDropdown"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmKA,MAAM,iBAAiB;AAAA;AAAA,EAErB,QAAQ;AAAA;AAAA,EAER,WAAW;AAAA;AAAA,EAEX,aAAa;AAAA;AAAA,EAEb,YAAY;AAAA;AAAA,EAEZ,mBAAmB;AAAA;AAAA,EAEnB,2BAA2B;AAC7B;AASO,MAAM,aAAa,gBAAgB,SAASA,YAIjD,OACA,KACA;AACM,QAAA;AAAA,IACJ,SAAS;AAAA,IACT;AAAA,IAEA;AAAA,IACA;AAAA,IAEA;AAAA,IACA;AAAA,IACA;AAAA,IAEA;AAAA,IACA,cAAc;AAAA,IACd,mBAAmB;AAAA,IACnB;AAAA,IACA,oBAAoB;AAAA,IAEpB,cAAc;AAAA,IAEd;AAAA,IAEA;AAAA,IACA;AAAA,IACA,qBAAqB;AAAA,IAErB;AAAA,IACA;AAAA,IACA;AAAA,IAEA;AAAA,IACA;AAAA,IAEA;AAAA,IACA,cAAc;AAAA,IACd;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA,wBAAwB;AAAA,IACxB;AAAA,IACA;AAAA,IACA,cAAc,CAAC;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA,oBAAoB,CAAC;AAAA,IACrB,YAAY,CAAC;AAAA,IACb,GAAG;AAAA,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;AAAA,gBACR;AAAA,gBACA;AAAA,gBACA,UAAU;AAAA,gBACV,UAAU;AAAA,gBACV;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA,cAAY;AAAA,gBACZ,mBAAiB,WAAW,MAAM,WAAW,OAAO,IAAI;AAAA,gBACxD;AAAA,gBACA;AAAA,gBACA;AAAA,gBACC,GAAG;AAAA,cAAA;AAAA,YAAA;AAAA,UACN;AAAA,QACF;AAAA,QACC,gBACC;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,IAAI,MAAM,WAAW,OAAO;AAAA,YAC5B,eAAa;AAAA,YACb,WAAW,QAAQ;AAAA,YAElB,UAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MACH;AAAA,IAAA;AAAA,EAEJ;AAEJ,CAAC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RightPanel.js","sources":["../../../../src/FilterGroup/RightPanel/RightPanel.tsx"],"sourcesContent":["import { useCallback, useContext, useEffect, useMemo, useState } from \"react\";\nimport { type ExtractNames } from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvCheckBox } from \"../../CheckBox\";\nimport { HvInput } from \"../../Input\";\nimport { HvList, HvListProps } from \"../../List\";\nimport { HvPanel } from \"../../Panel\";\nimport { CounterLabel } from \"../../utils/CounterLabel\";\nimport { setId } from \"../../utils/setId\";\nimport { HvFilterGroupContext } from \"../FilterGroupContext\";\nimport { staticClasses, useClasses } from \"./RightPanel.styles\";\n\nexport { staticClasses as filterGroupRightPanelClasses };\n\nexport type HvFilterGroupRightPanelClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvFilterGroupRightPanelProps {\n id?: string;\n className?: string;\n labels?: {\n searchBoxPlaceholder?: string;\n selectAll?: string;\n multiSelectionConjunction?: string;\n };\n emptyElement?: React.ReactNode;\n classes?: HvFilterGroupRightPanelClasses;\n}\n\nexport const HvFilterGroupRightPanel = ({\n id,\n className,\n labels,\n emptyElement,\n classes: classesProp,\n}: HvFilterGroupRightPanelProps) => {\n const { classes } = useClasses(classesProp);\n const [searchStr, setSearchStr] = useState(\"\");\n const [allSelected, setAllSelected] = useState(false);\n const [anySelected, setAnySelected] = useState(false);\n\n const {\n filterOptions,\n filterValues = [],\n setFilterValues,\n activeGroup,\n } = useContext(HvFilterGroupContext);\n\n const { all: allActiveGroupOptions, enabled: enabledActiveGroupOptions } =\n useMemo(() => {\n const filteredOptions = filterOptions[activeGroup]?.data.filter(\n (option) => option.name.toLowerCase().includes(searchStr.toLowerCase()),\n );\n\n return {\n all: filteredOptions?.map((option) => option.id) || [],\n enabled:\n filteredOptions\n ?.filter((option) => !option.disabled)\n ?.map((option) => option.id) || [],\n };\n }, [filterOptions, activeGroup, searchStr]);\n\n const activeFilterValues = useMemo(\n () =>\n filterValues[activeGroup]?.filter((value) =>\n allActiveGroupOptions.includes(value),\n ) || [],\n [filterValues, allActiveGroupOptions, activeGroup],\n );\n\n const listValues = useMemo(\n () =>\n filterOptions[activeGroup]?.data.map((option) => ({\n ...option,\n label: option.name,\n selected: filterValues[activeGroup]?.includes(option.id),\n isHidden:\n option.name.toLowerCase().indexOf(searchStr.toLowerCase()) < 0,\n })) || [],\n [filterOptions, filterValues, activeGroup, searchStr],\n );\n\n const updateSelectAll = useCallback(() => {\n const nbrSelected = activeFilterValues?.length;\n const hasSelection = nbrSelected > 0;\n const allSelect = nbrSelected === allActiveGroupOptions.length;\n\n setAnySelected(hasSelection);\n setAllSelected(hasSelection && allSelect);\n }, [activeFilterValues, allActiveGroupOptions]);\n\n useEffect(() => {\n updateSelectAll();\n }, [activeFilterValues, updateSelectAll]);\n\n useEffect(() => setSearchStr(\"\"), [activeGroup]);\n\n const onChangeHandler: HvListProps[\"onChange\"] = (values) => {\n const newFilterValues = filterOptions.map((_, i) =>\n activeGroup === i\n ? values.filter((v) => v.selected).map((v) => v.id)\n : [...(filterValues[i] || [])],\n );\n setFilterValues(newFilterValues as any);\n };\n\n const handleSelectAll = useCallback(() => {\n const newFilterValues = structuredClone(filterValues);\n\n if (anySelected) {\n if (searchStr !== \"\") {\n newFilterValues[activeGroup] = filterValues[activeGroup]?.filter(\n (value) => !enabledActiveGroupOptions.includes(value),\n );\n } else {\n newFilterValues[activeGroup] = [];\n }\n } else {\n const currentOptions = newFilterValues[activeGroup] || [];\n newFilterValues[activeGroup] = [\n ...currentOptions,\n ...enabledActiveGroupOptions,\n ];\n }\n\n setFilterValues(newFilterValues);\n }, [\n activeGroup,\n enabledActiveGroupOptions,\n anySelected,\n filterValues,\n setFilterValues,\n searchStr,\n ]);\n\n const SelectAll = useCallback(() => {\n return (\n <div className={classes.selectAllContainer}>\n <HvCheckBox\n id={setId(id, \"select-all\")}\n label={\n <CounterLabel\n selected={activeFilterValues?.length}\n total={allActiveGroupOptions.length}\n conjunctionLabel={labels?.multiSelectionConjunction}\n />\n }\n onChange={() => handleSelectAll()}\n className={classes.selectAll}\n indeterminate={anySelected && !allSelected}\n checked={allSelected}\n />\n </div>\n );\n }, [\n activeFilterValues?.length,\n allActiveGroupOptions.length,\n allSelected,\n anySelected,\n handleSelectAll,\n id,\n labels,\n classes?.selectAllContainer,\n classes?.selectAll,\n ]);\n\n return (\n <HvPanel id={setId(id, \"rightPanel\")} className={className}>\n {listValues.length > 0 ? (\n <>\n <HvInput\n id={setId(id, \"search\")}\n classes={{\n root: classes.search,\n }}\n type=\"search\"\n placeholder={labels?.searchBoxPlaceholder}\n value={searchStr}\n onChange={(_, str) => setSearchStr(str)}\n />\n <SelectAll />\n <HvList\n key={activeGroup}\n id={setId(id, \"list\")}\n values={listValues}\n className={classes.list}\n multiSelect\n useSelector\n showSelectAll={false}\n onChange={onChangeHandler}\n selectable\n condensed\n hasTooltips\n />\n </>\n ) : (\n emptyElement\n )}\n </HvPanel>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"RightPanel.js","sources":["../../../../src/FilterGroup/RightPanel/RightPanel.tsx"],"sourcesContent":["import { useCallback, useContext, useEffect, useMemo, useState } from \"react\";\nimport { type ExtractNames } from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvCheckBox } from \"../../CheckBox\";\nimport { HvInput } from \"../../Input\";\nimport { HvList, HvListProps } from \"../../List\";\nimport { HvPanel } from \"../../Panel\";\nimport { CounterLabel } from \"../../utils/CounterLabel\";\nimport { setId } from \"../../utils/setId\";\nimport { HvFilterGroupContext } from \"../FilterGroupContext\";\nimport { staticClasses, useClasses } from \"./RightPanel.styles\";\n\nexport { staticClasses as filterGroupRightPanelClasses };\n\nexport type HvFilterGroupRightPanelClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvFilterGroupRightPanelProps {\n id?: string;\n className?: string;\n labels?: {\n searchBoxPlaceholder?: string;\n /** @deprecated unused */\n selectAll?: string;\n multiSelectionConjunction?: string;\n };\n emptyElement?: React.ReactNode;\n classes?: HvFilterGroupRightPanelClasses;\n}\n\nexport const HvFilterGroupRightPanel = ({\n id,\n className,\n labels,\n emptyElement,\n classes: classesProp,\n}: HvFilterGroupRightPanelProps) => {\n const { classes } = useClasses(classesProp);\n const [searchStr, setSearchStr] = useState(\"\");\n const [allSelected, setAllSelected] = useState(false);\n const [anySelected, setAnySelected] = useState(false);\n\n const {\n filterOptions,\n filterValues = [],\n setFilterValues,\n activeGroup,\n } = useContext(HvFilterGroupContext);\n\n const { all: allActiveGroupOptions, enabled: enabledActiveGroupOptions } =\n useMemo(() => {\n const filteredOptions = filterOptions[activeGroup]?.data.filter(\n (option) => option.name.toLowerCase().includes(searchStr.toLowerCase()),\n );\n\n return {\n all: filteredOptions?.map((option) => option.id) || [],\n enabled:\n filteredOptions\n ?.filter((option) => !option.disabled)\n ?.map((option) => option.id) || [],\n };\n }, [filterOptions, activeGroup, searchStr]);\n\n const activeFilterValues = useMemo(\n () =>\n filterValues[activeGroup]?.filter((value) =>\n allActiveGroupOptions.includes(value),\n ) || [],\n [filterValues, allActiveGroupOptions, activeGroup],\n );\n\n const listValues = useMemo(\n () =>\n filterOptions[activeGroup]?.data.map((option) => ({\n ...option,\n label: option.name,\n selected: filterValues[activeGroup]?.includes(option.id),\n isHidden:\n option.name.toLowerCase().indexOf(searchStr.toLowerCase()) < 0,\n })) || [],\n [filterOptions, filterValues, activeGroup, searchStr],\n );\n\n const updateSelectAll = useCallback(() => {\n const nbrSelected = activeFilterValues?.length;\n const hasSelection = nbrSelected > 0;\n const allSelect = nbrSelected === allActiveGroupOptions.length;\n\n setAnySelected(hasSelection);\n setAllSelected(hasSelection && allSelect);\n }, [activeFilterValues, allActiveGroupOptions]);\n\n useEffect(() => {\n updateSelectAll();\n }, [activeFilterValues, updateSelectAll]);\n\n useEffect(() => setSearchStr(\"\"), [activeGroup]);\n\n const onChangeHandler: HvListProps[\"onChange\"] = (values) => {\n const newFilterValues = filterOptions.map((_, i) =>\n activeGroup === i\n ? values.filter((v) => v.selected).map((v) => v.id)\n : [...(filterValues[i] || [])],\n );\n setFilterValues(newFilterValues as any);\n };\n\n const handleSelectAll = useCallback(() => {\n const newFilterValues = structuredClone(filterValues);\n\n if (anySelected) {\n if (searchStr !== \"\") {\n newFilterValues[activeGroup] = filterValues[activeGroup]?.filter(\n (value) => !enabledActiveGroupOptions.includes(value),\n );\n } else {\n newFilterValues[activeGroup] = [];\n }\n } else {\n const currentOptions = newFilterValues[activeGroup] || [];\n newFilterValues[activeGroup] = [\n ...currentOptions,\n ...enabledActiveGroupOptions,\n ];\n }\n\n setFilterValues(newFilterValues);\n }, [\n activeGroup,\n enabledActiveGroupOptions,\n anySelected,\n filterValues,\n setFilterValues,\n searchStr,\n ]);\n\n const SelectAll = useCallback(() => {\n return (\n <div className={classes.selectAllContainer}>\n <HvCheckBox\n id={setId(id, \"select-all\")}\n label={\n <CounterLabel\n selected={activeFilterValues?.length}\n total={allActiveGroupOptions.length}\n conjunctionLabel={labels?.multiSelectionConjunction}\n />\n }\n onChange={() => handleSelectAll()}\n className={classes.selectAll}\n indeterminate={anySelected && !allSelected}\n checked={allSelected}\n />\n </div>\n );\n }, [\n activeFilterValues?.length,\n allActiveGroupOptions.length,\n allSelected,\n anySelected,\n handleSelectAll,\n id,\n labels,\n classes?.selectAllContainer,\n classes?.selectAll,\n ]);\n\n return (\n <HvPanel id={setId(id, \"rightPanel\")} className={className}>\n {listValues.length > 0 ? (\n <>\n <HvInput\n id={setId(id, \"search\")}\n classes={{\n root: classes.search,\n }}\n type=\"search\"\n placeholder={labels?.searchBoxPlaceholder}\n value={searchStr}\n onChange={(_, str) => setSearchStr(str)}\n />\n <SelectAll />\n <HvList\n key={activeGroup}\n id={setId(id, \"list\")}\n values={listValues}\n className={classes.list}\n multiSelect\n useSelector\n showSelectAll={false}\n onChange={onChangeHandler}\n selectable\n condensed\n hasTooltips\n />\n </>\n ) : (\n emptyElement\n )}\n </HvPanel>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;AA6BO,MAAM,0BAA0B,CAAC;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AACX,MAAoC;AAClC,QAAM,EAAE,QAAA,IAAY,WAAW,WAAW;AAC1C,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,EAAE;AAC7C,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,KAAK;AACpD,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,KAAK;AAE9C,QAAA;AAAA,IACJ;AAAA,IACA,eAAe,CAAC;AAAA,IAChB;AAAA,IACA;AAAA,EAAA,IACE,WAAW,oBAAoB;AAEnC,QAAM,EAAE,KAAK,uBAAuB,SAAS,0BAA0B,IACrE,QAAQ,MAAM;AACZ,UAAM,kBAAkB,cAAc,WAAW,GAAG,KAAK;AAAA,MACvD,CAAC,WAAW,OAAO,KAAK,cAAc,SAAS,UAAU,YAAa,CAAA;AAAA,IACxE;AAEO,WAAA;AAAA,MACL,KAAK,iBAAiB,IAAI,CAAC,WAAW,OAAO,EAAE,KAAK,CAAC;AAAA,MACrD,SACE,iBACI,OAAO,CAAC,WAAW,CAAC,O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EjB,qBAAA,UAAA,EAAA,UAAA;AAAA,IAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,IAAI,MAAM,IAAI,QAAQ;AAAA,QACtB,SAAS;AAAA,UACP,MAAM,QAAQ;AAAA,QAChB;AAAA,QACA,MAAK;AAAA,QACL,aAAa,QAAQ;AAAA,QACrB,OAAO;AAAA,QACP,UAAU,CAAC,GAAG,QAAQ,aAAa,GAAG;AAAA,MAAA;AAAA,IACxC;AAAA,wBACC,WAAU,EAAA;AAAA,IACX;AAAA,MAAC;AAAA,MAAA;AAAA,QAEC,IAAI,MAAM,IAAI,MAAM;AAAA,QACpB,QAAQ;AAAA,QACR,WAAW,QAAQ;AAAA,QACnB,aAAW;AAAA,QACX,aAAW;AAAA,QACX,eAAe;AAAA,QACf,UAAU;AAAA,QACV,YAAU;AAAA,QACV,WAAS;AAAA,QACT,aAAW;AAAA,MAAA;AAAA,MAVN;AAAA,IAAA;AAAA,EAWP,EACF,CAAA,IAEA,cAEJ;AAEJ;"}
|
|
@@ -39,12 +39,9 @@ const HvInlineEditor = fixedForwardRef(function HvInlineEditor2(props, ref) {
|
|
|
39
39
|
const [isOverflowing, setIsOverflowing] = useState(false);
|
|
40
40
|
const typographyStyles = activeTheme?.typography[variant] || {};
|
|
41
41
|
const { lineHeight } = typographyStyles;
|
|
42
|
-
const checkOverflow = () => {
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
inputRef.current.scrollWidth > inputRef.current.clientWidth
|
|
46
|
-
);
|
|
47
|
-
}
|
|
42
|
+
const checkOverflow = (el) => {
|
|
43
|
+
if (!el) return;
|
|
44
|
+
setIsOverflowing(el.scrollWidth > el.clientWidth);
|
|
48
45
|
};
|
|
49
46
|
useEnhancedEffect(() => {
|
|
50
47
|
const input = inputRef.current;
|
|
@@ -69,13 +66,11 @@ const HvInlineEditor = fixedForwardRef(function HvInlineEditor2(props, ref) {
|
|
|
69
66
|
newValue = cachedValue;
|
|
70
67
|
setEditMode(false);
|
|
71
68
|
setValue(newValue);
|
|
72
|
-
checkOverflow();
|
|
73
69
|
}
|
|
74
70
|
onKeyDown?.(event, newValue);
|
|
75
71
|
};
|
|
76
72
|
const handleChange = (event, val) => {
|
|
77
73
|
setValue(val);
|
|
78
|
-
checkOverflow();
|
|
79
74
|
onChange?.(event, val);
|
|
80
75
|
};
|
|
81
76
|
return /* @__PURE__ */ jsx("div", { className: cx(classes.root, className), children: editMode && !disabled ? /* @__PURE__ */ jsx(
|
|
@@ -85,8 +80,7 @@ const HvInlineEditor = fixedForwardRef(function HvInlineEditor2(props, ref) {
|
|
|
85
80
|
inputRef,
|
|
86
81
|
classes: {
|
|
87
82
|
root: classes.inputRoot,
|
|
88
|
-
input: classes.input
|
|
89
|
-
inputBorderContainer: classes.inputBorderContainer
|
|
83
|
+
input: classes.input
|
|
90
84
|
},
|
|
91
85
|
inputProps: {
|
|
92
86
|
style: {
|
|
@@ -100,7 +94,7 @@ const HvInlineEditor = fixedForwardRef(function HvInlineEditor2(props, ref) {
|
|
|
100
94
|
onKeyDown: handleKeyDown,
|
|
101
95
|
...others
|
|
102
96
|
}
|
|
103
|
-
) : /* @__PURE__ */ jsx(
|
|
97
|
+
) : /* @__PURE__ */ jsx(
|
|
104
98
|
HvButton,
|
|
105
99
|
{
|
|
106
100
|
variant: "secondaryGhost",
|
|
@@ -120,18 +114,20 @@ const HvInlineEditor = fixedForwardRef(function HvInlineEditor2(props, ref) {
|
|
|
120
114
|
onClick: handleClick,
|
|
121
115
|
disabled,
|
|
122
116
|
...buttonProps,
|
|
123
|
-
children: /* @__PURE__ */ jsx(
|
|
117
|
+
children: /* @__PURE__ */ jsx(HvTooltip, { title: isOverflowing && value, children: /* @__PURE__ */ jsx(
|
|
124
118
|
HvTypography,
|
|
125
119
|
{
|
|
120
|
+
component: "div",
|
|
121
|
+
ref: checkOverflow,
|
|
126
122
|
variant,
|
|
127
123
|
noWrap: true,
|
|
128
124
|
className: cx(classes.text, { [classes.textEmpty]: !value }),
|
|
129
125
|
...typographyProps,
|
|
130
126
|
children: value || placeholder
|
|
131
127
|
}
|
|
132
|
-
)
|
|
128
|
+
) })
|
|
133
129
|
}
|
|
134
|
-
) })
|
|
130
|
+
) });
|
|
135
131
|
});
|
|
136
132
|
export {
|
|
137
133
|
HvInlineEditor,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InlineEditor.js","sources":["../../../src/InlineEditor/InlineEditor.tsx"],"sourcesContent":["import { useRef, useState } from \"react\";\nimport { Edit } from \"@hitachivantara/uikit-react-icons\";\nimport {\n useDefaultProps,\n useTheme,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvButton, HvButtonProps } from \"../Button\";\nimport { useControlled } from \"../hooks/useControlled\";\nimport { useEnhancedEffect } from \"../hooks/useEnhancedEffect\";\nimport { HvInput, HvInputProps } from \"../Input\";\nimport { HvTooltip } from \"../Tooltip\";\nimport {\n fixedForwardRef,\n PolymorphicComponentRef,\n PolymorphicRef,\n} from \"../types/generic\";\nimport {\n HvTypography,\n HvTypographyProps,\n HvTypographyVariants,\n} from \"../Typography\";\nimport { isKey } from \"../utils/keyboardUtils\";\nimport { staticClasses, useClasses } from \"./InlineEditor.styles\";\n\nexport { staticClasses as inlineEditorClasses };\n\nexport type HvInlineEditorClasses = ExtractNames<typeof useClasses>;\n\nexport type HvInlineEditorProps<C extends React.ElementType = typeof HvInput> =\n PolymorphicComponentRef<\n C,\n {\n /** The value of the form element. */\n value?: string;\n /** The default value of the form element. */\n defaultValue?: string;\n /** Whether the Edit icon should always be visible */\n showIcon?: boolean;\n /** Variant of the HvTypography to display */\n variant?: HvTypographyVariants;\n /** Called when the input is blurred. */\n onBlur?: (\n event: React.FocusEvent<HTMLTextAreaElement | HTMLInputElement>,\n value: string,\n ) => void;\n /** Called when the input value changes. */\n onChange?: (event: React.SyntheticEvent, value: string) => void;\n /** Called when there's a keydown event on the input. */\n onKeyDown?: (\n event:\n | React.KeyboardEvent<HTMLTextAreaElement | HTMLInputElement>\n | React.MouseEvent,\n value: string,\n ) => void;\n /** Props passed to the HvButton component */\n buttonProps?: HvButtonProps;\n /** Props passed to the HvTypography text component */\n typographyProps?: HvTypographyProps;\n /** Whether the editor is disabled or not. */\n disabled?: boolean;\n /** A Jss Object used to override or extend the styles applied to the empty state component. */\n classes?: HvInlineEditorClasses;\n /** The placeholder value of the input. */\n placeholder?: string;\n }\n >;\n\n/**\n * An Inline Editor allows the user to edit a record without making a major switch\n * between viewing and editing, making it an efficient method of updating a record.\n */\nexport const HvInlineEditor = fixedForwardRef(function HvInlineEditor<\n C extends React.ElementType = typeof HvInput,\n>(props: HvInlineEditorProps<C>, ref: PolymorphicRef<C>) {\n const {\n className,\n classes: classesProp,\n value: valueProp,\n defaultValue = \"\",\n showIcon,\n component: InputComponent = HvInput,\n variant = \"body\",\n placeholder = \"Enter text\",\n onBlur,\n onChange,\n onKeyDown,\n buttonProps,\n typographyProps,\n disabled,\n ...others\n } = useDefaultProps(\"HvInlineEditor\", props);\n\n const { classes, cx } = useClasses(classesProp);\n const [value, setValue] = useControlled(valueProp, defaultValue);\n const [editMode, setEditMode] = useState(false);\n const [cachedValue, setCachedValue] = useState(value);\n const inputRef = useRef<HTMLInputElement>();\n const { activeTheme } = useTheme();\n const [isOverflowing, setIsOverflowing] = useState(false);\n\n const typographyStyles = activeTheme?.typography[variant] || {};\n const { lineHeight } = typographyStyles;\n\n const checkOverflow = () => {\n if (
|
|
1
|
+
{"version":3,"file":"InlineEditor.js","sources":["../../../src/InlineEditor/InlineEditor.tsx"],"sourcesContent":["import { useRef, useState } from \"react\";\nimport { Edit } from \"@hitachivantara/uikit-react-icons\";\nimport {\n useDefaultProps,\n useTheme,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvButton, HvButtonProps } from \"../Button\";\nimport { useControlled } from \"../hooks/useControlled\";\nimport { useEnhancedEffect } from \"../hooks/useEnhancedEffect\";\nimport { HvInput, HvInputProps } from \"../Input\";\nimport { HvTooltip } from \"../Tooltip\";\nimport {\n fixedForwardRef,\n PolymorphicComponentRef,\n PolymorphicRef,\n} from \"../types/generic\";\nimport {\n HvTypography,\n HvTypographyProps,\n HvTypographyVariants,\n} from \"../Typography\";\nimport { isKey } from \"../utils/keyboardUtils\";\nimport { staticClasses, useClasses } from \"./InlineEditor.styles\";\n\nexport { staticClasses as inlineEditorClasses };\n\nexport type HvInlineEditorClasses = ExtractNames<typeof useClasses>;\n\nexport type HvInlineEditorProps<C extends React.ElementType = typeof HvInput> =\n PolymorphicComponentRef<\n C,\n {\n /** The value of the form element. */\n value?: string;\n /** The default value of the form element. */\n defaultValue?: string;\n /** Whether the Edit icon should always be visible */\n showIcon?: boolean;\n /** Variant of the HvTypography to display */\n variant?: HvTypographyVariants;\n /** Called when the input is blurred. */\n onBlur?: (\n event: React.FocusEvent<HTMLTextAreaElement | HTMLInputElement>,\n value: string,\n ) => void;\n /** Called when the input value changes. */\n onChange?: (event: React.SyntheticEvent, value: string) => void;\n /** Called when there's a keydown event on the input. */\n onKeyDown?: (\n event:\n | React.KeyboardEvent<HTMLTextAreaElement | HTMLInputElement>\n | React.MouseEvent,\n value: string,\n ) => void;\n /** Props passed to the HvButton component */\n buttonProps?: HvButtonProps;\n /** Props passed to the HvTypography text component */\n typographyProps?: HvTypographyProps;\n /** Whether the editor is disabled or not. */\n disabled?: boolean;\n /** A Jss Object used to override or extend the styles applied to the empty state component. */\n classes?: HvInlineEditorClasses;\n /** The placeholder value of the input. */\n placeholder?: string;\n }\n >;\n\n/**\n * An Inline Editor allows the user to edit a record without making a major switch\n * between viewing and editing, making it an efficient method of updating a record.\n */\nexport const HvInlineEditor = fixedForwardRef(function HvInlineEditor<\n C extends React.ElementType = typeof HvInput,\n>(props: HvInlineEditorProps<C>, ref: PolymorphicRef<C>) {\n const {\n className,\n classes: classesProp,\n value: valueProp,\n defaultValue = \"\",\n showIcon,\n component: InputComponent = HvInput,\n variant = \"body\",\n placeholder = \"Enter text\",\n onBlur,\n onChange,\n onKeyDown,\n buttonProps,\n typographyProps,\n disabled,\n ...others\n } = useDefaultProps(\"HvInlineEditor\", props);\n\n const { classes, cx } = useClasses(classesProp);\n const [value, setValue] = useControlled(valueProp, defaultValue);\n const [editMode, setEditMode] = useState(false);\n const [cachedValue, setCachedValue] = useState(value);\n const inputRef = useRef<HTMLInputElement>();\n const { activeTheme } = useTheme();\n const [isOverflowing, setIsOverflowing] = useState(false);\n\n const typographyStyles = activeTheme?.typography[variant] || {};\n const { lineHeight } = typographyStyles;\n\n const checkOverflow = (el: HTMLElement | null) => {\n if (!el) return;\n setIsOverflowing(el.scrollWidth > el.clientWidth);\n };\n\n useEnhancedEffect(() => {\n const input = inputRef.current;\n if (editMode && input) {\n input.focus();\n input.select();\n }\n }, [editMode]);\n\n const handleClick = () => {\n setEditMode(true);\n setCachedValue(value);\n };\n\n const handleBlur: HvInputProps[\"onBlur\"] = (event) => {\n setEditMode(false);\n\n const newValue = value || cachedValue; // empty values should be ignored\n setValue(newValue);\n onBlur?.(event, newValue);\n };\n\n const handleKeyDown: HvInputProps[\"onKeyDown\"] = (event) => {\n let newValue = value;\n if (isKey(event, \"Esc\")) {\n newValue = cachedValue;\n setEditMode(false);\n setValue(newValue);\n }\n onKeyDown?.(event, newValue);\n };\n\n const handleChange: HvInputProps[\"onChange\"] = (event, val) => {\n setValue(val);\n onChange?.(event, val);\n };\n\n return (\n <div className={cx(classes.root, className)}>\n {editMode && !disabled ? (\n <InputComponent\n ref={ref}\n inputRef={inputRef}\n classes={{\n root: classes.inputRoot,\n input: classes.input,\n }}\n inputProps={{\n style: {\n ...typographyStyles,\n height: InputComponent === HvInput ? lineHeight : undefined,\n },\n }}\n value={value}\n onBlur={handleBlur}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n {...others}\n />\n ) : (\n <HvButton\n variant=\"secondaryGhost\"\n overrideIconColors={false}\n endIcon={\n <Edit\n color=\"secondary_60\"\n className={cx(classes.icon, {\n [classes.iconVisible]: showIcon,\n })}\n />\n }\n className={cx(classes.button, {\n [classes.largeText]: parseInt(lineHeight as string, 10) >= 28,\n })}\n onClick={handleClick}\n disabled={disabled}\n {...buttonProps}\n >\n <HvTooltip title={isOverflowing && value}>\n <HvTypography\n component=\"div\"\n ref={checkOverflow}\n variant={variant}\n noWrap\n className={cx(classes.text, { [classes.textEmpty]: !value })}\n {...typographyProps}\n >\n {value || placeholder}\n </HvTypography>\n </HvTooltip>\n </HvButton>\n )}\n </div>\n );\n});\n"],"names":["HvInlineEditor"],"mappings":";;;;;;;;;;;;;;AAyEO,MAAM,iBAAiB,gBAAgB,SAASA,gBAErD,OAA+B,KAAwB;AACjD,QAAA;AAAA,IACJ;AAAA,IACA,SAAS;AAAA,IACT,OAAO;AAAA,IACP,eAAe;AAAA,IACf;AAAA,IACA,WAAW,iBAAiB;AAAA,IAC5B,UAAU;AAAA,IACV,cAAc;AAAA,IACd;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,IACD,gBAAgB,kBAAkB,KAAK;AAE3C,QAAM,EAAE,SAAS,OAAO,WAAW,WAAW;AAC9C,QAAM,CAAC,OAAO,QAAQ,IAAI,cAAc,WAAW,YAAY;AAC/D,QAAM,CAAC,UAAU,WAAW,IAAI,SAAS,KAAK;AAC9C,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,KAAK;AACpD,QAAM,WAAW,OAAyB;AACpC,QAAA,EAAE,YAAY,IAAI,SAAS;AACjC,QAAM,CAAC,eAAe,gBAAgB,IAAI,SAAS,KAAK;AAExD,QAAM,mBAAmB,aAAa,WAAW,OAAO,KAAK,CAAC;AACxD,QAAA,EAAE,eAAe;AAEjB,QAAA,gBAAgB,CAAC,OAA2B;AAChD,QAAI,CAAC,GAAI;AACQ,qBAAA,GAAG,cAAc,GAAG,WAAW;AAAA,EAClD;AAEA,oBAAkB,MAAM;AACtB,UAAM,QAAQ,SAAS;AACvB,QAAI,YAAY,O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AAAA,QAAA;AAAA,MACH;AAAA,MAEF,WAAW,GAAG,QAAQ,QAAQ;AAAA,QAC5B,CAAC,QAAQ,SAAS,GAAG,SAAS,YAAsB,EAAE,KAAK;AAAA,MAAA,CAC5D;AAAA,MACD,SAAS;AAAA,MACT;AAAA,MACC,GAAG;AAAA,MAEJ,UAAC,oBAAA,WAAA,EAAU,OAAO,iBAAiB,OACjC,UAAA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,WAAU;AAAA,UACV,KAAK;AAAA,UACL;AAAA,UACA,QAAM;AAAA,UACN,WAAW,GAAG,QAAQ,MAAM,EAAE,CAAC,QAAQ,SAAS,GAAG,CAAC,OAAO;AAAA,UAC1D,GAAG;AAAA,UAEH,UAAS,SAAA;AAAA,QAAA;AAAA,MAAA,EAEd,CAAA;AAAA,IAAA;AAAA,EAAA,GAGN;AAEJ,CAAC;"}
|
|
@@ -1,28 +1,15 @@
|
|
|
1
1
|
import { createClasses } from "@hitachivantara/uikit-react-utils";
|
|
2
2
|
import { theme } from "@hitachivantara/uikit-styles";
|
|
3
|
-
import { staticClasses as staticClasses$1 } from "../BaseInput/BaseInput.styles.js";
|
|
4
|
-
import "../BaseInput/BaseInput.js";
|
|
5
|
-
import { staticClasses as staticClasses$2 } from "../Input/Input.styles.js";
|
|
6
|
-
import "../Input/Input.js";
|
|
7
3
|
const { staticClasses, useClasses } = createClasses("HvInlineEditor", {
|
|
8
|
-
root: {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
minHeight: "32px"
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
inputBorderContainer: {
|
|
15
|
-
top: "unset",
|
|
16
|
-
bottom: 0
|
|
17
|
-
},
|
|
4
|
+
root: {},
|
|
5
|
+
/** @deprecated unused. use `classes.root::after` instead */
|
|
6
|
+
inputBorderContainer: {},
|
|
18
7
|
input: {},
|
|
19
|
-
inputRoot: {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
textOverflow: "ellipsis",
|
|
23
|
-
whiteSpace: "nowrap",
|
|
24
|
-
alignSelf: "center"
|
|
8
|
+
inputRoot: {
|
|
9
|
+
height: "100%",
|
|
10
|
+
minHeight: "32px"
|
|
25
11
|
},
|
|
12
|
+
text: {},
|
|
26
13
|
largeText: {},
|
|
27
14
|
textEmpty: {
|
|
28
15
|
color: theme.colors.secondary_60
|
|
@@ -35,41 +22,31 @@ const { staticClasses, useClasses } = createClasses("HvInlineEditor", {
|
|
|
35
22
|
height: "100%",
|
|
36
23
|
width: "100%",
|
|
37
24
|
maxWidth: "100%",
|
|
38
|
-
justifyContent: "
|
|
25
|
+
justifyContent: "start",
|
|
26
|
+
textAlign: "start",
|
|
39
27
|
alignItems: "center",
|
|
40
28
|
backgroundColor: theme.colors.atmo1,
|
|
41
|
-
|
|
29
|
+
borderColor: "transparent",
|
|
42
30
|
"&:hover, &:focus": {
|
|
43
|
-
|
|
31
|
+
borderColor: theme.colors.primary,
|
|
44
32
|
backgroundColor: theme.colors.atmo1,
|
|
45
33
|
"& $icon": {
|
|
46
34
|
visibility: "visible"
|
|
47
35
|
}
|
|
48
36
|
},
|
|
49
37
|
"&:active": {
|
|
50
|
-
|
|
38
|
+
borderColor: theme.colors.secondary,
|
|
51
39
|
backgroundColor: "transparent",
|
|
52
40
|
"& $icon": {
|
|
53
41
|
visibility: "visible"
|
|
54
42
|
}
|
|
55
|
-
},
|
|
56
|
-
"& > div": {
|
|
57
|
-
width: "100%"
|
|
58
|
-
},
|
|
59
|
-
"& > div > span": {
|
|
60
|
-
width: "100%"
|
|
61
43
|
}
|
|
62
44
|
},
|
|
63
45
|
icon: {
|
|
64
46
|
cursor: "pointer",
|
|
65
47
|
visibility: "hidden",
|
|
66
48
|
alignSelf: "center",
|
|
67
|
-
height:
|
|
68
|
-
width: "32px",
|
|
69
|
-
minWidth: "32px",
|
|
70
|
-
"& svg": {
|
|
71
|
-
margin: theme.spacing(0, "xs")
|
|
72
|
-
}
|
|
49
|
+
height: 16
|
|
73
50
|
},
|
|
74
51
|
iconVisible: {
|
|
75
52
|
visibility: "visible"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InlineEditor.styles.js","sources":["../../../src/InlineEditor/InlineEditor.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\
|
|
1
|
+
{"version":3,"file":"InlineEditor.styles.js","sources":["../../../src/InlineEditor/InlineEditor.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvInlineEditor\", {\n root: {},\n /** @deprecated unused. use `classes.root::after` instead */\n inputBorderContainer: {},\n input: {},\n inputRoot: {\n height: \"100%\",\n minHeight: \"32px\",\n },\n text: {},\n largeText: {},\n textEmpty: {\n color: theme.colors.secondary_60,\n },\n button: {\n padding: theme.spacing(\"6px\", \"8px\", \"5px\", \"8px\"),\n minHeight: \"32px\",\n\n boxSizing: \"border-box\",\n cursor: \"text\",\n height: \"100%\",\n width: \"100%\",\n maxWidth: \"100%\",\n justifyContent: \"start\",\n textAlign: \"start\",\n alignItems: \"center\",\n\n backgroundColor: theme.colors.atmo1,\n borderColor: \"transparent\",\n\n \"&:hover, &:focus\": {\n borderColor: theme.colors.primary,\n backgroundColor: theme.colors.atmo1,\n\n \"& $icon\": {\n visibility: \"visible\",\n },\n },\n\n \"&:active\": {\n borderColor: theme.colors.secondary,\n backgroundColor: \"transparent\",\n\n \"& $icon\": {\n visibility: \"visible\",\n },\n },\n },\n icon: {\n cursor: \"pointer\",\n visibility: \"hidden\",\n alignSelf: \"center\",\n height: 16,\n },\n iconVisible: {\n visibility: \"visible\",\n },\n});\n"],"names":[],"mappings":";;AAGO,MAAM,EAAE,eAAe,eAAe,cAAc,kBAAkB;AAAA,EAC3E,MAAM,CAAC;AAAA;AAAA,EAEP,sBAAsB,CAAC;AAAA,EACvB,OAAO,CAAC;AAAA,EACR,WAAW;AAAA,IACT,QAAQ;AAAA,IACR,WAAW;AAAA,EACb;AAAA,EACA,MAAM,CAAC;AAAA,EACP,WAAW,CAAC;AAAA,EACZ,WAAW;AAAA,IACT,OAAO,MAAM,OAAO;AAAA,EACtB;AAAA,EACA,QAAQ;AAAA,IACN,SAAS,MAAM,QAAQ,OAAO,OAAO,OAAO,KAAK;AAAA,IACjD,WAAW;AAAA,IAEX,WAAW;AAAA,IACX,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,UAAU;AAAA,IACV,gBAAgB;AAAA,IAChB,WAAW;AAAA,IACX,YAAY;AAAA,IAEZ,iBAAiB,MAAM,OAAO;AAAA,IAC9B,aAAa;AAAA,IAEb,oBAAoB;AAAA,MAClB,aAAa,MAAM,OAAO;AAAA,MAC1B,iBAAiB,MAAM,OAAO;AAAA,MAE9B,WAAW;AAAA,QACT,YAAY;AAAA,MAAA;AAAA,IAEhB;AAAA,IAEA,YAAY;AAAA,MACV,aAAa,MAAM,OAAO;AAAA,MAC1B,iBAAiB;AAAA,MAEjB,WAAW;AAAA,QACT,YAAY;AAAA,MAAA;AAAA,IACd;AAAA,EAEJ;AAAA,EACA,MAAM;AAAA,IACJ,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,QAAQ;AAAA,EACV;AAAA,EACA,aAAa;AAAA,IACX,YAAY;AAAA,EAAA;AAEhB,CAAC;"}
|
package/dist/esm/Input/Input.js
CHANGED
|
@@ -447,11 +447,10 @@ const HvInput = fixedForwardRef(function HvInput2(props, ref) {
|
|
|
447
447
|
type: realType,
|
|
448
448
|
classes: {
|
|
449
449
|
input: classes.input,
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
inputBorderContainer: classes.inputBorderContainer
|
|
450
|
+
root: classes.inputRoot,
|
|
451
|
+
focused: classes.inputRootFocused,
|
|
452
|
+
disabled: classes.inputRootDisabled,
|
|
453
|
+
multiline: classes.inputRootMultiline
|
|
455
454
|
},
|
|
456
455
|
invalid: isStateInvalid,
|
|
457
456
|
inputProps: {
|