@recursica/mantine-adapter 0.48.0 → 0.49.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.
Files changed (39) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/index.d.ts +42 -7
  3. package/dist/mantine-adapter.cjs +2 -2
  4. package/dist/mantine-adapter.cjs.map +1 -1
  5. package/dist/mantine-adapter.css +1 -1
  6. package/dist/mantine-adapter.js +1662 -1613
  7. package/dist/mantine-adapter.js.map +1 -1
  8. package/package.json +2 -2
  9. package/src/components/Accordion/Accordion.module.css +11 -0
  10. package/src/components/AutoComplete/AUTOCOMPLETE_IMPLEMENTATION_NOTES.md +18 -2
  11. package/src/components/AutoComplete/AutoComplete.module.css +127 -12
  12. package/src/components/AutoComplete/AutoComplete.stories.tsx +149 -0
  13. package/src/components/AutoComplete/AutoComplete.tsx +29 -1
  14. package/src/components/AutoComplete/USAGE.md +32 -2
  15. package/src/components/Button/Button.module.css +10 -0
  16. package/src/components/Card/Card.stories.tsx +2 -4
  17. package/src/components/Chip/Chip.module.css +9 -0
  18. package/src/components/DatePicker/DatePicker.module.css +16 -0
  19. package/src/components/Dropdown/DROPDOWN_IMPLEMENTATION_NOTES.md +3 -0
  20. package/src/components/Dropdown/Dropdown.module.css +124 -6
  21. package/src/components/Dropdown/Dropdown.stories.tsx +149 -0
  22. package/src/components/Dropdown/Dropdown.tsx +30 -2
  23. package/src/components/Dropdown/USAGE.md +21 -0
  24. package/src/components/FileInput/FILEINPUT_IMPLEMENTATION_NOTES.md +4 -1
  25. package/src/components/FileInput/FileInput.module.css +17 -0
  26. package/src/components/FileUpload/FileUpload.module.css +6 -0
  27. package/src/components/Link/Link.module.css +5 -0
  28. package/src/components/Menu/Menu.module.css +6 -0
  29. package/src/components/NumberInput/NumberInput.module.css +8 -0
  30. package/src/components/Pagination/Pagination.module.css +7 -0
  31. package/src/components/Slider/Slider.module.css +8 -0
  32. package/src/components/Switch/Switch.module.css +8 -0
  33. package/src/components/Table/Table.module.css +6 -0
  34. package/src/components/Tabs/Tabs.module.css +7 -0
  35. package/src/components/TextArea/TextArea.module.css +8 -0
  36. package/src/components/TextField/TextField.module.css +8 -0
  37. package/src/components/TimePicker/TimePicker.module.css +8 -0
  38. package/src/components/Tree/Tree.module.css +11 -0
  39. package/src/utils/renderRichOption.tsx +65 -0
@@ -0,0 +1,65 @@
1
+ import React from "react";
2
+ import {
3
+ type ComboboxStringItem,
4
+ type ComboboxLikeRenderOptionInput,
5
+ } from "@mantine/core";
6
+
7
+ // `ComboboxStringItem`/`ComboboxItem` only type `value`/`label`/`disabled` —
8
+ // `leadingIcon`/`supportingText` are extra fields Mantine's own `getParsedComboboxData` passes
9
+ // through untouched whenever an item already has both `value` and `label` (see
10
+ // get-parsed-combobox-data.mjs), so they reach `option` here at runtime even though the upstream
11
+ // type doesn't know about them. Generic over both Autocomplete's `ComboboxStringItem` (optional
12
+ // `label`) and Dropdown's `ComboboxItem` (required `label`) — the same renderer serves both.
13
+ type RichComboboxItem = ComboboxStringItem & {
14
+ label?: string;
15
+ leadingIcon?: React.ReactNode;
16
+ supportingText?: string;
17
+ };
18
+
19
+ export interface RichOptionClassNames {
20
+ optionContent: string;
21
+ optionIcon: string;
22
+ optionText: string;
23
+ /** Combined with `optionText` when `wrapItemText` is true — see `renderRichOption` below. */
24
+ optionTextWrap: string;
25
+ optionSupportingText: string;
26
+ }
27
+
28
+ /**
29
+ * `renderOption` for Autocomplete/Dropdown that renders an item's `leadingIcon`/`supportingText`
30
+ * (see MANTINE_ADAPTER_RICH_OPTION_DATA.md) inside the option row. Falls back to plain
31
+ * `option.label` — the same rendering Mantine uses when no `renderOption` is supplied at all — so
32
+ * items without the new fields are unaffected.
33
+ *
34
+ * `wrapItemText` (default `false`) controls whether `label`/`supportingText` wrap onto additional
35
+ * lines or truncate to a single line with an ellipsis.
36
+ */
37
+ export function renderRichOption<T extends ComboboxStringItem>(
38
+ { option }: ComboboxLikeRenderOptionInput<T>,
39
+ classNames: RichOptionClassNames,
40
+ wrapItemText = false,
41
+ ): React.ReactNode {
42
+ const { label, leadingIcon, supportingText } = option as RichComboboxItem;
43
+ const displayLabel = label ?? option.value;
44
+ if (!leadingIcon && !supportingText) {
45
+ return displayLabel;
46
+ }
47
+ const optionTextClassName = wrapItemText
48
+ ? `${classNames.optionText} ${classNames.optionTextWrap}`
49
+ : classNames.optionText;
50
+ return (
51
+ <span className={classNames.optionContent}>
52
+ {leadingIcon && (
53
+ <span className={classNames.optionIcon}>{leadingIcon}</span>
54
+ )}
55
+ <span className={optionTextClassName}>
56
+ <span>{displayLabel}</span>
57
+ {supportingText && (
58
+ <span className={classNames.optionSupportingText}>
59
+ {supportingText}
60
+ </span>
61
+ )}
62
+ </span>
63
+ </span>
64
+ );
65
+ }