fiboui 1.0.2 → 2.0.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.
- package/README.md +138 -92
- package/dist/FineGrain-kBxv0WeR.js +29 -0
- package/dist/Link-DDzSPY1Q.js +88 -0
- package/dist/PluginManager-D5-ApsSN.js +111 -0
- package/dist/Router-i6Nc6qVs.js +386 -0
- package/dist/builder-DjLYXkXu.js +1842 -0
- package/dist/bundle-mjs-wppB-TKB.js +2760 -0
- package/dist/cli/bin.js +20 -0
- package/dist/cli/commands/generate/component.js +67 -0
- package/dist/cli/commands/generate/index.js +10 -0
- package/dist/cli/commands/generate/module.js +58 -0
- package/dist/cli/commands/generate/plugin.js +67 -0
- package/dist/cli/commands/init.js +58 -0
- package/dist/content.js +17 -0
- package/dist/core.js +33 -0
- package/dist/{effects-D16XdB_d.mjs → effects-CnevV566.js} +1 -0
- package/dist/index-B1av7e36.js +1102 -0
- package/dist/index-BQGRpkzR.js +1024 -0
- package/dist/index-CTRZRn9S.js +90 -0
- package/dist/index-DKFr-sai.js +33 -0
- package/dist/index-Dm4j2mMM.js +1031 -0
- package/dist/index-RbfIZuAo.js +119 -0
- package/dist/index-yeYkDTAx.js +778 -0
- package/dist/index.d.ts +43753 -6
- package/dist/index.js +2054 -0
- package/dist/interactive.js +12 -0
- package/dist/layout.js +18 -0
- package/dist/mount-sAVX_FBU.js +95 -0
- package/dist/navigation.js +13 -0
- package/dist/provider-B0eB-Wy7.js +286 -0
- package/dist/structure.js +15 -0
- package/dist/style.css +1 -1
- package/dist/style.js +1 -0
- package/dist/theme.js +9 -0
- package/package.json +88 -13
- package/dist/content/Alert/index.d.ts +0 -878
- package/dist/content/Avatar/index.d.ts +0 -886
- package/dist/content/Badge/index.d.ts +0 -887
- package/dist/content/Image/index.d.ts +0 -893
- package/dist/content/Label/index.d.ts +0 -879
- package/dist/content/Progress/index.d.ts +0 -898
- package/dist/content/Skeleton/index.d.ts +0 -879
- package/dist/content/Spinner/index.d.ts +0 -880
- package/dist/content/Text/index.d.ts +0 -878
- package/dist/content/index.d.ts +0 -9
- package/dist/core/StateWrapper.d.ts +0 -31
- package/dist/core/builder.d.ts +0 -58
- package/dist/core/component.d.ts +0 -7
- package/dist/core/effects.d.ts +0 -4
- package/dist/core/hooks.d.ts +0 -5
- package/dist/core/icons.d.ts +0 -11
- package/dist/core/index.d.ts +0 -6
- package/dist/core/state.d.ts +0 -86
- package/dist/core/types.d.ts +0 -51
- package/dist/demo.d.ts +0 -7
- package/dist/index.esm.js +0 -4777
- package/dist/index.umd.js +0 -251
- package/dist/interactive/Button/index.d.ts +0 -897
- package/dist/interactive/Checkbox/index.d.ts +0 -884
- package/dist/interactive/Combobox/index.d.ts +0 -898
- package/dist/interactive/RadioGroup/index.d.ts +0 -888
- package/dist/interactive/Select/index.d.ts +0 -895
- package/dist/interactive/Switch/index.d.ts +0 -881
- package/dist/interactive/TextField/index.d.ts +0 -893
- package/dist/interactive/Textarea/index.d.ts +0 -890
- package/dist/interactive/index.d.ts +0 -8
- package/dist/layout/Center/index.d.ts +0 -869
- package/dist/layout/Column/index.d.ts +0 -881
- package/dist/layout/Container/index.d.ts +0 -870
- package/dist/layout/DashboardLayout/index.d.ts +0 -870
- package/dist/layout/Header/index.d.ts +0 -870
- package/dist/layout/Line/index.d.ts +0 -872
- package/dist/layout/Row/index.d.ts +0 -879
- package/dist/layout/Scaffold/index.d.ts +0 -878
- package/dist/layout/ScrollView/index.d.ts +0 -879
- package/dist/layout/Sidebar/index.d.ts +0 -870
- package/dist/layout/Spacer/index.d.ts +0 -875
- package/dist/layout/StakentComponents.d.ts +0 -4
- package/dist/layout/index.d.ts +0 -11
- package/dist/structure/Banner/index.d.ts +0 -879
- package/dist/structure/Box/index.d.ts +0 -869
- package/dist/structure/Card/index.d.ts +0 -881
- package/dist/structure/Collapse/index.d.ts +0 -884
- package/dist/structure/Grid/index.d.ts +0 -1757
- package/dist/structure/List/index.d.ts +0 -888
- package/dist/structure/Table/index.d.ts +0 -895
- package/dist/structure/Tags/index.d.ts +0 -876
- package/dist/structure/cards/AssetCard/index.d.ts +0 -884
- package/dist/structure/cards/CollectionCard/index.d.ts +0 -880
- package/dist/structure/cards/ContentCard/index.d.ts +0 -884
- package/dist/structure/cards/ProfileCard/index.d.ts +0 -892
- package/dist/structure/cards/index.d.ts +0 -5
- package/dist/structure/cards/variants/index.d.ts +0 -3490
- package/dist/structure/index.d.ts +0 -9
- package/dist/theme/cupertino.d.ts +0 -3
- package/dist/theme/index.d.ts +0 -5
- package/dist/theme/material.d.ts +0 -3
- package/dist/theme/provider.d.ts +0 -16
- package/dist/theme/types.d.ts +0 -57
- package/dist/theme/web.d.ts +0 -3
- package/src/content/Alert/index.ts +0 -110
- package/src/content/Avatar/index.ts +0 -116
- package/src/content/Badge/index.ts +0 -162
- package/src/content/Image/index.ts +0 -137
- package/src/content/Label/index.ts +0 -66
- package/src/content/Progress/index.ts +0 -378
- package/src/content/Skeleton/index.ts +0 -71
- package/src/content/Spinner/index.ts +0 -139
- package/src/content/Text/index.ts +0 -74
- package/src/content/index.ts +0 -9
- package/src/core/StateWrapper.tsx +0 -131
- package/src/core/builder.ts +0 -301
- package/src/core/component.ts +0 -49
- package/src/core/effects.ts +0 -27
- package/src/core/hooks.ts +0 -48
- package/src/core/icons.tsx +0 -57
- package/src/core/index.ts +0 -6
- package/src/core/state.ts +0 -297
- package/src/core/types.ts +0 -62
- package/src/demo.tsx +0 -1050
- package/src/index.ts +0 -8
- package/src/interactive/Button/index.ts +0 -219
- package/src/interactive/Checkbox/index.ts +0 -145
- package/src/interactive/Combobox/index.ts +0 -278
- package/src/interactive/RadioGroup/index.ts +0 -124
- package/src/interactive/Select/index.ts +0 -227
- package/src/interactive/Switch/index.ts +0 -123
- package/src/interactive/TextField/index.ts +0 -223
- package/src/interactive/Textarea/index.ts +0 -129
- package/src/interactive/index.ts +0 -8
- package/src/layout/Center/index.ts +0 -34
- package/src/layout/Column/index.ts +0 -101
- package/src/layout/Container/index.ts +0 -28
- package/src/layout/DashboardLayout/index.ts +0 -106
- package/src/layout/Header/index.ts +0 -50
- package/src/layout/Line/index.ts +0 -41
- package/src/layout/Row/index.ts +0 -93
- package/src/layout/Scaffold/index.ts +0 -133
- package/src/layout/ScrollView/index.ts +0 -67
- package/src/layout/Sidebar/index.ts +0 -56
- package/src/layout/Spacer/index.ts +0 -46
- package/src/layout/StakentComponents.tsx +0 -57
- package/src/layout/index.ts +0 -11
- package/src/structure/Banner/index.ts +0 -92
- package/src/structure/Box/index.ts +0 -46
- package/src/structure/Card/index.ts +0 -113
- package/src/structure/Collapse/index.ts +0 -122
- package/src/structure/Grid/index.ts +0 -197
- package/src/structure/List/index.ts +0 -185
- package/src/structure/Table/index.ts +0 -165
- package/src/structure/Tags/index.ts +0 -69
- package/src/structure/cards/AssetCard/index.ts +0 -158
- package/src/structure/cards/CollectionCard/index.ts +0 -95
- package/src/structure/cards/ContentCard/index.ts +0 -127
- package/src/structure/cards/ProfileCard/index.ts +0 -152
- package/src/structure/cards/index.ts +0 -5
- package/src/structure/cards/variants/index.ts +0 -301
- package/src/structure/index.ts +0 -10
- package/src/styles/base.css +0 -186
- package/src/styles/core.css +0 -52
- package/src/styles/themes/cupertino.css +0 -197
- package/src/styles/themes/material.css +0 -322
- package/src/styles/themes/web.css +0 -196
- package/src/theme/cupertino.ts +0 -85
- package/src/theme/index.ts +0 -5
- package/src/theme/material.ts +0 -86
- package/src/theme/provider.tsx +0 -76
- package/src/theme/types.ts +0 -62
- package/src/theme/web.ts +0 -82
package/src/index.ts
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
import React, { ReactElement, ReactNode } from 'react';
|
|
2
|
-
import { FiboBuilder, createBuilder } from '../../core/builder';
|
|
3
|
-
import { BaseProps, ButtonVariant } from '../../core/types';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
type ExtendedButtonVariant = ButtonVariant | 'ghost' | 'soft' | 'outline' | 'text';
|
|
7
|
-
type ButtonSize = 'sm' | 'md' | 'lg';
|
|
8
|
-
type ButtonShape = 'default' | 'pill' | 'square';
|
|
9
|
-
|
|
10
|
-
const ButtonInner = React.memo((props: any) => {
|
|
11
|
-
const {
|
|
12
|
-
text,
|
|
13
|
-
variant,
|
|
14
|
-
size,
|
|
15
|
-
onPress,
|
|
16
|
-
disabled,
|
|
17
|
-
icon,
|
|
18
|
-
shape,
|
|
19
|
-
shadow,
|
|
20
|
-
className,
|
|
21
|
-
style,
|
|
22
|
-
...rest
|
|
23
|
-
} = props;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const finalStyle = { ...style };
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const sizeStyles: Record<ButtonSize, any> = {
|
|
30
|
-
sm: { padding: '6px 14px', fontSize: '13px', gap: '6px', height: '32px' },
|
|
31
|
-
md: { padding: '10px 22px', fontSize: '15px', gap: '8px', height: '44px' },
|
|
32
|
-
lg: { padding: '16px 32px', fontSize: '17px', gap: '10px', height: '56px' }
|
|
33
|
-
};
|
|
34
|
-
Object.assign(finalStyle, sizeStyles[size as ButtonSize]);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (shape === 'pill') {
|
|
38
|
-
finalStyle.borderRadius = '9999px';
|
|
39
|
-
} else if (shape === 'square') {
|
|
40
|
-
finalStyle.borderRadius = '12px';
|
|
41
|
-
} else {
|
|
42
|
-
finalStyle.borderRadius = '14px';
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (shadow === 'soft') {
|
|
47
|
-
|
|
48
|
-
finalStyle.boxShadow = '0 8px 20px -6px rgba(59, 130, 246, 0.4)';
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (variant === 'ghost') {
|
|
53
|
-
finalStyle.backgroundColor = 'transparent';
|
|
54
|
-
finalStyle.color = '#4B5563';
|
|
55
|
-
finalStyle.boxShadow = 'none';
|
|
56
|
-
finalStyle.border = '1px solid transparent';
|
|
57
|
-
}
|
|
58
|
-
else if (variant === 'text') {
|
|
59
|
-
finalStyle.backgroundColor = 'transparent';
|
|
60
|
-
finalStyle.color = '#4B5563';
|
|
61
|
-
finalStyle.boxShadow = 'none';
|
|
62
|
-
finalStyle.border = 'none';
|
|
63
|
-
finalStyle.paddingLeft = '8px';
|
|
64
|
-
finalStyle.paddingRight = '8px';
|
|
65
|
-
}
|
|
66
|
-
else if (variant === 'soft') {
|
|
67
|
-
|
|
68
|
-
finalStyle.backgroundColor = '#EEF2FF';
|
|
69
|
-
finalStyle.color = '#4F46E5';
|
|
70
|
-
finalStyle.boxShadow = 'none';
|
|
71
|
-
finalStyle.border = 'none';
|
|
72
|
-
} else if (variant === 'outline') {
|
|
73
|
-
finalStyle.backgroundColor = 'transparent';
|
|
74
|
-
finalStyle.border = '1.5px solid #E5E7EB';
|
|
75
|
-
finalStyle.color = '#374151';
|
|
76
|
-
finalStyle.boxShadow = 'none';
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const children = [];
|
|
80
|
-
if (icon) {
|
|
81
|
-
children.push(icon);
|
|
82
|
-
}
|
|
83
|
-
if (text) {
|
|
84
|
-
children.push(text);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return React.createElement(
|
|
88
|
-
'button',
|
|
89
|
-
{
|
|
90
|
-
className,
|
|
91
|
-
style: {
|
|
92
|
-
display: 'inline-flex',
|
|
93
|
-
alignItems: 'center',
|
|
94
|
-
justifyContent: 'center',
|
|
95
|
-
cursor: disabled ? 'not-allowed' : 'pointer',
|
|
96
|
-
opacity: disabled ? 0.6 : 1,
|
|
97
|
-
fontWeight: 600,
|
|
98
|
-
whiteSpace: 'nowrap',
|
|
99
|
-
...finalStyle
|
|
100
|
-
},
|
|
101
|
-
onClick: (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
102
|
-
if (!disabled) {
|
|
103
|
-
|
|
104
|
-
if (document.documentElement.classList.contains('fibo-theme-material')) {
|
|
105
|
-
const target = e.currentTarget;
|
|
106
|
-
import('../../core/effects').then(({ createRipple }) => {
|
|
107
|
-
createRipple(e, target);
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
onPress?.();
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
disabled: disabled,
|
|
114
|
-
...rest,
|
|
115
|
-
},
|
|
116
|
-
...children
|
|
117
|
-
);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
class ButtonBuilder extends FiboBuilder {
|
|
121
|
-
private _text: string = '';
|
|
122
|
-
private _variant: ExtendedButtonVariant = 'elevated';
|
|
123
|
-
private _size: ButtonSize = 'md';
|
|
124
|
-
private _onPress?: () => void;
|
|
125
|
-
private _disabled: boolean = false;
|
|
126
|
-
private _icon?: ReactNode;
|
|
127
|
-
private _shape: ButtonShape = 'default';
|
|
128
|
-
private _shadow: 'none' | 'soft' = 'none';
|
|
129
|
-
|
|
130
|
-
constructor(text: string = '') {
|
|
131
|
-
super();
|
|
132
|
-
this._text = text;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
text(value: string): this {
|
|
136
|
-
this._text = value;
|
|
137
|
-
return this;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
variant(variant: ExtendedButtonVariant): this {
|
|
141
|
-
this._variant = variant;
|
|
142
|
-
return this;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
size(size: ButtonSize): this {
|
|
146
|
-
this._size = size;
|
|
147
|
-
return this;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
onPress(handler: () => void): this {
|
|
151
|
-
this._onPress = handler;
|
|
152
|
-
return this;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
disabled(value: boolean = true): this {
|
|
156
|
-
this._disabled = value;
|
|
157
|
-
return this;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
icon(icon: ReactNode): this {
|
|
161
|
-
this._icon = icon;
|
|
162
|
-
return this;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
shape(value: ButtonShape): this {
|
|
166
|
-
this._shape = value;
|
|
167
|
-
return this;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
shadow(value: 'none' | 'soft'): this {
|
|
171
|
-
this._shadow = value;
|
|
172
|
-
return this;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
build(): ReactElement {
|
|
176
|
-
const className = [
|
|
177
|
-
'fibo-button',
|
|
178
|
-
`fibo-button-${this._variant}`,
|
|
179
|
-
'active:scale-[0.96]',
|
|
180
|
-
'transform',
|
|
181
|
-
'transition-all',
|
|
182
|
-
'duration-200',
|
|
183
|
-
'ease-out',
|
|
184
|
-
...this._classNames,
|
|
185
|
-
]
|
|
186
|
-
.filter(Boolean)
|
|
187
|
-
.join(' ');
|
|
188
|
-
|
|
189
|
-
const props = {
|
|
190
|
-
text: this._text,
|
|
191
|
-
variant: this._variant,
|
|
192
|
-
size: this._size,
|
|
193
|
-
onPress: this._onPress,
|
|
194
|
-
disabled: this._disabled,
|
|
195
|
-
icon: this._icon,
|
|
196
|
-
shape: this._shape,
|
|
197
|
-
shadow: this._shadow,
|
|
198
|
-
className: className,
|
|
199
|
-
style: this.getStyle(),
|
|
200
|
-
...this._props
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
return React.createElement(ButtonInner, props);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
export const Button = createBuilder(ButtonBuilder);
|
|
209
|
-
|
|
210
|
-
export interface ButtonProps extends BaseProps {
|
|
211
|
-
text: string;
|
|
212
|
-
variant?: ExtendedButtonVariant;
|
|
213
|
-
size?: ButtonSize;
|
|
214
|
-
onPress?: () => void;
|
|
215
|
-
disabled?: boolean;
|
|
216
|
-
icon?: ReactNode;
|
|
217
|
-
shape?: ButtonShape;
|
|
218
|
-
shadow?: 'none' | 'soft';
|
|
219
|
-
}
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import React, { ReactElement } from 'react';
|
|
2
|
-
import { FiboBuilder, createBuilder } from '../../core/builder';
|
|
3
|
-
import { BaseProps } from '../../core/types';
|
|
4
|
-
|
|
5
|
-
const CheckboxInner = React.memo((props: any) => {
|
|
6
|
-
const {
|
|
7
|
-
checked,
|
|
8
|
-
onChange,
|
|
9
|
-
label,
|
|
10
|
-
disabled,
|
|
11
|
-
indeterminate,
|
|
12
|
-
className,
|
|
13
|
-
style
|
|
14
|
-
} = props;
|
|
15
|
-
|
|
16
|
-
const isCheckedOrIndeterminate = checked || indeterminate;
|
|
17
|
-
|
|
18
|
-
const baseStyle: React.CSSProperties = {
|
|
19
|
-
width: '20px',
|
|
20
|
-
height: '20px',
|
|
21
|
-
borderRadius: '6px',
|
|
22
|
-
border: isCheckedOrIndeterminate ? 'none' : '2px solid #D1D5DB',
|
|
23
|
-
backgroundColor: isCheckedOrIndeterminate ? 'var(--fibo-primary, #3B82F6)' : 'transparent',
|
|
24
|
-
display: 'flex',
|
|
25
|
-
alignItems: 'center',
|
|
26
|
-
justifyContent: 'center',
|
|
27
|
-
transition: 'all 0.2s',
|
|
28
|
-
cursor: disabled ? 'not-allowed' : 'pointer',
|
|
29
|
-
opacity: disabled ? 0.5 : 1,
|
|
30
|
-
...style
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
let icon = null;
|
|
35
|
-
if (indeterminate) {
|
|
36
|
-
|
|
37
|
-
icon = React.createElement('div', { style: { width: '10px', height: '2px', backgroundColor: 'white', borderRadius: '1px' } });
|
|
38
|
-
} else if (checked) {
|
|
39
|
-
|
|
40
|
-
icon = React.createElement('svg', {
|
|
41
|
-
width: '12',
|
|
42
|
-
height: '12',
|
|
43
|
-
viewBox: '0 0 12 12',
|
|
44
|
-
fill: 'none',
|
|
45
|
-
xmlns: 'http://www.w3.org/2000/svg'
|
|
46
|
-
},
|
|
47
|
-
React.createElement('path', {
|
|
48
|
-
d: 'M10 3L4.5 8.5L2 6',
|
|
49
|
-
stroke: 'white',
|
|
50
|
-
strokeWidth: '2',
|
|
51
|
-
strokeLinecap: 'round',
|
|
52
|
-
strokeLinejoin: 'round'
|
|
53
|
-
}));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return React.createElement(
|
|
57
|
-
'label',
|
|
58
|
-
{
|
|
59
|
-
className: `fibo-checkbox flex items-center gap-2 ${className}`
|
|
60
|
-
},
|
|
61
|
-
React.createElement(
|
|
62
|
-
'div',
|
|
63
|
-
{
|
|
64
|
-
className: 'fibo-checkbox-box',
|
|
65
|
-
style: baseStyle,
|
|
66
|
-
onClick: (e: React.MouseEvent) => {
|
|
67
|
-
e.preventDefault();
|
|
68
|
-
if (!disabled && onChange) {
|
|
69
|
-
onChange(!checked);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
icon
|
|
74
|
-
),
|
|
75
|
-
label && React.createElement(
|
|
76
|
-
'span',
|
|
77
|
-
{ className: 'text-sm text-gray-700 select-none' },
|
|
78
|
-
label
|
|
79
|
-
),
|
|
80
|
-
React.createElement('input', {
|
|
81
|
-
type: 'checkbox',
|
|
82
|
-
checked: checked,
|
|
83
|
-
disabled: disabled,
|
|
84
|
-
className: 'sr-only',
|
|
85
|
-
onChange: (e: React.ChangeEvent<HTMLInputElement>) => !disabled && onChange?.(e.target.checked)
|
|
86
|
-
})
|
|
87
|
-
);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
class CheckboxBuilder extends FiboBuilder {
|
|
91
|
-
private _checked: boolean = false;
|
|
92
|
-
private _onChange?: (checked: boolean) => void;
|
|
93
|
-
private _label?: string;
|
|
94
|
-
private _disabled: boolean = false;
|
|
95
|
-
private _indeterminate: boolean = false;
|
|
96
|
-
|
|
97
|
-
checked(value: boolean): this {
|
|
98
|
-
this._checked = value;
|
|
99
|
-
return this;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
indeterminate(value: boolean): this {
|
|
103
|
-
this._indeterminate = value;
|
|
104
|
-
return this;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
onChange(handler: (checked: boolean) => void): this {
|
|
108
|
-
this._onChange = handler;
|
|
109
|
-
return this;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
label(text: string): this {
|
|
113
|
-
this._label = text;
|
|
114
|
-
return this;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
disabled(value: boolean = true): this {
|
|
118
|
-
this._disabled = value;
|
|
119
|
-
return this;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
build(): ReactElement {
|
|
123
|
-
const props = {
|
|
124
|
-
checked: this._checked,
|
|
125
|
-
onChange: this._onChange,
|
|
126
|
-
label: this._label,
|
|
127
|
-
disabled: this._disabled,
|
|
128
|
-
indeterminate: this._indeterminate,
|
|
129
|
-
className: this.getClassName(),
|
|
130
|
-
style: this.getStyle()
|
|
131
|
-
};
|
|
132
|
-
return React.createElement(CheckboxInner, props);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
export const Checkbox = createBuilder(CheckboxBuilder);
|
|
138
|
-
|
|
139
|
-
export interface CheckboxProps extends BaseProps {
|
|
140
|
-
checked: boolean;
|
|
141
|
-
onChange?: (checked: boolean) => void;
|
|
142
|
-
label?: string;
|
|
143
|
-
disabled?: boolean;
|
|
144
|
-
indeterminate?: boolean;
|
|
145
|
-
}
|
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
import React, { ReactElement, useState, useRef, useEffect, ChangeEvent } 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 ComboboxInner = React.memo((props: any) => {
|
|
11
|
-
const uniqueId = React.useId();
|
|
12
|
-
const inputId = props.id || uniqueId;
|
|
13
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
14
|
-
const [searchTerm, setSearchTerm] = useState('');
|
|
15
|
-
const containerRef = useRef<HTMLDivElement>(null);
|
|
16
|
-
|
|
17
|
-
const {
|
|
18
|
-
containerClass,
|
|
19
|
-
containerStyle,
|
|
20
|
-
label,
|
|
21
|
-
error,
|
|
22
|
-
value,
|
|
23
|
-
options = [],
|
|
24
|
-
placeholder,
|
|
25
|
-
onChange,
|
|
26
|
-
onAdd,
|
|
27
|
-
disabled,
|
|
28
|
-
multiple,
|
|
29
|
-
...rest
|
|
30
|
-
} = props;
|
|
31
|
-
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
if (!multiple) {
|
|
34
|
-
const selected = props.options.find((o: Option) => o.value === props.value);
|
|
35
|
-
if (selected && !isOpen && searchTerm !== selected.label) {
|
|
36
|
-
setSearchTerm(selected.label);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}, [props.value, props.options, isOpen, multiple]);
|
|
40
|
-
|
|
41
|
-
const filteredOptions = options.filter((opt: Option) =>
|
|
42
|
-
opt.label.toLowerCase().includes(searchTerm.toLowerCase())
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
useEffect(() => {
|
|
46
|
-
const handleClickOutside = (event: MouseEvent) => {
|
|
47
|
-
if (containerRef.current && !containerRef.current.contains(event.target as Node)) {
|
|
48
|
-
setIsOpen(false);
|
|
49
|
-
if (!multiple) {
|
|
50
|
-
const selected = options.find((o: Option) => o.value === value);
|
|
51
|
-
setSearchTerm(selected ? selected.label : '');
|
|
52
|
-
} else {
|
|
53
|
-
setSearchTerm('');
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
document.addEventListener('mousedown', handleClickOutside);
|
|
58
|
-
return () => document.removeEventListener('mousedown', handleClickOutside);
|
|
59
|
-
}, [value, options, multiple]);
|
|
60
|
-
|
|
61
|
-
const handleSelect = (opt: Option) => {
|
|
62
|
-
if (multiple) {
|
|
63
|
-
const currentValues = Array.isArray(value) ? [...value] : [];
|
|
64
|
-
if (!currentValues.includes(opt.value)) {
|
|
65
|
-
currentValues.push(opt.value);
|
|
66
|
-
onChange?.(currentValues);
|
|
67
|
-
}
|
|
68
|
-
setSearchTerm('');
|
|
69
|
-
} else {
|
|
70
|
-
setSearchTerm(opt.label);
|
|
71
|
-
onChange?.(opt.value);
|
|
72
|
-
setIsOpen(false);
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const handleRemoveTag = (valToRemove: string) => {
|
|
77
|
-
if (multiple && Array.isArray(value)) {
|
|
78
|
-
const newValues = value.filter(v => v !== valToRemove);
|
|
79
|
-
onChange?.(newValues);
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const handleAdd = () => {
|
|
84
|
-
onAdd?.(searchTerm);
|
|
85
|
-
if (multiple) {
|
|
86
|
-
setSearchTerm('');
|
|
87
|
-
} else {
|
|
88
|
-
setIsOpen(false);
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const isSelected = (val: string) => {
|
|
93
|
-
if (multiple) {
|
|
94
|
-
return Array.isArray(value) && value.includes(val);
|
|
95
|
-
}
|
|
96
|
-
return value === val;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
return React.createElement(
|
|
100
|
-
'div',
|
|
101
|
-
{
|
|
102
|
-
ref: containerRef,
|
|
103
|
-
className: containerClass,
|
|
104
|
-
style: containerStyle
|
|
105
|
-
},
|
|
106
|
-
React.createElement('div', { className: 'relative w-full' }, [
|
|
107
|
-
React.createElement('div', {
|
|
108
|
-
className: `fibo-textfield-input flex flex-wrap items-center gap-1 ${isOpen ? 'ring-2 ring-[var(--fibo-primary-container)] border-[var(--fibo-primary)]' : ''}`,
|
|
109
|
-
style: { minHeight: '42px', padding: '4px 8px' }
|
|
110
|
-
}, [
|
|
111
|
-
multiple && Array.isArray(value) && value.map((val: string) => {
|
|
112
|
-
const opt = options.find((o: Option) => o.value === val);
|
|
113
|
-
const labelStr = opt ? opt.label : val;
|
|
114
|
-
return React.createElement('span', {
|
|
115
|
-
key: val,
|
|
116
|
-
className: 'bg-[var(--fibo-primary-container)] text-[var(--fibo-on-primary-container)] text-xs font-medium px-2 py-1 rounded-md flex items-center'
|
|
117
|
-
}, [
|
|
118
|
-
labelStr,
|
|
119
|
-
React.createElement('button', {
|
|
120
|
-
type: 'button',
|
|
121
|
-
className: 'ml-1 hover:text-[var(--fibo-primary)] focus:outline-none',
|
|
122
|
-
onClick: (e: any) => { e.stopPropagation(); handleRemoveTag(val); }
|
|
123
|
-
}, '×')
|
|
124
|
-
]);
|
|
125
|
-
}),
|
|
126
|
-
|
|
127
|
-
React.createElement('input', {
|
|
128
|
-
key: 'input',
|
|
129
|
-
id: inputId,
|
|
130
|
-
className: 'bg-transparent outline-none flex-1 min-w-[60px] text-sm h-8',
|
|
131
|
-
value: searchTerm,
|
|
132
|
-
placeholder: (multiple && Array.isArray(value) && value.length > 0) ? '' : (placeholder || ' '),
|
|
133
|
-
disabled: disabled,
|
|
134
|
-
onChange: (e: ChangeEvent<HTMLInputElement>) => {
|
|
135
|
-
setSearchTerm(e.target.value);
|
|
136
|
-
if (!isOpen) setIsOpen(true);
|
|
137
|
-
},
|
|
138
|
-
onFocus: () => setIsOpen(true),
|
|
139
|
-
...rest
|
|
140
|
-
})
|
|
141
|
-
]),
|
|
142
|
-
|
|
143
|
-
label && React.createElement(
|
|
144
|
-
'label',
|
|
145
|
-
{
|
|
146
|
-
key: 'label',
|
|
147
|
-
htmlFor: inputId,
|
|
148
|
-
className: 'fibo-textfield-label'
|
|
149
|
-
},
|
|
150
|
-
label
|
|
151
|
-
),
|
|
152
|
-
|
|
153
|
-
isOpen && React.createElement('div', {
|
|
154
|
-
key: 'dropdown',
|
|
155
|
-
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 left-0'
|
|
156
|
-
}, [
|
|
157
|
-
filteredOptions.length > 0 ?
|
|
158
|
-
filteredOptions.map((opt: Option) => {
|
|
159
|
-
const selected = isSelected(opt.value);
|
|
160
|
-
return React.createElement('div', {
|
|
161
|
-
key: opt.value,
|
|
162
|
-
className: `px-4 py-2 cursor-pointer text-sm hover:bg-[var(--fibo-primary-container)] hover:text-[var(--fibo-on-primary-container)] ${selected ? 'bg-[var(--fibo-primary-container)] text-[var(--fibo-on-primary-container)] font-medium opacity-50' : 'text-[var(--fibo-on-surface)]'}`,
|
|
163
|
-
onClick: () => !selected && handleSelect(opt)
|
|
164
|
-
}, opt.label);
|
|
165
|
-
}) :
|
|
166
|
-
React.createElement('div', { className: 'px-4 py-2 text-sm text-gray-500' }, 'No results found.'),
|
|
167
|
-
|
|
168
|
-
searchTerm && !filteredOptions.some((o: Option) => o.label.toLowerCase() === searchTerm.toLowerCase()) && onAdd && React.createElement('div', {
|
|
169
|
-
key: 'add-new',
|
|
170
|
-
className: 'border-t border-[var(--fibo-outline)] px-4 py-2 cursor-pointer text-sm text-[var(--fibo-primary)] hover:bg-[var(--fibo-primary-container)] font-medium flex items-center',
|
|
171
|
-
onClick: handleAdd
|
|
172
|
-
}, [
|
|
173
|
-
React.createElement('span', { className: 'mr-1' }, '+'),
|
|
174
|
-
`Add "${searchTerm}"`
|
|
175
|
-
])
|
|
176
|
-
])
|
|
177
|
-
]),
|
|
178
|
-
|
|
179
|
-
error && React.createElement(
|
|
180
|
-
'span',
|
|
181
|
-
{ className: 'text-[var(--fibo-error)] text-xs mt-1 ml-1' },
|
|
182
|
-
error
|
|
183
|
-
)
|
|
184
|
-
);
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
class ComboboxBuilder extends FiboBuilder {
|
|
188
|
-
private _value: string | string[] = '';
|
|
189
|
-
private _label: string = '';
|
|
190
|
-
private _placeholder: string = '';
|
|
191
|
-
private _disabled: boolean = false;
|
|
192
|
-
private _error?: string;
|
|
193
|
-
private _multiple: boolean = false;
|
|
194
|
-
private _options: Option[] = [];
|
|
195
|
-
private _onChange?: (value: string | string[]) => void;
|
|
196
|
-
private _onAdd?: (newLabel: string) => void;
|
|
197
|
-
|
|
198
|
-
value(val: string | string[]): this {
|
|
199
|
-
this._value = val;
|
|
200
|
-
return this;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
label(val: string): this {
|
|
204
|
-
this._label = val;
|
|
205
|
-
return this;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
placeholder(val: string): this {
|
|
209
|
-
this._placeholder = val;
|
|
210
|
-
return this;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
options(opts: Option[]): this {
|
|
214
|
-
this._options = opts;
|
|
215
|
-
return this;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
multiple(val: boolean = true): this {
|
|
219
|
-
this._multiple = val;
|
|
220
|
-
return this;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
disabled(val: boolean = true): this {
|
|
224
|
-
this._disabled = val;
|
|
225
|
-
return this;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
error(val: string): this {
|
|
229
|
-
this._error = val;
|
|
230
|
-
return this;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
onChange(handler: (value: string | string[]) => void): this {
|
|
234
|
-
this._onChange = handler;
|
|
235
|
-
return this;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
onAdd(handler: (newLabel: string) => void): this {
|
|
239
|
-
this._onAdd = handler;
|
|
240
|
-
return this;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
build(): ReactElement {
|
|
244
|
-
const containerClass = ['fibo-textfield-container relative', ...this._classNames]
|
|
245
|
-
.filter(Boolean)
|
|
246
|
-
.join(' ');
|
|
247
|
-
|
|
248
|
-
const props = {
|
|
249
|
-
containerClass,
|
|
250
|
-
containerStyle: this.getStyle(),
|
|
251
|
-
label: this._label,
|
|
252
|
-
error: this._error,
|
|
253
|
-
value: this._value,
|
|
254
|
-
placeholder: this._placeholder,
|
|
255
|
-
options: this._options,
|
|
256
|
-
disabled: this._disabled,
|
|
257
|
-
multiple: this._multiple,
|
|
258
|
-
onChange: this._onChange,
|
|
259
|
-
onAdd: this._onAdd,
|
|
260
|
-
...this._props
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
return React.createElement(ComboboxInner, props);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
export const Combobox = createBuilder(ComboboxBuilder);
|
|
269
|
-
|
|
270
|
-
export interface ComboboxProps extends BaseProps {
|
|
271
|
-
value: string | string[];
|
|
272
|
-
label?: string;
|
|
273
|
-
placeholder?: string;
|
|
274
|
-
multiple?: boolean;
|
|
275
|
-
options: Option[];
|
|
276
|
-
onChange?: (value: string | string[]) => void;
|
|
277
|
-
onAdd?: (newLabel: string) => void;
|
|
278
|
-
}
|