@mantine/core 9.4.3-alpha.0 → 9.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/components/Accordion/Accordion.cjs +5 -2
- package/cjs/components/Accordion/Accordion.cjs.map +1 -1
- package/cjs/components/AngleSlider/AngleSlider.cjs +4 -1
- package/cjs/components/AngleSlider/AngleSlider.cjs.map +1 -1
- package/cjs/components/Avatar/AvatarGroup/AvatarGroup.cjs +15 -14
- package/cjs/components/Avatar/AvatarGroup/AvatarGroup.cjs.map +1 -1
- package/cjs/components/Cascader/Cascader.cjs +371 -0
- package/cjs/components/Cascader/Cascader.cjs.map +1 -0
- package/cjs/components/Cascader/Cascader.module.cjs +18 -0
- package/cjs/components/Cascader/Cascader.module.cjs.map +1 -0
- package/cjs/components/Cascader/CascaderColumns.cjs +136 -0
- package/cjs/components/Cascader/CascaderColumns.cjs.map +1 -0
- package/cjs/components/Cascader/flatten-cascader-paths.cjs +26 -0
- package/cjs/components/Cascader/flatten-cascader-paths.cjs.map +1 -0
- package/cjs/components/Cascader/get-cascader-columns.cjs +30 -0
- package/cjs/components/Cascader/get-cascader-columns.cjs.map +1 -0
- package/cjs/components/Cascader/get-cascader-path-options.cjs +19 -0
- package/cjs/components/Cascader/get-cascader-path-options.cjs.map +1 -0
- package/cjs/components/Cascader/use-cascader.cjs +135 -0
- package/cjs/components/Cascader/use-cascader.cjs.map +1 -0
- package/cjs/components/ColorPicker/converters/converters.cjs +5 -0
- package/cjs/components/ColorPicker/converters/parsers.cjs +5 -0
- package/cjs/components/Combobox/use-combobox/use-combobox.cjs +6 -2
- package/cjs/components/Combobox/use-combobox/use-combobox.cjs.map +1 -1
- package/cjs/components/ComboboxPopover/ComboboxPopover.cjs +2 -1
- package/cjs/components/ComboboxPopover/ComboboxPopover.cjs.map +1 -1
- package/cjs/components/Drawer/DrawerStack.cjs +1 -1
- package/cjs/components/Drawer/DrawerStack.cjs.map +1 -1
- package/cjs/components/FloatingIndicator/FloatingIndicator.cjs +2 -1
- package/cjs/components/FloatingIndicator/FloatingIndicator.cjs.map +1 -1
- package/cjs/components/FloatingWindow/FloatingWindow.cjs +31 -10
- package/cjs/components/FloatingWindow/FloatingWindow.cjs.map +1 -1
- package/cjs/components/FloatingWindow/FloatingWindow.context.cjs +8 -0
- package/cjs/components/FloatingWindow/FloatingWindow.context.cjs.map +1 -0
- package/cjs/components/FloatingWindow/FloatingWindow.module.cjs.map +1 -1
- package/cjs/components/FloatingWindow/FloatingWindowResizeHandle.cjs +161 -0
- package/cjs/components/FloatingWindow/FloatingWindowResizeHandle.cjs.map +1 -0
- package/cjs/components/Modal/ModalStack.cjs +1 -1
- package/cjs/components/Modal/ModalStack.cjs.map +1 -1
- package/cjs/components/OverflowList/OverflowList.cjs +2 -1
- package/cjs/components/OverflowList/OverflowList.cjs.map +1 -1
- package/cjs/components/Pagination/PaginationEdges/PaginationEdges.cjs +1 -0
- package/cjs/components/ScrollArea/ScrollArea.cjs +7 -2
- package/cjs/components/ScrollArea/ScrollArea.cjs.map +1 -1
- package/cjs/components/ScrollArea/ScrollArea.module.cjs.map +1 -1
- package/cjs/components/ScrollArea/ScrollAreaCorner/ScrollAreaCorner.cjs +1 -0
- package/cjs/components/ScrollArea/ScrollAreaScrollbar/Scrollbar.cjs +8 -4
- package/cjs/components/ScrollArea/ScrollAreaScrollbar/Scrollbar.cjs.map +1 -1
- package/cjs/components/ScrollArea/ScrollAreaThumb/ScrollAreaThumb.cjs +3 -1
- package/cjs/components/ScrollArea/ScrollAreaThumb/ScrollAreaThumb.cjs.map +1 -1
- package/cjs/components/SimpleGrid/SimpleGridVariables.cjs +1 -1
- package/cjs/components/SimpleGrid/SimpleGridVariables.cjs.map +1 -1
- package/cjs/components/Slider/RangeSlider/RangeSlider.cjs +18 -11
- package/cjs/components/Slider/RangeSlider/RangeSlider.cjs.map +1 -1
- package/cjs/components/Table/Table.components.cjs +1 -0
- package/cjs/components/TagsInput/TagsInput.cjs +2 -1
- package/cjs/components/TagsInput/TagsInput.cjs.map +1 -1
- package/cjs/components/Timeline/Timeline.cjs +5 -1
- package/cjs/components/Timeline/Timeline.cjs.map +1 -1
- package/cjs/components/Timeline/Timeline.module.cjs +2 -1
- package/cjs/components/Timeline/Timeline.module.cjs.map +1 -1
- package/cjs/components/Timeline/TimelineItem/TimelineItem.cjs +31 -20
- package/cjs/components/Timeline/TimelineItem/TimelineItem.cjs.map +1 -1
- package/cjs/components/Tree/TreeNode.cjs.map +1 -1
- package/cjs/components/Tree/use-tree.cjs +1 -1
- package/cjs/components/Tree/use-tree.cjs.map +1 -1
- package/cjs/components/TreeSelect/TreeSelect.cjs +3 -2
- package/cjs/components/TreeSelect/TreeSelect.cjs.map +1 -1
- package/cjs/core/Box/get-box-mod/get-box-mod.cjs +1 -0
- package/cjs/core/MantineProvider/MantineThemeProvider/MantineThemeProvider.cjs +6 -5
- package/cjs/core/MantineProvider/MantineThemeProvider/MantineThemeProvider.cjs.map +1 -1
- package/cjs/core/MantineProvider/merge-mantine-theme/merge-mantine-theme.cjs +2 -0
- package/cjs/core/MantineProvider/use-matches/use-matches.cjs +3 -2
- package/cjs/core/MantineProvider/use-matches/use-matches.cjs.map +1 -1
- package/cjs/index.cjs +7 -1
- package/esm/components/Accordion/Accordion.mjs +5 -2
- package/esm/components/Accordion/Accordion.mjs.map +1 -1
- package/esm/components/AngleSlider/AngleSlider.mjs +4 -1
- package/esm/components/AngleSlider/AngleSlider.mjs.map +1 -1
- package/esm/components/Avatar/AvatarGroup/AvatarGroup.mjs +15 -14
- package/esm/components/Avatar/AvatarGroup/AvatarGroup.mjs.map +1 -1
- package/esm/components/Cascader/Cascader.mjs +371 -0
- package/esm/components/Cascader/Cascader.mjs.map +1 -0
- package/esm/components/Cascader/Cascader.module.mjs +18 -0
- package/esm/components/Cascader/Cascader.module.mjs.map +1 -0
- package/esm/components/Cascader/CascaderColumns.mjs +135 -0
- package/esm/components/Cascader/CascaderColumns.mjs.map +1 -0
- package/esm/components/Cascader/flatten-cascader-paths.mjs +26 -0
- package/esm/components/Cascader/flatten-cascader-paths.mjs.map +1 -0
- package/esm/components/Cascader/get-cascader-columns.mjs +28 -0
- package/esm/components/Cascader/get-cascader-columns.mjs.map +1 -0
- package/esm/components/Cascader/get-cascader-path-options.mjs +19 -0
- package/esm/components/Cascader/get-cascader-path-options.mjs.map +1 -0
- package/esm/components/Cascader/use-cascader.mjs +135 -0
- package/esm/components/Cascader/use-cascader.mjs.map +1 -0
- package/esm/components/ColorPicker/converters/converters.mjs +1 -1
- package/esm/components/ColorPicker/converters/parsers.mjs +1 -1
- package/esm/components/Combobox/use-combobox/use-combobox.mjs +6 -2
- package/esm/components/Combobox/use-combobox/use-combobox.mjs.map +1 -1
- package/esm/components/ComboboxPopover/ComboboxPopover.mjs +2 -1
- package/esm/components/ComboboxPopover/ComboboxPopover.mjs.map +1 -1
- package/esm/components/Drawer/DrawerStack.mjs +1 -1
- package/esm/components/Drawer/DrawerStack.mjs.map +1 -1
- package/esm/components/FloatingIndicator/FloatingIndicator.mjs +2 -1
- package/esm/components/FloatingIndicator/FloatingIndicator.mjs.map +1 -1
- package/esm/components/FloatingWindow/FloatingWindow.context.mjs +8 -0
- package/esm/components/FloatingWindow/FloatingWindow.context.mjs.map +1 -0
- package/esm/components/FloatingWindow/FloatingWindow.mjs +32 -11
- package/esm/components/FloatingWindow/FloatingWindow.mjs.map +1 -1
- package/esm/components/FloatingWindow/FloatingWindow.module.mjs.map +1 -1
- package/esm/components/FloatingWindow/FloatingWindowResizeHandle.mjs +161 -0
- package/esm/components/FloatingWindow/FloatingWindowResizeHandle.mjs.map +1 -0
- package/esm/components/Modal/ModalStack.mjs +1 -1
- package/esm/components/Modal/ModalStack.mjs.map +1 -1
- package/esm/components/OverflowList/OverflowList.mjs +2 -1
- package/esm/components/OverflowList/OverflowList.mjs.map +1 -1
- package/esm/components/Pagination/PaginationEdges/PaginationEdges.mjs +1 -1
- package/esm/components/ScrollArea/ScrollArea.mjs +7 -2
- package/esm/components/ScrollArea/ScrollArea.mjs.map +1 -1
- package/esm/components/ScrollArea/ScrollArea.module.mjs.map +1 -1
- package/esm/components/ScrollArea/ScrollAreaCorner/ScrollAreaCorner.mjs +1 -1
- package/esm/components/ScrollArea/ScrollAreaScrollbar/Scrollbar.mjs +8 -4
- package/esm/components/ScrollArea/ScrollAreaScrollbar/Scrollbar.mjs.map +1 -1
- package/esm/components/ScrollArea/ScrollAreaThumb/ScrollAreaThumb.mjs +3 -2
- package/esm/components/ScrollArea/ScrollAreaThumb/ScrollAreaThumb.mjs.map +1 -1
- package/esm/components/SimpleGrid/SimpleGridVariables.mjs +1 -1
- package/esm/components/SimpleGrid/SimpleGridVariables.mjs.map +1 -1
- package/esm/components/Slider/RangeSlider/RangeSlider.mjs +18 -11
- package/esm/components/Slider/RangeSlider/RangeSlider.mjs.map +1 -1
- package/esm/components/Table/Table.components.mjs +1 -1
- package/esm/components/TagsInput/TagsInput.mjs +2 -1
- package/esm/components/TagsInput/TagsInput.mjs.map +1 -1
- package/esm/components/Timeline/Timeline.mjs +5 -1
- package/esm/components/Timeline/Timeline.mjs.map +1 -1
- package/esm/components/Timeline/Timeline.module.mjs +2 -1
- package/esm/components/Timeline/Timeline.module.mjs.map +1 -1
- package/esm/components/Timeline/TimelineItem/TimelineItem.mjs +31 -20
- package/esm/components/Timeline/TimelineItem/TimelineItem.mjs.map +1 -1
- package/esm/components/Tree/TreeNode.mjs.map +1 -1
- package/esm/components/Tree/use-tree.mjs +1 -1
- package/esm/components/Tree/use-tree.mjs.map +1 -1
- package/esm/components/TreeSelect/TreeSelect.mjs +3 -2
- package/esm/components/TreeSelect/TreeSelect.mjs.map +1 -1
- package/esm/core/Box/get-box-mod/get-box-mod.mjs +1 -1
- package/esm/core/MantineProvider/MantineThemeProvider/MantineThemeProvider.mjs +6 -5
- package/esm/core/MantineProvider/MantineThemeProvider/MantineThemeProvider.mjs.map +1 -1
- package/esm/core/MantineProvider/merge-mantine-theme/merge-mantine-theme.mjs +1 -1
- package/esm/core/MantineProvider/use-matches/use-matches.mjs +3 -2
- package/esm/core/MantineProvider/use-matches/use-matches.mjs.map +1 -1
- package/esm/index.mjs +5 -2
- package/lib/components/Accordion/Accordion.d.ts +2 -0
- package/lib/components/Cascader/Cascader.d.ts +114 -0
- package/lib/components/Cascader/CascaderColumns.d.ts +36 -0
- package/lib/components/Cascader/flatten-cascader-paths.d.ts +12 -0
- package/lib/components/Cascader/get-cascader-columns.d.ts +4 -0
- package/lib/components/Cascader/get-cascader-path-options.d.ts +2 -0
- package/lib/components/Cascader/index.d.ts +12 -0
- package/lib/components/Cascader/use-cascader.d.ts +25 -0
- package/lib/components/FloatingWindow/FloatingWindow.context.d.ts +21 -0
- package/lib/components/FloatingWindow/FloatingWindow.d.ts +10 -5
- package/lib/components/FloatingWindow/FloatingWindowResizeHandle.d.ts +11 -0
- package/lib/components/FloatingWindow/index.d.ts +2 -0
- package/lib/components/ScrollArea/ScrollArea.d.ts +5 -0
- package/lib/components/Timeline/TimelineItem/TimelineItem.d.ts +5 -1
- package/lib/components/index.d.ts +1 -0
- package/package.json +3 -3
- package/styles/Cascader.css +215 -0
- package/styles/Cascader.layer.css +216 -0
- package/styles/FloatingWindow.css +2 -0
- package/styles/FloatingWindow.layer.css +2 -0
- package/styles/ScrollArea.css +58 -0
- package/styles/ScrollArea.layer.css +58 -0
- package/styles/Timeline.css +88 -14
- package/styles/Timeline.layer.css +88 -14
- package/styles.css +364 -14
- package/styles.layer.css +364 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComboboxPopover.mjs","names":["comboboxClasses"],"sources":["../../../src/components/ComboboxPopover/ComboboxPopover.tsx"],"sourcesContent":["import { useMemo } from 'react';\nimport cx from 'clsx';\nimport { useUncontrolled } from '@mantine/hooks';\nimport {\n Factory,\n genericFactory,\n Primitive,\n StylesApiProps,\n useProps,\n useResolvedStylesApi,\n} from '../../core';\nimport { CheckIcon } from '../Checkbox';\nimport {\n Combobox,\n ComboboxData,\n ComboboxItem,\n ComboboxLikeRenderOptionInput,\n ComboboxLikeStylesNames,\n ComboboxProps,\n defaultOptionsFilter,\n getOptionsLockup,\n getParsedComboboxData,\n isOptionsGroup,\n OptionsDropdown,\n OptionsFilter,\n useCombobox,\n} from '../Combobox';\nimport { ComboboxParsedItem } from '../Combobox/Combobox.types';\nimport { isEmptyComboboxData } from '../Combobox/OptionsDropdown/is-empty-combobox-data';\nimport { ScrollArea, ScrollAreaProps } from '../ScrollArea';\nimport { ComboboxPopoverValue } from './ComboboxPopover.types';\nimport { ComboboxPopoverTarget } from './ComboboxPopoverTarget';\nimport comboboxClasses from '../Combobox/Combobox.module.css';\n\nfunction isValueChecked(value: Primitive | Primitive[] | undefined | null, optionValue: Primitive) {\n return Array.isArray(value) ? value.includes(optionValue) : value === optionValue;\n}\n\ninterface OptionProps {\n data: ComboboxParsedItem<Primitive>;\n withCheckIcon?: boolean;\n withAlignedLabels?: boolean;\n value?: Primitive | Primitive[] | null;\n checkIconPosition?: 'left' | 'right';\n unstyled: boolean | undefined;\n renderOption?: (input: ComboboxLikeRenderOptionInput<any>) => React.ReactNode;\n}\n\nfunction Option({\n data,\n withCheckIcon,\n withAlignedLabels,\n value,\n checkIconPosition,\n unstyled,\n renderOption,\n}: OptionProps) {\n if (isOptionsGroup(data)) {\n const options = data.items.map((item) => (\n <Option\n data={item}\n value={value}\n key={`${item.value}`}\n unstyled={unstyled}\n withCheckIcon={withCheckIcon}\n withAlignedLabels={withAlignedLabels}\n checkIconPosition={checkIconPosition}\n renderOption={renderOption}\n />\n ));\n return <Combobox.Group label={data.group}>{options}</Combobox.Group>;\n }\n\n const checked = isValueChecked(value, data.value);\n const check =\n withCheckIcon &&\n (checked ? (\n <CheckIcon className={comboboxClasses.optionsDropdownCheckIcon} />\n ) : withAlignedLabels ? (\n <div className={comboboxClasses.optionsDropdownCheckPlaceholder} />\n ) : null);\n\n const defaultContent = (\n <>\n {checkIconPosition === 'left' && check}\n <span>{data.label}</span>\n {checkIconPosition === 'right' && check}\n </>\n );\n\n return (\n <Combobox.Option\n value={data.value}\n disabled={data.disabled}\n className={cx({ [comboboxClasses.optionsDropdownOption]: !unstyled })}\n data-reverse={checkIconPosition === 'right' || undefined}\n data-checked={checked || undefined}\n aria-selected={checked}\n active={checked}\n >\n {typeof renderOption === 'function'\n ? renderOption({ option: data, checked })\n : defaultContent}\n </Combobox.Option>\n );\n}\n\ninterface SearchableDropdownProps {\n data: ComboboxParsedItem<Primitive>[];\n filter: OptionsFilter<Primitive> | undefined;\n search: string;\n limit: number | undefined;\n nothingFoundMessage: React.ReactNode | undefined;\n withScrollArea: boolean | undefined;\n maxDropdownHeight: number | string | undefined;\n value: Primitive | Primitive[] | null;\n checkIconPosition: 'left' | 'right' | undefined;\n withCheckIcon: boolean | undefined;\n withAlignedLabels: boolean | undefined;\n unstyled: boolean | undefined;\n renderOption?: (input: ComboboxLikeRenderOptionInput<any>) => React.ReactNode;\n scrollAreaProps: ScrollAreaProps | undefined;\n onSearchChange: (event: React.ChangeEvent<HTMLInputElement>) => void;\n}\n\nfunction SearchableDropdown({\n data,\n filter,\n search,\n limit,\n nothingFoundMessage,\n withScrollArea = true,\n maxDropdownHeight,\n value,\n checkIconPosition,\n withCheckIcon = false,\n withAlignedLabels = false,\n unstyled,\n renderOption,\n scrollAreaProps,\n onSearchChange,\n}: SearchableDropdownProps) {\n const filteredData = (filter || defaultOptionsFilter)({\n options: data,\n search,\n limit: limit ?? Infinity,\n });\n const isEmpty = isEmptyComboboxData(filteredData);\n\n const options = filteredData.map((item, index) => (\n <Option\n data={item}\n key={\n isOptionsGroup(item)\n ? `group-${typeof item.group === 'string' ? item.group : index}`\n : `${item.value}`\n }\n withCheckIcon={withCheckIcon}\n withAlignedLabels={withAlignedLabels}\n value={value}\n checkIconPosition={checkIconPosition}\n unstyled={unstyled}\n renderOption={renderOption}\n />\n ));\n\n return (\n <Combobox.Dropdown data-composed>\n <Combobox.Search value={search} onChange={onSearchChange} placeholder=\"Search...\" />\n <Combobox.Options>\n {withScrollArea ? (\n <ScrollArea.Autosize\n mah={maxDropdownHeight ?? 220}\n type=\"scroll\"\n scrollbarSize=\"var(--combobox-padding)\"\n offsetScrollbars=\"y\"\n {...scrollAreaProps}\n >\n {options}\n </ScrollArea.Autosize>\n ) : (\n options\n )}\n {isEmpty && nothingFoundMessage && <Combobox.Empty>{nothingFoundMessage}</Combobox.Empty>}\n </Combobox.Options>\n </Combobox.Dropdown>\n );\n}\n\nexport type ComboboxPopoverStylesNames = ComboboxLikeStylesNames;\n\nexport interface ComboboxPopoverProps<\n Multiple extends boolean = false,\n Value extends Primitive = string,\n> extends StylesApiProps<ComboboxPopoverFactory> {\n /** If set, multiple items can be selected at the same time */\n multiple?: Multiple;\n\n /** Controlled component value */\n value?: ComboboxPopoverValue<Multiple, Value>;\n\n /** Uncontrolled component default value */\n defaultValue?: ComboboxPopoverValue<Multiple, Value>;\n\n /** Called when value changes */\n onChange?: (value: ComboboxPopoverValue<Multiple, Value>) => void;\n\n /** Data used to generate options */\n data?: ComboboxData<Value>;\n\n /** Controlled dropdown opened state */\n dropdownOpened?: boolean;\n\n /** Uncontrolled dropdown initial opened state */\n defaultDropdownOpened?: boolean;\n\n /** Called when dropdown opens */\n onDropdownOpen?: () => void;\n\n /** Called when dropdown closes */\n onDropdownClose?: () => void;\n\n /** Called when option is submitted from dropdown with mouse click or Enter key */\n onOptionSubmit?: (value: Value) => void;\n\n /** Props passed down to Combobox component */\n comboboxProps?: ComboboxProps;\n\n /** Function based on which items are filtered and sorted */\n filter?: OptionsFilter<Value>;\n\n /** Maximum number of options displayed at a time @default Infinity */\n limit?: number;\n\n /** Determines whether the options should be wrapped with ScrollArea.AutoSize @default true */\n withScrollArea?: boolean;\n\n /** max-height of the dropdown @default 250 */\n maxDropdownHeight?: number | string;\n\n /** If set, the first option is selected when dropdown opens @default false */\n selectFirstOptionOnDropdownOpen?: boolean;\n\n /** Displays check icon near the selected option label @default true */\n withCheckIcon?: boolean;\n\n /** Aligns unchecked labels with the checked one @default false */\n withAlignedLabels?: boolean;\n\n /** Position of the check icon relative to the option label @default 'left' */\n checkIconPosition?: 'left' | 'right';\n\n /** Message displayed when no options match the search query or when there is no data */\n nothingFoundMessage?: React.ReactNode;\n\n /** Allows searching through options @default false */\n searchable?: boolean;\n\n /** Controlled search value */\n searchValue?: string;\n\n /** Default search value */\n defaultSearchValue?: string;\n\n /** Called when search changes */\n onSearchChange?: (value: string) => void;\n\n /** Allows deselecting the selected option by clicking it (only for single mode) @default true */\n allowDeselect?: boolean;\n\n /** A function to render content of the option, replaces the default content of the option */\n renderOption?: (item: ComboboxLikeRenderOptionInput<ComboboxItem>) => React.ReactNode;\n\n /** Props passed down to the underlying ScrollArea component in the dropdown */\n scrollAreaProps?: ScrollAreaProps;\n\n /** Props passed down to the hidden input */\n hiddenInputProps?: Omit<React.ComponentProps<'input'>, 'value'>;\n\n /** Hidden input name for form submission */\n name?: string;\n\n /** Hidden input form for form submission */\n form?: string;\n\n /** Content of the component */\n children?: React.ReactNode;\n\n /** Divider used to separate values in the hidden input value attribute @default ',' */\n hiddenInputValuesDivider?: string;\n}\n\nexport type ComboboxPopoverFactory = Factory<{\n props: ComboboxPopoverProps;\n ref: HTMLDivElement;\n stylesNames: ComboboxPopoverStylesNames;\n signature: <Multiple extends boolean = false, Value extends Primitive = string>(\n props: ComboboxPopoverProps<Multiple, Value>\n ) => React.JSX.Element;\n staticComponents: {\n Target: typeof ComboboxPopoverTarget;\n };\n}>;\n\nconst defaultProps = {\n withCheckIcon: true,\n allowDeselect: true,\n checkIconPosition: 'left',\n hiddenInputValuesDivider: ',',\n} satisfies Partial<ComboboxPopoverProps>;\n\nexport const ComboboxPopover = genericFactory<ComboboxPopoverFactory>((_props) => {\n const props = useProps('ComboboxPopover', defaultProps as any, _props);\n const {\n classNames,\n styles,\n unstyled,\n vars,\n children,\n multiple,\n value,\n defaultValue,\n onChange,\n data,\n dropdownOpened,\n defaultDropdownOpened,\n onDropdownOpen,\n onDropdownClose,\n onOptionSubmit,\n comboboxProps,\n filter,\n limit,\n withScrollArea,\n maxDropdownHeight,\n selectFirstOptionOnDropdownOpen,\n withCheckIcon,\n withAlignedLabels,\n checkIconPosition,\n nothingFoundMessage,\n searchable,\n searchValue,\n defaultSearchValue,\n onSearchChange,\n allowDeselect,\n renderOption,\n scrollAreaProps,\n hiddenInputProps,\n name,\n form,\n hiddenInputValuesDivider,\n attributes,\n ...others\n } = props;\n\n const parsedData = useMemo(() => getParsedComboboxData(data), [data]);\n const optionsLockup = useMemo(() => getOptionsLockup(parsedData), [parsedData]);\n\n const [_value, setValue] = useUncontrolled({\n value,\n defaultValue,\n finalValue: multiple ? ([] as any) : null,\n onChange,\n });\n\n const [_searchValue, setSearchValue] = useUncontrolled({\n value: searchValue,\n defaultValue: defaultSearchValue,\n finalValue: '',\n onChange: onSearchChange,\n });\n\n const combobox = useCombobox({\n opened: dropdownOpened,\n defaultOpened: defaultDropdownOpened,\n onDropdownOpen: () => {\n onDropdownOpen?.();\n if (searchable) {\n combobox.focusSearchInput();\n }\n if (selectFirstOptionOnDropdownOpen) {\n combobox.selectFirstOption();\n }\n },\n onDropdownClose: () => {\n onDropdownClose?.();\n combobox.resetSelectedOption();\n if (searchable) {\n combobox.focusTarget();\n }\n },\n });\n\n const handleSearchChange = (val: string) => {\n setSearchValue(val);\n combobox.resetSelectedOption();\n };\n\n const { resolvedClassNames, resolvedStyles } = useResolvedStylesApi<ComboboxPopoverFactory>({\n props,\n styles,\n classNames,\n });\n\n const handleOptionSubmit = (val: string) => {\n onOptionSubmit?.(val as any);\n const option = optionsLockup[val];\n\n if (multiple) {\n const currentValue = Array.isArray(_value) ? _value : [];\n if (currentValue.includes(option.value)) {\n setValue(currentValue.filter((v: any) => v !== option.value) as any);\n } else {\n setValue([...currentValue, option.value] as any);\n }\n combobox.updateSelectedOptionIndex('selected');\n } else {\n const nextValue = allowDeselect && `${option.value}` === `${_value}` ? null : option.value;\n setValue(nextValue as any);\n combobox.closeDropdown();\n }\n\n if (searchable) {\n handleSearchChange('');\n }\n };\n\n return (\n <>\n <Combobox\n store={combobox}\n __staticSelector=\"ComboboxPopover\"\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n unstyled={unstyled}\n attributes={attributes}\n onOptionSubmit={handleOptionSubmit}\n {...comboboxProps}\n {...others}\n >\n {children}\n {searchable ? (\n <SearchableDropdown\n data={parsedData as any}\n filter={filter as OptionsFilter<Primitive> | undefined}\n search={_searchValue}\n limit={limit}\n nothingFoundMessage={nothingFoundMessage}\n withScrollArea={withScrollArea}\n maxDropdownHeight={maxDropdownHeight}\n value={_value}\n checkIconPosition={checkIconPosition}\n withCheckIcon={withCheckIcon}\n withAlignedLabels={withAlignedLabels}\n unstyled={unstyled}\n renderOption={renderOption}\n scrollAreaProps={scrollAreaProps}\n onSearchChange={(event) => {\n handleSearchChange(event.currentTarget.value);\n }}\n />\n ) : (\n <OptionsDropdown\n data={parsedData as any}\n filter={filter as OptionsFilter<Primitive> | undefined}\n search={undefined}\n limit={limit}\n hiddenWhenEmpty={!nothingFoundMessage}\n withScrollArea={withScrollArea}\n maxDropdownHeight={maxDropdownHeight}\n filterOptions={false}\n value={_value}\n checkIconPosition={checkIconPosition}\n withCheckIcon={withCheckIcon}\n withAlignedLabels={withAlignedLabels}\n nothingFoundMessage={nothingFoundMessage}\n unstyled={unstyled}\n renderOption={renderOption}\n scrollAreaProps={scrollAreaProps}\n labelId={undefined}\n aria-label={undefined}\n />\n )}\n </Combobox>\n <Combobox.HiddenInput\n name={name}\n value={_value}\n form={form}\n valuesDivider={hiddenInputValuesDivider}\n {...hiddenInputProps}\n />\n </>\n );\n});\n\nComboboxPopover.classes = Combobox.classes;\nComboboxPopover.displayName = '@mantine/core/ComboboxPopover';\nComboboxPopover.Target = ComboboxPopoverTarget;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAkCA,SAAS,eAAe,OAAmD,aAAwB;CACjG,OAAO,MAAM,QAA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B,MAAM,cAAc,KAAK;GAC9C;EACD,CAAA,IAED,oBAAC,iBAAD;GACE,MAAM;GACE;GACR,QAAQ,KAAA;GACD;GACP,iBAAiB,CAAC;GACF;GACG;GACnB,eAAe;GACf,OAAO;GACY;GACJ;GACI;GACE;GACX;GACI;GACG;GACjB,SAAS,KAAA;GACT,cAAY,KAAA;EACb,CAAA,CAEK;KACV,oBAAC,SAAS,aAAV;EACQ;EACN,OAAO;EACD;EACN,eAAe;EACf,GAAI;CACL,CAAA,CACD,EAAA,CAAA;AAEN,CAAC;AAED,gBAAgB,UAAU,SAAS;AACnC,gBAAgB,cAAc;AAC9B,gBAAgB,SAAS"}
|
|
1
|
+
{"version":3,"file":"ComboboxPopover.mjs","names":["comboboxClasses"],"sources":["../../../src/components/ComboboxPopover/ComboboxPopover.tsx"],"sourcesContent":["import { useMemo } from 'react';\nimport cx from 'clsx';\nimport { useUncontrolled } from '@mantine/hooks';\nimport {\n Factory,\n genericFactory,\n Primitive,\n StylesApiProps,\n useProps,\n useResolvedStylesApi,\n} from '../../core';\nimport { CheckIcon } from '../Checkbox';\nimport {\n Combobox,\n ComboboxData,\n ComboboxItem,\n ComboboxLikeRenderOptionInput,\n ComboboxLikeStylesNames,\n ComboboxProps,\n defaultOptionsFilter,\n getOptionsLockup,\n getParsedComboboxData,\n isOptionsGroup,\n OptionsDropdown,\n OptionsFilter,\n useCombobox,\n} from '../Combobox';\nimport { ComboboxParsedItem } from '../Combobox/Combobox.types';\nimport { isEmptyComboboxData } from '../Combobox/OptionsDropdown/is-empty-combobox-data';\nimport { ScrollArea, ScrollAreaProps } from '../ScrollArea';\nimport { ComboboxPopoverValue } from './ComboboxPopover.types';\nimport { ComboboxPopoverTarget } from './ComboboxPopoverTarget';\nimport comboboxClasses from '../Combobox/Combobox.module.css';\n\nfunction isValueChecked(value: Primitive | Primitive[] | undefined | null, optionValue: Primitive) {\n return Array.isArray(value) ? value.includes(optionValue) : value === optionValue;\n}\n\ninterface OptionProps {\n data: ComboboxParsedItem<Primitive>;\n withCheckIcon?: boolean;\n withAlignedLabels?: boolean;\n value?: Primitive | Primitive[] | null;\n checkIconPosition?: 'left' | 'right';\n unstyled: boolean | undefined;\n renderOption?: (input: ComboboxLikeRenderOptionInput<any>) => React.ReactNode;\n}\n\nfunction Option({\n data,\n withCheckIcon,\n withAlignedLabels,\n value,\n checkIconPosition,\n unstyled,\n renderOption,\n}: OptionProps) {\n if (isOptionsGroup(data)) {\n const options = data.items.map((item) => (\n <Option\n data={item}\n value={value}\n key={`${item.value}`}\n unstyled={unstyled}\n withCheckIcon={withCheckIcon}\n withAlignedLabels={withAlignedLabels}\n checkIconPosition={checkIconPosition}\n renderOption={renderOption}\n />\n ));\n return <Combobox.Group label={data.group}>{options}</Combobox.Group>;\n }\n\n const checked = isValueChecked(value, data.value);\n const check =\n withCheckIcon &&\n (checked ? (\n <CheckIcon className={comboboxClasses.optionsDropdownCheckIcon} />\n ) : withAlignedLabels ? (\n <div className={comboboxClasses.optionsDropdownCheckPlaceholder} />\n ) : null);\n\n const defaultContent = (\n <>\n {checkIconPosition === 'left' && check}\n <span>{data.label}</span>\n {checkIconPosition === 'right' && check}\n </>\n );\n\n return (\n <Combobox.Option\n value={data.value}\n disabled={data.disabled}\n className={cx({ [comboboxClasses.optionsDropdownOption]: !unstyled })}\n data-reverse={checkIconPosition === 'right' || undefined}\n data-checked={checked || undefined}\n aria-selected={checked}\n active={checked}\n >\n {typeof renderOption === 'function'\n ? renderOption({ option: data, checked })\n : defaultContent}\n </Combobox.Option>\n );\n}\n\ninterface SearchableDropdownProps {\n data: ComboboxParsedItem<Primitive>[];\n filter: OptionsFilter<Primitive> | undefined;\n search: string;\n limit: number | undefined;\n nothingFoundMessage: React.ReactNode | undefined;\n withScrollArea: boolean | undefined;\n maxDropdownHeight: number | string | undefined;\n value: Primitive | Primitive[] | null;\n checkIconPosition: 'left' | 'right' | undefined;\n withCheckIcon: boolean | undefined;\n withAlignedLabels: boolean | undefined;\n unstyled: boolean | undefined;\n renderOption?: (input: ComboboxLikeRenderOptionInput<any>) => React.ReactNode;\n scrollAreaProps: ScrollAreaProps | undefined;\n onSearchChange: (event: React.ChangeEvent<HTMLInputElement>) => void;\n}\n\nfunction SearchableDropdown({\n data,\n filter,\n search,\n limit,\n nothingFoundMessage,\n withScrollArea = true,\n maxDropdownHeight,\n value,\n checkIconPosition,\n withCheckIcon = false,\n withAlignedLabels = false,\n unstyled,\n renderOption,\n scrollAreaProps,\n onSearchChange,\n}: SearchableDropdownProps) {\n const filteredData = (filter || defaultOptionsFilter)({\n options: data,\n search,\n limit: limit ?? Infinity,\n });\n const isEmpty = isEmptyComboboxData(filteredData);\n\n const options = filteredData.map((item, index) => (\n <Option\n data={item}\n key={\n isOptionsGroup(item)\n ? `group-${typeof item.group === 'string' ? item.group : index}`\n : `${item.value}`\n }\n withCheckIcon={withCheckIcon}\n withAlignedLabels={withAlignedLabels}\n value={value}\n checkIconPosition={checkIconPosition}\n unstyled={unstyled}\n renderOption={renderOption}\n />\n ));\n\n return (\n <Combobox.Dropdown data-composed>\n <Combobox.Search value={search} onChange={onSearchChange} placeholder=\"Search...\" />\n <Combobox.Options>\n {withScrollArea ? (\n <ScrollArea.Autosize\n mah={maxDropdownHeight ?? 220}\n type=\"scroll\"\n scrollbarSize=\"var(--combobox-padding)\"\n offsetScrollbars=\"y\"\n {...scrollAreaProps}\n >\n {options}\n </ScrollArea.Autosize>\n ) : (\n options\n )}\n {isEmpty && nothingFoundMessage && <Combobox.Empty>{nothingFoundMessage}</Combobox.Empty>}\n </Combobox.Options>\n </Combobox.Dropdown>\n );\n}\n\nexport type ComboboxPopoverStylesNames = ComboboxLikeStylesNames;\n\nexport interface ComboboxPopoverProps<\n Multiple extends boolean = false,\n Value extends Primitive = string,\n> extends StylesApiProps<ComboboxPopoverFactory> {\n /** If set, multiple items can be selected at the same time */\n multiple?: Multiple;\n\n /** Controlled component value */\n value?: ComboboxPopoverValue<Multiple, Value>;\n\n /** Uncontrolled component default value */\n defaultValue?: ComboboxPopoverValue<Multiple, Value>;\n\n /** Called when value changes */\n onChange?: (value: ComboboxPopoverValue<Multiple, Value>) => void;\n\n /** Data used to generate options */\n data?: ComboboxData<Value>;\n\n /** Controlled dropdown opened state */\n dropdownOpened?: boolean;\n\n /** Uncontrolled dropdown initial opened state */\n defaultDropdownOpened?: boolean;\n\n /** Called when dropdown opens */\n onDropdownOpen?: () => void;\n\n /** Called when dropdown closes */\n onDropdownClose?: () => void;\n\n /** Called when option is submitted from dropdown with mouse click or Enter key */\n onOptionSubmit?: (value: Value) => void;\n\n /** Props passed down to Combobox component */\n comboboxProps?: ComboboxProps;\n\n /** Function based on which items are filtered and sorted */\n filter?: OptionsFilter<Value>;\n\n /** Maximum number of options displayed at a time @default Infinity */\n limit?: number;\n\n /** Determines whether the options should be wrapped with ScrollArea.AutoSize @default true */\n withScrollArea?: boolean;\n\n /** max-height of the dropdown @default 250 */\n maxDropdownHeight?: number | string;\n\n /** If set, the first option is selected when dropdown opens @default false */\n selectFirstOptionOnDropdownOpen?: boolean;\n\n /** Displays check icon near the selected option label @default true */\n withCheckIcon?: boolean;\n\n /** Aligns unchecked labels with the checked one @default false */\n withAlignedLabels?: boolean;\n\n /** Position of the check icon relative to the option label @default 'left' */\n checkIconPosition?: 'left' | 'right';\n\n /** Message displayed when no options match the search query or when there is no data */\n nothingFoundMessage?: React.ReactNode;\n\n /** Allows searching through options @default false */\n searchable?: boolean;\n\n /** Controlled search value */\n searchValue?: string;\n\n /** Default search value */\n defaultSearchValue?: string;\n\n /** Called when search changes */\n onSearchChange?: (value: string) => void;\n\n /** Allows deselecting the selected option by clicking it (only for single mode) @default true */\n allowDeselect?: boolean;\n\n /** A function to render content of the option, replaces the default content of the option */\n renderOption?: (item: ComboboxLikeRenderOptionInput<ComboboxItem>) => React.ReactNode;\n\n /** Props passed down to the underlying ScrollArea component in the dropdown */\n scrollAreaProps?: ScrollAreaProps;\n\n /** Props passed down to the hidden input */\n hiddenInputProps?: Omit<React.ComponentProps<'input'>, 'value'>;\n\n /** Hidden input name for form submission */\n name?: string;\n\n /** Hidden input form for form submission */\n form?: string;\n\n /** Content of the component */\n children?: React.ReactNode;\n\n /** Divider used to separate values in the hidden input value attribute @default ',' */\n hiddenInputValuesDivider?: string;\n}\n\nexport type ComboboxPopoverFactory = Factory<{\n props: ComboboxPopoverProps;\n ref: HTMLDivElement;\n stylesNames: ComboboxPopoverStylesNames;\n signature: <Multiple extends boolean = false, Value extends Primitive = string>(\n props: ComboboxPopoverProps<Multiple, Value>\n ) => React.JSX.Element;\n staticComponents: {\n Target: typeof ComboboxPopoverTarget;\n };\n}>;\n\nconst defaultProps = {\n withCheckIcon: true,\n allowDeselect: true,\n checkIconPosition: 'left',\n hiddenInputValuesDivider: ',',\n} satisfies Partial<ComboboxPopoverProps>;\n\nexport const ComboboxPopover = genericFactory<ComboboxPopoverFactory>((_props) => {\n const props = useProps('ComboboxPopover', defaultProps as any, _props);\n const {\n classNames,\n styles,\n unstyled,\n vars,\n children,\n multiple,\n value,\n defaultValue,\n onChange,\n data,\n dropdownOpened,\n defaultDropdownOpened,\n onDropdownOpen,\n onDropdownClose,\n onOptionSubmit,\n comboboxProps,\n filter,\n limit,\n withScrollArea,\n maxDropdownHeight,\n selectFirstOptionOnDropdownOpen,\n withCheckIcon,\n withAlignedLabels,\n checkIconPosition,\n nothingFoundMessage,\n searchable,\n searchValue,\n defaultSearchValue,\n onSearchChange,\n allowDeselect,\n renderOption,\n scrollAreaProps,\n hiddenInputProps,\n name,\n form,\n hiddenInputValuesDivider,\n attributes,\n ...others\n } = props;\n\n const parsedData = useMemo(() => getParsedComboboxData(data), [data]);\n const optionsLockup = useMemo(() => getOptionsLockup(parsedData), [parsedData]);\n\n const [_value, setValue] = useUncontrolled({\n value,\n defaultValue,\n finalValue: multiple ? ([] as any) : null,\n onChange,\n });\n\n const [_searchValue, setSearchValue] = useUncontrolled({\n value: searchValue,\n defaultValue: defaultSearchValue,\n finalValue: '',\n onChange: onSearchChange,\n });\n\n const combobox = useCombobox({\n opened: dropdownOpened,\n defaultOpened: defaultDropdownOpened,\n onDropdownOpen: () => {\n onDropdownOpen?.();\n if (searchable) {\n combobox.focusSearchInput();\n }\n if (selectFirstOptionOnDropdownOpen) {\n combobox.selectFirstOption();\n }\n },\n onDropdownClose: () => {\n onDropdownClose?.();\n combobox.resetSelectedOption();\n if (searchable) {\n combobox.focusTarget();\n }\n },\n });\n\n const handleSearchChange = (val: string) => {\n setSearchValue(val);\n combobox.resetSelectedOption();\n };\n\n const { resolvedClassNames, resolvedStyles } = useResolvedStylesApi<ComboboxPopoverFactory>({\n props,\n styles,\n classNames,\n });\n\n const handleOptionSubmit = (val: string) => {\n onOptionSubmit?.(val as any);\n const option = optionsLockup[val];\n\n if (multiple) {\n const currentValue = Array.isArray(_value) ? _value : [];\n if (currentValue.includes(option.value)) {\n setValue(currentValue.filter((v: any) => v !== option.value) as any);\n } else {\n setValue([...currentValue, option.value] as any);\n }\n combobox.updateSelectedOptionIndex('selected');\n } else {\n const nextValue = allowDeselect && `${option.value}` === `${_value}` ? null : option.value;\n setValue(nextValue as any);\n combobox.closeDropdown();\n }\n\n if (searchable) {\n handleSearchChange('');\n }\n };\n\n return (\n <>\n <Combobox\n store={combobox}\n __staticSelector=\"ComboboxPopover\"\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n unstyled={unstyled}\n attributes={attributes}\n onOptionSubmit={handleOptionSubmit}\n {...comboboxProps}\n {...others}\n >\n {children}\n {searchable ? (\n <SearchableDropdown\n data={parsedData as any}\n filter={filter as OptionsFilter<Primitive> | undefined}\n search={_searchValue}\n limit={limit}\n nothingFoundMessage={nothingFoundMessage}\n withScrollArea={withScrollArea}\n maxDropdownHeight={maxDropdownHeight}\n value={_value}\n checkIconPosition={checkIconPosition}\n withCheckIcon={withCheckIcon}\n withAlignedLabels={withAlignedLabels}\n unstyled={unstyled}\n renderOption={renderOption}\n scrollAreaProps={scrollAreaProps}\n onSearchChange={(event) => {\n handleSearchChange(event.currentTarget.value);\n }}\n />\n ) : (\n <OptionsDropdown\n data={parsedData as any}\n filter={filter as OptionsFilter<Primitive> | undefined}\n search={undefined}\n limit={limit}\n hiddenWhenEmpty={!nothingFoundMessage}\n withScrollArea={withScrollArea}\n maxDropdownHeight={maxDropdownHeight}\n filterOptions={false}\n value={_value}\n checkIconPosition={checkIconPosition}\n withCheckIcon={withCheckIcon}\n withAlignedLabels={withAlignedLabels}\n nothingFoundMessage={nothingFoundMessage}\n unstyled={unstyled}\n renderOption={renderOption}\n scrollAreaProps={scrollAreaProps}\n labelId={undefined}\n aria-label={undefined}\n />\n )}\n </Combobox>\n <Combobox.HiddenInput\n name={name}\n value={_value}\n form={form}\n valuesDivider={hiddenInputValuesDivider}\n {...hiddenInputProps}\n />\n </>\n );\n});\n\nComboboxPopover.classes = Combobox.classes;\nComboboxPopover.displayName = '@mantine/core/ComboboxPopover';\nComboboxPopover.Target = ComboboxPopoverTarget;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAkCA,SAAS,eAAe,OAAmD,aAAwB;CACjG,OAAO,MAAM,QAAQ,KAAK,IAAI,MAAM,SAAS,WAAW,IAAI,UAAU;AACxE;AAYA,SAAS,OAAO,EACd,MACA,eACA,mBACA,OACA,mBACA,UACA,gBACc;CACd,IAAI,eAAe,IAAI,GAAG;EACxB,MAAM,UAAU,KAAK,MAAM,KAAK,SAC9B,oBAAC,QAAD;GACE,MAAM;GACC;GAEG;GACK;GACI;GACA;GACL;EACf,GANM,GAAG,KAAK,OAMd,CACF;EACD,OAAO,oBAAC,SAAS,OAAV;GAAgB,OAAO,KAAK;aAAQ;EAAwB,CAAA;CACrE;CAEA,MAAM,UAAU,eAAe,OAAO,KAAK,KAAK;CAChD,MAAM,QACJ,kBACC,UACC,oBAAC,WAAD,EAAW,WAAWA,wBAAgB,yBAA2B,CAAA,IAC/D,oBACF,oBAAC,OAAD,EAAK,WAAWA,wBAAgB,gCAAkC,CAAA,IAChE;CAEN,MAAM,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AAU;GACZ,MAAM,eAAe,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC;GACvD,IAAI,aAAa,SAAS,OAAO,KAAK,GACpC,SAAS,aAAa,QAAQ,MAAW,MAAM,OAAO,KAAK,CAAQ;QAEnE,SAAS,CAAC,GAAG,cAAc,OAAO,KAAK,CAAQ;GAEjD,SAAS,0BAA0B,UAAU;EAC/C,OAAO;GACL,MAAM,YAAY,iBAAiB,GAAG,OAAO,YAAY,GAAG,WAAW,OAAO,OAAO;GACrF,SAAS,SAAgB;GACzB,SAAS,cAAc;EACzB;EAEA,IAAI,YACF,mBAAmB,EAAE;CAEzB;CAEA,OACE,qBAAA,YAAA,EAAA,UAAA,CACE,qBAAC,UAAD;EACE,OAAO;EACP,kBAAiB;EACjB,YAAY;EACZ,QAAQ;EACE;EACE;EACZ,gBAAgB;EAChB,GAAI;EACJ,GAAI;YATN,CAWG,UACA,aACC,oBAAC,oBAAD;GACE,MAAM;GACE;GACR,QAAQ;GACD;GACc;GACL;GACG;GACnB,OAAO;GACY;GACJ;GACI;GACT;GACI;GACG;GACjB,iBAAiB,UAAU;IACzB,mBAAmB,MAAM,cAAc,KAAK;GAC9C;EACD,CAAA,IAED,oBAAC,iBAAD;GACE,MAAM;GACE;GACR,QAAQ,KAAA;GACD;GACP,iBAAiB,CAAC;GACF;GACG;GACnB,eAAe;GACf,OAAO;GACY;GACJ;GACI;GACE;GACX;GACI;GACG;GACjB,SAAS,KAAA;GACT,cAAY,KAAA;EACb,CAAA,CAEK;KACV,oBAAC,SAAS,aAAV;EACQ;EACN,OAAO;EACD;EACN,eAAe;EACf,GAAI;CACL,CAAA,CACD,EAAA,CAAA;AAEN,CAAC;AAED,gBAAgB,UAAU,SAAS;AACnC,gBAAgB,cAAc;AAC9B,gBAAgB,SAAS"}
|
|
@@ -11,7 +11,7 @@ function DrawerStack({ children }) {
|
|
|
11
11
|
value: {
|
|
12
12
|
stack,
|
|
13
13
|
addModal: (id, zIndex) => {
|
|
14
|
-
setStack((current) => [
|
|
14
|
+
setStack((current) => [.../* @__PURE__ */ new Set([...current, id])]);
|
|
15
15
|
setMaxZIndex((current) => typeof zIndex === "number" && typeof current === "number" ? Math.max(current, zIndex) : current);
|
|
16
16
|
},
|
|
17
17
|
removeModal: (id) => setStack((current) => current.filter((currentId) => currentId !== id)),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DrawerStack.mjs","names":[],"sources":["../../../src/components/Drawer/DrawerStack.tsx"],"sourcesContent":["import { createContext, useState } from 'react';\nimport { getDefaultZIndex } from '../../core';\n\ninterface DrawerStackContext {\n stack: string[];\n addModal: (id: string, zIndex: number | string) => void;\n removeModal: (id: string) => void;\n getZIndex: (id: string) => string;\n currentId: string;\n maxZIndex: string | number;\n}\n\nexport const DrawerStackContext = createContext<DrawerStackContext | null>(null);\n\nexport interface DrawerStackProps {\n children: React.ReactNode;\n}\n\nexport function DrawerStack({ children }: DrawerStackProps) {\n const [stack, setStack] = useState<string[]>([]);\n const [maxZIndex, setMaxZIndex] = useState<number | string>(getDefaultZIndex('modal'));\n\n return (\n <DrawerStackContext\n value={{\n stack,\n addModal: (id, zIndex) => {\n setStack((current) => [...new Set([...current, id])]);\n setMaxZIndex((current) =>\n typeof zIndex === 'number' && typeof current === 'number'\n ? Math.max(current, zIndex)\n : current\n );\n },\n removeModal: (id) => setStack((current) => current.filter((currentId) => currentId !== id)),\n getZIndex: (id) => `calc(${maxZIndex} + ${stack.indexOf(id)} + 1)`,\n currentId: stack[stack.length - 1],\n maxZIndex,\n }}\n >\n {children}\n </DrawerStackContext>\n );\n}\n\nDrawerStack.displayName = '@mantine/core/DrawerStack';\n"],"mappings":";;;;;AAYA,MAAa,qBAAqB,cAAyC,IAAI;AAM/E,SAAgB,YAAY,EAAE,YAA8B;CAC1D,MAAM,CAAC,OAAO,YAAY,SAAmB,CAAC,CAAC;CAC/C,MAAM,CAAC,WAAW,gBAAgB,SAA0B,iBAAiB,OAAO,CAAC;CAErF,OACE,oBAAC,oBAAD;EACE,OAAO;GACL;GACA,WAAW,IAAI,WAAW;IACxB,UAAU,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"DrawerStack.mjs","names":[],"sources":["../../../src/components/Drawer/DrawerStack.tsx"],"sourcesContent":["import { createContext, useState } from 'react';\nimport { getDefaultZIndex } from '../../core';\n\ninterface DrawerStackContext {\n stack: string[];\n addModal: (id: string, zIndex: number | string) => void;\n removeModal: (id: string) => void;\n getZIndex: (id: string) => string;\n currentId: string;\n maxZIndex: string | number;\n}\n\nexport const DrawerStackContext = createContext<DrawerStackContext | null>(null);\n\nexport interface DrawerStackProps {\n children: React.ReactNode;\n}\n\nexport function DrawerStack({ children }: DrawerStackProps) {\n const [stack, setStack] = useState<string[]>([]);\n const [maxZIndex, setMaxZIndex] = useState<number | string>(getDefaultZIndex('modal'));\n\n return (\n <DrawerStackContext\n value={{\n stack,\n addModal: (id, zIndex) => {\n setStack((current) => [...new Set([...current, id])]);\n setMaxZIndex((current) =>\n typeof zIndex === 'number' && typeof current === 'number'\n ? Math.max(current, zIndex)\n : current\n );\n },\n removeModal: (id) => setStack((current) => current.filter((currentId) => currentId !== id)),\n getZIndex: (id) => `calc(${maxZIndex} + ${stack.indexOf(id)} + 1)`,\n currentId: stack[stack.length - 1],\n maxZIndex,\n }}\n >\n {children}\n </DrawerStackContext>\n );\n}\n\nDrawerStack.displayName = '@mantine/core/DrawerStack';\n"],"mappings":";;;;;AAYA,MAAa,qBAAqB,cAAyC,IAAI;AAM/E,SAAgB,YAAY,EAAE,YAA8B;CAC1D,MAAM,CAAC,OAAO,YAAY,SAAmB,CAAC,CAAC;CAC/C,MAAM,CAAC,WAAW,gBAAgB,SAA0B,iBAAiB,OAAO,CAAC;CAErF,OACE,oBAAC,oBAAD;EACE,OAAO;GACL;GACA,WAAW,IAAI,WAAW;IACxB,UAAU,YAAY,CAAC,mBAAG,IAAI,IAAI,CAAC,GAAG,SAAS,EAAE,CAAC,CAAC,CAAC;IACpD,cAAc,YACZ,OAAO,WAAW,YAAY,OAAO,YAAY,WAC7C,KAAK,IAAI,SAAS,MAAM,IACxB,OACN;GACF;GACA,cAAc,OAAO,UAAU,YAAY,QAAQ,QAAQ,cAAc,cAAc,EAAE,CAAC;GAC1F,YAAY,OAAO,QAAQ,UAAU,KAAK,MAAM,QAAQ,EAAE,EAAE;GAC5D,WAAW,MAAM,MAAM,SAAS;GAChC;EACF;EAEC;CACiB,CAAA;AAExB;AAEA,YAAY,cAAc"}
|
|
@@ -16,6 +16,7 @@ const varsResolver = createVarsResolver((theme, { transitionDuration }, { should
|
|
|
16
16
|
const FloatingIndicator = factory((_props) => {
|
|
17
17
|
const props = useProps("FloatingIndicator", null, _props);
|
|
18
18
|
const { classNames, className, style, styles, unstyled, vars, target, parent, transitionDuration, mod, displayAfterTransitionEnd, onTransitionStart, onTransitionEnd, attributes, ref, ...others } = props;
|
|
19
|
+
const shouldReduceMotion = useReducedMotion();
|
|
19
20
|
const getStyles = useStyles({
|
|
20
21
|
name: "FloatingIndicator",
|
|
21
22
|
classes: FloatingIndicator_module_default,
|
|
@@ -28,7 +29,7 @@ const FloatingIndicator = factory((_props) => {
|
|
|
28
29
|
attributes,
|
|
29
30
|
vars,
|
|
30
31
|
varsResolver,
|
|
31
|
-
stylesCtx: { shouldReduceMotion
|
|
32
|
+
stylesCtx: { shouldReduceMotion }
|
|
32
33
|
});
|
|
33
34
|
const innerRef = useRef(null);
|
|
34
35
|
const { initialized, hidden } = useFloatingIndicator({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FloatingIndicator.mjs","names":["classes"],"sources":["../../../src/components/FloatingIndicator/FloatingIndicator.tsx"],"sourcesContent":["import { useRef } from 'react';\nimport { useMergedRef, useReducedMotion } from '@mantine/hooks';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n factory,\n Factory,\n StylesApiProps,\n useProps,\n useStyles,\n} from '../../core';\nimport { useFloatingIndicator } from './use-floating-indicator';\nimport classes from './FloatingIndicator.module.css';\n\nexport type FloatingIndicatorStylesNames = 'root';\nexport type FloatingIndicatorCssVariables = {\n root: '--transition-duration';\n};\n\nexport interface FloatingIndicatorProps\n extends BoxProps, StylesApiProps<FloatingIndicatorFactory>, ElementProps<'div'> {\n /** Target element over which the indicator is displayed.\n * The indicator will be positioned to match the target's size and position.\n * */\n target: HTMLElement | null | undefined;\n\n /** Parent container element that must have `position: relative`.\n * The indicator's position is calculated relative to this element.\n * */\n parent: HTMLElement | null | undefined;\n\n /** Transition duration in ms @default 150 */\n transitionDuration?: number | string;\n\n /** Controls whether the indicator should be hidden initially and displayed after the parent's transition ends.\n * Set to `true` when the parent container has CSS transitions (e.g., `transform: scale()`) to prevent\n * the indicator from appearing at the wrong position during the parent's animation.\n * @default false\n * */\n displayAfterTransitionEnd?: boolean;\n\n /** Called when the indicator starts transitioning to a new position */\n onTransitionStart?: () => void;\n\n /** Called when the indicator finishes transitioning to a new position */\n onTransitionEnd?: () => void;\n}\n\nexport type FloatingIndicatorFactory = Factory<{\n props: FloatingIndicatorProps;\n ref: HTMLDivElement;\n stylesNames: FloatingIndicatorStylesNames;\n vars: FloatingIndicatorCssVariables;\n ctx: { shouldReduceMotion: boolean };\n}>;\n\nconst varsResolver = createVarsResolver<FloatingIndicatorFactory>(\n (theme, { transitionDuration }, { shouldReduceMotion }) => {\n const reduceMotion = theme.respectReducedMotion ? shouldReduceMotion : false;\n const duration = reduceMotion\n ? '0ms'\n : typeof transitionDuration === 'number'\n ? `${transitionDuration}ms`\n : transitionDuration || '150ms';\n\n return {\n root: {\n '--transition-duration': duration,\n },\n };\n }\n);\n\nexport const FloatingIndicator = factory<FloatingIndicatorFactory>((_props) => {\n const props = useProps('FloatingIndicator', null, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n target,\n parent,\n transitionDuration,\n mod,\n displayAfterTransitionEnd,\n onTransitionStart,\n onTransitionEnd,\n attributes,\n ref,\n ...others\n } = props;\n\n const shouldReduceMotion = useReducedMotion();\n\n const getStyles = useStyles<FloatingIndicatorFactory>({\n name: 'FloatingIndicator',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n stylesCtx: { shouldReduceMotion },\n });\n\n const innerRef = useRef<HTMLDivElement>(null);\n const { initialized, hidden } = useFloatingIndicator({\n target,\n parent,\n ref: innerRef,\n displayAfterTransitionEnd,\n onTransitionStart,\n onTransitionEnd,\n });\n\n const mergedRef = useMergedRef(ref, innerRef);\n\n if (!target || !parent) {\n return null;\n }\n\n return (\n <Box ref={mergedRef} mod={[{ initialized, hidden }, mod]} {...getStyles('root')} {...others} />\n );\n});\n\nFloatingIndicator.displayName = '@mantine/core/FloatingIndicator';\nFloatingIndicator.classes = classes;\nFloatingIndicator.varsResolver = varsResolver;\n\nexport namespace FloatingIndicator {\n export type Props = FloatingIndicatorProps;\n export type StylesNames = FloatingIndicatorStylesNames;\n export type CssVariables = FloatingIndicatorCssVariables;\n export type Factory = FloatingIndicatorFactory;\n}\n"],"mappings":";;;;;;;;;;;;AA0DA,MAAM,eAAe,oBAClB,OAAO,EAAE,sBAAsB,EAAE,yBAAyB;CAQzD,OAAO,EACL,MAAM,EACJ,0BATiB,MAAM,uBAAuB,qBAAqB,SAEnE,QACA,OAAO,uBAAuB,WAC5B,GAAG,mBAAmB,MACtB,sBAAsB,QAK1B,EACF;AACF,CACF;AAEA,MAAa,oBAAoB,SAAmC,WAAW;CAC7E,MAAM,QAAQ,SAAS,qBAAqB,MAAM,MAAM;CACxD,MAAM,EACJ,YACA,WACA,OACA,QACA,UACA,MACA,QACA,QACA,oBACA,KACA,2BACA,mBACA,iBACA,YACA,KACA,GAAG,WACD;
|
|
1
|
+
{"version":3,"file":"FloatingIndicator.mjs","names":["classes"],"sources":["../../../src/components/FloatingIndicator/FloatingIndicator.tsx"],"sourcesContent":["import { useRef } from 'react';\nimport { useMergedRef, useReducedMotion } from '@mantine/hooks';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n factory,\n Factory,\n StylesApiProps,\n useProps,\n useStyles,\n} from '../../core';\nimport { useFloatingIndicator } from './use-floating-indicator';\nimport classes from './FloatingIndicator.module.css';\n\nexport type FloatingIndicatorStylesNames = 'root';\nexport type FloatingIndicatorCssVariables = {\n root: '--transition-duration';\n};\n\nexport interface FloatingIndicatorProps\n extends BoxProps, StylesApiProps<FloatingIndicatorFactory>, ElementProps<'div'> {\n /** Target element over which the indicator is displayed.\n * The indicator will be positioned to match the target's size and position.\n * */\n target: HTMLElement | null | undefined;\n\n /** Parent container element that must have `position: relative`.\n * The indicator's position is calculated relative to this element.\n * */\n parent: HTMLElement | null | undefined;\n\n /** Transition duration in ms @default 150 */\n transitionDuration?: number | string;\n\n /** Controls whether the indicator should be hidden initially and displayed after the parent's transition ends.\n * Set to `true` when the parent container has CSS transitions (e.g., `transform: scale()`) to prevent\n * the indicator from appearing at the wrong position during the parent's animation.\n * @default false\n * */\n displayAfterTransitionEnd?: boolean;\n\n /** Called when the indicator starts transitioning to a new position */\n onTransitionStart?: () => void;\n\n /** Called when the indicator finishes transitioning to a new position */\n onTransitionEnd?: () => void;\n}\n\nexport type FloatingIndicatorFactory = Factory<{\n props: FloatingIndicatorProps;\n ref: HTMLDivElement;\n stylesNames: FloatingIndicatorStylesNames;\n vars: FloatingIndicatorCssVariables;\n ctx: { shouldReduceMotion: boolean };\n}>;\n\nconst varsResolver = createVarsResolver<FloatingIndicatorFactory>(\n (theme, { transitionDuration }, { shouldReduceMotion }) => {\n const reduceMotion = theme.respectReducedMotion ? shouldReduceMotion : false;\n const duration = reduceMotion\n ? '0ms'\n : typeof transitionDuration === 'number'\n ? `${transitionDuration}ms`\n : transitionDuration || '150ms';\n\n return {\n root: {\n '--transition-duration': duration,\n },\n };\n }\n);\n\nexport const FloatingIndicator = factory<FloatingIndicatorFactory>((_props) => {\n const props = useProps('FloatingIndicator', null, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n target,\n parent,\n transitionDuration,\n mod,\n displayAfterTransitionEnd,\n onTransitionStart,\n onTransitionEnd,\n attributes,\n ref,\n ...others\n } = props;\n\n const shouldReduceMotion = useReducedMotion();\n\n const getStyles = useStyles<FloatingIndicatorFactory>({\n name: 'FloatingIndicator',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n stylesCtx: { shouldReduceMotion },\n });\n\n const innerRef = useRef<HTMLDivElement>(null);\n const { initialized, hidden } = useFloatingIndicator({\n target,\n parent,\n ref: innerRef,\n displayAfterTransitionEnd,\n onTransitionStart,\n onTransitionEnd,\n });\n\n const mergedRef = useMergedRef(ref, innerRef);\n\n if (!target || !parent) {\n return null;\n }\n\n return (\n <Box ref={mergedRef} mod={[{ initialized, hidden }, mod]} {...getStyles('root')} {...others} />\n );\n});\n\nFloatingIndicator.displayName = '@mantine/core/FloatingIndicator';\nFloatingIndicator.classes = classes;\nFloatingIndicator.varsResolver = varsResolver;\n\nexport namespace FloatingIndicator {\n export type Props = FloatingIndicatorProps;\n export type StylesNames = FloatingIndicatorStylesNames;\n export type CssVariables = FloatingIndicatorCssVariables;\n export type Factory = FloatingIndicatorFactory;\n}\n"],"mappings":";;;;;;;;;;;;AA0DA,MAAM,eAAe,oBAClB,OAAO,EAAE,sBAAsB,EAAE,yBAAyB;CAQzD,OAAO,EACL,MAAM,EACJ,0BATiB,MAAM,uBAAuB,qBAAqB,SAEnE,QACA,OAAO,uBAAuB,WAC5B,GAAG,mBAAmB,MACtB,sBAAsB,QAK1B,EACF;AACF,CACF;AAEA,MAAa,oBAAoB,SAAmC,WAAW;CAC7E,MAAM,QAAQ,SAAS,qBAAqB,MAAM,MAAM;CACxD,MAAM,EACJ,YACA,WACA,OACA,QACA,UACA,MACA,QACA,QACA,oBACA,KACA,2BACA,mBACA,iBACA,YACA,KACA,GAAG,WACD;CAEJ,MAAM,qBAAqB,iBAAiB;CAE5C,MAAM,YAAY,UAAoC;EACpD,MAAM;EACN,SAAA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,WAAW,EAAE,mBAAmB;CAClC,CAAC;CAED,MAAM,WAAW,OAAuB,IAAI;CAC5C,MAAM,EAAE,aAAa,WAAW,qBAAqB;EACnD;EACA;EACA,KAAK;EACL;EACA;EACA;CACF,CAAC;CAED,MAAM,YAAY,aAAa,KAAK,QAAQ;CAE5C,IAAI,CAAC,UAAU,CAAC,QACd,OAAO;CAGT,OACE,oBAAC,KAAD;EAAK,KAAK;EAAW,KAAK,CAAC;GAAE;GAAa;EAAO,GAAG,GAAG;EAAG,GAAI,UAAU,MAAM;EAAG,GAAI;CAAS,CAAA;AAElG,CAAC;AAED,kBAAkB,cAAc;AAChC,kBAAkB,UAAUA;AAC5B,kBAAkB,eAAe"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createSafeContext } from "../../core/utils/create-safe-context/create-safe-context.mjs";
|
|
3
|
+
//#region packages/@mantine/core/src/components/FloatingWindow/FloatingWindow.context.ts
|
|
4
|
+
const [FloatingWindowProvider, useFloatingWindowContext] = createSafeContext("FloatingWindow.ResizeHandle must be used within FloatingWindow");
|
|
5
|
+
//#endregion
|
|
6
|
+
export { FloatingWindowProvider, useFloatingWindowContext };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=FloatingWindow.context.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FloatingWindow.context.mjs","names":[],"sources":["../../../src/components/FloatingWindow/FloatingWindow.context.ts"],"sourcesContent":["import { createSafeContext } from '../../core';\n\nexport interface FloatingWindowDimensions {\n /** Initial width of the floating window in px */\n initialWidth?: number;\n\n /** Minimum width of the floating window in px */\n minWidth?: number;\n\n /** Maximum width of the floating window in px */\n maxWidth?: number;\n\n /** Initial height of the floating window in px */\n initialHeight?: number;\n\n /** Minimum height of the floating window in px */\n minHeight?: number;\n\n /** Maximum height of the floating window in px */\n maxHeight?: number;\n}\n\nexport interface FloatingWindowContextValue {\n rootRef: React.RefObject<HTMLDivElement | null>;\n dimensions: FloatingWindowDimensions | undefined;\n constrainToViewport: boolean | undefined;\n constrainOffset: number | undefined;\n}\n\nexport const [FloatingWindowProvider, useFloatingWindowContext] =\n createSafeContext<FloatingWindowContextValue>(\n 'FloatingWindow.ResizeHandle must be used within FloatingWindow'\n );\n"],"mappings":";;;AA6BA,MAAa,CAAC,wBAAwB,4BACpC,kBACE,gEACF"}
|
|
@@ -5,8 +5,10 @@ import { useStyles } from "../../core/styles-api/use-styles/use-styles.mjs";
|
|
|
5
5
|
import { factory } from "../../core/factory/factory.mjs";
|
|
6
6
|
import { Paper } from "../Paper/Paper.mjs";
|
|
7
7
|
import { OptionalPortal } from "../Portal/OptionalPortal.mjs";
|
|
8
|
+
import { FloatingWindowProvider } from "./FloatingWindow.context.mjs";
|
|
9
|
+
import { FloatingWindowResizeHandle } from "./FloatingWindowResizeHandle.mjs";
|
|
8
10
|
import FloatingWindow_module_default from "./FloatingWindow.module.mjs";
|
|
9
|
-
import { useImperativeHandle } from "react";
|
|
11
|
+
import { useImperativeHandle, useRef } from "react";
|
|
10
12
|
import { useFloatingWindow, useMergedRef } from "@mantine/hooks";
|
|
11
13
|
import { jsx } from "react/jsx-runtime";
|
|
12
14
|
//#region packages/@mantine/core/src/components/FloatingWindow/FloatingWindow.tsx
|
|
@@ -14,9 +16,16 @@ const defaultProps = {
|
|
|
14
16
|
constrainToViewport: true,
|
|
15
17
|
zIndex: getDefaultZIndex("overlay")
|
|
16
18
|
};
|
|
19
|
+
function clampDimension(value, min, max) {
|
|
20
|
+
let v = value;
|
|
21
|
+
if (min != null) v = Math.max(v, min);
|
|
22
|
+
if (max != null) v = Math.min(v, max);
|
|
23
|
+
return v;
|
|
24
|
+
}
|
|
17
25
|
const FloatingWindow = factory((_props) => {
|
|
18
26
|
const props = useProps("FloatingWindow", defaultProps, _props);
|
|
19
|
-
const { classNames, className, style, styles, unstyled, vars, mod, enabled, constrainToViewport, constrainOffset, dragHandleSelector, excludeDragHandleSelector, axis, initialPosition, onPositionChange, onDragStart, onDragEnd, setPositionRef, withinPortal, portalProps, zIndex, ref, ...others } = props;
|
|
27
|
+
const { classNames, className, style, styles, unstyled, vars, mod, enabled, constrainToViewport, constrainOffset, dragHandleSelector, excludeDragHandleSelector, axis, initialPosition, onPositionChange, onDragStart, onDragEnd, setPositionRef, withinPortal, portalProps, zIndex, dimensions, ref, ...others } = props;
|
|
28
|
+
const rootRef = useRef(null);
|
|
20
29
|
const getStyles = useStyles({
|
|
21
30
|
name: "FloatingWindow",
|
|
22
31
|
classes: FloatingWindow_module_default,
|
|
@@ -41,20 +50,32 @@ const FloatingWindow = factory((_props) => {
|
|
|
41
50
|
onDragEnd
|
|
42
51
|
});
|
|
43
52
|
useImperativeHandle(setPositionRef, () => floatingWindow.setPosition, [floatingWindow.setPosition]);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
const cssVars = { "--floating-window-z-index": zIndex.toString() };
|
|
54
|
+
if (dimensions?.initialWidth != null) cssVars["--floating-window-width"] = `${clampDimension(dimensions.initialWidth, dimensions.minWidth, dimensions.maxWidth)}px`;
|
|
55
|
+
if (dimensions?.initialHeight != null) cssVars["--floating-window-height"] = `${clampDimension(dimensions.initialHeight, dimensions.minHeight, dimensions.maxHeight)}px`;
|
|
56
|
+
return /* @__PURE__ */ jsx(FloatingWindowProvider, {
|
|
57
|
+
value: {
|
|
58
|
+
rootRef,
|
|
59
|
+
dimensions,
|
|
60
|
+
constrainToViewport,
|
|
61
|
+
constrainOffset
|
|
62
|
+
},
|
|
63
|
+
children: /* @__PURE__ */ jsx(OptionalPortal, {
|
|
64
|
+
withinPortal,
|
|
65
|
+
...portalProps,
|
|
66
|
+
children: /* @__PURE__ */ jsx(Paper, {
|
|
67
|
+
ref: useMergedRef(ref, floatingWindow.ref, rootRef),
|
|
68
|
+
mod: [{ dragging: floatingWindow.isDragging }, mod],
|
|
69
|
+
...getStyles("root"),
|
|
70
|
+
...others,
|
|
71
|
+
__vars: cssVars
|
|
72
|
+
})
|
|
53
73
|
})
|
|
54
74
|
});
|
|
55
75
|
});
|
|
56
76
|
FloatingWindow.displayName = "@mantine/core/FloatingWindow";
|
|
57
77
|
FloatingWindow.classes = FloatingWindow_module_default;
|
|
78
|
+
FloatingWindow.ResizeHandle = FloatingWindowResizeHandle;
|
|
58
79
|
//#endregion
|
|
59
80
|
export { FloatingWindow };
|
|
60
81
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FloatingWindow.mjs","names":["classes"],"sources":["../../../src/components/FloatingWindow/FloatingWindow.tsx"],"sourcesContent":["import { useImperativeHandle } from 'react';\nimport {\n SetFloatingWindowPosition,\n useFloatingWindow,\n UseFloatingWindowOptions,\n useMergedRef,\n} from '@mantine/hooks';\nimport {\n BoxProps,\n ElementProps,\n factory,\n Factory,\n getDefaultZIndex,\n StylesApiProps,\n useProps,\n useStyles,\n} from '../../core';\nimport { Paper, PaperBaseProps } from '../Paper';\nimport { OptionalPortal, PortalProps } from '../Portal';\nimport classes from './FloatingWindow.module.css';\n\nexport type FloatingWindowStylesNames = 'root';\n\nexport interface FloatingWindowProps\n extends\n UseFloatingWindowOptions,\n PaperBaseProps,\n BoxProps,\n StylesApiProps<FloatingWindowFactory>,\n ElementProps<'div', keyof UseFloatingWindowOptions> {\n /** Assigns ref to set position programmatically */\n setPositionRef?: React.RefObject<SetFloatingWindowPosition | null>;\n\n /** Determines whether the window should be rendered inside `Portal` @default true */\n withinPortal?: boolean;\n\n /** Props passed down to `Portal` component */\n portalProps?: Omit<PortalProps, 'children'>;\n\n /** `z-index` of the root element @default 400 */\n zIndex?: React.CSSProperties['zIndex'];\n}\n\nexport type FloatingWindowFactory = Factory<{\n props: FloatingWindowProps;\n ref: HTMLDivElement;\n stylesNames: FloatingWindowStylesNames;\n}>;\n\nconst defaultProps = {\n constrainToViewport: true,\n zIndex: getDefaultZIndex('overlay'),\n} satisfies Partial<FloatingWindowProps>;\n\nexport const FloatingWindow = factory<FloatingWindowFactory>((_props) => {\n const props = useProps('FloatingWindow', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n mod,\n enabled,\n constrainToViewport,\n constrainOffset,\n dragHandleSelector,\n excludeDragHandleSelector,\n axis,\n initialPosition,\n onPositionChange,\n onDragStart,\n onDragEnd,\n setPositionRef,\n withinPortal,\n portalProps,\n zIndex,\n ref,\n ...others\n } = props;\n\n const getStyles = useStyles<FloatingWindowFactory>({\n name: 'FloatingWindow',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n vars,\n });\n\n const floatingWindow = useFloatingWindow({\n enabled,\n constrainToViewport,\n constrainOffset,\n dragHandleSelector,\n excludeDragHandleSelector,\n axis,\n initialPosition,\n onPositionChange,\n onDragStart,\n onDragEnd,\n });\n\n useImperativeHandle(setPositionRef, () => floatingWindow.setPosition, [\n floatingWindow.setPosition,\n ]);\n\n return (\n <OptionalPortal withinPortal={withinPortal} {...portalProps}>\n
|
|
1
|
+
{"version":3,"file":"FloatingWindow.mjs","names":["classes"],"sources":["../../../src/components/FloatingWindow/FloatingWindow.tsx"],"sourcesContent":["import { useImperativeHandle, useRef } from 'react';\nimport {\n SetFloatingWindowPosition,\n useFloatingWindow,\n UseFloatingWindowOptions,\n useMergedRef,\n} from '@mantine/hooks';\nimport {\n BoxProps,\n ElementProps,\n factory,\n Factory,\n getDefaultZIndex,\n StylesApiProps,\n useProps,\n useStyles,\n} from '../../core';\nimport { Paper, PaperBaseProps } from '../Paper';\nimport { OptionalPortal, PortalProps } from '../Portal';\nimport { FloatingWindowDimensions, FloatingWindowProvider } from './FloatingWindow.context';\nimport { FloatingWindowResizeHandle } from './FloatingWindowResizeHandle';\nimport classes from './FloatingWindow.module.css';\n\nexport type FloatingWindowStylesNames = 'root';\n\nexport interface FloatingWindowProps\n extends\n UseFloatingWindowOptions,\n PaperBaseProps,\n BoxProps,\n StylesApiProps<FloatingWindowFactory>,\n ElementProps<'div', keyof UseFloatingWindowOptions> {\n /** Assigns ref to set position programmatically */\n setPositionRef?: React.RefObject<SetFloatingWindowPosition | null>;\n\n /** Determines whether the window should be rendered inside `Portal` @default true */\n withinPortal?: boolean;\n\n /** Props passed down to `Portal` component */\n portalProps?: Omit<PortalProps, 'children'>;\n\n /** `z-index` of the root element @default 400 */\n zIndex?: React.CSSProperties['zIndex'];\n\n /** Dimensions configuration for resizable floating window */\n dimensions?: FloatingWindowDimensions;\n}\n\nexport type FloatingWindowFactory = Factory<{\n props: FloatingWindowProps;\n ref: HTMLDivElement;\n stylesNames: FloatingWindowStylesNames;\n staticComponents: {\n ResizeHandle: typeof FloatingWindowResizeHandle;\n };\n}>;\n\nconst defaultProps = {\n constrainToViewport: true,\n zIndex: getDefaultZIndex('overlay'),\n} satisfies Partial<FloatingWindowProps>;\n\nfunction clampDimension(value: number, min?: number, max?: number): number {\n let v = value;\n if (min != null) {\n v = Math.max(v, min);\n }\n if (max != null) {\n v = Math.min(v, max);\n }\n return v;\n}\n\nexport const FloatingWindow = factory<FloatingWindowFactory>((_props) => {\n const props = useProps('FloatingWindow', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n mod,\n enabled,\n constrainToViewport,\n constrainOffset,\n dragHandleSelector,\n excludeDragHandleSelector,\n axis,\n initialPosition,\n onPositionChange,\n onDragStart,\n onDragEnd,\n setPositionRef,\n withinPortal,\n portalProps,\n zIndex,\n dimensions,\n ref,\n ...others\n } = props;\n\n const rootRef = useRef<HTMLDivElement>(null);\n\n const getStyles = useStyles<FloatingWindowFactory>({\n name: 'FloatingWindow',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n vars,\n });\n\n const floatingWindow = useFloatingWindow({\n enabled,\n constrainToViewport,\n constrainOffset,\n dragHandleSelector,\n excludeDragHandleSelector,\n axis,\n initialPosition,\n onPositionChange,\n onDragStart,\n onDragEnd,\n });\n\n useImperativeHandle(setPositionRef, () => floatingWindow.setPosition, [\n floatingWindow.setPosition,\n ]);\n\n const cssVars: Record<string, string | undefined> = {\n '--floating-window-z-index': zIndex.toString(),\n };\n\n if (dimensions?.initialWidth != null) {\n cssVars['--floating-window-width'] =\n `${clampDimension(dimensions.initialWidth, dimensions.minWidth, dimensions.maxWidth)}px`;\n }\n\n if (dimensions?.initialHeight != null) {\n cssVars['--floating-window-height'] =\n `${clampDimension(dimensions.initialHeight, dimensions.minHeight, dimensions.maxHeight)}px`;\n }\n\n return (\n <FloatingWindowProvider\n value={{\n rootRef,\n dimensions,\n constrainToViewport,\n constrainOffset,\n }}\n >\n <OptionalPortal withinPortal={withinPortal} {...portalProps}>\n <Paper\n ref={useMergedRef(ref, floatingWindow.ref, rootRef)}\n mod={[{ dragging: floatingWindow.isDragging }, mod]}\n {...getStyles('root')}\n {...others}\n __vars={cssVars}\n />\n </OptionalPortal>\n </FloatingWindowProvider>\n );\n});\n\nFloatingWindow.displayName = '@mantine/core/FloatingWindow';\nFloatingWindow.classes = classes;\nFloatingWindow.ResizeHandle = FloatingWindowResizeHandle;\n"],"mappings":";;;;;;;;;;;;;;AAyDA,MAAM,eAAe;CACnB,qBAAqB;CACrB,QAAQ,iBAAiB,SAAS;AACpC;AAEA,SAAS,eAAe,OAAe,KAAc,KAAsB;CACzE,IAAI,IAAI;CACR,IAAI,OAAO,MACT,IAAI,KAAK,IAAI,GAAG,GAAG;CAErB,IAAI,OAAO,MACT,IAAI,KAAK,IAAI,GAAG,GAAG;CAErB,OAAO;AACT;AAEA,MAAa,iBAAiB,SAAgC,WAAW;CACvE,MAAM,QAAQ,SAAS,kBAAkB,cAAc,MAAM;CAC7D,MAAM,EACJ,YACA,WACA,OACA,QACA,UACA,MACA,KACA,SACA,qBACA,iBACA,oBACA,2BACA,MACA,iBACA,kBACA,aACA,WACA,gBACA,cACA,aACA,QACA,YACA,KACA,GAAG,WACD;CAEJ,MAAM,UAAU,OAAuB,IAAI;CAE3C,MAAM,YAAY,UAAiC;EACjD,MAAM;EACN,SAAA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,MAAM,iBAAiB,kBAAkB;EACvC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,oBAAoB,sBAAsB,eAAe,aAAa,CACpE,eAAe,WACjB,CAAC;CAED,MAAM,UAA8C,EAClD,6BAA6B,OAAO,SAAS,EAC/C;CAEA,IAAI,YAAY,gBAAgB,MAC9B,QAAQ,6BACN,GAAG,eAAe,WAAW,cAAc,WAAW,UAAU,WAAW,QAAQ,EAAE;CAGzF,IAAI,YAAY,iBAAiB,MAC/B,QAAQ,8BACN,GAAG,eAAe,WAAW,eAAe,WAAW,WAAW,WAAW,SAAS,EAAE;CAG5F,OACE,oBAAC,wBAAD;EACE,OAAO;GACL;GACA;GACA;GACA;EACF;YAEA,oBAAC,gBAAD;GAA8B;GAAc,GAAI;aAC9C,oBAAC,OAAD;IACE,KAAK,aAAa,KAAK,eAAe,KAAK,OAAO;IAClD,KAAK,CAAC,EAAE,UAAU,eAAe,WAAW,GAAG,GAAG;IAClD,GAAI,UAAU,MAAM;IACpB,GAAI;IACJ,QAAQ;GACT,CAAA;EACa,CAAA;CACM,CAAA;AAE5B,CAAC;AAED,eAAe,cAAc;AAC7B,eAAe,UAAUA;AACzB,eAAe,eAAe"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FloatingWindow.module.mjs","names":[],"sources":["../../../src/components/FloatingWindow/FloatingWindow.module.css"],"sourcesContent":[".root {\n position: fixed;\n z-index: var(--floating-window-z-index);\n}\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"FloatingWindow.module.mjs","names":[],"sources":["../../../src/components/FloatingWindow/FloatingWindow.module.css"],"sourcesContent":[".root {\n position: fixed;\n z-index: var(--floating-window-z-index);\n width: var(--floating-window-width, auto);\n height: var(--floating-window-height, auto);\n}\n"],"mappings":""}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useProps } from "../../core/MantineProvider/use-props/use-props.mjs";
|
|
3
|
+
import { factory } from "../../core/factory/factory.mjs";
|
|
4
|
+
import { Box } from "../../core/Box/Box.mjs";
|
|
5
|
+
import { useFloatingWindowContext } from "./FloatingWindow.context.mjs";
|
|
6
|
+
import { useEffect, useRef } from "react";
|
|
7
|
+
import { useMergedRef } from "@mantine/hooks";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
//#region packages/@mantine/core/src/components/FloatingWindow/FloatingWindowResizeHandle.tsx
|
|
10
|
+
const defaultProps = {};
|
|
11
|
+
const KEYBOARD_STEP = 10;
|
|
12
|
+
function clampDimension(value, min, max, viewportMax) {
|
|
13
|
+
let v = value;
|
|
14
|
+
if (min != null) v = Math.max(v, min);
|
|
15
|
+
if (max != null) v = Math.min(v, max);
|
|
16
|
+
if (viewportMax != null) v = Math.min(v, viewportMax);
|
|
17
|
+
return v;
|
|
18
|
+
}
|
|
19
|
+
function getViewportLimits(root, constrainToViewport, constrainOffset) {
|
|
20
|
+
if (!constrainToViewport) return {
|
|
21
|
+
maxWidth: void 0,
|
|
22
|
+
maxHeight: void 0
|
|
23
|
+
};
|
|
24
|
+
const rect = root.getBoundingClientRect();
|
|
25
|
+
const offset = constrainOffset ?? 0;
|
|
26
|
+
return {
|
|
27
|
+
maxWidth: window.innerWidth - rect.left - offset,
|
|
28
|
+
maxHeight: window.innerHeight - rect.top - offset
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function constrainWidth(root, width, dimensions, constrainToViewport, constrainOffset) {
|
|
32
|
+
const { maxWidth: vpMax } = getViewportLimits(root, constrainToViewport, constrainOffset);
|
|
33
|
+
return clampDimension(width, dimensions?.minWidth, dimensions?.maxWidth, vpMax);
|
|
34
|
+
}
|
|
35
|
+
function constrainHeight(root, height, dimensions, constrainToViewport, constrainOffset) {
|
|
36
|
+
const { maxHeight: vpMax } = getViewportLimits(root, constrainToViewport, constrainOffset);
|
|
37
|
+
return clampDimension(height, dimensions?.minHeight, dimensions?.maxHeight, vpMax);
|
|
38
|
+
}
|
|
39
|
+
const FloatingWindowResizeHandle = factory((_props) => {
|
|
40
|
+
const { children, ref, style, ...others } = useProps("FloatingWindowResizeHandle", defaultProps, _props);
|
|
41
|
+
const ctx = useFloatingWindowContext();
|
|
42
|
+
const handleRef = useRef(null);
|
|
43
|
+
const hasWidth = ctx.dimensions?.initialWidth != null || ctx.dimensions?.minWidth != null || ctx.dimensions?.maxWidth != null;
|
|
44
|
+
const hasHeight = ctx.dimensions?.initialHeight != null || ctx.dimensions?.minHeight != null || ctx.dimensions?.maxHeight != null;
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
const handle = handleRef.current;
|
|
47
|
+
if (!handle) return;
|
|
48
|
+
const controller = new AbortController();
|
|
49
|
+
const { signal } = controller;
|
|
50
|
+
let isResizing = false;
|
|
51
|
+
let startX = 0;
|
|
52
|
+
let startY = 0;
|
|
53
|
+
let startWidth = 0;
|
|
54
|
+
let startHeight = 0;
|
|
55
|
+
const applySize = (width, height) => {
|
|
56
|
+
const root = ctx.rootRef.current;
|
|
57
|
+
if (!root) return;
|
|
58
|
+
if (width !== null) {
|
|
59
|
+
const w = constrainWidth(root, width, ctx.dimensions, ctx.constrainToViewport, ctx.constrainOffset);
|
|
60
|
+
root.style.width = `${w}px`;
|
|
61
|
+
handle.setAttribute("aria-valuenow", String(Math.round(w)));
|
|
62
|
+
}
|
|
63
|
+
if (height !== null) {
|
|
64
|
+
const h = constrainHeight(root, height, ctx.dimensions, ctx.constrainToViewport, ctx.constrainOffset);
|
|
65
|
+
root.style.height = `${h}px`;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const onStart = (e) => {
|
|
69
|
+
if ("button" in e && e.button !== 0) return;
|
|
70
|
+
e.stopPropagation();
|
|
71
|
+
e.preventDefault();
|
|
72
|
+
const root = ctx.rootRef.current;
|
|
73
|
+
if (!root) return;
|
|
74
|
+
const point = "touches" in e ? e.touches[0] : e;
|
|
75
|
+
startX = point.clientX;
|
|
76
|
+
startY = point.clientY;
|
|
77
|
+
const rect = root.getBoundingClientRect();
|
|
78
|
+
startWidth = rect.width;
|
|
79
|
+
startHeight = rect.height;
|
|
80
|
+
isResizing = true;
|
|
81
|
+
document.body.style.userSelect = "none";
|
|
82
|
+
document.body.style.webkitUserSelect = "none";
|
|
83
|
+
document.addEventListener("mousemove", onMove, { signal });
|
|
84
|
+
document.addEventListener("mouseup", onEnd, { signal });
|
|
85
|
+
document.addEventListener("touchmove", onMove, {
|
|
86
|
+
signal,
|
|
87
|
+
passive: false
|
|
88
|
+
});
|
|
89
|
+
document.addEventListener("touchend", onEnd, { signal });
|
|
90
|
+
};
|
|
91
|
+
const onMove = (e) => {
|
|
92
|
+
if (!isResizing) return;
|
|
93
|
+
e.preventDefault();
|
|
94
|
+
const point = "touches" in e ? e.touches[0] : e;
|
|
95
|
+
const deltaX = point.clientX - startX;
|
|
96
|
+
const deltaY = point.clientY - startY;
|
|
97
|
+
applySize(hasWidth ? startWidth + deltaX : null, hasHeight ? startHeight + deltaY : null);
|
|
98
|
+
};
|
|
99
|
+
const onEnd = () => {
|
|
100
|
+
if (!isResizing) return;
|
|
101
|
+
isResizing = false;
|
|
102
|
+
document.body.style.userSelect = "";
|
|
103
|
+
document.body.style.webkitUserSelect = "";
|
|
104
|
+
};
|
|
105
|
+
const onKeyDown = (e) => {
|
|
106
|
+
const root = ctx.rootRef.current;
|
|
107
|
+
if (!root) return;
|
|
108
|
+
const rect = root.getBoundingClientRect();
|
|
109
|
+
let newWidth = null;
|
|
110
|
+
let newHeight = null;
|
|
111
|
+
if (e.key === "ArrowRight" && hasWidth) newWidth = rect.width + KEYBOARD_STEP;
|
|
112
|
+
else if (e.key === "ArrowLeft" && hasWidth) newWidth = rect.width - KEYBOARD_STEP;
|
|
113
|
+
else if (e.key === "ArrowDown" && hasHeight) newHeight = rect.height + KEYBOARD_STEP;
|
|
114
|
+
else if (e.key === "ArrowUp" && hasHeight) newHeight = rect.height - KEYBOARD_STEP;
|
|
115
|
+
else if (e.key === "Home") {
|
|
116
|
+
if (hasWidth) newWidth = ctx.dimensions?.minWidth ?? rect.width;
|
|
117
|
+
if (hasHeight) newHeight = ctx.dimensions?.minHeight ?? rect.height;
|
|
118
|
+
} else if (e.key === "End") {
|
|
119
|
+
if (hasWidth) newWidth = ctx.dimensions?.maxWidth ?? rect.width;
|
|
120
|
+
if (hasHeight) newHeight = ctx.dimensions?.maxHeight ?? rect.height;
|
|
121
|
+
}
|
|
122
|
+
if (newWidth !== null || newHeight !== null) {
|
|
123
|
+
e.preventDefault();
|
|
124
|
+
applySize(newWidth, newHeight);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
handle.addEventListener("mousedown", onStart, { signal });
|
|
128
|
+
handle.addEventListener("touchstart", onStart, {
|
|
129
|
+
signal,
|
|
130
|
+
passive: false
|
|
131
|
+
});
|
|
132
|
+
handle.addEventListener("keydown", onKeyDown, { signal });
|
|
133
|
+
return () => {
|
|
134
|
+
controller.abort();
|
|
135
|
+
};
|
|
136
|
+
}, [
|
|
137
|
+
ctx.rootRef,
|
|
138
|
+
ctx.dimensions,
|
|
139
|
+
ctx.constrainToViewport,
|
|
140
|
+
ctx.constrainOffset,
|
|
141
|
+
hasWidth,
|
|
142
|
+
hasHeight
|
|
143
|
+
]);
|
|
144
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
145
|
+
ref: useMergedRef(ref, handleRef),
|
|
146
|
+
role: "separator",
|
|
147
|
+
"aria-label": "Resize window",
|
|
148
|
+
"aria-valuenow": ctx.dimensions?.initialWidth,
|
|
149
|
+
"aria-valuemin": ctx.dimensions?.minWidth,
|
|
150
|
+
"aria-valuemax": ctx.dimensions?.maxWidth,
|
|
151
|
+
tabIndex: 0,
|
|
152
|
+
...others,
|
|
153
|
+
style: [{ touchAction: "none" }, style],
|
|
154
|
+
children
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
FloatingWindowResizeHandle.displayName = "@mantine/core/FloatingWindowResizeHandle";
|
|
158
|
+
//#endregion
|
|
159
|
+
export { FloatingWindowResizeHandle };
|
|
160
|
+
|
|
161
|
+
//# sourceMappingURL=FloatingWindowResizeHandle.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FloatingWindowResizeHandle.mjs","names":[],"sources":["../../../src/components/FloatingWindow/FloatingWindowResizeHandle.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-deprecated */\nimport { useEffect, useRef } from 'react';\nimport { useMergedRef } from '@mantine/hooks';\nimport { Box, BoxProps, ElementProps, factory, Factory, useProps } from '../../core';\nimport { FloatingWindowDimensions, useFloatingWindowContext } from './FloatingWindow.context';\n\nexport interface FloatingWindowResizeHandleProps extends BoxProps, ElementProps<'div', 'role'> {}\n\nexport type FloatingWindowResizeHandleFactory = Factory<{\n props: FloatingWindowResizeHandleProps;\n ref: HTMLDivElement;\n}>;\n\nconst defaultProps = {} satisfies Partial<FloatingWindowResizeHandleProps>;\n\nconst KEYBOARD_STEP = 10;\n\nfunction clampDimension(\n value: number,\n min: number | undefined,\n max: number | undefined,\n viewportMax: number | undefined\n) {\n let v = value;\n if (min != null) {\n v = Math.max(v, min);\n }\n if (max != null) {\n v = Math.min(v, max);\n }\n if (viewportMax != null) {\n v = Math.min(v, viewportMax);\n }\n return v;\n}\n\nfunction getViewportLimits(\n root: HTMLElement,\n constrainToViewport: boolean | undefined,\n constrainOffset: number | undefined\n) {\n if (!constrainToViewport) {\n return { maxWidth: undefined, maxHeight: undefined };\n }\n const rect = root.getBoundingClientRect();\n const offset = constrainOffset ?? 0;\n return {\n maxWidth: window.innerWidth - rect.left - offset,\n maxHeight: window.innerHeight - rect.top - offset,\n };\n}\n\nfunction constrainWidth(\n root: HTMLElement,\n width: number,\n dimensions: FloatingWindowDimensions | undefined,\n constrainToViewport: boolean | undefined,\n constrainOffset: number | undefined\n) {\n const { maxWidth: vpMax } = getViewportLimits(root, constrainToViewport, constrainOffset);\n return clampDimension(width, dimensions?.minWidth, dimensions?.maxWidth, vpMax);\n}\n\nfunction constrainHeight(\n root: HTMLElement,\n height: number,\n dimensions: FloatingWindowDimensions | undefined,\n constrainToViewport: boolean | undefined,\n constrainOffset: number | undefined\n) {\n const { maxHeight: vpMax } = getViewportLimits(root, constrainToViewport, constrainOffset);\n return clampDimension(height, dimensions?.minHeight, dimensions?.maxHeight, vpMax);\n}\n\nexport const FloatingWindowResizeHandle = factory<FloatingWindowResizeHandleFactory>((_props) => {\n const props = useProps('FloatingWindowResizeHandle', defaultProps, _props);\n const { children, ref, style, ...others } = props;\n const ctx = useFloatingWindowContext();\n const handleRef = useRef<HTMLDivElement>(null);\n\n const hasWidth =\n ctx.dimensions?.initialWidth != null ||\n ctx.dimensions?.minWidth != null ||\n ctx.dimensions?.maxWidth != null;\n const hasHeight =\n ctx.dimensions?.initialHeight != null ||\n ctx.dimensions?.minHeight != null ||\n ctx.dimensions?.maxHeight != null;\n\n useEffect(() => {\n const handle = handleRef.current;\n if (!handle) {\n return;\n }\n\n const controller = new AbortController();\n const { signal } = controller;\n let isResizing = false;\n let startX = 0;\n let startY = 0;\n let startWidth = 0;\n let startHeight = 0;\n\n const applySize = (width: number | null, height: number | null) => {\n const root = ctx.rootRef.current;\n if (!root) {\n return;\n }\n\n if (width !== null) {\n const w = constrainWidth(\n root,\n width,\n ctx.dimensions,\n ctx.constrainToViewport,\n ctx.constrainOffset\n );\n root.style.width = `${w}px`;\n handle.setAttribute('aria-valuenow', String(Math.round(w)));\n }\n\n if (height !== null) {\n const h = constrainHeight(\n root,\n height,\n ctx.dimensions,\n ctx.constrainToViewport,\n ctx.constrainOffset\n );\n root.style.height = `${h}px`;\n }\n };\n\n const onStart = (e: MouseEvent | TouchEvent) => {\n if ('button' in e && e.button !== 0) {\n return;\n }\n\n e.stopPropagation();\n e.preventDefault();\n\n const root = ctx.rootRef.current;\n if (!root) {\n return;\n }\n\n const point = 'touches' in e ? e.touches[0] : e;\n startX = point.clientX;\n startY = point.clientY;\n const rect = root.getBoundingClientRect();\n startWidth = rect.width;\n startHeight = rect.height;\n isResizing = true;\n\n document.body.style.userSelect = 'none';\n document.body.style.webkitUserSelect = 'none';\n\n document.addEventListener('mousemove', onMove, { signal });\n document.addEventListener('mouseup', onEnd, { signal });\n document.addEventListener('touchmove', onMove, { signal, passive: false });\n document.addEventListener('touchend', onEnd, { signal });\n };\n\n const onMove = (e: MouseEvent | TouchEvent) => {\n if (!isResizing) {\n return;\n }\n\n e.preventDefault();\n const point = 'touches' in e ? e.touches[0] : e;\n const deltaX = point.clientX - startX;\n const deltaY = point.clientY - startY;\n applySize(hasWidth ? startWidth + deltaX : null, hasHeight ? startHeight + deltaY : null);\n };\n\n const onEnd = () => {\n if (!isResizing) {\n return;\n }\n\n isResizing = false;\n document.body.style.userSelect = '';\n document.body.style.webkitUserSelect = '';\n };\n\n const onKeyDown = (e: KeyboardEvent) => {\n const root = ctx.rootRef.current;\n if (!root) {\n return;\n }\n\n const rect = root.getBoundingClientRect();\n let newWidth: number | null = null;\n let newHeight: number | null = null;\n\n if (e.key === 'ArrowRight' && hasWidth) {\n newWidth = rect.width + KEYBOARD_STEP;\n } else if (e.key === 'ArrowLeft' && hasWidth) {\n newWidth = rect.width - KEYBOARD_STEP;\n } else if (e.key === 'ArrowDown' && hasHeight) {\n newHeight = rect.height + KEYBOARD_STEP;\n } else if (e.key === 'ArrowUp' && hasHeight) {\n newHeight = rect.height - KEYBOARD_STEP;\n } else if (e.key === 'Home') {\n if (hasWidth) {\n newWidth = ctx.dimensions?.minWidth ?? rect.width;\n }\n if (hasHeight) {\n newHeight = ctx.dimensions?.minHeight ?? rect.height;\n }\n } else if (e.key === 'End') {\n if (hasWidth) {\n newWidth = ctx.dimensions?.maxWidth ?? rect.width;\n }\n if (hasHeight) {\n newHeight = ctx.dimensions?.maxHeight ?? rect.height;\n }\n }\n\n if (newWidth !== null || newHeight !== null) {\n e.preventDefault();\n applySize(newWidth, newHeight);\n }\n };\n\n handle.addEventListener('mousedown', onStart, { signal });\n handle.addEventListener('touchstart', onStart, { signal, passive: false });\n handle.addEventListener('keydown', onKeyDown, { signal });\n\n return () => {\n controller.abort();\n };\n }, [\n ctx.rootRef,\n ctx.dimensions,\n ctx.constrainToViewport,\n ctx.constrainOffset,\n hasWidth,\n hasHeight,\n ]);\n\n return (\n <Box\n ref={useMergedRef(ref, handleRef)}\n role=\"separator\"\n aria-label=\"Resize window\"\n aria-valuenow={ctx.dimensions?.initialWidth}\n aria-valuemin={ctx.dimensions?.minWidth}\n aria-valuemax={ctx.dimensions?.maxWidth}\n tabIndex={0}\n {...others}\n style={[{ touchAction: 'none' }, style]}\n >\n {children}\n </Box>\n );\n});\n\nFloatingWindowResizeHandle.displayName = '@mantine/core/FloatingWindowResizeHandle';\n"],"mappings":";;;;;;;;;AAaA,MAAM,eAAe,CAAC;AAEtB,MAAM,gBAAgB;AAEtB,SAAS,eACP,OACA,KACA,KACA,aACA;CACA,IAAI,IAAI;CACR,IAAI,OAAO,MACT,IAAI,KAAK,IAAI,GAAG,GAAG;CAErB,IAAI,OAAO,MACT,IAAI,KAAK,IAAI,GAAG,GAAG;CAErB,IAAI,eAAe,MACjB,IAAI,KAAK,IAAI,GAAG,WAAW;CAE7B,OAAO;AACT;AAEA,SAAS,kBACP,MACA,qBACA,iBACA;CACA,IAAI,CAAC,qBACH,OAAO;EAAE,UAAU,KAAA;EAAW,WAAW,KAAA;CAAU;CAErD,MAAM,OAAO,KAAK,sBAAsB;CACxC,MAAM,SAAS,mBAAmB;CAClC,OAAO;EACL,UAAU,OAAO,aAAa,KAAK,OAAO;EAC1C,WAAW,OAAO,cAAc,KAAK,MAAM;CAC7C;AACF;AAEA,SAAS,eACP,MACA,OACA,YACA,qBACA,iBACA;CACA,MAAM,EAAE,UAAU,UAAU,k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WAAW,KAAK,QAAQ;QACnB,IAAI,EAAE,QAAQ,eAAe,WAClC,YAAY,KAAK,SAAS;QACrB,IAAI,EAAE,QAAQ,aAAa,WAChC,YAAY,KAAK,SAAS;QACrB,IAAI,EAAE,QAAQ,QAAQ;IAC3B,IAAI,UACF,WAAW,IAAI,YAAY,YAAY,KAAK;IAE9C,IAAI,WACF,YAAY,IAAI,YAAY,aAAa,KAAK;GAElD,OAAO,IAAI,EAAE,QAAQ,OAAO;IAC1B,IAAI,UACF,WAAW,IAAI,YAAY,YAAY,KAAK;IAE9C,IAAI,WACF,YAAY,IAAI,YAAY,aAAa,KAAK;GAElD;GAEA,IAAI,aAAa,QAAQ,cAAc,MAAM;IAC3C,EAAE,eAAe;IACjB,UAAU,UAAU,SAAS;GAC/B;EACF;EAEA,OAAO,iBAAiB,aAAa,SAAS,EAAE,OAAO,CAAC;EACxD,OAAO,iBAAiB,cAAc,SAAS;GAAE;GAAQ,SAAS;EAAM,CAAC;EACzE,OAAO,iBAAiB,WAAW,WAAW,EAAE,OAAO,CAAC;EAExD,aAAa;GACX,WAAW,MAAM;EACnB;CACF,GAAG;EACD,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ;EACA;CACF,CAAC;CAED,OACE,oBAAC,KAAD;EACE,KAAK,aAAa,KAAK,SAAS;EAChC,MAAK;EACL,cAAW;EACX,iBAAe,IAAI,YAAY;EAC/B,iBAAe,IAAI,YAAY;EAC/B,iBAAe,IAAI,YAAY;EAC/B,UAAU;EACV,GAAI;EACJ,OAAO,CAAC,EAAE,aAAa,OAAO,GAAG,KAAK;EAErC;CACE,CAAA;AAET,CAAC;AAED,2BAA2B,cAAc"}
|
|
@@ -11,7 +11,7 @@ function ModalStack({ children }) {
|
|
|
11
11
|
value: {
|
|
12
12
|
stack,
|
|
13
13
|
addModal: (id, zIndex) => {
|
|
14
|
-
setStack((current) => [
|
|
14
|
+
setStack((current) => [.../* @__PURE__ */ new Set([...current, id])]);
|
|
15
15
|
setMaxZIndex((current) => typeof zIndex === "number" && typeof current === "number" ? Math.max(current, zIndex) : current);
|
|
16
16
|
},
|
|
17
17
|
removeModal: (id) => setStack((current) => current.filter((currentId) => currentId !== id)),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModalStack.mjs","names":[],"sources":["../../../src/components/Modal/ModalStack.tsx"],"sourcesContent":["import { createContext, useState } from 'react';\nimport { getDefaultZIndex } from '../../core';\n\ninterface ModalStackContext {\n stack: string[];\n addModal: (id: string, zIndex: number | string) => void;\n removeModal: (id: string) => void;\n getZIndex: (id: string) => string;\n currentId: string;\n maxZIndex: string | number;\n}\n\nexport const ModalStackContext = createContext<ModalStackContext | null>(null);\n\nexport interface ModalStackProps {\n children: React.ReactNode;\n}\n\nexport function ModalStack({ children }: ModalStackProps) {\n const [stack, setStack] = useState<string[]>([]);\n const [maxZIndex, setMaxZIndex] = useState<number | string>(getDefaultZIndex('modal'));\n\n return (\n <ModalStackContext\n value={{\n stack,\n addModal: (id, zIndex) => {\n setStack((current) => [...new Set([...current, id])]);\n setMaxZIndex((current) =>\n typeof zIndex === 'number' && typeof current === 'number'\n ? Math.max(current, zIndex)\n : current\n );\n },\n removeModal: (id) => setStack((current) => current.filter((currentId) => currentId !== id)),\n getZIndex: (id) => `calc(${maxZIndex} + ${stack.indexOf(id)} + 1)`,\n currentId: stack[stack.length - 1],\n maxZIndex,\n }}\n >\n {children}\n </ModalStackContext>\n );\n}\n\nModalStack.displayName = '@mantine/core/ModalStack';\n"],"mappings":";;;;;AAYA,MAAa,oBAAoB,cAAwC,IAAI;AAM7E,SAAgB,WAAW,EAAE,YAA6B;CACxD,MAAM,CAAC,OAAO,YAAY,SAAmB,CAAC,CAAC;CAC/C,MAAM,CAAC,WAAW,gBAAgB,SAA0B,iBAAiB,OAAO,CAAC;CAErF,OACE,oBAAC,mBAAD;EACE,OAAO;GACL;GACA,WAAW,IAAI,WAAW;IACxB,UAAU,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"ModalStack.mjs","names":[],"sources":["../../../src/components/Modal/ModalStack.tsx"],"sourcesContent":["import { createContext, useState } from 'react';\nimport { getDefaultZIndex } from '../../core';\n\ninterface ModalStackContext {\n stack: string[];\n addModal: (id: string, zIndex: number | string) => void;\n removeModal: (id: string) => void;\n getZIndex: (id: string) => string;\n currentId: string;\n maxZIndex: string | number;\n}\n\nexport const ModalStackContext = createContext<ModalStackContext | null>(null);\n\nexport interface ModalStackProps {\n children: React.ReactNode;\n}\n\nexport function ModalStack({ children }: ModalStackProps) {\n const [stack, setStack] = useState<string[]>([]);\n const [maxZIndex, setMaxZIndex] = useState<number | string>(getDefaultZIndex('modal'));\n\n return (\n <ModalStackContext\n value={{\n stack,\n addModal: (id, zIndex) => {\n setStack((current) => [...new Set([...current, id])]);\n setMaxZIndex((current) =>\n typeof zIndex === 'number' && typeof current === 'number'\n ? Math.max(current, zIndex)\n : current\n );\n },\n removeModal: (id) => setStack((current) => current.filter((currentId) => currentId !== id)),\n getZIndex: (id) => `calc(${maxZIndex} + ${stack.indexOf(id)} + 1)`,\n currentId: stack[stack.length - 1],\n maxZIndex,\n }}\n >\n {children}\n </ModalStackContext>\n );\n}\n\nModalStack.displayName = '@mantine/core/ModalStack';\n"],"mappings":";;;;;AAYA,MAAa,oBAAoB,cAAwC,IAAI;AAM7E,SAAgB,WAAW,EAAE,YAA6B;CACxD,MAAM,CAAC,OAAO,YAAY,SAAmB,CAAC,CAAC;CAC/C,MAAM,CAAC,WAAW,gBAAgB,SAA0B,iBAAiB,OAAO,CAAC;CAErF,OACE,oBAAC,mBAAD;EACE,OAAO;GACL;GACA,WAAW,IAAI,WAAW;IACxB,UAAU,YAAY,CAAC,mBAAG,IAAI,IAAI,CAAC,GAAG,SAAS,EAAE,CAAC,CAAC,CAAC;IACpD,cAAc,YACZ,OAAO,WAAW,YAAY,OAAO,YAAY,WAC7C,KAAK,IAAI,SAAS,MAAM,IACxB,OACN;GACF;GACA,cAAc,OAAO,UAAU,YAAY,QAAQ,QAAQ,cAAc,cAAc,EAAE,CAAC;GAC1F,YAAY,OAAO,QAAQ,UAAU,KAAK,MAAM,QAAQ,EAAE,EAAE;GAC5D,WAAW,MAAM,MAAM,SAAS;GAChC;EACF;EAEC;CACgB,CAAA;AAEvB;AAEA,WAAW,cAAc"}
|
|
@@ -133,7 +133,8 @@ const OverflowList = genericFactory((_props) => {
|
|
|
133
133
|
if (!container) return false;
|
|
134
134
|
const containerWidth = container.getBoundingClientRect().width;
|
|
135
135
|
const columnGap = parseFloat(getComputedStyle(container).columnGap) || 0;
|
|
136
|
-
|
|
136
|
+
const itemWidths = [_overflowRef.current.getBoundingClientRect().width, ...rowData.children.map((child) => child.getBoundingClientRect().width)];
|
|
137
|
+
if (!fitsInRows(itemWidths, containerWidth, columnGap)) {
|
|
137
138
|
setSubtractCount((c) => c + 1);
|
|
138
139
|
return true;
|
|
139
140
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OverflowList.mjs","names":["Fragment","classes"],"sources":["../../../src/components/OverflowList/OverflowList.tsx"],"sourcesContent":["// Originally based on https://github.com/Eliav2/react-responsive-overflow-list (MIT License)\n// Contains the modified version adapted for Mantine\nimport { cloneElement, useMemo, useRef, useState } from 'react';\nimport { Fragment } from 'react/jsx-runtime';\nimport { useIsomorphicEffect, useMergedRef } from '@mantine/hooks';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n Factory,\n genericFactory,\n getSpacing,\n MantineSpacing,\n StylesApiProps,\n useProps,\n useStyles,\n} from '../../core';\nimport { getRowPositionsData } from './get-row-position-data';\nimport { useDimensions } from './use-dimensions';\nimport classes from './OverflowList.module.css';\n\nexport type OverflowListStylesNames = 'root';\nexport type OverflowListCssVariables = {\n root: '--ol-gap';\n};\n\nexport interface OverflowListProps<T = any>\n extends BoxProps, StylesApiProps<OverflowListFactory>, ElementProps<'div', 'children'> {\n /** Array of items to display */\n data: T[];\n\n /** Function to render item */\n renderItem: (item: T, index: number) => React.ReactNode;\n\n /** Function to render hidden items */\n renderOverflow: (items: T[]) => React.ReactNode;\n\n /** Number of rows to display @default 1 */\n maxRows?: number;\n\n /** Maximum number of visible items @default Infinity */\n maxVisibleItems?: number;\n\n /** Key of `theme.spacing` or any valid CSS value for `gap`, numbers are converted to rem @default 'xs' */\n gap?: MantineSpacing;\n\n /** Direction from which items are collapsed when they overflow, `'end'` collapses last items, `'start'` collapses first items @default 'end' */\n collapseFrom?: 'start' | 'end';\n\n /** A function to resolve a unique key for each item. Used to detect when the contents of `data`\n * change (for example when items are reordered while the length stays the same) so the\n * visible/overflow split can be recomputed. Required to detect reordering when `data` contains\n * objects; for primitive items (strings, numbers) the item value is used by default. */\n getItemKey?: (item: T, index: number) => React.Key;\n}\n\nexport type OverflowListFactory = Factory<{\n props: OverflowListProps<any>;\n ref: HTMLDivElement;\n stylesNames: OverflowListStylesNames;\n vars: OverflowListCssVariables;\n signature: <T = any>(props: OverflowListProps<T>) => React.JSX.Element;\n}>;\n\nconst defaultProps = {\n maxRows: 1,\n maxVisibleItems: Infinity,\n} satisfies Partial<OverflowListProps<any>>;\n\nconst varsResolver = createVarsResolver<OverflowListFactory>((_, { gap }) => ({\n root: {\n '--ol-gap': getSpacing(gap),\n },\n}));\n\nfunction getDataSignature<T>(\n data: T[],\n getItemKey: ((item: T, index: number) => React.Key) | undefined\n): string {\n return data\n .map((item, index) => {\n if (getItemKey) {\n return getItemKey(item, index);\n }\n return item !== null && (typeof item === 'object' || typeof item === 'function')\n ? index\n : String(item);\n })\n .join('\\u0000');\n}\n\nexport const OverflowList = genericFactory<OverflowListFactory>((_props) => {\n const props = useProps('OverflowList', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n attributes,\n data,\n renderOverflow,\n renderItem,\n maxRows,\n maxVisibleItems,\n collapseFrom,\n getItemKey,\n ref,\n ...others\n } = props;\n\n const getStyles = useStyles<OverflowListFactory>({\n name: 'OverflowList',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n const [visibleCount, setVisibleCount] = useState(data.length);\n const [subtractCount, setSubtractCount] = useState(0);\n const [phase, setPhase] = useState<'normal' | 'measuring' | 'measuring-overflow-indicator'>(\n 'normal'\n );\n\n const containerRef = useRef<HTMLElement>(null);\n const rootRef = useMergedRef(containerRef, ref);\n const finalVisibleCount = visibleCount - subtractCount;\n const overflowCount = data.length - finalVisibleCount;\n const showOverflow = overflowCount > 0 && phase !== 'measuring';\n const isCollapseStart = collapseFrom === 'start';\n const overflowItems = isCollapseStart\n ? data.slice(0, data.length - finalVisibleCount)\n : data.slice(finalVisibleCount);\n const overflowElement = showOverflow ? renderOverflow?.(overflowItems) : null;\n\n const _overflowRef = useRef<HTMLElement>(null);\n const overflowRef = useMergedRef(_overflowRef, (overflowElement as any)?.ref);\n const dimensions = useDimensions(containerRef);\n const dataKey = useMemo(() => getDataSignature(data, getItemKey), [data, getItemKey]);\n\n useIsomorphicEffect(() => {\n setPhase('measuring');\n setVisibleCount(data.length);\n setSubtractCount(0);\n }, [dataKey, maxRows, collapseFrom]);\n\n useIsomorphicEffect(() => {\n if (phase === 'measuring') {\n countVisibleItems();\n setPhase('measuring-overflow-indicator');\n }\n }, [phase]);\n\n useIsomorphicEffect(() => {\n if (phase === 'measuring-overflow-indicator') {\n const updateWasNeeded = updateOverflowIndicator();\n if (!updateWasNeeded) {\n setPhase('normal');\n }\n }\n }, [phase, subtractCount]);\n\n useIsomorphicEffect(() => {\n if (phase === 'normal') {\n setPhase('measuring');\n setSubtractCount(0);\n }\n }, [dimensions]);\n\n const fitsInRows = (\n itemWidths: number[],\n containerWidth: number,\n columnGap: number,\n startIndex = 0\n ) => {\n let rows = 1;\n let rowWidth = 0;\n\n for (let i = startIndex; i < itemWidths.length; i += 1) {\n const width = itemWidths[i];\n const needed = rowWidth > 0 ? width + columnGap : width;\n\n if (rowWidth + needed > containerWidth && rowWidth > 0) {\n rows++;\n if (rows > maxRows!) {\n return false;\n }\n rowWidth = width;\n } else {\n rowWidth += needed;\n }\n }\n\n return true;\n };\n\n const countVisibleItems = () => {\n const rowData = getRowPositionsData(containerRef, _overflowRef);\n if (!rowData) {\n return;\n }\n\n const container = containerRef.current;\n if (!container) {\n return;\n }\n\n if (isCollapseStart) {\n const containerWidth = container.getBoundingClientRect().width;\n const columnGap = parseFloat(getComputedStyle(container).columnGap) || 0;\n const children = rowData.children;\n const widths = children.map((child) => child.getBoundingClientRect().width);\n\n let count = 0;\n for (let i = widths.length - 1; i >= 0; i--) {\n if (!fitsInRows(widths, containerWidth, columnGap, i)) {\n break;\n }\n count = widths.length - i;\n }\n\n count = Math.min(count, maxVisibleItems!);\n setVisibleCount(count);\n return;\n }\n\n if (data.length === 1) {\n const itemRef = rowData.itemsSizesMap[rowData.rowPositions[0]].elements.values().next().value;\n const containerWidth = container.getBoundingClientRect().width;\n const itemWidth = itemRef?.getBoundingClientRect().width ?? 0;\n\n if (itemWidth > containerWidth) {\n setVisibleCount(0);\n } else {\n setVisibleCount(1);\n }\n\n return;\n }\n\n const visibleRowPositions = rowData.rowPositions.slice(0, maxRows);\n\n let fittingCount = visibleRowPositions.reduce((acc, position) => {\n return acc + rowData.itemsSizesMap[position].elements.size;\n }, 0);\n\n fittingCount = Math.min(fittingCount, maxVisibleItems);\n setVisibleCount(fittingCount);\n };\n\n const updateOverflowIndicator = () => {\n if (!_overflowRef.current) {\n return false;\n }\n const rowData = getRowPositionsData(containerRef, _overflowRef);\n if (!rowData) {\n return false;\n }\n\n const { rowPositions, itemsSizesMap } = rowData;\n\n if (isCollapseStart) {\n const container = containerRef.current;\n if (!container) {\n return false;\n }\n const containerWidth = container.getBoundingClientRect().width;\n const columnGap = parseFloat(getComputedStyle(container).columnGap) || 0;\n const overflowWidth = _overflowRef.current.getBoundingClientRect().width;\n const children = rowData.children;\n const itemWidths = [\n overflowWidth,\n ...children.map((child) => child.getBoundingClientRect().width),\n ];\n\n if (!fitsInRows(itemWidths, containerWidth, columnGap)) {\n setSubtractCount((c) => c + 1);\n return true;\n }\n\n return false;\n }\n\n const overflowRect = _overflowRef.current.getBoundingClientRect();\n const overflowMiddleY = overflowRect.top + overflowRect.height / 2;\n const lastRowTop = rowPositions[rowPositions.length - 1];\n const lastRow = itemsSizesMap[lastRowTop];\n\n if (overflowMiddleY > lastRow.bottom) {\n setSubtractCount((c) => c + 1);\n return true;\n }\n\n return false;\n };\n\n const clonedOverflowElement = overflowElement\n ? cloneElement(overflowElement as React.ReactElement<any>, { ref: overflowRef })\n : null;\n\n let finalItems = data;\n if (maxVisibleItems) {\n finalItems = isCollapseStart\n ? finalItems.slice(-maxVisibleItems!)\n : finalItems.slice(0, maxVisibleItems);\n }\n\n const indexOffset = isCollapseStart ? data.length - finalItems.length : 0;\n\n return (\n <Box ref={rootRef} {...getStyles('root')} {...others}>\n {isCollapseStart && clonedOverflowElement}\n\n {finalItems.map((item, index) => {\n const isVisible =\n phase === 'measuring' ||\n (isCollapseStart\n ? index >= finalItems.length - finalVisibleCount\n : index < finalVisibleCount);\n if (!isVisible) {\n return null;\n }\n const dataIndex = indexOffset + index;\n const itemComponent = renderItem(item, dataIndex);\n\n return <Fragment key={dataIndex}>{itemComponent}</Fragment>;\n })}\n\n {!isCollapseStart && clonedOverflowElement}\n </Box>\n );\n});\n\nOverflowList.displayName = '@mantine/core/OverflowList';\nOverflowList.classes = classes;\nOverflowList.varsResolver = varsResolver;\n\nexport namespace OverflowList {\n export type Props = OverflowListProps;\n export type Factory = OverflowListFactory;\n export type StylesNames = OverflowListStylesNames;\n export type CssVariables = OverflowListCssVariables;\n}\n"],"mappings":";;;;;;;;;;;;;;AAiEA,MAAM,eAAe;CACnB,SAAS;CACT,iBAAiB;AACnB;AAEA,MAAM,eAAe,oBAAyC,GAAG,EAAE,WAAW,EAC5E,MAAM,EACJ,YAAY,WAAW,GAAG,EAC5B,EACF,EAAE;AAEF,SAAS,iBACP,MACA,YACQ;CACR,OAAO,KACJ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;GAC7B,OAAO;EACT;EAEA,OAAO;CACT;CAEA,MAAM,wBAAwB,kBAC1B,aAAa,iBAA4C,EAAE,KAAK,YAAY,CAAC,IAC7E;CAEJ,IAAI,aAAa;CACjB,IAAI,iBACF,aAAa,kBACT,WAAW,MAAM,CAAC,eAAgB,IAClC,WAAW,MAAM,GAAG,eAAe;CAGzC,MAAM,cAAc,kBAAkB,KAAK,SAAS,WAAW,SAAS;CAExE,OACE,qBAAC,KAAD;EAAK,KAAK;EAAS,GAAI,UAAU,MAAM;EAAG,GAAI;YAA9C;GACG,mBAAmB;GAEnB,WAAW,KAAK,MAAM,UAAU;IAM/B,IAAI,EAJF,UAAU,gBACT,kBACG,SAAS,WAAW,SAAS,oBAC7B,QAAQ,qBAEZ,OAAO;IAET,MAAM,YAAY,cAAc;IAGhC,OAAO,oBAACA,YAAD,EAAA,UAFe,WAAW,MAAM,SAEO,EAAY,GAApC,SAAoC;GAC5D,CAAC;GAEA,CAAC,mBAAmB;EAClB;;AAET,CAAC;AAED,aAAa,cAAc;AAC3B,aAAa,UAAUC;AACvB,aAAa,eAAe"}
|
|
1
|
+
{"version":3,"file":"OverflowList.mjs","names":["Fragment","classes"],"sources":["../../../src/components/OverflowList/OverflowList.tsx"],"sourcesContent":["// Originally based on https://github.com/Eliav2/react-responsive-overflow-list (MIT License)\n// Contains the modified version adapted for Mantine\nimport { cloneElement, useMemo, useRef, useState } from 'react';\nimport { Fragment } from 'react/jsx-runtime';\nimport { useIsomorphicEffect, useMergedRef } from '@mantine/hooks';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n Factory,\n genericFactory,\n getSpacing,\n MantineSpacing,\n StylesApiProps,\n useProps,\n useStyles,\n} from '../../core';\nimport { getRowPositionsData } from './get-row-position-data';\nimport { useDimensions } from './use-dimensions';\nimport classes from './OverflowList.module.css';\n\nexport type OverflowListStylesNames = 'root';\nexport type OverflowListCssVariables = {\n root: '--ol-gap';\n};\n\nexport interface OverflowListProps<T = any>\n extends BoxProps, StylesApiProps<OverflowListFactory>, ElementProps<'div', 'children'> {\n /** Array of items to display */\n data: T[];\n\n /** Function to render item */\n renderItem: (item: T, index: number) => React.ReactNode;\n\n /** Function to render hidden items */\n renderOverflow: (items: T[]) => React.ReactNode;\n\n /** Number of rows to display @default 1 */\n maxRows?: number;\n\n /** Maximum number of visible items @default Infinity */\n maxVisibleItems?: number;\n\n /** Key of `theme.spacing` or any valid CSS value for `gap`, numbers are converted to rem @default 'xs' */\n gap?: MantineSpacing;\n\n /** Direction from which items are collapsed when they overflow, `'end'` collapses last items, `'start'` collapses first items @default 'end' */\n collapseFrom?: 'start' | 'end';\n\n /** A function to resolve a unique key for each item. Used to detect when the contents of `data`\n * change (for example when items are reordered while the length stays the same) so the\n * visible/overflow split can be recomputed. Required to detect reordering when `data` contains\n * objects; for primitive items (strings, numbers) the item value is used by default. */\n getItemKey?: (item: T, index: number) => React.Key;\n}\n\nexport type OverflowListFactory = Factory<{\n props: OverflowListProps<any>;\n ref: HTMLDivElement;\n stylesNames: OverflowListStylesNames;\n vars: OverflowListCssVariables;\n signature: <T = any>(props: OverflowListProps<T>) => React.JSX.Element;\n}>;\n\nconst defaultProps = {\n maxRows: 1,\n maxVisibleItems: Infinity,\n} satisfies Partial<OverflowListProps<any>>;\n\nconst varsResolver = createVarsResolver<OverflowListFactory>((_, { gap }) => ({\n root: {\n '--ol-gap': getSpacing(gap),\n },\n}));\n\nfunction getDataSignature<T>(\n data: T[],\n getItemKey: ((item: T, index: number) => React.Key) | undefined\n): string {\n return data\n .map((item, index) => {\n if (getItemKey) {\n return getItemKey(item, index);\n }\n return item !== null && (typeof item === 'object' || typeof item === 'function')\n ? index\n : String(item);\n })\n .join('\\u0000');\n}\n\nexport const OverflowList = genericFactory<OverflowListFactory>((_props) => {\n const props = useProps('OverflowList', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n attributes,\n data,\n renderOverflow,\n renderItem,\n maxRows,\n maxVisibleItems,\n collapseFrom,\n getItemKey,\n ref,\n ...others\n } = props;\n\n const getStyles = useStyles<OverflowListFactory>({\n name: 'OverflowList',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n const [visibleCount, setVisibleCount] = useState(data.length);\n const [subtractCount, setSubtractCount] = useState(0);\n const [phase, setPhase] = useState<'normal' | 'measuring' | 'measuring-overflow-indicator'>(\n 'normal'\n );\n\n const containerRef = useRef<HTMLElement>(null);\n const rootRef = useMergedRef(containerRef, ref);\n const finalVisibleCount = visibleCount - subtractCount;\n const overflowCount = data.length - finalVisibleCount;\n const showOverflow = overflowCount > 0 && phase !== 'measuring';\n const isCollapseStart = collapseFrom === 'start';\n const overflowItems = isCollapseStart\n ? data.slice(0, data.length - finalVisibleCount)\n : data.slice(finalVisibleCount);\n const overflowElement = showOverflow ? renderOverflow?.(overflowItems) : null;\n\n const _overflowRef = useRef<HTMLElement>(null);\n const overflowRef = useMergedRef(_overflowRef, (overflowElement as any)?.ref);\n const dimensions = useDimensions(containerRef);\n const dataKey = useMemo(() => getDataSignature(data, getItemKey), [data, getItemKey]);\n\n useIsomorphicEffect(() => {\n setPhase('measuring');\n setVisibleCount(data.length);\n setSubtractCount(0);\n }, [dataKey, maxRows, collapseFrom]);\n\n useIsomorphicEffect(() => {\n if (phase === 'measuring') {\n countVisibleItems();\n setPhase('measuring-overflow-indicator');\n }\n }, [phase]);\n\n useIsomorphicEffect(() => {\n if (phase === 'measuring-overflow-indicator') {\n const updateWasNeeded = updateOverflowIndicator();\n if (!updateWasNeeded) {\n setPhase('normal');\n }\n }\n }, [phase, subtractCount]);\n\n useIsomorphicEffect(() => {\n if (phase === 'normal') {\n setPhase('measuring');\n setSubtractCount(0);\n }\n }, [dimensions]);\n\n const fitsInRows = (\n itemWidths: number[],\n containerWidth: number,\n columnGap: number,\n startIndex = 0\n ) => {\n let rows = 1;\n let rowWidth = 0;\n\n for (let i = startIndex; i < itemWidths.length; i += 1) {\n const width = itemWidths[i];\n const needed = rowWidth > 0 ? width + columnGap : width;\n\n if (rowWidth + needed > containerWidth && rowWidth > 0) {\n rows++;\n if (rows > maxRows!) {\n return false;\n }\n rowWidth = width;\n } else {\n rowWidth += needed;\n }\n }\n\n return true;\n };\n\n const countVisibleItems = () => {\n const rowData = getRowPositionsData(containerRef, _overflowRef);\n if (!rowData) {\n return;\n }\n\n const container = containerRef.current;\n if (!container) {\n return;\n }\n\n if (isCollapseStart) {\n const containerWidth = container.getBoundingClientRect().width;\n const columnGap = parseFloat(getComputedStyle(container).columnGap) || 0;\n const children = rowData.children;\n const widths = children.map((child) => child.getBoundingClientRect().width);\n\n let count = 0;\n for (let i = widths.length - 1; i >= 0; i--) {\n if (!fitsInRows(widths, containerWidth, columnGap, i)) {\n break;\n }\n count = widths.length - i;\n }\n\n count = Math.min(count, maxVisibleItems!);\n setVisibleCount(count);\n return;\n }\n\n if (data.length === 1) {\n const itemRef = rowData.itemsSizesMap[rowData.rowPositions[0]].elements.values().next().value;\n const containerWidth = container.getBoundingClientRect().width;\n const itemWidth = itemRef?.getBoundingClientRect().width ?? 0;\n\n if (itemWidth > containerWidth) {\n setVisibleCount(0);\n } else {\n setVisibleCount(1);\n }\n\n return;\n }\n\n const visibleRowPositions = rowData.rowPositions.slice(0, maxRows);\n\n let fittingCount = visibleRowPositions.reduce((acc, position) => {\n return acc + rowData.itemsSizesMap[position].elements.size;\n }, 0);\n\n fittingCount = Math.min(fittingCount, maxVisibleItems);\n setVisibleCount(fittingCount);\n };\n\n const updateOverflowIndicator = () => {\n if (!_overflowRef.current) {\n return false;\n }\n const rowData = getRowPositionsData(containerRef, _overflowRef);\n if (!rowData) {\n return false;\n }\n\n const { rowPositions, itemsSizesMap } = rowData;\n\n if (isCollapseStart) {\n const container = containerRef.current;\n if (!container) {\n return false;\n }\n const containerWidth = container.getBoundingClientRect().width;\n const columnGap = parseFloat(getComputedStyle(container).columnGap) || 0;\n const overflowWidth = _overflowRef.current.getBoundingClientRect().width;\n const children = rowData.children;\n const itemWidths = [\n overflowWidth,\n ...children.map((child) => child.getBoundingClientRect().width),\n ];\n\n if (!fitsInRows(itemWidths, containerWidth, columnGap)) {\n setSubtractCount((c) => c + 1);\n return true;\n }\n\n return false;\n }\n\n const overflowRect = _overflowRef.current.getBoundingClientRect();\n const overflowMiddleY = overflowRect.top + overflowRect.height / 2;\n const lastRowTop = rowPositions[rowPositions.length - 1];\n const lastRow = itemsSizesMap[lastRowTop];\n\n if (overflowMiddleY > lastRow.bottom) {\n setSubtractCount((c) => c + 1);\n return true;\n }\n\n return false;\n };\n\n const clonedOverflowElement = overflowElement\n ? cloneElement(overflowElement as React.ReactElement<any>, { ref: overflowRef })\n : null;\n\n let finalItems = data;\n if (maxVisibleItems) {\n finalItems = isCollapseStart\n ? finalItems.slice(-maxVisibleItems!)\n : finalItems.slice(0, maxVisibleItems);\n }\n\n const indexOffset = isCollapseStart ? data.length - finalItems.length : 0;\n\n return (\n <Box ref={rootRef} {...getStyles('root')} {...others}>\n {isCollapseStart && clonedOverflowElement}\n\n {finalItems.map((item, index) => {\n const isVisible =\n phase === 'measuring' ||\n (isCollapseStart\n ? index >= finalItems.length - finalVisibleCount\n : index < finalVisibleCount);\n if (!isVisible) {\n return null;\n }\n const dataIndex = indexOffset + index;\n const itemComponent = renderItem(item, dataIndex);\n\n return <Fragment key={dataIndex}>{itemComponent}</Fragment>;\n })}\n\n {!isCollapseStart && clonedOverflowElement}\n </Box>\n );\n});\n\nOverflowList.displayName = '@mantine/core/OverflowList';\nOverflowList.classes = classes;\nOverflowList.varsResolver = varsResolver;\n\nexport namespace OverflowList {\n export type Props = OverflowListProps;\n export type Factory = OverflowListFactory;\n export type StylesNames = OverflowListStylesNames;\n export type CssVariables = OverflowListCssVariables;\n}\n"],"mappings":";;;;;;;;;;;;;;AAiEA,MAAM,eAAe;CACnB,SAAS;CACT,iBAAiB;AACnB;AAEA,MAAM,eAAe,oBAAyC,GAAG,EAAE,WAAW,E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E,IAJwB,aAAa,MAAM,aAAa,SAAS,IAEjD,cADG,aAAa,aAAa,SAAS,GAGzB,CAAC,QAAQ;GACpC,kBAAkB,MAAM,IAAI,CAAC;GAC7B,OAAO;EACT;EAEA,OAAO;CACT;CAEA,MAAM,wBAAwB,kBAC1B,aAAa,iBAA4C,EAAE,KAAK,YAAY,CAAC,IAC7E;CAEJ,IAAI,aAAa;CACjB,IAAI,iBACF,aAAa,kBACT,WAAW,MAAM,CAAC,eAAgB,IAClC,WAAW,MAAM,GAAG,eAAe;CAGzC,MAAM,cAAc,kBAAkB,KAAK,SAAS,WAAW,SAAS;CAExE,OACE,qBAAC,KAAD;EAAK,KAAK;EAAS,GAAI,UAAU,MAAM;EAAG,GAAI;YAA9C;GACG,mBAAmB;GAEnB,WAAW,KAAK,MAAM,UAAU;IAM/B,IAAI,EAJF,UAAU,gBACT,kBACG,SAAS,WAAW,SAAS,oBAC7B,QAAQ,qBAEZ,OAAO;IAET,MAAM,YAAY,cAAc;IAGhC,OAAO,oBAACA,YAAD,EAAA,UAFe,WAAW,MAAM,SAEO,EAAY,GAApC,SAAoC;GAC5D,CAAC;GAEA,CAAC,mBAAmB;EAClB;;AAET,CAAC;AAED,aAAa,cAAc;AAC3B,aAAa,UAAUC;AACvB,aAAa,eAAe"}
|
|
@@ -54,6 +54,6 @@ const PaginationLast = createEdgeComponent({
|
|
|
54
54
|
type: "next"
|
|
55
55
|
});
|
|
56
56
|
//#endregion
|
|
57
|
-
export { PaginationFirst, PaginationLast, PaginationNext, PaginationPrevious };
|
|
57
|
+
export { PaginationFirst, PaginationLast, PaginationNext, PaginationPrevious, createEdgeComponent };
|
|
58
58
|
|
|
59
59
|
//# sourceMappingURL=PaginationEdges.mjs.map
|