tyrell-react 1.0.0-TC7
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/LICENSE +21 -0
- package/README.md +386 -0
- package/dist/components/TyButton.d.ts +50 -0
- package/dist/components/TyButton.d.ts.map +1 -0
- package/dist/components/TyButton.js +63 -0
- package/dist/components/TyButton.js.map +1 -0
- package/dist/components/TyCalendar.d.ts +63 -0
- package/dist/components/TyCalendar.d.ts.map +1 -0
- package/dist/components/TyCalendar.js +122 -0
- package/dist/components/TyCalendar.js.map +1 -0
- package/dist/components/TyCalendarMonth.d.ts +32 -0
- package/dist/components/TyCalendarMonth.d.ts.map +1 -0
- package/dist/components/TyCalendarMonth.js +54 -0
- package/dist/components/TyCalendarMonth.js.map +1 -0
- package/dist/components/TyCalendarNavigation.d.ts +21 -0
- package/dist/components/TyCalendarNavigation.d.ts.map +1 -0
- package/dist/components/TyCalendarNavigation.js +50 -0
- package/dist/components/TyCalendarNavigation.js.map +1 -0
- package/dist/components/TyCheckbox.d.ts +39 -0
- package/dist/components/TyCheckbox.d.ts.map +1 -0
- package/dist/components/TyCheckbox.js +68 -0
- package/dist/components/TyCheckbox.js.map +1 -0
- package/dist/components/TyCopy.d.ts +21 -0
- package/dist/components/TyCopy.d.ts.map +1 -0
- package/dist/components/TyCopy.js +42 -0
- package/dist/components/TyCopy.js.map +1 -0
- package/dist/components/TyDatePicker.d.ts +45 -0
- package/dist/components/TyDatePicker.d.ts.map +1 -0
- package/dist/components/TyDatePicker.js +114 -0
- package/dist/components/TyDatePicker.js.map +1 -0
- package/dist/components/TyDropdown.d.ts +51 -0
- package/dist/components/TyDropdown.d.ts.map +1 -0
- package/dist/components/TyDropdown.js +97 -0
- package/dist/components/TyDropdown.js.map +1 -0
- package/dist/components/TyIcon.d.ts +17 -0
- package/dist/components/TyIcon.d.ts.map +1 -0
- package/dist/components/TyIcon.js +41 -0
- package/dist/components/TyIcon.js.map +1 -0
- package/dist/components/TyInput.d.ts +65 -0
- package/dist/components/TyInput.d.ts.map +1 -0
- package/dist/components/TyInput.js +92 -0
- package/dist/components/TyInput.js.map +1 -0
- package/dist/components/TyModal.d.ts +29 -0
- package/dist/components/TyModal.d.ts.map +1 -0
- package/dist/components/TyModal.js +74 -0
- package/dist/components/TyModal.js.map +1 -0
- package/dist/components/TyMultiselect.d.ts +51 -0
- package/dist/components/TyMultiselect.d.ts.map +1 -0
- package/dist/components/TyMultiselect.js +92 -0
- package/dist/components/TyMultiselect.js.map +1 -0
- package/dist/components/TyOption.d.ts +10 -0
- package/dist/components/TyOption.d.ts.map +1 -0
- package/dist/components/TyOption.js +25 -0
- package/dist/components/TyOption.js.map +1 -0
- package/dist/components/TyPopup.d.ts +24 -0
- package/dist/components/TyPopup.d.ts.map +1 -0
- package/dist/components/TyPopup.js +61 -0
- package/dist/components/TyPopup.js.map +1 -0
- package/dist/components/TyResizeObserver.d.ts +11 -0
- package/dist/components/TyResizeObserver.d.ts.map +1 -0
- package/dist/components/TyResizeObserver.js +28 -0
- package/dist/components/TyResizeObserver.js.map +1 -0
- package/dist/components/TyScrollContainer.d.ts +25 -0
- package/dist/components/TyScrollContainer.d.ts.map +1 -0
- package/dist/components/TyScrollContainer.js +43 -0
- package/dist/components/TyScrollContainer.js.map +1 -0
- package/dist/components/TyStep.d.ts +17 -0
- package/dist/components/TyStep.d.ts.map +1 -0
- package/dist/components/TyStep.js +35 -0
- package/dist/components/TyStep.js.map +1 -0
- package/dist/components/TyTab.d.ts +13 -0
- package/dist/components/TyTab.d.ts.map +1 -0
- package/dist/components/TyTab.js +32 -0
- package/dist/components/TyTab.js.map +1 -0
- package/dist/components/TyTabs.d.ts +23 -0
- package/dist/components/TyTabs.d.ts.map +1 -0
- package/dist/components/TyTabs.js +48 -0
- package/dist/components/TyTabs.js.map +1 -0
- package/dist/components/TyTag.d.ts +22 -0
- package/dist/components/TyTag.d.ts.map +1 -0
- package/dist/components/TyTag.js +45 -0
- package/dist/components/TyTag.js.map +1 -0
- package/dist/components/TyTextarea.d.ts +37 -0
- package/dist/components/TyTextarea.d.ts.map +1 -0
- package/dist/components/TyTextarea.js +83 -0
- package/dist/components/TyTextarea.js.map +1 -0
- package/dist/components/TyTooltip.d.ts +17 -0
- package/dist/components/TyTooltip.d.ts.map +1 -0
- package/dist/components/TyTooltip.js +40 -0
- package/dist/components/TyTooltip.js.map +1 -0
- package/dist/components/TyWizard.d.ts +26 -0
- package/dist/components/TyWizard.d.ts.map +1 -0
- package/dist/components/TyWizard.js +50 -0
- package/dist/components/TyWizard.js.map +1 -0
- package/dist/components/index.d.ts +93 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +106 -0
- package/dist/components/index.js.map +1 -0
- package/package.json +46 -0
- package/src/components/EventConventionTest.tsx +155 -0
- package/src/components/TyButton.tsx +140 -0
- package/src/components/TyCalendar.tsx +244 -0
- package/src/components/TyCalendarMonth.tsx +108 -0
- package/src/components/TyCalendarNavigation.tsx +91 -0
- package/src/components/TyCheckbox.tsx +138 -0
- package/src/components/TyCopy.tsx +78 -0
- package/src/components/TyDatePicker.tsx +216 -0
- package/src/components/TyDropdown.tsx +205 -0
- package/src/components/TyIcon.tsx +72 -0
- package/src/components/TyInput.tsx +194 -0
- package/src/components/TyModal.tsx +142 -0
- package/src/components/TyMultiselect.tsx +189 -0
- package/src/components/TyOption.tsx +42 -0
- package/src/components/TyPopup.tsx +111 -0
- package/src/components/TyResizeObserver.tsx +54 -0
- package/src/components/TyScrollContainer.tsx +87 -0
- package/src/components/TyStep.tsx +71 -0
- package/src/components/TyTab.tsx +63 -0
- package/src/components/TyTabs.tsx +93 -0
- package/src/components/TyTag.tsx +79 -0
- package/src/components/TyTextarea.tsx +144 -0
- package/src/components/TyTooltip.tsx +83 -0
- package/src/components/TyWizard.tsx +99 -0
- package/src/components/index.ts +230 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
// Type definitions for Ty Calendar Navigation component
|
|
4
|
+
export interface TyCalendarNavigationProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onChange'> {
|
|
5
|
+
/** Display month (1-12) */
|
|
6
|
+
displayMonth?: number;
|
|
7
|
+
|
|
8
|
+
/** Display year */
|
|
9
|
+
displayYear?: number;
|
|
10
|
+
|
|
11
|
+
/** Locale for month name formatting */
|
|
12
|
+
locale?: string;
|
|
13
|
+
|
|
14
|
+
/** Navigation size */
|
|
15
|
+
size?: 'sm' | 'md' | 'lg';
|
|
16
|
+
|
|
17
|
+
/** Width of navigation */
|
|
18
|
+
width?: string;
|
|
19
|
+
|
|
20
|
+
/** Navigation change event handler */
|
|
21
|
+
onChange?: (event: CustomEvent<NavigationChangeDetail>) => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface NavigationChangeDetail {
|
|
25
|
+
month: number; // 1-12
|
|
26
|
+
year: number; // e.g., 2025
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// React wrapper for ty-calendar-navigation web component
|
|
30
|
+
export const TyCalendarNavigation = React.forwardRef<HTMLElement, TyCalendarNavigationProps>(
|
|
31
|
+
({
|
|
32
|
+
displayMonth,
|
|
33
|
+
displayYear,
|
|
34
|
+
locale,
|
|
35
|
+
size,
|
|
36
|
+
width,
|
|
37
|
+
onChange,
|
|
38
|
+
...props
|
|
39
|
+
}, ref) => {
|
|
40
|
+
const elementRef = useRef<HTMLElement>(null);
|
|
41
|
+
|
|
42
|
+
// Handle change events
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
const element = elementRef.current;
|
|
45
|
+
if (!element) return;
|
|
46
|
+
|
|
47
|
+
const handleChange = (event: Event) => {
|
|
48
|
+
if (onChange) {
|
|
49
|
+
onChange(event as CustomEvent<NavigationChangeDetail>);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
element.addEventListener('change', handleChange);
|
|
54
|
+
|
|
55
|
+
return () => {
|
|
56
|
+
element.removeEventListener('change', handleChange);
|
|
57
|
+
};
|
|
58
|
+
}, [onChange]);
|
|
59
|
+
|
|
60
|
+
// Combine refs if needed
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (ref && elementRef.current) {
|
|
63
|
+
if (typeof ref === 'function') {
|
|
64
|
+
ref(elementRef.current);
|
|
65
|
+
} else {
|
|
66
|
+
ref.current = elementRef.current;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}, [ref]);
|
|
70
|
+
|
|
71
|
+
// Convert React props to web component attributes
|
|
72
|
+
const webComponentProps: Record<string, any> = {
|
|
73
|
+
...props,
|
|
74
|
+
ref: elementRef,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// Add attributes
|
|
78
|
+
if (displayMonth !== undefined) webComponentProps['display-month'] = displayMonth;
|
|
79
|
+
if (displayYear !== undefined) webComponentProps['display-year'] = displayYear;
|
|
80
|
+
if (locale) webComponentProps.locale = locale;
|
|
81
|
+
if (size) webComponentProps.size = size;
|
|
82
|
+
if (width) webComponentProps.width = width;
|
|
83
|
+
|
|
84
|
+
return React.createElement(
|
|
85
|
+
'ty-calendar-navigation',
|
|
86
|
+
webComponentProps
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
TyCalendarNavigation.displayName = 'TyCalendarNavigation';
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
// Type definitions for Ty Checkbox component
|
|
4
|
+
export interface TyCheckboxProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onChange' | 'onInput'> {
|
|
5
|
+
/** Checked state */
|
|
6
|
+
checked?: boolean;
|
|
7
|
+
|
|
8
|
+
/** Form field value when checked */
|
|
9
|
+
value?: string;
|
|
10
|
+
|
|
11
|
+
/** Form field name */
|
|
12
|
+
name?: string;
|
|
13
|
+
|
|
14
|
+
/** Disable the checkbox */
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
|
|
17
|
+
/** Required field */
|
|
18
|
+
required?: boolean;
|
|
19
|
+
|
|
20
|
+
/** Error message */
|
|
21
|
+
error?: string;
|
|
22
|
+
|
|
23
|
+
/** Checkbox size */
|
|
24
|
+
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
25
|
+
|
|
26
|
+
/** Semantic styling variant */
|
|
27
|
+
flavor?: 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'neutral';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Fires when checkbox state changes (React convention)
|
|
31
|
+
* Maps to native 'input' event from ty-checkbox
|
|
32
|
+
*/
|
|
33
|
+
onChange?: (event: CustomEvent<TyCheckboxEventDetail>) => void;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Fires on blur if value changed (native DOM behavior)
|
|
37
|
+
* Maps to native 'change' event from ty-checkbox
|
|
38
|
+
*/
|
|
39
|
+
onChangeCommit?: (event: CustomEvent<TyCheckboxEventDetail>) => void;
|
|
40
|
+
|
|
41
|
+
/** Checkbox label content */
|
|
42
|
+
children?: React.ReactNode;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface TyCheckboxEventDetail {
|
|
46
|
+
value: boolean;
|
|
47
|
+
checked: boolean;
|
|
48
|
+
formValue: string | null;
|
|
49
|
+
originalEvent: Event;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// React wrapper for ty-checkbox web component
|
|
53
|
+
export const TyCheckbox = React.forwardRef<HTMLElement, TyCheckboxProps>(
|
|
54
|
+
({
|
|
55
|
+
children,
|
|
56
|
+
checked,
|
|
57
|
+
value,
|
|
58
|
+
name,
|
|
59
|
+
disabled,
|
|
60
|
+
required,
|
|
61
|
+
error,
|
|
62
|
+
size,
|
|
63
|
+
flavor,
|
|
64
|
+
onChange,
|
|
65
|
+
onChangeCommit,
|
|
66
|
+
...props
|
|
67
|
+
}, ref) => {
|
|
68
|
+
const elementRef = useRef<HTMLElement>(null);
|
|
69
|
+
|
|
70
|
+
// Handle change events
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
const element = elementRef.current;
|
|
73
|
+
if (!element) return;
|
|
74
|
+
|
|
75
|
+
// Map onChange to input event (React convention)
|
|
76
|
+
const handleInput = (event: Event) => {
|
|
77
|
+
if (onChange) {
|
|
78
|
+
onChange(event as CustomEvent<TyCheckboxEventDetail>);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// Map onChangeCommit to change event (blur behavior)
|
|
83
|
+
const handleChangeCommit = (event: Event) => {
|
|
84
|
+
if (onChangeCommit) {
|
|
85
|
+
onChangeCommit(event as CustomEvent<TyCheckboxEventDetail>);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// Map onChange → input event (React convention)
|
|
90
|
+
element.addEventListener('input', handleInput);
|
|
91
|
+
|
|
92
|
+
// Map onChangeCommit → change event (blur behavior)
|
|
93
|
+
element.addEventListener('change', handleChangeCommit);
|
|
94
|
+
|
|
95
|
+
return () => {
|
|
96
|
+
element.removeEventListener('input', handleInput);
|
|
97
|
+
element.removeEventListener('change', handleChangeCommit);
|
|
98
|
+
};
|
|
99
|
+
}, [onChange, onChangeCommit]);
|
|
100
|
+
|
|
101
|
+
// Combine refs if needed
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
if (ref && elementRef.current) {
|
|
104
|
+
if (typeof ref === 'function') {
|
|
105
|
+
ref(elementRef.current);
|
|
106
|
+
} else {
|
|
107
|
+
ref.current = elementRef.current;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}, [ref]);
|
|
111
|
+
|
|
112
|
+
// Convert React props to web component attributes
|
|
113
|
+
const webComponentProps: Record<string, any> = {
|
|
114
|
+
...props,
|
|
115
|
+
ref: elementRef,
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// Add boolean attributes
|
|
119
|
+
if (checked) webComponentProps.checked = '';
|
|
120
|
+
if (disabled) webComponentProps.disabled = '';
|
|
121
|
+
if (required) webComponentProps.required = '';
|
|
122
|
+
|
|
123
|
+
// Add string attributes
|
|
124
|
+
if (value) webComponentProps.value = value;
|
|
125
|
+
if (name) webComponentProps.name = name;
|
|
126
|
+
if (error) webComponentProps.error = error;
|
|
127
|
+
if (size) webComponentProps.size = size;
|
|
128
|
+
if (flavor) webComponentProps.flavor = flavor;
|
|
129
|
+
|
|
130
|
+
return React.createElement(
|
|
131
|
+
'ty-checkbox',
|
|
132
|
+
webComponentProps,
|
|
133
|
+
children
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
TyCheckbox.displayName = 'TyCheckbox';
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
// Type definitions for Ty Copy component
|
|
4
|
+
export interface TyCopyProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onChange'> {
|
|
5
|
+
/** Text to copy */
|
|
6
|
+
value?: string;
|
|
7
|
+
|
|
8
|
+
/** Field label */
|
|
9
|
+
label?: string;
|
|
10
|
+
|
|
11
|
+
/** Component size */
|
|
12
|
+
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
13
|
+
|
|
14
|
+
/** Semantic styling variant */
|
|
15
|
+
flavor?: 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'neutral';
|
|
16
|
+
|
|
17
|
+
/** Display format */
|
|
18
|
+
format?: 'text' | 'code';
|
|
19
|
+
|
|
20
|
+
/** Multi-line display */
|
|
21
|
+
multiline?: boolean;
|
|
22
|
+
|
|
23
|
+
/** Disable the field */
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
|
|
26
|
+
/** Required field */
|
|
27
|
+
required?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// React wrapper for ty-copy web component
|
|
31
|
+
export const TyCopy = React.forwardRef<HTMLElement, TyCopyProps>(
|
|
32
|
+
({
|
|
33
|
+
value,
|
|
34
|
+
label,
|
|
35
|
+
size,
|
|
36
|
+
flavor,
|
|
37
|
+
format,
|
|
38
|
+
multiline,
|
|
39
|
+
disabled,
|
|
40
|
+
required,
|
|
41
|
+
...props
|
|
42
|
+
}, ref) => {
|
|
43
|
+
const elementRef = useRef<HTMLElement>(null);
|
|
44
|
+
|
|
45
|
+
// Handle ref forwarding
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (ref && elementRef.current) {
|
|
48
|
+
if (typeof ref === 'function') {
|
|
49
|
+
ref(elementRef.current);
|
|
50
|
+
} else {
|
|
51
|
+
ref.current = elementRef.current;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}, [ref]);
|
|
55
|
+
|
|
56
|
+
// Convert React props to web component attributes
|
|
57
|
+
const webComponentProps: Record<string, any> = {
|
|
58
|
+
...props,
|
|
59
|
+
ref: elementRef,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// Add string attributes
|
|
63
|
+
if (value) webComponentProps.value = value;
|
|
64
|
+
if (label) webComponentProps.label = label;
|
|
65
|
+
if (size) webComponentProps.size = size;
|
|
66
|
+
if (flavor) webComponentProps.flavor = flavor;
|
|
67
|
+
if (format) webComponentProps.format = format;
|
|
68
|
+
|
|
69
|
+
// Add boolean attributes
|
|
70
|
+
if (multiline) webComponentProps.multiline = '';
|
|
71
|
+
if (disabled) webComponentProps.disabled = '';
|
|
72
|
+
if (required) webComponentProps.required = '';
|
|
73
|
+
|
|
74
|
+
return React.createElement('ty-copy', webComponentProps);
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
TyCopy.displayName = 'TyCopy';
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
// Type definitions for Ty DatePicker component
|
|
4
|
+
export interface TyDatePickerEventDetail {
|
|
5
|
+
/** The selected date value (ISO string or formatted string based on format) */
|
|
6
|
+
value: string | null;
|
|
7
|
+
/** The selected date as milliseconds since epoch */
|
|
8
|
+
milliseconds: number | null;
|
|
9
|
+
/** Source of the change: "selection" | "time-change" | "clear" | "external" */
|
|
10
|
+
source: 'selection' | 'time-change' | 'clear' | 'external';
|
|
11
|
+
/** Formatted display value */
|
|
12
|
+
formatted: string | null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface TyDatePickerProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onChange'> {
|
|
16
|
+
/** The selected date value (ISO string or formatted string) */
|
|
17
|
+
value?: string;
|
|
18
|
+
|
|
19
|
+
/** Input size: "sm" | "md" | "lg" */
|
|
20
|
+
size?: 'sm' | 'md' | 'lg';
|
|
21
|
+
|
|
22
|
+
/** Visual flavor: "default" | "success" | "danger" | "warning" */
|
|
23
|
+
flavor?: 'default' | 'success' | 'danger' | 'warning';
|
|
24
|
+
|
|
25
|
+
/** Label text displayed above the input */
|
|
26
|
+
label?: string;
|
|
27
|
+
|
|
28
|
+
/** Placeholder text when no date is selected */
|
|
29
|
+
placeholder?: string;
|
|
30
|
+
|
|
31
|
+
/** Whether the field is required */
|
|
32
|
+
required?: boolean;
|
|
33
|
+
|
|
34
|
+
/** Whether the field is disabled */
|
|
35
|
+
disabled?: boolean;
|
|
36
|
+
|
|
37
|
+
/** Form field name for form submission */
|
|
38
|
+
name?: string;
|
|
39
|
+
|
|
40
|
+
/** Whether to show a clear button */
|
|
41
|
+
clearable?: boolean;
|
|
42
|
+
|
|
43
|
+
/** Date format: "short" | "medium" | "long" | "full" | custom format string */
|
|
44
|
+
format?: 'short' | 'medium' | 'long' | 'full' | string;
|
|
45
|
+
|
|
46
|
+
/** Locale for date formatting (e.g., "en-US", "de-DE") */
|
|
47
|
+
locale?: string;
|
|
48
|
+
|
|
49
|
+
/** Whether to include time selection */
|
|
50
|
+
withTime?: boolean;
|
|
51
|
+
|
|
52
|
+
/** Callback when the date value changes */
|
|
53
|
+
onChange?: (event: CustomEvent<TyDatePickerEventDetail>) => void;
|
|
54
|
+
|
|
55
|
+
/** Callback when the dropdown opens */
|
|
56
|
+
onOpen?: (event: CustomEvent<{}>) => void;
|
|
57
|
+
|
|
58
|
+
/** Callback when the dropdown closes */
|
|
59
|
+
onClose?: (event: CustomEvent<{}>) => void;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// React wrapper for ty-date-picker web component
|
|
63
|
+
export const TyDatePicker = React.forwardRef<HTMLElement, TyDatePickerProps>(
|
|
64
|
+
({
|
|
65
|
+
value,
|
|
66
|
+
size,
|
|
67
|
+
flavor,
|
|
68
|
+
label,
|
|
69
|
+
placeholder,
|
|
70
|
+
required,
|
|
71
|
+
disabled,
|
|
72
|
+
name,
|
|
73
|
+
clearable,
|
|
74
|
+
format,
|
|
75
|
+
locale,
|
|
76
|
+
withTime,
|
|
77
|
+
onChange,
|
|
78
|
+
onOpen,
|
|
79
|
+
onClose,
|
|
80
|
+
...props
|
|
81
|
+
}, ref) => {
|
|
82
|
+
const elementRef = useRef<HTMLElement>(null);
|
|
83
|
+
|
|
84
|
+
// Handle ref forwarding
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (ref && elementRef.current) {
|
|
87
|
+
if (typeof ref === 'function') {
|
|
88
|
+
ref(elementRef.current);
|
|
89
|
+
} else {
|
|
90
|
+
ref.current = elementRef.current;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}, [ref]);
|
|
94
|
+
|
|
95
|
+
// Sync value property with the web component
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
const element = elementRef.current;
|
|
98
|
+
if (element && value !== undefined) {
|
|
99
|
+
// Set the value property directly on the element
|
|
100
|
+
(element as any).value = value || '';
|
|
101
|
+
}
|
|
102
|
+
}, [value]);
|
|
103
|
+
|
|
104
|
+
// Handle change events
|
|
105
|
+
const handleChange = useCallback((event: Event) => {
|
|
106
|
+
const customEvent = event as CustomEvent<TyDatePickerEventDetail>;
|
|
107
|
+
if (onChange) {
|
|
108
|
+
onChange(customEvent);
|
|
109
|
+
}
|
|
110
|
+
}, [onChange]);
|
|
111
|
+
|
|
112
|
+
// Handle open events
|
|
113
|
+
const handleOpen = useCallback((event: Event) => {
|
|
114
|
+
const customEvent = event as CustomEvent<{}>;
|
|
115
|
+
if (onOpen) {
|
|
116
|
+
onOpen(customEvent);
|
|
117
|
+
}
|
|
118
|
+
}, [onOpen]);
|
|
119
|
+
|
|
120
|
+
// Handle close events
|
|
121
|
+
const handleClose = useCallback((event: Event) => {
|
|
122
|
+
const customEvent = event as CustomEvent<{}>;
|
|
123
|
+
if (onClose) {
|
|
124
|
+
onClose(customEvent);
|
|
125
|
+
}
|
|
126
|
+
}, [onClose]);
|
|
127
|
+
|
|
128
|
+
// Set up event listeners
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
const element = elementRef.current;
|
|
131
|
+
if (!element) return;
|
|
132
|
+
|
|
133
|
+
const listeners: Array<[string, EventListener]> = [];
|
|
134
|
+
|
|
135
|
+
if (onChange) {
|
|
136
|
+
element.addEventListener('change', handleChange);
|
|
137
|
+
listeners.push(['change', handleChange]);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (onOpen) {
|
|
141
|
+
element.addEventListener('open', handleOpen);
|
|
142
|
+
listeners.push(['open', handleOpen]);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (onClose) {
|
|
146
|
+
element.addEventListener('close', handleClose);
|
|
147
|
+
listeners.push(['close', handleClose]);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return () => {
|
|
151
|
+
listeners.forEach(([eventName, handler]) => {
|
|
152
|
+
element.removeEventListener(eventName, handler);
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
}, [handleChange, handleOpen, handleClose, onChange, onOpen, onClose]);
|
|
156
|
+
|
|
157
|
+
// Convert React props to web component attributes
|
|
158
|
+
const webComponentProps: Record<string, any> = {
|
|
159
|
+
...props,
|
|
160
|
+
ref: elementRef,
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// Add optional attributes only if they have values
|
|
164
|
+
if (value !== undefined) {
|
|
165
|
+
webComponentProps.value = value;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (size) {
|
|
169
|
+
webComponentProps.size = size;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (flavor) {
|
|
173
|
+
webComponentProps.flavor = flavor;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (label) {
|
|
177
|
+
webComponentProps.label = label;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (placeholder) {
|
|
181
|
+
webComponentProps.placeholder = placeholder;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (required) {
|
|
185
|
+
webComponentProps.required = ''; // Boolean attributes as empty string
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (disabled) {
|
|
189
|
+
webComponentProps.disabled = ''; // Boolean attributes as empty string
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (name) {
|
|
193
|
+
webComponentProps.name = name;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (clearable) {
|
|
197
|
+
webComponentProps.clearable = ''; // Boolean attributes as empty string
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (format) {
|
|
201
|
+
webComponentProps.format = format;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (locale) {
|
|
205
|
+
webComponentProps.locale = locale;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (withTime) {
|
|
209
|
+
webComponentProps['with-time'] = ''; // Convert camelCase to kebab-case
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return React.createElement('ty-date-picker', webComponentProps);
|
|
213
|
+
}
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
TyDatePicker.displayName = 'TyDatePicker';
|