fiboui 1.0.2 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/README.md +141 -96
  2. package/dist/FineGrain-BTgNt7fN.js +29 -0
  3. package/dist/Link-DDzSPY1Q.js +88 -0
  4. package/dist/PluginManager-D5-ApsSN.js +111 -0
  5. package/dist/Router-i6Nc6qVs.js +386 -0
  6. package/dist/builder-6GkZlCaz.js +1894 -0
  7. package/dist/bundle-mjs-wppB-TKB.js +2760 -0
  8. package/dist/cli/bin.js +20 -0
  9. package/dist/cli/commands/generate/component.js +67 -0
  10. package/dist/cli/commands/generate/index.js +10 -0
  11. package/dist/cli/commands/generate/module.js +58 -0
  12. package/dist/cli/commands/generate/plugin.js +67 -0
  13. package/dist/cli/commands/init.js +58 -0
  14. package/dist/content.js +17 -0
  15. package/dist/core.js +33 -0
  16. package/dist/{effects-D16XdB_d.mjs → effects-CnevV566.js} +1 -0
  17. package/dist/index-BaX5zy8O.js +33 -0
  18. package/dist/index-C4xZywsh.js +1024 -0
  19. package/dist/index-C8y7FIYH.js +119 -0
  20. package/dist/index-CREALegH.js +1031 -0
  21. package/dist/index-CWz0hYog.js +778 -0
  22. package/dist/index-OLW4l8s8.js +1102 -0
  23. package/dist/index-zOfPHD00.js +90 -0
  24. package/dist/index.d.ts +43764 -6
  25. package/dist/index.js +2070 -0
  26. package/dist/interactive.js +12 -0
  27. package/dist/layout.js +18 -0
  28. package/dist/mount-rDUAHuDT.js +95 -0
  29. package/dist/navigation.js +13 -0
  30. package/dist/provider-B0eB-Wy7.js +286 -0
  31. package/dist/structure.js +15 -0
  32. package/dist/style.css +1 -1
  33. package/dist/style.js +1 -0
  34. package/dist/theme.js +9 -0
  35. package/package.json +88 -13
  36. package/dist/content/Alert/index.d.ts +0 -878
  37. package/dist/content/Avatar/index.d.ts +0 -886
  38. package/dist/content/Badge/index.d.ts +0 -887
  39. package/dist/content/Image/index.d.ts +0 -893
  40. package/dist/content/Label/index.d.ts +0 -879
  41. package/dist/content/Progress/index.d.ts +0 -898
  42. package/dist/content/Skeleton/index.d.ts +0 -879
  43. package/dist/content/Spinner/index.d.ts +0 -880
  44. package/dist/content/Text/index.d.ts +0 -878
  45. package/dist/content/index.d.ts +0 -9
  46. package/dist/core/StateWrapper.d.ts +0 -31
  47. package/dist/core/builder.d.ts +0 -58
  48. package/dist/core/component.d.ts +0 -7
  49. package/dist/core/effects.d.ts +0 -4
  50. package/dist/core/hooks.d.ts +0 -5
  51. package/dist/core/icons.d.ts +0 -11
  52. package/dist/core/index.d.ts +0 -6
  53. package/dist/core/state.d.ts +0 -86
  54. package/dist/core/types.d.ts +0 -51
  55. package/dist/demo.d.ts +0 -7
  56. package/dist/index.esm.js +0 -4777
  57. package/dist/index.umd.js +0 -251
  58. package/dist/interactive/Button/index.d.ts +0 -897
  59. package/dist/interactive/Checkbox/index.d.ts +0 -884
  60. package/dist/interactive/Combobox/index.d.ts +0 -898
  61. package/dist/interactive/RadioGroup/index.d.ts +0 -888
  62. package/dist/interactive/Select/index.d.ts +0 -895
  63. package/dist/interactive/Switch/index.d.ts +0 -881
  64. package/dist/interactive/TextField/index.d.ts +0 -893
  65. package/dist/interactive/Textarea/index.d.ts +0 -890
  66. package/dist/interactive/index.d.ts +0 -8
  67. package/dist/layout/Center/index.d.ts +0 -869
  68. package/dist/layout/Column/index.d.ts +0 -881
  69. package/dist/layout/Container/index.d.ts +0 -870
  70. package/dist/layout/DashboardLayout/index.d.ts +0 -870
  71. package/dist/layout/Header/index.d.ts +0 -870
  72. package/dist/layout/Line/index.d.ts +0 -872
  73. package/dist/layout/Row/index.d.ts +0 -879
  74. package/dist/layout/Scaffold/index.d.ts +0 -878
  75. package/dist/layout/ScrollView/index.d.ts +0 -879
  76. package/dist/layout/Sidebar/index.d.ts +0 -870
  77. package/dist/layout/Spacer/index.d.ts +0 -875
  78. package/dist/layout/StakentComponents.d.ts +0 -4
  79. package/dist/layout/index.d.ts +0 -11
  80. package/dist/structure/Banner/index.d.ts +0 -879
  81. package/dist/structure/Box/index.d.ts +0 -869
  82. package/dist/structure/Card/index.d.ts +0 -881
  83. package/dist/structure/Collapse/index.d.ts +0 -884
  84. package/dist/structure/Grid/index.d.ts +0 -1757
  85. package/dist/structure/List/index.d.ts +0 -888
  86. package/dist/structure/Table/index.d.ts +0 -895
  87. package/dist/structure/Tags/index.d.ts +0 -876
  88. package/dist/structure/cards/AssetCard/index.d.ts +0 -884
  89. package/dist/structure/cards/CollectionCard/index.d.ts +0 -880
  90. package/dist/structure/cards/ContentCard/index.d.ts +0 -884
  91. package/dist/structure/cards/ProfileCard/index.d.ts +0 -892
  92. package/dist/structure/cards/index.d.ts +0 -5
  93. package/dist/structure/cards/variants/index.d.ts +0 -3490
  94. package/dist/structure/index.d.ts +0 -9
  95. package/dist/theme/cupertino.d.ts +0 -3
  96. package/dist/theme/index.d.ts +0 -5
  97. package/dist/theme/material.d.ts +0 -3
  98. package/dist/theme/provider.d.ts +0 -16
  99. package/dist/theme/types.d.ts +0 -57
  100. package/dist/theme/web.d.ts +0 -3
  101. package/src/content/Alert/index.ts +0 -110
  102. package/src/content/Avatar/index.ts +0 -116
  103. package/src/content/Badge/index.ts +0 -162
  104. package/src/content/Image/index.ts +0 -137
  105. package/src/content/Label/index.ts +0 -66
  106. package/src/content/Progress/index.ts +0 -378
  107. package/src/content/Skeleton/index.ts +0 -71
  108. package/src/content/Spinner/index.ts +0 -139
  109. package/src/content/Text/index.ts +0 -74
  110. package/src/content/index.ts +0 -9
  111. package/src/core/StateWrapper.tsx +0 -131
  112. package/src/core/builder.ts +0 -301
  113. package/src/core/component.ts +0 -49
  114. package/src/core/effects.ts +0 -27
  115. package/src/core/hooks.ts +0 -48
  116. package/src/core/icons.tsx +0 -57
  117. package/src/core/index.ts +0 -6
  118. package/src/core/state.ts +0 -297
  119. package/src/core/types.ts +0 -62
  120. package/src/demo.tsx +0 -1050
  121. package/src/index.ts +0 -8
  122. package/src/interactive/Button/index.ts +0 -219
  123. package/src/interactive/Checkbox/index.ts +0 -145
  124. package/src/interactive/Combobox/index.ts +0 -278
  125. package/src/interactive/RadioGroup/index.ts +0 -124
  126. package/src/interactive/Select/index.ts +0 -227
  127. package/src/interactive/Switch/index.ts +0 -123
  128. package/src/interactive/TextField/index.ts +0 -223
  129. package/src/interactive/Textarea/index.ts +0 -129
  130. package/src/interactive/index.ts +0 -8
  131. package/src/layout/Center/index.ts +0 -34
  132. package/src/layout/Column/index.ts +0 -101
  133. package/src/layout/Container/index.ts +0 -28
  134. package/src/layout/DashboardLayout/index.ts +0 -106
  135. package/src/layout/Header/index.ts +0 -50
  136. package/src/layout/Line/index.ts +0 -41
  137. package/src/layout/Row/index.ts +0 -93
  138. package/src/layout/Scaffold/index.ts +0 -133
  139. package/src/layout/ScrollView/index.ts +0 -67
  140. package/src/layout/Sidebar/index.ts +0 -56
  141. package/src/layout/Spacer/index.ts +0 -46
  142. package/src/layout/StakentComponents.tsx +0 -57
  143. package/src/layout/index.ts +0 -11
  144. package/src/structure/Banner/index.ts +0 -92
  145. package/src/structure/Box/index.ts +0 -46
  146. package/src/structure/Card/index.ts +0 -113
  147. package/src/structure/Collapse/index.ts +0 -122
  148. package/src/structure/Grid/index.ts +0 -197
  149. package/src/structure/List/index.ts +0 -185
  150. package/src/structure/Table/index.ts +0 -165
  151. package/src/structure/Tags/index.ts +0 -69
  152. package/src/structure/cards/AssetCard/index.ts +0 -158
  153. package/src/structure/cards/CollectionCard/index.ts +0 -95
  154. package/src/structure/cards/ContentCard/index.ts +0 -127
  155. package/src/structure/cards/ProfileCard/index.ts +0 -152
  156. package/src/structure/cards/index.ts +0 -5
  157. package/src/structure/cards/variants/index.ts +0 -301
  158. package/src/structure/index.ts +0 -10
  159. package/src/styles/base.css +0 -186
  160. package/src/styles/core.css +0 -52
  161. package/src/styles/themes/cupertino.css +0 -197
  162. package/src/styles/themes/material.css +0 -322
  163. package/src/styles/themes/web.css +0 -196
  164. package/src/theme/cupertino.ts +0 -85
  165. package/src/theme/index.ts +0 -5
  166. package/src/theme/material.ts +0 -86
  167. package/src/theme/provider.tsx +0 -76
  168. package/src/theme/types.ts +0 -62
  169. package/src/theme/web.ts +0 -82
@@ -1,124 +0,0 @@
1
- import React, { ReactElement } from 'react';
2
- import { FiboBuilder, createBuilder } from '../../core/builder';
3
- import { BaseProps } from '../../core/types';
4
-
5
- interface RadioOption {
6
- label: string;
7
- value: string;
8
- disabled?: boolean;
9
- }
10
-
11
- const RadioGroupInner = React.memo((props: any) => {
12
- const {
13
- value,
14
- options,
15
- onChange,
16
- name,
17
- direction,
18
- className,
19
- style
20
- } = props;
21
-
22
- return React.createElement(
23
- 'div',
24
- {
25
- className: `fibo-radio-group flex ${direction === 'vertical' ? 'flex-col gap-2' : 'flex-row gap-4'} ${className}`,
26
- style: style
27
- },
28
- options.map((option: any) => {
29
- const isSelected = value === option.value;
30
- const isDisabled = option.disabled;
31
-
32
- return React.createElement(
33
- 'label',
34
- {
35
- key: option.value,
36
- className: `flex items-center gap-2 cursor-pointer ${isDisabled ? 'opacity-50 cursor-not-allowed' : ''}`
37
- },
38
- React.createElement(
39
- 'div',
40
- {
41
- className: 'relative flex items-center justify-center',
42
- style: {
43
- width: '18px',
44
- height: '18px',
45
- borderRadius: '50%',
46
- border: isSelected ? '5px solid var(--fibo-primary, #3B82F6)' : '2px solid #D1D5DB',
47
- transition: 'all 0.2s',
48
- }
49
- },
50
- React.createElement('input', {
51
- type: 'radio',
52
- name: name,
53
- value: option.value,
54
- checked: isSelected,
55
- disabled: isDisabled,
56
- className: 'sr-only',
57
- onChange: () => !isDisabled && onChange?.(option.value)
58
- })
59
- ),
60
- React.createElement(
61
- 'span',
62
- { className: 'text-sm text-gray-700' },
63
- option.label
64
- )
65
- );
66
- })
67
- );
68
- });
69
-
70
- class RadioGroupBuilder extends FiboBuilder {
71
- private _value: string = '';
72
- private _options: RadioOption[] = [];
73
- private _onChange?: (value: string) => void;
74
- private _name: string = `radio-group-${Math.random().toString(36).substr(2, 9)}`;
75
- private _direction: 'vertical' | 'horizontal' = 'vertical';
76
-
77
- value(val: string): this {
78
- this._value = val;
79
- return this;
80
- }
81
-
82
- options(opts: RadioOption[]): this {
83
- this._options = opts;
84
- return this;
85
- }
86
-
87
- onChange(handler: (val: string) => void): this {
88
- this._onChange = handler;
89
- return this;
90
- }
91
-
92
- direction(dir: 'vertical' | 'horizontal'): this {
93
- this._direction = dir;
94
- return this;
95
- }
96
-
97
- name(val: string): this {
98
- this._name = val;
99
- return this;
100
- }
101
-
102
- build(): ReactElement {
103
- const props = {
104
- value: this._value,
105
- options: this._options,
106
- onChange: this._onChange,
107
- name: this._name,
108
- direction: this._direction,
109
- className: this.getClassName(),
110
- style: this.getStyle()
111
- };
112
- return React.createElement(RadioGroupInner, props);
113
- }
114
- }
115
-
116
-
117
- export const RadioGroup = createBuilder(RadioGroupBuilder);
118
-
119
- export interface RadioGroupProps extends BaseProps {
120
- value: string;
121
- options: RadioOption[];
122
- onChange?: (value: string) => void;
123
- direction?: 'vertical' | 'horizontal';
124
- }
@@ -1,227 +0,0 @@
1
- import React, { ReactElement, useState, useRef, useEffect } from 'react';
2
- import { FiboBuilder, createBuilder } from '../../core/builder';
3
- import { BaseProps } from '../../core/types';
4
-
5
- interface Option {
6
- label: string;
7
- value: string;
8
- }
9
-
10
- const SelectInner = React.memo((props: any) => {
11
- const uniqueId = React.useId();
12
- const inputId = props.id || uniqueId;
13
- const [isOpen, setIsOpen] = useState(false);
14
- const containerRef = useRef<HTMLDivElement>(null);
15
-
16
- const {
17
- containerClass,
18
- containerStyle,
19
- label,
20
- error,
21
- value,
22
- options = [],
23
- placeholder,
24
- onChange,
25
- disabled,
26
- multiple,
27
- ...rest
28
- } = props;
29
-
30
- useEffect(() => {
31
- const handleClickOutside = (event: MouseEvent) => {
32
- if (containerRef.current && !containerRef.current.contains(event.target as Node)) {
33
- setIsOpen(false);
34
- }
35
- };
36
- document.addEventListener('mousedown', handleClickOutside);
37
- return () => document.removeEventListener('mousedown', handleClickOutside);
38
- }, []);
39
-
40
- const isSelected = (val: string) => {
41
- if (multiple) {
42
- return Array.isArray(value) && value.includes(val);
43
- }
44
- return value === val;
45
- };
46
-
47
- let displayText = '';
48
- if (multiple) {
49
- if (Array.isArray(value) && value.length > 0) {
50
- displayText = options
51
- .filter((opt: Option) => value.includes(opt.value))
52
- .map((opt: Option) => opt.label)
53
- .join(', ');
54
- }
55
- } else {
56
- const selectedOption = options.find((opt: Option) => opt.value === value);
57
- displayText = selectedOption ? selectedOption.label : '';
58
- }
59
-
60
- const handleSelect = (val: string) => {
61
- if (disabled) return;
62
-
63
- if (multiple) {
64
- const currentValues = Array.isArray(value) ? [...value] : [];
65
- const index = currentValues.indexOf(val);
66
- if (index > -1) {
67
- currentValues.splice(index, 1);
68
- } else {
69
- currentValues.push(val);
70
- }
71
- onChange?.(currentValues);
72
- } else {
73
- onChange?.(val);
74
- setIsOpen(false);
75
- }
76
- };
77
-
78
- return React.createElement(
79
- 'div',
80
- {
81
- ref: containerRef,
82
- className: containerClass,
83
- style: containerStyle
84
- },
85
- React.createElement('div', { className: 'relative w-full' }, [
86
- React.createElement('button', {
87
- key: 'trigger',
88
- id: inputId,
89
- type: 'button',
90
- disabled: disabled,
91
- className: `fibo-textfield-input text-left w-full flex items-center justify-between ${!displayText ? 'text-gray-400' : ''}`,
92
- onClick: () => !disabled && setIsOpen(!isOpen),
93
- ...rest
94
- }, [
95
- React.createElement('span', { key: 'text', className: 'truncate' }, displayText || placeholder || ' '),
96
- React.createElement('svg', {
97
- key: 'icon',
98
- className: `w-4 h-4 transition-transform ${isOpen ? 'rotate-180' : ''}`,
99
- fill: "none",
100
- stroke: "currentColor",
101
- viewBox: "0 0 24 24"
102
- }, React.createElement('path', { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M19 9l-7 7-7-7" }))
103
- ]),
104
-
105
- label && React.createElement(
106
- 'label',
107
- {
108
- key: 'label',
109
- htmlFor: inputId,
110
- className: 'fibo-textfield-label'
111
- },
112
- label
113
- ),
114
-
115
- isOpen && React.createElement('div', {
116
- key: 'dropdown',
117
- className: 'absolute z-50 w-full mt-1 bg-[var(--fibo-surface)] border border-[var(--fibo-outline)] rounded-md shadow-lg max-h-60 overflow-auto focus:outline-none'
118
- }, options.map((opt: Option) => {
119
- const selected = isSelected(opt.value);
120
- return React.createElement('div', {
121
- key: opt.value,
122
- className: `px-4 py-2 cursor-pointer text-sm hover:bg-[var(--fibo-primary-container)] hover:text-[var(--fibo-on-primary-container)] flex items-center justify-between ${selected ? 'bg-[var(--fibo-primary-container)] text-[var(--fibo-on-primary-container)] font-medium' : 'text-[var(--fibo-on-surface)]'}`,
123
- onClick: () => handleSelect(opt.value)
124
- }, [
125
- React.createElement('span', { key: 'label' }, opt.label),
126
- selected && React.createElement('svg', {
127
- key: 'check',
128
- className: "w-4 h-4 text-[var(--fibo-primary)]",
129
- viewBox: "0 0 20 20",
130
- fill: "currentColor"
131
- }, React.createElement('path', { fillRule: "evenodd", d: "M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z", clipRule: "evenodd" }))
132
- ])
133
- }))
134
- ]),
135
-
136
- error && React.createElement(
137
- 'span',
138
- { className: 'text-[var(--fibo-error)] text-xs mt-1 ml-1' },
139
- error
140
- )
141
- );
142
- });
143
-
144
- class SelectBuilder extends FiboBuilder {
145
- private _value: string | string[] = '';
146
- private _label: string = '';
147
- private _placeholder: string = '';
148
- private _disabled: boolean = false;
149
- private _error?: string;
150
- private _multiple: boolean = false;
151
- private _options: Option[] = [];
152
- private _onChange?: (value: string | string[]) => void;
153
-
154
- value(val: string | string[]): this {
155
- this._value = val;
156
- return this;
157
- }
158
-
159
- label(val: string): this {
160
- this._label = val;
161
- return this;
162
- }
163
-
164
- placeholder(val: string): this {
165
- this._placeholder = val;
166
- return this;
167
- }
168
-
169
- options(opts: Option[]): this {
170
- this._options = opts;
171
- return this;
172
- }
173
-
174
- multiple(val: boolean = true): this {
175
- this._multiple = val;
176
- return this;
177
- }
178
-
179
- disabled(val: boolean = true): this {
180
- this._disabled = val;
181
- return this;
182
- }
183
-
184
- error(val: string): this {
185
- this._error = val;
186
- return this;
187
- }
188
-
189
- onChange(handler: (value: string | string[]) => void): this {
190
- this._onChange = handler;
191
- return this;
192
- }
193
-
194
- build(): ReactElement {
195
- const containerClass = ['fibo-textfield-container relative', ...this._classNames]
196
- .filter(Boolean)
197
- .join(' ');
198
-
199
- const props = {
200
- containerClass,
201
- containerStyle: this.getStyle(),
202
- label: this._label,
203
- error: this._error,
204
- value: this._value,
205
- placeholder: this._placeholder,
206
- options: this._options,
207
- disabled: this._disabled,
208
- multiple: this._multiple,
209
- onChange: this._onChange,
210
- ...this._props
211
- };
212
-
213
- return React.createElement(SelectInner, props);
214
- }
215
- }
216
-
217
-
218
- export const Select = createBuilder(SelectBuilder);
219
-
220
- export interface SelectProps extends BaseProps {
221
- value: string | string[];
222
- label?: string;
223
- placeholder?: string;
224
- multiple?: boolean;
225
- options: Option[];
226
- onChange?: (value: string | string[]) => void;
227
- }
@@ -1,123 +0,0 @@
1
- import React, { ReactElement } from 'react';
2
- import { FiboBuilder, createBuilder } from '../../core/builder';
3
- import { BaseProps } from '../../core/types';
4
-
5
- const SwitchInner = React.memo((props: any) => {
6
- const {
7
- checked,
8
- onChange,
9
- label,
10
- disabled,
11
- className,
12
- style
13
- } = props;
14
-
15
-
16
- const trackBaseStyle: React.CSSProperties = {
17
- width: '44px',
18
- height: '24px',
19
- borderRadius: '9999px',
20
- position: 'relative',
21
- transition: 'background-color 0.2s ease-in-out',
22
- cursor: disabled ? 'not-allowed' : 'pointer',
23
- opacity: disabled ? 0.5 : 1,
24
- backgroundColor: checked ? 'var(--fibo-primary, #3B82F6)' : '#E5E7EB',
25
- ...style
26
- };
27
-
28
- const thumbStyle: React.CSSProperties = {
29
- width: '20px',
30
- height: '20px',
31
- borderRadius: '50%',
32
- backgroundColor: 'white',
33
- position: 'absolute',
34
- top: '2px',
35
- left: '2px',
36
- transition: 'transform 0.2s ease-in-out',
37
- transform: checked ? 'translateX(20px)' : 'translateX(0)',
38
- boxShadow: '0 1px 3px rgba(0,0,0,0.1)'
39
- };
40
-
41
- return React.createElement(
42
- 'label',
43
- {
44
- className: `fibo-switch flex items-center gap-3 ${className}`
45
- },
46
- React.createElement(
47
- 'div',
48
- {
49
- className: 'fibo-switch-track',
50
- style: trackBaseStyle,
51
- onClick: (e: React.MouseEvent) => {
52
- e.preventDefault();
53
- if (!disabled && onChange) {
54
- onChange(!checked);
55
- }
56
- }
57
- },
58
- React.createElement('div', { style: thumbStyle })
59
- ),
60
- label && React.createElement(
61
- 'span',
62
- { className: 'text-sm font-medium text-gray-700 select-none' },
63
- label
64
- ),
65
-
66
- React.createElement('input', {
67
- type: 'checkbox',
68
- checked: checked,
69
- disabled: disabled,
70
- className: 'sr-only',
71
- onChange: (e: React.ChangeEvent<HTMLInputElement>) => !disabled && onChange?.(e.target.checked)
72
- })
73
- );
74
- });
75
-
76
- class SwitchBuilder extends FiboBuilder {
77
- private _checked: boolean = false;
78
- private _onChange?: (checked: boolean) => void;
79
- private _label?: string;
80
- private _disabled: boolean = false;
81
-
82
- checked(value: boolean): this {
83
- this._checked = value;
84
- return this;
85
- }
86
-
87
- onChange(handler: (checked: boolean) => void): this {
88
- this._onChange = handler;
89
- return this;
90
- }
91
-
92
- label(text: string): this {
93
- this._label = text;
94
- return this;
95
- }
96
-
97
- disabled(value: boolean = true): this {
98
- this._disabled = value;
99
- return this;
100
- }
101
-
102
- build(): ReactElement {
103
- const props = {
104
- checked: this._checked,
105
- onChange: this._onChange,
106
- label: this._label,
107
- disabled: this._disabled,
108
- className: this.getClassName(),
109
- style: this.getStyle()
110
- };
111
- return React.createElement(SwitchInner, props);
112
- }
113
- }
114
-
115
-
116
- export const Switch = createBuilder(SwitchBuilder);
117
-
118
- export interface SwitchProps extends BaseProps {
119
- checked: boolean;
120
- onChange?: (checked: boolean) => void;
121
- label?: string;
122
- disabled?: boolean;
123
- }
@@ -1,223 +0,0 @@
1
- import React, { ReactElement, ChangeEvent, useEffect, useState } from 'react';
2
- import { FiboBuilder, createBuilder } from '../../core/builder';
3
- import { BaseProps } from '../../core/types';
4
- import { Signal } from '../../core/state';
5
-
6
- const applyMask = (value: string, mask: string) => {
7
- let i = 0;
8
- const valueChars = value.replace(/\D/g, '').split('');
9
- let output = '';
10
-
11
- for (let m = 0; m < mask.length; m++) {
12
- if (i >= valueChars.length) break;
13
-
14
- if (mask[m] === '9') {
15
- output += valueChars[i++];
16
- } else {
17
- output += mask[m];
18
- }
19
- }
20
- return output;
21
- };
22
-
23
- const TextFieldInner = React.memo((props: any) => {
24
- const uniqueId = React.useId();
25
- const inputId = props.id || uniqueId;
26
- const [showPassword, setShowPassword] = React.useState(false);
27
-
28
- const {
29
- containerClass,
30
- containerStyle,
31
- label,
32
- error,
33
- mask,
34
- type,
35
- value, // Can be string or Signal
36
- onChange,
37
- ...inputRest
38
- } = props;
39
-
40
- // Handle Signal or primitive value
41
- const isSignal = value instanceof Signal;
42
- const [localValue, setLocalValue] = useState(isSignal ? value.value : value);
43
-
44
- // Sync with Signal updates
45
- useEffect(() => {
46
- if (isSignal) {
47
- const unsubscribe = value.subscribe((val: string) => {
48
- setLocalValue(val);
49
- });
50
- return unsubscribe;
51
- } else {
52
- setLocalValue(value);
53
- }
54
- }, [value, isSignal]);
55
-
56
- const isPassword = type === 'password';
57
- const effectiveType = isPassword && showPassword ? 'text' : type;
58
-
59
- const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
60
- let newValue = e.target.value;
61
- if (mask) {
62
- newValue = applyMask(newValue, mask);
63
-
64
- const syntheticEvent = {
65
- ...e,
66
- target: {
67
- ...e.target,
68
- value: newValue
69
- }
70
- } as React.ChangeEvent<HTMLInputElement>;
71
-
72
- if (isSignal) {
73
- value.value = newValue; // Update signal
74
- }
75
- onChange?.(syntheticEvent);
76
- } else {
77
- if (isSignal) {
78
- value.value = newValue; // Update signal
79
- }
80
- onChange?.(e);
81
- }
82
- };
83
-
84
- return React.createElement(
85
- 'div',
86
- { className: containerClass, style: containerStyle },
87
- React.createElement('div', { className: 'relative w-full' }, [
88
- React.createElement('input', {
89
- key: 'input',
90
- id: inputId,
91
- className: 'fibo-textfield-input',
92
- type: effectiveType,
93
- onChange: handleChange,
94
- value: localValue,
95
- ...inputRest
96
- }),
97
- label && React.createElement(
98
- 'label',
99
- {
100
- key: 'label',
101
- htmlFor: inputId,
102
- className: 'fibo-textfield-label'
103
- },
104
- label
105
- ),
106
- isPassword && React.createElement(
107
- 'button',
108
- {
109
- key: 'toggle',
110
- type: 'button',
111
- className: 'absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-400 hover:text-gray-600 focus:outline-none',
112
- onClick: () => setShowPassword(!showPassword),
113
- tabIndex: -1
114
- },
115
- showPassword ?
116
- React.createElement('svg', { width: 16, height: 16, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round" },
117
- React.createElement('path', { d: "M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24" }),
118
- React.createElement('line', { x1: 1, y1: 1, x2: 23, y2: 23 })
119
- ) :
120
- React.createElement('svg', { width: 16, height: 16, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round" },
121
- React.createElement('path', { d: "M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" }),
122
- React.createElement('circle', { cx: 12, cy: 12, r: 3 })
123
- )
124
- )
125
- ]),
126
- error && React.createElement(
127
- 'span',
128
- { className: 'text-[var(--fibo-error)] text-xs mt-1 ml-1' },
129
- error
130
- )
131
- );
132
- });
133
-
134
- class TextFieldBuilder extends FiboBuilder {
135
- private _value: string | Signal<string> = '';
136
- private _label: string = '';
137
- private _placeholder: string = '';
138
- private _type: string = 'text';
139
- private _disabled: boolean = false;
140
- private _error?: string;
141
- private _mask?: string;
142
- private _onChange?: (value: string) => void;
143
-
144
- constructor(value: string = '') {
145
- super();
146
- this._value = value;
147
- }
148
-
149
- value(val: string | Signal<string>): this {
150
- this._value = val;
151
- return this;
152
- }
153
-
154
- label(val: string): this {
155
- this._label = val;
156
- return this;
157
- }
158
-
159
- placeholder(val: string): this {
160
- this._placeholder = val;
161
- return this;
162
- }
163
-
164
- type(val: 'text' | 'password' | 'email' | 'number' | 'tel'): this {
165
- this._type = val;
166
- return this;
167
- }
168
-
169
- mask(format: string): this {
170
- this._mask = format;
171
- return this;
172
- }
173
-
174
- disabled(val: boolean = true): this {
175
- this._disabled = val;
176
- return this;
177
- }
178
-
179
- error(val: string): this {
180
- this._error = val;
181
- return this;
182
- }
183
-
184
- onChange(handler: (value: string) => void): this {
185
- this._onChange = handler;
186
- return this;
187
- }
188
-
189
- build(): ReactElement {
190
- const containerClass = ['fibo-textfield-container', ...this._classNames]
191
- .filter(Boolean)
192
- .join(' ');
193
-
194
- const props = {
195
- containerClass,
196
- containerStyle: this.getStyle(),
197
- label: this._label,
198
- error: this._error,
199
- value: this._value,
200
- placeholder: this._placeholder || ' ',
201
- type: this._type,
202
- mask: this._mask,
203
- disabled: this._disabled,
204
- onChange: (e: ChangeEvent<HTMLInputElement>) => {
205
- this._onChange?.(e.target.value);
206
- },
207
- ...this._props
208
- };
209
-
210
- return React.createElement(TextFieldInner, props);
211
- }
212
- }
213
-
214
- export const TextField = createBuilder(TextFieldBuilder);
215
-
216
- export interface TextFieldProps extends BaseProps {
217
- value: string | Signal<string>;
218
- label?: string;
219
- placeholder?: string;
220
- onChange?: (value: string) => void;
221
- type?: 'text' | 'password' | 'email' | 'number' | 'tel';
222
- mask?: string;
223
- }