@neo4j-ndl/react 4.0.16 → 4.0.18

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.
@@ -160,7 +160,22 @@ const DatePicker = (_a) => {
160
160
  }
161
161
  setPreSelectedDate(date);
162
162
  }, [picker, preSelectedDate, reactDatePickerProps]);
163
- const datePickerProps = Object.assign(Object.assign({}, reactDatePickerProps), { onCalendarClose: interceptedOnCalendarClose, onChange: interceptedChange, onMonthChange: handleMonthChange });
163
+ /**
164
+ * Intercept onChangeRaw to handle clearing the input
165
+ * When the user clears the text input, set the date to null
166
+ */
167
+ const interceptedOnChangeRaw = (0, react_1.useCallback)((event) => {
168
+ var _a;
169
+ const target = event === null || event === void 0 ? void 0 : event.target;
170
+ if ((target === null || target === void 0 ? void 0 : target.value) === '') {
171
+ setPreSelectedDate(null);
172
+ if (reactDatePickerProps.onChange) {
173
+ reactDatePickerProps.onChange(null, event);
174
+ }
175
+ }
176
+ (_a = reactDatePickerProps === null || reactDatePickerProps === void 0 ? void 0 : reactDatePickerProps.onChangeRaw) === null || _a === void 0 ? void 0 : _a.call(reactDatePickerProps, event);
177
+ }, [reactDatePickerProps]);
178
+ const datePickerProps = Object.assign(Object.assign({}, reactDatePickerProps), { onCalendarClose: interceptedOnCalendarClose, onChange: interceptedChange, onChangeRaw: interceptedOnChangeRaw, onMonthChange: handleMonthChange });
164
179
  return ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: classes, ref: ref, style: style }, restProps, htmlAttributes, { children: (0, jsx_runtime_1.jsx)(react_datepicker_1.default, Object.assign({ ref: datetimeRef, customInput: (0, jsx_runtime_1.jsx)(DatePickerTextInputWrapper, { isDisabled: isDisabled, textInputProps: textInputProps }), customTimeInput: (0, jsx_runtime_1.jsxs)("span", { children: [(0, jsx_runtime_1.jsx)(divider_1.Divider, { className: "n-my-4" }), (0, jsx_runtime_1.jsx)(time_picker_1.TimePicker, Object.assign({ isFluid: true, value: preSelectedDate
165
180
  ? new time_picker_1.NeedleTime(preSelectedDate.getHours(), preSelectedDate.getMinutes())
166
181
  : undefined, onChange: handleTimeChange }, timePickerProps, { floatingStrategy: "absolute", isPortaled: false }))] }), disabled: isDisabled, showPopperArrow: false, showMonthYearPicker: picker === 'month', showYearPicker: picker === 'year', shouldCloseOnSelect: picker === 'day' && !((_b = reactDatePickerProps.showTimeInput) !== null && _b !== void 0 ? _b : false), dayClassName: () => 'ndl-datepicker-day', renderCustomHeader: CustomHeader }, datePickerProps, { popperClassName: (0, classnames_1.default)('ndl-datepicker-popper', reactDatePickerProps.popperClassName), popperProps: Object.assign({ strategy: isInsideDialog ? 'fixed' : 'absolute' }, reactDatePickerProps.popperProps) })) })));
@@ -1 +1 @@
1
- {"version":3,"file":"DatePicker.js","sourceRoot":"","sources":["../../../src/date-picker/DatePicker.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,iCAAiC;AACjC,yDAAyD;AAEzD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,4DAAoC;AACpC,uCAAkC;AAClC,iCAAsD;AACtD,wEAE0B;AAG1B,4DAAuD;AACvD,6DAA6D;AAC7D,wCAAqC;AACrC,oCAKkB;AAClB,8CAA0C;AAC1C,gDAA8E;AAC9E,8CAA2C;AAC3C,mCAA4D;AAQ5D,2EAA2E;AAC3E,6EAA6E;AAC7E,8DAA8D;AAC9D,MAAM,0BAA0B,GAAG,CAAC,EAMF,EAAE,EAAE;QANF,EAClC,cAAc,EACd,UAAU,EACV,KAAK,EACL,WAAW,OAEqB,EAD7B,SAAS,cALsB,wDAMnC,CADa;IAEZ,iFAAiF;IACjF,MAAM,KAKF,cAAc,aAAd,cAAc,cAAd,cAAc,GAAI,EAAE,EALlB,EACJ,WAAW,EAAE,oBAAoB,EACjC,cAAc,EAAE,uBAAuB,EACvC,GAAG,OAEmB,EADnB,kBAAkB,cAJjB,wCAKL,CAAuB,CAAC;IAEzB,OAAO,CACL,uBAAC,sBAAS,kBACR,GAAG,EA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,OAAO,EACvC,cAAc,EAAE,MAAM,KAAK,MAAM,EACjC,mBAAmB,EACjB,MAAM,KAAK,KAAK,IAAI,CAAC,CAAC,MAAA,oBAAoB,CAAC,aAAa,mCAAI,KAAK,CAAC,EAEpE,YAAY,EAAE,GAAG,EAAE,CAAC,oBAAoB,EACxC,kBAAkB,EAAE,YAAY,IAC5B,eAAe,IACnB,eAAe,EAAE,IAAA,oBAAU,EACzB,uBAAuB,EACvB,oBAAoB,CAAC,eAAe,CACrC,EACD,WAAW,kBACT,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,IAC5C,oBAAoB,CAAC,WAAW,KAErC,IACE,CACP,CAAC;AACJ,CAAC,CAAC;AAtRW,QAAA,UAAU,cAsRrB","sourcesContent":["// TODO: try to fix as some point\n/* eslint-disable @typescript-eslint/naming-convention */\n\n/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport classNames from 'classnames';\nimport { format } from 'date-fns';\nimport { useCallback, useRef, useState } from 'react';\nimport ReactDatePicker, {\n type ReactDatePickerCustomHeaderProps,\n} from 'react-datepicker';\n\nimport type { CommonProps } from '../_common/types';\nimport { CleanIconButton } from '../clean-icon-button';\nimport { useIsInsideDialog } from '../dialog/dialog-context';\nimport { Divider } from '../divider';\nimport {\n ArrowLeftIconOutline,\n ArrowRightIconOutline,\n CalendarDaysIconOutline,\n ChevronDownIconOutline,\n} from '../icons';\nimport { TextInput } from '../text-input';\nimport { NeedleTime, TimePicker, type TimePickerProps } from '../time-picker';\nimport { Typography } from '../typography';\nimport { daysInMonth, getYearsPeriodString } from './utils';\n\ntype DatePickerTextInputWrapperProps = React.ComponentProps<'input'> & {\n textInputProps?: React.ComponentProps<typeof TextInput>;\n isDisabled?: boolean;\n value?: string;\n};\n\n// This wrapper is needed due to react-datepicker injecting html attributes\n// into the custom input component on root level, since we use htmlAttributes\n// we need to help spread them there instead of the root level\nconst DatePickerTextInputWrapper = ({\n textInputProps,\n isDisabled,\n value,\n placeholder,\n ...restProps\n}: DatePickerTextInputWrapperProps) => {\n // deconstruct textInputProps to avoid bugs with react-datepicker injecting props\n const {\n placeholder: textInputPlaceholder,\n htmlAttributes: textInputHtmlAttributes,\n ref,\n ...restTextInputProps\n } = textInputProps ?? {};\n\n return (\n <TextInput\n ref={ref}\n aria-label=\"Date picker input\"\n trailingElement={\n <CalendarDaysIconOutline className=\"ndl-datepicker-icon\" />\n }\n value={value}\n placeholder={placeholder ?? textInputPlaceholder}\n isDisabled={isDisabled}\n // react-datepicker injects html attributes into the custom input\n htmlAttributes={{\n ...textInputHtmlAttributes,\n ...restProps,\n }}\n {...restTextInputProps}\n />\n );\n};\n\n/**\n *\n *\n * Types\n *\n *\n */\n\ntype PickerType = 'day' | 'month' | 'year';\n\n// Define a more flexible type for onChange\ntype DatePickerChangeHandler = (\n date: Date | null | [Date | null, Date | null] | Date[],\n event?: React.SyntheticEvent | undefined,\n) => void;\n\ninterface DatePickerProps {\n /** Props for the embedded `TextInput` component. */\n textInputProps?: React.ComponentProps<typeof TextInput>;\n /** Whether the date picker is disabled. */\n isDisabled?: boolean;\n /** Props for the embedded `TimePicker` component. */\n timePickerProps?: TimePickerProps;\n /** Props forwarded to underlying `react-datepicker` component. */\n reactDatePickerProps: React.ComponentProps<typeof ReactDatePicker>;\n}\n\nexport const DatePicker = ({\n reactDatePickerProps,\n textInputProps,\n timePickerProps,\n isDisabled,\n ref,\n className,\n style,\n htmlAttributes,\n ...restProps\n}: CommonProps<'div', DatePickerProps>) => {\n const classes = classNames(`ndl-datepicker`, className, {});\n const datetimeRef = useRef<ReactDatePicker>(null);\n const [picker, setPicker] = useState<PickerType>('day');\n const [preSelectedDate, setPreSelectedDate] = useState<Date | null>(\n (reactDatePickerProps.selected as Date | null) ||\n (reactDatePickerProps.startDate as Date | null),\n );\n\n const isInsideDialog = useIsInsideDialog();\n\n const headerAction = useCallback(\n (action: PickerType) => {\n setPicker(picker === action ? 'day' : action);\n },\n [picker],\n );\n\n const CustomHeader = useCallback(\n (props: ReactDatePickerCustomHeaderProps) => {\n const {\n decreaseMonth,\n increaseMonth,\n increaseYear,\n decreaseYear,\n nextMonthButtonDisabled,\n nextYearButtonDisabled,\n prevMonthButtonDisabled,\n prevYearButtonDisabled,\n } = props;\n\n const prevCallback = picker === 'year' ? decreaseYear : decreaseMonth;\n const nextCallback = picker === 'year' ? increaseYear : increaseMonth;\n const prevDisabled =\n picker === 'year' ? prevYearButtonDisabled : prevMonthButtonDisabled;\n const nextDisabled =\n picker === 'year' ? nextYearButtonDisabled : nextMonthButtonDisabled;\n\n return (\n <div className=\"ndl-datepicker-header\">\n <div className=\"ndl-datepicker-selects\">\n {picker !== 'year' && (\n <button\n aria-label={`${picker === 'month' ? 'Close' : 'Open'} month picker`}\n aria-pressed={picker === 'month'}\n onClick={() => headerAction('month')}\n >\n <div className=\"n-flex n-items-center n-gap-token-4\">\n <Typography variant=\"subheading-small\">\n {format(props.date, 'MMM')}\n </Typography>\n <ChevronDownIconOutline\n className={classNames('ndl-datepicker-chevron', {\n 'n-rotate-180': picker === 'month',\n })}\n aria-label=\"Chevron icon\"\n />\n </div>\n </button>\n )}\n {picker !== 'month' && (\n <button\n aria-label={`${picker === 'year' ? 'Close' : 'Open'} year picker`}\n onClick={() => headerAction('year')}\n >\n <div className=\"n-flex n-items-center n-gap-token-4\">\n <Typography variant=\"subheading-small\">\n {picker === 'year'\n ? getYearsPeriodString(\n props.date,\n reactDatePickerProps?.yearItemNumber,\n )\n : format(props.date, 'yyyy')}\n </Typography>\n <ChevronDownIconOutline\n className={classNames('ndl-datepicker-chevron', {\n 'n-rotate-180': picker === 'year',\n })}\n aria-label=\"Chevron icon\"\n />\n </div>\n </button>\n )}\n </div>\n {picker !== 'month' && (\n <div className=\"n-flex n-justify-center n-gap-token-16\">\n <CleanIconButton\n description={\n picker === 'year' ? 'Previous period' : 'Previous month'\n }\n onClick={prevCallback}\n isDisabled={prevDisabled}\n className=\"n-text-neutral-text-weak\"\n size=\"small\"\n >\n <ArrowLeftIconOutline />\n </CleanIconButton>\n <CleanIconButton\n description={picker === 'year' ? 'Next period' : 'Next month'}\n onClick={nextCallback}\n isDisabled={nextDisabled}\n className=\"n-text-neutral-text-weak\"\n size=\"small\"\n >\n <ArrowRightIconOutline />\n </CleanIconButton>\n </div>\n )}\n </div>\n );\n },\n [picker, headerAction, reactDatePickerProps?.yearItemNumber],\n );\n\n const handleTimeChange = (newTime: NeedleTime) => {\n if (\n reactDatePickerProps.selectsRange ||\n reactDatePickerProps.selectsMultiple\n ) {\n // this is consistent with the behavior of react-datepicker\n return;\n }\n\n if (!preSelectedDate) return;\n\n const newDate = new Date(preSelectedDate);\n newDate.setHours(newTime.hour, newTime.minute, 0, 0);\n setPreSelectedDate(newDate);\n\n if (reactDatePickerProps.onChange) {\n // For single date selection\n reactDatePickerProps.onChange(newDate, undefined);\n }\n };\n\n /**\n * Intercept onChange so we can work with\n * Month and Year pickers\n */\n const interceptedChange: DatePickerChangeHandler = useCallback(\n (\n date: Date | null | [Date | null, Date | null] | Date[],\n event?: React.SyntheticEvent,\n ) => {\n if (picker !== 'day') {\n // setTimeout to prevent picker change before the handleMonthChange logic\n setTimeout(() => {\n setPicker('day');\n });\n } else if (picker === 'day') {\n if (date instanceof Date) {\n setPreSelectedDate(date);\n } else if (\n Array.isArray(date) &&\n date.length > 0 &&\n date[0] instanceof Date\n ) {\n setPreSelectedDate(date[0]);\n } else if (date === null) {\n setPreSelectedDate(null);\n }\n\n if (reactDatePickerProps.onChange && date !== null) {\n (reactDatePickerProps.onChange as DatePickerChangeHandler)(\n date,\n event,\n );\n }\n }\n },\n [picker, reactDatePickerProps],\n );\n\n /**\n * Intercept onCalendarClose so we can\n * switch to \"day\" picker if we close on \"month\" or \"year\"\n * view\n */\n const interceptedOnCalendarClose = useCallback(() => {\n if (picker !== 'day') {\n setPicker('day');\n }\n reactDatePickerProps?.onCalendarClose?.();\n }, [picker, reactDatePickerProps]);\n\n const handleMonthChange = useCallback(\n (date: Date) => {\n if (picker === 'month') {\n const selectedDay = preSelectedDate?.getDate() ?? 1;\n const daysInNewMonth = daysInMonth(date.getMonth(), date.getFullYear());\n date.setDate(Math.min(selectedDay, daysInNewMonth));\n reactDatePickerProps?.onMonthChange?.(date);\n } else if (picker === 'year') {\n const selectedDay = preSelectedDate?.getDate() ?? 1;\n const selectedMonth = preSelectedDate?.getMonth() ?? 0;\n const daysInNewMonth = daysInMonth(selectedMonth, date.getFullYear());\n date.setMonth(selectedMonth, Math.min(selectedDay, daysInNewMonth));\n reactDatePickerProps?.onMonthChange?.(date);\n }\n setPreSelectedDate(date);\n },\n [picker, preSelectedDate, reactDatePickerProps],\n );\n\n const datePickerProps = {\n ...reactDatePickerProps,\n onCalendarClose: interceptedOnCalendarClose,\n onChange: interceptedChange,\n onMonthChange: handleMonthChange,\n };\n\n return (\n <div\n className={classes}\n ref={ref}\n style={style}\n {...restProps}\n {...htmlAttributes}\n >\n <ReactDatePicker\n ref={datetimeRef}\n customInput={\n <DatePickerTextInputWrapper\n isDisabled={isDisabled}\n textInputProps={textInputProps}\n />\n }\n customTimeInput={\n <span>\n <Divider className=\"n-my-4\" />\n <TimePicker\n isFluid\n value={\n preSelectedDate\n ? new NeedleTime(\n preSelectedDate.getHours(),\n preSelectedDate.getMinutes(),\n )\n : undefined\n }\n onChange={handleTimeChange}\n {...timePickerProps}\n floatingStrategy=\"absolute\"\n isPortaled={false}\n />\n </span>\n }\n disabled={isDisabled}\n showPopperArrow={false}\n showMonthYearPicker={picker === 'month'}\n showYearPicker={picker === 'year'}\n shouldCloseOnSelect={\n picker === 'day' && !(reactDatePickerProps.showTimeInput ?? false)\n }\n dayClassName={() => 'ndl-datepicker-day'}\n renderCustomHeader={CustomHeader}\n {...datePickerProps}\n popperClassName={classNames(\n 'ndl-datepicker-popper',\n reactDatePickerProps.popperClassName,\n )}\n popperProps={{\n strategy: isInsideDialog ? 'fixed' : 'absolute',\n ...reactDatePickerProps.popperProps,\n }}\n />\n </div>\n );\n};\n"]}
1
+ {"version":3,"file":"DatePicker.js","sourceRoot":"","sources":["../../../src/date-picker/DatePicker.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,iCAAiC;AACjC,yDAAyD;AAEzD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,4DAAoC;AACpC,uCAAkC;AAClC,iCAAsD;AACtD,wEAE0B;AAG1B,4DAAuD;AACvD,6DAA6D;AAC7D,wCAAqC;AACrC,oCAKkB;AAClB,8CAA0C;AAC1C,gDAA8E;AAC9E,8CAA2C;AAC3C,mCAA4D;AAQ5D,2EAA2E;AAC3E,6EAA6E;AAC7E,8DAA8D;AAC9D,MAAM,0BAA0B,GAAG,CAAC,EAMF,EAAE,EAAE;QANF,EAClC,cAAc,EACd,UAAU,EACV,KAAK,EACL,WAAW,OAEqB,EAD7B,SAAS,cALsB,wDAMnC,CADa;IAEZ,iFAAiF;IACjF,MAAM,KAKF,cAAc,aAAd,cAAc,cAAd,cAAc,GAAI,EAAE,EALlB,EACJ,WAAW,EAAE,oBAAoB,EACjC,cAAc,EAAE,uBAAuB,EACvC,GAAG,OAEmB,EADnB,kBAAkB,cAJjB,wCAKL,CAAuB,CAAC;IAEzB,OAAO,CACL,uBAAC,sBAAS,kBACR,GAAG,EAAE,GAAG,gBACG,mBAAmB,EAC9B,eAAe,EACb,uBAAC,+BAAuB,IAAC,SAAS,EAAC,qBAAqB,GAAG,EAE7D,KAAK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U,EAAE,UAAU,EACtB,cAAc,EAAE,cAAc,GAC9B,EAEJ,eAAe,EACb,6CACE,uBAAC,iBAAO,IAAC,SAAS,EAAC,QAAQ,GAAG,EAC9B,uBAAC,wBAAU,kBACT,OAAO,QACP,KAAK,EACH,eAAe;4BACb,CAAC,CAAC,IAAI,wBAAU,CACZ,eAAe,CAAC,QAAQ,EAAE,EAC1B,eAAe,CAAC,UAAU,EAAE,CAC7B;4BACH,CAAC,CAAC,SAAS,EAEf,QAAQ,EAAE,gBAAgB,IACtB,eAAe,IACnB,gBAAgB,EAAC,UAAU,EAC3B,UAAU,EAAE,KAAK,IACjB,IACG,EAET,QAAQ,EAAE,UAAU,EACpB,eAAe,EAAE,KAAK,EACtB,mBAAmB,EAAE,MAAM,KAAK,OAAO,EACvC,cAAc,EAAE,MAAM,KAAK,MAAM,EACjC,mBAAmB,EACjB,MAAM,KAAK,KAAK,IAAI,CAAC,CAAC,MAAA,oBAAoB,CAAC,aAAa,mCAAI,KAAK,CAAC,EAEpE,YAAY,EAAE,GAAG,EAAE,CAAC,oBAAoB,EACxC,kBAAkB,EAAE,YAAY,IAC5B,eAAe,IACnB,eAAe,EAAE,IAAA,oBAAU,EACzB,uBAAuB,EACvB,oBAAoB,CAAC,eAAe,CACrC,EACD,WAAW,kBACT,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,IAC5C,oBAAoB,CAAC,WAAW,KAErC,IACE,CACP,CAAC;AACJ,CAAC,CAAC;AAhTW,QAAA,UAAU,cAgTrB","sourcesContent":["// TODO: try to fix as some point\n/* eslint-disable @typescript-eslint/naming-convention */\n\n/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport classNames from 'classnames';\nimport { format } from 'date-fns';\nimport { useCallback, useRef, useState } from 'react';\nimport ReactDatePicker, {\n type ReactDatePickerCustomHeaderProps,\n} from 'react-datepicker';\n\nimport type { CommonProps } from '../_common/types';\nimport { CleanIconButton } from '../clean-icon-button';\nimport { useIsInsideDialog } from '../dialog/dialog-context';\nimport { Divider } from '../divider';\nimport {\n ArrowLeftIconOutline,\n ArrowRightIconOutline,\n CalendarDaysIconOutline,\n ChevronDownIconOutline,\n} from '../icons';\nimport { TextInput } from '../text-input';\nimport { NeedleTime, TimePicker, type TimePickerProps } from '../time-picker';\nimport { Typography } from '../typography';\nimport { daysInMonth, getYearsPeriodString } from './utils';\n\ntype DatePickerTextInputWrapperProps = React.ComponentProps<'input'> & {\n textInputProps?: React.ComponentProps<typeof TextInput>;\n isDisabled?: boolean;\n value?: string;\n};\n\n// This wrapper is needed due to react-datepicker injecting html attributes\n// into the custom input component on root level, since we use htmlAttributes\n// we need to help spread them there instead of the root level\nconst DatePickerTextInputWrapper = ({\n textInputProps,\n isDisabled,\n value,\n placeholder,\n ...restProps\n}: DatePickerTextInputWrapperProps) => {\n // deconstruct textInputProps to avoid bugs with react-datepicker injecting props\n const {\n placeholder: textInputPlaceholder,\n htmlAttributes: textInputHtmlAttributes,\n ref,\n ...restTextInputProps\n } = textInputProps ?? {};\n\n return (\n <TextInput\n ref={ref}\n aria-label=\"Date picker input\"\n trailingElement={\n <CalendarDaysIconOutline className=\"ndl-datepicker-icon\" />\n }\n value={value}\n placeholder={placeholder ?? textInputPlaceholder}\n isDisabled={isDisabled}\n // react-datepicker injects html attributes into the custom input\n htmlAttributes={{\n ...textInputHtmlAttributes,\n ...restProps,\n }}\n {...restTextInputProps}\n />\n );\n};\n\n/**\n *\n *\n * Types\n *\n *\n */\n\ntype PickerType = 'day' | 'month' | 'year';\n\n// Define a more flexible type for onChange\ntype DatePickerChangeHandler = (\n date: Date | null | [Date | null, Date | null] | Date[],\n event?: React.SyntheticEvent | undefined,\n) => void;\n\ninterface DatePickerProps {\n /** Props for the embedded `TextInput` component. */\n textInputProps?: React.ComponentProps<typeof TextInput>;\n /** Whether the date picker is disabled. */\n isDisabled?: boolean;\n /** Props for the embedded `TimePicker` component. */\n timePickerProps?: TimePickerProps;\n /** Props forwarded to underlying `react-datepicker` component. */\n reactDatePickerProps: React.ComponentProps<typeof ReactDatePicker>;\n}\n\nexport const DatePicker = ({\n reactDatePickerProps,\n textInputProps,\n timePickerProps,\n isDisabled,\n ref,\n className,\n style,\n htmlAttributes,\n ...restProps\n}: CommonProps<'div', DatePickerProps>) => {\n const classes = classNames(`ndl-datepicker`, className, {});\n const datetimeRef = useRef<ReactDatePicker>(null);\n const [picker, setPicker] = useState<PickerType>('day');\n const [preSelectedDate, setPreSelectedDate] = useState<Date | null>(\n (reactDatePickerProps.selected as Date | null) ||\n (reactDatePickerProps.startDate as Date | null),\n );\n\n const isInsideDialog = useIsInsideDialog();\n\n const headerAction = useCallback(\n (action: PickerType) => {\n setPicker(picker === action ? 'day' : action);\n },\n [picker],\n );\n\n const CustomHeader = useCallback(\n (props: ReactDatePickerCustomHeaderProps) => {\n const {\n decreaseMonth,\n increaseMonth,\n increaseYear,\n decreaseYear,\n nextMonthButtonDisabled,\n nextYearButtonDisabled,\n prevMonthButtonDisabled,\n prevYearButtonDisabled,\n } = props;\n\n const prevCallback = picker === 'year' ? decreaseYear : decreaseMonth;\n const nextCallback = picker === 'year' ? increaseYear : increaseMonth;\n const prevDisabled =\n picker === 'year' ? prevYearButtonDisabled : prevMonthButtonDisabled;\n const nextDisabled =\n picker === 'year' ? nextYearButtonDisabled : nextMonthButtonDisabled;\n\n return (\n <div className=\"ndl-datepicker-header\">\n <div className=\"ndl-datepicker-selects\">\n {picker !== 'year' && (\n <button\n aria-label={`${picker === 'month' ? 'Close' : 'Open'} month picker`}\n aria-pressed={picker === 'month'}\n onClick={() => headerAction('month')}\n >\n <div className=\"n-flex n-items-center n-gap-token-4\">\n <Typography variant=\"subheading-small\">\n {format(props.date, 'MMM')}\n </Typography>\n <ChevronDownIconOutline\n className={classNames('ndl-datepicker-chevron', {\n 'n-rotate-180': picker === 'month',\n })}\n aria-label=\"Chevron icon\"\n />\n </div>\n </button>\n )}\n {picker !== 'month' && (\n <button\n aria-label={`${picker === 'year' ? 'Close' : 'Open'} year picker`}\n onClick={() => headerAction('year')}\n >\n <div className=\"n-flex n-items-center n-gap-token-4\">\n <Typography variant=\"subheading-small\">\n {picker === 'year'\n ? getYearsPeriodString(\n props.date,\n reactDatePickerProps?.yearItemNumber,\n )\n : format(props.date, 'yyyy')}\n </Typography>\n <ChevronDownIconOutline\n className={classNames('ndl-datepicker-chevron', {\n 'n-rotate-180': picker === 'year',\n })}\n aria-label=\"Chevron icon\"\n />\n </div>\n </button>\n )}\n </div>\n {picker !== 'month' && (\n <div className=\"n-flex n-justify-center n-gap-token-16\">\n <CleanIconButton\n description={\n picker === 'year' ? 'Previous period' : 'Previous month'\n }\n onClick={prevCallback}\n isDisabled={prevDisabled}\n className=\"n-text-neutral-text-weak\"\n size=\"small\"\n >\n <ArrowLeftIconOutline />\n </CleanIconButton>\n <CleanIconButton\n description={picker === 'year' ? 'Next period' : 'Next month'}\n onClick={nextCallback}\n isDisabled={nextDisabled}\n className=\"n-text-neutral-text-weak\"\n size=\"small\"\n >\n <ArrowRightIconOutline />\n </CleanIconButton>\n </div>\n )}\n </div>\n );\n },\n [picker, headerAction, reactDatePickerProps?.yearItemNumber],\n );\n\n const handleTimeChange = (newTime: NeedleTime) => {\n if (\n reactDatePickerProps.selectsRange ||\n reactDatePickerProps.selectsMultiple\n ) {\n // this is consistent with the behavior of react-datepicker\n return;\n }\n\n if (!preSelectedDate) return;\n\n const newDate = new Date(preSelectedDate);\n newDate.setHours(newTime.hour, newTime.minute, 0, 0);\n setPreSelectedDate(newDate);\n\n if (reactDatePickerProps.onChange) {\n // For single date selection\n reactDatePickerProps.onChange(newDate, undefined);\n }\n };\n\n /**\n * Intercept onChange so we can work with\n * Month and Year pickers\n */\n const interceptedChange: DatePickerChangeHandler = useCallback(\n (\n date: Date | null | [Date | null, Date | null] | Date[],\n event?: React.SyntheticEvent,\n ) => {\n if (picker !== 'day') {\n // setTimeout to prevent picker change before the handleMonthChange logic\n setTimeout(() => {\n setPicker('day');\n });\n } else if (picker === 'day') {\n if (date instanceof Date) {\n setPreSelectedDate(date);\n } else if (\n Array.isArray(date) &&\n date.length > 0 &&\n date[0] instanceof Date\n ) {\n setPreSelectedDate(date[0]);\n } else if (date === null) {\n setPreSelectedDate(null);\n }\n\n if (reactDatePickerProps.onChange && date !== null) {\n (reactDatePickerProps.onChange as DatePickerChangeHandler)(\n date,\n event,\n );\n }\n }\n },\n [picker, reactDatePickerProps],\n );\n\n /**\n * Intercept onCalendarClose so we can\n * switch to \"day\" picker if we close on \"month\" or \"year\"\n * view\n */\n const interceptedOnCalendarClose = useCallback(() => {\n if (picker !== 'day') {\n setPicker('day');\n }\n reactDatePickerProps?.onCalendarClose?.();\n }, [picker, reactDatePickerProps]);\n\n const handleMonthChange = useCallback(\n (date: Date) => {\n if (picker === 'month') {\n const selectedDay = preSelectedDate?.getDate() ?? 1;\n const daysInNewMonth = daysInMonth(date.getMonth(), date.getFullYear());\n date.setDate(Math.min(selectedDay, daysInNewMonth));\n reactDatePickerProps?.onMonthChange?.(date);\n } else if (picker === 'year') {\n const selectedDay = preSelectedDate?.getDate() ?? 1;\n const selectedMonth = preSelectedDate?.getMonth() ?? 0;\n const daysInNewMonth = daysInMonth(selectedMonth, date.getFullYear());\n date.setMonth(selectedMonth, Math.min(selectedDay, daysInNewMonth));\n reactDatePickerProps?.onMonthChange?.(date);\n }\n setPreSelectedDate(date);\n },\n [picker, preSelectedDate, reactDatePickerProps],\n );\n\n /**\n * Intercept onChangeRaw to handle clearing the input\n * When the user clears the text input, set the date to null\n */\n const interceptedOnChangeRaw = useCallback(\n (\n event?:\n | React.KeyboardEvent<HTMLElement>\n | React.MouseEvent<HTMLElement, MouseEvent>,\n ) => {\n const target = event?.target as HTMLInputElement | undefined;\n if (target?.value === '') {\n setPreSelectedDate(null);\n if (reactDatePickerProps.onChange) {\n (reactDatePickerProps.onChange as DatePickerChangeHandler)(\n null,\n event,\n );\n }\n }\n reactDatePickerProps?.onChangeRaw?.(event);\n },\n [reactDatePickerProps],\n );\n\n const datePickerProps = {\n ...reactDatePickerProps,\n onCalendarClose: interceptedOnCalendarClose,\n onChange: interceptedChange,\n onChangeRaw: interceptedOnChangeRaw,\n onMonthChange: handleMonthChange,\n };\n\n return (\n <div\n className={classes}\n ref={ref}\n style={style}\n {...restProps}\n {...htmlAttributes}\n >\n <ReactDatePicker\n ref={datetimeRef}\n customInput={\n <DatePickerTextInputWrapper\n isDisabled={isDisabled}\n textInputProps={textInputProps}\n />\n }\n customTimeInput={\n <span>\n <Divider className=\"n-my-4\" />\n <TimePicker\n isFluid\n value={\n preSelectedDate\n ? new NeedleTime(\n preSelectedDate.getHours(),\n preSelectedDate.getMinutes(),\n )\n : undefined\n }\n onChange={handleTimeChange}\n {...timePickerProps}\n floatingStrategy=\"absolute\"\n isPortaled={false}\n />\n </span>\n }\n disabled={isDisabled}\n showPopperArrow={false}\n showMonthYearPicker={picker === 'month'}\n showYearPicker={picker === 'year'}\n shouldCloseOnSelect={\n picker === 'day' && !(reactDatePickerProps.showTimeInput ?? false)\n }\n dayClassName={() => 'ndl-datepicker-day'}\n renderCustomHeader={CustomHeader}\n {...datePickerProps}\n popperClassName={classNames(\n 'ndl-datepicker-popper',\n reactDatePickerProps.popperClassName,\n )}\n popperProps={{\n strategy: isInsideDialog ? 'fixed' : 'absolute',\n ...reactDatePickerProps.popperProps,\n }}\n />\n </div>\n );\n};\n"]}
@@ -44,7 +44,8 @@ const clean_icon_button_1 = require("../clean-icon-button");
44
44
  const conditional_wrap_1 = require("../conditional-wrap");
45
45
  const icons_1 = require("../icons");
46
46
  const typography_1 = require("../typography");
47
- const DrawerComponent = function DrawerComponent({ children, className = '', isExpanded, onExpandedChange, position = 'left', type = 'overlay', isResizeable = false, resizeableProps, isCloseable = true, isPortaled = false, portalProps = {}, htmlAttributes, ref, }) {
47
+ const DrawerComponent = function DrawerComponent(_a) {
48
+ var { children, className = '', isExpanded, onExpandedChange, position = 'left', type = 'overlay', isResizeable = false, resizeableProps, isCloseable = true, isPortaled = false, portalProps = {}, htmlAttributes, style, ref, as } = _a, restProps = __rest(_a, ["children", "className", "isExpanded", "onExpandedChange", "position", "type", "isResizeable", "resizeableProps", "isCloseable", "isPortaled", "portalProps", "htmlAttributes", "style", "ref", "as"]);
48
49
  const setOnExpandedChange = (0, react_2.useCallback)(() => {
49
50
  if (onExpandedChange)
50
51
  onExpandedChange(!isExpanded);
@@ -58,14 +59,15 @@ const DrawerComponent = function DrawerComponent({ children, className = '', isE
58
59
  });
59
60
  const resizableStylePosition = type === 'overlay' ? 'absolute' : 'relative';
60
61
  const shouldRenderInPortal = isPortaled && type === 'overlay';
62
+ const Component = as !== null && as !== void 0 ? as : 'div';
61
63
  const Close = () => ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: isCloseable && ((0, jsx_runtime_1.jsx)(clean_icon_button_1.CleanIconButton, { className: "ndl-drawer-close-button", onClick: setOnExpandedChange, description: "Close", size: "medium", htmlAttributes: {
62
64
  title: 'Close drawer',
63
65
  }, children: (0, jsx_runtime_1.jsx)(icons_1.XMarkIconOutline, {}) })) }));
64
66
  if (isResizeable) {
65
- return ((0, jsx_runtime_1.jsx)(conditional_wrap_1.ConditionalWrap, { shouldWrap: shouldRenderInPortal, wrap: (wrapChildren) => ((0, jsx_runtime_1.jsx)(react_1.FloatingPortal, Object.assign({ preserveTabOrder: true }, portalProps, { children: wrapChildren }))), children: (0, jsx_runtime_1.jsxs)(re_resizable_1.Resizable, Object.assign({ defaultSize: {
67
+ return ((0, jsx_runtime_1.jsx)(conditional_wrap_1.ConditionalWrap, { shouldWrap: shouldRenderInPortal, wrap: (wrapChildren) => ((0, jsx_runtime_1.jsx)(react_1.FloatingPortal, Object.assign({ preserveTabOrder: true }, portalProps, { children: wrapChildren }))), children: (0, jsx_runtime_1.jsxs)(re_resizable_1.Resizable, Object.assign({ as: Component, defaultSize: {
66
68
  height: '100%',
67
69
  width: 'auto',
68
- } }, resizeableProps, { className: classes, style: Object.assign({ position: resizableStylePosition }, resizeableProps === null || resizeableProps === void 0 ? void 0 : resizeableProps.style), boundsByDirection: true, bounds: "parent", handleStyles: {
70
+ } }, resizeableProps, { className: classes, style: Object.assign(Object.assign({ position: resizableStylePosition }, style), resizeableProps === null || resizeableProps === void 0 ? void 0 : resizeableProps.style), boundsByDirection: true, bounds: "parent", handleStyles: {
69
71
  /*
70
72
  * adding a small offset to the handle to make it easier to click
71
73
  * if the content of the drawer is scrollable, most noticeable if not using
@@ -83,9 +85,9 @@ const DrawerComponent = function DrawerComponent({ children, className = '', isE
83
85
  top: false,
84
86
  topLeft: false,
85
87
  topRight: false,
86
- }, ref: ref, children: [children, (0, jsx_runtime_1.jsx)(Close, {})] })) }));
88
+ }, ref: ref }, restProps, htmlAttributes, { children: [children, (0, jsx_runtime_1.jsx)(Close, {})] })) }));
87
89
  }
88
- return ((0, jsx_runtime_1.jsx)(conditional_wrap_1.ConditionalWrap, { shouldWrap: shouldRenderInPortal, wrap: (wrapChildren) => ((0, jsx_runtime_1.jsx)(react_1.FloatingPortal, Object.assign({ preserveTabOrder: true }, portalProps, { children: wrapChildren }))), children: (0, jsx_runtime_1.jsxs)("div", Object.assign({ className: classes, ref: ref }, htmlAttributes, { children: [children, (0, jsx_runtime_1.jsx)(Close, {})] })) }));
90
+ return ((0, jsx_runtime_1.jsx)(conditional_wrap_1.ConditionalWrap, { shouldWrap: shouldRenderInPortal, wrap: (wrapChildren) => ((0, jsx_runtime_1.jsx)(react_1.FloatingPortal, Object.assign({ preserveTabOrder: true }, portalProps, { children: wrapChildren }))), children: (0, jsx_runtime_1.jsxs)(Component, Object.assign({ className: classes, style: style, ref: ref }, restProps, htmlAttributes, { children: [children, (0, jsx_runtime_1.jsx)(Close, {})] })) }));
89
91
  };
90
92
  DrawerComponent.displayName = 'Drawer';
91
93
  const DrawerHeader = (_a) => {
@@ -1 +1 @@
1
- {"version":3,"file":"Drawer.js","sourceRoot":"","sources":["../../../src/drawer/Drawer.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,8CAAoD;AACpD,4DAAoC;AACpC,+CAA8D;AAE9D,iCAAyD;AAMzD,4DAAuD;AACvD,0DAAsD;AACtD,oCAA4C;AAC5C,8CAA2C;AA4C3C,MAAM,eAAe,GAAG,SAAS,eAAe,CAE9C,EACA,QAAQ,EACR,SAAS,GAAG,EAAE,EACd,UAAU,EACV,gBAAgB,EAChB,QAAQ,GAAG,MAAM,EACjB,IAAI,GAAG,SAAS,EAChB,YAAY,GAAG,KAAK,EACpB,eAAe,EACf,WAAW,GAAG,IAAI,EAClB,UAAU,GAAG,KAAK,EAClB,WAAW,GAAG,EAAE,EAChB,cAAc,EACd,GAAG,GACoC;IACvC,MAAM,mBAAmB,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;QAC3C,IAAI,gBAAgB;YAAE,gBAAgB,CAAC,CAAC,UAAU,CAAC,CAAC;IACtD,CAAC,EAAE,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAEnC,MAAM,OAAO,GAAG,IAAA,oBAAU,EAAC,YAAY,EAAE,SAAS,EAAE;QAClD,qBAAqB,EAAE,UAAU;QACjC,iBAAiB,EAAE,QAAQ,KAAK,MAAM;QACtC,oBAAoB,EAAE,IAAI,KAAK,SAAS;QACxC,iBAAiB,EAAE,IAAI,KAAK,MAAM;QAClC,kBAAkB,EAAE,QAAQ,KAAK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AAC,oBAAoB,EAAE,SAAS,CAAC,CAAC;IAE5D,OAAO,CACL,gDAAS,SAAS,IAAE,SAAS,EAAE,OAAO,YACnC,QAAQ,IACL,CACP,CAAC;AACJ,CAAC,CAAC;AAQF,MAAM,UAAU,GAAG,CAAC,EAIF,EAAE,EAAE;QAJF,EAClB,QAAQ,EACR,SAAS,GAAG,EAAE,OAEE,EADb,SAAS,cAHM,yBAInB,CADa;IAEZ,MAAM,OAAO,GAAG,IAAA,oBAAU,EAAC,iBAAiB,EAAE,SAAS,CAAC,CAAC;IAEzD,OAAO,CACL,gCAAK,SAAS,EAAC,yBAAyB,YACtC,gDAAS,SAAS,IAAE,SAAS,EAAE,OAAO,YACnC,QAAQ,IACL,GACF,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE;IAC5C,OAAO,EAAE,aAAa;IACtB,IAAI,EAAE,UAAU;IAChB,MAAM,EAAE,YAAY;CACrB,CAAC,CAAC;AAEM,wBAAM","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport { FloatingPortal } from '@floating-ui/react';\nimport classNames from 'classnames';\nimport { Resizable, type ResizableProps } from 're-resizable';\nimport type React from 'react';\nimport { type ComponentProps, useCallback } from 'react';\n\nimport {\n type HtmlAttributes,\n type PolymorphicCommonProps,\n} from '../_common/types';\nimport { CleanIconButton } from '../clean-icon-button';\nimport { ConditionalWrap } from '../conditional-wrap';\nimport { XMarkIconOutline } from '../icons';\nimport { Typography } from '../typography';\n\ntype DrawerPosition = 'left' | 'right';\n\ntype DrawerType = 'overlay' | 'push';\n\ntype DrawerProps = {\n /** Controls whether the drawer is open (expanded) or closed (collapsed). */\n isExpanded: boolean;\n\n /** Callback functions fired when the drawer's expanded state changes. */\n onExpandedChange?: (expanded: boolean) => void;\n\n /** Position where the drawer appears on screen. By default, it appears from the left. */\n position?: DrawerPosition;\n\n /** How the drawer affects the layout of sibling content. By default, it overlays content. */\n type?: DrawerType;\n\n /** Enables horizontal resizing of the drawer, by default it is not resizable. */\n isResizeable?: boolean;\n\n /** To use this prop the isResizeable prop must be set to true. For overriding the third party library props: https://github.com/bokuweb/re-resizable */\n resizeableProps?: ResizableProps;\n\n /** Whether a close button (X) is displayed in the drawer. */\n isCloseable?: boolean;\n\n /** Whether to portal the content */\n isPortaled?: boolean;\n\n /** The content to display within the drawer. */\n children: React.ReactNode;\n\n /** Additional CSS classes to apply to the drawer container. */\n className?: string;\n\n /**\n * Props to pass to the portal from @floating-ui/react FloatingPortal\n * @see https://floating-ui.com/docs/floatingportal\n */\n portalProps?: ComponentProps<typeof FloatingPortal>;\n};\n\nconst DrawerComponent = function DrawerComponent<\n T extends React.ElementType = 'div',\n>({\n children,\n className = '',\n isExpanded,\n onExpandedChange,\n position = 'left',\n type = 'overlay',\n isResizeable = false,\n resizeableProps,\n isCloseable = true,\n isPortaled = false,\n portalProps = {},\n htmlAttributes,\n ref,\n}: PolymorphicCommonProps<T, DrawerProps>) {\n const setOnExpandedChange = useCallback(() => {\n if (onExpandedChange) onExpandedChange(!isExpanded);\n }, [isExpanded, onExpandedChange]);\n\n const classes = classNames('ndl-drawer', className, {\n 'ndl-drawer-expanded': isExpanded,\n 'ndl-drawer-left': position === 'left',\n 'ndl-drawer-overlay': type === 'overlay',\n 'ndl-drawer-push': type === 'push',\n 'ndl-drawer-right': position === 'right',\n });\n\n const resizableStylePosition = type === 'overlay' ? 'absolute' : 'relative';\n const shouldRenderInPortal = isPortaled && type === 'overlay';\n\n const Close = () => (\n <>\n {isCloseable && (\n <CleanIconButton\n className=\"ndl-drawer-close-button\"\n onClick={setOnExpandedChange}\n description=\"Close\"\n size=\"medium\"\n htmlAttributes={{\n title: 'Close drawer',\n }}\n >\n <XMarkIconOutline />\n </CleanIconButton>\n )}\n </>\n );\n\n if (isResizeable) {\n return (\n <ConditionalWrap\n shouldWrap={shouldRenderInPortal}\n wrap={(wrapChildren) => (\n <FloatingPortal preserveTabOrder={true} {...portalProps}>\n {wrapChildren}\n </FloatingPortal>\n )}\n >\n <Resizable\n defaultSize={{\n height: '100%',\n width: 'auto',\n }}\n {...resizeableProps}\n className={classes}\n style={{\n position: resizableStylePosition,\n ...resizeableProps?.style,\n }}\n boundsByDirection={true}\n bounds=\"parent\"\n handleStyles={{\n /*\n * adding a small offset to the handle to make it easier to click\n * if the content of the drawer is scrollable, most noticeable if not using\n * a mouse on mac or chrome on windows with the fluent scrollbars\n */\n right: {\n right: '-8px',\n },\n }}\n enable={{\n bottom: false,\n bottomLeft: false,\n bottomRight: false,\n left: position === 'right',\n right: position === 'left',\n top: false,\n topLeft: false,\n topRight: false,\n }}\n ref={ref}\n >\n {children}\n <Close />\n </Resizable>\n </ConditionalWrap>\n );\n }\n\n return (\n <ConditionalWrap\n shouldWrap={shouldRenderInPortal}\n wrap={(wrapChildren) => (\n <FloatingPortal preserveTabOrder={true} {...portalProps}>\n {wrapChildren}\n </FloatingPortal>\n )}\n >\n <div className={classes} ref={ref} {...htmlAttributes}>\n {children}\n <Close />\n </div>\n </ConditionalWrap>\n );\n};\n\nDrawerComponent.displayName = 'Drawer';\n\ntype DrawerHeaderProps = {\n children: React.ReactNode;\n className?: string;\n htmlAttributes?: HtmlAttributes<'h5'>;\n};\n\nconst DrawerHeader = ({\n children,\n className = '',\n ...restProps\n}: DrawerHeaderProps) => {\n const classes = classNames('ndl-drawer-header', className);\n\n if (typeof children === 'string' || typeof children === 'number') {\n return (\n <Typography variant=\"title-3\" {...restProps} className={classes}>\n {children}\n </Typography>\n );\n }\n\n return (\n <div {...restProps} className={classes}>\n {children}\n </div>\n );\n};\n\ntype DrawerActionsProps = {\n children: React.ReactNode;\n className?: string;\n htmlAttributes?: HtmlAttributes<'div'>;\n};\n\nconst DrawerActions = ({\n children,\n className = '',\n ...restProps\n}: DrawerActionsProps) => {\n const classes = classNames('ndl-drawer-actions', className);\n\n return (\n <div {...restProps} className={classes}>\n {children}\n </div>\n );\n};\n\ntype DrawerBodyProps = {\n children: React.ReactNode;\n className?: string;\n htmlAttributes?: HtmlAttributes<'div'>;\n};\n\nconst DrawerBody = ({\n children,\n className = '',\n ...restProps\n}: DrawerBodyProps) => {\n const classes = classNames('ndl-drawer-body', className);\n\n return (\n <div className=\"ndl-drawer-body-wrapper\">\n <div {...restProps} className={classes}>\n {children}\n </div>\n </div>\n );\n};\n\nconst Drawer = Object.assign(DrawerComponent, {\n Actions: DrawerActions,\n Body: DrawerBody,\n Header: DrawerHeader,\n});\n\nexport { Drawer };\n"]}
1
+ {"version":3,"file":"Drawer.js","sourceRoot":"","sources":["../../../src/drawer/Drawer.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,8CAAoD;AACpD,4DAAoC;AACpC,+CAA8D;AAE9D,iCAAyD;AAMzD,4DAAuD;AACvD,0DAAsD;AACtD,oCAA4C;AAC5C,8CAA2C;AA4C3C,MAAM,eAAe,GAAG,SAAS,eAAe,CAE9C,EAiBuC;QAjBvC,EACA,QAAQ,EACR,SAAS,GAAG,EAAE,EACd,UAAU,EACV,gBAAgB,EAChB,QAAQ,GAAG,MAAM,EACjB,IAAI,GAAG,SAAS,EAChB,YAAY,GAAG,KAAK,EACpB,eAAe,EACf,WAAW,GAAG,IAAI,EAClB,UAAU,GAAG,KAAK,EAClB,WAAW,GAAG,EAAE,EAChB,cAAc,EACd,KAAK,EACL,GAAG,E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tB,IAAI,EAAE,UAAU;IAChB,MAAM,EAAE,YAAY;CACrB,CAAC,CAAC;AAEM,wBAAM","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport { FloatingPortal } from '@floating-ui/react';\nimport classNames from 'classnames';\nimport { Resizable, type ResizableProps } from 're-resizable';\nimport type React from 'react';\nimport { type ComponentProps, useCallback } from 'react';\n\nimport {\n type HtmlAttributes,\n type PolymorphicCommonProps,\n} from '../_common/types';\nimport { CleanIconButton } from '../clean-icon-button';\nimport { ConditionalWrap } from '../conditional-wrap';\nimport { XMarkIconOutline } from '../icons';\nimport { Typography } from '../typography';\n\ntype DrawerPosition = 'left' | 'right';\n\ntype DrawerType = 'overlay' | 'push';\n\ntype DrawerProps = {\n /** Controls whether the drawer is open (expanded) or closed (collapsed). */\n isExpanded: boolean;\n\n /** Callback functions fired when the drawer's expanded state changes. */\n onExpandedChange?: (expanded: boolean) => void;\n\n /** Position where the drawer appears on screen. By default, it appears from the left. */\n position?: DrawerPosition;\n\n /** How the drawer affects the layout of sibling content. By default, it overlays content. */\n type?: DrawerType;\n\n /** Enables horizontal resizing of the drawer, by default it is not resizable. */\n isResizeable?: boolean;\n\n /** To use this prop the isResizeable prop must be set to true. For overriding the third party library props: https://github.com/bokuweb/re-resizable */\n resizeableProps?: ResizableProps;\n\n /** Whether a close button (X) is displayed in the drawer. */\n isCloseable?: boolean;\n\n /** Whether to portal the content */\n isPortaled?: boolean;\n\n /** The content to display within the drawer. */\n children: React.ReactNode;\n\n /** Additional CSS classes to apply to the drawer container. */\n className?: string;\n\n /**\n * Props to pass to the portal from @floating-ui/react FloatingPortal\n * @see https://floating-ui.com/docs/floatingportal\n */\n portalProps?: ComponentProps<typeof FloatingPortal>;\n};\n\nconst DrawerComponent = function DrawerComponent<\n T extends React.ElementType = 'div',\n>({\n children,\n className = '',\n isExpanded,\n onExpandedChange,\n position = 'left',\n type = 'overlay',\n isResizeable = false,\n resizeableProps,\n isCloseable = true,\n isPortaled = false,\n portalProps = {},\n htmlAttributes,\n style,\n ref,\n as,\n ...restProps\n}: PolymorphicCommonProps<T, DrawerProps>) {\n const setOnExpandedChange = useCallback(() => {\n if (onExpandedChange) onExpandedChange(!isExpanded);\n }, [isExpanded, onExpandedChange]);\n\n const classes = classNames('ndl-drawer', className, {\n 'ndl-drawer-expanded': isExpanded,\n 'ndl-drawer-left': position === 'left',\n 'ndl-drawer-overlay': type === 'overlay',\n 'ndl-drawer-push': type === 'push',\n 'ndl-drawer-right': position === 'right',\n });\n\n const resizableStylePosition = type === 'overlay' ? 'absolute' : 'relative';\n const shouldRenderInPortal = isPortaled && type === 'overlay';\n const Component = as ?? 'div';\n\n const Close = () => (\n <>\n {isCloseable && (\n <CleanIconButton\n className=\"ndl-drawer-close-button\"\n onClick={setOnExpandedChange}\n description=\"Close\"\n size=\"medium\"\n htmlAttributes={{\n title: 'Close drawer',\n }}\n >\n <XMarkIconOutline />\n </CleanIconButton>\n )}\n </>\n );\n\n if (isResizeable) {\n return (\n <ConditionalWrap\n shouldWrap={shouldRenderInPortal}\n wrap={(wrapChildren) => (\n <FloatingPortal preserveTabOrder={true} {...portalProps}>\n {wrapChildren}\n </FloatingPortal>\n )}\n >\n <Resizable\n as={Component}\n defaultSize={{\n height: '100%',\n width: 'auto',\n }}\n {...resizeableProps}\n className={classes}\n style={{\n position: resizableStylePosition,\n ...style,\n ...resizeableProps?.style,\n }}\n boundsByDirection={true}\n bounds=\"parent\"\n handleStyles={{\n /*\n * adding a small offset to the handle to make it easier to click\n * if the content of the drawer is scrollable, most noticeable if not using\n * a mouse on mac or chrome on windows with the fluent scrollbars\n */\n right: {\n right: '-8px',\n },\n }}\n enable={{\n bottom: false,\n bottomLeft: false,\n bottomRight: false,\n left: position === 'right',\n right: position === 'left',\n top: false,\n topLeft: false,\n topRight: false,\n }}\n ref={ref}\n {...restProps}\n {...htmlAttributes}\n >\n {children}\n <Close />\n </Resizable>\n </ConditionalWrap>\n );\n }\n\n return (\n <ConditionalWrap\n shouldWrap={shouldRenderInPortal}\n wrap={(wrapChildren) => (\n <FloatingPortal preserveTabOrder={true} {...portalProps}>\n {wrapChildren}\n </FloatingPortal>\n )}\n >\n <Component\n className={classes}\n style={style}\n ref={ref}\n {...restProps}\n {...htmlAttributes}\n >\n {children}\n <Close />\n </Component>\n </ConditionalWrap>\n );\n};\n\nDrawerComponent.displayName = 'Drawer';\n\ntype DrawerHeaderProps = {\n children: React.ReactNode;\n className?: string;\n htmlAttributes?: HtmlAttributes<'h5'>;\n};\n\nconst DrawerHeader = ({\n children,\n className = '',\n ...restProps\n}: DrawerHeaderProps) => {\n const classes = classNames('ndl-drawer-header', className);\n\n if (typeof children === 'string' || typeof children === 'number') {\n return (\n <Typography variant=\"title-3\" {...restProps} className={classes}>\n {children}\n </Typography>\n );\n }\n\n return (\n <div {...restProps} className={classes}>\n {children}\n </div>\n );\n};\n\ntype DrawerActionsProps = {\n children: React.ReactNode;\n className?: string;\n htmlAttributes?: HtmlAttributes<'div'>;\n};\n\nconst DrawerActions = ({\n children,\n className = '',\n ...restProps\n}: DrawerActionsProps) => {\n const classes = classNames('ndl-drawer-actions', className);\n\n return (\n <div {...restProps} className={classes}>\n {children}\n </div>\n );\n};\n\ntype DrawerBodyProps = {\n children: React.ReactNode;\n className?: string;\n htmlAttributes?: HtmlAttributes<'div'>;\n};\n\nconst DrawerBody = ({\n children,\n className = '',\n ...restProps\n}: DrawerBodyProps) => {\n const classes = classNames('ndl-drawer-body', className);\n\n return (\n <div className=\"ndl-drawer-body-wrapper\">\n <div {...restProps} className={classes}>\n {children}\n </div>\n </div>\n );\n};\n\nconst Drawer = Object.assign(DrawerComponent, {\n Actions: DrawerActions,\n Body: DrawerBody,\n Header: DrawerHeader,\n});\n\nexport { Drawer };\n"]}
@@ -154,7 +154,22 @@ export const DatePicker = (_a) => {
154
154
  }
155
155
  setPreSelectedDate(date);
156
156
  }, [picker, preSelectedDate, reactDatePickerProps]);
157
- const datePickerProps = Object.assign(Object.assign({}, reactDatePickerProps), { onCalendarClose: interceptedOnCalendarClose, onChange: interceptedChange, onMonthChange: handleMonthChange });
157
+ /**
158
+ * Intercept onChangeRaw to handle clearing the input
159
+ * When the user clears the text input, set the date to null
160
+ */
161
+ const interceptedOnChangeRaw = useCallback((event) => {
162
+ var _a;
163
+ const target = event === null || event === void 0 ? void 0 : event.target;
164
+ if ((target === null || target === void 0 ? void 0 : target.value) === '') {
165
+ setPreSelectedDate(null);
166
+ if (reactDatePickerProps.onChange) {
167
+ reactDatePickerProps.onChange(null, event);
168
+ }
169
+ }
170
+ (_a = reactDatePickerProps === null || reactDatePickerProps === void 0 ? void 0 : reactDatePickerProps.onChangeRaw) === null || _a === void 0 ? void 0 : _a.call(reactDatePickerProps, event);
171
+ }, [reactDatePickerProps]);
172
+ const datePickerProps = Object.assign(Object.assign({}, reactDatePickerProps), { onCalendarClose: interceptedOnCalendarClose, onChange: interceptedChange, onChangeRaw: interceptedOnChangeRaw, onMonthChange: handleMonthChange });
158
173
  return (_jsx("div", Object.assign({ className: classes, ref: ref, style: style }, restProps, htmlAttributes, { children: _jsx(ReactDatePicker, Object.assign({ ref: datetimeRef, customInput: _jsx(DatePickerTextInputWrapper, { isDisabled: isDisabled, textInputProps: textInputProps }), customTimeInput: _jsxs("span", { children: [_jsx(Divider, { className: "n-my-4" }), _jsx(TimePicker, Object.assign({ isFluid: true, value: preSelectedDate
159
174
  ? new NeedleTime(preSelectedDate.getHours(), preSelectedDate.getMinutes())
160
175
  : undefined, onChange: handleTimeChange }, timePickerProps, { floatingStrategy: "absolute", isPortaled: false }))] }), disabled: isDisabled, showPopperArrow: false, showMonthYearPicker: picker === 'month', showYearPicker: picker === 'year', shouldCloseOnSelect: picker === 'day' && !((_b = reactDatePickerProps.showTimeInput) !== null && _b !== void 0 ? _b : false), dayClassName: () => 'ndl-datepicker-day', renderCustomHeader: CustomHeader }, datePickerProps, { popperClassName: classNames('ndl-datepicker-popper', reactDatePickerProps.popperClassName), popperProps: Object.assign({ strategy: isInsideDialog ? 'fixed' : 'absolute' }, reactDatePickerProps.popperProps) })) })));
@@ -1 +1 @@
1
- {"version":3,"file":"DatePicker.js","sourceRoot":"","sources":["../../../src/date-picker/DatePicker.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iCAAiC;AACjC,yDAAyD;AAEzD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,eAEN,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAwB,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC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AAC,IAAI,UAAU,CACZ,eAAe,CAAC,QAAQ,EAAE,EAC1B,eAAe,CAAC,UAAU,EAAE,CAC7B;4BACH,CAAC,CAAC,SAAS,EAEf,QAAQ,EAAE,gBAAgB,IACtB,eAAe,IACnB,gBAAgB,EAAC,UAAU,EAC3B,UAAU,EAAE,KAAK,IACjB,IACG,EAET,QAAQ,EAAE,UAAU,EACpB,eAAe,EAAE,KAAK,EACtB,mBAAmB,EAAE,MAAM,KAAK,OAAO,EACvC,cAAc,EAAE,MAAM,KAAK,MAAM,EACjC,mBAAmB,EACjB,MAAM,KAAK,KAAK,IAAI,CAAC,CAAC,MAAA,oBAAoB,CAAC,aAAa,mCAAI,KAAK,CAAC,EAEpE,YAAY,EAAE,GAAG,EAAE,CAAC,oBAAoB,EACxC,kBAAkB,EAAE,YAAY,IAC5B,eAAe,IACnB,eAAe,EAAE,UAAU,CACzB,uBAAuB,EACvB,oBAAoB,CAAC,eAAe,CACrC,EACD,WAAW,kBACT,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,IAC5C,oBAAoB,CAAC,WAAW,KAErC,IACE,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["// TODO: try to fix as some point\n/* eslint-disable @typescript-eslint/naming-convention */\n\n/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport classNames from 'classnames';\nimport { format } from 'date-fns';\nimport { useCallback, useRef, useState } from 'react';\nimport ReactDatePicker, {\n type ReactDatePickerCustomHeaderProps,\n} from 'react-datepicker';\n\nimport type { CommonProps } from '../_common/types';\nimport { CleanIconButton } from '../clean-icon-button';\nimport { useIsInsideDialog } from '../dialog/dialog-context';\nimport { Divider } from '../divider';\nimport {\n ArrowLeftIconOutline,\n ArrowRightIconOutline,\n CalendarDaysIconOutline,\n ChevronDownIconOutline,\n} from '../icons';\nimport { TextInput } from '../text-input';\nimport { NeedleTime, TimePicker, type TimePickerProps } from '../time-picker';\nimport { Typography } from '../typography';\nimport { daysInMonth, getYearsPeriodString } from './utils';\n\ntype DatePickerTextInputWrapperProps = React.ComponentProps<'input'> & {\n textInputProps?: React.ComponentProps<typeof TextInput>;\n isDisabled?: boolean;\n value?: string;\n};\n\n// This wrapper is needed due to react-datepicker injecting html attributes\n// into the custom input component on root level, since we use htmlAttributes\n// we need to help spread them there instead of the root level\nconst DatePickerTextInputWrapper = ({\n textInputProps,\n isDisabled,\n value,\n placeholder,\n ...restProps\n}: DatePickerTextInputWrapperProps) => {\n // deconstruct textInputProps to avoid bugs with react-datepicker injecting props\n const {\n placeholder: textInputPlaceholder,\n htmlAttributes: textInputHtmlAttributes,\n ref,\n ...restTextInputProps\n } = textInputProps ?? {};\n\n return (\n <TextInput\n ref={ref}\n aria-label=\"Date picker input\"\n trailingElement={\n <CalendarDaysIconOutline className=\"ndl-datepicker-icon\" />\n }\n value={value}\n placeholder={placeholder ?? textInputPlaceholder}\n isDisabled={isDisabled}\n // react-datepicker injects html attributes into the custom input\n htmlAttributes={{\n ...textInputHtmlAttributes,\n ...restProps,\n }}\n {...restTextInputProps}\n />\n );\n};\n\n/**\n *\n *\n * Types\n *\n *\n */\n\ntype PickerType = 'day' | 'month' | 'year';\n\n// Define a more flexible type for onChange\ntype DatePickerChangeHandler = (\n date: Date | null | [Date | null, Date | null] | Date[],\n event?: React.SyntheticEvent | undefined,\n) => void;\n\ninterface DatePickerProps {\n /** Props for the embedded `TextInput` component. */\n textInputProps?: React.ComponentProps<typeof TextInput>;\n /** Whether the date picker is disabled. */\n isDisabled?: boolean;\n /** Props for the embedded `TimePicker` component. */\n timePickerProps?: TimePickerProps;\n /** Props forwarded to underlying `react-datepicker` component. */\n reactDatePickerProps: React.ComponentProps<typeof ReactDatePicker>;\n}\n\nexport const DatePicker = ({\n reactDatePickerProps,\n textInputProps,\n timePickerProps,\n isDisabled,\n ref,\n className,\n style,\n htmlAttributes,\n ...restProps\n}: CommonProps<'div', DatePickerProps>) => {\n const classes = classNames(`ndl-datepicker`, className, {});\n const datetimeRef = useRef<ReactDatePicker>(null);\n const [picker, setPicker] = useState<PickerType>('day');\n const [preSelectedDate, setPreSelectedDate] = useState<Date | null>(\n (reactDatePickerProps.selected as Date | null) ||\n (reactDatePickerProps.startDate as Date | null),\n );\n\n const isInsideDialog = useIsInsideDialog();\n\n const headerAction = useCallback(\n (action: PickerType) => {\n setPicker(picker === action ? 'day' : action);\n },\n [picker],\n );\n\n const CustomHeader = useCallback(\n (props: ReactDatePickerCustomHeaderProps) => {\n const {\n decreaseMonth,\n increaseMonth,\n increaseYear,\n decreaseYear,\n nextMonthButtonDisabled,\n nextYearButtonDisabled,\n prevMonthButtonDisabled,\n prevYearButtonDisabled,\n } = props;\n\n const prevCallback = picker === 'year' ? decreaseYear : decreaseMonth;\n const nextCallback = picker === 'year' ? increaseYear : increaseMonth;\n const prevDisabled =\n picker === 'year' ? prevYearButtonDisabled : prevMonthButtonDisabled;\n const nextDisabled =\n picker === 'year' ? nextYearButtonDisabled : nextMonthButtonDisabled;\n\n return (\n <div className=\"ndl-datepicker-header\">\n <div className=\"ndl-datepicker-selects\">\n {picker !== 'year' && (\n <button\n aria-label={`${picker === 'month' ? 'Close' : 'Open'} month picker`}\n aria-pressed={picker === 'month'}\n onClick={() => headerAction('month')}\n >\n <div className=\"n-flex n-items-center n-gap-token-4\">\n <Typography variant=\"subheading-small\">\n {format(props.date, 'MMM')}\n </Typography>\n <ChevronDownIconOutline\n className={classNames('ndl-datepicker-chevron', {\n 'n-rotate-180': picker === 'month',\n })}\n aria-label=\"Chevron icon\"\n />\n </div>\n </button>\n )}\n {picker !== 'month' && (\n <button\n aria-label={`${picker === 'year' ? 'Close' : 'Open'} year picker`}\n onClick={() => headerAction('year')}\n >\n <div className=\"n-flex n-items-center n-gap-token-4\">\n <Typography variant=\"subheading-small\">\n {picker === 'year'\n ? getYearsPeriodString(\n props.date,\n reactDatePickerProps?.yearItemNumber,\n )\n : format(props.date, 'yyyy')}\n </Typography>\n <ChevronDownIconOutline\n className={classNames('ndl-datepicker-chevron', {\n 'n-rotate-180': picker === 'year',\n })}\n aria-label=\"Chevron icon\"\n />\n </div>\n </button>\n )}\n </div>\n {picker !== 'month' && (\n <div className=\"n-flex n-justify-center n-gap-token-16\">\n <CleanIconButton\n description={\n picker === 'year' ? 'Previous period' : 'Previous month'\n }\n onClick={prevCallback}\n isDisabled={prevDisabled}\n className=\"n-text-neutral-text-weak\"\n size=\"small\"\n >\n <ArrowLeftIconOutline />\n </CleanIconButton>\n <CleanIconButton\n description={picker === 'year' ? 'Next period' : 'Next month'}\n onClick={nextCallback}\n isDisabled={nextDisabled}\n className=\"n-text-neutral-text-weak\"\n size=\"small\"\n >\n <ArrowRightIconOutline />\n </CleanIconButton>\n </div>\n )}\n </div>\n );\n },\n [picker, headerAction, reactDatePickerProps?.yearItemNumber],\n );\n\n const handleTimeChange = (newTime: NeedleTime) => {\n if (\n reactDatePickerProps.selectsRange ||\n reactDatePickerProps.selectsMultiple\n ) {\n // this is consistent with the behavior of react-datepicker\n return;\n }\n\n if (!preSelectedDate) return;\n\n const newDate = new Date(preSelectedDate);\n newDate.setHours(newTime.hour, newTime.minute, 0, 0);\n setPreSelectedDate(newDate);\n\n if (reactDatePickerProps.onChange) {\n // For single date selection\n reactDatePickerProps.onChange(newDate, undefined);\n }\n };\n\n /**\n * Intercept onChange so we can work with\n * Month and Year pickers\n */\n const interceptedChange: DatePickerChangeHandler = useCallback(\n (\n date: Date | null | [Date | null, Date | null] | Date[],\n event?: React.SyntheticEvent,\n ) => {\n if (picker !== 'day') {\n // setTimeout to prevent picker change before the handleMonthChange logic\n setTimeout(() => {\n setPicker('day');\n });\n } else if (picker === 'day') {\n if (date instanceof Date) {\n setPreSelectedDate(date);\n } else if (\n Array.isArray(date) &&\n date.length > 0 &&\n date[0] instanceof Date\n ) {\n setPreSelectedDate(date[0]);\n } else if (date === null) {\n setPreSelectedDate(null);\n }\n\n if (reactDatePickerProps.onChange && date !== null) {\n (reactDatePickerProps.onChange as DatePickerChangeHandler)(\n date,\n event,\n );\n }\n }\n },\n [picker, reactDatePickerProps],\n );\n\n /**\n * Intercept onCalendarClose so we can\n * switch to \"day\" picker if we close on \"month\" or \"year\"\n * view\n */\n const interceptedOnCalendarClose = useCallback(() => {\n if (picker !== 'day') {\n setPicker('day');\n }\n reactDatePickerProps?.onCalendarClose?.();\n }, [picker, reactDatePickerProps]);\n\n const handleMonthChange = useCallback(\n (date: Date) => {\n if (picker === 'month') {\n const selectedDay = preSelectedDate?.getDate() ?? 1;\n const daysInNewMonth = daysInMonth(date.getMonth(), date.getFullYear());\n date.setDate(Math.min(selectedDay, daysInNewMonth));\n reactDatePickerProps?.onMonthChange?.(date);\n } else if (picker === 'year') {\n const selectedDay = preSelectedDate?.getDate() ?? 1;\n const selectedMonth = preSelectedDate?.getMonth() ?? 0;\n const daysInNewMonth = daysInMonth(selectedMonth, date.getFullYear());\n date.setMonth(selectedMonth, Math.min(selectedDay, daysInNewMonth));\n reactDatePickerProps?.onMonthChange?.(date);\n }\n setPreSelectedDate(date);\n },\n [picker, preSelectedDate, reactDatePickerProps],\n );\n\n const datePickerProps = {\n ...reactDatePickerProps,\n onCalendarClose: interceptedOnCalendarClose,\n onChange: interceptedChange,\n onMonthChange: handleMonthChange,\n };\n\n return (\n <div\n className={classes}\n ref={ref}\n style={style}\n {...restProps}\n {...htmlAttributes}\n >\n <ReactDatePicker\n ref={datetimeRef}\n customInput={\n <DatePickerTextInputWrapper\n isDisabled={isDisabled}\n textInputProps={textInputProps}\n />\n }\n customTimeInput={\n <span>\n <Divider className=\"n-my-4\" />\n <TimePicker\n isFluid\n value={\n preSelectedDate\n ? new NeedleTime(\n preSelectedDate.getHours(),\n preSelectedDate.getMinutes(),\n )\n : undefined\n }\n onChange={handleTimeChange}\n {...timePickerProps}\n floatingStrategy=\"absolute\"\n isPortaled={false}\n />\n </span>\n }\n disabled={isDisabled}\n showPopperArrow={false}\n showMonthYearPicker={picker === 'month'}\n showYearPicker={picker === 'year'}\n shouldCloseOnSelect={\n picker === 'day' && !(reactDatePickerProps.showTimeInput ?? false)\n }\n dayClassName={() => 'ndl-datepicker-day'}\n renderCustomHeader={CustomHeader}\n {...datePickerProps}\n popperClassName={classNames(\n 'ndl-datepicker-popper',\n reactDatePickerProps.popperClassName,\n )}\n popperProps={{\n strategy: isInsideDialog ? 'fixed' : 'absolute',\n ...reactDatePickerProps.popperProps,\n }}\n />\n </div>\n );\n};\n"]}
1
+ {"version":3,"file":"DatePicker.js","sourceRoot":"","sources":["../../../src/date-picker/DatePicker.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iCAAiC;AACjC,yDAAyD;AAEzD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,eAEN,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,SA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E,GAAG,EAAE,CAAC,oBAAoB,EACxC,kBAAkB,EAAE,YAAY,IAC5B,eAAe,IACnB,eAAe,EAAE,UAAU,CACzB,uBAAuB,EACvB,oBAAoB,CAAC,eAAe,CACrC,EACD,WAAW,kBACT,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,IAC5C,oBAAoB,CAAC,WAAW,KAErC,IACE,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["// TODO: try to fix as some point\n/* eslint-disable @typescript-eslint/naming-convention */\n\n/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport classNames from 'classnames';\nimport { format } from 'date-fns';\nimport { useCallback, useRef, useState } from 'react';\nimport ReactDatePicker, {\n type ReactDatePickerCustomHeaderProps,\n} from 'react-datepicker';\n\nimport type { CommonProps } from '../_common/types';\nimport { CleanIconButton } from '../clean-icon-button';\nimport { useIsInsideDialog } from '../dialog/dialog-context';\nimport { Divider } from '../divider';\nimport {\n ArrowLeftIconOutline,\n ArrowRightIconOutline,\n CalendarDaysIconOutline,\n ChevronDownIconOutline,\n} from '../icons';\nimport { TextInput } from '../text-input';\nimport { NeedleTime, TimePicker, type TimePickerProps } from '../time-picker';\nimport { Typography } from '../typography';\nimport { daysInMonth, getYearsPeriodString } from './utils';\n\ntype DatePickerTextInputWrapperProps = React.ComponentProps<'input'> & {\n textInputProps?: React.ComponentProps<typeof TextInput>;\n isDisabled?: boolean;\n value?: string;\n};\n\n// This wrapper is needed due to react-datepicker injecting html attributes\n// into the custom input component on root level, since we use htmlAttributes\n// we need to help spread them there instead of the root level\nconst DatePickerTextInputWrapper = ({\n textInputProps,\n isDisabled,\n value,\n placeholder,\n ...restProps\n}: DatePickerTextInputWrapperProps) => {\n // deconstruct textInputProps to avoid bugs with react-datepicker injecting props\n const {\n placeholder: textInputPlaceholder,\n htmlAttributes: textInputHtmlAttributes,\n ref,\n ...restTextInputProps\n } = textInputProps ?? {};\n\n return (\n <TextInput\n ref={ref}\n aria-label=\"Date picker input\"\n trailingElement={\n <CalendarDaysIconOutline className=\"ndl-datepicker-icon\" />\n }\n value={value}\n placeholder={placeholder ?? textInputPlaceholder}\n isDisabled={isDisabled}\n // react-datepicker injects html attributes into the custom input\n htmlAttributes={{\n ...textInputHtmlAttributes,\n ...restProps,\n }}\n {...restTextInputProps}\n />\n );\n};\n\n/**\n *\n *\n * Types\n *\n *\n */\n\ntype PickerType = 'day' | 'month' | 'year';\n\n// Define a more flexible type for onChange\ntype DatePickerChangeHandler = (\n date: Date | null | [Date | null, Date | null] | Date[],\n event?: React.SyntheticEvent | undefined,\n) => void;\n\ninterface DatePickerProps {\n /** Props for the embedded `TextInput` component. */\n textInputProps?: React.ComponentProps<typeof TextInput>;\n /** Whether the date picker is disabled. */\n isDisabled?: boolean;\n /** Props for the embedded `TimePicker` component. */\n timePickerProps?: TimePickerProps;\n /** Props forwarded to underlying `react-datepicker` component. */\n reactDatePickerProps: React.ComponentProps<typeof ReactDatePicker>;\n}\n\nexport const DatePicker = ({\n reactDatePickerProps,\n textInputProps,\n timePickerProps,\n isDisabled,\n ref,\n className,\n style,\n htmlAttributes,\n ...restProps\n}: CommonProps<'div', DatePickerProps>) => {\n const classes = classNames(`ndl-datepicker`, className, {});\n const datetimeRef = useRef<ReactDatePicker>(null);\n const [picker, setPicker] = useState<PickerType>('day');\n const [preSelectedDate, setPreSelectedDate] = useState<Date | null>(\n (reactDatePickerProps.selected as Date | null) ||\n (reactDatePickerProps.startDate as Date | null),\n );\n\n const isInsideDialog = useIsInsideDialog();\n\n const headerAction = useCallback(\n (action: PickerType) => {\n setPicker(picker === action ? 'day' : action);\n },\n [picker],\n );\n\n const CustomHeader = useCallback(\n (props: ReactDatePickerCustomHeaderProps) => {\n const {\n decreaseMonth,\n increaseMonth,\n increaseYear,\n decreaseYear,\n nextMonthButtonDisabled,\n nextYearButtonDisabled,\n prevMonthButtonDisabled,\n prevYearButtonDisabled,\n } = props;\n\n const prevCallback = picker === 'year' ? decreaseYear : decreaseMonth;\n const nextCallback = picker === 'year' ? increaseYear : increaseMonth;\n const prevDisabled =\n picker === 'year' ? prevYearButtonDisabled : prevMonthButtonDisabled;\n const nextDisabled =\n picker === 'year' ? nextYearButtonDisabled : nextMonthButtonDisabled;\n\n return (\n <div className=\"ndl-datepicker-header\">\n <div className=\"ndl-datepicker-selects\">\n {picker !== 'year' && (\n <button\n aria-label={`${picker === 'month' ? 'Close' : 'Open'} month picker`}\n aria-pressed={picker === 'month'}\n onClick={() => headerAction('month')}\n >\n <div className=\"n-flex n-items-center n-gap-token-4\">\n <Typography variant=\"subheading-small\">\n {format(props.date, 'MMM')}\n </Typography>\n <ChevronDownIconOutline\n className={classNames('ndl-datepicker-chevron', {\n 'n-rotate-180': picker === 'month',\n })}\n aria-label=\"Chevron icon\"\n />\n </div>\n </button>\n )}\n {picker !== 'month' && (\n <button\n aria-label={`${picker === 'year' ? 'Close' : 'Open'} year picker`}\n onClick={() => headerAction('year')}\n >\n <div className=\"n-flex n-items-center n-gap-token-4\">\n <Typography variant=\"subheading-small\">\n {picker === 'year'\n ? getYearsPeriodString(\n props.date,\n reactDatePickerProps?.yearItemNumber,\n )\n : format(props.date, 'yyyy')}\n </Typography>\n <ChevronDownIconOutline\n className={classNames('ndl-datepicker-chevron', {\n 'n-rotate-180': picker === 'year',\n })}\n aria-label=\"Chevron icon\"\n />\n </div>\n </button>\n )}\n </div>\n {picker !== 'month' && (\n <div className=\"n-flex n-justify-center n-gap-token-16\">\n <CleanIconButton\n description={\n picker === 'year' ? 'Previous period' : 'Previous month'\n }\n onClick={prevCallback}\n isDisabled={prevDisabled}\n className=\"n-text-neutral-text-weak\"\n size=\"small\"\n >\n <ArrowLeftIconOutline />\n </CleanIconButton>\n <CleanIconButton\n description={picker === 'year' ? 'Next period' : 'Next month'}\n onClick={nextCallback}\n isDisabled={nextDisabled}\n className=\"n-text-neutral-text-weak\"\n size=\"small\"\n >\n <ArrowRightIconOutline />\n </CleanIconButton>\n </div>\n )}\n </div>\n );\n },\n [picker, headerAction, reactDatePickerProps?.yearItemNumber],\n );\n\n const handleTimeChange = (newTime: NeedleTime) => {\n if (\n reactDatePickerProps.selectsRange ||\n reactDatePickerProps.selectsMultiple\n ) {\n // this is consistent with the behavior of react-datepicker\n return;\n }\n\n if (!preSelectedDate) return;\n\n const newDate = new Date(preSelectedDate);\n newDate.setHours(newTime.hour, newTime.minute, 0, 0);\n setPreSelectedDate(newDate);\n\n if (reactDatePickerProps.onChange) {\n // For single date selection\n reactDatePickerProps.onChange(newDate, undefined);\n }\n };\n\n /**\n * Intercept onChange so we can work with\n * Month and Year pickers\n */\n const interceptedChange: DatePickerChangeHandler = useCallback(\n (\n date: Date | null | [Date | null, Date | null] | Date[],\n event?: React.SyntheticEvent,\n ) => {\n if (picker !== 'day') {\n // setTimeout to prevent picker change before the handleMonthChange logic\n setTimeout(() => {\n setPicker('day');\n });\n } else if (picker === 'day') {\n if (date instanceof Date) {\n setPreSelectedDate(date);\n } else if (\n Array.isArray(date) &&\n date.length > 0 &&\n date[0] instanceof Date\n ) {\n setPreSelectedDate(date[0]);\n } else if (date === null) {\n setPreSelectedDate(null);\n }\n\n if (reactDatePickerProps.onChange && date !== null) {\n (reactDatePickerProps.onChange as DatePickerChangeHandler)(\n date,\n event,\n );\n }\n }\n },\n [picker, reactDatePickerProps],\n );\n\n /**\n * Intercept onCalendarClose so we can\n * switch to \"day\" picker if we close on \"month\" or \"year\"\n * view\n */\n const interceptedOnCalendarClose = useCallback(() => {\n if (picker !== 'day') {\n setPicker('day');\n }\n reactDatePickerProps?.onCalendarClose?.();\n }, [picker, reactDatePickerProps]);\n\n const handleMonthChange = useCallback(\n (date: Date) => {\n if (picker === 'month') {\n const selectedDay = preSelectedDate?.getDate() ?? 1;\n const daysInNewMonth = daysInMonth(date.getMonth(), date.getFullYear());\n date.setDate(Math.min(selectedDay, daysInNewMonth));\n reactDatePickerProps?.onMonthChange?.(date);\n } else if (picker === 'year') {\n const selectedDay = preSelectedDate?.getDate() ?? 1;\n const selectedMonth = preSelectedDate?.getMonth() ?? 0;\n const daysInNewMonth = daysInMonth(selectedMonth, date.getFullYear());\n date.setMonth(selectedMonth, Math.min(selectedDay, daysInNewMonth));\n reactDatePickerProps?.onMonthChange?.(date);\n }\n setPreSelectedDate(date);\n },\n [picker, preSelectedDate, reactDatePickerProps],\n );\n\n /**\n * Intercept onChangeRaw to handle clearing the input\n * When the user clears the text input, set the date to null\n */\n const interceptedOnChangeRaw = useCallback(\n (\n event?:\n | React.KeyboardEvent<HTMLElement>\n | React.MouseEvent<HTMLElement, MouseEvent>,\n ) => {\n const target = event?.target as HTMLInputElement | undefined;\n if (target?.value === '') {\n setPreSelectedDate(null);\n if (reactDatePickerProps.onChange) {\n (reactDatePickerProps.onChange as DatePickerChangeHandler)(\n null,\n event,\n );\n }\n }\n reactDatePickerProps?.onChangeRaw?.(event);\n },\n [reactDatePickerProps],\n );\n\n const datePickerProps = {\n ...reactDatePickerProps,\n onCalendarClose: interceptedOnCalendarClose,\n onChange: interceptedChange,\n onChangeRaw: interceptedOnChangeRaw,\n onMonthChange: handleMonthChange,\n };\n\n return (\n <div\n className={classes}\n ref={ref}\n style={style}\n {...restProps}\n {...htmlAttributes}\n >\n <ReactDatePicker\n ref={datetimeRef}\n customInput={\n <DatePickerTextInputWrapper\n isDisabled={isDisabled}\n textInputProps={textInputProps}\n />\n }\n customTimeInput={\n <span>\n <Divider className=\"n-my-4\" />\n <TimePicker\n isFluid\n value={\n preSelectedDate\n ? new NeedleTime(\n preSelectedDate.getHours(),\n preSelectedDate.getMinutes(),\n )\n : undefined\n }\n onChange={handleTimeChange}\n {...timePickerProps}\n floatingStrategy=\"absolute\"\n isPortaled={false}\n />\n </span>\n }\n disabled={isDisabled}\n showPopperArrow={false}\n showMonthYearPicker={picker === 'month'}\n showYearPicker={picker === 'year'}\n shouldCloseOnSelect={\n picker === 'day' && !(reactDatePickerProps.showTimeInput ?? false)\n }\n dayClassName={() => 'ndl-datepicker-day'}\n renderCustomHeader={CustomHeader}\n {...datePickerProps}\n popperClassName={classNames(\n 'ndl-datepicker-popper',\n reactDatePickerProps.popperClassName,\n )}\n popperProps={{\n strategy: isInsideDialog ? 'fixed' : 'absolute',\n ...reactDatePickerProps.popperProps,\n }}\n />\n </div>\n );\n};\n"]}
@@ -38,7 +38,8 @@ import { CleanIconButton } from '../clean-icon-button';
38
38
  import { ConditionalWrap } from '../conditional-wrap';
39
39
  import { XMarkIconOutline } from '../icons';
40
40
  import { Typography } from '../typography';
41
- const DrawerComponent = function DrawerComponent({ children, className = '', isExpanded, onExpandedChange, position = 'left', type = 'overlay', isResizeable = false, resizeableProps, isCloseable = true, isPortaled = false, portalProps = {}, htmlAttributes, ref, }) {
41
+ const DrawerComponent = function DrawerComponent(_a) {
42
+ var { children, className = '', isExpanded, onExpandedChange, position = 'left', type = 'overlay', isResizeable = false, resizeableProps, isCloseable = true, isPortaled = false, portalProps = {}, htmlAttributes, style, ref, as } = _a, restProps = __rest(_a, ["children", "className", "isExpanded", "onExpandedChange", "position", "type", "isResizeable", "resizeableProps", "isCloseable", "isPortaled", "portalProps", "htmlAttributes", "style", "ref", "as"]);
42
43
  const setOnExpandedChange = useCallback(() => {
43
44
  if (onExpandedChange)
44
45
  onExpandedChange(!isExpanded);
@@ -52,14 +53,15 @@ const DrawerComponent = function DrawerComponent({ children, className = '', isE
52
53
  });
53
54
  const resizableStylePosition = type === 'overlay' ? 'absolute' : 'relative';
54
55
  const shouldRenderInPortal = isPortaled && type === 'overlay';
56
+ const Component = as !== null && as !== void 0 ? as : 'div';
55
57
  const Close = () => (_jsx(_Fragment, { children: isCloseable && (_jsx(CleanIconButton, { className: "ndl-drawer-close-button", onClick: setOnExpandedChange, description: "Close", size: "medium", htmlAttributes: {
56
58
  title: 'Close drawer',
57
59
  }, children: _jsx(XMarkIconOutline, {}) })) }));
58
60
  if (isResizeable) {
59
- return (_jsx(ConditionalWrap, { shouldWrap: shouldRenderInPortal, wrap: (wrapChildren) => (_jsx(FloatingPortal, Object.assign({ preserveTabOrder: true }, portalProps, { children: wrapChildren }))), children: _jsxs(Resizable, Object.assign({ defaultSize: {
61
+ return (_jsx(ConditionalWrap, { shouldWrap: shouldRenderInPortal, wrap: (wrapChildren) => (_jsx(FloatingPortal, Object.assign({ preserveTabOrder: true }, portalProps, { children: wrapChildren }))), children: _jsxs(Resizable, Object.assign({ as: Component, defaultSize: {
60
62
  height: '100%',
61
63
  width: 'auto',
62
- } }, resizeableProps, { className: classes, style: Object.assign({ position: resizableStylePosition }, resizeableProps === null || resizeableProps === void 0 ? void 0 : resizeableProps.style), boundsByDirection: true, bounds: "parent", handleStyles: {
64
+ } }, resizeableProps, { className: classes, style: Object.assign(Object.assign({ position: resizableStylePosition }, style), resizeableProps === null || resizeableProps === void 0 ? void 0 : resizeableProps.style), boundsByDirection: true, bounds: "parent", handleStyles: {
63
65
  /*
64
66
  * adding a small offset to the handle to make it easier to click
65
67
  * if the content of the drawer is scrollable, most noticeable if not using
@@ -77,9 +79,9 @@ const DrawerComponent = function DrawerComponent({ children, className = '', isE
77
79
  top: false,
78
80
  topLeft: false,
79
81
  topRight: false,
80
- }, ref: ref, children: [children, _jsx(Close, {})] })) }));
82
+ }, ref: ref }, restProps, htmlAttributes, { children: [children, _jsx(Close, {})] })) }));
81
83
  }
82
- return (_jsx(ConditionalWrap, { shouldWrap: shouldRenderInPortal, wrap: (wrapChildren) => (_jsx(FloatingPortal, Object.assign({ preserveTabOrder: true }, portalProps, { children: wrapChildren }))), children: _jsxs("div", Object.assign({ className: classes, ref: ref }, htmlAttributes, { children: [children, _jsx(Close, {})] })) }));
84
+ return (_jsx(ConditionalWrap, { shouldWrap: shouldRenderInPortal, wrap: (wrapChildren) => (_jsx(FloatingPortal, Object.assign({ preserveTabOrder: true }, portalProps, { children: wrapChildren }))), children: _jsxs(Component, Object.assign({ className: classes, style: style, ref: ref }, restProps, htmlAttributes, { children: [children, _jsx(Close, {})] })) }));
83
85
  };
84
86
  DrawerComponent.displayName = 'Drawer';
85
87
  const DrawerHeader = (_a) => {
@@ -1 +1 @@
1
- {"version":3,"file":"Drawer.js","sourceRoot":"","sources":["../../../src/drawer/Drawer.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,SAAS,EAAuB,MAAM,cAAc,CAAC;AAE9D,OAAO,EAAuB,WAAW,EAAE,MAAM,OAAO,CAAC;AAMzD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AA4C3C,MAAM,eAAe,GAAG,SAAS,eAAe,CAE9C,EACA,QAAQ,EACR,SAAS,GAAG,EAAE,EACd,UAAU,EACV,gBAAgB,EAChB,QAAQ,GAAG,MAAM,EACjB,IAAI,GAAG,SAAS,EAChB,YAAY,GAAG,KAAK,EACpB,eAAe,EACf,WAAW,GAAG,IAAI,EAClB,UAAU,GAAG,KAAK,EAClB,WAAW,GAAG,EAAE,EAChB,cAAc,EACd,GAAG,GACoC;IACvC,MAAM,mBAAmB,GAAG,WAAW,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EAAC,SAAS,IAAK,SAAS,IAAE,SAAS,EAAE,OAAO,YAC5D,QAAQ,IACE,CACd,CAAC;IACJ,CAAC;IAED,OAAO,CACL,8BAAS,SAAS,IAAE,SAAS,EAAE,OAAO,YACnC,QAAQ,IACL,CACP,CAAC;AACJ,CAAC,CAAC;AAQF,MAAM,aAAa,GAAG,CAAC,EAIF,EAAE,EAAE;QAJF,EACrB,QAAQ,EACR,SAAS,GAAG,EAAE,OAEK,EADhB,SAAS,cAHS,yBAItB,CADa;IAEZ,MAAM,OAAO,GAAG,UAAU,CAAC,oBAAoB,EAAE,SAAS,CAAC,CAAC;IAE5D,OAAO,CACL,8BAAS,SAAS,IAAE,SAAS,EAAE,OAAO,YACnC,QAAQ,IACL,CACP,CAAC;AACJ,CAAC,CAAC;AAQF,MAAM,UAAU,GAAG,CAAC,EAIF,EAAE,EAAE;QAJF,EAClB,QAAQ,EACR,SAAS,GAAG,EAAE,OAEE,EADb,SAAS,cAHM,yBAInB,CADa;IAEZ,MAAM,OAAO,GAAG,UAAU,CAAC,iBAAiB,EAAE,SAAS,CAAC,CAAC;IAEzD,OAAO,CACL,cAAK,SAAS,EAAC,yBAAyB,YACtC,8BAAS,SAAS,IAAE,SAAS,EAAE,OAAO,YACnC,QAAQ,IACL,GACF,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE;IAC5C,OAAO,EAAE,aAAa;IACtB,IAAI,EAAE,UAAU;IAChB,MAAM,EAAE,YAAY;CACrB,CAAC,CAAC;AAEH,OAAO,EAAE,MAAM,EAAE,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport { FloatingPortal } from '@floating-ui/react';\nimport classNames from 'classnames';\nimport { Resizable, type ResizableProps } from 're-resizable';\nimport type React from 'react';\nimport { type ComponentProps, useCallback } from 'react';\n\nimport {\n type HtmlAttributes,\n type PolymorphicCommonProps,\n} from '../_common/types';\nimport { CleanIconButton } from '../clean-icon-button';\nimport { ConditionalWrap } from '../conditional-wrap';\nimport { XMarkIconOutline } from '../icons';\nimport { Typography } from '../typography';\n\ntype DrawerPosition = 'left' | 'right';\n\ntype DrawerType = 'overlay' | 'push';\n\ntype DrawerProps = {\n /** Controls whether the drawer is open (expanded) or closed (collapsed). */\n isExpanded: boolean;\n\n /** Callback functions fired when the drawer's expanded state changes. */\n onExpandedChange?: (expanded: boolean) => void;\n\n /** Position where the drawer appears on screen. By default, it appears from the left. */\n position?: DrawerPosition;\n\n /** How the drawer affects the layout of sibling content. By default, it overlays content. */\n type?: DrawerType;\n\n /** Enables horizontal resizing of the drawer, by default it is not resizable. */\n isResizeable?: boolean;\n\n /** To use this prop the isResizeable prop must be set to true. For overriding the third party library props: https://github.com/bokuweb/re-resizable */\n resizeableProps?: ResizableProps;\n\n /** Whether a close button (X) is displayed in the drawer. */\n isCloseable?: boolean;\n\n /** Whether to portal the content */\n isPortaled?: boolean;\n\n /** The content to display within the drawer. */\n children: React.ReactNode;\n\n /** Additional CSS classes to apply to the drawer container. */\n className?: string;\n\n /**\n * Props to pass to the portal from @floating-ui/react FloatingPortal\n * @see https://floating-ui.com/docs/floatingportal\n */\n portalProps?: ComponentProps<typeof FloatingPortal>;\n};\n\nconst DrawerComponent = function DrawerComponent<\n T extends React.ElementType = 'div',\n>({\n children,\n className = '',\n isExpanded,\n onExpandedChange,\n position = 'left',\n type = 'overlay',\n isResizeable = false,\n resizeableProps,\n isCloseable = true,\n isPortaled = false,\n portalProps = {},\n htmlAttributes,\n ref,\n}: PolymorphicCommonProps<T, DrawerProps>) {\n const setOnExpandedChange = useCallback(() => {\n if (onExpandedChange) onExpandedChange(!isExpanded);\n }, [isExpanded, onExpandedChange]);\n\n const classes = classNames('ndl-drawer', className, {\n 'ndl-drawer-expanded': isExpanded,\n 'ndl-drawer-left': position === 'left',\n 'ndl-drawer-overlay': type === 'overlay',\n 'ndl-drawer-push': type === 'push',\n 'ndl-drawer-right': position === 'right',\n });\n\n const resizableStylePosition = type === 'overlay' ? 'absolute' : 'relative';\n const shouldRenderInPortal = isPortaled && type === 'overlay';\n\n const Close = () => (\n <>\n {isCloseable && (\n <CleanIconButton\n className=\"ndl-drawer-close-button\"\n onClick={setOnExpandedChange}\n description=\"Close\"\n size=\"medium\"\n htmlAttributes={{\n title: 'Close drawer',\n }}\n >\n <XMarkIconOutline />\n </CleanIconButton>\n )}\n </>\n );\n\n if (isResizeable) {\n return (\n <ConditionalWrap\n shouldWrap={shouldRenderInPortal}\n wrap={(wrapChildren) => (\n <FloatingPortal preserveTabOrder={true} {...portalProps}>\n {wrapChildren}\n </FloatingPortal>\n )}\n >\n <Resizable\n defaultSize={{\n height: '100%',\n width: 'auto',\n }}\n {...resizeableProps}\n className={classes}\n style={{\n position: resizableStylePosition,\n ...resizeableProps?.style,\n }}\n boundsByDirection={true}\n bounds=\"parent\"\n handleStyles={{\n /*\n * adding a small offset to the handle to make it easier to click\n * if the content of the drawer is scrollable, most noticeable if not using\n * a mouse on mac or chrome on windows with the fluent scrollbars\n */\n right: {\n right: '-8px',\n },\n }}\n enable={{\n bottom: false,\n bottomLeft: false,\n bottomRight: false,\n left: position === 'right',\n right: position === 'left',\n top: false,\n topLeft: false,\n topRight: false,\n }}\n ref={ref}\n >\n {children}\n <Close />\n </Resizable>\n </ConditionalWrap>\n );\n }\n\n return (\n <ConditionalWrap\n shouldWrap={shouldRenderInPortal}\n wrap={(wrapChildren) => (\n <FloatingPortal preserveTabOrder={true} {...portalProps}>\n {wrapChildren}\n </FloatingPortal>\n )}\n >\n <div className={classes} ref={ref} {...htmlAttributes}>\n {children}\n <Close />\n </div>\n </ConditionalWrap>\n );\n};\n\nDrawerComponent.displayName = 'Drawer';\n\ntype DrawerHeaderProps = {\n children: React.ReactNode;\n className?: string;\n htmlAttributes?: HtmlAttributes<'h5'>;\n};\n\nconst DrawerHeader = ({\n children,\n className = '',\n ...restProps\n}: DrawerHeaderProps) => {\n const classes = classNames('ndl-drawer-header', className);\n\n if (typeof children === 'string' || typeof children === 'number') {\n return (\n <Typography variant=\"title-3\" {...restProps} className={classes}>\n {children}\n </Typography>\n );\n }\n\n return (\n <div {...restProps} className={classes}>\n {children}\n </div>\n );\n};\n\ntype DrawerActionsProps = {\n children: React.ReactNode;\n className?: string;\n htmlAttributes?: HtmlAttributes<'div'>;\n};\n\nconst DrawerActions = ({\n children,\n className = '',\n ...restProps\n}: DrawerActionsProps) => {\n const classes = classNames('ndl-drawer-actions', className);\n\n return (\n <div {...restProps} className={classes}>\n {children}\n </div>\n );\n};\n\ntype DrawerBodyProps = {\n children: React.ReactNode;\n className?: string;\n htmlAttributes?: HtmlAttributes<'div'>;\n};\n\nconst DrawerBody = ({\n children,\n className = '',\n ...restProps\n}: DrawerBodyProps) => {\n const classes = classNames('ndl-drawer-body', className);\n\n return (\n <div className=\"ndl-drawer-body-wrapper\">\n <div {...restProps} className={classes}>\n {children}\n </div>\n </div>\n );\n};\n\nconst Drawer = Object.assign(DrawerComponent, {\n Actions: DrawerActions,\n Body: DrawerBody,\n Header: DrawerHeader,\n});\n\nexport { Drawer };\n"]}
1
+ {"version":3,"file":"Drawer.js","sourceRoot":"","sources":["../../../src/drawer/Drawer.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,UAAU,MAAM,Y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AU,CAAC,oBAAoB,EAAE,SAAS,CAAC,CAAC;IAE5D,OAAO,CACL,8BAAS,SAAS,IAAE,SAAS,EAAE,OAAO,YACnC,QAAQ,IACL,CACP,CAAC;AACJ,CAAC,CAAC;AAQF,MAAM,UAAU,GAAG,CAAC,EAIF,EAAE,EAAE;QAJF,EAClB,QAAQ,EACR,SAAS,GAAG,EAAE,OAEE,EADb,SAAS,cAHM,yBAInB,CADa;IAEZ,MAAM,OAAO,GAAG,UAAU,CAAC,iBAAiB,EAAE,SAAS,CAAC,CAAC;IAEzD,OAAO,CACL,cAAK,SAAS,EAAC,yBAAyB,YACtC,8BAAS,SAAS,IAAE,SAAS,EAAE,OAAO,YACnC,QAAQ,IACL,GACF,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE;IAC5C,OAAO,EAAE,aAAa;IACtB,IAAI,EAAE,UAAU;IAChB,MAAM,EAAE,YAAY;CACrB,CAAC,CAAC;AAEH,OAAO,EAAE,MAAM,EAAE,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport { FloatingPortal } from '@floating-ui/react';\nimport classNames from 'classnames';\nimport { Resizable, type ResizableProps } from 're-resizable';\nimport type React from 'react';\nimport { type ComponentProps, useCallback } from 'react';\n\nimport {\n type HtmlAttributes,\n type PolymorphicCommonProps,\n} from '../_common/types';\nimport { CleanIconButton } from '../clean-icon-button';\nimport { ConditionalWrap } from '../conditional-wrap';\nimport { XMarkIconOutline } from '../icons';\nimport { Typography } from '../typography';\n\ntype DrawerPosition = 'left' | 'right';\n\ntype DrawerType = 'overlay' | 'push';\n\ntype DrawerProps = {\n /** Controls whether the drawer is open (expanded) or closed (collapsed). */\n isExpanded: boolean;\n\n /** Callback functions fired when the drawer's expanded state changes. */\n onExpandedChange?: (expanded: boolean) => void;\n\n /** Position where the drawer appears on screen. By default, it appears from the left. */\n position?: DrawerPosition;\n\n /** How the drawer affects the layout of sibling content. By default, it overlays content. */\n type?: DrawerType;\n\n /** Enables horizontal resizing of the drawer, by default it is not resizable. */\n isResizeable?: boolean;\n\n /** To use this prop the isResizeable prop must be set to true. For overriding the third party library props: https://github.com/bokuweb/re-resizable */\n resizeableProps?: ResizableProps;\n\n /** Whether a close button (X) is displayed in the drawer. */\n isCloseable?: boolean;\n\n /** Whether to portal the content */\n isPortaled?: boolean;\n\n /** The content to display within the drawer. */\n children: React.ReactNode;\n\n /** Additional CSS classes to apply to the drawer container. */\n className?: string;\n\n /**\n * Props to pass to the portal from @floating-ui/react FloatingPortal\n * @see https://floating-ui.com/docs/floatingportal\n */\n portalProps?: ComponentProps<typeof FloatingPortal>;\n};\n\nconst DrawerComponent = function DrawerComponent<\n T extends React.ElementType = 'div',\n>({\n children,\n className = '',\n isExpanded,\n onExpandedChange,\n position = 'left',\n type = 'overlay',\n isResizeable = false,\n resizeableProps,\n isCloseable = true,\n isPortaled = false,\n portalProps = {},\n htmlAttributes,\n style,\n ref,\n as,\n ...restProps\n}: PolymorphicCommonProps<T, DrawerProps>) {\n const setOnExpandedChange = useCallback(() => {\n if (onExpandedChange) onExpandedChange(!isExpanded);\n }, [isExpanded, onExpandedChange]);\n\n const classes = classNames('ndl-drawer', className, {\n 'ndl-drawer-expanded': isExpanded,\n 'ndl-drawer-left': position === 'left',\n 'ndl-drawer-overlay': type === 'overlay',\n 'ndl-drawer-push': type === 'push',\n 'ndl-drawer-right': position === 'right',\n });\n\n const resizableStylePosition = type === 'overlay' ? 'absolute' : 'relative';\n const shouldRenderInPortal = isPortaled && type === 'overlay';\n const Component = as ?? 'div';\n\n const Close = () => (\n <>\n {isCloseable && (\n <CleanIconButton\n className=\"ndl-drawer-close-button\"\n onClick={setOnExpandedChange}\n description=\"Close\"\n size=\"medium\"\n htmlAttributes={{\n title: 'Close drawer',\n }}\n >\n <XMarkIconOutline />\n </CleanIconButton>\n )}\n </>\n );\n\n if (isResizeable) {\n return (\n <ConditionalWrap\n shouldWrap={shouldRenderInPortal}\n wrap={(wrapChildren) => (\n <FloatingPortal preserveTabOrder={true} {...portalProps}>\n {wrapChildren}\n </FloatingPortal>\n )}\n >\n <Resizable\n as={Component}\n defaultSize={{\n height: '100%',\n width: 'auto',\n }}\n {...resizeableProps}\n className={classes}\n style={{\n position: resizableStylePosition,\n ...style,\n ...resizeableProps?.style,\n }}\n boundsByDirection={true}\n bounds=\"parent\"\n handleStyles={{\n /*\n * adding a small offset to the handle to make it easier to click\n * if the content of the drawer is scrollable, most noticeable if not using\n * a mouse on mac or chrome on windows with the fluent scrollbars\n */\n right: {\n right: '-8px',\n },\n }}\n enable={{\n bottom: false,\n bottomLeft: false,\n bottomRight: false,\n left: position === 'right',\n right: position === 'left',\n top: false,\n topLeft: false,\n topRight: false,\n }}\n ref={ref}\n {...restProps}\n {...htmlAttributes}\n >\n {children}\n <Close />\n </Resizable>\n </ConditionalWrap>\n );\n }\n\n return (\n <ConditionalWrap\n shouldWrap={shouldRenderInPortal}\n wrap={(wrapChildren) => (\n <FloatingPortal preserveTabOrder={true} {...portalProps}>\n {wrapChildren}\n </FloatingPortal>\n )}\n >\n <Component\n className={classes}\n style={style}\n ref={ref}\n {...restProps}\n {...htmlAttributes}\n >\n {children}\n <Close />\n </Component>\n </ConditionalWrap>\n );\n};\n\nDrawerComponent.displayName = 'Drawer';\n\ntype DrawerHeaderProps = {\n children: React.ReactNode;\n className?: string;\n htmlAttributes?: HtmlAttributes<'h5'>;\n};\n\nconst DrawerHeader = ({\n children,\n className = '',\n ...restProps\n}: DrawerHeaderProps) => {\n const classes = classNames('ndl-drawer-header', className);\n\n if (typeof children === 'string' || typeof children === 'number') {\n return (\n <Typography variant=\"title-3\" {...restProps} className={classes}>\n {children}\n </Typography>\n );\n }\n\n return (\n <div {...restProps} className={classes}>\n {children}\n </div>\n );\n};\n\ntype DrawerActionsProps = {\n children: React.ReactNode;\n className?: string;\n htmlAttributes?: HtmlAttributes<'div'>;\n};\n\nconst DrawerActions = ({\n children,\n className = '',\n ...restProps\n}: DrawerActionsProps) => {\n const classes = classNames('ndl-drawer-actions', className);\n\n return (\n <div {...restProps} className={classes}>\n {children}\n </div>\n );\n};\n\ntype DrawerBodyProps = {\n children: React.ReactNode;\n className?: string;\n htmlAttributes?: HtmlAttributes<'div'>;\n};\n\nconst DrawerBody = ({\n children,\n className = '',\n ...restProps\n}: DrawerBodyProps) => {\n const classes = classNames('ndl-drawer-body', className);\n\n return (\n <div className=\"ndl-drawer-body-wrapper\">\n <div {...restProps} className={classes}>\n {children}\n </div>\n </div>\n );\n};\n\nconst Drawer = Object.assign(DrawerComponent, {\n Actions: DrawerActions,\n Body: DrawerBody,\n Header: DrawerHeader,\n});\n\nexport { Drawer };\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"DatePicker.d.ts","sourceRoot":"","sources":["../../../src/date-picker/DatePicker.tsx"],"names":[],"mappings":"AA0BA,OAAO,eAEN,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAUpD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAA0B,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAgE9E,UAAU,eAAe;IACvB,oDAAoD;IACpD,cAAc,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,OAAO,SAAS,CAAC,CAAC;IACxD,2CAA2C;IAC3C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,qDAAqD;IACrD,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,kEAAkE;IAClE,oBAAoB,EAAE,KAAK,CAAC,cAAc,CAAC,OAAO,eAAe,CAAC,CAAC;CACpE;AAED,eAAO,MAAM,UAAU,GAAI,4HAUxB,WAAW,CAAC,KAAK,EAAE,eAAe,CAAC,4CA4QrC,CAAC"}
1
+ {"version":3,"file":"DatePicker.d.ts","sourceRoot":"","sources":["../../../src/date-picker/DatePicker.tsx"],"names":[],"mappings":"AA0BA,OAAO,eAEN,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAUpD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAA0B,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAgE9E,UAAU,eAAe;IACvB,oDAAoD;IACpD,cAAc,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,OAAO,SAAS,CAAC,CAAC;IACxD,2CAA2C;IAC3C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,qDAAqD;IACrD,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,kEAAkE;IAClE,oBAAoB,EAAE,KAAK,CAAC,cAAc,CAAC,OAAO,eAAe,CAAC,CAAC;CACpE;AAED,eAAO,MAAM,UAAU,GAAI,4HAUxB,WAAW,CAAC,KAAK,EAAE,eAAe,CAAC,4CAsSrC,CAAC"}
@@ -68,7 +68,7 @@ type DrawerBodyProps = {
68
68
  htmlAttributes?: HtmlAttributes<'div'>;
69
69
  };
70
70
  declare const Drawer: {
71
- <T extends React.ElementType = "div">({ children, className, isExpanded, onExpandedChange, position, type, isResizeable, resizeableProps, isCloseable, isPortaled, portalProps, htmlAttributes, ref, }: PolymorphicCommonProps<T, DrawerProps>): import("react/jsx-runtime").JSX.Element;
71
+ <T extends React.ElementType = "div">({ children, className, isExpanded, onExpandedChange, position, type, isResizeable, resizeableProps, isCloseable, isPortaled, portalProps, htmlAttributes, style, ref, as, ...restProps }: PolymorphicCommonProps<T, DrawerProps>): import("react/jsx-runtime").JSX.Element;
72
72
  displayName: string;
73
73
  } & {
74
74
  Actions: ({ children, className, ...restProps }: DrawerActionsProps) => import("react/jsx-runtime").JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"Drawer.d.ts","sourceRoot":"","sources":["../../../src/drawer/Drawer.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAa,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,KAAK,cAAc,EAAe,MAAM,OAAO,CAAC;AAEzD,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC5B,MAAM,kBAAkB,CAAC;AAM1B,KAAK,cAAc,GAAG,MAAM,GAAG,OAAO,CAAC;AAEvC,KAAK,UAAU,GAAG,SAAS,GAAG,MAAM,CAAC;AAErC,KAAK,WAAW,GAAG;IACjB,4EAA4E;IAC5E,UAAU,EAAE,OAAO,CAAC;IAEpB,yEAAyE;IACzE,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;IAE/C,yFAAyF;IACzF,QAAQ,CAAC,EAAE,cAAc,CAAC;IAE1B,6FAA6F;IAC7F,IAAI,CAAC,EAAE,UAAU,CAAC;IAElB,iFAAiF;IACjF,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB,wJAAwJ;IACxJ,eAAe,CAAC,EAAE,cAAc,CAAC;IAEjC,6DAA6D;IAC7D,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,oCAAoC;IACpC,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB,gDAAgD;IAChD,QAAQ,EAAE,KAAK,CAAC,SAAS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AC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC;CACxC,CAAC;AAkBF,QAAA,MAAM,MAAM;KA5MV,CAAC,SAAS,KAAK,CAAC,WAAW,oMAkB1B,sBAAsB,CAAC,CAAC,EAAE,WAAW,CAAC;;;qDA0JtC,kBAAkB;kDAoBlB,eAAe;oDAhDf,iBAAiB;CAgElB,CAAC;AAEH,OAAO,EAAE,MAAM,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neo4j-ndl/react",
3
- "version": "4.0.16",
3
+ "version": "4.0.18",
4
4
  "sideEffects": false,
5
5
  "description": "React implementation of Neo4j Design System",
6
6
  "keywords": [