tyrell-react 1.0.0-TC10

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 (139) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +410 -0
  3. package/dist/components/TyButton.d.ts +50 -0
  4. package/dist/components/TyButton.d.ts.map +1 -0
  5. package/dist/components/TyButton.js +68 -0
  6. package/dist/components/TyButton.js.map +1 -0
  7. package/dist/components/TyCalendar.d.ts +63 -0
  8. package/dist/components/TyCalendar.d.ts.map +1 -0
  9. package/dist/components/TyCalendar.js +122 -0
  10. package/dist/components/TyCalendar.js.map +1 -0
  11. package/dist/components/TyCalendarMonth.d.ts +32 -0
  12. package/dist/components/TyCalendarMonth.d.ts.map +1 -0
  13. package/dist/components/TyCalendarMonth.js +54 -0
  14. package/dist/components/TyCalendarMonth.js.map +1 -0
  15. package/dist/components/TyCalendarNavigation.d.ts +21 -0
  16. package/dist/components/TyCalendarNavigation.d.ts.map +1 -0
  17. package/dist/components/TyCalendarNavigation.js +50 -0
  18. package/dist/components/TyCalendarNavigation.js.map +1 -0
  19. package/dist/components/TyCheckbox.d.ts +39 -0
  20. package/dist/components/TyCheckbox.d.ts.map +1 -0
  21. package/dist/components/TyCheckbox.js +79 -0
  22. package/dist/components/TyCheckbox.js.map +1 -0
  23. package/dist/components/TyCopy.d.ts +21 -0
  24. package/dist/components/TyCopy.d.ts.map +1 -0
  25. package/dist/components/TyCopy.js +42 -0
  26. package/dist/components/TyCopy.js.map +1 -0
  27. package/dist/components/TyDatePicker.d.ts +45 -0
  28. package/dist/components/TyDatePicker.d.ts.map +1 -0
  29. package/dist/components/TyDatePicker.js +114 -0
  30. package/dist/components/TyDatePicker.js.map +1 -0
  31. package/dist/components/TyDropdown.d.ts +51 -0
  32. package/dist/components/TyDropdown.d.ts.map +1 -0
  33. package/dist/components/TyDropdown.js +109 -0
  34. package/dist/components/TyDropdown.js.map +1 -0
  35. package/dist/components/TyIcon.d.ts +17 -0
  36. package/dist/components/TyIcon.d.ts.map +1 -0
  37. package/dist/components/TyIcon.js +41 -0
  38. package/dist/components/TyIcon.js.map +1 -0
  39. package/dist/components/TyInput.d.ts +65 -0
  40. package/dist/components/TyInput.d.ts.map +1 -0
  41. package/dist/components/TyInput.js +105 -0
  42. package/dist/components/TyInput.js.map +1 -0
  43. package/dist/components/TyModal.d.ts +29 -0
  44. package/dist/components/TyModal.d.ts.map +1 -0
  45. package/dist/components/TyModal.js +74 -0
  46. package/dist/components/TyModal.js.map +1 -0
  47. package/dist/components/TyMultiselect.d.ts +51 -0
  48. package/dist/components/TyMultiselect.d.ts.map +1 -0
  49. package/dist/components/TyMultiselect.js +103 -0
  50. package/dist/components/TyMultiselect.js.map +1 -0
  51. package/dist/components/TyOption.d.ts +10 -0
  52. package/dist/components/TyOption.d.ts.map +1 -0
  53. package/dist/components/TyOption.js +25 -0
  54. package/dist/components/TyOption.js.map +1 -0
  55. package/dist/components/TyPopup.d.ts +24 -0
  56. package/dist/components/TyPopup.d.ts.map +1 -0
  57. package/dist/components/TyPopup.js +61 -0
  58. package/dist/components/TyPopup.js.map +1 -0
  59. package/dist/components/TyRadio.d.ts +20 -0
  60. package/dist/components/TyRadio.d.ts.map +1 -0
  61. package/dist/components/TyRadio.js +31 -0
  62. package/dist/components/TyRadio.js.map +1 -0
  63. package/dist/components/TyRadioGroup.d.ts +40 -0
  64. package/dist/components/TyRadioGroup.d.ts.map +1 -0
  65. package/dist/components/TyRadioGroup.js +58 -0
  66. package/dist/components/TyRadioGroup.js.map +1 -0
  67. package/dist/components/TyResizeObserver.d.ts +11 -0
  68. package/dist/components/TyResizeObserver.d.ts.map +1 -0
  69. package/dist/components/TyResizeObserver.js +28 -0
  70. package/dist/components/TyResizeObserver.js.map +1 -0
  71. package/dist/components/TyScrollContainer.d.ts +25 -0
  72. package/dist/components/TyScrollContainer.d.ts.map +1 -0
  73. package/dist/components/TyScrollContainer.js +43 -0
  74. package/dist/components/TyScrollContainer.js.map +1 -0
  75. package/dist/components/TyStep.d.ts +17 -0
  76. package/dist/components/TyStep.d.ts.map +1 -0
  77. package/dist/components/TyStep.js +35 -0
  78. package/dist/components/TyStep.js.map +1 -0
  79. package/dist/components/TySwitch.d.ts +35 -0
  80. package/dist/components/TySwitch.d.ts.map +1 -0
  81. package/dist/components/TySwitch.js +54 -0
  82. package/dist/components/TySwitch.js.map +1 -0
  83. package/dist/components/TyTab.d.ts +13 -0
  84. package/dist/components/TyTab.d.ts.map +1 -0
  85. package/dist/components/TyTab.js +32 -0
  86. package/dist/components/TyTab.js.map +1 -0
  87. package/dist/components/TyTabs.d.ts +23 -0
  88. package/dist/components/TyTabs.d.ts.map +1 -0
  89. package/dist/components/TyTabs.js +48 -0
  90. package/dist/components/TyTabs.js.map +1 -0
  91. package/dist/components/TyTag.d.ts +22 -0
  92. package/dist/components/TyTag.d.ts.map +1 -0
  93. package/dist/components/TyTag.js +45 -0
  94. package/dist/components/TyTag.js.map +1 -0
  95. package/dist/components/TyTextarea.d.ts +37 -0
  96. package/dist/components/TyTextarea.d.ts.map +1 -0
  97. package/dist/components/TyTextarea.js +93 -0
  98. package/dist/components/TyTextarea.js.map +1 -0
  99. package/dist/components/TyTooltip.d.ts +17 -0
  100. package/dist/components/TyTooltip.d.ts.map +1 -0
  101. package/dist/components/TyTooltip.js +40 -0
  102. package/dist/components/TyTooltip.js.map +1 -0
  103. package/dist/components/TyWizard.d.ts +26 -0
  104. package/dist/components/TyWizard.d.ts.map +1 -0
  105. package/dist/components/TyWizard.js +50 -0
  106. package/dist/components/TyWizard.js.map +1 -0
  107. package/dist/components/index.d.ts +105 -0
  108. package/dist/components/index.d.ts.map +1 -0
  109. package/dist/components/index.js +112 -0
  110. package/dist/components/index.js.map +1 -0
  111. package/package.json +46 -0
  112. package/src/components/EventConventionTest.tsx +155 -0
  113. package/src/components/TyButton.tsx +145 -0
  114. package/src/components/TyCalendar.tsx +244 -0
  115. package/src/components/TyCalendarMonth.tsx +108 -0
  116. package/src/components/TyCalendarNavigation.tsx +91 -0
  117. package/src/components/TyCheckbox.tsx +149 -0
  118. package/src/components/TyCopy.tsx +78 -0
  119. package/src/components/TyDatePicker.tsx +216 -0
  120. package/src/components/TyDropdown.tsx +218 -0
  121. package/src/components/TyIcon.tsx +72 -0
  122. package/src/components/TyInput.tsx +207 -0
  123. package/src/components/TyModal.tsx +142 -0
  124. package/src/components/TyMultiselect.tsx +200 -0
  125. package/src/components/TyOption.tsx +42 -0
  126. package/src/components/TyPopup.tsx +111 -0
  127. package/src/components/TyRadio.tsx +56 -0
  128. package/src/components/TyRadioGroup.tsx +121 -0
  129. package/src/components/TyResizeObserver.tsx +54 -0
  130. package/src/components/TyScrollContainer.tsx +87 -0
  131. package/src/components/TyStep.tsx +71 -0
  132. package/src/components/TySwitch.tsx +108 -0
  133. package/src/components/TyTab.tsx +63 -0
  134. package/src/components/TyTabs.tsx +93 -0
  135. package/src/components/TyTag.tsx +79 -0
  136. package/src/components/TyTextarea.tsx +154 -0
  137. package/src/components/TyTooltip.tsx +83 -0
  138. package/src/components/TyWizard.tsx +99 -0
  139. package/src/components/index.ts +251 -0
@@ -0,0 +1,244 @@
1
+ import React, { useEffect, useRef, useCallback } from 'react';
2
+
3
+ // Type definitions for Ty Calendar component
4
+ export interface TyCalendarChangeEventDetail {
5
+ /** Selected month (1-12) */
6
+ month: number;
7
+ /** Selected year (4-digit) */
8
+ year: number;
9
+ /** Selected day (1-31) */
10
+ day: number;
11
+ /** Action that triggered the change: "select" */
12
+ action: 'select';
13
+ /** Source of the change: "day-click" */
14
+ source: 'day-click';
15
+ /** Complete day context from the calendar month */
16
+ dayContext: any;
17
+ }
18
+
19
+ export interface TyCalendarNavigateEventDetail {
20
+ /** Navigation target month (1-12) */
21
+ month: number;
22
+ /** Navigation target year (4-digit) */
23
+ year: number;
24
+ /** Action that triggered the navigation: "navigate" */
25
+ action: 'navigate';
26
+ /** Source of the change: "navigation" */
27
+ source: 'navigation';
28
+ }
29
+
30
+ export interface TyCalendarProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onChange'> {
31
+ /** Selected year (4-digit) */
32
+ year?: number | string;
33
+
34
+ /** Selected month (1-12) */
35
+ month?: number | string;
36
+
37
+ /** Selected day (1-31) */
38
+ day?: number | string;
39
+
40
+ /** Show navigation controls */
41
+ showNavigation?: boolean;
42
+
43
+ /** Stateless mode - no internal state management */
44
+ stateless?: boolean;
45
+
46
+ /** Calendar size */
47
+ size?: 'sm' | 'md' | 'lg';
48
+
49
+ /** Locale for date formatting */
50
+ locale?: string;
51
+
52
+ /** Calendar width */
53
+ width?: string | number;
54
+
55
+ /** Minimum calendar width */
56
+ minWidth?: string | number;
57
+
58
+ /** Maximum calendar width */
59
+ maxWidth?: string | number;
60
+
61
+ /** Form field name for form submission */
62
+ name?: string;
63
+
64
+ /** Form value (ISO date string) */
65
+ value?: string;
66
+
67
+ /** Function to render custom day content */
68
+ dayContentFn?: (dayContext: any) => HTMLElement | string;
69
+
70
+ /** Function to determine day CSS classes */
71
+ dayClassesFn?: (dayContext: any) => string[];
72
+
73
+ /** Custom CSS injection for render functions */
74
+ customCSS?: string;
75
+
76
+ /** Callback when a date is selected */
77
+ onChange?: (event: CustomEvent<TyCalendarChangeEventDetail>) => void;
78
+
79
+ /** Callback when navigation changes month/year */
80
+ onNavigate?: (event: CustomEvent<TyCalendarNavigateEventDetail>) => void;
81
+ }
82
+
83
+ // React wrapper for ty-calendar web component
84
+ export const TyCalendar = React.forwardRef<HTMLElement, TyCalendarProps>(
85
+ ({
86
+ year,
87
+ month,
88
+ day,
89
+ showNavigation,
90
+ stateless,
91
+ size,
92
+ locale,
93
+ width,
94
+ minWidth,
95
+ maxWidth,
96
+ name,
97
+ value,
98
+ dayContentFn,
99
+ dayClassesFn,
100
+ customCSS,
101
+ onChange,
102
+ onNavigate,
103
+ ...props
104
+ }, ref) => {
105
+ const elementRef = useRef<HTMLElement>(null);
106
+
107
+ // Handle ref forwarding
108
+ useEffect(() => {
109
+ if (ref && elementRef.current) {
110
+ if (typeof ref === 'function') {
111
+ ref(elementRef.current);
112
+ } else {
113
+ ref.current = elementRef.current;
114
+ }
115
+ }
116
+ }, [ref]);
117
+
118
+ // Handle change events (date selection)
119
+ const handleChange = useCallback((event: Event) => {
120
+ const customEvent = event as CustomEvent<TyCalendarChangeEventDetail>;
121
+ if (onChange) {
122
+ onChange(customEvent);
123
+ }
124
+ }, [onChange]);
125
+
126
+ // Handle navigate events (month/year navigation)
127
+ const handleNavigate = useCallback((event: Event) => {
128
+ const customEvent = event as CustomEvent<TyCalendarNavigateEventDetail>;
129
+ if (onNavigate) {
130
+ onNavigate(customEvent);
131
+ }
132
+ }, [onNavigate]);
133
+
134
+ // Set up event listeners
135
+ useEffect(() => {
136
+ const element = elementRef.current;
137
+ if (!element) return;
138
+
139
+ const listeners: Array<[string, EventListener]> = [];
140
+
141
+ if (onChange) {
142
+ element.addEventListener('change', handleChange);
143
+ listeners.push(['change', handleChange]);
144
+ }
145
+
146
+ if (onNavigate) {
147
+ element.addEventListener('navigate', handleNavigate);
148
+ listeners.push(['navigate', handleNavigate]);
149
+ }
150
+
151
+ return () => {
152
+ listeners.forEach(([eventName, handler]) => {
153
+ element.removeEventListener(eventName, handler);
154
+ });
155
+ };
156
+ }, [handleChange, handleNavigate, onChange, onNavigate]);
157
+
158
+ // Set function properties directly on the element (preferred over attributes)
159
+ useEffect(() => {
160
+ const element = elementRef.current;
161
+ if (!element) return;
162
+
163
+ // Day content function property (preferred over attribute)
164
+ if (dayContentFn) {
165
+ (element as any).dayContentFn = dayContentFn;
166
+ } else {
167
+ (element as any).dayContentFn = null;
168
+ }
169
+
170
+ // Day classes function property (preferred over attribute)
171
+ if (dayClassesFn) {
172
+ (element as any).dayClassesFn = dayClassesFn;
173
+ } else {
174
+ (element as any).dayClassesFn = null;
175
+ }
176
+
177
+ // Custom CSS property
178
+ if (customCSS) {
179
+ (element as any).customCSS = customCSS;
180
+ } else {
181
+ (element as any).customCSS = null;
182
+ }
183
+ }, [dayContentFn, dayClassesFn, customCSS]);
184
+
185
+ // Convert React props to web component attributes
186
+ const webComponentProps: Record<string, any> = {
187
+ ...props,
188
+ ref: elementRef,
189
+ };
190
+
191
+ // Add optional attributes only if they have values
192
+ if (year !== undefined) {
193
+ webComponentProps.year = year.toString();
194
+ }
195
+
196
+ if (month !== undefined) {
197
+ webComponentProps.month = month.toString();
198
+ }
199
+
200
+ if (day !== undefined) {
201
+ webComponentProps.day = day.toString();
202
+ }
203
+
204
+ if (showNavigation) {
205
+ webComponentProps['show-navigation'] = ''; // Boolean attributes as empty string
206
+ }
207
+
208
+ if (stateless) {
209
+ webComponentProps.stateless = ''; // Boolean attributes as empty string
210
+ }
211
+
212
+ if (size) {
213
+ webComponentProps.size = size;
214
+ }
215
+
216
+ if (locale) {
217
+ webComponentProps.locale = locale;
218
+ }
219
+
220
+ if (width !== undefined) {
221
+ webComponentProps.width = width.toString();
222
+ }
223
+
224
+ if (minWidth !== undefined) {
225
+ webComponentProps['min-width'] = minWidth.toString();
226
+ }
227
+
228
+ if (maxWidth !== undefined) {
229
+ webComponentProps['max-width'] = maxWidth.toString();
230
+ }
231
+
232
+ if (name) {
233
+ webComponentProps.name = name;
234
+ }
235
+
236
+ if (value) {
237
+ webComponentProps.value = value;
238
+ }
239
+
240
+ return React.createElement('ty-calendar', webComponentProps);
241
+ }
242
+ );
243
+
244
+ TyCalendar.displayName = 'TyCalendar';
@@ -0,0 +1,108 @@
1
+ import React, { useEffect, useRef } from 'react';
2
+
3
+ // Type definitions for Ty Calendar Month component
4
+ export interface TyCalendarMonthProps extends React.HTMLAttributes<HTMLElement> {
5
+ /** Display year */
6
+ displayYear?: number;
7
+
8
+ /** Display month (1-12) */
9
+ displayMonth?: number;
10
+
11
+ /** Locale for date formatting */
12
+ locale?: string;
13
+
14
+ /** Calendar size */
15
+ size?: 'sm' | 'md' | 'lg';
16
+
17
+ /** Width of calendar */
18
+ width?: string;
19
+
20
+ /** Minimum width */
21
+ minWidth?: string;
22
+
23
+ /** Maximum width */
24
+ maxWidth?: string;
25
+
26
+ /** Day click event handler */
27
+ onDayClick?: (event: CustomEvent<DayClickDetail>) => void;
28
+ }
29
+
30
+ export interface DayClickDetail {
31
+ dayContext: any; // DayContext type from calendar-utils
32
+ value: number;
33
+ year: number;
34
+ month: number;
35
+ day: number;
36
+ isHoliday?: boolean;
37
+ isToday?: boolean;
38
+ isWeekend: boolean;
39
+ isOtherMonth: boolean;
40
+ }
41
+
42
+ // React wrapper for ty-calendar-month web component
43
+ export const TyCalendarMonth = React.forwardRef<HTMLElement, TyCalendarMonthProps>(
44
+ ({
45
+ displayYear,
46
+ displayMonth,
47
+ locale,
48
+ size,
49
+ width,
50
+ minWidth,
51
+ maxWidth,
52
+ onDayClick,
53
+ ...props
54
+ }, ref) => {
55
+ const elementRef = useRef<HTMLElement>(null);
56
+
57
+ // Handle day click events
58
+ useEffect(() => {
59
+ const element = elementRef.current;
60
+ if (!element) return;
61
+
62
+ const handleDayClick = (event: Event) => {
63
+ if (onDayClick) {
64
+ onDayClick(event as CustomEvent<DayClickDetail>);
65
+ }
66
+ };
67
+
68
+ element.addEventListener('day-click', handleDayClick);
69
+
70
+ return () => {
71
+ element.removeEventListener('day-click', handleDayClick);
72
+ };
73
+ }, [onDayClick]);
74
+
75
+ // Combine refs if needed
76
+ useEffect(() => {
77
+ if (ref && elementRef.current) {
78
+ if (typeof ref === 'function') {
79
+ ref(elementRef.current);
80
+ } else {
81
+ ref.current = elementRef.current;
82
+ }
83
+ }
84
+ }, [ref]);
85
+
86
+ // Convert React props to web component attributes
87
+ const webComponentProps: Record<string, any> = {
88
+ ...props,
89
+ ref: elementRef,
90
+ };
91
+
92
+ // Add attributes
93
+ if (displayYear !== undefined) webComponentProps['display-year'] = displayYear;
94
+ if (displayMonth !== undefined) webComponentProps['display-month'] = displayMonth;
95
+ if (locale) webComponentProps.locale = locale;
96
+ if (size) webComponentProps.size = size;
97
+ if (width) webComponentProps.width = width;
98
+ if (minWidth) webComponentProps['min-width'] = minWidth;
99
+ if (maxWidth) webComponentProps['max-width'] = maxWidth;
100
+
101
+ return React.createElement(
102
+ 'ty-calendar-month',
103
+ webComponentProps
104
+ );
105
+ }
106
+ );
107
+
108
+ TyCalendarMonth.displayName = 'TyCalendarMonth';
@@ -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,149 @@
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
+ // Imperatively sync `checked` to the underlying property. React 18 sets
113
+ // boolean attributes as empty strings on first render but doesn't reliably
114
+ // remove them when the prop flips back to false on a custom element.
115
+ useEffect(() => {
116
+ const element = elementRef.current as any;
117
+ if (!element) return;
118
+ if (Boolean(element.checked) !== Boolean(checked)) {
119
+ element.checked = Boolean(checked);
120
+ }
121
+ }, [checked]);
122
+
123
+ // Convert React props to web component attributes
124
+ const webComponentProps: Record<string, any> = {
125
+ ...props,
126
+ ref: elementRef,
127
+ };
128
+
129
+ // Add boolean attributes
130
+ if (checked) webComponentProps.checked = '';
131
+ if (disabled) webComponentProps.disabled = '';
132
+ if (required) webComponentProps.required = '';
133
+
134
+ // Add string attributes
135
+ if (value) webComponentProps.value = value;
136
+ if (name) webComponentProps.name = name;
137
+ if (error) webComponentProps.error = error;
138
+ if (size) webComponentProps.size = size;
139
+ if (flavor) webComponentProps.flavor = flavor;
140
+
141
+ return React.createElement(
142
+ 'ty-checkbox',
143
+ webComponentProps,
144
+ children
145
+ );
146
+ }
147
+ );
148
+
149
+ 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';