ywana-core8 0.1.75 → 0.1.76
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/ACCORDION_EVALUATION.md +583 -0
- package/CHECKBOX_EVALUATION.md +273 -0
- package/CHIP_EVALUATION.md +542 -0
- package/COLOR_EVALUATION.md +524 -0
- package/COMPONENTS_EVALUATION.md +477 -0
- package/FORM_EVALUATION.md +459 -0
- package/HEADER_EVALUATION.md +436 -0
- package/ICON_EVALUATION.md +254 -0
- package/LIST_EVALUATION.md +574 -0
- package/PROGRESS_EVALUATION.md +450 -0
- package/RADIO_EVALUATION.md +439 -0
- package/RADIO_VISUAL_FIX.md +183 -0
- package/SECTION_IMPROVEMENTS.md +153 -0
- package/SWITCH_EVALUATION.md +335 -0
- package/SWITCH_VISUAL_FIX.md +232 -0
- package/TAB_EVALUATION.md +626 -0
- package/TEXTFIELD_EVALUATION.md +747 -0
- package/TOOLTIP_FIX.md +157 -0
- package/TREE_EVALUATION.md +708 -0
- package/dist/index.cjs +7900 -1615
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +6094 -1122
- package/dist/index.css.map +1 -1
- package/dist/index.modern.js +7929 -1645
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +7900 -1615
- package/dist/index.umd.js.map +1 -1
- package/jest.config.js +24 -0
- package/package.json +10 -1
- package/src/html/accordion.css +208 -4
- package/src/html/accordion.example.js +390 -0
- package/src/html/accordion.js +284 -28
- package/src/html/accordion.unit.test.js +334 -0
- package/src/html/button.css +157 -16
- package/src/html/button.example.js +374 -0
- package/src/html/button.js +240 -60
- package/src/html/button.test.js +422 -0
- package/src/html/checkbox.css +74 -2
- package/src/html/checkbox.example.js +316 -0
- package/src/html/checkbox.js +113 -26
- package/src/html/checkbox.test.js +285 -0
- package/src/html/chip.css +230 -19
- package/src/html/chip.example.js +355 -0
- package/src/html/chip.js +321 -25
- package/src/html/chip.test.js +425 -0
- package/src/html/color.css +435 -6
- package/src/html/color.example.js +527 -0
- package/src/html/color.js +458 -9
- package/src/html/color.test.js +362 -4
- package/src/html/components.example.js +492 -0
- package/src/html/components_enhanced.test.js +581 -0
- package/src/html/form.css +70 -3
- package/src/html/form.example.js +385 -0
- package/src/html/form.js +232 -34
- package/src/html/form.test.js +369 -0
- package/src/html/header2.css +264 -0
- package/src/html/header2.example.js +411 -0
- package/src/html/header2.js +203 -0
- package/src/html/header2.test.js +377 -0
- package/src/html/icon.css +20 -2
- package/src/html/icon.example.js +268 -0
- package/src/html/icon.js +86 -16
- package/src/html/icon.test.js +231 -0
- package/src/html/index.js +1 -1
- package/src/html/list.css +393 -1
- package/src/html/list.example.js +404 -0
- package/src/html/list.js +583 -40
- package/src/html/list.test.js +383 -0
- package/src/html/progress.css +707 -17
- package/src/html/progress.example.js +424 -0
- package/src/html/progress.js +906 -9
- package/src/html/progress.test.js +313 -0
- package/src/html/property.css +399 -0
- package/src/html/property.example.js +553 -0
- package/src/html/property.js +393 -15
- package/src/html/property.test.js +351 -2
- package/src/html/radio-visual-test.js +289 -0
- package/src/html/radio.css +137 -11
- package/src/html/radio.example.js +389 -0
- package/src/html/radio.js +234 -10
- package/src/html/radio.test.js +318 -0
- package/src/html/section.example.js +99 -0
- package/src/html/section.js +40 -3
- package/src/html/section.test.js +131 -0
- package/src/html/selector.css +329 -3
- package/src/html/selector.js +369 -23
- package/src/html/switch-debug.js +197 -0
- package/src/html/switch-test-visual.js +294 -0
- package/src/html/switch.css +200 -0
- package/src/html/switch.example.js +461 -0
- package/src/html/switch.js +283 -23
- package/src/html/switch.test.js +355 -0
- package/src/html/tab.css +288 -0
- package/src/html/tab.example.js +446 -0
- package/src/html/tab.js +387 -22
- package/src/html/tab_enhanced.js +378 -0
- package/src/html/tab_enhanced.test.js +504 -0
- package/src/html/table2.css +576 -0
- package/src/html/table2.example.js +703 -0
- package/src/html/table2.js +1252 -0
- package/src/html/table2.migration.md +328 -0
- package/src/html/table2.test.js +582 -0
- package/src/html/text.css +375 -0
- package/src/html/text.js +311 -20
- package/src/html/textfield2.css +842 -0
- package/src/html/textfield2.example.js +499 -0
- package/src/html/textfield2.js +1130 -0
- package/src/html/textfield2.test.js +950 -0
- package/src/html/thumbnail.css +289 -2
- package/src/html/thumbnail.js +214 -9
- package/src/html/tokenfield.css +449 -1
- package/src/html/tokenfield.example.js +503 -0
- package/src/html/tokenfield.js +561 -56
- package/src/html/tokenfield.test.js +423 -0
- package/src/html/tooltip-positioning-demo.js +187 -0
- package/src/html/tooltip.css +25 -2
- package/src/html/tree.css +228 -0
- package/src/html/tree.example.js +475 -0
- package/src/html/tree.js +712 -28
- package/src/html/tree_enhanced.test.js +495 -0
- package/table2.test.js +454 -0
- package/src/html/button.tsx +0 -38
package/src/html/chip.js
CHANGED
@@ -1,49 +1,345 @@
|
|
1
|
-
import React from 'react'
|
1
|
+
import React, { useState, useCallback, useEffect } from 'react'
|
2
|
+
import PropTypes from 'prop-types'
|
2
3
|
import { Icon } from './icon'
|
3
4
|
import { Text } from './text'
|
4
|
-
import {
|
5
|
+
import { Tooltip } from './tooltip'
|
5
6
|
import './chip.css'
|
6
7
|
|
7
8
|
/**
|
8
|
-
* Chip
|
9
|
+
* Chip component with enhanced features and accessibility
|
9
10
|
*/
|
10
11
|
export const Chip = (props) => {
|
12
|
+
const {
|
13
|
+
id,
|
14
|
+
icon,
|
15
|
+
label,
|
16
|
+
tooltip,
|
17
|
+
action,
|
18
|
+
outlined = false,
|
19
|
+
selected = false,
|
20
|
+
disabled = false,
|
21
|
+
deletable = false,
|
22
|
+
size = 'normal',
|
23
|
+
variant = 'default',
|
24
|
+
className,
|
25
|
+
ariaLabel,
|
26
|
+
onSelect,
|
27
|
+
onDelete,
|
28
|
+
onClick,
|
29
|
+
onKeyDown,
|
30
|
+
...restProps
|
31
|
+
} = props
|
11
32
|
|
12
|
-
|
33
|
+
// Validate required props
|
34
|
+
if (!label && !icon && !ariaLabel) {
|
35
|
+
console.warn('Chip component: label, icon, or ariaLabel prop is required for accessibility')
|
36
|
+
}
|
37
|
+
|
38
|
+
const handleSelect = useCallback((event) => {
|
39
|
+
if (!disabled) {
|
40
|
+
event.stopPropagation()
|
41
|
+
event.preventDefault()
|
42
|
+
|
43
|
+
if (onSelect) onSelect(id, !selected, event)
|
44
|
+
if (onClick) onClick(event)
|
45
|
+
}
|
46
|
+
}, [disabled, onSelect, onClick, id, selected])
|
47
|
+
|
48
|
+
const handleDelete = useCallback((event) => {
|
49
|
+
if (!disabled && deletable && onDelete) {
|
50
|
+
event.stopPropagation()
|
51
|
+
event.preventDefault()
|
52
|
+
onDelete(id, event)
|
53
|
+
}
|
54
|
+
}, [disabled, deletable, onDelete, id])
|
55
|
+
|
56
|
+
// Handle keyboard events for accessibility
|
57
|
+
const handleKeyDown = useCallback((event) => {
|
58
|
+
if (!disabled) {
|
59
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
60
|
+
event.preventDefault()
|
61
|
+
handleSelect(event)
|
62
|
+
} else if (event.key === 'Delete' || event.key === 'Backspace') {
|
63
|
+
if (deletable) {
|
64
|
+
event.preventDefault()
|
65
|
+
handleDelete(event)
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
if (onKeyDown) onKeyDown(event)
|
70
|
+
}, [disabled, handleSelect, handleDelete, deletable, onKeyDown])
|
13
71
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
72
|
+
// Generate CSS classes
|
73
|
+
const style = outlined ? 'outlined' : 'normal'
|
74
|
+
const safeClassName = className || ''
|
75
|
+
|
76
|
+
const cssClasses = [
|
77
|
+
'chip',
|
78
|
+
style,
|
79
|
+
size,
|
80
|
+
variant,
|
81
|
+
selected && 'selected',
|
82
|
+
disabled && 'disabled',
|
83
|
+
deletable && 'deletable',
|
84
|
+
safeClassName
|
85
|
+
].filter(Boolean).join(' ')
|
86
|
+
|
87
|
+
// Accessibility attributes
|
88
|
+
const ariaAttributes = {
|
89
|
+
role: onSelect ? 'button' : 'img',
|
90
|
+
'aria-label': ariaLabel || label || (icon ? `${icon} chip` : 'chip'),
|
91
|
+
'aria-pressed': onSelect ? selected : undefined,
|
92
|
+
'aria-disabled': disabled,
|
93
|
+
tabIndex: disabled ? -1 : 0
|
18
94
|
}
|
19
95
|
|
20
|
-
|
21
|
-
|
96
|
+
// Icon size based on chip size
|
97
|
+
const iconSize = size === 'small' ? 'small' : size === 'large' ? 'normal' : 'small'
|
98
|
+
|
99
|
+
const chipContent = (
|
100
|
+
<div
|
101
|
+
className={cssClasses}
|
102
|
+
onClick={handleSelect}
|
103
|
+
onKeyDown={handleKeyDown}
|
104
|
+
{...ariaAttributes}
|
105
|
+
{...restProps}
|
106
|
+
>
|
107
|
+
{icon && (
|
108
|
+
<Icon
|
109
|
+
icon={icon}
|
110
|
+
size={iconSize}
|
111
|
+
disabled={disabled}
|
112
|
+
className="chip-icon"
|
113
|
+
/>
|
114
|
+
)}
|
115
|
+
{label && (
|
116
|
+
<main className="chip-content">
|
117
|
+
<Text>{label}</Text>
|
118
|
+
</main>
|
119
|
+
)}
|
120
|
+
{action && (
|
121
|
+
<span className="chip-action">
|
122
|
+
{action}
|
123
|
+
</span>
|
124
|
+
)}
|
125
|
+
{deletable && (
|
126
|
+
<Icon
|
127
|
+
icon="close"
|
128
|
+
size="small"
|
129
|
+
clickable={!disabled}
|
130
|
+
disabled={disabled}
|
131
|
+
action={handleDelete}
|
132
|
+
className="chip-delete"
|
133
|
+
ariaLabel="Delete chip"
|
134
|
+
/>
|
135
|
+
)}
|
136
|
+
</div>
|
137
|
+
)
|
138
|
+
|
22
139
|
return tooltip ? (
|
23
140
|
<Tooltip {...tooltip}>
|
24
|
-
|
25
|
-
{icon ? <Icon icon={icon} size="small" /> : null}
|
26
|
-
<main><Text>{label}</Text></main>
|
27
|
-
{action ? <span className="meta">{action}</span> : null}
|
28
|
-
</div>
|
141
|
+
{chipContent}
|
29
142
|
</Tooltip>
|
30
|
-
) :
|
31
|
-
<div className={`chip ${className} ${style}`} onClick={select}>
|
32
|
-
{icon ? <Icon icon={icon} size="small" /> : null}
|
33
|
-
<main><Text>{label}</Text></main>
|
34
|
-
{action ? <span className="meta">{action}</span> : null}
|
35
|
-
</div>
|
36
|
-
)
|
143
|
+
) : chipContent
|
37
144
|
}
|
38
145
|
|
39
146
|
/**
|
40
|
-
* Chips
|
147
|
+
* Chips container component for managing multiple chips
|
41
148
|
*/
|
42
149
|
export const Chips = (props) => {
|
43
|
-
const {
|
150
|
+
const {
|
151
|
+
children,
|
152
|
+
items = [],
|
153
|
+
selected = [],
|
154
|
+
disabled = false,
|
155
|
+
deletable = false,
|
156
|
+
multiSelect = false,
|
157
|
+
size = 'normal',
|
158
|
+
variant = 'default',
|
159
|
+
className,
|
160
|
+
onSelect,
|
161
|
+
onDelete,
|
162
|
+
onChange,
|
163
|
+
...restProps
|
164
|
+
} = props
|
165
|
+
|
166
|
+
const [selectedItems, setSelectedItems] = useState(selected)
|
167
|
+
|
168
|
+
// Sync with external selected value
|
169
|
+
useEffect(() => {
|
170
|
+
setSelectedItems(selected)
|
171
|
+
}, [selected])
|
172
|
+
|
173
|
+
const handleChipSelect = useCallback((id, isSelected, event) => {
|
174
|
+
if (disabled) return
|
175
|
+
|
176
|
+
let newSelected
|
177
|
+
if (multiSelect) {
|
178
|
+
newSelected = isSelected
|
179
|
+
? [...selectedItems, id]
|
180
|
+
: selectedItems.filter(item => item !== id)
|
181
|
+
} else {
|
182
|
+
newSelected = isSelected ? [id] : []
|
183
|
+
}
|
184
|
+
|
185
|
+
setSelectedItems(newSelected)
|
186
|
+
|
187
|
+
if (onSelect) onSelect(id, isSelected, event)
|
188
|
+
if (onChange) onChange(newSelected, event)
|
189
|
+
}, [disabled, multiSelect, selectedItems, onSelect, onChange])
|
190
|
+
|
191
|
+
const handleChipDelete = useCallback((id, event) => {
|
192
|
+
if (disabled) return
|
193
|
+
|
194
|
+
// Remove from selected items
|
195
|
+
const newSelected = selectedItems.filter(item => item !== id)
|
196
|
+
setSelectedItems(newSelected)
|
197
|
+
|
198
|
+
if (onDelete) onDelete(id, event)
|
199
|
+
if (onChange) onChange(newSelected, event)
|
200
|
+
}, [disabled, selectedItems, onDelete, onChange])
|
201
|
+
|
202
|
+
const safeClassName = className || ''
|
203
|
+
const cssClasses = [
|
204
|
+
'chips',
|
205
|
+
size,
|
206
|
+
disabled && 'disabled',
|
207
|
+
safeClassName
|
208
|
+
].filter(Boolean).join(' ')
|
209
|
+
|
210
|
+
// If items are provided, render them as chips
|
211
|
+
if (items && items.length > 0) {
|
212
|
+
return (
|
213
|
+
<div className={cssClasses} {...restProps}>
|
214
|
+
{items.map((item, index) => {
|
215
|
+
const itemId = item.id || item.value || index
|
216
|
+
const isSelected = selectedItems.includes(itemId)
|
217
|
+
|
218
|
+
return (
|
219
|
+
<Chip
|
220
|
+
key={itemId}
|
221
|
+
id={itemId}
|
222
|
+
label={item.label}
|
223
|
+
icon={item.icon}
|
224
|
+
tooltip={item.tooltip}
|
225
|
+
action={item.action}
|
226
|
+
outlined={item.outlined}
|
227
|
+
selected={isSelected}
|
228
|
+
disabled={disabled || item.disabled}
|
229
|
+
deletable={deletable || item.deletable}
|
230
|
+
size={size}
|
231
|
+
variant={variant}
|
232
|
+
onSelect={handleChipSelect}
|
233
|
+
onDelete={handleChipDelete}
|
234
|
+
ariaLabel={item.ariaLabel}
|
235
|
+
/>
|
236
|
+
)
|
237
|
+
})}
|
238
|
+
</div>
|
239
|
+
)
|
240
|
+
}
|
241
|
+
|
242
|
+
// Otherwise render children
|
44
243
|
return (
|
45
|
-
<div className=
|
244
|
+
<div className={cssClasses} {...restProps}>
|
46
245
|
{children}
|
47
246
|
</div>
|
48
247
|
)
|
248
|
+
}
|
249
|
+
|
250
|
+
// PropTypes para Chip
|
251
|
+
Chip.propTypes = {
|
252
|
+
/** Unique identifier for the chip */
|
253
|
+
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
254
|
+
/** Icon name for Material Icons */
|
255
|
+
icon: PropTypes.string,
|
256
|
+
/** Chip text label */
|
257
|
+
label: PropTypes.string,
|
258
|
+
/** Tooltip configuration */
|
259
|
+
tooltip: PropTypes.object,
|
260
|
+
/** Action element (usually an icon) */
|
261
|
+
action: PropTypes.node,
|
262
|
+
/** Whether the chip has outlined style */
|
263
|
+
outlined: PropTypes.bool,
|
264
|
+
/** Whether the chip is selected */
|
265
|
+
selected: PropTypes.bool,
|
266
|
+
/** Whether the chip is disabled */
|
267
|
+
disabled: PropTypes.bool,
|
268
|
+
/** Whether the chip can be deleted */
|
269
|
+
deletable: PropTypes.bool,
|
270
|
+
/** Size variant of the chip */
|
271
|
+
size: PropTypes.oneOf(['small', 'normal', 'large']),
|
272
|
+
/** Visual variant of the chip */
|
273
|
+
variant: PropTypes.oneOf(['default', 'primary', 'secondary', 'success', 'warning', 'error']),
|
274
|
+
/** Additional CSS classes */
|
275
|
+
className: PropTypes.string,
|
276
|
+
/** Accessibility label for screen readers */
|
277
|
+
ariaLabel: PropTypes.string,
|
278
|
+
/** Selection handler function */
|
279
|
+
onSelect: PropTypes.func,
|
280
|
+
/** Delete handler function */
|
281
|
+
onDelete: PropTypes.func,
|
282
|
+
/** Click event handler */
|
283
|
+
onClick: PropTypes.func,
|
284
|
+
/** KeyDown event handler */
|
285
|
+
onKeyDown: PropTypes.func
|
286
|
+
}
|
287
|
+
|
288
|
+
Chip.defaultProps = {
|
289
|
+
outlined: false,
|
290
|
+
selected: false,
|
291
|
+
disabled: false,
|
292
|
+
deletable: false,
|
293
|
+
size: 'normal',
|
294
|
+
variant: 'default',
|
295
|
+
className: ''
|
296
|
+
}
|
297
|
+
|
298
|
+
// PropTypes para Chips
|
299
|
+
Chips.propTypes = {
|
300
|
+
/** Child chip components */
|
301
|
+
children: PropTypes.node,
|
302
|
+
/** Array of chip data objects */
|
303
|
+
items: PropTypes.arrayOf(PropTypes.shape({
|
304
|
+
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
305
|
+
label: PropTypes.string,
|
306
|
+
icon: PropTypes.string,
|
307
|
+
tooltip: PropTypes.object,
|
308
|
+
action: PropTypes.node,
|
309
|
+
outlined: PropTypes.bool,
|
310
|
+
disabled: PropTypes.bool,
|
311
|
+
deletable: PropTypes.bool,
|
312
|
+
ariaLabel: PropTypes.string
|
313
|
+
})),
|
314
|
+
/** Array of selected chip IDs */
|
315
|
+
selected: PropTypes.array,
|
316
|
+
/** Whether all chips are disabled */
|
317
|
+
disabled: PropTypes.bool,
|
318
|
+
/** Whether chips can be deleted */
|
319
|
+
deletable: PropTypes.bool,
|
320
|
+
/** Whether multiple chips can be selected */
|
321
|
+
multiSelect: PropTypes.bool,
|
322
|
+
/** Size variant for all chips */
|
323
|
+
size: PropTypes.oneOf(['small', 'normal', 'large']),
|
324
|
+
/** Visual variant for all chips */
|
325
|
+
variant: PropTypes.oneOf(['default', 'primary', 'secondary', 'success', 'warning', 'error']),
|
326
|
+
/** Additional CSS classes */
|
327
|
+
className: PropTypes.string,
|
328
|
+
/** Individual chip selection handler */
|
329
|
+
onSelect: PropTypes.func,
|
330
|
+
/** Individual chip delete handler */
|
331
|
+
onDelete: PropTypes.func,
|
332
|
+
/** Selection change handler (receives array of selected IDs) */
|
333
|
+
onChange: PropTypes.func
|
334
|
+
}
|
335
|
+
|
336
|
+
Chips.defaultProps = {
|
337
|
+
items: [],
|
338
|
+
selected: [],
|
339
|
+
disabled: false,
|
340
|
+
deletable: false,
|
341
|
+
multiSelect: false,
|
342
|
+
size: 'normal',
|
343
|
+
variant: 'default',
|
344
|
+
className: ''
|
49
345
|
}
|