tyrell-react 1.0.0-RC6
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 +410 -0
- package/dist/components/TyButton.d.ts +50 -0
- package/dist/components/TyButton.d.ts.map +1 -0
- package/dist/components/TyButton.js +68 -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 +127 -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 +83 -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 +119 -0
- package/dist/components/TyDatePicker.js.map +1 -0
- package/dist/components/TyDropdown.d.ts +56 -0
- package/dist/components/TyDropdown.d.ts.map +1 -0
- package/dist/components/TyDropdown.js +110 -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 +127 -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 +107 -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/TyRadio.d.ts +20 -0
- package/dist/components/TyRadio.d.ts.map +1 -0
- package/dist/components/TyRadio.js +46 -0
- package/dist/components/TyRadio.js.map +1 -0
- package/dist/components/TyRadioGroup.d.ts +40 -0
- package/dist/components/TyRadioGroup.d.ts.map +1 -0
- package/dist/components/TyRadioGroup.js +58 -0
- package/dist/components/TyRadioGroup.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/TySwitch.d.ts +35 -0
- package/dist/components/TySwitch.d.ts.map +1 -0
- package/dist/components/TySwitch.js +69 -0
- package/dist/components/TySwitch.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 +113 -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 +105 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +112 -0
- package/dist/components/index.js.map +1 -0
- package/dist/utils/react-version.d.ts +2 -0
- package/dist/utils/react-version.d.ts.map +1 -0
- package/dist/utils/react-version.js +8 -0
- package/dist/utils/react-version.js.map +1 -0
- package/package.json +46 -0
- package/src/components/EventConventionTest.tsx +155 -0
- package/src/components/TyButton.tsx +145 -0
- package/src/components/TyCalendar.tsx +248 -0
- package/src/components/TyCalendarMonth.tsx +108 -0
- package/src/components/TyCalendarNavigation.tsx +91 -0
- package/src/components/TyCheckbox.tsx +152 -0
- package/src/components/TyCopy.tsx +78 -0
- package/src/components/TyDatePicker.tsx +220 -0
- package/src/components/TyDropdown.tsx +225 -0
- package/src/components/TyIcon.tsx +72 -0
- package/src/components/TyInput.tsx +232 -0
- package/src/components/TyModal.tsx +142 -0
- package/src/components/TyMultiselect.tsx +203 -0
- package/src/components/TyOption.tsx +42 -0
- package/src/components/TyPopup.tsx +111 -0
- package/src/components/TyRadio.tsx +70 -0
- package/src/components/TyRadioGroup.tsx +121 -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/TySwitch.tsx +122 -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 +177 -0
- package/src/components/TyTooltip.tsx +83 -0
- package/src/components/TyWizard.tsx +99 -0
- package/src/components/index.ts +251 -0
- package/src/utils/react-version.ts +8 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
// Type definitions for Ty Popup component
|
|
4
|
+
export interface TyPopupProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onClose'> {
|
|
5
|
+
/** Preferred placement of the popup relative to anchor parent: "top" | "bottom" | "left" | "right" */
|
|
6
|
+
placement?: 'top' | 'bottom' | 'left' | 'right';
|
|
7
|
+
|
|
8
|
+
/** Distance offset from the anchor in pixels (default: 8) */
|
|
9
|
+
offset?: number;
|
|
10
|
+
|
|
11
|
+
/** Disable automatic click trigger - requires manual open/close via ref methods */
|
|
12
|
+
manual?: boolean;
|
|
13
|
+
|
|
14
|
+
/** Disable automatic close on outside click and ESC key */
|
|
15
|
+
disableClose?: boolean;
|
|
16
|
+
|
|
17
|
+
/** Fired when the popup opens (after the open animation starts) */
|
|
18
|
+
onOpen?: (event: CustomEvent) => void;
|
|
19
|
+
|
|
20
|
+
/** Fired when the popup closes */
|
|
21
|
+
onClose?: (event: CustomEvent) => void;
|
|
22
|
+
|
|
23
|
+
/** Popup content - popup should be a child of the anchor element */
|
|
24
|
+
children?: React.ReactNode;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Programmatic API for popup control
|
|
28
|
+
export interface TyPopupElement extends HTMLElement {
|
|
29
|
+
openPopup(): void;
|
|
30
|
+
closePopup(): void;
|
|
31
|
+
togglePopup(): void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// React wrapper for ty-popup web component
|
|
35
|
+
export const TyPopup = React.forwardRef<TyPopupElement, TyPopupProps>(
|
|
36
|
+
({
|
|
37
|
+
placement,
|
|
38
|
+
offset,
|
|
39
|
+
manual,
|
|
40
|
+
disableClose,
|
|
41
|
+
onOpen,
|
|
42
|
+
onClose,
|
|
43
|
+
children,
|
|
44
|
+
...props
|
|
45
|
+
}, ref) => {
|
|
46
|
+
const elementRef = useRef<TyPopupElement>(null);
|
|
47
|
+
|
|
48
|
+
// Handle ref forwarding
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (ref && elementRef.current) {
|
|
51
|
+
if (typeof ref === 'function') {
|
|
52
|
+
ref(elementRef.current);
|
|
53
|
+
} else {
|
|
54
|
+
ref.current = elementRef.current;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}, [ref]);
|
|
58
|
+
|
|
59
|
+
// Listen for popup open/close events
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
const element = elementRef.current;
|
|
62
|
+
if (!element) return;
|
|
63
|
+
|
|
64
|
+
const handleOpen = (event: Event) => {
|
|
65
|
+
if (onOpen) onOpen(event as CustomEvent);
|
|
66
|
+
};
|
|
67
|
+
const handleClose = (event: Event) => {
|
|
68
|
+
if (onClose) onClose(event as CustomEvent);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
if (onOpen) element.addEventListener('open', handleOpen);
|
|
72
|
+
if (onClose) element.addEventListener('close', handleClose);
|
|
73
|
+
|
|
74
|
+
return () => {
|
|
75
|
+
if (onOpen) element.removeEventListener('open', handleOpen);
|
|
76
|
+
if (onClose) element.removeEventListener('close', handleClose);
|
|
77
|
+
};
|
|
78
|
+
}, [onOpen, onClose]);
|
|
79
|
+
|
|
80
|
+
// Convert React props to web component attributes
|
|
81
|
+
const webComponentProps: Record<string, any> = {
|
|
82
|
+
...props,
|
|
83
|
+
ref: elementRef,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// Add optional attributes only if they have values
|
|
87
|
+
if (placement) {
|
|
88
|
+
webComponentProps.placement = placement;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (offset !== undefined) {
|
|
92
|
+
webComponentProps.offset = offset.toString();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (manual) {
|
|
96
|
+
webComponentProps.manual = ''; // Boolean attributes as empty string
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (disableClose) {
|
|
100
|
+
webComponentProps['disable-close'] = ''; // Boolean attributes as empty string
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return React.createElement(
|
|
104
|
+
'ty-popup',
|
|
105
|
+
webComponentProps,
|
|
106
|
+
children
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
TyPopup.displayName = 'TyPopup';
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import { needsPropertyBridge } from '../utils/react-version';
|
|
3
|
+
|
|
4
|
+
export interface TyRadioProps extends React.HTMLAttributes<HTMLElement> {
|
|
5
|
+
/** Form field value (selected by parent ty-radio-group when matches its `value`) */
|
|
6
|
+
value?: string;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Selected state. Usually managed by the parent `<TyRadioGroup>` based on its
|
|
10
|
+
* own `value`; set explicitly only when using `ty-radio` outside a group.
|
|
11
|
+
*/
|
|
12
|
+
checked?: boolean;
|
|
13
|
+
|
|
14
|
+
/** Disable this individual radio */
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
|
|
17
|
+
/** Radio size — typically inherited from the parent group */
|
|
18
|
+
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
19
|
+
|
|
20
|
+
/** Semantic styling variant — typically inherited from the parent group */
|
|
21
|
+
flavor?: 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'neutral';
|
|
22
|
+
|
|
23
|
+
/** Label content (wrap in a `<label>` for click delegation, see ty-radio docs) */
|
|
24
|
+
children?: React.ReactNode;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const TyRadio = React.forwardRef<HTMLElement, TyRadioProps>(
|
|
28
|
+
({ children, value, checked, disabled, size, flavor, ...props }, ref) => {
|
|
29
|
+
const elementRef = useRef<HTMLElement>(null);
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (ref && elementRef.current) {
|
|
33
|
+
if (typeof ref === 'function') {
|
|
34
|
+
ref(elementRef.current);
|
|
35
|
+
} else {
|
|
36
|
+
ref.current = elementRef.current;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}, [ref]);
|
|
40
|
+
|
|
41
|
+
// Imperatively sync `checked` to the underlying property. React 18 sets
|
|
42
|
+
// boolean attributes as empty strings on first render but doesn't reliably
|
|
43
|
+
// remove them when the prop flips back to false on a custom element.
|
|
44
|
+
// React 19+ handles boolean prop-to-property bridging natively.
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (!needsPropertyBridge) return;
|
|
47
|
+
const element = elementRef.current as any;
|
|
48
|
+
if (!element) return;
|
|
49
|
+
if (Boolean(element.checked) !== Boolean(checked)) {
|
|
50
|
+
element.checked = Boolean(checked);
|
|
51
|
+
}
|
|
52
|
+
}, [checked]);
|
|
53
|
+
|
|
54
|
+
const webComponentProps: Record<string, any> = {
|
|
55
|
+
...props,
|
|
56
|
+
ref: elementRef,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
if (checked) webComponentProps.checked = '';
|
|
60
|
+
if (disabled) webComponentProps.disabled = '';
|
|
61
|
+
|
|
62
|
+
if (value !== undefined) webComponentProps.value = value;
|
|
63
|
+
if (size) webComponentProps.size = size;
|
|
64
|
+
if (flavor) webComponentProps.flavor = flavor;
|
|
65
|
+
|
|
66
|
+
return React.createElement('ty-radio', webComponentProps, children);
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
TyRadio.displayName = 'TyRadio';
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface TyRadioGroupProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onChange' | 'onInput'> {
|
|
4
|
+
/** Currently selected value (matches one child `<TyRadio value="...">`) */
|
|
5
|
+
value?: string;
|
|
6
|
+
|
|
7
|
+
/** Form field name */
|
|
8
|
+
name?: string;
|
|
9
|
+
|
|
10
|
+
/** Group label rendered above the radios */
|
|
11
|
+
label?: string;
|
|
12
|
+
|
|
13
|
+
/** Disable the entire group */
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
|
|
16
|
+
/** Required field — renders required-icon next to the label */
|
|
17
|
+
required?: boolean;
|
|
18
|
+
|
|
19
|
+
/** Error message rendered below the group */
|
|
20
|
+
error?: string;
|
|
21
|
+
|
|
22
|
+
/** Layout direction for radio children */
|
|
23
|
+
orientation?: 'vertical' | 'horizontal';
|
|
24
|
+
|
|
25
|
+
/** Group size — propagates to all `<TyRadio>` children */
|
|
26
|
+
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
27
|
+
|
|
28
|
+
/** Group flavor — propagates to all `<TyRadio>` children */
|
|
29
|
+
flavor?: 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'neutral';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Fires when selection changes (React convention)
|
|
33
|
+
* Maps to native 'input' event from ty-radio-group
|
|
34
|
+
*/
|
|
35
|
+
onChange?: (event: CustomEvent<TyRadioGroupEventDetail>) => void;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Fires on blur if value changed (native DOM behavior)
|
|
39
|
+
* Maps to native 'change' event from ty-radio-group
|
|
40
|
+
*/
|
|
41
|
+
onChangeCommit?: (event: CustomEvent<TyRadioGroupEventDetail>) => void;
|
|
42
|
+
|
|
43
|
+
/** `<TyRadio>` children */
|
|
44
|
+
children?: React.ReactNode;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface TyRadioGroupEventDetail {
|
|
48
|
+
value: string;
|
|
49
|
+
formValue: string;
|
|
50
|
+
originalEvent: Event;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const TyRadioGroup = React.forwardRef<HTMLElement, TyRadioGroupProps>(
|
|
54
|
+
({
|
|
55
|
+
children,
|
|
56
|
+
value,
|
|
57
|
+
name,
|
|
58
|
+
label,
|
|
59
|
+
disabled,
|
|
60
|
+
required,
|
|
61
|
+
error,
|
|
62
|
+
orientation,
|
|
63
|
+
size,
|
|
64
|
+
flavor,
|
|
65
|
+
onChange,
|
|
66
|
+
onChangeCommit,
|
|
67
|
+
...props
|
|
68
|
+
}, ref) => {
|
|
69
|
+
const elementRef = useRef<HTMLElement>(null);
|
|
70
|
+
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
const element = elementRef.current;
|
|
73
|
+
if (!element) return;
|
|
74
|
+
|
|
75
|
+
const handleInput = (event: Event) => {
|
|
76
|
+
if (onChange) onChange(event as CustomEvent<TyRadioGroupEventDetail>);
|
|
77
|
+
};
|
|
78
|
+
const handleChangeCommit = (event: Event) => {
|
|
79
|
+
if (onChangeCommit) onChangeCommit(event as CustomEvent<TyRadioGroupEventDetail>);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
element.addEventListener('input', handleInput);
|
|
83
|
+
element.addEventListener('change', handleChangeCommit);
|
|
84
|
+
|
|
85
|
+
return () => {
|
|
86
|
+
element.removeEventListener('input', handleInput);
|
|
87
|
+
element.removeEventListener('change', handleChangeCommit);
|
|
88
|
+
};
|
|
89
|
+
}, [onChange, onChangeCommit]);
|
|
90
|
+
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
if (ref && elementRef.current) {
|
|
93
|
+
if (typeof ref === 'function') {
|
|
94
|
+
ref(elementRef.current);
|
|
95
|
+
} else {
|
|
96
|
+
ref.current = elementRef.current;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}, [ref]);
|
|
100
|
+
|
|
101
|
+
const webComponentProps: Record<string, any> = {
|
|
102
|
+
...props,
|
|
103
|
+
ref: elementRef,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
if (disabled) webComponentProps.disabled = '';
|
|
107
|
+
if (required) webComponentProps.required = '';
|
|
108
|
+
|
|
109
|
+
if (value !== undefined) webComponentProps.value = value;
|
|
110
|
+
if (name) webComponentProps.name = name;
|
|
111
|
+
if (label) webComponentProps.label = label;
|
|
112
|
+
if (error) webComponentProps.error = error;
|
|
113
|
+
if (orientation) webComponentProps.orientation = orientation;
|
|
114
|
+
if (size) webComponentProps.size = size;
|
|
115
|
+
if (flavor) webComponentProps.flavor = flavor;
|
|
116
|
+
|
|
117
|
+
return React.createElement('ty-radio-group', webComponentProps, children);
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
TyRadioGroup.displayName = 'TyRadioGroup';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
// Type definitions for Ty ResizeObserver component
|
|
4
|
+
export interface TyResizeObserverProps extends React.HTMLAttributes<HTMLElement> {
|
|
5
|
+
/** Required unique identifier for size registry */
|
|
6
|
+
id: string;
|
|
7
|
+
|
|
8
|
+
/** Debounce in milliseconds (default: 0 = no debounce) */
|
|
9
|
+
debounce?: number;
|
|
10
|
+
|
|
11
|
+
/** Content to observe */
|
|
12
|
+
children?: React.ReactNode;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// React wrapper for ty-resize-observer web component
|
|
16
|
+
export const TyResizeObserver = React.forwardRef<HTMLElement, TyResizeObserverProps>(
|
|
17
|
+
({
|
|
18
|
+
children,
|
|
19
|
+
id,
|
|
20
|
+
debounce,
|
|
21
|
+
...props
|
|
22
|
+
}, ref) => {
|
|
23
|
+
const elementRef = useRef<HTMLElement>(null);
|
|
24
|
+
|
|
25
|
+
// Combine refs if needed
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (ref && elementRef.current) {
|
|
28
|
+
if (typeof ref === 'function') {
|
|
29
|
+
ref(elementRef.current);
|
|
30
|
+
} else {
|
|
31
|
+
ref.current = elementRef.current;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}, [ref]);
|
|
35
|
+
|
|
36
|
+
// Convert React props to web component attributes
|
|
37
|
+
const webComponentProps: Record<string, any> = {
|
|
38
|
+
...props,
|
|
39
|
+
ref: elementRef,
|
|
40
|
+
id,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// Add number attributes
|
|
44
|
+
if (debounce !== undefined) webComponentProps.debounce = debounce;
|
|
45
|
+
|
|
46
|
+
return React.createElement(
|
|
47
|
+
'ty-resize-observer',
|
|
48
|
+
webComponentProps,
|
|
49
|
+
children
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
TyResizeObserver.displayName = 'TyResizeObserver';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useImperativeHandle } from 'react';
|
|
2
|
+
|
|
3
|
+
// Type definitions for Ty ScrollContainer component
|
|
4
|
+
export interface TyScrollContainerProps extends React.HTMLAttributes<HTMLElement> {
|
|
5
|
+
/** Maximum height of the scroll container */
|
|
6
|
+
maxHeight?: string;
|
|
7
|
+
|
|
8
|
+
/** Enable/disable scroll shadows (default: true) */
|
|
9
|
+
shadow?: boolean;
|
|
10
|
+
|
|
11
|
+
/** Hide native scrollbar */
|
|
12
|
+
hideScrollbar?: boolean;
|
|
13
|
+
|
|
14
|
+
/** Content to scroll */
|
|
15
|
+
children?: React.ReactNode;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Ref interface for imperative methods
|
|
19
|
+
export interface TyScrollContainerRef {
|
|
20
|
+
/** Force update shadows (useful after dynamic content changes) */
|
|
21
|
+
updateShadows: () => void;
|
|
22
|
+
/** Scroll to top */
|
|
23
|
+
scrollToTop: (smooth?: boolean) => void;
|
|
24
|
+
/** Scroll to bottom */
|
|
25
|
+
scrollToBottom: (smooth?: boolean) => void;
|
|
26
|
+
/** Get the underlying scroll element */
|
|
27
|
+
scrollElement: HTMLElement | null;
|
|
28
|
+
/** Get the native element */
|
|
29
|
+
element: HTMLElement | null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// React wrapper for ty-scroll-container web component
|
|
33
|
+
export const TyScrollContainer = React.forwardRef<TyScrollContainerRef, TyScrollContainerProps>(
|
|
34
|
+
({
|
|
35
|
+
children,
|
|
36
|
+
maxHeight,
|
|
37
|
+
shadow,
|
|
38
|
+
hideScrollbar,
|
|
39
|
+
...props
|
|
40
|
+
}, ref) => {
|
|
41
|
+
const elementRef = useRef<HTMLElement>(null);
|
|
42
|
+
|
|
43
|
+
// Expose imperative methods via ref
|
|
44
|
+
useImperativeHandle(ref, () => ({
|
|
45
|
+
updateShadows: () => {
|
|
46
|
+
const el = elementRef.current as any;
|
|
47
|
+
el?.updateShadows?.();
|
|
48
|
+
},
|
|
49
|
+
scrollToTop: (smooth = true) => {
|
|
50
|
+
const el = elementRef.current as any;
|
|
51
|
+
el?.scrollToTop?.(smooth);
|
|
52
|
+
},
|
|
53
|
+
scrollToBottom: (smooth = true) => {
|
|
54
|
+
const el = elementRef.current as any;
|
|
55
|
+
el?.scrollToBottom?.(smooth);
|
|
56
|
+
},
|
|
57
|
+
get scrollElement() {
|
|
58
|
+
const el = elementRef.current as any;
|
|
59
|
+
return el?.scrollElement ?? null;
|
|
60
|
+
},
|
|
61
|
+
get element() {
|
|
62
|
+
return elementRef.current;
|
|
63
|
+
}
|
|
64
|
+
}), []);
|
|
65
|
+
|
|
66
|
+
// Convert React props to web component attributes
|
|
67
|
+
const webComponentProps: Record<string, any> = {
|
|
68
|
+
...props,
|
|
69
|
+
ref: elementRef,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// Add string attributes
|
|
73
|
+
if (maxHeight) webComponentProps['max-height'] = maxHeight;
|
|
74
|
+
|
|
75
|
+
// Add boolean attributes
|
|
76
|
+
if (shadow === false) webComponentProps.shadow = 'false';
|
|
77
|
+
if (hideScrollbar) webComponentProps['hide-scrollbar'] = true;
|
|
78
|
+
|
|
79
|
+
return React.createElement(
|
|
80
|
+
'ty-scroll-container',
|
|
81
|
+
webComponentProps,
|
|
82
|
+
children
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
TyScrollContainer.displayName = 'TyScrollContainer';
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
// Type definitions for Ty Step component
|
|
4
|
+
export interface TyStepProps extends React.HTMLAttributes<HTMLElement> {
|
|
5
|
+
/** Required unique identifier for the step */
|
|
6
|
+
id: string;
|
|
7
|
+
|
|
8
|
+
/** Main step title displayed in indicator */
|
|
9
|
+
label?: string;
|
|
10
|
+
|
|
11
|
+
/** Optional subtitle/description */
|
|
12
|
+
description?: string;
|
|
13
|
+
|
|
14
|
+
/** Whether the step is disabled */
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
|
|
17
|
+
/** User-controlled status override */
|
|
18
|
+
status?: 'completed' | 'active' | 'pending' | 'error';
|
|
19
|
+
|
|
20
|
+
/** Step content */
|
|
21
|
+
children?: React.ReactNode;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// React wrapper for ty-step web component
|
|
25
|
+
export const TyStep = React.forwardRef<HTMLElement, TyStepProps>(
|
|
26
|
+
({
|
|
27
|
+
children,
|
|
28
|
+
id,
|
|
29
|
+
label,
|
|
30
|
+
description,
|
|
31
|
+
disabled,
|
|
32
|
+
status,
|
|
33
|
+
...props
|
|
34
|
+
}, ref) => {
|
|
35
|
+
const elementRef = useRef<HTMLElement>(null);
|
|
36
|
+
|
|
37
|
+
// Combine refs if needed
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (ref && elementRef.current) {
|
|
40
|
+
if (typeof ref === 'function') {
|
|
41
|
+
ref(elementRef.current);
|
|
42
|
+
} else {
|
|
43
|
+
ref.current = elementRef.current;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}, [ref]);
|
|
47
|
+
|
|
48
|
+
// Convert React props to web component attributes
|
|
49
|
+
const webComponentProps: Record<string, any> = {
|
|
50
|
+
...props,
|
|
51
|
+
ref: elementRef,
|
|
52
|
+
id,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// Add string attributes
|
|
56
|
+
if (label) webComponentProps.label = label;
|
|
57
|
+
if (description) webComponentProps.description = description;
|
|
58
|
+
if (status) webComponentProps.status = status;
|
|
59
|
+
|
|
60
|
+
// Add boolean attributes
|
|
61
|
+
if (disabled) webComponentProps.disabled = true;
|
|
62
|
+
|
|
63
|
+
return React.createElement(
|
|
64
|
+
'ty-step',
|
|
65
|
+
webComponentProps,
|
|
66
|
+
children
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
TyStep.displayName = 'TyStep';
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import { needsPropertyBridge } from '../utils/react-version';
|
|
3
|
+
|
|
4
|
+
export interface TySwitchProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onChange' | 'onInput'> {
|
|
5
|
+
/** Checked (on) 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 switch */
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
|
|
17
|
+
/** Required field */
|
|
18
|
+
required?: boolean;
|
|
19
|
+
|
|
20
|
+
/** Switch size */
|
|
21
|
+
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
22
|
+
|
|
23
|
+
/** Semantic styling variant */
|
|
24
|
+
flavor?: 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'neutral';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Fires when switch state changes (React convention)
|
|
28
|
+
* Maps to native 'input' event from ty-switch
|
|
29
|
+
*/
|
|
30
|
+
onChange?: (event: CustomEvent<TySwitchEventDetail>) => void;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Fires on blur if value changed (native DOM behavior)
|
|
34
|
+
* Maps to native 'change' event from ty-switch
|
|
35
|
+
*/
|
|
36
|
+
onChangeCommit?: (event: CustomEvent<TySwitchEventDetail>) => void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface TySwitchEventDetail {
|
|
40
|
+
value: boolean;
|
|
41
|
+
checked: boolean;
|
|
42
|
+
formValue: string | null;
|
|
43
|
+
originalEvent: Event;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const TySwitch = React.forwardRef<HTMLElement, TySwitchProps>(
|
|
47
|
+
({
|
|
48
|
+
checked,
|
|
49
|
+
value,
|
|
50
|
+
name,
|
|
51
|
+
disabled,
|
|
52
|
+
required,
|
|
53
|
+
size,
|
|
54
|
+
flavor,
|
|
55
|
+
onChange,
|
|
56
|
+
onChangeCommit,
|
|
57
|
+
...props
|
|
58
|
+
}, ref) => {
|
|
59
|
+
const elementRef = useRef<HTMLElement>(null);
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
const element = elementRef.current;
|
|
63
|
+
if (!element) return;
|
|
64
|
+
|
|
65
|
+
const handleInput = (event: Event) => {
|
|
66
|
+
if (onChange) onChange(event as CustomEvent<TySwitchEventDetail>);
|
|
67
|
+
};
|
|
68
|
+
const handleChangeCommit = (event: Event) => {
|
|
69
|
+
if (onChangeCommit) onChangeCommit(event as CustomEvent<TySwitchEventDetail>);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
element.addEventListener('input', handleInput);
|
|
73
|
+
element.addEventListener('change', handleChangeCommit);
|
|
74
|
+
|
|
75
|
+
return () => {
|
|
76
|
+
element.removeEventListener('input', handleInput);
|
|
77
|
+
element.removeEventListener('change', handleChangeCommit);
|
|
78
|
+
};
|
|
79
|
+
}, [onChange, onChangeCommit]);
|
|
80
|
+
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
if (ref && elementRef.current) {
|
|
83
|
+
if (typeof ref === 'function') {
|
|
84
|
+
ref(elementRef.current);
|
|
85
|
+
} else {
|
|
86
|
+
ref.current = elementRef.current;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}, [ref]);
|
|
90
|
+
|
|
91
|
+
// Imperatively sync `checked` to the underlying property. React 18 sets
|
|
92
|
+
// boolean attributes as empty strings on first render but doesn't reliably
|
|
93
|
+
// remove them when the prop flips back to false on a custom element.
|
|
94
|
+
// React 19+ handles boolean prop-to-property bridging natively.
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
if (!needsPropertyBridge) return;
|
|
97
|
+
const element = elementRef.current as any;
|
|
98
|
+
if (!element) return;
|
|
99
|
+
if (Boolean(element.checked) !== Boolean(checked)) {
|
|
100
|
+
element.checked = Boolean(checked);
|
|
101
|
+
}
|
|
102
|
+
}, [checked]);
|
|
103
|
+
|
|
104
|
+
const webComponentProps: Record<string, any> = {
|
|
105
|
+
...props,
|
|
106
|
+
ref: elementRef,
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
if (checked) webComponentProps.checked = '';
|
|
110
|
+
if (disabled) webComponentProps.disabled = '';
|
|
111
|
+
if (required) webComponentProps.required = '';
|
|
112
|
+
|
|
113
|
+
if (value) webComponentProps.value = value;
|
|
114
|
+
if (name) webComponentProps.name = name;
|
|
115
|
+
if (size) webComponentProps.size = size;
|
|
116
|
+
if (flavor) webComponentProps.flavor = flavor;
|
|
117
|
+
|
|
118
|
+
return React.createElement('ty-switch', webComponentProps);
|
|
119
|
+
}
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
TySwitch.displayName = 'TySwitch';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
// Type definitions for Ty Tab component
|
|
4
|
+
export interface TyTabProps extends React.HTMLAttributes<HTMLElement> {
|
|
5
|
+
/** Required unique identifier */
|
|
6
|
+
id: string;
|
|
7
|
+
|
|
8
|
+
/** Simple text label */
|
|
9
|
+
label?: string;
|
|
10
|
+
|
|
11
|
+
/** Whether the tab is disabled */
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
|
|
14
|
+
/** Tab content */
|
|
15
|
+
children?: React.ReactNode;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// React wrapper for ty-tab web component
|
|
19
|
+
export const TyTab = React.forwardRef<HTMLElement, TyTabProps>(
|
|
20
|
+
({
|
|
21
|
+
children,
|
|
22
|
+
id,
|
|
23
|
+
label,
|
|
24
|
+
disabled,
|
|
25
|
+
...props
|
|
26
|
+
}, ref) => {
|
|
27
|
+
const elementRef = useRef<HTMLElement>(null);
|
|
28
|
+
|
|
29
|
+
// Combine refs if needed
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (ref && elementRef.current) {
|
|
32
|
+
if (typeof ref === 'function') {
|
|
33
|
+
ref(elementRef.current);
|
|
34
|
+
} else {
|
|
35
|
+
ref.current = elementRef.current;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}, [ref]);
|
|
39
|
+
|
|
40
|
+
// Convert React props to web component attributes
|
|
41
|
+
const webComponentProps: Record<string, any> = {
|
|
42
|
+
...props,
|
|
43
|
+
ref: elementRef,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// Add required attribute
|
|
47
|
+
webComponentProps.id = id;
|
|
48
|
+
|
|
49
|
+
// Add boolean attributes
|
|
50
|
+
if (disabled) webComponentProps.disabled = '';
|
|
51
|
+
|
|
52
|
+
// Add string attributes
|
|
53
|
+
if (label) webComponentProps.label = label;
|
|
54
|
+
|
|
55
|
+
return React.createElement(
|
|
56
|
+
'ty-tab',
|
|
57
|
+
webComponentProps,
|
|
58
|
+
children
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
TyTab.displayName = 'TyTab';
|