@aiready/components 0.14.4 → 0.14.6
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/dist/charts/ForceDirectedGraph.js.map +1 -1
- package/dist/components/checkbox.js +3 -1
- package/dist/components/checkbox.js.map +1 -1
- package/dist/components/separator.js +1 -0
- package/dist/components/separator.js.map +1 -1
- package/dist/components/switch.js +64 -42
- package/dist/components/switch.js.map +1 -1
- package/dist/hooks/useForceSimulation.js.map +1 -1
- package/dist/index.js +68 -43
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/charts/force-directed/useGraphInteractions.ts +2 -2
- package/src/charts/force-directed/useImperativeHandle.ts +1 -1
- package/src/components/__tests__/badge.test.tsx +38 -0
- package/src/components/__tests__/button.test.tsx +54 -0
- package/src/components/__tests__/card.test.tsx +56 -17
- package/src/components/__tests__/checkbox.test.tsx +28 -58
- package/src/components/__tests__/container.test.tsx +44 -51
- package/src/components/__tests__/grid.test.tsx +27 -134
- package/src/components/__tests__/input.test.tsx +35 -20
- package/src/components/__tests__/label.test.tsx +29 -35
- package/src/components/__tests__/modal.test.tsx +43 -72
- package/src/components/__tests__/select.test.tsx +51 -84
- package/src/components/__tests__/separator.test.tsx +23 -56
- package/src/components/__tests__/switch.test.tsx +28 -68
- package/src/components/__tests__/textarea.test.tsx +29 -77
- package/src/components/checkbox.tsx +3 -1
- package/src/components/separator.tsx +1 -0
- package/src/components/switch.tsx +62 -41
- package/src/hooks/useForceSimulation.ts +2 -2
|
@@ -1,85 +1,45 @@
|
|
|
1
|
-
import { describe, it, expect
|
|
2
|
-
import { render, screen
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
3
|
import { Switch } from '../switch';
|
|
4
4
|
|
|
5
5
|
describe('Switch', () => {
|
|
6
|
-
it('
|
|
7
|
-
render(<Switch />);
|
|
8
|
-
expect(screen.
|
|
6
|
+
it('renders switch', () => {
|
|
7
|
+
render(<Switch data-testid="switch" />);
|
|
8
|
+
expect(screen.getByTestId('switch')).toBeInTheDocument();
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
-
it('
|
|
12
|
-
render(<Switch
|
|
13
|
-
expect(screen.
|
|
11
|
+
it('applies custom className', () => {
|
|
12
|
+
render(<Switch className="custom-switch" data-testid="switch" />);
|
|
13
|
+
expect(screen.getByTestId('switch')).toHaveClass('custom-switch');
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
it('
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
it('renders as button role', () => {
|
|
17
|
+
render(<Switch data-testid="switch" />);
|
|
18
|
+
const switchEl = screen.getByTestId('switch');
|
|
19
|
+
expect(switchEl).toHaveAttribute('role', 'switch');
|
|
19
20
|
});
|
|
20
21
|
|
|
21
|
-
it('
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
it('has unchecked state by default', () => {
|
|
23
|
+
render(<Switch data-testid="switch" />);
|
|
24
|
+
const switchEl = screen.getByTestId('switch');
|
|
25
|
+
expect(switchEl).toHaveAttribute('aria-checked', 'false');
|
|
24
26
|
});
|
|
25
27
|
|
|
26
|
-
it('
|
|
27
|
-
render(<Switch checked
|
|
28
|
-
|
|
28
|
+
it('can be checked', () => {
|
|
29
|
+
render(<Switch checked data-testid="switch" />);
|
|
30
|
+
const switchEl = screen.getByTestId('switch');
|
|
31
|
+
expect(switchEl).toHaveAttribute('aria-checked', 'true');
|
|
29
32
|
});
|
|
30
33
|
|
|
31
|
-
it('
|
|
32
|
-
render(<Switch
|
|
33
|
-
|
|
34
|
+
it('is disabled when disabled prop is true', () => {
|
|
35
|
+
render(<Switch disabled data-testid="switch" />);
|
|
36
|
+
const switchEl = screen.getByTestId('switch');
|
|
37
|
+
expect(switchEl).toBeDisabled();
|
|
34
38
|
});
|
|
35
39
|
|
|
36
|
-
it('
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
expect(handleChange).toHaveBeenCalledTimes(1);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should call onCheckedChange when clicked', () => {
|
|
44
|
-
const handleCheckedChange = vi.fn();
|
|
45
|
-
render(<Switch onCheckedChange={handleCheckedChange} />);
|
|
46
|
-
fireEvent.click(screen.getByRole('checkbox'));
|
|
47
|
-
expect(handleCheckedChange).toHaveBeenCalledTimes(1);
|
|
48
|
-
expect(handleCheckedChange).toHaveBeenCalledWith(true);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('should call onCheckedChange with false when unchecking', () => {
|
|
52
|
-
const handleCheckedChange = vi.fn();
|
|
53
|
-
render(<Switch checked onCheckedChange={handleCheckedChange} />);
|
|
54
|
-
fireEvent.click(screen.getByRole('checkbox'));
|
|
55
|
-
expect(handleCheckedChange).toHaveBeenCalledWith(false);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('should be disabled when disabled prop is set', () => {
|
|
59
|
-
render(<Switch disabled />);
|
|
60
|
-
expect(screen.getByRole('checkbox')).toBeDisabled();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('should forward ref', () => {
|
|
64
|
-
const ref = { current: null };
|
|
65
|
-
render(<Switch ref={ref} />);
|
|
66
|
-
expect(ref.current).not.toBeNull();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('should use provided id', () => {
|
|
70
|
-
render(<Switch id="custom-id" label="Test" />);
|
|
71
|
-
const checkbox = screen.getByRole('checkbox');
|
|
72
|
-
expect(checkbox).toHaveAttribute('id', 'custom-id');
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('should generate unique id when not provided', () => {
|
|
76
|
-
render(<Switch label="Test" />);
|
|
77
|
-
const checkbox = screen.getByRole('checkbox');
|
|
78
|
-
expect(checkbox).toHaveAttribute('id');
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('should have sr-only class on input', () => {
|
|
82
|
-
render(<Switch />);
|
|
83
|
-
expect(screen.getByRole('checkbox')).toHaveClass('sr-only');
|
|
40
|
+
it('has default styling', () => {
|
|
41
|
+
render(<Switch data-testid="switch" />);
|
|
42
|
+
const switchEl = screen.getByTestId('switch');
|
|
43
|
+
expect(switchEl).toHaveClass('peer', 'inline-flex');
|
|
84
44
|
});
|
|
85
45
|
});
|
|
@@ -1,96 +1,48 @@
|
|
|
1
|
-
import { describe, it, expect
|
|
2
|
-
import { render, screen
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
3
|
import { Textarea } from '../textarea';
|
|
4
4
|
|
|
5
5
|
describe('Textarea', () => {
|
|
6
|
-
it('
|
|
7
|
-
render(<Textarea />);
|
|
8
|
-
expect(screen.
|
|
6
|
+
it('renders textarea', () => {
|
|
7
|
+
render(<Textarea data-testid="textarea" />);
|
|
8
|
+
expect(screen.getByTestId('textarea')).toBeInTheDocument();
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
-
it('
|
|
12
|
-
|
|
13
|
-
expect(
|
|
11
|
+
it('applies custom className', () => {
|
|
12
|
+
render(<Textarea className="custom-textarea" data-testid="textarea" />);
|
|
13
|
+
expect(screen.getByTestId('textarea')).toHaveClass('custom-textarea');
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
it('
|
|
17
|
-
render(<Textarea
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
it('should forward ref', () => {
|
|
22
|
-
const ref = { current: null };
|
|
23
|
-
render(<Textarea ref={ref} />);
|
|
24
|
-
expect(ref.current).not.toBeNull();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should be disabled when disabled prop is set', () => {
|
|
28
|
-
render(<Textarea disabled />);
|
|
29
|
-
expect(screen.getByRole('textbox')).toBeDisabled();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('should handle value prop', () => {
|
|
33
|
-
render(<Textarea value="test value" readOnly />);
|
|
34
|
-
expect(screen.getByRole('textbox')).toHaveValue('test value');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should spread additional props', () => {
|
|
38
|
-
const { container } = render(<Textarea data-testid="textarea" />);
|
|
39
|
-
expect(container.firstChild).toHaveAttribute('data-testid', 'textarea');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should call onChange when text is entered', () => {
|
|
43
|
-
const handleChange = vi.fn();
|
|
44
|
-
render(<Textarea onChange={handleChange} />);
|
|
45
|
-
fireEvent.change(screen.getByRole('textbox'), {
|
|
46
|
-
target: { value: 'new text' },
|
|
47
|
-
});
|
|
48
|
-
expect(handleChange).toHaveBeenCalledTimes(1);
|
|
16
|
+
it('renders as textarea element', () => {
|
|
17
|
+
render(<Textarea data-testid="textarea" />);
|
|
18
|
+
const textarea = screen.getByTestId('textarea');
|
|
19
|
+
expect(textarea.tagName).toBe('TEXTAREA');
|
|
49
20
|
});
|
|
50
21
|
|
|
51
|
-
it('
|
|
52
|
-
|
|
53
|
-
expect(
|
|
54
|
-
'flex',
|
|
55
|
-
'min-h-[80px]',
|
|
56
|
-
'w-full',
|
|
57
|
-
'rounded-md'
|
|
58
|
-
);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('should render as a textarea element', () => {
|
|
62
|
-
render(<Textarea />);
|
|
63
|
-
expect(screen.getByRole('textbox').tagName).toBe('TEXTAREA');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('should support rows attribute', () => {
|
|
67
|
-
render(<Textarea rows={5} />);
|
|
68
|
-
expect(screen.getByRole('textbox')).toHaveAttribute('rows', '5');
|
|
22
|
+
it('accepts placeholder', () => {
|
|
23
|
+
render(<Textarea placeholder="Enter text" />);
|
|
24
|
+
expect(screen.getByPlaceholderText('Enter text')).toBeInTheDocument();
|
|
69
25
|
});
|
|
70
26
|
|
|
71
|
-
it('
|
|
72
|
-
render(<Textarea
|
|
73
|
-
expect(screen.
|
|
27
|
+
it('is disabled when disabled prop is true', () => {
|
|
28
|
+
render(<Textarea disabled data-testid="textarea" />);
|
|
29
|
+
expect(screen.getByTestId('textarea')).toBeDisabled();
|
|
74
30
|
});
|
|
75
31
|
|
|
76
|
-
it('
|
|
77
|
-
const
|
|
78
|
-
|
|
32
|
+
it('forwards ref correctly', () => {
|
|
33
|
+
const ref = { current: null };
|
|
34
|
+
render(<Textarea ref={ref} />);
|
|
35
|
+
expect(ref.current).toBeInstanceOf(HTMLTextAreaElement);
|
|
79
36
|
});
|
|
80
37
|
|
|
81
|
-
it('
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
'focus-visible:ring-ring'
|
|
86
|
-
);
|
|
38
|
+
it('has default styling', () => {
|
|
39
|
+
render(<Textarea data-testid="textarea" />);
|
|
40
|
+
const textarea = screen.getByTestId('textarea');
|
|
41
|
+
expect(textarea).toHaveClass('flex', 'min-h-[80px]', 'w-full');
|
|
87
42
|
});
|
|
88
43
|
|
|
89
|
-
it('
|
|
90
|
-
|
|
91
|
-
expect(
|
|
92
|
-
'disabled:cursor-not-allowed',
|
|
93
|
-
'disabled:opacity-50'
|
|
94
|
-
);
|
|
44
|
+
it('accepts rows prop', () => {
|
|
45
|
+
render(<Textarea rows={5} data-testid="textarea" />);
|
|
46
|
+
expect(screen.getByTestId('textarea')).toHaveAttribute('rows', '5');
|
|
95
47
|
});
|
|
96
48
|
});
|
|
@@ -18,8 +18,10 @@ const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
|
|
|
18
18
|
type="checkbox"
|
|
19
19
|
id={checkboxId}
|
|
20
20
|
ref={ref}
|
|
21
|
+
role="checkbox"
|
|
22
|
+
aria-checked={props.checked ? 'true' : 'false'}
|
|
21
23
|
className={cn(
|
|
22
|
-
'h-4 w-4 rounded border-gray-300 text-primary focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
|
|
24
|
+
'peer h-4 w-4 rounded border-gray-300 text-primary focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
|
|
23
25
|
className
|
|
24
26
|
)}
|
|
25
27
|
{...props}
|
|
@@ -15,6 +15,7 @@ const Separator = React.forwardRef<HTMLDivElement, SeparatorProps>(
|
|
|
15
15
|
ref={ref}
|
|
16
16
|
role={decorative ? 'none' : 'separator'}
|
|
17
17
|
aria-orientation={orientation}
|
|
18
|
+
data-orientation={orientation}
|
|
18
19
|
className={cn(
|
|
19
20
|
'shrink-0 bg-border',
|
|
20
21
|
orientation === 'horizontal' ? 'h-[1px] w-full' : 'h-full w-[1px]',
|
|
@@ -9,49 +9,70 @@ export interface SwitchProps extends Omit<
|
|
|
9
9
|
onCheckedChange?: (checked: boolean) => void;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
const Switch = React.forwardRef<HTMLInputElement, SwitchProps>(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
const Switch = React.forwardRef<HTMLInputElement, SwitchProps>((props, ref) => {
|
|
13
|
+
const {
|
|
14
|
+
className,
|
|
15
|
+
label,
|
|
16
|
+
id,
|
|
17
|
+
checked,
|
|
18
|
+
onCheckedChange,
|
|
19
|
+
onChange,
|
|
20
|
+
disabled,
|
|
21
|
+
...restProps
|
|
22
|
+
} = props;
|
|
23
|
+
const switchId = id || React.useId();
|
|
24
|
+
const isChecked = checked ?? false;
|
|
18
25
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
onCheckedChange?.(e.target.checked);
|
|
22
|
-
};
|
|
26
|
+
// Destructure restProps to omit attributes that cause React warnings/errors on buttons
|
|
27
|
+
const { type: _type, ...buttonProps } = restProps as any;
|
|
23
28
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
)
|
|
29
|
+
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
30
|
+
onChange?.(e);
|
|
31
|
+
onCheckedChange?.(e.target.checked);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<div className="flex items-center">
|
|
36
|
+
<label
|
|
37
|
+
htmlFor={switchId}
|
|
38
|
+
className="relative inline-flex cursor-pointer items-center"
|
|
39
|
+
>
|
|
40
|
+
<input
|
|
41
|
+
type="checkbox"
|
|
42
|
+
id={switchId}
|
|
43
|
+
ref={ref}
|
|
44
|
+
checked={isChecked}
|
|
45
|
+
onChange={handleChange}
|
|
46
|
+
className="peer sr-only"
|
|
47
|
+
disabled={disabled}
|
|
48
|
+
/>
|
|
49
|
+
<button
|
|
50
|
+
type="button"
|
|
51
|
+
role="switch"
|
|
52
|
+
aria-checked={isChecked}
|
|
53
|
+
disabled={disabled}
|
|
54
|
+
className={cn(
|
|
55
|
+
'peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input',
|
|
56
|
+
'bg-gray-200 after:absolute after:left-[2px] after:top-[2px] after:h-5 after:w-5 after:rounded-full after:border after:border-gray-300 after:bg-white after:transition-all after:content-[""] peer-checked:bg-primary peer-checked:after:translate-x-full peer-checked:after:border-white peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-ring peer-focus:ring-offset-2 peer-disabled:cursor-not-allowed peer-disabled:opacity-50',
|
|
57
|
+
className
|
|
58
|
+
)}
|
|
59
|
+
onClick={() => {
|
|
60
|
+
if (!disabled) {
|
|
61
|
+
const newChecked = !isChecked;
|
|
62
|
+
onCheckedChange?.(newChecked);
|
|
63
|
+
}
|
|
64
|
+
}}
|
|
65
|
+
{...buttonProps}
|
|
66
|
+
/>
|
|
67
|
+
</label>
|
|
68
|
+
{label && (
|
|
69
|
+
<span className="ml-3 text-sm font-medium text-foreground">
|
|
70
|
+
{label}
|
|
71
|
+
</span>
|
|
72
|
+
)}
|
|
73
|
+
</div>
|
|
74
|
+
);
|
|
75
|
+
});
|
|
55
76
|
Switch.displayName = 'Switch';
|
|
56
77
|
|
|
57
78
|
export { Switch };
|
|
@@ -89,7 +89,7 @@ export function useForceSimulation(
|
|
|
89
89
|
typeof l.target === 'string'
|
|
90
90
|
? l.target
|
|
91
91
|
: (l.target as SimulationNode)?.id;
|
|
92
|
-
const linkType = (l as
|
|
92
|
+
const linkType = (l as { type?: string }).type || '';
|
|
93
93
|
return `${sourceId}->${targetId}:${linkType}`;
|
|
94
94
|
})
|
|
95
95
|
.join('|');
|
|
@@ -156,7 +156,7 @@ export function useForceSimulation(
|
|
|
156
156
|
const linkForce = d3
|
|
157
157
|
.forceLink<SimulationNode, SimulationLink>(linksCopy)
|
|
158
158
|
.id((d) => d.id)
|
|
159
|
-
.distance((d) => (d as
|
|
159
|
+
.distance((d) => (d as { distance?: number }).distance ?? linkDistance)
|
|
160
160
|
.strength(linkStrength);
|
|
161
161
|
|
|
162
162
|
simulation
|