@tpzdsp/next-toolkit 1.1.0 → 1.2.1
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/package.json +70 -8
- package/src/assets/styles/globals.css +2 -0
- package/src/assets/styles/ol.css +122 -0
- package/src/components/Button/Button.test.tsx +1 -1
- package/src/components/Button/Button.tsx +1 -1
- package/src/components/Card/Card.test.tsx +1 -1
- package/src/components/ErrorText/ErrorText.test.tsx +1 -1
- package/src/components/ErrorText/ErrorText.tsx +1 -1
- package/src/components/Heading/Heading.test.tsx +1 -1
- package/src/components/Hint/Hint.test.tsx +1 -1
- package/src/components/Hint/Hint.tsx +1 -1
- package/src/components/Modal/Modal.stories.tsx +252 -0
- package/src/components/Modal/Modal.test.tsx +248 -0
- package/src/components/Modal/Modal.tsx +61 -0
- package/src/components/Paragraph/Paragraph.test.tsx +1 -1
- package/src/components/SlidingPanel/SlidingPanel.test.tsx +1 -2
- package/src/components/accordion/Accordion.stories.tsx +235 -0
- package/src/components/accordion/Accordion.test.tsx +199 -0
- package/src/components/accordion/Accordion.tsx +47 -0
- package/src/components/divider/RuleDivider.stories.tsx +255 -0
- package/src/components/divider/RuleDivider.test.tsx +164 -0
- package/src/components/divider/RuleDivider.tsx +18 -0
- package/src/components/dropdown/DropdownMenu.test.tsx +1 -1
- package/src/components/dropdown/useDropdownMenu.ts +1 -1
- package/src/components/index.ts +6 -2
- package/src/components/layout/header/Header.tsx +2 -1
- package/src/components/layout/header/HeaderAuthClient.tsx +17 -9
- package/src/components/layout/header/HeaderNavClient.tsx +3 -3
- package/src/components/link/ExternalLink.tsx +1 -1
- package/src/components/link/Link.tsx +1 -1
- package/src/components/select/Select.stories.tsx +336 -0
- package/src/components/select/Select.test.tsx +473 -0
- package/src/components/select/Select.tsx +132 -0
- package/src/components/select/SelectSkeleton.stories.tsx +195 -0
- package/src/components/select/SelectSkeleton.test.tsx +105 -0
- package/src/components/select/SelectSkeleton.tsx +16 -0
- package/src/components/select/common.ts +4 -0
- package/src/contexts/index.ts +0 -5
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useClickOutside.test.ts +290 -0
- package/src/hooks/useClickOutside.ts +26 -0
- package/src/index.ts +3 -0
- package/src/map/LayerSwitcherControl.ts +147 -0
- package/src/map/Map.tsx +230 -0
- package/src/map/MapContext.tsx +211 -0
- package/src/map/Popup.tsx +74 -0
- package/src/map/basemaps.ts +79 -0
- package/src/map/geocoder.ts +61 -0
- package/src/map/geometries.ts +60 -0
- package/src/map/images/basemaps/OS.png +0 -0
- package/src/map/images/basemaps/dark.png +0 -0
- package/src/map/images/basemaps/sat-map-tiler.png +0 -0
- package/src/map/images/basemaps/satellite-map-tiler.png +0 -0
- package/src/map/images/basemaps/satellite.png +0 -0
- package/src/map/images/basemaps/streets.png +0 -0
- package/src/map/images/openlayers-logo.png +0 -0
- package/src/map/index.ts +10 -0
- package/src/map/map.ts +40 -0
- package/src/map/osOpenNamesSearch.ts +54 -0
- package/src/map/projections.ts +14 -0
- package/src/ol-geocoder.d.ts +1 -0
- package/src/test/index.ts +1 -0
- package/src/types/api.ts +52 -0
- package/src/types/auth.ts +13 -0
- package/src/types/index.ts +6 -0
- package/src/types/map.ts +26 -0
- package/src/types/navigation.ts +8 -0
- package/src/types/utils.ts +13 -0
- package/src/utils/auth.ts +1 -1
- package/src/utils/http.ts +143 -0
- package/src/utils/index.ts +1 -1
- package/src/utils/utils.ts +1 -1
- package/src/components/link/NextLinkWrapper.tsx +0 -66
- package/src/contexts/ThemeContext.tsx +0 -72
- package/src/types.ts +0 -99
- /package/src/{utils → test}/renderers.tsx +0 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { Accordion } from './Accordion';
|
|
4
|
+
import { render, screen, userEvent } from '../../test/renderers';
|
|
5
|
+
|
|
6
|
+
const TEST_CONTENT = 'Test content';
|
|
7
|
+
const ARIA_EXPANDED = 'aria-expanded';
|
|
8
|
+
const ARIA_HIDDEN = 'aria-hidden';
|
|
9
|
+
|
|
10
|
+
describe('Accordion', () => {
|
|
11
|
+
it('should render with title and content', () => {
|
|
12
|
+
render(
|
|
13
|
+
<Accordion title="Test Section">
|
|
14
|
+
<div>{TEST_CONTENT}</div>
|
|
15
|
+
</Accordion>,
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
expect(screen.getByText('Test Section')).toBeInTheDocument();
|
|
19
|
+
expect(screen.getByText(TEST_CONTENT)).toBeInTheDocument();
|
|
20
|
+
|
|
21
|
+
expect(screen.getByText(TEST_CONTENT).closest('section')).toHaveClass('hidden');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should render with content closed by default', () => {
|
|
25
|
+
render(
|
|
26
|
+
<Accordion title="Test Section">
|
|
27
|
+
<div>{TEST_CONTENT}</div>
|
|
28
|
+
</Accordion>,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
expect(screen.getByRole('button', { name: /test section/i })).toHaveAttribute(
|
|
32
|
+
ARIA_EXPANDED,
|
|
33
|
+
'false',
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const section = screen.getByText(TEST_CONTENT).closest('section');
|
|
37
|
+
|
|
38
|
+
expect(section).toHaveAttribute(ARIA_HIDDEN, 'true');
|
|
39
|
+
expect(section).toHaveClass('hidden');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should open and close content when clicked', async () => {
|
|
43
|
+
const user = userEvent.setup();
|
|
44
|
+
|
|
45
|
+
render(
|
|
46
|
+
<Accordion title="Test Section">
|
|
47
|
+
<div>Test content</div>
|
|
48
|
+
</Accordion>,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const button = screen.getByRole('button', { name: /test section/i });
|
|
52
|
+
const section = screen.getByText(TEST_CONTENT).closest('section');
|
|
53
|
+
|
|
54
|
+
// Initially closed
|
|
55
|
+
expect(button).toHaveAttribute(ARIA_EXPANDED, 'false');
|
|
56
|
+
expect(section).toHaveAttribute(ARIA_HIDDEN, 'true');
|
|
57
|
+
expect(section).toHaveClass('hidden');
|
|
58
|
+
|
|
59
|
+
// Click to open
|
|
60
|
+
await user.click(button);
|
|
61
|
+
expect(button).toHaveAttribute(ARIA_EXPANDED, 'true');
|
|
62
|
+
expect(section).toHaveAttribute(ARIA_HIDDEN, 'false');
|
|
63
|
+
expect(section).toHaveClass('block');
|
|
64
|
+
|
|
65
|
+
// Click again to close
|
|
66
|
+
await user.click(button);
|
|
67
|
+
expect(button).toHaveAttribute(ARIA_EXPANDED, 'false');
|
|
68
|
+
expect(section).toHaveAttribute(ARIA_HIDDEN, 'true');
|
|
69
|
+
expect(section).toHaveClass('hidden');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('should render with content open when defaultOpen is true', () => {
|
|
73
|
+
render(
|
|
74
|
+
<Accordion title="Test Section" defaultOpen>
|
|
75
|
+
<div>Test content</div>
|
|
76
|
+
</Accordion>,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const button = screen.getByRole('button', { name: /test section/i });
|
|
80
|
+
|
|
81
|
+
expect(button).toHaveAttribute(ARIA_EXPANDED, 'true');
|
|
82
|
+
expect(screen.getByText(TEST_CONTENT)).toBeInTheDocument();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('should have proper accessibility attributes', () => {
|
|
86
|
+
render(
|
|
87
|
+
<Accordion title="Test Section">
|
|
88
|
+
<div>Test content</div>
|
|
89
|
+
</Accordion>,
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const button = screen.getByRole('button', { name: /test section/i });
|
|
93
|
+
|
|
94
|
+
expect(button).toHaveAttribute(ARIA_EXPANDED, 'false');
|
|
95
|
+
expect(button).toHaveAttribute('aria-controls');
|
|
96
|
+
expect(button).toHaveAttribute('id');
|
|
97
|
+
|
|
98
|
+
const content = screen.getByRole('region', { hidden: true });
|
|
99
|
+
|
|
100
|
+
expect(content).toHaveAttribute('aria-labelledby', button.id);
|
|
101
|
+
expect(content).toHaveAttribute(ARIA_HIDDEN, 'true');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('should update aria-hidden when opened', async () => {
|
|
105
|
+
const user = userEvent.setup();
|
|
106
|
+
|
|
107
|
+
render(
|
|
108
|
+
<Accordion title="Test Section">
|
|
109
|
+
<div>Test content</div>
|
|
110
|
+
</Accordion>,
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
const button = screen.getByRole('button', { name: /test section/i });
|
|
114
|
+
const content = screen.getByRole('region', { hidden: true });
|
|
115
|
+
|
|
116
|
+
expect(content).toHaveAttribute(ARIA_HIDDEN, 'true');
|
|
117
|
+
|
|
118
|
+
await user.click(button);
|
|
119
|
+
|
|
120
|
+
expect(content).toHaveAttribute(ARIA_HIDDEN, 'false');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('should render complex content correctly', () => {
|
|
124
|
+
render(
|
|
125
|
+
<Accordion title="Complex Section" defaultOpen>
|
|
126
|
+
<div>
|
|
127
|
+
<p>Paragraph content</p>
|
|
128
|
+
|
|
129
|
+
<button>Nested button</button>
|
|
130
|
+
|
|
131
|
+
<ul>
|
|
132
|
+
<li>List item 1</li>
|
|
133
|
+
|
|
134
|
+
<li>List item 2</li>
|
|
135
|
+
</ul>
|
|
136
|
+
</div>
|
|
137
|
+
</Accordion>,
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
expect(screen.getByText('Paragraph content')).toBeInTheDocument();
|
|
141
|
+
expect(screen.getByRole('button', { name: 'Nested button' })).toBeInTheDocument();
|
|
142
|
+
expect(screen.getByText('List item 1')).toBeInTheDocument();
|
|
143
|
+
expect(screen.getByText('List item 2')).toBeInTheDocument();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('should rotate chevron icon when opened', async () => {
|
|
147
|
+
const user = userEvent.setup();
|
|
148
|
+
|
|
149
|
+
render(
|
|
150
|
+
<Accordion title="Test Section">
|
|
151
|
+
<div>Test content</div>
|
|
152
|
+
</Accordion>,
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
const button = screen.getByRole('button', { name: /test section/i });
|
|
156
|
+
const chevron = button.querySelector('.rotate-180');
|
|
157
|
+
|
|
158
|
+
// Should not have rotate-180 class when closed
|
|
159
|
+
expect(chevron).toBeNull();
|
|
160
|
+
|
|
161
|
+
await user.click(button);
|
|
162
|
+
|
|
163
|
+
// Should have rotate-180 class when opened
|
|
164
|
+
const rotatedChevron = button.querySelector('.rotate-180');
|
|
165
|
+
|
|
166
|
+
expect(rotatedChevron).toBeInTheDocument();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('should have correct styling classes', () => {
|
|
170
|
+
render(
|
|
171
|
+
<Accordion title="Test Section">
|
|
172
|
+
<div>Test content</div>
|
|
173
|
+
</Accordion>,
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
const container = screen.getByRole('button').closest('div');
|
|
177
|
+
|
|
178
|
+
expect(container).toHaveClass(
|
|
179
|
+
'flex',
|
|
180
|
+
'flex-col',
|
|
181
|
+
'gap-2',
|
|
182
|
+
'border-l-2',
|
|
183
|
+
'border-neutral-100',
|
|
184
|
+
'rounded-md',
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
const button = screen.getByRole('button');
|
|
188
|
+
|
|
189
|
+
expect(button).toHaveClass(
|
|
190
|
+
'flex',
|
|
191
|
+
'justify-between',
|
|
192
|
+
'items-center',
|
|
193
|
+
'px-2',
|
|
194
|
+
'py-1',
|
|
195
|
+
'bg-neutral-100',
|
|
196
|
+
'rounded-md',
|
|
197
|
+
);
|
|
198
|
+
});
|
|
199
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { type ReactNode, useId, useState } from 'react';
|
|
4
|
+
|
|
5
|
+
import { LuChevronDown } from 'react-icons/lu';
|
|
6
|
+
import { twMerge } from 'tailwind-merge';
|
|
7
|
+
|
|
8
|
+
export type AccordionProps = {
|
|
9
|
+
title: string;
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
defaultOpen?: boolean;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const Accordion = ({ title, children, defaultOpen = false }: AccordionProps) => {
|
|
15
|
+
const contentId = useId();
|
|
16
|
+
const buttonId = useId();
|
|
17
|
+
|
|
18
|
+
const [isOpen, setIsOpen] = useState(defaultOpen);
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<div className="flex flex-col gap-2 border-l-2 border-neutral-100 rounded-md">
|
|
22
|
+
<button
|
|
23
|
+
aria-expanded={isOpen}
|
|
24
|
+
aria-controls={contentId}
|
|
25
|
+
className="flex justify-between items-center px-2 py-1 bg-neutral-100 rounded-md"
|
|
26
|
+
id={buttonId}
|
|
27
|
+
onClick={() => setIsOpen(!isOpen)}
|
|
28
|
+
type="button"
|
|
29
|
+
>
|
|
30
|
+
<span>{title}</span>
|
|
31
|
+
|
|
32
|
+
<span aria-hidden="true">
|
|
33
|
+
<LuChevronDown className={twMerge('w-4 h-4', isOpen ? 'rotate-180' : '')} />
|
|
34
|
+
</span>
|
|
35
|
+
</button>
|
|
36
|
+
|
|
37
|
+
<section
|
|
38
|
+
id={contentId}
|
|
39
|
+
aria-labelledby={buttonId}
|
|
40
|
+
aria-hidden={!isOpen}
|
|
41
|
+
className={twMerge('px-2 pb-1', isOpen ? 'block' : 'hidden')}
|
|
42
|
+
>
|
|
43
|
+
{children}
|
|
44
|
+
</section>
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
};
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/* eslint-disable storybook/no-renderer-packages */
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
|
+
|
|
4
|
+
import { RuleDivider } from './RuleDivider';
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: 'Components/RuleDivider',
|
|
8
|
+
component: RuleDivider,
|
|
9
|
+
parameters: {
|
|
10
|
+
layout: 'centered',
|
|
11
|
+
},
|
|
12
|
+
tags: ['autodocs'],
|
|
13
|
+
} satisfies Meta<typeof RuleDivider>;
|
|
14
|
+
|
|
15
|
+
export default meta;
|
|
16
|
+
type Story = StoryObj<typeof meta>;
|
|
17
|
+
|
|
18
|
+
export const Default: Story = {
|
|
19
|
+
render: () => (
|
|
20
|
+
<div className="w-96">
|
|
21
|
+
<RuleDivider />
|
|
22
|
+
</div>
|
|
23
|
+
),
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const WithText: Story = {
|
|
27
|
+
render: () => (
|
|
28
|
+
<div className="w-96">
|
|
29
|
+
<RuleDivider>OR</RuleDivider>
|
|
30
|
+
</div>
|
|
31
|
+
),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const WithLongerText: Story = {
|
|
35
|
+
render: () => (
|
|
36
|
+
<div className="w-96">
|
|
37
|
+
<RuleDivider>Continue Reading</RuleDivider>
|
|
38
|
+
</div>
|
|
39
|
+
),
|
|
40
|
+
};
|
|
41
|
+
export const WithIcon: Story = {
|
|
42
|
+
render: () => (
|
|
43
|
+
<div className="w-96">
|
|
44
|
+
<RuleDivider>
|
|
45
|
+
<svg
|
|
46
|
+
className="w-4 h-4"
|
|
47
|
+
fill="none"
|
|
48
|
+
stroke="currentColor"
|
|
49
|
+
viewBox="0 0 24 24"
|
|
50
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
51
|
+
>
|
|
52
|
+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 4v16m8-8H4" />
|
|
53
|
+
</svg>
|
|
54
|
+
</RuleDivider>
|
|
55
|
+
</div>
|
|
56
|
+
),
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const WithStyledText: Story = {
|
|
60
|
+
render: () => (
|
|
61
|
+
<div className="w-96">
|
|
62
|
+
<RuleDivider>
|
|
63
|
+
<span className="text-sm text-gray-500 uppercase tracking-wide">Section Break</span>
|
|
64
|
+
</RuleDivider>
|
|
65
|
+
</div>
|
|
66
|
+
),
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export const WithBoldText: Story = {
|
|
70
|
+
render: () => (
|
|
71
|
+
<div className="w-96">
|
|
72
|
+
<RuleDivider>
|
|
73
|
+
<strong className="text-gray-700">Important</strong>
|
|
74
|
+
</RuleDivider>
|
|
75
|
+
</div>
|
|
76
|
+
),
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export const WithColoredText: Story = {
|
|
80
|
+
render: () => (
|
|
81
|
+
<div className="w-96">
|
|
82
|
+
<RuleDivider>
|
|
83
|
+
<span className="text-blue-600 font-medium">New Content</span>
|
|
84
|
+
</RuleDivider>
|
|
85
|
+
</div>
|
|
86
|
+
),
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export const InContainer: Story = {
|
|
90
|
+
render: () => (
|
|
91
|
+
<div className="w-96 p-4 border rounded">
|
|
92
|
+
<p className="mb-4">This is some content above the divider.</p>
|
|
93
|
+
|
|
94
|
+
<RuleDivider>
|
|
95
|
+
<span className="text-gray-500">More below</span>
|
|
96
|
+
</RuleDivider>
|
|
97
|
+
|
|
98
|
+
<p className="mt-4">This is content below the divider.</p>
|
|
99
|
+
</div>
|
|
100
|
+
),
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export const FormSeparator: Story = {
|
|
104
|
+
render: () => (
|
|
105
|
+
<div className="w-80 p-6 border rounded">
|
|
106
|
+
<div className="space-y-4">
|
|
107
|
+
<div>
|
|
108
|
+
<p className="block text-sm font-medium mb-1">Email</p>
|
|
109
|
+
|
|
110
|
+
<input
|
|
111
|
+
type="email"
|
|
112
|
+
className="w-full p-2 border border-gray-300 rounded"
|
|
113
|
+
placeholder="Enter your email"
|
|
114
|
+
/>
|
|
115
|
+
</div>
|
|
116
|
+
|
|
117
|
+
<div>
|
|
118
|
+
<p className="block text-sm font-medium mb-1">Password</p>
|
|
119
|
+
|
|
120
|
+
<input
|
|
121
|
+
type="password"
|
|
122
|
+
className="w-full p-2 border border-gray-300 rounded"
|
|
123
|
+
placeholder="Enter your password"
|
|
124
|
+
/>
|
|
125
|
+
</div>
|
|
126
|
+
</div>
|
|
127
|
+
|
|
128
|
+
<div className="my-6">
|
|
129
|
+
<RuleDivider>
|
|
130
|
+
<span className="text-xs text-gray-400 uppercase">OR</span>
|
|
131
|
+
</RuleDivider>
|
|
132
|
+
</div>
|
|
133
|
+
|
|
134
|
+
<button className="w-full py-2 px-4 bg-blue-500 text-white rounded hover:bg-blue-600">
|
|
135
|
+
Continue with Google
|
|
136
|
+
</button>
|
|
137
|
+
</div>
|
|
138
|
+
),
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export const ContentSections: Story = {
|
|
142
|
+
render: () => (
|
|
143
|
+
<div className="max-w-2xl p-6 space-y-6">
|
|
144
|
+
<div>
|
|
145
|
+
<h2 className="text-xl font-bold mb-2">Introduction</h2>
|
|
146
|
+
|
|
147
|
+
<p className="text-gray-600">
|
|
148
|
+
This is the introduction section with some content that explains the topic.
|
|
149
|
+
</p>
|
|
150
|
+
</div>
|
|
151
|
+
|
|
152
|
+
<RuleDivider>
|
|
153
|
+
<span className="text-sm text-gray-500">Chapter 1</span>
|
|
154
|
+
</RuleDivider>
|
|
155
|
+
|
|
156
|
+
<div>
|
|
157
|
+
<h3 className="text-lg font-semibold mb-2">Getting Started</h3>
|
|
158
|
+
|
|
159
|
+
<p className="text-gray-600">
|
|
160
|
+
Here we dive into the first chapter with detailed explanations and examples.
|
|
161
|
+
</p>
|
|
162
|
+
</div>
|
|
163
|
+
|
|
164
|
+
<RuleDivider>
|
|
165
|
+
<span className="text-sm text-gray-500">Chapter 2</span>
|
|
166
|
+
</RuleDivider>
|
|
167
|
+
|
|
168
|
+
<div>
|
|
169
|
+
<h3 className="text-lg font-semibold mb-2">Advanced Topics</h3>
|
|
170
|
+
|
|
171
|
+
<p className="text-gray-600">This section covers more advanced concepts and use cases.</p>
|
|
172
|
+
</div>
|
|
173
|
+
</div>
|
|
174
|
+
),
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
export const MultipleInList: Story = {
|
|
178
|
+
render: () => (
|
|
179
|
+
<div className="w-80 space-y-4">
|
|
180
|
+
<RuleDivider />
|
|
181
|
+
|
|
182
|
+
<RuleDivider>
|
|
183
|
+
<span className="text-gray-600">Section A</span>
|
|
184
|
+
</RuleDivider>
|
|
185
|
+
|
|
186
|
+
<RuleDivider>
|
|
187
|
+
<span className="text-gray-600">Section B</span>
|
|
188
|
+
</RuleDivider>
|
|
189
|
+
|
|
190
|
+
<RuleDivider>
|
|
191
|
+
<span className="text-gray-600">Section C</span>
|
|
192
|
+
</RuleDivider>
|
|
193
|
+
|
|
194
|
+
<RuleDivider />
|
|
195
|
+
</div>
|
|
196
|
+
),
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
export const DifferentWidths: Story = {
|
|
200
|
+
render: () => (
|
|
201
|
+
<div className="space-y-6">
|
|
202
|
+
<div className="w-32">
|
|
203
|
+
<div className="text-sm mb-2">Small (w-32)</div>
|
|
204
|
+
|
|
205
|
+
<RuleDivider>
|
|
206
|
+
<span className="text-xs">OR</span>
|
|
207
|
+
</RuleDivider>
|
|
208
|
+
</div>
|
|
209
|
+
|
|
210
|
+
<div className="w-64">
|
|
211
|
+
<div className="text-sm mb-2">Medium (w-64)</div>
|
|
212
|
+
|
|
213
|
+
<RuleDivider>
|
|
214
|
+
<span className="text-sm">Continue</span>
|
|
215
|
+
</RuleDivider>
|
|
216
|
+
</div>
|
|
217
|
+
|
|
218
|
+
<div className="w-96">
|
|
219
|
+
<div className="text-sm mb-2">Large (w-96)</div>
|
|
220
|
+
|
|
221
|
+
<RuleDivider>
|
|
222
|
+
<span className="text-base">Section Divider</span>
|
|
223
|
+
</RuleDivider>
|
|
224
|
+
</div>
|
|
225
|
+
</div>
|
|
226
|
+
),
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
export const WithButton: Story = {
|
|
230
|
+
render: () => (
|
|
231
|
+
<RuleDivider>
|
|
232
|
+
<button className="px-3 py-1 text-xs bg-gray-100 text-gray-600 rounded hover:bg-gray-200">
|
|
233
|
+
Show More
|
|
234
|
+
</button>
|
|
235
|
+
</RuleDivider>
|
|
236
|
+
),
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
export const WithMultipleElements: Story = {
|
|
240
|
+
render: () => (
|
|
241
|
+
<RuleDivider>
|
|
242
|
+
<div className="flex items-center gap-2">
|
|
243
|
+
<svg className="w-3 h-3" fill="currentColor" viewBox="0 0 20 20">
|
|
244
|
+
<path
|
|
245
|
+
fillRule="evenodd"
|
|
246
|
+
d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z"
|
|
247
|
+
clipRule="evenodd"
|
|
248
|
+
/>
|
|
249
|
+
</svg>
|
|
250
|
+
|
|
251
|
+
<span className="text-sm text-green-600">Completed</span>
|
|
252
|
+
</div>
|
|
253
|
+
</RuleDivider>
|
|
254
|
+
),
|
|
255
|
+
};
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { RuleDivider } from './RuleDivider';
|
|
2
|
+
import { render, screen } from '../../test/renderers';
|
|
3
|
+
|
|
4
|
+
describe('RuleDivider', () => {
|
|
5
|
+
it('should render with default props', () => {
|
|
6
|
+
const { container } = render(<RuleDivider />);
|
|
7
|
+
|
|
8
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should render single hr element when no children provided', () => {
|
|
12
|
+
const { container } = render(<RuleDivider />);
|
|
13
|
+
|
|
14
|
+
const hrElements = container.querySelectorAll('hr');
|
|
15
|
+
|
|
16
|
+
expect(hrElements).toHaveLength(1);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should have correct container classes', () => {
|
|
20
|
+
const { container } = render(<RuleDivider />);
|
|
21
|
+
|
|
22
|
+
const containerElement = container.firstChild as HTMLElement;
|
|
23
|
+
|
|
24
|
+
expect(containerElement).toHaveClass('flex', 'items-center');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should render with children', () => {
|
|
28
|
+
render(<RuleDivider>Divider Text</RuleDivider>);
|
|
29
|
+
|
|
30
|
+
expect(screen.getByText('Divider Text')).toBeInTheDocument();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should render two hr elements when children are provided', () => {
|
|
34
|
+
const { container } = render(<RuleDivider>With Text</RuleDivider>);
|
|
35
|
+
|
|
36
|
+
const hrElements = container.querySelectorAll('hr');
|
|
37
|
+
|
|
38
|
+
expect(hrElements).toHaveLength(2);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should apply correct classes to hr elements', () => {
|
|
42
|
+
const { container } = render(<RuleDivider />);
|
|
43
|
+
|
|
44
|
+
const hrElement = container.querySelector('hr');
|
|
45
|
+
|
|
46
|
+
expect(hrElement).toHaveClass('flex-grow');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should apply correct classes to span when children provided', () => {
|
|
50
|
+
const { container } = render(<RuleDivider>Test Content</RuleDivider>);
|
|
51
|
+
|
|
52
|
+
const spanElement = container.querySelector('span');
|
|
53
|
+
|
|
54
|
+
expect(spanElement).toHaveClass('px-2');
|
|
55
|
+
expect(spanElement).toHaveTextContent('Test Content');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should render complex children correctly', () => {
|
|
59
|
+
render(
|
|
60
|
+
<RuleDivider>
|
|
61
|
+
<strong>Bold Text</strong>
|
|
62
|
+
</RuleDivider>,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
expect(screen.getByText('Bold Text')).toBeInTheDocument();
|
|
66
|
+
expect(screen.getByText('Bold Text').tagName).toBe('STRONG');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('should handle multiple text nodes as children', () => {
|
|
70
|
+
render(<RuleDivider>Multiple words here</RuleDivider>);
|
|
71
|
+
|
|
72
|
+
expect(screen.getByText('Multiple words here')).toBeInTheDocument();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should render icon as children', () => {
|
|
76
|
+
const IconComponent = () => <svg data-testid="test-icon" />;
|
|
77
|
+
|
|
78
|
+
render(
|
|
79
|
+
<RuleDivider>
|
|
80
|
+
<IconComponent />
|
|
81
|
+
</RuleDivider>,
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
expect(screen.getByTestId('test-icon')).toBeInTheDocument();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should have proper structure when children provided', () => {
|
|
88
|
+
const { container } = render(<RuleDivider>Content</RuleDivider>);
|
|
89
|
+
|
|
90
|
+
const containerElement = container.firstChild as HTMLElement;
|
|
91
|
+
|
|
92
|
+
expect(containerElement.children).toHaveLength(3); // hr + span + hr
|
|
93
|
+
|
|
94
|
+
const [firstHr, span, secondHr] = containerElement.children;
|
|
95
|
+
|
|
96
|
+
expect(firstHr.tagName).toBe('HR');
|
|
97
|
+
expect(span.tagName).toBe('SPAN');
|
|
98
|
+
expect(secondHr.tagName).toBe('HR');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('should have proper structure when no children provided', () => {
|
|
102
|
+
const { container } = render(<RuleDivider />);
|
|
103
|
+
|
|
104
|
+
const containerElement = container.firstChild as HTMLElement;
|
|
105
|
+
|
|
106
|
+
expect(containerElement.children).toHaveLength(1); // only hr
|
|
107
|
+
|
|
108
|
+
const hrElement = containerElement.children[0];
|
|
109
|
+
|
|
110
|
+
expect(hrElement.tagName).toBe('HR');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('should handle empty string as children', () => {
|
|
114
|
+
const { container } = render(<RuleDivider>{''}</RuleDivider>);
|
|
115
|
+
|
|
116
|
+
// Empty string is falsy, so should behave like no children
|
|
117
|
+
const hrElements = container.querySelectorAll('hr');
|
|
118
|
+
|
|
119
|
+
expect(hrElements).toHaveLength(1);
|
|
120
|
+
|
|
121
|
+
const spanElement = container.querySelector('span');
|
|
122
|
+
|
|
123
|
+
expect(spanElement).not.toBeInTheDocument();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('should handle null children correctly', () => {
|
|
127
|
+
const { container } = render(<RuleDivider>{null}</RuleDivider>);
|
|
128
|
+
|
|
129
|
+
// null should be considered falsy, so only one hr should render
|
|
130
|
+
const hrElements = container.querySelectorAll('hr');
|
|
131
|
+
|
|
132
|
+
expect(hrElements).toHaveLength(1);
|
|
133
|
+
|
|
134
|
+
const spanElement = container.querySelector('span');
|
|
135
|
+
|
|
136
|
+
expect(spanElement).not.toBeInTheDocument();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('should handle undefined children correctly', () => {
|
|
140
|
+
const { container } = render(<RuleDivider>{undefined}</RuleDivider>);
|
|
141
|
+
|
|
142
|
+
// undefined should be considered falsy, so only one hr should render
|
|
143
|
+
const hrElements = container.querySelectorAll('hr');
|
|
144
|
+
|
|
145
|
+
expect(hrElements).toHaveLength(1);
|
|
146
|
+
|
|
147
|
+
const spanElement = container.querySelector('span');
|
|
148
|
+
|
|
149
|
+
expect(spanElement).not.toBeInTheDocument();
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('should render multiple child elements', () => {
|
|
153
|
+
render(
|
|
154
|
+
<RuleDivider>
|
|
155
|
+
<span>Text 1</span>
|
|
156
|
+
|
|
157
|
+
<span>Text 2</span>
|
|
158
|
+
</RuleDivider>,
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
expect(screen.getByText('Text 1')).toBeInTheDocument();
|
|
162
|
+
expect(screen.getByText('Text 2')).toBeInTheDocument();
|
|
163
|
+
});
|
|
164
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type RuleDividerProps = {
|
|
2
|
+
children?: React.ReactNode;
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
export const RuleDivider = ({ children }: RuleDividerProps) => {
|
|
6
|
+
return (
|
|
7
|
+
<div className="flex items-center">
|
|
8
|
+
<hr className="flex-grow" />
|
|
9
|
+
{children ? (
|
|
10
|
+
<>
|
|
11
|
+
<span className="px-2">{children}</span>
|
|
12
|
+
|
|
13
|
+
<hr className="flex-grow" />
|
|
14
|
+
</>
|
|
15
|
+
) : null}
|
|
16
|
+
</div>
|
|
17
|
+
);
|
|
18
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
|
|
3
3
|
import { DropdownMenu, type DropdownMenuItem, type DrowndownMenuButton } from './DropdownMenu';
|
|
4
|
-
import { render, screen, userEvent, waitFor } from '../../
|
|
4
|
+
import { render, screen, userEvent, waitFor } from '../../test/renderers';
|
|
5
5
|
|
|
6
6
|
type Item = { label: string };
|
|
7
7
|
|