@recursica/mantine-adapter 0.22.0 → 0.23.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.
@@ -1,7 +1,168 @@
1
- import React from "react";
1
+ import React, { forwardRef } from "react";
2
+ import { DatePickerInput, type DatePickerInputProps } from "@mantine/dates";
3
+ import { type ReadOnlyControlProps } from "@recursica/adapter-common";
4
+ import {
5
+ filterStylingProps,
6
+ type RecursicaOverStyled,
7
+ } from "../../utils/filterStylingProps";
8
+ import { type RecursicaFormControlWrapperProps } from "../FormControlWrapper/FormControlWrapper";
9
+ import { WithReadOnlyWrapper } from "../ReadOnlyField/WithReadOnlyWrapper";
10
+ import styles from "./DatePicker.module.css";
2
11
 
3
- export type DatePickerProps = React.HTMLAttributes<HTMLDivElement>;
12
+ export interface RecursicaDatePickerProps
13
+ extends Omit<
14
+ DatePickerInputProps,
15
+ | "size"
16
+ | "variant"
17
+ | "radius"
18
+ | "wrapperProps"
19
+ | "label"
20
+ | "error"
21
+ | "required"
22
+ | "withAsterisk"
23
+ | "id"
24
+ | "description"
25
+ >,
26
+ Pick<
27
+ DatePickerInputProps,
28
+ "label" | "error" | "required" | "withAsterisk" | "id"
29
+ >,
30
+ Omit<
31
+ RecursicaFormControlWrapperProps,
32
+ "controlMaxWidth" | "controlMinWidth"
33
+ >,
34
+ ReadOnlyControlProps {}
4
35
 
5
- export const DatePicker: React.FC<DatePickerProps> = (props) => {
6
- return <div {...props}>DatePicker</div>;
7
- };
36
+ export type DatePickerProps = RecursicaOverStyled<RecursicaDatePickerProps>;
37
+
38
+ export const DatePicker = forwardRef<HTMLInputElement, DatePickerProps>(
39
+ function DatePicker(props, ref) {
40
+ const {
41
+ overStyled = false,
42
+ formLayout = "stacked",
43
+
44
+ // Label & Wrapper Maps
45
+ labelSize,
46
+ labelAlignment,
47
+ labelOptionalText,
48
+ labelWithEditIcon,
49
+ onLabelEditClick,
50
+
51
+ label,
52
+ assistiveText,
53
+ assistiveWithIcon,
54
+ error,
55
+ required,
56
+ withAsterisk,
57
+ id,
58
+ className,
59
+ style,
60
+ disabled,
61
+ readOnly,
62
+ readOnlyComponent,
63
+ emptyValueComponent,
64
+ value,
65
+ defaultValue,
66
+ ...rest
67
+ } = props;
68
+
69
+ const sanitizedProps = filterStylingProps(rest, overStyled);
70
+ const restRecord = sanitizedProps as Record<string, unknown>;
71
+
72
+ // Delete prohibited sizing hooks from bypassing variables natively
73
+ delete restRecord["size"];
74
+ delete restRecord["variant"];
75
+ delete restRecord["radius"];
76
+ delete restRecord["description"]; // Managed by FormControlWrapper via assistiveText
77
+
78
+ // Securely map core native blocks down ensuring nested CSS modules map precisely
79
+ const mergedClassNames: Partial<Record<string, string>> = {
80
+ wrapper: styles.root, // The nested Input internal relative wrapper bounding box
81
+ input: styles.input,
82
+ section: styles.section,
83
+ dropdown: styles.dropdown,
84
+ day: styles.day,
85
+ calendarHeader: styles.calendarHeader,
86
+ };
87
+
88
+ const classNamesProp = restRecord.classNames;
89
+ if (
90
+ classNamesProp &&
91
+ typeof classNamesProp === "object" &&
92
+ !Array.isArray(classNamesProp)
93
+ ) {
94
+ const o = classNamesProp as Partial<Record<string, string>>;
95
+ mergedClassNames.wrapper = o.wrapper
96
+ ? `${styles.root} ${o.wrapper}`
97
+ : styles.root;
98
+ mergedClassNames.input = o.input
99
+ ? `${styles.input} ${o.input}`
100
+ : styles.input;
101
+ mergedClassNames.section = o.section
102
+ ? `${styles.section} ${o.section}`
103
+ : styles.section;
104
+ }
105
+
106
+ const wrapperClass = className
107
+ ? `${styles.layoutOverride} ${className}`
108
+ : styles.layoutOverride;
109
+
110
+ return (
111
+ <WithReadOnlyWrapper
112
+ className={wrapperClass}
113
+ style={style as React.CSSProperties}
114
+ controlMaxWidth={undefined}
115
+ controlMinWidth={undefined}
116
+ overStyled={overStyled as true}
117
+ formLayout={formLayout}
118
+ labelSize={labelSize}
119
+ labelAlignment={labelAlignment}
120
+ labelOptionalText={labelOptionalText}
121
+ labelWithEditIcon={labelWithEditIcon}
122
+ onLabelEditClick={onLabelEditClick}
123
+ label={label}
124
+ assistiveText={assistiveText}
125
+ assistiveWithIcon={assistiveWithIcon}
126
+ error={error}
127
+ required={required}
128
+ withAsterisk={withAsterisk}
129
+ id={id}
130
+ readOnly={readOnly}
131
+ readOnlyComponent={readOnlyComponent}
132
+ emptyValueComponent={emptyValueComponent}
133
+ readOnlyType="text"
134
+ readOnlyValue={
135
+ value !== undefined
136
+ ? String(value)
137
+ : defaultValue
138
+ ? String(defaultValue)
139
+ : undefined
140
+ }
141
+ readOnlyNativeProps={props}
142
+ activeComponent={
143
+ /* Naked Input execution safely decoupled from Mantine's macro Input.Wrapper DOM hooks */
144
+ <DatePickerInput
145
+ ref={ref}
146
+ classNames={mergedClassNames}
147
+ disabled={disabled}
148
+ // @ts-expect-error Mantine 8 DatePickerInput types are overly complex for unified wrappers
149
+ value={value}
150
+ // @ts-expect-error Mantine 8 DatePickerInput types are overly complex for unified wrappers
151
+ defaultValue={defaultValue}
152
+ label={undefined} // Disable Mantine's native label
153
+ description={undefined} // Disable Mantine's native description
154
+ error={undefined} // Disable Mantine's native error text (handled by wrapper)
155
+ withAsterisk={false} // Handled by wrapper
156
+ wrapperProps={{
157
+ "data-disabled": disabled ? "true" : undefined,
158
+ "data-error": error ? "true" : undefined,
159
+ }}
160
+ {...(sanitizedProps as unknown as DatePickerInputProps)}
161
+ />
162
+ }
163
+ />
164
+ );
165
+ },
166
+ );
167
+
168
+ DatePicker.displayName = "DatePicker";
@@ -64,6 +64,7 @@
64
64
  --form-field-vertical-padding: var(
65
65
  --recursica_ui-kit_globals_form_field_size_vertical-padding
66
66
  );
67
+ color: var(--form-field-text-valued);
67
68
  }
68
69
 
69
70
  .inputSection {
@@ -17,8 +17,7 @@ Mantine natively sets sizing dynamically at the component root and parses thickn
17
17
 
18
18
  #### Specific CSS Targeting Hacks Used
19
19
 
20
- - `border-width` structurally styles the `thickness` configuration of the `oval` variant by resolving `--recursica_ui-kit_components_loader_variants_sizes_..._properties_thickness`.
21
- - For non-oval variants, `border-radius` natively maps downwards to targeting component `span` children within the wrapper to capture `<span className="mantine-Loader-dot" />` geometries safely without polluting the flex wrapper natively.
20
+ - `border-width` and `border-radius` structurally style the `thickness` and `border-radius` configuration of the `oval` variant on the `::after` pseudo-element by resolving `--recursica_ui-kit_components_loader_variants_sizes_..._properties_thickness` and `_border-radius`.
22
21
 
23
22
  ### Unsupported Properties
24
23
 
@@ -14,12 +14,10 @@
14
14
  --recursica_ui-kit_components_loader_variants_sizes_small_properties_size
15
15
  );
16
16
  }
17
- .root[data-size="small"][data-variant="oval"] {
17
+ .root[data-size="small"][data-variant="oval"]::after {
18
18
  border-width: var(
19
19
  --recursica_ui-kit_components_loader_variants_sizes_small_properties_thickness
20
20
  );
21
- }
22
- .root[data-size="small"]:not([data-variant="oval"]) span {
23
21
  border-radius: var(
24
22
  --recursica_ui-kit_components_loader_variants_sizes_small_properties_border-radius
25
23
  );
@@ -31,12 +29,10 @@
31
29
  --recursica_ui-kit_components_loader_variants_sizes_default_properties_size
32
30
  );
33
31
  }
34
- .root[data-size="default"][data-variant="oval"] {
32
+ .root[data-size="default"][data-variant="oval"]::after {
35
33
  border-width: var(
36
34
  --recursica_ui-kit_components_loader_variants_sizes_default_properties_thickness
37
35
  );
38
- }
39
- .root[data-size="default"]:not([data-variant="oval"]) span {
40
36
  border-radius: var(
41
37
  --recursica_ui-kit_components_loader_variants_sizes_default_properties_border-radius
42
38
  );
@@ -48,12 +44,10 @@
48
44
  --recursica_ui-kit_components_loader_variants_sizes_large_properties_size
49
45
  );
50
46
  }
51
- .root[data-size="large"][data-variant="oval"] {
47
+ .root[data-size="large"][data-variant="oval"]::after {
52
48
  border-width: var(
53
49
  --recursica_ui-kit_components_loader_variants_sizes_large_properties_thickness
54
50
  );
55
- }
56
- .root[data-size="large"]:not([data-variant="oval"]) span {
57
51
  border-radius: var(
58
52
  --recursica_ui-kit_components_loader_variants_sizes_large_properties_border-radius
59
53
  );
@@ -0,0 +1,49 @@
1
+ # Slider Implementation Notes
2
+
3
+ This document contains specific design decisions, architectural constraints, and hacks required to bridge the Recursica design system with Mantine's underlying `Slider` primitive.
4
+
5
+ ## 1. Bidirectional State Synchronization
6
+
7
+ **Decision:** Maintain a highly responsive, bidirectional connection between the sliding track value and the adjacent numeric text input.
8
+ **Implementation:**
9
+
10
+ - The slider track requires a clean `number` state, whereas the text box requires a `string` state (`inputValue`) to allow typing intermediate characters like decimals (`2.`), negative signs (`-`), or empty text without breaking standard React input binding.
11
+ - A `useEffect` hook continuously feeds the outer numeric state changes back into the text input value as a string representation.
12
+ - Input changes instantly parsed as float clamp bounds securely. On blur (`onBlur`), the input state is automatically sanitized and reset to the clean, clamped string representation of the final track value.
13
+
14
+ ## 2. Outer Form Control Wrapper Integration
15
+
16
+ **Decision:** Bypass Mantine's native `Input.Wrapper` and `label` properties.
17
+ **Implementation:**
18
+
19
+ - Universal form wrappers like `<FormControlWrapper>` and `<WithReadOnlyWrapper>` handle the outer layout architecture, including labels, assistive text, error states, and optional edit-triggering fields.
20
+ - Therefore, we map the outer form label directly to the `label` property of the `Slider` (delegated to the wrapper), and rename Mantine's internal dragging tooltip label property to `tooltipLabel`.
21
+
22
+ ## 3. Custom Min-Max Labels and Step Indicators
23
+
24
+ **Decision:** Enforce rigid typography tokens on lower bounds and custom mark indicators.
25
+ **Implementation:**
26
+
27
+ - Mantine's native mark and step structures are fully styles-mapped back to our scoped variables in `Slider.module.css`.
28
+ - Min and Max numeric guides are rendered directly to the left and right of the slider track, centered vertically and spaced automatically using standard input gaps, while dynamically fetching custom typography tokens for min-max labels to avoid hardcoded formatting constraints.
29
+
30
+ ## 4. Visual Overrides for Stacked and Side-by-Side Spacing
31
+
32
+ **Decision:** Enforce layout margins dynamically based on container orientation parameters.
33
+ **Implementation:**
34
+
35
+ - Using custom layouts (e.g. `stacked` and `side-by-side`), we override the margins by assigning the component-specific Figma spacing variables to the unified `--form-control-margin-bottom` property.
36
+
37
+ ## 5. Right-Aligned Floating Current Value
38
+
39
+ **Decision:** Position the current active value of the slider directly above the max guide (or right-side element) on the right side of the track.
40
+ **Implementation:**
41
+
42
+ - Wrap the max guide element in a relative layout container (`.rightGuideContainer`) to provide a positioning anchor.
43
+ - Place the active value element (`.currentValue`) inside `.rightGuideContainer` and position it absolutely (`bottom: calc(100% + var(--recursica_ui-kit_globals_form_properties_label-field-gap-vertical, 8px))`, `right: 0`).
44
+ - This absolute positioning strategy guarantees that the active value floats cleanly above the track's right side, while aligning it vertically on the Y-axis to sit in perfect baseline alignment with the component's left-aligned form label.
45
+ - Set typography using the Figma-aligned component-specific read-only value variables (`--recursica_ui-kit_components_slider_properties_read-only-value_...`).
46
+ - Allow the text color of both the floating current value (`.currentValue`) and the component's read-only value (`.readOnlyValue`) to naturally inherit from their parent states/form globals, automatically supporting default (`--form-field-text-valued`), disabled (`--form-field-disabled-text`), and error colors without explicit color overrides, matching the min/max guides.
47
+ - If `showInput` is enabled, the floating `.currentValue` is hidden since the active value is already displayed and editable within the adjacent numeric text input, avoiding visual redundancy.
48
+ - In `side-by-side` form layouts, the `.currentValue` is positioned inline (static positioning) to the right of the max label rather than floating above it, centered vertically with the max label and aligned right to the container. This uses CSS flexbox ordering (`order: 2` for `.currentValue` and `order: 1` for `.minMaxGuide`) to visually swap their positions while preserving clean, semantic DOM ordering.
49
+ - To ensure perfect, pixel-perfect vertical track alignment between sliders that show numeric text inputs (`showInput={true}`) and sliders that display the active inline value (`showInput={false}`), the `.currentValue` element is globally given a width equal to the input width (`var(--recursica_ui-kit_components_slider_properties_input-width)`) and right-aligned (`text-align: right`). In `side-by-side` layouts, `.rightGuideContainer`'s flex gap is also matched to the horizontal input-to-track gap (`var(--recursica_ui-kit_components_slider_properties_input-gap)`), making the horizontal space occupied by the rightmost elements exactly identical in both component modes.